LibreOffice Module sw (master)  1
porlin.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 <libxml/xmlwriter.h>
22 
23 #include "possiz.hxx"
24 #include <txttypes.hxx>
25 #include <TextFrameIndex.hxx>
26 #include <rtl/ustring.hxx>
27 
28 class SwTextSizeInfo;
29 class SwTextPaintInfo;
30 class SwTextFormatInfo;
31 class SwPortionHandler;
32 
35 #define PORGRP_TXT 0x8000
36 #define PORGRP_EXP 0x4000
37 #define PORGRP_FLD 0x2000
38 #define PORGRP_HYPH 0x1000
39 #define PORGRP_NUMBER 0x0800
40 #define PORGRP_GLUE 0x0400
41 #define PORGRP_FIX 0x0200
42 #define PORGRP_TAB 0x0100
43 // Small special groups
44 #define PORGRP_FIXMARG 0x0040
45 //#define PORGRP_? 0x0020
46 #define PORGRP_TABNOTLFT 0x0010
47 #define PORGRP_TOXREF 0x0008
48 
51 class SAL_DLLPUBLIC_RTTI SwLinePortion: public SwPosSize
52 {
53 protected:
54  // Here we have areas with different attributes
56  // Count of chars and spaces on the line
58  SwTwips mnAscent; // Maximum ascender
60 
61  SwLinePortion();
62 private:
63  PortionType mnWhichPor; // Who's who?
66 
67  void Truncate_();
68 
69 public:
70  explicit inline SwLinePortion(const SwLinePortion &rPortion);
71  virtual ~SwLinePortion();
72 
73  // Access methods
74  SwLinePortion *GetNextPortion() const { return mpNextPortion; }
75  inline SwLinePortion &operator=(const SwLinePortion &rPortion);
76  TextFrameIndex GetLen() const { return mnLineLength; }
77  void SetLen(TextFrameIndex const nLen) { mnLineLength = nLen; }
78  void SetNextPortion( SwLinePortion *pNew ){ mpNextPortion = pNew; }
79  SwTwips &GetAscent() { return mnAscent; }
80  SwTwips GetAscent() const { return mnAscent; }
81  void SetAscent( const SwTwips nNewAsc ) { mnAscent = nNewAsc; }
82  void PrtWidth( SwTwips nNewWidth ) { Width( nNewWidth ); }
83  SwTwips PrtWidth() const { return Width(); }
84  void AddPrtWidth( const SwTwips nNew ) { Width( Width() + nNew ); }
85  void SubPrtWidth( const SwTwips nNew ) { Width( Width() - nNew ); }
86  SwTwips GetHangingBaseline() const { return mnHangingBaseline; }
87  void SetHangingBaseline( const SwTwips nNewBaseline ) { mnHangingBaseline = nNewBaseline; }
88 
89  // Insert methods
90  virtual SwLinePortion *Insert( SwLinePortion *pPortion );
91  virtual SwLinePortion *Append( SwLinePortion *pPortion );
92  SwLinePortion *Cut( SwLinePortion *pVictim );
93  inline void Truncate();
94 
95  // Returns 0, if there's no payload
96  virtual SwLinePortion *Compress();
97 
98  void SetWhichPor( const PortionType nNew ) { mnWhichPor = nNew; }
99  PortionType GetWhichPor( ) const { return mnWhichPor; }
100 
101 // Group queries
102  bool InTextGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TXT) != 0; }
103  bool InGlueGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_GLUE) != 0; }
104  bool InTabGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TAB) != 0; }
105  bool InHyphGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_HYPH) != 0; }
106  bool InNumberGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_NUMBER) != 0; }
107  bool InFixGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIX) != 0; }
108  bool InFieldGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FLD) != 0; }
109  bool InToxRefGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TOXREF) != 0; }
110  bool InToxRefOrFieldGrp() const { return (sal_uInt16(mnWhichPor) & ( PORGRP_FLD | PORGRP_TOXREF )) != 0; }
111  bool InExpGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_EXP) != 0; }
112  bool InFixMargGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIXMARG) != 0; }
113  bool InSpaceGrp() const { return InTextGrp() || IsMultiPortion(); }
114 // Individual queries
115  bool IsGrfNumPortion() const { return mnWhichPor == PortionType::GrfNum; }
116  bool IsFlyCntPortion() const { return mnWhichPor == PortionType::FlyCnt; }
117  bool IsBlankPortion() const { return mnWhichPor == PortionType::Blank; }
118  bool IsBreakPortion() const { return mnWhichPor == PortionType::Break; }
119  bool IsErgoSumPortion() const { return mnWhichPor == PortionType::ErgoSum; }
120  bool IsQuoVadisPortion() const { return mnWhichPor == PortionType::QuoVadis; }
121  bool IsTabLeftPortion() const { return mnWhichPor == PortionType::TabLeft; }
122  bool IsTabRightPortion() const { return mnWhichPor == PortionType::TabRight; }
123  bool IsTabCenterPortion() const { return mnWhichPor == PortionType::TabCenter; }
124  bool IsTabDecimalPortion() const { return mnWhichPor == PortionType::TabDecimal; }
125  bool IsFootnoteNumPortion() const { return mnWhichPor == PortionType::FootnoteNum; }
126  bool IsFootnotePortion() const { return mnWhichPor == PortionType::Footnote; }
127  bool IsDropPortion() const { return mnWhichPor == PortionType::Drop; }
128  bool IsLayPortion() const { return mnWhichPor == PortionType::Lay; }
129  bool IsParaPortion() const { return mnWhichPor == PortionType::Para; }
130  bool IsMarginPortion() const { return mnWhichPor == PortionType::Margin; }
131  bool IsFlyPortion() const { return mnWhichPor == PortionType::Fly; }
132  bool IsHolePortion() const { return mnWhichPor == PortionType::Hole; }
133  bool IsSoftHyphPortion() const { return mnWhichPor == PortionType::SoftHyphen; }
134  bool IsPostItsPortion() const { return mnWhichPor == PortionType::PostIts; }
135  bool IsCombinedPortion() const { return mnWhichPor == PortionType::Combined; }
136  bool IsTextPortion() const { return mnWhichPor == PortionType::Text; }
137  bool IsHangingPortion() const { return mnWhichPor == PortionType::Hanging; }
138  bool IsKernPortion() const { return mnWhichPor == PortionType::Kern; }
139  bool IsArrowPortion() const { return mnWhichPor == PortionType::Arrow; }
140  bool IsMultiPortion() const { return mnWhichPor == PortionType::Multi; }
141  bool IsNumberPortion() const { return mnWhichPor == PortionType::Number; } // #i23726#
142  bool IsControlCharPortion() const { return mnWhichPor == PortionType::ControlChar || mnWhichPor == PortionType::Bookmark; }
143 
144  // Positioning
145  SwLinePortion *FindPrevPortion( const SwLinePortion *pRoot );
146  SwLinePortion *FindLastPortion();
147 
149  virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const;
150  virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const;
151  void CalcTextSize( const SwTextSizeInfo &rInfo );
152 
153  // Output
154  virtual void Paint( const SwTextPaintInfo &rInf ) const = 0;
155  void PrePaint( const SwTextPaintInfo &rInf, const SwLinePortion *pLast ) const;
156 
157  virtual bool Format( SwTextFormatInfo &rInf );
158  // Is called for the line's last portion
159  virtual void FormatEOL( SwTextFormatInfo &rInf );
160  void Move( SwTextPaintInfo &rInf );
161 
162  // For SwTextSlot
163  virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const;
164 
165  // For SwFieldPortion, SwSoftHyphPortion
166  virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const;
167 
168  // for text- and multi-portions
169  virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const;
170 
171  // Accessibility: pass information about this portion to the PortionHandler
172  virtual void HandlePortion( SwPortionHandler& rPH ) const;
173 
174  bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev; }
175  bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext; }
176  void SetJoinBorderWithPrev( const bool bJoinPrev ) { m_bJoinBorderWithPrev = bJoinPrev; }
177  void SetJoinBorderWithNext( const bool bJoinNext ) { m_bJoinBorderWithNext = bJoinNext; }
178 
179  virtual void dumpAsXml(xmlTextWriterPtr pWriter, const OUString& rText,
180  TextFrameIndex& rOffset) const;
181  void dumpAsXmlAttributes(xmlTextWriterPtr writer, std::u16string_view rText,
182  TextFrameIndex nOffset) const;
183 };
184 
186 {
187  *static_cast<SwPosSize*>(this) = rPortion;
188  mnLineLength = rPortion.mnLineLength;
189  mnAscent = rPortion.mnAscent;
191  mnWhichPor = rPortion.mnWhichPor;
194  return *this;
195 }
196 
198  SwPosSize( rPortion ),
199  mpNextPortion( nullptr ),
200  mnLineLength( rPortion.mnLineLength ),
201  mnAscent( rPortion.mnAscent ),
202  mnHangingBaseline( rPortion.mnHangingBaseline ),
203  mnWhichPor( rPortion.mnWhichPor ),
204  m_bJoinBorderWithPrev( rPortion.m_bJoinBorderWithPrev ),
205  m_bJoinBorderWithNext( rPortion.m_bJoinBorderWithNext )
206 {
207 }
208 
210 {
211  if ( mpNextPortion )
212  Truncate_();
213 }
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTwips PrtWidth() const
Definition: porlin.hxx:83
#define PORGRP_EXP
Definition: porlin.hxx:36
bool IsGrfNumPortion() const
Definition: porlin.hxx:115
bool InToxRefGrp() const
Definition: porlin.hxx:109
bool InSpaceGrp() const
Definition: porlin.hxx:113
#define PORGRP_FIX
Definition: porlin.hxx:41
bool InNumberGrp() const
Definition: porlin.hxx:106
#define PORGRP_TXT
Portion groups.
Definition: porlin.hxx:35
bool IsTextPortion() const
Definition: porlin.hxx:136
void Truncate_()
Definition: porlin.cxx:152
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:174
long Long
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
void SetLen(TextFrameIndex const nLen)
Definition: porlin.hxx:77
bool IsHangingPortion() const
Definition: porlin.hxx:137
void SetJoinBorderWithPrev(const bool bJoinPrev)
Definition: porlin.hxx:176
bool InFieldGrp() const
Definition: porlin.hxx:108
bool IsParaPortion() const
Definition: porlin.hxx:129
bool IsControlCharPortion() const
Definition: porlin.hxx:142
bool IsLayPortion() const
Definition: porlin.hxx:128
bool IsMarginPortion() const
Definition: porlin.hxx:130
bool InToxRefOrFieldGrp() const
Definition: porlin.hxx:110
bool IsTabDecimalPortion() const
Definition: porlin.hxx:124
bool InHyphGrp() const
Definition: porlin.hxx:105
bool IsBreakPortion() const
Definition: porlin.hxx:118
SwPosSize & operator=(SwPosSize const &)=default
#define PORGRP_TOXREF
Definition: porlin.hxx:47
#define PORGRP_FIXMARG
Definition: porlin.hxx:44
SwTwips GetHangingBaseline() const
Definition: porlin.hxx:86
bool InFixMargGrp() const
Definition: porlin.hxx:112
bool IsSoftHyphPortion() const
Definition: porlin.hxx:133
bool InGlueGrp() const
Definition: porlin.hxx:103
bool IsCombinedPortion() const
Definition: porlin.hxx:135
#define PORGRP_FLD
Definition: porlin.hxx:37
bool IsFootnoteNumPortion() const
Definition: porlin.hxx:125
void PrtWidth(SwTwips nNewWidth)
Definition: porlin.hxx:82
bool IsTabRightPortion() const
Definition: porlin.hxx:122
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:98
bool IsTabCenterPortion() const
Definition: porlin.hxx:123
SwLinePortion & operator=(const SwLinePortion &rPortion)
Definition: porlin.hxx:185
bool IsFlyPortion() const
Definition: porlin.hxx:131
PortionType mnWhichPor
Definition: porlin.hxx:63
bool IsKernPortion() const
Definition: porlin.hxx:138
bool IsNumberPortion() const
Definition: porlin.hxx:141
SwTwips mnAscent
Definition: porlin.hxx:58
void SetJoinBorderWithNext(const bool bJoinNext)
Definition: porlin.hxx:177
#define PORGRP_NUMBER
Definition: porlin.hxx:39
PortionType
Definition: txttypes.hxx:23
bool IsTabLeftPortion() const
Definition: porlin.hxx:121
bool IsDropPortion() const
Definition: porlin.hxx:127
TextFrameIndex GetLen() const
Definition: porlin.hxx:76
#define PORGRP_GLUE
Definition: porlin.hxx:40
bool m_bJoinBorderWithPrev
Definition: porlin.hxx:64
bool InTabGrp() const
Definition: porlin.hxx:104
tools::Long SwTwips
Definition: swtypes.hxx:51
bool IsHolePortion() const
Definition: porlin.hxx:132
bool m_bJoinBorderWithNext
Definition: porlin.hxx:65
SwTwips & GetAscent()
Definition: porlin.hxx:79
void Truncate()
Definition: porlin.hxx:209
SwLinePortion * mpNextPortion
Definition: porlin.hxx:55
bool IsMultiPortion() const
Definition: porlin.hxx:140
#define PORGRP_HYPH
Definition: porlin.hxx:38
Base class for anything that can be part of a line in the Writer layout.
Definition: porlin.hxx:51
TextFrameIndex mnLineLength
Definition: porlin.hxx:57
bool InExpGrp() const
Definition: porlin.hxx:111
SwTwips Width() const
Definition: possiz.hxx:51
SwTwips GetAscent() const
Definition: porlin.hxx:80
PortionType GetWhichPor() const
Definition: porlin.hxx:99
bool IsFootnotePortion() const
Definition: porlin.hxx:126
bool IsErgoSumPortion() const
Definition: porlin.hxx:119
#define PORGRP_TAB
Definition: porlin.hxx:42
void AddPrtWidth(const SwTwips nNew)
Definition: porlin.hxx:84
bool InTextGrp() const
Definition: porlin.hxx:102
void SetNextPortion(SwLinePortion *pNew)
Definition: porlin.hxx:78
struct _xmlTextWriter * xmlTextWriterPtr
bool IsArrowPortion() const
Definition: porlin.hxx:139
void SubPrtWidth(const SwTwips nNew)
Definition: porlin.hxx:85
bool IsQuoVadisPortion() const
Definition: porlin.hxx:120
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:175
SwLinePortion * GetNextPortion() const
Definition: porlin.hxx:74
bool InFixGrp() const
Definition: porlin.hxx:107
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
float GetTextSize(std::u16string_view sValue)
void SetHangingBaseline(const SwTwips nNewBaseline)
Definition: porlin.hxx:87
bool IsFlyCntPortion() const
Definition: porlin.hxx:116
bool IsPostItsPortion() const
Definition: porlin.hxx:134
SwTwips mnHangingBaseline
Definition: porlin.hxx:59
void SetAscent(const SwTwips nNewAsc)
Definition: porlin.hxx:81
bool IsBlankPortion() const
Definition: porlin.hxx:117