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>
27 #include <swporlayoutcontext.hxx>
30 class SwTextPaintInfo
;
31 class SwTextFormatInfo
;
32 class SwPortionHandler
;
34 /// Base class for anything that can be part of a line in the Writer layout.
35 /// Typically owned by SwLineLayout.
36 class SAL_DLLPUBLIC_RTTI SwLinePortion
: public SwPosSize
39 // Here we have areas with different attributes
40 SwLinePortion
*mpNextPortion
;
41 // Count of chars and spaces on the line
42 TextFrameIndex mnLineLength
;
43 SwTwips mnAscent
; // Maximum ascender
44 SwTwips mnHangingBaseline
;
48 PortionType mnWhichPor
; // Who's who?
49 bool m_bJoinBorderWithPrev
;
50 bool m_bJoinBorderWithNext
;
51 bool m_bIsFieldmarkText
;
52 SwTwips m_nExtraBlankWidth
= 0; // width of spaces after the break
53 SwTwips m_nExtraShrunkWidth
= 0; // width of not shrunk line
55 std::optional
<SwLinePortionLayoutContext
> m_nLayoutContext
;
60 explicit inline SwLinePortion(const SwLinePortion
&rPortion
);
61 virtual ~SwLinePortion();
64 SwLinePortion
*GetNextPortion() const { return mpNextPortion
; }
65 inline SwLinePortion
&operator=(const SwLinePortion
&rPortion
);
66 TextFrameIndex
GetLen() const { return mnLineLength
; }
67 void SetLen(TextFrameIndex
const nLen
) { mnLineLength
= nLen
; }
68 void SetNextPortion( SwLinePortion
*pNew
){ mpNextPortion
= pNew
; }
69 SwTwips
&GetAscent() { return mnAscent
; }
70 SwTwips
GetAscent() const { return mnAscent
; }
71 void SetAscent( const SwTwips nNewAsc
) { mnAscent
= nNewAsc
; }
72 void PrtWidth( SwTwips nNewWidth
) { Width( nNewWidth
); }
73 SwTwips
PrtWidth() const { return Width(); }
74 void AddPrtWidth( const SwTwips nNew
) { Width( Width() + nNew
); }
75 void SubPrtWidth( const SwTwips nNew
) { Width( Width() - nNew
); }
76 SwTwips
ExtraBlankWidth() const { return m_nExtraBlankWidth
; }
77 void ExtraBlankWidth(const SwTwips nNew
) { m_nExtraBlankWidth
= nNew
; }
78 SwTwips
ExtraShrunkWidth() const { return m_nExtraShrunkWidth
; }
79 void ExtraShrunkWidth(const SwTwips nNew
) { m_nExtraShrunkWidth
= nNew
; }
80 SwTwips
GetHangingBaseline() const { return mnHangingBaseline
; }
81 void SetHangingBaseline( const SwTwips nNewBaseline
) { mnHangingBaseline
= nNewBaseline
; }
82 const std::optional
<SwLinePortionLayoutContext
> & GetLayoutContext() const { return m_nLayoutContext
; }
83 void SetLayoutContext(std::optional
<SwLinePortionLayoutContext
> nNew
)
85 m_nLayoutContext
= nNew
;
89 virtual SwLinePortion
*Insert( SwLinePortion
*pPortion
);
90 virtual SwLinePortion
*Append( SwLinePortion
*pPortion
);
91 SwLinePortion
*Cut( SwLinePortion
*pVictim
);
92 inline void Truncate();
94 // Returns 0, if there's no payload
95 virtual SwLinePortion
*Compress();
97 void SetWhichPor( const PortionType nNew
) { mnWhichPor
= nNew
; }
98 PortionType
GetWhichPor( ) const { return mnWhichPor
; }
101 bool InTextGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TXT
) != 0; }
102 bool InGlueGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_GLUE
) != 0; }
103 bool InTabGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TAB
) != 0; }
104 bool InHyphGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_HYPH
) != 0; }
105 bool InNumberGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_NUMBER
) != 0; }
106 bool InFixGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FIX
) != 0; }
107 bool InFieldGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FLD
) != 0; }
108 bool InToxRefGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_TOXREF
) != 0; }
109 bool InToxRefOrFieldGrp() const { return (sal_uInt16(mnWhichPor
) & ( PORGRP_FLD
| PORGRP_TOXREF
)) != 0; }
110 bool InExpGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_EXP
) != 0; }
111 bool InFixMargGrp() const { return (sal_uInt16(mnWhichPor
) & PORGRP_FIXMARG
) != 0; }
112 bool InSpaceGrp() const { return InTextGrp() || IsMultiPortion(); }
113 // Individual queries
114 bool IsGrfNumPortion() const { return mnWhichPor
== PortionType::GrfNum
; }
115 bool IsFlyCntPortion() const { return mnWhichPor
== PortionType::FlyCnt
; }
116 bool IsBlankPortion() const { return mnWhichPor
== PortionType::Blank
; }
117 bool IsBreakPortion() const { return mnWhichPor
== PortionType::Break
; }
118 bool IsErgoSumPortion() const { return mnWhichPor
== PortionType::ErgoSum
; }
119 bool IsQuoVadisPortion() const { return mnWhichPor
== PortionType::QuoVadis
; }
120 bool IsTabLeftPortion() const { return mnWhichPor
== PortionType::TabLeft
; }
121 bool IsTabRightPortion() const { return mnWhichPor
== PortionType::TabRight
; }
122 bool IsTabCenterPortion() const { return mnWhichPor
== PortionType::TabCenter
; }
123 bool IsTabDecimalPortion() const { return mnWhichPor
== PortionType::TabDecimal
; }
124 bool IsFootnoteNumPortion() const { return mnWhichPor
== PortionType::FootnoteNum
; }
125 bool IsFootnotePortion() const { return mnWhichPor
== PortionType::Footnote
; }
126 bool IsDropPortion() const { return mnWhichPor
== PortionType::Drop
; }
127 bool IsLayPortion() const { return mnWhichPor
== PortionType::Lay
; }
128 bool IsParaPortion() const { return mnWhichPor
== PortionType::Para
; }
129 bool IsMarginPortion() const { return mnWhichPor
== PortionType::Margin
; }
130 bool IsFlyPortion() const { return mnWhichPor
== PortionType::Fly
; }
131 bool IsHolePortion() const { return mnWhichPor
== PortionType::Hole
; }
132 bool IsSoftHyphPortion() const { return mnWhichPor
== PortionType::SoftHyphen
; }
133 bool IsPostItsPortion() const { return mnWhichPor
== PortionType::PostIts
; }
134 bool IsCombinedPortion() const { return mnWhichPor
== PortionType::Combined
; }
135 bool IsTextPortion() const { return mnWhichPor
== PortionType::Text
; }
136 bool IsHangingPortion() const { return mnWhichPor
== PortionType::Hanging
; }
137 bool IsKernPortion() const { return mnWhichPor
== PortionType::Kern
; }
138 bool IsArrowPortion() const { return mnWhichPor
== PortionType::Arrow
; }
139 bool IsMultiPortion() const { return mnWhichPor
== PortionType::Multi
; }
140 bool IsNumberPortion() const { return mnWhichPor
== PortionType::Number
; } // #i23726#
141 bool IsControlCharPortion() const { return mnWhichPor
== PortionType::ControlChar
|| mnWhichPor
== PortionType::Bookmark
; }
144 SwLinePortion
*FindPrevPortion( const SwLinePortion
*pRoot
);
145 SwLinePortion
*FindLastPortion();
147 virtual TextFrameIndex
GetModelPositionForViewPoint(SwTwips nOfst
) const;
148 virtual SwPosSize
GetTextSize( const SwTextSizeInfo
&rInfo
) const;
149 void CalcTextSize( const SwTextSizeInfo
&rInfo
);
152 virtual void Paint( const SwTextPaintInfo
&rInf
) const = 0;
153 void PrePaint( const SwTextPaintInfo
&rInf
, const SwLinePortion
*pLast
) const;
155 virtual bool Format( SwTextFormatInfo
&rInf
);
156 // Is called for the line's last portion
157 virtual void FormatEOL( SwTextFormatInfo
&rInf
);
158 void Move(SwTextPaintInfo
& rInf
) const;
161 virtual bool GetExpText( const SwTextSizeInfo
&rInf
, OUString
&rText
) const;
163 // For SwFieldPortion, SwSoftHyphPortion
164 virtual SwTwips
GetViewWidth(const SwTextSizeInfo
& rInf
) const;
166 // for text- and multi-portions
167 virtual SwTwips
CalcSpacing( tools::Long nSpaceAdd
, const SwTextSizeInfo
&rInf
) const;
169 // Accessibility: pass information about this portion to the PortionHandler
170 virtual void HandlePortion( SwPortionHandler
& rPH
) const;
172 bool GetJoinBorderWithPrev() const { return m_bJoinBorderWithPrev
; }
173 bool GetJoinBorderWithNext() const { return m_bJoinBorderWithNext
; }
174 bool IsFieldmarkText() const {return m_bIsFieldmarkText
;}
175 void SetJoinBorderWithPrev( const bool bJoinPrev
) { m_bJoinBorderWithPrev
= bJoinPrev
; }
176 void SetJoinBorderWithNext( const bool bJoinNext
) { m_bJoinBorderWithNext
= bJoinNext
; }
177 void SetFieldmarkText(bool bSet
) { m_bIsFieldmarkText
= bSet
; }
179 virtual void dumpAsXml(xmlTextWriterPtr pWriter
, const OUString
& rText
,
180 TextFrameIndex
& rOffset
) const;
181 void dumpAsXmlAttributes(xmlTextWriterPtr writer
, std::u16string_view rText
,
182 TextFrameIndex nOffset
) const;
185 inline SwLinePortion
&SwLinePortion::operator=(const SwLinePortion
&rPortion
)
187 *static_cast<SwPosSize
*>(this) = rPortion
;
188 mnLineLength
= rPortion
.mnLineLength
;
189 mnAscent
= rPortion
.mnAscent
;
190 mnHangingBaseline
= rPortion
.mnHangingBaseline
;
191 mnWhichPor
= rPortion
.mnWhichPor
;
192 m_bJoinBorderWithPrev
= rPortion
.m_bJoinBorderWithPrev
;
193 m_bJoinBorderWithNext
= rPortion
.m_bJoinBorderWithNext
;
194 m_nExtraBlankWidth
= rPortion
.m_nExtraBlankWidth
;
195 m_nExtraShrunkWidth
= rPortion
.m_nExtraShrunkWidth
;
196 m_nLayoutContext
= rPortion
.m_nLayoutContext
;
200 inline SwLinePortion::SwLinePortion(const SwLinePortion
&rPortion
) :
201 SwPosSize( rPortion
),
202 mpNextPortion( nullptr ),
203 mnLineLength( rPortion
.mnLineLength
),
204 mnAscent( rPortion
.mnAscent
),
205 mnHangingBaseline( rPortion
.mnHangingBaseline
),
206 mnWhichPor( rPortion
.mnWhichPor
),
207 m_bJoinBorderWithPrev( rPortion
.m_bJoinBorderWithPrev
),
208 m_bJoinBorderWithNext( rPortion
.m_bJoinBorderWithNext
),
209 m_bIsFieldmarkText( rPortion
.m_bIsFieldmarkText
),
210 m_nExtraBlankWidth(rPortion
.m_nExtraBlankWidth
),
211 m_nExtraShrunkWidth(rPortion
.m_nExtraShrunkWidth
),
212 m_nLayoutContext(rPortion
.m_nLayoutContext
)
216 inline void SwLinePortion::Truncate()
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */