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