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