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
249
250
251
252
253
254
255
256
|
/* -*- 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 <com/sun/star/text/RubyAdjust.hpp>
class IDocumentSettingAccess;
class SwTextFormatInfo;
class SwTextCursor;
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
};
enum class RubyPosition : sal_uInt16
{
ABOVE = 0,
BELOW = 1,
RIGHT = 2
};
struct SwMultiCreator
{
TextFrameIndex nStartOfAttr;
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
{
TextFrameIndex nStart; // Start of text attribute determines 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 m_aRoot; // One or more lines
bool m_bTab1 :1; // First line tabulator
bool m_bTab2 :1; // Second line includes tabulator
bool m_bDouble :1; // Double line
bool m_bRuby :1; // Phonetics
bool m_bBidi :1;
bool m_bFormatted :1; // Already formatted
bool m_bFollowField :1; // Field follow inside
bool m_bFlyInContent:1; // Fly as character inside
RubyPosition m_eRubyPosition; // Phonetic position
sal_uInt8 m_nDirection:2; // Direction (0/90/180/270 degrees)
protected:
explicit SwMultiPortion(TextFrameIndex const nEnd)
: m_bTab1(false)
, m_bTab2(false)
, m_bDouble(false)
, m_bRuby(false)
, m_bBidi(false)
, m_bFormatted(false)
, m_bFollowField(false)
, m_bFlyInContent(false)
, m_eRubyPosition( RubyPosition::ABOVE )
, m_nDirection(0)
{
SetWhichPor(PortionType::Multi);
SetLen(nEnd);
}
void SetDouble() { m_bDouble = true; }
void SetRuby() { m_bRuby = true; }
void SetBidi() { m_bBidi = true; }
void SetRubyPosition( RubyPosition eNew ) { m_eRubyPosition = eNew; }
void SetTab1( bool bNew ) { m_bTab1 = bNew; }
void SetTab2( bool bNew ) { m_bTab2 = bNew; }
void SetDirection( sal_uInt8 nNew ) { m_nDirection = nNew; }
bool GetTab1() const { return m_bTab1; }
bool GetTab2() const { return m_bTab2; }
public:
virtual ~SwMultiPortion() override;
const SwLineLayout& GetRoot() const { return m_aRoot; }
SwLineLayout& GetRoot() { return m_aRoot; }
bool HasTabulator() const { return m_bTab1 || m_bTab2; }
bool IsFormatted() const { return m_bFormatted; }
void SetFormatted() { m_bFormatted = true; }
bool IsFollowField() const { return m_bFollowField; }
void SetFollowField() { m_bFollowField = true; }
bool HasFlyInContent() const { return m_bFlyInContent; }
void SetFlyInContent( bool bNew ) { m_bFlyInContent = bNew; }
bool IsDouble() const { return m_bDouble; }
bool IsRuby() const { return m_bRuby; }
bool IsBidi() const { return m_bBidi; }
bool OnTop() const { return m_eRubyPosition == RubyPosition::ABOVE; }
bool OnRight() const { return m_eRubyPosition == RubyPosition::RIGHT; }
RubyPosition GetRubyPosition() const { return m_eRubyPosition; }
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 & m_nDirection); }
bool IsRevers() const { return 0 != (2 & m_nDirection); }
sal_uInt8 GetDirection() const { return m_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
TextFrameIndex nBlank1; ///< Number of blanks in the first line
TextFrameIndex nBlank2; ///< Number of blanks in the second line
public:
SwDoubleLinePortion(SwDoubleLinePortion& rDouble, TextFrameIndex nEnd);
SwDoubleLinePortion(const SwMultiCreator& rCreate, TextFrameIndex 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; }
TextFrameIndex GetSpaceCnt() const
{ return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; }
TextFrameIndex 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
{
TextFrameIndex nRubyOffset;
css::text::RubyAdjust nAdjustment;
void Adjust_( SwTextFormatInfo &rInf);
public:
SwRubyPortion(const SwRubyPortion& rRuby, TextFrameIndex nEnd);
SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
const IDocumentSettingAccess& rIDocumentSettingAccess,
TextFrameIndex nEnd, TextFrameIndex nOffs,
const SwTextSizeInfo &rInf );
void CalcRubyOffset();
void Adjust( SwTextFormatInfo &rInf )
{ if(nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
css::text::RubyAdjust GetAdjustment() const { return nAdjustment; }
TextFrameIndex GetRubyOffset() const { return nRubyOffset; }
};
class SwRotatedPortion : public SwMultiPortion
{
public:
SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
: SwMultiPortion( nEnd ) { SetDirection( nDir ); }
SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
bool bRTL );
};
class SwBidiPortion : public SwMultiPortion
{
sal_uInt8 nLevel;
public:
SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv);
sal_uInt8 GetLevel() const { return nLevel; }
// Get number of blanks for justified alignment
TextFrameIndex 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;
TextFrameIndex nStart;
sal_uInt16 nWidth;
sal_uInt8 nOldProp;
bool bSpaceChg;
public:
SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
SwTwips nY, sal_uInt16& nX, TextFrameIndex 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: */
|