1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 // We need this to enable namespace support in libgrengine headers.
34 #include <graphite_static.hxx>
35 #include <graphite2/Font.h>
36 #include <graphite2/Segment.h>
38 #include <vcl/dllapi.h>
40 #include "sallayout.hxx"
44 // Module type definitions and forward declarations.
47 class PhysicalFontFace
;
50 namespace grutils
{ class GrFeatureParser
; }
52 class GraphiteFaceWrapper
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
);
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())
73 void addFont(int ppm
, gr_font
* pFont
)
76 gr_font_destroy(m_fonts
[ppm
]);
84 // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
87 class VCL_PLUGIN_PUBLIC GraphiteLayout
: public SalLayout
91 class Glyphs
: public std::vector
<GlyphItem
>
94 typedef std::pair
<Glyphs::const_iterator
, Glyphs::const_iterator
> iterator_pair_t
;
98 mutable Glyphs mvGlyphs
;
102 const gr_face
* mpFace
; // not owned by layout
103 gr_font
* mpFont
; // not owned by layout
104 int mnSegCharOffset
; // relative to ImplLayoutArgs::mpStr
106 std::vector
<int> mvChar2BaseGlyph
;
107 std::vector
<int> mvGlyph2Char
;
108 std::vector
<int> mvCharDxs
;
109 std::vector
<int> mvCharBreaks
;
111 const grutils::GrFeatureParser
* mpFeatures
;
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
;
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: */