Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / vcl / inc / graphite_layout.hxx
blob6a84d54647fb4eb72e54fd2e504fdb9efc2affb3
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_INC_GRAPHITE_LAYOUT_HXX
21 #define INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
22 // Description: An implementation of the SalLayout interface that uses the
23 // Graphite engine.
25 // We need this to enable namespace support in libgrengine headers.
26 #define GR_NAMESPACE
28 // Standard Library
29 #include <memory>
30 #include <vector>
31 #include <map>
32 #include <utility>
33 // Libraries
34 #include <graphite_static.hxx>
35 #include <graphite2/Font.h>
36 #include <graphite2/Segment.h>
37 // Platform
38 #include <vcl/dllapi.h>
40 #include "sallayout.hxx"
42 // Module
44 // Module type definitions and forward declarations.
45 // SAL/VCL types
46 class ServerFont;
47 class PhysicalFontFace;
49 // Graphite types
50 namespace grutils { class GrFeatureParser; }
52 class GraphiteFaceWrapper
54 public:
55 typedef std::map<int, gr_font*> GrFontMap;
56 GraphiteFaceWrapper(gr_face * pFace) : m_pFace(pFace) {}
57 ~GraphiteFaceWrapper()
59 GrFontMap::iterator i = m_fonts.begin();
60 while (i != m_fonts.end())
61 gr_font_destroy((*i++).second);
62 m_fonts.clear();
63 gr_face_destroy(m_pFace);
65 const gr_face * face() const { return m_pFace; }
66 gr_font * font(int ppm) const
68 GrFontMap::const_iterator i = m_fonts.find(ppm);
69 if (i != m_fonts.end())
70 return i->second;
71 return NULL;
73 void addFont(int ppm, gr_font * pFont)
75 if (m_fonts[ppm])
76 gr_font_destroy(m_fonts[ppm]);
77 m_fonts[ppm] = pFont;
79 private:
80 gr_face * m_pFace;
81 GrFontMap m_fonts;
84 // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
85 // @author tse
87 class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout
89 public:
91 class Glyphs : public std::vector<GlyphItem>
93 public:
94 typedef std::pair<Glyphs::const_iterator, Glyphs::const_iterator> iterator_pair_t;
98 mutable Glyphs mvGlyphs;
99 void clear();
101 private:
102 const gr_face * mpFace; // not owned by layout
103 gr_font * mpFont; // not owned by layout
104 int mnSegCharOffset; // relative to ImplLayoutArgs::mpStr
105 long mnWidth;
106 std::vector<int> mvChar2BaseGlyph;
107 std::vector<int> mvGlyph2Char;
108 std::vector<int> mvCharDxs;
109 std::vector<int> mvCharBreaks;
110 float mfScaling;
111 const grutils::GrFeatureParser * mpFeatures;
113 public:
114 GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
115 const grutils::GrFeatureParser * features = NULL) throw();
117 // used by upper layers
118 virtual bool LayoutText( ImplLayoutArgs& ) SAL_OVERRIDE; // first step of layout
119 // split into two stages to allow dc to be restored on the segment
120 gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
121 bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
123 virtual void AdjustLayout( ImplLayoutArgs& ) SAL_OVERRIDE; // adjusting positions
125 // methods using string indexing
126 virtual sal_Int32 GetTextBreak(long nMaxWidth, long nCharExtra=0, int nFactor=1) const SAL_OVERRIDE;
127 virtual long FillDXArray( sal_Int32* pDXArray ) const SAL_OVERRIDE;
128 virtual void ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth);
130 virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const SAL_OVERRIDE;
132 // methods using glyph indexing
133 virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
134 sal_Int32* pGlyphAdvAry = NULL, int* pCharPosAry = NULL,
135 const PhysicalFontFace** pFallbackFonts = NULL ) const SAL_OVERRIDE;
137 // used by glyph+font+script fallback
138 virtual void MoveGlyph( int nStart, long nNewXPos ) SAL_OVERRIDE;
139 virtual void DropGlyph( int nStart ) SAL_OVERRIDE;
140 virtual void Simplify( bool bIsBase ) SAL_OVERRIDE;
142 // Dummy implementation so layout can be shared between Linux/Windows
143 virtual void DrawText(SalGraphics&) const SAL_OVERRIDE {};
145 virtual ~GraphiteLayout() throw();
146 void SetFont(gr_font * pFont) { mpFont = pFont; }
147 gr_font * GetFont() { return mpFont; }
148 void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
149 void SetFontScale(float s) { mfScaling = s; };
150 virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
151 void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
153 static const int EXTRA_CONTEXT_LENGTH;
154 private:
155 void expandOrCondense(ImplLayoutArgs &rArgs);
156 void fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
158 float append(gr_segment * pSeg,
159 ImplLayoutArgs & rArgs,
160 const gr_slot * pSlot, float gOrigin,
161 float nextGlyphOrigin, float fScaling,
162 long & rDXOffset, bool bIsBase, int baseChar);
165 #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */