[692] | 1 |
|
---|
| 2 | /** Tool designed to take the binary width files from BitmapFontBuilder
|
---|
| 3 | http://www.lmnopc.com/bitmapfontbuilder/ and convert them into
|
---|
| 4 | Ogre .fontdef 'glyph' statements.
|
---|
| 5 | Highly inelegant, but it works!
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include <iostream>
|
---|
| 9 | #include <fstream>
|
---|
| 10 | #include <string>
|
---|
| 11 | #include <math.h>
|
---|
| 12 | using namespace std;
|
---|
| 13 |
|
---|
| 14 | int main(int argc, char** argv)
|
---|
| 15 | {
|
---|
| 16 | int size;
|
---|
| 17 | std::string datName, newName, fontName, imageName, genGlyph;
|
---|
| 18 |
|
---|
| 19 | cout << "Enter unique font name: ";
|
---|
| 20 | cin >> fontName;
|
---|
| 21 | cout << "Enter font image name: ";
|
---|
| 22 | cin >> imageName;
|
---|
| 23 | cout << "Enter size of texture(Example: 256): ";
|
---|
| 24 | cin >> size;
|
---|
| 25 | cout << "Enter name of file containing binary widths: ";
|
---|
| 26 | cin >> datName;
|
---|
| 27 | cout << "Generate all glyph statements(Not Recommended)(Y/N): ";
|
---|
| 28 | cin >> genGlyph;
|
---|
| 29 | cout << "Enter name of new text file to create: ";
|
---|
| 30 | cin >> newName;
|
---|
| 31 |
|
---|
| 32 | int charSize = size / 16;
|
---|
| 33 | int halfWidth = charSize / 2;
|
---|
| 34 | FILE *fp = fopen(datName.c_str(), "rb");
|
---|
| 35 |
|
---|
| 36 | ofstream o(newName.c_str());
|
---|
| 37 |
|
---|
| 38 | o << fontName << endl;
|
---|
| 39 | o << "{" << "\n\n";
|
---|
| 40 | o << "\ttype\timage" << endl;
|
---|
| 41 | o << "\tsource\t" << imageName << "\n\n\n";
|
---|
| 42 |
|
---|
| 43 | int posx = 0;
|
---|
| 44 | int posy = 0;
|
---|
| 45 | int colcount = 0;
|
---|
| 46 | for (int c = 0; c < 256; c++, colcount++)
|
---|
| 47 | {
|
---|
| 48 | if (colcount == 16)
|
---|
| 49 | {
|
---|
| 50 | colcount = 0;
|
---|
| 51 | posx = 0;
|
---|
| 52 | posy += charSize;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | // Little endian only, but this tool isn't available for OSX anyway
|
---|
| 56 | int width = fgetc(fp) + (fgetc(fp) << 8);
|
---|
| 57 | float thisx_start = posx + halfWidth - (width / 2);
|
---|
| 58 | float thisx_end = posx + halfWidth + (width / 2);
|
---|
| 59 |
|
---|
| 60 | float u1, u2, v1, v2;
|
---|
| 61 | u1 = thisx_start / (float)(size) ;
|
---|
| 62 | u2 = thisx_end / (float)(size);
|
---|
| 63 | v1 = (float)posy / (float)(size);
|
---|
| 64 | v2 = (float)(posy + charSize) / (float)(size);
|
---|
| 65 |
|
---|
| 66 | if((genGlyph.at(0) == 'N' || genGlyph.at(0) == 'n') && c >= '!' && c <= '~')
|
---|
| 67 | {
|
---|
| 68 | std::string s = " ";
|
---|
| 69 | s.at(0) = c;
|
---|
| 70 | o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if((genGlyph.at(0) != 'N' && genGlyph.at(0) != 'n'))
|
---|
| 74 | {
|
---|
| 75 | std::string s = " ";
|
---|
| 76 | s.at(0) = c;
|
---|
| 77 | o << "\tglyph " << s << " " << u1 << " " << v1 << " " << u2 << " " << v2 << std::endl;
|
---|
| 78 | }
|
---|
| 79 | posx += charSize;
|
---|
| 80 |
|
---|
| 81 | }
|
---|
| 82 | o << endl;
|
---|
| 83 | o << "}" << endl;
|
---|
| 84 | fclose(fp);
|
---|
| 85 |
|
---|
| 86 | return 0;
|
---|
| 87 | }
|
---|