1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <libxml/xmlwriter.h>
24 #include <txttypes.hxx>
25 #include <TextFrameIndex.hxx>
26 #include <rtl/ustring.hxx>
29 class SwTextPaintInfo
;
30 class SwTextFormatInfo
;
31 class SwPortionHandler
;
34 /// @see enum PortionType in txttypes.hxx
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
49 /// Base class for anything that can be part of a line in the Writer layout.
50 /// Typically owned by SwLineLayout.
51 class SAL_DLLPUBLIC_RTTI SwLinePortion
: public SwPosSize
54 // Here we have areas with different attributes
55 SwLinePortion
*mpNextPortion
;
56 // Count of chars and spaces on the line
57 TextFrameIndex mnLineLength
;
58 SwTwips mnAscent
; // Maximum ascender
59 SwTwips mnHangingBaseline
;
63 PortionType mnWhichPor
; // Who's who?
64 bool m_bJoinBorderWithPrev
;
65 bool m_bJoinBorderWithNext
;
66 SwTwips m_nExtraBlankWidth
= 0; // width of spaces after the break
71 explicit inline SwLinePortion(const SwLinePortion
&rPortion
);
72 virtual ~SwLinePortion();
75 SwLinePortion
*GetNextPortion() const { return mpNextPortion
; }
76 inline SwLinePortion
&operator=(const SwLinePortion
&rPortion
);
77 TextFrameIndex
GetLen() const { return mnLineLength
; }
78 void SetLen(TextFrameIndex
const nLen
) { mnLineLength
= nLen
; }
79 void SetNextPortion( SwLinePortion
*pNew
){ mpNextPortion
= pNew
; }
80 SwTwips
&GetAscent() { return mnAscent
; }
81 SwTwips
GetAscent() const { return mnAscent
; }
82 void SetAscent( const SwTwips nNewAsc
) { mnAscent
= nNewAsc
; }
83 void PrtWidth( SwTwips nNewWidth
) { Width( nNewWidth
); }
84 SwTwips
PrtWidth() const { return Width(); }
85 void AddPrtWidth( const SwTwips nNew
) { Width( Width() + nNew
); }
86 void SubPrtWidth( const SwTwips nNew
) { Width( Width() - nNew
); }
87 SwTwips
ExtraBlankWidth() const { return m_nExtraBlankWidth
; }
88 void ExtraBlankWidth(const SwTwips nNew
) { m_nExtraBlankWidth
= nNew
; }
89 SwTwips
GetHangingBaseline() const { return mnHangingBaseline
; }
90 void SetHangingBaseline( const SwTwips nNewBaseline
) { mnHangingBaseline
= nNewBaseline
; }
93 virtual SwLinePortion
*Insert( SwLinePortion
*pPortion
);
94 virtual SwLinePortion
*Append( SwLinePortion
*pPortion
);
95 SwLinePortion
*Cut( SwLinePortion
*pVictim
);
96 inline void Truncate();
98 // Returns 0, if there's no payload
99 virtual SwLinePortion
*Compress();
101 void SetWhichPor( const PortionType nNew
) { mnWhichPor
= nNew
; }
102 PortionType
GetWhichPor( ) const { return mnWhichPor
; }
105 bool InTextGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TXT
) != 0; }
106 bool InGlueGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_GLUE
) != 0; }
107 bool InTabGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TAB
) != 0; }
108 bool InHyphGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_HYPH
) != 0; }
109 bool InNumberGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_NUMBER
) != 0; }
110 bool InFixGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FIX
) != 0; }
111 bool InFieldGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FLD
) != 0; }
112 bool InToxRefGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TOXREF
) != 0; }
113 bool InToxRefOrFieldGrp() const { return (sal_uInt16(mnWhichPor
) & ( PORGRP_FLD
| PORGRP_TOXREF
)) != 0; }
114 bool InExpGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_EXP
) != 0; }
115 bool InFixMargGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FIXMARG
) != 0; }
116 bool InSpaceGrp() const { return InTextGrp() || IsMultiPortion(); }
117 // Individual queries
118 bool IsGrfNumPortion() const { return mnWhichPor
== PortionType::GrfNum
; }
119 bool IsFlyCntPortion() const { return mnWhichPor
== PortionType::FlyCnt
; }
120 bool IsBlankPortion() const { return mnWhichPor
== PortionType::Blank
; }
121 bool IsBreakPortion() const { return mnWhichPor
== PortionType::Break
; }
122 bool IsErgoSumPortion() const { return mnWhichPor
== PortionType::ErgoSum
; }
123 bool IsQuoVadisPortion() const { return mnWhichPor
== PortionType::QuoVadis
; }
124 bool IsTabLeftPortion() const { return mnWhichPor
== PortionType::TabLeft
; }
125 bool IsTabRightPortion() const { return mnWhichPor
== PortionType::TabRight
; }
126 bool IsTabCenterPortion() const { return mnWhichPor
== PortionType::TabCenter
; }
127 bool IsTabDecimalPortion() const { return mnWhichPor
== PortionType::TabDecimal
; }
128 bool IsFootnoteNumPortion() const { return mnWhichPor
== PortionType::FootnoteNum
; }
129 bool IsFootnotePortion() const { return mnWhichPor
== PortionType::Footnote
; }
130 bool IsDropPortion() const { return mnWhichPor
== PortionType::Drop
; }
131 bool IsLayPortion() const { return mnWhichPor
== PortionType::Lay
; }
132 bool IsParaPortion() const { return mnWhichPor
== PortionType::Para
; }
133 bool IsMarginPortion() const { return mnWhichPor
== PortionType::Margin
; }
134 bool IsFlyPortion() const { return mnWhichPor
== PortionType::Fly
; }
135 bool IsHolePortion() const { return mnWhichPor
== PortionType::Hole
; }
136 bool IsSoftHyphPortion() const { return mnWhichPor
== PortionType::SoftHyphen
; }
137 bool IsPostItsPortion() const { return mnWhichPor
== PortionType::PostIts
; }
138 bool IsCombinedPortion() const { return mnWhichPor
== PortionType::Combined
; }
139 bool IsTextPortion() const { return mnWhichPor
== PortionType::Text
; }
140 bool IsHangingPortion() const { return mnWhichPor
== PortionType::Hanging
; }
141 bool IsKernPortion() const { return mnWhichPor
== PortionType::Kern
; }
142 bool IsArrowPortion() const { return mnWhichPor
== PortionType::Arrow
; }
143 bool IsMultiPortion() const { return mnWhichPor
== PortionType::Multi
; }
144 bool IsNumberPortion() const { return mnWhichPor
== PortionType::Number
; } // #i23726#
145 bool IsControlCharPortion() const { return mnWhichPor
== PortionType::ControlChar
|| mnWhichPor
== PortionType::Bookmark
; }
148 SwLinePortion
*FindPrevPortion( const SwLinePortion
*pRoot
);
149 SwLinePortion
*FindLastPortion();
151 /// the parameter is actually SwTwips apparently?
152 virtual TextFrameIndex
GetModelPositionForViewPoint(sal_uInt16 nOfst
) const;
153 virtual SwPosSize
GetTextSize( const SwTextSizeInfo
&rInfo
) const;
154 void CalcTextSize( const SwTextSizeInfo
&rInfo
);
157 virtual void Paint( const SwTextPaintInfo
&rInf
) const = 0;
158 void PrePaint( const SwTextPaintInfo
&rInf
, const SwLinePortion
*pLast
) const;
160 virtual bool Format( SwTextFormatInfo
&rInf
);
161 // Is called for the line's last portion
162 virtual void FormatEOL( SwTextFormatInfo
&rInf
);
163 void Move( SwTextPaintInfo
&rInf
);
166 virtual bool GetExpText( const SwTextSizeInfo
&rInf
, OUString
&rText
) const;
168 // For SwFieldPortion, SwSoftHyphPortion
169 virtual sal_uInt16
GetViewWidth( const SwTextSizeInfo
&rInf
) const;
171 // for text- and multi-portions
172 virtual tools::Long
CalcSpacing( tools::Long nSpaceAdd
, const SwTextSizeInfo
&rInf
) const;
174 // Accessibility: pass information about this portion to the PortionHandler
175 virtual void HandlePortion( SwPortionHandler
& rPH
) const;
177 bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev
; }
178 bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext
; }
179 void SetJoinBorderWithPrev( const bool bJoinPrev
) { m_bJoinBorderWithPrev
= bJoinPrev
; }
180 void SetJoinBorderWithNext( const bool bJoinNext
) { m_bJoinBorderWithNext
= bJoinNext
; }
182 virtual void dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
183 TextFrameIndex
& rOffset
) const;
184 void dumpAsXmlAttributes(xmlTextWriterPtr writer
, std::u16string_view rText
,
185 TextFrameIndex nOffset
) const;
188 inline SwLinePortion
&SwLinePortion::operator=(const SwLinePortion
&rPortion
)
190 *static_cast<SwPosSize
*>(this) = rPortion
;
191 mnLineLength
= rPortion
.mnLineLength
;
192 mnAscent
= rPortion
.mnAscent
;
193 mnHangingBaseline
= rPortion
.mnHangingBaseline
;
194 mnWhichPor
= rPortion
.mnWhichPor
;
195 m_bJoinBorderWithPrev
= rPortion
.m_bJoinBorderWithPrev
;
196 m_bJoinBorderWithNext
= rPortion
.m_bJoinBorderWithNext
;
197 m_nExtraBlankWidth
= rPortion
.m_nExtraBlankWidth
;
201 inline SwLinePortion::SwLinePortion(const SwLinePortion
&rPortion
) :
202 SwPosSize( rPortion
),
203 mpNextPortion( nullptr ),
204 mnLineLength( rPortion
.mnLineLength
),
205 mnAscent( rPortion
.mnAscent
),
206 mnHangingBaseline( rPortion
.mnHangingBaseline
),
207 mnWhichPor( rPortion
.mnWhichPor
),
208 m_bJoinBorderWithPrev( rPortion
.m_bJoinBorderWithPrev
),
209 m_bJoinBorderWithNext( rPortion
.m_bJoinBorderWithNext
),
210 m_nExtraBlankWidth(rPortion
.m_nExtraBlankWidth
)
214 inline void SwLinePortion::Truncate()
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */