LCOV - code coverage report
Current view: top level - sw/source/core/inc - scriptinfo.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 25 39 64.1 %
Date: 2014-11-03 Functions: 15 22 68.2 %
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 INCLUDED_SW_SOURCE_CORE_INC_SCRIPTINFO_HXX
      21             : #define INCLUDED_SW_SOURCE_CORE_INC_SCRIPTINFO_HXX
      22             : 
      23             : #include <list>
      24             : #include <deque>
      25             : #include "swscanner.hxx"
      26             : #include <rtl/ustrbuf.hxx>
      27             : 
      28             : class SwTxtNode;
      29             : class Point;
      30             : class MultiSelection;
      31             : typedef std::list< sal_Int32 > PositionList;
      32             : 
      33             : #define SPACING_PRECISION_FACTOR 100
      34             : 
      35             : // encapsultes information about script changes
      36             : class SwScriptInfo
      37             : {
      38             : public:
      39             :     enum CompType { KANA, SPECIAL_LEFT, SPECIAL_RIGHT, NONE };
      40             : 
      41             : private:
      42             :     //! Records a single change in script type.
      43             :     struct ScriptChangeInfo
      44             :     {
      45             :         sal_Int32 position; //!< Character position at which we change script
      46             :         sal_uInt8       type;     //!< Script type (Latin/Asian/Complex) that we change to.
      47       84433 :         inline ScriptChangeInfo(sal_Int32 pos, sal_uInt8 typ) : position(pos), type(typ) {};
      48             :     };
      49             :     //TODO - This is sorted, so should probably be a std::set rather than vector.
      50             :     //       But we also use random access (probably unnecessarily).
      51             :     std::vector<ScriptChangeInfo> aScriptChanges;
      52             :     //! Records a single change in direction.
      53             :     struct DirectionChangeInfo
      54             :     {
      55             :         sal_Int32 position; //!< Character position at which we change direction.
      56             :         sal_uInt8       type;     //!< Direction that we change to.
      57          74 :         inline DirectionChangeInfo(sal_Int32 pos, sal_uInt8 typ) : position(pos), type(typ) {};
      58             :     };
      59             :     std::vector<DirectionChangeInfo> aDirectionChanges;
      60             :     std::deque< sal_Int32 > aKashida;
      61             :     std::deque< sal_Int32 > aKashidaInvalid;
      62             :     std::deque< sal_Int32 > aNoKashidaLine;
      63             :     std::deque< sal_Int32 > aNoKashidaLineEnd;
      64             :     std::deque< sal_Int32 > aHiddenChg;
      65             :     //! Records a single change in compression.
      66             :     struct CompressionChangeInfo
      67             :     {
      68             :         sal_Int32 position; //!< Character position where the change occurs.
      69             :         sal_Int32 length;   //!< Length of the segment.
      70             :         CompType  type;     //!< Type of compression that we change to.
      71           0 :         inline CompressionChangeInfo(sal_Int32 pos, sal_Int32 len, CompType typ) : position(pos), length(len), type(typ) {};
      72             :     };
      73             :     std::vector<CompressionChangeInfo> aCompressionChanges;
      74             : #ifdef DBG_UTIL
      75             :     CompType DbgCompType( const sal_Int32 nPos ) const;
      76             : #endif
      77             : 
      78             :     sal_Int32 nInvalidityPos;
      79             :     sal_uInt8 nDefaultDir;
      80             : 
      81             :     void UpdateBidiInfo( const OUString& rTxt );
      82             : 
      83             :     bool IsKashidaValid(sal_Int32 nKashPos) const;
      84             :     void MarkKashidaInvalid(sal_Int32 nKashPos);
      85             :     void ClearKashidaInvalid(sal_Int32 nKashPos);
      86             :     bool MarkOrClearKashidaInvalid(sal_Int32 nStt, sal_Int32 nLen, bool bMark, sal_Int32 nMarkCount);
      87             :     bool IsKashidaLine(sal_Int32 nCharIdx) const;
      88             :     // examines the range [ nStart, nStart + nEnd ] if there are kanas
      89             :     // returns start index of kana entry in array, otherwise SAL_MAX_SIZE
      90             :     size_t HasKana( sal_Int32 nStart, const sal_Int32 nEnd ) const;
      91             : 
      92             : public:
      93             : 
      94             :     SwScriptInfo();
      95             :     ~SwScriptInfo();
      96             : 
      97             :     // determines script changes
      98             :     void InitScriptInfo( const SwTxtNode& rNode, bool bRTL );
      99             :     void InitScriptInfo( const SwTxtNode& rNode );
     100             : 
     101             :     // set/get position from which data is invalid
     102        9724 :     void SetInvalidityA(const sal_Int32 nPos)
     103             :     {
     104        9724 :         if (nPos < nInvalidityPos)
     105        7754 :             nInvalidityPos = nPos;
     106        9724 :     }
     107      329559 :     sal_Int32 GetInvalidityA() const
     108             :     {
     109      329559 :         return nInvalidityPos;
     110             :     }
     111             : 
     112             :     // get default direction for paragraph
     113        2586 :     inline sal_uInt8 GetDefaultDir() const { return nDefaultDir; };
     114             : 
     115             :     // array operations, nCnt refers to array position
     116     1546699 :     size_t CountScriptChg() const { return aScriptChanges.size(); }
     117     1617113 :     sal_Int32 GetScriptChg( const size_t nCnt ) const
     118             :     {
     119             :         OSL_ENSURE( nCnt < aScriptChanges.size(),"No ScriptChange today!");
     120     1617113 :         return aScriptChanges[nCnt].position;
     121             :     }
     122     1150251 :     sal_uInt8 GetScriptType( const size_t nCnt ) const
     123             :     {
     124             :         OSL_ENSURE( nCnt < aScriptChanges.size(),"No ScriptType today!");
     125     1150251 :         return aScriptChanges[nCnt].type;
     126             :     }
     127             : 
     128      481280 :     size_t CountDirChg() const { return aDirectionChanges.size(); }
     129         600 :     sal_Int32 GetDirChg( const size_t nCnt ) const
     130             :     {
     131             :         OSL_ENSURE( nCnt < aDirectionChanges.size(),"No DirChange today!");
     132         600 :         return aDirectionChanges[ nCnt ].position;
     133             :     }
     134         228 :     sal_uInt8 GetDirType( const size_t nCnt ) const
     135             :     {
     136             :         OSL_ENSURE( nCnt < aDirectionChanges.size(),"No DirType today!");
     137         228 :         return aDirectionChanges[ nCnt ].type;
     138             :     }
     139             : 
     140        1774 :     size_t CountKashida() const
     141             :     {
     142        1774 :         return aKashida.size();
     143             :     }
     144             : 
     145           0 :     sal_Int32 GetKashida(const size_t nCnt) const
     146             :     {
     147             :         OSL_ENSURE( nCnt < aKashida.size(),"No Kashidas today!");
     148           0 :         return aKashida[nCnt];
     149             :     }
     150             : 
     151          42 :     size_t CountCompChg() const { return aCompressionChanges.size(); };
     152           0 :     sal_Int32 GetCompStart( const size_t nCnt ) const
     153             :     {
     154             :         OSL_ENSURE( nCnt < aCompressionChanges.size(),"No CompressionStart today!");
     155           0 :         return aCompressionChanges[ nCnt ].position;
     156             :     }
     157           0 :     sal_Int32 GetCompLen( const size_t nCnt ) const
     158             :     {
     159             :         OSL_ENSURE( nCnt < aCompressionChanges.size(),"No CompressionLen today!");
     160           0 :         return aCompressionChanges[ nCnt ].length;
     161             :     }
     162           0 :     CompType GetCompType( const size_t nCnt ) const
     163             :     {
     164             :         OSL_ENSURE( nCnt < aCompressionChanges.size(),"No CompressionType today!");
     165           0 :         return aCompressionChanges[ nCnt ].type;
     166             :     }
     167             : 
     168      548442 :     size_t CountHiddenChg() const { return aHiddenChg.size(); };
     169          64 :     sal_Int32 GetHiddenChg( const size_t nCnt ) const
     170             :     {
     171             :         OSL_ENSURE( nCnt < aHiddenChg.size(),"No HiddenChg today!");
     172          64 :         return aHiddenChg[ nCnt ];
     173             :     }
     174             :     static void CalcHiddenRanges(const SwTxtNode& rNode, MultiSelection& rHiddenMulti);
     175             :     static void selectHiddenTextProperty(const SwTxtNode& rNode, MultiSelection &rHiddenMulti);
     176             :     static void selectRedLineDeleted(const SwTxtNode& rNode, MultiSelection &rHiddenMulti, bool bSelect=true);
     177             : 
     178             :     // "high" level operations, nPos refers to string position
     179             :     sal_Int32 NextScriptChg( const sal_Int32 nPos ) const;
     180             :     sal_uInt8 ScriptType( const sal_Int32 nPos ) const;
     181             : 
     182             :     // Returns the position of the next direction level change.
     183             :     // If bLevel is set, the position of the next level which is smaller
     184             :     // than the level at position nPos is returned. This is required to
     185             :     // obtain the end of a SwBidiPortion
     186             :     sal_Int32 NextDirChg( const sal_Int32 nPos,
     187             :                            const sal_uInt8* pLevel = 0 ) const;
     188             :     sal_uInt8 DirType( const sal_Int32 nPos ) const;
     189             : 
     190             :     // HIDDEN TEXT STUFF START
     191             : 
     192             : /** Hidden text range information - static and non-version
     193             : 
     194             :     @descr  Determines if a given position is inside a hidden text range. The
     195             :             static version tries to obtain a valid SwScriptInfo object
     196             :             via the SwTxtNode, otherwise it calculates the values from scratch.
     197             :             The non-static version uses the internally cached informatio
     198             :             for the calculation.
     199             : 
     200             :     @param  rNode
     201             :                 The text node.
     202             :     @param  nPos
     203             :                 The given position that should be checked.
     204             :     @param  rnStartPos
     205             :                 Return parameter for the start position of the hidden range.
     206             :                 COMPLETE_STRING if nPos is not inside a hidden range.
     207             :     @param  rnEndPos
     208             :                 Return parameter for the end position of the hidden range.
     209             :                 0 if nPos is not inside a hidden range.
     210             :     @param  rnEndPos
     211             :                 Return parameter that contains all the hidden text ranges. Optional.
     212             :     @return
     213             :             returns true if there are any hidden characters in this paragraph.
     214             : 
     215             : */
     216             :     static bool GetBoundsOfHiddenRange( const SwTxtNode& rNode, sal_Int32 nPos,
     217             :                                         sal_Int32& rnStartPos, sal_Int32& rnEndPos,
     218             :                                         PositionList* pList = 0 );
     219             :     bool GetBoundsOfHiddenRange(  sal_Int32 nPos, sal_Int32& rnStartPos,
     220             :                                   sal_Int32& rnEndPos, PositionList* pList = 0 ) const;
     221             : 
     222             :     static bool IsInHiddenRange( const SwTxtNode& rNode, sal_Int32 nPos );
     223             : 
     224             : /** Hidden text attribute handling
     225             : 
     226             :     @descr  Takes a string and either deletes the hidden ranges or sets
     227             :             a given character in place of the hidden characters.
     228             : 
     229             :     @param  rNode
     230             :                 The text node.
     231             :     @param  rText
     232             :                 The string to modify.
     233             :     @param  cChar
     234             :                 The character that should replace the hidden characters.
     235             :     @param  bDel
     236             :                 If set, the hidden ranges will be deleted from the text node.
     237             :  */
     238             :     static sal_Int32 MaskHiddenRanges(
     239             :             const SwTxtNode& rNode, OUStringBuffer& rText,
     240             :                                     const sal_Int32 nStt, const sal_Int32 nEnd,
     241             :                                     const sal_Unicode cChar );
     242             : 
     243             : /** Hidden text attribute handling
     244             : 
     245             :     @descr  Takes a SwTxtNode and deletes the hidden ranges from the node.
     246             : 
     247             :     @param  rNode
     248             :                 The text node.
     249             :  */
     250             :     static void DeleteHiddenRanges( SwTxtNode& rNode );
     251             : 
     252             :     // HIDDEN TEXT STUFF END
     253             : 
     254             :     // modifies the kerning array according to a given compress value
     255             :     long Compress( long* pKernArray, sal_Int32 nIdx, sal_Int32 nLen,
     256             :                    const sal_uInt16 nCompress, const sal_uInt16 nFontHeight,
     257             :                    Point* pPoint = NULL ) const;
     258             : 
     259             : /** Performes a kashida justification on the kerning array
     260             : 
     261             :     @descr  Add some extra space for kashida justification to the
     262             :             positions in the kerning array.
     263             :     @param  pKernArray
     264             :                 The printers kerning array. Optional.
     265             :     @param  pScrArray
     266             :                 The screen kerning array. Optional.
     267             :     @param  nStt
     268             :                 Start referring to the paragraph.
     269             :     @param  nLen
     270             :                 The number of characters to be considered.
     271             :     @param  nSpaceAdd
     272             :                 The value which has to be added to a kashida opportunity.
     273             :     @return The number of kashida opportunities in the given range
     274             : */
     275             :     sal_Int32 KashidaJustify( long* pKernArray, long* pScrArray,
     276             :                               sal_Int32 nStt, sal_Int32 nLen, long nSpaceAdd = 0) const;
     277             : 
     278             : /** Clears array of kashidas marked as invalid
     279             :  */
     280           0 :     void ClearKashidaInvalid(sal_Int32 nStt, sal_Int32 nLen)
     281             :     {
     282           0 :         MarkOrClearKashidaInvalid(nStt, nLen, false, 0);
     283           0 :     }
     284             : 
     285             : /** Marks nCnt kashida positions as invalid
     286             :    pKashidaPositions: array of char indices relative to the paragraph
     287             : */
     288             :     bool MarkKashidasInvalid(sal_Int32 nCnt, sal_Int32* pKashidaPositions);
     289             : 
     290             : /** Marks nCnt kashida positions as invalid
     291             :     in the given text range
     292             :  */
     293           0 :     bool MarkKashidasInvalid(sal_Int32 nCnt, sal_Int32 nStt, sal_Int32 nLen)
     294             :     {
     295           0 :         return MarkOrClearKashidaInvalid(nStt, nLen, true, nCnt);
     296             :     }
     297             : 
     298             : /** retrieves kashida opportunities for a given text range.
     299             :    returns the number of kashida positions in the given text range
     300             : 
     301             :    pKashidaPositions: buffer to reveive the char indices of the
     302             :                       kashida opportunties relative to the paragraph
     303             : */
     304             :     sal_Int32 GetKashidaPositions(sal_Int32 nStt, sal_Int32 nLen,
     305             :        sal_Int32* pKashidaPosition);
     306             : 
     307             : /** Use regular blank justification instead of kashdida justification for the given line of text.
     308             :    nStt Start char index of the line referring to the paragraph.
     309             :    nLen Number of characters in the line
     310             : */
     311             :     void SetNoKashidaLine(sal_Int32 nStt, sal_Int32 nLen);
     312             : 
     313             : /** Clear forced blank justification for a given line.
     314             :    nStt Start char index of the line referring to the paragraph.
     315             :    nLen Number of characters in the line
     316             : */
     317             :     void ClearNoKashidaLine(sal_Int32 nStt, sal_Int32 nLen);
     318             : 
     319             : /** Checks if text is Arabic text.
     320             : 
     321             :      @descr  Checks if text is Arabic text.
     322             :      @param  rTxt
     323             :                  The text to check
     324             :      @param  nStt
     325             :                  Start index of the text
     326             :      @return Returns if the language is an Arabic language
     327             :  */
     328             :     static bool IsArabicText( const OUString& rTxt, sal_Int32 nStt, sal_Int32 nLen );
     329             : 
     330             : /** Performes a thai justification on the kerning array
     331             : 
     332             :     @descr  Add some extra space for thai justification to the
     333             :             positions in the kerning array.
     334             :     @param  rTxt
     335             :                 The String
     336             :     @param  pKernArray
     337             :                 The printers kerning array. Optional.
     338             :     @param  pScrArray
     339             :                 The screen kerning array. Optional.
     340             :     @param  nIdx
     341             :                 Start referring to the paragraph.
     342             :     @param  nLen
     343             :                 The number of characters to be considered.
     344             :     @param  nSpaceAdd
     345             :                 The value which has to be added to the cells.
     346             :     @return The number of extra spaces in the given range
     347             : */
     348             :     static sal_Int32 ThaiJustify( const OUString& rTxt, long* pKernArray,
     349             :                                   long* pScrArray, sal_Int32 nIdx,
     350             :                                   sal_Int32 nLen, sal_Int32 nNumberOfBlanks = 0,
     351             :                                   long nSpaceAdd = 0 );
     352             : 
     353             :     static SwScriptInfo* GetScriptInfo( const SwTxtNode& rNode,
     354             :                                         bool bAllowInvalid = false );
     355             : 
     356             :     static sal_uInt8 WhichFont(sal_Int32 nIdx, const OUString* pTxt, const SwScriptInfo* pSI);
     357             : };
     358             : 
     359             : #endif
     360             : 
     361             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10