1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <qprostyle.hxx>
23 
24 #include <scitems.hxx>
25 #include <svx/algitem.hxx>
26 #include <editeng/udlnitem.hxx>
27 #include <editeng/wghtitem.hxx>
28 #include <editeng/postitem.hxx>
29 #include <editeng/fhgtitem.hxx>
30 #include <editeng/fontitem.hxx>
31 #include <editeng/justifyitem.hxx>
32 
33 #include <attrib.hxx>
34 #include <global.hxx>
35 #include <docpool.hxx>
36 #include <patattr.hxx>
37 #include <document.hxx>
38 
SetFormat(ScDocument * pDoc,sal_uInt8 nCol,sal_uInt16 nRow,SCTAB nTab,sal_uInt16 nStyle)39 void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, SCTAB nTab, sal_uInt16 nStyle )
40 {
41     if (nStyle >= maxsize)
42         return;
43 
44     ScPatternAttr aPattern(pDoc->GetPool());
45     SfxItemSet& rItemSet = aPattern.GetItemSet();
46 
47     sal_uInt8 nTmp = maAlign[ nStyle ];
48     sal_uInt8 nHor = ( nTmp & 0x07 );
49     sal_uInt8 nVer = ( nTmp & 0x18 );
50     sal_uInt8 nOrient = ( nTmp & 0x60 );
51 
52     // Horizontal Alignment
53     SvxCellHorJustify eJustify = SvxCellHorJustify::Standard;
54     switch( nHor )
55     {
56         case 0x00:
57             eJustify = SvxCellHorJustify::Standard;
58             break;
59 
60         case 0x01:
61             eJustify = SvxCellHorJustify::Left;
62             break;
63 
64         case 0x02:
65             eJustify = SvxCellHorJustify::Center;
66             break;
67 
68         case 0x03:
69             eJustify = SvxCellHorJustify::Right;
70             break;
71 
72         case 0x04:
73             eJustify = SvxCellHorJustify::Block;
74             break;
75     }
76     rItemSet.Put( SvxHorJustifyItem( eJustify, ATTR_HOR_JUSTIFY ) );
77 
78     // Vertical Alignment
79     SvxCellVerJustify eVerJustify = SvxCellVerJustify::Standard;
80     switch( nVer )
81     {
82         case 0x00:
83             eVerJustify = SvxCellVerJustify::Bottom;
84             break;
85 
86         case 0x08:
87             eVerJustify = SvxCellVerJustify::Center;
88             break;
89 
90         case 0x10:
91             eVerJustify = SvxCellVerJustify::Top;
92             break;
93     }
94 
95     rItemSet.Put(SvxVerJustifyItem( eVerJustify, ATTR_VER_JUSTIFY ) );
96 
97     // Orientation
98     SvxCellOrientation eOrient = SvxCellOrientation::Standard;
99     switch( nOrient )
100     {
101         case 0x20:
102             eOrient = SvxCellOrientation::TopBottom;
103             break;
104 
105     }
106     rItemSet.Put( SvxOrientationItem( eOrient, 0) );
107 
108     // Wrap cell contents
109     if( nTmp & 0x80 )
110     {
111         ScLineBreakCell aWrapItem(true);
112         rItemSet.Put( aWrapItem );
113     }
114 
115     // Font Attributes
116     sal_uInt16 nTmpFnt = maFontRecord[ maFont[ nStyle ] ];
117     bool bIsBold, bIsItalic, bIsUnderLine;
118 
119     bIsBold = ( nTmpFnt & 0x0001 ) != 0;
120     bIsItalic = ( nTmpFnt & 0x0002 ) != 0;
121     bIsUnderLine = ( nTmpFnt & 0x0004 ) != 0;
122     //(nTmpFnt & 0x0020 ) for StrikeThrough
123 
124     if( bIsBold )
125         rItemSet.Put( SvxWeightItem( WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
126     if( bIsItalic )
127         rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
128     if( bIsUnderLine )
129         rItemSet.Put( SvxUnderlineItem( LINESTYLE_SINGLE, ATTR_FONT_UNDERLINE ) );
130 
131     if (maFontHeight[ maFont [ nStyle ] ])
132         rItemSet.Put( SvxFontHeightItem( static_cast<sal_uLong>(20 * maFontHeight[ maFont[ nStyle ] ] ), 100, ATTR_FONT_HEIGHT ) );
133 
134     OUString fntName = maFontType[ maFont[ nStyle ] ];
135     rItemSet.Put( SvxFontItem( FAMILY_SYSTEM, fntName, EMPTY_OUSTRING, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
136 
137     pDoc->ApplyPattern( nCol, nRow, nTab, aPattern );
138 }
139 
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
141