From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/libnrtype/OpenTypeUtil.h | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/libnrtype/OpenTypeUtil.h (limited to 'src/libnrtype/OpenTypeUtil.h') diff --git a/src/libnrtype/OpenTypeUtil.h b/src/libnrtype/OpenTypeUtil.h new file mode 100644 index 0000000..3385698 --- /dev/null +++ b/src/libnrtype/OpenTypeUtil.h @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * TODO: insert short description here + *//* + * Authors: see git history + * + * Copyright (C) 2018 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_OPENTYPEUTIL_H +#define SEEN_OPENTYPEUTIL_H + +#ifndef USE_PANGO_WIN32 + +#include + +#include +#include FT_FREETYPE_H + +#include + +/* + * A set of utilities to extract data from OpenType fonts. + * + * Isolates dependencies on FreeType, Harfbuzz, and Pango. + * All three provide variable amounts of access to data. + */ + +struct hb_font_t; + +// OpenType substitution +class OTSubstitution { +public: + OTSubstitution() = default;; + Glib::ustring before; + Glib::ustring input; + Glib::ustring after; + Glib::ustring output; +}; + +// An OpenType fvar axis. +class OTVarAxis { +public: + OTVarAxis() + : minimum(0) + , def(500) // Default + , maximum(1000) + , set_val(500) + , index(-1) {}; + + OTVarAxis(double _minimum, double _def, double _maximum, double _set_val, int _index) + : minimum(_minimum) + , def(_def) // Default + , maximum(_maximum) + , set_val(_set_val) + , index (_index) {}; + + double minimum; + double def; + double maximum; + double set_val; + int index; // Index in OpenType file (since we use a map). +}; + +// A particular instance of a variable font. +// A map indexed by axis name with value. +class OTVarInstance { + std::map axes; +}; + +inline double FTFixedToDouble (FT_Fixed value) { + return static_cast(value) / 65536.0; +} + +inline FT_Fixed FTDoubleToFixed (double value) { + return static_cast(value * 65536); +} + + +namespace Inkscape { class Pixbuf; } + +class SVGTableEntry { +public: + SVGTableEntry() : pixbuf(nullptr) {}; + std::string svg; + Inkscape::Pixbuf* pixbuf; +}; + +// This would be better if one had std::vector instead of OTSubstitution where each +// entry corresponded to one substitution (e.g. ff -> ff) but Harfbuzz at the moment cannot return +// individual substitutions. See Harfbuzz issue #673. +void readOpenTypeGsubTable (hb_font_t* hb_font, + std::map& tables); + +void readOpenTypeFvarAxes (const FT_Face ft_face, + std::map& axes); + +void readOpenTypeFvarNamed (const FT_Face ft_face, + std::map& named); + +void readOpenTypeSVGTable (hb_font_t* hb_font, + std::map& glyphs); + +#endif /* !USE_PANGO_WIND32 */ +#endif /* !SEEN_OPENTYPEUTIL_H */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3