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