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

Generated by: LCOV version 1.10