crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / vcl / source / app / unohelp.cxx
blob05ac38c4fa7e8a186fe5d83f64cdc024f244dd90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
21 #include <vcl/unohelp.hxx>
23 #include <osl/diagnose.h>
25 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/i18n/BreakIterator.hpp>
28 #include <com/sun/star/i18n/CharacterClassification.hpp>
29 #include <com/sun/star/awt/FontWeight.hpp>
30 #include <com/sun/star/awt/FontWidth.hpp>
31 #include <com/sun/star/awt/XExtendedToolkit.hpp>
32 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
33 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 using namespace ::com::sun::star;
37 uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
39 const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
40 return i18n::BreakIterator::create(xContext);
43 uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
45 return i18n::CharacterClassification::create( comphelper::getProcessComponentContext() );
48 float vcl::unohelper::ConvertFontWidth( FontWidth eWidth )
50 if( eWidth == WIDTH_DONTKNOW )
51 return css::awt::FontWidth::DONTKNOW;
52 else if( eWidth == WIDTH_ULTRA_CONDENSED )
53 return css::awt::FontWidth::ULTRACONDENSED;
54 else if( eWidth == WIDTH_EXTRA_CONDENSED )
55 return css::awt::FontWidth::EXTRACONDENSED;
56 else if( eWidth == WIDTH_CONDENSED )
57 return css::awt::FontWidth::CONDENSED;
58 else if( eWidth == WIDTH_SEMI_CONDENSED )
59 return css::awt::FontWidth::SEMICONDENSED;
60 else if( eWidth == WIDTH_NORMAL )
61 return css::awt::FontWidth::NORMAL;
62 else if( eWidth == WIDTH_SEMI_EXPANDED )
63 return css::awt::FontWidth::SEMIEXPANDED;
64 else if( eWidth == WIDTH_EXPANDED )
65 return css::awt::FontWidth::EXPANDED;
66 else if( eWidth == WIDTH_EXTRA_EXPANDED )
67 return css::awt::FontWidth::EXTRAEXPANDED;
68 else if( eWidth == WIDTH_ULTRA_EXPANDED )
69 return css::awt::FontWidth::ULTRAEXPANDED;
71 OSL_FAIL( "Unknown FontWidth" );
72 return css::awt::FontWidth::DONTKNOW;
75 FontWidth vcl::unohelper::ConvertFontWidth( float f )
77 if( f <= css::awt::FontWidth::DONTKNOW )
78 return WIDTH_DONTKNOW;
79 else if( f <= css::awt::FontWidth::ULTRACONDENSED )
80 return WIDTH_ULTRA_CONDENSED;
81 else if( f <= css::awt::FontWidth::EXTRACONDENSED )
82 return WIDTH_EXTRA_CONDENSED;
83 else if( f <= css::awt::FontWidth::CONDENSED )
84 return WIDTH_CONDENSED;
85 else if( f <= css::awt::FontWidth::SEMICONDENSED )
86 return WIDTH_SEMI_CONDENSED;
87 else if( f <= css::awt::FontWidth::NORMAL )
88 return WIDTH_NORMAL;
89 else if( f <= css::awt::FontWidth::SEMIEXPANDED )
90 return WIDTH_SEMI_EXPANDED;
91 else if( f <= css::awt::FontWidth::EXPANDED )
92 return WIDTH_EXPANDED;
93 else if( f <= css::awt::FontWidth::EXTRAEXPANDED )
94 return WIDTH_EXTRA_EXPANDED;
95 else if( f <= css::awt::FontWidth::ULTRAEXPANDED )
96 return WIDTH_ULTRA_EXPANDED;
98 OSL_FAIL( "Unknown FontWidth" );
99 return WIDTH_DONTKNOW;
102 float vcl::unohelper::ConvertFontWeight( FontWeight eWeight )
104 if( eWeight == WEIGHT_DONTKNOW )
105 return css::awt::FontWeight::DONTKNOW;
106 else if( eWeight == WEIGHT_THIN )
107 return css::awt::FontWeight::THIN;
108 else if( eWeight == WEIGHT_ULTRALIGHT )
109 return css::awt::FontWeight::ULTRALIGHT;
110 else if( eWeight == WEIGHT_LIGHT )
111 return css::awt::FontWeight::LIGHT;
112 else if( eWeight == WEIGHT_SEMILIGHT )
113 return css::awt::FontWeight::SEMILIGHT;
114 else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
115 return css::awt::FontWeight::NORMAL;
116 else if( eWeight == WEIGHT_SEMIBOLD )
117 return css::awt::FontWeight::SEMIBOLD;
118 else if( eWeight == WEIGHT_BOLD )
119 return css::awt::FontWeight::BOLD;
120 else if( eWeight == WEIGHT_ULTRABOLD )
121 return css::awt::FontWeight::ULTRABOLD;
122 else if( eWeight == WEIGHT_BLACK )
123 return css::awt::FontWeight::BLACK;
125 OSL_FAIL( "Unknown FontWeight" );
126 return css::awt::FontWeight::DONTKNOW;
129 FontWeight vcl::unohelper::ConvertFontWeight( float f )
131 if( f <= css::awt::FontWeight::DONTKNOW )
132 return WEIGHT_DONTKNOW;
133 else if( f <= css::awt::FontWeight::THIN )
134 return WEIGHT_THIN;
135 else if( f <= css::awt::FontWeight::ULTRALIGHT )
136 return WEIGHT_ULTRALIGHT;
137 else if( f <= css::awt::FontWeight::LIGHT )
138 return WEIGHT_LIGHT;
139 else if( f <= css::awt::FontWeight::SEMILIGHT )
140 return WEIGHT_SEMILIGHT;
141 else if( f <= css::awt::FontWeight::NORMAL )
142 return WEIGHT_NORMAL;
143 else if( f <= css::awt::FontWeight::SEMIBOLD )
144 return WEIGHT_SEMIBOLD;
145 else if( f <= css::awt::FontWeight::BOLD )
146 return WEIGHT_BOLD;
147 else if( f <= css::awt::FontWeight::ULTRABOLD )
148 return WEIGHT_ULTRABOLD;
149 else if( f <= css::awt::FontWeight::BLACK )
150 return WEIGHT_BLACK;
152 OSL_FAIL( "Unknown FontWeight" );
153 return WEIGHT_DONTKNOW;
156 css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
158 css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
159 switch (eItalic)
161 case ITALIC_NONE:
162 eRet = css::awt::FontSlant_NONE;
163 break;
164 case ITALIC_OBLIQUE:
165 eRet = css::awt::FontSlant_OBLIQUE;
166 break;
167 case ITALIC_NORMAL:
168 eRet = css::awt::FontSlant_ITALIC;
169 break;
170 case ITALIC_DONTKNOW:
171 eRet = css::awt::FontSlant_DONTKNOW;
172 break;
173 case FontItalic_FORCE_EQUAL_SIZE:
174 eRet = css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE;
175 break;
177 return eRet;
180 FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
182 FontItalic eRet = ITALIC_DONTKNOW;
183 switch (eSlant)
185 case css::awt::FontSlant_NONE:
186 eRet = ITALIC_NONE;
187 break;
188 case css::awt::FontSlant_OBLIQUE:
189 eRet = ITALIC_OBLIQUE;
190 break;
191 case css::awt::FontSlant_ITALIC:
192 eRet = ITALIC_NORMAL;
193 break;
194 case css::awt::FontSlant_DONTKNOW:
195 eRet = ITALIC_DONTKNOW;
196 break;
197 case css::awt::FontSlant_REVERSE_OBLIQUE:
198 //there is no vcl reverse oblique
199 eRet = ITALIC_OBLIQUE;
200 break;
201 case css::awt::FontSlant_REVERSE_ITALIC:
202 //there is no vcl reverse normal
203 eRet = ITALIC_NORMAL;
204 break;
205 case css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE:
206 eRet = FontItalic_FORCE_EQUAL_SIZE;
207 break;
209 return eRet;
212 Size vcl::unohelper::ConvertToVCLSize(const css::awt::Size& rAWTSize)
214 return Size(rAWTSize.Width, rAWTSize.Height);
217 css::awt::Size vcl::unohelper::ConvertToAWTSize(const Size& rVCLSize)
219 return css::awt::Size(rVCLSize.Width(), rVCLSize.Height());
222 Point vcl::unohelper::ConvertToVCLPoint(const css::awt::Point& rAWTPoint)
224 return Point(rAWTPoint.X, rAWTPoint.Y);
227 css::awt::Point vcl::unohelper::ConvertToAWTPoint(const PointTemplateBase& rVCLPoint)
229 return css::awt::Point(rVCLPoint.X(), rVCLPoint.Y());
232 tools::Rectangle vcl::unohelper::ConvertToVCLRect(const css::awt::Rectangle& rAWTRect)
234 return ::tools::Rectangle(Point(rAWTRect.X, rAWTRect.Y),
235 Size(rAWTRect.Width, rAWTRect.Height));
238 css::awt::Rectangle vcl::unohelper::ConvertToAWTRect(const RectangleTemplateBase& rVCLRect)
240 return css::awt::Rectangle(rVCLRect.Left(), rVCLRect.Top(), rVCLRect.GetWidth(),
241 rVCLRect.GetHeight());
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */