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 
26 class SwTextFormatInfo;
27 class SwTextCursor;
28 class SwTextPaintInfo;
29 class SwTextAttr;
30 class SfxPoolItem;
31 class 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.
38 enum class SwMultiCreatorId
39 {
41 };
42 
43 enum class RubyPosition : sal_uInt16
44 {
45  ABOVE = 0,
46  BELOW = 1,
47  RIGHT = 2
48 };
49 
51 {
53  const SwTextAttr* pAttr;
57 };
58 
59 // A two-line-portion (SwMultiPortion) could have surrounding brackets,
60 // in this case the structure SwBracket will be used.
61 struct SwBracket
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.
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)
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)
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; }
118 public:
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; }
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 
155 {
156  std::unique_ptr<SwBracket> m_pBracket; // Surrounding brackets
157  SwTwips m_nLineDiff; // Difference of the width of the both lines
160 public:
162  SwDoubleLinePortion(const SwMultiCreator& rCreate, TextFrameIndex nEnd);
163  virtual ~SwDoubleLinePortion() override;
164 
165  SwBracket* GetBrackets() const { return m_pBracket.get(); }
166  void SetBrackets( const SwDoubleLinePortion& rDouble );
167  void PaintBracket( SwTextPaintInfo& rInf, tools::Long nSpaceAdd, bool bOpen ) const;
168  void FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxWidth );
169  sal_uInt16 PreWidth() const { return m_pBracket->nPreWidth; };
170  sal_uInt16 PostWidth() const { return m_pBracket->nPostWidth; }
172  { m_pBracket->nPreWidth = m_pBracket->nPostWidth=0; Width( 0 ); }
173  sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
174 
175  void CalcBlanks( SwTextFormatInfo &rInf );
176  static void ResetSpaceAdd( SwLineLayout* pCurr );
177  SwTwips GetLineDiff() const { return m_nLineDiff; }
179  { return ( m_nLineDiff < 0 ) ? m_nBlank2 : m_nBlank1; }
181  { return ( m_nLineDiff < 0 ) ? m_nBlank1 : m_nBlank2; }
182 
183  virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
184  virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const override;
185 };
186 
188 {
190  css::text::RubyAdjust m_nAdjustment;
191  void Adjust_( SwTextFormatInfo &rInf);
192 public:
193  SwRubyPortion(const SwRubyPortion& rRuby, TextFrameIndex nEnd);
194 
195  SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
196  const IDocumentSettingAccess& rIDocumentSettingAccess,
197  TextFrameIndex nEnd, TextFrameIndex nOffs,
198  const SwTextSizeInfo &rInf );
199 
200  void CalcRubyOffset();
201  void Adjust( SwTextFormatInfo &rInf )
202  { if(m_nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
203  css::text::RubyAdjust GetAdjustment() const { return m_nAdjustment; }
205 };
206 
208 {
209 public:
211  : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
212  SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
213  bool bRTL );
214 };
215 
217 {
219 
220 public:
222 
223  sal_uInt8 GetLevel() const { return m_nLevel; }
224  // Get number of blanks for justified alignment
225  TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const;
226  // Calculates extra spacing based on number of blanks
227  virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
228  // Manipulate the spacing array at pCurr
229  virtual bool ChgSpaceAdd( SwLineLayout* pCurr, tools::Long nSpaceAdd ) const override;
230 };
231 
232 // For cursor travelling in multiportions
233 
235 {
239  sal_uInt16 nWidth;
241  bool bSpaceChg;
242 public:
243  SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
244  SwTwips nY, sal_uInt16& nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd);
246 };
247 
248 inline bool SwMultiPortion::HasBrackets() const
249 {
250  return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
251 }
252 
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasFlyInContent() const
Definition: pormulti.hxx:128
sal_uInt16 nHeight
Definition: pormulti.hxx:65
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:122
void CalcSize(SwTextFormatter &rLine, SwTextFormatInfo &rInf)
Definition: pormulti.cxx:66
SwRubyPortion(const SwRubyPortion &rRuby, TextFrameIndex nEnd)
Definition: pormulti.cxx:539
SwTextCursorSave(SwTextCursor *pTextCursor, SwMultiPortion *pMulti, SwTwips nY, sal_uInt16 &nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd)
Definition: pormulti.cxx:2510
virtual ~SwMultiPortion() override
Definition: pormulti.cxx:55
sal_Unicode cPost
Definition: pormulti.hxx:69
virtual ~SwDoubleLinePortion() override
Definition: pormulti.cxx:533
void SetTab1(bool bNew)
Definition: pormulti.hxx:113
sal_uInt16 BracketWidth()
Definition: pormulti.hxx:173
TextFrameIndex nStart
Definition: pormulti.hxx:238
SwFontScript nPostScript
Definition: pormulti.hxx:71
SwFontScript nPreScript
Definition: pormulti.hxx:70
RubyPosition
Definition: pormulti.hxx:43
sal_uInt8 m_nLevel
Definition: pormulti.hxx:218
long Long
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
void SetFlyInContent(bool bNew)
Definition: pormulti.hxx:129
const SwLineLayout & GetRoot() const
Definition: pormulti.hxx:120
void CalcRubyOffset()
Definition: pormulti.cxx:720
TextFrameIndex GetRubyOffset() const
Definition: pormulti.hxx:204
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:74
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:482
SwTextCursor * pTextCursor
Definition: pormulti.hxx:236
sal_uInt8 GetDirection() const
Definition: pormulti.hxx:148
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: pormulti.cxx:59
bool m_bFormatted
Definition: pormulti.hxx:88
sal_uInt8 m_nDirection
Definition: pormulti.hxx:92
void SetTab2(bool bNew)
Definition: pormulti.hxx:114
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: pormulti.cxx:132
void PaintBracket(SwTextPaintInfo &rInf, tools::Long nSpaceAdd, bool bOpen) const
Definition: pormulti.cxx:335
sal_uInt16 sal_Unicode
SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
Definition: pormulti.hxx:210
void FormatBrackets(SwTextFormatInfo &rInf, SwTwips &nMaxWidth)
Definition: pormulti.cxx:384
const SfxPoolItem * pItem
Definition: pormulti.hxx:54
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
css::text::RubyAdjust GetAdjustment() const
Definition: pormulti.hxx:203
bool HasRotation() const
Definition: pormulti.hxx:146
bool IsFollowField() const
Definition: pormulti.hxx:126
void Adjust_(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:631
TextFrameIndex m_nRubyOffset
Definition: pormulti.hxx:189
sal_uInt16 nAscent
Definition: pormulti.hxx:64
void SetBidi()
Definition: pormulti.hxx:111
void SetFormatted()
Definition: pormulti.hxx:125
sal_uInt16 nPreWidth
Definition: pormulti.hxx:66
bool IsBidi() const
Definition: pormulti.hxx:132
sal_uInt8 nOldProp
Definition: pormulti.hxx:240
sal_uInt8 GetLevel() const
Definition: pormulti.hxx:223
sal_uInt16 nWidth
Definition: pormulti.hxx:239
void SetFollowField()
Definition: pormulti.hxx:127
Collection of SwLinePortion instances, representing one line of text.
Definition: porlay.hxx:78
SwTwips GetLineDiff() const
Definition: pormulti.hxx:177
static void ResetSpaceAdd(SwLineLayout *pCurr)
Definition: pormulti.cxx:526
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:93
css::text::RubyAdjust m_nAdjustment
Definition: pormulti.hxx:190
const SwTextAttr * pAttr
Definition: pormulti.hxx:53
bool GetTab1() const
Definition: pormulti.hxx:116
TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const
Definition: pormulti.cxx:213
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const override
Definition: pormulti.cxx:493
Provides access to settings of a document.
TextFrameIndex GetSmallerSpaceCnt() const
Definition: pormulti.hxx:180
void CalcBlanks(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:450
sal_uInt8 nLevel
Definition: pormulti.hxx:56
void Adjust(SwTextFormatInfo &rInf)
Definition: pormulti.hxx:201
sal_uInt16 PreWidth() const
Definition: pormulti.hxx:169
tools::Long SwTwips
Definition: swtypes.hxx:49
std::unique_ptr< SwBracket > m_pBracket
Definition: pormulti.hxx:156
bool HasBrackets() const
Definition: pormulti.hxx:248
bool OnTop() const
Definition: pormulti.hxx:133
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:49
SwMultiPortion(TextFrameIndex const nEnd)
Definition: pormulti.hxx:94
bool IsRevers() const
Definition: pormulti.hxx:147
TextFrameIndex m_nBlank1
Number of blanks in the first line.
Definition: pormulti.hxx:158
void SetRuby()
Definition: pormulti.hxx:110
unsigned char sal_uInt8
SwMultiCreatorId nId
Definition: pormulti.hxx:55
bool GetTab2() const
Definition: pormulti.hxx:117
void SetDirection(sal_uInt8 nNew)
Definition: pormulti.hxx:115
bool IsDouble() const
Definition: pormulti.hxx:130
bool OnRight() const
Definition: pormulti.hxx:134
sal_uInt16 PostWidth() const
Definition: pormulti.hxx:170
SwLineLayout & GetRoot()
Definition: pormulti.hxx:121
TextFrameIndex nStart
Definition: pormulti.hxx:63
bool m_bFollowField
Definition: pormulti.hxx:89
TextFrameIndex GetSpaceCnt() const
Definition: pormulti.hxx:178
void ActualizeTabulator()
Definition: pormulti.cxx:138
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const override
Definition: pormulti.cxx:201
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:196
void SetDouble()
Definition: pormulti.hxx:109
sal_uInt16 Width() const
Definition: possiz.hxx:51
SwFontScript
Definition: swfont.hxx:122
RubyPosition GetRubyPosition() const
Definition: pormulti.hxx:135
SwMultiCreatorId
Definition: pormulti.hxx:38
sal_uInt16 nPostWidth
Definition: pormulti.hxx:67
void SetBrackets(const SwDoubleLinePortion &rDouble)
Definition: pormulti.cxx:368
bool m_bFlyInContent
Definition: pormulti.hxx:90
TextFrameIndex nStartOfAttr
Definition: pormulti.hxx:52
bool HasTabulator() const
Definition: pormulti.hxx:123
TextFrameIndex m_nBlank2
Number of blanks in the second line.
Definition: pormulti.hxx:159
void SetRubyPosition(RubyPosition eNew)
Definition: pormulti.hxx:112
sal_Unicode cPre
Definition: pormulti.hxx:68
SwLineLayout * pCurr
Definition: pormulti.hxx:237
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const
Definition: pormulti.cxx:127
SwLineLayout m_aRoot
Definition: pormulti.hxx:82
SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv)
Definition: pormulti.cxx:185
bool IsFormatted() const
Definition: pormulti.hxx:124
bool IsRuby() const
Definition: pormulti.hxx:131
SwBracket * GetBrackets() const
Definition: pormulti.hxx:165
RubyPosition m_eRubyPosition
Definition: pormulti.hxx:91
SwDoubleLinePortion(SwDoubleLinePortion &rDouble, TextFrameIndex nEnd)
Definition: pormulti.cxx:238