LCOV - code coverage report
Current view: top level - vcl/inc - sallayout.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 41 80.5 %
Date: 2012-08-25 Functions: 30 38 78.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _SV_SALLAYOUT_HXX
      30                 :            : #define _SV_SALLAYOUT_HXX
      31                 :            : 
      32                 :            : #include <tools/gen.hxx>
      33                 :            : 
      34                 :            : #include <vector>
      35                 :            : namespace basegfx {
      36                 :            :     class B2DPolyPolygon;
      37                 :            :     typedef std::vector<B2DPolyPolygon> B2DPolyPolygonVector;
      38                 :            : }
      39                 :            : 
      40                 :            : #ifndef _TOOLS_LANG_HXX
      41                 :            : typedef unsigned short LanguageType;
      42                 :            : #endif
      43                 :            : 
      44                 :            : #include <vector>
      45                 :            : #include <list>
      46                 :            : #include <vcl/dllapi.h>
      47                 :            : 
      48                 :            : // for typedef sal_UCS4
      49                 :            : #include <vcl/vclenum.hxx>
      50                 :            : 
      51                 :            : class SalGraphics;
      52                 :            : class PhysicalFontFace;
      53                 :            : 
      54                 :            : #define MAX_FALLBACK 16
      55                 :            : 
      56                 :            : // ----------------
      57                 :            : // - LayoutOption -
      58                 :            : // ----------------
      59                 :            : 
      60                 :            : #define SAL_LAYOUT_BIDI_RTL                 0x0001
      61                 :            : #define SAL_LAYOUT_BIDI_STRONG              0x0002
      62                 :            : #define SAL_LAYOUT_RIGHT_ALIGN              0x0004
      63                 :            : #define SAL_LAYOUT_KERNING_PAIRS            0x0010
      64                 :            : #define SAL_LAYOUT_KERNING_ASIAN            0x0020
      65                 :            : #define SAL_LAYOUT_VERTICAL                 0x0040
      66                 :            : #define SAL_LAYOUT_COMPLEX_DISABLED         0x0100
      67                 :            : #define SAL_LAYOUT_ENABLE_LIGATURES         0x0200
      68                 :            : #define SAL_LAYOUT_SUBSTITUTE_DIGITS        0x0400
      69                 :            : #define SAL_LAYOUT_KASHIDA_JUSTIFICATON     0x0800
      70                 :            : #define SAL_LAYOUT_DISABLE_GLYPH_PROCESSING 0x1000
      71                 :            : #define SAL_LAYOUT_FOR_FALLBACK             0x2000
      72                 :            : 
      73                 :            : // -----------------
      74                 :            : 
      75                 :            : // used for managing runs e.g. for BiDi, glyph and script fallback
      76                 :    2224336 : class VCL_PLUGIN_PUBLIC ImplLayoutRuns
      77                 :            : {
      78                 :            : private:
      79                 :            :     int                 mnRunIndex;
      80                 :            :     std::vector<int>    maRuns;
      81                 :            : 
      82                 :            : public:
      83         [ +  - ]:    2121409 :             ImplLayoutRuns() { mnRunIndex = 0; maRuns.reserve(8); }
      84                 :            : 
      85                 :      18714 :     void    Clear()             { maRuns.clear(); }
      86                 :            :     bool    AddPos( int nCharPos, bool bRTL );
      87                 :            :     bool    AddRun( int nMinRunPos, int nEndRunPos, bool bRTL );
      88                 :            : 
      89                 :     999779 :     bool    IsEmpty() const     { return maRuns.empty(); }
      90                 :    1097144 :     void    ResetPos()          { mnRunIndex = 0; }
      91                 :    1973407 :     void    NextRun()           { mnRunIndex += 2; }
      92                 :            :     bool    GetRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL ) const;
      93                 :            :     bool    GetNextPos( int* nCharPos, bool* bRTL );
      94                 :            :     bool    PosIsInRun( int nCharPos ) const;
      95                 :            :     bool    PosIsInAnyRun( int nCharPos ) const;
      96                 :            : };
      97                 :            : 
      98                 :            : // -----------------
      99                 :            : 
     100         [ +  - ]:     999884 : class ImplLayoutArgs
     101                 :            : {
     102                 :            : public:
     103                 :            :     // string related inputs
     104                 :            :     int                 mnFlags;
     105                 :            :     int                 mnLength;
     106                 :            :     int                 mnMinCharPos;
     107                 :            :     int                 mnEndCharPos;
     108                 :            :     const xub_Unicode*  mpStr;
     109                 :            : 
     110                 :            :     // positioning related inputs
     111                 :            :     const sal_Int32*    mpDXArray;          // in pixel units
     112                 :            :     long                mnLayoutWidth;      // in pixel units
     113                 :            :     int                 mnOrientation;      // in 0-3600 system
     114                 :            : 
     115                 :            :     // data for bidi and glyph+script fallback
     116                 :            :     ImplLayoutRuns      maRuns;
     117                 :            :     ImplLayoutRuns      maReruns;
     118                 :            : 
     119                 :            : public:
     120                 :            :                 ImplLayoutArgs( const xub_Unicode* pStr, int nLength,
     121                 :            :                     int nMinCharPos, int nEndCharPos, int nFlags );
     122                 :            : 
     123                 :     981170 :     void        SetLayoutWidth( long nWidth )       { mnLayoutWidth = nWidth; }
     124                 :     981170 :     void        SetDXArray( const sal_Int32* pDXArray )  { mpDXArray = pDXArray; }
     125                 :     981170 :     void        SetOrientation( int nOrientation )  { mnOrientation = nOrientation; }
     126                 :            : 
     127                 :      40821 :     void        ResetPos()
     128                 :      40821 :                     { maRuns.ResetPos(); }
     129                 :    1680867 :     bool        GetNextPos( int* nCharPos, bool* bRTL )
     130                 :    1680867 :                     { return maRuns.GetNextPos( nCharPos, bRTL ); }
     131                 :            :     bool        GetNextRun( int* nMinRunPos, int* nEndRunPos, bool* bRTL );
     132                 :       9654 :     bool        NeedFallback( int nCharPos, bool bRTL )
     133                 :       9654 :                     { return maReruns.AddPos( nCharPos, bRTL ); }
     134                 :            :     bool        NeedFallback( int nMinRunPos, int nEndRunPos, bool bRTL )
     135                 :            :                     { return maReruns.AddRun( nMinRunPos, nEndRunPos, bRTL ); }
     136                 :            :     // methods used by BiDi and glyph fallback
     137                 :     981065 :     bool        NeedFallback() const
     138                 :     981065 :                     { return !maReruns.IsEmpty(); }
     139                 :            :     bool        PrepareFallback();
     140                 :            : 
     141                 :            : protected:
     142                 :            :     void        AddRun( int nMinCharPos, int nEndCharPos, bool bRTL );
     143                 :            : };
     144                 :            : 
     145                 :            : // helper functions often used with ImplLayoutArgs
     146                 :            : bool IsDiacritic( sal_UCS4 );
     147                 :            : int GetVerticalFlags( sal_UCS4 );
     148                 :            : sal_UCS4 GetVerticalChar( sal_UCS4 );
     149                 :            : // #i80090# GetMirroredChar also needed outside vcl, moved to svapp.hxx
     150                 :            : // VCL_DLLPUBLIC sal_UCS4 GetMirroredChar( sal_UCS4 );
     151                 :            : sal_UCS4 GetLocalizedChar( sal_UCS4, LanguageType );
     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                 :    1517983 :     Point&          DrawBase()                              { return maDrawBase; }
     187                 :       5844 :     const Point&    DrawBase() const                        { return maDrawBase; }
     188                 :      24977 :     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                 :      15579 :     virtual void    InitFont() const {}
     195                 :            :     virtual void    DrawText( SalGraphics& ) const = 0;
     196                 :            : 
     197                 :     874509 :     int             GetUnitsPerPixel() const                { return mnUnitsPerPixel; }
     198                 :          0 :     int             GetOrientation() const                  { return mnOrientation; }
     199                 :            : 
     200                 :            :     virtual const PhysicalFontFace* 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                 :        381 :     virtual long    GetTextWidth() const { return FillDXArray( NULL ); }
     206                 :            :     virtual void    GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const = 0;
     207                 :          0 :     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            Release() const;
     219                 :            : 
     220                 :            :     // used by glyph+font+script fallback
     221                 :            :     virtual void    MoveGlyph( int nStart, long nNewXPos ) = 0;
     222                 :            :     virtual void    DropGlyph( int nStart ) = 0;
     223                 :            :     virtual void    Simplify( bool bIsBase ) = 0;
     224                 :      37428 :     virtual void    DisableGlyphInjection( bool /*bDisable*/ ) {}
     225                 :            : 
     226                 :            : protected:
     227                 :            :     // used by layout engines
     228                 :            :                     SalLayout();
     229                 :            :     virtual         ~SalLayout();
     230                 :            : 
     231                 :            :     // used by layout layers
     232                 :          0 :     void            SetUnitsPerPixel( int n )               { mnUnitsPerPixel = n; }
     233                 :          0 :     void            SetOrientation( int nOrientation )      // in 0-3600 system
     234                 :          0 :                     { mnOrientation = nOrientation; }
     235                 :            : 
     236                 :            :     static int      CalcAsianKerning( sal_UCS4, bool bLeft, bool bVertical );
     237                 :            : 
     238                 :            : private:
     239                 :            :     // enforce proper copy semantic
     240                 :            :     SAL_DLLPRIVATE  SalLayout( const SalLayout& );
     241                 :            :     SAL_DLLPRIVATE  SalLayout& operator=( const SalLayout& );
     242                 :            : 
     243                 :            : protected:
     244                 :            :     int             mnMinCharPos;
     245                 :            :     int             mnEndCharPos;
     246                 :            :     int             mnLayoutFlags;
     247                 :            : 
     248                 :            :     int             mnUnitsPerPixel;
     249                 :            :     int             mnOrientation;
     250                 :            : 
     251                 :            :     mutable int     mnRefCount;
     252                 :            :     mutable Point   maDrawOffset;
     253                 :            :     Point           maDrawBase;
     254                 :            : };
     255                 :            : 
     256                 :            : // ------------------
     257                 :            : // - MultiSalLayout -
     258                 :            : // ------------------
     259                 :            : 
     260                 :            : class VCL_PLUGIN_PUBLIC MultiSalLayout : public SalLayout
     261                 :            : {
     262                 :            : public:
     263                 :            :     virtual void    DrawText( SalGraphics& ) const;
     264                 :            :     virtual int     GetTextBreak( long nMaxWidth, long nCharExtra, int nFactor ) const;
     265                 :            :     virtual long    FillDXArray( sal_Int32* pDXArray ) const;
     266                 :            :     virtual void    GetCaretPositions( int nArraySize, sal_Int32* pCaretXArray ) const;
     267                 :            :     virtual int     GetNextGlyphs( int nLen, sal_GlyphId* pGlyphIdxAry, Point& rPos,
     268                 :            :                         int&, sal_Int32* pGlyphAdvAry, int* pCharPosAry ) const;
     269                 :            :     virtual bool    GetOutline( SalGraphics&, ::basegfx::B2DPolyPolygonVector& ) const;
     270                 :            :     virtual bool    GetBoundRect( SalGraphics&, Rectangle& ) const;
     271                 :            : 
     272                 :            :     // used only by OutputDevice::ImplLayout, TODO: make friend
     273                 :            :     explicit        MultiSalLayout( SalLayout& rBaseLayout,
     274                 :            :                          const PhysicalFontFace* pBaseFont = NULL );
     275                 :            :     virtual bool    AddFallback( SalLayout& rFallbackLayout,
     276                 :            :                          ImplLayoutRuns&, const PhysicalFontFace* pFallbackFont );
     277                 :            :     virtual bool    LayoutText( ImplLayoutArgs& );
     278                 :            :     virtual void    AdjustLayout( ImplLayoutArgs& );
     279                 :            :     virtual void    InitFont() const;
     280                 :            : 
     281                 :            :     virtual const PhysicalFontFace* GetFallbackFontData( sal_GlyphId ) const;
     282                 :            : 
     283                 :            :     void SetInComplete(bool bInComplete = true);
     284                 :            : 
     285                 :            : protected:
     286                 :            :     virtual         ~MultiSalLayout();
     287                 :            : 
     288                 :            : private:
     289                 :            :     // dummy implementations
     290                 :          0 :     virtual void    MoveGlyph( int, long ) {}
     291                 :          0 :     virtual void    DropGlyph( int ) {}
     292                 :          0 :     virtual void    Simplify( bool ) {}
     293                 :            : 
     294                 :            :     // enforce proper copy semantic
     295                 :            :     SAL_DLLPRIVATE  MultiSalLayout( const MultiSalLayout& );
     296                 :            :     SAL_DLLPRIVATE  MultiSalLayout& operator=( const MultiSalLayout& );
     297                 :            : 
     298                 :            : private:
     299                 :            :     SalLayout*      mpLayouts[ MAX_FALLBACK ];
     300                 :            :     const PhysicalFontFace* mpFallbackFonts[ MAX_FALLBACK ];
     301                 :            :     ImplLayoutRuns  maFallbackRuns[ MAX_FALLBACK ];
     302                 :            :     int             mnLevel;
     303                 :            :     bool            mbInComplete;
     304                 :            : };
     305                 :            : 
     306                 :            : // --------------------
     307                 :            : // - GenericSalLayout -
     308                 :            : // --------------------
     309                 :            : 
     310                 :            : struct GlyphItem
     311                 :            : {
     312                 :            :     int     mnFlags;
     313                 :            :     int     mnCharPos;      // index in string
     314                 :            :     int     mnOrigWidth;    // original glyph width
     315                 :            :     int     mnNewWidth;     // width after adjustments
     316                 :            :     sal_GlyphId mnGlyphIndex;
     317                 :            :     Point   maLinearPos;    // absolute position of non rotated string
     318                 :            : 
     319                 :            : public:
     320                 :      25816 :             GlyphItem() {}
     321                 :            : 
     322                 :   22395212 :             GlyphItem( int nCharPos, sal_GlyphId nGlyphIndex, const Point& rLinearPos,
     323                 :            :                 long nFlags, int nOrigWidth )
     324                 :            :             :   mnFlags(nFlags), mnCharPos(nCharPos),
     325                 :            :                 mnOrigWidth(nOrigWidth), mnNewWidth(nOrigWidth),
     326                 :   22395212 :                 mnGlyphIndex(nGlyphIndex), maLinearPos(rLinearPos)
     327                 :   22395212 :             {}
     328                 :            : 
     329                 :            :     enum{ FALLBACK_MASK=0xFF, IS_IN_CLUSTER=0x100, IS_RTL_GLYPH=0x200, IS_DIACRITIC=0x400 };
     330                 :            : 
     331                 :   46511885 :     bool    IsClusterStart() const  { return ((mnFlags & IS_IN_CLUSTER) == 0); }
     332                 :    1668135 :     bool    IsRTLGlyph() const      { return ((mnFlags & IS_RTL_GLYPH) != 0); }
     333                 :   44709485 :     bool    IsDiacritic() const     { return ((mnFlags & IS_DIACRITIC) != 0); }
     334                 :            : };
     335                 :            : 
     336                 :            : // ---------------
     337                 :            : 
     338                 :            : typedef std::list<GlyphItem> GlyphList;
     339                 :            : typedef std::vector<GlyphItem> GlyphVector;
     340                 :            : 
     341                 :            : // ---------------
     342                 :            : 
     343                 :            : class VCL_PLUGIN_PUBLIC GenericSalLayout : public SalLayout
     344                 :            : {
     345                 :            : public:
     346                 :            :     // used by layout engines
     347                 :            :     void            AppendGlyph( const GlyphItem& );
     348                 :     993815 :     void            Reserve(int size) { m_GlyphItems.reserve(size + 1); }
     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                 :            :     GlyphVector     m_GlyphItems;
     379                 :            :     mutable Point   maBasePoint;
     380                 :            : 
     381                 :            :     // enforce proper copy semantic
     382                 :            :     SAL_DLLPRIVATE  GenericSalLayout( const GenericSalLayout& );
     383                 :            :     SAL_DLLPRIVATE  GenericSalLayout& operator=( const GenericSalLayout& );
     384                 :            : };
     385                 :            : 
     386                 :            : #undef SalGraphics
     387                 :            : 
     388                 :            : #endif // _SV_SALLAYOUT_HXX
     389                 :            : 
     390                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10