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 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  return maWinTextureCache[nGlyphIndex];
103  }
104 
105  bool IsGlyphCached(int nGlyphIndex) const
106  {
107  return maWinTextureCache.find(nGlyphIndex) != maWinTextureCache.end();
108  }
109 };
110 
111 // win32 specific logical font instance
113 {
115 
116 public:
117  ~WinFontInstance() override;
118 
119  bool hasHScale() const;
120  float getHScale() const;
121 
124 
125  HFONT GetHFONT() const { return m_hFont; }
126  float GetScale() const { return m_fScale; }
127 
128  // Prevent deletion of the HFONT in the WinFontInstance destructor
129  // Used for the ScopedFont handling
130  void SetHFONT(HFONT hFont) { m_hFont = hFont; }
131 
132  const WinFontFace * GetFontFace() const { return static_cast<const WinFontFace *>(LogicalFontInstance::GetFontFace()); }
134 
135  bool CacheGlyphToAtlas(HDC hDC, HFONT hFont, int nGlyphIndex, SalGraphics& rGraphics, const GenericSalLayout& rLayout);
137 
138  bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override;
139 
140 private:
141  explicit WinFontInstance(const WinFontFace&, const FontSelectPattern&);
142 
143  hb_font_t* ImplInitHbFont() override;
144  bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override;
145 
147  HFONT m_hFont;
148  float m_fScale;
150 };
151 
153 {
154 protected:
155  explicit TextOutRenderer() = default;
156  TextOutRenderer(const TextOutRenderer &) = delete;
157  TextOutRenderer & operator = (const TextOutRenderer &) = delete;
158 
159 public:
160  static TextOutRenderer & get(bool bUseDWrite);
161 
162  virtual ~TextOutRenderer() = default;
163 
164  virtual bool operator ()(GenericSalLayout const &rLayout,
165  SalGraphics &rGraphics,
166  HDC hDC) = 0;
167 };
168 
170 {
171  ExTextOutRenderer(const ExTextOutRenderer &) = delete;
172  ExTextOutRenderer & operator = (const ExTextOutRenderer &) = delete;
173 
174 public:
175  explicit ExTextOutRenderer() = default;
176 
177  bool operator ()(GenericSalLayout const &rLayout,
178  SalGraphics &rGraphics,
179  HDC hDC) override;
180 };
181 
182 #endif // INCLUDED_VCL_INC_WIN_WINLAYOUT_HXX
183 
184 /* 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 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
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