summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/src/Font.cpp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-01-12 03:01:29 +0000
committerNorbert Preining <norbert@preining.info>2023-01-12 03:01:29 +0000
commit6a7900c93acc16d1bbd2f1e26286c7dd7387e6c0 (patch)
tree76196287351cba68a51934c49468bf1a7846aa76 /dviware/dvisvgm/src/Font.cpp
parentc1c19023b4b1d43cb874f84df5102b485853e672 (diff)
CTAN sync 202301120301
Diffstat (limited to 'dviware/dvisvgm/src/Font.cpp')
-rw-r--r--dviware/dvisvgm/src/Font.cpp69
1 files changed, 58 insertions, 11 deletions
diff --git a/dviware/dvisvgm/src/Font.cpp b/dviware/dvisvgm/src/Font.cpp
index 2fa4ce5be9..c60b162828 100644
--- a/dviware/dvisvgm/src/Font.cpp
+++ b/dviware/dvisvgm/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();
}
//////////////////////////////////////////////////////////////////////////////