LCOV - code coverage report
Current view: top level - include/oox/helper - graphichelper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 1 100.0 %
Date: 2014-11-03 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10