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 {
159 sValue.append( ',' );
160 sValue.append( ' ' );
161 }
162 sal_Int32 nLen = nLast-nFirst+1;
163 std::u16string_view sFamily( aStrFamilyName.subView( nFirst, nLen ) );
164 bool bQuote = false;
165 for( sal_Int32 i=0; i < nLen; i++ )
166 {
167 sal_Unicode c = sFamily[i];
168 if( ' ' == c || ',' == c )
169 {
170 bQuote = true;
171 break;
172 }
173 }
174 if( bQuote )
175 sValue.append( '\'' );
176 sValue.append( sFamily );
177 if( bQuote )
178 sValue.append( '\'' );
179 }
180 }
181 while( -1 != nPos );
182
183 rStrExpValue = sValue.makeStringAndClear();
184
185 bRet = true;
186 }
187
188 return bRet;
189}
190
191
193{
194 // Nothing to do
195}
196
197bool XMLFontFamilyPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
198{
199 FontFamily eNewFamily;
200 bool bRet = SvXMLUnitConverter::convertEnum( eNewFamily, rStrImpValue, lcl_getFontFamilyGenericMapping() );
201 if( bRet )
202 rValue <<= static_cast<sal_Int16>(eNewFamily);
203
204 return bRet;
205}
206
207bool XMLFontFamilyPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
208{
209 bool bRet = false;
210 OUStringBuffer aOut;
211
212 sal_Int16 nFamily = sal_Int16();
213 if( rValue >>= nFamily )
214 {
215 FontFamily eFamily = static_cast<FontFamily>(nFamily);
216 if( eFamily != FAMILY_DONTKNOW )
218 }
219
220 rStrExpValue = aOut.makeStringAndClear();
221
222 return bRet;
223}
224
225
227{
228 // Nothing to do
229}
230
231bool XMLFontEncodingPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
232{
233 if( IsXMLToken( rStrImpValue, XML_X_SYMBOL ) )
234 rValue <<= sal_Int16(RTL_TEXTENCODING_SYMBOL);
235
236 return true;
237}
238
239bool XMLFontEncodingPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
240{
241 bool bRet = false;
242 sal_Int16 nSet = sal_Int16();
243
244 if( rValue >>= nSet )
245 {
246 if( static_cast<rtl_TextEncoding>(nSet) == RTL_TEXTENCODING_SYMBOL )
247 {
248 rStrExpValue = GetXMLToken(XML_X_SYMBOL);
249 bRet = true;
250 }
251 }
252
253 return bRet;
254}
255
256
258{
259 // Nothing to do
260}
261
262bool XMLFontPitchPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
263{
264 FontPitch eNewPitch;
265 bool bRet = SvXMLUnitConverter::convertEnum( eNewPitch, rStrImpValue, aFontPitchMapping );
266 if( bRet )
267 rValue <<= static_cast<sal_Int16>(eNewPitch);
268
269 return bRet;
270}
271
272bool XMLFontPitchPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
273{
274 bool bRet = false;
275 sal_Int16 nPitch = sal_Int16();
276
277 FontPitch ePitch = PITCH_DONTKNOW;
278 if( rValue >>= nPitch )
279 ePitch = static_cast<FontPitch>(nPitch);
280
281 if( PITCH_DONTKNOW != ePitch )
282 {
283 OUStringBuffer aOut;
285 rStrExpValue = aOut.makeStringAndClear();
286 }
287
288 return bRet;
289}
290
291/* 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:231
virtual ~XMLFontEncodingPropHdl() override
Definition: fonthdl.cxx:226
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:239
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:192
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:197
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:207
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:272
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:262
virtual ~XMLFontPitchPropHdl() override
Definition: fonthdl.cxx:257
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:3581
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3525
sal_uInt16 sal_Unicode