LibreOffice Module vcl (master)  1
fontinstance.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 #ifndef INCLUDED_VCL_INC_FONTINSTANCE_HXX
21 #define INCLUDED_VCL_INC_FONTINSTANCE_HXX
22 
23 #include "fontselect.hxx"
24 #include "impfontmetricdata.hxx"
25 
27 #include <rtl/ref.hxx>
29 #include <tools/gen.hxx>
30 #include <tools/fontenum.hxx>
31 #include <tools/degree.hxx>
32 #include <vcl/glyphitem.hxx>
33 
34 #include <optional>
35 #include <unordered_map>
36 #include <memory>
37 
38 #include <hb.h>
39 
40 class ConvertChar;
41 class ImplFontCache;
42 class PhysicalFontFace;
43 
44 // TODO: allow sharing of metrics for related fonts
45 
47 {
48  // just declaring the factory function doesn't work AKA
49  // friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
50  friend class PhysicalFontFace;
51  friend class ImplFontCache;
52 
53 public: // TODO: make data members private
54  virtual ~LogicalFontInstance() override;
55 
56  ImplFontMetricDataRef mxFontMetric; // Font attributes
57  const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
58 
60  Degree10 mnOwnOrientation; // text angle if lower layers don't rotate text themselves
61  Degree10 mnOrientation; // text angle in 3600 system
62  bool mbInit; // true if maFontMetric member is valid
63 
64  void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName );
65  bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
66  void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, std::u16string_view rFontName );
67 
68  inline hb_font_t* GetHbFont();
69  bool IsGraphiteFont();
70  void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = std::abs(nFactor); }
71  double GetAverageWidthFactor() const { return m_nAveWidthFactor; }
72  const FontSelectPattern& GetFontSelectPattern() const { return m_aFontSelData; }
73 
74  const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
75  PhysicalFontFace* GetFontFace() { return m_pFontFace.get(); }
76  const ImplFontCache* GetFontCache() const { return mpFontCache; }
77 
78  bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
79  virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;
80 
81  int GetKashidaWidth();
82 
83  void GetScale(double* nXScale, double* nYScale);
84  static inline void DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName);
85 
86 protected:
88 
89  virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const = 0;
90 
91  // Takes ownership of pHbFace.
92  static hb_font_t* InitHbFont(hb_face_t* pHbFace);
93  virtual hb_font_t* ImplInitHbFont() { assert(false); return hb_font_get_empty(); }
94 
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;
103  hb_font_t* m_pHbFont;
106  std::optional<bool> m_xbIsGraphiteFont;
107 };
108 
110 {
111  if (!m_pHbFont)
113  return m_pHbFont;
114 }
115 
116 inline void LogicalFontInstance::DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName)
117 {
118  pTagName[0] = static_cast<char>(nTableTag >> 24);
119  pTagName[1] = static_cast<char>(nTableTag >> 16);
120  pTagName[2] = static_cast<char>(nTableTag >> 8);
121  pTagName[3] = static_cast<char>(nTableTag);
122  pTagName[4] = 0;
123 }
124 
125 #endif // INCLUDED_VCL_INC_FONTINSTANCE_HXX
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::optional< bool > m_xbIsGraphiteFont
::std::unordered_map< ::std::pair< sal_UCS4, FontWeight >, OUString > UnicodeFallbackList
tools::Long mnLineHeight
ImplFontCache * mpFontCache
sal_uInt32 sal_UCS4
Definition: vclenum.hxx:196
void SetAverageWidthFactor(double nFactor)
const ConvertChar * mpConversion
rtl::Reference< PhysicalFontFace > m_pFontFace
long Long
hb_font_t * GetHbFont()
static void DecodeOpenTypeTag(const uint32_t nTableTag, char *pTagName)
ImplFontMetricDataRef mxFontMetric
double GetAverageWidthFactor() const
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
abstract base class for physical font faces
std::unique_ptr< UnicodeFallbackList > mpUnicodeFallbackList
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
const FontSelectPattern & GetFontSelectPattern() const
FontWeight
const FontSelectPattern m_aFontSelData
const ImplFontCache * GetFontCache() const
virtual hb_font_t * ImplInitHbFont()
const PhysicalFontFace * GetFontFace() const
PhysicalFontFace * GetFontFace()