/src/libreoffice/oox/source/drawingml/textfont.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 <drawingml/textfont.hxx> |
21 | | #include <com/sun/star/awt/FontFamily.hpp> |
22 | | #include <com/sun/star/awt/FontPitch.hpp> |
23 | | #include <oox/drawingml/theme.hxx> |
24 | | #include <oox/core/xmlfilterbase.hxx> |
25 | | #include <oox/helper/attributelist.hxx> |
26 | | #include <oox/token/tokens.hxx> |
27 | | #include <docmodel/theme/Theme.hxx> |
28 | | |
29 | | using ::oox::core::XmlFilterBase; |
30 | | |
31 | | namespace oox::drawingml { |
32 | | |
33 | | namespace { |
34 | | |
35 | | sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue ) |
36 | 2.44M | { |
37 | 2.44M | using namespace ::com::sun::star::awt::FontPitch; |
38 | 2.44M | static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE }; |
39 | 2.44M | return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW ); |
40 | 2.44M | } |
41 | | |
42 | | sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue ) |
43 | 2.44M | { |
44 | 2.44M | using namespace ::com::sun::star::awt::FontFamily; |
45 | 2.44M | static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE }; |
46 | 2.44M | return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW ); |
47 | 2.44M | } |
48 | | |
49 | | } // namespace |
50 | | |
51 | | TextFont::TextFont() : |
52 | 91.5M | mnPitchFamily(0), |
53 | 91.5M | mnCharset( WINDOWS_CHARSET_ANSI ) |
54 | 91.5M | { |
55 | 91.5M | } |
56 | | |
57 | | void TextFont::setAttributes( const AttributeList& rAttribs ) |
58 | 542k | { |
59 | 542k | maTypeface = rAttribs.getStringDefaulted( XML_typeface); |
60 | 542k | maPanose = rAttribs.getStringDefaulted( XML_panose); |
61 | 542k | mnPitchFamily = rAttribs.getInteger( XML_pitchFamily, 0 ); |
62 | 542k | mnCharset = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT ); |
63 | 542k | } |
64 | | |
65 | | void TextFont::setAttributes( const OUString& sFontName ) |
66 | 0 | { |
67 | 0 | maTypeface = sFontName; |
68 | 0 | maPanose.clear(); |
69 | 0 | mnPitchFamily = 0; |
70 | 0 | mnCharset = WINDOWS_CHARSET_DEFAULT; |
71 | 0 | } |
72 | | |
73 | | void TextFont::assignIfUsed( const TextFont& rTextFont ) |
74 | 51.6M | { |
75 | 51.6M | if( !rTextFont.maTypeface.isEmpty() ) |
76 | 2.49M | *this = rTextFont; |
77 | 51.6M | } |
78 | | |
79 | | bool TextFont::getFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily, bool* pbSymbol, const XmlFilterBase& rFilter ) const |
80 | 2.41M | { |
81 | 2.41M | if( const Theme* pTheme = rFilter.getCurrentTheme() ) |
82 | 2.35M | if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) ) |
83 | 449k | return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily, pbSymbol ); |
84 | 1.96M | return implGetFontData( rFontName, rnFontPitch, rnFontFamily, pbSymbol ); |
85 | 2.41M | } |
86 | | |
87 | | bool TextFont::implGetFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily, bool* pbSymbol ) const |
88 | 2.41M | { |
89 | 2.41M | rFontName = maTypeface; |
90 | 2.41M | resolvePitch(mnPitchFamily, rnFontPitch, rnFontFamily); |
91 | 2.41M | if (pbSymbol) |
92 | 104k | *pbSymbol = mnCharset == WINDOWS_CHARSET_SYMBOL; |
93 | 2.41M | return !rFontName.isEmpty(); |
94 | 2.41M | } |
95 | | |
96 | | void TextFont::fillThemeFont(model::ThemeFont& rThemeFont) const |
97 | 0 | { |
98 | 0 | rThemeFont.maTypeface = maTypeface; |
99 | 0 | rThemeFont.maPanose = maPanose; |
100 | 0 | rThemeFont.maCharset = mnCharset; |
101 | 0 | resolvePitch(mnPitchFamily, rThemeFont.maPitch, rThemeFont.maFamily); |
102 | 0 | } |
103 | | |
104 | | void TextFont::resolvePitch(sal_Int32 nOoxPitchFamily, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily) |
105 | 2.44M | { |
106 | 2.44M | rnFontPitch = lclGetFontPitch(extractValue<sal_Int16>(nOoxPitchFamily, 0, 4)); |
107 | 2.44M | rnFontFamily = lclGetFontFamily(extractValue<sal_Int16>(nOoxPitchFamily, 4, 4)); |
108 | 2.44M | } |
109 | | |
110 | | |
111 | | } // namespace oox::drawingml |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |