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 #ifndef INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
20 #define INCLUDED_SW_SOURCE_CORE_TEXT_PORMULTI_HXX
21 
22 #include <memory>
23 #include "porlay.hxx"
24 #include <com/sun/star/text/RubyAdjust.hpp>
25 
27 class SwTextFormatInfo;
28 class SwTextCursor;
29 class SwTextPaintInfo;
30 class SwTextAttr;
31 class SfxPoolItem;
32 class SwFont;
33 
34 // SwMultiCreator is a small structure to create a multiportion.
35 // It contains the kind of multiportion and a textattribute
36 // or a poolitem.
37 // The GetMultiCreator-function fills this structure and
38 // the Ctor of the SwMultiPortion uses it.
39 enum class SwMultiCreatorId
40 {
42 };
43 
44 enum class RubyPosition : sal_uInt16
45 {
46  ABOVE = 0,
47  BELOW = 1,
48  RIGHT = 2
49 };
50 
52 {
54  const SwTextAttr* pAttr;
58 };
59 
60 // A two-line-portion (SwMultiPortion) could have surrounding brackets,
61 // in this case the structure SwBracket will be used.
62 struct SwBracket
63 {
64  TextFrameIndex nStart; // Start of text attribute determines the font
65  sal_uInt16 nAscent; // Ascent of the brackets
66  sal_uInt16 nHeight; // Height of them
67  sal_uInt16 nPreWidth; // Width of the opening bracket
68  sal_uInt16 nPostWidth; // Width of the closing bracket
69  sal_Unicode cPre; // Initial character, e.g. '('
70  sal_Unicode cPost; // Final character, e.g. ')'
71  SwFontScript nPreScript; // Script of the initial character
72  SwFontScript nPostScript; // Script of the final character
73 };
74 
75 // The SwMultiPortion is line portion inside a line portion,
76 // it's a group of portions,
77 // e.g. a double line portion in a line
78 // or phonetics (ruby)
79 // or combined characters
80 // or a rotated portion.
82 {
83  SwLineLayout m_aRoot; // One or more lines
84  bool m_bTab1 :1; // First line tabulator
85  bool m_bTab2 :1; // Second line includes tabulator
86  bool m_bDouble :1; // Double line
87  bool m_bRuby :1; // Phonetics
88  bool m_bBidi :1;
89  bool m_bFormatted :1; // Already formatted
90  bool m_bFollowField :1; // Field follow inside
91  bool m_bFlyInContent:1; // Fly as character inside
92  RubyPosition m_eRubyPosition; // Phonetic position
93  sal_uInt8 m_nDirection:2; // Direction (0/90/180/270 degrees)
94 protected:
95  explicit SwMultiPortion(TextFrameIndex const nEnd)
96  : m_bTab1(false)
97  , m_bTab2(false)
98  , m_bDouble(false)
99  , m_bRuby(false)
100  , m_bBidi(false)
101  , m_bFormatted(false)
102  , m_bFollowField(false)
103  , m_bFlyInContent(false)
104  , m_eRubyPosition( RubyPosition::ABOVE )
105  , m_nDirection(0)
106  {
108  SetLen(nEnd);
109  }
110  void SetDouble() { m_bDouble = true; }
111  void SetRuby() { m_bRuby = true; }
112  void SetBidi() { m_bBidi = true; }
113  void SetRubyPosition( RubyPosition eNew ) { m_eRubyPosition = eNew; }
114  void SetTab1( bool bNew ) { m_bTab1 = bNew; }
115  void SetTab2( bool bNew ) { m_bTab2 = bNew; }
116  void SetDirection( sal_uInt8 nNew ) { m_nDirection = nNew; }
117  bool GetTab1() const { return m_bTab1; }
118  bool GetTab2() const { return m_bTab2; }
119 public:
120  virtual ~SwMultiPortion() override;
121  const SwLineLayout& GetRoot() const { return m_aRoot; }
122  SwLineLayout& GetRoot() { return m_aRoot; }
123 
124  bool HasTabulator() const { return m_bTab1 || m_bTab2; }
125  bool IsFormatted() const { return m_bFormatted; }
126  void SetFormatted() { m_bFormatted = true; }
127  bool IsFollowField() const { return m_bFollowField; }
128  void SetFollowField() { m_bFollowField = true; }
129  bool HasFlyInContent() const { return m_bFlyInContent; }
130  void SetFlyInContent( bool bNew ) { m_bFlyInContent = bNew; }
131  bool IsDouble() const { return m_bDouble; }
132  bool IsRuby() const { return m_bRuby; }
133  bool IsBidi() const { return m_bBidi; }
134  bool OnTop() const { return m_eRubyPosition == RubyPosition::ABOVE; }
135  bool OnRight() const { return m_eRubyPosition == RubyPosition::RIGHT; }
137  void ActualizeTabulator();
138 
139  virtual void Paint( const SwTextPaintInfo &rInf ) const override;
140  virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
141  virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const;
142 
143  // Summarize the internal lines to calculate the (external) size
144  void CalcSize( SwTextFormatter& rLine, SwTextFormatInfo &rInf );
145 
146  inline bool HasBrackets() const;
147  bool HasRotation() const { return 0 != (1 & m_nDirection); }
148  bool IsRevers() const { return 0 != (2 & m_nDirection); }
149  sal_uInt8 GetDirection() const { return m_nDirection; }
150 
151  // Accessibility: pass information about this portion to the PortionHandler
152  virtual void HandlePortion( SwPortionHandler& rPH ) const override;
153 };
154 
156 {
157  std::unique_ptr<SwBracket> pBracket; // Surrounding brackets
158  SwTwips nLineDiff; // Difference of the width of the both lines
161 public:
163  SwDoubleLinePortion(const SwMultiCreator& rCreate, TextFrameIndex nEnd);
164  virtual ~SwDoubleLinePortion() override;
165 
166  SwBracket* GetBrackets() const { return pBracket.get(); }
167  void SetBrackets( const SwDoubleLinePortion& rDouble );
168  void PaintBracket( SwTextPaintInfo& rInf, long nSpaceAdd, bool bOpen ) const;
169  void FormatBrackets( SwTextFormatInfo &rInf, SwTwips& nMaxWidth );
170  sal_uInt16 PreWidth() const { return pBracket->nPreWidth; };
171  sal_uInt16 PostWidth() const { return pBracket->nPostWidth; }
173  { pBracket->nPreWidth = pBracket->nPostWidth=0; Width( 0 ); }
174  sal_uInt16 BracketWidth(){ return PreWidth() + PostWidth(); }
175 
176  void CalcBlanks( SwTextFormatInfo &rInf );
177  static void ResetSpaceAdd( SwLineLayout* pCurr );
178  SwTwips GetLineDiff() const { return nLineDiff; }
180  { return ( nLineDiff < 0 ) ? nBlank2 : nBlank1; }
182  { return ( nLineDiff < 0 ) ? nBlank1 : nBlank2; }
183 
184  virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
185  virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const override;
186 };
187 
189 {
191  css::text::RubyAdjust nAdjustment;
192  void Adjust_( SwTextFormatInfo &rInf);
193 public:
194  SwRubyPortion(const SwRubyPortion& rRuby, TextFrameIndex nEnd);
195 
196  SwRubyPortion( const SwMultiCreator& rCreate, const SwFont& rFnt,
197  const IDocumentSettingAccess& rIDocumentSettingAccess,
198  TextFrameIndex nEnd, TextFrameIndex nOffs,
199  const SwTextSizeInfo &rInf );
200 
201  void CalcRubyOffset();
202  void Adjust( SwTextFormatInfo &rInf )
203  { if(nAdjustment != css::text::RubyAdjust_LEFT && GetRoot().GetNext()) Adjust_(rInf); }
204  css::text::RubyAdjust GetAdjustment() const { return nAdjustment; }
206 };
207 
209 {
210 public:
212  : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
213  SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
214  bool bRTL );
215 };
216 
218 {
220 
221 public:
223 
224  sal_uInt8 GetLevel() const { return nLevel; }
225  // Get number of blanks for justified alignment
226  TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const;
227  // Calculates extra spacing based on number of blanks
228  virtual long CalcSpacing( long nSpaceAdd, const SwTextSizeInfo &rInf ) const override;
229  // Manipulate the spacing array at pCurr
230  virtual bool ChgSpaceAdd( SwLineLayout* pCurr, long nSpaceAdd ) const override;
231 };
232 
233 // For cursor travelling in multiportions
234 
236 {
240  sal_uInt16 nWidth;
242  bool bSpaceChg;
243 public:
244  SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
245  SwTwips nY, sal_uInt16& nX, TextFrameIndex nCurrStart, long nSpaceAdd);
247 };
248 
249 inline bool SwMultiPortion::HasBrackets() const
250 {
251  return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
252 }
253 
254 #endif
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasFlyInContent() const
Definition: pormulti.hxx:129
sal_uInt16 nHeight
Definition: pormulti.hxx:66
TextFrameIndex nBlank1
Number of blanks in the first line.
Definition: pormulti.hxx:159
TextFrameIndex nRubyOffset
Definition: pormulti.hxx:190
void CalcSize(SwTextFormatter &rLine, SwTextFormatInfo &rInf)
Definition: pormulti.cxx:70
SwRubyPortion(const SwRubyPortion &rRuby, TextFrameIndex nEnd)
Definition: pormulti.cxx:543
virtual ~SwMultiPortion() override
Definition: pormulti.cxx:59
sal_Unicode cPost
Definition: pormulti.hxx:70
virtual ~SwDoubleLinePortion() override
Definition: pormulti.cxx:537
void SetTab1(bool bNew)
Definition: pormulti.hxx:114
sal_uInt16 BracketWidth()
Definition: pormulti.hxx:174
TextFrameIndex nStart
Definition: pormulti.hxx:239
SwFontScript nPostScript
Definition: pormulti.hxx:72
SwFontScript nPreScript
Definition: pormulti.hxx:71
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, long nSpaceAdd) const
Definition: pormulti.cxx:131
virtual long CalcSpacing(long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:200
RubyPosition
Definition: pormulti.hxx:44
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
void SetFlyInContent(bool bNew)
Definition: pormulti.hxx:130
TextFrameIndex nBlank2
Number of blanks in the second line.
Definition: pormulti.hxx:160
const SwLineLayout & GetRoot() const
Definition: pormulti.hxx:121
void CalcRubyOffset()
Definition: pormulti.cxx:724
TextFrameIndex GetRubyOffset() const
Definition: pormulti.hxx:205
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:74
virtual long CalcSpacing(long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:486
long SwTwips
Definition: swtypes.hxx:49
SwTextCursor * pTextCursor
Definition: pormulti.hxx:237
void PaintBracket(SwTextPaintInfo &rInf, long nSpaceAdd, bool bOpen) const
Definition: pormulti.cxx:339
sal_uInt8 GetDirection() const
Definition: pormulti.hxx:149
virtual void Paint(const SwTextPaintInfo &rInf) const override
Definition: pormulti.cxx:63
bool m_bFormatted
Definition: pormulti.hxx:89
std::unique_ptr< SwBracket > pBracket
Definition: pormulti.hxx:157
sal_uInt8 m_nDirection
Definition: pormulti.hxx:93
void SetTab2(bool bNew)
Definition: pormulti.hxx:115
virtual void HandlePortion(SwPortionHandler &rPH) const override
Definition: pormulti.cxx:136
sal_uInt16 sal_Unicode
SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
Definition: pormulti.hxx:211
void FormatBrackets(SwTextFormatInfo &rInf, SwTwips &nMaxWidth)
Definition: pormulti.cxx:388
virtual long CalcSpacing(long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:126
const SfxPoolItem * pItem
Definition: pormulti.hxx:55
css::text::RubyAdjust GetAdjustment() const
Definition: pormulti.hxx:204
bool HasRotation() const
Definition: pormulti.hxx:147
bool IsFollowField() const
Definition: pormulti.hxx:127
void Adjust_(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:635
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, long nSpaceAdd) const override
Definition: pormulti.cxx:497
sal_uInt16 nAscent
Definition: pormulti.hxx:65
void SetBidi()
Definition: pormulti.hxx:112
sal_uInt8 const nLevel
Definition: pormulti.hxx:219
void SetFormatted()
Definition: pormulti.hxx:126
sal_uInt16 nPreWidth
Definition: pormulti.hxx:67
bool IsBidi() const
Definition: pormulti.hxx:133
sal_uInt8 nOldProp
Definition: pormulti.hxx:241
css::text::RubyAdjust nAdjustment
Definition: pormulti.hxx:191
sal_uInt8 GetLevel() const
Definition: pormulti.hxx:224
sal_uInt16 nWidth
Definition: pormulti.hxx:240
SwTextCursorSave(SwTextCursor *pTextCursor, SwMultiPortion *pMulti, SwTwips nY, sal_uInt16 &nX, TextFrameIndex nCurrStart, long nSpaceAdd)
Definition: pormulti.cxx:2489
void SetFollowField()
Definition: pormulti.hxx:128
Collection of SwLinePortion instances, representing one line of text.
Definition: porlay.hxx:78
SwTwips GetLineDiff() const
Definition: pormulti.hxx:178
static void ResetSpaceAdd(SwLineLayout *pCurr)
Definition: pormulti.cxx:530
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:93
const SwTextAttr * pAttr
Definition: pormulti.hxx:54
bool GetTab1() const
Definition: pormulti.hxx:117
TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const
Definition: pormulti.cxx:217
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, long nSpaceAdd) const override
Definition: pormulti.cxx:205
Provides access to settings of a document.
TextFrameIndex GetSmallerSpaceCnt() const
Definition: pormulti.hxx:181
void CalcBlanks(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:454
sal_uInt8 nLevel
Definition: pormulti.hxx:57
void Adjust(SwTextFormatInfo &rInf)
Definition: pormulti.hxx:202
sal_uInt16 PreWidth() const
Definition: pormulti.hxx:170
bool HasBrackets() const
Definition: pormulti.hxx:249
bool OnTop() const
Definition: pormulti.hxx:134
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:95
bool IsRevers() const
Definition: pormulti.hxx:148
void SetRuby()
Definition: pormulti.hxx:111
unsigned char sal_uInt8
SwMultiCreatorId nId
Definition: pormulti.hxx:56
bool GetTab2() const
Definition: pormulti.hxx:118
void SetDirection(sal_uInt8 nNew)
Definition: pormulti.hxx:116
bool IsDouble() const
Definition: pormulti.hxx:131
bool OnRight() const
Definition: pormulti.hxx:135
sal_uInt16 PostWidth() const
Definition: pormulti.hxx:171
SwLineLayout & GetRoot()
Definition: pormulti.hxx:122
TextFrameIndex nStart
Definition: pormulti.hxx:64
bool m_bFollowField
Definition: pormulti.hxx:90
TextFrameIndex GetSpaceCnt() const
Definition: pormulti.hxx:179
void ActualizeTabulator()
Definition: pormulti.cxx:142
void SetDouble()
Definition: pormulti.hxx:110
sal_uInt16 Width() const
Definition: possiz.hxx:46
SwFontScript
Definition: swfont.hxx:119
RubyPosition GetRubyPosition() const
Definition: pormulti.hxx:136
SwMultiCreatorId
Definition: pormulti.hxx:39
sal_uInt16 nPostWidth
Definition: pormulti.hxx:68
void SetBrackets(const SwDoubleLinePortion &rDouble)
Definition: pormulti.cxx:372
bool m_bFlyInContent
Definition: pormulti.hxx:91
TextFrameIndex nStartOfAttr
Definition: pormulti.hxx:53
bool HasTabulator() const
Definition: pormulti.hxx:124
void SetRubyPosition(RubyPosition eNew)
Definition: pormulti.hxx:113
sal_Unicode cPre
Definition: pormulti.hxx:69
SwLineLayout * pCurr
Definition: pormulti.hxx:238
SwLineLayout m_aRoot
Definition: pormulti.hxx:83
SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv)
Definition: pormulti.cxx:189
bool IsFormatted() const
Definition: pormulti.hxx:125
bool IsRuby() const
Definition: pormulti.hxx:132
SwBracket * GetBrackets() const
Definition: pormulti.hxx:166
RubyPosition m_eRubyPosition
Definition: pormulti.hxx:92
SwDoubleLinePortion(SwDoubleLinePortion &rDouble, TextFrameIndex nEnd)
Definition: pormulti.cxx:242