Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/canvas/source/vcl/canvasfont.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 <sal/config.h>
21
22
#include <basegfx/numeric/ftools.hxx>
23
#include <canvas/canvastools.hxx>
24
#include <com/sun/star/rendering/PanoseProportion.hpp>
25
#include <cppuhelper/supportsservice.hxx>
26
#include <i18nlangtag/languagetag.hxx>
27
#include <rtl/math.hxx>
28
#include <vcl/metric.hxx>
29
#include <vcl/virdev.hxx>
30
31
#include "canvasfont.hxx"
32
#include "textlayout.hxx"
33
34
using namespace ::com::sun::star;
35
36
37
namespace vclcanvas
38
{
39
    CanvasFont::CanvasFont( const rendering::FontRequest&                   rFontRequest,
40
                            const uno::Sequence< beans::PropertyValue >&    rExtraFontProperties,
41
                            const geometry::Matrix2D&                       rFontMatrix,
42
                            rendering::XGraphicDevice&                      rDevice,
43
                            const OutDevProviderSharedPtr&                  rOutDevProvider ) :
44
0
        maFont( vcl::Font( rFontRequest.FontDescription.FamilyName,
45
0
                      rFontRequest.FontDescription.StyleName,
46
0
                      Size( 0, ::basegfx::fround<::tools::Long>(rFontRequest.CellSize) ) ) ),
47
0
        maFontRequest( rFontRequest ),
48
0
        mpRefDevice( &rDevice ),
49
0
        mpOutDevProvider( rOutDevProvider ),
50
0
        maFontMatrix( rFontMatrix )
51
0
    {
52
0
        maFont->SetAlignment( ALIGN_BASELINE );
53
0
        maFont->SetCharSet( (rFontRequest.FontDescription.IsSymbolFont==css::util::TriState_YES) ? RTL_TEXTENCODING_SYMBOL : RTL_TEXTENCODING_UNICODE );
54
0
        maFont->SetVertical( rFontRequest.FontDescription.IsVertical==css::util::TriState_YES );
55
56
        // TODO(F2): improve panose->vclenum conversion
57
0
        maFont->SetWeight( static_cast<FontWeight>(rFontRequest.FontDescription.FontDescription.Weight) );
58
0
        maFont->SetItalic( (rFontRequest.FontDescription.FontDescription.Letterform<=8) ? ITALIC_NONE : ITALIC_NORMAL );
59
0
        maFont->SetPitch(
60
0
                rFontRequest.FontDescription.FontDescription.Proportion == rendering::PanoseProportion::MONO_SPACED
61
0
                    ? PITCH_FIXED : PITCH_VARIABLE);
62
63
0
        maFont->SetLanguage( LanguageTag::convertToLanguageType( rFontRequest.Locale, false));
64
65
        // adjust to stretched/shrunk font
66
0
        vclcanvastools::setupFontWidth(rFontMatrix, maFont.get(), rOutDevProvider->getOutDev());
67
68
0
        sal_uInt32 nEmphasisMark = 0;
69
70
0
        ::canvastools::extractExtraFontProperties(rExtraFontProperties, nEmphasisMark);
71
72
0
        if (nEmphasisMark)
73
0
            maFont->SetEmphasisMark(FontEmphasisMark(nEmphasisMark));
74
0
    }
Unexecuted instantiation: vclcanvas::CanvasFont::CanvasFont(com::sun::star::rendering::FontRequest const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&, com::sun::star::geometry::Matrix2D const&, com::sun::star::rendering::XGraphicDevice&, std::__1::shared_ptr<vclcanvas::OutDevProvider> const&)
Unexecuted instantiation: vclcanvas::CanvasFont::CanvasFont(com::sun::star::rendering::FontRequest const&, com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> const&, com::sun::star::geometry::Matrix2D const&, com::sun::star::rendering::XGraphicDevice&, std::__1::shared_ptr<vclcanvas::OutDevProvider> const&)
75
76
    void CanvasFont::disposing(std::unique_lock<std::mutex>& rGuard)
77
0
    {
78
0
        rGuard.unlock();
79
0
        {
80
0
            SolarMutexGuard aGuard;
81
82
0
            mpOutDevProvider.reset();
83
0
            mpRefDevice.clear();
84
0
        }
85
0
        rGuard.lock();
86
0
    }
87
88
    uno::Reference< rendering::XTextLayout > SAL_CALL  CanvasFont::createTextLayout( const rendering::StringContext& aText, sal_Int8 nDirection, sal_Int64 )
89
0
    {
90
0
        SolarMutexGuard aGuard;
91
92
0
        if( !mpRefDevice.is() )
93
0
            return uno::Reference< rendering::XTextLayout >(); // we're disposed
94
95
0
        return new TextLayout( aText,
96
0
                               nDirection,
97
0
                               Reference( this ),
98
0
                               mpRefDevice,
99
0
                               mpOutDevProvider);
100
0
    }
101
102
    rendering::FontRequest SAL_CALL  CanvasFont::getFontRequest(  )
103
0
    {
104
0
        return maFontRequest;
105
0
    }
106
107
    rendering::FontMetrics SAL_CALL  CanvasFont::getFontMetrics(  )
108
0
    {
109
0
        SolarMutexGuard aGuard;
110
111
0
        OutputDevice& rOutDev = mpOutDevProvider->getOutDev();
112
0
        ScopedVclPtrInstance< VirtualDevice > pVDev( rOutDev );
113
0
        pVDev->SetFont(getVCLFont());
114
0
        const ::FontMetric aMetric( pVDev->GetFontMetric() );
115
116
0
        return rendering::FontMetrics(
117
0
            aMetric.GetAscent(),
118
0
            aMetric.GetDescent(),
119
0
            aMetric.GetInternalLeading(),
120
0
            aMetric.GetExternalLeading(),
121
0
            0,
122
0
            aMetric.GetDescent() / 2.0,
123
0
            aMetric.GetAscent() / 2.0);
124
0
    }
125
126
    uno::Sequence< double > SAL_CALL  CanvasFont::getAvailableSizes(  )
127
0
    {
128
        // TODO(F1)
129
0
        return uno::Sequence< double >();
130
0
    }
131
132
    uno::Sequence< beans::PropertyValue > SAL_CALL  CanvasFont::getExtraFontProperties(  )
133
0
    {
134
        // TODO(F1)
135
0
        return uno::Sequence< beans::PropertyValue >();
136
0
    }
137
138
    OUString SAL_CALL CanvasFont::getImplementationName()
139
0
    {
140
0
        return u"VCLCanvas::CanvasFont"_ustr;
141
0
    }
142
143
    sal_Bool SAL_CALL CanvasFont::supportsService( const OUString& ServiceName )
144
0
    {
145
0
        return cppu::supportsService( this, ServiceName );
146
0
    }
147
148
    uno::Sequence< OUString > SAL_CALL CanvasFont::getSupportedServiceNames()
149
0
    {
150
0
        return { u"com.sun.star.rendering.CanvasFont"_ustr };
151
0
    }
152
153
    vcl::Font const & CanvasFont::getVCLFont() const
154
0
    {
155
0
        return *maFont;
156
0
    }
157
158
    const css::geometry::Matrix2D& CanvasFont::getFontMatrix() const
159
0
    {
160
0
        return maFontMatrix;
161
0
    }
162
}
163
164
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */