Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/helper/graphichelper.hxx
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
#ifndef INCLUDED_OOX_HELPER_GRAPHICHELPER_HXX
21
#define INCLUDED_OOX_HELPER_GRAPHICHELPER_HXX
22
23
#include <map>
24
25
#include <com/sun/star/awt/DeviceInfo.hpp>
26
#include <com/sun/star/uno/Reference.hxx>
27
#include <oox/dllapi.h>
28
#include <oox/helper/binarystreambase.hxx>
29
#include <oox/helper/helper.hxx>
30
#include <oox/helper/storagebase.hxx>
31
#include <rtl/ustring.hxx>
32
#include <sal/types.h>
33
#include <com/sun/star/graphic/XGraphicProvider2.hpp>
34
#include <com/sun/star/graphic/XGraphicMapper.hpp>
35
#include <vcl/vclptr.hxx>
36
37
struct WmfExternal;
38
class OutputDevice;
39
class ImpGraphic;
40
41
namespace com::sun::star {
42
    namespace awt { struct Point; }
43
    namespace awt { struct Size; }
44
    namespace io { class XInputStream; }
45
    namespace frame { class XFrame; }
46
    namespace graphic { class XGraphic; }
47
    namespace uno { class XComponentContext; }
48
}
49
50
namespace oox {
51
52
53
/** Provides helper functions for colors, device measurement conversion,
54
    graphics, and graphic objects handling.
55
 */
56
57
typedef std::tuple<std::shared_ptr<ImpGraphic>, sal_Int32, sal_Int32, sal_Int16> ColorChangeKey;
58
typedef std::map<ColorChangeKey, css::uno::Reference<css::graphic::XGraphic>> ColorChangeCache;
59
60
class OOX_DLLPUBLIC GraphicHelper
61
{
62
public:
63
    explicit            GraphicHelper(
64
                            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
65
                            const css::uno::Reference< css::frame::XFrame >& rxTargetFrame,
66
                            StorageRef xStorage );
67
    virtual             ~GraphicHelper();
68
69
    // Avoid implicitly defined copy constructors/assignments for the DLLPUBLIC class (they may
70
    // require forward-declared classes used internally to be defined in places using GraphicHelper)
71
    GraphicHelper(const GraphicHelper&) = delete;
72
    GraphicHelper(GraphicHelper&&) = delete;
73
    GraphicHelper& operator=(const GraphicHelper&) = delete;
74
    GraphicHelper& operator=(GraphicHelper&&) = delete;
75
76
    // System colors and predefined colors ------------------------------------
77
78
    /** Returns a system color specified by the passed XML token identifier. */
79
    ::Color            getSystemColor( sal_Int32 nToken, ::Color nDefaultRgb = API_RGB_TRANSPARENT ) const;
80
    /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
81
    virtual ::Color    getSchemeColor( sal_Int32 nToken ) const;
82
    /** Derived classes may implement to resolve a ColorMap token from the passed XML token identifier. */
83
    virtual void       getSchemeColorToken(sal_Int32& nToken) const;
84
    /** Derived classes may implement to resolve a palette index to an RGB color. */
85
    virtual ::Color    getPaletteColor( sal_Int32 nPaletteIdx ) const;
86
87
    virtual sal_Int32 getDefaultChartAreaFillStyle() const;
88
89
    /** Returns chartspace automatic default border style */
90
    static sal_Int32 getDefaultChartAreaLineStyle();
91
92
    /** Returns chartspace automatic default border width in Emu */
93
    static sal_Int16 getDefaultChartAreaLineWidth();
94
95
    // Device info and device dependent unit conversion -----------------------
96
97
    /** Returns information about the output device. */
98
4.33k
    const css::awt::DeviceInfo& getDeviceInfo() const { return maDeviceInfo;}
99
100
    /** Converts the passed value from horizontal screen pixels to 1/100 mm. */
101
    sal_Int32           convertScreenPixelXToHmm( double fPixelX ) const;
102
    /** Converts the passed value from vertical screen pixels to 1/100 mm. */
103
    sal_Int32           convertScreenPixelYToHmm( double fPixelY ) const;
104
    /** Converts the passed size from screen pixels to 1/100 mm. */
105
    css::awt::Size convertScreenPixelToHmm( const css::awt::Size& rPixel ) const;
106
107
    /** Converts the passed value from 1/100 mm to horizontal screen pixels. */
108
    double              convertHmmToScreenPixelX( sal_Int32 nHmmX ) const;
109
    /** Converts the passed value from 1/100 mm to vertical screen pixels. */
110
    double              convertHmmToScreenPixelY( sal_Int32 nHmmY ) const;
111
    /** Converts the passed point from 1/100 mm to screen pixels. */
112
    css::awt::Point convertHmmToScreenPixel( const css::awt::Point& rHmm ) const;
113
    /** Converts the passed size from 1/100 mm to screen pixels. */
114
    css::awt::Size convertHmmToScreenPixel( const css::awt::Size& rHmm ) const;
115
116
    /** Converts the passed point from 1/100 mm to AppFont units. */
117
    css::awt::Point convertHmmToAppFont( const css::awt::Point& rHmm ) const;
118
    /** Converts the passed size from 1/100 mm to AppFont units. */
119
    css::awt::Size convertHmmToAppFont( const css::awt::Size& rHmm ) const;
120
121
122
    // Graphics and graphic objects  ------------------------------------------
123
124
    /** Imports a graphic from the passed input stream. */
125
    css::uno::Reference< css::graphic::XGraphic >
126
                        importGraphic(
127
                            const css::uno::Reference< css::io::XInputStream >& rxInStrm,
128
                            const WmfExternal* pExtHeader = nullptr,
129
                            const bool bLazyLoad = true ) const;
130
131
    /** Imports a graphic from the passed binary memory block. */
132
    css::uno::Reference< css::graphic::XGraphic >
133
                        importGraphic( const StreamDataSequence& rGraphicData ) const;
134
135
    /** Imports a graphic from the storage stream with the passed path and name. */
136
    css::uno::Reference< css::graphic::XGraphic >
137
                        importEmbeddedGraphic(
138
                            const OUString& rStreamName,
139
                            const WmfExternal* pExtHeader = nullptr ) const;
140
141
    /** calculates the original size of a graphic which is necessary to be able to calculate cropping values
142
        @return The original Graphic size in 100thmm */
143
    css::awt::Size getOriginalSize( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic ) const;
144
145
    void setGraphicMapper(css::uno::Reference<css::graphic::XGraphicMapper> const & rxGraphicMapper);
146
147
    void initializeGraphicMapperIfNeeded() const;
148
149
    css::uno::Reference<css::graphic::XGraphic> getCachedColorChangeGraphic(const ColorChangeKey& rKey) const;
150
    void addGraphicToColorChangeCache(const ColorChangeKey& rKey, const css::uno::Reference<css::graphic::XGraphic>& xGraphic) const;
151
152
private:
153
154
    css::uno::Reference< css::uno::XComponentContext > mxContext;
155
    css::uno::Reference< css::graphic::XGraphicProvider2 > mxGraphicProvider;
156
    VclPtr<OutputDevice> mxDefaultOutputDevice;
157
    css::awt::DeviceInfo maDeviceInfo; ///< Current output device info.
158
    ::std::map< sal_Int32, ::Color >  maSystemPalette;  ///< Maps system colors (XML tokens) to RGB color values.
159
    StorageRef          mxStorage;                  ///< Storage containing embedded graphics.
160
    double              mfPixelPerHmmX;             ///< Number of screen pixels per 1/100 mm in X direction.
161
    double              mfPixelPerHmmY;             ///< Number of screen pixels per 1/100 mm in Y direction.
162
    css::uno::Reference<css::graphic::XGraphicMapper> mxGraphicMapper;
163
    mutable ColorChangeCache maColorChangeCache;
164
};
165
166
167
} // namespace oox
168
169
#endif
170
171
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */