xref: /aoo4110/main/sc/source/filter/qpro/qprostyle.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include <sal/config.h>
29 #include <stdio.h>
30 #include <sfx2/docfile.hxx>
31 
32 #include "qproform.hxx"
33 #include "qpro.hxx"
34 #include "qprostyle.hxx"
35 
36 #include <tools/color.hxx>
37 #include <scitems.hxx>
38 #include <svx/algitem.hxx>
39 #include <editeng/udlnitem.hxx>
40 #include <editeng/wghtitem.hxx>
41 #include <editeng/postitem.hxx>
42 #include <editeng/crsditem.hxx>
43 #include <editeng/fhgtitem.hxx>
44 #include <editeng/fontitem.hxx>
45 #include <map>
46 
47 #include "global.hxx"
48 #include "scerrors.hxx"
49 #include "docpool.hxx"
50 #include "patattr.hxx"
51 #include "filter.hxx"
52 #include "document.hxx"
53 #include "cell.hxx"
54 
ScQProStyle()55 ScQProStyle::ScQProStyle()
56 {
57 	rtl_fillMemory (maAlign, sizeof (maAlign), 0);
58 	rtl_fillMemory (maFont, sizeof (maFont), 0);
59 	rtl_fillMemory (maFontRecord, sizeof (maFontRecord), 0);
60 	rtl_fillMemory (maFontHeight, sizeof (maFontHeight), 0);
61 }
62 
SetFormat(ScDocument * pDoc,sal_uInt8 nCol,sal_uInt16 nRow,SCTAB nTab,sal_uInt16 nStyle)63 void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, SCTAB nTab, sal_uInt16 nStyle )
64 {
65     if (nStyle >= maxsize)
66         return;
67 
68     ScPatternAttr aPattern(pDoc->GetPool());
69     SfxItemSet& rItemSet = aPattern.GetItemSet();
70 
71     sal_uInt8 nTmp = maAlign[ nStyle ];
72     sal_uInt8 nHor = ( nTmp & 0x07 );
73     sal_uInt8 nVer = ( nTmp & 0x18 );
74     sal_uInt8 nOrient = ( nTmp & 0x60 );
75 
76     // Horizontal Alignment
77     SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_STANDARD;
78     switch( nHor )
79     {
80         case 0x00:
81             eJustify = SVX_HOR_JUSTIFY_STANDARD;
82             break;
83 
84         case 0x01:
85             eJustify = SVX_HOR_JUSTIFY_LEFT;
86             break;
87 
88         case 0x02:
89             eJustify = SVX_HOR_JUSTIFY_CENTER;
90             break;
91 
92         case 0x03:
93             eJustify = SVX_HOR_JUSTIFY_RIGHT;
94             break;
95 
96         case 0x04:
97             eJustify = SVX_HOR_JUSTIFY_BLOCK;
98             break;
99     }
100     rItemSet.Put( SvxHorJustifyItem( eJustify, ATTR_HOR_JUSTIFY ) );
101 
102     // Vertical Alignment
103     SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
104     switch( nVer )
105     {
106         case 0x00:
107             eVerJustify = SVX_VER_JUSTIFY_BOTTOM;
108             break;
109 
110         case 0x08:
111             eVerJustify = SVX_VER_JUSTIFY_CENTER;
112             break;
113 
114         case 0x10:
115             eVerJustify = SVX_VER_JUSTIFY_TOP;
116             break;
117     }
118 
119     rItemSet.Put(SvxVerJustifyItem( eVerJustify, ATTR_VER_JUSTIFY ) );
120 
121     // Orientation
122     SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
123     switch( nOrient )
124     {
125         case 0x20:
126             eOrient = SVX_ORIENTATION_TOPBOTTOM;
127             break;
128 
129     }
130     rItemSet.Put( SvxOrientationItem( eOrient, 0) );
131 
132     // Wrap cell contents
133     if( nTmp & 0x80 )
134     {
135         SfxBoolItem aWrapItem( ATTR_LINEBREAK );
136         aWrapItem.SetValue( sal_True );
137         rItemSet.Put( aWrapItem );
138     }
139 
140     // Font Attributes
141     sal_uInt16 nTmpFnt = maFontRecord[ maFont[ nStyle ] ];
142     sal_Bool bIsBold, bIsItalic, bIsUnderLine, bIsStrikeThrough;
143 
144     bIsBold = ( nTmpFnt & 0x0001 ) != 0;
145     bIsItalic = ( nTmpFnt & 0x0002 ) != 0;
146     bIsUnderLine = ( nTmpFnt & 0x0004 ) != 0;
147     bIsStrikeThrough = (nTmpFnt & 0x0020 ) != 0;
148 
149     if( bIsBold )
150         rItemSet.Put( SvxWeightItem( WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
151     if( bIsItalic )
152         rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
153     if( bIsUnderLine )
154         rItemSet.Put( SvxUnderlineItem( UNDERLINE_SINGLE, ATTR_FONT_UNDERLINE ) );
155 
156 	if (maFontHeight[ maFont [ nStyle ] ])
157         rItemSet.Put( SvxFontHeightItem( (sal_uLong) (20 * maFontHeight[ maFont[ nStyle ] ] ), 100, ATTR_FONT_HEIGHT ) );
158 
159     String fntName = maFontType[ maFont[ nStyle ] ];
160     rItemSet.Put( SvxFontItem( FAMILY_SYSTEM, fntName, EMPTY_STRING, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
161 
162     pDoc->ApplyPattern( nCol, nRow, nTab, aPattern );
163 }
164