summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSune Vuorela <sune@vuorela.dk>2025-01-08 08:36:14 +0000
committerAlbert Astals Cid <aacid@kde.org>2025-01-08 08:36:14 +0000
commite3773a71fc7dd6d0e8428989ab7fb8578e53e64b (patch)
tree161ed1a0661204701697607663199a6405232133
parentd54ada8a69284f6562f84fc9e37facf74d7387b1 (diff)
Fonts: cidMap is a vector
-rw-r--r--fofi/FoFiTrueType.cc48
-rw-r--r--fofi/FoFiTrueType.h18
-rw-r--r--fofi/FoFiType1C.cc119
-rw-r--r--fofi/FoFiType1C.h7
-rw-r--r--poppler/CairoFontEngine.cc46
-rw-r--r--poppler/GfxFont.cc42
-rw-r--r--poppler/GfxFont.h13
-rw-r--r--poppler/PSOutputDev.cc86
-rw-r--r--poppler/PSOutputDev.h4
-rw-r--r--poppler/SplashOutputDev.cc36
-rw-r--r--qt5/src/QPainterOutputDev.cc58
-rw-r--r--qt5/src/QPainterOutputDev.h6
-rw-r--r--qt6/src/QPainterOutputDev.cc62
-rw-r--r--qt6/src/QPainterOutputDev.h6
-rw-r--r--splash/SplashFTFont.cc6
-rw-r--r--splash/SplashFTFontEngine.cc10
-rw-r--r--splash/SplashFTFontEngine.h5
-rw-r--r--splash/SplashFTFontFile.cc24
-rw-r--r--splash/SplashFTFontFile.h11
-rw-r--r--splash/SplashFontEngine.cc12
-rw-r--r--splash/SplashFontEngine.h5
-rw-r--r--splash/SplashFontFile.cc2
22 files changed, 243 insertions, 383 deletions
diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index c6cb8233..de061180 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -659,21 +659,19 @@ bool FoFiTrueType::getCFFBlock(char **start, int *length) const
return true;
}
-int *FoFiTrueType::getCIDToGIDMap(int *nCIDs) const
+std::vector<int> FoFiTrueType::getCIDToGIDMap() const
{
char *start;
int length;
FoFiType1C *ff;
- int *map;
- *nCIDs = 0;
if (!getCFFBlock(&start, &length)) {
- return nullptr;
+ return {};
}
if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
- return nullptr;
+ return {};
}
- map = ff->getCIDToGIDMap(nCIDs);
+ std::vector<int> map = ff->getCIDToGIDMap();
delete ff;
return map;
}
@@ -719,7 +717,7 @@ void FoFiTrueType::getFontMatrix(double *mat) const
delete ff;
}
-void FoFiTrueType::convertToType42(const char *psName, char **encoding, int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::convertToType42(const char *psName, char **encoding, const std::vector<int> &codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
{
int maxUsedGlyph;
bool ok;
@@ -769,7 +767,7 @@ void FoFiTrueType::convertToType1(const char *psName, const char **newEncoding,
delete ff;
}
-void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int nCIDs, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::convertToCIDType2(const char *psName, const std::vector<int> &cidMap, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const
{
int cid, maxUsedGlyph;
bool ok;
@@ -797,16 +795,16 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
(*outputFunc)(outputStream, " /Supplement 0 def\n", 20);
(*outputFunc)(outputStream, " end def\n", 10);
(*outputFunc)(outputStream, "/GDBytes 2 def\n", 15);
- if (cidMap) {
- buf = GooString::format("/CIDCount {0:d} def\n", nCIDs);
+ if (!cidMap.empty()) {
+ buf = GooString::format("/CIDCount {0:d} def\n", int(cidMap.size()));
(*outputFunc)(outputStream, buf.c_str(), buf.size());
- if (nCIDs > 32767) {
+ if (cidMap.size() > 32767) {
(*outputFunc)(outputStream, "/CIDMap [", 9);
- for (i = 0; i < nCIDs; i += 32768 - 16) {
+ for (i = 0; i < int(cidMap.size()); i += 32768 - 16) {
(*outputFunc)(outputStream, "<\n", 2);
- for (j = 0; j < 32768 - 16 && i + j < nCIDs; j += 16) {
+ for (j = 0; j < 32768 - 16 && i + j < int(cidMap.size()); j += 16) {
(*outputFunc)(outputStream, " ", 2);
- for (k = 0; k < 16 && i + j + k < nCIDs; ++k) {
+ for (k = 0; k < 16 && i + j + k < int(cidMap.size()); ++k) {
cid = cidMap[i + j + k];
buf = GooString::format("{0:02x}{1:02x}", (cid >> 8) & 0xff, cid & 0xff);
(*outputFunc)(outputStream, buf.c_str(), buf.size());
@@ -819,9 +817,9 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
(*outputFunc)(outputStream, "] def\n", 6);
} else {
(*outputFunc)(outputStream, "/CIDMap <\n", 10);
- for (i = 0; i < nCIDs; i += 16) {
+ for (i = 0; i < int(cidMap.size()); i += 16) {
(*outputFunc)(outputStream, " ", 2);
- for (j = 0; j < 16 && i + j < nCIDs; ++j) {
+ for (j = 0; j < 16 && i + j < int(cidMap.size()); ++j) {
cid = cidMap[i + j];
buf = GooString::format("{0:02x}{1:02x}", (cid >> 8) & 0xff, cid & 0xff);
(*outputFunc)(outputStream, buf.c_str(), buf.size());
@@ -876,7 +874,7 @@ void FoFiTrueType::convertToCIDType2(const char *psName, const int *cidMap, int
(*outputFunc)(outputStream, "CIDFontName currentdict end /CIDFont defineresource pop\n", 56);
}
-void FoFiTrueType::convertToCIDType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::convertToCIDType0(const char *psName, const std::vector<int> &cidMap, FoFiOutputFunc outputFunc, void *outputStream) const
{
char *start;
int length;
@@ -888,11 +886,11 @@ void FoFiTrueType::convertToCIDType0(const char *psName, int *cidMap, int nCIDs,
if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
return;
}
- ff->convertToCIDType0(psName, cidMap, nCIDs, outputFunc, outputStream);
+ ff->convertToCIDType0(psName, cidMap, outputFunc, outputStream);
delete ff;
}
-void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::convertToType0(const char *psName, const std::vector<int> &cidMap, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const
{
GooString *sfntsName;
int maxUsedGlyph, n, i, j;
@@ -926,8 +924,8 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
// referencing zero-length glyphs that we trimmed.
// This allows pdftops to avoid writing huge files while still
// handling the rare PDF that uses a zero-length glyph.
- if (cidMap) {
- n = nCIDs;
+ if (!cidMap.empty()) {
+ n = cidMap.size();
} else if (nGlyphs > maxUsedGlyph + 256) {
if (maxUsedGlyph <= 255) {
n = 256;
@@ -961,7 +959,7 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
(*outputFunc)(outputStream, "/CharStrings 257 dict dup begin\n", 32);
(*outputFunc)(outputStream, "/.notdef 0 def\n", 15);
for (j = 0; j < 256 && i + j < n; ++j) {
- buf = GooString::format("/c{0:02x} {1:d} def\n", j, cidMap ? cidMap[i + j] : i + j);
+ buf = GooString::format("/c{0:02x} {1:d} def\n", j, !cidMap.empty() ? cidMap[i + j] : i + j);
(*outputFunc)(outputStream, buf.c_str(), buf.size());
}
(*outputFunc)(outputStream, "end readonly def\n", 17);
@@ -993,7 +991,7 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, bo
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
}
-void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::convertToType0(const char *psName, const std::vector<int> &cidMap, FoFiOutputFunc outputFunc, void *outputStream) const
{
char *start;
int length;
@@ -1005,7 +1003,7 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, Fo
if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
return;
}
- ff->convertToType0(psName, cidMap, nCIDs, outputFunc, outputStream);
+ ff->convertToType0(psName, cidMap, outputFunc, outputStream);
delete ff;
}
@@ -1034,7 +1032,7 @@ void FoFiTrueType::cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void
(*outputFunc)(outputStream, "readonly def\n", 13);
}
-void FoFiTrueType::cvtCharStrings(char **encoding, const int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
+void FoFiTrueType::cvtCharStrings(char **encoding, const std::vector<int> &codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const
{
const char *name;
char buf2[16];
diff --git a/fofi/FoFiTrueType.h b/fofi/FoFiTrueType.h
index 65f90c98..f2978ea7 100644
--- a/fofi/FoFiTrueType.h
+++ b/fofi/FoFiTrueType.h
@@ -87,10 +87,10 @@ public:
// font does not have a post table.
int mapNameToGID(const char *name) const;
- // Return the mapping from CIDs to GIDs, and return the number of
- // CIDs in *<nCIDs>. This is only useful for CID fonts. (Only
+ // Return the mapping from CIDs to GIDs
+ // This is only useful for CID fonts. (Only
// useful for OpenType CFF fonts.)
- int *getCIDToGIDMap(int *nCIDs) const;
+ std::vector<int> getCIDToGIDMap() const;
// Returns the least restrictive embedding licensing right (as
// defined by the TrueType spec):
@@ -112,7 +112,7 @@ public:
// If <encoding> is NULL, the encoding is unknown or undefined. The
// <codeToGID> array specifies the mapping from char codes to GIDs.
// (Not useful for OpenType CFF fonts.)
- void convertToType42(const char *psName, char **encoding, int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void convertToType42(const char *psName, char **encoding, const std::vector<int> &codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const;
// Convert to a Type 1 font, suitable for embedding in a PostScript
// file. This is only useful with 8-bit fonts. If <newEncoding> is
@@ -128,24 +128,24 @@ public:
// name (so we don't need to depend on the 'name' table in the
// font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
// entries. (Not useful for OpenType CFF fonts.)
- void convertToCIDType2(const char *psName, const int *cidMap, int nCIDs, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void convertToCIDType2(const char *psName, const std::vector<int> &cidMap, bool needVerticalMetrics, FoFiOutputFunc outputFunc, void *outputStream) const;
// Convert to a Type 0 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font
// name. (Only useful for OpenType CFF fonts.)
- void convertToCIDType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void convertToCIDType0(const char *psName, const std::vector<int> &cidMap, FoFiOutputFunc outputFunc, void *outputStream) const;
// Convert to a Type 0 (but non-CID) composite 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 <cidMap> array maps CIDs to GIDs; it has
// <nCIDs> entries. (Not useful for OpenType CFF fonts.)
- void convertToType0(const char *psName, int *cidMap, int nCIDs, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void convertToType0(const char *psName, const std::vector<int> &cidMap, bool needVerticalMetrics, int *maxValidGlyph, FoFiOutputFunc outputFunc, void *outputStream) const;
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
// PostScript font name. (Only useful for OpenType CFF fonts.)
- void convertToType0(const char *psName, int *cidMap, int nCIDs, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void convertToType0(const char *psName, const std::vector<int> &cidMap, FoFiOutputFunc outputFunc, void *outputStream) const;
// Returns a pointer to the CFF font embedded in this OpenType font.
// If successful, sets *<start> and *<length>, and returns true.
@@ -161,7 +161,7 @@ public:
private:
FoFiTrueType(const unsigned char *fileA, int lenA, bool freeFileDataA, int faceIndexA);
void cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void *outputStream) const;
- void cvtCharStrings(char **encoding, const int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const;
+ void cvtCharStrings(char **encoding, const std::vector<int> &codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const;
void cvtSfnts(FoFiOutputFunc outputFunc, void *outputStream, const GooString *name, bool needVerticalMetrics, int *maxUsedGlyph) const;
static void dumpString(std::span<const unsigned char> s, FoFiOutputFunc outputFunc, void *outputStream);
static unsigned int computeTableChecksum(std::span<const unsigned char> data);
diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 636ef7f2..fd996bf2 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -131,15 +131,13 @@ GooString *FoFiType1C::getGlyphName(int gid) const
return new GooString(buf);
}
-int *FoFiType1C::getCIDToGIDMap(int *nCIDs) const
+std::vector<int> FoFiType1C::getCIDToGIDMap() const
{
- int *map;
int n, i;
// a CID font's top dict has ROS as the first operator
if (topDict.firstOp != 0x0c1e) {
- *nCIDs = 0;
- return nullptr;
+ return {};
}
// in a CID font, the charset data is the GID-to-CID mapping, so all
@@ -151,12 +149,11 @@ int *FoFiType1C::getCIDToGIDMap(int *nCIDs) const
}
}
++n;
- map = (int *)gmallocn(n, sizeof(int));
- memset(map, 0, n * sizeof(int));
+ std::vector<int> map;
+ map.resize(n, 0);
for (i = 0; i < nGlyphs; ++i) {
map[charset[i]] = i;
}
- *nCIDs = n;
return map;
}
@@ -438,55 +435,51 @@ void FoFiType1C::convertToType1(const char *psName, const char **newEncoding, bo
(*outputFunc)(outputStream, "cleartomark\n", 12);
}
-void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream)
+void FoFiType1C::convertToCIDType0(const char *psName, const std::vector<int> &codeMap, FoFiOutputFunc outputFunc, void *outputStream)
{
- int *cidMap;
+ std::vector<int> cidMap;
GooString *charStrings;
int *charStringOffsets;
Type1CIndex subrIdx;
Type1CIndexVal val;
- int nCIDs, gdBytes;
+ int gdBytes;
char buf2[256];
bool ok;
- int gid, offset, n, i, j, k;
+ int gid, offset, n, j, k;
// compute the CID count and build the CID-to-GID mapping
- if (codeMap) {
- nCIDs = nCodes;
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCodes; ++i) {
- if (codeMap[i] >= 0 && codeMap[i] < nGlyphs) {
- cidMap[i] = codeMap[i];
+ if (!codeMap.empty()) {
+ cidMap.reserve(codeMap.size());
+ for (int c : codeMap) {
+ if (c >= 0 && c < nGlyphs) {
+ cidMap.push_back(c);
} else {
- cidMap[i] = -1;
+ cidMap.push_back(-1);
}
}
} else if (topDict.firstOp == 0x0c1e) {
- nCIDs = 0;
- for (i = 0; i < nGlyphs && i < charsetLength; ++i) {
+ int nCIDs = 0;
+ for (int i = 0; i < nGlyphs && i < charsetLength; ++i) {
if (charset[i] >= nCIDs) {
nCIDs = charset[i] + 1;
}
}
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCIDs; ++i) {
- cidMap[i] = -1;
- }
- for (i = 0; i < nGlyphs && i < charsetLength; ++i) {
+ cidMap.resize(nCIDs, -1);
+ for (int i = 0; i < nGlyphs && i < charsetLength; ++i) {
cidMap[charset[i]] = i;
}
} else {
- nCIDs = nGlyphs;
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCIDs; ++i) {
+ int nCIDs = nGlyphs;
+ cidMap.resize(nCIDs, 0);
+ for (int i = 0; i < nCIDs; ++i) {
cidMap[i] = i;
}
}
// build the charstrings
charStrings = new GooString();
- charStringOffsets = (int *)gmallocn(nCIDs + 1, sizeof(int));
- for (i = 0; i < nCIDs; ++i) {
+ charStringOffsets = (int *)gmallocn(cidMap.size() + 1, sizeof(int));
+ for (size_t i = 0; i < cidMap.size(); ++i) {
charStringOffsets[i] = charStrings->getLength();
if ((gid = cidMap[i]) >= 0) {
ok = true;
@@ -501,13 +494,13 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
}
}
}
- charStringOffsets[nCIDs] = charStrings->getLength();
+ charStringOffsets[cidMap.size()] = charStrings->getLength();
// compute gdBytes = number of bytes needed for charstring offsets
// (offset size needs to account for the charstring offset table,
// with a worst case of five bytes per entry, plus the charstrings
// themselves)
- i = (nCIDs + 1) * 5 + charStrings->getLength();
+ int i = (cidMap.size() + 1) * 5 + charStrings->getLength();
if (i < 0x100) {
gdBytes = 1;
} else if (i < 0x10000) {
@@ -564,7 +557,7 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
(*outputFunc)(outputStream, "end def\n", 8);
// CIDFont-specific entries
- buf = GooString::format("/CIDCount {0:d} def\n", nCIDs);
+ buf = GooString::format("/CIDCount {0:d} def\n", int(cidMap.size()));
(*outputFunc)(outputStream, buf.c_str(), buf.size());
(*outputFunc)(outputStream, "/FDBytes 1 def\n", 15);
buf = GooString::format("/GDBytes {0:d} def\n", gdBytes);
@@ -684,14 +677,14 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
(*outputFunc)(outputStream, "def\n", 4);
// start the binary section
- offset = (nCIDs + 1) * (1 + gdBytes);
+ offset = (cidMap.size() + 1) * (1 + gdBytes);
buf = GooString::format("(Hex) {0:d} StartData\n", offset + charStrings->getLength());
(*outputFunc)(outputStream, buf.c_str(), buf.size());
// write the charstring offset (CIDMap) table
- for (i = 0; i <= nCIDs; i += 6) {
- for (j = 0; j < 6 && i + j <= nCIDs; ++j) {
- if (i + j < nCIDs && cidMap[i + j] >= 0 && fdSelect) {
+ for (i = 0; i <= int(cidMap.size()); i += 6) {
+ for (j = 0; j < 6 && i + j <= int(cidMap.size()); ++j) {
+ if (i + j < int(cidMap.size()) && cidMap[i + j] >= 0 && fdSelect) {
buf2[0] = (char)fdSelect[cidMap[i + j]];
} else {
buf2[0] = (char)0;
@@ -724,55 +717,49 @@ void FoFiType1C::convertToCIDType0(const char *psName, const int *codeMap, int n
gfree(charStringOffsets);
delete charStrings;
- gfree(cidMap);
}
-void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream)
+void FoFiType1C::convertToType0(const char *psName, const std::vector<int> &codeMap, FoFiOutputFunc outputFunc, void *outputStream)
{
- int *cidMap;
+ std::vector<int> cidMap;
Type1CIndex subrIdx;
Type1CIndexVal val;
- int nCIDs;
Type1CEexecBuf eb;
bool ok;
- int fd, i, j, k;
+ int fd, j, k;
// compute the CID count and build the CID-to-GID mapping
- if (codeMap) {
- nCIDs = nCodes;
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCodes; ++i) {
- if (codeMap[i] >= 0 && codeMap[i] < nGlyphs) {
- cidMap[i] = codeMap[i];
+ if (!codeMap.empty()) {
+ cidMap.reserve(codeMap.size());
+ for (int c : codeMap) {
+ if (c >= 0 && c < nGlyphs) {
+ cidMap.push_back(c);
} else {
- cidMap[i] = -1;
+ cidMap.push_back(-1);
}
}
} else if (topDict.firstOp == 0x0c1e) {
- nCIDs = 0;
- for (i = 0; i < nGlyphs && i < charsetLength; ++i) {
+ int nCIDs = 0;
+ for (int i = 0; i < nGlyphs && i < charsetLength; ++i) {
if (charset[i] >= nCIDs) {
nCIDs = charset[i] + 1;
}
}
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCIDs; ++i) {
- cidMap[i] = -1;
- }
- for (i = 0; i < nGlyphs && i < charsetLength; ++i) {
+ cidMap.resize(nCIDs, -1);
+ for (int i = 0; i < nGlyphs && i < charsetLength; ++i) {
cidMap[charset[i]] = i;
}
} else {
- nCIDs = nGlyphs;
- cidMap = (int *)gmallocn(nCIDs, sizeof(int));
- for (i = 0; i < nCIDs; ++i) {
+ int nCIDs = nGlyphs;
+ cidMap.resize(nCIDs);
+ for (int i = 0; i < nCIDs; ++i) {
cidMap[i] = i;
}
}
if (privateDicts) {
// write the descendant Type 1 fonts
- for (i = 0; i < nCIDs; i += 256) {
+ for (int i = 0; i < int(cidMap.size()); i += 256) {
//~ this assumes that all CIDs in this block have the same FD --
//~ to handle multiple FDs correctly, need to somehow divide the
@@ -780,7 +767,7 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
fd = 0;
// if fdSelect is NULL, we have an 8-bit font, so just leave fd=0
if (fdSelect) {
- for (j = i == 0 ? 1 : 0; j < 256 && i + j < nCIDs; ++j) {
+ for (j = i == 0 ? 1 : 0; j < 256 && i + j < int(cidMap.size()); ++j) {
if (cidMap[i + j] >= 0) {
fd = fdSelect[cidMap[i + j]];
break;
@@ -817,7 +804,7 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
(*outputFunc)(outputStream, buf.c_str(), buf.size());
}
(*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
- for (j = 0; j < 256 && i + j < nCIDs; ++j) {
+ for (j = 0; j < 256 && i + j < int(cidMap.size()); ++j) {
buf = GooString::format("dup {0:d} /c{1:02x} put\n", j, j);
(*outputFunc)(outputStream, buf.c_str(), buf.size());
}
@@ -949,7 +936,7 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
}
// write the CharStrings
- for (j = 0; j < 256 && i + j < nCIDs; ++j) {
+ for (j = 0; j < 256 && i + j < int(cidMap.size()); ++j) {
if (cidMap[i + j] >= 0) {
ok = true;
getIndexVal(&charStringsIdx, cidMap[i + j], &val, &ok);
@@ -994,13 +981,13 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
}
(*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
(*outputFunc)(outputStream, "/Encoding [\n", 12);
- for (i = 0; i < nCIDs; i += 256) {
+ for (int i = 0; i < int(cidMap.size()); i += 256) {
const std::string buf = GooString::format("{0:d}\n", i >> 8);
(*outputFunc)(outputStream, buf.c_str(), buf.size());
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "/FDepVector [\n", 14);
- for (i = 0; i < nCIDs; i += 256) {
+ for (int i = 0; i < int(cidMap.size()); i += 256) {
(*outputFunc)(outputStream, "/", 1);
(*outputFunc)(outputStream, psName, strlen(psName));
const std::string buf = GooString::format("_{0:02x} findfont\n", i >> 8);
@@ -1008,8 +995,6 @@ void FoFiType1C::convertToType0(const char *psName, const int *codeMap, int nCod
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
-
- gfree(cidMap);
}
void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, int offset, int nBytes, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict)
diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h
index f3a9b731..d3720b2c 100644
--- a/fofi/FoFiType1C.h
+++ b/fofi/FoFiType1C.h
@@ -31,6 +31,7 @@
#include "poppler_private_export.h"
#include <set>
+#include <vector>
class GooString;
@@ -175,7 +176,7 @@ public:
// Return the mapping from CIDs to GIDs, and return the number of
// CIDs in *<nCIDs>. This is only useful for CID fonts.
- int *getCIDToGIDMap(int *nCIDs) const;
+ std::vector<int> getCIDToGIDMap() const;
// Return the font matrix as an array of six numbers.
void getFontMatrix(double *mat) const;
@@ -196,7 +197,7 @@ public:
// font's internal CID-to-GID mapping is used
// (3) is <codeMap> is NULL and this is an 8-bit CFF font, then
// the identity CID-to-GID mapping is used
- void convertToCIDType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream);
+ void convertToCIDType0(const char *psName, const std::vector<int> &codeMap, FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
@@ -207,7 +208,7 @@ public:
// font's internal CID-to-GID mapping is used
// (3) is <codeMap> is NULL and this is an 8-bit CFF font, then
// the identity CID-to-GID mapping is used
- void convertToType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream);
+ void convertToType0(const char *psName, const std::vector<int> &codeMap, FoFiOutputFunc outputFunc, void *outputStream);
private:
FoFiType1C(const unsigned char *fileA, int lenA, bool freeFileDataA);
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index ee75d63b..3eccd31e 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -204,7 +204,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
std::string fileName;
int faceIndex = 0;
std::vector<unsigned char> font_data;
- int i, n;
+ int i;
std::optional<GfxFontLoc> fontLoc;
char **enc;
const char *name;
@@ -272,13 +272,9 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
break;
case fontCIDType2:
case fontCIDType2OT:
- if (std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID()) {
- n = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGIDLen();
- if (n) {
- const int *src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID();
- codeToGID.reserve(n);
- codeToGID.insert(codeToGID.begin(), src, src + n);
- }
+ if (std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGIDLen() > 0) {
+ std::vector<int> src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID();
+ codeToGID = std::move(src);
} else {
std::unique_ptr<FoFiTrueType> ff;
if (!font_data.empty()) {
@@ -289,10 +285,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
if (!ff) {
goto err2;
}
- int *src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCodeToGIDMap(ff.get(), &n);
- codeToGID.reserve(n);
- codeToGID.insert(codeToGID.begin(), src, src + n);
- gfree(src);
+ std::vector<int> src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCodeToGIDMap(ff.get());
+ codeToGID = std::move(src);
}
/* Fall through */
case fontTrueType:
@@ -309,10 +303,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
}
/* This might be set already for the CIDType2 case */
if (fontType == fontTrueType || fontType == fontTrueTypeOT) {
- int *src = std::static_pointer_cast<Gfx8BitFont>(gfxFont)->getCodeToGIDMap(ff.get());
- codeToGID.reserve(256);
- codeToGID.insert(codeToGID.begin(), src, src + 256);
- gfree(src);
+ std::vector<int> src = std::static_pointer_cast<Gfx8BitFont>(gfxFont)->getCodeToGIDMap(ff.get());
+ codeToGID = std::move(src);
}
font_face = createFreeTypeFontFace(lib, fileName, std::move(font_data));
if (!font_face) {
@@ -330,10 +322,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
ff1c = FoFiType1C::load(fileName.c_str());
}
if (ff1c) {
- int *src = ff1c->getCIDToGIDMap(&n);
- codeToGID.reserve(n);
- codeToGID.insert(codeToGID.begin(), src, src + n);
- gfree(src);
+ std::vector<int> src = ff1c->getCIDToGIDMap();
+ codeToGID = std::move(src);
delete ff1c;
}
}
@@ -346,13 +336,9 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
break;
case fontCIDType0COT:
- if (std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID()) {
- n = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGIDLen();
- if (n) {
- const int *src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID();
- codeToGID.reserve(n);
- codeToGID.insert(codeToGID.begin(), src, src + n);
- }
+ if (std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGIDLen() > 0) {
+ std::vector<int> src = std::static_pointer_cast<GfxCIDFont>(gfxFont)->getCIDToGID();
+ codeToGID = std::move(src);
}
if (codeToGID.empty()) {
@@ -365,10 +351,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(const std::shared_ptr<GfxFont> &gfx
}
if (ff) {
if (ff->isOpenTypeCFF()) {
- int *src = ff->getCIDToGIDMap(&n);
- codeToGID.reserve(n);
- codeToGID.insert(codeToGID.begin(), src, src + n);
- gfree(src);
+ std::vector<int> src = ff->getCIDToGIDMap();
+ codeToGID = std::move(src);
}
}
}
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 51059b8d..bfe7c9ac 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -1534,9 +1534,9 @@ const CharCodeToUnicode *Gfx8BitFont::getToUnicode() const
return ctu.get();
}
-int *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff)
+std::vector<int> Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff)
{
- int *map;
+ std::vector<int> map;
int cmapPlatform, cmapEncoding;
int unicodeCmap, macRomanCmap, msSymbolCmap, cmap;
bool useMacRoman, useUnicode;
@@ -1544,10 +1544,7 @@ int *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff)
Unicode u;
int code, i, n;
- map = (int *)gmallocn(256, sizeof(int));
- for (i = 0; i < 256; ++i) {
- map[i] = 0;
- }
+ map.resize(256, 0);
// To match up with the Adobe-defined behaviour, we choose a cmap
// like this:
@@ -1718,8 +1715,6 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std:
widths.defWidth = 1.0;
widths.defHeight = -1.0;
widths.defVY = 0.880;
- cidToGID = nullptr;
- cidToGIDLen = 0;
// get the descendant font
obj1 = fontDict->lookup("DescendantFonts");
@@ -1809,16 +1804,9 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std:
// CIDToGIDMap (for embedded TrueType fonts)
obj1 = desFontDict->lookup("CIDToGIDMap");
if (obj1.isStream()) {
- cidToGIDLen = 0;
- unsigned int i = 64;
- cidToGID = (int *)gmallocn(i, sizeof(int));
obj1.streamReset();
while ((c1 = obj1.streamGetChar()) != EOF && (c2 = obj1.streamGetChar()) != EOF) {
- if (cidToGIDLen == i) {
- i *= 2;
- cidToGID = (int *)greallocn(cidToGID, i, sizeof(int));
- }
- cidToGID[cidToGIDLen++] = (c1 << 8) + c2;
+ cidToGID.push_back((c1 << 8) + c2);
}
} else if (!obj1.isName("Identity") && !obj1.isNull()) {
error(errSyntaxError, -1, "Invalid CIDToGIDMap entry in CID font");
@@ -1922,12 +1910,7 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, std::optional<std:
ok = true;
}
-GfxCIDFont::~GfxCIDFont()
-{
- if (cidToGID) {
- gfree(cidToGID);
- }
-}
+GfxCIDFont::~GfxCIDFont() = default;
int GfxCIDFont::getNextChar(const char *s, int len, CharCode *code, Unicode const **u, int *uLen, double *dx, double *dy, double *ox, double *oy) const
{
@@ -2025,7 +2008,7 @@ int GfxCIDFont::mapCodeToGID(FoFiTrueType *ff, int cmapi, Unicode unicode, bool
return gid;
}
-int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
+std::vector<int> GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff)
{
#define N_UCS_CANDIDATES 2
/* space characters */
@@ -2081,7 +2064,6 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
Unicode *humap = nullptr;
Unicode *vumap = nullptr;
Unicode *tumap = nullptr;
- int *codeToGID = nullptr;
int i;
unsigned long code;
int wmode;
@@ -2091,21 +2073,19 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
int cmapPlatform, cmapEncoding;
Ref embID;
- *codeToGIDLen = 0;
if (!ctu || !getCollection()) {
- return nullptr;
+ return {};
}
if (getEmbeddedFontID(&embID)) {
if (getCollection()->cmp("Adobe-Identity") == 0) {
- return nullptr;
+ return {};
}
/* if this font is embedded font,
* CIDToGIDMap should be embedded in PDF file
* and already set. So return it.
*/
- *codeToGIDLen = getCIDToGIDLen();
return getCIDToGID();
}
@@ -2127,7 +2107,7 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
}
}
if (cmap < 0) {
- return nullptr;
+ return {};
}
wmode = getWMode();
@@ -2196,7 +2176,8 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
}
}
// map CID -> Unicode -> GID
- codeToGID = (int *)gmallocn(n, sizeof(int));
+ std::vector<int> codeToGID;
+ codeToGID.resize(n, 0);
for (code = 0; code < n; ++code) {
Unicode unicode;
unsigned long gid;
@@ -2244,7 +2225,6 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen)
}
codeToGID[code] = gid;
}
- *codeToGIDLen = n;
delete[] humap;
delete[] tumap;
delete[] vumap;
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index f70e4093..7e9f1871 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -353,7 +353,7 @@ public:
// Return a char code-to-GID mapping for the provided font file.
// (This is only useful for TrueType fonts.)
- int *getCodeToGIDMap(FoFiTrueType *ff);
+ std::vector<int> getCodeToGIDMap(FoFiTrueType *ff);
// Return the Type 3 CharProc dictionary, or NULL if none.
Dict *getCharProcs();
@@ -406,10 +406,10 @@ public:
// Return the CID-to-GID mapping table. These should only be called
// if type is fontCIDType2.
- int *getCIDToGID() const { return cidToGID; }
- unsigned int getCIDToGIDLen() const { return cidToGIDLen; }
+ const std::vector<int> &getCIDToGID() const { return cidToGID; }
+ unsigned int getCIDToGIDLen() const { return cidToGID.size(); }
- int *getCodeToGIDMap(FoFiTrueType *ff, int *codeToGIDLen);
+ std::vector<int> getCodeToGIDMap(FoFiTrueType *ff);
double getWidth(char *s, int len) const;
@@ -425,9 +425,8 @@ private:
bool ctuUsesCharCode; // true: ctu maps char code to Unicode;
// false: ctu maps CID to Unicode
GfxFontCIDWidths widths; // character widths
- int *cidToGID; // CID --> GID mapping (for embedded
- // TrueType fonts)
- unsigned int cidToGIDLen;
+ std::vector<int> cidToGID; // CID --> GID mapping (for embedded
+ // TrueType fonts)
};
//------------------------------------------------------------------------
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 8c180905..76a5c022 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -916,7 +916,7 @@ struct PST1FontName
struct PSFont8Info
{
Ref fontID;
- int *codeToGID; // code-to-GID mapping for TrueType fonts
+ std::vector<int> codeToGID; // code-to-GID mapping for TrueType fonts
};
// Encoding info for substitute 16-bit font
@@ -1078,7 +1078,6 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *docA, char *psTitleA, con
customCodeCbk = customCodeCbkA;
customCodeCbkData = customCodeCbkDataA;
- font8Info = nullptr;
font16Enc = nullptr;
imgIDs = nullptr;
formIDs = nullptr;
@@ -1134,7 +1133,6 @@ PSOutputDev::PSOutputDev(int fdA, PDFDoc *docA, char *psTitleA, const std::vecto
customCodeCbk = customCodeCbkA;
customCodeCbkData = customCodeCbkDataA;
- font8Info = nullptr;
font16Enc = nullptr;
imgIDs = nullptr;
formIDs = nullptr;
@@ -1171,7 +1169,6 @@ PSOutputDev::PSOutputDev(FoFiOutputFunc outputFuncA, void *outputStreamA, char *
customCodeCbk = customCodeCbkA;
customCodeCbkData = customCodeCbkDataA;
- font8Info = nullptr;
font16Enc = nullptr;
imgIDs = nullptr;
formIDs = nullptr;
@@ -1388,8 +1385,6 @@ void PSOutputDev::postInit()
for (i = 0; i < 14; ++i) {
fontNames.emplace(psBase14SubstFonts[i].psName);
}
- font8InfoLen = 0;
- font8InfoSize = 0;
font16EncLen = 0;
font16EncSize = 0;
imgIDLen = 0;
@@ -1514,12 +1509,6 @@ PSOutputDev::~PSOutputDev()
#endif
}
delete embFontList;
- if (font8Info) {
- for (i = 0; i < font8InfoLen; ++i) {
- gfree(font8Info[i].codeToGID);
- }
- gfree(font8Info);
- }
if (font16Enc) {
for (i = 0; i < font16EncLen; ++i) {
delete font16Enc[i].enc;
@@ -2378,8 +2367,6 @@ void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString
void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName, int faceIndex)
{
- int *codeToGID;
-
// beginning comment
writePSFmt("%%BeginResource: font {0:t}\n", psName);
embFontList->append("%%+ font ");
@@ -2390,16 +2377,10 @@ void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *p
const std::optional<std::vector<unsigned char>> fontBuf = font->readEmbFontFile(xref);
if (fontBuf) {
if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf->data(), fontBuf->size(), faceIndex)) {
- codeToGID = ((Gfx8BitFont *)font)->getCodeToGIDMap(ffTT.get());
+ std::vector<int> codeToGID = ((Gfx8BitFont *)font)->getCodeToGIDMap(ffTT.get());
ffTT->convertToType42(psName->c_str(), ((Gfx8BitFont *)font)->getHasEncoding() ? ((Gfx8BitFont *)font)->getEncoding() : nullptr, codeToGID, outputFunc, outputStream);
- if (codeToGID) {
- if (font8InfoLen >= font8InfoSize) {
- font8InfoSize += 16;
- font8Info = (PSFont8Info *)greallocn(font8Info, font8InfoSize, sizeof(PSFont8Info));
- }
- font8Info[font8InfoLen].fontID = *font->getID();
- font8Info[font8InfoLen].codeToGID = codeToGID;
- ++font8InfoLen;
+ if (!codeToGID.empty()) {
+ font8Info.emplace_back(*font->getID(), std::move(codeToGID));
}
}
}
@@ -2410,8 +2391,6 @@ void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *p
void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, const std::string &fileName, GooString *psName, int faceIndex)
{
- int *codeToGID;
-
// beginning comment
writePSFmt("%%BeginResource: font {0:t}\n", psName);
embFontList->append("%%+ font ");
@@ -2420,16 +2399,10 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, const std::string &fi
// convert it to a Type 42 font
if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::load(fileName.c_str(), faceIndex)) {
- codeToGID = ((Gfx8BitFont *)font)->getCodeToGIDMap(ffTT.get());
+ std::vector<int> codeToGID = ((Gfx8BitFont *)font)->getCodeToGIDMap(ffTT.get());
ffTT->convertToType42(psName->c_str(), ((Gfx8BitFont *)font)->getHasEncoding() ? ((Gfx8BitFont *)font)->getEncoding() : nullptr, codeToGID, outputFunc, outputStream);
- if (codeToGID) {
- if (font8InfoLen >= font8InfoSize) {
- font8InfoSize += 16;
- font8Info = (PSFont8Info *)greallocn(font8Info, font8InfoSize, sizeof(PSFont8Info));
- }
- font8Info[font8InfoLen].fontID = *font->getID();
- font8Info[font8InfoLen].codeToGID = codeToGID;
- ++font8InfoLen;
+ if (!codeToGID.empty()) {
+ font8Info.emplace_back(*font->getID(), std::move(codeToGID));
}
}
@@ -2449,8 +2422,7 @@ void PSOutputDev::updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph)
void PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, const std::string &fileName, GooString *psName, bool needVerticalMetrics, int faceIndex)
{
- int *codeToGID;
- int codeToGIDLen;
+ std::vector<int> codeToGID;
// beginning comment
writePSFmt("%%BeginResource: font {0:t}\n", psName);
@@ -2464,29 +2436,22 @@ void PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, const std::string
// check for embedding permission
if (ffTT->getEmbeddingRights() >= 1) {
- codeToGID = nullptr;
- codeToGIDLen = 0;
- if (((GfxCIDFont *)font)->getCIDToGID()) {
- codeToGIDLen = ((GfxCIDFont *)font)->getCIDToGIDLen();
- if (codeToGIDLen) {
- codeToGID = (int *)gmallocn(codeToGIDLen, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)font)->getCIDToGID(), codeToGIDLen * sizeof(int));
- }
+ if (((GfxCIDFont *)font)->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)font)->getCIDToGID();
} else {
- codeToGID = ((GfxCIDFont *)font)->getCodeToGIDMap(ffTT.get(), &codeToGIDLen);
+ codeToGID = ((GfxCIDFont *)font)->getCodeToGIDMap(ffTT.get());
}
if (ffTT->isOpenTypeCFF()) {
- ffTT->convertToCIDType0(psName->c_str(), codeToGID, codeToGIDLen, outputFunc, outputStream);
+ ffTT->convertToCIDType0(psName->c_str(), codeToGID, outputFunc, outputStream);
} else if (level >= psLevel3) {
// Level 3: use a CID font
- ffTT->convertToCIDType2(psName->c_str(), codeToGID, codeToGIDLen, needVerticalMetrics, outputFunc, outputStream);
+ ffTT->convertToCIDType2(psName->c_str(), codeToGID, needVerticalMetrics, outputFunc, outputStream);
} else {
// otherwise: use a non-CID composite font
int maxValidGlyph = -1;
- ffTT->convertToType0(psName->c_str(), codeToGID, codeToGIDLen, needVerticalMetrics, &maxValidGlyph, outputFunc, outputStream);
+ ffTT->convertToType0(psName->c_str(), codeToGID, needVerticalMetrics, &maxValidGlyph, outputFunc, outputStream);
updateFontMaxValidGlyph(font, maxValidGlyph);
}
- gfree(codeToGID);
} else {
error(errSyntaxError, -1, "TrueType font '{0:s}' does not allow embedding", font->getName() ? font->getName()->c_str() : "(unnamed)");
}
@@ -2522,10 +2487,10 @@ void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *p
if ((ffT1C = FoFiType1C::make(fontBuf->data(), fontBuf->size()))) {
if (level >= psLevel3) {
// Level 3: use a CID font
- ffT1C->convertToCIDType0(psName->c_str(), nullptr, 0, outputFunc, outputStream);
+ ffT1C->convertToCIDType0(psName->c_str(), {}, outputFunc, outputStream);
} else {
// otherwise: use a non-CID composite font
- ffT1C->convertToType0(psName->c_str(), nullptr, 0, outputFunc, outputStream);
+ ffT1C->convertToType0(psName->c_str(), {}, outputFunc, outputStream);
}
delete ffT1C;
}
@@ -2549,11 +2514,11 @@ void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString
if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf->data(), fontBuf->size(), faceIndex)) {
if (level >= psLevel3) {
// Level 3: use a CID font
- ffTT->convertToCIDType2(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), needVerticalMetrics, outputFunc, outputStream);
+ ffTT->convertToCIDType2(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), needVerticalMetrics, outputFunc, outputStream);
} else {
// otherwise: use a non-CID composite font
int maxValidGlyph = -1;
- ffTT->convertToType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), needVerticalMetrics, &maxValidGlyph, outputFunc, outputStream);
+ ffTT->convertToType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), needVerticalMetrics, &maxValidGlyph, outputFunc, outputStream);
updateFontMaxValidGlyph(font, maxValidGlyph);
}
}
@@ -2588,10 +2553,10 @@ void PSOutputDev::setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString
if (ffTT->isOpenTypeCFF()) {
if (level >= psLevel3) {
// Level 3: use a CID font
- ffTT->convertToCIDType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), outputFunc, outputStream);
+ ffTT->convertToCIDType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), outputFunc, outputStream);
} else {
// otherwise: use a non-CID composite font
- ffTT->convertToType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), outputFunc, outputStream);
+ ffTT->convertToType0(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), outputFunc, outputStream);
}
}
}
@@ -4913,7 +4878,7 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s)
{
std::shared_ptr<GfxFont> font;
int wMode;
- int *codeToGID;
+ std::vector<int> codeToGID;
GooString *s2;
double dx, dy, originX, originY;
const char *p;
@@ -4954,7 +4919,6 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s)
// check for a subtitute 16-bit font
uMap = nullptr;
- codeToGID = nullptr;
if (font->isCIDFont()) {
for (i = 0; i < font16EncLen; ++i) {
if (*font->getID() == font16Enc[i].fontID) {
@@ -4969,9 +4933,9 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s)
// check for a code-to-GID map
} else {
- for (i = 0; i < font8InfoLen; ++i) {
- if (*font->getID() == font8Info[i].fontID) {
- codeToGID = font8Info[i].codeToGID;
+ for (const auto &font8 : font8Info) {
+ if (*font->getID() == font8.fontID) {
+ codeToGID = font8.codeToGID;
break;
}
}
@@ -5040,7 +5004,7 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s)
++nChars;
}
} else {
- if (!codeToGID || codeToGID[code] >= 0) {
+ if (codeToGID.empty() || codeToGID[code] >= 0) {
s2->append((char)code);
dxdy[2 * nChars] = dx;
dxdy[2 * nChars + 1] = dy;
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 774d706b..081a3530 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -454,9 +454,7 @@ private:
std::unordered_set<std::string> fontNames; // all used font names
std::unordered_map<std::string, int> perFontMaxValidGlyph; // max valid glyph of each font
std::vector<PST1FontName> t1FontNames; // font names for Type 1/1C fonts
- PSFont8Info *font8Info; // info for 8-bit fonts
- int font8InfoLen; // number of entries in font8Info array
- int font8InfoSize; // size of font8Info array
+ std::vector<PSFont8Info> font8Info; // info for 8-bit fonts
PSFont16Enc *font16Enc; // encodings for substitute 16-bit fonts
int font16EncLen; // number of entries in font16Enc array
int font16EncSize; // size of font16Enc array
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index bebf5ff8..f72aef45 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1921,8 +1921,7 @@ reload:
} else {
ff = FoFiTrueType::make(fontsrc->buf.data(), fontsrc->buf.size(), fontLoc->fontNum);
}
- int *codeToGID;
- const int n = ff ? 256 : 0;
+ std::vector<int> codeToGID;
if (ff) {
codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff.get());
// if we're substituting for a non-TrueType font, we need to mark
@@ -1935,10 +1934,8 @@ reload:
}
}
}
- } else {
- codeToGID = nullptr;
}
- if (!(fontFile = fontEngine->loadTrueTypeFont(std::move(id), fontsrc, codeToGID, n, fontLoc->fontNum))) {
+ if (!(fontFile = fontEngine->loadTrueTypeFont(std::move(id), fontsrc, std::move(codeToGID), fontLoc->fontNum))) {
error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
if (gfxFont->invalidateEmbeddedFont()) {
goto reload;
@@ -1958,19 +1955,13 @@ reload:
}
break;
case fontCIDType0COT: {
- int *codeToGID;
- int n;
- if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
- n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
- codeToGID = (int *)gmallocn(n, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), n * sizeof(int));
+ std::vector<int> codeToGID;
+ if (((GfxCIDFont *)gfxFont)->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont)->getCIDToGID();
} else {
- codeToGID = nullptr;
- n = 0;
}
- if (!(fontFile = fontEngine->loadOpenTypeCFFFont(std::move(id), fontsrc, codeToGID, n, fontLoc->fontNum))) {
+ if (!(fontFile = fontEngine->loadOpenTypeCFFFont(std::move(id), fontsrc, std::move(codeToGID), fontLoc->fontNum))) {
error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
- gfree(codeToGID);
if (gfxFont->invalidateEmbeddedFont()) {
goto reload;
}
@@ -1980,14 +1971,9 @@ reload:
}
case fontCIDType2:
case fontCIDType2OT: {
- int *codeToGID = nullptr;
- int n = 0;
- if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
- n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
- if (n) {
- codeToGID = (int *)gmallocn(n, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(), n * sizeof(int));
- }
+ std::vector<int> codeToGID;
+ if (((GfxCIDFont *)gfxFont)->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont)->getCIDToGID();
} else {
std::unique_ptr<FoFiTrueType> ff;
if (!fileName.empty()) {
@@ -1999,9 +1985,9 @@ reload:
error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
goto err;
}
- codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff.get(), &n);
+ codeToGID = ((GfxCIDFont *)gfxFont)->getCodeToGIDMap(ff.get());
}
- if (!(fontFile = fontEngine->loadTrueTypeFont(std::move(id), fontsrc, codeToGID, n, fontLoc->fontNum))) {
+ if (!(fontFile = fontEngine->loadTrueTypeFont(std::move(id), fontsrc, std::move(codeToGID), fontLoc->fontNum))) {
error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
if (gfxFont->invalidateEmbeddedFont()) {
goto reload;
diff --git a/qt5/src/QPainterOutputDev.cc b/qt5/src/QPainterOutputDev.cc
index 4fe2cfe8..d3252a14 100644
--- a/qt5/src/QPainterOutputDev.cc
+++ b/qt5/src/QPainterOutputDev.cc
@@ -162,10 +162,6 @@ QPainterOutputDev::QPainterOutputDev(QPainter *painter) : m_lastTransparencyGrou
QPainterOutputDev::~QPainterOutputDev()
{
- for (auto &codeToGID : m_codeToGIDCache) {
- gfree(const_cast<int *>(codeToGID.second));
- }
-
FT_Done_FreeType(m_ftLibrary);
}
@@ -174,10 +170,9 @@ void QPainterOutputDev::startDoc(PDFDoc *doc)
xref = doc->getXRef();
m_doc = doc;
- for (auto &codeToGID : m_codeToGIDCache) {
- gfree(const_cast<int *>(codeToGID.second));
- }
m_codeToGIDCache.clear();
+ m_codeToGIDStack = {};
+ m_codeToGID = nullptr;
}
void QPainterOutputDev::startPage(int pageNum, GfxState *state, XRef *) { }
@@ -515,7 +510,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
if (codeToGIDIt != m_codeToGIDCache.end()) {
- m_codeToGID = codeToGIDIt->second;
+ m_codeToGID = &(codeToGIDIt->second);
} else {
@@ -563,9 +558,9 @@ void QPainterOutputDev::updateFont(GfxState *state)
const char *name;
- int *codeToGID = (int *)gmallocn(256, sizeof(int));
+ std::vector<int> codeToGID;
+ codeToGID.resize(256, 0);
for (int i = 0; i < 256; ++i) {
- codeToGID[i] = 0;
if ((name = ((const char **)((Gfx8BitFont *)gfxFont.get())->getEncoding())[i])) {
codeToGID[i] = (int)FT_Get_Name_Index(freeTypeFace, (char *)name);
if (codeToGID[i] == 0) {
@@ -579,7 +574,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
FT_Done_Face(freeTypeFace);
- m_codeToGIDCache[id] = codeToGID;
+ m_codeToGIDCache[id] = std::move(codeToGID);
break;
}
@@ -587,20 +582,19 @@ void QPainterOutputDev::updateFont(GfxState *state)
case fontTrueTypeOT: {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
- m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : nullptr;
+ m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : std::vector<int> {};
break;
}
case fontCIDType0:
case fontCIDType0C: {
- int *cidToGIDMap = nullptr;
- int nCIDs = 0;
+ std::vector<int> cidToGIDMap;
// check for a CFF font
if (!m_useCIDs) {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(fontBuffer->data(), fontBuffer->size()));
- cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
+ cidToGIDMap = (ff) ? ff->getCIDToGIDMap() : std::vector<int> {};
}
m_codeToGIDCache[id] = cidToGIDMap;
@@ -608,45 +602,37 @@ void QPainterOutputDev::updateFont(GfxState *state)
break;
}
case fontCIDType0COT: {
- int *codeToGID = nullptr;
+ std::vector<int> codeToGID;
- if (((GfxCIDFont *)gfxFont.get())->getCIDToGID()) {
- int codeToGIDLen = ((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen();
- codeToGID = (int *)gmallocn(codeToGIDLen, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
+ if (((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCIDToGID();
}
- int *cidToGIDMap = nullptr;
- int nCIDs = 0;
+ std::vector<int> cidToGIDMap;
- if (!codeToGID && !m_useCIDs) {
+ if (codeToGID.empty() && !m_useCIDs) {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
if (ff && ff->isOpenTypeCFF()) {
- cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
+ cidToGIDMap = ff->getCIDToGIDMap();
}
}
- m_codeToGIDCache[id] = codeToGID ? codeToGID : cidToGIDMap;
+ m_codeToGIDCache[id] = !codeToGID.empty() ? std::move(codeToGID) : std::move(cidToGIDMap);
break;
}
case fontCIDType2:
case fontCIDType2OT: {
- int *codeToGID = nullptr;
- int codeToGIDLen = 0;
- if (((GfxCIDFont *)gfxFont.get())->getCIDToGID()) {
- codeToGIDLen = ((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen();
- if (codeToGIDLen) {
- codeToGID = (int *)gmallocn(codeToGIDLen, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
- }
+ std::vector<int> codeToGID;
+ if (((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCIDToGID();
} else {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
if (!ff) {
return;
}
- codeToGID = ((GfxCIDFont *)gfxFont.get())->getCodeToGIDMap(ff.get(), &codeToGIDLen);
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCodeToGIDMap(ff.get());
}
m_codeToGIDCache[id] = codeToGID;
@@ -658,7 +644,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
return;
}
- m_codeToGID = m_codeToGIDCache[id];
+ m_codeToGID = &m_codeToGIDCache[id];
}
}
@@ -912,7 +898,7 @@ void QPainterOutputDev::drawChar(GfxState *state, double x, double y, double dx,
}
if (!(render & 1)) {
- quint32 glyphIndex = (m_codeToGID) ? m_codeToGID[code] : code;
+ quint32 glyphIndex = (m_codeToGID && code < m_codeToGID->size()) ? m_codeToGID->at(code) : code;
QPointF glyphPosition = QPointF(x - originX, y - originY);
// QGlyphRun objects can hold an entire sequence of glyphs, and it would possibly
diff --git a/qt5/src/QPainterOutputDev.h b/qt5/src/QPainterOutputDev.h
index c8dc1c0c..3440cdd0 100644
--- a/qt5/src/QPainterOutputDev.h
+++ b/qt5/src/QPainterOutputDev.h
@@ -192,11 +192,11 @@ private:
using QPainterFontID = std::pair<Ref, double>;
std::map<QPainterFontID, std::unique_ptr<QRawFont>> m_rawFontCache;
std::map<QPainterFontID, std::unique_ptr<QPainterOutputDevType3Font>> m_type3FontCache;
- std::map<Ref, const int *> m_codeToGIDCache;
+ std::map<Ref, std::vector<int>> m_codeToGIDCache;
// The table that maps character codes to glyph indexes
- const int *m_codeToGID;
- std::stack<const int *> m_codeToGIDStack;
+ std::vector<int> *m_codeToGID;
+ std::stack<std::vector<int> *> m_codeToGIDStack;
FT_Library m_ftLibrary;
// as of FT 2.1.8, CID fonts are indexed by CID instead of GID
diff --git a/qt6/src/QPainterOutputDev.cc b/qt6/src/QPainterOutputDev.cc
index 4fe2cfe8..afc9e596 100644
--- a/qt6/src/QPainterOutputDev.cc
+++ b/qt6/src/QPainterOutputDev.cc
@@ -162,10 +162,6 @@ QPainterOutputDev::QPainterOutputDev(QPainter *painter) : m_lastTransparencyGrou
QPainterOutputDev::~QPainterOutputDev()
{
- for (auto &codeToGID : m_codeToGIDCache) {
- gfree(const_cast<int *>(codeToGID.second));
- }
-
FT_Done_FreeType(m_ftLibrary);
}
@@ -174,10 +170,9 @@ void QPainterOutputDev::startDoc(PDFDoc *doc)
xref = doc->getXRef();
m_doc = doc;
- for (auto &codeToGID : m_codeToGIDCache) {
- gfree(const_cast<int *>(codeToGID.second));
- }
m_codeToGIDCache.clear();
+ m_codeToGIDStack = {};
+ m_codeToGID = nullptr;
}
void QPainterOutputDev::startPage(int pageNum, GfxState *state, XRef *) { }
@@ -515,7 +510,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
if (codeToGIDIt != m_codeToGIDCache.end()) {
- m_codeToGID = codeToGIDIt->second;
+ m_codeToGID = &codeToGIDIt->second;
} else {
@@ -563,9 +558,9 @@ void QPainterOutputDev::updateFont(GfxState *state)
const char *name;
- int *codeToGID = (int *)gmallocn(256, sizeof(int));
+ std::vector<int> codeToGID;
+ codeToGID.resize(256, 0);
for (int i = 0; i < 256; ++i) {
- codeToGID[i] = 0;
if ((name = ((const char **)((Gfx8BitFont *)gfxFont.get())->getEncoding())[i])) {
codeToGID[i] = (int)FT_Get_Name_Index(freeTypeFace, (char *)name);
if (codeToGID[i] == 0) {
@@ -579,7 +574,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
FT_Done_Face(freeTypeFace);
- m_codeToGIDCache[id] = codeToGID;
+ m_codeToGIDCache[id] = std::move(codeToGID);
break;
}
@@ -587,66 +582,59 @@ void QPainterOutputDev::updateFont(GfxState *state)
case fontTrueTypeOT: {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
- m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : nullptr;
+ m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : std::vector<int> {};
break;
}
case fontCIDType0:
case fontCIDType0C: {
- int *cidToGIDMap = nullptr;
- int nCIDs = 0;
+ std::vector<int> cidToGIDMap;
// check for a CFF font
if (!m_useCIDs) {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(fontBuffer->data(), fontBuffer->size()));
- cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
+ cidToGIDMap = (ff) ? ff->getCIDToGIDMap() : std::vector<int> {};
}
- m_codeToGIDCache[id] = cidToGIDMap;
+ m_codeToGIDCache[id] = std::move(cidToGIDMap);
break;
}
case fontCIDType0COT: {
- int *codeToGID = nullptr;
+ std::vector<int> codeToGID;
+ ;
- if (((GfxCIDFont *)gfxFont.get())->getCIDToGID()) {
- int codeToGIDLen = ((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen();
- codeToGID = (int *)gmallocn(codeToGIDLen, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
+ if (((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCIDToGID();
}
- int *cidToGIDMap = nullptr;
- int nCIDs = 0;
+ std::vector<int> cidToGIDMap;
- if (!codeToGID && !m_useCIDs) {
+ if (codeToGID.empty() && !m_useCIDs) {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
if (ff && ff->isOpenTypeCFF()) {
- cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
+ cidToGIDMap = ff->getCIDToGIDMap();
}
}
- m_codeToGIDCache[id] = codeToGID ? codeToGID : cidToGIDMap;
+ m_codeToGIDCache[id] = !codeToGID.empty() ? codeToGID : cidToGIDMap;
break;
}
case fontCIDType2:
case fontCIDType2OT: {
- int *codeToGID = nullptr;
- int codeToGIDLen = 0;
- if (((GfxCIDFont *)gfxFont.get())->getCIDToGID()) {
- codeToGIDLen = ((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen();
- if (codeToGIDLen) {
- codeToGID = (int *)gmallocn(codeToGIDLen, sizeof(int));
- memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
- }
+ std::vector<int> codeToGID;
+ ;
+ if (((GfxCIDFont *)gfxFont.get())->getCIDToGIDLen() > 0) {
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCIDToGID();
} else {
auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str(), fontLoc->fontNum) : FoFiTrueType::make(fontBuffer->data(), fontBuffer->size(), fontLoc->fontNum);
if (!ff) {
return;
}
- codeToGID = ((GfxCIDFont *)gfxFont.get())->getCodeToGIDMap(ff.get(), &codeToGIDLen);
+ codeToGID = ((GfxCIDFont *)gfxFont.get())->getCodeToGIDMap(ff.get());
}
m_codeToGIDCache[id] = codeToGID;
@@ -658,7 +646,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
return;
}
- m_codeToGID = m_codeToGIDCache[id];
+ m_codeToGID = &m_codeToGIDCache[id];
}
}
@@ -912,7 +900,7 @@ void QPainterOutputDev::drawChar(GfxState *state, double x, double y, double dx,
}
if (!(render & 1)) {
- quint32 glyphIndex = (m_codeToGID) ? m_codeToGID[code] : code;
+ quint32 glyphIndex = (m_codeToGID && code < m_codeToGID->size()) ? m_codeToGID->at(code) : code;
QPointF glyphPosition = QPointF(x - originX, y - originY);
// QGlyphRun objects can hold an entire sequence of glyphs, and it would possibly
diff --git a/qt6/src/QPainterOutputDev.h b/qt6/src/QPainterOutputDev.h
index 3c133d64..c06506ec 100644
--- a/qt6/src/QPainterOutputDev.h
+++ b/qt6/src/QPainterOutputDev.h
@@ -192,11 +192,11 @@ private:
using QPainterFontID = std::pair<Ref, double>;
std::map<QPainterFontID, std::unique_ptr<QRawFont>> m_rawFontCache;
std::map<QPainterFontID, std::unique_ptr<QPainterOutputDevType3Font>> m_type3FontCache;
- std::map<Ref, const int *> m_codeToGIDCache;
+ std::map<Ref, std::vector<int>> m_codeToGIDCache;
// The table that maps character codes to glyph indexes
- const int *m_codeToGID;
- std::stack<const int *> m_codeToGIDStack;
+ const std::vector<int> *m_codeToGID;
+ std::stack<const std::vector<int> *> m_codeToGIDStack;
FT_Library m_ftLibrary;
// as of FT 2.1.8, CID fonts are indexed by CID instead of GID
diff --git a/splash/SplashFTFont.cc b/splash/SplashFTFont.cc
index e45bf7b5..6c369b7b 100644
--- a/splash/SplashFTFont.cc
+++ b/splash/SplashFTFont.cc
@@ -206,7 +206,7 @@ bool SplashFTFont::makeGlyph(int c, int xFrac, int yFrac, SplashGlyphBitmap *bit
FT_Set_Transform(ff->face, &matrix, &offset);
slot = ff->face->glyph;
- if (ff->codeToGID && c < ff->codeToGIDLen && c >= 0) {
+ if (c < int(ff->codeToGID.size()) && c >= 0) {
gid = (FT_UInt)ff->codeToGID[c];
} else {
gid = (FT_UInt)c;
@@ -285,7 +285,7 @@ double SplashFTFont::getGlyphAdvance(int c)
ff->face->size = sizeObj;
FT_Set_Transform(ff->face, &identityMatrix, &offset);
- if (ff->codeToGID && c < ff->codeToGIDLen) {
+ if (c < int(ff->codeToGID.size())) {
gid = (FT_UInt)ff->codeToGID[c];
} else {
gid = (FT_UInt)c;
@@ -337,7 +337,7 @@ SplashPath *SplashFTFont::getGlyphPath(int c)
ff->face->size = sizeObj;
FT_Set_Transform(ff->face, &textMatrix, nullptr);
slot = ff->face->glyph;
- if (ff->codeToGID && c < ff->codeToGIDLen && c >= 0) {
+ if (c < int(ff->codeToGID.size()) && c >= 0) {
gid = ff->codeToGID[c];
} else {
gid = (FT_UInt)c;
diff --git a/splash/SplashFTFontEngine.cc b/splash/SplashFTFontEngine.cc
index bc0f1d55..84587c2b 100644
--- a/splash/SplashFTFontEngine.cc
+++ b/splash/SplashFTFontEngine.cc
@@ -83,17 +83,17 @@ SplashFontFile *SplashFTFontEngine::loadOpenTypeT1CFont(std::unique_ptr<SplashFo
SplashFontFile *SplashFTFontEngine::loadCIDFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int faceIndex)
{
- return SplashFTFontFile::loadCIDFont(this, std::move(idA), src, nullptr, 0, faceIndex);
+ return SplashFTFontFile::loadCIDFont(this, std::move(idA), src, {}, faceIndex);
}
-SplashFontFile *SplashFTFontEngine::loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex)
+SplashFontFile *SplashFTFontEngine::loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex)
{
- return SplashFTFontFile::loadCIDFont(this, std::move(idA), src, codeToGID ? codeToGID : nullptr, codeToGID ? codeToGIDLen : 0, faceIndex);
+ return SplashFTFontFile::loadCIDFont(this, std::move(idA), src, std::move(codeToGID), faceIndex);
}
-SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex)
+SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex)
{
SplashFontFile *ret;
- ret = SplashFTFontFile::loadTrueTypeFont(this, std::move(idA), src, codeToGID, codeToGIDLen, faceIndex);
+ ret = SplashFTFontFile::loadTrueTypeFont(this, std::move(idA), src, std::move(codeToGID), faceIndex);
return ret;
}
diff --git a/splash/SplashFTFontEngine.h b/splash/SplashFTFontEngine.h
index 92ae74b7..8a576e0a 100644
--- a/splash/SplashFTFontEngine.h
+++ b/splash/SplashFTFontEngine.h
@@ -30,6 +30,7 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include <memory>
+#include <vector>
class SplashFontFile;
class SplashFontFileID;
@@ -54,8 +55,8 @@ public:
SplashFontFile *loadType1CFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **enc, int faceIndex);
SplashFontFile *loadOpenTypeT1CFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **enc, int faceIndex);
SplashFontFile *loadCIDFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int faceIndex);
- SplashFontFile *loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex);
- SplashFontFile *loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex);
+ SplashFontFile *loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex);
+ SplashFontFile *loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex);
bool getAA() { return aa; }
void setAA(bool aaA) { aa = aaA; }
diff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc
index b04940f2..0c72cfcc 100644
--- a/splash/SplashFTFontFile.cc
+++ b/splash/SplashFTFontFile.cc
@@ -40,7 +40,6 @@
SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **encA, int faceIndexA)
{
FT_Face faceA;
- int *codeToGIDA;
const char *name;
int i;
@@ -53,9 +52,9 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, std
return nullptr;
}
}
- codeToGIDA = (int *)gmallocn(256, sizeof(int));
+ std::vector<int> codeToGIDA;
+ codeToGIDA.resize(256, 0);
for (i = 0; i < 256; ++i) {
- codeToGIDA[i] = 0;
if ((name = encA[i])) {
codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
if (codeToGIDA[i] == 0) {
@@ -67,10 +66,10 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, std
}
}
- return new SplashFTFontFile(engineA, std::move(idA), src, faceA, codeToGIDA, 256, false, true);
+ return new SplashFTFontFile(engineA, std::move(idA), src, faceA, std::move(codeToGIDA), false, true);
}
-SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA, int faceIndexA)
+SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGIDA, int faceIndexA)
{
FT_Face faceA;
@@ -84,10 +83,10 @@ SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, std::
}
}
- return new SplashFTFontFile(engineA, std::move(idA), src, faceA, codeToGIDA, codeToGIDLenA, false, false);
+ return new SplashFTFontFile(engineA, std::move(idA), src, faceA, std::move(codeToGIDA), false, false);
}
-SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA, int faceIndexA)
+SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGIDA, int faceIndexA)
{
FT_Face faceA;
@@ -101,16 +100,14 @@ SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
}
}
- return new SplashFTFontFile(engineA, std::move(idA), src, faceA, codeToGIDA, codeToGIDLenA, true, false);
+ return new SplashFTFontFile(engineA, std::move(idA), src, faceA, std::move(codeToGIDA), true, false);
}
-SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *srcA, FT_Face faceA, int *codeToGIDA, int codeToGIDLenA, bool trueTypeA, bool type1A)
- : SplashFontFile(std::move(idA), srcA)
+SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *srcA, FT_Face faceA, std::vector<int> &&codeToGIDA, bool trueTypeA, bool type1A) : SplashFontFile(std::move(idA), srcA)
{
engine = engineA;
face = faceA;
- codeToGID = codeToGIDA;
- codeToGIDLen = codeToGIDLenA;
+ codeToGID = std::move(codeToGIDA);
trueType = trueTypeA;
type1 = type1A;
}
@@ -120,9 +117,6 @@ SplashFTFontFile::~SplashFTFontFile()
if (face) {
FT_Done_Face(face);
}
- if (codeToGID) {
- gfree(codeToGID);
- }
}
SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat, const SplashCoord *textMat)
diff --git a/splash/SplashFTFontFile.h b/splash/SplashFTFontFile.h
index e985aea0..054194d1 100644
--- a/splash/SplashFTFontFile.h
+++ b/splash/SplashFTFontFile.h
@@ -25,6 +25,8 @@
#ifndef SPLASHFTFONTFILE_H
#define SPLASHFTFONTFILE_H
+#include <vector>
+
#include <ft2build.h>
#include FT_FREETYPE_H
#include "SplashFontFile.h"
@@ -40,8 +42,8 @@ class SplashFTFontFile : public SplashFontFile
{
public:
static SplashFontFile *loadType1Font(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **encA, int faceIndexA);
- static SplashFontFile *loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA, int faceIndexA);
- static SplashFontFile *loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA, int faceIndexA);
+ static SplashFontFile *loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGIDA, int faceIndexA);
+ static SplashFontFile *loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGIDA, int faceIndexA);
~SplashFTFontFile() override;
@@ -50,12 +52,11 @@ public:
SplashFont *makeFont(SplashCoord *mat, const SplashCoord *textMat) override;
private:
- SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, FT_Face faceA, int *codeToGIDA, int codeToGIDLenA, bool trueTypeA, bool type1A);
+ SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, FT_Face faceA, std::vector<int> &&codeToGIDA, bool trueTypeA, bool type1A);
SplashFTFontEngine *engine;
FT_Face face;
- int *codeToGID;
- int codeToGIDLen;
+ std::vector<int> codeToGID;
bool trueType;
bool type1;
diff --git a/splash/SplashFontEngine.cc b/splash/SplashFontEngine.cc
index e262cbc8..2d425802 100644
--- a/splash/SplashFontEngine.cc
+++ b/splash/SplashFontEngine.cc
@@ -159,12 +159,12 @@ SplashFontFile *SplashFontEngine::loadCIDFont(std::unique_ptr<SplashFontFileID>
return fontFile;
}
-SplashFontFile *SplashFontEngine::loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex)
+SplashFontFile *SplashFontEngine::loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex)
{
SplashFontFile *fontFile = nullptr;
if (ftEngine) {
- fontFile = ftEngine->loadOpenTypeCFFFont(std::move(idA), src, codeToGID, codeToGIDLen, faceIndex);
+ fontFile = ftEngine->loadOpenTypeCFFFont(std::move(idA), src, std::move(codeToGID), faceIndex);
}
// delete the (temporary) font file -- with Unix hard link
@@ -178,16 +178,12 @@ SplashFontFile *SplashFontEngine::loadOpenTypeCFFFont(std::unique_ptr<SplashFont
return fontFile;
}
-SplashFontFile *SplashFontEngine::loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex)
+SplashFontFile *SplashFontEngine::loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex)
{
SplashFontFile *fontFile = nullptr;
if (ftEngine) {
- fontFile = ftEngine->loadTrueTypeFont(std::move(idA), src, codeToGID, codeToGIDLen, faceIndex);
- }
-
- if (!fontFile) {
- gfree(codeToGID);
+ fontFile = ftEngine->loadTrueTypeFont(std::move(idA), src, std::move(codeToGID), faceIndex);
}
// delete the (temporary) font file -- with Unix hard link
diff --git a/splash/SplashFontEngine.h b/splash/SplashFontEngine.h
index a5f6c962..a62cfadd 100644
--- a/splash/SplashFontEngine.h
+++ b/splash/SplashFontEngine.h
@@ -30,6 +30,7 @@
#include <array>
#include <memory>
+#include <vector>
#include "SplashTypes.h"
#include "poppler_private_export.h"
@@ -67,8 +68,8 @@ public:
SplashFontFile *loadType1CFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **enc, int faceIndex);
SplashFontFile *loadOpenTypeT1CFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, const char **enc, int faceIndex);
SplashFontFile *loadCIDFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int faceIndex);
- SplashFontFile *loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex);
- SplashFontFile *loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, int *codeToGID, int codeToGIDLen, int faceIndex);
+ SplashFontFile *loadOpenTypeCFFFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex);
+ SplashFontFile *loadTrueTypeFont(std::unique_ptr<SplashFontFileID> idA, SplashFontSrc *src, std::vector<int> &&codeToGID, int faceIndex);
// Get a font - this does a cache lookup first, and if not found,
// creates a new SplashFont object and adds it to the cache. The
diff --git a/splash/SplashFontFile.cc b/splash/SplashFontFile.cc
index 6a37ef5a..42ddfe0b 100644
--- a/splash/SplashFontFile.cc
+++ b/splash/SplashFontFile.cc
@@ -28,8 +28,6 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
-#include "goo/gmem.h"
-#include "goo/GooString.h"
#include "SplashFontFile.h"
#include "SplashFontFileID.h"