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 <vcl/glyphitem.hxx>
32 
33 #include <boost/optional.hpp>
34 #include <unordered_map>
35 #include <memory>
36 
37 #include <hb.h>
38 
39 class ConvertChar;
40 class ImplFontCache;
41 class PhysicalFontFace;
42 
43 // TODO: allow sharing of metrics for related fonts
44 
46 {
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;
51 
52 public: // TODO: make data members private
53  virtual ~LogicalFontInstance() override;
54 
55  ImplFontMetricDataRef mxFontMetric; // Font attributes
56  const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
57 
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
62 
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 );
66 
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; }
72 
73  const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); }
74  const ImplFontCache* GetFontCache() const { return mpFontCache; }
75 
76  bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const;
77  virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0;
78 
79  int GetKashidaWidth();
80 
81  void GetScale(double* nXScale, double* nYScale);
82  static inline void DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName);
83 
84 protected:
86 
87  virtual bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const = 0;
88 
89  // Takes ownership of pHbFace.
90  static hb_font_t* InitHbFont(hb_face_t* pHbFace);
91  virtual hb_font_t* ImplInitHbFont() { assert(false); return hb_font_get_empty(); }
92  inline void ReleaseHbFont();
93 
94 private:
95  // cache of Unicode characters and replacement font names
96  // TODO: a fallback map can be shared with many other ImplFontEntries
97  // TODO: at least the ones which just differ in orientation, stretching or height
98  typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
99  std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList;
102  hb_font_t* m_pHbFont;
106 };
107 
109 {
110  if (!m_pHbFont)
112  return m_pHbFont;
113 }
114 
116 {
117  if (!m_pHbFont)
118  return;
119  hb_font_destroy(m_pHbFont);
120  m_pHbFont = nullptr;
121 }
122 
123 inline void LogicalFontInstance::DecodeOpenTypeTag(const uint32_t nTableTag, char* pTagName)
124 {
125  pTagName[0] = static_cast<char>(nTableTag >> 24);
126  pTagName[1] = static_cast<char>(nTableTag >> 16);
127  pTagName[2] = static_cast<char>(nTableTag >> 8);
128  pTagName[3] = static_cast<char>(nTableTag);
129  pTagName[4] = 0;
130 }
131 
132 #endif // INCLUDED_VCL_INC_FONTINSTANCE_HXX
133 
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unordered_map< ::std::pair< sal_UCS4, FontWeight >, OUString > UnicodeFallbackList
ImplFontCache * mpFontCache
void SetAverageWidthFactor(double nFactor)
const ConvertChar * mpConversion
rtl::Reference< PhysicalFontFace > m_pFontFace
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
abstract base class for physical font faces
boost::optional< bool > m_xbIsGraphiteFont
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
sal_uInt32 sal_UCS4
Definition: fontcharmap.hxx:29