Commit 85e43288 authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Replace GooHash by std::unordered_map in PSOutputDev.

parent d5701be9
......@@ -32,6 +32,7 @@
// Copyright (C) 2015 Marek Kasik <mkasik@redhat.com>
// Copyright (C) 2016 Caolán McNamara <caolanm@redhat.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
// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
//
// 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
......@@ -53,7 +54,6 @@
#include <algorithm>
#include "goo/GooString.h"
#include "goo/GooList.h"
#include "goo/GooHash.h"
#include "poppler-config.h"
#include "GlobalParams.h"
#include "Object.h"
......@@ -1108,8 +1108,6 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
customCodeCbkData = customCodeCbkDataA;
fontIDs = nullptr;
fontNames = new GooHash(gTrue);
fontMaxValidGlyph = new GooHash(gTrue);
t1FontNames = nullptr;
font8Info = nullptr;
font16Enc = nullptr;
......@@ -1177,8 +1175,6 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
customCodeCbkData = customCodeCbkDataA;
fontIDs = nullptr;
fontNames = new GooHash(gTrue);
fontMaxValidGlyph = new GooHash(gTrue);
t1FontNames = nullptr;
font8Info = nullptr;
font16Enc = nullptr;
......@@ -1409,7 +1405,7 @@ void PSOutputDev::postInit()
fontIDLen = 0;
fontIDs = (Ref *)gmallocn(fontIDSize, sizeof(Ref));
for (i = 0; i < 14; ++i) {
fontNames->add(new GooString(psBase14SubstFonts[i].psName), 1);
fontNames.emplace(psBase14SubstFonts[i].psName);
}
t1FontNameSize = 64;
t1FontNameLen = 0;
......@@ -1499,8 +1495,6 @@ PSOutputDev::~PSOutputDev() {
if (fontIDs) {
gfree(fontIDs);
}
delete fontNames;
delete fontMaxValidGlyph;
if (t1FontNames) {
for (i = 0; i < t1FontNameLen; ++i) {
delete t1FontNames[i].psName;
......@@ -2128,10 +2122,9 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) {
GBool writePadding = gTrue;
// check if font is already embedded
if (fontNames->lookupInt(psName)) {
if (!fontNames.emplace(psName->toStr()).second) {
return;
}
fontNames->add(psName->copy(), 1);
// get the font stream and info
Object obj1, obj2, obj3;
......@@ -2307,10 +2300,9 @@ void PSOutputDev::setupExternalType1Font(GooString *fileName, GooString *psName)
FILE *fontFile;
int c;
if (fontNames->lookupInt(psName)) {
if (!fontNames.emplace(psName->toStr()).second) {
return;
}
fontNames->add(psName->copy(), 1);
// beginning comment
writePSFmt("%%BeginResource: font {0:t}\n", psName);
......@@ -2546,8 +2538,9 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GooString *fileName,
void PSOutputDev::updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph) {
if (maxValidGlyph >= 0 && font->getName()) {
if (maxValidGlyph > fontMaxValidGlyph->lookupInt(font->getName())) {
fontMaxValidGlyph->replace(font->getName()->copy(), maxValidGlyph);
auto& fontMaxValidGlyph = this->fontMaxValidGlyph[font->getName()->toStr()];
if (fontMaxValidGlyph < maxValidGlyph) {
fontMaxValidGlyph = maxValidGlyph;
}
}
}
......@@ -2872,16 +2865,14 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id) {
if ((s = font->getEmbeddedFontName())) {
psName = filterPSName(s);
if (!fontNames->lookupInt(psName)) {
fontNames->add(psName->copy(), 1);
if (fontNames.emplace(psName->toStr()).second) {
return psName;
}
delete psName;
}
if ((s = font->getName())) {
psName = filterPSName(s);
if (!fontNames->lookupInt(psName)) {
fontNames->add(psName->copy(), 1);
if (fontNames.emplace(psName->toStr()).second) {
return psName;
}
delete psName;
......@@ -2896,7 +2887,7 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, const Ref *id) {
psName->append('_')->append(s);
delete s;
}
fontNames->add(psName->copy(), 1);
fontNames.emplace(psName->toStr());
return psName;
}
......@@ -5042,7 +5033,7 @@ void PSOutputDev::drawString(GfxState *state, const GooString *s) {
if (!(font = state->getFont())) {
return;
}
maxGlyphInt = (font->getName()? fontMaxValidGlyph->lookupInt(font->getName()): 0);
maxGlyphInt = (font->getName() ? fontMaxValidGlyph[font->getName()->toStr()] : 0);
if (maxGlyphInt < 0) maxGlyphInt = 0;
maxGlyph = (CharCode) maxGlyphInt;
wMode = font->getWMode();
......
......@@ -48,8 +48,10 @@
#include <set>
#include <map>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <string>
class GooHash;
class PDFDoc;
class XRef;
class Function;
......@@ -476,8 +478,8 @@ private:
int fontIDLen; // number of entries in fontIDs array
int fontIDSize; // size of fontIDs array
std::set<int> resourceIDs; // list of object IDs of objects containing Resources we've already set up
GooHash *fontNames; // all used font names
GooHash *fontMaxValidGlyph; // max valid glyph of each font
std::unordered_set<std::string> fontNames; // all used font names
std::unordered_map<std::string, int> fontMaxValidGlyph; // max valid glyph of each font
PST1FontName *t1FontNames; // font names for Type 1/1C fonts
int t1FontNameLen; // number of entries in t1FontNames array
int t1FontNameSize; // size of t1FontNames array
......
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