1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SV_SALLAYOUT_HXX 29 #define _SV_SALLAYOUT_HXX 30 31 #include <tools/gen.hxx> 32 33 #include <vector> 34 namespace basegfx { 35 class B2DPolyPolygon; 36 typedef std::vector<B2DPolyPolygon> B2DPolyPolygonVector; 37 } 38 39 #ifndef _TOOLS_LANG_HXX 40 typedef unsigned short LanguageType; 41 #endif 42 43 #include <vector> 44 #include <list> 45 #include <vcl/dllapi.h> 46 47 // for typedef sal_UCS4 48 #include <vcl/vclenum.hxx> 49 50 class SalGraphics; 51 class ImplFontData; 52 53 #define MAX_FALLBACK 16 54 55 // ---------------- 56 // - LayoutOption - 57 // ---------------- 58 59 #define SAL_LAYOUT_BIDI_RTL 0x0001 60 #define SAL_LAYOUT_BIDI_STRONG 0x0002 61 #define SAL_LAYOUT_RIGHT_ALIGN 0x0004 62 #define SAL_LAYOUT_KERNING_PAIRS 0x0010 63 #define SAL_LAYOUT_KERNING_ASIAN 0x0020 64 #define SAL_LAYOUT_VERTICAL 0x0040 65 #define SAL_LAYOUT_COMPLEX_DISABLED 0x0100 66 #define SAL_LAYOUT_ENABLE_LIGATURES 0x0200 67 #define SAL_LAYOUT_SUBSTITUTE_DIGITS 0x0400 68 #define SAL_LAYOUT_KASHIDA_JUSTIFICATON 0x0800 69 #define SAL_LAYOUT_DISABLE_GLYPH_PROCESSING 0x1000 70 #define SAL_LAYOUT_FOR_FALLBACK 0x2000 71 72 // ----------------- 73 74 // used for managing runs e.g. for BiDi, glyph and script fallback 75 class VCL_PLUGIN_PUBLIC ImplLayoutRuns 76 { 77 private: 78 int mnRunIndex; 79 std::vector<int> maRuns; 80 81 public: 82 ImplLayoutRuns() { mnRunIndex = 0; maRuns.reserve(8); } 83 84 void Clear() { maRuns.clear(); } 85 bool AddPos( int nCharPos, bool bRTL ); 86 bool AddRun( int nMinRunPos, int nEndRunPos, bool bRTL ); 87 88 bool IsEmpty() const { return maRuns.empty(); } 89 void ResetPos() { mnRunIndex = 0; } 90 void NextRun() { mnRunIndex += 2; } 91 bool GetRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL ) const; 92 bool GetNextPos( int* nCharPos, bool* bRTL ); 93 bool PosIsInRun( int nCharPos ) const; 94 bool PosIsInAnyRun( int nCharPos ) const; 95 }; 96 97 // ----------------- 98 99 class ImplLayoutArgs 100 { 101 public: 102 // string related inputs 103 int mnFlags; 104 int mnLength; 105 int mnMinCharPos; 106 int mnEndCharPos; 107 const xub_Unicode* mpStr; 108 109 // positioning related inputs 110 const sal_Int32* mpDXArray; // in pixel units 111 long mnLayoutWidth; // in pixel units 112 int mnOrientation; // in 0-3600 system 113 114 // data for bidi and glyph+script fallback 115 ImplLayoutRuns maRuns; 116 ImplLayoutRuns maReruns; 117 118 public: 119 ImplLayoutArgs( const xub_Unicode* pStr, int nLength, 120 int nMinCharPos, int nEndCharPos, int nFlags ); 121 122 void SetLayoutWidth( long nWidth ) { mnLayoutWidth = nWidth; } 123 void SetDXArray( const sal_Int32* pDXArray ) { mpDXArray = pDXArray; } 124 void SetOrientation( int nOrientation ) { mnOrientation = nOrientation; } 125 126 void ResetPos() 127 { maRuns.ResetPos(); } 128 bool GetNextPos( int* nCharPos, bool* bRTL ) 129 { return maRuns.GetNextPos( nCharPos, bRTL ); } 130 bool GetNextRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL ); 131 bool NeedFallback( int nCharPos, bool bRTL ) 132 { return maReruns.AddPos( nCharPos, bRTL ); } 133 bool NeedFallback( int nMinRunPos, int nEndRunPos, bool bRTL ) 134 { return maReruns.AddRun( nMinRunPos, nEndRunPos, bRTL ); } 135 // methods used by BiDi and glyph fallback 136 bool NeedFallback() const 137 { return !maReruns.IsEmpty(); } 138 bool PrepareFallback(); 139 140 protected: 141 void AddRun( int nMinCharPos, int nEndCharPos, bool bRTL ); 142 }; 143 144 // helper functions often used with ImplLayoutArgs 145 bool IsDiacritic( sal_UCS4 ); 146 int GetVerticalFlags( sal_UCS4 ); 147 sal_UCS4 GetVerticalChar( sal_UCS4 ); 148 // #i80090# GetMirroredChar also needed outside vcl, moved to svapp.hxx 149 // VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 ); 150 sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType ); 151 VCL_PLUGIN_PUBLIC const char* GetAutofallback( sal_UCS4 ) ; 152 153 // ------------- 154 // - SalLayout - 155 // ------------- 156 157 typedef sal_uInt32 sal_GlyphId; 158 159 // Glyph Flags 160 #define GF_NONE 0x00000000 161 #define GF_FLAGMASK 0xFF800000 162 #define GF_IDXMASK ~GF_FLAGMASK 163 #define GF_ISCHAR 0x00800000 164 #define GF_ROTL 0x01000000 165 // caution !!! 166 #define GF_VERT 0x02000000 167 // GF_VERT is only for windows implementation 168 // (win/source/gdi/salgdi3.cxx, win/source/gdi/winlayout.cxx) 169 // don't use this elsewhere !!! 170 #define GF_ROTR 0x03000000 171 #define GF_ROTMASK 0x03000000 172 #define GF_UNHINTED 0x04000000 173 #define GF_GSUB 0x08000000 174 #define GF_FONTMASK 0xF0000000 175 #define GF_FONTSHIFT 28 176 177 #define GF_DROPPED 0xFFFFFFFF 178 179 // all positions/widths are in font units 180 // one exception: drawposition is in pixel units 181 182 class VCL_PLUGIN_PUBLIC SalLayout 183 { 184 public: 185 // used by upper layers 186 Point& DrawBase() { return maDrawBase; } 187 const Point& DrawBase() const { return maDrawBase; } 188 Point& DrawOffset() { return maDrawOffset; } 189 const Point& DrawOffset() const { return maDrawOffset; } 190 Point GetDrawPosition( const Point& rRelative = Point(0,0) ) const; 191 192 virtual bool LayoutText( ImplLayoutArgs& ) = 0; // first step of layouting 193 virtual void AdjustLayout( ImplLayoutArgs& ); // adjusting after fallback etc. 194 virtual void InitFont() const {} 195 virtual void DrawText( SalGraphics& ) const = 0; 196 197 int GetUnitsPerPixel() const { return mnUnitsPerPixel; } 198 int GetOrientation() const { return mnOrientation; } 199 200 virtual const ImplFontData* GetFallbackFontData( sal_GlyphId ) const; 201 202 // methods using string indexing 203 virtual int GetTextBreak( long nMaxWidth, long nCharExtra=0, int nFactor=1 ) const = 0; 204 virtual long FillDXArray( sal_Int32* pDXArray ) const = 0; 205 virtual long GetTextWidth() const { return FillDXArray( NULL ); } 206 virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const = 0; 207 virtual bool IsKashidaPosValid ( int /*nCharPos*/ ) const { return true; } // i60594 208 209 // methods using glyph indexing 210 virtual int GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIdAry, Point& rPos, int&, 211 sal_Int32* pGlyphAdvAry = NULL, int* pCharPosAry = NULL ) const = 0; 212 virtual bool GetOutline( SalGraphics&, ::basegfx::B2DPolyPolygonVector& ) const; 213 virtual bool GetBoundRect( SalGraphics&, Rectangle& ) const; 214 215 virtual bool IsSpacingGlyph( sal_GlyphId ) const; 216 217 // reference counting 218 void Reference() const; 219 void Release() const; 220 221 // used by glyph+font+script fallback 222 virtual void MoveGlyph( int nStart, long nNewXPos ) = 0; 223 virtual void DropGlyph( int nStart ) = 0; 224 virtual void Simplify( bool bIsBase ) = 0; 225 virtual void DisableGlyphInjection( bool /*bDisable*/ ) {} 226 227 protected: 228 // used by layout engines 229 SalLayout(); 230 virtual ~SalLayout(); 231 232 // used by layout layers 233 void SetUnitsPerPixel( int n ) { mnUnitsPerPixel = n; } 234 void SetOrientation( int nOrientation ) // in 0-3600 system 235 { mnOrientation = nOrientation; } 236 237 static int CalcAsianKerning( sal_UCS4, bool bLeft, bool bVertical ); 238 239 private: 240 // enforce proper copy semantic 241 SAL_DLLPRIVATE SalLayout( const SalLayout& ); 242 SAL_DLLPRIVATE SalLayout& operator=( const SalLayout& ); 243 244 protected: 245 int mnMinCharPos; 246 int mnEndCharPos; 247 int mnLayoutFlags; 248 249 int mnUnitsPerPixel; 250 int mnOrientation; 251 252 mutable int mnRefCount; 253 mutable Point maDrawOffset; 254 Point maDrawBase; 255 }; 256 257 // ------------------ 258 // - MultiSalLayout - 259 // ------------------ 260 261 class VCL_PLUGIN_PUBLIC MultiSalLayout : public SalLayout 262 { 263 public: 264 virtual void DrawText( SalGraphics& ) const; 265 virtual int GetTextBreak( long nMaxWidth, long nCharExtra, int nFactor ) const; 266 virtual long FillDXArray( sal_Int32* pDXArray ) const; 267 virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const; 268 virtual int GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIdxAry, Point& rPos, 269 int&, sal_Int32* pGlyphAdvAry, int* pCharPosAry ) const; 270 virtual bool GetOutline( SalGraphics&, ::basegfx::B2DPolyPolygonVector& ) const; 271 virtual bool GetBoundRect( SalGraphics&, Rectangle& ) const; 272 273 // used only by OutputDevice::ImplLayout, TODO: make friend 274 explicit MultiSalLayout( SalLayout& rBaseLayout, 275 const ImplFontData* pBaseFont = NULL ); 276 virtual bool AddFallback( SalLayout& rFallbackLayout, 277 ImplLayoutRuns&, const ImplFontData* pFallbackFont ); 278 virtual bool LayoutText( ImplLayoutArgs& ); 279 virtual void AdjustLayout( ImplLayoutArgs& ); 280 virtual void InitFont() const; 281 282 virtual const ImplFontData* GetFallbackFontData( sal_GlyphId ) const; 283 284 void SetInComplete(bool bInComplete = true); 285 286 protected: 287 virtual ~MultiSalLayout(); 288 289 private: 290 // dummy implementations 291 virtual void MoveGlyph( int, long ) {} 292 virtual void DropGlyph( int ) {} 293 virtual void Simplify( bool ) {} 294 295 // enforce proper copy semantic 296 SAL_DLLPRIVATE MultiSalLayout( const MultiSalLayout& ); 297 SAL_DLLPRIVATE MultiSalLayout& operator=( const MultiSalLayout& ); 298 299 private: 300 SalLayout* mpLayouts[ MAX_FALLBACK ]; 301 const ImplFontData* mpFallbackFonts[ MAX_FALLBACK ]; 302 ImplLayoutRuns maFallbackRuns[ MAX_FALLBACK ]; 303 int mnLevel; 304 bool mbInComplete; 305 }; 306 307 // -------------------- 308 // - GenericSalLayout - 309 // -------------------- 310 311 struct GlyphItem 312 { 313 int mnFlags; 314 int mnCharPos; // index in string 315 int mnOrigWidth; // original glyph width 316 int mnNewWidth; // width after adjustments 317 sal_GlyphId mnGlyphIndex; 318 Point maLinearPos; // absolute position of non rotated string 319 320 public: 321 GlyphItem() {} 322 323 GlyphItem( int nCharPos, sal_GlyphId nGlyphIndex, const Point& rLinearPos, 324 long nFlags, int nOrigWidth ) 325 : mnFlags(nFlags), mnCharPos(nCharPos), 326 mnOrigWidth(nOrigWidth), mnNewWidth(nOrigWidth), 327 mnGlyphIndex(nGlyphIndex), maLinearPos(rLinearPos) 328 {} 329 330 enum{ FALLBACK_MASK=0xFF, IS_IN_CLUSTER=0x100, IS_RTL_GLYPH=0x200, IS_DIACRITIC=0x400 }; 331 332 bool IsClusterStart() const { return ((mnFlags & IS_IN_CLUSTER) == 0); } 333 bool IsRTLGlyph() const { return ((mnFlags & IS_RTL_GLYPH) != 0); } 334 bool IsDiacritic() const { return ((mnFlags & IS_DIACRITIC) != 0); } 335 }; 336 337 // --------------- 338 339 typedef std::list<GlyphItem> GlyphList; 340 typedef std::vector<GlyphItem> GlyphVector; 341 342 // --------------- 343 344 class VCL_PLUGIN_PUBLIC GenericSalLayout : public SalLayout 345 { 346 public: 347 // used by layout engines 348 void AppendGlyph( const GlyphItem& ); 349 virtual void AdjustLayout( ImplLayoutArgs& ); 350 virtual void ApplyDXArray( ImplLayoutArgs& ); 351 virtual void Justify( long nNewWidth ); 352 void KashidaJustify( long nIndex, int nWidth ); 353 void ApplyAsianKerning( const sal_Unicode*, int nLength ); 354 void SortGlyphItems(); 355 356 // used by upper layers 357 virtual long GetTextWidth() const; 358 virtual long FillDXArray( sal_Int32* pDXArray ) const; 359 virtual int GetTextBreak( long nMaxWidth, long nCharExtra, int nFactor ) const; 360 virtual void GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const; 361 362 // used by display layers 363 virtual int GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIdxAry, Point& rPos, int&, 364 sal_Int32* pGlyphAdvAry = NULL, int* pCharPosAry = NULL ) const; 365 366 protected: 367 GenericSalLayout(); 368 virtual ~GenericSalLayout(); 369 370 // for glyph+font+script fallback 371 virtual void MoveGlyph( int nStart, long nNewXPos ); 372 virtual void DropGlyph( int nStart ); 373 virtual void Simplify( bool bIsBase ); 374 375 bool GetCharWidths( sal_Int32* pCharWidths ) const; 376 377 private: 378 GlyphItem* mpGlyphItems; // TODO: change to GlyphList 379 int mnGlyphCount; 380 int mnGlyphCapacity; 381 mutable Point maBasePoint; 382 383 // enforce proper copy semantic 384 SAL_DLLPRIVATE GenericSalLayout( const GenericSalLayout& ); 385 SAL_DLLPRIVATE GenericSalLayout& operator=( const GenericSalLayout& ); 386 }; 387 388 #undef SalGraphics 389 390 #endif // _SV_SALLAYOUT_HXX 391