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 20 #pragma once 21 22 #include <sal/config.h> 23 24 #include <string_view> 25 26 #include <swtypes.hxx> 27 #include <swfont.hxx> 28 #include "porexp.hxx" 29 #include <o3tl/enumarray.hxx> 30 31 class SvxBrushItem; 32 class SwFormatVertOrient; 33 34 class SwFieldPortion : public SwExpandPortion 35 { 36 friend class SwTextFormatter; 37 protected: 38 OUString m_aExpand; // The expanded field 39 std::unique_ptr<SwFont> m_pFont; // For multi-line fields 40 TextFrameIndex m_nNextOffset; // Offset of the follow in the original string 41 TextFrameIndex m_nNextScriptChg; 42 TextFrameIndex m_nFieldLen; //< Length of field text, 1 for normal fields, any number for input fields 43 // TODO ^ do we need this as member or is base class len enough? 44 sal_uInt16 m_nViewWidth; // Screen width for empty fields 45 bool m_bFollow : 1; // 2nd or later part of a field 46 bool m_bLeft : 1; // Used by SwNumberPortion 47 bool m_bHide : 1; // Used by SwNumberPortion 48 bool m_bCenter : 1; // Used by SwNumberPortion 49 bool m_bHasFollow : 1; // Continues on the next line 50 bool m_bAnimated : 1; // Used by SwGrfNumPortion 51 bool m_bNoPaint : 1; // Used by SwGrfNumPortion 52 bool m_bReplace : 1; // Used by SwGrfNumPortion 53 const bool m_bPlaceHolder : 1; 54 bool m_bNoLength : 1; // HACK for meta suffix (no CH_TXTATR) 55 SetFont(std::unique_ptr<SwFont> pNew)56 void SetFont( std::unique_ptr<SwFont> pNew ) { m_pFont = std::move(pNew); } IsNoLength() const57 bool IsNoLength() const { return m_bNoLength; } SetNoLength()58 void SetNoLength() { m_bNoLength = true; } 59 60 public: 61 SwFieldPortion( const SwFieldPortion& rField ); 62 SwFieldPortion(const OUString &rExpand, std::unique_ptr<SwFont> pFnt = nullptr, bool bPlaceHolder = false, TextFrameIndex nLen = TextFrameIndex(1)); 63 virtual ~SwFieldPortion() override; 64 65 sal_uInt16 m_nAttrFieldType; 66 void TakeNextOffset( const SwFieldPortion* pField ); 67 void CheckScript( const SwTextSizeInfo &rInf ); HasFont() const68 bool HasFont() const { return nullptr != m_pFont; } 69 // #i89179# - made public GetFont() const70 const SwFont *GetFont() const { return m_pFont.get(); } 71 GetExp() const72 const OUString& GetExp() const { return m_aExpand; } 73 virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const override; 74 virtual bool Format( SwTextFormatInfo &rInf ) override; 75 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 76 77 // Empty fields are also allowed 78 virtual SwLinePortion *Compress() override; 79 80 virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const override; 81 IsFollow() const82 bool IsFollow() const { return m_bFollow; } SetFollow(bool bNew)83 void SetFollow( bool bNew ) { m_bFollow = bNew; } 84 IsLeft() const85 bool IsLeft() const { return m_bLeft; } SetLeft(bool bNew)86 void SetLeft( bool bNew ) { m_bLeft = bNew; } 87 IsHide() const88 bool IsHide() const { return m_bHide; } SetHide(bool bNew)89 void SetHide( bool bNew ) { m_bHide = bNew; } 90 IsCenter() const91 bool IsCenter() const { return m_bCenter; } SetCenter(bool bNew)92 void SetCenter( bool bNew ) { m_bCenter = bNew; } 93 HasFollow() const94 bool HasFollow() const { return m_bHasFollow; } SetHasFollow(bool bNew)95 void SetHasFollow( bool bNew ) { m_bHasFollow = bNew; } 96 GetNextOffset() const97 TextFrameIndex GetNextOffset() const { return m_nNextOffset; } SetNextOffset(TextFrameIndex nNew)98 void SetNextOffset(TextFrameIndex nNew) { m_nNextOffset = nNew; } 99 GetFieldLen() const100 TextFrameIndex GetFieldLen() const { return m_nFieldLen; } 101 102 // Field cloner for SplitGlue 103 virtual SwFieldPortion *Clone( const OUString &rExpand ) const; 104 105 // Extra GetTextSize because of pFnt 106 virtual SwPosSize GetTextSize( const SwTextSizeInfo &rInfo ) const override; 107 108 // Accessibility: pass information about this portion to the PortionHandler 109 virtual void HandlePortion( SwPortionHandler& rPH ) const override; 110 }; 111 112 /** 113 * Distinguish only for painting/hide 114 */ 115 class SwHiddenPortion : public SwFieldPortion 116 { 117 public: SwHiddenPortion(const OUString & rExpand,std::unique_ptr<SwFont> pFntL=nullptr)118 SwHiddenPortion( const OUString &rExpand, std::unique_ptr<SwFont> pFntL = nullptr ) 119 : SwFieldPortion( rExpand, std::move(pFntL) ) 120 { SetLen(TextFrameIndex(1)); SetWhichPor( PortionType::Hidden ); } 121 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 122 virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const override; 123 124 // Field cloner for SplitGlue 125 virtual SwFieldPortion *Clone( const OUString &rExpand ) const override; 126 }; 127 128 class SwNumberPortion : public SwFieldPortion 129 { 130 protected: 131 sal_uInt16 m_nFixWidth; // See Glues 132 sal_uInt16 m_nMinDist; // Minimal distance to the text 133 bool mbLabelAlignmentPosAndSpaceModeActive; 134 135 public: 136 SwNumberPortion( const OUString &rExpand, 137 std::unique_ptr<SwFont> pFnt, 138 const bool bLeft, 139 const bool bCenter, 140 const sal_uInt16 nMinDst, 141 const bool bLabelAlignmentPosAndSpaceModeActive ); 142 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 143 virtual TextFrameIndex GetModelPositionForViewPoint(sal_uInt16 nOfst) const override; 144 virtual bool Format( SwTextFormatInfo &rInf ) override; 145 146 // Field cloner for SplitGlue 147 virtual SwFieldPortion *Clone( const OUString &rExpand ) const override; 148 virtual void FormatEOL( SwTextFormatInfo &rInf ) override; 149 }; 150 151 class SwBulletPortion : public SwNumberPortion 152 { 153 public: 154 SwBulletPortion( const sal_UCS4 cCh, 155 std::u16string_view rBulletFollowedBy, 156 std::unique_ptr<SwFont> pFnt, 157 const bool bLeft, 158 const bool bCenter, 159 const sal_uInt16 nMinDst, 160 const bool bLabelAlignmentPosAndSpaceModeActive ); 161 }; 162 163 class SwGrfNumPortion : public SwNumberPortion 164 { 165 std::unique_ptr<SvxBrushItem> m_pBrush; 166 tools::Long m_nId; // For StopAnimation 167 SwTwips m_nYPos; // _Always_ contains the current RelPos 168 SwTwips m_nGrfHeight; 169 sal_Int16 m_eOrient; 170 public: 171 SwGrfNumPortion( const OUString& rGraphicFollowedBy, 172 const SvxBrushItem* pGrfBrush, 173 OUString const & referer, 174 const SwFormatVertOrient* pGrfOrient, 175 const Size& rGrfSize, 176 const bool bLeft, 177 const bool bCenter, 178 const sal_uInt16 nMinDst, 179 const bool bLabelAlignmentPosAndSpaceModeActive ); 180 virtual ~SwGrfNumPortion() override; 181 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 182 virtual bool Format( SwTextFormatInfo &rInf ) override; 183 184 void SetBase( tools::Long nLnAscent, tools::Long nLnDescent, 185 tools::Long nFlyAscent, tools::Long nFlyDescent ); 186 187 void StopAnimation( const OutputDevice* pOut ); 188 IsAnimated() const189 bool IsAnimated() const { return m_bAnimated; } SetAnimated(bool bNew)190 void SetAnimated( bool bNew ) { m_bAnimated = bNew; } SetRelPos(SwTwips nNew)191 void SetRelPos( SwTwips nNew ) { m_nYPos = nNew; } SetId(tools::Long nNew) const192 void SetId( tools::Long nNew ) const 193 { const_cast<SwGrfNumPortion*>(this)->m_nId = nNew; } GetRelPos() const194 SwTwips GetRelPos() const { return m_nYPos; } GetGrfHeight() const195 SwTwips GetGrfHeight() const { return m_nGrfHeight; } GetOrient() const196 sal_Int16 GetOrient() const { return m_eOrient; } 197 }; 198 199 /** 200 * Used in for asian layout specialities to display up to six characters 201 * in 2 rows and 2-3 columns. 202 * E.g.: <pre> 203 * A.. A.. A.B A.B A.B.C A.B.C 204 * ... ..B .C. C.D .D.E. D.E.F 205 * </pre> 206 */ 207 class SwCombinedPortion : public SwFieldPortion 208 { 209 sal_uInt16 m_aPos[6]; // up to six X positions 210 o3tl::enumarray<SwFontScript,sal_uInt16> m_aWidth = {}; // one width for every scripttype 211 SwFontScript m_aScrType[6]; // scripttype of every character 212 sal_uInt16 m_nUpPos; // the Y position of the upper baseline 213 sal_uInt16 m_nLowPos; // the Y position of the lower baseline 214 sal_uInt8 m_nProportion; // relative font height 215 public: 216 explicit SwCombinedPortion( const OUString &rExpand ); 217 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 218 virtual bool Format( SwTextFormatInfo &rInf ) override; 219 virtual sal_uInt16 GetViewWidth( const SwTextSizeInfo &rInf ) const override; 220 }; 221 222 namespace sw::mark { class IFieldmark; } 223 224 class SwFieldFormDropDownPortion : public SwFieldPortion 225 { 226 public: SwFieldFormDropDownPortion(sw::mark::IFieldmark * pFieldMark,const OUString & rExpand)227 explicit SwFieldFormDropDownPortion(sw::mark::IFieldmark *pFieldMark, const OUString &rExpand) 228 : SwFieldPortion(rExpand) 229 , m_pFieldMark(pFieldMark) 230 { 231 } 232 // Field cloner for SplitGlue 233 virtual SwFieldPortion *Clone( const OUString &rExpand ) const override; 234 235 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 236 237 private: 238 sw::mark::IFieldmark* m_pFieldMark; 239 }; 240 241 class SwFieldFormDatePortion : public SwFieldPortion 242 { 243 public: SwFieldFormDatePortion(sw::mark::IFieldmark * pFieldMark,bool bStart)244 explicit SwFieldFormDatePortion(sw::mark::IFieldmark *pFieldMark, bool bStart) 245 : SwFieldPortion("") 246 , m_pFieldMark(pFieldMark) 247 , m_bStart(bStart) 248 { 249 } 250 // Field cloner for SplitGlue 251 virtual SwFieldPortion *Clone( const OUString &rExpand) const override; 252 253 virtual void Paint( const SwTextPaintInfo &rInf ) const override; 254 255 private: 256 sw::mark::IFieldmark* m_pFieldMark; 257 bool m_bStart; 258 }; 259 260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 261