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 
29 class WinFontInstance;
30 
31 namespace
32 {
33 // Extra space at the top and bottom of the glyph in total = tmHeight / GLYPH_SPACE_RATIO;
34 const int GLYPH_SPACE_RATIO = 8;
35 // Border size at the top of the glyph = tmHeight / GLYPH_OFFSET_RATIO;
36 const int GLYPH_OFFSET_RATIO = GLYPH_SPACE_RATIO * 2;
37 }
38 
40 {
43  std::unique_ptr<CompatibleDC::Texture> maTexture;
45  int mnHeight;
46  bool mbVertical;
47 
48  int getExtraSpace() const
49  {
50  return std::max(mnHeight / GLYPH_SPACE_RATIO, 4);
51  }
52 
53  int getExtraOffset() const
54  {
55  return std::max(mnHeight / GLYPH_OFFSET_RATIO, 2);
56  }
57 };
58 
59 class WinGlyphCache;
60 
62 {
63  std::unordered_set<WinGlyphCache*> maWinGlyphCaches;
64 
65  static GlobalWinGlyphCache * get();
66 
67  virtual ~GlobalWinGlyphCache() {}
68  virtual bool AllocateTexture(WinGlyphDrawElement& rElement, CompatibleDC* dc) = 0;
69  virtual void NotifyElementUsed(WinGlyphDrawElement& /*rElement*/) {}
70  virtual void Prune() {}
71 };
72 
74 {
75 protected:
76  std::unordered_map<int, WinGlyphDrawElement> maWinTextureCache;
77 
78 public:
80  {
82  c->maWinGlyphCaches.insert(this);
83  }
84 
85  virtual ~WinGlyphCache()
86  {
88  c->maWinGlyphCaches.erase(this);
89  }
90 
91  void PutDrawElementInCache(WinGlyphDrawElement&& rElement, int nGlyphIndex)
92  {
93  assert(GlobalWinGlyphCache::get());
94  assert(!IsGlyphCached(nGlyphIndex));
95  maWinTextureCache[nGlyphIndex] = std::move( rElement );
96  }
97 
99  {
100  assert(GlobalWinGlyphCache::get());
101  assert(IsGlyphCached(nGlyphIndex));
102  WinGlyphDrawElement& element = maWinTextureCache[nGlyphIndex];
104  return element;
105  }
106 
107  bool IsGlyphCached(int nGlyphIndex) const
108  {
109  return maWinTextureCache.find(nGlyphIndex) != maWinTextureCache.end();
110  }
111 };
112 
113 // win32 specific logical font instance
115 {
117 
118 public:
119  ~WinFontInstance() override;
120 
121  bool hasHScale() const;
122  float getHScale() const;
123 
126 
127  HFONT GetHFONT() const { return m_hFont; }
128  float GetScale() const { return m_fScale; }
129 
130  // Prevent deletion of the HFONT in the WinFontInstance destructor
131  // Used for the ScopedFont handling
132  void SetHFONT(HFONT hFont) { m_hFont = hFont; }
133 
134  const WinFontFace * GetFontFace() const { return static_cast<const WinFontFace *>(LogicalFontInstance::GetFontFace()); }
136 
137  bool CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics& rGraphics, const GenericSalLayout& rLayout);
139 
140  bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override;
141 
142 private:
143  explicit WinFontInstance(const WinFontFace&, const FontSelectPattern&);
144 
145  hb_font_t* ImplInitHbFont() override;
146  bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override;
147 
149  HFONT m_hFont;
150  float m_fScale;
152 };
153 
155 {
156 protected:
157  explicit TextOutRenderer() = default;
158  TextOutRenderer(const TextOutRenderer &) = delete;
159  TextOutRenderer & operator = (const TextOutRenderer &) = delete;
160 
161 public:
162  static TextOutRenderer & get(bool bUseDWrite);
163 
164  virtual ~TextOutRenderer() = default;
165 
166  virtual bool operator ()(GenericSalLayout const &rLayout,
167  SalGraphics &rGraphics,
168  HDC hDC) = 0;
169 };
170 
172 {
173  ExTextOutRenderer(const ExTextOutRenderer &) = delete;
174  ExTextOutRenderer & operator = (const ExTextOutRenderer &) = delete;
175 
176 public:
177  explicit ExTextOutRenderer() = default;
178 
179  bool operator ()(GenericSalLayout const &rLayout,
180  SalGraphics &rGraphics,
181  HDC hDC) override;
182 };
183 
184 #endif // INCLUDED_VCL_INC_WIN_WINLAYOUT_HXX
185 
186 /* 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
std::unordered_set< WinGlyphCache * > maWinGlyphCaches
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
~WinFontInstance() override
virtual ~WinGlyphCache()
WinGlyphCache maWinGlyphCache
std::unique_ptr< CompatibleDC::Texture > maTexture
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