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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XISTRING_HXX 21 #define INCLUDED_SC_SOURCE_FILTER_INC_XISTRING_HXX 22 23 #include <rtl/ustring.hxx> 24 #include "xlstring.hxx" 25 26 // Byte/Unicode strings ======================================================= 27 28 class XclImpStream; 29 30 /** This class represents an unformatted or formatted string and provides importing from stream. */ 31 class XclImpString 32 { 33 public: 34 /** Constructs an empty string. */ 35 explicit XclImpString(); 36 /** Constructs an unformatted string. */ 37 explicit XclImpString( const OUString& rString ); 38 39 ~XclImpString(); 40 41 /** Reads a complete string from the passed stream. */ 42 void Read( XclImpStream& rStrm, XclStrFlags nFlags = XclStrFlags::NONE ); 43 44 /** Sets the passed string data. */ SetText(const OUString & rText)45 void SetText( const OUString& rText ) { maString = rText; } 46 /** Sets the passed formatting buffer. */ SetFormats(const XclFormatRunVec & rFormats)47 void SetFormats( const XclFormatRunVec& rFormats ) { maFormats = rFormats; } 48 /** Reads and appends the formatting information (run count and runs) from stream. */ ReadFormats(XclImpStream & rStrm)49 void ReadFormats( XclImpStream& rStrm ) { ReadFormats( rStrm, maFormats ); } 50 /** Reads and appends formatting runs from an OBJ or TXO record. */ ReadObjFormats(XclImpStream & rStrm,sal_uInt16 nFormatSize)51 void ReadObjFormats( XclImpStream& rStrm, sal_uInt16 nFormatSize ) { ReadObjFormats( rStrm, maFormats, nFormatSize ); } 52 53 /** Returns true, if the string is empty. */ IsEmpty() const54 bool IsEmpty() const { return maString.isEmpty(); } 55 /** Returns the pure text data of the string. */ GetText() const56 const OUString& GetText() const { return maString; } 57 58 /** Returns true, if the string contains formatting information. */ IsRich() const59 bool IsRich() const { return !maFormats.empty(); } 60 /** Returns the formatting run vector. */ GetFormats() const61 const XclFormatRunVec& GetFormats() const { return maFormats; } 62 63 /** Insert a formatting run to the passed format buffer. */ 64 static void AppendFormat( XclFormatRunVec& rFormats, sal_uInt16 nChar, sal_uInt16 nFontIdx ); 65 /** Reads and appends the formatting information (run count and runs) from stream. */ 66 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats ); 67 /** Reads and appends nRunCount formatting runs from stream. */ 68 static void ReadFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nRunCount ); 69 /** Reads and appends formatting runs from an OBJ or TXO record. */ 70 static void ReadObjFormats( XclImpStream& rStrm, XclFormatRunVec& rFormats, sal_uInt16 nFormatSize ); 71 72 private: 73 OUString maString; /// The text data of the string. 74 XclFormatRunVec maFormats; /// All formatting runs. 75 }; 76 77 // String iterator ============================================================ 78 79 /** Iterates over formatted string portions. */ 80 class XclImpStringIterator 81 { 82 public: 83 explicit XclImpStringIterator( const XclImpString& rString ); 84 85 /** Returns true, if the iterator references a valid text portion. */ Is() const86 bool Is() const { return mnTextBeg < mrText.getLength(); } 87 /** Returns the index of the current text portion. */ GetPortionIndex() const88 size_t GetPortionIndex() const { return mnPortion; } 89 /** Returns the string of the current text portion. */ 90 OUString GetPortionText() const; 91 /** Returns the font index of the current text portion. */ 92 sal_uInt16 GetPortionFont() const; 93 94 /** Moves iterator to next text portion. */ 95 XclImpStringIterator& operator++(); 96 97 private: 98 const OUString& mrText; /// The processed string. 99 const XclFormatRunVec& mrFormats; /// The vector of formatting runs. 100 size_t mnPortion; /// Current text portion. 101 sal_Int32 mnTextBeg; /// First character of current portion. 102 sal_Int32 mnTextEnd; /// First character of next portion. 103 size_t mnFormatsBeg; /// Formatting run index for current portion. 104 size_t mnFormatsEnd; /// Formatting run index for next portion. 105 }; 106 107 #endif 108 109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 110