summaryrefslogtreecommitdiff
path: root/Build/source/texk/ttf2pk2/ttfaux.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2012-09-18 17:56:42 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2012-09-18 17:56:42 +0000
commitbcf4f5c089878ad822ed4073e7de63b12344b978 (patch)
tree7947195be8a18a343b2b238bd4d6b758203dc17a /Build/source/texk/ttf2pk2/ttfaux.c
parente3167f2329da4174fd1332e069788693de96b72a (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/source/texk/ttf2pk2/ttfaux.c')
-rw-r--r--Build/source/texk/ttf2pk2/ttfaux.c393
1 files changed, 18 insertions, 375 deletions
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);