use insert function instead of for loop
[LibreOffice.git] / sc / source / filter / excel / fontbuff.cxx
blob40e04fcb06ea44fb2148ab0df30bc93f31625665
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 <lotfntbf.hxx>
22 #include <scitems.hxx>
23 #include <editeng/postitem.hxx>
24 #include <editeng/udlnitem.hxx>
25 #include <editeng/wghtitem.hxx>
26 #include <osl/diagnose.h>
27 #include <svl/itemset.hxx>
29 void LotusFontBuffer::Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet )
31 sal_uInt8 nIntIndex = nIndex & 0x07;
33 ENTRY* pCurrent = pData + nIntIndex;
35 if( pCurrent->pFont )
36 rItemSet.Put( *pCurrent->pFont );
38 if( pCurrent->pHeight )
39 rItemSet.Put( *pCurrent->pHeight );
41 if( nIndex & 0x08 )
43 SvxWeightItem aWeightItem( WEIGHT_BOLD, ATTR_FONT_WEIGHT );
44 rItemSet.Put( aWeightItem );
47 if( nIndex & 0x10 )
49 SvxPostureItem aAttr( ITALIC_NORMAL, ATTR_FONT_POSTURE );
50 rItemSet.Put( aAttr );
53 FontLineStyle eUnderline;
54 switch( nIndex & 0x60 ) // Bit 5+6
56 case 0x60:
57 case 0x20: eUnderline = LINESTYLE_SINGLE; break;
58 case 0x40: eUnderline = LINESTYLE_DOUBLE; break;
59 default: eUnderline = LINESTYLE_NONE;
61 if( eUnderline != LINESTYLE_NONE )
63 SvxUnderlineItem aUndItem( eUnderline, ATTR_FONT_UNDERLINE );
64 rItemSet.Put( aUndItem );
68 void LotusFontBuffer::SetName( const sal_uInt16 nIndex, const OUString& rName )
70 OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetName(): Array too small!" );
71 if( nIndex < nSize )
73 ENTRY* pEntry = pData + nIndex;
74 pEntry->TmpName( rName );
76 if( pEntry->nType >= 0 )
77 MakeFont( pEntry );
81 void LotusFontBuffer::SetHeight( const sal_uInt16 nIndex, const sal_uInt16 nHeight )
83 OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetHeight(): Array too small!" );
84 if( nIndex < nSize )
85 pData[ nIndex ].Height( std::make_unique<SvxFontHeightItem>( static_cast<sal_uInt32>(nHeight) * 20, 100, ATTR_FONT_HEIGHT ) );
88 void LotusFontBuffer::SetType( const sal_uInt16 nIndex, const sal_uInt16 nType )
90 OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetType(): Array too small!" );
91 if( nIndex < nSize )
93 ENTRY* pEntry = pData + nIndex;
94 pEntry->Type( nType );
96 if( pEntry->xTmpName )
97 MakeFont( pEntry );
101 void LotusFontBuffer::MakeFont( ENTRY* pEntry )
103 FontFamily eFamily = FAMILY_DONTKNOW;
104 FontPitch ePitch = PITCH_DONTKNOW;
105 rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW;
107 switch( pEntry->nType )
109 case 0x00: // Helvetica
110 eFamily = FAMILY_SWISS;
111 ePitch = PITCH_VARIABLE;
112 break;
113 case 0x01: // Times Roman
114 eFamily = FAMILY_ROMAN;
115 ePitch = PITCH_VARIABLE;
116 break;
117 case 0x02: // Courier
118 ePitch = PITCH_FIXED;
119 break;
120 case 0x03: // Symbol
121 eCharSet = RTL_TEXTENCODING_SYMBOL;
122 break;
125 pEntry->pFont.reset( new SvxFontItem( eFamily, *pEntry->xTmpName, OUString(), ePitch, eCharSet, ATTR_FONT ) );
127 pEntry->xTmpName.reset();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */