WebFont.cc (xpdf-4.03) | : | WebFont.cc (xpdf-4.04) | ||
---|---|---|---|---|
skipping to change at line 74 | skipping to change at line 74 | |||
} | } | |||
GBool WebFont::canWriteOTF() { | GBool WebFont::canWriteOTF() { | |||
return ffType1C || isOpenType; | return ffType1C || isOpenType; | |||
} | } | |||
static void writeToFile(void *stream, const char *data, int len) { | static void writeToFile(void *stream, const char *data, int len) { | |||
fwrite(data, 1, len, (FILE *)stream); | fwrite(data, 1, len, (FILE *)stream); | |||
} | } | |||
GBool WebFont::writeTTF(const char *fontFilePath) { | static void writeToString(void *stream, const char *data, int len) { | |||
FILE *out; | ((GString *)stream)->append(data, len); | |||
} | ||||
GBool WebFont::generateTTF(FoFiOutputFunc outFunc, void *stream) { | ||||
int *codeToGID; | int *codeToGID; | |||
Guchar *cmapTable; | Guchar *cmapTable; | |||
GBool freeCodeToGID; | GBool freeCodeToGID; | |||
int nCodes, cmapTableLength; | int nCodes, cmapTableLength; | |||
if (!ffTrueType) { | if (!ffTrueType) { | |||
return gFalse; | return gFalse; | |||
} | } | |||
if (gfxFont->isCIDFont()) { | if (gfxFont->isCIDFont()) { | |||
codeToGID = ((GfxCIDFont *)gfxFont)->getCIDToGID(); | codeToGID = ((GfxCIDFont *)gfxFont)->getCIDToGID(); | |||
skipping to change at line 103 | skipping to change at line 106 | |||
nCodes = 256; | nCodes = 256; | |||
freeCodeToGID = gTrue; | freeCodeToGID = gTrue; | |||
} | } | |||
cmapTable = makeUnicodeCmapTable(codeToGID, nCodes, &cmapTableLength); | cmapTable = makeUnicodeCmapTable(codeToGID, nCodes, &cmapTableLength); | |||
if (freeCodeToGID) { | if (freeCodeToGID) { | |||
gfree(codeToGID); | gfree(codeToGID); | |||
} | } | |||
if (!cmapTable) { | if (!cmapTable) { | |||
return gFalse; | return gFalse; | |||
} | } | |||
if (!(out = fopen(fontFilePath, "wb"))) { | ffTrueType->writeTTF(outFunc, stream, NULL, NULL, | |||
gfree(cmapTable); | ||||
return gFalse; | ||||
} | ||||
ffTrueType->writeTTF(writeToFile, out, NULL, NULL, | ||||
cmapTable, cmapTableLength); | cmapTable, cmapTableLength); | |||
fclose(out); | ||||
gfree(cmapTable); | gfree(cmapTable); | |||
return gTrue; | return gTrue; | |||
} | } | |||
GBool WebFont::writeOTF(const char *fontFilePath) { | GBool WebFont::writeTTF(const char *fontFilePath) { | |||
FILE *out = fopen(fontFilePath, "wb"); | ||||
if (!out) { | ||||
return gFalse; | ||||
} | ||||
GBool ret = generateTTF(writeToFile, out); | ||||
fclose(out); | ||||
return ret; | ||||
} | ||||
GString *WebFont::getTTFData() { | ||||
GString *s = new GString(); | ||||
if (!generateTTF(writeToString, s)) { | ||||
delete s; | ||||
return NULL; | ||||
} | ||||
return s; | ||||
} | ||||
GBool WebFont::generateOTF(FoFiOutputFunc outFunc, void *stream) { | ||||
int *codeToGID; | int *codeToGID; | |||
Gushort *widths; | Gushort *widths; | |||
Guchar *cmapTable; | Guchar *cmapTable; | |||
FILE *out; | ||||
int nCodes, nWidths, cmapTableLength; | int nCodes, nWidths, cmapTableLength; | |||
if (ffType1C) { | if (ffType1C) { | |||
if (gfxFont->getType() == fontType1C) { | if (gfxFont->getType() == fontType1C) { | |||
codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ffType1C); | codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ffType1C); | |||
if (!(cmapTable = makeUnicodeCmapTable(codeToGID, 256, | if (!(cmapTable = makeUnicodeCmapTable(codeToGID, 256, | |||
&cmapTableLength))) { | &cmapTableLength))) { | |||
gfree(codeToGID); | gfree(codeToGID); | |||
return gFalse; | return gFalse; | |||
} | } | |||
skipping to change at line 141 | skipping to change at line 157 | |||
} else { // fontCIDType0C | } else { // fontCIDType0C | |||
codeToGID = ffType1C->getCIDToGIDMap(&nCodes); | codeToGID = ffType1C->getCIDToGIDMap(&nCodes); | |||
if (!(cmapTable = makeUnicodeCmapTable(codeToGID, nCodes, | if (!(cmapTable = makeUnicodeCmapTable(codeToGID, nCodes, | |||
&cmapTableLength))) { | &cmapTableLength))) { | |||
gfree(codeToGID); | gfree(codeToGID); | |||
return gFalse; | return gFalse; | |||
} | } | |||
widths = makeCIDType0CWidths(codeToGID, nCodes, &nWidths); | widths = makeCIDType0CWidths(codeToGID, nCodes, &nWidths); | |||
gfree(codeToGID); | gfree(codeToGID); | |||
} | } | |||
if (!(out = fopen(fontFilePath, "wb"))) { | ffType1C->convertToOpenType(outFunc, stream, nWidths, widths, | |||
gfree(cmapTable); | ||||
gfree(widths); | ||||
return gFalse; | ||||
} | ||||
ffType1C->convertToOpenType(writeToFile, out, | ||||
nWidths, widths, | ||||
cmapTable, cmapTableLength); | cmapTable, cmapTableLength); | |||
fclose(out); | ||||
gfree(cmapTable); | gfree(cmapTable); | |||
gfree(widths); | gfree(widths); | |||
} else if (isOpenType) { | } else if (isOpenType) { | |||
if (!(out = fopen(fontFilePath, "wb"))) { | outFunc(stream, fontBuf, fontLength); | |||
return gFalse; | ||||
} | ||||
if (fwrite(fontBuf, 1, fontLength, out) != (Guint)fontLength) { | ||||
fclose(out); | ||||
return gFalse; | ||||
} | ||||
fclose(out); | ||||
} else { | } else { | |||
return gFalse; | return gFalse; | |||
} | } | |||
return gTrue; | return gTrue; | |||
} | } | |||
GBool WebFont::writeOTF(const char *fontFilePath) { | ||||
FILE *out = fopen(fontFilePath, "wb"); | ||||
if (!out) { | ||||
return gFalse; | ||||
} | ||||
GBool ret = generateOTF(writeToFile, out); | ||||
fclose(out); | ||||
return ret; | ||||
} | ||||
GString *WebFont::getOTFData() { | ||||
GString *s = new GString(); | ||||
if (!generateOTF(writeToString, s)) { | ||||
delete s; | ||||
return NULL; | ||||
} | ||||
return s; | ||||
} | ||||
Gushort *WebFont::makeType1CWidths(int *codeToGID, int nCodes, | Gushort *WebFont::makeType1CWidths(int *codeToGID, int nCodes, | |||
int *nWidths) { | int *nWidths) { | |||
Gushort *widths; | Gushort *widths; | |||
Gushort width; | Gushort width; | |||
int widthsLen, gid, i; | int widthsLen, gid, i; | |||
widthsLen = ffType1C->getNumGlyphs(); | widthsLen = ffType1C->getNumGlyphs(); | |||
widths = (Gushort *)gmallocn(widthsLen, sizeof(Gushort)); | widths = (Gushort *)gmallocn(widthsLen, sizeof(Gushort)); | |||
for (i = 0; i < widthsLen; ++i) { | for (i = 0; i < widthsLen; ++i) { | |||
widths[i] = 0; | widths[i] = 0; | |||
End of changes. 9 change blocks. | ||||
26 lines changed or deleted | 47 lines changed or added |