diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2012-09-18 17:56:42 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2012-09-18 17:56:42 +0000 |
commit | bcf4f5c089878ad822ed4073e7de63b12344b978 (patch) | |
tree | 7947195be8a18a343b2b238bd4d6b758203dc17a /Build | |
parent | e3167f2329da4174fd1332e069788693de96b72a (diff) |
ttf2pk: Adapt to W32TeX (from Akira)
Start handling the GSUB table
Extend the test to cover vert feature from GSUB table
git-svn-id: svn://tug.org/texlive/trunk@27716 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
21 files changed, 837 insertions, 805 deletions
diff --git a/Build/source/texk/ttf2pk2/ChangeLog b/Build/source/texk/ttf2pk2/ChangeLog index 840cd0bb0ac..f0dfe1b50f6 100644 --- a/Build/source/texk/ttf2pk2/ChangeLog +++ b/Build/source/texk/ttf2pk2/ChangeLog @@ -1,3 +1,39 @@ +2012-09-16 Peter Breitenlohner <peb@mppmu.mpg.de> + + * tests/ttf2pk.cfg, tests/ttf2pk.test: Extend the test to cover + vertical glyph presentation forms from GSUB table. + * tests/Test.sfd, tests/ipaexg.ttf, tests/ipaexg-[vh].map: + Additional test input. + * Makefile.am (EXTRA_DIST, DISTCLEANFILES): Adapted. + +2012-09-14 Peter Breitenlohner <peb@mppmu.mpg.de> + + * ttflib.c (SetRasterArea, LoadTrueTypeChar, TTFprocess): + Handle bitmap and bounding box. + +2012-09-11 Peter Breitenlohner <peb@mppmu.mpg.de> + + Factor out common parts of freetype2 handling into + separate files ftlib.c and ftlib.h. + * ttflib.c, ttfaux.c: Moved code from here ... + * ftlib.c, ftlib.h: ... to these new files. + * Makefile.am (common_sources): Add the new files. + +2012-09-09 Peter Breitenlohner <peb@mppmu.mpg.de> + + Revert parts of ttf2pk.diff.bz2 from ???. + * ligkern.c (checkligkern): This was obviously wrong. + * newobj.c (init_font_structure), ttf2tfm.c (main): Most of this was + never applied for W32TeX. + * ttfaux.c (readttf): Obtain font xheight from OS/2 table. + +2012-09-07 Peter Breitenlohner <peb@mppmu.mpg.de> + + * newobj.c, subfont.c, tfmaux.c, ttf2tfm.[ch], ttfaux.c, + vplaux.[ch]: Apply ttf2pk-1.5-20020430.patch from + http://ftp.ktug.or.kr/pub/ktug/freetype/contrib/ as already done + long ago for W32TeX. + 2012-07-18 Peter Breitenlohner <peb@mppmu.mpg.de> * tfmaux.c, ttf2tfm.c: Use binary mode for output files. diff --git a/Build/source/texk/ttf2pk2/Makefile.am b/Build/source/texk/ttf2pk2/Makefile.am index e3d00fa9692..fe7a373c6d4 100644 --- a/Build/source/texk/ttf2pk2/Makefile.am +++ b/Build/source/texk/ttf2pk2/Makefile.am @@ -1,6 +1,6 @@ ## Makefile.am for the TeX Live subdirectory texk/ttf2pk2/ ## -## Copyright (C) 2011 Peter Breitenlohner <tex-live@tug.org> +## Copyright (C) 2011, 2012 Peter Breitenlohner <tex-live@tug.org> ## You may freely use, modify and/or distribute this file. ## ACLOCAL_AMFLAGS = -I ../../m4 @@ -16,6 +16,8 @@ common_sources = \ errormsg.h \ filesrch.c \ filesrch.h \ + ftlib.c \ + ftlib.h \ ligkern.c \ ligkern.h \ newobj.c \ @@ -100,8 +102,9 @@ TESTS = tests/ttf2pk.test EXTRA_DIST = $(TESTS) ## tests/ttf2pk.test EXTRA_DIST += tests/GenR102.ttf tests/gentium-ec.enc tests/ttf2pk.cfg \ - tests/GenR102-ec.map tests/GenR102-h.map tests/GenR102-v.map -DISTCLEANFILES += GenR-ec.vpl GenR102-* + tests/GenR102-ec.map tests/GenR102-h.map tests/GenR102-v.map \ + tests/Test.sfd tests/ipaexg.ttf tests/ipaexg-h.map tests/ipaexg-v.map +DISTCLEANFILES += GenR-ec.vpl GenR102-* ipaexg-* ## Not used ## diff --git a/Build/source/texk/ttf2pk2/Makefile.in b/Build/source/texk/ttf2pk2/Makefile.in index 755337b2d66..b1d54c4a828 100644 --- a/Build/source/texk/ttf2pk2/Makefile.in +++ b/Build/source/texk/ttf2pk2/Makefile.in @@ -92,7 +92,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" \ "$(DESTDIR)$(cfgdatadir)" "$(DESTDIR)$(encdatadir)" \ "$(DESTDIR)$(mapdatadir)" "$(DESTDIR)$(sfddatadir)" PROGRAMS = $(bin_PROGRAMS) -am__objects_1 = errormsg.$(OBJEXT) filesrch.$(OBJEXT) \ +am__objects_1 = errormsg.$(OBJEXT) filesrch.$(OBJEXT) ftlib.$(OBJEXT) \ ligkern.$(OBJEXT) newobj.$(OBJEXT) parse.$(OBJEXT) \ subfont.$(OBJEXT) texenc.$(OBJEXT) ttfenc.$(OBJEXT) am_ttf2pk_OBJECTS = $(am__objects_1) pklib.$(OBJEXT) ttf2pk.$(OBJEXT) \ @@ -320,6 +320,8 @@ common_sources = \ errormsg.h \ filesrch.c \ filesrch.h \ + ftlib.c \ + ftlib.h \ ligkern.c \ ligkern.h \ newobj.c \ @@ -354,7 +356,7 @@ ttf2tfm_SOURCES = \ vplaux.c \ vplaux.h -DISTCLEANFILES = config.force GenR-ec.vpl GenR102-* +DISTCLEANFILES = config.force GenR-ec.vpl GenR102-* ipaexg-* LDADD = $(KPATHSEA_LIBS) $(FREETYPE2_LIBS) $(ZLIB_LIBS) dist_man1_MANS = ttf2pk.1 ttf2tfm.1 cfgdatadir = $(datarootdir)/texmf/ttf2pk @@ -382,8 +384,10 @@ dist_sfddata_DATA = \ TESTS = tests/ttf2pk.test EXTRA_DIST = $(TESTS) tests/GenR102.ttf tests/gentium-ec.enc \ tests/ttf2pk.cfg tests/GenR102-ec.map tests/GenR102-h.map \ - tests/GenR102-v.map BUGS MakeSub.in Makefile.dm dvidrv.btm \ - dvidrv.doc emdir.c emdir.h emtexdir.c emtexdir.h ttf2pk.doc + tests/GenR102-v.map tests/Test.sfd tests/ipaexg.ttf \ + tests/ipaexg-h.map tests/ipaexg-v.map BUGS MakeSub.in \ + Makefile.dm dvidrv.btm dvidrv.doc emdir.c emdir.h emtexdir.c \ + emtexdir.h ttf2pk.doc all: c-auto.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -500,6 +504,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/case.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errormsg.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filesrch.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftlib.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ligkern.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newobj.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@ diff --git a/Build/source/texk/ttf2pk2/ftlib.c b/Build/source/texk/ttf2pk2/ftlib.c new file mode 100644 index 00000000000..5a45d7b15ef --- /dev/null +++ b/Build/source/texk/ttf2pk2/ftlib.c @@ -0,0 +1,454 @@ +/* + * ftlib.c + * + * This file is part of the ttf2pk package. + * + * Copyright 1997-1999, 2000, 2002, 2003 by + * Frederic Loyer <loyer@ensta.fr> + * Werner Lemberg <wl@gnu.org> + * + * Copyright (C) 2012 by + * Peter Breitenlohner <tex-live@tug.org> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include <ft2build.h> +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H +#include FT_OPENTYPE_VALIDATE_H + +#include "ttf2tfm.h" +#include "ttfenc.h" +#include "errormsg.h" +#include "newobj.h" +#include "ftlib.h" + +#define Macintosh_platform 1 +#define Macintosh_encoding 0 + +#define Microsoft_platform 3 +#define Microsoft_Symbol_encoding 0 +#define Microsoft_Unicode_encoding 1 + +#define TTAG_GSUB FT_MAKE_TAG('G', 'S', 'U', 'B') + +#define SCRIPT_kana FT_MAKE_TAG('k', 'a', 'n', 'a') +#define SCRIPT_hani FT_MAKE_TAG('h', 'a', 'n', 'i') +#define SCRIPT_hang FT_MAKE_TAG('h', 'a', 'n', 'g') + +#define LANGUAGE_JAN FT_MAKE_TAG('J', 'A', 'N', ' ') +#define LANGUAGE_CHN FT_MAKE_TAG('C', 'H', 'N', ' ') +#define LANGUAGE_KOR FT_MAKE_TAG('K', 'O', 'R', ' ') + +#define FEATURE_vert FT_MAKE_TAG('v', 'e', 'r', 't') + +FT_Library engine; +FT_Face face; + +FT_Matrix matrix1, matrix2; + +int dpi, ptsize; + +Boolean has_gsub; + +TT_OS2 *os2; +TT_Postscript *postscript; + +FT_Byte *GSUB_table; +FT_ULong GSUB_length; +FT_ULong GSUB_ptr; +FT_ULong Script_List_ptr; +FT_ULong Feature_List_ptr; +FT_ULong Lookup_List_ptr; + +static inline void +need (FT_ULong needed) +{ + if (GSUB_ptr + needed > GSUB_length) + oops("GSUB: Unexpected end of table."); +} + +static inline FT_Byte +get_Byte(void) +{ + return GSUB_table[GSUB_ptr++]; +} + +static inline signed char +get_SByte(void) +{ + return (signed char) GSUB_table[GSUB_ptr++]; +} + +static FT_UShort +get_UShort(void) +{ + unsigned int cc; + cc = get_Byte() << 8; + cc |= get_Byte(); + return (FT_UShort) cc; +} + +static FT_Short +get_Short(void) +{ + int cc; + cc = get_SByte() << 8; + cc |= get_Byte(); + return (FT_Short) cc; +} + +static FT_ULong +get_ULong(void) +{ + unsigned int cc; + cc = get_Byte() << 24; + cc |= get_Byte() << 16; + cc |= get_Byte() << 8; + cc |= get_Byte(); + return (FT_ULong) cc; +} + +static FT_Long +get_Long(void) +{ + int cc; + cc = get_SByte() << 24; + cc |= get_Byte() << 16; + cc |= get_Byte() << 8; + cc |= get_Byte(); + return (FT_Long) cc; +} + +#if 0 +FT_UShort in_string[2]; + +TTO_GSUBHeader gsub_; +TTO_GSUBHeader *gsub; +TTO_GSUB_String in, out; +#endif + +void +FTopen (char *filename, Font *fnt, Boolean do_tfm, Boolean quiet) +{ + FT_Error error; + int i; + unsigned short num_cmap, cmap_plat=0, cmap_enc=0; + +#if 0 + FT_UShort script_index, language_index, feature_index; + FT_UShort req_feature_index = 0xFFFF; +#endif + + if ((error = FT_Init_FreeType(&engine))) + oops("Cannot initialize FreeType engine (error code = 0x%x).", error); + +#if 0 + if (fnt->rotate) + if ((error = FT_Init_GSUB_Extension(engine))) + oops("Cannot initialize GSUB support (error code = 0x%x).", error); +#endif + + /* + * Load face. + */ + if ((error = FT_New_Face(engine, filename, 0, &face))) + oops("Cannot open `%s'.", filename); + + if (face->num_faces == 1) + { + if (fnt->fontindex != 0) + { + warning("This isn't a TrueType collection.\n" + "Parameter `%s' is ignored.", do_tfm ? "-f" : "Fontindex"); + fnt->fontindex = 0; + } + fnt->fontindexparam = NULL; + } + else + { + if (fnt->fontindex != 0) + { + /* + * Now we try to open the proper font in a collection. + */ + FT_Done_Face(face); + if ((error = FT_New_Face(engine, filename, (FT_Long)fnt->fontindex, &face))) + oops("Cannot open font %lu in TrueType Collection `%s'.", + fnt->fontindex, filename); + } + } + + if (do_tfm) + { + /* + * Get the OS/2 table. + */ + if ((os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2)) == NULL) + oops("Cannot find OS/2 table for `%s'.", filename); + + /* + * Get the Postscript table. + */ + if ((postscript = FT_Get_Sfnt_Table(face, ft_sfnt_post)) == NULL) + oops("Cannot find Postscript table for `%s'.", filename); + } + + if ((error = FT_Set_Char_Size(face, ptsize * 64, ptsize * 64, dpi, dpi))) + oops("Cannot set character size (error code = 0x%x).", error); + + 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) + { + matrix2.xx = 0; + matrix2.yx = 1L << 16; + matrix2.xy = -matrix2.yx; + matrix2.yy = matrix2.xx; + } + + if (do_tfm) + { + fnt->units_per_em = face->units_per_EM; + fnt->fixedpitch = postscript->isFixedPitch; + fnt->italicangle = postscript->italicAngle / 65536.0; + fnt->xheight = os2->sxHeight * 1000 / fnt->units_per_em; + } + + if (fnt->PSnames != Only) + { + num_cmap = face->num_charmaps; + for (i = 0; i < num_cmap; i++) + { + cmap_plat=face->charmaps[i]->platform_id; + cmap_enc=face->charmaps[i]->encoding_id; + if (cmap_plat == fnt->pid && cmap_enc == fnt->eid) + break; + } + if (i == num_cmap) + { + fprintf(stderr, "%s: ERROR: Invalid platform and/or encoding ID.\n", + progname); + if (num_cmap == 1) + fprintf(stderr, " The only valid PID/EID pair is"); + else + fprintf(stderr, " Valid PID/EID pairs are:\n"); + for (i = 0; i < num_cmap; i++) + { + cmap_plat=face->charmaps[i]->platform_id; + cmap_enc=face->charmaps[i]->encoding_id; + fprintf(stderr, " (%i,%i)\n", cmap_plat, cmap_enc); + } + fprintf(stderr, "\n"); + exit(1); + } + + if ((error = FT_Set_Charmap(face, face->charmaps[i]))) + oops("Cannot load cmap (error code = 0x%x).", error); + } + + if (fnt->PSnames) + { + if (!FT_HAS_GLYPH_NAMES(face)) + oops("This font does not support PS names."); + } + else if (cmap_plat == Microsoft_platform && + cmap_enc == Microsoft_Unicode_encoding) + set_encoding_scheme(encUnicode, fnt); + else if (cmap_plat == Macintosh_platform && + cmap_enc == Macintosh_encoding) + set_encoding_scheme(encMac, fnt); + else + set_encoding_scheme(encFontSpecific, fnt); + + if (fnt->rotate) + { + if ((error = FT_Load_Sfnt_Table(face, TTAG_GSUB, 0, NULL, &GSUB_length))) + { + warning("No GSUB data available " + "for vertical glyph presentation forms."); + return; + } + GSUB_table = mymalloc(GSUB_length); + if ((error = FT_Load_Sfnt_Table(face, TTAG_GSUB, 0, GSUB_table, &GSUB_length))) + { + warning("Cannot load GSUB table (error code = 0x%x).", error); + return; + } + need(10); + if (get_ULong() != 0x00010000) + oops("GSUB: Bad version."); + Script_List_ptr = get_UShort(); + warning("GSUB: Script List at 0x%04x.", Script_List_ptr); + Feature_List_ptr = get_UShort(); + warning("GSUB: Feature List at 0x%04x.", Feature_List_ptr); + Lookup_List_ptr = get_UShort(); + warning("GSUB: Lookup List at 0x%04x.", Lookup_List_ptr); + GSUB_ptr = Script_List_ptr; + need(2); + { + FT_UShort Script_Count = get_UShort(); + need (6 * Script_Count); + for (i = 0; i < Script_Count; i++) + { + FT_Tag tag = get_ULong(); + FT_ULong Script_ptr = Script_List_ptr + get_UShort(); + warning("Script[%d] '%c%c%c%c' at 0x%04x.", i, + tag >> 24, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff, + Script_ptr); + } + } + has_gsub = True; +// exit(1); +#if 0 + gsub = &gsub_; + + error = FT_Load_GSUB_Table(face, gsub, NULL); + if (!error) + has_gsub = True; + else if (error != FT_Err_Table_Missing) + warning("Cannot load GSUB table (error code = 0x%x).", error); + else + warning("No GSUB data available " + "for vertical glyph presentation forms."); + + /* we check for the `vert' feature in Chinese, Japanese, and Korean */ + + error = FT_GSUB_Select_Script(gsub, + SCRIPT_kana, + &script_index); + if (error) + goto check_hani; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + 0xFFFF, + &feature_index); + if (error) + { + error = FT_GSUB_Select_Language(gsub, + LANGUAGE_JAN, + script_index, + &language_index, + &req_feature_index); + if (error) + goto check_hani; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + language_index, + &feature_index); + if (error) + goto check_hani; + else + goto Done; + } + else + goto Done; + + check_hani: + error = FT_GSUB_Select_Script(gsub, + SCRIPT_hani, + &script_index); + if (error) + goto check_hang; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + 0xFFFF, + &feature_index); + if (error) + { + error = FT_GSUB_Select_Language(gsub, + LANGUAGE_CHN, + script_index, + &language_index, + &req_feature_index); + if (error) + goto check_hang; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + language_index, + &feature_index); + if (error) + goto check_hang; + else + goto Done; + } + else + goto Done; + + check_hang: + error = FT_GSUB_Select_Script(gsub, + SCRIPT_hang, + &script_index); + if (error) + goto Done; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + 0xFFFF, + &feature_index); + if (error) + { + error = FT_GSUB_Select_Language(gsub, + LANGUAGE_KOR, + script_index, + &language_index, + &req_feature_index); + if (error) + goto Done; + error = FT_GSUB_Select_Feature(gsub, + FEATURE_vert, + script_index, + language_index, + &feature_index); + } + + Done: + if (error) + { + warning("There is no data for vertical typesetting in GSUB table."); + has_gsub = False; + } + + if (req_feature_index != 0xFFFF) + 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; + in.string = in_string; + in.properties = NULL; + + out.pos = 0; + out.allocated = 0; + out.string = NULL; + out.properties = NULL; +#endif + } +} + +int +Get_Vert (int Num) +{ + warning("GSUB: Looking for vertical form of glyph %d.", Num); +#if 0 + in_string[0] = Num; + 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 + return Num; +} diff --git a/Build/source/texk/ttf2pk2/ftlib.h b/Build/source/texk/ttf2pk2/ftlib.h new file mode 100644 index 00000000000..558c86b5bca --- /dev/null +++ b/Build/source/texk/ttf2pk2/ftlib.h @@ -0,0 +1,31 @@ +/* + * ftlib.h + * + * This file is part of the ttf2pk package. + * + * Copyright 1997-1999, 2000, 2002, 2003 by + * Frederic Loyer <loyer@ensta.fr> + * Werner Lemberg <wl@gnu.org> + * + * Copyright (C) 2012 by + * Peter Breitenlohner <tex-live@tug.org> + */ + +#ifndef FTLIB_H +#define FTLIB_H + +extern FT_Library engine; +extern FT_Face face; + +extern FT_Matrix matrix1, matrix2; + +extern int dpi, ptsize; + +extern Boolean has_gsub; + + +void FTopen(char *filename, Font *fnt, Boolean do_tfm, Boolean quiet); + +int Get_Vert(int Num); + +#endif /* FTLIB_H */ diff --git a/Build/source/texk/ttf2pk2/ligkern.c b/Build/source/texk/ttf2pk2/ligkern.c index 98f889f7c8b..68c7f4245c2 100644 --- a/Build/source/texk/ttf2pk2/ligkern.c +++ b/Build/source/texk/ttf2pk2/ligkern.c @@ -212,7 +212,7 @@ checkligkern(char *s, Font *fnt) lig *lig; - if (findadobe(mlist[2], fnt->charlist)) + if (findadobe(mlist[1], fnt->charlist)) /* remove coincident kerns */ rmkern(mlist[0], mlist[1], ti, fnt); diff --git a/Build/source/texk/ttf2pk2/newobj.c b/Build/source/texk/ttf2pk2/newobj.c index 9be49ed9c2a..3639961c8cd 100644 --- a/Build/source/texk/ttf2pk2/newobj.c +++ b/Build/source/texk/ttf2pk2/newobj.c @@ -202,6 +202,8 @@ newchar(Font *fnt) ti->dptr = 0; ti->iptr = 0; + ti->fntnum = -1; + fnt->charlist = ti; return ti; @@ -313,6 +315,10 @@ init_font_structure(Font *fnt) fnt->codingscheme = default_codingscheme; fnt->titlebuf = NULL; + fnt->cksum = 0; + fnt->subfont_num = 0; + fnt->subfont_list = NULL; + fnt->units_per_em = 0; fnt->italicangle = 0.0; fnt->fixedpitch = 0; @@ -321,7 +327,7 @@ init_font_structure(Font *fnt) fnt->pid = 3; fnt->eid = 1; - fnt->xheight = 400; + fnt->xheight = 0; fnt->fontspace = 0; fnt->y_offset = 0.25; diff --git a/Build/source/texk/ttf2pk2/subfont.c b/Build/source/texk/ttf2pk2/subfont.c index c919028dbe3..89619f11e01 100644 --- a/Build/source/texk/ttf2pk2/subfont.c +++ b/Build/source/texk/ttf2pk2/subfont.c @@ -35,7 +35,7 @@ static realsubfont *real_sfd_name = NULL, *real_lig_name = NULL; static realsubfont * really_init_sfd(char *name, Boolean fatal); static Boolean -really_get_sfd(Font *fnt, Boolean next, realsubfont *rsf); +really_get_sfd(Font *fnt, Boolean next, realsubfont *rsf, Boolean new_sfd); static void really_close_sfd(realsubfont *real_name); @@ -163,14 +163,14 @@ really_init_sfd(char *name, Boolean fatal) Boolean get_sfd(Font *fnt, Boolean is_sfd) { if (is_sfd) - return really_get_sfd(fnt, False, real_sfd_name); + return really_get_sfd(fnt, False, real_sfd_name, True); else - return really_get_sfd(fnt, False, real_lig_name); + return really_get_sfd(fnt, False, real_lig_name, False); } static Boolean -really_get_sfd(Font *fnt, Boolean next, realsubfont *rsf) +really_get_sfd(Font *fnt, Boolean next, realsubfont *rsf, Boolean new_sfd) { long i, offset; long begin, end = -1; @@ -229,7 +229,7 @@ again: if (*bufp == '\0') oops("Invalid subfont entry in `%s'.", rsf->name); - if (next) + if (next || !new_sfd) { if (strcmp(fnt->subfont_name, buffer)) goto again; @@ -309,7 +309,7 @@ again: if (!next) while ((rsf = rsf->next)) - (void)really_get_sfd(fnt, True, rsf); + (void)really_get_sfd(fnt, True, rsf, new_sfd); return True; } diff --git a/Build/source/texk/ttf2pk2/tests/Test.sfd b/Build/source/texk/ttf2pk2/tests/Test.sfd new file mode 100644 index 00000000000..fc06d999aac --- /dev/null +++ b/Build/source/texk/ttf2pk2/tests/Test.sfd @@ -0,0 +1,7 @@ +# Test.sfd +# +# GID 36->41 37 38 39 40->38 41 42 43 + +03 0x0041_0x0048 + +# eof diff --git a/Build/source/texk/ttf2pk2/tests/ipaexg-h.map b/Build/source/texk/ttf2pk2/tests/ipaexg-h.map new file mode 100644 index 00000000000..b34a19deaa3 --- /dev/null +++ b/Build/source/texk/ttf2pk2/tests/ipaexg-h.map @@ -0,0 +1 @@ +ipaexg-h@Test@ ipaexg diff --git a/Build/source/texk/ttf2pk2/tests/ipaexg-v.map b/Build/source/texk/ttf2pk2/tests/ipaexg-v.map new file mode 100644 index 00000000000..f94c427ac5b --- /dev/null +++ b/Build/source/texk/ttf2pk2/tests/ipaexg-v.map @@ -0,0 +1 @@ +ipaexg-v@Test@ ipaexg Rotate=Yes diff --git a/Build/source/texk/ttf2pk2/tests/ipaexg.ttf b/Build/source/texk/ttf2pk2/tests/ipaexg.ttf Binary files differnew file mode 100644 index 00000000000..a82b95c1de3 --- /dev/null +++ b/Build/source/texk/ttf2pk2/tests/ipaexg.ttf diff --git a/Build/source/texk/ttf2pk2/tests/ttf2pk.cfg b/Build/source/texk/ttf2pk2/tests/ttf2pk.cfg index 4a61f25f3cc..709b3d0c428 100644 --- a/Build/source/texk/ttf2pk2/tests/ttf2pk.cfg +++ b/Build/source/texk/ttf2pk2/tests/ttf2pk.cfg @@ -1,3 +1,5 @@ map GenR102-ec map +GenR102-h map +GenR102-v +map +ipaexg-h +map +ipaexg-v diff --git a/Build/source/texk/ttf2pk2/tests/ttf2pk.test b/Build/source/texk/ttf2pk2/tests/ttf2pk.test index 3dcfc9227dc..b1e23ad5e46 100755 --- a/Build/source/texk/ttf2pk2/tests/ttf2pk.test +++ b/Build/source/texk/ttf2pk2/tests/ttf2pk.test @@ -1,14 +1,14 @@ #! /bin/sh -# Copyright (C) 2011 Peter Breitenlohner <tex-live@tug.org> +# Copyright (C) 2011, 2012 Peter Breitenlohner <tex-live@tug.org> # You may freely use, modify and/or distribute this file. -rm -f GenR-ec.vpl GenR102-* +rm -f GenR-ec.vpl GenR102-* ipaexg-* TEXMFCNF=$srcdir/../kpathsea TEXFONTS=.:$srcdir/tests TTF2PKINPUTS=$srcdir/tests -SFDFONTS=$srcdir/data +SFDFONTS="$srcdir/data;$srcdir/tests" export TEXMFCNF TEXFONTS TTF2PKINPUTS SFDFONTS @@ -50,3 +50,23 @@ done echo passed GenR102-v test +./ttf2tfm ipaexg -q ipaexg-h@Test@ >ipaexg-h.map || exit 1 +diff $srcdir/tests/ipaexg-h.map ipaexg-h.map || exit 1 + +./ttf2pk -q ipaexg-h03 100 || exit 1 + +tftopl ipaexg-h03 ipaexg-h03 || exit 77 +pktype ipaexg-h03.100pk >ipaexg-h03.typ || exit 77 + +echo passed ipaexg-h test + +./ttf2tfm ipaexg -q -x ipaexg-v@Test@ >ipaexg-v.map || exit 1 +diff $srcdir/tests/ipaexg-v.map ipaexg-v.map || exit 1 + +./ttf2pk -q ipaexg-v03 100 || exit 1 + +tftopl ipaexg-v03 ipaexg-v03 || exit 77 +pktype ipaexg-v03.100pk >ipaexg-v03.typ || exit 77 + +echo passed ipaexg-v test + diff --git a/Build/source/texk/ttf2pk2/tfmaux.c b/Build/source/texk/ttf2pk2/tfmaux.c index 68e80a708bf..314c105e9fb 100644 --- a/Build/source/texk/ttf2pk2/tfmaux.c +++ b/Build/source/texk/ttf2pk2/tfmaux.c @@ -282,7 +282,6 @@ buildtfm(Font *fnt) register int i, j; register ttfinfo *ti; int byte1, old_byte1, byte2; - long cksum; double Slant; char buffer[256]; struct sf sf_array[256]; @@ -365,8 +364,8 @@ buildtfm(Font *fnt) } header = (long *)mymalloc(40000L); - cksum = checksum(fnt->inencptrs); - header[0] = cksum; + fnt->cksum = checksum(fnt->inencptrs); + header[0] = fnt->cksum; header[1] = 0xA00000; /* 10pt design size */ (void)makebcpl(header + 2, fnt->codingscheme, 39); @@ -509,7 +508,8 @@ buildtfm(Font *fnt) old_byte1 = byte1; nl++; } - ligkern[nl - 1] |= 0x80000000L; + if (nl > 0) + ligkern[nl - 1] |= 0x80000000L; } kerns = ligkern + nl; diff --git a/Build/source/texk/ttf2pk2/ttf2tfm.c b/Build/source/texk/ttf2pk2/ttf2tfm.c index b118529014f..ebc92a10df9 100644 --- a/Build/source/texk/ttf2pk2/ttf2tfm.c +++ b/Build/source/texk/ttf2pk2/ttf2tfm.c @@ -235,6 +235,37 @@ end: } +#define MAX_SFLIST 10 +static void +add_subfont_list(Font *fnt) +{ + if (fnt->subfont_list == NULL) + fnt->subfont_list = (sflist *)mymalloc(MAX_SFLIST * sizeof(sflist)); + else if (fnt->subfont_num % MAX_SFLIST == 0) + fnt->subfont_list = (sflist *)myrealloc(fnt->subfont_list, + (fnt->subfont_num / MAX_SFLIST + 1) * MAX_SFLIST * sizeof(sflist)); + + (fnt->subfont_list[fnt->subfont_num]).name = + (char *)mymalloc(strlen(fnt->fullname)+1); + strcpy((fnt->subfont_list[fnt->subfont_num]).name, fnt->fullname); + (fnt->subfont_list[fnt->subfont_num]).cksum = fnt->cksum; + + fnt->subfont_num++; +} + + +static void +release_subfont_list(Font *fnt) +{ + register int i; + + for (i = 0; i < fnt->subfont_num; i++) + free((fnt->subfont_list[i]).name); + + free(fnt->subfont_list); +} + + #define VERSION "\ Copyright (C) 1997-1999, 2000, 2002 Frederic Loyer and Werner Lemberg.\n\ There is NO warranty. You may redistribute this software\n\ @@ -272,6 +303,7 @@ version(void) -L LIGFILE[.sfd] create 1st/2nd byte ligatures in subfonts using LIGFILE\n\ -n use PS names of TrueType font\n\ -N use only PS names and no cmap\n\ +-o FILE[.ovp] make an OVP file for conversion to OVF and OFM\n\ -O use octal for all character codes in the vpl file\n\ -p ENCFILE[.enc] read ENCFILE for the TTF->raw TeX mapping\n\ -P INT select INT as the TTF platform ID [3]\n\ @@ -528,6 +560,15 @@ handle_options(int argc, char *argv[], Font *fnt) arginc = 1; break; + case 'o': + if (argc <= 3) + oops("Missing parameter for -o option."); + if (vpl_name) + free(vpl_name); + vpl_name = newstring(argv[3]); + handle_extension(&vpl_name, ".ovp"); + break; + default: if (argc <= 3 || argv[3][0] == '-') { @@ -664,6 +705,9 @@ handle_options(int argc, char *argv[], Font *fnt) warning("Ignoring `-v' and `-V' switches for subfonts."); makevpl = 0; } + if (vpl_name) + if ((fnt->vplout = fopen(vpl_name, "wb")) == NULL) + oops("Cannot open ovp output file."); if (have_capheight) warning("Ignoring `-c' switch for subfonts."); if (fnt->inencname || fnt->outencname) @@ -864,6 +908,18 @@ main(int argc, char *argv[]) if (font.replacements) warning("Replacement glyphs will be ignored."); + /* second try to get an xheight value */ + if (font.xheight == 0) + { + if (NULL != (ti = findadobe("x", font.charlist))) + font.xheight = ti->ury; + else if (font.pid == 3 && font.eid == 1 && + NULL != (ti = findadobe(".c0x78", font.charlist))) + font.xheight = ti->ury; + else + font.xheight = 400; + } + if (NULL != (ti = findadobe("space", font.charlist))) font.fontspace = ti->width; else if (NULL != (ti = findadobe(".c0x20", font.charlist))) @@ -879,10 +935,19 @@ main(int argc, char *argv[]) writetfm(&font); if (font.write_enc) writeenc(&font); + if (font.vplout) + add_subfont_list(&font); } } close_sfd(); + + if (font.vplout) + { + writeovp(&font); + fclose(font.vplout); + release_subfont_list(&font); + } } else { @@ -891,6 +956,18 @@ main(int argc, char *argv[]) readttf(&font, quiet, False); replace_glyphs(&font); + /* second try to get an xheight value */ + if (font.xheight == 0) + { + if (NULL != (ti = findadobe("x", font.charlist))) + font.xheight = ti->ury; + else if (font.pid == 3 && font.eid == 1 && + NULL != (ti = findadobe(".c0x78", font.charlist))) + font.xheight = ti->ury; + else + font.xheight = 400; + } + if (NULL != (ti = findadobe("space", font.charlist))) font.fontspace = ti->width; else if (NULL != (ti = findadobe(".c0x20", font.charlist))) diff --git a/Build/source/texk/ttf2pk2/ttf2tfm.h b/Build/source/texk/ttf2pk2/ttf2tfm.h index 586ca1c5634..73e6008d9a7 100644 --- a/Build/source/texk/ttf2pk2/ttf2tfm.h +++ b/Build/source/texk/ttf2pk2/ttf2tfm.h @@ -54,7 +54,8 @@ struct _pcc; typedef struct _pcc pcc; struct _stringlist; typedef struct _stringlist stringlist; - +struct _sflist; +typedef struct _sflist sflist; struct _ttfinfo @@ -77,6 +78,8 @@ struct _ttfinfo pcc *pccs; /* we use the composite feature for */ /* `germandbls' <--> `SS' only */ unsigned char wptr, hptr, dptr, iptr; + + short fntnum; }; @@ -120,6 +123,13 @@ struct _stringlist }; +struct _sflist +{ + char *name; + long cksum; +}; + + struct _Font { char *ttfname; @@ -187,6 +197,11 @@ struct _Font const char *codingscheme; /* coding scheme for TeX */ char *titlebuf; + long cksum; + + short subfont_num; + sflist *subfont_list; + /* * The name of the subfont definition file. */ diff --git a/Build/source/texk/ttf2pk2/ttfaux.c b/Build/source/texk/ttf2pk2/ttfaux.c index 60d9c45030e..943dabb6f5b 100644 --- a/Build/source/texk/ttf2pk2/ttfaux.c +++ b/Build/source/texk/ttf2pk2/ttfaux.c @@ -3,20 +3,17 @@ * * This file is part of the ttf2pk package. * - * Copyright 1997-1999, 2000, 2002 by + * Copyright 1997-1999, 2000, 2002, 2003 by * Frederic Loyer <loyer@ensta.fr> * Werner Lemberg <wl@gnu.org> */ -#include <math.h> #include <string.h> #include <stdlib.h> #include <ft2build.h> #include FT_FREETYPE_H #include FT_OUTLINE_H -#include FT_TYPE1_TABLES_H -#include FT_TRUETYPE_TABLES_H #include FT_BBOX_H #include "ttf2tfm.h" @@ -27,51 +24,15 @@ #include "errormsg.h" #include "ttfaux.h" #include "filesrch.h" - - -#define Macintosh_platform 1 -#define Macintosh_encoding 0 - -#define Microsoft_platform 3 -#define Microsoft_Unicode_encoding 1 - -#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_FT_TAG('v', 'e', 'r', 't') +#include "ftlib.h" char *real_ttfname; -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; -TT_Postscript *postscript; -#if 0 -TTO_GSUBHeader gsub_; -TTO_GSUBHeader *gsub; -#endif - -Boolean has_gsub; - static void readttf_kern(Font *fnt) @@ -98,12 +59,13 @@ readttf_kern(Font *fnt) nk->succ = tj->adobename; nk->delta = transform(akerning.x * 1000 / fnt->units_per_em, 0, fnt->efactor, fnt->slant); - /* We append the new kern to reproduce the old .vpl file */ - tail->next = nk; - tail = nk; #if 0 nk->next = ti->kerns; ti->kerns = nk; +#else + /* We append the new kern to reproduce the old .vpl file */ + tail->next = nk; + tail = nk; #endif } } @@ -120,22 +82,10 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) long Num, index; unsigned int i, j; long k, max_k; - unsigned short num_cmap; - unsigned short cmap_plat=0, cmap_enc=0; int index_array[257]; static Boolean initialized = False; -#if 0 - FT_UShort in_string[2]; -#if 0 - TTO_GSUB_String in, out; -#endif - - FT_UShort script_index, language_index, feature_index; - FT_UShort req_feature_index = 0xFFFF; -#endif - /* * We allocate a placeholder boundary and the `.notdef' character. @@ -158,302 +108,17 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) if (!initialized) { - if ((error = FT_Init_FreeType(&engine))) - oops("Cannot initialize engine (error code = 0x%x).", error); -#if 0 - if ((error = FT_Init_Kerning_Extension(engine))) - oops("Cannot initialize kerning (error code = 0x%x).", error); - - if (fnt->PSnames) - if ((error = FT_Init_Post_Extension(engine))) - oops("Cannot initialize PS name support (error code = 0x%x).", error); - - if (fnt->rotate) - if ((error = FT_Init_GSUB_Extension(engine))) - oops("Cannot initialize GSUB support (error code = 0x%x).", error); -#endif - /* - * Load face. + * We use a dummy glyph size of 10pt. */ + dpi = 92; + ptsize = 10 * 64; real_ttfname = TeX_search_ttf_file(&(fnt->ttfname)); if (!real_ttfname) oops("Cannot find `%s'.", fnt->ttfname); - if ((error = FT_New_Face(engine, real_ttfname, 0,&face))) - oops("Cannot open `%s'.", real_ttfname); - - /* - * Get face properties and allocate preload arrays. - */ - -#if 0 - FT_Get_Face_Properties(face, &properties); -#endif - - /* - * Now we try to open the proper font in a collection. - */ - - if (fnt->fontindex != 0) - { - if (face->num_faces == 1) - { - warning("This isn't a TrueType collection.\n" - "Parameter `-f' is ignored."); - fnt->fontindex = 0; - fnt->fontindexparam = NULL; - } - else - { -#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 - } - } - - /* - * Create instance. - */ - -#if 0 - if ((error = FT_New_Instance(face, &instance))) - oops("Cannot create instance for `%s' (error code = 0x%x).", - real_ttfname, error); -#endif - - /* - * Get the Postscript table. - */ - - if ((postscript = FT_Get_Sfnt_Table(face, ft_sfnt_post)) == NULL) - oops("Cannot find Postscript table for `%s'.", real_ttfname); - - /* - * We use a dummy glyph size of 10pt. - */ - -#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 = (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) - { - matrix2.xx = 0; - matrix2.yx = 1L << 16; - matrix2.xy = -matrix2.yx; - matrix2.yy = matrix2.xx; - } - -#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 0 - if ((error = FT_New_Glyph(face, &glyph))) - oops("Cannot create glyph container (error code = 0x%x).", error); -#endif - - fnt->units_per_em = face->units_per_EM; - fnt->fixedpitch = postscript->isFixedPitch; - fnt->italicangle = postscript->italicAngle / 65536.0; - - if (fnt->PSnames != Only) - { - num_cmap = face->num_charmaps; - for (i = 0; i < num_cmap; i++) - { - cmap_plat=face->charmaps[i]->platform_id; - cmap_enc=face->charmaps[i]->encoding_id; - if (cmap_plat == fnt->pid && cmap_enc == fnt->eid) - break; - } - if (i == num_cmap) - { - fprintf(stderr, "%s: ERROR: Invalid platform and/or encoding ID.\n", - progname); - if (num_cmap == 1) - fprintf(stderr, " The only valid PID/EID pair is"); - else - fprintf(stderr, " Valid PID/EID pairs are:\n"); - for (i = 0; i < num_cmap; i++) - { - cmap_plat=face->charmaps[i]->platform_id; - cmap_enc=face->charmaps[i]->encoding_id; - fprintf(stderr, " (%i,%i)\n", cmap_plat, cmap_enc); - } - fprintf(stderr, "\n"); - exit(1); - } - - if ((error = FT_Set_Charmap(face, face->charmaps[i]))) - oops("Cannot load cmap (error code = 0x%x).", error); - } - - if (fnt->PSnames) - { - if (!FT_HAS_GLYPH_NAMES(face)) - oops("Cannot load PS names."); - } - else if (cmap_plat == Microsoft_platform && - cmap_enc == Microsoft_Unicode_encoding) - set_encoding_scheme(encUnicode, fnt); - else if (cmap_plat == Macintosh_platform && - cmap_enc == Macintosh_encoding) - set_encoding_scheme(encMac, fnt); - else - set_encoding_scheme(encFontSpecific, fnt); - -#if 0 - if (fnt->rotate) - { - gsub = &gsub_; - - error = FT_Load_GSUB_Table(face, gsub, NULL); - if (!error) - has_gsub = True; - else if (error != FT_Err_Table_Missing) - warning("Cannot load GSUB table (error code = 0x%x).", error); - else - warning("No GSUB data available " - "for vertical glyph presentation forms."); - - /* we check for the `vert' feature in Chinese, Japanese, and Korean */ - - error = FT_GSUB_Select_Script(gsub, - SCRIPT_kana, - &script_index); - if (error) - goto check_hani; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_JAN, - script_index, - &language_index, - &req_feature_index); - if (error) - goto check_hani; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - if (error) - goto check_hani; - else - goto Done; - } - else - goto Done; - - check_hani: - error = FT_GSUB_Select_Script(gsub, - SCRIPT_hani, - &script_index); - if (error) - goto check_hang; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_CHN, - script_index, - &language_index, - &req_feature_index); - if (error) - goto check_hang; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - if (error) - goto check_hang; - else - goto Done; - } - else - goto Done; - - check_hang: - error = FT_GSUB_Select_Script(gsub, - SCRIPT_hang, - &script_index); - if (error) - goto Done; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_KOR, - script_index, - &language_index, - &req_feature_index); - if (error) - goto Done; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - } - - Done: - if (error) - { - warning("There is no data for vertical typesetting in GSUB table."); - has_gsub = False; - } - - if (req_feature_index != 0xFFFF) - 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; - in.string = in_string; - in.properties = NULL; - - out.pos = 0; - out.allocated = 0; - out.string = NULL; - out.properties = NULL; - } -#endif + FTopen(real_ttfname, fnt, True, True); initialized = True; } @@ -464,8 +129,8 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) printf("\n\n%s:\n", fnt->fullname); printf("\n"); printf("Glyph Code Glyph Name "); - printf("Width llx lly urx ury\n"); - printf("---------------------------------------"); + printf("Width llx lly urx ury\n"); + printf("----------------------------------------"); printf("---------------------------------\n"); } @@ -516,19 +181,8 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) 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 = 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 + Num = Get_Vert(Num); if (Num < 0) oops("Failure on cmap mapping from %s.", fnt->ttfname); @@ -545,22 +199,15 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) } error = FT_Load_Glyph(face, Num, flags); -#if 0 - if (!error) - error = FT_Get_Glyph_Big_Metrics(glyph, &metrics); - if (!error) - error = FT_Get_Glyph_Outline(glyph, &outline); -#endif if (!error) { if (fnt->efactor != 1.0 || fnt->slant != 0.0 ) FT_Outline_Transform(&face->glyph->outline, &matrix1); if (fnt->rotate) FT_Outline_Transform(&face->glyph->outline, &matrix2); - } - if (!error) error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non- - grid-fitted bbox */ + grid-fitted bbox */ + } if (!error) { if (fnt->PSnames) @@ -589,6 +236,8 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) ti->urx = bbox.xMax * 1000 / fnt->units_per_em; ti->ury = bbox.yMax * 1000 / fnt->units_per_em; + ti->fntnum = fnt->subfont_num; + /* * We must now shift the rotated character both horizontally * and vertically. The vertical amount is 25% by default. @@ -650,14 +299,8 @@ readttf(Font *fnt, Boolean quiet, Boolean only_range) if (index_array[i] == 0) { error = FT_Load_Glyph(face, i, flags); -#if 0 - if (!error) - error = FT_Get_Glyph_Big_Metrics(glyph, &metrics); if (!error) - error = FT_Get_Glyph_Outline(glyph, &outline); - if (!error) - error = FT_Get_Outline_BBox(&outline, &bbox); -#endif + error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); if (!error) { an = code_to_adobename(i | 0x1000000); diff --git a/Build/source/texk/ttf2pk2/ttflib.c b/Build/source/texk/ttf2pk2/ttflib.c index a6943de41fa..b01ca1209c6 100644 --- a/Build/source/texk/ttf2pk2/ttflib.c +++ b/Build/source/texk/ttf2pk2/ttflib.c @@ -18,67 +18,22 @@ #include <ft2build.h> #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 "ftlib.h" -#define Macintosh_platform 1 -#define Macintosh_encoding 0 - -#define Microsoft_platform 3 -#define Microsoft_Symbol_encoding 0 -#define Microsoft_Unicode_encoding 1 - -#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_FT_TAG('v', 'e', 'r', 't') - - -FT_Library engine; -FT_Face face; -//FT_Instance instance; -FT_GlyphSlot glyph; -FT_CharMap char_map; - -//FT_Outline outline; -//FT_Glyph outline; -//FT_Face_Properties properties; FT_BBox bbox; -//FT_Post post; +FT_Bitmap Bit; +unsigned char *Bitp; -FT_Bitmap Bit, Bit2; -void *Bitp, *Bit2p; - -int dpi; -int ptsize; - -int x_offset, y_offset; int ppem; -//FT_Big_Glyph_Metrics face; - -FT_Matrix matrix1, matrix2; - -//OTL_GSUBHeader gsub_; -//OTL_GSUBHeader *gsub; - -FT_UShort in_string[2]; -//OTL_GSUB_String in, out; - -Boolean has_gsub; static void @@ -92,15 +47,8 @@ SetRasterArea(int quiet) temp2_x = (bbox.xMax + 63) / 64; temp2_y = (bbox.yMax + 63) / 64; - x_offset = 5 - temp1_x; - y_offset = 5 - temp1_y; - if (!quiet) - printf(" off = (%d, %d)", x_offset, y_offset); - -#if 0 - x_offset = y_offset = 0; -#endif + printf(" off = (%d, %d)", 5 - temp1_x, 5 - temp1_y); if (!quiet) printf(" bbox = (%d, %d) <-> (%d, %d)\n", @@ -110,47 +58,17 @@ SetRasterArea(int quiet) Bit.width = temp2_x - temp1_x + 10; 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 * purposes in pklib.c, making `gcc -fbounds-checking' happy. */ - if (Bitp) free(Bitp); Bitp = mymalloc(Bit.rows*Bit.pitch + Bit.pitch); Bit.buffer = Bitp; - - Bit2 = Bit; - - if (Bit2p) - free(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.buffer; - p2 = (char *)Bit2.buffer + Bit2.pitch * (Bit2.rows - 1); - - for (y = 0; y < Bit.rows; y++) - { - memcpy(p2, p1, Bit.pitch); - p1 += Bit.pitch; - p2 -= Bit.pitch; - } -} - -#endif - static void CopyBit(FT_Bitmap *b2,FT_Bitmap *b1) { @@ -202,277 +120,14 @@ Output(FT_Bitmap Bit) void TTFopen(char *filename, Font *fnt, int new_dpi, int new_ptsize, Boolean quiet) { - unsigned short i, num_cmap; - 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 = FT_Init_FreeType(&engine))) - oops("Cannot initialize FreeType engine (error code = 0x%x).", error); - -#if 0 - if (fnt->PSnames) - if ((error = FT_Init_Post_Extension(engine))) - oops("Cannot initialize PS name support (error code = 0x%x).", error); - - if (fnt->rotate) - if ((error = FT_Init_GSUB_Extension(engine))) - oops("Cannot initialize GSUB support (error code = 0x%x).", error); -#endif - - error = FT_New_Face(engine, filename, 0,&face); - if (error) - oops("Cannot open `%s'.", filename); - if (fnt->fontindex != 0) - { - if (face->num_faces == 1) - warning("This isn't a TrueType collection.\n" - "Parameter `Fontindex' is ignored."); - else - { - /* - * 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 - } - } -// 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 = FT_New_Instance(face, &instance))) -// oops("Cannot create instance for `%s' (error code = 0x%x).", -// filename, error); - -// if ((error = FT_Set_Instance_Resolutions(instance, dpi, dpi))) -// oops("Cannot set device resolutions (error code = 0x%x)."); - -// if ((error = FT_Set_Instance_CharSize(instance, ptsize * 64))) -// oops("Cannot set character size (error code = 0x%x).", error); - 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; if (!quiet) printf("dpi = %d, ptsize = %d, ppem = %d\n\n", dpi, ptsize, ppem); - 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) - { - matrix2.xx = 0; - matrix2.yx = 1L << 16; - matrix2.xy = -matrix2.yx; - matrix2.yy = matrix2.xx; - } - -#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 0 - if ((error = FT_New_Glyph(face, &glyph))) - oops("Cannot create glyph container (error code = 0x%x)."); -#endif - - if (fnt->PSnames != Only) - { - num_cmap = face->num_charmaps; - for (i = 0; i < num_cmap; i++) - { - 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 = FT_Set_Charmap(face, face->charmaps[i]))) - oops("Cannot load cmap (error code = 0x%x).", error); - } - -#if 0 - if (fnt->PSnames) - { - if ((error = FT_Load_PS_Names(face, &post))) - oops("Cannot load TrueType PS names (error code = 0x%x).", error); - } -#endif - if (cmap_plat == Microsoft_platform && - cmap_enc == Microsoft_Unicode_encoding) - set_encoding_scheme(encUnicode, fnt); - else if (cmap_plat == Macintosh_platform && - cmap_enc == Macintosh_encoding) - set_encoding_scheme(encMac, fnt); - else - set_encoding_scheme(encFontSpecific, fnt); - -#ifdef FREETYPE1 - if (fnt->rotate) - { - gsub = &gsub_; - - error = FT_Load_GSUB_Table(face, gsub, NULL); - if (!error) - has_gsub = True; - else if (error != FT_Err_Table_Missing) - warning("Cannot load GSUB table (error code = 0x%x).", error); - else - warning("No GSUB data available " - "for vertical glyph presentation forms."); - - /* we check for the `vert' feature in Chinese, Japanese, and Korean */ - - error = FT_GSUB_Select_Script(gsub, - SCRIPT_kana, - &script_index); - if (error) - goto check_hani; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_JAN, - script_index, - &language_index, - &req_feature_index); - if (error) - goto check_hani; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - if (error) - goto check_hani; - else - goto Done; - } - else - goto Done; - - check_hani: - error = FT_GSUB_Select_Script(gsub, - SCRIPT_hani, - &script_index); - if (error) - goto check_hang; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_CHN, - script_index, - &language_index, - &req_feature_index); - if (error) - goto check_hang; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - if (error) - goto check_hang; - else - goto Done; - } - else - goto Done; - - check_hang: - error = FT_GSUB_Select_Script(gsub, - SCRIPT_hang, - &script_index); - if (error) - goto Done; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - 0xFFFF, - &feature_index); - if (error) - { - error = FT_GSUB_Select_Language(gsub, - LANGUAGE_KOR, - script_index, - &language_index, - &req_feature_index); - if (error) - goto Done; - error = FT_GSUB_Select_Feature(gsub, - FEATURE_vert, - script_index, - language_index, - &feature_index); - } - - Done: - if (error) - { - warning("There is no data for vertical typesetting in GSUB table."); - has_gsub = False; - } - - if (req_feature_index != 0xFFFF) - 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; - in.string = in_string; - in.properties = NULL; - - out.pos = 0; - out.allocated = 0; - out.string = NULL; - out.properties = NULL; - } -#endif // FREETYPE1 + FTopen(filename, fnt, False, quiet); } @@ -486,39 +141,31 @@ LoadTrueTypeChar(Font *fnt, int flags; -// flags = FT_LOAD_SCALE_GLYPH; flags = FT_LOAD_DEFAULT; if (hint) flags |= FT_LOAD_FORCE_AUTOHINT; - //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 ) -// FT_Transform_Outline(&outline, &matrix1); FT_Outline_Transform(&face->glyph->outline, &matrix1); if (fnt->rotate) + { FT_Outline_Transform(&face->glyph->outline, &matrix2); + error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non- + grid-fitted bbox */ + if (!error) + FT_Outline_Translate(&face->glyph->outline, + face->glyph->metrics.vertBearingY - bbox.xMin, + -fnt->y_offset * ppem * 64); + } } if (!error) - error = FT_Outline_Get_BBox(&face->glyph->outline, &bbox); /* we need the non- - grid-fitted bbox */ - if (fnt->rotate) - FT_Outline_Translate(&face->glyph->outline, - face->glyph->metrics.vertBearingY - bbox.xMin, - -fnt->y_offset * ppem * 64); - 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 */ + if (!error) + { + FT_Outline_Get_CBox(&face->glyph->outline, &bbox); /* for the case of BBox != CBox */ SetRasterArea(quiet); } return error; @@ -545,58 +192,30 @@ TTFprocess(Font *fnt, Num = Code & 0xFFFFFF; else { -// Num = FT_Char_Index(char_map, Code); Num = FT_Get_Char_Index(face, Code); -#if 0 + + /* now we try to get a vertical glyph form */ if (has_gsub) - { - in_string[0] = Num; - 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 + Num = Get_Vert(Num); } if ((error = LoadTrueTypeChar(fnt, Num, hinting, quiet)) == FT_Err_Ok) { - 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); + memset(Bit.buffer, 0, Bit.rows*Bit.pitch); CopyBit(&Bit, &face->glyph->bitmap); -#if 0 - FlipBit(); - *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); */ + *height = face->glyph->bitmap.rows; + *hoff = -face->glyph->bitmap_left; + *voff = *height + 1 - face->glyph->bitmap_top; + /* Output(Bit); */ return True; } else @@ -636,7 +255,6 @@ TTFget_first_glyphs(Font *fnt, long *array) for (i = 0; i <= 0x16FFFF; 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) @@ -737,7 +355,6 @@ TTFget_subfont(Font *fnt, long *array) array[i] = j; else { - //Num = FT_Char_Index(char_map, j); Num = FT_Get_Char_Index(face, j); if (Num < 0) oops("cmap mapping failure."); diff --git a/Build/source/texk/ttf2pk2/vplaux.c b/Build/source/texk/ttf2pk2/vplaux.c index 448aa8d019f..ffe6d539502 100644 --- a/Build/source/texk/ttf2pk2/vplaux.c +++ b/Build/source/texk/ttf2pk2/vplaux.c @@ -595,4 +595,117 @@ writevpl(Font *fnt, char makevpl, Boolean forceoctal) } +void +writeovp(Font *fnt) +{ + register int i; + register ttfinfo *ti; + long bc, ec; + char header[256]; + float Slant; + ttfinfo *ofm_array[65536]; + + + out = fnt->vplout; + + header[0] = '\0'; + strncat(header, "Created by `", 12); + strncat(header, fnt->titlebuf, 255 - 12 - 1); + strncat(header, "'", 1); + + voutln2("(VTITLE %s)", header); + voutln("(COMMENT Please change VTITLE if you edit this file)"); + + voutln("(OFMLEVEL H 1)"); + voutln("(FONTDIR TL)"); + voutln2("(FAMILY %s)", fnt->outname); + voutln("(FACE F MRR)"); + voutln("(CODINGSCHEME UNSPECIFIED)"); + voutln("(DESIGNSIZE R 10.0)"); + voutln("(DESIGNUNITS R 1000)"); + voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)"); + voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)"); + +#if 0 + /* Let vptovf compute the checksum. */ + voutln2("(CHECKSUM O %lo)", cksum ^ 0xFFFFFFFF); +#endif + + vleft(&level); + voutln("FONTDIMEN"); + + Slant = fnt->slant - fnt->efactor * tan(fnt->italicangle * (PI / 180.0)); + + if (Slant) + voutln2("(SLANT R %f)", Slant); + voutln2("(SPACE D %d)", fnt->fontspace); + if (!fnt->fixedpitch) + { + voutln2("(STRETCH D %d)", transform(200, 0, fnt->efactor, fnt->slant)); + voutln2("(SHRINK D %d)", transform(100, 0, fnt->efactor, fnt->slant)); + } + voutln2("(XHEIGHT D %d)", fnt->xheight); + voutln2("(QUAD D %d)", transform(1000, 0, fnt->efactor, fnt->slant)); + voutln2("(EXTRASPACE D %d)", + fnt->fixedpitch ? fnt->fontspace : + transform(111, 0, fnt->efactor, fnt->slant)); + vright(&level); + + for (i = 0; i < fnt->subfont_num; i++) + { + vleft(&level); + voutln2("MAPFONT D %d", i); + voutln2("(FONTNAME %s)", (fnt->subfont_list[i]).name); + voutln2("(FONTCHECKSUM O %lo)", (fnt->subfont_list[i]).cksum); + vright(&level); + } + + for (i = 0; i <= 0xFFFF; i++) + ofm_array[i] = NULL; + + for (ti = fnt->charlist; ti != NULL; ti = ti->next) + if (ti->charcode >= 0 && ti->charcode <= 0xFFFF) + ofm_array[ti->charcode] = ti; + + for (i = 0; i <= 0xFFFF && ofm_array[i] == NULL; i++) + ; + bc = i; + for (i = 0xFFFF; i >= 0 && ofm_array[i] == NULL; i--) + ; + ec = i; + + if (ec < bc) + oops("No TTF characters."); + + for (i = bc; i <= ec; i++) + { + if ((ti = ofm_array[i]) == NULL) continue; + + vleft(&level); + fprintf(out, "CHARACTER H %lX\n ", ti->charcode); + + voutln2("(CHARWD R %d)", ti->width); + if (ti->ury) + voutln2("(CHARHT R %d)", ti->ury); + if (ti->lly) + voutln2("(CHARDP R %d)", -ti->lly); + if (ti->urx > ti->width) + voutln2("(CHARIC R %d)", ti->urx - ti->width); + + vleft(&level); + voutln("MAP"); + if (ti->fntnum) + voutln2("(SELECTFONT D %d)", ti->fntnum); + + voutln2("(SETCHAR H %X)", (unsigned)ti->incode); + vright(&level); + + vright(&level); + } + + if (level) + oops("I forgot to match the parentheses."); +} + + /* end */ diff --git a/Build/source/texk/ttf2pk2/vplaux.h b/Build/source/texk/ttf2pk2/vplaux.h index 417d558ff53..cd30f908de4 100644 --- a/Build/source/texk/ttf2pk2/vplaux.h +++ b/Build/source/texk/ttf2pk2/vplaux.h @@ -16,6 +16,7 @@ void writevpl(Font *fnt, char makevpl, Boolean forceoctal); void upmap(Font *fnt); +void writeovp(Font *fnt); #endif /* VPLAUX_H */ |