Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / oox / helper / graphichelper.hxx
blob41a1ed76aac11eb6382efa03724be549ad91d410
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_HELPER_GRAPHICHELPER_HXX
21 #define INCLUDED_OOX_HELPER_GRAPHICHELPER_HXX
23 #include <deque>
24 #include <map>
26 #include <com/sun/star/awt/DeviceInfo.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <oox/dllapi.h>
29 #include <oox/helper/binarystreambase.hxx>
30 #include <oox/helper/helper.hxx>
31 #include <oox/helper/storagebase.hxx>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
35 struct WMF_EXTERNALHEADER;
37 namespace com { namespace sun { namespace star {
38 namespace awt { struct Point; }
39 namespace awt { struct Size; }
40 namespace awt { class XUnitConversion; }
41 namespace io { class XInputStream; }
42 namespace frame { class XFrame; }
43 namespace graphic { class XGraphic; }
44 namespace graphic { class XGraphicObject; }
45 namespace graphic { class XGraphicProvider; }
46 namespace uno { class XComponentContext; }
47 } } }
49 namespace oox {
52 /** Provides helper functions for colors, device measurement conversion,
53 graphics, and graphic objects handling.
55 All createGraphicObject() and importGraphicObject() functions create
56 persistent graphic objects internally and store them in an internal
57 container to prevent their early destruction. This makes it possible to use
58 the returned URL of the graphic object in any way (e.g. insert it into a
59 property map) without needing to store it immediately at an object that
60 resolves the graphic object from the passed URL and thus prevents it from
61 being destroyed.
63 class OOX_DLLPUBLIC GraphicHelper
65 public:
66 explicit GraphicHelper(
67 const css::uno::Reference< css::uno::XComponentContext >& rxContext,
68 const css::uno::Reference< css::frame::XFrame >& rxTargetFrame,
69 const StorageRef& rxStorage );
70 virtual ~GraphicHelper();
72 // System colors and predefined colors ------------------------------------
74 /** Returns a system color specified by the passed XML token identifier. */
75 sal_Int32 getSystemColor( sal_Int32 nToken, sal_Int32 nDefaultRgb = API_RGB_TRANSPARENT ) const;
76 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
77 virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
78 /** Derived classes may implement to resolve a palette index to an RGB color. */
79 virtual sal_Int32 getPaletteColor( sal_Int32 nPaletteIdx ) const;
81 virtual sal_Int32 getDefaultChartAreaFillStyle() const;
83 // Device info and device dependent unit conversion -----------------------
85 /** Returns information about the output device. */
86 const css::awt::DeviceInfo& getDeviceInfo() const { return maDeviceInfo;}
88 /** Converts the passed value from horizontal screen pixels to 1/100 mm. */
89 sal_Int32 convertScreenPixelXToHmm( double fPixelX ) const;
90 /** Converts the passed value from vertical screen pixels to 1/100 mm. */
91 sal_Int32 convertScreenPixelYToHmm( double fPixelY ) const;
92 /** Converts the passed size from screen pixels to 1/100 mm. */
93 css::awt::Size convertScreenPixelToHmm( const css::awt::Size& rPixel ) const;
95 /** Converts the passed value from 1/100 mm to horizontal screen pixels. */
96 double convertHmmToScreenPixelX( sal_Int32 nHmmX ) const;
97 /** Converts the passed value from 1/100 mm to vertical screen pixels. */
98 double convertHmmToScreenPixelY( sal_Int32 nHmmY ) const;
99 /** Converts the passed point from 1/100 mm to screen pixels. */
100 css::awt::Point convertHmmToScreenPixel( const css::awt::Point& rHmm ) const;
101 /** Converts the passed size from 1/100 mm to screen pixels. */
102 css::awt::Size convertHmmToScreenPixel( const css::awt::Size& rHmm ) const;
104 /** Converts the passed point from 1/100 mm to AppFont units. */
105 css::awt::Point convertHmmToAppFont( const css::awt::Point& rHmm ) const;
106 /** Converts the passed size from 1/100 mm to AppFont units. */
107 css::awt::Size convertHmmToAppFont( const css::awt::Size& rHmm ) const;
109 // Graphics and graphic objects ------------------------------------------
111 /** Imports a graphic from the passed input stream. */
112 css::uno::Reference< css::graphic::XGraphic >
113 importGraphic(
114 const css::uno::Reference< css::io::XInputStream >& rxInStrm,
115 const WMF_EXTERNALHEADER* pExtHeader = nullptr ) const;
117 /** Imports a graphic from the passed binary memory block. */
118 css::uno::Reference< css::graphic::XGraphic >
119 importGraphic( const StreamDataSequence& rGraphicData ) const;
121 /** Imports a graphic from the storage stream with the passed path and name. */
122 css::uno::Reference< css::graphic::XGraphic >
123 importEmbeddedGraphic(
124 const OUString& rStreamName,
125 const WMF_EXTERNALHEADER* pExtHeader = nullptr ) const;
127 /** Creates a persistent graphic object from the passed graphic.
128 @return The URL of the created and internally cached graphic object. */
129 OUString createGraphicObject(
130 const css::uno::Reference< css::graphic::XGraphic >& rxGraphic ) const;
132 /** Creates a persistent graphic object from the passed input stream.
133 @return The URL of the created and internally cached graphic object. */
134 OUString importGraphicObject(
135 const css::uno::Reference< css::io::XInputStream >& rxInStrm,
136 const WMF_EXTERNALHEADER* pExtHeader ) const;
138 /** Creates a persistent graphic object from the passed binary memory block.
139 @return The URL of the created and internally cached graphic object. */
140 OUString importGraphicObject( const StreamDataSequence& rGraphicData ) const;
142 /** Imports a graphic object from the storage stream with the passed path and name.
143 @return The URL of the created and internally cached graphic object. */
144 OUString importEmbeddedGraphicObject( const OUString& rStreamName ) const;
146 /** calculates the original size of a graphic which is necessary to be able to calculate cropping values
147 @return The original Graphic size in 100thmm */
148 css::awt::Size getOriginalSize( const css::uno::Reference< css::graphic::XGraphic >& rxGraphic ) const;
151 private:
152 typedef ::std::map< sal_Int32, sal_Int32 > SystemPalette;
153 typedef ::std::deque< css::uno::Reference< css::graphic::XGraphicObject > > GraphicObjectDeque;
154 typedef ::std::map< OUString, css::uno::Reference< css::graphic::XGraphic > > EmbeddedGraphicMap;
156 css::uno::Reference< css::uno::XComponentContext > mxContext;
157 css::uno::Reference< css::graphic::XGraphicProvider > mxGraphicProvider;
158 css::uno::Reference< css::awt::XUnitConversion > mxUnitConversion;
159 css::awt::DeviceInfo maDeviceInfo; ///< Current output device info.
160 SystemPalette maSystemPalette; ///< Maps system colors (XML tokens) to RGB color values.
161 StorageRef mxStorage; ///< Storage containing embedded graphics.
162 mutable GraphicObjectDeque maGraphicObjects; ///< Caches all created graphic objects to keep them alive.
163 mutable EmbeddedGraphicMap maEmbeddedGraphics; ///< Maps all embedded graphics by their storage path.
164 const OUString maGraphicObjScheme; ///< The URL scheme name for graphic objects.
165 double mfPixelPerHmmX; ///< Number of screen pixels per 1/100 mm in X direction.
166 double mfPixelPerHmmY; ///< Number of screen pixels per 1/100 mm in Y direction.
170 } // namespace oox
172 #endif
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */