1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #ifndef OOX_HELPER_GRAPHICHELPER_HXX
25*b1cdbd2cSJim Jagielski #define OOX_HELPER_GRAPHICHELPER_HXX
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski #include <deque>
28*b1cdbd2cSJim Jagielski #include <map>
29*b1cdbd2cSJim Jagielski #include <rtl/ustring.hxx>
30*b1cdbd2cSJim Jagielski #include <com/sun/star/awt/DeviceInfo.hpp>
31*b1cdbd2cSJim Jagielski #include <com/sun/star/uno/Reference.hxx>
32*b1cdbd2cSJim Jagielski #include "oox/helper/binarystreambase.hxx"
33*b1cdbd2cSJim Jagielski #include "oox/helper/storagebase.hxx"
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski namespace com { namespace sun { namespace star {
36*b1cdbd2cSJim Jagielski     namespace awt { struct Point; }
37*b1cdbd2cSJim Jagielski     namespace awt { struct Size; }
38*b1cdbd2cSJim Jagielski     namespace awt { class XUnitConversion; }
39*b1cdbd2cSJim Jagielski     namespace io { class XInputStream; }
40*b1cdbd2cSJim Jagielski     namespace frame { class XFrame; }
41*b1cdbd2cSJim Jagielski     namespace graphic { class XGraphic; }
42*b1cdbd2cSJim Jagielski     namespace graphic { class XGraphicObject; }
43*b1cdbd2cSJim Jagielski     namespace graphic { class XGraphicProvider; }
44*b1cdbd2cSJim Jagielski     namespace uno { class XComponentContext; }
45*b1cdbd2cSJim Jagielski } } }
46*b1cdbd2cSJim Jagielski 
47*b1cdbd2cSJim Jagielski namespace oox {
48*b1cdbd2cSJim Jagielski 
49*b1cdbd2cSJim Jagielski // ============================================================================
50*b1cdbd2cSJim Jagielski 
51*b1cdbd2cSJim Jagielski /** Provides helper functions for colors, device measurement conversion,
52*b1cdbd2cSJim Jagielski     graphics, and graphic objects handling.
53*b1cdbd2cSJim Jagielski 
54*b1cdbd2cSJim Jagielski     All createGraphicObject() and importGraphicObject() functions create
55*b1cdbd2cSJim Jagielski     persistent graphic objects internally and store them in an internal
56*b1cdbd2cSJim Jagielski     container to prevent their early destruction. This makes it possible to use
57*b1cdbd2cSJim Jagielski     the returned URL of the graphic object in any way (e.g. insert it into a
58*b1cdbd2cSJim Jagielski     property map) without needing to store it immediatly at an object that
59*b1cdbd2cSJim Jagielski     resolves the graphic object from the passed URL and thus prevents it from
60*b1cdbd2cSJim Jagielski     being destroyed.
61*b1cdbd2cSJim Jagielski  */
62*b1cdbd2cSJim Jagielski class GraphicHelper
63*b1cdbd2cSJim Jagielski {
64*b1cdbd2cSJim Jagielski public:
65*b1cdbd2cSJim Jagielski     explicit            GraphicHelper(
66*b1cdbd2cSJim Jagielski                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
67*b1cdbd2cSJim Jagielski                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxTargetFrame,
68*b1cdbd2cSJim Jagielski                             const StorageRef& rxStorage );
69*b1cdbd2cSJim Jagielski     virtual             ~GraphicHelper();
70*b1cdbd2cSJim Jagielski 
71*b1cdbd2cSJim Jagielski     // System colors and predefined colors ------------------------------------
72*b1cdbd2cSJim Jagielski 
73*b1cdbd2cSJim Jagielski     /** Returns a system color specified by the passed XML token identifier. */
74*b1cdbd2cSJim Jagielski     sal_Int32           getSystemColor( sal_Int32 nToken, sal_Int32 nDefaultRgb = API_RGB_TRANSPARENT ) const;
75*b1cdbd2cSJim Jagielski     /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
76*b1cdbd2cSJim Jagielski     virtual sal_Int32   getSchemeColor( sal_Int32 nToken ) const;
77*b1cdbd2cSJim Jagielski     /** Derived classes may implement to resolve a palette index to an RGB color. */
78*b1cdbd2cSJim Jagielski     virtual sal_Int32   getPaletteColor( sal_Int32 nPaletteIdx ) const;
79*b1cdbd2cSJim Jagielski 
80*b1cdbd2cSJim Jagielski     // Device info and device dependent unit conversion -----------------------
81*b1cdbd2cSJim Jagielski 
82*b1cdbd2cSJim Jagielski     /** Returns information about the output device. */
83*b1cdbd2cSJim Jagielski     const ::com::sun::star::awt::DeviceInfo& getDeviceInfo() const;
84*b1cdbd2cSJim Jagielski 
85*b1cdbd2cSJim Jagielski     /** Converts the passed value from horizontal screen pixels to 1/100 mm. */
86*b1cdbd2cSJim Jagielski     sal_Int32           convertScreenPixelXToHmm( double fPixelX ) const;
87*b1cdbd2cSJim Jagielski     /** Converts the passed value from vertical screen pixels to 1/100 mm. */
88*b1cdbd2cSJim Jagielski     sal_Int32           convertScreenPixelYToHmm( double fPixelY ) const;
89*b1cdbd2cSJim Jagielski     /** Converts the passed point from screen pixels to 1/100 mm. */
90*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Point convertScreenPixelToHmm( const ::com::sun::star::awt::Point& rPixel ) const;
91*b1cdbd2cSJim Jagielski     /** Converts the passed size from screen pixels to 1/100 mm. */
92*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Size convertScreenPixelToHmm( const ::com::sun::star::awt::Size& rPixel ) const;
93*b1cdbd2cSJim Jagielski 
94*b1cdbd2cSJim Jagielski     /** Converts the passed value from 1/100 mm to horizontal screen pixels. */
95*b1cdbd2cSJim Jagielski     double              convertHmmToScreenPixelX( sal_Int32 nHmmX ) const;
96*b1cdbd2cSJim Jagielski     /** Converts the passed value from 1/100 mm to vertical screen pixels. */
97*b1cdbd2cSJim Jagielski     double              convertHmmToScreenPixelY( sal_Int32 nHmmY ) const;
98*b1cdbd2cSJim Jagielski     /** Converts the passed point from 1/100 mm to screen pixels. */
99*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Point convertHmmToScreenPixel( const ::com::sun::star::awt::Point& rHmm ) const;
100*b1cdbd2cSJim Jagielski     /** Converts the passed size from 1/100 mm to screen pixels. */
101*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Size convertHmmToScreenPixel( const ::com::sun::star::awt::Size& rHmm ) const;
102*b1cdbd2cSJim Jagielski 
103*b1cdbd2cSJim Jagielski     /** Converts the passed point from AppFont units to 1/100 mm. */
104*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Point convertAppFontToHmm( const ::com::sun::star::awt::Point& rAppFont ) const;
105*b1cdbd2cSJim Jagielski     /** Converts the passed point from AppFont units to 1/100 mm. */
106*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Size convertAppFontToHmm( const ::com::sun::star::awt::Size& rAppFont ) const;
107*b1cdbd2cSJim Jagielski 
108*b1cdbd2cSJim Jagielski     /** Converts the passed point from 1/100 mm to AppFont units. */
109*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Point convertHmmToAppFont( const ::com::sun::star::awt::Point& rHmm ) const;
110*b1cdbd2cSJim Jagielski     /** Converts the passed size from 1/100 mm to AppFont units. */
111*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::Size convertHmmToAppFont( const ::com::sun::star::awt::Size& rHmm ) const;
112*b1cdbd2cSJim Jagielski 
113*b1cdbd2cSJim Jagielski     // Graphics and graphic objects  ------------------------------------------
114*b1cdbd2cSJim Jagielski 
115*b1cdbd2cSJim Jagielski     /** Imports a graphic from the passed input stream. */
116*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >
117*b1cdbd2cSJim Jagielski                         importGraphic(
118*b1cdbd2cSJim Jagielski                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm ) const;
119*b1cdbd2cSJim Jagielski 
120*b1cdbd2cSJim Jagielski     /** Imports a graphic from the passed binary memory block. */
121*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >
122*b1cdbd2cSJim Jagielski                         importGraphic( const StreamDataSequence& rGraphicData ) const;
123*b1cdbd2cSJim Jagielski 
124*b1cdbd2cSJim Jagielski     /** Imports a graphic from the storage stream with the passed path and name. */
125*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >
126*b1cdbd2cSJim Jagielski                         importEmbeddedGraphic( const ::rtl::OUString& rStreamName ) const;
127*b1cdbd2cSJim Jagielski 
128*b1cdbd2cSJim Jagielski     /** Creates a persistent graphic object from the passed graphic.
129*b1cdbd2cSJim Jagielski         @return  The URL of the created and internally cached graphic object. */
130*b1cdbd2cSJim Jagielski     ::rtl::OUString     createGraphicObject(
131*b1cdbd2cSJim Jagielski                             const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rxGraphic ) const;
132*b1cdbd2cSJim Jagielski 
133*b1cdbd2cSJim Jagielski     /** Creates a persistent graphic object from the passed input stream.
134*b1cdbd2cSJim Jagielski         @return  The URL of the created and internally cached graphic object. */
135*b1cdbd2cSJim Jagielski     ::rtl::OUString     importGraphicObject(
136*b1cdbd2cSJim Jagielski                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm ) const;
137*b1cdbd2cSJim Jagielski 
138*b1cdbd2cSJim Jagielski     /** Creates a persistent graphic object from the passed binary memory block.
139*b1cdbd2cSJim Jagielski         @return  The URL of the created and internally cached graphic object. */
140*b1cdbd2cSJim Jagielski     ::rtl::OUString     importGraphicObject( const StreamDataSequence& rGraphicData ) const;
141*b1cdbd2cSJim Jagielski 
142*b1cdbd2cSJim Jagielski     /** Imports a graphic object from the storage stream with the passed path and name.
143*b1cdbd2cSJim Jagielski         @return  The URL of the created and internally cached graphic object. */
144*b1cdbd2cSJim Jagielski     ::rtl::OUString     importEmbeddedGraphicObject( const ::rtl::OUString& rStreamName ) const;
145*b1cdbd2cSJim Jagielski 
146*b1cdbd2cSJim Jagielski 	/** calculates the orignal size of a graphic which is necessary to be able to calculate cropping values
147*b1cdbd2cSJim Jagielski 		@return	The original Graphic size in 100thmm */
148*b1cdbd2cSJim Jagielski 	::com::sun::star::awt::Size getOriginalSize( const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rxGraphic ) const;
149*b1cdbd2cSJim Jagielski 
150*b1cdbd2cSJim Jagielski     // ------------------------------------------------------------------------
151*b1cdbd2cSJim Jagielski private:
152*b1cdbd2cSJim Jagielski     typedef ::std::map< sal_Int32, sal_Int32 > SystemPalette;
153*b1cdbd2cSJim Jagielski     typedef ::std::deque< ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicObject > > GraphicObjectDeque;
154*b1cdbd2cSJim Jagielski     typedef ::std::map< ::rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > > EmbeddedGraphicMap;
155*b1cdbd2cSJim Jagielski 
156*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
157*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphicProvider > mxGraphicProvider;
158*b1cdbd2cSJim Jagielski     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XUnitConversion > mxUnitConversion;
159*b1cdbd2cSJim Jagielski     ::com::sun::star::awt::DeviceInfo maDeviceInfo; /// Current output device info.
160*b1cdbd2cSJim Jagielski     SystemPalette       maSystemPalette;            /// Maps system colors (XML tokens) to RGB color values.
161*b1cdbd2cSJim Jagielski     StorageRef          mxStorage;                  /// Storage containing embedded graphics.
162*b1cdbd2cSJim Jagielski     mutable GraphicObjectDeque maGraphicObjects;    /// Caches all created graphic objects to keep them alive.
163*b1cdbd2cSJim Jagielski     mutable EmbeddedGraphicMap maEmbeddedGraphics;  /// Maps all embedded graphics by their storage path.
164*b1cdbd2cSJim Jagielski     const ::rtl::OUString maGraphicObjScheme;       /// The URL scheme name for graphic objects.
165*b1cdbd2cSJim Jagielski     double              mfPixelPerHmmX;             /// Number of screen pixels per 1/100 mm in X direction.
166*b1cdbd2cSJim Jagielski     double              mfPixelPerHmmY;             /// Number of screen pixels per 1/100 mm in Y direction.
167*b1cdbd2cSJim Jagielski };
168*b1cdbd2cSJim Jagielski 
169*b1cdbd2cSJim Jagielski // ============================================================================
170*b1cdbd2cSJim Jagielski 
171*b1cdbd2cSJim Jagielski } // namespace oox
172*b1cdbd2cSJim Jagielski 
173*b1cdbd2cSJim Jagielski #endif
174