LCOV - code coverage report
Current view: top level - libreoffice/vcl/inc - sallayout.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 41 75.6 %
Date: 2012-12-27 Functions: 28 38 73.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10