LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - stylesbuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1005 1532 65.6 %
Date: 2012-12-27 Functions: 151 203 74.4 %
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             : #include "stylesbuffer.hxx"
      21             : 
      22             : #include <com/sun/star/awt/FontDescriptor.hpp>
      23             : #include <com/sun/star/awt/FontFamily.hpp>
      24             : #include <com/sun/star/awt/FontPitch.hpp>
      25             : #include <com/sun/star/awt/FontSlant.hpp>
      26             : #include <com/sun/star/awt/FontStrikeout.hpp>
      27             : #include <com/sun/star/awt/FontType.hpp>
      28             : #include <com/sun/star/awt/FontWeight.hpp>
      29             : #include <com/sun/star/awt/FontUnderline.hpp>
      30             : #include <com/sun/star/awt/XDevice.hpp>
      31             : #include <com/sun/star/awt/XFont2.hpp>
      32             : #include <com/sun/star/container/XIndexAccess.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <com/sun/star/style/XStyle.hpp>
      35             : #include <com/sun/star/text/WritingMode2.hpp>
      36             : #include <com/sun/star/text/XText.hpp>
      37             : #include <com/sun/star/table/CellVertJustify2.hpp>
      38             : #include <com/sun/star/table/CellJustifyMethod.hpp>
      39             : #include <com/sun/star/table/TableBorder.hpp>
      40             : #include <editeng/justifyitem.hxx>
      41             : #include <editeng/frmdiritem.hxx>
      42             : #include <editeng/fontitem.hxx>
      43             : #include <editeng/postitem.hxx>
      44             : #include <editeng/fhgtitem.hxx>
      45             : #include <editeng/wghtitem.hxx>
      46             : #include <editeng/udlnitem.hxx>
      47             : #include <editeng/colritem.hxx>
      48             : #include <editeng/crsditem.hxx>
      49             : #include <editeng/cntritem.hxx>
      50             : #include <editeng/escpitem.hxx>
      51             : #include <editeng/shdditem.hxx>
      52             : #include <editeng/eeitem.hxx>
      53             : #include <editeng/boxitem.hxx>
      54             : #include <editeng/bolnitem.hxx>
      55             : #include <editeng/brshitem.hxx>
      56             : #include <svx/rotmodit.hxx>
      57             : #include <tools/fontenum.hxx>
      58             : #include <toolkit/helper/vclunohelper.hxx>
      59             : #include <rtl/tencinfo.h>
      60             : #include <rtl/ustrbuf.hxx>
      61             : #include <oox/core/filterbase.hxx>
      62             : #include <oox/helper/attributelist.hxx>
      63             : #include <oox/helper/containerhelper.hxx>
      64             : #include <oox/helper/propertymap.hxx>
      65             : #include <oox/helper/propertyset.hxx>
      66             : #include "biffinputstream.hxx"
      67             : #include "condformatbuffer.hxx"
      68             : #include "excelhandlers.hxx"
      69             : #include "themebuffer.hxx"
      70             : #include "unitconverter.hxx"
      71             : #include "document.hxx"
      72             : #include "stlpool.hxx"
      73             : #include "docpool.hxx"
      74             : #include "ftools.hxx"
      75             : #include "scitems.hxx"
      76             : #include "attrib.hxx"
      77             : #include "globstr.hrc"
      78             : 
      79             : using ::com::sun::star::table::BorderLine2;
      80             : namespace oox {
      81             : namespace xls {
      82             : 
      83             : // ============================================================================
      84             : 
      85             : using namespace ::com::sun::star::awt;
      86             : using namespace ::com::sun::star::container;
      87             : using namespace ::com::sun::star::style;
      88             : using namespace ::com::sun::star::table;
      89             : using namespace ::com::sun::star::text;
      90             : using namespace ::com::sun::star::uno;
      91             : 
      92             : using ::oox::core::FilterBase;
      93             : using ::rtl::OUString;
      94             : using ::rtl::OUStringBuffer;
      95             : 
      96             : // ============================================================================
      97             : 
      98             : namespace {
      99             : 
     100             : // OOXML constants ------------------------------------------------------------
     101             : 
     102             : // OOXML predefined color indexes (also used in BIFF3-BIFF8)
     103             : const sal_Int32 OOX_COLOR_USEROFFSET        = 0;        /// First user defined color in palette (OOXML/BIFF12).
     104             : const sal_Int32 BIFF_COLOR_USEROFFSET       = 8;        /// First user defined color in palette (BIFF3-BIFF8).
     105             : 
     106             : // OOXML font family (also used in BIFF)
     107             : const sal_Int32 OOX_FONTFAMILY_NONE         = 0;
     108             : const sal_Int32 OOX_FONTFAMILY_ROMAN        = 1;
     109             : const sal_Int32 OOX_FONTFAMILY_SWISS        = 2;
     110             : const sal_Int32 OOX_FONTFAMILY_MODERN       = 3;
     111             : const sal_Int32 OOX_FONTFAMILY_SCRIPT       = 4;
     112             : const sal_Int32 OOX_FONTFAMILY_DECORATIVE   = 5;
     113             : 
     114             : // OOXML cell text direction (also used in BIFF)
     115             : const sal_Int32 OOX_XF_TEXTDIR_CONTEXT      = 0;
     116             : const sal_Int32 OOX_XF_TEXTDIR_LTR          = 1;
     117             : const sal_Int32 OOX_XF_TEXTDIR_RTL          = 2;
     118             : 
     119             : // OOXML cell rotation (also used in BIFF)
     120             : const sal_Int32 OOX_XF_ROTATION_NONE        = 0;
     121             : const sal_Int32 OOX_XF_ROTATION_90CCW       = 90;
     122             : const sal_Int32 OOX_XF_ROTATION_90CW        = 180;
     123             : const sal_Int32 OOX_XF_ROTATION_STACKED     = 255;
     124             : 
     125             : // OOXML cell indentation
     126             : const sal_Int32 OOX_XF_INDENT_NONE          = 0;
     127             : 
     128             : // OOXML built-in cell styles (also used in BIFF)
     129             : const sal_Int32 OOX_STYLE_NORMAL            = 0;        /// Default cell style.
     130             : const sal_Int32 OOX_STYLE_ROWLEVEL          = 1;        /// RowLevel_x cell style.
     131             : const sal_Int32 OOX_STYLE_COLLEVEL          = 2;        /// ColLevel_x cell style.
     132             : 
     133             : const sal_Int32 OOX_STYLE_LEVELCOUNT        = 7;        /// Number of outline level styles.
     134             : 
     135             : // BIFF12 constants -----------------------------------------------------------
     136             : 
     137             : // BIFF12 color types
     138             : const sal_uInt8 BIFF12_COLOR_AUTO           = 0;
     139             : const sal_uInt8 BIFF12_COLOR_INDEXED        = 1;
     140             : const sal_uInt8 BIFF12_COLOR_RGB            = 2;
     141             : const sal_uInt8 BIFF12_COLOR_THEME          = 3;
     142             : 
     143             : // BIFF12 diagonal borders
     144             : const sal_uInt8 BIFF12_BORDER_DIAG_TLBR     = 0x01;     /// Top-left to bottom-right.
     145             : const sal_uInt8 BIFF12_BORDER_DIAG_BLTR     = 0x02;     /// Bottom-left to top-right.
     146             : 
     147             : // BIFF12 gradient fill
     148             : const sal_Int32 BIFF12_FILL_GRADIENT        = 40;
     149             : 
     150             : // BIFF12 XF flags
     151             : const sal_uInt32 BIFF12_XF_WRAPTEXT         = 0x00400000;
     152             : const sal_uInt32 BIFF12_XF_JUSTLASTLINE     = 0x00800000;
     153             : const sal_uInt32 BIFF12_XF_SHRINK           = 0x01000000;
     154             : const sal_uInt32 BIFF12_XF_LOCKED           = 0x10000000;
     155             : const sal_uInt32 BIFF12_XF_HIDDEN           = 0x20000000;
     156             : 
     157             : // BIFF12 XF attribute used flags
     158             : const sal_uInt16 BIFF12_XF_NUMFMT_USED      = 0x0001;
     159             : const sal_uInt16 BIFF12_XF_FONT_USED        = 0x0002;
     160             : const sal_uInt16 BIFF12_XF_ALIGN_USED       = 0x0004;
     161             : const sal_uInt16 BIFF12_XF_BORDER_USED      = 0x0008;
     162             : const sal_uInt16 BIFF12_XF_AREA_USED        = 0x0010;
     163             : const sal_uInt16 BIFF12_XF_PROT_USED        = 0x0020;
     164             : 
     165             : // BIFF12 DXF constants
     166             : const sal_uInt16 BIFF12_DXF_FILL_PATTERN    = 0;
     167             : const sal_uInt16 BIFF12_DXF_FILL_FGCOLOR    = 1;
     168             : const sal_uInt16 BIFF12_DXF_FILL_BGCOLOR    = 2;
     169             : const sal_uInt16 BIFF12_DXF_FILL_GRADIENT   = 3;
     170             : const sal_uInt16 BIFF12_DXF_FILL_STOP       = 4;
     171             : const sal_uInt16 BIFF12_DXF_FONT_COLOR      = 5;
     172             : const sal_uInt16 BIFF12_DXF_BORDER_TOP      = 6;
     173             : const sal_uInt16 BIFF12_DXF_BORDER_BOTTOM   = 7;
     174             : const sal_uInt16 BIFF12_DXF_BORDER_LEFT     = 8;
     175             : const sal_uInt16 BIFF12_DXF_BORDER_RIGHT    = 9;
     176             : const sal_uInt16 BIFF12_DXF_BORDER_DIAG     = 10;
     177             : const sal_uInt16 BIFF12_DXF_BORDER_VERT     = 11;
     178             : const sal_uInt16 BIFF12_DXF_BORDER_HOR      = 12;
     179             : const sal_uInt16 BIFF12_DXF_BORDER_DIAGUP   = 13;
     180             : const sal_uInt16 BIFF12_DXF_BORDER_DIAGDOWN = 14;
     181             : const sal_uInt16 BIFF12_DXF_FONT_NAME       = 24;
     182             : const sal_uInt16 BIFF12_DXF_FONT_WEIGHT     = 25;
     183             : const sal_uInt16 BIFF12_DXF_FONT_UNDERLINE  = 26;
     184             : const sal_uInt16 BIFF12_DXF_FONT_ESCAPEMENT = 27;
     185             : const sal_uInt16 BIFF12_DXF_FONT_ITALIC     = 28;
     186             : const sal_uInt16 BIFF12_DXF_FONT_STRIKE     = 29;
     187             : const sal_uInt16 BIFF12_DXF_FONT_OUTLINE    = 30;
     188             : const sal_uInt16 BIFF12_DXF_FONT_SHADOW     = 31;
     189             : const sal_uInt16 BIFF12_DXF_FONT_CONDENSE   = 32;
     190             : const sal_uInt16 BIFF12_DXF_FONT_EXTEND     = 33;
     191             : const sal_uInt16 BIFF12_DXF_FONT_CHARSET    = 34;
     192             : const sal_uInt16 BIFF12_DXF_FONT_FAMILY     = 35;
     193             : const sal_uInt16 BIFF12_DXF_FONT_HEIGHT     = 36;
     194             : const sal_uInt16 BIFF12_DXF_FONT_SCHEME     = 37;
     195             : const sal_uInt16 BIFF12_DXF_NUMFMT_CODE     = 38;
     196             : const sal_uInt16 BIFF12_DXF_NUMFMT_ID       = 41;
     197             : 
     198             : // BIFF12 CELLSTYLE flags
     199             : const sal_uInt16 BIFF12_CELLSTYLE_BUILTIN   = 0x0001;
     200             : const sal_uInt16 BIFF12_CELLSTYLE_HIDDEN    = 0x0002;
     201             : const sal_uInt16 BIFF12_CELLSTYLE_CUSTOM    = 0x0004;
     202             : 
     203             : // BIFF constants -------------------------------------------------------------
     204             : 
     205             : // BIFF predefined color indexes
     206             : const sal_uInt16 BIFF2_COLOR_BLACK          = 0;        /// Black (text) in BIFF2.
     207             : const sal_uInt16 BIFF2_COLOR_WHITE          = 1;        /// White (background) in BIFF2.
     208             : 
     209             : // BIFF font flags, also used in BIFF12
     210             : const sal_uInt16 BIFF_FONTFLAG_BOLD         = 0x0001;
     211             : const sal_uInt16 BIFF_FONTFLAG_ITALIC       = 0x0002;
     212             : const sal_uInt16 BIFF_FONTFLAG_UNDERLINE    = 0x0004;
     213             : const sal_uInt16 BIFF_FONTFLAG_STRIKEOUT    = 0x0008;
     214             : const sal_uInt16 BIFF_FONTFLAG_OUTLINE      = 0x0010;
     215             : const sal_uInt16 BIFF_FONTFLAG_SHADOW       = 0x0020;
     216             : const sal_uInt16 BIFF_FONTFLAG_CONDENSE     = 0x0040;
     217             : 
     218             : // BIFF font weight
     219             : const sal_uInt16 BIFF_FONTWEIGHT_BOLD       = 450;
     220             : 
     221             : // BIFF font underline, also used in BIFF12
     222             : const sal_uInt8 BIFF_FONTUNDERL_NONE        = 0;
     223             : const sal_uInt8 BIFF_FONTUNDERL_SINGLE      = 1;
     224             : const sal_uInt8 BIFF_FONTUNDERL_DOUBLE      = 2;
     225             : const sal_uInt8 BIFF_FONTUNDERL_SINGLE_ACC  = 33;
     226             : const sal_uInt8 BIFF_FONTUNDERL_DOUBLE_ACC  = 34;
     227             : 
     228             : // BIFF XF flags
     229             : const sal_uInt16 BIFF_XF_LOCKED             = 0x0001;
     230             : const sal_uInt16 BIFF_XF_HIDDEN             = 0x0002;
     231             : const sal_uInt16 BIFF_XF_STYLE              = 0x0004;
     232             : const sal_uInt16 BIFF_XF_STYLEPARENT        = 0x0FFF;   /// Styles don't have a parent.
     233             : const sal_uInt16 BIFF_XF_WRAPTEXT           = 0x0008;   /// Automatic line break.
     234             : const sal_uInt16 BIFF_XF_JUSTLASTLINE       = 0x0080;
     235             : const sal_uInt16 BIFF_XF_SHRINK             = 0x0010;   /// Shrink to fit into cell.
     236             : const sal_uInt16 BIFF_XF_MERGE              = 0x0020;
     237             : 
     238             : // BIFF XF attribute used flags
     239             : const sal_uInt8 BIFF_XF_NUMFMT_USED         = 0x01;
     240             : const sal_uInt8 BIFF_XF_FONT_USED           = 0x02;
     241             : const sal_uInt8 BIFF_XF_ALIGN_USED          = 0x04;
     242             : const sal_uInt8 BIFF_XF_BORDER_USED         = 0x08;
     243             : const sal_uInt8 BIFF_XF_AREA_USED           = 0x10;
     244             : const sal_uInt8 BIFF_XF_PROT_USED           = 0x20;
     245             : 
     246             : // BIFF XF text orientation
     247             : const sal_uInt8 BIFF_XF_ORIENT_NONE         = 0;
     248             : const sal_uInt8 BIFF_XF_ORIENT_STACKED      = 1;        /// Stacked top to bottom.
     249             : const sal_uInt8 BIFF_XF_ORIENT_90CCW        = 2;        /// 90 degr. counterclockwise.
     250             : const sal_uInt8 BIFF_XF_ORIENT_90CW         = 3;        /// 90 degr. clockwise.
     251             : 
     252             : // BIFF XF line styles
     253             : const sal_uInt8 BIFF_LINE_NONE              = 0;
     254             : const sal_uInt8 BIFF_LINE_THIN              = 1;
     255             : 
     256             : // BIFF XF patterns
     257             : const sal_uInt8 BIFF_PATT_NONE              = 0;
     258             : const sal_uInt8 BIFF_PATT_125               = 17;
     259             : 
     260             : // BIFF2 XF flags
     261             : const sal_uInt8 BIFF2_XF_VALFMT_MASK        = 0x3F;
     262             : const sal_uInt8 BIFF2_XF_LOCKED             = 0x40;
     263             : const sal_uInt8 BIFF2_XF_HIDDEN             = 0x80;
     264             : const sal_uInt8 BIFF2_XF_LEFTLINE           = 0x08;
     265             : const sal_uInt8 BIFF2_XF_RIGHTLINE          = 0x10;
     266             : const sal_uInt8 BIFF2_XF_TOPLINE            = 0x20;
     267             : const sal_uInt8 BIFF2_XF_BOTTOMLINE         = 0x40;
     268             : const sal_uInt8 BIFF2_XF_BACKGROUND         = 0x80;
     269             : 
     270             : // BIFF8 diagonal borders
     271             : const sal_uInt32 BIFF_XF_DIAG_TLBR          = 0x40000000;   /// Top-left to bottom-right.
     272             : const sal_uInt32 BIFF_XF_DIAG_BLTR          = 0x80000000;   /// Bottom-left to top-right.
     273             : 
     274             : // BIFF STYLE flags
     275             : const sal_uInt16 BIFF_STYLE_BUILTIN         = 0x8000;
     276             : const sal_uInt16 BIFF_STYLE_XFMASK          = 0x0FFF;
     277             : 
     278             : // BIFF STYLEEXT flags
     279             : const sal_uInt8 BIFF_STYLEEXT_BUILTIN       = 0x01;
     280             : const sal_uInt8 BIFF_STYLEEXT_HIDDEN        = 0x02;
     281             : const sal_uInt8 BIFF_STYLEEXT_CUSTOM        = 0x04;
     282             : 
     283             : // BIFF conditional formatting
     284             : const sal_uInt32 BIFF_CFRULE_BORDER_LEFT    = 0x00000400;
     285             : const sal_uInt32 BIFF_CFRULE_BORDER_RIGHT   = 0x00000800;
     286             : const sal_uInt32 BIFF_CFRULE_BORDER_TOP     = 0x00001000;
     287             : const sal_uInt32 BIFF_CFRULE_BORDER_BOTTOM  = 0x00002000;
     288             : const sal_uInt32 BIFF_CFRULE_FILL_PATTERN   = 0x00010000;
     289             : const sal_uInt32 BIFF_CFRULE_FILL_PATTCOLOR = 0x00020000;
     290             : const sal_uInt32 BIFF_CFRULE_FILL_FILLCOLOR = 0x00040000;
     291             : const sal_uInt32 BIFF_CFRULE_FONTBLOCK      = 0x04000000;
     292             : const sal_uInt32 BIFF_CFRULE_ALIGNBLOCK     = 0x08000000;
     293             : const sal_uInt32 BIFF_CFRULE_BORDERBLOCK    = 0x10000000;
     294             : const sal_uInt32 BIFF_CFRULE_FILLBLOCK      = 0x20000000;
     295             : const sal_uInt32 BIFF_CFRULE_PROTBLOCK      = 0x40000000;
     296             : 
     297             : const sal_uInt32 BIFF_CFRULE_FONT_STYLE     = 0x00000002;   /// Font posture or weight modified?
     298             : const sal_uInt32 BIFF_CFRULE_FONT_OUTLINE   = 0x00000008;   /// Font outline modified?
     299             : const sal_uInt32 BIFF_CFRULE_FONT_SHADOW    = 0x00000010;   /// Font shadow modified?
     300             : const sal_uInt32 BIFF_CFRULE_FONT_STRIKEOUT = 0x00000080;   /// Font cancellation modified?
     301             : const sal_uInt32 BIFF_CFRULE_FONT_UNDERL    = 0x00000001;   /// Font underline type modified?
     302             : const sal_uInt32 BIFF_CFRULE_FONT_ESCAPEM   = 0x00000001;   /// Font escapement type modified?
     303             : 
     304             : // ----------------------------------------------------------------------------
     305             : 
     306           0 : sal_Int32 lclReadRgbColor( BinaryInputStream& rStrm )
     307             : {
     308             :     sal_uInt8 nR, nG, nB, nA;
     309           0 :     rStrm >> nR >> nG >> nB >> nA;
     310           0 :     sal_Int32 nValue = nA;
     311           0 :     nValue <<= 8;
     312           0 :     nValue |= nR;
     313           0 :     nValue <<= 8;
     314           0 :     nValue |= nG;
     315           0 :     nValue <<= 8;
     316           0 :     nValue |= nB;
     317           0 :     return nValue;
     318             : }
     319             : 
     320             : } // namespace
     321             : 
     322             : // ============================================================================
     323             : 
     324          11 : ExcelGraphicHelper::ExcelGraphicHelper( const WorkbookHelper& rHelper ) :
     325          22 :     GraphicHelper( rHelper.getBaseFilter().getComponentContext(), rHelper.getBaseFilter().getTargetFrame(), rHelper.getBaseFilter().getStorage() ),
     326          22 :     WorkbookHelper( rHelper )
     327             : {
     328          11 : }
     329             : 
     330           6 : sal_Int32 ExcelGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
     331             : {
     332           6 :     if( getFilterType() == FILTER_OOXML )
     333           6 :         return getTheme().getColorByToken( nToken );
     334           0 :     return GraphicHelper::getSchemeColor( nToken );
     335             : }
     336             : 
     337          66 : sal_Int32 ExcelGraphicHelper::getPaletteColor( sal_Int32 nPaletteIdx ) const
     338             : {
     339          66 :     return getStyles().getPaletteColor( nPaletteIdx );
     340             : }
     341             : 
     342             : // ============================================================================
     343             : 
     344           0 : void Color::setAuto()
     345             : {
     346           0 :     clearTransformations();
     347           0 :     setSchemeClr( XML_phClr );
     348           0 : }
     349             : 
     350          36 : void Color::setRgb( sal_Int32 nRgbValue, double fTint )
     351             : {
     352          36 :     clearTransformations();
     353          36 :     setSrgbClr( nRgbValue & 0xFFFFFF );
     354          36 :     if( fTint != 0.0 ) addExcelTintTransformation( fTint );
     355          36 : }
     356             : 
     357           6 : void Color::setTheme( sal_Int32 nThemeIdx, double fTint )
     358             : {
     359           6 :     clearTransformations();
     360             :     static const sal_Int32 spnColorTokens[] = {
     361             :         XML_lt1, XML_dk1, XML_lt2, XML_dk2, XML_accent1, XML_accent2,
     362             :         XML_accent3, XML_accent4, XML_accent5, XML_accent6, XML_hlink, XML_folHlink };
     363           6 :     setSchemeClr( STATIC_ARRAY_SELECT( spnColorTokens, nThemeIdx, XML_TOKEN_INVALID ) );
     364           6 :     if( fTint != 0.0 ) addExcelTintTransformation( fTint );
     365           6 : }
     366             : 
     367         193 : void Color::setIndexed( sal_Int32 nPaletteIdx, double fTint )
     368             : {
     369         193 :     clearTransformations();
     370         193 :     setPaletteClr( nPaletteIdx );
     371         193 :     if( fTint != 0.0 ) addExcelTintTransformation( fTint );
     372         193 : }
     373             : 
     374          42 : void Color::importColor( const AttributeList& rAttribs )
     375             : {
     376          42 :     if( rAttribs.getBool( XML_auto, false ) )
     377           0 :         setAuto();
     378          42 :     else if( rAttribs.hasAttribute( XML_rgb ) )
     379          36 :         setRgb( rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT ), rAttribs.getDouble( XML_tint, 0.0 ) );
     380           6 :     else if( rAttribs.hasAttribute( XML_theme ) )
     381           6 :         setTheme( rAttribs.getInteger( XML_theme, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
     382           0 :     else if( rAttribs.hasAttribute( XML_indexed ) )
     383           0 :         setIndexed( rAttribs.getInteger( XML_indexed, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
     384             :     else
     385             :     {
     386             :         OSL_FAIL( "Color::importColor - unknown color type" );
     387           0 :         setAuto();
     388             :     }
     389          42 : }
     390             : 
     391           0 : void Color::importColor( SequenceInputStream& rStrm )
     392             : {
     393             :     sal_uInt8 nFlags, nIndex;
     394             :     sal_Int16 nTint;
     395           0 :     rStrm >> nFlags >> nIndex >> nTint;
     396             : 
     397             :     // scale tint from signed 16-bit to double range -1.0 ... 1.0
     398           0 :     double fTint = nTint;
     399           0 :     if( nTint < 0 )
     400           0 :         fTint /= -SAL_MIN_INT16;
     401           0 :     else if( nTint > 0 )
     402           0 :         fTint /= SAL_MAX_INT16;
     403             : 
     404           0 :     switch( extractValue< sal_uInt8 >( nFlags, 1, 7 ) )
     405             :     {
     406             :         case BIFF12_COLOR_AUTO:
     407           0 :             setAuto();
     408           0 :             rStrm.skip( 4 );
     409           0 :         break;
     410             :         case BIFF12_COLOR_INDEXED:
     411           0 :             setIndexed( nIndex, fTint );
     412           0 :             rStrm.skip( 4 );
     413           0 :         break;
     414             :         case BIFF12_COLOR_RGB:
     415           0 :             setRgb( lclReadRgbColor( rStrm ), fTint );
     416           0 :         break;
     417             :         case BIFF12_COLOR_THEME:
     418           0 :             setTheme( nIndex, fTint );
     419           0 :             rStrm.skip( 4 );
     420           0 :         break;
     421             :         default:
     422             :             OSL_FAIL( "Color::importColor - unknown color type" );
     423           0 :             setAuto();
     424           0 :             rStrm.skip( 4 );
     425             :     }
     426           0 : }
     427             : 
     428           0 : void Color::importColorId( SequenceInputStream& rStrm )
     429             : {
     430           0 :     setIndexed( rStrm.readInt32() );
     431           0 : }
     432             : 
     433           0 : SequenceInputStream& operator>>( SequenceInputStream& rStrm, Color& orColor )
     434             : {
     435           0 :     orColor.importColor( rStrm );
     436           0 :     return rStrm;
     437             : }
     438             : 
     439             : // ============================================================================
     440             : 
     441             : namespace {
     442             : 
     443             : /** Standard EGA colors, bright. */
     444             : #define PALETTE_EGA_COLORS_LIGHT \
     445             :             0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
     446             : /** Standard EGA colors, dark. */
     447             : #define PALETTE_EGA_COLORS_DARK \
     448             :             0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
     449             : 
     450             : /** Default color table for BIFF2. */
     451             : static const sal_Int32 spnDefColors2[] =
     452             : {
     453             : /*  0 */    PALETTE_EGA_COLORS_LIGHT
     454             : };
     455             : 
     456             : /** Default color table for BIFF3/BIFF4. */
     457             : static const sal_Int32 spnDefColors3[] =
     458             : {
     459             : /*  0 */    PALETTE_EGA_COLORS_LIGHT,
     460             : /*  8 */    PALETTE_EGA_COLORS_LIGHT,
     461             : /* 16 */    PALETTE_EGA_COLORS_DARK
     462             : };
     463             : 
     464             : /** Default color table for BIFF5. */
     465             : static const sal_Int32 spnDefColors5[] =
     466             : {
     467             : /*  0 */    PALETTE_EGA_COLORS_LIGHT,
     468             : /*  8 */    PALETTE_EGA_COLORS_LIGHT,
     469             : /* 16 */    PALETTE_EGA_COLORS_DARK,
     470             : /* 24 */    0x8080FF, 0x802060, 0xFFFFC0, 0xA0E0E0, 0x600080, 0xFF8080, 0x0080C0, 0xC0C0FF,
     471             : /* 32 */    0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
     472             : /* 40 */    0x00CFFF, 0x69FFFF, 0xE0FFE0, 0xFFFF80, 0xA6CAF0, 0xDD9CB3, 0xB38FEE, 0xE3E3E3,
     473             : /* 48 */    0x2A6FF9, 0x3FB8CD, 0x488436, 0x958C41, 0x8E5E42, 0xA0627A, 0x624FAC, 0x969696,
     474             : /* 56 */    0x1D2FBE, 0x286676, 0x004500, 0x453E01, 0x6A2813, 0x85396A, 0x4A3285, 0x424242
     475             : };
     476             : 
     477             : /** Default color table for BIFF8/BIFF12/OOXML. */
     478             : static const sal_Int32 spnDefColors8[] =
     479             : {
     480             : /*  0 */    PALETTE_EGA_COLORS_LIGHT,
     481             : /*  8 */    PALETTE_EGA_COLORS_LIGHT,
     482             : /* 16 */    PALETTE_EGA_COLORS_DARK,
     483             : /* 24 */    0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
     484             : /* 32 */    0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
     485             : /* 40 */    0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
     486             : /* 48 */    0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
     487             : /* 56 */    0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
     488             : };
     489             : 
     490             : #undef PALETTE_EGA_COLORS_LIGHT
     491             : #undef PALETTE_EGA_COLORS_DARK
     492             : 
     493             : } // namespace
     494             : 
     495             : // ----------------------------------------------------------------------------
     496             : 
     497          11 : ColorPalette::ColorPalette( const WorkbookHelper& rHelper ) :
     498          11 :     WorkbookHelper( rHelper )
     499             : {
     500             :     // default colors
     501          11 :     switch( getFilterType() )
     502             :     {
     503             :         case FILTER_OOXML:
     504          11 :             maColors.insert( maColors.begin(), spnDefColors8, STATIC_ARRAY_END( spnDefColors8 ) );
     505          11 :             mnAppendIndex = OOX_COLOR_USEROFFSET;
     506          11 :         break;
     507             :         case FILTER_BIFF:
     508           0 :             switch( getBiff() )
     509             :             {
     510           0 :                 case BIFF2: maColors.insert( maColors.begin(), spnDefColors2, STATIC_ARRAY_END( spnDefColors2 ) );  break;
     511             :                 case BIFF3:
     512           0 :                 case BIFF4: maColors.insert( maColors.begin(), spnDefColors3, STATIC_ARRAY_END( spnDefColors3 ) );  break;
     513           0 :                 case BIFF5: maColors.insert( maColors.begin(), spnDefColors5, STATIC_ARRAY_END( spnDefColors5 ) );  break;
     514           0 :                 case BIFF8: maColors.insert( maColors.begin(), spnDefColors8, STATIC_ARRAY_END( spnDefColors8 ) );  break;
     515           0 :                 case BIFF_UNKNOWN: break;
     516             :             }
     517           0 :             mnAppendIndex = BIFF_COLOR_USEROFFSET;
     518           0 :         break;
     519           0 :         case FILTER_UNKNOWN: break;
     520             :     }
     521          11 : }
     522             : 
     523          56 : void ColorPalette::importPaletteColor( const AttributeList& rAttribs )
     524             : {
     525          56 :     appendColor( rAttribs.getIntegerHex( XML_rgb, API_RGB_WHITE ) );
     526          56 : }
     527             : 
     528           0 : void ColorPalette::importPaletteColor( SequenceInputStream& rStrm )
     529             : {
     530           0 :     sal_Int32 nRgb = lclReadRgbColor( rStrm );
     531           0 :     appendColor( nRgb & 0xFFFFFF );
     532           0 : }
     533             : 
     534          66 : sal_Int32 ColorPalette::getColor( sal_Int32 nPaletteIdx ) const
     535             : {
     536          66 :     sal_Int32 nColor = API_RGB_TRANSPARENT;
     537          66 :     if( const sal_Int32* pnPaletteColor = ContainerHelper::getVectorElement( maColors, nPaletteIdx ) )
     538             :     {
     539           0 :         nColor = *pnPaletteColor;
     540             :     }
     541          66 :     else switch( nPaletteIdx )
     542             :     {
     543             :         case OOX_COLOR_WINDOWTEXT3:
     544             :         case OOX_COLOR_WINDOWTEXT:
     545          55 :         case OOX_COLOR_CHWINDOWTEXT:    nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_windowText );   break;
     546             :         case OOX_COLOR_WINDOWBACK3:
     547             :         case OOX_COLOR_WINDOWBACK:
     548          11 :         case OOX_COLOR_CHWINDOWBACK:    nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_window );       break;
     549           0 :         case OOX_COLOR_BUTTONBACK:      nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_btnFace );      break;
     550           0 :         case OOX_COLOR_CHBORDERAUTO:    nColor = API_RGB_BLACK; /* really always black? */                              break;
     551           0 :         case OOX_COLOR_NOTEBACK:        nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoBk );       break;
     552           0 :         case OOX_COLOR_NOTETEXT:        nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoText );     break;
     553           0 :         case OOX_COLOR_FONTAUTO:        nColor = API_RGB_TRANSPARENT;                                                   break;
     554             :         default:                        OSL_FAIL( "ColorPalette::getColor - unknown color index" );
     555             :     }
     556          66 :     return nColor;
     557             : }
     558             : 
     559          56 : void ColorPalette::appendColor( sal_Int32 nRGBValue )
     560             : {
     561          56 :     if( mnAppendIndex < maColors.size() )
     562          56 :         maColors[ mnAppendIndex ] = nRGBValue;
     563             :     else
     564           0 :         maColors.push_back( nRGBValue );
     565          56 :     ++mnAppendIndex;
     566          56 : }
     567             : 
     568             : // ============================================================================
     569             : 
     570             : namespace {
     571             : 
     572         312 : void lclSetFontName( ApiScriptFontName& rFontName, const FontDescriptor& rFontDesc, bool bHasGlyphs )
     573             : {
     574         312 :     if( bHasGlyphs )
     575             :     {
     576         117 :         rFontName.maName = rFontDesc.Name;
     577         117 :         rFontName.mnFamily = rFontDesc.Family;
     578             :         // API font descriptor contains rtl_TextEncoding constants
     579         117 :         rFontName.mnTextEnc = rFontDesc.CharSet;
     580             :     }
     581             :     else
     582             :     {
     583         195 :         rFontName = ApiScriptFontName();
     584             :     }
     585         312 : }
     586             : 
     587             : } // namespace
     588             : 
     589             : // ----------------------------------------------------------------------------
     590             : 
     591          22 : FontModel::FontModel() :
     592             :     mnScheme( XML_none ),
     593             :     mnFamily( OOX_FONTFAMILY_NONE ),
     594             :     mnCharSet( WINDOWS_CHARSET_DEFAULT ),
     595             :     mfHeight( 0.0 ),
     596             :     mnUnderline( XML_none ),
     597             :     mnEscapement( XML_baseline ),
     598             :     mbBold( false ),
     599             :     mbItalic( false ),
     600             :     mbStrikeout( false ),
     601             :     mbOutline( false ),
     602          22 :     mbShadow( false )
     603             : {
     604          22 : }
     605             : 
     606           0 : void FontModel::setBiff12Scheme( sal_uInt8 nScheme )
     607             : {
     608             :     static const sal_Int32 spnSchemes[] = { XML_none, XML_major, XML_minor };
     609           0 :     mnScheme = STATIC_ARRAY_SELECT( spnSchemes, nScheme, XML_none );
     610           0 : }
     611             : 
     612           0 : void FontModel::setBiffHeight( sal_uInt16 nHeight )
     613             : {
     614           0 :     mfHeight = nHeight / 20.0;  // convert twips to points
     615           0 : }
     616             : 
     617           0 : void FontModel::setBiffWeight( sal_uInt16 nWeight )
     618             : {
     619           0 :     mbBold = nWeight >= BIFF_FONTWEIGHT_BOLD;
     620           0 : }
     621             : 
     622           0 : void FontModel::setBiffUnderline( sal_uInt16 nUnderline )
     623             : {
     624           0 :     switch( nUnderline )
     625             :     {
     626           0 :         case BIFF_FONTUNDERL_NONE:          mnUnderline = XML_none;             break;
     627           0 :         case BIFF_FONTUNDERL_SINGLE:        mnUnderline = XML_single;           break;
     628           0 :         case BIFF_FONTUNDERL_DOUBLE:        mnUnderline = XML_double;           break;
     629           0 :         case BIFF_FONTUNDERL_SINGLE_ACC:    mnUnderline = XML_singleAccounting; break;
     630           0 :         case BIFF_FONTUNDERL_DOUBLE_ACC:    mnUnderline = XML_doubleAccounting; break;
     631           0 :         default:                            mnUnderline = XML_none;
     632             :     }
     633           0 : }
     634             : 
     635           0 : void FontModel::setBiffEscapement( sal_uInt16 nEscapement )
     636             : {
     637             :     static const sal_Int32 spnEscapes[] = { XML_baseline, XML_superscript, XML_subscript };
     638           0 :     mnEscapement = STATIC_ARRAY_SELECT( spnEscapes, nEscapement, XML_baseline );
     639           0 : }
     640             : 
     641             : // ----------------------------------------------------------------------------
     642             : 
     643         104 : ApiFontUsedFlags::ApiFontUsedFlags( bool bAllUsed ) :
     644             :     mbNameUsed( bAllUsed ),
     645             :     mbColorUsed( bAllUsed ),
     646             :     mbSchemeUsed( bAllUsed ),
     647             :     mbHeightUsed( bAllUsed ),
     648             :     mbUnderlineUsed( bAllUsed ),
     649             :     mbEscapementUsed( bAllUsed ),
     650             :     mbWeightUsed( bAllUsed ),
     651             :     mbPostureUsed( bAllUsed ),
     652             :     mbStrikeoutUsed( bAllUsed ),
     653             :     mbOutlineUsed( bAllUsed ),
     654         104 :     mbShadowUsed( bAllUsed )
     655             : {
     656         104 : }
     657             : 
     658             : // ----------------------------------------------------------------------------
     659             : 
     660         507 : ApiScriptFontName::ApiScriptFontName() :
     661             :     mnFamily( ::com::sun::star::awt::FontFamily::DONTKNOW ),
     662         507 :     mnTextEnc( RTL_TEXTENCODING_DONTKNOW )
     663             : {
     664         507 : }
     665             : 
     666             : // ----------------------------------------------------------------------------
     667             : 
     668         104 : ApiFontData::ApiFontData() :
     669             :     maDesc(
     670             :         "Calibri",
     671             :         220,                                            // height 11 points
     672             :         0,
     673             :         OUString(),
     674             :         ::com::sun::star::awt::FontFamily::DONTKNOW,
     675             :         RTL_TEXTENCODING_DONTKNOW,
     676             :         ::com::sun::star::awt::FontPitch::DONTKNOW,
     677             :         100.0,
     678             :         ::com::sun::star::awt::FontWeight::NORMAL,
     679             :         ::com::sun::star::awt::FontSlant_NONE,
     680             :         ::com::sun::star::awt::FontUnderline::NONE,
     681             :         ::com::sun::star::awt::FontStrikeout::NONE,
     682             :         0.0,
     683             :         sal_False,
     684             :         sal_False,
     685             :         ::com::sun::star::awt::FontType::DONTKNOW ),
     686             :     mnColor( API_RGB_TRANSPARENT ),
     687             :     mnEscapement( API_ESCAPE_NONE ),
     688             :     mnEscapeHeight( API_ESCAPEHEIGHT_NONE ),
     689             :     mbOutline( false ),
     690         104 :     mbShadow( false )
     691             : {
     692         104 :     maLatinFont.maName = maDesc.Name;
     693         104 : }
     694             : 
     695             : // ============================================================================
     696             : 
     697          66 : Font::Font( const WorkbookHelper& rHelper, bool bDxf ) :
     698             :     WorkbookHelper( rHelper ),
     699          66 :     maModel( rHelper.getTheme().getDefaultFontModel() ),
     700          66 :     maUsedFlags( !bDxf ),
     701         198 :     mbDxf( bDxf )
     702             : {
     703          66 : }
     704             : 
     705          38 : Font::Font( const WorkbookHelper& rHelper, const FontModel& rModel ) :
     706             :     WorkbookHelper( rHelper ),
     707             :     maModel( rModel ),
     708             :     maUsedFlags( true ),
     709          38 :     mbDxf( false )
     710             : {
     711          38 : }
     712             : 
     713         265 : void Font::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs )
     714             : {
     715         265 :     const FontModel& rDefModel = getTheme().getDefaultFontModel();
     716         265 :     switch( nElement )
     717             :     {
     718             :         case XLS_TOKEN( name ):     // when in <font> element
     719             :         case XLS_TOKEN( rFont ):    // when in <rPr> element
     720          66 :             if( rAttribs.hasAttribute( XML_val ) )
     721             :             {
     722          66 :                 maModel.maName = rAttribs.getXString( XML_val, OUString() );
     723          66 :                 maUsedFlags.mbNameUsed = true;
     724             :             }
     725          66 :         break;
     726             :         case XLS_TOKEN( scheme ):
     727           3 :             maModel.mnScheme = rAttribs.getToken( XML_val, rDefModel.mnScheme );
     728           3 :         break;
     729             :         case XLS_TOKEN( family ):
     730          66 :             maModel.mnFamily = rAttribs.getInteger( XML_val, rDefModel.mnFamily );
     731          66 :         break;
     732             :         case XLS_TOKEN( charset ):
     733          34 :             maModel.mnCharSet = rAttribs.getInteger( XML_val, rDefModel.mnCharSet );
     734          34 :         break;
     735             :         case XLS_TOKEN( sz ):
     736          66 :             maModel.mfHeight = rAttribs.getDouble( XML_val, rDefModel.mfHeight );
     737          66 :             maUsedFlags.mbHeightUsed = true;
     738          66 :         break;
     739             :         case XLS_TOKEN( color ):
     740          18 :             maModel.maColor.importColor( rAttribs );
     741          18 :             maUsedFlags.mbColorUsed = true;
     742          18 :         break;
     743             :         case XLS_TOKEN( u ):
     744           3 :             maModel.mnUnderline = rAttribs.getToken( XML_val, XML_single );
     745           3 :             maUsedFlags.mbUnderlineUsed = true;
     746           3 :         break;
     747             :         case XLS_TOKEN( vertAlign ):
     748           0 :             maModel.mnEscapement = rAttribs.getToken( XML_val, XML_baseline );
     749           0 :             maUsedFlags.mbEscapementUsed = true;
     750           0 :         break;
     751             :         case XLS_TOKEN( b ):
     752           4 :             maModel.mbBold = rAttribs.getBool( XML_val, true );
     753           4 :             maUsedFlags.mbWeightUsed = true;
     754           4 :         break;
     755             :         case XLS_TOKEN( i ):
     756           4 :             maModel.mbItalic = rAttribs.getBool( XML_val, true );
     757           4 :             maUsedFlags.mbPostureUsed = true;
     758           4 :         break;
     759             :         case XLS_TOKEN( strike ):
     760           1 :             maModel.mbStrikeout = rAttribs.getBool( XML_val, true );
     761           1 :             maUsedFlags.mbStrikeoutUsed = true;
     762           1 :         break;
     763             :         case XLS_TOKEN( outline ):
     764           0 :             maModel.mbOutline = rAttribs.getBool( XML_val, true );
     765           0 :             maUsedFlags.mbOutlineUsed = true;
     766           0 :         break;
     767             :         case XLS_TOKEN( shadow ):
     768           0 :             maModel.mbShadow = rAttribs.getBool( XML_val, true );
     769           0 :             maUsedFlags.mbShadowUsed = true;
     770           0 :         break;
     771             :     }
     772         265 : }
     773             : 
     774           0 : void Font::importFont( SequenceInputStream& rStrm )
     775             : {
     776             :     OSL_ENSURE( !mbDxf, "Font::importFont - unexpected conditional formatting flag" );
     777             : 
     778             :     sal_uInt16 nHeight, nFlags, nWeight, nEscapement;
     779             :     sal_uInt8 nUnderline, nFamily, nCharSet, nScheme;
     780           0 :     rStrm >> nHeight >> nFlags >> nWeight >> nEscapement >> nUnderline >> nFamily >> nCharSet;
     781           0 :     rStrm.skip( 1 );
     782           0 :     rStrm >> maModel.maColor >> nScheme >> maModel.maName;
     783             : 
     784             :     // equal constants in all BIFFs for weight, underline, and escapement
     785           0 :     maModel.setBiff12Scheme( nScheme );
     786           0 :     maModel.setBiffHeight( nHeight );
     787           0 :     maModel.setBiffWeight( nWeight );
     788           0 :     maModel.setBiffUnderline( nUnderline );
     789           0 :     maModel.setBiffEscapement( nEscapement );
     790           0 :     maModel.mnFamily    = nFamily;
     791           0 :     maModel.mnCharSet   = nCharSet;
     792             :     // equal flags in all BIFFs
     793           0 :     maModel.mbItalic    = getFlag( nFlags, BIFF_FONTFLAG_ITALIC );
     794           0 :     maModel.mbStrikeout = getFlag( nFlags, BIFF_FONTFLAG_STRIKEOUT );
     795           0 :     maModel.mbOutline   = getFlag( nFlags, BIFF_FONTFLAG_OUTLINE );
     796           0 :     maModel.mbShadow    = getFlag( nFlags, BIFF_FONTFLAG_SHADOW );
     797           0 : }
     798             : 
     799           0 : void Font::importDxfName( SequenceInputStream& rStrm )
     800             : {
     801             :     OSL_ENSURE( mbDxf, "Font::importDxfName - missing conditional formatting flag" );
     802           0 :     maModel.maName = BiffHelper::readString( rStrm, false );
     803           0 :     maUsedFlags.mbColorUsed = true;
     804           0 : }
     805             : 
     806           0 : void Font::importDxfColor( SequenceInputStream& rStrm )
     807             : {
     808             :     OSL_ENSURE( mbDxf, "Font::importDxfColor - missing conditional formatting flag" );
     809           0 :     rStrm >> maModel.maColor;
     810           0 :     maUsedFlags.mbColorUsed = true;
     811           0 : }
     812             : 
     813           0 : void Font::importDxfScheme( SequenceInputStream& rStrm )
     814             : {
     815             :     OSL_ENSURE( mbDxf, "Font::importDxfScheme - missing conditional formatting flag" );
     816           0 :     maModel.setBiff12Scheme( rStrm.readuInt8() );
     817           0 :     maUsedFlags.mbSchemeUsed = true;
     818           0 : }
     819             : 
     820           0 : void Font::importDxfHeight( SequenceInputStream& rStrm )
     821             : {
     822             :     OSL_ENSURE( mbDxf, "Font::importDxfHeight - missing conditional formatting flag" );
     823           0 :     maModel.setBiffHeight( rStrm.readuInt16() );
     824           0 :     maUsedFlags.mbHeightUsed = true;
     825           0 : }
     826             : 
     827           0 : void Font::importDxfWeight( SequenceInputStream& rStrm )
     828             : {
     829             :     OSL_ENSURE( mbDxf, "Font::importDxfWeight - missing conditional formatting flag" );
     830           0 :     maModel.setBiffWeight( rStrm.readuInt16() );
     831           0 :     maUsedFlags.mbWeightUsed = true;
     832           0 : }
     833             : 
     834           0 : void Font::importDxfUnderline( SequenceInputStream& rStrm )
     835             : {
     836             :     OSL_ENSURE( mbDxf, "Font::importDxfUnderline - missing conditional formatting flag" );
     837           0 :     maModel.setBiffUnderline( rStrm.readuInt16() );
     838           0 :     maUsedFlags.mbUnderlineUsed = true;
     839           0 : }
     840             : 
     841           0 : void Font::importDxfEscapement( SequenceInputStream& rStrm )
     842             : {
     843             :     OSL_ENSURE( mbDxf, "Font::importDxfEscapement - missing conditional formatting flag" );
     844           0 :     maModel.setBiffEscapement( rStrm.readuInt16() );
     845           0 :     maUsedFlags.mbEscapementUsed = true;
     846           0 : }
     847             : 
     848           0 : void Font::importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm )
     849             : {
     850             :     OSL_ENSURE( mbDxf, "Font::importDxfFlag - missing conditional formatting flag" );
     851           0 :     bool bFlag = rStrm.readuInt8() != 0;
     852           0 :     switch( nElement )
     853             :     {
     854             :         case XML_i:
     855           0 :             maModel.mbItalic = bFlag;
     856           0 :             maUsedFlags.mbPostureUsed = true;
     857           0 :         break;
     858             :         case XML_strike:
     859           0 :             maModel.mbStrikeout = bFlag;
     860           0 :             maUsedFlags.mbStrikeoutUsed = true;
     861           0 :         break;
     862             :         case XML_outline:
     863           0 :             maModel.mbOutline = bFlag;
     864           0 :             maUsedFlags.mbOutlineUsed = true;
     865           0 :         break;
     866             :         case XML_shadow:
     867           0 :             maModel.mbShadow = bFlag;
     868           0 :             maUsedFlags.mbShadowUsed = true;
     869           0 :         break;
     870             :         default:
     871             :             OSL_FAIL( "Font::importDxfFlag - unexpected element identifier" );
     872             :     }
     873           0 : }
     874             : 
     875         104 : void Font::finalizeImport()
     876             : {
     877             :     namespace cssawt = ::com::sun::star::awt;
     878             : 
     879             :     // font name
     880         104 :     maApiData.maDesc.Name = maModel.maName;
     881             : 
     882             :     // font family
     883         104 :     switch( maModel.mnFamily )
     884             :     {
     885          21 :         case OOX_FONTFAMILY_NONE:           maApiData.maDesc.Family = cssawt::FontFamily::DONTKNOW;     break;
     886           0 :         case OOX_FONTFAMILY_ROMAN:          maApiData.maDesc.Family = cssawt::FontFamily::ROMAN;        break;
     887          83 :         case OOX_FONTFAMILY_SWISS:          maApiData.maDesc.Family = cssawt::FontFamily::SWISS;        break;
     888           0 :         case OOX_FONTFAMILY_MODERN:         maApiData.maDesc.Family = cssawt::FontFamily::MODERN;       break;
     889           0 :         case OOX_FONTFAMILY_SCRIPT:         maApiData.maDesc.Family = cssawt::FontFamily::SCRIPT;       break;
     890           0 :         case OOX_FONTFAMILY_DECORATIVE:     maApiData.maDesc.Family = cssawt::FontFamily::DECORATIVE;   break;
     891             :     }
     892             : 
     893             :     // character set (API font descriptor uses rtl_TextEncoding in member CharSet!)
     894         104 :     if( (0 <= maModel.mnCharSet) && (maModel.mnCharSet <= SAL_MAX_UINT8) )
     895             :         maApiData.maDesc.CharSet = static_cast< sal_Int16 >(
     896         104 :             rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( maModel.mnCharSet ) ) );
     897             : 
     898             :     // color, height, weight, slant, strikeout, outline, shadow
     899         104 :     maApiData.mnColor          = maModel.maColor.getColor( getBaseFilter().getGraphicHelper() );
     900         104 :     maApiData.maDesc.Height    = static_cast< sal_Int16 >( maModel.mfHeight * 20.0 );
     901         104 :     maApiData.maDesc.Weight    = maModel.mbBold ? cssawt::FontWeight::BOLD : cssawt::FontWeight::NORMAL;
     902         104 :     maApiData.maDesc.Slant     = maModel.mbItalic ? cssawt::FontSlant_ITALIC : cssawt::FontSlant_NONE;
     903         104 :     maApiData.maDesc.Strikeout = maModel.mbStrikeout ? cssawt::FontStrikeout::SINGLE : cssawt::FontStrikeout::NONE;
     904         104 :     maApiData.mbOutline        = maModel.mbOutline;
     905         104 :     maApiData.mbShadow         = maModel.mbShadow;
     906             : 
     907             :     // underline
     908         104 :     switch( maModel.mnUnderline )
     909             :     {
     910           0 :         case XML_double:            maApiData.maDesc.Underline = cssawt::FontUnderline::DOUBLE; break;
     911           0 :         case XML_doubleAccounting:  maApiData.maDesc.Underline = cssawt::FontUnderline::DOUBLE; break;
     912         101 :         case XML_none:              maApiData.maDesc.Underline = cssawt::FontUnderline::NONE;   break;
     913           3 :         case XML_single:            maApiData.maDesc.Underline = cssawt::FontUnderline::SINGLE; break;
     914           0 :         case XML_singleAccounting:  maApiData.maDesc.Underline = cssawt::FontUnderline::SINGLE; break;
     915             :     }
     916             : 
     917             :     // escapement
     918         104 :     switch( maModel.mnEscapement )
     919             :     {
     920             :         case XML_baseline:
     921         104 :             maApiData.mnEscapement = API_ESCAPE_NONE;
     922         104 :             maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_NONE;
     923         104 :         break;
     924             :         case XML_superscript:
     925           0 :             maApiData.mnEscapement = API_ESCAPE_SUPERSCRIPT;
     926           0 :             maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_DEFAULT;
     927           0 :         break;
     928             :         case XML_subscript:
     929           0 :             maApiData.mnEscapement = API_ESCAPE_SUBSCRIPT;
     930           0 :             maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_DEFAULT;
     931           0 :         break;
     932             :     }
     933             : 
     934             :     // supported script types
     935         104 :     if( maUsedFlags.mbNameUsed )
     936             :     {
     937         104 :         PropertySet aDocProps( getDocument() );
     938         104 :         Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
     939         104 :         if( xDevice.is() )
     940             :         {
     941         104 :             Reference< XFont2 > xFont( xDevice->getFont( maApiData.maDesc ), UNO_QUERY );
     942         104 :             if( xFont.is() )
     943             :             {
     944             :                 // #91658# CJK fonts
     945             :                 bool bHasAsian =
     946         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x3041 ) ) ) ||    // 3040-309F: Hiragana
     947         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x30A1 ) ) ) ||    // 30A0-30FF: Katakana
     948         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x3111 ) ) ) ||    // 3100-312F: Bopomofo
     949         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x3131 ) ) ) ||    // 3130-318F: Hangul Compatibility Jamo
     950         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x3301 ) ) ) ||    // 3300-33FF: CJK Compatibility
     951         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x3401 ) ) ) ||    // 3400-4DBF: CJK Unified Ideographs Extension A
     952         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x4E01 ) ) ) ||    // 4E00-9FAF: CJK Unified Ideographs
     953         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x7E01 ) ) ) ||    // 4E00-9FAF: CJK unified ideographs
     954         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xA001 ) ) ) ||    // A001-A48F: Yi Syllables
     955         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xAC01 ) ) ) ||    // AC00-D7AF: Hangul Syllables
     956         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xCC01 ) ) ) ||    // AC00-D7AF: Hangul Syllables
     957         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xF901 ) ) ) ||    // F900-FAFF: CJK Compatibility Ideographs
     958        2600 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xFF71 ) ) );      // FF00-FFEF: Halfwidth/Fullwidth Forms
     959             :                 // #113783# CTL fonts
     960             :                 bool bHasCmplx =
     961         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x05D1 ) ) ) ||    // 0590-05FF: Hebrew
     962         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x0631 ) ) ) ||    // 0600-06FF: Arabic
     963         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x0721 ) ) ) ||    // 0700-074F: Syriac
     964         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x0911 ) ) ) ||    // 0900-0DFF: Indic scripts
     965         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0x0E01 ) ) ) ||    // 0E00-0E7F: Thai
     966         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xFB21 ) ) ) ||    // FB1D-FB4F: Hebrew Presentation Forms
     967         286 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xFB51 ) ) ) ||    // FB50-FDFF: Arabic Presentation Forms-A
     968        1404 :                     xFont->hasGlyphs( OUString( sal_Unicode( 0xFE71 ) ) );      // FE70-FEFF: Arabic Presentation Forms-B
     969             :                 // Western fonts
     970             :                 bool bHasLatin =
     971         208 :                     (!bHasAsian && !bHasCmplx) ||
     972         312 :                     xFont->hasGlyphs( OUString( sal_Unicode( 'A' ) ) );
     973             : 
     974         104 :                 lclSetFontName( maApiData.maLatinFont, maApiData.maDesc, bHasLatin );
     975         104 :                 lclSetFontName( maApiData.maAsianFont, maApiData.maDesc, bHasAsian );
     976         104 :                 lclSetFontName( maApiData.maCmplxFont, maApiData.maDesc, bHasCmplx );
     977         104 :             }
     978         104 :         }
     979             :     }
     980         104 : }
     981             : 
     982          11 : const FontDescriptor& Font::getFontDescriptor() const
     983             : {
     984          11 :     return maApiData.maDesc;
     985             : }
     986             : 
     987          61 : bool Font::needsRichTextFormat() const
     988             : {
     989          61 :     return maApiData.mnEscapement != API_ESCAPE_NONE;
     990             : }
     991         178 : ::FontFamily lcl_getFontFamily( sal_Int32 nFamily )
     992             : {
     993             :     namespace cssawt = ::com::sun::star::awt;
     994             : 
     995         178 :     ::FontFamily eScFamily = FAMILY_DONTKNOW;
     996         178 :     switch( nFamily )
     997             :     {
     998             :         case cssawt::FontFamily::DONTKNOW:
     999          63 :             eScFamily = FAMILY_DONTKNOW;
    1000          63 :             break;
    1001             :         case cssawt::FontFamily::ROMAN:
    1002           0 :             eScFamily = FAMILY_ROMAN;
    1003           0 :             break;
    1004             :         case cssawt::FontFamily::SWISS:
    1005         115 :             eScFamily = FAMILY_SWISS;
    1006         115 :             break;
    1007             :         case cssawt::FontFamily::MODERN:
    1008           0 :             eScFamily = FAMILY_MODERN;
    1009           0 :             break;
    1010             :         case cssawt::FontFamily::SCRIPT:
    1011           0 :             eScFamily = FAMILY_SCRIPT;
    1012           0 :             break;
    1013             :         case cssawt::FontFamily::DECORATIVE:
    1014           0 :             eScFamily = FAMILY_DECORATIVE;
    1015           0 :             break;
    1016             :     }
    1017         178 :     return eScFamily;
    1018             : }
    1019             : 
    1020         164 : void Font::fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool bSkipPoolDefs ) const
    1021             : {
    1022             :     namespace cssawt = ::com::sun::star::awt;
    1023         164 :     if ( maUsedFlags.mbNameUsed )
    1024             :     {
    1025         164 :         if( !maApiData.maLatinFont.maName.isEmpty() )
    1026             :         {
    1027         164 :             rtl_TextEncoding eFontEnc = maApiData.maLatinFont.mnTextEnc;
    1028             :             SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maLatinFont.mnFamily ), maApiData.maLatinFont.maName, rtl::OUString(),
    1029         164 :                 PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
    1030             :         }
    1031         164 :         if( !maApiData.maAsianFont.maName.isEmpty() )
    1032             :         {
    1033           0 :             rtl_TextEncoding eFontEnc = maApiData.maAsianFont.mnTextEnc;
    1034             :             SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maAsianFont.mnFamily ), maApiData.maAsianFont.maName, rtl::OUString(),
    1035           0 :                 PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
    1036             :         }
    1037         164 :         if( !maApiData.maCmplxFont.maName.isEmpty() )
    1038             :         {
    1039          14 :             rtl_TextEncoding eFontEnc = maApiData.maCmplxFont.mnTextEnc;
    1040             :             SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maCmplxFont.mnFamily ), maApiData.maCmplxFont.maName, rtl::OUString(),
    1041          14 :                 PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
    1042             :         }
    1043             :     }
    1044             :     // font height
    1045         164 :     if( maUsedFlags.mbHeightUsed )
    1046             :     {
    1047             :         // leave in twips ?
    1048         164 :         SvxFontHeightItem aHeightItem( maApiData.maDesc.Height, 100, ATTR_FONT_HEIGHT );
    1049         164 :         ScfTools::PutItem( rItemSet, aHeightItem, ATTR_FONT_HEIGHT, bSkipPoolDefs );
    1050         164 :         ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs );
    1051         164 :         ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CTL_FONT_HEIGHT, bSkipPoolDefs );
    1052             :     }
    1053             :     // font weight
    1054         164 :     if( maUsedFlags.mbWeightUsed )
    1055             :     {
    1056         164 :         ::FontWeight fWeight = VCLUnoHelper::ConvertFontWeight( maApiData.maDesc.Weight );
    1057         164 :         SvxWeightItem aWeightItem( fWeight, ATTR_FONT_WEIGHT );
    1058         164 :         ScfTools::PutItem( rItemSet, aWeightItem, ATTR_FONT_WEIGHT, bSkipPoolDefs );
    1059         164 :         ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CTL_FONT_WEIGHT, bSkipPoolDefs );
    1060         164 :         ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CJK_FONT_WEIGHT, bSkipPoolDefs );
    1061             :     }
    1062             :     // font posture
    1063         164 :     if( maUsedFlags.mbPostureUsed )
    1064             :     {
    1065         164 :         SvxPostureItem aPostItem( ( maApiData.maDesc.Slant == cssawt::FontSlant_ITALIC ) ? ITALIC_NORMAL :  ITALIC_NONE,  ATTR_FONT_POSTURE);
    1066         164 :         ScfTools::PutItem( rItemSet, aPostItem, ATTR_FONT_POSTURE, bSkipPoolDefs );
    1067         164 :         ScfTools::PutItem( rItemSet, aPostItem, ATTR_CJK_FONT_POSTURE, bSkipPoolDefs );
    1068         164 :         ScfTools::PutItem( rItemSet, aPostItem, ATTR_CTL_FONT_POSTURE, bSkipPoolDefs );
    1069             :     }
    1070             :     // character color
    1071         164 :     if( maUsedFlags.mbColorUsed )
    1072             :     {
    1073         164 :         ScfTools::PutItem( rItemSet,SvxColorItem( maApiData.mnColor, ATTR_FONT_COLOR  ) , bSkipPoolDefs );
    1074             :     }
    1075             :     // underline style
    1076         164 :     if( maUsedFlags.mbUnderlineUsed )
    1077             :     {
    1078             :         ::FontUnderline eScUnderl;
    1079         164 :         if ( maApiData.maDesc.Underline == cssawt::FontUnderline::DOUBLE )
    1080           0 :             eScUnderl = UNDERLINE_DOUBLE;
    1081         164 :         else if ( maApiData.maDesc.Underline == cssawt::FontUnderline::SINGLE )
    1082           3 :             eScUnderl = UNDERLINE_SINGLE;
    1083             :         else
    1084         161 :             eScUnderl = UNDERLINE_NONE;
    1085         164 :         SvxUnderlineItem aUnderlItem( eScUnderl, ATTR_FONT_UNDERLINE );
    1086         164 :         ScfTools::PutItem( rItemSet, aUnderlItem, ATTR_FONT_UNDERLINE, bSkipPoolDefs );
    1087             :     }
    1088             :     // strike out style
    1089         164 :     if( maUsedFlags.mbStrikeoutUsed )
    1090             :     {
    1091         164 :         ScfTools::PutItem( rItemSet, SvxCrossedOutItem( maModel.mbStrikeout ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ), ATTR_FONT_CROSSEDOUT, bSkipPoolDefs );
    1092             :     }
    1093             : 
    1094             :     // outline style
    1095         164 :     if( maUsedFlags.mbOutlineUsed )
    1096             :     {
    1097         164 :         ScfTools::PutItem( rItemSet, SvxContourItem( maApiData.mbOutline, ATTR_FONT_CONTOUR ), ATTR_FONT_CONTOUR, bSkipPoolDefs );
    1098             :     }
    1099             : 
    1100             :     // shadow style
    1101         164 :     if( maUsedFlags.mbShadowUsed )
    1102             :     {
    1103         164 :         ScfTools::PutItem( rItemSet, SvxShadowedItem( maApiData.mbShadow, ATTR_FONT_SHADOWED ), ATTR_FONT_SHADOWED, bSkipPoolDefs );
    1104             :     }
    1105         164 :     if( maUsedFlags.mbEscapementUsed )
    1106             :     {
    1107         164 :         SvxEscapement eScEscapem = SVX_ESCAPEMENT_OFF;
    1108         164 :         if ( maApiData.mnEscapement == API_ESCAPE_SUPERSCRIPT )
    1109           0 :             eScEscapem = SVX_ESCAPEMENT_SUPERSCRIPT;
    1110         164 :         else if ( maApiData.mnEscapement == API_ESCAPE_SUBSCRIPT )
    1111           0 :             eScEscapem = SVX_ESCAPEMENT_SUBSCRIPT;
    1112         164 :         rItemSet.Put( SvxEscapementItem( eScEscapem, EE_CHAR_ESCAPEMENT ) );
    1113             :         if( ePropType == FONT_PROPTYPE_TEXT )
    1114             :         {
    1115             :            // #TODO handle EscapementHeight
    1116             :         }
    1117             :     }
    1118         164 : }
    1119             : 
    1120          71 : void Font::writeToPropertyMap( PropertyMap& rPropMap, FontPropertyType ePropType ) const
    1121             : {
    1122             :     // font name properties
    1123          71 :     if( maUsedFlags.mbNameUsed )
    1124             :     {
    1125          71 :         if( !maApiData.maLatinFont.maName.isEmpty() )
    1126             :         {
    1127          71 :             rPropMap[ PROP_CharFontName ]    <<= maApiData.maLatinFont.maName;
    1128          71 :             rPropMap[ PROP_CharFontFamily ]  <<= maApiData.maLatinFont.mnFamily;
    1129          71 :             rPropMap[ PROP_CharFontCharSet ] <<= maApiData.maLatinFont.mnTextEnc;
    1130             :         }
    1131          71 :         if( !maApiData.maAsianFont.maName.isEmpty() )
    1132             :         {
    1133           0 :             rPropMap[ PROP_CharFontNameAsian ]    <<= maApiData.maAsianFont.maName;
    1134           0 :             rPropMap[ PROP_CharFontFamilyAsian ]  <<= maApiData.maAsianFont.mnFamily;
    1135           0 :             rPropMap[ PROP_CharFontCharSetAsian ] <<= maApiData.maAsianFont.mnTextEnc;
    1136             :         }
    1137          71 :         if( !maApiData.maCmplxFont.maName.isEmpty() )
    1138             :         {
    1139          12 :             rPropMap[ PROP_CharFontNameComplex ]    <<= maApiData.maCmplxFont.maName;
    1140          12 :             rPropMap[ PROP_CharFontFamilyComplex ]  <<= maApiData.maCmplxFont.mnFamily;
    1141          12 :             rPropMap[ PROP_CharFontCharSetComplex ] <<= maApiData.maCmplxFont.mnTextEnc;
    1142             :         }
    1143             :     }
    1144             :     // font height
    1145          71 :     if( maUsedFlags.mbHeightUsed )
    1146             :     {
    1147          71 :         float fHeight = static_cast< float >( maApiData.maDesc.Height / 20.0 ); // twips to points
    1148          71 :         rPropMap[ PROP_CharHeight ] <<= fHeight;
    1149          71 :         rPropMap[ PROP_CharHeightAsian ] <<= fHeight;
    1150          71 :         rPropMap[ PROP_CharHeightComplex ] <<= fHeight;
    1151             :     }
    1152             :     // font weight
    1153          71 :     if( maUsedFlags.mbWeightUsed )
    1154             :     {
    1155          51 :         float fWeight = maApiData.maDesc.Weight;
    1156          51 :         rPropMap[ PROP_CharWeight ] <<= fWeight;
    1157          51 :         rPropMap[ PROP_CharWeightAsian ] <<= fWeight;
    1158          51 :         rPropMap[ PROP_CharWeightComplex ] <<= fWeight;
    1159             :     }
    1160             :     // font posture
    1161          71 :     if( maUsedFlags.mbPostureUsed )
    1162             :     {
    1163          51 :         rPropMap[ PROP_CharPosture ] <<= maApiData.maDesc.Slant;
    1164          51 :         rPropMap[ PROP_CharPostureAsian ] <<= maApiData.maDesc.Slant;
    1165          51 :         rPropMap[ PROP_CharPostureComplex ] <<= maApiData.maDesc.Slant;
    1166             :     }
    1167             :     // character color
    1168          71 :     if( maUsedFlags.mbColorUsed )
    1169          59 :         rPropMap[ PROP_CharColor ] <<= maApiData.mnColor;
    1170             :     // underline style
    1171          71 :     if( maUsedFlags.mbUnderlineUsed )
    1172          51 :         rPropMap[ PROP_CharUnderline ] <<= maApiData.maDesc.Underline;
    1173             :     // strike out style
    1174          71 :     if( maUsedFlags.mbStrikeoutUsed )
    1175          51 :         rPropMap[ PROP_CharStrikeout ] <<= maApiData.maDesc.Strikeout;
    1176             :     // outline style
    1177          71 :     if( maUsedFlags.mbOutlineUsed )
    1178          51 :         rPropMap[ PROP_CharContoured ] <<= maApiData.mbOutline;
    1179             :     // shadow style
    1180          71 :     if( maUsedFlags.mbShadowUsed )
    1181          51 :         rPropMap[ PROP_CharShadowed ] <<= maApiData.mbShadow;
    1182             :     // escapement
    1183          71 :     if( maUsedFlags.mbEscapementUsed )
    1184             :     {
    1185          51 :         rPropMap[ PROP_CharEscapement ] <<= maApiData.mnEscapement;
    1186          51 :         if( ePropType == FONT_PROPTYPE_TEXT )
    1187          40 :             rPropMap[ PROP_CharEscapementHeight ] <<= maApiData.mnEscapeHeight;
    1188             :     }
    1189          71 : }
    1190             : 
    1191          40 : void Font::writeToPropertySet( PropertySet& rPropSet, FontPropertyType ePropType ) const
    1192             : {
    1193          40 :     PropertyMap aPropMap;
    1194          40 :     writeToPropertyMap( aPropMap, ePropType );
    1195          40 :     rPropSet.setProperties( aPropMap );
    1196          40 : }
    1197             : 
    1198             : // ============================================================================
    1199             : 
    1200         186 : AlignmentModel::AlignmentModel() :
    1201             :     mnHorAlign( XML_general ),
    1202             :     mnVerAlign( XML_bottom ),
    1203             :     mnTextDir( OOX_XF_TEXTDIR_CONTEXT ),
    1204             :     mnRotation( OOX_XF_ROTATION_NONE ),
    1205             :     mnIndent( OOX_XF_INDENT_NONE ),
    1206             :     mbWrapText( false ),
    1207             :     mbShrink( false ),
    1208         186 :     mbJustLastLine( false )
    1209             : {
    1210         186 : }
    1211             : 
    1212           0 : void AlignmentModel::setBiffHorAlign( sal_uInt8 nHorAlign )
    1213             : {
    1214             :     static const sal_Int32 spnHorAligns[] = {
    1215             :         XML_general, XML_left, XML_center, XML_right,
    1216             :         XML_fill, XML_justify, XML_centerContinuous, XML_distributed };
    1217           0 :     mnHorAlign = STATIC_ARRAY_SELECT( spnHorAligns, nHorAlign, XML_general );
    1218           0 : }
    1219             : 
    1220           0 : void AlignmentModel::setBiffVerAlign( sal_uInt8 nVerAlign )
    1221             : {
    1222             :     static const sal_Int32 spnVerAligns[] = {
    1223             :         XML_top, XML_center, XML_bottom, XML_justify, XML_distributed };
    1224           0 :     mnVerAlign = STATIC_ARRAY_SELECT( spnVerAligns, nVerAlign, XML_bottom );
    1225           0 : }
    1226             : 
    1227             : // ----------------------------------------------------------------------------
    1228             : 
    1229         186 : ApiAlignmentData::ApiAlignmentData() :
    1230             :     meHorJustify( ::com::sun::star::table::CellHoriJustify_STANDARD ),
    1231             :     mnHorJustifyMethod( ::com::sun::star::table::CellJustifyMethod::AUTO ),
    1232             :     mnVerJustify( ::com::sun::star::table::CellVertJustify2::STANDARD ),
    1233             :     mnVerJustifyMethod( ::com::sun::star::table::CellJustifyMethod::AUTO ),
    1234             :     meOrientation( ::com::sun::star::table::CellOrientation_STANDARD ),
    1235             :     mnRotation( 0 ),
    1236             :     mnWritingMode( ::com::sun::star::text::WritingMode2::PAGE ),
    1237             :     mnIndent( 0 ),
    1238             :     mbWrapText( false ),
    1239         186 :     mbShrink( false )
    1240             : {
    1241         186 : }
    1242             : 
    1243          39 : bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight )
    1244             : {
    1245             :     return
    1246             :         (rLeft.meHorJustify  == rRight.meHorJustify) &&
    1247             :         (rLeft.mnHorJustifyMethod == rRight.mnHorJustifyMethod) &&
    1248             :         (rLeft.mnVerJustify  == rRight.mnVerJustify) &&
    1249             :         (rLeft.mnVerJustifyMethod == rRight.mnVerJustifyMethod) &&
    1250             :         (rLeft.meOrientation == rRight.meOrientation) &&
    1251             :         (rLeft.mnRotation    == rRight.mnRotation) &&
    1252             :         (rLeft.mnWritingMode == rRight.mnWritingMode) &&
    1253             :         (rLeft.mnIndent      == rRight.mnIndent) &&
    1254             :         (rLeft.mbWrapText    == rRight.mbWrapText) &&
    1255          39 :         (rLeft.mbShrink      == rRight.mbShrink);
    1256             : }
    1257             : 
    1258             : // ============================================================================
    1259             : 
    1260         186 : Alignment::Alignment( const WorkbookHelper& rHelper ) :
    1261         186 :     WorkbookHelper( rHelper )
    1262             : {
    1263         186 : }
    1264             : 
    1265          35 : void Alignment::importAlignment( const AttributeList& rAttribs )
    1266             : {
    1267          35 :     maModel.mnHorAlign     = rAttribs.getToken( XML_horizontal, XML_general );
    1268          35 :     maModel.mnVerAlign     = rAttribs.getToken( XML_vertical, XML_bottom );
    1269          35 :     maModel.mnTextDir      = rAttribs.getInteger( XML_readingOrder, OOX_XF_TEXTDIR_CONTEXT );
    1270          35 :     maModel.mnRotation     = rAttribs.getInteger( XML_textRotation, OOX_XF_ROTATION_NONE );
    1271          35 :     maModel.mnIndent       = rAttribs.getInteger( XML_indent, OOX_XF_INDENT_NONE );
    1272          35 :     maModel.mbWrapText     = rAttribs.getBool( XML_wrapText, false );
    1273          35 :     maModel.mbShrink       = rAttribs.getBool( XML_shrinkToFit, false );
    1274          35 :     maModel.mbJustLastLine = rAttribs.getBool( XML_justifyLastLine, false );
    1275          35 : }
    1276             : 
    1277           0 : void Alignment::setBiff12Data( sal_uInt32 nFlags )
    1278             : {
    1279           0 :     maModel.setBiffHorAlign( extractValue< sal_uInt8 >( nFlags, 16, 3 ) );
    1280           0 :     maModel.setBiffVerAlign( extractValue< sal_uInt8 >( nFlags, 19, 3 ) );
    1281           0 :     maModel.mnTextDir      = extractValue< sal_Int32 >( nFlags, 26, 2 );
    1282           0 :     maModel.mnRotation     = extractValue< sal_Int32 >( nFlags, 0, 8 );
    1283           0 :     maModel.mnIndent       = extractValue< sal_uInt8 >( nFlags, 8, 8 );
    1284           0 :     maModel.mbWrapText     = getFlag( nFlags, BIFF12_XF_WRAPTEXT );
    1285           0 :     maModel.mbShrink       = getFlag( nFlags, BIFF12_XF_SHRINK );
    1286           0 :     maModel.mbJustLastLine = getFlag( nFlags, BIFF12_XF_JUSTLASTLINE );
    1287           0 : }
    1288             : 
    1289         186 : void Alignment::finalizeImport()
    1290             : {
    1291             :     namespace csstab = ::com::sun::star::table;
    1292             :     namespace csstxt = ::com::sun::star::text;
    1293             : 
    1294             :     // horizontal alignment
    1295         186 :     switch( maModel.mnHorAlign )
    1296             :     {
    1297           5 :         case XML_center:            maApiData.meHorJustify = csstab::CellHoriJustify_CENTER;    break;
    1298           0 :         case XML_centerContinuous:  maApiData.meHorJustify = csstab::CellHoriJustify_CENTER;    break;
    1299           0 :         case XML_distributed:       maApiData.meHorJustify = csstab::CellHoriJustify_BLOCK;     break;
    1300           0 :         case XML_fill:              maApiData.meHorJustify = csstab::CellHoriJustify_REPEAT;    break;
    1301         179 :         case XML_general:           maApiData.meHorJustify = csstab::CellHoriJustify_STANDARD;  break;
    1302           1 :         case XML_justify:           maApiData.meHorJustify = csstab::CellHoriJustify_BLOCK;     break;
    1303           0 :         case XML_left:              maApiData.meHorJustify = csstab::CellHoriJustify_LEFT;      break;
    1304           1 :         case XML_right:             maApiData.meHorJustify = csstab::CellHoriJustify_RIGHT;     break;
    1305             :     }
    1306             : 
    1307         186 :     if (maModel.mnHorAlign == XML_distributed)
    1308           0 :         maApiData.mnHorJustifyMethod = csstab::CellJustifyMethod::DISTRIBUTE;
    1309             : 
    1310             :     // vertical alignment
    1311         186 :     switch( maModel.mnVerAlign )
    1312             :     {
    1313         184 :         case XML_bottom:        maApiData.mnVerJustify = csstab::CellVertJustify2::BOTTOM;    break;
    1314           2 :         case XML_center:        maApiData.mnVerJustify = csstab::CellVertJustify2::CENTER;    break;
    1315           0 :         case XML_distributed:   maApiData.mnVerJustify = csstab::CellVertJustify2::BLOCK;     break;
    1316           0 :         case XML_justify:       maApiData.mnVerJustify = csstab::CellVertJustify2::BLOCK;     break;
    1317           0 :         case XML_top:           maApiData.mnVerJustify = csstab::CellVertJustify2::TOP;       break;
    1318             :     }
    1319             : 
    1320         186 :     if (maModel.mnVerAlign == XML_distributed)
    1321           0 :         maApiData.mnVerJustifyMethod = csstab::CellJustifyMethod::DISTRIBUTE;
    1322             : 
    1323             :     /*  indentation: expressed as number of blocks of 3 space characters in
    1324             :         OOXML/BIFF12, and as multiple of 10 points in BIFF8. */
    1325         186 :     sal_Int32 nIndent = 0;
    1326         186 :     switch( getFilterType() )
    1327             :     {
    1328         186 :         case FILTER_OOXML:  nIndent = getUnitConverter().scaleToMm100( 3.0 * maModel.mnIndent, UNIT_SPACE );  break;
    1329           0 :         case FILTER_BIFF:   nIndent = getUnitConverter().scaleToMm100( 10.0 * maModel.mnIndent, UNIT_POINT ); break;
    1330           0 :         case FILTER_UNKNOWN: break;
    1331             :     }
    1332         186 :     if( (0 <= nIndent) && (nIndent <= SAL_MAX_INT16) )
    1333         186 :         maApiData.mnIndent = static_cast< sal_Int16 >( nIndent );
    1334             : 
    1335             :     // complex text direction
    1336         186 :     switch( maModel.mnTextDir )
    1337             :     {
    1338         186 :         case OOX_XF_TEXTDIR_CONTEXT:    maApiData.mnWritingMode = csstxt::WritingMode2::PAGE;   break;
    1339           0 :         case OOX_XF_TEXTDIR_LTR:        maApiData.mnWritingMode = csstxt::WritingMode2::LR_TB;  break;
    1340           0 :         case OOX_XF_TEXTDIR_RTL:        maApiData.mnWritingMode = csstxt::WritingMode2::RL_TB;  break;
    1341             :     }
    1342             : 
    1343             :     // rotation: 0-90 means 0 to 90 degrees ccw, 91-180 means 1 to 90 degrees cw, 255 means stacked
    1344         186 :     sal_Int32 nOoxRot = maModel.mnRotation;
    1345             :     maApiData.mnRotation = ((0 <= nOoxRot) && (nOoxRot <= 90)) ?
    1346             :         (100 * nOoxRot) :
    1347         186 :         (((91 <= nOoxRot) && (nOoxRot <= 180)) ? (100 * (450 - nOoxRot)) : 0);
    1348             : 
    1349             :     // "Orientation" property used for character stacking
    1350             :     maApiData.meOrientation = (nOoxRot == OOX_XF_ROTATION_STACKED) ?
    1351         186 :         csstab::CellOrientation_STACKED : csstab::CellOrientation_STANDARD;
    1352             : 
    1353             :     // alignment flags (#i84960 automatic line break, if vertically justified/distributed)
    1354         186 :     maApiData.mbWrapText = maModel.mbWrapText || (maModel.mnVerAlign == XML_distributed) || (maModel.mnVerAlign == XML_justify);
    1355         186 :     maApiData.mbShrink = maModel.mbShrink;
    1356             : 
    1357         186 : }
    1358             : 
    1359          20 : ::SvxCellVerJustify Alignment::GetScVerAlign() const
    1360             : {
    1361             :     namespace csstab = ::com::sun::star::table;
    1362          20 :     ::SvxCellVerJustify nVert = ::SVX_VER_JUSTIFY_STANDARD;
    1363          20 :     switch ( maApiData.mnVerJustify )
    1364             :     {
    1365             :         case csstab::CellVertJustify2::BOTTOM:
    1366          19 :             nVert = ::SVX_VER_JUSTIFY_BOTTOM;
    1367          19 :             break;
    1368             :         case csstab::CellVertJustify2::CENTER:
    1369           1 :             nVert = ::SVX_VER_JUSTIFY_CENTER;
    1370           1 :             break;
    1371             :         case csstab::CellVertJustify2::TOP:
    1372           0 :             nVert = ::SVX_VER_JUSTIFY_TOP;
    1373           0 :             break;
    1374             :         case csstab::CellVertJustify2::BLOCK:
    1375           0 :             nVert = ::SVX_VER_JUSTIFY_BLOCK;
    1376           0 :             break;
    1377             :         case csstab::CellVertJustify2::STANDARD:
    1378             :         default:
    1379           0 :             nVert = ::SVX_VER_JUSTIFY_STANDARD;
    1380           0 :             break;
    1381             :     }
    1382          20 :     return nVert;
    1383             : }
    1384             : 
    1385          20 : ::SvxCellHorJustify Alignment::GetScHorAlign() const
    1386             : {
    1387             :     namespace csstab = ::com::sun::star::table;
    1388          20 :     ::SvxCellHorJustify nHori = ::SVX_HOR_JUSTIFY_STANDARD;
    1389          20 :     switch( maApiData.meHorJustify )
    1390             :     {
    1391             :         case csstab::CellHoriJustify_LEFT:
    1392           0 :             nHori = ::SVX_HOR_JUSTIFY_LEFT;
    1393           0 :             break;
    1394             :         case csstab::CellHoriJustify_CENTER:
    1395           4 :             nHori = ::SVX_HOR_JUSTIFY_CENTER;
    1396           4 :             break;
    1397             :         case csstab::CellHoriJustify_RIGHT:
    1398           1 :             nHori = ::SVX_HOR_JUSTIFY_RIGHT;
    1399           1 :             break;
    1400             :         case csstab::CellHoriJustify_BLOCK:
    1401           1 :             nHori = ::SVX_HOR_JUSTIFY_BLOCK;
    1402           1 :             break;
    1403             :         case csstab::CellHoriJustify_REPEAT:
    1404           0 :             nHori = ::SVX_HOR_JUSTIFY_REPEAT;
    1405           0 :             break;
    1406             :         case csstab::CellHoriJustify_STANDARD:
    1407             :         default:
    1408          14 :             nHori = ::SVX_HOR_JUSTIFY_STANDARD;
    1409          14 :             break;
    1410             :     }
    1411          20 :     return nHori;
    1412             : }
    1413             : 
    1414          20 : ::SvxFrameDirection Alignment::GetScFrameDir() const
    1415             : {
    1416             :     namespace csstxt = ::com::sun::star::text;
    1417          20 :     ::SvxFrameDirection eFrameDir = ::FRMDIR_ENVIRONMENT;
    1418          20 :     switch( maApiData.mnWritingMode )
    1419             :     {
    1420             :         case csstxt::WritingMode2::PAGE:
    1421          20 :             eFrameDir = ::FRMDIR_ENVIRONMENT;
    1422          20 :             break;
    1423             :         case csstxt::WritingMode2::LR_TB:
    1424           0 :             eFrameDir = ::FRMDIR_HORI_LEFT_TOP;
    1425           0 :             break;
    1426             :         case csstxt::WritingMode2::RL_TB:
    1427           0 :             eFrameDir = ::FRMDIR_HORI_RIGHT_TOP;
    1428           0 :             break;
    1429             :         default:
    1430             :             OSL_FAIL( "GetScFrameDir - unknown CTL text direction" );
    1431             :     }
    1432          20 :     return eFrameDir;
    1433             : }
    1434             : 
    1435          20 : void Alignment::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
    1436             : {
    1437             :     namespace csstab = ::com::sun::star::table;
    1438             :     // horizontal alignment
    1439          20 :     ScfTools::PutItem( rItemSet, SvxHorJustifyItem( GetScHorAlign(), ATTR_HOR_JUSTIFY ), bSkipPoolDefs );
    1440          20 :     ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnHorJustifyMethod == csstab::CellJustifyMethod::DISTRIBUTE ) ? ::SVX_JUSTIFY_METHOD_DISTRIBUTE : ::SVX_JUSTIFY_METHOD_AUTO, ATTR_HOR_JUSTIFY_METHOD ), bSkipPoolDefs );
    1441          20 :     ScfTools::PutItem( rItemSet, SvxVerJustifyItem( GetScVerAlign(), ATTR_VER_JUSTIFY ), bSkipPoolDefs );
    1442             :     // vertical alignment
    1443          20 :     ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnVerJustifyMethod == csstab::CellJustifyMethod::DISTRIBUTE ) ? ::SVX_JUSTIFY_METHOD_DISTRIBUTE : ::SVX_JUSTIFY_METHOD_AUTO, ATTR_VER_JUSTIFY_METHOD ), bSkipPoolDefs );
    1444             : 
    1445             :     // CTL text direction
    1446          20 :     ScfTools::PutItem( rItemSet, SvxFrameDirectionItem( GetScFrameDir(), ATTR_WRITINGDIR ), bSkipPoolDefs );
    1447             :     // set an angle in the range from -90 to 90 degrees
    1448          20 :     ScfTools::PutItem( rItemSet, SfxInt32Item( ATTR_ROTATE_VALUE, maApiData.mnRotation ), bSkipPoolDefs );
    1449             :     // Orientation
    1450          20 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_STACKED, maApiData.meOrientation == csstab::CellOrientation_STACKED ), bSkipPoolDefs );
    1451             :     // indent
    1452          20 :     ScfTools::PutItem( rItemSet, SfxUInt16Item( ATTR_INDENT, maApiData.mnIndent ), bSkipPoolDefs );
    1453             :     // line wrap
    1454          20 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_LINEBREAK, maApiData.mbWrapText ), bSkipPoolDefs );
    1455          20 :     ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_SHRINKTOFIT, maApiData.mbShrink ), bSkipPoolDefs );
    1456          20 : }
    1457             : 
    1458          11 : void Alignment::writeToPropertyMap( PropertyMap& rPropMap ) const
    1459             : {
    1460          11 :     rPropMap[ PROP_HoriJustify ]     <<= maApiData.meHorJustify;
    1461          11 :     rPropMap[ PROP_HoriJustifyMethod ] <<= maApiData.mnHorJustifyMethod;
    1462          11 :     rPropMap[ PROP_VertJustify ]     <<= maApiData.mnVerJustify;
    1463          11 :     rPropMap[ PROP_VertJustifyMethod ] <<= maApiData.mnVerJustifyMethod;
    1464          11 :     rPropMap[ PROP_WritingMode ]     <<= maApiData.mnWritingMode;
    1465          11 :     rPropMap[ PROP_RotateAngle ]     <<= maApiData.mnRotation;
    1466          11 :     rPropMap[ PROP_Orientation ]     <<= maApiData.meOrientation;
    1467          11 :     rPropMap[ PROP_ParaIndent ]      <<= maApiData.mnIndent;
    1468          11 :     rPropMap[ PROP_IsTextWrapped ]   <<= maApiData.mbWrapText;
    1469          11 :     rPropMap[ PROP_ShrinkToFit ]     <<= maApiData.mbShrink;
    1470          11 : }
    1471             : 
    1472             : // ============================================================================
    1473             : 
    1474         186 : ProtectionModel::ProtectionModel() :
    1475             :     mbLocked( true ),   // default in Excel and Calc
    1476         186 :     mbHidden( false )
    1477             : {
    1478         186 : }
    1479             : 
    1480             : // ----------------------------------------------------------------------------
    1481             : 
    1482         186 : ApiProtectionData::ApiProtectionData() :
    1483         186 :     maCellProt( sal_True, sal_False, sal_False, sal_False )
    1484             : {
    1485         186 : }
    1486             : 
    1487          37 : bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight )
    1488             : {
    1489             :     return
    1490             :         (rLeft.maCellProt.IsLocked        == rRight.maCellProt.IsLocked) &&
    1491             :         (rLeft.maCellProt.IsFormulaHidden == rRight.maCellProt.IsFormulaHidden) &&
    1492             :         (rLeft.maCellProt.IsHidden        == rRight.maCellProt.IsHidden) &&
    1493          37 :         (rLeft.maCellProt.IsPrintHidden   == rRight.maCellProt.IsPrintHidden);
    1494             : }
    1495             : 
    1496             : // ============================================================================
    1497             : 
    1498         186 : Protection::Protection( const WorkbookHelper& rHelper ) :
    1499         186 :     WorkbookHelper( rHelper )
    1500             : {
    1501         186 : }
    1502             : 
    1503          33 : void Protection::importProtection( const AttributeList& rAttribs )
    1504             : {
    1505          33 :     maModel.mbLocked = rAttribs.getBool( XML_locked, true );
    1506          33 :     maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
    1507          33 : }
    1508             : 
    1509           0 : void Protection::setBiff12Data( sal_uInt32 nFlags )
    1510             : {
    1511           0 :     maModel.mbLocked = getFlag( nFlags, BIFF12_XF_LOCKED );
    1512           0 :     maModel.mbHidden = getFlag( nFlags, BIFF12_XF_HIDDEN );
    1513           0 : }
    1514             : 
    1515         186 : void Protection::finalizeImport()
    1516             : {
    1517         186 :     maApiData.maCellProt.IsLocked = maModel.mbLocked;
    1518         186 :     maApiData.maCellProt.IsFormulaHidden = maModel.mbHidden;
    1519         186 : }
    1520             : 
    1521          11 : void Protection::writeToPropertyMap( PropertyMap& rPropMap ) const
    1522             : {
    1523          11 :     rPropMap[ PROP_CellProtection ] <<= maApiData.maCellProt;
    1524          11 : }
    1525             : 
    1526          16 : void Protection::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
    1527             : {
    1528          16 :     ScfTools::PutItem( rItemSet, ScProtectionAttr( maApiData.maCellProt.IsLocked, maApiData.maCellProt.IsFormulaHidden ), bSkipPoolDefs );
    1529          16 : }
    1530             : 
    1531             : // ============================================================================
    1532             : 
    1533             : namespace {
    1534             : 
    1535          48 : bool lcl_isBorder(const ::com::sun::star::table::BorderLine& rBorder)
    1536             : {
    1537          48 :     return (rBorder.InnerLineWidth > 0) || (rBorder.OuterLineWidth > 0);
    1538             : }
    1539             : 
    1540             : }
    1541             : 
    1542          55 : BorderLineModel::BorderLineModel( bool bDxf ) :
    1543             :     mnStyle( XML_none ),
    1544          55 :     mbUsed( !bDxf )
    1545             : {
    1546          55 :     maColor.setIndexed( OOX_COLOR_WINDOWTEXT );
    1547          55 : }
    1548             : 
    1549           0 : void BorderLineModel::setBiffStyle( sal_Int32 nLineStyle )
    1550             : {
    1551             :     static const sal_Int32 spnStyleIds[] = {
    1552             :         XML_none, XML_thin, XML_medium, XML_dashed,
    1553             :         XML_dotted, XML_thick, XML_double, XML_hair,
    1554             :         XML_mediumDashed, XML_dashDot, XML_mediumDashDot, XML_dashDotDot,
    1555             :         XML_mediumDashDotDot, XML_slantDashDot };
    1556           0 :     mnStyle = STATIC_ARRAY_SELECT( spnStyleIds, nLineStyle, XML_none );
    1557           0 : }
    1558             : 
    1559             : // ----------------------------------------------------------------------------
    1560             : 
    1561          11 : BorderModel::BorderModel( bool bDxf ) :
    1562             :     maLeft( bDxf ),
    1563             :     maRight( bDxf ),
    1564             :     maTop( bDxf ),
    1565             :     maBottom( bDxf ),
    1566             :     maDiagonal( bDxf ),
    1567             :     mbDiagTLtoBR( false ),
    1568          11 :     mbDiagBLtoTR( false )
    1569             : {
    1570          11 : }
    1571             : 
    1572             : // ----------------------------------------------------------------------------
    1573             : 
    1574          11 : ApiBorderData::ApiBorderData() :
    1575             :     mbBorderUsed( false ),
    1576          11 :     mbDiagUsed( false )
    1577             : {
    1578          11 : }
    1579             : 
    1580           1 : bool ApiBorderData::hasAnyOuterBorder() const
    1581             : {
    1582             :     return
    1583           1 :         ( ( lcl_isBorder( maTop ) &&  maTop.OuterLineWidth > 0 ) ) ||
    1584           1 :         ( ( lcl_isBorder( maBottom ) && maBottom.OuterLineWidth > 0 ) ) ||
    1585           1 :         ( ( lcl_isBorder( maLeft ) && maLeft.OuterLineWidth > 0 ) ) ||
    1586           3 :         ( ( lcl_isBorder( maRight ) && maRight.OuterLineWidth > 0 ) );
    1587             : }
    1588             : 
    1589             : namespace {
    1590             : 
    1591           0 : bool operator==( const BorderLine& rLeft, const BorderLine& rRight )
    1592             : {
    1593             :     return
    1594             :         (rLeft.Color          == rRight.Color) &&
    1595             :         (rLeft.InnerLineWidth == rRight.InnerLineWidth) &&
    1596             :         (rLeft.OuterLineWidth == rRight.OuterLineWidth) &&
    1597           0 :         (rLeft.LineDistance   == rRight.LineDistance);
    1598             : }
    1599             : 
    1600             : } // namespace
    1601             : 
    1602           0 : bool operator==( const ApiBorderData& rLeft, const ApiBorderData& rRight )
    1603             : {
    1604             :     return
    1605           0 :         (rLeft.maLeft       == rRight.maLeft)   &&
    1606           0 :         (rLeft.maRight      == rRight.maRight)  &&
    1607           0 :         (rLeft.maTop        == rRight.maTop)    &&
    1608           0 :         (rLeft.maBottom     == rRight.maBottom) &&
    1609           0 :         (rLeft.maTLtoBR     == rRight.maTLtoBR) &&
    1610           0 :         (rLeft.maBLtoTR     == rRight.maBLtoTR) &&
    1611             :         (rLeft.mbBorderUsed == rRight.mbBorderUsed) &&
    1612           0 :         (rLeft.mbDiagUsed   == rRight.mbDiagUsed);
    1613             : }
    1614             : 
    1615             : // ============================================================================
    1616             : 
    1617             : namespace {
    1618             : 
    1619          44 : inline void lclSetBorderLineWidth( BorderLine& rBorderLine,
    1620             :         sal_Int16 nOuter, sal_Int16 nDist = API_LINE_NONE, sal_Int16 nInner = API_LINE_NONE )
    1621             : {
    1622          44 :     rBorderLine.OuterLineWidth = nOuter;
    1623          44 :     rBorderLine.LineDistance = nDist;
    1624          44 :     rBorderLine.InnerLineWidth = nInner;
    1625          44 : }
    1626             : 
    1627             : } // namespace
    1628             : 
    1629             : // ----------------------------------------------------------------------------
    1630             : 
    1631          11 : Border::Border( const WorkbookHelper& rHelper, bool bDxf ) :
    1632             :     WorkbookHelper( rHelper ),
    1633             :     maModel( bDxf ),
    1634          11 :     mbDxf( bDxf )
    1635             : {
    1636          11 : }
    1637             : 
    1638          11 : void Border::importBorder( const AttributeList& rAttribs )
    1639             : {
    1640          11 :     maModel.mbDiagTLtoBR = rAttribs.getBool( XML_diagonalDown, false );
    1641          11 :     maModel.mbDiagBLtoTR = rAttribs.getBool( XML_diagonalUp, false );
    1642          11 : }
    1643             : 
    1644          55 : void Border::importStyle( sal_Int32 nElement, const AttributeList& rAttribs )
    1645             : {
    1646          55 :     if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
    1647             :     {
    1648          55 :         pBorderLine->mnStyle = rAttribs.getToken( XML_style, XML_none );
    1649          55 :         pBorderLine->mbUsed = true;
    1650             :     }
    1651          55 : }
    1652             : 
    1653           0 : void Border::importColor( sal_Int32 nElement, const AttributeList& rAttribs )
    1654             : {
    1655           0 :     if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
    1656           0 :         pBorderLine->maColor.importColor( rAttribs );
    1657           0 : }
    1658             : 
    1659           0 : void Border::importBorder( SequenceInputStream& rStrm )
    1660             : {
    1661           0 :     sal_uInt8 nFlags = rStrm.readuInt8();
    1662           0 :     maModel.mbDiagTLtoBR = getFlag( nFlags, BIFF12_BORDER_DIAG_TLBR );
    1663           0 :     maModel.mbDiagBLtoTR = getFlag( nFlags, BIFF12_BORDER_DIAG_BLTR );
    1664           0 :     maModel.maTop.setBiffStyle( rStrm.readuInt16() );
    1665           0 :     rStrm >> maModel.maTop.maColor;
    1666           0 :     maModel.maBottom.setBiffStyle( rStrm.readuInt16() );
    1667           0 :     rStrm >> maModel.maBottom.maColor;
    1668           0 :     maModel.maLeft.setBiffStyle( rStrm.readuInt16() );
    1669           0 :     rStrm >> maModel.maLeft.maColor;
    1670           0 :     maModel.maRight.setBiffStyle( rStrm.readuInt16() );
    1671           0 :     rStrm >> maModel.maRight.maColor;
    1672           0 :     maModel.maDiagonal.setBiffStyle( rStrm.readuInt16() );
    1673           0 :     rStrm >> maModel.maDiagonal.maColor;
    1674           0 : }
    1675             : 
    1676           0 : void Border::importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm )
    1677             : {
    1678             :     OSL_ENSURE( mbDxf, "Border::importDxfBorder - missing conditional formatting flag" );
    1679           0 :     if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
    1680             :     {
    1681             :         sal_uInt16 nStyle;
    1682           0 :         rStrm >> pBorderLine->maColor >> nStyle;
    1683           0 :         pBorderLine->setBiffStyle( nStyle );
    1684           0 :         pBorderLine->mbUsed = true;
    1685             :     }
    1686           0 : }
    1687             : 
    1688          11 : void Border::finalizeImport()
    1689             : {
    1690          11 :     maApiData.mbBorderUsed = maModel.maLeft.mbUsed || maModel.maRight.mbUsed || maModel.maTop.mbUsed || maModel.maBottom.mbUsed;
    1691          11 :     maApiData.mbDiagUsed   = maModel.maDiagonal.mbUsed;
    1692             : 
    1693          11 :     convertBorderLine( maApiData.maLeft,   maModel.maLeft );
    1694          11 :     convertBorderLine( maApiData.maRight,  maModel.maRight );
    1695          11 :     convertBorderLine( maApiData.maTop,    maModel.maTop );
    1696          11 :     convertBorderLine( maApiData.maBottom, maModel.maBottom );
    1697             : 
    1698          11 :     if( maModel.mbDiagTLtoBR )
    1699           0 :         convertBorderLine( maApiData.maTLtoBR, maModel.maDiagonal );
    1700          11 :     if( maModel.mbDiagBLtoTR )
    1701           0 :         convertBorderLine( maApiData.maBLtoTR, maModel.maDiagonal );
    1702          11 : }
    1703             : 
    1704          16 : void Border::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
    1705             : {
    1706          16 :     if( maApiData.mbBorderUsed )
    1707             :     {
    1708          16 :          SvxBoxItem aBoxItem( ATTR_BORDER );
    1709          16 :          ::editeng::SvxBorderLine aLine;
    1710             : 
    1711          16 :          if ( SvxBoxItem::LineToSvxLine(maApiData.maLeft, aLine, true ) )
    1712             :          {
    1713           0 :              aBoxItem.SetLine( &aLine, BOX_LINE_LEFT );
    1714             :          }
    1715          16 :          if ( SvxBoxItem::LineToSvxLine(maApiData.maRight, aLine, true ) )
    1716             :          {
    1717           0 :              aBoxItem.SetLine( &aLine, BOX_LINE_RIGHT );
    1718             :          }
    1719          16 :          if ( SvxBoxItem::LineToSvxLine(maApiData.maTop, aLine, true ) )
    1720             :          {
    1721           0 :              aBoxItem.SetLine( &aLine, BOX_LINE_TOP );
    1722             :          }
    1723          16 :          if ( SvxBoxItem::LineToSvxLine(maApiData.maBottom, aLine, true ) )
    1724             :          {
    1725           0 :              aBoxItem.SetLine( &aLine, BOX_LINE_BOTTOM );
    1726             :          }
    1727          16 :          ScfTools::PutItem( rItemSet, aBoxItem, bSkipPoolDefs );
    1728             :     }
    1729          16 :     if ( maApiData.mbDiagUsed )
    1730             :     {
    1731          16 :         SvxLineItem aTLBRItem( ATTR_BORDER_TLBR );
    1732          16 :         SvxLineItem aBLTRItem( ATTR_BORDER_BLTR );
    1733          16 :         ::editeng::SvxBorderLine aLine;
    1734          16 :         if ( SvxBoxItem::LineToSvxLine(maApiData.maTLtoBR, aLine, true ) )
    1735             :         {
    1736           0 :             aTLBRItem.SetLine( &aLine );
    1737             :         }
    1738          16 :         if ( SvxBoxItem::LineToSvxLine(maApiData.maBLtoTR, aLine, true ) )
    1739             :         {
    1740           0 :             aBLTRItem.SetLine( &aLine );
    1741             :         }
    1742          16 :         ScfTools::PutItem( rItemSet, aTLBRItem, bSkipPoolDefs );
    1743          16 :         ScfTools::PutItem( rItemSet, aBLTRItem, bSkipPoolDefs );
    1744             :     }
    1745          16 : }
    1746             : 
    1747          11 : void Border::writeToPropertyMap( PropertyMap& rPropMap ) const
    1748             : {
    1749          11 :     if( maApiData.mbBorderUsed )
    1750             :     {
    1751          11 :         rPropMap[ PROP_LeftBorder ]   <<= maApiData.maLeft;
    1752          11 :         rPropMap[ PROP_RightBorder ]  <<= maApiData.maRight;
    1753          11 :         rPropMap[ PROP_TopBorder ]    <<= maApiData.maTop;
    1754          11 :         rPropMap[ PROP_BottomBorder ] <<= maApiData.maBottom;
    1755             :     }
    1756          11 :     if( maApiData.mbDiagUsed )
    1757             :     {
    1758          11 :         rPropMap[ PROP_DiagonalTLBR ] <<= maApiData.maTLtoBR;
    1759          11 :         rPropMap[ PROP_DiagonalBLTR ] <<= maApiData.maBLtoTR;
    1760             :     }
    1761          11 : }
    1762             : 
    1763          11 : bool Border::hasBorder() const
    1764             : {
    1765          11 :     if (lcl_isBorder(maApiData.maBottom))
    1766           0 :         return true;
    1767             : 
    1768          11 :     if (lcl_isBorder(maApiData.maTop))
    1769           0 :         return true;
    1770             : 
    1771          11 :     if (lcl_isBorder(maApiData.maLeft))
    1772           0 :         return true;
    1773             : 
    1774          11 :     if (lcl_isBorder(maApiData.maRight))
    1775           0 :         return true;
    1776             : 
    1777          11 :     return false;
    1778             : }
    1779             : 
    1780          55 : BorderLineModel* Border::getBorderLine( sal_Int32 nElement )
    1781             : {
    1782          55 :     switch( nElement )
    1783             :     {
    1784          11 :         case XLS_TOKEN( left ):     return &maModel.maLeft;
    1785          11 :         case XLS_TOKEN( right ):    return &maModel.maRight;
    1786          11 :         case XLS_TOKEN( top ):      return &maModel.maTop;
    1787          11 :         case XLS_TOKEN( bottom ):   return &maModel.maBottom;
    1788          11 :         case XLS_TOKEN( diagonal ): return &maModel.maDiagonal;
    1789             :     }
    1790           0 :     return 0;
    1791             : }
    1792             : 
    1793          44 : bool Border::convertBorderLine( BorderLine2& rBorderLine, const BorderLineModel& rModel )
    1794             : {
    1795          44 :     rBorderLine.Color = rModel.maColor.getColor( getBaseFilter().getGraphicHelper(), API_RGB_BLACK );
    1796          44 :     switch( rModel.mnStyle )
    1797             :     {
    1798           0 :         case XML_dashDot:           lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );    break;
    1799           0 :         case XML_dashDotDot:        lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );    break;
    1800             :         case XML_dashed:
    1801             :         {
    1802           0 :                                     lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
    1803           0 :                                     rBorderLine.LineStyle = API_LINE_DASHED;
    1804           0 :                                     break;
    1805             :         }
    1806             :         case XML_dotted:
    1807             :         {
    1808           0 :                                     lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
    1809           0 :                                     rBorderLine.LineStyle = API_LINE_DOTTED;
    1810           0 :                                     break;
    1811             :         }
    1812           0 :         case XML_double:            lclSetBorderLineWidth( rBorderLine, API_LINE_THIN, API_LINE_THIN, API_LINE_THIN ); break;
    1813           0 :         case XML_hair:              lclSetBorderLineWidth( rBorderLine, API_LINE_HAIR );    break;
    1814           0 :         case XML_medium:            lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );  break;
    1815           0 :         case XML_mediumDashDot:     lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );  break;
    1816           0 :         case XML_mediumDashDotDot:  lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );  break;
    1817           0 :         case XML_mediumDashed:      lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );  break;
    1818          44 :         case XML_none:              lclSetBorderLineWidth( rBorderLine, API_LINE_NONE );    break;
    1819           0 :         case XML_slantDashDot:      lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );  break;
    1820           0 :         case XML_thick:             lclSetBorderLineWidth( rBorderLine, API_LINE_THICK );   break;
    1821           0 :         case XML_thin:              lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );    break;
    1822           0 :         default:                    lclSetBorderLineWidth( rBorderLine, API_LINE_NONE );    break;
    1823             :     }
    1824          44 :     return rModel.mbUsed;
    1825             : }
    1826             : 
    1827             : 
    1828             : // ============================================================================
    1829             : 
    1830          44 : PatternFillModel::PatternFillModel( bool bDxf ) :
    1831             :     mnPattern( XML_none ),
    1832          44 :     mbPattColorUsed( !bDxf ),
    1833          44 :     mbFillColorUsed( !bDxf ),
    1834         132 :     mbPatternUsed( !bDxf )
    1835             : {
    1836          44 :     maPatternColor.setIndexed( OOX_COLOR_WINDOWTEXT );
    1837          44 :     maFillColor.setIndexed( OOX_COLOR_WINDOWBACK );
    1838          44 : }
    1839             : 
    1840           0 : void PatternFillModel::setBiffPattern( sal_Int32 nPattern )
    1841             : {
    1842             :     static const sal_Int32 spnPatternIds[] = {
    1843             :         XML_none, XML_solid, XML_mediumGray, XML_darkGray,
    1844             :         XML_lightGray, XML_darkHorizontal, XML_darkVertical, XML_darkDown,
    1845             :         XML_darkUp, XML_darkGrid, XML_darkTrellis, XML_lightHorizontal,
    1846             :         XML_lightVertical, XML_lightDown, XML_lightUp, XML_lightGrid,
    1847             :         XML_lightTrellis, XML_gray125, XML_gray0625 };
    1848           0 :     mnPattern = STATIC_ARRAY_SELECT( spnPatternIds, nPattern, XML_none );
    1849           0 : }
    1850             : 
    1851             : // ----------------------------------------------------------------------------
    1852             : 
    1853           0 : GradientFillModel::GradientFillModel() :
    1854             :     mnType( XML_linear ),
    1855             :     mfAngle( 0.0 ),
    1856             :     mfLeft( 0.0 ),
    1857             :     mfRight( 0.0 ),
    1858             :     mfTop( 0.0 ),
    1859           0 :     mfBottom( 0.0 )
    1860             : {
    1861           0 : }
    1862             : 
    1863           0 : void GradientFillModel::readGradient( SequenceInputStream& rStrm )
    1864             : {
    1865             :     sal_Int32 nType;
    1866           0 :     rStrm >> nType >> mfAngle >> mfLeft >> mfRight >> mfTop >> mfBottom;
    1867             :     static const sal_Int32 spnTypes[] = { XML_linear, XML_path };
    1868           0 :     mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
    1869           0 : }
    1870             : 
    1871           0 : void GradientFillModel::readGradientStop( SequenceInputStream& rStrm, bool bDxf )
    1872             : {
    1873           0 :     Color aColor;
    1874             :     double fPosition;
    1875           0 :     if( bDxf )
    1876             :     {
    1877           0 :         rStrm.skip( 2 );
    1878           0 :         rStrm >> fPosition >> aColor;
    1879             :     }
    1880             :     else
    1881             :     {
    1882           0 :         rStrm >> aColor >> fPosition;
    1883             :     }
    1884           0 :     if( !rStrm.isEof() && (fPosition >= 0.0) )
    1885           0 :         maColors[ fPosition ] = aColor;
    1886           0 : }
    1887             : 
    1888             : // ----------------------------------------------------------------------------
    1889             : 
    1890          44 : ApiSolidFillData::ApiSolidFillData() :
    1891             :     mnColor( API_RGB_TRANSPARENT ),
    1892             :     mbTransparent( true ),
    1893          44 :     mbUsed( false )
    1894             : {
    1895          44 : }
    1896             : 
    1897           0 : bool operator==( const ApiSolidFillData& rLeft, const ApiSolidFillData& rRight )
    1898             : {
    1899             :     return
    1900             :         (rLeft.mnColor       == rRight.mnColor) &&
    1901             :         (rLeft.mbTransparent == rRight.mbTransparent) &&
    1902           0 :         (rLeft.mbUsed        == rRight.mbUsed);
    1903             : }
    1904             : 
    1905             : // ============================================================================
    1906             : 
    1907             : namespace {
    1908             : 
    1909          99 : inline sal_Int32 lclGetMixedColorComp( sal_Int32 nPatt, sal_Int32 nFill, sal_Int32 nAlpha )
    1910             : {
    1911          99 :     return ((nPatt - nFill) * nAlpha) / 0x80 + nFill;
    1912             : }
    1913             : 
    1914          33 : sal_Int32 lclGetMixedColor( sal_Int32 nPattColor, sal_Int32 nFillColor, sal_Int32 nAlpha )
    1915             : {
    1916             :     return
    1917          33 :         (lclGetMixedColorComp( nPattColor & 0xFF0000, nFillColor & 0xFF0000, nAlpha ) & 0xFF0000) |
    1918          33 :         (lclGetMixedColorComp( nPattColor & 0x00FF00, nFillColor & 0x00FF00, nAlpha ) & 0x00FF00) |
    1919          66 :         (lclGetMixedColorComp( nPattColor & 0x0000FF, nFillColor & 0x0000FF, nAlpha ) & 0x0000FF);
    1920             : }
    1921             : 
    1922             : } // namespace
    1923             : 
    1924             : // ----------------------------------------------------------------------------
    1925             : 
    1926          44 : Fill::Fill( const WorkbookHelper& rHelper, bool bDxf ) :
    1927             :     WorkbookHelper( rHelper ),
    1928          44 :     mbDxf( bDxf )
    1929             : {
    1930          44 : }
    1931             : 
    1932          44 : void Fill::importPatternFill( const AttributeList& rAttribs )
    1933             : {
    1934          44 :     mxPatternModel.reset( new PatternFillModel( mbDxf ) );
    1935          44 :     mxPatternModel->mnPattern = rAttribs.getToken( XML_patternType, XML_none );
    1936          44 :     if( mbDxf )
    1937          20 :         mxPatternModel->mbPatternUsed = rAttribs.hasAttribute( XML_patternType );
    1938          44 : }
    1939             : 
    1940           2 : void Fill::importFgColor( const AttributeList& rAttribs )
    1941             : {
    1942             :     OSL_ENSURE( mxPatternModel.get(), "Fill::importFgColor - missing pattern data" );
    1943           2 :     if( mxPatternModel.get() )
    1944             :     {
    1945           2 :         mxPatternModel->maPatternColor.importColor( rAttribs );
    1946           2 :         mxPatternModel->mbPattColorUsed = true;
    1947             :     }
    1948           2 : }
    1949             : 
    1950          22 : void Fill::importBgColor( const AttributeList& rAttribs )
    1951             : {
    1952             :     OSL_ENSURE( mxPatternModel.get(), "Fill::importBgColor - missing pattern data" );
    1953          22 :     if( mxPatternModel.get() )
    1954             :     {
    1955          22 :         mxPatternModel->maFillColor.importColor( rAttribs );
    1956          22 :         mxPatternModel->mbFillColorUsed = true;
    1957             :     }
    1958          22 : }
    1959             : 
    1960           0 : void Fill::importGradientFill( const AttributeList& rAttribs )
    1961             : {
    1962           0 :     mxGradientModel.reset( new GradientFillModel );
    1963           0 :     mxGradientModel->mnType = rAttribs.getToken( XML_type, XML_linear );
    1964           0 :     mxGradientModel->mfAngle = rAttribs.getDouble( XML_degree, 0.0 );
    1965           0 :     mxGradientModel->mfLeft = rAttribs.getDouble( XML_left, 0.0 );
    1966           0 :     mxGradientModel->mfRight = rAttribs.getDouble( XML_right, 0.0 );
    1967           0 :     mxGradientModel->mfTop = rAttribs.getDouble( XML_top, 0.0 );
    1968           0 :     mxGradientModel->mfBottom = rAttribs.getDouble( XML_bottom, 0.0 );
    1969           0 : }
    1970             : 
    1971           0 : void Fill::importColor( const AttributeList& rAttribs, double fPosition )
    1972             : {
    1973             :     OSL_ENSURE( mxGradientModel.get(), "Fill::importColor - missing gradient data" );
    1974           0 :     if( mxGradientModel.get() && (fPosition >= 0.0) )
    1975           0 :         mxGradientModel->maColors[ fPosition ].importColor( rAttribs );
    1976           0 : }
    1977             : 
    1978           0 : void Fill::importFill( SequenceInputStream& rStrm )
    1979             : {
    1980             :     OSL_ENSURE( !mbDxf, "Fill::importFill - unexpected conditional formatting flag" );
    1981           0 :     sal_Int32 nPattern = rStrm.readInt32();
    1982           0 :     if( nPattern == BIFF12_FILL_GRADIENT )
    1983             :     {
    1984           0 :         mxGradientModel.reset( new GradientFillModel );
    1985             :         sal_Int32 nStopCount;
    1986           0 :         rStrm.skip( 16 );
    1987           0 :         mxGradientModel->readGradient( rStrm );
    1988           0 :         rStrm >> nStopCount;
    1989           0 :         for( sal_Int32 nStop = 0; (nStop < nStopCount) && !rStrm.isEof(); ++nStop )
    1990           0 :             mxGradientModel->readGradientStop( rStrm, false );
    1991             :     }
    1992             :     else
    1993             :     {
    1994           0 :         mxPatternModel.reset( new PatternFillModel( mbDxf ) );
    1995           0 :         mxPatternModel->setBiffPattern( nPattern );
    1996           0 :         rStrm >> mxPatternModel->maPatternColor >> mxPatternModel->maFillColor;
    1997             :     }
    1998           0 : }
    1999             : 
    2000           0 : void Fill::importDxfPattern( SequenceInputStream& rStrm )
    2001             : {
    2002             :     OSL_ENSURE( mbDxf, "Fill::importDxfPattern - missing conditional formatting flag" );
    2003           0 :     if( !mxPatternModel )
    2004           0 :         mxPatternModel.reset( new PatternFillModel( mbDxf ) );
    2005           0 :     mxPatternModel->setBiffPattern( rStrm.readuInt8() );
    2006           0 :     mxPatternModel->mbPatternUsed = true;
    2007           0 : }
    2008             : 
    2009           0 : void Fill::importDxfFgColor( SequenceInputStream& rStrm )
    2010             : {
    2011             :     OSL_ENSURE( mbDxf, "Fill::importDxfFgColor - missing conditional formatting flag" );
    2012           0 :     if( !mxPatternModel )
    2013           0 :         mxPatternModel.reset( new PatternFillModel( mbDxf ) );
    2014           0 :     mxPatternModel->maPatternColor.importColor( rStrm );
    2015           0 :     mxPatternModel->mbPattColorUsed = true;
    2016           0 : }
    2017             : 
    2018           0 : void Fill::importDxfBgColor( SequenceInputStream& rStrm )
    2019             : {
    2020             :     OSL_ENSURE( mbDxf, "Fill::importDxfBgColor - missing conditional formatting flag" );
    2021           0 :     if( !mxPatternModel )
    2022           0 :         mxPatternModel.reset( new PatternFillModel( mbDxf ) );
    2023           0 :     mxPatternModel->maFillColor.importColor( rStrm );
    2024           0 :     mxPatternModel->mbFillColorUsed = true;
    2025           0 : }
    2026             : 
    2027           0 : void Fill::importDxfGradient( SequenceInputStream& rStrm )
    2028             : {
    2029             :     OSL_ENSURE( mbDxf, "Fill::importDxfGradient - missing conditional formatting flag" );
    2030           0 :     if( !mxGradientModel )
    2031           0 :         mxGradientModel.reset( new GradientFillModel );
    2032           0 :     mxGradientModel->readGradient( rStrm );
    2033           0 : }
    2034             : 
    2035           0 : void Fill::importDxfStop( SequenceInputStream& rStrm )
    2036             : {
    2037             :     OSL_ENSURE( mbDxf, "Fill::importDxfStop - missing conditional formatting flag" );
    2038           0 :     if( !mxGradientModel )
    2039           0 :         mxGradientModel.reset( new GradientFillModel );
    2040           0 :     mxGradientModel->readGradientStop( rStrm, true );
    2041           0 : }
    2042             : 
    2043          44 : void Fill::finalizeImport()
    2044             : {
    2045          44 :     const GraphicHelper& rGraphicHelper = getBaseFilter().getGraphicHelper();
    2046             : 
    2047          44 :     if( mxPatternModel.get() )
    2048             :     {
    2049             :         // finalize the OOXML data struct
    2050          44 :         PatternFillModel& rModel = *mxPatternModel;
    2051          44 :         if( mbDxf )
    2052             :         {
    2053          20 :             if( rModel.mbFillColorUsed && (!rModel.mbPatternUsed || (rModel.mnPattern == XML_solid)) )
    2054             :             {
    2055          20 :                 rModel.maPatternColor = rModel.maFillColor;
    2056          20 :                 rModel.mnPattern = XML_solid;
    2057          20 :                 rModel.mbPattColorUsed = rModel.mbPatternUsed = true;
    2058             :             }
    2059           0 :             else if( !rModel.mbFillColorUsed && rModel.mbPatternUsed && (rModel.mnPattern == XML_solid) )
    2060             :             {
    2061           0 :                 rModel.mbPatternUsed = false;
    2062             :             }
    2063             :         }
    2064             : 
    2065             :         // convert to API fill settings
    2066          44 :         maApiData.mbUsed = rModel.mbPatternUsed;
    2067          44 :         if( rModel.mnPattern == XML_none )
    2068             :         {
    2069          11 :             maApiData.mnColor = API_RGB_TRANSPARENT;
    2070          11 :             maApiData.mbTransparent = true;
    2071             :         }
    2072             :         else
    2073             :         {
    2074          33 :             sal_Int32 nAlpha = 0x80;
    2075          33 :             switch( rModel.mnPattern )
    2076             :             {
    2077           0 :                 case XML_darkDown:          nAlpha = 0x40;  break;
    2078           0 :                 case XML_darkGray:          nAlpha = 0x60;  break;
    2079           0 :                 case XML_darkGrid:          nAlpha = 0x40;  break;
    2080           0 :                 case XML_darkHorizontal:    nAlpha = 0x40;  break;
    2081           0 :                 case XML_darkTrellis:       nAlpha = 0x60;  break;
    2082           0 :                 case XML_darkUp:            nAlpha = 0x40;  break;
    2083           0 :                 case XML_darkVertical:      nAlpha = 0x40;  break;
    2084           0 :                 case XML_gray0625:          nAlpha = 0x08;  break;
    2085          11 :                 case XML_gray125:           nAlpha = 0x10;  break;
    2086           0 :                 case XML_lightDown:         nAlpha = 0x20;  break;
    2087           0 :                 case XML_lightGray:         nAlpha = 0x20;  break;
    2088           0 :                 case XML_lightGrid:         nAlpha = 0x38;  break;
    2089           0 :                 case XML_lightHorizontal:   nAlpha = 0x20;  break;
    2090           0 :                 case XML_lightTrellis:      nAlpha = 0x30;  break;
    2091           0 :                 case XML_lightUp:           nAlpha = 0x20;  break;
    2092           0 :                 case XML_lightVertical:     nAlpha = 0x20;  break;
    2093           0 :                 case XML_mediumGray:        nAlpha = 0x40;  break;
    2094          22 :                 case XML_solid:             nAlpha = 0x80;  break;
    2095             :             }
    2096             : 
    2097          33 :             sal_Int32 nWinTextColor = rGraphicHelper.getSystemColor( XML_windowText );
    2098          33 :             sal_Int32 nWinColor = rGraphicHelper.getSystemColor( XML_window );
    2099             : 
    2100          33 :             if( !rModel.mbPattColorUsed )
    2101           0 :                 rModel.maPatternColor.setAuto();
    2102          33 :             sal_Int32 nPattColor = rModel.maPatternColor.getColor( rGraphicHelper, nWinTextColor );
    2103             : 
    2104          33 :             if( !rModel.mbFillColorUsed )
    2105           0 :                 rModel.maFillColor.setAuto();
    2106          33 :             sal_Int32 nFillColor = rModel.maFillColor.getColor( rGraphicHelper, nWinColor );
    2107             : 
    2108          33 :             maApiData.mnColor = lclGetMixedColor( nPattColor, nFillColor, nAlpha );
    2109          33 :             maApiData.mbTransparent = false;
    2110             :         }
    2111             :     }
    2112           0 :     else if( mxGradientModel.get() && !mxGradientModel->maColors.empty() )
    2113             :     {
    2114           0 :         GradientFillModel& rModel = *mxGradientModel;
    2115           0 :         maApiData.mbUsed = true;    // no support for differential attributes
    2116           0 :         GradientFillModel::ColorMap::const_iterator aIt = rModel.maColors.begin();
    2117             :         OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
    2118           0 :         maApiData.mnColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
    2119           0 :         if( ++aIt != rModel.maColors.end() )
    2120             :         {
    2121             :             OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
    2122           0 :             sal_Int32 nEndColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
    2123           0 :             maApiData.mnColor = lclGetMixedColor( maApiData.mnColor, nEndColor, 0x40 );
    2124           0 :             maApiData.mbTransparent = false;
    2125             :         }
    2126             :     }
    2127          44 : }
    2128             : 
    2129         150 : void Fill::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
    2130             : {
    2131         150 :     if( maApiData.mbUsed )
    2132             :     {
    2133         150 :         SvxBrushItem aBrushItem( ATTR_BACKGROUND );
    2134         150 :         if ( maApiData.mbTransparent )
    2135             :         {
    2136         148 :             aBrushItem.SetColor( ::Color( COL_TRANSPARENT ) );
    2137             :         }
    2138             :         else
    2139             :         {
    2140           2 :             aBrushItem.SetColor( maApiData.mnColor  );
    2141             :         }
    2142         150 :         ScfTools::PutItem( rItemSet, aBrushItem, bSkipPoolDefs );
    2143             :     }
    2144         150 : }
    2145             : 
    2146          31 : void Fill::writeToPropertyMap( PropertyMap& rPropMap ) const
    2147             : {
    2148          31 :     if( maApiData.mbUsed )
    2149             :     {
    2150          31 :         rPropMap[ PROP_CellBackColor ] <<= maApiData.mnColor;
    2151          31 :         rPropMap[ PROP_IsCellBackgroundTransparent ] <<= maApiData.mbTransparent;
    2152             :     }
    2153          31 : }
    2154             : 
    2155             : // ============================================================================
    2156             : 
    2157         186 : XfModel::XfModel() :
    2158             :     mnStyleXfId( -1 ),
    2159             :     mnFontId( -1 ),
    2160             :     mnNumFmtId( -1 ),
    2161             :     mnBorderId( -1 ),
    2162             :     mnFillId( -1 ),
    2163             :     mbCellXf( true ),
    2164             :     mbFontUsed( false ),
    2165             :     mbNumFmtUsed( false ),
    2166             :     mbAlignUsed( false ),
    2167             :     mbProtUsed( false ),
    2168             :     mbBorderUsed( false ),
    2169         186 :     mbAreaUsed( false )
    2170             : {
    2171         186 : }
    2172             : 
    2173             : // ============================================================================
    2174             : 
    2175         186 : Xf::Xf( const WorkbookHelper& rHelper ) :
    2176             :     WorkbookHelper( rHelper ),
    2177             :     maAlignment( rHelper ),
    2178             :     maProtection( rHelper ),
    2179             :     meRotationRef( ::com::sun::star::table::CellVertJustify2::STANDARD ),
    2180         186 :     mpStyleSheet( NULL )
    2181             : {
    2182         186 : }
    2183             : 
    2184         186 : void Xf::importXf( const AttributeList& rAttribs, bool bCellXf )
    2185             : {
    2186         186 :     maModel.mbCellXf = bCellXf;
    2187         186 :     maModel.mnStyleXfId = rAttribs.getInteger( XML_xfId, -1 );
    2188         186 :     maModel.mnFontId = rAttribs.getInteger( XML_fontId, -1 );
    2189         186 :     maModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, -1 );
    2190         186 :     maModel.mnBorderId = rAttribs.getInteger( XML_borderId, -1 );
    2191         186 :     maModel.mnFillId = rAttribs.getInteger( XML_fillId, -1 );
    2192             : 
    2193             :     /*  Default value of the apply*** attributes is dependent on context:
    2194             :         true in cellStyleXfs element, false in cellXfs element... */
    2195         186 :     maModel.mbAlignUsed  = rAttribs.getBool( XML_applyAlignment,    !maModel.mbCellXf );
    2196         186 :     maModel.mbProtUsed   = rAttribs.getBool( XML_applyProtection,   !maModel.mbCellXf );
    2197         186 :     maModel.mbFontUsed   = rAttribs.getBool( XML_applyFont,         !maModel.mbCellXf );
    2198         186 :     maModel.mbNumFmtUsed = rAttribs.getBool( XML_applyNumberFormat, !maModel.mbCellXf );
    2199         186 :     maModel.mbBorderUsed = rAttribs.getBool( XML_applyBorder,       !maModel.mbCellXf );
    2200         186 :     maModel.mbAreaUsed   = rAttribs.getBool( XML_applyFill,         !maModel.mbCellXf );
    2201         186 : }
    2202             : 
    2203          35 : void Xf::importAlignment( const AttributeList& rAttribs )
    2204             : {
    2205          35 :     maAlignment.importAlignment( rAttribs );
    2206          35 : }
    2207             : 
    2208          33 : void Xf::importProtection( const AttributeList& rAttribs )
    2209             : {
    2210          33 :     maProtection.importProtection( rAttribs );
    2211          33 : }
    2212             : 
    2213           0 : void Xf::importXf( SequenceInputStream& rStrm, bool bCellXf )
    2214             : {
    2215           0 :     maModel.mbCellXf = bCellXf;
    2216           0 :     maModel.mnStyleXfId = rStrm.readuInt16();
    2217           0 :     maModel.mnNumFmtId = rStrm.readuInt16();
    2218           0 :     maModel.mnFontId = rStrm.readuInt16();
    2219           0 :     maModel.mnFillId = rStrm.readuInt16();
    2220           0 :     maModel.mnBorderId = rStrm.readuInt16();
    2221           0 :     sal_uInt32 nFlags = rStrm.readuInt32();
    2222           0 :     maAlignment.setBiff12Data( nFlags );
    2223           0 :     maProtection.setBiff12Data( nFlags );
    2224             :     // used flags, see comments in Xf::setBiffUsedFlags()
    2225           0 :     sal_uInt16 nUsedFlags = rStrm.readuInt16();
    2226           0 :     maModel.mbFontUsed   = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_FONT_USED );
    2227           0 :     maModel.mbNumFmtUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_NUMFMT_USED );
    2228           0 :     maModel.mbAlignUsed  = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_ALIGN_USED );
    2229           0 :     maModel.mbProtUsed   = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_PROT_USED );
    2230           0 :     maModel.mbBorderUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_BORDER_USED );
    2231           0 :     maModel.mbAreaUsed   = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_AREA_USED );
    2232           0 : }
    2233             : 
    2234         186 : void Xf::finalizeImport()
    2235             : {
    2236             :     // alignment and protection
    2237         186 :     maAlignment.finalizeImport();
    2238         186 :     maProtection.finalizeImport();
    2239         186 :     createPattern();
    2240         186 : }
    2241             : 
    2242         109 : FontRef Xf::getFont() const
    2243             : {
    2244         109 :     return getStyles().getFont( maModel.mnFontId );
    2245             : }
    2246             : 
    2247          37 : void Xf::writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId  )
    2248             : {
    2249          37 :     createPattern();
    2250          37 :     ScPatternAttr& rPat = *mpPattern;
    2251          37 :     ScDocument& rDoc = getScDocument();
    2252          37 :     if ( isCellXf() )
    2253             :     {
    2254          37 :         StylesBuffer& rStyles = getStyles();
    2255          37 :         rStyles.createCellStyle( maModel.mnStyleXfId );
    2256             : 
    2257          37 :         mpStyleSheet = rStyles.getCellStyleSheet( maModel.mnStyleXfId );
    2258          37 :         if ( mpStyleSheet )
    2259             :         {
    2260           1 :             rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*mpStyleSheet), rMarkData );
    2261             :         }
    2262             :         else
    2263             :         {
    2264          36 :             ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
    2265          36 :             if (pStylePool)
    2266             :             {
    2267             :                 ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>(
    2268             :                     pStylePool->Find(
    2269          36 :                         ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA));
    2270             : 
    2271          36 :                 if (pStyleSheet)
    2272          36 :                     rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*pStyleSheet), rMarkData );
    2273             :             }
    2274             :         }
    2275             :     }
    2276          37 :     if ( nNumFmtId >= 0 )
    2277             :     {
    2278           0 :         ScPatternAttr aNumPat(rDoc.GetPool());
    2279           0 :         getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId );
    2280           0 :         rPat.GetItemSet().Put(aNumPat.GetItemSet());
    2281             :     }
    2282          37 :     rDoc.ApplySelectionPattern( rPat, rMarkData );
    2283          37 : }
    2284             : 
    2285          40 : void Xf::writeToPropertyMap( PropertyMap& rPropMap ) const
    2286             : {
    2287          40 :     StylesBuffer& rStyles = getStyles();
    2288             : 
    2289             :     // create and set cell style
    2290          40 :     if( isCellXf() )
    2291          29 :         rPropMap[ PROP_CellStyle ] <<= rStyles.createCellStyle( maModel.mnStyleXfId );
    2292             : 
    2293          40 :     if( maModel.mbFontUsed )
    2294          11 :         rStyles.writeFontToPropertyMap( rPropMap, maModel.mnFontId );
    2295          40 :     if( maModel.mbNumFmtUsed )
    2296          11 :         rStyles.writeNumFmtToPropertyMap( rPropMap, maModel.mnNumFmtId );
    2297          40 :     if( maModel.mbAlignUsed )
    2298          11 :         maAlignment.writeToPropertyMap( rPropMap );
    2299          40 :     if( maModel.mbProtUsed )
    2300          11 :         maProtection.writeToPropertyMap( rPropMap );
    2301          40 :     if( maModel.mbBorderUsed )
    2302          11 :         rStyles.writeBorderToPropertyMap( rPropMap, maModel.mnBorderId );
    2303          40 :     if( maModel.mbAreaUsed )
    2304          11 :         rStyles.writeFillToPropertyMap( rPropMap, maModel.mnFillId );
    2305          40 :     if( maModel.mbAlignUsed || maModel.mbBorderUsed )
    2306          11 :         rPropMap[ PROP_RotateReference ] <<= meRotationRef;
    2307             : 
    2308          40 :     sal_Int32 eRotRef = ::com::sun::star::table::CellVertJustify2::STANDARD;
    2309          40 :     if (maModel.mbBorderUsed && rStyles.hasBorder(maModel.mnBorderId) && maAlignment.getApiData().mnRotation)
    2310           0 :         eRotRef = ::com::sun::star::table::CellVertJustify2::BOTTOM;
    2311          40 :     rPropMap[ PROP_RotateReference ] <<= eRotRef;
    2312          40 : }
    2313             : 
    2314          40 : void Xf::writeToPropertySet( PropertySet& rPropSet ) const
    2315             : {
    2316          40 :     PropertyMap aPropMap;
    2317          40 :     writeToPropertyMap( aPropMap );
    2318          40 :     rPropSet.setProperties( aPropMap );
    2319          40 : }
    2320             : 
    2321             : const ::ScPatternAttr&
    2322         228 : Xf::createPattern( bool bSkipPoolDefs )
    2323             : {
    2324         228 :     if( mpPattern.get() )
    2325          42 :         return *mpPattern;
    2326         186 :     mpPattern.reset( new ::ScPatternAttr( getScDocument().GetPool() ) );
    2327         186 :     SfxItemSet& rItemSet = mpPattern->GetItemSet();
    2328             :     /*  Enables the used flags, if the formatting attributes differ from the
    2329             :         style XF. In cell XFs Excel uses the cell attributes, if they differ
    2330             :         from the parent style XF (even if the used flag is switched off).
    2331             :         #109899# ...or if the respective flag is not set in parent style XF.
    2332             :      */
    2333         186 :     StylesBuffer& rStyles = getStyles();
    2334             : 
    2335         186 :     const Xf* pStyleXf = isCellXf() ? rStyles.getStyleXf( maModel.mnStyleXfId ).get() : 0;
    2336         186 :     if( pStyleXf )
    2337             :     {
    2338          37 :         const XfModel& rStyleData = pStyleXf->maModel;
    2339          37 :         if( !maModel.mbFontUsed )
    2340          23 :             maModel.mbFontUsed = !rStyleData.mbFontUsed || (maModel.mnFontId != rStyleData.mnFontId);
    2341          37 :         if( !maModel.mbNumFmtUsed )
    2342          37 :             maModel.mbNumFmtUsed = !rStyleData.mbNumFmtUsed || (maModel.mnNumFmtId != rStyleData.mnNumFmtId);
    2343          37 :         if( !maModel.mbAlignUsed )
    2344          33 :             maModel.mbAlignUsed = !rStyleData.mbAlignUsed || !(maAlignment.getApiData() == pStyleXf->maAlignment.getApiData());
    2345          37 :         if( !maModel.mbProtUsed )
    2346          37 :             maModel.mbProtUsed = !rStyleData.mbProtUsed || !(maProtection.getApiData() == pStyleXf->maProtection.getApiData());
    2347          37 :         if( !maModel.mbBorderUsed )
    2348          37 :             maModel.mbBorderUsed = !rStyleData.mbBorderUsed || !rStyles.equalBorders( maModel.mnBorderId, rStyleData.mnBorderId );
    2349          37 :         if( !maModel.mbAreaUsed )
    2350          37 :             maModel.mbAreaUsed = !rStyleData.mbAreaUsed || !rStyles.equalFills( maModel.mnFillId, rStyleData.mnFillId );
    2351             :     }
    2352             :     // cell protection
    2353         186 :     if( maModel.mbProtUsed )
    2354             :     {
    2355          16 :         maProtection.fillToItemSet( rItemSet, bSkipPoolDefs );
    2356             :     }
    2357             : 
    2358             :     // font
    2359         186 :     if( maModel.mbFontUsed )
    2360             :     {
    2361         164 :         rStyles.writeFontToItemSet( rItemSet, maModel.mnFontId, bSkipPoolDefs );
    2362             :     }
    2363             : 
    2364             :     // value format
    2365         186 :     if( maModel.mbNumFmtUsed )
    2366             :     {
    2367         161 :         rStyles.writeNumFmtToItemSet( rItemSet, maModel.mnNumFmtId, bSkipPoolDefs );
    2368             :     }
    2369             :     // alignment
    2370         186 :     if( maModel.mbAlignUsed )
    2371             :     {
    2372          20 :         maAlignment.fillToItemSet( rItemSet, bSkipPoolDefs );
    2373             :     }
    2374             : 
    2375             :     // border
    2376         186 :     if( maModel.mbBorderUsed )
    2377             :     {
    2378          16 :         rStyles.writeBorderToItemSet( rItemSet, maModel.mnBorderId, bSkipPoolDefs );
    2379             :     }
    2380             : 
    2381             :     // area
    2382         186 :     if( maModel.mbAreaUsed )
    2383             :     {
    2384         150 :         rStyles.writeFillToItemSet( rItemSet, maModel.mnFillId, bSkipPoolDefs );
    2385             :     }
    2386             : 
    2387             :     /*  #i38709# Decide which rotation reference mode to use. If any outer
    2388             :         border line of the cell is set (either explicitly or via cell style),
    2389             :         and the cell contents are rotated, set rotation reference to bottom of
    2390             :         cell. This causes the borders to be painted rotated with the text. */
    2391         186 :     if( const Alignment* pAlignment = maModel.mbAlignUsed ? &maAlignment : (pStyleXf ? &pStyleXf->maAlignment : 0) )
    2392             :     {
    2393          53 :         SvxRotateMode eRotateMode = SVX_ROTATE_MODE_STANDARD;
    2394          53 :         sal_Int32 nBorderId = maModel.mbBorderUsed ? maModel.mnBorderId : (pStyleXf ? pStyleXf->maModel.mnBorderId : -1);
    2395          53 :         if( const Border* pBorder = rStyles.getBorder( nBorderId ).get() )
    2396             :         {
    2397          53 :             if( (pAlignment->getApiData().mnRotation != 0) && pBorder->getApiData().hasAnyOuterBorder() )
    2398             :             {
    2399           0 :                 meRotationRef = ::com::sun::star::table::CellVertJustify2::BOTTOM;
    2400           0 :                 eRotateMode = SVX_ROTATE_MODE_BOTTOM;
    2401             :             }
    2402             :         }
    2403          53 :         ScfTools::PutItem( rItemSet, SvxRotateModeItem( eRotateMode, ATTR_ROTATE_MODE ), bSkipPoolDefs );
    2404             :     }
    2405             : 
    2406         186 :     return *mpPattern;
    2407             : }
    2408             : 
    2409             : // ============================================================================
    2410             : 
    2411          70 : Dxf::Dxf( const WorkbookHelper& rHelper ) :
    2412          70 :     WorkbookHelper( rHelper )
    2413             : {
    2414          70 : }
    2415             : 
    2416          20 : FontRef Dxf::createFont( bool bAlwaysNew )
    2417             : {
    2418          20 :     if( bAlwaysNew || !mxFont )
    2419          20 :         mxFont.reset( new Font( *this, true ) );
    2420          20 :     return mxFont;
    2421             : }
    2422             : 
    2423           0 : BorderRef Dxf::createBorder( bool bAlwaysNew )
    2424             : {
    2425           0 :     if( bAlwaysNew || !mxBorder )
    2426           0 :         mxBorder.reset( new Border( *this, true ) );
    2427           0 :     return mxBorder;
    2428             : }
    2429             : 
    2430          20 : FillRef Dxf::createFill( bool bAlwaysNew )
    2431             : {
    2432          20 :     if( bAlwaysNew || !mxFill )
    2433          20 :         mxFill.reset( new Fill( *this, true ) );
    2434          20 :     return mxFill;
    2435             : }
    2436             : 
    2437          70 : void Dxf::importNumFmt( const AttributeList& rAttribs )
    2438             : {
    2439             :     // don't propagate number formats defined in Dxf entries
    2440             :     // they can have the same id ( but different format codes ) as those
    2441             :     // defined globally earlier. We discard the id defined in XML_numFmtId
    2442             :     // and generate one ourselves ( this assumes that the normal numberformat
    2443             :     // import has already taken place )
    2444          70 :     sal_Int32 nNumFmtId  = getStyles().nextFreeNumFmtId();
    2445          70 :     OUString aFmtCode = rAttribs.getXString( XML_formatCode, OUString() );
    2446             :     // we might need to do this generally for format codes,
    2447             :     // specifically for a fraction code '\ ?/?' is passed to us in xml, the '\' is not
    2448             :     // an escape character but merely should be telling the formatter to display the next
    2449             :     // char in the format ( afaics it does that anyhow )
    2450          70 :     aFmtCode = aFmtCode.replaceAll("\\", "");
    2451          70 :     mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
    2452          70 : }
    2453             : 
    2454           0 : void Dxf::importDxf( SequenceInputStream& rStrm )
    2455             : {
    2456           0 :     sal_Int32 nNumFmtId = -1;
    2457           0 :     OUString aFmtCode;
    2458             :     sal_uInt16 nRecCount;
    2459           0 :     rStrm.skip( 4 );    // flags
    2460           0 :     rStrm >> nRecCount;
    2461           0 :     for( sal_uInt16 nRec = 0; !rStrm.isEof() && (nRec < nRecCount); ++nRec )
    2462             :     {
    2463             :         sal_uInt16 nSubRecId, nSubRecSize;
    2464           0 :         sal_Int64 nRecEnd = rStrm.tell();
    2465           0 :         rStrm >> nSubRecId >> nSubRecSize;
    2466           0 :         nRecEnd += nSubRecSize;
    2467           0 :         switch( nSubRecId )
    2468             :         {
    2469           0 :             case BIFF12_DXF_FILL_PATTERN:       createFill( false )->importDxfPattern( rStrm );                         break;
    2470           0 :             case BIFF12_DXF_FILL_FGCOLOR:       createFill( false )->importDxfFgColor( rStrm );                         break;
    2471           0 :             case BIFF12_DXF_FILL_BGCOLOR:       createFill( false )->importDxfBgColor( rStrm );                         break;
    2472           0 :             case BIFF12_DXF_FILL_GRADIENT:      createFill( false )->importDxfGradient( rStrm );                        break;
    2473           0 :             case BIFF12_DXF_FILL_STOP:          createFill( false )->importDxfStop( rStrm );                            break;
    2474           0 :             case BIFF12_DXF_FONT_COLOR:         createFont( false )->importDxfColor( rStrm );                           break;
    2475           0 :             case BIFF12_DXF_BORDER_TOP:         createBorder( false )->importDxfBorder( XLS_TOKEN( top ), rStrm );      break;
    2476           0 :             case BIFF12_DXF_BORDER_BOTTOM:      createBorder( false )->importDxfBorder( XLS_TOKEN( bottom ), rStrm );   break;
    2477           0 :             case BIFF12_DXF_BORDER_LEFT:        createBorder( false )->importDxfBorder( XLS_TOKEN( left ), rStrm );     break;
    2478           0 :             case BIFF12_DXF_BORDER_RIGHT:       createBorder( false )->importDxfBorder( XLS_TOKEN( right ), rStrm );    break;
    2479           0 :             case BIFF12_DXF_FONT_NAME:          createFont( false )->importDxfName( rStrm );                            break;
    2480           0 :             case BIFF12_DXF_FONT_WEIGHT:        createFont( false )->importDxfWeight( rStrm );                          break;
    2481           0 :             case BIFF12_DXF_FONT_UNDERLINE:     createFont( false )->importDxfUnderline( rStrm );                       break;
    2482           0 :             case BIFF12_DXF_FONT_ESCAPEMENT:    createFont( false )->importDxfEscapement( rStrm );                      break;
    2483           0 :             case BIFF12_DXF_FONT_ITALIC:        createFont( false )->importDxfFlag( XML_i, rStrm );                     break;
    2484           0 :             case BIFF12_DXF_FONT_STRIKE:        createFont( false )->importDxfFlag( XML_strike, rStrm );                break;
    2485           0 :             case BIFF12_DXF_FONT_OUTLINE:       createFont( false )->importDxfFlag( XML_outline, rStrm );               break;
    2486           0 :             case BIFF12_DXF_FONT_SHADOW:        createFont( false )->importDxfFlag( XML_shadow, rStrm );                break;
    2487           0 :             case BIFF12_DXF_FONT_HEIGHT:        createFont( false )->importDxfHeight( rStrm );                          break;
    2488           0 :             case BIFF12_DXF_FONT_SCHEME:        createFont( false )->importDxfScheme( rStrm );                          break;
    2489           0 :             case BIFF12_DXF_NUMFMT_CODE:        aFmtCode = BiffHelper::readString( rStrm, false );                      break;
    2490           0 :             case BIFF12_DXF_NUMFMT_ID:          nNumFmtId = rStrm.readuInt16();                                         break;
    2491             :         }
    2492           0 :         rStrm.seek( nRecEnd );
    2493             :     }
    2494             :     OSL_ENSURE( !rStrm.isEof() && (rStrm.getRemaining() == 0), "Dxf::importDxf - unexpected remaining data" );
    2495           0 :     mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
    2496           0 : }
    2497             : 
    2498          70 : void Dxf::finalizeImport()
    2499             : {
    2500          70 :     if( mxFont.get() )
    2501          20 :         mxFont->finalizeImport();
    2502             :     // number format already finalized by the number formats buffer
    2503          70 :     if( mxAlignment.get() )
    2504           0 :         mxAlignment->finalizeImport();
    2505          70 :     if( mxProtection.get() )
    2506           0 :         mxProtection->finalizeImport();
    2507          70 :     if( mxBorder.get() )
    2508           0 :         mxBorder->finalizeImport();
    2509          70 :     if( mxFill.get() )
    2510          20 :         mxFill->finalizeImport();
    2511          70 : }
    2512             : 
    2513          36 : void Dxf::writeToPropertyMap( PropertyMap& rPropMap ) const
    2514             : {
    2515          36 :     if( mxFont.get() )
    2516          20 :         mxFont->writeToPropertyMap( rPropMap, FONT_PROPTYPE_CELL );
    2517          36 :     if( mxNumFmt.get() )
    2518          36 :         mxNumFmt->writeToPropertyMap( rPropMap );
    2519          36 :     if( mxAlignment.get() )
    2520           0 :         mxAlignment->writeToPropertyMap( rPropMap );
    2521          36 :     if( mxProtection.get() )
    2522           0 :         mxProtection->writeToPropertyMap( rPropMap );
    2523          36 :     if( mxBorder.get() )
    2524           0 :         mxBorder->writeToPropertyMap( rPropMap );
    2525          36 :     if( mxFill.get() )
    2526          20 :         mxFill->writeToPropertyMap( rPropMap );
    2527          36 : }
    2528             : 
    2529          36 : void Dxf::writeToPropertySet( PropertySet& rPropSet ) const
    2530             : {
    2531          36 :     PropertyMap aPropMap;
    2532          36 :     writeToPropertyMap( aPropMap );
    2533          36 :     rPropSet.setProperties( aPropMap );
    2534          36 : }
    2535             : 
    2536             : // ============================================================================
    2537             : 
    2538             : namespace {
    2539             : 
    2540             : const sal_Char* const spcLegacyStyleNamePrefix = "Excel_BuiltIn_";
    2541             : const sal_Char* const sppcLegacyStyleNames[] =
    2542             : {
    2543             :     "Normal",
    2544             :     "RowLevel_",            // outline level will be appended
    2545             :     "ColumnLevel_",         // outline level will be appended
    2546             :     "Comma",
    2547             :     "Currency",
    2548             :     "Percent",
    2549             :     "Comma_0",              // new in BIFF4
    2550             :     "Currency_0",
    2551             :     "Hyperlink",            // new in BIFF8
    2552             :     "Followed_Hyperlink"
    2553             : };
    2554             : const sal_Int32 snLegacyStyleNamesCount = static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( sppcLegacyStyleNames ) );
    2555             : 
    2556             : const sal_Char* const spcStyleNamePrefix = "Excel Built-in ";
    2557             : const sal_Char* const sppcStyleNames[] =
    2558             : {
    2559             :     "Normal",
    2560             :     "RowLevel_",            // outline level will be appended
    2561             :     "ColLevel_",            // outline level will be appended
    2562             :     "Comma",
    2563             :     "Currency",
    2564             :     "Percent",
    2565             :     "Comma [0]",            // new in BIFF4
    2566             :     "Currency [0]",
    2567             :     "Hyperlink",            // new in BIFF8
    2568             :     "Followed Hyperlink",
    2569             :     "Note",                 // new in OOX
    2570             :     "Warning Text",
    2571             :     0,
    2572             :     0,
    2573             :     0,
    2574             :     "Title",
    2575             :     "Heading 1",
    2576             :     "Heading 2",
    2577             :     "Heading 3",
    2578             :     "Heading 4",
    2579             :     "Input",
    2580             :     "Output",
    2581             :     "Calculation",
    2582             :     "Check Cell",
    2583             :     "Linked Cell",
    2584             :     "Total",
    2585             :     "Good",
    2586             :     "Bad",
    2587             :     "Neutral",
    2588             :     "Accent1",
    2589             :     "20% - Accent1",
    2590             :     "40% - Accent1",
    2591             :     "60% - Accent1",
    2592             :     "Accent2",
    2593             :     "20% - Accent2",
    2594             :     "40% - Accent2",
    2595             :     "60% - Accent2",
    2596             :     "Accent3",
    2597             :     "20% - Accent3",
    2598             :     "40% - Accent3",
    2599             :     "60% - Accent3",
    2600             :     "Accent4",
    2601             :     "20% - Accent4",
    2602             :     "40% - Accent4",
    2603             :     "60% - Accent4",
    2604             :     "Accent5",
    2605             :     "20% - Accent5",
    2606             :     "40% - Accent5",
    2607             :     "60% - Accent5",
    2608             :     "Accent6",
    2609             :     "20% - Accent6",
    2610             :     "40% - Accent6",
    2611             :     "60% - Accent6",
    2612             :     "Explanatory Text"
    2613             : };
    2614             : const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( sppcStyleNames ) );
    2615             : 
    2616         126 : OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, const OUString& rName, sal_Int32 nLevel = 0 )
    2617             : {
    2618             :     OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" );
    2619         126 :     OUStringBuffer aStyleName;
    2620         126 :     aStyleName.appendAscii( spcStyleNamePrefix );
    2621         126 :     if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != 0) )
    2622         125 :         aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] );
    2623           1 :     else if( !rName.isEmpty() )
    2624           1 :         aStyleName.append( rName );
    2625             :     else
    2626           0 :         aStyleName.append( nBuiltinId );
    2627         126 :     if( (nBuiltinId == OOX_STYLE_ROWLEVEL) || (nBuiltinId == OOX_STYLE_COLLEVEL) )
    2628           0 :         aStyleName.append( nLevel );
    2629         126 :     return aStyleName.makeStringAndClear();
    2630             : }
    2631             : 
    2632          44 : OUString lclCreateStyleName( const CellStyleModel& rModel )
    2633             : {
    2634          44 :     return rModel.mbBuiltin ? lclGetBuiltinStyleName( rModel.mnBuiltinId, rModel.maName, rModel.mnLevel ) : rModel.maName;
    2635             : }
    2636             : 
    2637             : } // namespace
    2638             : 
    2639             : // ----------------------------------------------------------------------------
    2640             : 
    2641          51 : CellStyleModel::CellStyleModel() :
    2642             :     mnXfId( -1 ),
    2643             :     mnBuiltinId( -1 ),
    2644             :     mnLevel( 0 ),
    2645             :     mbBuiltin( false ),
    2646             :     mbCustom( false ),
    2647          51 :     mbHidden( false )
    2648             : {
    2649          51 : }
    2650             : 
    2651          91 : bool CellStyleModel::isBuiltin() const
    2652             : {
    2653          91 :     return mbBuiltin && (mnBuiltinId >= 0);
    2654             : }
    2655             : 
    2656         103 : bool CellStyleModel::isDefaultStyle() const
    2657             : {
    2658         103 :     return mbBuiltin && (mnBuiltinId == OOX_STYLE_NORMAL);
    2659             : }
    2660             : 
    2661             : // ============================================================================
    2662             : 
    2663          51 : CellStyle::CellStyle( const WorkbookHelper& rHelper ) :
    2664             :     WorkbookHelper( rHelper ),
    2665             :     mbCreated( false ),
    2666          51 :     mpStyleSheet( NULL )
    2667             : {
    2668          51 : }
    2669             : 
    2670          51 : void CellStyle::importCellStyle( const AttributeList& rAttribs )
    2671             : {
    2672          51 :     maModel.maName      = rAttribs.getXString( XML_name, OUString() );
    2673          51 :     maModel.mnXfId      = rAttribs.getInteger( XML_xfId, -1 );
    2674          51 :     maModel.mnBuiltinId = rAttribs.getInteger( XML_builtinId, -1 );
    2675          51 :     maModel.mnLevel     = rAttribs.getInteger( XML_iLevel, 0 );
    2676          51 :     maModel.mbBuiltin   = rAttribs.hasAttribute( XML_builtinId );
    2677          51 :     maModel.mbCustom    = rAttribs.getBool( XML_customBuiltin, false );
    2678          51 :     maModel.mbHidden    = rAttribs.getBool( XML_hidden, false );
    2679          51 : }
    2680             : 
    2681           0 : void CellStyle::importCellStyle( SequenceInputStream& rStrm )
    2682             : {
    2683             :     sal_uInt16 nFlags;
    2684           0 :     rStrm >> maModel.mnXfId >> nFlags;
    2685           0 :     maModel.mnBuiltinId = rStrm.readInt8();
    2686           0 :     maModel.mnLevel = rStrm.readInt8();
    2687           0 :     rStrm >> maModel.maName;
    2688           0 :     maModel.mbBuiltin = getFlag( nFlags, BIFF12_CELLSTYLE_BUILTIN );
    2689           0 :     maModel.mbCustom = getFlag( nFlags, BIFF12_CELLSTYLE_CUSTOM );
    2690           0 :     maModel.mbHidden = getFlag( nFlags, BIFF12_CELLSTYLE_HIDDEN );
    2691           0 : }
    2692             : 
    2693          96 : void CellStyle::createCellStyle()
    2694             : {
    2695             : 
    2696             :     // #i1624# #i1768# ignore unnamed user styles
    2697          96 :     if( !mbCreated )
    2698          17 :         mbCreated = maFinalName.isEmpty();
    2699             : 
    2700          96 :     ::ScDocument& rDoc = getScDocument();
    2701          96 :     if( !mbCreated && !mpStyleSheet )
    2702             :     {
    2703           5 :         bool bCreatePattern = false;
    2704           5 :         Xf* pXF = getStyles().getStyleXf( maModel.mnXfId ).get();
    2705             : 
    2706           5 :         bool bDefStyle = maModel.isDefaultStyle();
    2707           5 :         if( bDefStyle )
    2708             :         {
    2709             :             // use existing "Default" style sheet
    2710           0 :             mpStyleSheet = static_cast< ScStyleSheet* >( static_cast< ScStyleSheetPool* >( rDoc.GetStyleSheetPool() )->Find(
    2711           0 :                 getStyles().getDefaultStyleName(), SFX_STYLE_FAMILY_PARA ) );
    2712             :             OSL_ENSURE( mpStyleSheet, "CellStyle::createStyle - Default style not found" );
    2713           0 :             bCreatePattern = true;
    2714             :         }
    2715             :         else
    2716             :         {
    2717           5 :             mpStyleSheet = static_cast< ScStyleSheet* >( static_cast< ScStyleSheetPool* >( rDoc.GetStyleSheetPool() )->Find( maFinalName, SFX_STYLE_FAMILY_PARA ) );
    2718           5 :             if( !mpStyleSheet )
    2719             :             {
    2720           5 :                 mpStyleSheet = &static_cast< ScStyleSheet& >( rDoc.GetStyleSheetPool()->Make( maFinalName, SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_USERDEF ) );
    2721           5 :                 bCreatePattern = true;
    2722             :             }
    2723             :         }
    2724             : 
    2725             :         // bDefStyle==true omits default pool items in CreatePattern()
    2726           5 :         if( bCreatePattern && mpStyleSheet && pXF )
    2727           5 :             mpStyleSheet->GetItemSet().Put( pXF->createPattern( bDefStyle ).GetItemSet() );
    2728             :     }
    2729          96 : }
    2730             : 
    2731          40 : void CellStyle::finalizeImport( const OUString& rFinalName )
    2732             : {
    2733          40 :     maFinalName = rFinalName;
    2734          40 :     if( !maModel.isBuiltin() || maModel.mbCustom )
    2735           5 :         createCellStyle();
    2736          40 : }
    2737             : 
    2738             : // ============================================================================
    2739             : 
    2740          11 : CellStyleBuffer::CellStyleBuffer( const WorkbookHelper& rHelper ) :
    2741          11 :     WorkbookHelper( rHelper )
    2742             : {
    2743          11 : }
    2744             : 
    2745          51 : CellStyleRef CellStyleBuffer::importCellStyle( const AttributeList& rAttribs )
    2746             : {
    2747          51 :     CellStyleRef xCellStyle( new CellStyle( *this ) );
    2748          51 :     xCellStyle->importCellStyle( rAttribs );
    2749          51 :     insertCellStyle( xCellStyle );
    2750          51 :     return xCellStyle;
    2751             : }
    2752             : 
    2753           0 : CellStyleRef CellStyleBuffer::importCellStyle( SequenceInputStream& rStrm )
    2754             : {
    2755           0 :     CellStyleRef xCellStyle( new CellStyle( *this ) );
    2756           0 :     xCellStyle->importCellStyle( rStrm );
    2757           0 :     insertCellStyle( xCellStyle );
    2758           0 :     return xCellStyle;
    2759             : }
    2760             : 
    2761          11 : void CellStyleBuffer::finalizeImport()
    2762             : {
    2763             :     // calculate final names of all styles
    2764             :     typedef RefMap< OUString, CellStyle, IgnoreCaseCompare > CellStyleNameMap;
    2765          11 :     CellStyleNameMap aCellStyles;
    2766          11 :     CellStyleVector aConflictNameStyles;
    2767             : 
    2768             :     /*  First, reserve style names that are built-in in Calc. This causes that
    2769             :         imported cell styles get different unused names and thus do not try to
    2770             :         overwrite these built-in styles. For BIFF4 workbooks (which contain a
    2771             :         separate list of cell styles per sheet), reserve all existing styles if
    2772             :         current sheet is not the first sheet (this styles buffer will be
    2773             :         constructed again for every new sheet). This will create unique names
    2774             :         for styles in different sheets with the same name. Assuming that the
    2775             :         BIFF4W import filter is never used to import from clipboard... */
    2776          11 :     bool bReserveAll = (getFilterType() == FILTER_BIFF) && (getBiff() == BIFF4) && isWorkbookFile() && (getCurrentSheetIndex() > 0);
    2777             :     try
    2778             :     {
    2779             :         // unfortunately, com.sun.star.style.StyleFamily does not implement XEnumerationAccess...
    2780          11 :         Reference< XIndexAccess > xStyleFamilyIA( getStyleFamily( false ), UNO_QUERY_THROW );
    2781          66 :         for( sal_Int32 nIndex = 0, nCount = xStyleFamilyIA->getCount(); nIndex < nCount; ++nIndex )
    2782             :         {
    2783          55 :             Reference< XStyle > xStyle( xStyleFamilyIA->getByIndex( nIndex ), UNO_QUERY_THROW );
    2784          55 :             if( bReserveAll || !xStyle->isUserDefined() )
    2785             :             {
    2786          55 :                 Reference< XNamed > xStyleName( xStyle, UNO_QUERY_THROW );
    2787             :                 // create an empty entry by using ::std::map<>::operator[]
    2788          55 :                 aCellStyles[ xStyleName->getName() ];
    2789             :             }
    2790          66 :         }
    2791             :     }
    2792           0 :     catch( Exception& )
    2793             :     {
    2794             :     }
    2795             : 
    2796             :     /*  Calculate names of built-in styles. Store styles with reserved names
    2797             :         in the aConflictNameStyles list. */
    2798          58 :     for( CellStyleVector::iterator aIt = maBuiltinStyles.begin(), aEnd = maBuiltinStyles.end(); aIt != aEnd; ++aIt )
    2799             :     {
    2800          47 :         const CellStyleModel& rModel = (*aIt)->getModel();
    2801          47 :         if (rModel.isDefaultStyle())
    2802          11 :             continue;
    2803             : 
    2804          36 :         OUString aStyleName = lclCreateStyleName( rModel );
    2805             :         /*  If a builtin style entry already exists, and we do not reserve all
    2806             :             existing styles, we just stick with the last definition and ignore
    2807             :             the preceding ones. */
    2808          36 :         if( bReserveAll && (aCellStyles.count( aStyleName ) > 0) )
    2809           0 :             aConflictNameStyles.push_back( *aIt );
    2810             :         else
    2811          36 :             aCellStyles[ aStyleName ] = *aIt;
    2812          36 :     }
    2813             : 
    2814             :     /*  Calculate names of user defined styles. Store styles with reserved
    2815             :         names in the aConflictNameStyles list. */
    2816          15 :     for( CellStyleVector::iterator aIt = maUserStyles.begin(), aEnd = maUserStyles.end(); aIt != aEnd; ++aIt )
    2817             :     {
    2818           4 :         const CellStyleModel& rModel = (*aIt)->getModel();
    2819           4 :         OUString aStyleName = lclCreateStyleName( rModel );
    2820             :         // #i1624# #i1768# ignore unnamed user styles
    2821           4 :         if( aStyleName.getLength() > 0 )
    2822             :         {
    2823           4 :             if( aCellStyles.count( aStyleName ) > 0 )
    2824           4 :                 aConflictNameStyles.push_back( *aIt );
    2825             :             else
    2826           0 :                 aCellStyles[ aStyleName ] = *aIt;
    2827             :         }
    2828           4 :     }
    2829             : 
    2830             :     // find unused names for all styles with conflicting names
    2831          15 :     for( CellStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt )
    2832             :     {
    2833           4 :         const CellStyleModel& rModel = (*aIt)->getModel();
    2834           4 :         OUString aStyleName = lclCreateStyleName( rModel );
    2835           4 :         OUString aUnusedName;
    2836           4 :         sal_Int32 nIndex = 0;
    2837           4 :         do
    2838             :         {
    2839           4 :             aUnusedName = OUStringBuffer( aStyleName ).append( sal_Unicode( ' ' ) ).append( ++nIndex ).makeStringAndClear();
    2840             :         }
    2841           4 :         while( aCellStyles.count( aUnusedName ) > 0 );
    2842           4 :         aCellStyles[ aUnusedName ] = *aIt;
    2843           4 :     }
    2844             : 
    2845             :     // set final names and create user-defined and modified built-in cell styles
    2846          11 :     aCellStyles.forEachMemWithKey( &CellStyle::finalizeImport );
    2847             : 
    2848          11 :     if (mxDefStyle)
    2849             :     {
    2850          11 :         Reference<XNameAccess> xNA(getStyleFamily(false), UNO_QUERY_THROW);
    2851          11 :         if (xNA->hasByName("Default"))
    2852             :         {
    2853          11 :             PropertySet aPropSet(xNA->getByName("Default"));
    2854          11 :             getStyles().writeStyleXfToPropertySet(aPropSet, mxDefStyle->getModel().mnXfId);
    2855          11 :         }
    2856          11 :     }
    2857          11 : }
    2858             : 
    2859          49 : sal_Int32 CellStyleBuffer::getDefaultXfId() const
    2860             : {
    2861          49 :     return mxDefStyle.get() ? mxDefStyle->getModel().mnXfId : -1;
    2862             : }
    2863             : 
    2864          25 : OUString CellStyleBuffer::getDefaultStyleName() const
    2865             : {
    2866          25 :     return createCellStyle( mxDefStyle );
    2867             : }
    2868             : 
    2869          66 : OUString CellStyleBuffer::createCellStyle( sal_Int32 nXfId ) const
    2870             : {
    2871          66 :     return createCellStyle( maStylesByXf.get( nXfId ) );
    2872             : }
    2873             : 
    2874          37 : ::ScStyleSheet*   CellStyleBuffer::getCellStyleSheet( sal_Int32 nXfId ) const
    2875             : {
    2876          37 :     return getCellStyleSheet( maStylesByXf.get( nXfId ) );
    2877             : }
    2878             : 
    2879             : // private --------------------------------------------------------------------
    2880             : 
    2881          51 : void CellStyleBuffer::insertCellStyle( CellStyleRef xCellStyle )
    2882             : {
    2883          51 :     const CellStyleModel& rModel = xCellStyle->getModel();
    2884          51 :     if( rModel.mnXfId >= 0 )
    2885             :     {
    2886             :         // insert into the built-in map or user defined map
    2887          51 :         (rModel.isBuiltin() ? maBuiltinStyles : maUserStyles).push_back( xCellStyle );
    2888             : 
    2889             :         // insert into the XF identifier map
    2890             :         OSL_ENSURE( maStylesByXf.count( rModel.mnXfId ) == 0, "CellStyleBuffer::insertCellStyle - multiple styles with equal XF identifier" );
    2891          51 :         maStylesByXf[ rModel.mnXfId ] = xCellStyle;
    2892             : 
    2893             :         // remember default cell style
    2894          51 :         if( rModel.isDefaultStyle() )
    2895          11 :             mxDefStyle = xCellStyle;
    2896             :     }
    2897          51 : }
    2898             : 
    2899          37 : ::ScStyleSheet* CellStyleBuffer::getCellStyleSheet( const CellStyleRef& rxCellStyle ) const
    2900             : {
    2901          37 :     ::ScStyleSheet* pStyleSheet = NULL;
    2902          37 :     if ( rxCellStyle.get() )
    2903          37 :         pStyleSheet = rxCellStyle->getStyleSheet();
    2904          37 :     return pStyleSheet;
    2905             : }
    2906             : 
    2907          91 : OUString CellStyleBuffer::createCellStyle( const CellStyleRef& rxCellStyle ) const
    2908             : {
    2909          91 :     if( rxCellStyle.get() )
    2910             :     {
    2911          91 :         rxCellStyle->createCellStyle();
    2912          91 :         const OUString& rStyleName = rxCellStyle->getFinalStyleName();
    2913          91 :         if( !rStyleName.isEmpty() )
    2914           1 :             return rStyleName;
    2915             :     }
    2916             :     // on error: fallback to default style
    2917          90 :     return lclGetBuiltinStyleName( OOX_STYLE_NORMAL, OUString() );
    2918             : }
    2919             : 
    2920             : // ============================================================================
    2921             : 
    2922           0 : AutoFormatModel::AutoFormatModel() :
    2923             :     mnAutoFormatId( 0 ),
    2924             :     mbApplyNumFmt( false ),
    2925             :     mbApplyFont( false ),
    2926             :     mbApplyAlignment( false ),
    2927             :     mbApplyBorder( false ),
    2928             :     mbApplyFill( false ),
    2929           0 :     mbApplyProtection( false )
    2930             : {
    2931           0 : }
    2932             : 
    2933             : // ============================================================================
    2934             : 
    2935          11 : StylesBuffer::StylesBuffer( const WorkbookHelper& rHelper ) :
    2936             :     WorkbookHelper( rHelper ),
    2937             :     maPalette( rHelper ),
    2938             :     maNumFmts( rHelper ),
    2939          11 :     maCellStyles( rHelper )
    2940             : {
    2941          11 : }
    2942             : 
    2943          44 : FontRef StylesBuffer::createFont( sal_Int32* opnFontId )
    2944             : {
    2945          44 :     if( opnFontId ) *opnFontId = static_cast< sal_Int32 >( maFonts.size() );
    2946          44 :     FontRef xFont( new Font( *this, false ) );
    2947          44 :     maFonts.push_back( xFont );
    2948          44 :     return xFont;
    2949             : }
    2950             : 
    2951          70 : NumberFormatRef StylesBuffer::createNumFmt( sal_Int32 nNumFmtId, const OUString& rFmtCode )
    2952             : {
    2953          70 :     return maNumFmts.createNumFmt( nNumFmtId, rFmtCode );
    2954             : }
    2955             : 
    2956          70 : sal_Int32 StylesBuffer::nextFreeNumFmtId()
    2957             : {
    2958          70 :     return maNumFmts.nextFreeId();
    2959             : }
    2960             : 
    2961          11 : BorderRef StylesBuffer::createBorder( sal_Int32* opnBorderId )
    2962             : {
    2963          11 :     if( opnBorderId ) *opnBorderId = static_cast< sal_Int32 >( maBorders.size() );
    2964          11 :     BorderRef xBorder( new Border( *this, false ) );
    2965          11 :     maBorders.push_back( xBorder );
    2966          11 :     return xBorder;
    2967             : }
    2968             : 
    2969          24 : FillRef StylesBuffer::createFill( sal_Int32* opnFillId )
    2970             : {
    2971          24 :     if( opnFillId ) *opnFillId = static_cast< sal_Int32 >( maFills.size() );
    2972          24 :     FillRef xFill( new Fill( *this, false ) );
    2973          24 :     maFills.push_back( xFill );
    2974          24 :     return xFill;
    2975             : }
    2976             : 
    2977          37 : XfRef StylesBuffer::createCellXf( sal_Int32* opnXfId )
    2978             : {
    2979          37 :     if( opnXfId ) *opnXfId = static_cast< sal_Int32 >( maCellXfs.size() );
    2980          37 :     XfRef xXf( new Xf( *this ) );
    2981          37 :     maCellXfs.push_back( xXf );
    2982          37 :     return xXf;
    2983             : }
    2984             : 
    2985         149 : XfRef StylesBuffer::createStyleXf( sal_Int32* opnXfId )
    2986             : {
    2987         149 :     if( opnXfId ) *opnXfId = static_cast< sal_Int32 >( maStyleXfs.size() );
    2988         149 :     XfRef xXf( new Xf( *this ) );
    2989         149 :     maStyleXfs.push_back( xXf );
    2990         149 :     return xXf;
    2991             : }
    2992             : 
    2993          70 : DxfRef StylesBuffer::createDxf( sal_Int32* opnDxfId )
    2994             : {
    2995          70 :     if( opnDxfId ) *opnDxfId = static_cast< sal_Int32 >( maDxfs.size() );
    2996          70 :     DxfRef xDxf( new Dxf( *this ) );
    2997          70 :     maDxfs.push_back( xDxf );
    2998          70 :     return xDxf;
    2999             : }
    3000             : 
    3001          56 : void StylesBuffer::importPaletteColor( const AttributeList& rAttribs )
    3002             : {
    3003          56 :     maPalette.importPaletteColor( rAttribs );
    3004          56 : }
    3005             : 
    3006          29 : NumberFormatRef StylesBuffer::importNumFmt( const AttributeList& rAttribs )
    3007             : {
    3008          29 :     return maNumFmts.importNumFmt( rAttribs );
    3009             : }
    3010             : 
    3011          51 : CellStyleRef StylesBuffer::importCellStyle( const AttributeList& rAttribs )
    3012             : {
    3013          51 :     return maCellStyles.importCellStyle( rAttribs );
    3014             : }
    3015             : 
    3016           0 : void StylesBuffer::importPaletteColor( SequenceInputStream& rStrm )
    3017             : {
    3018           0 :     maPalette.importPaletteColor( rStrm );
    3019           0 : }
    3020             : 
    3021           0 : void StylesBuffer::importNumFmt( SequenceInputStream& rStrm )
    3022             : {
    3023           0 :     maNumFmts.importNumFmt( rStrm );
    3024           0 : }
    3025             : 
    3026           0 : void StylesBuffer::importCellStyle( SequenceInputStream& rStrm )
    3027             : {
    3028           0 :     maCellStyles.importCellStyle( rStrm );
    3029           0 : }
    3030             : 
    3031          11 : void StylesBuffer::finalizeImport()
    3032             : {
    3033             :     // fonts first, are needed to finalize unit converter and XFs below
    3034          11 :     maFonts.forEachMem( &Font::finalizeImport );
    3035             :     // finalize unit coefficients after default font is known
    3036          11 :     getUnitConverter().finalizeImport();
    3037             :     // number formats
    3038          11 :     maNumFmts.finalizeImport();
    3039             :     // borders and fills
    3040          11 :     maBorders.forEachMem( &Border::finalizeImport );
    3041          11 :     maFills.forEachMem( &Fill::finalizeImport );
    3042             :     // style XFs and cell XFs
    3043          11 :     maStyleXfs.forEachMem( &Xf::finalizeImport );
    3044          11 :     maCellXfs.forEachMem( &Xf::finalizeImport );
    3045             :     // built-in and user defined cell styles
    3046          11 :     maCellStyles.finalizeImport();
    3047             :     // differential formatting (for conditional formatting)
    3048          11 :     maDxfs.forEachMem( &Dxf::finalizeImport );
    3049          11 : }
    3050             : 
    3051          66 : sal_Int32 StylesBuffer::getPaletteColor( sal_Int32 nPaletteIdx ) const
    3052             : {
    3053          66 :     return maPalette.getColor( nPaletteIdx );
    3054             : }
    3055             : 
    3056         109 : FontRef StylesBuffer::getFont( sal_Int32 nFontId ) const
    3057             : {
    3058         109 :     return maFonts.get( nFontId );
    3059             : }
    3060             : 
    3061          53 : BorderRef StylesBuffer::getBorder( sal_Int32 nBorderId ) const
    3062             : {
    3063          53 :     return maBorders.get( nBorderId );
    3064             : }
    3065             : 
    3066         562 : XfRef StylesBuffer::getCellXf( sal_Int32 nXfId ) const
    3067             : {
    3068         562 :     return maCellXfs.get( nXfId );
    3069             : }
    3070             : 
    3071          91 : XfRef StylesBuffer::getStyleXf( sal_Int32 nXfId ) const
    3072             : {
    3073          91 :     return maStyleXfs.get( nXfId );
    3074             : }
    3075             : 
    3076          78 : FontRef StylesBuffer::getFontFromCellXf( sal_Int32 nXfId ) const
    3077             : {
    3078          78 :     FontRef xFont;
    3079          78 :     if( const Xf* pXf = getCellXf( nXfId ).get() )
    3080          60 :         xFont = pXf->getFont();
    3081          78 :     return xFont;
    3082             : }
    3083             : 
    3084          49 : FontRef StylesBuffer::getDefaultFont() const
    3085             : {
    3086          49 :     FontRef xDefFont;
    3087          49 :     if( const Xf* pXf = getStyleXf( maCellStyles.getDefaultXfId() ).get() )
    3088          49 :         xDefFont = pXf->getFont();
    3089             :     // no font from styles - try first loaded font (e.g. BIFF2)
    3090          49 :     if( !xDefFont )
    3091           0 :         xDefFont = maFonts.get( 0 );
    3092             :     OSL_ENSURE( xDefFont.get(), "StylesBuffer::getDefaultFont - no default font found" );
    3093          49 :     return xDefFont;
    3094             : }
    3095             : 
    3096          38 : const FontModel& StylesBuffer::getDefaultFontModel() const
    3097             : {
    3098          38 :     FontRef xDefFont = getDefaultFont();
    3099          38 :     return xDefFont.get() ? xDefFont->getModel() : getTheme().getDefaultFontModel();
    3100             : }
    3101             : 
    3102          37 : bool StylesBuffer::equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 ) const
    3103             : {
    3104          37 :     if( nBorderId1 == nBorderId2 )
    3105          37 :         return true;
    3106             : 
    3107           0 :     switch( getFilterType() )
    3108             :     {
    3109             :         case FILTER_OOXML:
    3110             :             // in OOXML, borders are assumed to be unique
    3111           0 :             return false;
    3112             : 
    3113             :         case FILTER_BIFF:
    3114             :         {
    3115             :             // in BIFF, a new border entry has been created for every XF
    3116           0 :             const Border* pBorder1 = maBorders.get( nBorderId1 ).get();
    3117           0 :             const Border* pBorder2 = maBorders.get( nBorderId2 ).get();
    3118           0 :             return pBorder1 && pBorder2 && (pBorder1->getApiData() == pBorder2->getApiData());
    3119             :         }
    3120             : 
    3121             :         case FILTER_UNKNOWN:
    3122           0 :         break;
    3123             :     }
    3124           0 :     return false;
    3125             : }
    3126             : 
    3127          37 : bool StylesBuffer::equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 ) const
    3128             : {
    3129          37 :     if( nFillId1 == nFillId2 )
    3130          36 :         return true;
    3131             : 
    3132           1 :     switch( getFilterType() )
    3133             :     {
    3134             :         case FILTER_OOXML:
    3135             :             // in OOXML, fills are assumed to be unique
    3136           1 :             return false;
    3137             : 
    3138             :         case FILTER_BIFF:
    3139             :         {
    3140             :             // in BIFF, a new fill entry has been created for every XF
    3141           0 :             const Fill* pFill1 = maFills.get( nFillId1 ).get();
    3142           0 :             const Fill* pFill2 = maFills.get( nFillId2 ).get();
    3143           0 :             return pFill1 && pFill2 && (pFill1->getApiData() == pFill2->getApiData());
    3144             :         }
    3145             : 
    3146             :         case FILTER_UNKNOWN:
    3147           0 :         break;
    3148             :     }
    3149           0 :     return false;
    3150             : }
    3151             : 
    3152          25 : OUString StylesBuffer::getDefaultStyleName() const
    3153             : {
    3154          25 :     return maCellStyles.getDefaultStyleName();
    3155             : }
    3156             : 
    3157          66 : OUString StylesBuffer::createCellStyle( sal_Int32 nXfId ) const
    3158             : {
    3159          66 :     return maCellStyles.createCellStyle( nXfId );
    3160             : }
    3161             : 
    3162          37 : ::ScStyleSheet* StylesBuffer::getCellStyleSheet( sal_Int32 nXfId ) const
    3163             : {
    3164          37 :     return maCellStyles.getCellStyleSheet( nXfId );
    3165             : }
    3166             : 
    3167          36 : OUString StylesBuffer::createDxfStyle( sal_Int32 nDxfId ) const
    3168             : {
    3169          36 :     OUString& rStyleName = maDxfStyles[ nDxfId ];
    3170          36 :     if( rStyleName.isEmpty() )
    3171             :     {
    3172          36 :         if( Dxf* pDxf = maDxfs.get( nDxfId ).get() )
    3173             :         {
    3174          36 :             rStyleName = OUStringBuffer( "ConditionalStyle_" ).append( nDxfId + 1 ).makeStringAndClear();
    3175             :             // create the style sheet (this may change rStyleName if such a style already exists)
    3176          36 :             Reference< XStyle > xStyle = createStyleObject( rStyleName, false );
    3177             :             // write style formatting properties
    3178          36 :             PropertySet aPropSet( xStyle );
    3179          36 :             pDxf->writeToPropertySet( aPropSet );
    3180             :         }
    3181             :         // on error: fallback to default style
    3182          36 :         if( rStyleName.isEmpty() )
    3183           0 :             rStyleName = maCellStyles.getDefaultStyleName();
    3184             :     }
    3185          36 :     return rStyleName;
    3186             : }
    3187             : 
    3188         164 : void StylesBuffer::writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs ) const
    3189             : {
    3190         164 :     if( Font* pFont = maFonts.get( nFontId ).get() )
    3191         164 :         pFont->fillToItemSet( rItemSet, FONT_PROPTYPE_CELL, bSkipPoolDefs );
    3192         164 : }
    3193             : 
    3194          11 : void StylesBuffer::writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const
    3195             : {
    3196          11 :     if( Font* pFont = maFonts.get( nFontId ).get() )
    3197          11 :         pFont->writeToPropertyMap( rPropMap, FONT_PROPTYPE_CELL );
    3198          11 : }
    3199             : 
    3200         161 : void StylesBuffer::writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const
    3201             : {
    3202         161 :     maNumFmts.fillToItemSet( rItemSet, nNumFmtId, bSkipPoolDefs );
    3203         161 : }
    3204             : 
    3205          11 : void StylesBuffer::writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const
    3206             : {
    3207          11 :     maNumFmts.writeToPropertyMap( rPropMap, nNumFmtId );
    3208          11 : }
    3209             : 
    3210          16 : void StylesBuffer::writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs ) const
    3211             : {
    3212          16 :     if( Border* pBorder = maBorders.get( nBorderId ).get() )
    3213          16 :         pBorder->fillToItemSet( rItemSet, bSkipPoolDefs );
    3214          16 : }
    3215             : 
    3216          11 : void StylesBuffer::writeBorderToPropertyMap( PropertyMap& rPropMap, sal_Int32 nBorderId ) const
    3217             : {
    3218          11 :     if( Border* pBorder = maBorders.get( nBorderId ).get() )
    3219          11 :         pBorder->writeToPropertyMap( rPropMap );
    3220          11 : }
    3221             : 
    3222         150 : void StylesBuffer::writeFillToItemSet( SfxItemSet& rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs ) const
    3223             : {
    3224         150 :     if( Fill* pFill = maFills.get( nFillId ).get() )
    3225         150 :         pFill->fillToItemSet( rItemSet, bSkipPoolDefs );
    3226         150 : }
    3227             : 
    3228          11 : void StylesBuffer::writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFillId ) const
    3229             : {
    3230          11 :     if( Fill* pFill = maFills.get( nFillId ).get() )
    3231          11 :         pFill->writeToPropertyMap( rPropMap );
    3232          11 : }
    3233             : 
    3234          62 : void StylesBuffer::writeCellXfToMarkData( ScMarkData& rMark,  sal_Int32 nXfId, sal_Int32 nNumFmtId  )
    3235             : {
    3236          62 :     if( Xf* pXf = maCellXfs.get( nXfId ).get() )
    3237          37 :         pXf->writeToMarkData( rMark, nNumFmtId );
    3238          62 : }
    3239             : 
    3240         119 : bool operator==( const XfModel& rXfModel1,  const XfModel& rXfModel2 )
    3241             : {
    3242             :     return ( rXfModel1.mbCellXf == rXfModel2.mbCellXf &&
    3243             :         rXfModel1.mnStyleXfId == rXfModel2.mnStyleXfId &&
    3244             :         rXfModel1.mbFontUsed == rXfModel2.mbFontUsed &&
    3245             :         rXfModel1.mnFontId == rXfModel2.mnFontId &&
    3246             :         rXfModel1.mbNumFmtUsed == rXfModel2.mbNumFmtUsed &&
    3247             :         rXfModel1.mnNumFmtId == rXfModel2.mnNumFmtId &&
    3248             :         rXfModel1.mbAlignUsed == rXfModel2.mbAlignUsed &&
    3249             :         rXfModel1.mbBorderUsed == rXfModel2.mbBorderUsed &&
    3250             :         rXfModel1.mnBorderId == rXfModel2.mnBorderId &&
    3251             :         rXfModel1.mbAreaUsed == rXfModel2.mbAreaUsed &&
    3252             :         rXfModel1.mnFillId == rXfModel2.mnFillId &&
    3253         119 :         rXfModel1.mbProtUsed == rXfModel2.mbProtUsed );
    3254             : }
    3255             : 
    3256         119 : bool operator==( const Xf& rXf1, const Xf& rXf2 )
    3257             : {
    3258         119 :     if ( rXf1.maModel == rXf2.maModel )
    3259             :     {
    3260           6 :         if ( rXf1.maModel.mbAlignUsed )
    3261             :         {
    3262           6 :             if ( !( rXf1.maAlignment.getApiData() == rXf2.maAlignment.getApiData() ) )
    3263           6 :                 return false;
    3264             :         }
    3265           0 :         if ( rXf1.maModel.mbProtUsed )
    3266             :         {
    3267           0 :             if ( !( rXf1.maProtection.getApiData() == rXf2.maProtection.getApiData() ) )
    3268           0 :                 return false;
    3269             :         }
    3270           0 :         return true;
    3271             :     }
    3272         113 :     return false;
    3273             : }
    3274             : 
    3275          32 : void StylesBuffer::writeCellXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const
    3276             : {
    3277          32 :     if( Xf* pXf = maCellXfs.get( nXfId ).get() )
    3278          29 :         pXf->writeToPropertySet( rPropSet );
    3279          32 : }
    3280             : 
    3281          11 : bool StylesBuffer::hasBorder( sal_Int32 nBorderId ) const
    3282             : {
    3283          11 :     Border* pBorder = maBorders.get( nBorderId ).get();
    3284          11 :     return pBorder && pBorder->hasBorder();
    3285             : }
    3286             : 
    3287          11 : void StylesBuffer::writeStyleXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const
    3288             : {
    3289          11 :     if( Xf* pXf = maStyleXfs.get( nXfId ).get() )
    3290          11 :         pXf->writeToPropertySet( rPropSet );
    3291          11 : }
    3292             : 
    3293             : // ============================================================================
    3294             : 
    3295             : } // namespace xls
    3296           9 : } // namespace oox
    3297             : 
    3298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10