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