1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _SV_GRAPHITELAYOUT_HXX 29*cdf0e10cSrcweir #define _SV_GRAPHITELAYOUT_HXX 30*cdf0e10cSrcweir // Description: An implementation of the SalLayout interface that uses the 31*cdf0e10cSrcweir // Graphite engine. 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir // We need this to enable namespace support in libgrengine headers. 34*cdf0e10cSrcweir #define GR_NAMESPACE 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #define GRCACHE 1 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // Standard Library 39*cdf0e10cSrcweir #include <memory> 40*cdf0e10cSrcweir #include <vector> 41*cdf0e10cSrcweir #include <utility> 42*cdf0e10cSrcweir // Libraries 43*cdf0e10cSrcweir #include <preextstl.h> 44*cdf0e10cSrcweir #include <graphite/GrClient.h> 45*cdf0e10cSrcweir #include <graphite/Font.h> 46*cdf0e10cSrcweir #include <graphite/GrConstants.h> 47*cdf0e10cSrcweir #include <graphite/GrAppData.h> 48*cdf0e10cSrcweir #include <graphite/SegmentAux.h> 49*cdf0e10cSrcweir #include <postextstl.h> 50*cdf0e10cSrcweir // Platform 51*cdf0e10cSrcweir #include <sallayout.hxx> 52*cdf0e10cSrcweir #include <vcl/dllapi.h> 53*cdf0e10cSrcweir // Module 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // For backwards compatibility with 2.4.x 56*cdf0e10cSrcweir #if (SUPD == 680) 57*cdf0e10cSrcweir typedef sal_Int32 sal_GlyphId; 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // Module type definitions and forward declarations. 62*cdf0e10cSrcweir // 63*cdf0e10cSrcweir class TextSourceAdaptor; 64*cdf0e10cSrcweir class GraphiteFontAdaptor; 65*cdf0e10cSrcweir class GrSegRecord; 66*cdf0e10cSrcweir // SAL/VCL types 67*cdf0e10cSrcweir class ServerFont; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #ifdef WNT 70*cdf0e10cSrcweir // The GraphiteWinFont is just a wrapper to enable GrFontHasher to be a friend 71*cdf0e10cSrcweir // so that UniqueCacheInfo can be called. 72*cdf0e10cSrcweir #include <graphite/WinFont.h> 73*cdf0e10cSrcweir class GraphiteWinFont : public gr::WinFont 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir friend class GrFontHasher; 76*cdf0e10cSrcweir public: 77*cdf0e10cSrcweir GraphiteWinFont(HDC hdc) : gr::WinFont(hdc) {}; 78*cdf0e10cSrcweir virtual ~GraphiteWinFont() {}; 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir #endif 81*cdf0e10cSrcweir // Graphite types 82*cdf0e10cSrcweir namespace gr { class Segment; class GlyphIterator; } 83*cdf0e10cSrcweir namespace grutils { class GrFeatureParser; } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // This class uses the SIL Graphite engine to provide complex text layout services to the VCL 86*cdf0e10cSrcweir // @author tse 87*cdf0e10cSrcweir // 88*cdf0e10cSrcweir class VCL_PLUGIN_PUBLIC GraphiteLayout : public SalLayout 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir public: 91*cdf0e10cSrcweir // Mask to allow Word break status to be stored within mvChar2BaseGlyph 92*cdf0e10cSrcweir enum { 93*cdf0e10cSrcweir WORD_BREAK_BEFORE = 0x40000000, 94*cdf0e10cSrcweir HYPHEN_BREAK_BEFORE = 0x80000000, 95*cdf0e10cSrcweir BREAK_MASK = 0xC0000000, 96*cdf0e10cSrcweir GLYPH_INDEX_MASK = 0x3FFFFFFF 97*cdf0e10cSrcweir } LineBreakMask; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir class Glyphs : public std::vector<GlyphItem> 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir public: 102*cdf0e10cSrcweir typedef std::pair<Glyphs::const_iterator, Glyphs::const_iterator> iterator_pair_t; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void fill_from(gr::Segment & rSeg, ImplLayoutArgs & rArgs, 105*cdf0e10cSrcweir bool bRtl, long &rWidth, float fScaling, 106*cdf0e10cSrcweir std::vector<int> & rChar2Base, std::vector<int> & rGlyph2Char, 107*cdf0e10cSrcweir std::vector<int> & rCharDxs); 108*cdf0e10cSrcweir void move_glyph(Glyphs::iterator, long dx); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir const_iterator cluster_base(const_iterator) const; 111*cdf0e10cSrcweir iterator_pair_t neighbour_clusters(const_iterator) const; 112*cdf0e10cSrcweir private: 113*cdf0e10cSrcweir std::pair<float,float> appendCluster(gr::Segment & rSeg, ImplLayoutArgs & rArgs, 114*cdf0e10cSrcweir bool bRtl, float fSegmentAdvance, int nFirstCharInCluster, int nNextChar, 115*cdf0e10cSrcweir int nFirstGlyphInCluster, int nNextGlyph, float fScaling, 116*cdf0e10cSrcweir std::vector<int> & rChar2Base, std::vector<int> & rGlyph2Char, 117*cdf0e10cSrcweir std::vector<int> & rCharDxs, long & rDXOffset); 118*cdf0e10cSrcweir void append(gr::Segment & rSeg, ImplLayoutArgs & rArgs, gr::GlyphInfo & rGi, float nextGlyphOrigin, float fScaling, std::vector<int> & rChar2Base, std::vector<int> & rGlyph2Char, std::vector<int> & rCharDxs, long & rDXOffset, bool bIsBase); 119*cdf0e10cSrcweir }; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir mutable Glyphs mvGlyphs; 122*cdf0e10cSrcweir void clear(); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir private: 125*cdf0e10cSrcweir TextSourceAdaptor * mpTextSrc; // Text source. 126*cdf0e10cSrcweir gr::LayoutEnvironment maLayout; 127*cdf0e10cSrcweir const gr::Font &mrFont; 128*cdf0e10cSrcweir long mnWidth; 129*cdf0e10cSrcweir std::vector<int> mvCharDxs; 130*cdf0e10cSrcweir std::vector<int> mvChar2BaseGlyph; 131*cdf0e10cSrcweir std::vector<int> mvGlyph2Char; 132*cdf0e10cSrcweir float mfScaling; 133*cdf0e10cSrcweir const grutils::GrFeatureParser * mpFeatures; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir public: 136*cdf0e10cSrcweir explicit GraphiteLayout( const gr::Font& font, const grutils::GrFeatureParser* features = NULL ) throw(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // used by upper layers 139*cdf0e10cSrcweir virtual bool LayoutText( ImplLayoutArgs& ); // first step of layout 140*cdf0e10cSrcweir // split into two stages to allow dc to be restored on the segment 141*cdf0e10cSrcweir #ifdef GRCACHE 142*cdf0e10cSrcweir gr::Segment * CreateSegment(ImplLayoutArgs& rArgs, GrSegRecord ** pRecord = NULL); 143*cdf0e10cSrcweir bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr::Segment * pSegment, GrSegRecord * pSegRecord); 144*cdf0e10cSrcweir #else 145*cdf0e10cSrcweir gr::Segment * CreateSegment(ImplLayoutArgs& rArgs); 146*cdf0e10cSrcweir bool LayoutGlyphs(ImplLayoutArgs& rArgs, gr::Segment * pSegment); 147*cdf0e10cSrcweir #endif 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir virtual void AdjustLayout( ImplLayoutArgs& ); // adjusting positions 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // methods using string indexing 152*cdf0e10cSrcweir virtual int GetTextBreak( long nMaxWidth, long nCharExtra=0, int nFactor=1 ) const; 153*cdf0e10cSrcweir virtual long FillDXArray( sal_Int32* pDXArray ) const; 154*cdf0e10cSrcweir virtual void ApplyDXArray(ImplLayoutArgs &rArgs, std::vector<int> & rDeltaWidth); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // methods using glyph indexing 159*cdf0e10cSrcweir virtual int GetNextGlyphs(int nLen, sal_GlyphId* pGlyphIdxAry, ::Point & rPos, int&, 160*cdf0e10cSrcweir sal_Int32* pGlyphAdvAry = 0, int* pCharPosAry = 0 ) const; 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // used by glyph+font+script fallback 163*cdf0e10cSrcweir virtual void MoveGlyph( int nStart, long nNewXPos ); 164*cdf0e10cSrcweir virtual void DropGlyph( int nStart ); 165*cdf0e10cSrcweir virtual void Simplify( bool bIsBase ); 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // Dummy implementation so layout can be shared between Linux/Windows 168*cdf0e10cSrcweir virtual void DrawText(SalGraphics&) const {}; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir virtual ~GraphiteLayout() throw(); 171*cdf0e10cSrcweir void SetFeatures(grutils::GrFeatureParser * aFeature) { mpFeatures = aFeature; } 172*cdf0e10cSrcweir void SetFontScale(float s) { mfScaling = s; }; 173*cdf0e10cSrcweir const TextSourceAdaptor * textSrc() const { return mpTextSrc; }; 174*cdf0e10cSrcweir virtual sal_GlyphId getKashidaGlyph(int & width) = 0; 175*cdf0e10cSrcweir void kashidaJustify(std::vector<int> & rDeltaWidth, sal_GlyphId, int width); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir static const int EXTRA_CONTEXT_LENGTH; 178*cdf0e10cSrcweir private: 179*cdf0e10cSrcweir int glyph_to_char(Glyphs::iterator); 180*cdf0e10cSrcweir std::pair<int,int> glyph_to_chars(const GlyphItem &) const; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir std::pair<long,long> caret_positions(size_t) const; 183*cdf0e10cSrcweir void expandOrCondense(ImplLayoutArgs &rArgs); 184*cdf0e10cSrcweir }; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir #endif // _SV_GRAPHITELAYOUT_HXX 187