LibreOffice Module xmloff (master) 1
fonthdl.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
20#include <sal/config.h>
21
22#include <string_view>
23
24#include "fonthdl.hxx"
25
27
28#include <xmloff/xmltoken.hxx>
29#include <xmloff/xmluconv.hxx>
30#include <xmloff/xmlement.hxx>
31#include <rtl/ustrbuf.hxx>
32#include <com/sun/star/uno/Any.hxx>
33#include <tools/fontenum.hxx>
34
35using namespace ::com::sun::star;
36using namespace ::xmloff::token;
37
39{
40 static SvXMLEnumMapEntry<FontFamily> const aFontFamilyGenericMapping[] =
41 {
43
50 };
51 return aFontFamilyGenericMapping;
52}
53
55{
59};
60
61
63{
64 // Nothing to do
65}
66
67bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
68{
69 bool bRet = false;
70 OUStringBuffer sValue;
71 sal_Int32 nPos = 0;
72
73 do
74 {
75 sal_Int32 nFirst = nPos;
76 nPos = ::sax::Converter::indexOfComma( rStrImpValue, nPos );
77 sal_Int32 nLast = (-1 == nPos ? rStrImpValue.getLength() - 1 : nPos - 1);
78
79 // skip trailing blanks
80 while( nLast > nFirst && ' ' == rStrImpValue[nLast] )
81 nLast--;
82
83 // skip leading blanks
84 while(nFirst <= nLast && ' ' == rStrImpValue[nFirst])
85 nFirst++;
86
87 // remove quotes
88 sal_Unicode c = nFirst > nLast ? 0 : rStrImpValue[nFirst];
89 if( nFirst < nLast && ('\'' == c || '\"' == c) && rStrImpValue[nLast] == c )
90 {
91 nFirst++;
92 nLast--;
93 }
94
95 if( nFirst <= nLast )
96 {
97 if( !sValue.isEmpty() )
98 sValue.append(';');
99
100 sValue.append(rStrImpValue.subView(nFirst, nLast-nFirst+1));
101 }
102
103 if( -1 != nPos )
104 nPos++;
105 }
106 while( -1 != nPos );
107
108 if (!sValue.isEmpty())
109 {
110 rValue <<= sValue.makeStringAndClear();
111 bRet = true;
112 }
113
114 return bRet;
115}
116
117bool XMLFontFamilyNamePropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
118{
119 bool bRet = false;
120 OUString aStrFamilyName;
121
122 if( rValue >>= aStrFamilyName )
123 {
124 OUStringBuffer sValue( aStrFamilyName.getLength() + 2 );
125 sal_Int32 nPos = 0;
126 do
127 {
128 sal_Int32 nFirst = nPos;
129 nPos = aStrFamilyName.indexOf( ';', nPos );
130 sal_Int32 nLast = (-1 == nPos ? aStrFamilyName.getLength() : nPos);
131
132 // Set position to the character behind the ';', so we won't
133 // forget this.
134 if( -1 != nPos )
135 nPos++;
136
137 // If the property value was empty, we stop now.
138 // If there is a ';' at the first position, the empty name
139 // at the start will be removed.
140 if( 0 == nLast )
141 continue;
142
143 // nFirst and nLast now denote the first and last character of
144 // one font name.
145 nLast--;
146
147 // skip trailing blanks
148 while( nLast > nFirst && ' ' == aStrFamilyName[nLast] )
149 nLast--;
150
151 // skip leading blanks
152 while( nFirst <= nLast && ' ' == aStrFamilyName[nFirst] )
153 nFirst++;
154
155 if( nFirst <= nLast )
156 {
157 if( !sValue.isEmpty() )
158 sValue.append( ", " );
159 sal_Int32 nLen = nLast-nFirst+1;
160 std::u16string_view sFamily( aStrFamilyName.subView( nFirst, nLen ) );
161 bool bQuote = false;
162 for( sal_Int32 i=0; i < nLen; i++ )
163 {
164 sal_Unicode c = sFamily[i];
165 if( ' ' == c || ',' == c )
166 {
167 bQuote = true;
168 break;
169 }
170 }
171 if( bQuote )
172 sValue.append( '\'' );
173 sValue.append( sFamily );
174 if( bQuote )
175 sValue.append( '\'' );
176 }
177 }
178 while( -1 != nPos );
179
180 rStrExpValue = sValue.makeStringAndClear();
181
182 bRet = true;
183 }
184
185 return bRet;
186}
187
188
190{
191 // Nothing to do
192}
193
194bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
195{
196 FontFamily eNewFamily;
197 bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
198 if( bRet )
199 rValue <<= static_cast<sal_Int16>(eNewFamily);
200
201 return bRet;
202}
203
204bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
205{
206 bool bRet = false;
207 OUStringBuffer aOut;
208
209 sal_Int16 nFamily = sal_Int16();
210 if( rValue >>= nFamily )
211 {
212 FontFamily eFamily = static_cast<FontFamily>(nFamily);
213 if( eFamily != FAMILY_DONTKNOW )
215 }
216
217 rStrExpValue = aOut.makeStringAndClear();
218
219 return bRet;
220}
221
222
224{
225 // Nothing to do
226}
227
228bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
229{
230 if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
231 rValue <<= sal_Int16(RTL_TEXTENCODING_SYMBOL);
232
233 return true;
234}
235
236bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
237{
238 bool bRet = false;
239 sal_Int16 nSet = sal_Int16();
240
241 if( rValue >>= nSet )
242 {
243 if( static_cast<rtl_TextEncoding>(nSet) == RTL_TEXTENCODING_SYMBOL )
244 {
245 rStrExpValue = GetXMLToken(XML_X_SYMBOL);
246 bRet = true;
247 }
248 }
249
250 return bRet;
251}
252
253
255{
256 // Nothing to do
257}
258
259bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
260{
261 FontPitch eNewPitch;
262 bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
263 if( bRet )
264 rValue <<= static_cast<sal_Int16>(eNewPitch);
265
266 return bRet;
267}
268
269bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
270{
271 bool bRet = false;
272 sal_Int16 nPitch = sal_Int16();
273
274 FontPitch ePitch = PITCH_DONTKNOW;
275 if( rValue >>= nPitch )
276 ePitch = static_cast<FontPitch>(nPitch);
277
278 if( PITCH_DONTKNOW != ePitch )
279 {
280 OUStringBuffer aOut;
282 rStrExpValue = aOut.makeStringAndClear();
283 }
284
285 return bRet;
286}
287
288/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
Definition: xmluconv.hxx:145
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:228
virtual ~XMLFontEncodingPropHdl() override
Definition: fonthdl.cxx:223
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:236
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:67
virtual ~XMLFontFamilyNamePropHdl() override
Definition: fonthdl.cxx:62
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:117
virtual ~XMLFontFamilyPropHdl() override
Definition: fonthdl.cxx:189
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:194
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:204
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:269
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
Definition: fonthdl.cxx:259
virtual ~XMLFontPitchPropHdl() override
Definition: fonthdl.cxx:254
static sal_Int32 indexOfComma(std::u16string_view rStr, sal_Int32 nPos)
FontPitch
PITCH_VARIABLE
PITCH_FIXED
PITCH_DONTKNOW
FontFamily
FAMILY_DECORATIVE
FAMILY_SYSTEM
FAMILY_DONTKNOW
FAMILY_SCRIPT
FAMILY_SWISS
FAMILY_MODERN
FAMILY_ROMAN
static const SvXMLEnumMapEntry< FontFamily > * lcl_getFontFamilyGenericMapping()
Definition: fonthdl.cxx:38
SvXMLEnumMapEntry< FontPitch > const aFontPitchMapping[]
Definition: fonthdl.cxx:54
sal_uInt16 nPos
int i
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
sal_uInt16 sal_Unicode