📄 disasm.c
字号:
/* Pango * disasm.c: Dump OpenType layout tables * * Copyright (C) 2000 Red Hat Software * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include <stdarg.h>#include "disasm.h"#define G_HAVE_GNUC_VARARGS#ifdef G_HAVE_ISO_VARARGS#define DUMP(...) dump (stream, indent, __VA_ARGS__)#elif defined (G_HAVE_GNUC_VARARGS)#define DUMP(args...) dump (stream, indent, args)#endif#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_FGLYPH(strct,fld) dump (stream, indent, "<" #fld ">%#4x</" #fld ">\n", (strct)->fld)#define DEF_DUMP(type) static void Dump_ ## type (TTO_ ## type *type, FILE *stream, int indent, FT_Bool 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_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)static voiddo_indent (FILE *stream, int indent){ int i; for (i = 0; i < indent * 3; i++) fputc (' ', stream);}static voiddump (FILE *stream, int indent, const char *format, ...){ va_list list; do_indent (stream, indent); va_start (list, format); vfprintf (stream, format, list); va_end (list);}static voidPrint_Tag (FT_ULong tag, FILE *stream){ fprintf (stream, "%c%c%c%c", (unsigned char)(tag >> 24), (unsigned char)((tag & 0xff0000) >> 16), (unsigned char)((tag & 0xff00) >> 8), (unsigned char)(tag & 0xff));}DEF_DUMP (LangSys){ int i; DUMP_FUINT (LangSys, LookupOrderOffset); DUMP_FUINT (LangSys, ReqFeatureIndex); DUMP_FUINT (LangSys, FeatureCount); for (i=0; i < LangSys->FeatureCount; i++) DUMP("<FeatureIndex>%d</FeatureIndex>\n", LangSys->FeatureIndex[i]);}DEF_DUMP (Script){ int i; RECURSE (DefaultLangSys, LangSys, &Script->DefaultLangSys); DUMP_FUINT (Script, LangSysCount); for (i=0; i < Script->LangSysCount; i++) { do_indent (stream, indent); fprintf (stream, "<LangSysTag>"); Print_Tag (Script->LangSysRecord[i].LangSysTag, stream); fprintf (stream, "</LangSysTag>\n"); RECURSE_NUM (LangSys, i, LangSys, &Script->LangSysRecord[i].LangSys); }}DEF_DUMP (ScriptList){ int i; DUMP_FUINT (ScriptList, ScriptCount); for (i=0; i < ScriptList->ScriptCount; i++) { do_indent (stream, indent); fprintf (stream, "<ScriptTag>"); Print_Tag (ScriptList->ScriptRecord[i].ScriptTag, stream); fprintf (stream, "</ScriptTag>\n"); RECURSE_NUM (Script, i, Script, &ScriptList->ScriptRecord[i].Script); }}DEF_DUMP (Feature){ int i; DUMP_FUINT (Feature, FeatureParams); DUMP_FUINT (Feature, LookupListCount); for (i=0; i < Feature->LookupListCount; i++) DUMP("<LookupIndex>%d</LookupIndex>\n", Feature->LookupListIndex[i]);}DEF_DUMP (MarkArray){ int i; DUMP_FUINT (MarkArray, MarkCount); for (i=0; i < MarkArray->MarkCount; i++) { TTO_MarkRecord *r = &MarkArray->MarkRecord[i]; DUMP("<MarkRecord> <!-- %d -->\n", i); DUMP(" <Class>%d</Class>\n", r->Class ); DUMP(" <Anchor>%d</Anchor>\n", r->MarkAnchor.PosFormat ); DUMP("</MarkRecord>\n"); }}DEF_DUMP (FeatureList){ int i; DUMP_FUINT (FeatureList, FeatureCount); for (i=0; i < FeatureList->FeatureCount; i++) { do_indent (stream, indent); fprintf (stream, "<FeatureTag %d>", i); Print_Tag (FeatureList->FeatureRecord[i].FeatureTag, stream); fprintf (stream, "</FeatureTag>\n"); RECURSE_NUM (Feature, i, Feature, &FeatureList->FeatureRecord[i].Feature); }}DEF_DUMP (Coverage){ DUMP_FUINT (Coverage, CoverageFormat); if (Coverage->CoverageFormat == 1) { int i; DUMP_FUINT (&Coverage->cf.cf1, GlyphCount); for (i = 0; i < Coverage->cf.cf1.GlyphCount; i++) DUMP("<Glyph>%#4x</Glyph> <!-- %d -->\n", Coverage->cf.cf1.GlyphArray[i], i); } else { int i; TTO_CoverageFormat2 *cf2 = &Coverage->cf.cf2; for ( i = 0; i < cf2->RangeCount; i++ ) { DUMP("<Glyph>%4x - %4x</Glyph>\n", cf2->RangeRecord[i].Start, cf2->RangeRecord[i].End ); } }}DEF_DUMP (ClassDefinition){ DUMP_FUINT( ClassDefinition, ClassFormat ); DUMP_FUINT( ClassDefinition, loaded ); if (ClassDefinition->ClassFormat == 1) { int i; TTO_ClassDefFormat1 *ClassDefFormat1 = &ClassDefinition->cd.cd1; DUMP("<ClassDefinition>\n"); DUMP_FUINT( ClassDefFormat1, StartGlyph ); DUMP_FUINT( ClassDefFormat1, GlyphCount ); for ( i = 0; i < ClassDefFormat1->GlyphCount; i++ ) { DUMP(" <Class>%d</Class> <!-- %x -->", ClassDefFormat1->ClassValueArray[i], ClassDefFormat1->StartGlyph+i ); } } else if (ClassDefinition->ClassFormat == 2) { int i; TTO_ClassDefFormat2 *ClassDefFormat2 = &ClassDefinition->cd.cd2; DUMP_FUINT (ClassDefFormat2, ClassRangeCount); for (i = 0; i < ClassDefFormat2->ClassRangeCount; i++) { DUMP("<ClassRangeRecord> <!-- %d -->\n", i); DUMP(" <Start>%#4x</Start> \n", ClassDefFormat2->ClassRangeRecord[i].Start); DUMP(" <End>%#4x</End>\n", ClassDefFormat2->ClassRangeRecord[i].End); DUMP(" <Class>%#4x</Class>\n", ClassDefFormat2->ClassRangeRecord[i].Class); DUMP("</ClassRangeRecord>\n"); } } else { printf("invalid class def table!!!\n"); }}DEF_DUMP (ChainSubClassSet){ int i; DUMP("<ChainSubClassSet>\n"); DUMP_FUINT( ChainSubClassSet, ChainSubClassRuleCount ); indent++; for ( i = 0; i < ChainSubClassSet->ChainSubClassRuleCount; i++ ) { int j; TTO_ChainSubClassRule *rule = &ChainSubClassSet->ChainSubClassRule[i]; DUMP("<ChainSubClassRule> <!-- %d -->\n", i ); indent++; DUMP("<Backtrack> <!-- %d -->\n", rule->BacktrackGlyphCount ); for ( j = 0; j < rule->BacktrackGlyphCount; j++ ) DUMP(" %d\n", (int)(FT_UShort) rule->Backtrack[j] ); DUMP("</Backtrack>\n"); DUMP("<Input> <!-- %d -->\n", rule->InputGlyphCount ); for ( j = 0; j < rule->InputGlyphCount-1; j++ ) DUMP(" %d\n", (int)(FT_UShort) rule->Input[j] ); DUMP("</Input>\n"); DUMP("<Lookahead> <!-- %d -->\n", rule->LookaheadGlyphCount ); for ( j = 0; j < rule->LookaheadGlyphCount; j++ ) DUMP(" %d\n", (int) (FT_UShort) rule->Lookahead[j] ); DUMP("</Lookahead>\n"); for ( j = 0; j < rule->SubstCount; j++ ) { TTO_SubstLookupRecord *r = &rule->SubstLookupRecord[j]; DUMP("<SubstLookupRecord> <!-- %d -->\n", j); indent++; DUMP_FUINT( r, SequenceIndex ); DUMP_FUINT( r, LookupListIndex ); indent--; DUMP("</SubstLookupRecord>\n"); } indent--; DUMP("</ChainSubClassRule>\n"); } indent--; DUMP("</ChainSubClassSet>\n");}static voidDump_GSUB_Lookup_Single (TTO_SubTable *subtable, FILE *stream, int indent, FT_Bool is_gsub){ TTO_SingleSubst *SingleSubst = &subtable->st.gsub.single; DUMP_FUINT (SingleSubst, SubstFormat); RECURSE (Coverage, Coverage, &SingleSubst->Coverage); if (SingleSubst->SubstFormat == 1) { DUMP_FINT (&SingleSubst->ssf.ssf1, DeltaGlyphID); } else { int i; DUMP_FINT (&SingleSubst->ssf.ssf2, GlyphCount); for (i=0; i < SingleSubst->ssf.ssf2.GlyphCount; i++) DUMP("<Substitute>%#4x</Substitute> <!-- %d -->\n", SingleSubst->ssf.ssf2.Substitute[i], i); }}DEF_DUMP (Ligature){ int i; DUMP_FGLYPH (Ligature, LigGlyph); DUMP_FUINT (Ligature, ComponentCount); for (i=0; i < Ligature->ComponentCount - 1; i++) DUMP("<Component>%#4x</Component>\n", Ligature->Component[i]);}DEF_DUMP (LigatureSet){ int i; DUMP_FUINT (LigatureSet, LigatureCount); for (i=0; i < LigatureSet->LigatureCount; i++) RECURSE_NUM (Ligature, i, Ligature, &LigatureSet->Ligature[i]);}static voidDump_GSUB_Lookup_Ligature (TTO_SubTable *subtable, FILE *stream, int indent, FT_Bool is_gsub){ int i; TTO_LigatureSubst *LigatureSubst = &subtable->st.gsub.ligature; DUMP_FUINT (LigatureSubst, SubstFormat); RECURSE (Coverage, Coverage, &LigatureSubst->Coverage); DUMP_FUINT (LigatureSubst, LigatureSetCount); for (i=0; i < LigatureSubst->LigatureSetCount; i++) RECURSE_NUM (LigatureSet, i, LigatureSet, &LigatureSubst->LigatureSet[i]);}static voidDump_GSUB_Lookup_ContextSubst1 (TTO_ContextSubstFormat1 *csf, FILE *stream, int indent, FT_Bool is_gsub){ DUMP("Not implemented!!!\n");}static voidDump_GSUB_Lookup_ContextSubst2 (TTO_ContextSubstFormat2 *csf, FILE *stream, int indent, FT_Bool is_gsub){ DUMP_FUINT( csf, MaxContextLength ); RECURSE (Coverage, Coverage, &csf->Coverage); RECURSE( ClassDefinition, ClassDefinition, &csf->ClassDef );}static voidDump_GSUB_Lookup_ContextSubst3 (TTO_ContextSubstFormat3 *csf, FILE *stream, int indent, FT_Bool is_gsub){ DUMP("Not implemented!!!\n");}static voidDump_GSUB_Lookup_Context (TTO_SubTable *subtable, FILE *stream, int indent, FT_Bool is_gsub){ int i; TTO_ContextSubst *ContextSubst = &subtable->st.gsub.context; DUMP_FUINT (ContextSubst, SubstFormat); switch( ContextSubst->SubstFormat ) { case 1: Dump_GSUB_Lookup_ContextSubst1 (&ContextSubst->csf.csf1, stream, indent+2, is_gsub); break; case 2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -