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