/src/libreoffice/xmloff/source/style/escphdl.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 "escphdl.hxx" |
21 | | |
22 | | #include <editeng/escapementitem.hxx> |
23 | | #include <sax/tools/converter.hxx> |
24 | | #include <xmloff/xmltoken.hxx> |
25 | | #include <xmloff/xmluconv.hxx> |
26 | | #include <rtl/ustrbuf.hxx> |
27 | | #include <com/sun/star/uno/Any.hxx> |
28 | | |
29 | | using namespace ::com::sun::star; |
30 | | using namespace ::xmloff::token; |
31 | | |
32 | | |
33 | | |
34 | | |
35 | | XMLEscapementPropHdl::~XMLEscapementPropHdl() |
36 | 121k | { |
37 | | // nothing to do |
38 | 121k | } |
39 | | |
40 | | bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
41 | 8.09k | { |
42 | 8.09k | sal_Int16 nVal; |
43 | | |
44 | 8.09k | SvXMLTokenEnumerator aTokens( rStrImpValue ); |
45 | | |
46 | 8.09k | std::u16string_view aToken; |
47 | 8.09k | if( ! aTokens.getNextToken( aToken ) ) |
48 | 0 | return false; |
49 | | |
50 | 8.09k | if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) ) |
51 | 730 | { |
52 | 730 | nVal = DFLT_ESC_AUTO_SUB; |
53 | 730 | } |
54 | 7.36k | else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) ) |
55 | 1.27k | { |
56 | 1.27k | nVal = DFLT_ESC_AUTO_SUPER; |
57 | 1.27k | } |
58 | 6.08k | else |
59 | 6.08k | { |
60 | 6.08k | sal_Int32 nNewEsc; |
61 | 6.08k | if (!::sax::Converter::convertPercent( nNewEsc, aToken )) |
62 | 21 | return false; |
63 | | |
64 | 6.06k | nVal = static_cast<sal_Int16>(nNewEsc); |
65 | 6.06k | } |
66 | | |
67 | 8.07k | rValue <<= nVal; |
68 | 8.07k | return true; |
69 | 8.09k | } |
70 | | |
71 | | bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
72 | 0 | { |
73 | 0 | sal_Int32 nValue = 0; |
74 | 0 | OUStringBuffer aOut; |
75 | |
|
76 | 0 | if( rValue >>= nValue ) |
77 | 0 | { |
78 | 0 | if( nValue == DFLT_ESC_AUTO_SUPER ) |
79 | 0 | { |
80 | 0 | aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) ); |
81 | 0 | } |
82 | 0 | else if( nValue == DFLT_ESC_AUTO_SUB ) |
83 | 0 | { |
84 | 0 | aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) ); |
85 | 0 | } |
86 | 0 | else |
87 | 0 | { |
88 | 0 | ::sax::Converter::convertPercent( aOut, nValue ); |
89 | 0 | } |
90 | 0 | } |
91 | |
|
92 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
93 | 0 | return !rStrExpValue.isEmpty(); |
94 | 0 | } |
95 | | |
96 | | |
97 | | |
98 | | |
99 | | XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl() |
100 | 121k | { |
101 | | // nothing to do |
102 | 121k | } |
103 | | |
104 | | bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const |
105 | 8.09k | { |
106 | 8.09k | if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) ) |
107 | 0 | return false; |
108 | | |
109 | 8.09k | SvXMLTokenEnumerator aTokens( rStrImpValue ); |
110 | | |
111 | 8.09k | std::u16string_view aToken; |
112 | 8.09k | if( ! aTokens.getNextToken( aToken ) ) |
113 | 0 | return false; |
114 | | |
115 | 8.09k | sal_Int8 nProp; |
116 | 8.09k | if( aTokens.getNextToken( aToken ) ) |
117 | 2.02k | { |
118 | 2.02k | sal_Int32 nNewProp; |
119 | 2.02k | if (!::sax::Converter::convertPercent( nNewProp, aToken )) |
120 | 34 | return false; |
121 | 1.99k | nProp = static_cast<sal_Int8>(nNewProp); |
122 | 1.99k | } |
123 | 6.06k | else |
124 | 6.06k | { |
125 | 6.06k | sal_Int32 nEscapementPosition=0; |
126 | 6.06k | if (::sax::Converter::convertPercent( nEscapementPosition, aToken ) |
127 | 6.06k | && (nEscapementPosition == 0)) |
128 | 6.06k | { |
129 | 6.06k | nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#) |
130 | 6.06k | } |
131 | 3 | else |
132 | 3 | nProp = sal_Int8(DFLT_ESC_PROP); |
133 | 6.06k | } |
134 | | |
135 | 8.05k | rValue <<= nProp; |
136 | 8.05k | return true; |
137 | 8.09k | } |
138 | | |
139 | | bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const |
140 | 0 | { |
141 | 0 | OUStringBuffer aOut( rStrExpValue ); |
142 | |
|
143 | 0 | sal_Int32 nValue = 0; |
144 | 0 | if( rValue >>= nValue ) |
145 | 0 | { |
146 | 0 | if( !rStrExpValue.isEmpty() ) |
147 | 0 | aOut.append( ' '); |
148 | |
|
149 | 0 | ::sax::Converter::convertPercent( aOut, nValue ); |
150 | 0 | } |
151 | |
|
152 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
153 | 0 | return !rStrExpValue.isEmpty(); |
154 | 0 | } |
155 | | |
156 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |