diff options
author | Karl Berry <karl@freefriends.org> | 2017-01-31 18:37:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-01-31 18:37:40 +0000 |
commit | 4c245316c293169ee655c8e2f922b4bee454f9bc (patch) | |
tree | 2d3b72165f3e7e1298df8dad8b52f119a42228dc /Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp | |
parent | 54a2f67f996dceca3c89276dea798f746b3cacaf (diff) |
import original dvisvgm-2.1
git-svn-id: svn://tug.org/texlive/trunk@43102 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp new file mode 100644 index 00000000000..ade32bec26c --- /dev/null +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/FontManager.hpp @@ -0,0 +1,83 @@ +/************************************************************************* +** FontManager.hpp ** +** ** +** This file is part of dvisvgm -- a fast DVI to SVG converter ** +** 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 ** +** published by the Free Software Foundation; either version 3 of ** +** the License, or (at your option) any later version. ** +** ** +** This program is distributed in the hope that it will be useful, but ** +** WITHOUT ANY WARRANTY; without even the implied warranty of ** +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** +** GNU General Public License for more details. ** +** ** +** You should have received a copy of the GNU General Public License ** +** along with this program; if not, see <http://www.gnu.org/licenses/>. ** +*************************************************************************/ + +#ifndef FONTMANAGER_HPP +#define FONTMANAGER_HPP + +#include <map> +#include <memory> +#include <ostream> +#include <set> +#include <string> +#include <stack> +#include <vector> +#include "Color.hpp" +#include "FontStyle.hpp" + + +class FileFinder; +class Font; +class VirtualFont; + +/** This class provides methods for easy DVI font handling. + * DVI and VF files use local font numbers to reference fonts. For SVG output + * we need a single list with unique IDs of all physical fonts. Characters of + * virtual fonts are completely replaced by their DVI description so they don't + * appear anywhere in the output. */ +class FontManager +{ + typedef std::map<uint32_t,int> Num2IdMap; + typedef std::map<std::string,int> Name2IdMap; + typedef std::map<const VirtualFont*,Num2IdMap> VfNum2IdMap; + typedef std::map<const VirtualFont*, uint32_t> VfFirstFontMap; + typedef std::stack<VirtualFont*> VfStack; + + public: + static FontManager& instance (); + int registerFont (uint32_t fontnum, const std::string &fontname, uint32_t checksum, double dsize, double scale); + int registerFont (uint32_t fontnum, const std::string &fname, double ptsize, const FontStyle &style, Color color); + int registerFont (uint32_t fontnum, std::string fname, int fontIndex, double ptsize, const FontStyle &style, Color color); + Font* getFont (int n) const; + Font* getFont (const std::string &name) const; + Font* getFontById (int id) const; + const VirtualFont* getVF () const; + int fontID (int n) const; + int fontID (const Font *font) const; + int fontID (const std::string &name) const; + int fontnum (int id) const; + int vfFirstFontNum (const VirtualFont *vf) const; + void enterVF (VirtualFont *vf); + void leaveVF (); + void assignVFChar (int c, std::vector<uint8_t> &&dvi); + std::ostream& write (std::ostream &os, Font *font=0, int level=0); + + protected: + FontManager () =default; + + private: + std::vector<std::unique_ptr<Font>> _fonts; ///< all registered Fonts + Num2IdMap _num2id; ///< DVI font number -> fontID + Name2IdMap _name2id; ///< fontname -> fontID + VfNum2IdMap _vfnum2id; + VfStack _vfStack; ///< stack of currently processed virtual fonts + VfFirstFontMap _vfFirstFontMap; ///< VF -> local font number of first font defined in VF +}; + +#endif |