diff -uNr ttf2pk-1.5_CVS20051222.003/ttfaux.c ttf2pk-1.5_CVS20051222.004/ttfaux.c --- ttf2pk-1.5_CVS20051222.003/ttfaux.c 2005-12-22 17:26:32.000000000 +0900 +++ ttf2pk-1.5_CVS20051222.004/ttfaux.c 2005-12-19 05:08:27.000000000 +0900 @@ -12,10 +12,16 @@ #include #include -#include "freetype.h" -#include "ftxkern.h" /* we are in the FreeType package tree */ -#include "ftxpost.h" -#include "ftxopen.h" +#include +#include FT_FREETYPE_H +#include FT_OUTLINE_H +#include FT_TYPE1_TABLES_H +#include FT_BBOX_H +#if 0 +#include "extend/ftxkern.h" /* we are in the FreeType package tree */ +#include "extend/ftxpost.h" +#include "extend/ftxopen.h" +#endif #include "ttf2tfm.h" #include "newobj.h" @@ -33,54 +39,60 @@ #define Microsoft_platform 3 #define Microsoft_Unicode_encoding 1 -#define SCRIPT_kana MAKE_TT_TAG('k', 'a', 'n', 'a') -#define SCRIPT_hani MAKE_TT_TAG('h', 'a', 'n', 'i') -#define SCRIPT_hang MAKE_TT_TAG('h', 'a', 'n', 'g') - -#define LANGUAGE_JAN MAKE_TT_TAG('J', 'A', 'N', ' ') -#define LANGUAGE_CHN MAKE_TT_TAG('C', 'H', 'N', ' ') -#define LANGUAGE_KOR MAKE_TT_TAG('K', 'O', 'R', ' ') +#define SCRIPT_kana MAKE_FT_TAG('k', 'a', 'n', 'a') +#define SCRIPT_hani MAKE_FT_TAG('h', 'a', 'n', 'i') +#define SCRIPT_hang MAKE_FT_TAG('h', 'a', 'n', 'g') + +#define LANGUAGE_JAN MAKE_FT_TAG('J', 'A', 'N', ' ') +#define LANGUAGE_CHN MAKE_FT_TAG('C', 'H', 'N', ' ') +#define LANGUAGE_KOR MAKE_FT_TAG('K', 'O', 'R', ' ') -#define FEATURE_vert MAKE_TT_TAG('v', 'e', 'r', 't') +#define FEATURE_vert MAKE_FT_TAG('v', 'e', 'r', 't') extern char progname[]; char *real_ttfname; -TT_Engine engine; -TT_Face face; -TT_Instance instance; -TT_Glyph glyph; -TT_Outline outline; -TT_CharMap char_map; -TT_Matrix matrix1, matrix2; - -TT_Big_Glyph_Metrics metrics; -TT_Face_Properties properties; -TT_BBox bbox; - -TT_Kerning directory; -TT_Post post; +FT_Library engine; +FT_Face face; +/*FT_Instance instance;*/ +FT_GlyphSlot glyph; +FT_Outline outline; +FT_CharMap char_map; +FT_Matrix matrix1, matrix2; + +int flags = FT_LOAD_DEFAULT|FT_LOAD_NO_SCALE; + +#if 0 +FT_Big_Glyph_Metrics metrics; +FT_Face_Properties properties; +#endif +FT_BBox bbox; + +#if 0 +FT_Kerning directory; +FT_Post post; TTO_GSUBHeader gsub_; TTO_GSUBHeader *gsub; +#endif Boolean has_gsub; - +#if 0 static void readttf_kern(Font *fnt) { register kern *nk; - register ttfinfo *ti_l, *ti_r; - TT_Kern_0_Pair* pairs0; - TT_Error error; + register ttfinfo *ti; + FT_Kern_0_Pair* pairs0; + FT_Error error; unsigned int i, j; - if ((error = TT_Get_Kerning_Directory(face, &directory))) + if ((error = FT_Get_Kerning_Directory(face, &directory))) oops("Cannot get kerning directory (error code = 0x%x).", error); if (directory.nTables == 0) @@ -88,7 +100,7 @@ for (i = 0; i < directory.nTables; i++) { - if ((error = TT_Load_Kerning_Table(face, i))) + if ((error = FT_Load_Kerning_Table(face, i))) oops("Cannot load kerning table (error code = 0x%x).", error); switch (directory.tables[i].format) @@ -97,18 +109,18 @@ pairs0 = directory.tables[i].t.kern0.pairs; for (j = 0; j < directory.tables[i].t.kern0.nPairs; j++, pairs0++) { - ti_l = findglyph(pairs0->left, fnt->charlist); - if (ti_l == NULL) - continue; - ti_r = findglyph(pairs0->right, fnt->charlist); - if (ti_r == NULL) - continue; - nk = newkern(); - nk->succ = ti_r->adobename; - nk->delta = transform(pairs0->value * 1000 / fnt->units_per_em, 0, - fnt->efactor, fnt->slant); - nk->next = ti_l->kerns; - ti_l->kerns = nk; + ti = findglyph(pairs0->left, fnt->charlist); + if (ti == NULL) + warning("kern char not found"); + else + { + nk = newkern(); + nk->succ = findglyph(pairs0->right, fnt->charlist)->adobename; + nk->delta = transform(pairs0->value * 1000 / fnt->units_per_em, 0, + fnt->efactor, fnt->slant); + nk->next = ti->kerns; + ti->kerns = nk; + } } return; /* we stop after the first format 0 kerning table */ @@ -119,26 +131,30 @@ return; } +#endif + void readttf(Font *fnt, Boolean quiet, Boolean only_range) { - TT_Error error; + FT_Error error; ttfinfo *ti, *Ti; long Num, index; unsigned int i, j; long k, max_k; unsigned short num_cmap; - unsigned short cmap_plat, cmap_enc; + unsigned short cmap_plat=0, cmap_enc=0; int index_array[257]; static Boolean initialized = False; - TT_UShort in_string[2]; +#if 0 + FT_UShort in_string[2]; TTO_GSUB_String in, out; - TT_UShort script_index, language_index, feature_index; - TT_UShort req_feature_index = 0xFFFF; + FT_UShort script_index, language_index, feature_index; + FT_UShort req_feature_index = 0xFFFF; +#endif /* @@ -162,19 +178,20 @@ if (!initialized) { - if ((error = TT_Init_FreeType(&engine))) + if ((error = FT_Init_FreeType(&engine))) oops("Cannot initialize engine (error code = 0x%x).", error); - - if ((error = TT_Init_Kerning_Extension(engine))) +#if 0 + if ((error = FT_Init_Kerning_Extension(engine))) oops("Cannot initialize kerning (error code = 0x%x).", error); if (fnt->PSnames) - if ((error = TT_Init_Post_Extension(engine))) + if ((error = FT_Init_Post_Extension(engine))) oops("Cannot initialize PS name support (error code = 0x%x).", error); if (fnt->rotate) - if ((error = TT_Init_GSUB_Extension(engine))) + if ((error = FT_Init_GSUB_Extension(engine))) oops("Cannot initialize GSUB support (error code = 0x%x).", error); +#endif /* * Load face. @@ -184,14 +201,16 @@ if (!real_ttfname) oops("Cannot find `%s'.", fnt->ttfname); - if ((error = TT_Open_Face(engine, real_ttfname, &face))) + if ((error = FT_New_Face(engine, real_ttfname, 0,&face))) oops("Cannot open `%s'.", real_ttfname); /* * Get face properties and allocate preload arrays. */ - TT_Get_Face_Properties(face, &properties); +#if 0 + FT_Get_Face_Properties(face, &properties); +#endif /* * Now we try to open the proper font in a collection. @@ -199,7 +218,7 @@ if (fnt->fontindex != 0) { - if (properties.num_Faces == 1) + if (face->num_faces == 1) { warning("This isn't a TrueType collection.\n" "Parameter `-f' is ignored."); @@ -208,11 +227,13 @@ } else { - TT_Close_Face(face); - if ((error = TT_Open_Collection(engine, real_ttfname, +#if 0 + FT_Close_Face(face); + if ((error = FT_Open_Collection(engine, real_ttfname, fnt->fontindex, &face))) oops("Cannot open font %lu in TrueType Collection `%s'.", fnt->fontindex, real_ttfname); +#endif } } @@ -220,21 +241,26 @@ * Create instance. */ - if ((error = TT_New_Instance(face, &instance))) +#if 0 + if ((error = FT_New_Instance(face, &instance))) oops("Cannot create instance for `%s' (error code = 0x%x).", real_ttfname, error); +#endif /* * We use a dummy glyph size of 10pt. */ - if ((error = TT_Set_Instance_CharSize(instance, 10 * 64))) +#if 1 + /*if ((error = FT_Set_Instance_CharSize(instance, 10 * 64)))*/ + if ((error = FT_Set_Char_Size(face, 10 * 64,10 * 64, 92,92))) oops("Cannot set character size (error code = 0x%x).", error); +#endif - matrix1.xx = (TT_Fixed)(floor(fnt->efactor * 1024) * (1L<<16)/1024); - matrix1.xy = (TT_Fixed)(floor(fnt->slant * 1024) * (1L<<16)/1024); - matrix1.yx = (TT_Fixed)0; - matrix1.yy = (TT_Fixed)(1L<<16); + matrix1.xx = (FT_Fixed)(floor(fnt->efactor * 1024) * (1L<<16)/1024); + matrix1.xy = (FT_Fixed)(floor(fnt->slant * 1024) * (1L<<16)/1024); + matrix1.yx = (FT_Fixed)0; + matrix1.yy = (FT_Fixed)(1L<<16); if (fnt->rotate) { @@ -244,31 +270,45 @@ matrix2.yy = matrix2.xx; } - if ((error = TT_Set_Instance_Transform_Flags( +#if 0 + if ((error = FT_Set_Instance_Transform_Flags( instance, fnt->rotate ? 1 : 0, fnt->efactor != 1.0 ? 1 : 0))) oops("Cannot set transform flags (error code = 0x%x).", error); +#endif /* * Create glyph container. */ - if ((error = TT_New_Glyph(face, &glyph))) +#if 0 + if ((error = FT_New_Glyph(face, &glyph))) oops("Cannot create glyph container (error code = 0x%x).", error); +#endif - fnt->units_per_em = properties.header->Units_Per_EM; + fnt->units_per_em = face->units_per_EM; + + /* fnt->fixedpitch = properties.postscript->isFixedPitch; fnt->italicangle = properties.postscript->italicAngle / 65536.0; fnt->xheight = properties.os2->sxHeight * 1000 / fnt->units_per_em; + */ + fnt->fixedpitch = FT_IS_FIXED_WIDTH(face); + fnt->italicangle = 0.0; + fnt->xheight = face->height * 1000 / fnt->units_per_em; if (fnt->PSnames != Only) { - num_cmap = properties.num_CharMaps; + num_cmap = face->num_charmaps; for (i = 0; i < num_cmap; i++) { - if ((error = TT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc))) + cmap_plat=face->charmaps[i]->platform_id; + cmap_enc=face->charmaps[i]->encoding_id; +#if 0 + if ((error = FT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc))) oops("Cannot query cmap (error code = 0x%x).", error); +#endif if (cmap_plat == fnt->pid && cmap_enc == fnt->eid) break; } @@ -282,21 +322,24 @@ fprintf(stderr, " Valid PID/EID pairs are:\n"); for (i = 0; i < num_cmap; i++) { - TT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc); + cmap_plat=face->charmaps[i]->platform_id; + cmap_enc=face->charmaps[i]->encoding_id; + /*FT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc);*/ fprintf(stderr, " (%i,%i)\n", cmap_plat, cmap_enc); } fprintf(stderr, "\n"); exit(1); } - if ((error = TT_Get_CharMap(face, i, &char_map))) +/* if ((error = FT_Get_CharMap(face, i, &char_map)))*/ + if ((error = FT_Set_Charmap(face, face->charmaps[i]))) oops("Cannot load cmap (error code = 0x%x).", error); } if (fnt->PSnames) { - if ((error = TT_Load_PS_Names(face, &post))) - oops("Cannot load TrueType PS names (error code = 0x%x).", error); + if (!FT_HAS_GLYPH_NAMES(face)) + oops("Cannot load PS names."); } else if (cmap_plat == Microsoft_platform && cmap_enc == Microsoft_Unicode_encoding) @@ -307,14 +350,15 @@ else set_encoding_scheme(encFontSpecific, fnt); +#if 0 if (fnt->rotate) { gsub = &gsub_; - error = TT_Load_GSUB_Table(face, gsub, NULL); + error = FT_Load_GSUB_Table(face, gsub, NULL); if (!error) has_gsub = True; - else if (error != TT_Err_Table_Missing) + else if (error != FT_Err_Table_Missing) warning("Cannot load GSUB table (error code = 0x%x).", error); else warning("No GSUB data available " @@ -322,26 +366,26 @@ /* we check for the `vert' feature in Chinese, Japanese, and Korean */ - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_kana, &script_index); if (error) goto check_hani; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_JAN, script_index, &language_index, &req_feature_index); if (error) goto check_hani; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -355,26 +399,26 @@ goto Done; check_hani: - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_hani, &script_index); if (error) goto check_hang; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_CHN, script_index, &language_index, &req_feature_index); if (error) goto check_hang; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -388,26 +432,26 @@ goto Done; check_hang: - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_hang, &script_index); if (error) goto Done; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_KOR, script_index, &language_index, &req_feature_index); if (error) goto Done; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -422,8 +466,8 @@ } if (req_feature_index != 0xFFFF) - TT_GSUB_Add_Feature(gsub, req_feature_index, ALL_GLYPHS); - TT_GSUB_Add_Feature(gsub, feature_index, ALL_GLYPHS); + FT_GSUB_Add_Feature(gsub, req_feature_index, ALL_GLYPHS); + FT_GSUB_Add_Feature(gsub, feature_index, ALL_GLYPHS); in.length = 1; in.pos = 0; @@ -435,6 +479,7 @@ out.string = NULL; out.properties = NULL; } +#endif initialized = True; } @@ -472,13 +517,14 @@ j = 0; if (fnt->PSnames == Only) - max_k = properties.num_Glyphs - 1; + max_k = face->num_glyphs - 1; else max_k = only_range ? 0xFF : 0x16FFFF; for (k = 0; k <= max_k; k++) { - char *an; + char buff[128]; + char *an=buff; if (fnt->PSnames != Only) @@ -493,20 +539,23 @@ else index = k; - Num = TT_Char_Index(char_map, index); + /*Num = FT_Char_Index(char_map, index);*/ + Num = FT_Get_Char_Index(face, index); /* now we try to get a vertical glyph form */ +#if 0 if (has_gsub) { in_string[0] = Num; - error = TT_GSUB_Apply_String(gsub, &in, &out); + error = FT_GSUB_Apply_String(gsub, &in, &out); if (error && error != TTO_Err_Not_Covered) warning("Cannot get the vertical glyph form for glyph index %d.", Num); else Num = out.string[0]; } +#endif if (Num < 0) oops("Failure on cmap mapping from %s.", fnt->ttfname); @@ -522,25 +571,28 @@ index = 0; } - error = TT_Load_Glyph(instance, glyph, Num, 0); +/* error = FT_Load_Glyph(instance, glyph, Num, 0);*/ + error = FT_Load_Glyph(face, Num, flags); +#if 0 if (!error) - error = TT_Get_Glyph_Big_Metrics(glyph, &metrics); + error = FT_Get_Glyph_Big_Metrics(glyph, &metrics); if (!error) - error = TT_Get_Glyph_Outline(glyph, &outline); + error = FT_Get_Glyph_Outline(glyph, &outline); +#endif if (!error) { if (fnt->efactor != 1.0 || fnt->slant != 0.0 ) - TT_Transform_Outline(&outline, &matrix1); + FT_Outline_Transform(&face->glyph->outline, &matrix1); if (fnt->rotate) - TT_Transform_Outline(&outline, &matrix2); + FT_Outline_Transform(&face->glyph->outline, &matrix2); } if (!error) - error = TT_Get_Outline_BBox(&outline, &bbox); /* we need the non- + error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non- grid-fitted bbox */ if (!error) { if (fnt->PSnames) - (void)TT_Get_PS_Name(face, Num, &an); + (void)FT_Get_Glyph_Name(face, Num, &an,128); else an = code_to_adobename(index); @@ -571,10 +623,10 @@ if (fnt->rotate) { - ti->llx += (metrics.vertBearingY - bbox.xMin) * + ti->llx += (face->glyph->metrics.vertBearingY - bbox.xMin) * 1000 / fnt->units_per_em; ti->lly -= 1000 * fnt->y_offset; - ti->urx += (metrics.vertBearingY - bbox.xMin) * + ti->urx += (face->glyph->metrics.vertBearingY - bbox.xMin) * 1000 / fnt->units_per_em; ti->ury -= 1000 * fnt->y_offset; } @@ -589,9 +641,9 @@ if (ti->ury < 0) ti->ury = 0; if (fnt->rotate) - ti->width = metrics.vertAdvance * 1000 / fnt->units_per_em; + ti->width = face->glyph->metrics.vertAdvance * 1000 / fnt->units_per_em; else - ti->width = transform(metrics.horiAdvance * 1000 / fnt->units_per_em, + ti->width = transform(face->glyph->metrics.horiAdvance * 1000 / fnt->units_per_em, 0, fnt->efactor, fnt->slant); if (!quiet) @@ -617,20 +669,22 @@ if (!only_range && !fnt->PSnames) { - for (i = 1; i <= properties.num_Glyphs; i++) + for (i = 1; i <= face->num_glyphs; i++) { char *an; if (index_array[i] == 0) { - error = TT_Load_Glyph(instance, glyph, i, 0); + error = FT_Load_Glyph(face, i, flags); +#if 0 if (!error) - error = TT_Get_Glyph_Big_Metrics(glyph, &metrics); + error = FT_Get_Glyph_Big_Metrics(glyph, &metrics); if (!error) - error = TT_Get_Glyph_Outline(glyph, &outline); + error = FT_Get_Glyph_Outline(glyph, &outline); if (!error) - error = TT_Get_Outline_BBox(&outline, &bbox); + error = FT_Get_Outline_BBox(&outline, &bbox); +#endif if (!error) { an = code_to_adobename(i | 0x1000000); @@ -648,7 +702,7 @@ ti->lly = 0; if (ti->ury < 0) ti->ury = 0; - ti->width = transform(metrics.horiAdvance*1000 / fnt->units_per_em, + ti->width = transform(face->glyph->metrics.horiAdvance*1000 / fnt->units_per_em, 0, fnt->efactor, fnt->slant); if (!quiet) @@ -681,8 +735,8 @@ ti = newchar(fnt); - ti->charcode = properties.num_Glyphs | 0x1000000; - ti->glyphindex = properties.num_Glyphs; + ti->charcode = face->num_glyphs | 0x1000000; + ti->glyphindex = face->num_glyphs; ti->adobename = "Germandbls"; ti->width = Ti->width << 1; ti->llx = Ti->llx; @@ -701,7 +755,7 @@ ti->constructed = True; if (!quiet) - printf("* %-25s %5d % 5d,% 5d -- % 5d,% 5d\n", + printf("* %-25s %5d % 5d,% 5d -- % 5d,% 5d\n", ti->adobename, ti->width, ti->llx, ti->lly, ti->urx, ti->ury); @@ -709,8 +763,10 @@ } /* kerning between subfonts isn't available */ +#if 0 if (!only_range) readttf_kern(fnt); +#endif } diff -uNr ttf2pk-1.5_CVS20051222.003/ttflib.c ttf2pk-1.5_CVS20051222.004/ttflib.c --- ttf2pk-1.5_CVS20051222.003/ttflib.c 2005-12-22 17:25:22.000000000 +0900 +++ ttf2pk-1.5_CVS20051222.004/ttflib.c 2005-12-19 05:08:27.000000000 +0900 @@ -15,15 +15,22 @@ #include #include "pklib.h" /* for the `byte' type */ -#include "freetype.h" +#include +#include FT_FREETYPE_H +#include FT_OUTLINE_H +#include FT_GLYPH_H +#include FT_TYPE1_TABLES_H +#include FT_BBOX_H #include "ttfenc.h" #include "ttflib.h" #include "errormsg.h" #include "newobj.h" #include "ttf2tfm.h" -#include "ftxpost.h" -#include "ftxopen.h" +#if 0 +#include "extend/ftxpost.h" +#include "extend/ftxopen.h" +#endif #define Macintosh_platform 1 @@ -33,30 +40,31 @@ #define Microsoft_Symbol_encoding 0 #define Microsoft_Unicode_encoding 1 -#define SCRIPT_kana MAKE_TT_TAG('k', 'a', 'n', 'a') -#define SCRIPT_hani MAKE_TT_TAG('h', 'a', 'n', 'i') -#define SCRIPT_hang MAKE_TT_TAG('h', 'a', 'n', 'g') +#define SCRIPT_kana MAKE_FT_TAG('k', 'a', 'n', 'a') +#define SCRIPT_hani MAKE_FT_TAG('h', 'a', 'n', 'i') +#define SCRIPT_hang MAKE_FT_TAG('h', 'a', 'n', 'g') -#define LANGUAGE_JAN MAKE_TT_TAG('J', 'A', 'N', ' ') -#define LANGUAGE_CHN MAKE_TT_TAG('C', 'H', 'N', ' ') -#define LANGUAGE_KOR MAKE_TT_TAG('K', 'O', 'R', ' ') +#define LANGUAGE_JAN MAKE_FT_TAG('J', 'A', 'N', ' ') +#define LANGUAGE_CHN MAKE_FT_TAG('C', 'H', 'N', ' ') +#define LANGUAGE_KOR MAKE_FT_TAG('K', 'O', 'R', ' ') -#define FEATURE_vert MAKE_TT_TAG('v', 'e', 'r', 't') +#define FEATURE_vert MAKE_FT_TAG('v', 'e', 'r', 't') -TT_Engine engine; -TT_Face face; -TT_Instance instance; -TT_Glyph glyph; -TT_CharMap char_map; +FT_Library engine; +FT_Face face; +/*FT_Instance instance;*/ +FT_GlyphSlot glyph; +FT_CharMap char_map; -TT_Outline outline; -TT_Face_Properties properties; -TT_BBox bbox; +/*FT_Outline outline;*/ +/*FT_Glyph outline;*/ +/*FT_Face_Properties properties;*/ +FT_BBox bbox; -TT_Post post; +/*FT_Post post;*/ -TT_Raster_Map Bit, Bit2; +FT_Bitmap Bit, Bit2; void *Bitp, *Bit2p; int dpi; @@ -65,15 +73,15 @@ int x_offset, y_offset; int ppem; -TT_Big_Glyph_Metrics metrics; +/*FT_Big_Glyph_Metrics face;*/ -TT_Matrix matrix1, matrix2; +FT_Matrix matrix1, matrix2; -TTO_GSUBHeader gsub_; -TTO_GSUBHeader *gsub; +/*OTL_GSUBHeader gsub_;*/ +/*OTL_GSUBHeader *gsub;*/ -TT_UShort in_string[2]; -TTO_GSUB_String in, out; +FT_UShort in_string[2]; +/*OTL_GSUB_String in, out;*/ Boolean has_gsub; @@ -106,9 +114,9 @@ Bit.rows = temp2_y - temp1_y + 10; Bit.width = temp2_x - temp1_x + 10; - Bit.cols = (Bit.width + 7) / 8; /* convert to # of bytes */ - Bit.flow = TT_Flow_Up; - Bit.size = Bit.rows * Bit.cols; /* number of bytes in buffer */ + Bit.pitch = (Bit.width + 7) / 8; /* convert to # of bytes */ +/* Bit.flow = FT_Flow_Up;*/ +/* Bit.size = Bit.rows * Bit.pitch;*/ /* number of bytes in buffer */ /* * We allocate one more row to have valid pointers for comparison @@ -117,40 +125,58 @@ if (Bitp) free(Bitp); - Bitp = mymalloc(Bit.size + Bit.cols); - Bit.bitmap = Bitp; + Bitp = mymalloc(Bit.rows*Bit.pitch + Bit.pitch); + Bit.buffer = Bitp; Bit2 = Bit; if (Bit2p) free(Bit2p); - Bit2p = mymalloc(Bit.size + Bit.cols); - Bit2.bitmap = Bit2p; + Bit2p = mymalloc(Bit.rows*Bit.pitch + Bit.pitch); + Bit2.buffer = Bit2p; } - +#if 0 static void FlipBit(void) { int y; char *p1, *p2; - p1 = (char *)Bit.bitmap; - p2 = (char *)Bit2.bitmap + Bit2.cols * (Bit2.rows - 1); + p1 = (char *)Bit.buffer; + p2 = (char *)Bit2.buffer + Bit2.pitch * (Bit2.rows - 1); for (y = 0; y < Bit.rows; y++) { - memcpy(p2, p1, Bit.cols); - p1 += Bit.cols; - p2 -= Bit.cols; + memcpy(p2, p1, Bit.pitch); + p1 += Bit.pitch; + p2 -= Bit.pitch; } } +#endif + +static void +CopyBit(FT_Bitmap *b2,FT_Bitmap *b1) +{ + int y; + char *p1, *p2; + + p1 = (char *)b1->buffer; /* source */ + p2 = (char *)b2->buffer; /* dest */ + + for (y = 0; y < b1->rows; y++) + { + memcpy(p2, p1, b1->pitch); + p1 += b1->pitch; + p2 += b2->pitch; + } +} #if 0 static void -Output(TT_Raster_Map Bit) +Output(FT_Bitmap Bit) { int x; int y; @@ -159,13 +185,13 @@ char *p, b; - p = Bit.bitmap; + p = Bit.buffer; printf("====\n"); for (y = 0; y < Bit.rows; y++) { printf("%3d:", y); - for (x = 0; x < Bit.cols; x++) + for (x = 0; x < Bit.pitch; x++) { b = *p++; for(i = 0x80; i; i >>= 1) @@ -182,73 +208,74 @@ TTFopen(char *filename, Font *fnt, int new_dpi, int new_ptsize, Boolean quiet) { unsigned short i, num_cmap; - unsigned short cmap_plat; - unsigned short cmap_enc; - TT_Error error; - - TT_UShort script_index, language_index, feature_index; - TT_UShort req_feature_index = 0xFFFF; + unsigned short cmap_plat=0; + unsigned short cmap_enc=0; + FT_Error error; +#if 0 + FT_UShort script_index, language_index, feature_index; + FT_UShort req_feature_index = 0xFFFF; +#endif dpi = new_dpi; ptsize = new_ptsize; - if ((error = TT_Init_FreeType(&engine))) + if ((error = FT_Init_FreeType(&engine))) oops("Cannot initialize FreeType engine (error code = 0x%x).", error); +#if 0 if (fnt->PSnames) - if ((error = TT_Init_Post_Extension(engine))) + if ((error = FT_Init_Post_Extension(engine))) oops("Cannot initialize PS name support (error code = 0x%x).", error); if (fnt->rotate) - if ((error = TT_Init_GSUB_Extension(engine))) + if ((error = FT_Init_GSUB_Extension(engine))) oops("Cannot initialize GSUB support (error code = 0x%x).", error); +#endif - /* - * Load face. - */ - - error = TT_Open_Face(engine, filename, &face); - if (error) - oops("Cannot open `%s'.", filename); - - /* - * Get face properties and allocate preloaded arrays. - */ - - TT_Get_Face_Properties(face, &properties); - - /* - * Now we try to open the proper font in a collection. - */ - + error = FT_New_Face(engine, filename, 0,&face); + if (error) + oops("Cannot open `%s'.", filename); if (fnt->fontindex != 0) { - if (properties.num_Faces == 1) + if (face->num_faces == 1) warning("This isn't a TrueType collection.\n" "Parameter `Fontindex' is ignored."); else { - TT_Close_Face(face); - if ((error = TT_Open_Collection(engine, filename, + /* + * Load face. + */ +#if 0 + FT_Close_Face(face); + if ((error = FT_Open_Collection(engine, filename, fnt->fontindex, &face))) oops("Cannot open font %lu in TrueType Collection `%s'.", fnt->fontindex, filename); +#endif } } +#if 0 + error= FT_Has_PS_Glyph_Names(face); + if (error) + if (!FT_HAS_GLYPH_NAMES(face)) + oops("This font does not support PS name (error code = 0x%x).", error); /* * Create instance. */ - if ((error = TT_New_Instance(face, &instance))) + if ((error = FT_New_Instance(face, &instance))) oops("Cannot create instance for `%s' (error code = 0x%x).", filename, error); - if ((error = TT_Set_Instance_Resolutions(instance, dpi, dpi))) + if ((error = FT_Set_Instance_Resolutions(instance, dpi, dpi))) oops("Cannot set device resolutions (error code = 0x%x)."); - if ((error = TT_Set_Instance_CharSize(instance, ptsize * 64))) + if ((error = FT_Set_Instance_CharSize(instance, ptsize * 64))) + oops("Cannot set character size (error code = 0x%x).", error); +#endif + if ((error = FT_Set_Char_Size(face, ptsize * 64, ptsize * 64, dpi,dpi))) oops("Cannot set character size (error code = 0x%x).", error); ppem = (dpi * ptsize + 36) / 72; @@ -256,10 +283,10 @@ if (!quiet) printf("dpi = %d, ptsize = %d, ppem = %d\n\n", dpi, ptsize, ppem); - matrix1.xx = (TT_Fixed)(floor(fnt->efactor * 1024) * (1<<16)/1024); - matrix1.xy = (TT_Fixed)(floor(fnt->slant * 1024) * (1<<16)/1024); - matrix1.yx = (TT_Fixed)0; - matrix1.yy = (TT_Fixed)(1<<16); + matrix1.xx = (FT_Fixed)(floor(fnt->efactor * 1024) * (1<<16)/1024); + matrix1.xy = (FT_Fixed)(floor(fnt->slant * 1024) * (1<<16)/1024); + matrix1.yx = (FT_Fixed)0; + matrix1.yy = (FT_Fixed)(1<<16); if (fnt->rotate) { @@ -269,42 +296,52 @@ matrix2.yy = matrix2.xx; } - if ((error = TT_Set_Instance_Transform_Flags( +#if 0 + if ((error = FT_Set_Instance_Transform_Flags( instance, fnt->rotate ? 1 : 0, fnt->efactor != 1.0 ? 1 : 0))) oops("Cannot set transform flags (error code = 0x%x).", error); +#endif /* * Create glyph container. */ - if ((error = TT_New_Glyph(face, &glyph))) +#if 0 + if ((error = FT_New_Glyph(face, &glyph))) oops("Cannot create glyph container (error code = 0x%x)."); +#endif if (fnt->PSnames != Only) { - num_cmap = properties.num_CharMaps; + num_cmap = face->num_charmaps; for (i = 0; i < num_cmap; i++) { - if ((error = TT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc))) + cmap_plat=face->charmaps[i]->platform_id; + cmap_enc=face->charmaps[i]->encoding_id; +#if 0 + if ((error = FT_Get_CharMap_ID(face, i, &cmap_plat, &cmap_enc))) oops("Cannot query cmap (error code = 0x%x).", error); +#endif if (cmap_plat == fnt->pid && cmap_enc == fnt->eid) break; } if (i == num_cmap) oops("Invalid platform and/or encoding ID."); - if ((error = TT_Get_CharMap(face, i, &char_map))) + if ((error = FT_Set_Charmap(face, face->charmaps[i]))) oops("Cannot load cmap (error code = 0x%x).", error); } +#if 0 if (fnt->PSnames) { - if ((error = TT_Load_PS_Names(face, &post))) + if ((error = FT_Load_PS_Names(face, &post))) oops("Cannot load TrueType PS names (error code = 0x%x).", error); } - else if (cmap_plat == Microsoft_platform && +#endif + if (cmap_plat == Microsoft_platform && cmap_enc == Microsoft_Unicode_encoding) set_encoding_scheme(encUnicode, fnt); else if (cmap_plat == Macintosh_platform && @@ -313,14 +350,15 @@ else set_encoding_scheme(encFontSpecific, fnt); +#ifdef FREETYPE1 if (fnt->rotate) { gsub = &gsub_; - error = TT_Load_GSUB_Table(face, gsub, NULL); + error = FT_Load_GSUB_Table(face, gsub, NULL); if (!error) has_gsub = True; - else if (error != TT_Err_Table_Missing) + else if (error != FT_Err_Table_Missing) warning("Cannot load GSUB table (error code = 0x%x).", error); else warning("No GSUB data available " @@ -328,26 +366,26 @@ /* we check for the `vert' feature in Chinese, Japanese, and Korean */ - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_kana, &script_index); if (error) goto check_hani; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_JAN, script_index, &language_index, &req_feature_index); if (error) goto check_hani; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -361,26 +399,26 @@ goto Done; check_hani: - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_hani, &script_index); if (error) goto check_hang; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_CHN, script_index, &language_index, &req_feature_index); if (error) goto check_hang; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -394,26 +432,26 @@ goto Done; check_hang: - error = TT_GSUB_Select_Script(gsub, + error = FT_GSUB_Select_Script(gsub, SCRIPT_hang, &script_index); if (error) goto Done; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, 0xFFFF, &feature_index); if (error) { - error = TT_GSUB_Select_Language(gsub, + error = FT_GSUB_Select_Language(gsub, LANGUAGE_KOR, script_index, &language_index, &req_feature_index); if (error) goto Done; - error = TT_GSUB_Select_Feature(gsub, + error = FT_GSUB_Select_Feature(gsub, FEATURE_vert, script_index, language_index, @@ -428,8 +466,8 @@ } if (req_feature_index != 0xFFFF) - TT_GSUB_Add_Feature(gsub, req_feature_index, ALL_GLYPHS); - TT_GSUB_Add_Feature(gsub, feature_index, ALL_GLYPHS); + FT_GSUB_Add_Feature(gsub, req_feature_index, ALL_GLYPHS); + FT_GSUB_Add_Feature(gsub, feature_index, ALL_GLYPHS); in.length = 1; in.pos = 0; @@ -441,46 +479,55 @@ out.string = NULL; out.properties = NULL; } +#endif /* FREETYPE1*/ } -static TT_Error +static FT_Error LoadTrueTypeChar(Font *fnt, int idx, Boolean hint, Boolean quiet) { - TT_Error error; + FT_Error error; int flags; - flags = TTLOAD_SCALE_GLYPH; +/* flags = FT_LOAD_SCALE_GLYPH;*/ + flags = FT_LOAD_DEFAULT; if (hint) - flags |= TTLOAD_HINT_GLYPH; + flags |= FT_LOAD_FORCE_AUTOHINT; - error = TT_Load_Glyph(instance, glyph, idx, flags); - if (!error) - error = TT_Get_Glyph_Big_Metrics(glyph, &metrics); - if (!error) - error = TT_Get_Glyph_Outline(glyph, &outline); + //error = FT_Load_Glyph(instance, glyph, idx, flags); + error = FT_Load_Glyph(face, idx, flags); +// if (!error) +// error = FT_Get_Glyph_Big_Metrics(glyph, &metrics); +// if (!error) +// error = FT_Get_Glyph_Outline(glyph, &outline); +// error = FT_Get_Glyph(glyph, &outline); +// error = FT_Get_Glyph(face->glyph, &glyph); if (!error) { if (fnt->efactor != 1.0 || fnt->slant != 0.0 ) - TT_Transform_Outline(&outline, &matrix1); +// FT_Transform_Outline(&outline, &matrix1); + FT_Outline_Transform(&face->glyph->outline, &matrix1); if (fnt->rotate) - TT_Transform_Outline(&outline, &matrix2); + FT_Outline_Transform(&face->glyph->outline, &matrix2); } if (!error) - error = TT_Get_Outline_BBox(&outline, &bbox); /* we need the non- + error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non- grid-fitted bbox */ if (fnt->rotate) - TT_Translate_Outline(&outline, - metrics.vertBearingY - bbox.xMin, + FT_Outline_Translate(&face->glyph->outline, + face->glyph->metrics.vertBearingY - bbox.xMin, -fnt->y_offset * ppem * 64); if (!error) - error = TT_Get_Outline_BBox(&outline, &bbox); - if (!error) + error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); + if (!error) { + FT_Outline_Get_CBox(&face->glyph->outline, &bbox); + /* for the case of BBox != CBox */ SetRasterArea(quiet); + } return error; } @@ -495,7 +542,7 @@ Boolean quiet) { int Num; - TT_Error error; + FT_Error error; if (!bitmap || !width || !height || !hoff || !voff) @@ -505,30 +552,55 @@ Num = Code & 0xFFFFFF; else { - Num = TT_Char_Index(char_map, Code); +// Num = FT_Char_Index(char_map, Code); + Num = FT_Get_Char_Index(face, Code); +#if 0 if (has_gsub) { in_string[0] = Num; - error = TT_GSUB_Apply_String(gsub, &in, &out); - if (error && error != TTO_Err_Not_Covered) + error = FT_GSUB_Apply_String(gsub, &in, &out); + if (error && error != OTL_Err_Not_Covered) warning("Cannot get the vertical glyph form for glyph index %d.", Num); else Num = out.string[0]; } +#endif } - if ((error = LoadTrueTypeChar(fnt, Num, hinting, quiet)) == TT_Err_Ok) + if ((error = LoadTrueTypeChar(fnt, Num, hinting, quiet)) == FT_Err_Ok) { - memset(Bit.bitmap, 0, Bit.size); - TT_Get_Glyph_Bitmap(glyph, &Bit, x_offset * 64, y_offset * 64); + memset(Bit.buffer, 0, Bit.rows*Bit.pitch); + //FT_Get_Glyph_Bitmap(glyph, &Bit, x_offset * 64, y_offset * 64); + //FT_Glyph_To_Bitmap(glyph, &Bit, x_offset * 64, y_offset * 64); + //error = FT_Outline_Get_Bitmap(engine,&face->glyph->outline, &Bit); + error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO); + if (error) { + warning("Cannot Render to Bitmap"); + return False; + } + + //fprintf(stderr,"(%d,%d) ->",Bit.width,Bit.rows); + //fprintf(stderr," (%d,%d)\n",face->glyph->bitmap.width,face->glyph->bitmap.rows); + CopyBit(&Bit, &face->glyph->bitmap); +#if 0 FlipBit(); - *bitmap = Bit2.bitmap; + *bitmap = Bit2.buffer; *width = Bit2.width; *height = Bit2.rows; +#else + *bitmap = Bit.buffer; + *width = Bit.width; + *height = Bit.rows; +#endif +#if 1 *hoff = x_offset; *voff = y_offset; +#else + *hoff = face->glyph->bitmap_left; + *voff = face->glyph->bitmap_top; +#endif /* *voff = Bit2.rows - y_offset; */ /* printf("%D %d\n", *hoff, *voff); */ /* Output(Bit2); */ @@ -552,9 +624,10 @@ encoding * TTFget_first_glyphs(Font *fnt, long *array) { - unsigned int i, j, Num; + unsigned int i, j, Num=0; unsigned int index_array[257]; /* we ignore glyph index 0 */ - char *n; + char buff[128]; + char *n=buff; encoding *e = (encoding *)mymalloc(sizeof (encoding)); @@ -569,7 +642,8 @@ { for (i = 0; i <= 0x16FFFF; i++) { - Num = TT_Char_Index(char_map, i); + Num = FT_Get_Char_Index(face, i); + // Num = FT_Char_Index(char_map, i); if (Num < 0) oops("cmap mapping failure."); if (Num == 0) @@ -578,7 +652,8 @@ index_array[Num] = 1; if (fnt->PSnames) - (void)TT_Get_PS_Name(face, Num, &n); + (void)FT_Get_Glyph_Name(face,Num,n,128); +// (void)FT_Get_PS_Name(face, Num, &n); else n = code_to_adobename(i); if (strcmp(n, ".notdef") == 0) @@ -600,7 +675,7 @@ if (!fnt->PSnames) { - for (i = 1; i < properties.num_Glyphs; i++) + for (i = 1; i < face->num_glyphs; i++) { if (index_array[i] == 0) { @@ -618,12 +693,14 @@ } else { - for (i = 0; i < properties.num_Glyphs; i++) + for (i = 0; i < face->num_glyphs; i++) { - char *n; + char buff[128]; + char *n=buff; - (void)TT_Get_PS_Name(face, i, &n); +// (void)FT_Get_PS_Name(face, i, &n); + (void)FT_Get_Glyph_Name(face,Num,n,128); if (strcmp(n, ".notdef") == 0) continue; @@ -669,7 +746,8 @@ array[i] = j; else { - Num = TT_Char_Index(char_map, j); + //Num = FT_Char_Index(char_map, j); + Num = FT_Get_Char_Index(face, j); if (Num < 0) oops("cmap mapping failure."); else @@ -683,17 +761,19 @@ TTFsearch_PS_name(char *name) { unsigned int i; - char *n; + char buff[128]; + char *n=buff; - for (i = 0; i < properties.num_Glyphs; i++) + for (i = 0; i < face->num_glyphs; i++) { - TT_Get_PS_Name(face, i, &n); + FT_Get_Glyph_Name(face, i, n,128); + //FT_Get_PS_Name(face, i, &n); if (strcmp(name, n) == 0) break; } - if (i == properties.num_Glyphs) + if (i == face->num_glyphs) return -1L; else return (long)i;