Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/app/unohelp.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 <tools/gen.hxx>
21
#include <vcl/svapp.hxx>
22
#include <vcl/unohelp.hxx>
23
24
#include <osl/diagnose.h>
25
26
#include <comphelper/processfactory.hxx>
27
28
#include <com/sun/star/i18n/BreakIterator.hpp>
29
#include <com/sun/star/i18n/CharacterClassification.hpp>
30
#include <com/sun/star/awt/FontWeight.hpp>
31
#include <com/sun/star/awt/FontWidth.hpp>
32
#include <com/sun/star/awt/Point.hpp>
33
#include <com/sun/star/awt/XExtendedToolkit.hpp>
34
35
using namespace ::com::sun::star;
36
37
uno::Reference < i18n::XBreakIterator > vcl::unohelper::CreateBreakIterator()
38
299k
{
39
299k
    const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
40
299k
    return i18n::BreakIterator::create(xContext);
41
299k
}
42
43
uno::Reference < i18n::XCharacterClassification > vcl::unohelper::CreateCharacterClassification()
44
0
{
45
0
    return i18n::CharacterClassification::create( comphelper::getProcessComponentContext() );
46
0
}
47
48
float vcl::unohelper::ConvertFontWidth( FontWidth eWidth )
49
0
{
50
0
    if( eWidth == WIDTH_DONTKNOW )
51
0
        return css::awt::FontWidth::DONTKNOW;
52
0
    else if( eWidth == WIDTH_ULTRA_CONDENSED )
53
0
        return css::awt::FontWidth::ULTRACONDENSED;
54
0
    else if( eWidth == WIDTH_EXTRA_CONDENSED )
55
0
        return css::awt::FontWidth::EXTRACONDENSED;
56
0
    else if( eWidth == WIDTH_CONDENSED )
57
0
        return css::awt::FontWidth::CONDENSED;
58
0
    else if( eWidth == WIDTH_SEMI_CONDENSED )
59
0
        return css::awt::FontWidth::SEMICONDENSED;
60
0
    else if( eWidth == WIDTH_NORMAL )
61
0
        return css::awt::FontWidth::NORMAL;
62
0
    else if( eWidth == WIDTH_SEMI_EXPANDED )
63
0
        return css::awt::FontWidth::SEMIEXPANDED;
64
0
    else if( eWidth == WIDTH_EXPANDED )
65
0
        return css::awt::FontWidth::EXPANDED;
66
0
    else if( eWidth == WIDTH_EXTRA_EXPANDED )
67
0
        return css::awt::FontWidth::EXTRAEXPANDED;
68
0
    else if( eWidth == WIDTH_ULTRA_EXPANDED )
69
0
        return css::awt::FontWidth::ULTRAEXPANDED;
70
71
0
    OSL_FAIL( "Unknown FontWidth" );
72
0
    return css::awt::FontWidth::DONTKNOW;
73
0
}
74
75
FontWidth vcl::unohelper::ConvertFontWidth( float f )
76
11.5k
{
77
11.5k
    if( f <= css::awt::FontWidth::DONTKNOW )
78
0
        return WIDTH_DONTKNOW;
79
11.5k
    else if( f <= css::awt::FontWidth::ULTRACONDENSED )
80
0
        return WIDTH_ULTRA_CONDENSED;
81
11.5k
    else if( f <= css::awt::FontWidth::EXTRACONDENSED )
82
0
        return WIDTH_EXTRA_CONDENSED;
83
11.5k
    else if( f <= css::awt::FontWidth::CONDENSED )
84
0
        return WIDTH_CONDENSED;
85
11.5k
    else if( f <= css::awt::FontWidth::SEMICONDENSED )
86
0
        return WIDTH_SEMI_CONDENSED;
87
11.5k
    else if( f <= css::awt::FontWidth::NORMAL )
88
11.5k
        return WIDTH_NORMAL;
89
0
    else if( f <= css::awt::FontWidth::SEMIEXPANDED )
90
0
        return WIDTH_SEMI_EXPANDED;
91
0
    else if( f <= css::awt::FontWidth::EXPANDED )
92
0
        return WIDTH_EXPANDED;
93
0
    else if( f <= css::awt::FontWidth::EXTRAEXPANDED )
94
0
        return WIDTH_EXTRA_EXPANDED;
95
0
    else if( f <= css::awt::FontWidth::ULTRAEXPANDED )
96
0
        return WIDTH_ULTRA_EXPANDED;
97
98
0
    OSL_FAIL( "Unknown FontWidth" );
99
0
    return WIDTH_DONTKNOW;
100
11.5k
}
101
102
float vcl::unohelper::ConvertFontWeight( FontWeight eWeight )
103
798k
{
104
798k
    if( eWeight == WEIGHT_DONTKNOW )
105
3.99k
        return css::awt::FontWeight::DONTKNOW;
106
794k
    else if( eWeight == WEIGHT_THIN )
107
0
        return css::awt::FontWeight::THIN;
108
794k
    else if( eWeight == WEIGHT_ULTRALIGHT )
109
0
        return css::awt::FontWeight::ULTRALIGHT;
110
794k
    else if( eWeight == WEIGHT_LIGHT )
111
0
        return css::awt::FontWeight::LIGHT;
112
794k
    else if( eWeight == WEIGHT_SEMILIGHT )
113
0
        return css::awt::FontWeight::SEMILIGHT;
114
794k
    else if( eWeight == WEIGHT_NORMAL )
115
793k
        return css::awt::FontWeight::NORMAL;
116
489
    else if( eWeight == WEIGHT_MEDIUM )
117
0
        return css::awt::FontWeight::MEDIUM;
118
489
    else if( eWeight == WEIGHT_SEMIBOLD )
119
0
        return css::awt::FontWeight::SEMIBOLD;
120
489
    else if( eWeight == WEIGHT_BOLD )
121
489
        return css::awt::FontWeight::BOLD;
122
0
    else if( eWeight == WEIGHT_ULTRABOLD )
123
0
        return css::awt::FontWeight::ULTRABOLD;
124
0
    else if( eWeight == WEIGHT_BLACK )
125
0
        return css::awt::FontWeight::BLACK;
126
127
0
    OSL_FAIL( "Unknown FontWeight" );
128
0
    return css::awt::FontWeight::DONTKNOW;
129
798k
}
130
131
FontWeight vcl::unohelper::ConvertFontWeight( float f )
132
2.01M
{
133
2.01M
    if( f <= css::awt::FontWeight::DONTKNOW )
134
145k
        return WEIGHT_DONTKNOW;
135
1.87M
    else if( f <= css::awt::FontWeight::THIN )
136
3.55k
        return WEIGHT_THIN;
137
1.87M
    else if( f <= css::awt::FontWeight::ULTRALIGHT )
138
261
        return WEIGHT_ULTRALIGHT;
139
1.87M
    else if( f <= css::awt::FontWeight::LIGHT )
140
10
        return WEIGHT_LIGHT;
141
1.87M
    else if( f <= css::awt::FontWeight::SEMILIGHT )
142
0
        return WEIGHT_SEMILIGHT;
143
1.87M
    else if( f <= css::awt::FontWeight::NORMAL )
144
1.69M
        return WEIGHT_NORMAL;
145
172k
    else if( f <= css::awt::FontWeight::MEDIUM )
146
12
        return WEIGHT_MEDIUM;
147
172k
    else if( f <= css::awt::FontWeight::SEMIBOLD )
148
2
        return WEIGHT_SEMIBOLD;
149
172k
    else if( f <= css::awt::FontWeight::BOLD )
150
169k
        return WEIGHT_BOLD;
151
3.51k
    else if( f <= css::awt::FontWeight::ULTRABOLD )
152
0
        return WEIGHT_ULTRABOLD;
153
3.51k
    else if( f <= css::awt::FontWeight::BLACK )
154
3.51k
        return WEIGHT_BLACK;
155
156
0
    OSL_FAIL( "Unknown FontWeight" );
157
0
    return WEIGHT_DONTKNOW;
158
2.01M
}
159
160
css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
161
810k
{
162
810k
    css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
163
810k
    switch (eItalic)
164
810k
    {
165
799k
        case ITALIC_NONE:
166
799k
            eRet = css::awt::FontSlant_NONE;
167
799k
            break;
168
171
        case ITALIC_OBLIQUE:
169
171
            eRet = css::awt::FontSlant_OBLIQUE;
170
171
            break;
171
11.5k
        case ITALIC_NORMAL:
172
11.5k
            eRet = css::awt::FontSlant_ITALIC;
173
11.5k
            break;
174
0
        case ITALIC_DONTKNOW:
175
0
            eRet = css::awt::FontSlant_DONTKNOW;
176
0
            break;
177
0
        case FontItalic_FORCE_EQUAL_SIZE:
178
0
            eRet = css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE;
179
0
            break;
180
810k
    }
181
810k
    return eRet;
182
810k
}
183
184
FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
185
1.48M
{
186
1.48M
    FontItalic eRet = ITALIC_DONTKNOW;
187
1.48M
    switch (eSlant)
188
1.48M
    {
189
1.44M
        case css::awt::FontSlant_NONE:
190
1.44M
            eRet = ITALIC_NONE;
191
1.44M
            break;
192
6
        case css::awt::FontSlant_OBLIQUE:
193
6
            eRet = ITALIC_OBLIQUE;
194
6
            break;
195
32.1k
        case css::awt::FontSlant_ITALIC:
196
32.1k
            eRet = ITALIC_NORMAL;
197
32.1k
            break;
198
0
        case css::awt::FontSlant_DONTKNOW:
199
0
            eRet = ITALIC_DONTKNOW;
200
0
            break;
201
0
        case css::awt::FontSlant_REVERSE_OBLIQUE:
202
            //there is no vcl reverse oblique
203
0
            eRet = ITALIC_OBLIQUE;
204
0
            break;
205
0
        case css::awt::FontSlant_REVERSE_ITALIC:
206
            //there is no vcl reverse normal
207
0
            eRet = ITALIC_NORMAL;
208
0
            break;
209
0
        case css::awt::FontSlant::FontSlant_MAKE_FIXED_SIZE:
210
0
            eRet = FontItalic_FORCE_EQUAL_SIZE;
211
0
            break;
212
1.48M
    }
213
1.48M
    return eRet;
214
1.48M
}
215
216
Size vcl::unohelper::ConvertToVCLSize(const css::awt::Size& rAWTSize)
217
0
{
218
0
    return Size(rAWTSize.Width, rAWTSize.Height);
219
0
}
220
221
css::awt::Size vcl::unohelper::ConvertToAWTSize(const Size& rVCLSize)
222
0
{
223
0
    return css::awt::Size(rVCLSize.Width(), rVCLSize.Height());
224
0
}
225
226
Point vcl::unohelper::ConvertToVCLPoint(const css::awt::Point& rAWTPoint)
227
98
{
228
98
    return Point(rAWTPoint.X, rAWTPoint.Y);
229
98
}
230
231
css::awt::Point vcl::unohelper::ConvertToAWTPoint(const PointTemplateBase& rVCLPoint)
232
0
{
233
0
    return css::awt::Point(rVCLPoint.X(), rVCLPoint.Y());
234
0
}
235
236
tools::Rectangle vcl::unohelper::ConvertToVCLRect(const css::awt::Rectangle& rAWTRect)
237
0
{
238
0
    return ::tools::Rectangle(Point(rAWTRect.X, rAWTRect.Y),
239
0
                              Size(rAWTRect.Width, rAWTRect.Height));
240
0
}
241
242
css::awt::Rectangle vcl::unohelper::ConvertToAWTRect(const RectangleTemplateBase& rVCLRect)
243
0
{
244
0
    return css::awt::Rectangle(rVCLRect.Left(), rVCLRect.Top(), rVCLRect.GetWidth(),
245
0
                               rVCLRect.GetHeight());
246
0
}
247
248
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */