LibreOffice Module sw (master) 1
pormulti.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <memory>
22#include "porlay.hxx"
23#include <com/sun/star/text/RubyAdjust.hpp>
24
27class SwTextCursor;
28class SwTextPaintInfo;
29class SwTextAttr;
30class SfxPoolItem;
31class SwFont;
32
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.
39{
41};
42
43enum class RubyPosition : sal_uInt16
44{
45 ABOVE = 0,
46 BELOW = 1,
47 RIGHT = 2
48};
49
51{
57};
58
59// A two-line-portion (SwMultiPortion) could have surrounding brackets,
60// in this case the structure SwBracket will be used.
62{
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
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.
80class SAL_DLLPUBLIC_RTTI SwMultiPortion : public SwLinePortion
81{
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)
93protected:
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)
105 {
107 SetLen(nEnd);
108 }
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; }
118public:
119 virtual ~SwMultiPortion() override;
120 const SwLineLayout& GetRoot() const { return m_aRoot; }
121 SwLineLayout& GetRoot() { return m_aRoot; }
122
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();
137
138 virtual void Paint( const SwTextPaintInfo &rInf ) const override;
139 virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
140 virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const;
141
142 // Summarize the internal lines to calculate the (external) size
143 void CalcSize( SwTextFormatter& rLine, SwTextFormatInfo &rInf );
144
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; }
149
150 // Accessibility: pass information about this portion to the PortionHandler
151 virtual void HandlePortion( SwPortionHandler& rPH ) const override;
152
153 void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
154 TextFrameIndex& nOffset) const override;
155};
156
158{
159 std::unique_ptr<SwBracket> m_pBracket; // Surrounding brackets
160 SwTwips m_nLineDiff; // Difference of the width of the both lines
163public:
166 virtual ~SwDoubleLinePortion() override;
167
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; }
175 { m_pBracket->nPreWidth = m_pBracket->nPostWidth=0; Width( 0 ); }
176 sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
177
178 void CalcBlanks( SwTextFormatInfo &rInf );
179 static void ResetSpaceAdd( SwLineLayout* pCurr );
180 SwTwips GetLineDiff() const { return m_nLineDiff; }
182 { return ( m_nLineDiff < 0 ) ? m_nBlank2 : m_nBlank1; }
184 { return ( m_nLineDiff < 0 ) ? m_nBlank1 : m_nBlank2; }
185
186 virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
187 virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const override;
188};
189
191{
193 css::text::RubyAdjust m_nAdjustment;
194 void Adjust_( SwTextFormatInfo &rInf);
195public:
196 SwRubyPortion(const SwRubyPortion& rRuby, TextFrameIndex nEnd);
197
198 SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
199 const IDocumentSettingAccess& rIDocumentSettingAccess,
200 TextFrameIndex nEnd, TextFrameIndex nOffs,
201 const SwTextSizeInfo &rInf );
202
203 void CalcRubyOffset();
205 { if(m_nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
206 css::text::RubyAdjust GetAdjustment() const { return m_nAdjustment; }
208};
209
211{
212public:
214 : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
215 SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
216 bool bRTL );
217};
218
220{
222
223public:
225
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 tools::Long 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;
233};
234
235// For cursor travelling in multiportions
236
238{
242 sal_uInt16 nWidth;
245public:
247 SwTwips nY, SwTwips& nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd);
249};
250
252{
253 return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
254}
255
256/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
Provides access to settings of a document.
SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv)
Definition: pormulti.cxx:210
sal_uInt8 m_nLevel
Definition: pormulti.hxx:221
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const override
Definition: pormulti.cxx:226
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:221
TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const
Definition: pormulti.cxx:238
sal_uInt8 GetLevel() const
Definition: pormulti.hxx:226
TextFrameIndex GetSmallerSpaceCnt() const
Definition: pormulti.hxx:183
virtual ~SwDoubleLinePortion() override
Definition: pormulti.cxx:558
void SetBrackets(const SwDoubleLinePortion &rDouble)
Definition: pormulti.cxx:393
TextFrameIndex m_nBlank1
Number of blanks in the first line.
Definition: pormulti.hxx:161
SwTwips GetLineDiff() const
Definition: pormulti.hxx:180
static void ResetSpaceAdd(SwLineLayout *pCurr)
Definition: pormulti.cxx:551
std::unique_ptr< SwBracket > m_pBracket
Definition: pormulti.hxx:159
void PaintBracket(SwTextPaintInfo &rInf, tools::Long nSpaceAdd, bool bOpen) const
Definition: pormulti.cxx:360
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:507
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const override
Definition: pormulti.cxx:518
SwDoubleLinePortion(SwDoubleLinePortion &rDouble, TextFrameIndex nEnd)
Definition: pormulti.cxx:263
sal_uInt16 PreWidth() const
Definition: pormulti.hxx:172
void FormatBrackets(SwTextFormatInfo &rInf, SwTwips &nMaxWidth)
Definition: pormulti.cxx:409
sal_uInt16 BracketWidth()
Definition: pormulti.hxx:176
TextFrameIndex m_nBlank2
Number of blanks in the second line.
Definition: pormulti.hxx:162
void CalcBlanks(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:475
TextFrameIndex GetSpaceCnt() const
Definition: pormulti.hxx:181
SwBracket * GetBrackets() const
Definition: pormulti.hxx:168
sal_uInt16 PostWidth() const
Definition: pormulti.hxx:173
Collection of SwLinePortion instances, representing one line of text.
Definition: porlay.hxx:79
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:52
virtual void Paint(const SwTextPaintInfo &rInf) const =0
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:306
virtual void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &rOffset) const
Definition: porlin.cxx:321
virtual void HandlePortion(SwPortionHandler &rPH) const
Definition: porlin.cxx:316
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:78
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:101
void SetTab2(bool bNew)
Definition: pormulti.hxx:114
bool IsDouble() const
Definition: pormulti.hxx:130
bool IsRuby() const
Definition: pormulti.hxx:131
SwLineLayout m_aRoot
Definition: pormulti.hxx:82
sal_uInt8 m_nDirection
Definition: pormulti.hxx:92
bool IsFormatted() const
Definition: pormulti.hxx:124
bool OnRight() const
Definition: pormulti.hxx:134
SwLineLayout & GetRoot()
Definition: pormulti.hxx:121
bool HasRotation() const
Definition: pormulti.hxx:146
bool m_bFlyInContent
Definition: pormulti.hxx:90
bool IsBidi() const
Definition: pormulti.hxx:132
bool IsFollowField() const
Definition: pormulti.hxx:126
bool m_bFollowField
Definition: pormulti.hxx:89
void SetBidi()
Definition: pormulti.hxx:111
void SetFormatted()
Definition: pormulti.hxx:125
bool HasFlyInContent() const
Definition: pormulti.hxx:128
bool m_bFormatted
Definition: pormulti.hxx:88
bool GetTab2() const
Definition: pormulti.hxx:117
RubyPosition m_eRubyPosition
Definition: pormulti.hxx:91
void SetFlyInContent(bool bNew)
Definition: pormulti.hxx:129
void SetRubyPosition(RubyPosition eNew)
Definition: pormulti.hxx:112
RubyPosition GetRubyPosition() const
Definition: pormulti.hxx:135
bool HasTabulator() const
Definition: pormulti.hxx:123
void SetFollowField()
Definition: pormulti.hxx:127
const SwLineLayout & GetRoot() const
Definition: pormulti.hxx:120
sal_uInt8 GetDirection() const
Definition: pormulti.hxx:148
bool GetTab1() const
Definition: pormulti.hxx:116
void SetDirection(sal_uInt8 nNew)
Definition: pormulti.hxx:115
void SetRuby()
Definition: pormulti.hxx:110
void SetTab1(bool bNew)
Definition: pormulti.hxx:113
void SetDouble()
Definition: pormulti.hxx:109
bool HasBrackets() const
Definition: pormulti.hxx:251
bool OnTop() const
Definition: pormulti.hxx:133
SwMultiPortion(TextFrameIndex const nEnd)
Definition: pormulti.hxx:94
bool IsRevers() const
Definition: pormulti.hxx:147
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
SwTwips Width() const
Definition: possiz.hxx:51
SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
Definition: pormulti.hxx:213
void Adjust(SwTextFormatInfo &rInf)
Definition: pormulti.hxx:204
SwRubyPortion(const SwRubyPortion &rRuby, TextFrameIndex nEnd)
Definition: pormulti.cxx:564
void Adjust_(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:656
TextFrameIndex GetRubyOffset() const
Definition: pormulti.hxx:207
css::text::RubyAdjust GetAdjustment() const
Definition: pormulti.hxx:206
TextFrameIndex m_nRubyOffset
Definition: pormulti.hxx:192
void CalcRubyOffset()
Definition: pormulti.cxx:745
css::text::RubyAdjust m_nAdjustment
Definition: pormulti.hxx:193
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
SwTextCursor * pTextCursor
Definition: pormulti.hxx:239
sal_uInt16 nWidth
Definition: pormulti.hxx:242
TextFrameIndex nStart
Definition: pormulti.hxx:241
SwLineLayout * pCurr
Definition: pormulti.hxx:240
sal_uInt8 nOldProp
Definition: pormulti.hxx:243
SwTextCursorSave(SwTextCursor *pTextCursor, SwMultiPortion *pMulti, SwTwips nY, SwTwips &nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd)
Definition: pormulti.cxx:2525
Point Rotate(const Point &rPoint, Degree10 nOrientation, const Point &rOrigin)
const sal_uInt32 RIGHT
long Long
RubyPosition
Definition: pormulti.hxx:44
SwMultiCreatorId
Definition: pormulti.hxx:39
sal_uInt16 nHeight
Definition: pormulti.hxx:65
SwFontScript nPreScript
Definition: pormulti.hxx:70
sal_Unicode cPost
Definition: pormulti.hxx:69
sal_Unicode cPre
Definition: pormulti.hxx:68
sal_uInt16 nPostWidth
Definition: pormulti.hxx:67
sal_uInt16 nPreWidth
Definition: pormulti.hxx:66
TextFrameIndex nStart
Definition: pormulti.hxx:63
SwFontScript nPostScript
Definition: pormulti.hxx:71
sal_uInt16 nAscent
Definition: pormulti.hxx:64
sal_uInt8 nLevel
Definition: pormulti.hxx:56
SwMultiCreatorId nId
Definition: pormulti.hxx:55
const SwTextAttr * pAttr
Definition: pormulti.hxx:53
const SfxPoolItem * pItem
Definition: pormulti.hxx:54
TextFrameIndex nStartOfAttr
Definition: pormulti.hxx:52
SwFontScript
Definition: swfont.hxx:124
tools::Long SwTwips
Definition: swtypes.hxx:51
unsigned char sal_uInt8
sal_uInt16 sal_Unicode