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