1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 OOX_HELPER_GRAPHICHELPER_HXX
21 #define OOX_HELPER_GRAPHICHELPER_HXX
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/awt/DeviceInfo.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include "oox/helper/binarystreambase.hxx"
29 #include "oox/helper/storagebase.hxx"
31 struct WMF_EXTERNALHEADER
;
33 namespace com
{ namespace sun
{ namespace star
{
34 namespace awt
{ struct Point
; }
35 namespace awt
{ struct Size
; }
36 namespace awt
{ class XUnitConversion
; }
37 namespace io
{ class XInputStream
; }
38 namespace frame
{ class XFrame
; }
39 namespace graphic
{ class XGraphic
; }
40 namespace graphic
{ class XGraphicObject
; }
41 namespace graphic
{ class XGraphicProvider
; }
42 namespace uno
{ class XComponentContext
; }
47 // ============================================================================
49 /** Provides helper functions for colors, device measurement conversion,
50 graphics, and graphic objects handling.
52 All createGraphicObject() and importGraphicObject() functions create
53 persistent graphic objects internally and store them in an internal
54 container to prevent their early destruction. This makes it possible to use
55 the returned URL of the graphic object in any way (e.g. insert it into a
56 property map) without needing to store it immediately at an object that
57 resolves the graphic object from the passed URL and thus prevents it from
60 class OOX_DLLPUBLIC GraphicHelper
63 explicit GraphicHelper(
64 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
65 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rxTargetFrame
,
66 const StorageRef
& rxStorage
);
67 virtual ~GraphicHelper();
69 // System colors and predefined colors ------------------------------------
71 /** Returns a system color specified by the passed XML token identifier. */
72 sal_Int32
getSystemColor( sal_Int32 nToken
, sal_Int32 nDefaultRgb
= API_RGB_TRANSPARENT
) const;
73 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
74 virtual sal_Int32
getSchemeColor( sal_Int32 nToken
) const;
75 /** Derived classes may implement to resolve a palette index to an RGB color. */
76 virtual sal_Int32
getPaletteColor( sal_Int32 nPaletteIdx
) const;
78 // Device info and device dependent unit conversion -----------------------
80 /** Returns information about the output device. */
81 const ::com::sun::star::awt::DeviceInfo
& getDeviceInfo() const;
83 /** Converts the passed value from horizontal screen pixels to 1/100 mm. */
84 sal_Int32
convertScreenPixelXToHmm( double fPixelX
) const;
85 /** Converts the passed value from vertical screen pixels to 1/100 mm. */
86 sal_Int32
convertScreenPixelYToHmm( double fPixelY
) const;
87 /** Converts the passed size from screen pixels to 1/100 mm. */
88 ::com::sun::star::awt::Size
convertScreenPixelToHmm( const ::com::sun::star::awt::Size
& rPixel
) const;
90 /** Converts the passed value from 1/100 mm to horizontal screen pixels. */
91 double convertHmmToScreenPixelX( sal_Int32 nHmmX
) const;
92 /** Converts the passed value from 1/100 mm to vertical screen pixels. */
93 double convertHmmToScreenPixelY( sal_Int32 nHmmY
) const;
94 /** Converts the passed point from 1/100 mm to screen pixels. */
95 ::com::sun::star::awt::Point
convertHmmToScreenPixel( const ::com::sun::star::awt::Point
& rHmm
) const;
96 /** Converts the passed size from 1/100 mm to screen pixels. */
97 ::com::sun::star::awt::Size
convertHmmToScreenPixel( const ::com::sun::star::awt::Size
& rHmm
) const;
99 /** Converts the passed point from 1/100 mm to AppFont units. */
100 ::com::sun::star::awt::Point
convertHmmToAppFont( const ::com::sun::star::awt::Point
& rHmm
) const;
101 /** Converts the passed size from 1/100 mm to AppFont units. */
102 ::com::sun::star::awt::Size
convertHmmToAppFont( const ::com::sun::star::awt::Size
& rHmm
) const;
104 // Graphics and graphic objects ------------------------------------------
106 /** Imports a graphic from the passed input stream. */
107 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& rxInStrm
,
110 const WMF_EXTERNALHEADER
* pExtHeader
= NULL
) const;
112 /** Imports a graphic from the passed binary memory block. */
113 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>
114 importGraphic( const StreamDataSequence
& rGraphicData
) const;
116 /** Imports a graphic from the storage stream with the passed path and name. */
117 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>
118 importEmbeddedGraphic( const OUString
& rStreamName
) const;
120 /** Creates a persistent graphic object from the passed graphic.
121 @return The URL of the created and internally cached graphic object. */
122 OUString
createGraphicObject(
123 const ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>& rxGraphic
) const;
125 /** Creates a persistent graphic object from the passed input stream.
126 @return The URL of the created and internally cached graphic object. */
127 OUString
importGraphicObject(
128 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& rxInStrm
,
129 const WMF_EXTERNALHEADER
* pExtHeader
= NULL
) const;
131 /** Creates a persistent graphic object from the passed binary memory block.
132 @return The URL of the created and internally cached graphic object. */
133 OUString
importGraphicObject( const StreamDataSequence
& rGraphicData
) const;
135 /** Imports a graphic object from the storage stream with the passed path and name.
136 @return The URL of the created and internally cached graphic object. */
137 OUString
importEmbeddedGraphicObject( const OUString
& rStreamName
) const;
139 /** calculates the orignal size of a graphic which is necessary to be able to calculate cropping values
140 @return The original Graphic size in 100thmm */
141 ::com::sun::star::awt::Size
getOriginalSize( const ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
>& rxGraphic
) const;
143 // ------------------------------------------------------------------------
145 typedef ::std::map
< sal_Int32
, sal_Int32
> SystemPalette
;
146 typedef ::std::deque
< ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphicObject
> > GraphicObjectDeque
;
147 typedef ::std::map
< OUString
, ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphic
> > EmbeddedGraphicMap
;
149 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> mxContext
;
150 ::com::sun::star::uno::Reference
< ::com::sun::star::graphic::XGraphicProvider
> mxGraphicProvider
;
151 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XUnitConversion
> mxUnitConversion
;
152 ::com::sun::star::awt::DeviceInfo maDeviceInfo
; ///< Current output device info.
153 SystemPalette maSystemPalette
; ///< Maps system colors (XML tokens) to RGB color values.
154 StorageRef mxStorage
; ///< Storage containing embedded graphics.
155 mutable GraphicObjectDeque maGraphicObjects
; ///< Caches all created graphic objects to keep them alive.
156 mutable EmbeddedGraphicMap maEmbeddedGraphics
; ///< Maps all embedded graphics by their storage path.
157 const OUString maGraphicObjScheme
; ///< The URL scheme name for graphic objects.
158 double mfPixelPerHmmX
; ///< Number of screen pixels per 1/100 mm in X direction.
159 double mfPixelPerHmmY
; ///< Number of screen pixels per 1/100 mm in Y direction.
162 // ============================================================================
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */