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 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include "fontselect.hxx"
25 #include "impfontmetricdata.hxx"
26 
28 #include <rtl/ref.hxx>
30 #include <tools/gen.hxx>
31 #include <tools/fontenum.hxx>
32 #include <tools/degree.hxx>
33 #include <vcl/glyphitem.hxx>
34 
35 #include <optional>
36 #include <unordered_map>
37 #include <memory>
38 
39 #include <hb.h>
40 
41 class ConvertChar;
42 class ImplFontCache;
43 class PhysicalFontFace;
44 
45 // TODO: allow sharing of metrics for related fonts
46 
48 {
49  // just declaring the factory function doesn't work AKA
50  // friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
51  friend class PhysicalFontFace;
52  friend class ImplFontCache;
53 
54 public: // TODO: make data members private
55  virtual ~LogicalFontInstance() override;
56 
57  ImplFontMetricDataRef mxFontMetric; // Font attributes
58  const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
59 
61  Degree10 mnOwnOrientation; // text angle if lower layers don't rotate text themselves
62  Degree10 mnOrientation; // text angle in 3600 system
63  bool mbInit; // true if maFontMetric member is valid
64 
65  void AddFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName );
66  bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const;
67  void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, std::u16string_view rFontName );
68 
69  inline hb_font_t* GetHbFont();
70  bool IsGraphiteFont();
71  void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = std::abs(nFactor); }
72  double GetAverageWidthFactor() const { return m_nAveWidthFactor; }
73  const FontSelectPattern& GetFontSelectPattern() const { return m_aFontSelData; }
74 
75  const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
76  PhysicalFontFace* GetFontFace() { return m_pFontFace.get(); }
77  const ImplFontCache* GetFontCache() const { return mpFontCache; }
78 
79  bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
80  virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;
81 
82  int GetKashidaWidth();
83 
84  void GetScale(double* nXScale, double* nYScale);
85  static inline void DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName);
86 
87 protected:
89 
90  virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const = 0;
91 
92  // Takes ownership of pHbFace.
93  static hb_font_t* InitHbFont(hb_face_t* pHbFace);
94  virtual hb_font_t* ImplInitHbFont() { assert(false); return hb_font_get_empty(); }
95 
96 private:
97  // cache of Unicode characters and replacement font names
98  // TODO: a fallback map can be shared with many other ImplFontEntries
99  // TODO: at least the ones which just differ in orientation, stretching or height
100  typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
101  std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
104  hb_font_t* m_pHbFont;
107  std::optional<bool> m_xbIsGraphiteFont;
108 };
109 
111 {
112  if (!m_pHbFont)
114  return m_pHbFont;
115 }
116 
117 inline void LogicalFontInstance::DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName)
118 {
119  pTagName[0] = static_cast<char>(nTableTag >> 24);
120  pTagName[1] = static_cast<char>(nTableTag >> 16);
121  pTagName[2] = static_cast<char>(nTableTag >> 8);
122  pTagName[3] = static_cast<char>(nTableTag);
123  pTagName[4] = 0;
124 }
125 
126 /* 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:192
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:29
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()