Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_GRAPHITELAYOUT_HXX
30 : : #define _SV_GRAPHITELAYOUT_HXX
31 : : // Description: An implementation of the SalLayout interface that uses the
32 : : // Graphite engine.
33 : :
34 : : // We need this to enable namespace support in libgrengine headers.
35 : : #define GR_NAMESPACE
36 : :
37 : : // Standard Library
38 : : #include <memory>
39 : : #include <vector>
40 : : #include <map>
41 : : #include <utility>
42 : : // Libraries
43 : : #include <graphite2/Font.h>
44 : : #include <graphite2/Segment.h>
45 : : // Platform
46 : : #include <sallayout.hxx>
47 : : #include <vcl/dllapi.h>
48 : : // Module
49 : :
50 : : // Module type definitions and forward declarations.
51 : : // SAL/VCL types
52 : : class ServerFont;
53 : :
54 : : // Graphite types
55 : : namespace grutils { class GrFeatureParser; }
56 : :
57 : : class GraphiteFaceWrapper
58 : : {
59 : : public:
60 : : typedef std::map<int, gr_font*> GrFontMap;
61 : 0 : GraphiteFaceWrapper(gr_face * pFace) : m_pFace(pFace) {}
62 : 0 : ~GraphiteFaceWrapper()
63 : 0 : {
64 : 0 : GrFontMap::iterator i = m_fonts.begin();
65 [ # # ]: 0 : while (i != m_fonts.end())
66 [ # # ]: 0 : gr_font_destroy((*i++).second);
67 : 0 : m_fonts.clear();
68 [ # # ]: 0 : gr_face_destroy(m_pFace);
69 : 0 : }
70 : 0 : const gr_face * face() const { return m_pFace; }
71 : 0 : gr_font * font(int ppm) const
72 : : {
73 [ # # ]: 0 : GrFontMap::const_iterator i = m_fonts.find(ppm);
74 [ # # ]: 0 : if (i != m_fonts.end())
75 : 0 : return i->second;
76 : 0 : return NULL;
77 : : };
78 : 0 : void addFont(int ppm, gr_font * pFont)
79 : : {
80 [ # # ]: 0 : if (m_fonts[ppm])
81 : 0 : gr_font_destroy(m_fonts[ppm]);
82 : 0 : m_fonts[ppm] = pFont;
83 : 0 : }
84 : : private:
85 : : gr_face * m_pFace;
86 : : GrFontMap m_fonts;
87 : : };
88 : :
89 : : // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
90 : : // @author tse
91 : : //
92 : : class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout
93 : : {
94 : : public:
95 : :
96 : 0 : class Glyphs : public std::vector<GlyphItem>
97 : : {
98 : : public:
99 : : typedef std::pair<Glyphs::const_iterator, Glyphs::const_iterator> iterator_pair_t;
100 : :
101 : : };
102 : :
103 : : mutable Glyphs mvGlyphs;
104 : : void clear();
105 : :
106 : : private:
107 : : const gr_face * mpFace; // not owned by layout
108 : : gr_font * mpFont; // not owned by layout
109 : : int mnSegCharOffset; // relative to ImplLayoutArgs::mpStr
110 : : long mnWidth;
111 : : std::vector<int> mvChar2BaseGlyph;
112 : : std::vector<int> mvGlyph2Char;
113 : : std::vector<int> mvCharDxs;
114 : : std::vector<int> mvCharBreaks;
115 : : float mfScaling;
116 : : const grutils::GrFeatureParser * mpFeatures;
117 : :
118 : : public:
119 : : GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
120 : : const grutils::GrFeatureParser * features = NULL) throw();
121 : :
122 : : // used by upper layers
123 : : virtual bool LayoutText( ImplLayoutArgs& ); // first step of layout
124 : : // split into two stages to allow dc to be restored on the segment
125 : : gr_segment * CreateSegment(ImplLayoutArgs& rArgs);
126 : : bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr_segment * pSegment);
127 : :
128 : : virtual void AdjustLayout( ImplLayoutArgs& ); // adjusting positions
129 : :
130 : : // methods using string indexing
131 : : virtual int GetTextBreak( long nMaxWidth, long nCharExtra=0, int nFactor=1 ) const;
132 : : virtual long FillDXArray( sal_Int32* pDXArray ) const;
133 : : virtual void ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth);
134 : :
135 : : virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const;
136 : :
137 : : // methods using glyph indexing
138 : : virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
139 : : sal_Int32* pGlyphAdvAry = 0, int* pCharPosAry = 0 ) const;
140 : :
141 : : // used by glyph+font+script fallback
142 : : virtual void MoveGlyph( int nStart, long nNewXPos );
143 : : virtual void DropGlyph( int nStart );
144 : : virtual void Simplify( bool bIsBase );
145 : :
146 : : // Dummy implementation so layout can be shared between Linux/Windows
147 : 0 : virtual void DrawText(SalGraphics&) const {};
148 : :
149 : : virtual ~GraphiteLayout() throw();
150 : 0 : void SetFont(gr_font * pFont) { mpFont = pFont; }
151 : : gr_font * GetFont() { return mpFont; }
152 : 0 : void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
153 : : void SetFontScale(float s) { mfScaling = s; };
154 : : virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
155 : : void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
156 : :
157 : : static const int EXTRA_CONTEXT_LENGTH;
158 : : private:
159 : : void expandOrCondense(ImplLayoutArgs &rArgs);
160 : : void fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
161 : :
162 : : float append(gr_segment * pSeg,
163 : : ImplLayoutArgs & rArgs,
164 : : const gr_slot * pSlot, float gOrigin,
165 : : float nextGlyphOrigin, float fScaling,
166 : : long & rDXOffset, bool bIsBase, int baseChar);
167 : : };
168 : :
169 : : #endif // _SV_GRAPHITELAYOUT_HXX
170 : :
171 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|