22#include <com/sun/star/awt/Point.hpp>
23#include <com/sun/star/awt/Size.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/graphic/GraphicProvider.hpp>
26#include <com/sun/star/graphic/GraphicMapper.hpp>
27#include <osl/diagnose.h>
39#include <oox/token/properties.hxx>
40#include <oox/token/tokens.hxx>
54sal_Int32 lclConvertScreenPixelToHmm(
double fPixel,
double fPixelPerHmm )
56 return static_cast< sal_Int32
>( (fPixelPerHmm > 0.0) ? (fPixel / fPixelPerHmm + 0.5) : 0.0 );
65 OSL_ENSURE(
mxContext.is(),
"GraphicHelper::GraphicHelper - missing component context" );
67 mxGraphicProvider.set( graphic::GraphicProvider::create( mxContext ), uno::UNO_QUERY );
70 maSystemPalette[ XML_3dDkShadow ] =
Color(0x716F64);
71 maSystemPalette[ XML_3dLight ] =
Color(0xF1EFE2);
72 maSystemPalette[ XML_activeBorder ] =
Color(0xD4D0C8);
73 maSystemPalette[ XML_activeCaption ] =
Color(0x0054E3);
74 maSystemPalette[ XML_appWorkspace ] =
Color(0x808080);
75 maSystemPalette[ XML_background ] =
Color(0x004E98);
76 maSystemPalette[ XML_btnFace ] =
Color(0xECE9D8);
77 maSystemPalette[ XML_btnHighlight ] =
Color(0xFFFFFF);
78 maSystemPalette[ XML_btnShadow ] =
Color(0xACA899);
79 maSystemPalette[ XML_btnText ] =
Color(0x000000);
80 maSystemPalette[ XML_captionText ] =
Color(0xFFFFFF);
81 maSystemPalette[ XML_gradientActiveCaption ] =
Color(0x3D95FF);
82 maSystemPalette[ XML_gradientInactiveCaption ] =
Color(0xD8E4F8);
83 maSystemPalette[ XML_grayText ] =
Color(0xACA899);
84 maSystemPalette[ XML_highlight ] =
Color(0x316AC5);
85 maSystemPalette[ XML_highlightText ] =
Color(0xFFFFFF);
86 maSystemPalette[ XML_hotLight ] =
Color(0x000080);
87 maSystemPalette[ XML_inactiveBorder ] =
Color(0xD4D0C8);
88 maSystemPalette[ XML_inactiveCaption ] =
Color(0x7A96DF);
89 maSystemPalette[ XML_inactiveCaptionText ] =
Color(0xD8E4F8);
90 maSystemPalette[ XML_infoBk ] =
Color(0xFFFFE1);
91 maSystemPalette[ XML_infoText ] =
Color(0x000000);
92 maSystemPalette[ XML_menu ] =
Color(0xFFFFFF);
93 maSystemPalette[ XML_menuBar ] =
Color(0xECE9D8);
94 maSystemPalette[ XML_menuHighlight ] =
Color(0x316AC5);
95 maSystemPalette[ XML_menuText ] =
Color(0x000000);
96 maSystemPalette[ XML_scrollBar ] =
Color(0xD4D0C8);
97 maSystemPalette[ XML_window ] =
Color(0xFFFFFF);
98 maSystemPalette[ XML_windowFrame ] =
Color(0x000000);
99 maSystemPalette[ XML_windowText ] =
Color(0x000000);
104 maDeviceInfo = mxDefaultOutputDevice->GetDeviceInfo();
107 Size aDefault = mxDefaultOutputDevice->LogicToPixel(
Size(100000, 100000),
MapMode(MapUnit::Map100thMM));
108 maDeviceInfo.PixelPerMeterX = aDefault.
Width();
109 maDeviceInfo.PixelPerMeterY = aDefault.
Height();
110 mfPixelPerHmmX = maDeviceInfo.PixelPerMeterX / 100000.0;
111 mfPixelPerHmmY = maDeviceInfo.PixelPerMeterY / 100000.0;
114GraphicHelper::~GraphicHelper()
120::Color GraphicHelper::getSystemColor( sal_Int32 nToken,
::Color nDefaultRgb )
const
122 return ContainerHelper::getMapElement( maSystemPalette,
nToken, nDefaultRgb );
125::Color GraphicHelper::getSchemeColor( sal_Int32 )
const
127 OSL_FAIL(
"GraphicHelper::getSchemeColor - scheme colors not implemented" );
131::Color GraphicHelper::getPaletteColor( sal_Int32 )
const
133 OSL_FAIL(
"GraphicHelper::getPaletteColor - palette colors not implemented" );
137sal_Int32 GraphicHelper::getDefaultChartAreaFillStyle()
const
139 return XML_solidFill;
142sal_Int32 GraphicHelper::getDefaultChartAreaLineStyle()
144 return XML_solidFill;
147sal_Int16 GraphicHelper::getDefaultChartAreaLineWidth()
155sal_Int32 GraphicHelper::convertScreenPixelXToHmm(
double fPixelX )
const
157 return lclConvertScreenPixelToHmm( fPixelX, mfPixelPerHmmX );
160sal_Int32 GraphicHelper::convertScreenPixelYToHmm(
double fPixelY )
const
162 return lclConvertScreenPixelToHmm( fPixelY, mfPixelPerHmmY );
165awt::Size GraphicHelper::convertScreenPixelToHmm(
const awt::Size& rPixel )
const
167 return awt::Size( convertScreenPixelXToHmm( rPixel.Width ), convertScreenPixelYToHmm( rPixel.Height ) );
170double GraphicHelper::convertHmmToScreenPixelX( sal_Int32 nHmmX )
const
172 return nHmmX * mfPixelPerHmmX;
175double GraphicHelper::convertHmmToScreenPixelY( sal_Int32 nHmmY )
const
177 return nHmmY * mfPixelPerHmmY;
180awt::Point GraphicHelper::convertHmmToScreenPixel(
const awt::Point& rHmm )
const
183 static_cast< sal_Int32
>( convertHmmToScreenPixelX( rHmm.X ) + 0.5 ),
184 static_cast< sal_Int32
>( convertHmmToScreenPixelY( rHmm.Y ) + 0.5 ) );
187awt::Size GraphicHelper::convertHmmToScreenPixel(
const awt::Size& rHmm )
const
190 static_cast< sal_Int32
>( convertHmmToScreenPixelX( rHmm.Width ) + 0.5 ),
191 static_cast< sal_Int32
>( convertHmmToScreenPixelY( rHmm.Height ) + 0.5 ) );
194awt::Point GraphicHelper::convertHmmToAppFont(
const awt::Point& rHmm )
const
198 awt::Point aPixel = convertHmmToScreenPixel( rHmm );
199 MapMode aMode(MapUnit::MapAppFont);
200 ::Point aVCLPoint(aPixel.X, aPixel.Y);
201 ::Point aDevPoint = mxDefaultOutputDevice->PixelToLogic(aVCLPoint, aMode );
202 return awt::Point(aDevPoint.
X(), aDevPoint.
Y());
208 return awt::Point( 0, 0 );
211awt::Size GraphicHelper::convertHmmToAppFont(
const awt::Size& rHmm )
const
215 awt::Size aPixel = convertHmmToScreenPixel( rHmm );
216 MapMode aMode(MapUnit::MapAppFont);
217 ::Size aVCLSize(aPixel.Width, aPixel.Height);
218 ::Size aDevSz = mxDefaultOutputDevice->PixelToLogic(aVCLSize, aMode );
225 return awt::Size( 0, 0 );
231Reference< XGraphic > GraphicHelper::importGraphic(
const Reference< XInputStream >& rxInStrm,
234 Reference< XGraphic > xGraphic;
235 if( rxInStrm.is() && mxGraphicProvider.is() )
try
240 if ( pExtHeader && pExtHeader->
mapMode > 0 )
242 aArgs.realloc( aArgs.getLength() + 1 );
243 auto pArgs = aArgs.getArray();
244 Sequence< PropertyValue > aFilterData{
249 pArgs[ 2 ].Name =
"FilterData";
250 pArgs[ 2 ].Value <<= aFilterData;
253 xGraphic = mxGraphicProvider->queryGraphic( aArgs );
263 Reference< XGraphic > xGraphic;
264 if( rGraphicData.hasElements() )
266 Reference< XInputStream > xInStrm( new ::comphelper::SequenceInputStream( rGraphicData ) );
267 xGraphic = importGraphic( xInStrm );
272Reference< XGraphic > GraphicHelper::importEmbeddedGraphic(
const OUString& rStreamName,
const WmfExternal* pExtHeader )
const
274 Reference< XGraphic > xGraphic;
275 OSL_ENSURE( !rStreamName.isEmpty(),
"GraphicHelper::importEmbeddedGraphic - empty stream name" );
277 if( !rStreamName.isEmpty() )
279 initializeGraphicMapperIfNeeded();
281 SAL_WARN_IF(!mxGraphicMapper.is(),
"oox",
"GraphicHelper::importEmbeddedGraphic - graphic mapper not available");
283 xGraphic = mxGraphicMapper->findGraphic(rStreamName);
287 xGraphic = importGraphic(
xStream, pExtHeader);
289 mxGraphicMapper->putGraphic(rStreamName, xGraphic);
295awt::Size GraphicHelper::getOriginalSize(
const Reference< XGraphic >& xGraphic )
const
299 if( aPropSet.
getProperty( aSizeHmm, PROP_Size100thMM ) && (aSizeHmm.Width == 0) && (aSizeHmm.Height == 0) )
301 awt::Size aSizePixel( 0, 0 );
302 if( aPropSet.
getProperty( aSizePixel, PROP_SizePixel ) )
303 aSizeHmm = convertScreenPixelToHmm( aSizePixel );
308void GraphicHelper::setGraphicMapper(css::uno::Reference<css::graphic::XGraphicMapper>
const & rGraphicMapper)
310 mxGraphicMapper = rGraphicMapper;
313void GraphicHelper::initializeGraphicMapperIfNeeded()
const
315 if (!mxGraphicMapper.is())
static OutputDevice * GetDefaultDevice()
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
css::uno::Reference< css::graphic::XGraphicMapper > mxGraphicMapper
GraphicHelper(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rxTargetFrame, StorageRef xStorage)
A wrapper for a UNO property set.
bool getProperty(Type &orValue, sal_Int32 nPropId) const
Gets the specified property from the property set.
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN_IF(condition, area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
std::shared_ptr< StorageBase > StorageRef
css::uno::Sequence< sal_Int8 > StreamDataSequence
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
Reference< XNameContainer > mxStorage