fofi/FoFiTrueType.cc | 76 ++++++++++++++++++++++++++++++--------------------- fofi/FoFiTrueType.h | 9 ++++++ fofi/FoFiType1.cc | 37 ++++++++++++++++++++++++ fofi/FoFiType1.h | 4 ++ fofi/FoFiType1C.cc | 29 +++++++++++++++++++ fofi/FoFiType1C.h | 3 ++ 6 files changed, 127 insertions(+), 31 deletions(-)
New commits: commit 876021b1aa16ad38767a91e1be31c392f368fde2 Author: Carlos Garcia Campos <[email protected]> Date: Thu Sep 1 19:07:01 2011 +0200 xpdf303: Add getFontMatrix() diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc index c132da1..1a171cb 100644 --- a/fofi/FoFiTrueType.cc +++ b/fofi/FoFiTrueType.cc @@ -442,21 +442,32 @@ int FoFiTrueType::mapNameToGID(char *name) { return nameToGID->lookupInt(name); } -int *FoFiTrueType::getCIDToGIDMap(int *nCIDs) { - FoFiType1C *ff; - int *map; +GBool FoFiTrueType::getCFFBlock(char **start, int *length) { int i; - *nCIDs = 0; if (!openTypeCFF) { - return NULL; + return gFalse; } i = seekTable("CFF "); if (!checkRegion(tables[i].offset, tables[i].len)) { + return gFalse; + } + *start = (char *)file + tables[i].offset; + *length = tables[i].len; + return gTrue; +} + +int *FoFiTrueType::getCIDToGIDMap(int *nCIDs) { + char *start; + int length; + FoFiType1C *ff; + int *map; + + *nCIDs = 0; + if (!getCFFBlock(&start, &length)) { return NULL; } - if (!(ff = FoFiType1C::make((char *)file + tables[i].offset, - tables[i].len))) { + if (!(ff = FoFiType1C::make(start, length))) { return NULL; } map = ff->getCIDToGIDMap(nCIDs); @@ -488,6 +499,21 @@ int FoFiTrueType::getEmbeddingRights() { return 3; } +void FoFiTrueType::getFontMatrix(double *mat) { + char *start; + int length; + FoFiType1C *ff; + + if (!getCFFBlock(&start, &length)) { + return; + } + if (!(ff = FoFiType1C::make(start, length))) { + return; + } + ff->getFontMatrix(mat); + delete ff; +} + void FoFiTrueType::convertToType42(char *psName, char **encoding, int *codeToGID, FoFiOutputFunc outputFunc, @@ -532,18 +558,14 @@ void FoFiTrueType::convertToType42(char *psName, char **encoding, void FoFiTrueType::convertToType1(char *psName, const char **newEncoding, GBool ascii, FoFiOutputFunc outputFunc, void *outputStream) { + char *start; + int length; FoFiType1C *ff; - int i; - if (!openTypeCFF) { - return; - } - i = seekTable("CFF "); - if (!checkRegion(tables[i].offset, tables[i].len)) { + if (!getCFFBlock(&start, &length)) { return; } - if (!(ff = FoFiType1C::make((char *)file + tables[i].offset, - tables[i].len))) { + if (!(ff = FoFiType1C::make(start, length))) { return; } ff->convertToType1(psName, newEncoding, ascii, outputFunc, outputStream); @@ -683,18 +705,14 @@ void FoFiTrueType::convertToCIDType2(char *psName, void FoFiTrueType::convertToCIDType0(char *psName, FoFiOutputFunc outputFunc, void *outputStream) { + char *start; + int length; FoFiType1C *ff; - int i; - if (!openTypeCFF) { + if (!getCFFBlock(&start, &length)) { return; } - i = seekTable("CFF "); - if (!checkRegion(tables[i].offset, tables[i].len)) { - return; - } - if (!(ff = FoFiType1C::make((char *)file + tables[i].offset, - tables[i].len))) { + if (!(ff = FoFiType1C::make(start, length))) { return; } ff->convertToCIDType0(psName, outputFunc, outputStream); @@ -808,18 +826,14 @@ void FoFiTrueType::convertToType0(char *psName, int *cidMap, int nCIDs, void FoFiTrueType::convertToType0(char *psName, FoFiOutputFunc outputFunc, void *outputStream) { + char *start; + int length; FoFiType1C *ff; - int i; - if (!openTypeCFF) { - return; - } - i = seekTable("CFF "); - if (!checkRegion(tables[i].offset, tables[i].len)) { + if (!getCFFBlock(&start, &length)) { return; } - if (!(ff = FoFiType1C::make((char *)file + tables[i].offset, - tables[i].len))) { + if (!(ff = FoFiType1C::make(start, length))) { return; } ff->convertToType0(psName, outputFunc, outputStream); diff --git a/fofi/FoFiTrueType.h b/fofi/FoFiTrueType.h index 7a53ebc..76be424 100644 --- a/fofi/FoFiTrueType.h +++ b/fofi/FoFiTrueType.h @@ -96,6 +96,10 @@ public: // * 0: restricted license embedding int getEmbeddingRights(); + // Return the font matrix as an array of six numbers. (Only useful + // for OpenType CFF fonts.) + void getFontMatrix(double *mat); + // Convert to a Type 42 font, suitable for embedding in a PostScript // file. <psName> will be used as the PostScript font name (so we // don't need to depend on the 'name' table in the font). The @@ -156,6 +160,11 @@ public: void writeTTF(FoFiOutputFunc outputFunc, void *outputStream, char *name = NULL, int *codeToGID = NULL); + // Returns a pointer to the CFF font embedded in this OpenType font. + // If successful, sets *<start> and *<length>, and returns true. + // Otherwise returns false. (Only useful for OpenType CFF fonts). + GBool getCFFBlock(char **start, int *length); + int setupGSUB(const char *tagName); private: diff --git a/fofi/FoFiType1.cc b/fofi/FoFiType1.cc index 00f2cf9..d47f543 100644 --- a/fofi/FoFiType1.cc +++ b/fofi/FoFiType1.cc @@ -59,6 +59,12 @@ FoFiType1::FoFiType1(char *fileA, int lenA, GBool freeFileDataA): { name = NULL; encoding = NULL; + fontMatrix[0] = 0.001; + fontMatrix[1] = 0; + fontMatrix[2] = 0; + fontMatrix[3] = 0.001; + fontMatrix[4] = 0; + fontMatrix[5] = 0; parsed = gFalse; } @@ -90,6 +96,17 @@ char **FoFiType1::getEncoding() { return encoding; } +void FoFiType1::getFontMatrix(double *mat) { + int i; + + if (!parsed) { + parse(); + } + for (i = 0; i < 6; ++i) { + mat[i] = fontMatrix[i]; + } +} + void FoFiType1::writeEncoded(const char **newEncoding, FoFiOutputFunc outputFunc, void *outputStream) { char buf[512]; @@ -195,7 +212,9 @@ void FoFiType1::parse() { char c; int n, code, i, j; char *tokptr; + GBool gotMatrix; + gotMatrix = gFalse; for (i = 1, line = (char *)file; i <= 100 && line && (!name || !encoding); ++i) { @@ -281,6 +300,24 @@ void FoFiType1::parse() { } //~ check for getinterval/putinterval junk + } else if (!gotMatrix && !strncmp(line, "/FontMatrix", 11)) { + strncpy(buf, line + 11, 255); + buf[255] = '\0'; + if ((p = strchr(buf, '['))) { + ++p; + if ((p2 = strchr(p, ']'))) { + *p2 = '\0'; + for (j = 0; j < 6; ++j) { + if ((p = strtok(j == 0 ? p : (char *)NULL, " \t\n\r"))) { + fontMatrix[j] = atof(p); + } else { + break; + } + } + } + } + gotMatrix = gTrue; + } else { line = getNextLine(line); } diff --git a/fofi/FoFiType1.h b/fofi/FoFiType1.h index 5abdfb2..ae1d73b 100644 --- a/fofi/FoFiType1.h +++ b/fofi/FoFiType1.h @@ -38,6 +38,9 @@ public: // be NULL). char **getEncoding(); + // Return the font matrix as an array of six numbers. + void getFontMatrix(double *mat); + // Write a version of the Type 1 font file with a new encoding. void writeEncoded(const char **newEncoding, FoFiOutputFunc outputFunc, void *outputStream); @@ -51,6 +54,7 @@ private: char *name; char **encoding; + double fontMatrix[6]; GBool parsed; }; diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc index c97f033..1abc866 100644 --- a/fofi/FoFiType1C.cc +++ b/fofi/FoFiType1C.cc @@ -144,6 +144,35 @@ int *FoFiType1C::getCIDToGIDMap(int *nCIDs) { return map; } +void FoFiType1C::getFontMatrix(double *mat) { + int i; + + if (topDict.firstOp == 0x0c1e && privateDicts[0].hasFontMatrix) { + if (topDict.hasFontMatrix) { + mat[0] = topDict.fontMatrix[0] * privateDicts[0].fontMatrix[0] + + topDict.fontMatrix[1] * privateDicts[0].fontMatrix[2]; + mat[1] = topDict.fontMatrix[0] * privateDicts[0].fontMatrix[1] + + topDict.fontMatrix[1] * privateDicts[0].fontMatrix[3]; + mat[2] = topDict.fontMatrix[2] * privateDicts[0].fontMatrix[0] + + topDict.fontMatrix[3] * privateDicts[0].fontMatrix[2]; + mat[3] = topDict.fontMatrix[2] * privateDicts[0].fontMatrix[1] + + topDict.fontMatrix[3] * privateDicts[0].fontMatrix[3]; + mat[4] = topDict.fontMatrix[4] * privateDicts[0].fontMatrix[0] + + topDict.fontMatrix[5] * privateDicts[0].fontMatrix[2]; + mat[5] = topDict.fontMatrix[4] * privateDicts[0].fontMatrix[1] + + topDict.fontMatrix[5] * privateDicts[0].fontMatrix[3]; + } else { + for (i = 0; i < 6; ++i) { + mat[i] = privateDicts[0].fontMatrix[i]; + } + } + } else { + for (i = 0; i < 6; ++i) { + mat[i] = topDict.fontMatrix[i]; + } + } +} + void FoFiType1C::convertToType1(char *psName, const char **newEncoding, GBool ascii, FoFiOutputFunc outputFunc, void *outputStream) { diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h index 2eb1308..7c8d30a 100644 --- a/fofi/FoFiType1C.h +++ b/fofi/FoFiType1C.h @@ -165,6 +165,9 @@ public: // CIDs in *<nCIDs>. This is only useful for CID fonts. int *getCIDToGIDMap(int *nCIDs); + // Return the font matrix as an array of six numbers. + void getFontMatrix(double *mat); + // Convert to a Type 1 font, suitable for embedding in a PostScript // file. This is only useful with 8-bit fonts. If <newEncoding> is // not NULL, it will be used in place of the encoding in the Type 1C _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
