/src/libreoffice/xmloff/source/style/lspachdl.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 "lspachdl.hxx" |
21 | | #include <xmloff/xmltoken.hxx> |
22 | | #include <xmloff/xmluconv.hxx> |
23 | | #include <sax/tools/converter.hxx> |
24 | | #include <rtl/ustrbuf.hxx> |
25 | | #include <com/sun/star/uno/Any.hxx> |
26 | | #include <com/sun/star/style/LineSpacing.hpp> |
27 | | #include <com/sun/star/style/LineSpacingMode.hpp> |
28 | | |
29 | | using namespace ::com::sun::star; |
30 | | using ::xmloff::token::IsXMLToken; |
31 | | using ::xmloff::token::XML_NORMAL; |
32 | | |
33 | | |
34 | | |
35 | | |
36 | | XMLLineHeightHdl::~XMLLineHeightHdl() |
37 | 126k | { |
38 | | // nothing to do |
39 | 126k | } |
40 | | |
41 | | bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
42 | 1.05k | { |
43 | 1.05k | style::LineSpacing aLSp; |
44 | 1.05k | sal_Int32 nTemp = 0; |
45 | | |
46 | 1.05k | if( -1 != rStrImpValue.indexOf( '%' ) ) |
47 | 1.04k | { |
48 | 1.04k | aLSp.Mode = style::LineSpacingMode::PROP; |
49 | 1.04k | if (!::sax::Converter::convertPercent( nTemp, rStrImpValue )) |
50 | 5 | return false; |
51 | 1.04k | aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); |
52 | 1.04k | } |
53 | 11 | else if( IsXMLToken( rStrImpValue, XML_NORMAL) ) |
54 | 0 | { |
55 | 0 | aLSp.Mode = style::LineSpacingMode::PROP; |
56 | 0 | aLSp.Height = 100; |
57 | 0 | } |
58 | 11 | else |
59 | 11 | { |
60 | 11 | aLSp.Mode = style::LineSpacingMode::FIX; |
61 | 11 | if (!rUnitConverter.convertMeasureToCore( |
62 | 11 | nTemp, rStrImpValue, 0x0000, 0xffff)) |
63 | 11 | return false; |
64 | 0 | aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); |
65 | 0 | } |
66 | | |
67 | 1.04k | rValue <<= aLSp; |
68 | 1.04k | return true; |
69 | 1.05k | } |
70 | | |
71 | | bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
72 | 1 | { |
73 | 1 | OUStringBuffer aOut; |
74 | | |
75 | 1 | style::LineSpacing aLSp; |
76 | 1 | if(!(rValue >>= aLSp)) |
77 | 0 | return false; |
78 | | |
79 | 1 | if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode ) |
80 | 0 | return false; |
81 | | |
82 | 1 | if( style::LineSpacingMode::PROP == aLSp.Mode ) |
83 | 1 | { |
84 | 1 | ::sax::Converter::convertPercent( aOut, aLSp.Height ); |
85 | 1 | } |
86 | 0 | else |
87 | 0 | { |
88 | 0 | rUnitConverter.convertMeasureToXML( aOut, aLSp.Height ); |
89 | 0 | } |
90 | | |
91 | 1 | rStrExpValue = aOut.makeStringAndClear(); |
92 | 1 | return !rStrExpValue.isEmpty(); |
93 | 1 | } |
94 | | |
95 | | |
96 | | |
97 | | |
98 | | XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl() |
99 | 126k | { |
100 | | // nothing to do |
101 | 126k | } |
102 | | |
103 | | bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
104 | 0 | { |
105 | 0 | style::LineSpacing aLSp; |
106 | |
|
107 | 0 | sal_Int32 nTemp; |
108 | 0 | aLSp.Mode = style::LineSpacingMode::MINIMUM; |
109 | 0 | if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff)) |
110 | 0 | return false; |
111 | 0 | aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); |
112 | |
|
113 | 0 | rValue <<= aLSp; |
114 | 0 | return true; |
115 | 0 | } |
116 | | |
117 | | bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
118 | 1 | { |
119 | 1 | OUStringBuffer aOut; |
120 | | |
121 | 1 | style::LineSpacing aLSp; |
122 | 1 | if(!(rValue >>= aLSp)) |
123 | 0 | return false; |
124 | | |
125 | 1 | if( style::LineSpacingMode::MINIMUM != aLSp.Mode ) |
126 | 1 | return false; |
127 | | |
128 | 0 | rUnitConverter.convertMeasureToXML( aOut, aLSp.Height ); |
129 | |
|
130 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
131 | 0 | return !rStrExpValue.isEmpty(); |
132 | 1 | } |
133 | | |
134 | | |
135 | | |
136 | | |
137 | | XMLLineSpacingHdl::~XMLLineSpacingHdl() |
138 | 126k | { |
139 | | // nothing to do |
140 | 126k | } |
141 | | |
142 | | bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
143 | 0 | { |
144 | 0 | style::LineSpacing aLSp; |
145 | 0 | sal_Int32 nTemp; |
146 | |
|
147 | 0 | aLSp.Mode = style::LineSpacingMode::LEADING; |
148 | 0 | if (!rUnitConverter.convertMeasureToCore( nTemp, rStrImpValue, 0, 0xffff)) |
149 | 0 | return false; |
150 | 0 | aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp); |
151 | |
|
152 | 0 | rValue <<= aLSp; |
153 | 0 | return true; |
154 | 0 | } |
155 | | |
156 | | bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const |
157 | 1 | { |
158 | 1 | OUStringBuffer aOut; |
159 | | |
160 | 1 | style::LineSpacing aLSp; |
161 | 1 | if(!(rValue >>= aLSp)) |
162 | 0 | return false; |
163 | | |
164 | 1 | if( style::LineSpacingMode::LEADING != aLSp.Mode ) |
165 | 1 | return false; |
166 | | |
167 | 0 | rUnitConverter.convertMeasureToXML( aOut, aLSp.Height ); |
168 | |
|
169 | 0 | rStrExpValue = aOut.makeStringAndClear(); |
170 | 0 | return !rStrExpValue.isEmpty(); |
171 | 1 | } |
172 | | |
173 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |