Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / inc / graphite_layout.hxx
blob434d6f6dca94a793ae5b0ada06c4036ff43b186f
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 <graphite2/Font.h>
35 #include <graphite2/Segment.h>
36 // Platform
37 #include <sallayout.hxx>
38 #include <vcl/dllapi.h>
39 // Module
41 // Module type definitions and forward declarations.
42 // SAL/VCL types
43 class ServerFont;
45 // Graphite types
46 namespace grutils { class GrFeatureParser; }
48 class GraphiteFaceWrapper
50 public:
51 typedef std::map<int, gr_font*> GrFontMap;
52 GraphiteFaceWrapper(gr_face * pFace) : m_pFace(pFace) {}
53 ~GraphiteFaceWrapper()
55 GrFontMap::iterator i = m_fonts.begin();
56 while (i != m_fonts.end())
57 gr_font_destroy((*i++).second);
58 m_fonts.clear();
59 gr_face_destroy(m_pFace);
61 const gr_face * face() const { return m_pFace; }
62 gr_font * font(int ppm) const
64 GrFontMap::const_iterator i = m_fonts.find(ppm);
65 if (i != m_fonts.end())
66 return i->second;
67 return NULL;
69 void addFont(int ppm, gr_font * pFont)
71 if (m_fonts[ppm])
72 gr_font_destroy(m_fonts[ppm]);
73 m_fonts[ppm] = pFont;
75 private:
76 gr_face * m_pFace;
77 GrFontMap m_fonts;
80 // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
81 // @author tse
83 class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout
85 public:
87 class Glyphs : public std::vector<GlyphItem>
89 public:
90 typedef std::pair<Glyphs::const_iterator, Glyphs::const_iterator> iterator_pair_t;
94 mutable Glyphs mvGlyphs;
95 void clear();
97 private:
98 const gr_face * mpFace; // not owned by layout
99 gr_font * mpFont; // not owned by layout
100 int mnSegCharOffset; // relative to ImplLayoutArgs::mpStr
101 long mnWidth;
102 std::vector<int> mvChar2BaseGlyph;
103 std::vector<int> mvGlyph2Char;
104 std::vector<int> mvCharDxs;
105 std::vector<int> mvCharBreaks;
106 float mfScaling;
107 const grutils::GrFeatureParser * mpFeatures;
109 public:
110 GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
111 const grutils::GrFeatureParser * features = NULL) throw();
113 // used by upper layers
114 virtual bool LayoutText( ImplLayoutArgs& ); // first step of layout
115 // split into two stages to allow dc to be restored on the segment
116 gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
117 bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
119 virtual void AdjustLayout( ImplLayoutArgs& ); // adjusting positions
121 // methods using string indexing
122 virtual int GetTextBreak( long nMaxWidth, long nCharExtra=0, int nFactor=1 ) const;
123 virtual long FillDXArray( sal_Int32* pDXArray ) const;
124 virtual void ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth);
126 virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const;
128 // methods using glyph indexing
129 virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
130 sal_Int32* pGlyphAdvAry = NULL, int* pCharPosAry = NULL,
131 const PhysicalFontFace** pFallbackFonts = NULL ) const;
133 // used by glyph+font+script fallback
134 virtual void MoveGlyph( int nStart, long nNewXPos );
135 virtual void DropGlyph( int nStart );
136 virtual void Simplify( bool bIsBase );
138 // Dummy implementation so layout can be shared between Linux/Windows
139 virtual void DrawText(SalGraphics&) const {};
141 virtual ~GraphiteLayout() throw();
142 void SetFont(gr_font * pFont) { mpFont = pFont; }
143 gr_font * GetFont() { return mpFont; }
144 void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
145 void SetFontScale(float s) { mfScaling = s; };
146 virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
147 void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
149 static const int EXTRA_CONTEXT_LENGTH;
150 private:
151 void expandOrCondense(ImplLayoutArgs &rArgs);
152 void fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
154 float append(gr_segment * pSeg,
155 ImplLayoutArgs & rArgs,
156 const gr_slot * pSlot, float gOrigin,
157 float nextGlyphOrigin, float fScaling,
158 long & rDXOffset, bool bIsBase, int baseChar);
161 #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */