1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _PORMULTI_HXX 24 #define _PORMULTI_HXX 25 26 #include "porlay.hxx" 27 #include "porexp.hxx" 28 29 class SwTxtFormatInfo; 30 class SwFldPortion; 31 class SwTxtCursor; 32 class SwLineLayout; 33 class SwTxtPaintInfo; 34 class SwTxtAttr; 35 class SfxPoolItem; 36 class SwFont; 37 38 /*-----------------02.02.01 15:01------------------- 39 * SwMultiCreator is a small structur to create a multiportion. 40 * It contains the kind of multiportion and a textattribute 41 * or a poolitem. 42 * The GetMultiCreator-function fills this structur and 43 * the Ctor of the SwMultiPortion uses it. 44 * --------------------------------------------------*/ 45 46 #define SW_MC_DOUBLE 0 47 #define SW_MC_RUBY 1 48 #define SW_MC_ROTATE 2 49 #define SW_MC_BIDI 3 50 51 struct SwMultiCreator 52 { 53 const SwTxtAttr* pAttr; 54 const SfxPoolItem* pItem; 55 sal_uInt8 nId; 56 sal_uInt8 nLevel; 57 }; 58 59 /*-----------------25.10.00 16:19------------------- 60 * A two-line-portion (SwMultiPortion) could have surrounding brackets, 61 * in this case the structur SwBracket will be used. 62 * --------------------------------------------------*/ 63 64 struct SwBracket 65 { 66 xub_StrLen nStart; // Start of text attribute determins the font 67 KSHORT nAscent; // Ascent of the brackets 68 KSHORT nHeight; // Height of them 69 KSHORT nPreWidth; // Width of the opening bracket 70 KSHORT nPostWidth; // Width of the closing bracket 71 sal_Unicode cPre; // Initial character, e.g. '(' 72 sal_Unicode cPost; // Final character, e.g. ')' 73 sal_uInt8 nPreScript; // Script of the initial character 74 sal_uInt8 nPostScript; // Script of the final character 75 }; 76 77 /*-----------------16.10.00 12:45------------------- 78 * The SwMultiPortion is line portion inside a line portion, 79 * it's a group of portions, 80 * e.g. a double line portion in a line 81 * or phonetics (ruby) 82 * or combined characters 83 * or a rotated portion. 84 * --------------------------------------------------*/ 85 86 class SwMultiPortion : public SwLinePortion 87 { 88 SwLineLayout aRoot; // One or more lines 89 SwFldPortion *pFldRest; // Field rest from the previous line 90 sal_Bool bTab1 :1; // First line tabulator 91 sal_Bool bTab2 :1; // Second line includes tabulator 92 sal_Bool bDouble :1; // Double line 93 sal_Bool bRuby :1; // Phonetics 94 sal_Bool bBidi :1; 95 sal_Bool bTop :1; // Phonetic position 96 sal_Bool bFormatted :1; // Already formatted 97 sal_Bool bFollowFld :1; // Field follow inside 98 sal_uInt8 nDirection:2; // Direction (0/90/180/270 degrees) 99 sal_Bool bFlyInCntnt:1; // Fly as character inside 100 protected: 101 SwMultiPortion( xub_StrLen nEnd ) : pFldRest( 0 ), bTab1( sal_False ), 102 bTab2( sal_False ), bDouble( sal_False ), bRuby( sal_False ), 103 bBidi( sal_False ), bFormatted( sal_False ), bFollowFld( sal_False ), 104 nDirection( 0 ), bFlyInCntnt( sal_False ) 105 { SetWhichPor( POR_MULTI ); SetLen( nEnd ); } 106 inline void SetDouble() { bDouble = sal_True; } 107 inline void SetRuby() { bRuby = sal_True; } 108 inline void SetBidi() { bBidi = sal_True; } 109 inline void SetTop( sal_Bool bNew ) { bTop = bNew; } 110 inline void SetTab1( sal_Bool bNew ) { bTab1 = bNew; } 111 inline void SetTab2( sal_Bool bNew ) { bTab2 = bNew; } 112 inline void SetDirection( sal_uInt8 nNew ) { nDirection = nNew; } 113 inline sal_Bool GetTab1() const { return bTab1; } 114 inline sal_Bool GetTab2() const { return bTab2; } 115 public: 116 ~SwMultiPortion(); 117 const SwLineLayout& GetRoot() const { return aRoot; } 118 SwLineLayout& GetRoot() { return aRoot; } 119 SwFldPortion* GetFldRest() { return pFldRest; } 120 void SetFldRest( SwFldPortion* pNew ) { pFldRest = pNew; } 121 122 inline sal_Bool HasTabulator() const { return bTab1 || bTab2; } 123 inline sal_Bool IsFormatted() const { return bFormatted; } 124 inline void SetFormatted() { bFormatted = sal_True; } 125 inline sal_Bool IsFollowFld() const { return bFollowFld; } 126 inline void SetFollowFld() { bFollowFld = sal_True; } 127 inline sal_Bool HasFlyInCntnt() const { return bFlyInCntnt; } 128 inline void SetFlyInCntnt( sal_Bool bNew ) { bFlyInCntnt = bNew; } 129 inline sal_Bool IsDouble() const { return bDouble; } 130 inline sal_Bool IsRuby() const { return bRuby; } 131 inline sal_Bool IsBidi() const { return bBidi; } 132 inline sal_Bool OnTop() const { return bTop; } 133 void ActualizeTabulator(); 134 135 virtual void Paint( const SwTxtPaintInfo &rInf ) const; 136 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const; 137 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const; 138 139 // Summarize the internal lines to calculate the (external) size 140 void CalcSize( SwTxtFormatter& rLine, SwTxtFormatInfo &rInf ); 141 142 inline sal_Bool HasBrackets() const; 143 inline sal_Bool HasRotation() const { return 0 != (1 & nDirection); } 144 inline sal_Bool IsRevers() const { return 0 != (2 & nDirection); } 145 inline sal_uInt8 GetDirection() const { return nDirection; } 146 inline sal_uInt16 GetFontRotation() const 147 { return ( HasRotation() ? ( IsRevers() ? 2700 : 900 ) : 0 ); } 148 149 // Accessibility: pass information about this portion to the PortionHandler 150 virtual void HandlePortion( SwPortionHandler& rPH ) const; 151 152 OUTPUT_OPERATOR 153 }; 154 155 class SwDoubleLinePortion : public SwMultiPortion 156 { 157 SwBracket* pBracket; // Surrounding brackets 158 SwTwips nLineDiff; // Difference of the width of the both lines 159 xub_StrLen nBlank1; // Number of blanks in the first line 160 xub_StrLen nBlank2; // Number of blanks in the second line 161 public: 162 SwDoubleLinePortion( SwDoubleLinePortion& rDouble, xub_StrLen nEnd ); 163 SwDoubleLinePortion( const SwMultiCreator& rCreate, xub_StrLen nEnd ); 164 ~SwDoubleLinePortion(); 165 166 inline SwBracket* GetBrackets() const { return pBracket; } 167 void SetBrackets( const SwDoubleLinePortion& rDouble ); 168 void PaintBracket( SwTxtPaintInfo& rInf, long nSpaceAdd, sal_Bool bOpen ) const; 169 void FormatBrackets( SwTxtFormatInfo &rInf, SwTwips& nMaxWidth ); 170 inline KSHORT PreWidth() const { return pBracket->nPreWidth; }; 171 inline KSHORT PostWidth() const { return pBracket->nPostWidth; } 172 inline void ClearBrackets() 173 { pBracket->nPreWidth = pBracket->nPostWidth=0; Width( 0 ); } 174 inline KSHORT BracketWidth(){ return PreWidth() + PostWidth(); } 175 176 void CalcBlanks( SwTxtFormatInfo &rInf ); 177 static void ResetSpaceAdd( SwLineLayout* pCurr ); 178 inline SwTwips GetLineDiff() const { return nLineDiff; } 179 inline xub_StrLen GetSpaceCnt() const 180 { return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; } 181 inline xub_StrLen GetSmallerSpaceCnt() const 182 { return ( nLineDiff < 0 ) ? nBlank1 : nBlank2; } 183 inline xub_StrLen GetBlank1() const { return nBlank1; } 184 inline xub_StrLen GetBlank2() const { return nBlank2; } 185 186 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const; 187 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const; 188 }; 189 190 class SwRubyPortion : public SwMultiPortion 191 { 192 xub_StrLen nRubyOffset; 193 sal_uInt16 nAdjustment; 194 void _Adjust( SwTxtFormatInfo &rInf); 195 public: 196 SwRubyPortion( const SwRubyPortion& rRuby, xub_StrLen nEnd ); 197 198 SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt, 199 const IDocumentSettingAccess& rIDocumentSettingAccess, 200 xub_StrLen nEnd, xub_StrLen nOffs, 201 const sal_Bool* pForceRubyPos ); 202 203 void CalcRubyOffset(); 204 inline void Adjust( SwTxtFormatInfo &rInf ) 205 { if(nAdjustment && GetRoot().GetNext()) _Adjust(rInf); } 206 inline sal_uInt16 GetAdjustment() const { return nAdjustment; } 207 inline xub_StrLen GetRubyOffset() const { return nRubyOffset; } 208 }; 209 210 class SwRotatedPortion : public SwMultiPortion 211 { 212 public: 213 SwRotatedPortion( xub_StrLen nEnd, sal_uInt8 nDir = 1 ) 214 : SwMultiPortion( nEnd ) { SetDirection( nDir ); } 215 SwRotatedPortion( const SwMultiCreator& rCreate, xub_StrLen nEnd, 216 sal_Bool bRTL ); 217 }; 218 219 class SwBidiPortion : public SwMultiPortion 220 { 221 sal_uInt8 nLevel; 222 223 public: 224 SwBidiPortion( xub_StrLen nEnd, sal_uInt8 nLv ); 225 226 inline sal_uInt8 GetLevel() const { return nLevel; } 227 // Get number of blanks for justified alignment 228 xub_StrLen GetSpaceCnt( const SwTxtSizeInfo &rInf ) const; 229 // Calculates extra spacing based on number of blanks 230 virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const; 231 // Manipulate the spacing array at pCurr 232 virtual sal_Bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const; 233 }; 234 235 // For cursor travelling in multiportions 236 237 class SwTxtCursorSave 238 { 239 SwTxtCursor* pTxtCrsr; 240 SwLineLayout* pCurr; 241 SwTwips nWidth; 242 xub_StrLen nStart; 243 sal_uInt8 nOldProp; 244 sal_Bool bSpaceChg; 245 public: 246 SwTxtCursorSave( SwTxtCursor* pTxtCursor, SwMultiPortion* pMulti, 247 SwTwips nY, sal_uInt16& nX, xub_StrLen nCurrStart, long nSpaceAdd ); 248 ~SwTxtCursorSave(); 249 }; 250 251 /************************************************************************* 252 * inline - Implementations 253 *************************************************************************/ 254 255 inline sal_Bool SwMultiPortion::HasBrackets() const 256 { 257 return sal::static_int_cast< sal_Bool >( IsDouble() ? 258 0 != ((SwDoubleLinePortion*)this)->GetBrackets() : 259 sal_False ); 260 } 261 262 CLASSIO( SwMultiPortion ) 263 264 #endif 265