Line data Source code
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"
22 : #include "oox/ole/axbinaryreader.hxx"
23 : #include "oox/ole/axbinarywriter.hxx"
24 :
25 : namespace oox {
26 : namespace ole {
27 :
28 264 : AxFontData::AxFontData() :
29 : mnFontEffects( 0 ),
30 : mnFontHeight( 160 ),
31 : mnFontCharSet( WINDOWS_CHARSET_DEFAULT ),
32 : mnHorAlign( AX_FONTDATA_LEFT ),
33 264 : mbDblUnderline( false )
34 : {
35 264 : }
36 :
37 82 : sal_Int16 AxFontData::getHeightPoints() const
38 : {
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 82 : return getLimitedValue< sal_Int16, sal_Int32 >( (mnFontHeight + 10) / 20, 1, SAL_MAX_INT16 );
43 : }
44 :
45 4 : void AxFontData::setHeightPoints( sal_Int16 nPoints )
46 : {
47 4 : mnFontHeight = getLimitedValue< sal_Int32, sal_Int32 >( ((nPoints * 4 + 1) / 3) * 15, 30, 4294967 );
48 4 : }
49 :
50 80 : bool AxFontData::importBinaryModel( BinaryInputStream& rInStrm )
51 : {
52 80 : AxBinaryPropertyReader aReader( rInStrm );
53 80 : aReader.readStringProperty( maFontName );
54 80 : aReader.readIntProperty< sal_uInt32 >( mnFontEffects );
55 80 : aReader.readIntProperty< sal_Int32 >( mnFontHeight );
56 80 : aReader.skipIntProperty< sal_Int32 >(); // font offset
57 80 : aReader.readIntProperty< sal_uInt8 >( mnFontCharSet );
58 80 : aReader.skipIntProperty< sal_uInt8 >(); // font pitch/family
59 80 : aReader.readIntProperty< sal_uInt8 >( mnHorAlign );
60 80 : aReader.skipIntProperty< sal_uInt16 >(); // font weight
61 80 : mbDblUnderline = false;
62 80 : return aReader.finalizeImport();
63 : }
64 :
65 2 : void AxFontData::exportBinaryModel( BinaryOutputStream& rOutStrm )
66 : {
67 2 : AxBinaryPropertyWriter aWriter( rOutStrm );
68 2 : aWriter.writeStringProperty( maFontName );
69 2 : aWriter.writeIntProperty< sal_uInt32 >( mnFontEffects );
70 2 : aWriter.writeIntProperty< sal_Int32 >( mnFontHeight );
71 2 : aWriter.skipProperty(); // font offset
72 : // TODO make AxFontDataModel::convertFromProperties convert the textencoding
73 2 : aWriter.writeIntProperty< sal_uInt8 >( mnFontCharSet );
74 2 : aWriter.skipProperty(); // font pitch/family
75 :
76 2 : aWriter.writeIntProperty< sal_uInt8 >( mnHorAlign );
77 2 : aWriter.skipProperty(); // font weight
78 2 : aWriter.finalizeExport();
79 2 : }
80 :
81 0 : bool AxFontData::importStdFont( BinaryInputStream& rInStrm )
82 : {
83 0 : StdFontInfo aFontInfo;
84 0 : if( OleHelper::importStdFont( aFontInfo, rInStrm, false ) )
85 : {
86 0 : maFontName = aFontInfo.maName;
87 0 : mnFontEffects = 0;
88 0 : setFlag( mnFontEffects, AX_FONTDATA_BOLD, aFontInfo.mnWeight >= OLE_STDFONT_BOLD );
89 0 : setFlag( mnFontEffects, AX_FONTDATA_ITALIC, getFlag( aFontInfo.mnFlags, OLE_STDFONT_ITALIC ) );
90 0 : setFlag( mnFontEffects, AX_FONTDATA_UNDERLINE, getFlag( aFontInfo.mnFlags, OLE_STDFONT_UNDERLINE ) );
91 0 : setFlag( mnFontEffects, AX_FONTDATA_STRIKEOUT, getFlag( aFontInfo.mnFlags,OLE_STDFONT_STRIKE ) );
92 0 : mbDblUnderline = false;
93 : // StdFont stores font height in 1/10,000 of points
94 0 : setHeightPoints( getLimitedValue< sal_Int16, sal_Int32 >( aFontInfo.mnHeight / 10000, 0, SAL_MAX_INT16 ) );
95 0 : mnFontCharSet = aFontInfo.mnCharSet;
96 0 : mnHorAlign = AX_FONTDATA_LEFT;
97 0 : return true;
98 : }
99 0 : return false;
100 : }
101 :
102 0 : bool AxFontData::importGuidAndFont( BinaryInputStream& rInStrm )
103 : {
104 0 : OUString aGuid = OleHelper::importGuid( rInStrm );
105 0 : if( aGuid.equalsAscii( AX_GUID_CFONT ) )
106 0 : return importBinaryModel( rInStrm );
107 0 : if ( aGuid == OLE_GUID_STDFONT )
108 0 : return importStdFont( rInStrm );
109 0 : return false;
110 : }
111 :
112 : } // namespace ole
113 408 : } // namespace oox
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|