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 "possiz.hxx"
22 #include <txttypes.hxx>
23 #include <TextFrameIndex.hxx>
24 #include <rtl/ustring.hxx>
25 
26 class SwTextSizeInfo;
27 class SwTextPaintInfo;
28 class SwTextFormatInfo;
29 class SwPortionHandler;
30 
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_uInt32 mnAscent; // Maximum ascender
57 
58  SwLinePortion();
59 private:
60  PortionType mnWhichPor; // 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 mnLineLength; }
74  void SetLen(TextFrameIndex const nLen) { mnLineLength = nLen; }
75  void SetNextPortion( SwLinePortion *pNew ){ mpNextPortion = pNew; }
76  sal_uInt32 &GetAscent() { return mnAscent; }
77  sal_uInt32 GetAscent() const { return mnAscent; }
78  void SetAscent( const sal_uInt32 nNewAsc ) { mnAscent = nNewAsc; }
79  void PrtWidth( sal_uInt16 nNewWidth ) { Width( nNewWidth ); }
80  sal_uInt32 PrtWidth() const { return Width(); }
81  void AddPrtWidth( const sal_uInt32 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 ) { mnWhichPor = nNew; }
94  PortionType GetWhichPor( ) const { return mnWhichPor; }
95 
96 // Group queries
97  bool InTextGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TXT) != 0; }
98  bool InGlueGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_GLUE) != 0; }
99  bool InTabGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TAB) != 0; }
100  bool InHyphGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_HYPH) != 0; }
101  bool InNumberGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_NUMBER) != 0; }
102  bool InFixGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIX) != 0; }
103  bool InFieldGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FLD) != 0; }
104  bool InToxRefGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_TOXREF) != 0; }
105  bool InToxRefOrFieldGrp() const { return (sal_uInt16(mnWhichPor) & ( PORGRP_FLD | PORGRP_TOXREF )) != 0; }
106  bool InExpGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_EXP) != 0; }
107  bool InFixMargGrp() const { return (sal_uInt16(mnWhichPor) & PORGRP_FIXMARG) != 0; }
108  bool InSpaceGrp() const { return InTextGrp() || IsMultiPortion(); }
109 // Individual queries
110  bool IsGrfNumPortion() const { return mnWhichPor == PortionType::GrfNum; }
111  bool IsFlyCntPortion() const { return mnWhichPor == PortionType::FlyCnt; }
112  bool IsBlankPortion() const { return mnWhichPor == PortionType::Blank; }
113  bool IsBreakPortion() const { return mnWhichPor == PortionType::Break; }
114  bool IsErgoSumPortion() const { return mnWhichPor == PortionType::ErgoSum; }
115  bool IsQuoVadisPortion() const { return mnWhichPor == PortionType::QuoVadis; }
116  bool IsTabLeftPortion() const { return mnWhichPor == PortionType::TabLeft; }
117  bool IsTabRightPortion() const { return mnWhichPor == PortionType::TabRight; }
118  bool IsTabCenterPortion() const { return mnWhichPor == PortionType::TabCenter; }
119  bool IsTabDecimalPortion() const { return mnWhichPor == PortionType::TabDecimal; }
120  bool IsFootnoteNumPortion() const { return mnWhichPor == PortionType::FootnoteNum; }
121  bool IsFootnotePortion() const { return mnWhichPor == PortionType::Footnote; }
122  bool IsDropPortion() const { return mnWhichPor == PortionType::Drop; }
123  bool IsLayPortion() const { return mnWhichPor == PortionType::Lay; }
124  bool IsParaPortion() const { return mnWhichPor == PortionType::Para; }
125  bool IsMarginPortion() const { return mnWhichPor == PortionType::Margin; }
126  bool IsFlyPortion() const { return mnWhichPor == PortionType::Fly; }
127  bool IsHolePortion() const { return mnWhichPor == PortionType::Hole; }
128  bool IsSoftHyphPortion() const { return mnWhichPor == PortionType::SoftHyphen; }
129  bool IsPostItsPortion() const { return mnWhichPor == PortionType::PostIts; }
130  bool IsCombinedPortion() const { return mnWhichPor == PortionType::Combined; }
131  bool IsTextPortion() const { return mnWhichPor == PortionType::Text; }
132  bool IsHangingPortion() const { return mnWhichPor == PortionType::Hanging; }
133  bool IsKernPortion() const { return mnWhichPor == PortionType::Kern; }
134  bool IsArrowPortion() const { return mnWhichPor == PortionType::Arrow; }
135  bool IsMultiPortion() const { return mnWhichPor == PortionType::Multi; }
136  bool IsNumberPortion() const { return mnWhichPor == PortionType::Number; } // #i23726#
137  bool IsControlCharPortion() const { return mnWhichPor == PortionType::ControlChar || mnWhichPor == PortionType::Bookmark; }
138 
139  // Positioning
142 
144  virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const;
145  virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const;
146  void CalcTextSize( const SwTextSizeInfo &rInfo );
147 
148  // Output
149  virtual void Paint( const SwTextPaintInfo &rInf ) const = 0;
150  void PrePaint( const SwTextPaintInfo &rInf, const SwLinePortion *pLast ) const;
151 
152  virtual bool Format( SwTextFormatInfo &rInf );
153  // Is called for the line's last portion
154  virtual void FormatEOL( SwTextFormatInfo &rInf );
155  void Move( SwTextPaintInfo &rInf );
156 
157  // For SwTextSlot
158  virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const;
159 
160  // For SwFieldPortion, SwSoftHyphPortion
161  virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const;
162 
163  // for text- and multi-portions
164  virtual tools::Long CalcSpacing( tools::Long nSpaceAdd, const SwTextSizeInfo &rInf ) const;
165 
166  // Accessibility: pass information about this portion to the PortionHandler
167  virtual void HandlePortion( SwPortionHandler& rPH ) const;
168 
171  void SetJoinBorderWithPrev( const bool bJoinPrev ) { m_bJoinBorderWithPrev = bJoinPrev; }
172  void SetJoinBorderWithNext( const bool bJoinNext ) { m_bJoinBorderWithNext = bJoinNext; }
173 };
174 
176 {
177  *static_cast<SwPosSize*>(this) = rPortion;
178  mnLineLength = rPortion.mnLineLength;
179  mnAscent = rPortion.mnAscent;
180  mnWhichPor = rPortion.mnWhichPor;
183  return *this;
184 }
185 
187  SwPosSize( rPortion ),
188  mpNextPortion( nullptr ),
189  mnLineLength( rPortion.mnLineLength ),
190  mnAscent( rPortion.mnAscent ),
191  mnWhichPor( rPortion.mnWhichPor ),
192  m_bJoinBorderWithPrev( rPortion.m_bJoinBorderWithPrev ),
193  m_bJoinBorderWithNext( rPortion.m_bJoinBorderWithNext )
194 {
195 }
196 
198 {
199  if ( mpNextPortion )
200  Truncate_();
201 }
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool Format(SwTextFormatInfo &rInf)
Definition: porlin.cxx:237
void Move(SwTextPaintInfo &rInf)
Definition: porlin.cxx:268
#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
virtual tools::Long CalcSpacing(tools::Long nSpaceAdd, const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:305
#define PORGRP_TXT
Portion groups.
Definition: porlin.hxx:33
bool IsTextPortion() const
Definition: porlin.hxx:131
void Truncate_()
Definition: porlin.cxx:151
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:169
void CalcTextSize(const SwTextSizeInfo &rInfo)
Definition: porlin.cxx:138
long Long
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:132
void SetJoinBorderWithPrev(const bool bJoinPrev)
Definition: porlin.hxx:171
bool InFieldGrp() const
Definition: porlin.hxx:103
bool IsParaPortion() const
Definition: porlin.hxx:124
virtual SwLinePortion * Compress()
Definition: porlin.cxx:56
bool IsControlCharPortion() const
Definition: porlin.hxx:137
bool IsLayPortion() const
Definition: porlin.hxx:123
bool IsMarginPortion() const
Definition: porlin.hxx:125
bool InToxRefOrFieldGrp() const
Definition: porlin.hxx:105
bool IsTabDecimalPortion() const
Definition: porlin.hxx:119
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
void SetAscent(const sal_uInt32 nNewAsc)
Definition: porlin.hxx:78
bool InFixMargGrp() const
Definition: porlin.hxx:107
bool IsSoftHyphPortion() const
Definition: porlin.hxx:128
bool InGlueGrp() const
Definition: porlin.hxx:98
bool IsCombinedPortion() const
Definition: porlin.hxx:130
#define PORGRP_FLD
Definition: porlin.hxx:35
bool IsFootnoteNumPortion() const
Definition: porlin.hxx:120
virtual SwLinePortion * Append(SwLinePortion *pPortion)
Definition: porlin.cxx:189
virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const
the parameter is actually SwTwips apparently?
Definition: porlin.cxx:222
void AddPrtWidth(const sal_uInt32 nNew)
Definition: porlin.hxx:81
virtual sal_uInt16 GetViewWidth(const SwTextSizeInfo &rInf) const
Definition: porlin.cxx:61
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const
Definition: porlin.cxx:310
bool IsTabRightPortion() const
Definition: porlin.hxx:117
void SetWhichPor(const PortionType nNew)
Definition: porlin.hxx:93
bool IsTabCenterPortion() const
Definition: porlin.hxx:118
SwLinePortion & operator=(const SwLinePortion &rPortion)
Definition: porlin.hxx:175
bool IsFlyPortion() const
Definition: porlin.hxx:126
PortionType mnWhichPor
Definition: porlin.hxx:60
bool IsKernPortion() const
Definition: porlin.hxx:133
bool IsNumberPortion() const
Definition: porlin.hxx:136
virtual void HandlePortion(SwPortionHandler &rPH) const
Definition: porlin.cxx:315
void SetJoinBorderWithNext(const bool bJoinNext)
Definition: porlin.hxx:172
#define PORGRP_NUMBER
Definition: porlin.hxx:37
PortionType
Definition: txttypes.hxx:23
bool IsTabLeftPortion() const
Definition: porlin.hxx:116
bool IsDropPortion() const
Definition: porlin.hxx:122
sal_uInt32 GetAscent() const
Definition: porlin.hxx:77
void PrePaint(const SwTextPaintInfo &rInf, const SwLinePortion *pLast) const
Definition: porlin.cxx:76
SwLinePortion * Cut(SwLinePortion *pVictim)
Definition: porlin.cxx:200
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:127
bool m_bJoinBorderWithNext
Definition: porlin.hxx:62
void Truncate()
Definition: porlin.hxx:197
SwLinePortion * mpNextPortion
Definition: porlin.hxx:53
bool IsMultiPortion() const
Definition: porlin.hxx:135
virtual ~SwLinePortion()
Definition: porlin.cxx:52
sal_uInt32 mnAscent
Definition: porlin.hxx:56
#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
TextFrameIndex mnLineLength
Definition: porlin.hxx:55
bool InExpGrp() const
Definition: porlin.hxx:106
PortionType GetWhichPor() const
Definition: porlin.hxx:94
bool IsFootnotePortion() const
Definition: porlin.hxx:121
SwLinePortion * FindLastPortion()
Definition: porlin.cxx:178
bool IsErgoSumPortion() const
Definition: porlin.hxx:114
#define PORGRP_TAB
Definition: porlin.hxx:40
virtual SwPosSize GetTextSize(const SwTextSizeInfo &rInfo) const
Definition: porlin.cxx:230
SwLinePortion * FindPrevPortion(const SwLinePortion *pRoot)
Definition: porlin.cxx:209
bool InTextGrp() const
Definition: porlin.hxx:97
void SetNextPortion(SwLinePortion *pNew)
Definition: porlin.hxx:75
bool IsArrowPortion() const
Definition: porlin.hxx:134
sal_uInt32 & GetAscent()
Definition: porlin.hxx:76
void PrtWidth(sal_uInt16 nNewWidth)
Definition: porlin.hxx:79
virtual void FormatEOL(SwTextFormatInfo &rInf)
Definition: porlin.cxx:265
bool IsQuoVadisPortion() const
Definition: porlin.hxx:115
void SubPrtWidth(const sal_uInt16 nNew)
Definition: porlin.hxx:82
sal_uInt32 Width() const
Definition: possiz.hxx:51
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:170
SwLinePortion * GetNextPortion() const
Definition: porlin.hxx:71
bool InFixGrp() const
Definition: porlin.hxx:102
bool IsFlyCntPortion() const
Definition: porlin.hxx:111
virtual SwLinePortion * Insert(SwLinePortion *pPortion)
Definition: porlin.cxx:168
bool IsPostItsPortion() const
Definition: porlin.hxx:129
sal_uInt32 PrtWidth() const
Definition: porlin.hxx:80
bool IsBlankPortion() const
Definition: porlin.hxx:112