Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / filter / qpro / qprostyle.cxx
blob9b88d71b00bcc809990ca8a167f08dbc3ff1997c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sfx2/docfile.hxx>
23 #include "qproform.hxx"
24 #include "qpro.hxx"
25 #include "qprostyle.hxx"
27 #include <scitems.hxx>
28 #include <svx/algitem.hxx>
29 #include <editeng/udlnitem.hxx>
30 #include <editeng/wghtitem.hxx>
31 #include <editeng/postitem.hxx>
32 #include <editeng/crossedoutitem.hxx>
33 #include <editeng/fhgtitem.hxx>
34 #include <editeng/fontitem.hxx>
35 #include <editeng/justifyitem.hxx>
36 #include <map>
38 #include "global.hxx"
39 #include "scerrors.hxx"
40 #include "docpool.hxx"
41 #include "patattr.hxx"
42 #include "filter.hxx"
43 #include "document.hxx"
44 #include "formulacell.hxx"
46 ScQProStyle::ScQProStyle()
48 memset (maAlign, 0, sizeof (maAlign));
49 memset (maFont, 0, sizeof (maFont));
50 memset (maFontRecord, 0, sizeof (maFontRecord));
51 memset (maFontHeight, 0, sizeof (maFontHeight));
54 void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, SCTAB nTab, sal_uInt16 nStyle )
56 if (nStyle >= maxsize)
57 return;
59 ScPatternAttr aPattern(pDoc->GetPool());
60 SfxItemSet& rItemSet = aPattern.GetItemSet();
62 sal_uInt8 nTmp = maAlign[ nStyle ];
63 sal_uInt8 nHor = ( nTmp & 0x07 );
64 sal_uInt8 nVer = ( nTmp & 0x18 );
65 sal_uInt8 nOrient = ( nTmp & 0x60 );
67 // Horizontal Alignment
68 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_STANDARD;
69 switch( nHor )
71 case 0x00:
72 eJustify = SVX_HOR_JUSTIFY_STANDARD;
73 break;
75 case 0x01:
76 eJustify = SVX_HOR_JUSTIFY_LEFT;
77 break;
79 case 0x02:
80 eJustify = SVX_HOR_JUSTIFY_CENTER;
81 break;
83 case 0x03:
84 eJustify = SVX_HOR_JUSTIFY_RIGHT;
85 break;
87 case 0x04:
88 eJustify = SVX_HOR_JUSTIFY_BLOCK;
89 break;
91 rItemSet.Put( SvxHorJustifyItem( eJustify, ATTR_HOR_JUSTIFY ) );
93 // Vertical Alignment
94 SvxCellVerJustify eVerJustify = SVX_VER_JUSTIFY_STANDARD;
95 switch( nVer )
97 case 0x00:
98 eVerJustify = SVX_VER_JUSTIFY_BOTTOM;
99 break;
101 case 0x08:
102 eVerJustify = SVX_VER_JUSTIFY_CENTER;
103 break;
105 case 0x10:
106 eVerJustify = SVX_VER_JUSTIFY_TOP;
107 break;
110 rItemSet.Put(SvxVerJustifyItem( eVerJustify, ATTR_VER_JUSTIFY ) );
112 // Orientation
113 SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD;
114 switch( nOrient )
116 case 0x20:
117 eOrient = SVX_ORIENTATION_TOPBOTTOM;
118 break;
121 rItemSet.Put( SvxOrientationItem( eOrient, 0) );
123 // Wrap cell contents
124 if( nTmp & 0x80 )
126 SfxBoolItem aWrapItem( ATTR_LINEBREAK );
127 aWrapItem.SetValue( true );
128 rItemSet.Put( aWrapItem );
131 // Font Attributes
132 sal_uInt16 nTmpFnt = maFontRecord[ maFont[ nStyle ] ];
133 bool bIsBold, bIsItalic, bIsUnderLine;
135 bIsBold = ( nTmpFnt & 0x0001 ) != 0;
136 bIsItalic = ( nTmpFnt & 0x0002 ) != 0;
137 bIsUnderLine = ( nTmpFnt & 0x0004 ) != 0;
138 //(nTmpFnt & 0x0020 ) for StrikeThrough
140 if( bIsBold )
141 rItemSet.Put( SvxWeightItem( WEIGHT_BOLD,ATTR_FONT_WEIGHT) );
142 if( bIsItalic )
143 rItemSet.Put( SvxPostureItem( ITALIC_NORMAL, ATTR_FONT_POSTURE ) );
144 if( bIsUnderLine )
145 rItemSet.Put( SvxUnderlineItem( LINESTYLE_SINGLE, ATTR_FONT_UNDERLINE ) );
147 if (maFontHeight[ maFont [ nStyle ] ])
148 rItemSet.Put( SvxFontHeightItem( (sal_uLong) (20 * maFontHeight[ maFont[ nStyle ] ] ), 100, ATTR_FONT_HEIGHT ) );
150 OUString fntName = maFontType[ maFont[ nStyle ] ];
151 rItemSet.Put( SvxFontItem( FAMILY_SYSTEM, fntName, EMPTY_OUSTRING, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, ATTR_FONT ) );
153 pDoc->ApplyPattern( nCol, nRow, nTab, aPattern );
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */