LibreOffice Module oox (master) 1
textfont.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
21#include <com/sun/star/awt/FontFamily.hpp>
22#include <com/sun/star/awt/FontPitch.hpp>
26#include <oox/token/tokens.hxx>
28
29using ::oox::core::XmlFilterBase;
30
31namespace oox::drawingml {
32
33namespace {
34
35sal_Int16 lclGetFontPitch( sal_Int32 nOoxValue )
36{
37 using namespace ::com::sun::star::awt::FontPitch;
38 static const sal_Int16 spnFontPitch[] = { DONTKNOW, FIXED, VARIABLE };
39 return STATIC_ARRAY_SELECT( spnFontPitch, nOoxValue, DONTKNOW );
40}
41
42sal_Int16 lclGetFontFamily( sal_Int32 nOoxValue )
43{
44 using namespace ::com::sun::star::awt::FontFamily;
45 static const sal_Int16 spnFontFamily[] = { DONTKNOW, ROMAN, SWISS, MODERN, SCRIPT, DECORATIVE };
46 return STATIC_ARRAY_SELECT( spnFontFamily, nOoxValue, DONTKNOW );
47}
48
49} // namespace
50
52 mnPitchFamily(0),
53 mnCharset( WINDOWS_CHARSET_ANSI )
54{
55}
56
58{
59 maTypeface = rAttribs.getStringDefaulted( XML_typeface);
60 maPanose = rAttribs.getStringDefaulted( XML_panose);
61 mnPitchFamily = rAttribs.getInteger( XML_pitchFamily, 0 );
62 mnCharset = rAttribs.getInteger( XML_charset, WINDOWS_CHARSET_DEFAULT );
63}
64
65void TextFont::setAttributes( const OUString& sFontName )
66{
67 maTypeface = sFontName;
68 maPanose.clear();
69 mnPitchFamily = 0;
71}
72
73void TextFont::assignIfUsed( const TextFont& rTextFont )
74{
75 if( !rTextFont.maTypeface.isEmpty() )
76 *this = rTextFont;
77}
78
79bool TextFont::getFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily, const XmlFilterBase& rFilter ) const
80{
81 if( const Theme* pTheme = rFilter.getCurrentTheme() )
82 if( const TextFont* pFont = pTheme->resolveFont( maTypeface ) )
83 return pFont->implGetFontData( rFontName, rnFontPitch, rnFontFamily );
84 return implGetFontData( rFontName, rnFontPitch, rnFontFamily );
85}
86
87bool TextFont::implGetFontData( OUString& rFontName, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily ) const
88{
89 rFontName = maTypeface;
90 resolvePitch(mnPitchFamily, rnFontPitch, rnFontFamily);
91 return !rFontName.isEmpty();
92}
93
95{
96 rThemeFont.maTypeface = maTypeface;
97 rThemeFont.maPanose = maPanose;
98 rThemeFont.maCharset = mnCharset;
99 resolvePitch(mnPitchFamily, rThemeFont.maPitch, rThemeFont.maFamily);
100}
101
102void TextFont::resolvePitch(sal_Int32 nOoxPitchFamily, sal_Int16& rnFontPitch, sal_Int16& rnFontFamily)
103{
104 rnFontPitch = lclGetFontPitch(extractValue<sal_Int16>(nOoxPitchFamily, 0, 4));
105 rnFontFamily = lclGetFontFamily(extractValue<sal_Int16>(nOoxPitchFamily, 4, 4));
106}
107
108
109} // namespace oox::drawingml
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
virtual const ::oox::drawingml::Theme * getCurrentTheme() const =0
Has to be implemented by each filter, returns the current theme.
carries a CT_TextFont
Definition: textfont.hxx:34
bool implGetFontData(OUString &rFontName, sal_Int16 &rnFontPitch, sal_Int16 &rnFontFamily) const
Definition: textfont.cxx:87
void assignIfUsed(const TextFont &rTextFont)
Overwrites this text font with the passed text font, if it is used.
Definition: textfont.cxx:73
void setAttributes(const AttributeList &rAttribs)
Sets attributes from the passed attribute list.
Definition: textfont.cxx:57
static void resolvePitch(sal_Int32 nOoxPitch, sal_Int16 &rnFontPitch, sal_Int16 &rnFontFamily)
Definition: textfont.cxx:102
void fillThemeFont(model::ThemeFont &rThemeFont) const
Definition: textfont.cxx:94
bool getFontData(OUString &rFontName, sal_Int16 &rnFontPitch, sal_Int16 &rnFontFamily, const ::oox::core::XmlFilterBase &rFilter) const
Returns the font name, pitch, and family; tries to resolve theme placeholder names,...
Definition: textfont.cxx:79
#define STATIC_ARRAY_SELECT(array, index, def)
Expands to the 'index'-th element of a STATIC data array, or to 'def', if 'index' is out of the array...
Definition: helper.hxx:57
const sal_uInt8 WINDOWS_CHARSET_ANSI
Definition: helper.hxx:62
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
Definition: helper.hxx:63
sal_Int16 maFamily
sal_Int16 maPitch
sal_Int32 maCharset
OUString maTypeface