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