summaryrefslogtreecommitdiff
path: root/Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc')
-rw-r--r--Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc73
1 files changed, 47 insertions, 26 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc b/Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc
index 9ae636226ae..c04b52f937a 100644
--- a/Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc
+++ b/Build/source/libs/xpdf/xpdf-src/xpdf/WebFont.cc
@@ -71,8 +71,11 @@ static void writeToFile(void *stream, const char *data, int len) {
fwrite(data, 1, len, (FILE *)stream);
}
-GBool WebFont::writeTTF(const char *fontFilePath) {
- FILE *out;
+static void writeToString(void *stream, const char *data, int len) {
+ ((GString *)stream)->append(data, len);
+}
+
+GBool WebFont::generateTTF(FoFiOutputFunc outFunc, void *stream) {
int *codeToGID;
Guchar *cmapTable;
GBool freeCodeToGID;
@@ -100,22 +103,35 @@ GBool WebFont::writeTTF(const char *fontFilePath) {
if (!cmapTable) {
return gFalse;
}
- if (!(out = fopen(fontFilePath, "wb"))) {
- gfree(cmapTable);
- return gFalse;
- }
- ffTrueType->writeTTF(writeToFile, out, NULL, NULL,
+ ffTrueType->writeTTF(outFunc, stream, NULL, NULL,
cmapTable, cmapTableLength);
- fclose(out);
gfree(cmapTable);
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;
Gushort *widths;
Guchar *cmapTable;
- FILE *out;
int nCodes, nWidths, cmapTableLength;
if (ffType1C) {
@@ -138,27 +154,13 @@ GBool WebFont::writeOTF(const char *fontFilePath) {
widths = makeCIDType0CWidths(codeToGID, nCodes, &nWidths);
gfree(codeToGID);
}
- if (!(out = fopen(fontFilePath, "wb"))) {
- gfree(cmapTable);
- gfree(widths);
- return gFalse;
- }
- ffType1C->convertToOpenType(writeToFile, out,
- nWidths, widths,
+ ffType1C->convertToOpenType(outFunc, stream, nWidths, widths,
cmapTable, cmapTableLength);
- fclose(out);
gfree(cmapTable);
gfree(widths);
} else if (isOpenType) {
- if (!(out = fopen(fontFilePath, "wb"))) {
- return gFalse;
- }
- if (fwrite(fontBuf, 1, fontLength, out) != (Guint)fontLength) {
- fclose(out);
- return gFalse;
- }
- fclose(out);
+ outFunc(stream, fontBuf, fontLength);
} else {
return gFalse;
@@ -167,6 +169,25 @@ GBool WebFont::writeOTF(const char *fontFilePath) {
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,
int *nWidths) {
Gushort *widths;