LCOV - code coverage report
Current view: top level - sw/source/core/text - pormulti.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 53 81.1 %
Date: 2015-06-13 12:38:46 Functions: 39 46 84.8 %
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             : #ifndef INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
      20             : #define INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
      21             : 
      22             : #include "porlay.hxx"
      23             : #include "porexp.hxx"
      24             : 
      25             : class SwTextFormatInfo;
      26             : class SwFieldPortion;
      27             : class SwTextCursor;
      28             : class SwLineLayout;
      29             : class SwTextPaintInfo;
      30             : class SwTextAttr;
      31             : class SfxPoolItem;
      32             : class SwFont;
      33             : 
      34             : // SwMultiCreator is a small structure to create a multiportion.
      35             : // It contains the kind of multiportion and a textattribute
      36             : // or a poolitem.
      37             : // The GetMultiCreator-function fills this structure and
      38             : // the Ctor of the SwMultiPortion uses it.
      39             : #define SW_MC_DOUBLE    0
      40             : #define SW_MC_RUBY      1
      41             : #define SW_MC_ROTATE    2
      42             : #define SW_MC_BIDI      3
      43             : 
      44             : struct SwMultiCreator
      45             : {
      46             :     const SwTextAttr* pAttr;
      47             :     const SfxPoolItem* pItem;
      48             :     sal_uInt8 nId;
      49             :     sal_uInt8 nLevel;
      50             : };
      51             : 
      52             : // A two-line-portion (SwMultiPortion) could have surrounding brackets,
      53             : // in this case the structure SwBracket will be used.
      54             : struct SwBracket
      55             : {
      56             :     sal_Int32 nStart;      // Start of text attribute determins the font
      57             :     sal_uInt16 nAscent;         // Ascent of the brackets
      58             :     sal_uInt16 nHeight;         // Height of them
      59             :     sal_uInt16 nPreWidth;       // Width of the opening bracket
      60             :     sal_uInt16 nPostWidth;      // Width of the closing bracket
      61             :     sal_Unicode cPre;       // Initial character, e.g. '('
      62             :     sal_Unicode cPost;      // Final character, e.g. ')'
      63             :     sal_uInt8 nPreScript;       // Script of the initial character
      64             :     sal_uInt8 nPostScript;       // Script of the final character
      65             : };
      66             : 
      67             : // The SwMultiPortion is line portion inside a line portion,
      68             : // it's a group of portions,
      69             : // e.g. a double line portion in a line
      70             : // or phonetics (ruby)
      71             : // or combined characters
      72             : // or a rotated portion.
      73             : class SwMultiPortion : public SwLinePortion
      74             : {
      75             :     SwLineLayout aRoot;     // One or more lines
      76             :     SwFieldPortion *pFieldRest; // Field rest from the previous line
      77             :     bool bTab1      :1;     // First line tabulator
      78             :     bool bTab2      :1;     // Second line includes tabulator
      79             :     bool bDouble    :1;     // Double line
      80             :     bool bRuby      :1;     // Phonetics
      81             :     bool bBidi      :1;
      82             :     bool bTop       :1;     // Phonetic position
      83             :     bool bFormatted :1;     // Already formatted
      84             :     bool bFollowField :1;     // Field follow inside
      85             :     bool bFlyInContent:1;     // Fly as character inside
      86             :     sal_uInt8 nDirection:2; // Direction (0/90/180/270 degrees)
      87             : protected:
      88         246 :     explicit SwMultiPortion(sal_Int32 nEnd)
      89             :         : pFieldRest(0)
      90             :         , bTab1(false)
      91             :         , bTab2(false)
      92             :         , bDouble(false)
      93             :         , bRuby(false)
      94             :         , bBidi(false)
      95             :         , bTop(false)
      96             :         , bFormatted(false)
      97             :         , bFollowField(false)
      98             :         , bFlyInContent(false)
      99         246 :         , nDirection(0)
     100             :     {
     101         246 :         SetWhichPor(POR_MULTI);
     102         246 :         SetLen(nEnd);
     103         246 :     }
     104           5 :     void SetDouble() { bDouble = true; }
     105         157 :     void SetRuby() { bRuby = true; }
     106          43 :     void SetBidi() { bBidi = true; }
     107         157 :     void SetTop( bool bNew ) { bTop = bNew; }
     108           5 :     void SetTab1( bool bNew ) { bTab1 = bNew; }
     109           5 :     void SetTab2( bool bNew ) { bTab2 = bNew; }
     110         246 :     void SetDirection( sal_uInt8 nNew ) { nDirection = nNew; }
     111           2 :     bool GetTab1() const { return bTab1; }
     112          14 :     bool GetTab2() const { return bTab2; }
     113             : public:
     114             :     virtual ~SwMultiPortion();
     115           9 :     const SwLineLayout& GetRoot() const { return aRoot; }
     116        5097 :     SwLineLayout& GetRoot() { return aRoot; }
     117             :     SwFieldPortion* GetFieldRest() { return pFieldRest; }
     118             :     void SetFieldRest( SwFieldPortion* pNew ) { pFieldRest = pNew; }
     119             : 
     120        1016 :     inline bool HasTabulator() const { return bTab1 || bTab2; }
     121         246 :     inline bool IsFormatted() const { return bFormatted; }
     122         246 :     inline void SetFormatted() { bFormatted = true; }
     123           0 :     inline bool IsFollowField() const { return bFollowField; }
     124           0 :     inline void SetFollowField() { bFollowField = true; }
     125         625 :     inline bool HasFlyInContent() const { return bFlyInContent; }
     126         463 :     inline void SetFlyInContent( bool bNew ) { bFlyInContent = bNew; }
     127        2663 :     inline bool IsDouble() const { return bDouble; }
     128        2296 :     inline bool IsRuby() const { return bRuby; }
     129        4452 :     inline bool IsBidi() const { return bBidi; }
     130        1732 :     inline bool OnTop() const { return bTop; }
     131             :     void ActualizeTabulator();
     132             : 
     133             :     virtual void Paint( const SwTextPaintInfo &rInf ) const SAL_OVERRIDE;
     134             :     virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const SAL_OVERRIDE;
     135             :     virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
     136             : 
     137             :     // Summarize the internal lines to calculate the (external) size
     138             :     void CalcSize( SwTextFormatter& rLine, SwTextFormatInfo &rInf );
     139             : 
     140             :     inline bool HasBrackets() const;
     141        1764 :     inline bool HasRotation() const { return 0 != (1 & nDirection); }
     142           2 :     inline bool IsRevers() const { return 0 != (2 & nDirection); }
     143         170 :     inline sal_uInt8 GetDirection() const { return nDirection; }
     144             :     inline sal_uInt16 GetFontRotation() const
     145             :         { return ( HasRotation() ? ( IsRevers() ? 2700 : 900 ) : 0 ); }
     146             : 
     147             :     // Accessibility: pass information about this portion to the PortionHandler
     148             :     virtual void HandlePortion( SwPortionHandler& rPH ) const SAL_OVERRIDE;
     149             : 
     150             :     OUTPUT_OPERATOR_OVERRIDE
     151             : };
     152             : 
     153             : class SwDoubleLinePortion : public SwMultiPortion
     154             : {
     155             :     SwBracket* pBracket;    // Surrounding brackets
     156             :     SwTwips nLineDiff;      // Difference of the width of the both lines
     157             :     sal_Int32 nBlank1;     // Number of blanks in the first line
     158             :     sal_Int32 nBlank2;     // Number of blanks in the second line
     159             : public:
     160             :     SwDoubleLinePortion( SwDoubleLinePortion& rDouble, sal_Int32 nEnd );
     161             :     SwDoubleLinePortion( const SwMultiCreator& rCreate, sal_Int32 nEnd );
     162             :     virtual ~SwDoubleLinePortion();
     163             : 
     164         218 :     inline SwBracket* GetBrackets() const { return pBracket; }
     165             :     void SetBrackets( const SwDoubleLinePortion& rDouble );
     166             :     void PaintBracket( SwTextPaintInfo& rInf, long nSpaceAdd, bool bOpen ) const;
     167             :     void FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxWidth );
     168          26 :     inline sal_uInt16 PreWidth() const { return pBracket->nPreWidth; };
     169          10 :     inline sal_uInt16 PostWidth() const { return pBracket->nPostWidth; }
     170           0 :     inline void ClearBrackets()
     171           0 :         { pBracket->nPreWidth = pBracket->nPostWidth=0; Width( 0 ); }
     172           4 :     inline sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
     173             : 
     174             :     void CalcBlanks( SwTextFormatInfo &rInf );
     175             :     static void ResetSpaceAdd( SwLineLayout* pCurr );
     176          10 :     inline SwTwips GetLineDiff() const { return nLineDiff; }
     177           0 :     inline sal_Int32 GetSpaceCnt() const
     178           0 :         { return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; }
     179           0 :     inline sal_Int32 GetSmallerSpaceCnt() const
     180           0 :         { return ( nLineDiff < 0 ) ? nBlank1 : nBlank2; }
     181             :     inline sal_Int32 GetBlank1() const { return nBlank1; }
     182             :     inline sal_Int32 GetBlank2() const { return nBlank2; }
     183             : 
     184             :     virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const SAL_OVERRIDE;
     185             :     virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const SAL_OVERRIDE;
     186             : };
     187             : 
     188         314 : class SwRubyPortion : public SwMultiPortion
     189             : {
     190             :     sal_Int32 nRubyOffset;
     191             :     sal_uInt16 nAdjustment;
     192             :     void _Adjust( SwTextFormatInfo &rInf);
     193             : public:
     194             :     SwRubyPortion( const SwRubyPortion& rRuby, sal_Int32 nEnd );
     195             : 
     196             :     SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
     197             :                    const IDocumentSettingAccess& rIDocumentSettingAccess,
     198             :                    sal_Int32 nEnd, sal_Int32 nOffs,
     199             :                    const bool* pForceRubyPos );
     200             : 
     201             :     void CalcRubyOffset();
     202         157 :     inline void Adjust( SwTextFormatInfo &rInf )
     203         157 :         { if(nAdjustment && GetRoot().GetNext()) _Adjust(rInf); }
     204           0 :     inline sal_uInt16 GetAdjustment() const { return nAdjustment; }
     205           0 :     inline sal_Int32 GetRubyOffset() const { return nRubyOffset; }
     206             : };
     207             : 
     208          82 : class SwRotatedPortion : public SwMultiPortion
     209             : {
     210             : public:
     211           1 :     SwRotatedPortion( sal_Int32 nEnd, sal_uInt8 nDir = 1 )
     212           1 :         : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
     213             :     SwRotatedPortion( const SwMultiCreator& rCreate, sal_Int32 nEnd,
     214             :                       bool bRTL );
     215             : };
     216             : 
     217          86 : class SwBidiPortion : public SwMultiPortion
     218             : {
     219             :     sal_uInt8 nLevel;
     220             : 
     221             : public:
     222             :     SwBidiPortion( sal_Int32 nEnd, sal_uInt8 nLv );
     223             : 
     224         264 :     inline sal_uInt8 GetLevel() const { return nLevel; }
     225             :     // Get number of blanks for justified alignment
     226             :     sal_Int32 GetSpaceCnt( const SwTextSizeInfo &rInf ) const;
     227             :     // Calculates extra spacing based on number of blanks
     228             :     virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const SAL_OVERRIDE;
     229             :     // Manipulate the spacing array at pCurr
     230             :     virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const SAL_OVERRIDE;
     231             : };
     232             : 
     233             : // For cursor travelling in multiportions
     234             : 
     235             : class SwTextCursorSave
     236             : {
     237             :     SwTextCursor* pTextCrsr;
     238             :     SwLineLayout* pCurr;
     239             :     sal_Int32 nStart;
     240             :     sal_uInt16 nWidth;
     241             :     sal_uInt8 nOldProp;
     242             :     bool bSpaceChg;
     243             : public:
     244             :     SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
     245             :         SwTwips nY, sal_uInt16& nX, sal_Int32 nCurrStart, long nSpaceAdd );
     246             :     ~SwTextCursorSave();
     247             : };
     248             : 
     249        1212 : inline bool SwMultiPortion::HasBrackets() const
     250             : {
     251        1212 :     return IsDouble() && 0 != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
     252             : }
     253             : 
     254             : #endif
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11