LibreOffice Module sc (master)  1
fontbuff.cxx
Go to the documentation of this file.
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 <lotfntbf.hxx>
21 
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>
28 
29 void LotusFontBuffer::Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet )
30 {
31  sal_uInt8 nIntIndex = nIndex & 0x07;
32 
33  ENTRY* pCurrent = pData + nIntIndex;
34 
35  if( pCurrent->pFont )
36  rItemSet.Put( *pCurrent->pFont );
37 
38  if( pCurrent->pHeight )
39  rItemSet.Put( *pCurrent->pHeight );
40 
41  if( nIndex & 0x08 )
42  {
44  rItemSet.Put( aWeightItem );
45  }
46 
47  if( nIndex & 0x10 )
48  {
50  rItemSet.Put( aAttr );
51  }
52 
53  FontLineStyle eUnderline;
54  switch( nIndex & 0x60 ) // Bit 5+6
55  {
56  case 0x60:
57  case 0x20: eUnderline = LINESTYLE_SINGLE; break;
58  case 0x40: eUnderline = LINESTYLE_DOUBLE; break;
59  default: eUnderline = LINESTYLE_NONE;
60  }
61  if( eUnderline != LINESTYLE_NONE )
62  {
63  SvxUnderlineItem aUndItem( eUnderline, ATTR_FONT_UNDERLINE );
64  rItemSet.Put( aUndItem );
65  }
66 }
67 
68 void LotusFontBuffer::SetName( const sal_uInt16 nIndex, const OUString& rName )
69 {
70  OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetName(): Array too small!" );
71  if( nIndex < nSize )
72  {
73  ENTRY* pEntry = pData + nIndex;
74  pEntry->TmpName( rName );
75 
76  if( pEntry->nType >= 0 )
77  MakeFont( pEntry );
78  }
79 }
80 
81 void LotusFontBuffer::SetHeight( const sal_uInt16 nIndex, const sal_uInt16 nHeight )
82 {
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 ) );
86 }
87 
88 void LotusFontBuffer::SetType( const sal_uInt16 nIndex, const sal_uInt16 nType )
89 {
90  OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetType(): Array too small!" );
91  if( nIndex < nSize )
92  {
93  ENTRY* pEntry = pData + nIndex;
94  pEntry->Type( nType );
95 
96  if( pEntry->xTmpName )
97  MakeFont( pEntry );
98  }
99 }
100 
102 {
103  FontFamily eFamily = FAMILY_DONTKNOW;
104  FontPitch ePitch = PITCH_DONTKNOW;
105  rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW;
106 
107  switch( pEntry->nType )
108  {
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;
123  }
124 
125  pEntry->pFont.reset( new SvxFontItem( eFamily, *pEntry->xTmpName, OUString(), ePitch, eCharSet, ATTR_FONT ) );
126 
127  pEntry->xTmpName.reset();
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FAMILY_DONTKNOW
std::optional< OUString > xTmpName
Definition: lotfntbf.hxx:33
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
FAMILY_ROMAN
void Height(std::unique_ptr< SvxFontHeightItem > pNew)
Definition: lotfntbf.hxx:41
WEIGHT_BOLD
LINESTYLE_NONE
void SetName(const sal_uInt16 nIndex, const OUString &rName)
Definition: fontbuff.cxx:68
PITCH_VARIABLE
void TmpName(const OUString &rNew)
Definition: lotfntbf.hxx:37
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
static const sal_uInt16 nSize
Definition: lotfntbf.hxx:50
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
ENTRY pData[nSize]
Definition: lotfntbf.hxx:56
PITCH_FIXED
LINESTYLE_SINGLE
PITCH_DONTKNOW
static void MakeFont(ENTRY *pEntry)
Definition: fontbuff.cxx:101
FontPitch
FontFamily
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetType(const sal_uInt16 nIndex, const sal_uInt16 nType)
Definition: fontbuff.cxx:88
std::unique_ptr< SvxFontHeightItem > pHeight
Definition: lotfntbf.hxx:35
ITALIC_NORMAL
unsigned char sal_uInt8
std::unique_ptr< SvxFontItem > pFont
Definition: lotfntbf.hxx:34
FAMILY_SWISS
void Type(const sal_uInt16 nNew)
Definition: lotfntbf.hxx:45
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
LINESTYLE_DOUBLE
FontLineStyle
void SetHeight(const sal_uInt16 nIndex, const sal_uInt16 nHeight)
Definition: fontbuff.cxx:81
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
void Fill(const sal_uInt8 nIndex, SfxItemSet &rItemSet)
Definition: fontbuff.cxx:29