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.
80 class 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)
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; }
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
163 public:
165  SwDoubleLinePortion(const SwMultiCreator& rCreate, TextFrameIndex nEnd);
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);
195 public:
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();
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; }
208 };
209 
211 {
212 public:
214  : SwMultiPortion( nEnd ) { SetDirection( nDir ); }
215  SwRotatedPortion( const SwMultiCreator& rCreate, TextFrameIndex nEnd,
216  bool bRTL );
217 };
218 
220 {
222 
223 public:
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;
244  bool bSpaceChg;
245 public:
246  SwTextCursorSave( SwTextCursor* pTextCursor, SwMultiPortion* pMulti,
247  SwTwips nY, SwTwips& nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd);
249 };
250 
251 inline bool SwMultiPortion::HasBrackets() const
252 {
253  return IsDouble() && nullptr != static_cast<const SwDoubleLinePortion*>(this)->GetBrackets();
254 }
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasFlyInContent() const
Definition: pormulti.hxx:128
sal_uInt16 nHeight
Definition: pormulti.hxx:65
SwRubyPortion(const SwRubyPortion &rRuby, TextFrameIndex nEnd)
Definition: pormulti.cxx:564
sal_Unicode cPost
Definition: pormulti.hxx:69
virtual ~SwDoubleLinePortion() override
Definition: pormulti.cxx:558
void SetTab1(bool bNew)
Definition: pormulti.hxx:113
sal_uInt16 BracketWidth()
Definition: pormulti.hxx:176
TextFrameIndex nStart
Definition: pormulti.hxx:241
SwFontScript nPostScript
Definition: pormulti.hxx:71
SwFontScript nPreScript
Definition: pormulti.hxx:70
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:306
RubyPosition
Definition: pormulti.hxx:43
sal_uInt8 m_nLevel
Definition: pormulti.hxx:221
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:745
TextFrameIndex GetRubyOffset() const
Definition: pormulti.hxx:207
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:77
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const override
Definition: pormulti.cxx:507
SwTextCursor * pTextCursor
Definition: pormulti.hxx:239
sal_uInt8 GetDirection() const
Definition: pormulti.hxx:148
void SetTab2(bool bNew)
Definition: pormulti.hxx:114
void PaintBracket(SwTextPaintInfo &rInf, tools::Long nSpaceAdd, bool bOpen) const
Definition: pormulti.cxx:360
sal_uInt16 sal_Unicode
SwRotatedPortion(TextFrameIndex const nEnd, sal_uInt8 nDir)
Definition: pormulti.hxx:213
virtual void Paint(const SwTextPaintInfo &rInf) const =0
void FormatBrackets(SwTextFormatInfo &rInf, SwTwips &nMaxWidth)
Definition: pormulti.cxx:409
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:43
css::text::RubyAdjust GetAdjustment() const
Definition: pormulti.hxx:206
bool HasRotation() const
Definition: pormulti.hxx:146
bool IsFollowField() const
Definition: pormulti.hxx:126
void Adjust_(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:656
TextFrameIndex m_nRubyOffset
Definition: pormulti.hxx:192
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:243
virtual void dumpAsXml(xmlTextWriterPtr pWriter, const OUString &rText, TextFrameIndex &rOffset) const
Definition: porlin.cxx:321
sal_uInt8 GetLevel() const
Definition: pormulti.hxx:226
sal_uInt16 nWidth
Definition: pormulti.hxx:242
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:180
static void ResetSpaceAdd(SwLineLayout *pCurr)
Definition: pormulti.cxx:551
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:98
css::text::RubyAdjust m_nAdjustment
Definition: pormulti.hxx:193
const SwTextAttr * pAttr
Definition: pormulti.hxx:53
bool GetTab1() const
Definition: pormulti.hxx:116
TextFrameIndex GetSpaceCnt(const SwTextSizeInfo &rInf) const
Definition: pormulti.cxx:238
SwTextCursorSave(SwTextCursor *pTextCursor, SwMultiPortion *pMulti, SwTwips nY, SwTwips &nX, TextFrameIndex nCurrStart, tools::Long nSpaceAdd)
Definition: pormulti.cxx:2526
virtual bool ChgSpaceAdd(SwLineLayout *pCurr, tools::Long nSpaceAdd) const override
Definition: pormulti.cxx:518
virtual void HandlePortion(SwPortionHandler &rPH) const
Definition: porlin.cxx:316
Provides access to settings of a document.
TextFrameIndex GetSmallerSpaceCnt() const
Definition: pormulti.hxx:183
void CalcBlanks(SwTextFormatInfo &rInf)
Definition: pormulti.cxx:475
sal_uInt8 nLevel
Definition: pormulti.hxx:56
void Adjust(SwTextFormatInfo &rInf)
Definition: pormulti.hxx:204
sal_uInt16 PreWidth() const
Definition: pormulti.hxx:172
tools::Long SwTwips
Definition: swtypes.hxx:51
std::unique_ptr< SwBracket > m_pBracket
Definition: pormulti.hxx:159
bool HasBrackets() const
Definition: pormulti.hxx:251
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:51
SwMultiPortion(TextFrameIndex const nEnd)
Definition: pormulti.hxx:94
bool IsRevers() const
Definition: pormulti.hxx:147
SwTwips Width() const
Definition: possiz.hxx:51
TextFrameIndex m_nBlank1
Number of blanks in the first line.
Definition: pormulti.hxx:161
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:173
SwLineLayout & GetRoot()
Definition: pormulti.hxx:121
TextFrameIndex nStart
Definition: pormulti.hxx:63
TextFrameIndex GetSpaceCnt() const
Definition: pormulti.hxx:181
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
void SetDouble()
Definition: pormulti.hxx:109
SwFontScript
Definition: swfont.hxx:123
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:393
TextFrameIndex nStartOfAttr
Definition: pormulti.hxx:52
struct _xmlTextWriter * xmlTextWriterPtr
bool HasTabulator() const
Definition: pormulti.hxx:123
TextFrameIndex m_nBlank2
Number of blanks in the second line.
Definition: pormulti.hxx:162
void SetRubyPosition(RubyPosition eNew)
Definition: pormulti.hxx:112
sal_Unicode cPre
Definition: pormulti.hxx:68
SwLineLayout * pCurr
Definition: pormulti.hxx:240
SwLineLayout m_aRoot
Definition: pormulti.hxx:82
SwBidiPortion(TextFrameIndex nEnd, sal_uInt8 nLv)
Definition: pormulti.cxx:210
bool IsFormatted() const
Definition: pormulti.hxx:124
bool IsRuby() const
Definition: pormulti.hxx:131
SwBracket * GetBrackets() const
Definition: pormulti.hxx:168
RubyPosition m_eRubyPosition
Definition: pormulti.hxx:91
SwDoubleLinePortion(SwDoubleLinePortion &rDouble, TextFrameIndex nEnd)
Definition: pormulti.cxx:263
bool m_bDetectedRangeSegmentation false