summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp96
1 files changed, 55 insertions, 41 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp
index f04368b9a8f..49f69f54725 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.hpp
@@ -2,7 +2,7 @@
** Font.hpp **
** **
** This file is part of dvisvgm -- a fast DVI to SVG converter **
-** Copyright (C) 2005-2017 Martin Gieseking <martin.gieseking@uos.de> **
+** Copyright (C) 2005-2018 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 **
@@ -21,9 +21,9 @@
#ifndef FONT_HPP
#define FONT_HPP
-#include <map>
#include <memory>
#include <string>
+#include <unordered_map>
#include <vector>
#include "Character.hpp"
#include "CharMapID.hpp"
@@ -40,13 +40,11 @@
#include "ToUnicodeMap.hpp"
#include "VFActions.hpp"
#include "VFReader.hpp"
-
+#include "utility.hpp"
struct FontStyle;
-
-struct GlyphMetrics
-{
+struct GlyphMetrics {
GlyphMetrics () : wl(0), wr(0), h(0), d(0) {}
GlyphMetrics (double wwl, double wwr, double hh, double dd) : wl(wwl), wr(wwr), h(hh), d(dd) {}
double wl, wr, h, d;
@@ -57,7 +55,7 @@ struct GlyphMetrics
class Font {
public:
virtual ~Font () =default;
- virtual Font* clone (double ds, double sc) const =0;
+ virtual std::unique_ptr<Font> clone (double ds, double sc) const =0;
virtual const Font* uniqueFont () const =0;
virtual std::string name () const =0;
virtual double designSize () const =0;
@@ -79,7 +77,7 @@ class Font {
virtual bool verticalLayout () const {return getMetrics() ? getMetrics()->verticalLayout() : false;}
virtual bool verifyChecksums () const {return true;}
virtual int fontIndex () const {return 0;}
- virtual const FontStyle* style () const {return 0;}
+ virtual const FontStyle* style () const {return nullptr;}
virtual Color color () const {return Color::BLACK;}
virtual const FontMap::Entry* fontMapEntry () const;
};
@@ -91,7 +89,7 @@ class Font {
class EmptyFont : public Font {
public:
EmptyFont (const std::string &name) : _fontname(name) {}
- Font* clone (double ds, double sc) const override {return new EmptyFont(*this);}
+ std::unique_ptr<Font> clone (double ds, double sc) const override {return util::make_unique<EmptyFont>(*this);}
const Font* uniqueFont () const override {return this;}
std::string name () const override {return _fontname;}
double designSize () const override {return 10;} // cmr10 design size in pt
@@ -100,8 +98,8 @@ class EmptyFont : public Font {
double charHeight (int c) const override {return 6.833;} // height of cmr10's 'M' in pt
double charDepth (int c) const override {return 0;}
double italicCorr (int c) const override {return 0;}
- const FontMetrics* getMetrics () const override {return 0;}
- const char* path () const override {return 0;}
+ const FontMetrics* getMetrics () const override {return nullptr;}
+ const char* path () const override {return nullptr;}
bool getGlyph (int c, Glyph &glyph, GFGlyphTracer::Callback *cb=0) const override {return false;}
private:
@@ -114,12 +112,12 @@ class PhysicalFont : public virtual Font {
public:
enum class Type {MF, OTF, PFB, TTC, TTF, UNKNOWN};
- static Font* create (const std::string &name, uint32_t checksum, double dsize, double ssize, PhysicalFont::Type type);
- static Font* create (const std::string &name, int fontindex, uint32_t checksum, double dsize, double ssize);
+ static std::unique_ptr<Font> create (const std::string &name, uint32_t checksum, double dsize, double ssize, PhysicalFont::Type type);
+ static std::unique_ptr<Font> create (const std::string &name, int fontindex, uint32_t checksum, double dsize, double ssize);
virtual Type type () const =0;
- virtual bool getGlyph (int c, Glyph &glyph, GFGlyphTracer::Callback *cb=0) const override;
- virtual bool getExactGlyphBox (int c, BoundingBox &bbox, GFGlyphTracer::Callback *cb=0) const;
- virtual bool getExactGlyphBox (int c, GlyphMetrics &metrics, bool vertical, GFGlyphTracer::Callback *cb=0) const;
+ virtual bool getGlyph (int c, Glyph &glyph, GFGlyphTracer::Callback *cb=nullptr) const override;
+ virtual bool getExactGlyphBox (int c, BoundingBox &bbox, GFGlyphTracer::Callback *cb=nullptr) const;
+ virtual bool getExactGlyphBox (int c, GlyphMetrics &metrics, bool vertical, GFGlyphTracer::Callback *cb=nullptr) const;
virtual bool isCIDFont () const;
virtual int hAdvance () const;
virtual std::string familyName () const;
@@ -131,7 +129,7 @@ class PhysicalFont : public virtual Font {
virtual double scaledAscent () const;
virtual int ascent () const;
virtual int descent () const;
- virtual int traceAllGlyphs (bool includeCached, GFGlyphTracer::Callback *cb=0) const;
+ virtual int traceAllGlyphs (bool includeCached, GFGlyphTracer::Callback *cb=nullptr) const;
virtual int collectCharMapIDs (std::vector<CharMapID> &charmapIDs) const;
virtual CharMapID getCharMapID () const =0;
virtual void setCharMapID (const CharMapID &id) {}
@@ -156,12 +154,12 @@ class PhysicalFont : public virtual Font {
class VirtualFont : public virtual Font {
friend class FontManager;
public:
- typedef std::vector<uint8_t> DVIVector;
+ using DVIVector = std::vector<uint8_t>;
public:
- static Font* create (const std::string &name, uint32_t checksum, double dsize, double ssize);
+ static std::unique_ptr<Font> create (const std::string &name, uint32_t checksum, double dsize, double ssize);
virtual const DVIVector* getDVI (int c) const =0;
- bool getGlyph (int c, Glyph &glyph, GFGlyphTracer::Callback *cb=0) const override {return false;}
+ bool getGlyph (int c, Glyph &glyph, GFGlyphTracer::Callback *cb=nullptr) const override {return false;}
protected:
virtual void assignChar (uint32_t c, DVIVector &&dvi) =0;
@@ -193,7 +191,10 @@ class TFMFont : public virtual Font {
class PhysicalFontProxy : public PhysicalFont {
friend class PhysicalFontImpl;
public:
- Font* clone (double ds, double sc) const override {return new PhysicalFontProxy(*this, ds, sc);}
+ std::unique_ptr<Font> clone (double ds, double sc) const override {
+ return std::unique_ptr<PhysicalFontProxy>(new PhysicalFontProxy(*this, ds, sc));
+ }
+
const Font* uniqueFont () const override {return _pf;}
std::string name () const override {return _pf->name();}
double designSize () const override {return _dsize;}
@@ -227,12 +228,15 @@ class PhysicalFontImpl : public PhysicalFont, public TFMFont {
friend class PhysicalFont;
public:
~PhysicalFontImpl();
- Font* clone (double ds, double ss) const override {return new PhysicalFontProxy(this, ds, ss);}
+
+ std::unique_ptr<Font> clone (double ds, double ss) const override {
+ return std::unique_ptr<PhysicalFontProxy>(new PhysicalFontProxy(this, ds, ss));
+ }
+
const Font* uniqueFont () const override {return this;}
Type type () const override {return _filetype;}
int fontIndex() const override {return _fontIndex;}
- const FontStyle* style () const override {return _fontMapEntry ? &_fontMapEntry->style : 0;}
- const FontMap::Entry* fontMapEntry () const override {return _fontMapEntry;}
+ const FontStyle* style () const override;
const FontEncoding* encoding () const override;
uint32_t unicode (uint32_t c) const override;
bool findAndAssignBaseFontMap () override;
@@ -245,17 +249,16 @@ class PhysicalFontImpl : public PhysicalFont, public TFMFont {
private:
Type _filetype;
int _fontIndex;
- const FontMap::Entry *_fontMapEntry;
FontEncodingPair _encodingPair;
CharMapID _charmapID; ///< ID of the font's charmap to use
- const RangeMap *_localCharMap;
+ std::unique_ptr<const RangeMap> _localCharMap;
};
class NativeFont : public PhysicalFont {
public:
- virtual NativeFont* clone (double ptsize, const FontStyle &style, Color color) const =0;
- virtual Font* clone (double ds, double sc) const override =0;
+ virtual std::unique_ptr<NativeFont> clone (double ptsize, const FontStyle &style, Color color) const =0;
+ virtual std::unique_ptr<Font> clone (double ds, double sc) const override =0;
std::string name () const override;
Type type () const override;
double designSize () const override {return _ptsize;}
@@ -264,10 +267,10 @@ class NativeFont : public PhysicalFont {
double charDepth (int c) const override;
double charHeight (int c) const override;
double italicCorr (int c) const override {return 0;}
- const FontMetrics* getMetrics () const override {return 0;}
+ const FontMetrics* getMetrics () const override {return nullptr;}
const FontStyle* style () const override {return &_style;}
Color color () const override {return _color;}
- const FontMap::Entry* fontMapEntry () const override {return 0;}
+ const FontMap::Entry* fontMapEntry () const override {return nullptr;}
static std::string uniqueName (const std::string &path, const FontStyle &style);
protected:
@@ -283,11 +286,14 @@ class NativeFont : public PhysicalFont {
class NativeFontProxy : public NativeFont {
friend class NativeFontImpl;
public:
- NativeFont* clone (double ptsize, const FontStyle &style, Color color) const override {
- return new NativeFontProxy(this, ptsize, style, color);
+ std::unique_ptr<NativeFont> clone (double ptsize, const FontStyle &style, Color color) const override {
+ return std::unique_ptr<NativeFontProxy>(new NativeFontProxy(this, ptsize, style, color));
+ }
+
+ std::unique_ptr<Font> clone (double ds, double sc) const override {
+ return std::unique_ptr<NativeFontProxy>(new NativeFontProxy(this , sc, *style(), color()));
}
- Font* clone (double ds, double sc) const override {return new NativeFontProxy(this , sc, *style(), color());}
const Font* uniqueFont () const override {return _nfont;}
const char* path () const override {return _nfont->path();}
int fontIndex () const override {return _nfont->fontIndex();}
@@ -309,11 +315,14 @@ class NativeFontImpl : public NativeFont {
NativeFontImpl (const std::string &fname, int fontIndex, double ptsize, const FontStyle &style, Color color)
: NativeFont(ptsize, style, color), _path(fname), _fontIndex(fontIndex) {}
- NativeFont* clone (double ptsize, const FontStyle &style, Color color) const override {
- return new NativeFontProxy(this, ptsize, style, color);
+ std::unique_ptr<NativeFont> clone (double ptsize, const FontStyle &style, Color color) const override {
+ return std::unique_ptr<NativeFontProxy>(new NativeFontProxy(this, ptsize, style, color));
+ }
+
+ std::unique_ptr<Font> clone (double ds, double sc) const override {
+ return std::unique_ptr<NativeFontProxy>(new NativeFontProxy(this , sc, *style(), color()));
}
- Font* clone (double ds, double sc) const override {return new NativeFontProxy(this , sc, *style(), color());}
const Font* uniqueFont () const override {return this;}
const char* path () const override {return _path.c_str();}
int fontIndex() const override {return _fontIndex;}
@@ -333,7 +342,10 @@ class NativeFontImpl : public NativeFont {
class VirtualFontProxy : public VirtualFont {
friend class VirtualFontImpl;
public:
- Font* clone (double ds, double ss) const override {return new VirtualFontProxy(*this, ds, ss);}
+ std::unique_ptr<Font> clone (double ds, double ss) const override {
+ return std::unique_ptr<VirtualFontProxy>(new VirtualFontProxy(*this, ds, ss));
+ }
+
const Font* uniqueFont () const override {return _vf;}
std::string name () const override {return _vf->name();}
const DVIVector* getDVI (int c) const override {return _vf->getDVI(c);}
@@ -361,7 +373,10 @@ class VirtualFontProxy : public VirtualFont {
class VirtualFontImpl : public VirtualFont, public TFMFont {
friend class VirtualFont;
public:
- Font* clone (double ds, double ss) const override {return new VirtualFontProxy(this, ds, ss);}
+ std::unique_ptr<Font> clone (double ds, double ss) const override {
+ return std::unique_ptr<VirtualFontProxy>(new VirtualFontProxy(this, ds, ss));
+ }
+
const Font* uniqueFont () const override {return this;}
const DVIVector* getDVI (int c) const override;
const char* path () const override;
@@ -371,12 +386,11 @@ class VirtualFontImpl : public VirtualFont, public TFMFont {
void assignChar (uint32_t c, DVIVector &&dvi) override;
private:
- std::map<uint32_t, DVIVector> _charDefs; ///< dvi subroutines defining the characters
+ std::unordered_map<uint32_t, DVIVector> _charDefs; ///< dvi subroutines defining the characters
};
-struct FontException : public MessageException
-{
+struct FontException : public MessageException {
FontException (const std::string &msg) : MessageException(msg) {}
};