diff options
author | Karl Berry <karl@freefriends.org> | 2023-01-20 01:55:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-01-20 01:55:04 +0000 |
commit | 2c99129a39be3be6622c7efa6826222141d4de1e (patch) | |
tree | 95f4cdda555eef7f4e9a98994ce081e2364a8a4a /Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp | |
parent | 5817f54a04657ab24f46489d2ddb97d47c3bef79 (diff) |
dvisvgm-3.0.1 + patches linked from https://github.com/TeX-Live/texlive-source/pull/59#issuecomment-1397666966
git-svn-id: svn://tug.org/texlive/trunk@65593 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp index 2fa4ce5be98..c60b1628288 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Font.cpp @@ -2,7 +2,7 @@ ** Font.cpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** -** Copyright (C) 2005-2022 Martin Gieseking <martin.gieseking@uos.de> ** +** Copyright (C) 2005-2023 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 ** @@ -18,8 +18,8 @@ ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** *************************************************************************/ +#include <algorithm> #include <cstdlib> -#include <fstream> #include <set> #include <sstream> #include "CMap.hpp" @@ -233,7 +233,8 @@ int PhysicalFont::unitsPerEm() const { } -int PhysicalFont::hAdvance () const { +/** Returns the average horizontal advance width in font units. */ +int PhysicalFont::hAverageAdvance () const { if (type() == Type::MF) return 0; FontEngine::instance().setFont(*this); @@ -241,6 +242,7 @@ int PhysicalFont::hAdvance () const { } +/** Returns the horizontal advance width of a character in font units. */ double PhysicalFont::hAdvance (int c) const { if (type() == Type::MF) return unitsPerEm()*charWidth(c)/designSize(); @@ -252,6 +254,7 @@ double PhysicalFont::hAdvance (int c) const { } +/** Returns the vertical advance width of a character in font units. */ double PhysicalFont::vAdvance (int c) const { if (type() == Type::MF) return unitsPerEm()*charWidth(c)/designSize(); @@ -279,7 +282,8 @@ double PhysicalFont::scaledAscent() const { } -/** Returns the unscaled ascender of the font in design units. */ +/** Returns the unscaled ascender of the font in design units. + * Positive values denote an extension above the baseline.'*/ int PhysicalFont::ascent () const { if (type() == Type::MF) return getMetrics() ? getMetrics()->getAscent()*unitsPerEm()/getMetrics()->getQuad() : 0; @@ -288,7 +292,8 @@ int PhysicalFont::ascent () const { } -/** Returns the unscaled descender of the font in design units. */ +/** Returns the unscaled descender of the font in design units. + * Positive values denote an extension below the baseline. */ int PhysicalFont::descent () const { if (type() == Type::MF) return getMetrics() ? getMetrics()->getDescent()*unitsPerEm()/getMetrics()->getQuad() : 0; @@ -315,6 +320,13 @@ std::string PhysicalFont::styleName () const { } +int PhysicalFont::charIndexByName(const string &charname) const { + if (charname.empty()) + return 0; + FontEngine::instance().setFont(*this); + return FontEngine::instance().getCharIndexByGlyphName(charname.c_str()); +} + /** Extracts the glyph outlines of a given character. * @param[in] c character code of requested glyph @@ -596,7 +608,7 @@ PhysicalFont::Type NativeFont::type () const { return PhysicalFont::Type::OTF; if (ext == "ttf") return PhysicalFont::Type::TTF; - if (ext == "pfb") + if (ext == "pfb" || ext == "pfa") return PhysicalFont::Type::PFB; } } @@ -607,7 +619,7 @@ PhysicalFont::Type NativeFont::type () const { double NativeFont::charWidth (int c) const { FontEngine::instance().setFont(*this); int upem = FontEngine::instance().getUnitsPerEM(); - return upem ? (scaledSize()*FontEngine::instance().getAdvance(c)/upem*_style.extend) : 0; + return upem ? (scaledSize()*FontEngine::instance().getHAdvance(decodeChar(c))/upem*_style.extend) : 0; } @@ -621,14 +633,37 @@ double NativeFont::italicCorr(int c) const { double NativeFont::charHeight (int c) const { FontEngine::instance().setFont(*this); int upem = FontEngine::instance().getUnitsPerEM(); - return upem ? (scaledSize()*FontEngine::instance().getHeight(Character(Character::INDEX, c))/upem) : 0; + return upem ? (scaledSize()*FontEngine::instance().getHeight(decodeChar(c))/upem) : 0; } double NativeFont::charDepth (int c) const { FontEngine::instance().setFont(*this); int upem = FontEngine::instance().getUnitsPerEM(); - return upem ? (scaledSize()*FontEngine::instance().getDepth(Character(Character::INDEX, c))/upem) : 0; + return upem ? (scaledSize()*FontEngine::instance().getDepth(decodeChar(c))/upem) : 0; +} + + +double NativeFont::hAdvance (Character c) const { + FontEngine::instance().setFont(*this); + int upem = FontEngine::instance().getUnitsPerEM(); + return upem ? (scaledSize()*FontEngine::instance().getHAdvance(c)/upem) : 0; +} + + +double NativeFont::vAdvance (Character c) const { + FontEngine::instance().setFont(*this); + int upem = FontEngine::instance().getUnitsPerEM(); + return upem ? (scaledSize()*FontEngine::instance().getVAdvance(c)/upem) : 0; +} + +////////////////////////////////////////////////////////////////////////////// + +NativeFontImpl::NativeFontImpl (string fname, string fontname, double ptsize) + : NativeFont(ptsize, FontStyle(), Color::BLACK), _path(std::move(fname)), _name(std::move(fontname)) +{ + // plus characters (as appended to subset prefixes) are not allowed in font/family names + std::replace(_name.begin(), _name.end(), '+', '-'); } @@ -644,13 +679,25 @@ bool NativeFontImpl::findAndAssignBaseFontMap () { Character NativeFontImpl::decodeChar (uint32_t c) const { - return Character(Character::INDEX, c); + return {Character::INDEX, c}; } uint32_t NativeFontImpl::unicode (uint32_t c) const { uint32_t ucode = _toUnicodeMap.valueAt(c); - return Unicode::charToCodepoint(ucode); + return Unicode::charToCodepoint(ucode, true); +} + + +void NativeFontImpl::mapCharToUnicode (uint32_t c, uint32_t codepoint) { + _toUnicodeMap.addRange(c, c, codepoint); +} + + +bool NativeFontImpl::verticalLayout() const { + FontEngine &fe = FontEngine::instance(); + fe.setFont(*this); + return fe.hasVerticalMetrics(); } ////////////////////////////////////////////////////////////////////////////// |