Coverage Report

Created: 2026-02-14 09:37

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
307k
{
39
307k
    const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
40
307k
    return i18n::BreakIterator::create(xContext);
41
307k
}
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.3k
{
77
11.3k
    if( f <= css::awt::FontWidth::DONTKNOW )
78
0
        return WIDTH_DONTKNOW;
79
11.3k
    else if( f <= css::awt::FontWidth::ULTRACONDENSED )
80
0
        return WIDTH_ULTRA_CONDENSED;
81
11.3k
    else if( f <= css::awt::FontWidth::EXTRACONDENSED )
82
0
        return WIDTH_EXTRA_CONDENSED;
83
11.3k
    else if( f <= css::awt::FontWidth::CONDENSED )
84
0
        return WIDTH_CONDENSED;
85
11.3k
    else if( f <= css::awt::FontWidth::SEMICONDENSED )
86
0
        return WIDTH_SEMI_CONDENSED;
87
11.3k
    else if( f <= css::awt::FontWidth::NORMAL )
88
11.3k
        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.3k
}
101
102
float vcl::unohelper::ConvertFontWeight( FontWeight eWeight )
103
719k
{
104
719k
    if( eWeight == WEIGHT_DONTKNOW )
105
1.64k
        return css::awt::FontWeight::DONTKNOW;
106
717k
    else if( eWeight == WEIGHT_THIN )
107
0
        return css::awt::FontWeight::THIN;
108
717k
    else if( eWeight == WEIGHT_ULTRALIGHT )
109
0
        return css::awt::FontWeight::ULTRALIGHT;
110
717k
    else if( eWeight == WEIGHT_LIGHT )
111
0
        return css::awt::FontWeight::LIGHT;
112
717k
    else if( eWeight == WEIGHT_SEMILIGHT )
113
0
        return css::awt::FontWeight::SEMILIGHT;
114
717k
    else if( eWeight == WEIGHT_NORMAL )
115
717k
        return css::awt::FontWeight::NORMAL;
116
435
    else if( eWeight == WEIGHT_MEDIUM )
117
0
        return css::awt::FontWeight::MEDIUM;
118
435
    else if( eWeight == WEIGHT_SEMIBOLD )
119
0
        return css::awt::FontWeight::SEMIBOLD;
120
435
    else if( eWeight == WEIGHT_BOLD )
121
435
        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
719k
}
130
131
FontWeight vcl::unohelper::ConvertFontWeight( float f )
132
2.88M
{
133
2.88M
    if( f <= css::awt::FontWeight::DONTKNOW )
134
108k
        return WEIGHT_DONTKNOW;
135
2.77M
    else if( f <= css::awt::FontWeight::THIN )
136
4.21k
        return WEIGHT_THIN;
137
2.77M
    else if( f <= css::awt::FontWeight::ULTRALIGHT )
138
341
        return WEIGHT_ULTRALIGHT;
139
2.77M
    else if( f <= css::awt::FontWeight::LIGHT )
140
18
        return WEIGHT_LIGHT;
141
2.77M
    else if( f <= css::awt::FontWeight::SEMILIGHT )
142
0
        return WEIGHT_SEMILIGHT;
143
2.77M
    else if( f <= css::awt::FontWeight::NORMAL )
144
1.72M
        return WEIGHT_NORMAL;
145
1.04M
    else if( f <= css::awt::FontWeight::MEDIUM )
146
8
        return WEIGHT_MEDIUM;
147
1.04M
    else if( f <= css::awt::FontWeight::SEMIBOLD )
148
3
        return WEIGHT_SEMIBOLD;
149
1.04M
    else if( f <= css::awt::FontWeight::BOLD )
150
1.03M
        return WEIGHT_BOLD;
151
4.05k
    else if( f <= css::awt::FontWeight::ULTRABOLD )
152
0
        return WEIGHT_ULTRABOLD;
153
4.05k
    else if( f <= css::awt::FontWeight::BLACK )
154
4.05k
        return WEIGHT_BLACK;
155
156
0
    OSL_FAIL( "Unknown FontWeight" );
157
0
    return WEIGHT_DONTKNOW;
158
2.88M
}
159
160
css::awt::FontSlant vcl::unohelper::ConvertFontSlant(FontItalic eItalic)
161
732k
{
162
732k
    css::awt::FontSlant eRet(css::awt::FontSlant_DONTKNOW);
163
732k
    switch (eItalic)
164
732k
    {
165
721k
        case ITALIC_NONE:
166
721k
            eRet = css::awt::FontSlant_NONE;
167
721k
            break;
168
0
        case ITALIC_OBLIQUE:
169
0
            eRet = css::awt::FontSlant_OBLIQUE;
170
0
            break;
171
10.9k
        case ITALIC_NORMAL:
172
10.9k
            eRet = css::awt::FontSlant_ITALIC;
173
10.9k
            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
732k
    }
181
732k
    return eRet;
182
732k
}
183
184
FontItalic vcl::unohelper::ConvertFontSlant(css::awt::FontSlant eSlant)
185
1.29M
{
186
1.29M
    FontItalic eRet = ITALIC_DONTKNOW;
187
1.29M
    switch (eSlant)
188
1.29M
    {
189
1.25M
        case css::awt::FontSlant_NONE:
190
1.25M
            eRet = ITALIC_NONE;
191
1.25M
            break;
192
0
        case css::awt::FontSlant_OBLIQUE:
193
0
            eRet = ITALIC_OBLIQUE;
194
0
            break;
195
36.5k
        case css::awt::FontSlant_ITALIC:
196
36.5k
            eRet = ITALIC_NORMAL;
197
36.5k
            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.29M
    }
213
1.29M
    return eRet;
214
1.29M
}
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
94
{
228
94
    return Point(rAWTPoint.X, rAWTPoint.Y);
229
94
}
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: */