1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
#define INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
#include <memory>
#include "porlay.hxx"
#include "porexp.hxx"
#include <com/sun/star/text/RubyAdjust.hpp>
class SwTextFormatInfo;
class SwFieldPortion;
class SwTextCursor;
class SwLineLayout;
class SwTextPaintInfo;
class SwTextAttr;
class SfxPoolItem;
class SwFont;
// SwMultiCreator is a small structure to create a multiportion.
// It contains the kind of multiportion and a textattribute
// or a poolitem.
// The GetMultiCreator-function fills this structure and
// the Ctor of the SwMultiPortion uses it.
enum class SwMultiCreatorId
{
Double, Ruby, Rotate, Bidi
};
struct SwMultiCreator
{
const SwTextAttr* pAttr;
const SfxPoolItem* pItem;
SwMultiCreatorId nId;
sal_uInt8 nLevel;
};
// A two-line-portion (SwMultiPortion) could have surrounding brackets,
// in this case the structure SwBracket will be used.
struct SwBracket
{
sal_Int32 nStart; // Start of text attribute determins the font
sal_uInt16 nAscent; // Ascent of the brackets
sal_uInt16 nHeight; // Height of them
sal_uInt16 nPreWidth; // Width of the opening bracket
sal_uInt16 nPostWidth; // Width of the closing bracket
sal_Unicode cPre; // Initial character, e.g. '('
sal_Unicode cPost; // Final character, e.g. ')'
SwFontScript nPreScript; // Script of the initial character
SwFontScript nPostScript; // Script of the final character
};
// The SwMultiPortion is line portion inside a line portion,
// it's a group of portions,
// e.g. a double line portion in a line
// or phonetics (ruby)
// or combined characters
// or a rotated portion.
class SwMultiPortion : public SwLinePortion
{
SwLineLayout aRoot; // One or more lines
bool bTab1 :1; // First line tabulator
bool bTab2 :1; // Second line includes tabulator
bool bDouble :1; // Double line
bool bRuby :1; // Phonetics
bool bBidi :1;
bool bTop :1; // Phonetic position
bool bFormatted :1; // Already formatted
bool bFollowField :1; // Field follow inside
bool bFlyInContent:1; // Fly as character inside
sal_uInt8 nDirection:2; // Direction (0/90/180/270 degrees)
protected:
explicit SwMultiPortion(sal_Int32 nEnd)
: bTab1(false)
, bTab2(false)
, bDouble(false)
, bRuby(false)
, bBidi(false)
, bTop(false)
, bFormatted(false)
, bFollowField(false)
, bFlyInContent(false)
, nDirection(0)
{
SetWhichPor(POR_MULTI);
SetLen(nEnd);
}
void SetDouble() { bDouble = true; }
void SetRuby() { bRuby = true; }
void SetBidi() { bBidi = true; }
void SetTop( bool bNew ) { bTop = bNew; }
void SetTab1( bool bNew ) { bTab1 = bNew; }
void SetTab2( bool bNew ) { bTab2 = bNew; }
void SetDirection( sal_uInt8 nNew ) { nDirection = nNew; }
bool GetTab1() const { return bTab1; }
bool GetTab2() const { return bTab2; }
public:
virtual ~SwMultiPortion() override;
const SwLineLayout& GetRoot() const { return aRoot; }
SwLineLayout& GetRoot() { return aRoot; }
bool HasTabulator() const { return bTab1 || bTab2; }
bool IsFormatted() const { return bFormatted; }
void SetFormatted() { bFormatted = true; }
bool IsFollowField() const { return bFollowField; }
void SetFollowField() { bFollowField = true; }
bool HasFlyInContent() const { return bFlyInContent; }
void SetFlyInContent( bool bNew ) { bFlyInContent = bNew; }
bool IsDouble() const { return bDouble; }
bool IsRuby() const { return bRuby; }
bool IsBidi() const { return bBidi; }
bool OnTop() const { return bTop; }
void ActualizeTabulator();
virtual void Paint( const SwTextPaintInfo &rInf ) const override;
virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
// Summarize the internal lines to calculate the (external) size
void CalcSize( SwTextFormatter& rLine, SwTextFormatInfo &rInf );
inline bool HasBrackets() const;
bool HasRotation() const { return 0 != (1 & nDirection); }
bool IsRevers() const { return 0 != (2 & nDirection); }
sal_uInt8 GetDirection() const { return nDirection; }
// Accessibility: pass information about this portion to the PortionHandler
virtual void HandlePortion( SwPortionHandler& rPH ) const override;
};
class SwDoubleLinePortion : public SwMultiPortion
{
std::unique_ptr<SwBracket> pBracket; // Surrounding brackets
SwTwips nLineDiff; // Difference of the width of the both lines
sal_Int32 nBlank1; // Number of blanks in the first line
sal_Int32 nBlank2; // Number of blanks in the second line
public:
SwDoubleLinePortion( SwDoubleLinePortion& rDouble, sal_Int32 nEnd );
SwDoubleLinePortion( const SwMultiCreator& rCreate, sal_Int32 nEnd );
virtual ~SwDoubleLinePortion() override;
SwBracket* GetBrackets() const { return pBracket.get(); }
void SetBrackets( const SwDoubleLinePortion& rDouble );
void PaintBracket( SwTextPaintInfo& rInf, long nSpaceAdd, bool bOpen ) const;
void FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxWidth );
sal_uInt16 PreWidth() const { return pBracket->nPreWidth; };
sal_uInt16 PostWidth() const { return pBracket->nPostWidth; }
void ClearBrackets()
{ pBracket->nPreWidth = pBracket->nPostWidth=0; Width( 0 ); }
sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
void CalcBlanks( SwTextFormatInfo &rInf );
static void ResetSpaceAdd( SwLineLayout* pCurr );
SwTwips GetLineDiff() const { return nLineDiff; }
sal_Int32 GetSpaceCnt() const
{ return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; }
sal_Int32 GetSmallerSpaceCnt() const
{ return ( nLineDiff < 0 ) ? nBlank1 : nBlank2; }
virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const override;
};
class SwRubyPortion : public SwMultiPortion
{
sal_Int32 nRubyOffset;
css::text::RubyAdjust nAdjustment;
void Adjust_( SwTextFormatInfo &rInf);
public:
SwRubyPortion( const SwRubyPortion& rRuby, sal_Int32 nEnd );
SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
const IDocumentSettingAccess& rIDocumentSettingAccess,
sal_Int32 nEnd, sal_Int32 nOffs,
const bool* pForceRubyPos );
void CalcRubyOffset();
void Adjust( SwTextFormatInfo &rInf )
{ if(nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
css::text::RubyAdjust GetAdjustment() const { return nAdjustment; }
sal_Int32 GetRubyOffset() const { return nRubyOffset; }
};
class SwRotatedPortion : public SwMultiPortion
{
public:
SwRotatedPortion( sal_Int32 nEnd, sal_uInt8 nDir )
: SwMultiPortion( nEnd ) { SetDirection( nDir ); }
SwRotatedPortion( const SwMultiCreator& rCreate, sal_Int32 nEnd,
bool bRTL );
};
class SwBidiPortion : public SwMultiPortion
{
sal_uInt8 nLevel;
public:
SwBidiPortion( sal_Int32 nEnd, sal_uInt8 nLv );
sal_uInt8 GetLevel() const { return nLevel; }
// Get number of blanks for justified alignment
sal_Int32 GetSpaceCnt( const SwTextSizeInfo &rInf ) const;
// Calculates extra spacing based on number of blanks
virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
// Manipulate the spacing array at pCurr
virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const override;
};
// For cursor travelling in multiportions
class SwTextCursorSave
{
SwTextCursor* pTextCursor;
SwLineLayout* pCurr;
sal_Int32 nStart;
sal_uInt16 nWidth;
sal_uInt8 nOldProp;
bool bSpaceChg;
public:
SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
SwTwips nY, sal_uInt16& nX, sal_Int32 nCurrStart, long nSpaceAdd );
~SwTextCursorSave();
};
inline bool SwMultiPortion::HasBrackets() const
{
return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|