提交 c6b22b91 编写于 作者: B Behdad Esfahbod 提交者: Behdad Esfahbod

Generate valid XML output. Dump LookupFlag too.

2005-08-29  Behdad Esfahbod  <pango@behdad.org>

        * pango/opentype/ottest.c, pango/opentype/disasm.c: Generate valid
        XML output.  Dump LookupFlag too.
上级 1e3747ca
...@@ -31,11 +31,11 @@ ...@@ -31,11 +31,11 @@
#endif #endif
#define DUMP_FINT(strct,fld) dump (stream, indent, "<" #fld ">%d</" #fld ">\n", (strct)->fld) #define DUMP_FINT(strct,fld) dump (stream, indent, "<" #fld ">%d</" #fld ">\n", (strct)->fld)
#define DUMP_FUINT(strct,fld) dump (stream, indent, "<" #fld ">%u</" #fld ">\n", (strct)->fld) #define DUMP_FUINT(strct,fld) dump (stream, indent, "<" #fld ">%u</" #fld ">\n", (strct)->fld)
#define DUMP_FGLYPH(strct,fld) dump (stream, indent, "<" #fld ">%#4x</" #fld ">\n", (strct)->fld) #define DUMP_FGLYPH(strct,fld) dump (stream, indent, "<" #fld ">%#06x</" #fld ">\n", (strct)->fld)
#define DUMP_FGLYPH(strct,fld) dump (stream, indent, "<" #fld ">%#4x</" #fld ">\n", (strct)->fld) #define DUMP_FGLYPH(strct,fld) dump (stream, indent, "<" #fld ">%#06x</" #fld ">\n", (strct)->fld)
#define DUMP_USHORT_ARRAY(strct,fld,cnt) Dump_UShort_Array ((strct)->fld, cnt, #fld, stream, indent, is_gsub); #define DUMP_USHORT_ARRAY(strct,fld,cnt) Dump_UShort_Array ((strct)->fld, cnt, #fld, stream, indent);
#define DEF_DUMP(type) static void Dump_ ## type (TTO_ ## type *type, FILE *stream, int indent, FT_Bool is_gsub) #define DEF_DUMP(type) static void Dump_ ## type (TTO_ ## type *type, FILE *stream, int indent, FT_Bool G_GNUC_UNUSED is_gsub)
#define RECURSE(name, type, val) do { DUMP ("<" #name ">\n"); Dump_ ## type (val, stream, indent + 1, is_gsub); DUMP ("</" #name ">\n"); } while (0) #define RECURSE(name, type, val) do { DUMP ("<" #name ">\n"); Dump_ ## type (val, stream, indent + 1, is_gsub); DUMP ("</" #name ">\n"); } while (0)
#define RECURSE_NUM(name, i, type, val) do { DUMP ("<" #name "> <!-- %d -->\n", i); Dump_ ## type (val, stream, indent + 1, is_gsub); DUMP ("</" #name ">\n"); } while (0) #define RECURSE_NUM(name, i, type, val) do { DUMP ("<" #name "> <!-- %d -->\n", i); Dump_ ## type (val, stream, indent + 1, is_gsub); DUMP ("</" #name ">\n"); } while (0)
#define DUMP_VALUE_RECORD(val, frmt) do { DUMP ("<ValueRecord>\n"); Dump_ValueRecord (val, stream, indent + 1, is_gsub, frmt); DUMP ("</ValueRecord>\n"); } while (0) #define DUMP_VALUE_RECORD(val, frmt) do { DUMP ("<ValueRecord>\n"); Dump_ValueRecord (val, stream, indent + 1, is_gsub, frmt); DUMP ("</ValueRecord>\n"); } while (0)
...@@ -43,10 +43,7 @@ ...@@ -43,10 +43,7 @@
static void static void
do_indent (FILE *stream, int indent) do_indent (FILE *stream, int indent)
{ {
int i; fprintf (stream, "%*s", indent * 3, "");
for (i = 0; i < indent * 3; i++)
fputc (' ', stream);
} }
static void static void
...@@ -62,16 +59,16 @@ dump (FILE *stream, int indent, const char *format, ...) ...@@ -62,16 +59,16 @@ dump (FILE *stream, int indent, const char *format, ...)
} }
static void static void
Dump_UShort_Array (FT_UShort *array, int count, const char *name, FILE *stream, int indent, FT_Bool is_gsub) Dump_UShort_Array (FT_UShort *array, int count, const char *name, FILE *stream, int indent)
{ {
int i; int i;
do_indent (stream, indent); do_indent (stream, indent);
printf ("<%s>", name); fprintf (stream, "<%s>", name);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
printf ("%d%s", array[i], i == 0 ? "" : " "); fprintf (stream, "%d%s", array[i], i == 0 ? "" : " ");
printf ("</%s>\n", name); fprintf (stream, "</%s>\n", name);
} }
static void static void
...@@ -79,8 +76,8 @@ Print_Tag (FT_ULong tag, FILE *stream) ...@@ -79,8 +76,8 @@ Print_Tag (FT_ULong tag, FILE *stream)
{ {
fprintf (stream, "%c%c%c%c", fprintf (stream, "%c%c%c%c",
(unsigned char)(tag >> 24), (unsigned char)(tag >> 24),
(unsigned char)((tag & 0xff0000) >> 16), (unsigned char)((tag >> 16) & 0xff),
(unsigned char)((tag & 0xff00) >> 8), (unsigned char)((tag >> 8) & 0xff),
(unsigned char)(tag & 0xff)); (unsigned char)(tag & 0xff));
} }
...@@ -183,7 +180,7 @@ DEF_DUMP (Coverage) ...@@ -183,7 +180,7 @@ DEF_DUMP (Coverage)
DUMP_FUINT (&Coverage->cf.cf1, GlyphCount); DUMP_FUINT (&Coverage->cf.cf1, GlyphCount);
for (i = 0; i < Coverage->cf.cf1.GlyphCount; i++) for (i = 0; i < Coverage->cf.cf1.GlyphCount; i++)
DUMP("<Glyph>%#4x</Glyph> <!-- %d -->\n", DUMP("<Glyph>%#06x</Glyph> <!-- %d -->\n",
Coverage->cf.cf1.GlyphArray[i], i); Coverage->cf.cf1.GlyphArray[i], i);
} }
else else
...@@ -192,7 +189,7 @@ DEF_DUMP (Coverage) ...@@ -192,7 +189,7 @@ DEF_DUMP (Coverage)
DUMP_FUINT (&Coverage->cf.cf2, RangeCount); DUMP_FUINT (&Coverage->cf.cf2, RangeCount);
for ( i = 0; i < Coverage->cf.cf2.RangeCount; i++ ) for ( i = 0; i < Coverage->cf.cf2.RangeCount; i++ )
DUMP("<Glyph>%#4x - %#4x</Glyph> <!-- %d -->\n", DUMP("<Glyph>%#06x - %#06x</Glyph> <!-- %d -->\n",
Coverage->cf.cf2.RangeRecord[i].Start, Coverage->cf.cf2.RangeRecord[i].Start,
Coverage->cf.cf2.RangeRecord[i].End); Coverage->cf.cf2.RangeRecord[i].End);
} }
...@@ -218,7 +215,7 @@ DEF_DUMP (ClassDefinition) ...@@ -218,7 +215,7 @@ DEF_DUMP (ClassDefinition)
DUMP_FUINT (ClassDefFormat1, StartGlyph ); DUMP_FUINT (ClassDefFormat1, StartGlyph );
DUMP_FUINT (ClassDefFormat1, GlyphCount ); DUMP_FUINT (ClassDefFormat1, GlyphCount );
for (i = 0; i < ClassDefFormat1->GlyphCount; i++) for (i = 0; i < ClassDefFormat1->GlyphCount; i++)
DUMP(" <Class>%d</Class> <!-- %#4x -->", ClassDefFormat1->ClassValueArray[i], DUMP(" <Class>%d</Class> <!-- %#06x -->", ClassDefFormat1->ClassValueArray[i],
ClassDefFormat1->StartGlyph+i ); ClassDefFormat1->StartGlyph+i );
} }
else if (ClassDefinition->ClassFormat == 2) else if (ClassDefinition->ClassFormat == 2)
...@@ -231,7 +228,7 @@ DEF_DUMP (ClassDefinition) ...@@ -231,7 +228,7 @@ DEF_DUMP (ClassDefinition)
RECURSE_NUM (ClassRangeRecord, i, ClassRangeRecord, &ClassDefFormat2->ClassRangeRecord[i]); RECURSE_NUM (ClassRangeRecord, i, ClassRangeRecord, &ClassDefFormat2->ClassRangeRecord[i]);
} }
else else
printf("invalid class def table!!!\n"); fprintf(stderr, "invalid class def table!!!\n");
} }
DEF_DUMP (SubstLookupRecord) DEF_DUMP (SubstLookupRecord)
...@@ -281,7 +278,7 @@ Dump_GSUB_Lookup_Single (TTO_SubTable *subtable, FILE *stream, int indent, FT_Bo ...@@ -281,7 +278,7 @@ Dump_GSUB_Lookup_Single (TTO_SubTable *subtable, FILE *stream, int indent, FT_Bo
DUMP_FINT (&SingleSubst->ssf.ssf2, GlyphCount); DUMP_FINT (&SingleSubst->ssf.ssf2, GlyphCount);
for (i=0; i < SingleSubst->ssf.ssf2.GlyphCount; i++) for (i=0; i < SingleSubst->ssf.ssf2.GlyphCount; i++)
DUMP("<Substitute>%#4x</Substitute> <!-- %d -->\n", SingleSubst->ssf.ssf2.Substitute[i], i); DUMP("<Substitute>%#06x</Substitute> <!-- %d -->\n", SingleSubst->ssf.ssf2.Substitute[i], i);
} }
} }
...@@ -293,7 +290,7 @@ DEF_DUMP (Ligature) ...@@ -293,7 +290,7 @@ DEF_DUMP (Ligature)
DUMP_FUINT (Ligature, ComponentCount); DUMP_FUINT (Ligature, ComponentCount);
for (i=0; i < Ligature->ComponentCount - 1; i++) for (i=0; i < Ligature->ComponentCount - 1; i++)
DUMP("<Component>%#4x</Component>\n", Ligature->Component[i]); DUMP("<Component>%#06x</Component>\n", Ligature->Component[i]);
} }
DEF_DUMP (LigatureSet) DEF_DUMP (LigatureSet)
...@@ -323,7 +320,7 @@ Dump_GSUB_Lookup_Ligature (TTO_SubTable *subtable, FILE *stream, int indent, FT_ ...@@ -323,7 +320,7 @@ Dump_GSUB_Lookup_Ligature (TTO_SubTable *subtable, FILE *stream, int indent, FT_
DEF_DUMP (ContextSubstFormat1) DEF_DUMP (ContextSubstFormat1)
{ {
DUMP("Not implemented!!!\n"); DUMP("<!-- Not implemented!!! -->\n");
} }
DEF_DUMP (ContextSubstFormat2) DEF_DUMP (ContextSubstFormat2)
...@@ -335,7 +332,7 @@ DEF_DUMP (ContextSubstFormat2) ...@@ -335,7 +332,7 @@ DEF_DUMP (ContextSubstFormat2)
DEF_DUMP (ContextSubstFormat3) DEF_DUMP (ContextSubstFormat3)
{ {
DUMP("Not implemented!!!\n"); DUMP("<!-- Not implemented!!! -->\n");
} }
static void static void
...@@ -356,13 +353,13 @@ Dump_GSUB_Lookup_Context (TTO_SubTable *subtable, FILE *stream, int indent, FT_B ...@@ -356,13 +353,13 @@ Dump_GSUB_Lookup_Context (TTO_SubTable *subtable, FILE *stream, int indent, FT_B
Dump_ContextSubstFormat3 (&ContextSubst->csf.csf3, stream, indent+2, is_gsub); Dump_ContextSubstFormat3 (&ContextSubst->csf.csf3, stream, indent+2, is_gsub);
break; break;
default: default:
printf("invalid subformat!!!!!\n"); fprintf(stderr, "invalid subformat!!!!!\n");
} }
} }
DEF_DUMP (ChainContextSubstFormat1) DEF_DUMP (ChainContextSubstFormat1)
{ {
DUMP("Not implemented!!!\n"); DUMP("<!-- Not implemented!!! -->\n");
} }
DEF_DUMP (ChainContextSubstFormat2) DEF_DUMP (ChainContextSubstFormat2)
...@@ -419,7 +416,7 @@ Dump_GSUB_Lookup_Chain (TTO_SubTable *subtable, FILE *stream, int indent, FT_Boo ...@@ -419,7 +416,7 @@ Dump_GSUB_Lookup_Chain (TTO_SubTable *subtable, FILE *stream, int indent, FT_Boo
Dump_ChainContextSubstFormat3 (&chain->ccsf.ccsf3, stream, indent+2, is_gsub); Dump_ChainContextSubstFormat3 (&chain->ccsf.ccsf3, stream, indent+2, is_gsub);
break; break;
default: default:
printf("invalid subformat!!!!!\n"); fprintf(stderr, "invalid subformat!!!!!\n");
} }
} }
...@@ -664,7 +661,8 @@ DEF_DUMP (Lookup) ...@@ -664,7 +661,8 @@ DEF_DUMP (Lookup)
} }
} }
DUMP("<LookupType>%s</LookupType>\n", lookup_name); DUMP("<LookupType>%s</LookupType> <!-- %d -->\n", lookup_name, Lookup->LookupType);
DUMP("<LookupFlag>%#06x</LookupFlag>\n", Lookup->LookupFlag);
for (i=0; i < Lookup->SubTableCount; i++) for (i=0; i < Lookup->SubTableCount; i++)
{ {
...@@ -688,9 +686,11 @@ DEF_DUMP (LookupList) ...@@ -688,9 +686,11 @@ DEF_DUMP (LookupList)
void void
TT_Dump_GSUB_Table (TTO_GSUB gsub, FILE *stream) TT_Dump_GSUB_Table (TTO_GSUB gsub, FILE *stream)
{ {
int indent = 0; int indent = 1;
FT_Bool is_gsub = 1; FT_Bool is_gsub = 1;
do_indent (stream, indent);
fprintf(stream, "<!-- GSUB -->\n");
RECURSE (ScriptList, ScriptList, &gsub->ScriptList); RECURSE (ScriptList, ScriptList, &gsub->ScriptList);
RECURSE (FeatureList, FeatureList, &gsub->FeatureList); RECURSE (FeatureList, FeatureList, &gsub->FeatureList);
RECURSE (LookupList, LookupList, &gsub->LookupList); RECURSE (LookupList, LookupList, &gsub->LookupList);
...@@ -699,9 +699,11 @@ TT_Dump_GSUB_Table (TTO_GSUB gsub, FILE *stream) ...@@ -699,9 +699,11 @@ TT_Dump_GSUB_Table (TTO_GSUB gsub, FILE *stream)
void void
TT_Dump_GPOS_Table (TTO_GPOS gpos, FILE *stream) TT_Dump_GPOS_Table (TTO_GPOS gpos, FILE *stream)
{ {
int indent = 0; int indent = 1;
FT_Bool is_gsub = 0; FT_Bool is_gsub = 0;
do_indent (stream, indent);
fprintf(stream, "<!-- GPOS -->\n");
RECURSE (ScriptList, ScriptList, &gpos->ScriptList); RECURSE (ScriptList, ScriptList, &gpos->ScriptList);
RECURSE (FeatureList, FeatureList, &gpos->FeatureList); RECURSE (FeatureList, FeatureList, &gpos->FeatureList);
RECURSE (LookupList, LookupList, &gpos->LookupList); RECURSE (LookupList, LookupList, &gpos->LookupList);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0])) #define N_ELEMENTS(arr) (sizeof(arr)/ sizeof((arr)[0]))
int static int
croak (const char *situation, FT_Error error) croak (const char *situation, FT_Error error)
{ {
fprintf (stderr, "%s: Error %d\n", situation, error); fprintf (stderr, "%s: Error %d\n", situation, error);
...@@ -36,6 +36,7 @@ croak (const char *situation, FT_Error error) ...@@ -36,6 +36,7 @@ croak (const char *situation, FT_Error error)
exit (1); exit (1);
} }
#if 0
enum { enum {
I = 1 << 0, I = 1 << 0,
M = 1 << 1, M = 1 << 1,
...@@ -43,17 +44,17 @@ enum { ...@@ -43,17 +44,17 @@ enum {
L = 1 << 3 L = 1 << 3
}; };
void static void
print_tag (FT_ULong tag) print_tag (FT_ULong tag)
{ {
fprintf (stderr, "%c%c%c%c", fprintf (stderr, "%c%c%c%c",
(unsigned char)(tag >> 24), (unsigned char)(tag >> 24),
(unsigned char)((tag & 0xff0000) >> 16), (unsigned char)((tag >> 16) & 0xff),
(unsigned char)((tag & 0xff00) >> 8), (unsigned char)((tag >> 8) & 0xff),
(unsigned char)(tag & 0xff)); (unsigned char)(tag & 0xff));
} }
void static void
maybe_add_feature (TTO_GSUB gsub, maybe_add_feature (TTO_GSUB gsub,
FT_UShort script_index, FT_UShort script_index,
FT_ULong tag, FT_ULong tag,
...@@ -81,7 +82,7 @@ maybe_add_feature (TTO_GSUB gsub, ...@@ -81,7 +82,7 @@ maybe_add_feature (TTO_GSUB gsub,
croak ("TT_GSUB_Add_Feature", error); croak ("TT_GSUB_Add_Feature", error);
} }
void static void
select_cmap (FT_Face face) select_cmap (FT_Face face)
{ {
FT_UShort i; FT_UShort i;
...@@ -119,7 +120,7 @@ select_cmap (FT_Face face) ...@@ -119,7 +120,7 @@ select_cmap (FT_Face face)
} }
} }
void static void
add_features (TTO_GSUB gsub) add_features (TTO_GSUB gsub)
{ {
FT_Error error; FT_Error error;
...@@ -144,6 +145,7 @@ add_features (TTO_GSUB gsub) ...@@ -144,6 +145,7 @@ add_features (TTO_GSUB gsub)
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('f', 'i', 'n', 'a'), F); maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('f', 'i', 'n', 'a'), F);
maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('l', 'i', 'g', 'a'), L); maybe_add_feature (gsub, script_index, FT_MAKE_TAG ('l', 'i', 'g', 'a'), L);
} }
#endif
#if 0 #if 0
void void
...@@ -227,7 +229,9 @@ main (int argc, char **argv) ...@@ -227,7 +229,9 @@ main (int argc, char **argv)
if ((error = FT_New_Face (library, argv[1], 0, &face))) if ((error = FT_New_Face (library, argv[1], 0, &face)))
croak ("FT_New_Face", error); croak ("FT_New_Face", error);
printf("----> GSUB <----\n"); printf ("<?xml version=\"1.0\"?>\n");
printf ("<OpenType>\n");
if (!(error = TT_Load_GSUB_Table (face, &gsub, NULL))) if (!(error = TT_Load_GSUB_Table (face, &gsub, NULL)))
{ {
TT_Dump_GSUB_Table (gsub, stdout); TT_Dump_GSUB_Table (gsub, stdout);
...@@ -238,7 +242,6 @@ main (int argc, char **argv) ...@@ -238,7 +242,6 @@ main (int argc, char **argv)
else else
fprintf (stderr, "TT_Load_GSUB_Table %x\n", error); fprintf (stderr, "TT_Load_GSUB_Table %x\n", error);
printf("----> GPOS <----\n");
if (!(error = TT_Load_GPOS_Table (face, &gpos, NULL))) if (!(error = TT_Load_GPOS_Table (face, &gpos, NULL)))
{ {
TT_Dump_GPOS_Table (gpos, stdout); TT_Dump_GPOS_Table (gpos, stdout);
...@@ -249,6 +252,8 @@ main (int argc, char **argv) ...@@ -249,6 +252,8 @@ main (int argc, char **argv)
else else
fprintf (stderr, "TT_Load_GPOS_Table %x\n", error); fprintf (stderr, "TT_Load_GPOS_Table %x\n", error);
printf ("</OpenType>\n");
#if 0 #if 0
select_cmap (face); select_cmap (face);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册