xref: /AOO41X/main/sc/source/filter/excel/fontbuff.cxx (revision 3ee7c2db59af3948da1f0fe563f557d5b49b2c39)
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 #include "lotfntbf.hxx"
28 
29 #include "scitems.hxx"
30 #include <editeng/cntritem.hxx>
31 #include <editeng/crsditem.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/postitem.hxx>
34 #include <editeng/shdditem.hxx>
35 #include <editeng/escpitem.hxx>
36 #include <editeng/udlnitem.hxx>
37 #include <editeng/wghtitem.hxx>
38 #include <sfx2/printer.hxx>
39 
40 #include "attrib.hxx"
41 #include "document.hxx"
42 #include "global.hxx"
43 #include "docpool.hxx"
44 #include "patattr.hxx"
45 #include "ftools.hxx"
46 
Fill(const sal_uInt8 nIndex,SfxItemSet & rItemSet)47 void LotusFontBuffer::Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet )
48 {
49     sal_uInt8   nIntIndex = nIndex & 0x07;
50 
51     ENTRY*  pAkt = pData + nIntIndex;
52 
53     if( pAkt->pFont )
54         rItemSet.Put( *pAkt->pFont );
55 
56     if( pAkt->pHeight )
57         rItemSet.Put( *pAkt->pHeight );
58 
59     if( pAkt->pColor )
60         rItemSet.Put( *pAkt->pColor );
61 
62     if( nIndex & 0x08 )
63     {
64         SvxWeightItem aWeightItem( WEIGHT_BOLD, ATTR_FONT_WEIGHT );
65         rItemSet.Put( aWeightItem );
66     }
67 
68     if( nIndex & 0x10 )
69     {
70         SvxPostureItem aAttr( ITALIC_NORMAL, ATTR_FONT_POSTURE );
71         rItemSet.Put( aAttr );
72     }
73 
74     FontUnderline eUnderline;
75     switch( nIndex & 0x60 ) // Bit 5+6
76     {
77         case 0x60:
78         case 0x20:  eUnderline = UNDERLINE_SINGLE;      break;
79         case 0x40:  eUnderline = UNDERLINE_DOUBLE;      break;
80         default:    eUnderline = UNDERLINE_NONE;
81     }
82     if( eUnderline != UNDERLINE_NONE )
83     {
84         SvxUnderlineItem aUndItem( eUnderline, ATTR_FONT_UNDERLINE );
85         rItemSet.Put( aUndItem );
86     }
87 }
88 
89 
SetName(const sal_uInt16 nIndex,const String & rName)90 void LotusFontBuffer::SetName( const sal_uInt16 nIndex, const String& rName )
91 {
92     DBG_ASSERT( nIndex < nSize, "*LotusFontBuffer::SetName(): Array zu klein!" );
93     if( nIndex < nSize )
94     {
95         register ENTRY* pEntry = pData + nIndex;
96         pEntry->TmpName( rName );
97 
98         if( pEntry->nType >= 0 )
99             MakeFont( pEntry );
100     }
101 }
102 
103 
SetHeight(const sal_uInt16 nIndex,const sal_uInt16 nHeight)104 void LotusFontBuffer::SetHeight( const sal_uInt16 nIndex, const sal_uInt16 nHeight )
105 {
106     DBG_ASSERT( nIndex < nSize, "*LotusFontBuffer::SetHeight(): Array zu klein!" );
107     if( nIndex < nSize )
108         pData[ nIndex ].Height( *( new SvxFontHeightItem( ( sal_uLong ) nHeight * 20, 100, ATTR_FONT_HEIGHT ) ) );
109 }
110 
111 
SetType(const sal_uInt16 nIndex,const sal_uInt16 nType)112 void LotusFontBuffer::SetType( const sal_uInt16 nIndex, const sal_uInt16 nType )
113 {
114     DBG_ASSERT( nIndex < nSize, "*LotusFontBuffer::SetType(): Array zu klein!" );
115     if( nIndex < nSize )
116     {
117         register ENTRY* pEntry = pData + nIndex;
118         pEntry->Type( nType );
119 
120         if( pEntry->pTmpName )
121             MakeFont( pEntry );
122     }
123 }
124 
125 
MakeFont(ENTRY * pEntry)126 void LotusFontBuffer::MakeFont( ENTRY* pEntry )
127 {
128     FontFamily      eFamily = FAMILY_DONTKNOW;
129     FontPitch       ePitch = PITCH_DONTKNOW;
130     CharSet         eCharSet = RTL_TEXTENCODING_DONTKNOW;
131 
132     switch( pEntry->nType )
133     {
134         case 0x00:                      // Helvetica
135             eFamily = FAMILY_SWISS;
136             ePitch  = PITCH_VARIABLE;
137             break;
138         case 0x01:                      // Times Roman
139             eFamily = FAMILY_ROMAN;
140             ePitch  = PITCH_VARIABLE;
141             break;
142         case 0x02:                      // Courier
143             ePitch  = PITCH_FIXED;
144             break;
145         case 0x03:                      // Symbol
146             eCharSet = RTL_TEXTENCODING_SYMBOL;
147             break;
148     }
149 
150     pEntry->pFont = new SvxFontItem( eFamily, *pEntry->pTmpName, EMPTY_STRING, ePitch, eCharSet, ATTR_FONT );
151 
152     delete pEntry->pTmpName;
153     pEntry->pTmpName = NULL;
154 }
155 
156 
157 
158