1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <oox/ole/axfontdata.hxx>
21 #include <oox/ole/olehelper.hxx>
22 #include <oox/ole/axbinaryreader.hxx>
23 #include <oox/ole/axbinarywriter.hxx>
28 AxFontData::AxFontData() :
29 mnFontEffects( AxFontFlags::NONE
),
31 mnFontCharSet( WINDOWS_CHARSET_DEFAULT
),
32 mnHorAlign( AxHorizontalAlign::Left
),
33 mbDblUnderline( false )
37 sal_Int16
AxFontData::getHeightPoints() const
39 /* MSO uses weird font sizes:
40 1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135,
41 8pt->165, 9pt->180, 10pt->195, 11pt->225, ... */
42 return getLimitedValue
< sal_Int16
, sal_Int32
>( (mnFontHeight
+ 10) / 20, 1, SAL_MAX_INT16
);
45 void AxFontData::setHeightPoints( sal_Int16 nPoints
)
47 mnFontHeight
= getLimitedValue
< sal_Int32
, sal_Int32
>( ((nPoints
* 4 + 1) / 3) * 15, 30, 4294967 );
50 bool AxFontData::importBinaryModel( BinaryInputStream
& rInStrm
)
52 AxBinaryPropertyReader
aReader( rInStrm
);
53 aReader
.readStringProperty( maFontName
);
54 sal_uInt32 nTmp32
= 0;
55 aReader
.readIntProperty
< sal_uInt32
>( nTmp32
);
56 mnFontEffects
= static_cast<AxFontFlags
>(nTmp32
);
57 aReader
.readIntProperty
< sal_Int32
>( mnFontHeight
);
58 aReader
.skipIntProperty
< sal_Int32
>(); // font offset
59 aReader
.readIntProperty
< sal_uInt8
>( mnFontCharSet
);
60 aReader
.skipIntProperty
< sal_uInt8
>(); // font pitch/family
61 sal_uInt8 nTmp
= static_cast<sal_uInt8
>(AxHorizontalAlign::Left
);
62 aReader
.readIntProperty
< sal_uInt8
>( nTmp
);
63 mnHorAlign
= static_cast<AxHorizontalAlign
>(nTmp
);
64 aReader
.skipIntProperty
< sal_uInt16
>(); // font weight
65 mbDblUnderline
= false;
66 return aReader
.finalizeImport();
69 void AxFontData::exportBinaryModel( BinaryOutputStream
& rOutStrm
)
71 AxBinaryPropertyWriter
aWriter( rOutStrm
);
72 aWriter
.writeStringProperty( maFontName
);
73 aWriter
.writeIntProperty
< sal_uInt32
>( static_cast<sal_uInt32
>(mnFontEffects
) );
74 aWriter
.writeIntProperty
< sal_Int32
>( mnFontHeight
);
75 aWriter
.skipProperty(); // font offset
76 // TODO make AxFontDataModel::convertFromProperties convert the textencoding
77 aWriter
.writeIntProperty
< sal_uInt8
>( mnFontCharSet
);
78 aWriter
.skipProperty(); // font pitch/family
80 aWriter
.writeIntProperty
< sal_uInt8
>( static_cast<sal_uInt8
>(mnHorAlign
) );
81 aWriter
.skipProperty(); // font weight
82 aWriter
.finalizeExport();
85 bool AxFontData::importStdFont( BinaryInputStream
& rInStrm
)
87 StdFontInfo aFontInfo
;
88 if( OleHelper::importStdFont( aFontInfo
, rInStrm
, false ) )
90 maFontName
= aFontInfo
.maName
;
91 mnFontEffects
= AxFontFlags::NONE
;
92 setFlag( mnFontEffects
, AxFontFlags::Bold
, aFontInfo
.mnWeight
>= OLE_STDFONT_BOLD
);
93 setFlag( mnFontEffects
, AxFontFlags::Italic
, getFlag( aFontInfo
.mnFlags
, OLE_STDFONT_ITALIC
) );
94 setFlag( mnFontEffects
, AxFontFlags::Underline
, getFlag( aFontInfo
.mnFlags
, OLE_STDFONT_UNDERLINE
) );
95 setFlag( mnFontEffects
, AxFontFlags::Strikeout
, getFlag( aFontInfo
.mnFlags
,OLE_STDFONT_STRIKE
) );
96 mbDblUnderline
= false;
97 // StdFont stores font height in 1/10,000 of points
98 setHeightPoints( getLimitedValue
< sal_Int16
, sal_Int32
>( aFontInfo
.mnHeight
/ 10000, 0, SAL_MAX_INT16
) );
99 mnFontCharSet
= aFontInfo
.mnCharSet
;
100 mnHorAlign
= AxHorizontalAlign::Left
;
106 bool AxFontData::importGuidAndFont( BinaryInputStream
& rInStrm
)
108 OUString aGuid
= OleHelper::importGuid( rInStrm
);
109 if( aGuid
== "{AFC20920-DA4E-11CE-B943-00AA006887B4}" )
110 return importBinaryModel( rInStrm
);
111 if ( aGuid
== OLE_GUID_STDFONT
)
112 return importStdFont( rInStrm
);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */