Coverage Report

Created: 2025-12-08 09:28

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