📄 fontfile.cc
字号:
int y, n; n = 0; if (fpA) { if (x >= -32768 && x < 32768) { y = (int)(x * 256.0); buf[0] = 255; buf[1] = (Guchar)(y >> 24); buf[2] = (Guchar)(y >> 16); buf[3] = (Guchar)(y >> 8); buf[4] = (Guchar)y; buf[5] = 255; buf[6] = 0; buf[7] = 0; buf[8] = 1; buf[9] = 0; buf[10] = 12; buf[11] = 12; n = 12; } else { error(-1, "Type 2 fixed point constant out of range"); } } else { y = (int)x; if (y >= -107 && y <= 107) { buf[0] = (Guchar)(y + 139); n = 1; } else if (y > 107 && y <= 1131) { y -= 108; buf[0] = (Guchar)((y >> 8) + 247); buf[1] = (Guchar)(y & 0xff); n = 2; } else if (y < -107 && y >= -1131) { y = -y - 108; buf[0] = (Guchar)((y >> 8) + 251); buf[1] = (Guchar)(y & 0xff); n = 2; } else { buf[0] = 255; buf[1] = (Guchar)(y >> 24); buf[2] = (Guchar)(y >> 16); buf[3] = (Guchar)(y >> 8); buf[4] = (Guchar)y; n = 5; } } charBuf->append((char *)buf, n);}void Type1CFontFile::eexecDumpOp1(int opA) { charBuf->append((char)opA);}void Type1CFontFile::eexecDumpOp2(int opA) { charBuf->append((char)12); charBuf->append((char)opA);}void Type1CFontFile::eexecWriteCharstring(Guchar *s, int n) { Guchar x; int i; // eexec encryption for (i = 0; i < n; ++i) { x = s[i] ^ (r1 >> 8); r1 = (x + r1) * 52845 + 22719; (*outputFunc)(outputStream, &hexChars[x >> 4], 1); (*outputFunc)(outputStream, &hexChars[x & 0x0f], 1); line += 2; if (line == 64) { (*outputFunc)(outputStream, "\n", 1); line = 0; } }}void Type1CFontFile::getDeltaInt(char *buf, char *key, double *opA, int n) { int x, i; sprintf(buf, "/%s [", key); buf += strlen(buf); x = 0; for (i = 0; i < n; ++i) { x += (int)opA[i]; sprintf(buf, "%s%d", i > 0 ? " " : "", x); buf += strlen(buf); } sprintf(buf, "] def\n");}void Type1CFontFile::getDeltaReal(char *buf, char *key, double *opA, int n) { double x; int i; sprintf(buf, "/%s [", key); buf += strlen(buf); x = 0; for (i = 0; i < n; ++i) { x += opA[i]; sprintf(buf, "%s%g", i > 0 ? " " : "", x); buf += strlen(buf); } sprintf(buf, "] def\n");}int Type1CFontFile::getIndexLen(Guchar *indexPtr) { return (int)getWord(indexPtr, 2);}Guchar *Type1CFontFile::getIndexValPtr(Guchar *indexPtr, int i) { int n, offSize; Guchar *idxStartPtr; n = (int)getWord(indexPtr, 2); offSize = indexPtr[2]; idxStartPtr = indexPtr + 3 + (n + 1) * offSize - 1; return idxStartPtr + getWord(indexPtr + 3 + i * offSize, offSize);}Guchar *Type1CFontFile::getIndexEnd(Guchar *indexPtr) { int n, offSize; Guchar *idxStartPtr; n = (int)getWord(indexPtr, 2); offSize = indexPtr[2]; idxStartPtr = indexPtr + 3 + (n + 1) * offSize - 1; return idxStartPtr + getWord(indexPtr + 3 + n * offSize, offSize);}Guint Type1CFontFile::getWord(Guchar *ptr, int size) { Guint x; int i; x = 0; for (i = 0; i < size; ++i) { x = (x << 8) + *ptr++; } return x;}double Type1CFontFile::getNum(Guchar **ptr, GBool *isFP) { static char nybChars[16] = "0123456789.ee -"; int b0, b, nyb0, nyb1; double x; char buf[65]; int i; x = 0; *isFP = gFalse; b0 = (*ptr)[0]; if (b0 < 28) { x = 0; } else if (b0 == 28) { x = ((*ptr)[1] << 8) + (*ptr)[2]; *ptr += 3; } else if (b0 == 29) { x = ((*ptr)[1] << 24) + ((*ptr)[2] << 16) + ((*ptr)[3] << 8) + (*ptr)[4]; *ptr += 5; } else if (b0 == 30) { *ptr += 1; i = 0; do { b = *(*ptr)++; nyb0 = b >> 4; nyb1 = b & 0x0f; if (nyb0 == 0xf) { break; } buf[i++] = nybChars[nyb0]; if (i == 64) { break; } if (nyb0 == 0xc) { buf[i++] = '-'; } if (i == 64) { break; } if (nyb1 == 0xf) { break; } buf[i++] = nybChars[nyb1]; if (i == 64) { break; } if (nyb1 == 0xc) { buf[i++] = '-'; } } while (i < 64); buf[i] = '\0'; x = atof(buf); *isFP = gTrue; } else if (b0 == 31) { x = 0; } else if (b0 < 247) { x = b0 - 139; *ptr += 1; } else if (b0 < 251) { x = ((b0 - 247) << 8) + (*ptr)[1] + 108; *ptr += 2; } else { x = -((b0 - 251) << 8) - (*ptr)[1] - 108; *ptr += 2; } return x;}char *Type1CFontFile::getString(int sid, char *buf) { Guchar *idxPtr0, *idxPtr1; int n; if (sid < 391) { strcpy(buf, type1CStdStrings[sid]); } else { sid -= 391; idxPtr0 = getIndexValPtr(stringIdxPtr, sid); idxPtr1 = getIndexValPtr(stringIdxPtr, sid + 1); if ((n = idxPtr1 - idxPtr0) > 255) { n = 255; } strncpy(buf, (char *)idxPtr0, n); buf[n] = '\0'; } return buf;}//------------------------------------------------------------------------// TrueTypeFontFile//------------------------------------------------------------------------//// Terminology// -----------//// character code = number used as an element of a text string//// character name = glyph name = name for a particular glyph within a// font//// glyph index = position (within some internal table in the font)// where the instructions to draw a particular glyph are// stored//// Type 1 fonts// ------------//// Type 1 fonts contain://// Encoding: array of glyph names, maps char codes to glyph names//// Encoding[charCode] = charName//// CharStrings: dictionary of instructions, keyed by character names,// maps character name to glyph data//// CharStrings[charName] = glyphData//// TrueType fonts// --------------//// TrueType fonts contain://// 'cmap' table: mapping from character code to glyph index; there may// be multiple cmaps in a TrueType font//// cmap[charCode] = glyphIdx//// 'post' table: mapping from glyph index to glyph name//// post[glyphIdx] = glyphName//// Type 42 fonts// -------------//// Type 42 fonts contain://// Encoding: array of glyph names, maps char codes to glyph names//// Encoding[charCode] = charName//// CharStrings: dictionary of glyph indexes, keyed by character names,// maps character name to glyph index//// CharStrings[charName] = glyphIdx//struct TTFontTableHdr { char tag[4]; Guint checksum; Guint offset; Guint length;};struct T42Table { char *tag; // 4-byte tag GBool required; // required by the TrueType spec?};// TrueType tables to be embedded in Type 42 fonts.// NB: the table names must be in alphabetical order here.#define nT42Tables 11static T42Table t42Tables[nT42Tables] = { { "cvt ", gTrue }, { "fpgm", gTrue }, { "glyf", gTrue }, { "head", gTrue }, { "hhea", gTrue }, { "hmtx", gTrue }, { "loca", gTrue }, { "maxp", gTrue }, { "prep", gTrue }, { "vhea", gFalse }, { "vmtx", gFalse }};#define t42HeadTable 3#define t42LocaTable 6#define t42GlyfTable 2// Glyph names in some arbitrary standard that Apple uses for their// TrueType fonts.static char *macGlyphNames[258] = { ".notdef", "null", "CR", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu1", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Ohm", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "increment", "guillemotleft", "guillemotright", "ellipsis", "nbspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -