diff options
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp | 98 |
1 files changed, 45 insertions, 53 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp index 0698e71121f..e91d9c7eaa6 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontMap.cpp @@ -2,7 +2,7 @@ ** FontMap.cpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2016 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2017 Martin Gieseking <martin.gieseking@uos.de> ** ** ** ** This program is free software; you can redistribute it and/or ** ** modify it under the terms of the GNU General Public License as ** @@ -19,28 +19,22 @@ *************************************************************************/ #include <config.h> +#include <algorithm> #include <cstring> #include <fstream> #include <limits> #include <vector> -#include "CMap.h" -#include "Directory.h" -#include "FileFinder.h" -#include "FontManager.h" -#include "FontMap.h" -#include "MapLine.h" -#include "Message.h" -#include "Subfont.h" +#include "CMap.hpp" +#include "Directory.hpp" +#include "FileFinder.hpp" +#include "FontManager.hpp" +#include "FontMap.hpp" +#include "MapLine.hpp" +#include "Message.hpp" +#include "Subfont.hpp" using namespace std; - -FontMap::~FontMap () { - for (Iterator it=_entries.begin(); it != _entries.end(); ++it) - delete it->second; -} - - /** Returns the singleton instance. */ FontMap& FontMap::instance() { static FontMap fontmap; @@ -86,9 +80,9 @@ bool FontMap::read (const string &fname, FontMap::Mode mode) { bool FontMap::read (const string &fname, char modechar) { Mode mode; switch (modechar) { - case '=': mode = FM_REPLACE; break; - case '-': mode = FM_REMOVE; break; - default : mode = FM_APPEND; + case '=': mode = Mode::REPLACE; break; + case '-': mode = Mode::REMOVE; break; + default : mode = Mode::APPEND; } return read(fname, mode); } @@ -100,9 +94,9 @@ bool FontMap::read (const string &fname, char modechar) { * @return true in case of success */ bool FontMap::apply (const MapLine& mapline, FontMap::Mode mode) { switch (mode) { - case FM_APPEND: + case Mode::APPEND: return append(mapline); - case FM_REMOVE: + case Mode::REMOVE: return remove(mapline); default: return replace(mapline); @@ -117,9 +111,9 @@ bool FontMap::apply (const MapLine& mapline, FontMap::Mode mode) { bool FontMap::apply (const MapLine& mapline, char modechar) { Mode mode; switch (modechar) { - case '=': mode = FM_REPLACE; break; - case '-': mode = FM_REMOVE; break; - default : mode = FM_APPEND; + case '=': mode = Mode::REPLACE; break; + case '-': mode = Mode::REMOVE; break; + default : mode = Mode::APPEND; } return apply(mapline, mode); } @@ -146,7 +140,7 @@ bool FontMap::read (const string &fname_seq) { } if (!fname.empty()) { if (!read(fname, modechar)) { - if (const char *path = FileFinder::lookup(fname, false)) + if (const char *path = FileFinder::instance().lookup(fname, false)) found = found || read(path, modechar); else Message::wstream(true) << "map file " << fname << " not found\n"; @@ -163,7 +157,7 @@ bool FontMap::read (const string &fname_seq) { * @param[in] mapline parsed font data * @return true if data has been appended */ bool FontMap::append (const MapLine &mapline) { - bool ret = false; + bool appended = false; if (!mapline.texname().empty()) { if (!mapline.fontfname().empty() || !mapline.encname().empty()) { vector<Subfont*> subfonts; @@ -171,17 +165,17 @@ bool FontMap::append (const MapLine &mapline) { mapline.sfd()->subfonts(subfonts); else subfonts.push_back(0); - for (size_t i=0; i < subfonts.size(); i++) { - string fontname = mapline.texname()+(subfonts[i] ? subfonts[i]->id() : ""); - Iterator it = _entries.find(fontname); + for (Subfont *subfont : subfonts) { + string fontname = mapline.texname()+(subfont ? subfont->id() : ""); + auto it = _entries.find(fontname); if (it == _entries.end()) { - _entries[fontname] = new Entry(mapline, subfonts[i]); - ret = true; + _entries[fontname].reset(new Entry(mapline, subfont)); + appended = true; } } } } - return ret; + return appended; } @@ -200,13 +194,13 @@ bool FontMap::replace (const MapLine &mapline) { mapline.sfd()->subfonts(subfonts); else subfonts.push_back(0); - for (size_t i=0; i < subfonts.size(); i++) { - string fontname = mapline.texname()+(subfonts[i] ? subfonts[i]->id() : ""); - Iterator it = _entries.find(fontname); + for (Subfont *subfont : subfonts) { + string fontname = mapline.texname()+(subfont ? subfont->id() : ""); + auto it = _entries.find(fontname); if (it == _entries.end()) - _entries[fontname] = new Entry(mapline, subfonts[i]); + _entries[fontname].reset(new Entry(mapline, subfont)); else if (!it->second->locked) - *it->second = Entry(mapline, subfonts[i]); + *it->second = Entry(mapline, subfont); } return true; } @@ -217,29 +211,29 @@ bool FontMap::replace (const MapLine &mapline) { * @param[in] mapline parsed font data * @return true if entry has been removed */ bool FontMap::remove (const MapLine &mapline) { - bool ret = false; + bool removed = false; if (!mapline.texname().empty()) { vector<Subfont*> subfonts; if (mapline.sfd()) mapline.sfd()->subfonts(subfonts); else subfonts.push_back(0); - for (size_t i=0; i < subfonts.size(); i++) { - string fontname = mapline.texname()+(subfonts[i] ? subfonts[i]->id() : ""); - Iterator it = _entries.find(fontname); + for (const Subfont *subfont : subfonts) { + string fontname = mapline.texname()+(subfont ? subfont->id() : ""); + auto it = _entries.find(fontname); if (it != _entries.end() && !it->second->locked) { _entries.erase(it); - ret = true; + removed = true; } } } - return ret; + return removed; } ostream& FontMap::write (ostream &os) const { - for (ConstIterator it=_entries.begin(); it != _entries.end(); ++it) - os << it->first << " -> " << it->second->fontname << " [" << it->second->encname << "]\n"; + for (const auto &entry : _entries) + os << entry.first << " -> " << entry.second->fontname << " [" << entry.second->encname << "]\n"; return os; } @@ -261,17 +255,17 @@ void FontMap::readdir (const string &dirname) { * @param[in] fontname name of font whose mapped name is retrieved * @returns name of mapped font */ const FontMap::Entry* FontMap::lookup (const string &fontname) const { - ConstIterator it = _entries.find(fontname); + auto it = _entries.find(fontname); if (it == _entries.end()) return 0; - return it->second; + return it->second.get(); } /** Sets the lock flag for the given font in order to avoid changing the map data of this font. * @param[in] fontname name of font to be locked */ void FontMap::lockFont (const string& fontname) { - Iterator it = _entries.find(fontname); + auto it = _entries.find(fontname); if (it != _entries.end()) it->second->locked = true; } @@ -283,14 +277,12 @@ void FontMap::clear (bool unlocked_only) { if (!unlocked_only) _entries.clear(); else { - Iterator it=_entries.begin(); + auto it=_entries.begin(); while (it != _entries.end()) { if (it->second->locked) ++it; - else { - delete it->second; - _entries.erase(it++); - } + else + it = _entries.erase(it); } } } |