LibreOffice Module vcl (master) 1
LogicalFontInstance.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
25#include <o3tl/hash_combine.hxx>
26#include <rtl/ref.hxx>
28#include <tools/gen.hxx>
29#include <tools/fontenum.hxx>
30#include <tools/degree.hxx>
31
34#include <glyphid.hxx>
35
36#include <optional>
37#include <unordered_map>
38#include <memory>
39
40#include <hb.h>
41
42class ConvertChar;
43class ImplFontCache;
44
45constexpr float ARTIFICIAL_ITALIC_MATRIX_XX = 1 << 16;
46constexpr float ARTIFICIAL_ITALIC_MATRIX_XY = (1 << 16) / 3.f;
48
49// extend std namespace to add custom hash needed for LogicalFontInstance
50
51namespace std
52{
53template <> struct hash<pair<sal_UCS4, FontWeight>>
54{
55 size_t operator()(const pair<sal_UCS4, FontWeight>& rData) const
56 {
57 std::size_t seed = 0;
58 o3tl::hash_combine(seed, rData.first);
59 o3tl::hash_combine(seed, rData.second);
60 return seed;
61 }
62};
63}
64
65// TODO: allow sharing of metrics for related fonts
66
68{
69 // just declaring the factory function doesn't work AKA
70 // friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
72 friend class ImplFontCache;
73
74public: // TODO: make data members private
75 virtual ~LogicalFontInstance() override;
76
77 FontMetricDataRef mxFontMetric; // Font attributes
78 const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
79
81 Degree10 mnOwnOrientation; // text angle if lower layers don't rotate text themselves
82 Degree10 mnOrientation; // text angle in 3600 system
83 bool mbInit; // true if maFontMetric member is valid
84
85 void AddFallbackForUnicode(sal_UCS4 cChar, FontWeight eWeight, const OUString& rFontName,
86 bool bEmbolden, const ItalicMatrix& rMatrix);
87 bool GetFallbackForUnicode(sal_UCS4 cInChar, FontWeight eInWeight, OUString* pOutFontName,
88 bool* pOutEmbolden, ItalicMatrix* pOutItalicMatrix) const;
89 void IgnoreFallbackForUnicode(sal_UCS4, FontWeight eWeight, std::u16string_view rFontName);
90
91 inline hb_font_t* GetHbFont();
92 bool IsGraphiteFont();
93 // NeedOffsetCorrection: Return if the font need offset correction in TTB direction.
94 // nYOffset is the original offset. It is used to check if the correction is necessary.
95 bool NeedOffsetCorrection(sal_Int32 nYOffset);
96 void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = std::abs(nFactor); }
97 double GetAverageWidthFactor() const { return m_nAveWidthFactor; }
98 const vcl::font::FontSelectPattern& GetFontSelectPattern() const { return m_aFontSelData; }
99
100 const vcl::font::PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
101 vcl::font::PhysicalFontFace* GetFontFace() { return m_pFontFace.get(); }
102 const ImplFontCache* GetFontCache() const { return mpFontCache; }
103
104 bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
105 virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;
106 basegfx::B2DPolyPolygon GetGlyphOutlineUntransformed(sal_GlyphId) const;
107
108 sal_GlyphId GetGlyphIndex(uint32_t, uint32_t = 0) const;
109
110 double GetGlyphWidth(sal_GlyphId, bool = false, bool = true) const;
111
112 double GetKashidaWidth() const;
113
114 void GetScale(double* nXScale, double* nYScale) const;
115
116 bool NeedsArtificialItalic() const;
117 bool NeedsArtificialBold() const;
118
119protected:
122
123 hb_font_t* InitHbFont();
124 virtual void ImplInitHbFont(hb_font_t*) {}
125
126private:
127 hb_font_t* GetHbFontUntransformed() const;
128
129 struct MapEntry
130 {
131 OUString sFontName;
134 };
135 // cache of Unicode characters and replacement font names and attributes
136 // TODO: a fallback map can be shared with many other ImplFontEntries
137 // TODO: at least the ones which just differ in orientation, stretching or height
138 typedef ::std::unordered_map<::std::pair<sal_UCS4, FontWeight>, MapEntry> UnicodeFallbackList;
142 hb_font_t* m_pHbFont;
143 mutable hb_font_t* m_pHbFontUntransformed = nullptr;
146 std::optional<bool> m_xbIsGraphiteFont;
147
148 enum class FontFamilyEnum
149 {
150 Unclassified,
151 DFKaiSB
152 };
153
154 // The value is initialized and used in NeedOffsetCorrection().
155 std::optional<FontFamilyEnum> m_xeFontFamilyEnum;
156
157 mutable hb_draw_funcs_t* m_pHbDrawFuncs = nullptr;
159};
160
162{
163 if (!m_pHbFont)
165 return m_pHbFont;
166}
167
168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr float ARTIFICIAL_ITALIC_MATRIX_XX
constexpr float ARTIFICIAL_ITALIC_MATRIX_XY
constexpr float ARTIFICIAL_ITALIC_SKEW
std::optional< bool > m_xbIsGraphiteFont
const ImplFontCache * GetFontCache() const
vcl::font::PhysicalFontFace * GetFontFace()
const vcl::font::PhysicalFontFace * GetFontFace() const
virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon &, bool) const =0
const vcl::font::FontSelectPattern m_aFontSelData
virtual void ImplInitHbFont(hb_font_t *)
basegfx::B2DPolygon m_aDrawPolygon
FontMetricDataRef mxFontMetric
rtl::Reference< vcl::font::PhysicalFontFace > m_pFontFace
void SetAverageWidthFactor(double nFactor)
const vcl::font::FontSelectPattern & GetFontSelectPattern() const
double GetAverageWidthFactor() const
std::optional< FontFamilyEnum > m_xeFontFamilyEnum
::std::unordered_map<::std::pair< sal_UCS4, FontWeight >, MapEntry > UnicodeFallbackList
UnicodeFallbackList maUnicodeFallbackList
const ConvertChar * mpConversion
abstract base class for physical font faces
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
uint32_t sal_GlyphId
Definition: glyphid.hxx:24
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
FontWeight
long Long
size_t operator()(const pair< sal_UCS4, FontWeight > &rData) const
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:160