LibreOffice Module oox (master)  1
axfontdata.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 <oox/ole/axfontdata.hxx>
21 #include <oox/ole/olehelper.hxx>
24 
25 namespace oox::ole {
26 
28  mnFontEffects( AxFontFlags::NONE ),
29  mnFontHeight( 160 ),
30  mnFontCharSet( WINDOWS_CHARSET_DEFAULT ),
31  mnHorAlign( AxHorizontalAlign::Left ),
32  mbDblUnderline( false )
33 {
34 }
35 
36 sal_Int16 AxFontData::getHeightPoints() const
37 {
38  /* MSO uses weird font sizes:
39  1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135,
40  8pt->165, 9pt->180, 10pt->195, 11pt->225, ... */
41  return getLimitedValue< sal_Int16, sal_Int32 >( (mnFontHeight + 10) / 20, 1, SAL_MAX_INT16 );
42 }
43 
44 void AxFontData::setHeightPoints( sal_Int16 nPoints )
45 {
46  mnFontHeight = getLimitedValue< sal_Int32, sal_Int32 >( ((nPoints * 4 + 1) / 3) * 15, 30, 4294967 );
47 }
48 
50 {
51  AxBinaryPropertyReader aReader( rInStrm );
52  aReader.readStringProperty( maFontName );
53  sal_uInt32 nTmp32 = 0;
54  aReader.readIntProperty< sal_uInt32 >( nTmp32 );
55  mnFontEffects = static_cast<AxFontFlags>(nTmp32);
56  aReader.readIntProperty< sal_Int32 >( mnFontHeight );
57  aReader.skipIntProperty< sal_Int32 >(); // font offset
59  aReader.skipIntProperty< sal_uInt8 >(); // font pitch/family
60  sal_uInt8 nTmp = static_cast<sal_uInt8>(AxHorizontalAlign::Left);
61  aReader.readIntProperty< sal_uInt8 >( nTmp );
62  mnHorAlign = static_cast<AxHorizontalAlign>(nTmp);
63  aReader.skipIntProperty< sal_uInt16 >(); // font weight
64  mbDblUnderline = false;
65  return aReader.finalizeImport();
66 }
67 
69 {
70  AxBinaryPropertyWriter aWriter( rOutStrm );
72  aWriter.writeIntProperty< sal_uInt32 >( static_cast<sal_uInt32>(mnFontEffects) );
73  aWriter.writeIntProperty< sal_Int32 >( mnFontHeight );
74  aWriter.skipProperty(); // font offset
75  // TODO make AxFontDataModel::convertFromProperties convert the textencoding
77  aWriter.skipProperty(); // font pitch/family
78 
79  aWriter.writeIntProperty< sal_uInt8 >( static_cast<sal_uInt8>(mnHorAlign) );
80  aWriter.skipProperty(); // font weight
81  aWriter.finalizeExport();
82 }
83 
85 {
86  StdFontInfo aFontInfo;
87  if( OleHelper::importStdFont( aFontInfo, rInStrm, false ) )
88  {
89  maFontName = aFontInfo.maName;
95  mbDblUnderline = false;
96  // StdFont stores font height in 1/10,000 of points
97  setHeightPoints( getLimitedValue< sal_Int16, sal_Int32 >( aFontInfo.mnHeight / 10000, 0, SAL_MAX_INT16 ) );
98  mnFontCharSet = aFontInfo.mnCharSet;
100  return true;
101  }
102  return false;
103 }
104 
106 {
107  OUString aGuid = OleHelper::importGuid( rInStrm );
108  if( aGuid == "{AFC20920-DA4E-11CE-B943-00AA006887B4}" )
109  return importBinaryModel( rInStrm );
110  if ( aGuid == OLE_GUID_STDFONT )
111  return importStdFont( rInStrm );
112  return false;
113 }
114 
115 } // namespace oox::ole
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 mnCharSet
Font charset.
Definition: olehelper.hxx:73
Export helper to write simple and complex ActiveX form control properties to a binary input stream...
sal_Int32 mnFontHeight
Height of the font (not really twips, see code).
Definition: axfontdata.hxx:57
void writeIntProperty(DataType ornValue)
Write an integer property value to the stream, the respective flag in the property mask is set...
bool importGuidAndFont(BinaryInputStream &rInStrm)
Reads the font data settings from the passed input stream depending on the GUID preceding the actual ...
Definition: axfontdata.cxx:105
sal_uInt16 mnWeight
Font weight (normal/bold).
Definition: olehelper.hxx:72
OOX_DLLPUBLIC bool importStdFont(StdFontInfo &orFontInfo, BinaryInputStream &rInStrm, bool bWithGuid)
Imports an OLE StdFont font structure from the current position of the passed binary stream...
Definition: olehelper.cxx:279
const sal_uInt16 OLE_STDFONT_BOLD
Definition: olehelper.hxx:61
void setHeightPoints(sal_Int16 nPoints)
Converts the passed font height from points to the internal representation.
Definition: axfontdata.cxx:44
OOX_DLLPUBLIC OUString importGuid(BinaryInputStream &rInStrm)
Imports a GUID from the passed binary stream and returns its string representation (in uppercase char...
Definition: olehelper.cxx:260
Interface for binary output stream classes.
bool mbDblUnderline
True = double underline style (legacy VML drawing controls only).
Definition: axfontdata.hxx:60
NONE
void finalizeExport()
Final processing, write contents of all complex properties, writes record size.
AxHorizontalAlign mnHorAlign
Horizontal text alignment.
Definition: axfontdata.hxx:59
const sal_uInt8 OLE_STDFONT_UNDERLINE
Definition: olehelper.hxx:64
OUString maFontName
Name of the used font.
Definition: axfontdata.hxx:55
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
Definition: helper.hxx:61
void skipIntProperty()
Skips the next integer property value in the stream, if the respective flag in the property mask is s...
bool getFlag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
Definition: helper.hxx:135
#define OLE_GUID_STDFONT
Definition: olehelper.hxx:56
void readIntProperty(DataType &ornValue)
Reads the next integer property value from the stream, if the respective flag in the property mask is...
bool importStdFont(BinaryInputStream &rInStrm)
Reads the font data settings from the passed input stream that contains an OLE StdFont structure...
Definition: axfontdata.cxx:84
Interface for binary input stream classes.
void setFlag(Type &ornBitField, Type nMask, bool bSet=true)
Sets or clears (according to bSet) all set bits of nMask in ornBitField.
Definition: helper.hxx:165
Import helper to read simple and complex ActiveX form control properties from a binary input stream...
AxFontFlags mnFontEffects
Font effect flags.
Definition: axfontdata.hxx:56
sal_Int16 getHeightPoints() const
Converts the internal representation of the font height to points.
Definition: axfontdata.cxx:36
void skipProperty()
Skips the next property clears the respective flag in the property mask.
sal_Int32 mnFontCharSet
Windows character set of the font.
Definition: axfontdata.hxx:58
sal_uInt32 mnHeight
Font height (1/10,000 points).
Definition: olehelper.hxx:71
void exportBinaryModel(BinaryOutputStream &rOutStrm)
Definition: axfontdata.cxx:68
void readStringProperty(OUString &orValue)
Reads the next string property from the stream, if the respective flag in the property mask is set...
bool importBinaryModel(BinaryInputStream &rInStrm)
Reads the font data settings from the passed input stream.
Definition: axfontdata.cxx:49
Stores data about a StdFont font structure.
Definition: olehelper.hxx:68
sal_uInt8 mnFlags
Font flags.
Definition: olehelper.hxx:74
OUString maName
Font name.
Definition: olehelper.hxx:70
void writeStringProperty(OUString &orValue)
Write a string property to the stream, the respective flag in the property mask is set...
unsigned char sal_uInt8
#define SAL_MAX_INT16
const sal_uInt8 OLE_STDFONT_STRIKE
Definition: olehelper.hxx:65
Left
const sal_uInt8 OLE_STDFONT_ITALIC
Definition: olehelper.hxx:63
bool finalizeImport()
Final processing, reads contents of all complex properties.
AxFontFlags
Definition: axfontdata.hxx:33