Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / win / source / gdi / winlayout.hxx
blobd558d4cc6bc2bfaa1ee82e40d048ec99596fde58
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_WIN_SOURCE_GDI_WINLAYOUT_HXX
21 #define INCLUDED_VCL_WIN_SOURCE_GDI_WINLAYOUT_HXX
23 #include <rtl/ustring.hxx>
25 #include <sallayout.hxx>
26 #include <svsys.h>
27 #include <win/salgdi.h>
29 #include <usp10.h>
31 // Graphite headers
32 #include <config_graphite.h>
33 #if ENABLE_GRAPHITE
34 #include <graphite_layout.hxx>
35 #endif
37 class ImplWinFontEntry;
38 struct VisualItem;
40 class WinLayout : public SalLayout
42 public:
43 WinLayout(HDC, const ImplWinFontData&, ImplWinFontEntry&, bool bUseOpenGL);
44 virtual ~WinLayout();
45 virtual void InitFont() const SAL_OVERRIDE;
46 void SetFontScale( float f ) { mfFontScale = f; }
47 HFONT DisableFontScaling() const;
49 SCRIPT_CACHE& GetScriptCache() const;
51 /// In the non-OpenGL case, call the DrawTextImpl directly, otherwise make
52 /// sure we draw to an interim texture.
53 virtual void DrawText(SalGraphics&) const SAL_OVERRIDE;
55 /// Draw to the provided HDC.
56 virtual void DrawTextImpl(HDC hDC) const = 0;
58 virtual bool CacheGlyphs(SalGraphics& rGraphics) const = 0;
59 virtual bool DrawCachedGlyphs(SalGraphics& rGraphics) const = 0;
61 HDC mhDC; // WIN32 device handle
62 HFONT mhFont; // WIN32 font handle
63 int mnBaseAdv; // x-offset relative to Layout origin
64 float mfFontScale; // allows metrics emulation of huge font sizes
65 bool mbUseOpenGL; ///< We need to render via OpenGL
67 const ImplWinFontData& mrWinFontData;
68 ImplWinFontEntry& mrWinFontEntry;
71 class UniscribeLayout : public WinLayout
73 public:
74 UniscribeLayout(HDC, const ImplWinFontData&, ImplWinFontEntry&, bool bUseOpenGL);
76 virtual bool LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE;
77 virtual void AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE;
78 virtual void DrawTextImpl(HDC hDC) const SAL_OVERRIDE;
79 virtual bool CacheGlyphs(SalGraphics& rGraphics) const SAL_OVERRIDE;
80 virtual bool DrawCachedGlyphs(SalGraphics& rGraphics) const SAL_OVERRIDE;
81 virtual int GetNextGlyphs( int nLen, sal_GlyphId* pGlyphs, Point& rPos, int&,
82 DeviceCoordinate* pGlyphAdvances, int* pCharPosAry,
83 const PhysicalFontFace** pFallbackFonts = NULL ) const SAL_OVERRIDE;
85 virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const SAL_OVERRIDE;
86 virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor) const SAL_OVERRIDE;
87 virtual void GetCaretPositions( int nArraySize, long* pCaretXArray ) const SAL_OVERRIDE;
88 virtual bool IsKashidaPosValid ( int nCharPos ) const SAL_OVERRIDE;
90 // for glyph+font+script fallback
91 virtual void MoveGlyph( int nStart, long nNewXPos ) SAL_OVERRIDE;
92 virtual void DropGlyph( int nStart ) SAL_OVERRIDE;
93 virtual void Simplify( bool bIsBase ) SAL_OVERRIDE;
94 virtual void DisableGlyphInjection( bool bDisable ) SAL_OVERRIDE { mbDisableGlyphInjection = bDisable; }
96 protected:
97 virtual ~UniscribeLayout();
99 void Justify( DeviceCoordinate nNewWidth );
100 void ApplyDXArray( const ImplLayoutArgs& );
102 bool GetItemSubrange( const VisualItem&,
103 int& rMinIndex, int& rEndIndex ) const;
105 private:
106 // item specific info
107 SCRIPT_ITEM* mpScriptItems; // in logical order
108 VisualItem* mpVisualItems; // in visual order
109 int mnItemCount; // number of visual items
111 // string specific info
112 // everything is in logical order
113 int mnCharCapacity;
114 WORD* mpLogClusters; // map from absolute_char_pos to relative_glyph_pos
115 int* mpCharWidths; // map from absolute_char_pos to char_width
116 int mnSubStringMin; // char_pos of first char in context
118 // glyph specific info
119 // everything is in visual order
120 int mnGlyphCount;
121 int mnGlyphCapacity;
122 int* mpGlyphAdvances; // glyph advance width before justification
123 int* mpJustifications; // glyph advance width after justification
124 WORD* mpOutGlyphs; // glyphids in visual order
125 GOFFSET* mpGlyphOffsets; // glyph offsets to the "naive" layout
126 SCRIPT_VISATTR* mpVisualAttrs; // glyph visual attributes
127 mutable int* mpGlyphs2Chars; // map from absolute_glyph_pos to absolute_char_pos
129 // kashida stuff
130 void InitKashidaHandling();
131 void KashidaItemFix( int nMinGlyphPos, int nEndGlyphPos );
132 bool KashidaWordFix( int nMinGlyphPos, int nEndGlyphPos, int* pnCurrentPos );
134 int mnMinKashidaWidth;
135 int mnMinKashidaGlyph;
136 bool mbDisableGlyphInjection;
139 #if ENABLE_GRAPHITE
141 class GraphiteLayoutWinImpl : public GraphiteLayout
143 public:
144 GraphiteLayoutWinImpl(const gr_face * pFace, ImplWinFontEntry & rFont)
145 throw()
146 : GraphiteLayout(pFace), mrFont(rFont) {};
147 virtual ~GraphiteLayoutWinImpl() throw() {};
148 virtual sal_GlyphId getKashidaGlyph(int & rWidth) SAL_OVERRIDE;
149 private:
150 ImplWinFontEntry & mrFont;
153 /// This class uses the SIL Graphite engine to provide complex text layout services to the VCL
154 class GraphiteWinLayout : public WinLayout
156 private:
157 gr_font * mpFont;
158 grutils::GrFeatureParser * mpFeatures;
159 mutable GraphiteLayoutWinImpl maImpl;
160 public:
161 GraphiteWinLayout(HDC hDC, const ImplWinFontData& rWFD, ImplWinFontEntry& rWFE, bool bUseOpenGL) throw();
162 virtual ~GraphiteWinLayout();
164 // used by upper layers
165 virtual bool LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE; // first step of layout
166 virtual void AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE; // adjusting after fallback etc.
167 virtual void DrawTextImpl(HDC hDC) const SAL_OVERRIDE;
168 virtual bool CacheGlyphs(SalGraphics& rGraphics) const SAL_OVERRIDE;
169 virtual bool DrawCachedGlyphs(SalGraphics& rGraphics) const SAL_OVERRIDE;
171 // methods using string indexing
172 virtual sal_Int32 GetTextBreak(DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra=0, int nFactor=1) const SAL_OVERRIDE;
173 virtual DeviceCoordinate FillDXArray( DeviceCoordinate* pDXArray ) const SAL_OVERRIDE;
175 virtual void GetCaretPositions( int nArraySize, long* pCaretXArray ) const SAL_OVERRIDE;
177 // methods using glyph indexing
178 virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
179 DeviceCoordinate* pGlyphAdvAry = NULL, int* pCharPosAry = NULL,
180 const PhysicalFontFace** pFallbackFonts = NULL ) const SAL_OVERRIDE;
182 // used by glyph+font+script fallback
183 virtual void MoveGlyph( int nStart, long nNewXPos ) SAL_OVERRIDE;
184 virtual void DropGlyph( int nStart ) SAL_OVERRIDE;
185 virtual void Simplify( bool bIsBase ) SAL_OVERRIDE;
188 #endif // ENABLE_GRAPHITE
190 #endif
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */