LCOV - code coverage report
Current view: top level - sc/source/filter/inc - richstring.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 16 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 OOX_XLS_RICHSTRING_HXX
      21             : #define OOX_XLS_RICHSTRING_HXX
      22             : 
      23             : #include "oox/helper/refvector.hxx"
      24             : #include "stylesbuffer.hxx"
      25             : 
      26             : class EditTextObject;
      27             : struct ESelection;
      28             : class ScEditEngineDefaulter;
      29             : 
      30             : namespace com { namespace sun { namespace star {
      31             :     namespace text { class XText; }
      32             : } } }
      33             : 
      34             : namespace oox {
      35             : namespace xls {
      36             : 
      37             : /** Flags used to specify import/export mode of strings. */
      38             : typedef sal_Int32 BiffStringFlags;
      39             : 
      40             : const BiffStringFlags BIFF_STR_DEFAULT      = 0x0000;   /// Default string settings.
      41             : const BiffStringFlags BIFF_STR_FORCEUNICODE = 0x0001;   /// Always use UCS-2 characters (default: try to compress). BIFF8 export only.
      42             : const BiffStringFlags BIFF_STR_8BITLENGTH   = 0x0002;   /// 8-bit string length field (default: 16-bit).
      43             : const BiffStringFlags BIFF_STR_SMARTFLAGS   = 0x0004;   /// Omit flags on empty string (default: read/write always). BIFF8 only.
      44             : const BiffStringFlags BIFF_STR_KEEPFONTS    = 0x0008;   /// Keep old fonts when reading unformatted string (default: clear fonts). Import only.
      45             : const BiffStringFlags BIFF_STR_EXTRAFONTS   = 0x0010;   /// Read trailing rich-string font array (default: nothing). BIFF2-BIFF5 import only.
      46             : 
      47             : /** Contains text data and font attributes for a part of a rich formatted string. */
      48           0 : class RichStringPortion : public WorkbookHelper
      49             : {
      50             : public:
      51             :     explicit            RichStringPortion( const WorkbookHelper& rHelper );
      52             : 
      53             :     /** Sets text data for this portion. */
      54             :     void                setText( const OUString& rText );
      55             :     /** Creates and returns a new font formatting object. */
      56             :     FontRef             createFont();
      57             :     /** Links this portion to a font object from the global font list. */
      58             :     void                setFontId( sal_Int32 nFontId );
      59             : 
      60             :     /** Final processing after import of all strings. */
      61             :     void                finalizeImport();
      62             : 
      63             :     /** Returns the text data of this portion. */
      64           0 :     inline const OUString& getText() const { return maText; }
      65             :     /** Returns true, if the portion fontains font formatting. */
      66           0 :     inline bool         hasFont() const { return mxFont.get() != 0; }
      67             : 
      68             :     /** Converts the portion and replaces or appends to the passed XText. */
      69             :     void                convert(
      70             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
      71             : 
      72             :                             const Font* pFont, bool bReplace );
      73             :     void                convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const Font* pFont );
      74             : 
      75             :     void                writeFontProperties(
      76             :         const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
      77             :         const Font* pFont ) const;
      78             : 
      79             : private:
      80             :     OUString     maText;         /// Portion text.
      81             :     FontRef             mxFont;         /// Embedded portion font, may be empty.
      82             :     sal_Int32           mnFontId;       /// Link to global font list.
      83             : };
      84             : 
      85             : typedef ::boost::shared_ptr< RichStringPortion > RichStringPortionRef;
      86             : 
      87             : enum BiffFontPortionMode
      88             : {
      89             :     BIFF_FONTPORTION_8BIT,              /// Font portion with 8-bit values.
      90             :     BIFF_FONTPORTION_16BIT,             /// Font portion with 16-bit values.
      91             :     BIFF_FONTPORTION_OBJ                /// Font portion in OBJ or TXO record.
      92             : };
      93             : 
      94             : /** Represents a position in a rich-string containing current font identifier.
      95             : 
      96             :     This object stores the position of a formatted character in a rich-string
      97             :     and the identifier of a font from the global font list used to format this
      98             :     and the following characters. Used in binary filters only.
      99             :  */
     100             : struct FontPortionModel
     101             : {
     102             :     sal_Int32           mnPos;          /// First character in the string.
     103             :     sal_Int32           mnFontId;       /// Font identifier for the next characters.
     104             : 
     105           0 :     explicit inline     FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
     106           0 :     explicit inline     FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) :
     107           0 :                             mnPos( nPos ), mnFontId( nFontId ) {}
     108             : 
     109             :     void                read( SequenceInputStream& rStrm );
     110             : };
     111             : 
     112             : /** A vector with all font portions in a rich-string. */
     113           0 : class FontPortionModelList : public ::std::vector< FontPortionModel >
     114             : {
     115             : public:
     116           0 :     inline explicit     FontPortionModelList() {}
     117             : 
     118             :     /** Appends a rich-string font identifier. */
     119             :     void                appendPortion( const FontPortionModel& rPortion );
     120             :     /** Reads count and font identifiers from the passed stream. */
     121             :     void                importPortions( SequenceInputStream& rStrm );
     122             : };
     123             : 
     124             : struct PhoneticDataModel
     125             : {
     126             :     sal_Int32           mnFontId;       /// Font identifier for text formatting.
     127             :     sal_Int32           mnType;         /// Phonetic text type.
     128             :     sal_Int32           mnAlignment;    /// Phonetic portion alignment.
     129             : 
     130             :     explicit            PhoneticDataModel();
     131             : 
     132             :     /** Sets the passed data from binary import. */
     133             :     void                setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
     134             : };
     135             : 
     136           0 : class PhoneticSettings : public WorkbookHelper
     137             : {
     138             : public:
     139             :     explicit            PhoneticSettings( const WorkbookHelper& rHelper );
     140             : 
     141             :     /** Imports phonetic settings from the phoneticPr element. */
     142             :     void                importPhoneticPr( const AttributeList& rAttribs );
     143             :     /** Imports phonetic settings from the PHONETICPR record. */
     144             :     void                importPhoneticPr( SequenceInputStream& rStrm );
     145             : 
     146             :     /** Imports phonetic settings from a rich string. */
     147             :     void                importStringData( SequenceInputStream& rStrm );
     148             : 
     149             : private:
     150             :     PhoneticDataModel   maModel;
     151             : };
     152             : 
     153             : /** Contains text data and positioning information for a phonetic text portion. */
     154           0 : class RichStringPhonetic : public WorkbookHelper
     155             : {
     156             : public:
     157             :     explicit            RichStringPhonetic( const WorkbookHelper& rHelper );
     158             : 
     159             :     /** Sets text data for this phonetic portion. */
     160             :     void                setText( const OUString& rText );
     161             :     /** Imports attributes of a phonetic run (rPh element). */
     162             :     void                importPhoneticRun( const AttributeList& rAttribs );
     163             :     /** Sets the associated range in base text for this phonetic portion. */
     164             :     void                setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
     165             : 
     166             : private:
     167             :     OUString     maText;         /// Portion text.
     168             :     sal_Int32           mnBasePos;      /// Start position in base text.
     169             :     sal_Int32           mnBaseEnd;      /// One-past-end position in base text.
     170             : };
     171             : 
     172             : typedef ::boost::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
     173             : 
     174             : /** Represents a phonetic text portion in a rich-string with phonetic text.
     175             :     Used in binary filters only. */
     176             : struct PhoneticPortionModel
     177             : {
     178             :     sal_Int32           mnPos;          /// First character in phonetic text.
     179             :     sal_Int32           mnBasePos;      /// First character in base text.
     180             :     sal_Int32           mnBaseLen;      /// Number of characters in base text.
     181             : 
     182           0 :     explicit inline     PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
     183           0 :     explicit inline     PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
     184           0 :                             mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
     185             : 
     186             :     void                read( SequenceInputStream& rStrm );
     187             : };
     188             : 
     189             : /** A vector with all phonetic portions in a rich-string. */
     190           0 : class PhoneticPortionModelList : public ::std::vector< PhoneticPortionModel >
     191             : {
     192             : public:
     193           0 :     inline explicit     PhoneticPortionModelList() {}
     194             : 
     195             :     /** Appends a rich-string phonetic portion. */
     196             :     void                appendPortion( const PhoneticPortionModel& rPortion );
     197             :     /** Reads all phonetic portions from the passed stream. */
     198             :     void                importPortions( SequenceInputStream& rStrm );
     199             : };
     200             : 
     201             : /** Contains string data and a list of formatting runs for a rich formatted string. */
     202           0 : class RichString : public WorkbookHelper
     203             : {
     204             : public:
     205             :     explicit            RichString( const WorkbookHelper& rHelper );
     206             : 
     207             :     /** Appends and returns a portion object for a plain string (t element). */
     208             :     RichStringPortionRef importText( const AttributeList& rAttribs );
     209             :     /** Appends and returns a portion object for a new formatting run (r element). */
     210             :     RichStringPortionRef importRun( const AttributeList& rAttribs );
     211             :     /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */
     212             :     RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
     213             :     /** Imports phonetic settings from the rPhoneticPr element. */
     214             :     void                importPhoneticPr( const AttributeList& rAttribs );
     215             : 
     216             :     /** Imports a Unicode rich-string from the passed record stream. */
     217             :     void                importString( SequenceInputStream& rStrm, bool bRich );
     218             : 
     219             :     /** Final processing after import of all strings. */
     220             :     void                finalizeImport();
     221             : 
     222             :     /** Tries to extract a plain string from this object. Returns the string,
     223             :         if there is only one unformatted portion. */
     224             :     bool                extractPlainString(
     225             :                             OUString& orString,
     226             :                             const Font* pFirstPortionFont = 0 ) const;
     227             : 
     228             :     /** Converts the string and writes it into the passed XText.
     229             :         @param rxText  The XText interface of the target object.
     230             :         @param bReplaceOld  True = replace old contents of the text object.
     231             :         @param pFirstPortionFont  Optional font providing additional rich-text
     232             :             formatting for the first text portion, e.g. font escapement. */
     233             :     void                convert(
     234             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
     235             :                             bool bReplaceOld,
     236             :                             const Font* pFirstPortionFont = 0 ) const;
     237             :     ::EditTextObject*   convert( ScEditEngineDefaulter& rEE, const Font* pFont ) const;
     238             : 
     239             : private:
     240             :     /** Creates, appends, and returns a new empty string portion. */
     241             :     RichStringPortionRef createPortion();
     242             :     /** Creates, appends, and returns a new empty phonetic text portion. */
     243             :     RichStringPhoneticRef createPhonetic();
     244             : 
     245             :     /** Create base text portions from the passed string and character formatting. */
     246             :     void                createTextPortions( const OUString& rText, FontPortionModelList& rPortions );
     247             :     /** Create phonetic text portions from the passed string and portion data. */
     248             :     void                createPhoneticPortions( const OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
     249             : 
     250             : private:
     251             :     typedef RefVector< RichStringPortion >  PortionVector;
     252             :     typedef RefVector< RichStringPhonetic > PhoneticVector;
     253             : 
     254             :     PortionVector       maTextPortions; /// String portions with font data.
     255             :     PhoneticSettings    maPhonSettings; /// Phonetic settings for this string.
     256             :     PhoneticVector      maPhonPortions; /// Phonetic text portions.
     257             : };
     258             : 
     259             : typedef ::boost::shared_ptr< RichString > RichStringRef;
     260             : 
     261             : } // namespace xls
     262             : } // namespace oox
     263             : 
     264             : #endif
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10