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