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 #include <global.hxx>
30 
31 void LotusFontBuffer::Fill( const sal_uInt8 nIndex, SfxItemSet& rItemSet )
32 {
33  sal_uInt8 nIntIndex = nIndex & 0x07;
34 
35  ENTRY* pCurrent = pData + nIntIndex;
36 
37  if( pCurrent->pFont )
38  rItemSet.Put( *pCurrent->pFont );
39 
40  if( pCurrent->pHeight )
41  rItemSet.Put( *pCurrent->pHeight );
42 
43  if( nIndex & 0x08 )
44  {
46  rItemSet.Put( aWeightItem );
47  }
48 
49  if( nIndex & 0x10 )
50  {
52  rItemSet.Put( aAttr );
53  }
54 
55  FontLineStyle eUnderline;
56  switch( nIndex & 0x60 ) // Bit 5+6
57  {
58  case 0x60:
59  case 0x20: eUnderline = LINESTYLE_SINGLE; break;
60  case 0x40: eUnderline = LINESTYLE_DOUBLE; break;
61  default: eUnderline = LINESTYLE_NONE;
62  }
63  if( eUnderline != LINESTYLE_NONE )
64  {
65  SvxUnderlineItem aUndItem( eUnderline, ATTR_FONT_UNDERLINE );
66  rItemSet.Put( aUndItem );
67  }
68 }
69 
70 void LotusFontBuffer::SetName( const sal_uInt16 nIndex, const OUString& rName )
71 {
72  OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetName(): Array too small!" );
73  if( nIndex < nSize )
74  {
75  ENTRY* pEntry = pData + nIndex;
76  pEntry->TmpName( rName );
77 
78  if( pEntry->nType >= 0 )
79  MakeFont( pEntry );
80  }
81 }
82 
83 void LotusFontBuffer::SetHeight( const sal_uInt16 nIndex, const sal_uInt16 nHeight )
84 {
85  OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetHeight(): Array too small!" );
86  if( nIndex < nSize )
87  pData[ nIndex ].Height( std::make_unique<SvxFontHeightItem>( static_cast<sal_uLong>(nHeight) * 20, 100, ATTR_FONT_HEIGHT ) );
88 }
89 
90 void LotusFontBuffer::SetType( const sal_uInt16 nIndex, const sal_uInt16 nType )
91 {
92  OSL_ENSURE( nIndex < nSize, "*LotusFontBuffer::SetType(): Array too small!" );
93  if( nIndex < nSize )
94  {
95  ENTRY* pEntry = pData + nIndex;
96  pEntry->Type( nType );
97 
98  if( pEntry->xTmpName )
99  MakeFont( pEntry );
100  }
101 }
102 
104 {
105  FontFamily eFamily = FAMILY_DONTKNOW;
106  FontPitch ePitch = PITCH_DONTKNOW;
107  rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW;
108 
109  switch( pEntry->nType )
110  {
111  case 0x00: // Helvetica
112  eFamily = FAMILY_SWISS;
113  ePitch = PITCH_VARIABLE;
114  break;
115  case 0x01: // Times Roman
116  eFamily = FAMILY_ROMAN;
117  ePitch = PITCH_VARIABLE;
118  break;
119  case 0x02: // Courier
120  ePitch = PITCH_FIXED;
121  break;
122  case 0x03: // Symbol
123  eCharSet = RTL_TEXTENCODING_SYMBOL;
124  break;
125  }
126 
127  pEntry->pFont.reset( new SvxFontItem( eFamily, *pEntry->xTmpName, EMPTY_OUSTRING, ePitch, eCharSet, ATTR_FONT ) );
128 
129  pEntry->xTmpName.reset();
130 }
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define EMPTY_OUSTRING
Definition: global.hxx:215
FAMILY_DONTKNOW
std::optional< OUString > xTmpName
Definition: lotfntbf.hxx:34
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
FAMILY_ROMAN
void Height(std::unique_ptr< SvxFontHeightItem > pNew)
Definition: lotfntbf.hxx:42
WEIGHT_BOLD
LINESTYLE_NONE
void SetName(const sal_uInt16 nIndex, const OUString &rName)
Definition: fontbuff.cxx:70
PITCH_VARIABLE
void TmpName(const OUString &rNew)
Definition: lotfntbf.hxx:38
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
static const sal_uInt16 nSize
Definition: lotfntbf.hxx:51
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
ENTRY pData[nSize]
Definition: lotfntbf.hxx:57
PITCH_FIXED
LINESTYLE_SINGLE
PITCH_DONTKNOW
static void MakeFont(ENTRY *pEntry)
Definition: fontbuff.cxx:103
FontPitch
FontFamily
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void SetType(const sal_uInt16 nIndex, const sal_uInt16 nType)
Definition: fontbuff.cxx:90
std::unique_ptr< SvxFontHeightItem > pHeight
Definition: lotfntbf.hxx:36
ITALIC_NORMAL
unsigned char sal_uInt8
std::unique_ptr< SvxFontItem > pFont
Definition: lotfntbf.hxx:35
FAMILY_SWISS
void Type(const sal_uInt16 nNew)
Definition: lotfntbf.hxx:46
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
LINESTYLE_DOUBLE
FontLineStyle
void SetHeight(const sal_uInt16 nIndex, const sal_uInt16 nHeight)
Definition: fontbuff.cxx:83
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
void Fill(const sal_uInt8 nIndex, SfxItemSet &rItemSet)
Definition: fontbuff.cxx:31