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