Commit 5804259f authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

GfxFont::getToUnicode -> const

And we don't need to do the inc/dec ref dance in Annot
since the GfxFont is still alive while we use it and there's
no other users to getToUnicode that may keep the CharCodeToUnicode
for longer time than the GfxFont live
parent 1eb06156
......@@ -36,6 +36,7 @@
// Copyright (C) 2015 Philipp Reinkemeier <philipp.reinkemeier@offis.de>
// Copyright (C) 2015 Tamas Szekeres <szekerest@gmail.com>
// Copyright (C) 2017 Hans-Ulrich Jüttner <huj@froreich-bioscientia.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -3906,13 +3907,12 @@ void Annot::layoutText(GooString *text, GooString *outBuf, int *i,
if (noReencode) {
outBuf->append(uChar);
} else {
CharCodeToUnicode *ccToUnicode = font->getToUnicode();
const CharCodeToUnicode *ccToUnicode = font->getToUnicode();
if (!ccToUnicode) {
// This assumes an identity CMap.
outBuf->append((uChar >> 8) & 0xff);
outBuf->append(uChar & 0xff);
} else if (ccToUnicode->mapToCharCode(&uChar, &c, 1)) {
ccToUnicode->decRefCnt();
if (font->isCIDFont()) {
// TODO: This assumes an identity CMap. It should be extended to
// handle the general case.
......@@ -3923,7 +3923,6 @@ void Annot::layoutText(GooString *text, GooString *outBuf, int *i,
outBuf->append(c);
}
} else {
ccToUnicode->decRefCnt();
error(errSyntaxError, -1, "AnnotWidget::layoutText, cannot convert U+{0:04uX}", uChar);
}
}
......
......@@ -32,6 +32,7 @@
// Copyright (C) 2012, 2017 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2013-2016, 2018 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2014 Olly Betts <olly@survex.com>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -1565,8 +1566,7 @@ int Gfx8BitFont::getNextChar(char *s, int len, CharCode *code,
return 1;
}
CharCodeToUnicode *Gfx8BitFont::getToUnicode() {
ctu->incRefCnt();
const CharCodeToUnicode *Gfx8BitFont::getToUnicode() const {
return ctu;
}
......@@ -2125,10 +2125,7 @@ int GfxCIDFont::getWMode() {
return cMap ? cMap->getWMode() : 0;
}
CharCodeToUnicode *GfxCIDFont::getToUnicode() {
if (ctu) {
ctu->incRefCnt();
}
const CharCodeToUnicode *GfxCIDFont::getToUnicode() const {
return ctu;
}
......@@ -2324,7 +2321,7 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
} else {
error(errSyntaxError, -1, "Unknown character collection {0:t}\n",
getCollection());
if ((ctu = getToUnicode()) != nullptr) {
if (ctu) {
CharCode cid;
for (cid = 0;cid < n ;cid++) {
Unicode *ucode;
......@@ -2337,7 +2334,6 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
humap[cid*N_UCS_CANDIDATES+i] = 0;
}
}
ctu->decRefCnt();
}
}
// map CID -> Unicode -> GID
......
......@@ -23,6 +23,7 @@
// Copyright (C) 2011, 2012, 2014 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2015, 2018 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -242,7 +243,7 @@ public:
GBool isBold() { return flags & fontBold; }
// Return the Unicode map.
virtual CharCodeToUnicode *getToUnicode() = 0;
virtual const CharCodeToUnicode *getToUnicode() const = 0;
// Return the font matrix.
double *getFontMatrix() { return fontMat; }
......@@ -337,7 +338,7 @@ public:
char **getEncoding() { return enc; }
// Return the Unicode map.
CharCodeToUnicode *getToUnicode() override;
const CharCodeToUnicode *getToUnicode() const override;
// Return the character name associated with <code>.
char *getCharName(int code) { return enc[code]; }
......@@ -402,7 +403,7 @@ public:
int getWMode() override;
// Return the Unicode map.
CharCodeToUnicode *getToUnicode() override;
const CharCodeToUnicode *getToUnicode() const override;
// Get the collection name (<registry>-<ordering>).
GooString *getCollection();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment