Line data Source code
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 _SV_GRAPHITELAYOUT_HXX
21 : #define _SV_GRAPHITELAYOUT_HXX
22 : // Description: An implementation of the SalLayout interface that uses the
23 : // Graphite engine.
24 :
25 : // We need this to enable namespace support in libgrengine headers.
26 : #define GR_NAMESPACE
27 :
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
40 :
41 : // Module type definitions and forward declarations.
42 : // SAL/VCL types
43 : class ServerFont;
44 :
45 : // Graphite types
46 : namespace grutils { class GrFeatureParser; }
47 :
48 : class GraphiteFaceWrapper
49 : {
50 : public:
51 : typedef std::map<int, gr_font*> GrFontMap;
52 0 : GraphiteFaceWrapper(gr_face * pFace) : m_pFace(pFace) {}
53 0 : ~GraphiteFaceWrapper()
54 0 : {
55 0 : GrFontMap::iterator i = m_fonts.begin();
56 0 : while (i != m_fonts.end())
57 0 : gr_font_destroy((*i++).second);
58 0 : m_fonts.clear();
59 0 : gr_face_destroy(m_pFace);
60 0 : }
61 0 : const gr_face * face() const { return m_pFace; }
62 0 : gr_font * font(int ppm) const
63 : {
64 0 : GrFontMap::const_iterator i = m_fonts.find(ppm);
65 0 : if (i != m_fonts.end())
66 0 : return i->second;
67 0 : return NULL;
68 : };
69 0 : void addFont(int ppm, gr_font * pFont)
70 : {
71 0 : if (m_fonts[ppm])
72 0 : gr_font_destroy(m_fonts[ppm]);
73 0 : m_fonts[ppm] = pFont;
74 0 : }
75 : private:
76 : gr_face * m_pFace;
77 : GrFontMap m_fonts;
78 : };
79 :
80 : // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
81 : // @author tse
82 : //
83 : class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout
84 : {
85 : public:
86 :
87 0 : class Glyphs : public std::vector<GlyphItem>
88 : {
89 : public:
90 : typedef std::pair<Glyphs::const_iterator, Glyphs::const_iterator> iterator_pair_t;
91 :
92 : };
93 :
94 : mutable Glyphs mvGlyphs;
95 : void clear();
96 :
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;
108 :
109 : public:
110 : GraphiteLayout(const gr_face * pFace, gr_font * pFont = NULL,
111 : const grutils::GrFeatureParser * features = NULL) throw();
112 :
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);
118 :
119 : virtual void AdjustLayout( ImplLayoutArgs& ); // adjusting positions
120 :
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);
125 :
126 : virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const;
127 :
128 : // methods using glyph indexing
129 : virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&,
130 : sal_Int32* pGlyphAdvAry = 0, int* pCharPosAry = 0 ) const;
131 :
132 : // used by glyph+font+script fallback
133 : virtual void MoveGlyph( int nStart, long nNewXPos );
134 : virtual void DropGlyph( int nStart );
135 : virtual void Simplify( bool bIsBase );
136 :
137 : // Dummy implementation so layout can be shared between Linux/Windows
138 0 : virtual void DrawText(SalGraphics&) const {};
139 :
140 : virtual ~GraphiteLayout() throw();
141 0 : void SetFont(gr_font * pFont) { mpFont = pFont; }
142 : gr_font * GetFont() { return mpFont; }
143 0 : void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; }
144 : void SetFontScale(float s) { mfScaling = s; };
145 : virtual sal_GlyphId getKashidaGlyph(int & width) = 0;
146 : void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width);
147 :
148 : static const int EXTRA_CONTEXT_LENGTH;
149 : private:
150 : void expandOrCondense(ImplLayoutArgs &rArgs);
151 : void fillFrom(gr_segment * rSeg, ImplLayoutArgs & rArgs, float fScaling);
152 :
153 : float append(gr_segment * pSeg,
154 : ImplLayoutArgs & rArgs,
155 : const gr_slot * pSlot, float gOrigin,
156 : float nextGlyphOrigin, float fScaling,
157 : long & rDXOffset, bool bIsBase, int baseChar);
158 : };
159 :
160 : #endif // _SV_GRAPHITELAYOUT_HXX
161 :
162 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|