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