LibreOffice Module vcl (master)  1
win/winlayout.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_WIN_WINLAYOUT_HXX
21 #define INCLUDED_VCL_INC_WIN_WINLAYOUT_HXX
22 
23 #include <rtl/ustring.hxx>
24 
25 #include <sallayout.hxx>
26 #include <svsys.h>
27 #include <win/salgdi.h>
28 #include <o3tl/sorted_vector.hxx>
29 
30 class WinFontInstance;
31 
32 namespace
33 {
34 // Extra space at the top and bottom of the glyph in total = tmHeight / GLYPH_SPACE_RATIO;
35 const int GLYPH_SPACE_RATIO = 8;
36 // Border size at the top of the glyph = tmHeight / GLYPH_OFFSET_RATIO;
37 const int GLYPH_OFFSET_RATIO = GLYPH_SPACE_RATIO * 2;
38 }
39 
41 {
44  std::unique_ptr<CompatibleDC::Texture> maTexture;
46  int mnHeight;
47  bool mbVertical;
48 
49  int getExtraSpace() const
50  {
51  return std::max(mnHeight / GLYPH_SPACE_RATIO, 4);
52  }
53 
54  int getExtraOffset() const
55  {
56  return std::max(mnHeight / GLYPH_OFFSET_RATIO, 2);
57  }
58 };
59 
60 class WinGlyphCache;
61 
63 {
65 
66  static GlobalWinGlyphCache * get();
67 
68  virtual ~GlobalWinGlyphCache() {}
69  virtual bool AllocateTexture(WinGlyphDrawElement& rElement, CompatibleDC* dc) = 0;
70  virtual void NotifyElementUsed(WinGlyphDrawElement& /*rElement*/) {}
71  virtual void Prune() {}
72 };
73 
75 {
76 protected:
77  std::unordered_map<int, WinGlyphDrawElement> maWinTextureCache;
78 
79 public:
81  {
83  c->maWinGlyphCaches.insert(this);
84  }
85 
86  virtual ~WinGlyphCache()
87  {
89  c->maWinGlyphCaches.erase(this);
90  }
91 
92  void PutDrawElementInCache(WinGlyphDrawElement&& rElement, int nGlyphIndex)
93  {
95  assert(!IsGlyphCached(nGlyphIndex));
96  maWinTextureCache[nGlyphIndex] = std::move( rElement );
97  }
98 
100  {
102  assert(IsGlyphCached(nGlyphIndex));
103  WinGlyphDrawElement& element = maWinTextureCache[nGlyphIndex];
105  return element;
106  }
107 
108  bool IsGlyphCached(int nGlyphIndex) const
109  {
110  return maWinTextureCache.find(nGlyphIndex) != maWinTextureCache.end();
111  }
112 };
113 
114 // win32 specific logical font instance
116 {
118 
119 public:
120  ~WinFontInstance() override;
121 
122  bool hasHScale() const;
123  float getHScale() const;
124 
127 
128  HFONT GetHFONT() const { return m_hFont; }
129  float GetScale() const { return m_fScale; }
130 
131  // Prevent deletion of the HFONT in the WinFontInstance destructor
132  // Used for the ScopedFont handling
133  void SetHFONT(HFONT hFont) { m_hFont = hFont; }
134 
135  const WinFontFace * GetFontFace() const { return static_cast<const WinFontFace *>(LogicalFontInstance::GetFontFace()); }
137 
138  bool CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics& rGraphics, const GenericSalLayout& rLayout);
140 
141  bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override;
142 
143 private:
144  explicit WinFontInstance(const WinFontFace&, const FontSelectPattern&);
145 
146  hb_font_t* ImplInitHbFont() override;
147  bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override;
148 
150  HFONT m_hFont;
151  float m_fScale;
153 };
154 
156 {
157 protected:
158  explicit TextOutRenderer() = default;
159  TextOutRenderer(const TextOutRenderer &) = delete;
160  TextOutRenderer & operator = (const TextOutRenderer &) = delete;
161 
162 public:
163  static TextOutRenderer & get(bool bUseDWrite);
164 
165  virtual ~TextOutRenderer() = default;
166 
167  virtual bool operator ()(GenericSalLayout const &rLayout,
168  SalGraphics &rGraphics,
169  HDC hDC) = 0;
170 };
171 
173 {
174  ExTextOutRenderer(const ExTextOutRenderer &) = delete;
175  ExTextOutRenderer & operator = (const ExTextOutRenderer &) = delete;
176 
177 public:
178  explicit ExTextOutRenderer() = default;
179 
180  bool operator ()(GenericSalLayout const &rLayout,
181  SalGraphics &rGraphics,
182  HDC hDC) override;
183 };
184 
185 #endif // INCLUDED_VCL_INC_WIN_WINLAYOUT_HXX
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics &rGraphics, const GenericSalLayout &rLayout)
void SetHFONT(HFONT hFont)
virtual ~TextOutRenderer()=default
bool IsGlyphCached(int nGlyphIndex) const
static GlobalWinGlyphCache * get()
WinSalGraphics * GetGraphics() const
bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle &, bool) const override
virtual void NotifyElementUsed(WinGlyphDrawElement &)
virtual bool AllocateTexture(WinGlyphDrawElement &rElement, CompatibleDC *dc)=0
bool hasHScale() const
TextOutRenderer & operator=(const TextOutRenderer &)=delete
std::unordered_map< int, WinGlyphDrawElement > maWinTextureCache
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
TextOutRenderer()=default
virtual bool operator()(GenericSalLayout const &rLayout, SalGraphics &rGraphics, HDC hDC)=0
bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon &, bool) const override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
~WinFontInstance() override
virtual ~WinGlyphCache()
WinGlyphCache maWinGlyphCache
std::unique_ptr< CompatibleDC::Texture > maTexture
o3tl::sorted_vector< WinGlyphCache * > maWinGlyphCaches
virtual void Prune()
virtual rtl::Reference< LogicalFontInstance > CreateFontInstance(const FontSelectPattern &) const override
bool operator()(GenericSalLayout const &rLayout, SalGraphics &rGraphics, HDC hDC) override
void SetGraphics(WinSalGraphics *)
WinFontInstance(const WinFontFace &, const FontSelectPattern &)
float getHScale() const
const WinFontFace * GetFontFace() const
tools::Rectangle maLocation
virtual ~GlobalWinGlyphCache()
WinGlyphCache & GetWinGlyphCache()
WinGlyphDrawElement & GetDrawElement(int nGlyphIndex)
ExTextOutRenderer()=default
ExTextOutRenderer & operator=(const ExTextOutRenderer &)=delete
WinFontFace * GetFontFace()
int getExtraSpace() const
WinSalGraphics * m_pGraphics
const PhysicalFontFace * GetFontFace() const
void PutDrawElementInCache(WinGlyphDrawElement &&rElement, int nGlyphIndex)
HFONT GetHFONT() const
hb_font_t * ImplInitHbFont() override
float GetScale() const
int getExtraOffset() const
Class that creates (and destroys) a compatible Device Context.
Definition: win/salgdi.h:100