bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / fontinstance.hxx
blobb4d7da6630904ac984c260e17380086c436b0665
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_FONTINSTANCE_HXX
21 #define INCLUDED_VCL_INC_FONTINSTANCE_HXX
23 #include "fontselect.hxx"
24 #include "impfontmetricdata.hxx"
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 #include <rtl/ref.hxx>
28 #include <salhelper/simplereferenceobject.hxx>
29 #include <tools/gen.hxx>
30 #include <tools/fontenum.hxx>
31 #include <vcl/glyphitem.hxx>
33 #include <boost/optional.hpp>
34 #include <unordered_map>
35 #include <memory>
37 #include <hb.h>
39 class ConvertChar;
40 class ImplFontCache;
41 class PhysicalFontFace;
43 // TODO: allow sharing of metrics for related fonts
45 class VCL_PLUGIN_PUBLIC LogicalFontInstance : public salhelper::SimpleReferenceObject
47 // just declaring the factory function doesn't work AKA
48 // friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
49 friend class PhysicalFontFace;
50 friend class ImplFontCache;
52 public: // TODO: make data members private
53 virtual ~LogicalFontInstance() override;
55 ImplFontMetricDataRef mxFontMetric; // Font attributes
56 const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
58 long mnLineHeight;
59 short mnOwnOrientation; // text angle if lower layers don't rotate text themselves
60 short mnOrientation; // text angle in 3600 system
61 bool mbInit; // true if maFontMetric member is valid
63 void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName );
64 bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
65 void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName );
67 inline hb_font_t* GetHbFont();
68 bool IsGraphiteFont();
69 void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = std::abs(nFactor); }
70 double GetAverageWidthFactor() const { return m_nAveWidthFactor; }
71 const FontSelectPattern& GetFontSelectPattern() const { return m_aFontSelData; }
73 const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
74 PhysicalFontFace* GetFontFace() { return m_pFontFace.get(); }
75 const ImplFontCache* GetFontCache() const { return mpFontCache; }
77 bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
78 virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;
80 int GetKashidaWidth();
82 void GetScale(double* nXScale, double* nYScale);
83 static inline void DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName);
85 protected:
86 explicit LogicalFontInstance(const PhysicalFontFace&, const FontSelectPattern&);
88 virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const = 0;
90 // Takes ownership of pHbFace.
91 static hb_font_t* InitHbFont(hb_face_t* pHbFace);
92 virtual hb_font_t* ImplInitHbFont() { assert(false); return hb_font_get_empty(); }
93 inline void ReleaseHbFont();
95 private:
96 // cache of Unicode characters and replacement font names
97 // TODO: a fallback map can be shared with many other ImplFontEntries
98 // TODO: at least the ones which just differ in orientation, stretching or height
99 typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
100 std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
101 mutable ImplFontCache * mpFontCache;
102 const FontSelectPattern m_aFontSelData;
103 hb_font_t* m_pHbFont;
104 double m_nAveWidthFactor;
105 rtl::Reference<PhysicalFontFace> m_pFontFace;
106 boost::optional<bool> m_xbIsGraphiteFont;
109 inline hb_font_t* LogicalFontInstance::GetHbFont()
111 if (!m_pHbFont)
112 m_pHbFont = ImplInitHbFont();
113 return m_pHbFont;
116 inline void LogicalFontInstance::ReleaseHbFont()
118 if (!m_pHbFont)
119 return;
120 hb_font_destroy(m_pHbFont);
121 m_pHbFont = nullptr;
124 inline void LogicalFontInstance::DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName)
126 pTagName[0] = static_cast<char>(nTableTag >> 24);
127 pTagName[1] = static_cast<char>(nTableTag >> 16);
128 pTagName[2] = static_cast<char>(nTableTag >> 8);
129 pTagName[3] = static_cast<char>(nTableTag);
130 pTagName[4] = 0;
133 #endif // INCLUDED_VCL_INC_FONTINSTANCE_HXX
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */