Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/components/fontident.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 <vcl/svapp.hxx>
21
#include <vcl/font.hxx>
22
23
#include <svdata.hxx>
24
25
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26
#include <com/sun/star/lang/XServiceInfo.hpp>
27
#include <com/sun/star/beans/XMaterialHolder.hpp>
28
#include <com/sun/star/awt/FontDescriptor.hpp>
29
#include <com/sun/star/awt/FontFamily.hpp>
30
#include <com/sun/star/awt/FontPitch.hpp>
31
#include <com/sun/star/awt/FontWeight.hpp>
32
#include <com/sun/star/awt/FontSlant.hpp>
33
#include <com/sun/star/lang/XInitialization.hpp>
34
35
#include <cppuhelper/implbase.hxx>
36
#include <cppuhelper/supportsservice.hxx>
37
38
namespace vcl
39
{
40
41
namespace {
42
43
class FontIdentificator : public ::cppu::WeakImplHelper<css::beans::XMaterialHolder, css::lang::XInitialization, css::lang::XServiceInfo>
44
{
45
    Font        m_aFont;
46
public:
47
0
    FontIdentificator() {}
48
49
    // XServiceInfo
50
    virtual OUString SAL_CALL getImplementationName(  ) override;
51
    virtual sal_Bool SAL_CALL supportsService( const OUString& ) override;
52
    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
53
54
    // XInitialization
55
    virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>&) override;
56
57
    // XMaterialHolder
58
    virtual css::uno::Any SAL_CALL getMaterial() override;
59
60
};
61
62
}
63
64
void SAL_CALL FontIdentificator::initialize(const css::uno::Sequence<css::uno::Any>& i_rArgs)
65
0
{
66
0
    if( !ImplGetSVData() )
67
0
        return; // VCL not initialized
68
69
0
    css::uno::Sequence<sal_Int8> aFontBuf;
70
0
    for( const auto& rArg : i_rArgs )
71
0
    {
72
0
        if( rArg >>= aFontBuf )
73
0
        {
74
0
            m_aFont = Font::identifyFont( aFontBuf.getConstArray(), aFontBuf.getLength() );
75
0
            break;
76
0
        }
77
0
    }
78
0
}
79
80
css::uno::Any SAL_CALL FontIdentificator::getMaterial()
81
0
{
82
0
    if( !ImplGetSVData() )
83
0
        return css::uno::Any(); // VCL not initialized
84
85
0
    css::awt::FontDescriptor aFD;
86
0
    aFD.Name                = m_aFont.GetFamilyName();
87
0
    aFD.Height              = 0;
88
0
    aFD.Width               = 0;
89
0
    aFD.StyleName           = m_aFont.GetStyleName();
90
0
    aFD.CharSet             = 0;
91
0
    aFD.CharacterWidth      = 0;
92
0
    aFD.Underline           = 0;
93
0
    aFD.Strikeout           = 0;
94
0
    aFD.Orientation         = 0;
95
0
    aFD.Kerning             = false;
96
0
    aFD.WordLineMode        = false;
97
0
    aFD.Type                = 0;
98
0
    switch( m_aFont.GetFamilyTypeMaybeAskConfig() )
99
0
    {
100
0
    case FAMILY_DECORATIVE: aFD.Family = css::awt::FontFamily::DECORATIVE;break;
101
0
    case FAMILY_MODERN: aFD.Family = css::awt::FontFamily::MODERN;break;
102
0
    case FAMILY_ROMAN: aFD.Family = css::awt::FontFamily::ROMAN;break;
103
0
    case FAMILY_SCRIPT: aFD.Family = css::awt::FontFamily::SCRIPT;break;
104
0
    case FAMILY_SWISS: aFD.Family = css::awt::FontFamily::SWISS;break;
105
0
    case FAMILY_SYSTEM: aFD.Family = css::awt::FontFamily::SYSTEM;break;
106
0
    default:
107
0
        aFD.Family = css::awt::FontFamily::DONTKNOW;
108
0
        break;
109
0
    }
110
0
    switch( m_aFont.GetPitchMaybeAskConfig() )
111
0
    {
112
0
    case PITCH_VARIABLE: aFD.Pitch = css::awt::FontPitch::VARIABLE;break;
113
0
    case PITCH_FIXED: aFD.Pitch = css::awt::FontPitch::FIXED;break;
114
0
    default:
115
0
        aFD.Pitch = css::awt::FontPitch::DONTKNOW;
116
0
        break;
117
0
    }
118
0
    switch( m_aFont.GetWeightMaybeAskConfig() )
119
0
    {
120
0
    case WEIGHT_THIN: aFD.Weight = css::awt::FontWeight::THIN;break;
121
0
    case WEIGHT_ULTRALIGHT: aFD.Weight = css::awt::FontWeight::ULTRALIGHT;break;
122
0
    case WEIGHT_LIGHT: aFD.Weight = css::awt::FontWeight::LIGHT;break;
123
0
    case WEIGHT_SEMILIGHT: aFD.Weight = css::awt::FontWeight::SEMILIGHT;break;
124
0
    case WEIGHT_MEDIUM: aFD.Weight = css::awt::FontWeight::MEDIUM;break;
125
0
    case WEIGHT_NORMAL: aFD.Weight = css::awt::FontWeight::NORMAL;break;
126
0
    case WEIGHT_SEMIBOLD: aFD.Weight = css::awt::FontWeight::SEMIBOLD;break;
127
0
    case WEIGHT_BOLD: aFD.Weight = css::awt::FontWeight::BOLD;break;
128
0
    case WEIGHT_ULTRABOLD: aFD.Weight = css::awt::FontWeight::ULTRABOLD;break;
129
0
    case WEIGHT_BLACK: aFD.Weight = css::awt::FontWeight::BLACK;break;
130
0
    default:
131
0
        aFD.Weight = css::awt::FontWeight::DONTKNOW;
132
0
        break;
133
0
    }
134
0
    switch( m_aFont.GetItalicMaybeAskConfig() )
135
0
    {
136
0
    case ITALIC_OBLIQUE: aFD.Slant = css::awt::FontSlant_OBLIQUE;break;
137
0
    case ITALIC_NORMAL: aFD.Slant = css::awt::FontSlant_ITALIC;break;
138
0
    default:
139
0
        aFD.Slant = css::awt::FontSlant_DONTKNOW;
140
0
        break;
141
0
    }
142
0
    return css::uno::Any( aFD );
143
0
}
144
145
// XServiceInfo
146
OUString SAL_CALL FontIdentificator::getImplementationName()
147
0
{
148
0
    return u"vcl::FontIdentificator"_ustr;
149
0
}
150
151
sal_Bool SAL_CALL FontIdentificator::supportsService( const OUString& i_rServiceName )
152
0
{
153
0
    return cppu::supportsService(this, i_rServiceName);
154
0
}
155
156
css::uno::Sequence<OUString> SAL_CALL FontIdentificator::getSupportedServiceNames()
157
0
{
158
0
    return { u"com.sun.star.awt.FontIdentificator"_ustr };
159
0
}
160
161
} // namespace vcl
162
163
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
164
vcl_FontIdentificator_get_implementation(
165
    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
166
0
{
167
0
    return cppu::acquire(new vcl::FontIdentificator());
168
0
}
169
170
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */