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