ITEM: Refactor ItemType
[LibreOffice.git] / sw / source / core / text / pormulti.hxx
blobe5a3da2b329cfca8d12b5600c68759d3af828320
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <memory>
22 #include "porlay.hxx"
23 #include <com/sun/star/text/RubyAdjust.hpp>
25 class IDocumentSettingAccess;
26 class SwTextFormatInfo;
27 class SwTextCursor;
28 class SwTextPaintInfo;
29 class SwTextAttr;
30 class SfxPoolItem;
31 class SwFont;
33 // SwMultiCreator is a small structure to create a multiportion.
34 // It contains the kind of multiportion and a textattribute
35 // or a poolitem.
36 // The GetMultiCreator-function fills this structure and
37 // the Ctor of the SwMultiPortion uses it.
38 enum class SwMultiCreatorId
40 Double, Ruby, Rotate, Bidi
43 enum class RubyPosition : sal_uInt16
45 ABOVE = 0,
46 BELOW = 1,
47 RIGHT = 2
50 struct SwMultiCreator
52 TextFrameIndex nStartOfAttr;
53 const SwTextAttr* pAttr;
54 const SfxPoolItem* pItem;
55 SwMultiCreatorId nId;
56 sal_uInt8 nLevel;
59 // A two-line-portion (SwMultiPortion) could have surrounding brackets,
60 // in this case the structure SwBracket will be used.
61 struct SwBracket
63 TextFrameIndex nStart; // Start of text attribute determines the font
64 sal_uInt16 nAscent; // Ascent of the brackets
65 sal_uInt16 nHeight; // Height of them
66 sal_uInt16 nPreWidth; // Width of the opening bracket
67 sal_uInt16 nPostWidth; // Width of the closing bracket
68 sal_Unicode cPre; // Initial character, e.g. '('
69 sal_Unicode cPost; // Final character, e.g. ')'
70 SwFontScript nPreScript; // Script of the initial character
71 SwFontScript nPostScript; // Script of the final character
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 class SAL_DLLPUBLIC_RTTI SwMultiPortion : public SwLinePortion
82 SwLineLayout m_aRoot; // One or more lines
83 bool m_bTab1 :1; // First line tabulator
84 bool m_bTab2 :1; // Second line includes tabulator
85 bool m_bDouble :1; // Double line
86 bool m_bRuby :1; // Phonetics
87 bool m_bBidi :1;
88 bool m_bFormatted :1; // Already formatted
89 bool m_bFollowField :1; // Field follow inside
90 bool m_bFlyInContent:1; // Fly as character inside
91 RubyPosition m_eRubyPosition; // Phonetic position
92 sal_uInt8 m_nDirection:2; // Direction (0/90/180/270 degrees)
93 protected:
94 explicit SwMultiPortion(TextFrameIndex const nEnd)
95 : m_bTab1(false)
96 , m_bTab2(false)
97 , m_bDouble(false)
98 , m_bRuby(false)
99 , m_bBidi(false)
100 , m_bFormatted(false)
101 , m_bFollowField(false)
102 , m_bFlyInContent(false)
103 , m_eRubyPosition( RubyPosition::ABOVE )
104 , m_nDirection(0)
106 SetWhichPor(PortionType::Multi);
107 SetLen(nEnd);
109 void SetDouble() { m_bDouble = true; }
110 void SetRuby() { m_bRuby = true; }
111 void SetBidi() { m_bBidi = true; }
112 void SetRubyPosition( RubyPosition eNew ) { m_eRubyPosition = eNew; }
113 void SetTab1( bool bNew ) { m_bTab1 = bNew; }
114 void SetTab2( bool bNew ) { m_bTab2 = bNew; }
115 void SetDirection( sal_uInt8 nNew ) { m_nDirection = nNew; }
116 bool GetTab1() const { return m_bTab1; }
117 bool GetTab2() const { return m_bTab2; }
118 public:
119 virtual ~SwMultiPortion() override;
120 const SwLineLayout& GetRoot() const { return m_aRoot; }
121 SwLineLayout& GetRoot() { return m_aRoot; }
123 bool HasTabulator() const { return m_bTab1 || m_bTab2; }
124 bool IsFormatted() const { return m_bFormatted; }
125 void SetFormatted() { m_bFormatted = true; }
126 bool IsFollowField() const { return m_bFollowField; }
127 void SetFollowField() { m_bFollowField = true; }
128 bool HasFlyInContent() const { return m_bFlyInContent; }
129 void SetFlyInContent( bool bNew ) { m_bFlyInContent = bNew; }
130 bool IsDouble() const { return m_bDouble; }
131 bool IsRuby() const { return m_bRuby; }
132 bool IsBidi() const { return m_bBidi; }
133 bool OnTop() const { return m_eRubyPosition == RubyPosition::ABOVE; }
134 bool OnRight() const { return m_eRubyPosition == RubyPosition::RIGHT; }
135 RubyPosition GetRubyPosition() const { return m_eRubyPosition; }
136 void ActualizeTabulator();
138 virtual void Paint( const SwTextPaintInfo &rInf ) const override;
139 virtual SwTwips CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
140 virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const;
142 // Summarize the internal lines to calculate the (external) size
143 void CalcSize( SwTextFormatter& rLine, SwTextFormatInfo &rInf );
145 inline bool HasBrackets() const;
146 bool HasRotation() const { return 0 != (1 & m_nDirection); }
147 bool IsRevers() const { return 0 != (2 & m_nDirection); }
148 sal_uInt8 GetDirection() const { return m_nDirection; }
150 // Accessibility: pass information about this portion to the PortionHandler
151 virtual void HandlePortion( SwPortionHandler& rPH ) const override;
153 void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
154 TextFrameIndex& nOffset) const override;
157 class SwDoubleLinePortion : public SwMultiPortion
159 std::unique_ptr<SwBracket> m_pBracket; // Surrounding brackets
160 SwTwips m_nLineDiff; // Difference of the width of the both lines
161 TextFrameIndex m_nBlank1; ///< Number of blanks in the first line
162 TextFrameIndex m_nBlank2; ///< Number of blanks in the second line
163 public:
164 SwDoubleLinePortion(SwDoubleLinePortion& rDouble, TextFrameIndex nEnd);
165 SwDoubleLinePortion(const SwMultiCreator& rCreate, TextFrameIndex nEnd);
166 virtual ~SwDoubleLinePortion() override;
168 SwBracket* GetBrackets() const { return m_pBracket.get(); }
169 void SetBrackets( const SwDoubleLinePortion& rDouble );
170 void PaintBracket( SwTextPaintInfo& rInf, tools::Long nSpaceAdd, bool bOpen ) const;
171 void FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxWidth );
172 sal_uInt16 PreWidth() const { return m_pBracket->nPreWidth; };
173 sal_uInt16 PostWidth() const { return m_pBracket->nPostWidth; }
174 void ClearBrackets()
175 { m_pBracket->nPreWidth = m_pBracket->nPostWidth=0; Width( 0 ); }
176 sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
178 void CalcBlanks( SwTextFormatInfo &rInf );
179 static void ResetSpaceAdd( SwLineLayout* pCurr );
180 SwTwips GetLineDiff() const { return m_nLineDiff; }
181 TextFrameIndex GetSpaceCnt() const
182 { return ( m_nLineDiff < 0 ) ? m_nBlank2 : m_nBlank1; }
183 TextFrameIndex GetSmallerSpaceCnt() const
184 { return ( m_nLineDiff < 0 ) ? m_nBlank1 : m_nBlank2; }
186 virtual SwTwips CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
187 virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const override;
190 class SwRubyPortion : public SwMultiPortion
192 TextFrameIndex m_nRubyOffset;
193 css::text::RubyAdjust m_nAdjustment;
194 void Adjust_( SwTextFormatInfo &rInf);
195 public:
196 SwRubyPortion(const SwRubyPortion& rRuby, TextFrameIndex nEnd);
198 SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
199 const IDocumentSettingAccess& rIDocumentSettingAccess,
200 TextFrameIndex nEnd, TextFrameIndex nOffs,
201 const SwTextSizeInfo &rInf );
203 void CalcRubyOffset();
204 void Adjust( SwTextFormatInfo &rInf )
205 { if(m_nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
206 css::text::RubyAdjust GetAdjustment() const { return m_nAdjustment; }
207 TextFrameIndex GetRubyOffset() const { return m_nRubyOffset; }
210 class SwRotatedPortion : public SwMultiPortion
212 public:
213 SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
214 : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
215 SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
216 bool bRTL );
219 class SwBidiPortion : public SwMultiPortion
221 sal_uInt8 m_nLevel;
223 public:
224 SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv);
226 sal_uInt8 GetLevel() const { return m_nLevel; }
227 // Get number of blanks for justified alignment
228 TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const;
229 // Calculates extra spacing based on number of blanks
230 virtual SwTwips CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
231 // Manipulate the spacing array at pCurr
232 virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const override;
235 // For cursor travelling in multiportions
237 class SwTextCursorSave
239 SwTextCursor* pTextCursor;
240 SwLineLayout* pCurr;
241 TextFrameIndex nStart;
242 sal_uInt16 nWidth;
243 sal_uInt8 nOldProp;
244 bool bSpaceChg;
245 public:
246 SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
247 SwTwips nY, SwTwips& nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd);
248 ~SwTextCursorSave();
251 inline bool SwMultiPortion::HasBrackets() const
253 return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */