-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-#include <limits.h>\r
-#include <zlib.h>\r
-#include <ft2build.h>\r
-#include FT_FREETYPE_H\r
-#include FT_STROKER_H\r
-#include FT_GLYPH_H\r
-\r
-typedef unsigned char uchar;\r
-typedef unsigned short ushort;\r
-typedef unsigned int uint;\r
-\r
-int imin(int a, int b) { return a < b ? a : b; }\r
-int imax(int a, int b) { return a > b ? a : b; }\r
-\r
-void fatal(const char *fmt, ...)\r {
-\r
- va_list v;\r
- va_start(v, fmt);\r
- vfprintf(stderr, fmt, v);\r
- va_end(v);\r
- fputc('\n', stderr);\r
-\r
- exit(EXIT_FAILURE);\r
-}\r
-\r
-uint bigswap(uint n)\r {
-\r
- const int islittleendian = 1;\r
- return *(const uchar *)&islittleendian ? (n<<24) | (n>>24) | ((n>>8)&0xFF00) | ((n<<8)&0xFF0000) : n;\r
-}\r
-\r
-size_t writebig(FILE *f, uint n)\r {
-\r
- n = bigswap(n);\r
- return fwrite(&n, 1, sizeof(n), f);\r
-}\r
-\r
-void writepngchunk(FILE *f, const char *type, uchar *data, uint len)\r {
-\r
- uint crc;\r
- writebig(f, len);\r
- fwrite(type, 1, 4, f);\r
- fwrite(data, 1, len, f);\r
-\r
- crc = crc32(0, Z_NULL, 0);\r
- crc = crc32(crc, (const Bytef *)type, 4);\r
- if(data) crc = crc32(crc, data, len);\r
- writebig(f, crc);\r
-}\r
-\r
-struct pngihdr\r {
-\r
- uint width, height;\r
- uchar bitdepth, colortype, compress, filter, interlace;\r
-};\r
-\r
-void savepng(const char *filename, uchar *data, int w, int h, int bpp, int flip)\r {
-\r
- const uchar signature[] = { 137, 80, 78, 71, 13, 10, 26, 10 };\r
- struct pngihdr ihdr;\r
- FILE *f;\r
- long idat;\r
- uint len, crc;\r
- z_stream z;\r
- uchar buf[1<<12];\r
- int i, j;\r
-\r
- memset(&ihdr, 0, sizeof(ihdr));\r
- ihdr.width = bigswap(w);\r
- ihdr.height = bigswap(h);\r
- ihdr.bitdepth = 8;\r
- switch(bpp)\r {
-\r
- case 1: ihdr.colortype = 0; break;\r
- case 2: ihdr.colortype = 4; break;\r
- case 3: ihdr.colortype = 2; break;\r
- case 4: ihdr.colortype = 6; break;\r
- default: fatal("cube2font: invalid PNG bpp"); return;\r
- }\r
- f = fopen(filename, "wb");\r
- if(!f) { fatal("cube2font: could not write to %s", filename); return; }\r
-\r
- fwrite(signature, 1, sizeof(signature), f);\r
-\r
- writepngchunk(f, "IHDR", (uchar *)&ihdr, 13);\r
-\r
- idat = ftell(f);\r
- len = 0;\r
- fwrite("\0\0\0\0IDAT", 1, 8, f);\r
- crc = crc32(0, Z_NULL, 0);\r
- crc = crc32(crc, (const Bytef *)"IDAT", 4);\r
-\r
- z.zalloc = NULL;\r
- z.zfree = NULL;\r
- z.opaque = NULL;\r
-\r
- if(deflateInit(&z, Z_BEST_COMPRESSION) != Z_OK)\r
- goto error;\r
-\r
- z.next_out = (Bytef *)buf;\r
- z.avail_out = sizeof(buf);\r
-\r
- for(i = 0; i < h; i++)\r {
-\r
- uchar filter = 0;\r
- for(j = 0; j < 2; j++)\r {
-\r
- z.next_in = j ? (Bytef *)data + (flip ? h-i-1 : i)*w*bpp : (Bytef *)&filter;\r
- z.avail_in = j ? w*bpp : 1;\r
- while(z.avail_in > 0)\r {
-\r
- if(deflate(&z, Z_NO_FLUSH) != Z_OK) goto cleanuperror;\r
- #define FLUSHZ do { \\r
- int flush = sizeof(buf) - z.avail_out; \\r
- crc = crc32(crc, buf, flush); \\r
- len += flush; \\r
- fwrite(buf, 1, flush, f); \\r
- z.next_out = (Bytef *)buf; \\r
- z.avail_out = sizeof(buf); \\r
- } while(0)\r
- FLUSHZ;\r
- }\r
- }\r
- }\r
-\r
- for(;;)\r {
-\r
- int err = deflate(&z, Z_FINISH);\r
- if(err != Z_OK && err != Z_STREAM_END) goto cleanuperror;\r
- FLUSHZ;\r
- if(err == Z_STREAM_END) break;\r
- }\r
-\r
- deflateEnd(&z);\r
-\r
- fseek(f, idat, SEEK_SET);\r
- writebig(f, len);\r
- fseek(f, 0, SEEK_END);\r
- writebig(f, crc);\r
-\r
- writepngchunk(f, "IEND", NULL, 0);\r
-\r
- fclose(f);\r
- return;\r
-\r
-cleanuperror:\r
- deflateEnd(&z);\r
-\r
-error:\r
- fclose(f);\r
-\r
- fatal("cube2font: failed saving PNG to %s", filename);\r
-}\r
-\r
-enum\r {
-\r
- CT_PRINT = 1<<0,\r
- CT_SPACE = 1<<1,\r
- CT_DIGIT = 1<<2,\r
- CT_ALPHA = 1<<3,\r
- CT_LOWER = 1<<4,\r
- CT_UPPER = 1<<5,\r
- CT_UNICODE = 1<<6\r
-};\r
-#define CUBECTYPE(s, p, d, a, A, u, U) \\r
- 0, U, U, U, U, U, U, U, U, s, s, s, s, s, U, U, \\r
- U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, \\r
- s, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, \\r
- d, d, d, d, d, d, d, d, d, d, p, p, p, p, p, p, \\r
- p, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, \\r
- A, A, A, A, A, A, A, A, A, A, A, p, p, p, p, p, \\r
- p, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, \\r
- a, a, a, a, a, a, a, a, a, a, a, p, p, p, p, U, \\r
- U, u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, \\r
- u, u, u, u, u, u, u, u, u, u, u, u, u, u, u, U, \\r
- u, U, u, U, u, U, u, U, u, U, u, U, u, U, u, U, \\r
- u, U, u, U, u, U, u, U, u, U, u, U, u, U, u, U, \\r
- u, U, u, U, u, U, u, U, U, u, U, u, U, u, U, U, \\r
- U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, \\r
- U, U, U, U, u, u, u, u, u, u, u, u, u, u, u, u, \\r
- u, u, u, u, u, u, u, u, u, u, u, u, u, u, U, u\r
-const uchar cubectype[256] =\r {
-\r
- CUBECTYPE(CT_SPACE,\r
- CT_PRINT,\r
- CT_PRINT|CT_DIGIT,\r
- CT_PRINT|CT_ALPHA|CT_LOWER,\r
- CT_PRINT|CT_ALPHA|CT_UPPER,\r
- CT_PRINT|CT_UNICODE|CT_ALPHA|CT_LOWER,\r
- CT_PRINT|CT_UNICODE|CT_ALPHA|CT_UPPER)\r
-};\r
-int iscubeprint(uchar c) { return cubectype[c]&CT_PRINT; }\r
-int iscubespace(uchar c) { return cubectype[c]&CT_SPACE; }\r
-int iscubealpha(uchar c) { return cubectype[c]&CT_ALPHA; }\r
-int iscubealnum(uchar c) { return cubectype[c]&(CT_ALPHA|CT_DIGIT); }\r
-int iscubelower(uchar c) { return cubectype[c]&CT_LOWER; }\r
-int iscubeupper(uchar c) { return cubectype[c]&CT_UPPER; }\r
-const int cube2unichars[256] =\r {
-\r
- 0, 192, 193, 194, 195, 196, 197, 198, 199, 9, 10, 11, 12, 13, 200, 201,\r
- 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219,\r
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,\r
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,\r
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,\r
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,\r
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,\r
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 220,\r
- 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,\r
- 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253, 255, 0x104,\r
- 0x105, 0x106, 0x107, 0x10C, 0x10D, 0x10E, 0x10F, 0x118, 0x119, 0x11A, 0x11B, 0x11E, 0x11F, 0x130, 0x131, 0x141,\r
- 0x142, 0x143, 0x144, 0x147, 0x148, 0x150, 0x151, 0x152, 0x153, 0x158, 0x159, 0x15A, 0x15B, 0x15E, 0x15F, 0x160,\r
- 0x161, 0x164, 0x165, 0x16E, 0x16F, 0x170, 0x171, 0x178, 0x179, 0x17A, 0x17B, 0x17C, 0x17D, 0x17E, 0x404, 0x411,\r
- 0x413, 0x414, 0x416, 0x417, 0x418, 0x419, 0x41B, 0x41F, 0x423, 0x424, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B,\r
- 0x42C, 0x42D, 0x42E, 0x42F, 0x431, 0x432, 0x433, 0x434, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D,\r
- 0x43F, 0x442, 0x444, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x454, 0x490, 0x491\r
-};\r
-int cube2uni(uchar c)\r {
-\r
- return cube2unichars[c];\r
-}\r
-\r
-const char *encodeutf8(int uni)\r {
-\r
- static char buf[7];\r
- char *dst = buf;\r
- if(uni <= 0x7F) { *dst++ = uni; goto uni1; }\r
- else if(uni <= 0x7FF) { *dst++ = 0xC0 | (uni>>6); goto uni2; }\r
- else if(uni <= 0xFFFF) { *dst++ = 0xE0 | (uni>>12); goto uni3; }\r
- else if(uni <= 0x1FFFFF) { *dst++ = 0xF0 | (uni>>18); goto uni4; }\r
- else if(uni <= 0x3FFFFFF) { *dst++ = 0xF8 | (uni>>24); goto uni5; }\r
- else if(uni <= 0x7FFFFFFF) { *dst++ = 0xFC | (uni>>30); goto uni6; }\r
- else goto uni1;\r
-uni6: *dst++ = 0x80 | ((uni>>24)&0x3F);\r
-uni5: *dst++ = 0x80 | ((uni>>18)&0x3F);\r
-uni4: *dst++ = 0x80 | ((uni>>12)&0x3F);\r
-uni3: *dst++ = 0x80 | ((uni>>6)&0x3F);\r
-uni2: *dst++ = 0x80 | (uni&0x3F);\r
-uni1: *dst++ = '\0';\r
- return buf;\r
-}\r
-\r
-struct fontchar { int code, uni, tex, x, y, w, h, offx, offy, offset, advance; FT_BitmapGlyph color, alpha; };\r
-\r
-const char *texdir = "";\r
-\r
-const char *texfilename(const char *name, int texnum)\r {
-\r
- static char file[256];\r
- snprintf(file, sizeof(file), "%s%d.png", name, texnum);\r
- return file;\r
-}\r
-\r
-const char *texname(const char *name, int texnum)\r {
-\r
- static char file[512];\r
- snprintf(file, sizeof(file), "<grey>%s%s", texdir, texfilename(name, texnum));\r
- return file;\r
-}\r
-\r
-void writetexs(const char *name, struct fontchar *chars, int numchars, int numtexs, int tw, int th)\r {
-\r
- int tex;\r
- uchar *pixels = (uchar *)malloc(tw*th*2);\r
- if(!pixels) fatal("cube2font: failed allocating textures");\r
- for(tex = 0; tex < numtexs; tex++)\r {
-\r
- const char *file = texfilename(name, tex);\r
- int texchars = 0, i;\r
- uchar *dst, *src;\r
- memset(pixels, 0, tw*th*2);\r
- for(i = 0; i < numchars; i++)\r {
-\r
- struct fontchar *c = &chars[i];\r
- int x, y;\r
- if(c->tex != tex) continue;\r
- texchars++;\r
- dst = &pixels[2*((c->y + c->offy - c->color->top)*tw + c->x + c->color->left - c->offx)];\r
- src = (uchar *)c->color->bitmap.buffer;\r
- for(y = 0; y < c->color->bitmap.rows; y++)\r {
-\r
- for(x = 0; x < c->color->bitmap.width; x++)\r
- dst[2*x] = src[x];\r
- src += c->color->bitmap.pitch;\r
- dst += 2*tw;\r
- }\r
- dst = &pixels[2*((c->y + c->offy - c->alpha->top)*tw + c->x + c->alpha->left - c->offx)];\r
- src = (uchar *)c->alpha->bitmap.buffer;\r
- for(y = 0; y < c->alpha->bitmap.rows; y++)\r {
-\r
- for(x = 0; x < c->alpha->bitmap.width; x++)\r
- dst[2*x+1] = src[x];\r
- src += c->alpha->bitmap.pitch;\r
- dst += 2*tw;\r
- }\r
- }\r
- printf("cube2font: writing %d chars to %s\n", texchars, file);\r
- savepng(file, pixels, tw, th, 2, 0);\r
- }\r
- free(pixels);\r
-}\r
-\r
-void writecfg(const char *name, struct fontchar *chars, int numchars, int x1, int y1, int x2, int y2, int sw, int sh, int argc, char **argv)\r {
-\r
- FILE *f;\r
- char file[256];\r
- int i, lastcode = 0, lasttex = 0;\r
- snprintf(file, sizeof(file), "%s.cfg", name);\r
- f = fopen(file, "w");\r
- if(!f) fatal("cube2font: failed writing %s", file);\r
- printf("cube2font: writing %d chars to %s\n", numchars, file);\r
- fprintf(f, "//");\r
- for(i = 1; i < argc; i++)\r
- fprintf(f, " %s", argv[i]);\r
- fprintf(f, "\n");\r
- fprintf(f, "font \"%s\" \"%s\" %d %d\n", name, texname(name, 0), sw, sh);\r
- for(i = 0; i < numchars; i++)\r {
-\r
- struct fontchar *c = &chars[i];\r
- if(!lastcode && lastcode < c->code)\r {
-\r
- fprintf(f, "fontoffset \"%s\"\n", encodeutf8(c->uni));\r
- lastcode = c->code;\r
- }\r
- else if(lastcode < c->code)\r {
-\r
- if(lastcode + 1 == c->code)\r
- fprintf(f, "fontskip // %d\n", lastcode);\r
- else\r
- fprintf(f, "fontskip %d // %d .. %d\n", c->code - lastcode, lastcode, c->code-1);\r
- lastcode = c->code;\r
- }\r
- if(lasttex != c->tex)\r {
-\r
- fprintf(f, "\nfonttex \"%s\"\n", texname(name, c->tex));\r
- lasttex = c->tex;\r
- }\r
- if(c->code != c->uni)\r
- fprintf(f, "fontchar %d %d %d %d %d %d %d // %s (%d -> 0x%X)\n", c->x, c->y, c->w, c->h, c->offx+c->offset, y2-c->offy, c->advance, encodeutf8(c->uni), c->code, c->uni);\r
- else\r
- fprintf(f, "fontchar %d %d %d %d %d %d %d // %s (%d)\n", c->x, c->y, c->w, c->h, c->offx+c->offset, y2-c->offy, c->advance, encodeutf8(c->uni), c->code);\r
- lastcode++;\r
- }\r
- fclose(f);\r
-}\r
-\r
-int groupchar(int c)\r {
-\r
- switch(c)\r {
-\r
- case 0x152: case 0x153: case 0x178: return 1;\r
- }\r
- if(c < 127 || c >= 0x2000) return 0;\r
- if(c < 0x100) return 1;\r
- if(c < 0x400) return 2;\r
- return 3;\r
-}\r
-\r
-int sortchars(const void *x, const void *y)\r {
-\r
- const struct fontchar *xc = *(const struct fontchar **)x, *yc = *(const struct fontchar **)y;\r
- int xg = groupchar(xc->uni), yg = groupchar(yc->uni);\r
- if(xg < yg) return -1;\r
- if(xg > yg) return 1;\r
- if(xc->h != yc->h) return yc->h - xc->h;\r
- if(xc->w != yc->w) return yc->w - xc->w;\r
- return yc->uni - xc->uni;\r
-}\r
-\r
-int scorechar(struct fontchar *f, int pad, int tw, int th, int rw, int rh, int ry)\r {
-\r
- int score = 0;\r
- if(rw + f->w > tw) { ry += rh + pad; score = 1; }\r
- if(ry + f->h > th) score = 2;\r
- return score;\r
-}\r
-\r
-int main(int argc, char **argv)\r {
-\r
- FT_Library l;\r
- FT_Face f;\r
- FT_Stroker s, s2;\r
- int i, pad, offset, advance, w, h, tw, th, c, trial = -2, rw = 0, rh = 0, ry = 0, x1 = INT_MAX, x2 = INT_MIN, y1 = INT_MAX, y2 = INT_MIN, w2 = 0, h2 = 0, sw = 0, sh = 0;\r
- float outborder = 0, inborder = 0;\r
- struct fontchar chars[256];\r
- struct fontchar *order[256];\r
- int numchars = 0, numtex = 0;\r
- if(argc < 11)\r
- fatal("Usage: cube2font infile outfile outborder[:inborder] pad offset advance charwidth charheight texwidth texheight [spacewidth spaceheight texdir]");\r
- sscanf(argv[3], "%f:%f", &outborder, &inborder);\r
- pad = atoi(argv[4]);\r
- offset = atoi(argv[5]);\r
- advance = atoi(argv[6]);\r
- w = atoi(argv[7]);\r
- h = atoi(argv[8]);\r
- tw = atoi(argv[9]);\r
- th = atoi(argv[10]);\r
- if(argc > 11) sw = atoi(argv[11]);\r
- if(argc > 12) sh = atoi(argv[12]);\r
- if(argc > 13) texdir = argv[13];\r
- if(FT_Init_FreeType(&l))\r
- fatal("cube2font: failed initing freetype");\r
- if(FT_New_Face(l, argv[1], 0, &f) ||\r
- FT_Set_Charmap(f, f->charmaps[0]) ||\r
- FT_Set_Pixel_Sizes(f, w, h) ||\r
- FT_Stroker_New(l, &s) ||\r
- FT_Stroker_New(l, &s2))\r
- fatal("cube2font: failed loading font %s", argv[1]);\r
- if(outborder > 0) FT_Stroker_Set(s, (FT_Fixed)(outborder * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);\r
- if(inborder > 0) FT_Stroker_Set(s2, (FT_Fixed)(inborder * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);\r
- for(c = 0; c < 256; c++) if(iscubeprint(c))\r {
-\r
- FT_Glyph p, p2;\r
- FT_BitmapGlyph b, b2;\r
- struct fontchar *dst = &chars[numchars];\r
- dst->code = c;\r
- dst->uni = cube2uni(c);\r
- if(FT_Load_Char(f, dst->uni, FT_LOAD_DEFAULT))\r
- fatal("cube2font: failed loading character %s", encodeutf8(dst->uni));\r
- FT_Get_Glyph(f->glyph, &p);\r
- p2 = p;\r
- if(outborder > 0) FT_Glyph_StrokeBorder(&p, s, 0, 0);\r
- if(inborder > 0) FT_Glyph_StrokeBorder(&p2, s2, 1, 0);\r
- FT_Glyph_To_Bitmap(&p, FT_RENDER_MODE_NORMAL, 0, 1);\r
- if(inborder > 0 || outborder > 0) FT_Glyph_To_Bitmap(&p2, FT_RENDER_MODE_NORMAL, 0, 1);\r
- else p2 = p;\r
- b = (FT_BitmapGlyph)p;\r
- b2 = (FT_BitmapGlyph)p2;\r
- dst->tex = -1;\r
- dst->x = INT_MIN;\r
- dst->y = INT_MIN;\r
- dst->offx = imin(b->left, b2->left);\r
- dst->offy = imax(b->top, b2->top);\r
- dst->offset = offset;\r
- dst->advance = offset + ((p->advance.x+0xFFFF)>>16) + advance;\r
- dst->w = imax(b->left + b->bitmap.width, b2->left + b2->bitmap.width) - dst->offx;\r
- dst->h = dst->offy - imin(b->top - b->bitmap.rows, b2->top - b2->bitmap.rows);\r
- dst->alpha = b;\r
- dst->color = b2;\r
- order[numchars++] = dst;\r
- }\r
- qsort(order, numchars, sizeof(order[0]), sortchars);\r
- for(i = 0; i < numchars;)\r {
-\r
- struct fontchar *dst;\r
- int j, k, trial0, prevscore, dstscore, fitscore;\r
- for(trial0 = trial, prevscore = -1; (trial -= 2) >= trial0-512;)\r {
-\r
- int g, fw = rw, fh = rh, fy = ry, curscore = 0, reused = 0;\r
- for(j = i; j < numchars; j++)\r {
-\r
- dst = order[j];\r
- if(dst->tex >= 0 || dst->tex <= trial) continue;\r
- g = groupchar(dst->uni);\r
- dstscore = scorechar(dst, pad, tw, th, fw, fh, fy);\r
- for(k = j; k < numchars; k++)\r {
-\r
- struct fontchar *fit = order[k];\r
- if(fit->tex >= 0 || fit->tex <= trial) continue;\r
- if(fit->tex >= trial0 && groupchar(fit->uni) != g) break;\r
- fitscore = scorechar(fit, pad, tw, th, fw, fh, fy);\r
- if(fitscore < dstscore || (fitscore == dstscore && fit->h > dst->h))\r {
-\r
- dst = fit;\r
- dstscore = fitscore;\r
- }\r
- }\r
- if(fw + dst->w > tw)\r {
-\r
- fy += fh + pad;\r
- fw = fh = 0;\r
- }\r
- if(fy + dst->h > th)\r {
-\r
- fy = fw = fh = 0;\r
- if(curscore > 0) break;\r
- }\r
- if(dst->tex >= trial+1 && dst->tex <= trial+2) { dst->tex = trial; reused++; }\r
- else dst->tex = trial;\r
- fw += dst->w + pad;\r
- fh = imax(fh, dst->h);\r
- if(dst != order[j]) --j;\r
- curscore++;\r
- }\r
- if(reused < prevscore || curscore <= prevscore) break;\r
- prevscore = curscore;\r
- }\r
- for(; i < numchars; i++)\r {
-\r
- dst = order[i];\r
- if(dst->tex >= 0) continue;\r
- dstscore = scorechar(dst, pad, tw, th, rw, rh, ry);\r
- for(j = i; j < numchars; j++)\r {
-\r
- struct fontchar *fit = order[j];\r
- if(fit->tex < trial || fit->tex > trial+2) continue;\r
- fitscore = scorechar(fit, pad, tw, th, rw, rh, ry);\r
- if(fitscore < dstscore || (fitscore == dstscore && fit->h > dst->h))\r {
-\r
- dst = fit;\r
- dstscore = fitscore;\r
- }\r
- }\r
- if(dst->tex < trial || dst->tex > trial+2) break;\r
- if(rw + dst->w > tw)\r {
-\r
- ry += rh + pad;\r
- rw = rh = 0;\r
- }\r
- if(ry + dst->h > th)\r {
-\r
- ry = rw = rh = 0;\r
- numtex++;\r
- }\r
- dst->tex = numtex;\r
- dst->x = rw;\r
- dst->y = ry;\r
- rw += dst->w + pad;\r
- rh = imax(rh, dst->h);\r
- y1 = imin(y1, dst->offy - dst->h);\r
- y2 = imax(y2, dst->offy);\r
- x1 = imin(x1, dst->offx);\r
- x2 = imax(x2, dst->offx + dst->w);\r
- w2 = imax(w2, dst->w);\r
- h2 = imax(h2, dst->h);\r
- if(dst != order[i]) --i;\r
- }\r
- }\r
- if(rh > 0) numtex++;\r
- if(sh <= 0) sh = y2 - y1;\r
- if(sw <= 0) sw = sh/3;\r
- writetexs(argv[2], chars, numchars, numtex, tw, th);\r
- writecfg(argv[2], chars, numchars, x1, y1, x2, y2, sw, sh, argc, argv);\r
- for(i = 0; i < numchars; i++) {\r
- if(chars[i].alpha != chars[i].color) FT_Done_Glyph((FT_Glyph)chars[i].alpha);\r
- FT_Done_Glyph((FT_Glyph)chars[i].color);\r
- }\r
- FT_Stroker_Done(s);\r
- FT_Stroker_Done(s2);\r
- FT_Done_FreeType(l);\r
- printf("cube2font: (%d, %d) .. (%d, %d) = (%d, %d) / (%d, %d), %d texs\n", x1, y1, x2, y2, x2 - x1, y2 - y1, w2, h2, numtex);\r
- return EXIT_SUCCESS;\r
-}\r
-\r