LCOV - code coverage report
Current view: top level - sc/source/filter/inc - richstring.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 16 31.2 %
Date: 2012-08-25 Functions: 7 18 38.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 12 41.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef OOX_XLS_RICHSTRING_HXX
      30                 :            : #define OOX_XLS_RICHSTRING_HXX
      31                 :            : 
      32                 :            : #include "oox/helper/refvector.hxx"
      33                 :            : #include "stylesbuffer.hxx"
      34                 :            : 
      35                 :            : namespace com { namespace sun { namespace star {
      36                 :            :     namespace text { class XText; }
      37                 :            : } } }
      38                 :            : 
      39                 :            : namespace oox {
      40                 :            : namespace xls {
      41                 :            : 
      42                 :            : // ============================================================================
      43                 :            : 
      44                 :            : /** Flags used to specify import/export mode of strings. */
      45                 :            : typedef sal_Int32 BiffStringFlags;
      46                 :            : 
      47                 :            : const BiffStringFlags BIFF_STR_DEFAULT      = 0x0000;   /// Default string settings.
      48                 :            : const BiffStringFlags BIFF_STR_FORCEUNICODE = 0x0001;   /// Always use UCS-2 characters (default: try to compress). BIFF8 export only.
      49                 :            : const BiffStringFlags BIFF_STR_8BITLENGTH   = 0x0002;   /// 8-bit string length field (default: 16-bit).
      50                 :            : const BiffStringFlags BIFF_STR_SMARTFLAGS   = 0x0004;   /// Omit flags on empty string (default: read/write always). BIFF8 only.
      51                 :            : const BiffStringFlags BIFF_STR_KEEPFONTS    = 0x0008;   /// Keep old fonts when reading unformatted string (default: clear fonts). Import only.
      52                 :            : const BiffStringFlags BIFF_STR_EXTRAFONTS   = 0x0010;   /// Read trailing rich-string font array (default: nothing). BIFF2-BIFF5 import only.
      53                 :            : 
      54                 :            : // ============================================================================
      55                 :            : 
      56                 :            : /** Contains text data and font attributes for a part of a rich formatted string. */
      57 [ +  - ][ -  + ]:        264 : class RichStringPortion : public WorkbookHelper
      58                 :            : {
      59                 :            : public:
      60                 :            :     explicit            RichStringPortion( const WorkbookHelper& rHelper );
      61                 :            : 
      62                 :            :     /** Sets text data for this portion. */
      63                 :            :     void                setText( const ::rtl::OUString& rText );
      64                 :            :     /** Creates and returns a new font formatting object. */
      65                 :            :     FontRef             createFont();
      66                 :            :     /** Links this portion to a font object from the global font list. */
      67                 :            :     void                setFontId( sal_Int32 nFontId );
      68                 :            : 
      69                 :            :     /** Final processing after import of all strings. */
      70                 :            :     void                finalizeImport();
      71                 :            : 
      72                 :            :     /** Returns the text data of this portion. */
      73                 :        150 :     inline const ::rtl::OUString& getText() const { return maText; }
      74                 :            :     /** Returns true, if the portion fontains font formatting. */
      75                 :        147 :     inline bool         hasFont() const { return mxFont.get() != 0; }
      76                 :            : 
      77                 :            :     /** Converts the portion and replaces or appends to the passed XText. */
      78                 :            :     void                convert(
      79                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
      80                 :            :                             const Font* pFont, bool bReplace );
      81                 :            : 
      82                 :            :     void                writeFontProperties(
      83                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
      84                 :            :         const Font* pFont ) const;
      85                 :            : 
      86                 :            : private:
      87                 :            :     ::rtl::OUString     maText;         /// Portion text.
      88                 :            :     FontRef             mxFont;         /// Embedded portion font, may be empty.
      89                 :            :     sal_Int32           mnFontId;       /// Link to global font list.
      90                 :            : };
      91                 :            : 
      92                 :            : typedef ::boost::shared_ptr< RichStringPortion > RichStringPortionRef;
      93                 :            : 
      94                 :            : // ----------------------------------------------------------------------------
      95                 :            : 
      96                 :            : enum BiffFontPortionMode
      97                 :            : {
      98                 :            :     BIFF_FONTPORTION_8BIT,              /// Font portion with 8-bit values.
      99                 :            :     BIFF_FONTPORTION_16BIT,             /// Font portion with 16-bit values.
     100                 :            :     BIFF_FONTPORTION_OBJ                /// Font portion in OBJ or TXO record.
     101                 :            : };
     102                 :            : 
     103                 :            : // ----------------------------------------------------------------------------
     104                 :            : 
     105                 :            : /** Represents a position in a rich-string containing current font identifier.
     106                 :            : 
     107                 :            :     This object stores the position of a formatted character in a rich-string
     108                 :            :     and the identifier of a font from the global font list used to format this
     109                 :            :     and the following characters. Used in binary filters only.
     110                 :            :  */
     111                 :            : struct FontPortionModel
     112                 :            : {
     113                 :            :     sal_Int32           mnPos;          /// First character in the string.
     114                 :            :     sal_Int32           mnFontId;       /// Font identifier for the next characters.
     115                 :            : 
     116                 :          0 :     explicit inline     FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
     117                 :          0 :     explicit inline     FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) :
     118                 :          0 :                             mnPos( nPos ), mnFontId( nFontId ) {}
     119                 :            : 
     120                 :            :     void                read( SequenceInputStream& rStrm );
     121                 :            : };
     122                 :            : 
     123                 :            : // ----------------------------------------------------------------------------
     124                 :            : 
     125                 :            : /** A vector with all font portions in a rich-string. */
     126                 :          0 : class FontPortionModelList : public ::std::vector< FontPortionModel >
     127                 :            : {
     128                 :            : public:
     129                 :          0 :     inline explicit     FontPortionModelList() {}
     130                 :            : 
     131                 :            :     /** Appends a rich-string font identifier. */
     132                 :            :     void                appendPortion( const FontPortionModel& rPortion );
     133                 :            :     /** Reads count and font identifiers from the passed stream. */
     134                 :            :     void                importPortions( SequenceInputStream& rStrm );
     135                 :            : };
     136                 :            : 
     137                 :            : // ============================================================================
     138                 :            : 
     139                 :            : struct PhoneticDataModel
     140                 :            : {
     141                 :            :     sal_Int32           mnFontId;       /// Font identifier for text formatting.
     142                 :            :     sal_Int32           mnType;         /// Phonetic text type.
     143                 :            :     sal_Int32           mnAlignment;    /// Phonetic portion alignment.
     144                 :            : 
     145                 :            :     explicit            PhoneticDataModel();
     146                 :            : 
     147                 :            :     /** Sets the passed data from binary import. */
     148                 :            :     void                setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
     149                 :            : };
     150                 :            : 
     151                 :            : // ----------------------------------------------------------------------------
     152                 :            : 
     153         [ -  + ]:        192 : class PhoneticSettings : public WorkbookHelper
     154                 :            : {
     155                 :            : public:
     156                 :            :     explicit            PhoneticSettings( const WorkbookHelper& rHelper );
     157                 :            : 
     158                 :            :     /** Imports phonetic settings from the phoneticPr element. */
     159                 :            :     void                importPhoneticPr( const AttributeList& rAttribs );
     160                 :            :     /** Imports phonetic settings from the PHONETICPR record. */
     161                 :            :     void                importPhoneticPr( SequenceInputStream& rStrm );
     162                 :            : 
     163                 :            :     /** Imports phonetic settings from a rich string. */
     164                 :            :     void                importStringData( SequenceInputStream& rStrm );
     165                 :            : 
     166                 :            : private:
     167                 :            :     PhoneticDataModel   maModel;
     168                 :            : };
     169                 :            : 
     170                 :            : // ============================================================================
     171                 :            : 
     172                 :            : /** Contains text data and positioning information for a phonetic text portion. */
     173         [ #  # ]:          0 : class RichStringPhonetic : public WorkbookHelper
     174                 :            : {
     175                 :            : public:
     176                 :            :     explicit            RichStringPhonetic( const WorkbookHelper& rHelper );
     177                 :            : 
     178                 :            :     /** Sets text data for this phonetic portion. */
     179                 :            :     void                setText( const ::rtl::OUString& rText );
     180                 :            :     /** Imports attributes of a phonetic run (rPh element). */
     181                 :            :     void                importPhoneticRun( const AttributeList& rAttribs );
     182                 :            :     /** Sets the associated range in base text for this phonetic portion. */
     183                 :            :     void                setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
     184                 :            : 
     185                 :            : private:
     186                 :            :     ::rtl::OUString     maText;         /// Portion text.
     187                 :            :     sal_Int32           mnBasePos;      /// Start position in base text.
     188                 :            :     sal_Int32           mnBaseEnd;      /// One-past-end position in base text.
     189                 :            : };
     190                 :            : 
     191                 :            : typedef ::boost::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
     192                 :            : 
     193                 :            : // ----------------------------------------------------------------------------
     194                 :            : 
     195                 :            : /** Represents a phonetic text portion in a rich-string with phonetic text.
     196                 :            :     Used in binary filters only. */
     197                 :            : struct PhoneticPortionModel
     198                 :            : {
     199                 :            :     sal_Int32           mnPos;          /// First character in phonetic text.
     200                 :            :     sal_Int32           mnBasePos;      /// First character in base text.
     201                 :            :     sal_Int32           mnBaseLen;      /// Number of characters in base text.
     202                 :            : 
     203                 :          0 :     explicit inline     PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
     204                 :          0 :     explicit inline     PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
     205                 :          0 :                             mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
     206                 :            : 
     207                 :            :     void                read( SequenceInputStream& rStrm );
     208                 :            : };
     209                 :            : 
     210                 :            : // ----------------------------------------------------------------------------
     211                 :            : 
     212                 :            : /** A vector with all phonetic portions in a rich-string. */
     213                 :          0 : class PhoneticPortionModelList : public ::std::vector< PhoneticPortionModel >
     214                 :            : {
     215                 :            : public:
     216                 :          0 :     inline explicit     PhoneticPortionModelList() {}
     217                 :            : 
     218                 :            :     /** Appends a rich-string phonetic portion. */
     219                 :            :     void                appendPortion( const PhoneticPortionModel& rPortion );
     220                 :            :     /** Reads all phonetic portions from the passed stream. */
     221                 :            :     void                importPortions( SequenceInputStream& rStrm );
     222                 :            : };
     223                 :            : 
     224                 :            : // ============================================================================
     225                 :            : 
     226                 :            : /** Contains string data and a list of formatting runs for a rich formatted string. */
     227 [ +  - ][ -  + ]:        264 : class RichString : public WorkbookHelper
     228                 :            : {
     229                 :            : public:
     230                 :            :     explicit            RichString( const WorkbookHelper& rHelper );
     231                 :            : 
     232                 :            :     /** Appends and returns a portion object for a plain string (t element). */
     233                 :            :     RichStringPortionRef importText( const AttributeList& rAttribs );
     234                 :            :     /** Appends and returns a portion object for a new formatting run (r element). */
     235                 :            :     RichStringPortionRef importRun( const AttributeList& rAttribs );
     236                 :            :     /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */
     237                 :            :     RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
     238                 :            :     /** Imports phonetic settings from the rPhoneticPr element. */
     239                 :            :     void                importPhoneticPr( const AttributeList& rAttribs );
     240                 :            : 
     241                 :            :     /** Imports a Unicode rich-string from the passed record stream. */
     242                 :            :     void                importString( SequenceInputStream& rStrm, bool bRich );
     243                 :            : 
     244                 :            :     /** Final processing after import of all strings. */
     245                 :            :     void                finalizeImport();
     246                 :            : 
     247                 :            :     /** Tries to extract a plain string from this object. Returns the string,
     248                 :            :         if there is only one unformatted portion. */
     249                 :            :     bool                extractPlainString(
     250                 :            :                             ::rtl::OUString& orString,
     251                 :            :                             const Font* pFirstPortionFont = 0 ) const;
     252                 :            : 
     253                 :            :     /** Converts the string and writes it into the passed XText.
     254                 :            :         @param rxText  The XText interface of the target object.
     255                 :            :         @param bReplaceOld  True = replace old contents of the text object.
     256                 :            :         @param pFirstPortionFont  Optional font providing additional rich-text
     257                 :            :             formatting for the first text portion, e.g. font escapement. */
     258                 :            :     void                convert(
     259                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
     260                 :            :                             bool bReplaceOld,
     261                 :            :                             const Font* pFirstPortionFont = 0 ) const;
     262                 :            : 
     263                 :            : private:
     264                 :            :     /** Creates, appends, and returns a new empty string portion. */
     265                 :            :     RichStringPortionRef createPortion();
     266                 :            :     /** Creates, appends, and returns a new empty phonetic text portion. */
     267                 :            :     RichStringPhoneticRef createPhonetic();
     268                 :            : 
     269                 :            :     /** Create base text portions from the passed string and character formatting. */
     270                 :            :     void                createTextPortions( const ::rtl::OUString& rText, FontPortionModelList& rPortions );
     271                 :            :     /** Create phonetic text portions from the passed string and portion data. */
     272                 :            :     void                createPhoneticPortions( const ::rtl::OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
     273                 :            : 
     274                 :            : private:
     275                 :            :     typedef RefVector< RichStringPortion >  PortionVector;
     276                 :            :     typedef RefVector< RichStringPhonetic > PhoneticVector;
     277                 :            : 
     278                 :            :     PortionVector       maTextPortions; /// String portions with font data.
     279                 :            :     PhoneticSettings    maPhonSettings; /// Phonetic settings for this string.
     280                 :            :     PhoneticVector      maPhonPortions; /// Phonetic text portions.
     281                 :            : };
     282                 :            : 
     283                 :            : typedef ::boost::shared_ptr< RichString > RichStringRef;
     284                 :            : 
     285                 :            : // ============================================================================
     286                 :            : 
     287                 :            : } // namespace xls
     288                 :            : } // namespace oox
     289                 :            : 
     290                 :            : #endif
     291                 :            : 
     292                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10