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

Generated by: LCOV version 1.10