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.
33 #include <graphite_static.hxx>
34 #include <graphite2/Font.h>
35 #include <graphite2/Segment.h>
37 #include <vcl/dllapi.h>
39 #include "sallayout.hxx"
42 class PhysicalFontFace
;
44 namespace grutils
{ class GrFeatureParser
; }
46 class GraphiteFaceWrapper
49 typedef std::pair
<int, int> GrFontMapKey
;
50 typedef std::map
<GrFontMapKey
, gr_font
*> GrFontMap
;
51 GraphiteFaceWrapper(gr_face
* pFace
) : m_pFace(pFace
) {}
52 ~GraphiteFaceWrapper()
54 GrFontMap::iterator i
= m_fonts
.begin();
55 while (i
!= m_fonts
.end())
56 gr_font_destroy((*i
++).second
);
58 gr_face_destroy(m_pFace
);
60 const gr_face
* face() const { return m_pFace
; }
61 gr_font
* font(int ppm
, bool isBold
, bool isItalic
) const
63 int styleKey
= int(isBold
) | (int(isItalic
) << 1);
64 GrFontMap::const_iterator i
= m_fonts
.find(GrFontMapKey(ppm
, styleKey
));
65 if (i
!= m_fonts
.end())
69 void addFont(int ppm
, gr_font
* pFont
, bool isBold
, bool isItalic
)
71 int styleKey
= int(isBold
) | (int(isItalic
) << 1);
72 GrFontMapKey
key(ppm
, styleKey
);
74 gr_font_destroy(m_fonts
[key
]);
82 // This class uses the SIL Graphite engine to provide complex text layout services to the VCL
85 class VCL_PLUGIN_PUBLIC GraphiteLayout
: public SalLayout
88 typedef std::vector
<GlyphItem
> Glyphs
;
90 mutable Glyphs mvGlyphs
;
94 const gr_face
* mpFace
; // not owned by layout
95 gr_font
* mpFont
; // not owned by layout
96 int mnSegCharOffset
; // relative to ImplLayoutArgs::mpStr
98 std::vector
<int> mvChar2BaseGlyph
;
99 std::vector
<int> mvGlyph2Char
;
100 std::vector
<int> mvCharDxs
;
101 std::vector
<int> mvCharBreaks
;
103 const grutils::GrFeatureParser
* mpFeatures
;
106 GraphiteLayout(const gr_face
* pFace
, gr_font
* pFont
= NULL
,
107 const grutils::GrFeatureParser
* features
= NULL
) throw();
109 // used by upper layers
110 virtual bool LayoutText( ImplLayoutArgs
& ) SAL_OVERRIDE
; // first step of layout
111 // split into two stages to allow dc to be restored on the segment
112 gr_segment
* CreateSegment(ImplLayoutArgs
& rArgs
);
113 bool LayoutGlyphs(ImplLayoutArgs
& rArgs
, gr_segment
* pSegment
);
115 virtual void AdjustLayout( ImplLayoutArgs
& ) SAL_OVERRIDE
; // adjusting positions
117 // methods using string indexing
118 virtual sal_Int32
GetTextBreak(DeviceCoordinate nMaxWidth
, DeviceCoordinate nCharExtra
=0, int nFactor
=1) const SAL_OVERRIDE
;
119 virtual DeviceCoordinate
FillDXArray( DeviceCoordinate
* pDXArray
) const SAL_OVERRIDE
;
120 void ApplyDXArray(ImplLayoutArgs
&rArgs
, std::vector
<int> & rDeltaWidth
);
122 virtual void GetCaretPositions( int nArraySize
, long* pCaretXArray
) const SAL_OVERRIDE
;
124 // methods using glyph indexing
125 virtual int GetNextGlyphs(int nLen
, sal_GlyphId
* pGlyphIdxAry
, ::Point
& rPos
, int&,
126 long* pGlyphAdvAry
= NULL
, int* pCharPosAry
= NULL
,
127 const PhysicalFontFace
** pFallbackFonts
= NULL
) const SAL_OVERRIDE
;
129 // used by glyph+font+script fallback
130 virtual void MoveGlyph( int nStart
, long nNewXPos
) SAL_OVERRIDE
;
131 virtual void DropGlyph( int nStart
) SAL_OVERRIDE
;
132 virtual void Simplify( bool bIsBase
) SAL_OVERRIDE
;
134 // Dummy implementation so layout can be shared between Linux/Windows
135 virtual void DrawText(SalGraphics
&) const SAL_OVERRIDE
{};
137 virtual ~GraphiteLayout() throw();
138 void SetFont(gr_font
* pFont
) { mpFont
= pFont
; }
139 gr_font
* GetFont() { return mpFont
; }
140 void SetFeatures(grutils::GrFeatureParser
* aFeature
) { mpFeatures
= aFeature
; }
141 void SetFontScale(float s
) { mfScaling
= s
; };
142 virtual sal_GlyphId
getKashidaGlyph(int & width
) = 0;
143 void kashidaJustify(std::vector
<int> & rDeltaWidth
, sal_GlyphId
, int width
);
145 static const int EXTRA_CONTEXT_LENGTH
;
147 void expandOrCondense(ImplLayoutArgs
&rArgs
);
148 void fillFrom(gr_segment
* rSeg
, ImplLayoutArgs
& rArgs
, float fScaling
);
150 float append(gr_segment
* pSeg
,
151 ImplLayoutArgs
& rArgs
,
152 const gr_slot
* pSlot
, float gOrigin
,
153 float nextGlyphOrigin
, float fScaling
,
154 long & rDXOffset
, bool bIsBase
, int baseChar
);
157 #endif // INCLUDED_VCL_INC_GRAPHITE_LAYOUT_HXX
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */