LibreOffice Module oox (master) 1
fillproperties.cxx
Go to the documentation of this file.
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
21
22#include <iterator>
23
26#include <vcl/graph.hxx>
27#include <vcl/BitmapFilter.hxx>
30
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/awt/Gradient.hpp>
33#include <com/sun/star/text/GraphicCrop.hpp>
34#include <com/sun/star/awt/Size.hpp>
35#include <com/sun/star/drawing/BitmapMode.hpp>
36#include <com/sun/star/drawing/ColorMode.hpp>
37#include <com/sun/star/drawing/FillStyle.hpp>
38#include <com/sun/star/drawing/RectanglePoint.hpp>
39#include <com/sun/star/graphic/XGraphicTransformer.hpp>
44#include <oox/token/namespaces.hxx>
45#include <oox/token/properties.hxx>
46#include <oox/token/tokens.hxx>
47#include <osl/diagnose.h>
48#include <sal/log.hxx>
49
50using namespace ::com::sun::star;
51using namespace ::com::sun::star::drawing;
52using namespace ::com::sun::star::graphic;
53
54using ::com::sun::star::uno::Reference;
55using ::com::sun::star::uno::Exception;
56using ::com::sun::star::uno::UNO_QUERY_THROW;
57using ::com::sun::star::geometry::IntegerRectangle2D;
58
59namespace oox::drawingml {
60
61namespace {
62
63Reference< XGraphic > lclCheckAndApplyDuotoneTransform(const BlipFillProperties& aBlipProps, uno::Reference<graphic::XGraphic> const & xGraphic,
64 const GraphicHelper& rGraphicHelper, const ::Color nPhClr)
65{
66 if (aBlipProps.maDuotoneColors[0].isUsed() && aBlipProps.maDuotoneColors[1].isUsed())
67 {
68 ::Color nColor1 = aBlipProps.maDuotoneColors[0].getColor( rGraphicHelper, nPhClr );
69 ::Color nColor2 = aBlipProps.maDuotoneColors[1].getColor( rGraphicHelper, nPhClr );
70
71 uno::Reference<graphic::XGraphicTransformer> xTransformer(aBlipProps.mxFillGraphic, uno::UNO_QUERY);
72 if (xTransformer.is())
73 return xTransformer->applyDuotone(xGraphic, sal_Int32(nColor1), sal_Int32(nColor2));
74 }
75 return xGraphic;
76}
77
78Reference< XGraphic > lclRotateGraphic(uno::Reference<graphic::XGraphic> const & xGraphic, Degree10 nRotation)
79{
80 ::Graphic aGraphic(xGraphic);
81 ::Graphic aReturnGraphic;
82
83 assert (aGraphic.GetType() == GraphicType::Bitmap);
84
85 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
86 const ::Color& aColor = ::Color(0x00);
87 aBitmapEx.Rotate(nRotation, aColor);
88 aReturnGraphic = ::Graphic(aBitmapEx);
89 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
90
91 return aReturnGraphic.GetXGraphic();
92}
93
94using Quotients = std::tuple<double, double, double, double>;
95Quotients getQuotients(geometry::IntegerRectangle2D aRelRect, double hDiv, double vDiv)
96{
97 return { aRelRect.X1 / hDiv, aRelRect.Y1 / vDiv, aRelRect.X2 / hDiv, aRelRect.Y2 / vDiv };
98}
99
100// ECMA-376 Part 1 20.1.8.55 srcRect (Source Rectangle)
101std::optional<Quotients> CropQuotientsFromSrcRect(geometry::IntegerRectangle2D aSrcRect)
102{
103 aSrcRect.X1 = std::max(aSrcRect.X1, sal_Int32(0));
104 aSrcRect.X2 = std::max(aSrcRect.X2, sal_Int32(0));
105 aSrcRect.Y1 = std::max(aSrcRect.Y1, sal_Int32(0));
106 aSrcRect.Y2 = std::max(aSrcRect.Y2, sal_Int32(0));
107 if (aSrcRect.X1 + aSrcRect.X2 >= 100'000 || aSrcRect.Y1 + aSrcRect.Y2 >= 100'000)
108 return {}; // Cropped everything
109 return getQuotients(aSrcRect, 100'000.0, 100'000.0);
110}
111
112// ECMA-376 Part 1 20.1.8.30 fillRect (Fill Rectangle)
113std::optional<Quotients> CropQuotientsFromFillRect(geometry::IntegerRectangle2D aFillRect)
114{
115 aFillRect.X1 = std::min(aFillRect.X1, sal_Int32(0));
116 aFillRect.X2 = std::min(aFillRect.X2, sal_Int32(0));
117 aFillRect.Y1 = std::min(aFillRect.Y1, sal_Int32(0));
118 aFillRect.Y2 = std::min(aFillRect.Y2, sal_Int32(0));
119 // Negative divisor and negative relative offset give positive value wanted in lclCropGraphic
120 return getQuotients(aFillRect, -100'000.0 + aFillRect.X1 + aFillRect.X2,
121 -100'000.0 + aFillRect.Y1 + aFillRect.Y2);
122}
123
124// Crops a piece of the bitmap. lclCropGraphic doesn't handle growing.
125Reference<XGraphic> lclCropGraphic(uno::Reference<graphic::XGraphic> const& xGraphic,
126 std::optional<Quotients> quotients)
127{
128 ::Graphic aGraphic(xGraphic);
129 assert (aGraphic.GetType() == GraphicType::Bitmap);
130
131 BitmapEx aBitmapEx;
132 if (quotients)
133 {
134 aBitmapEx = aGraphic.GetBitmapEx();
135
136 const Size bmpSize = aBitmapEx.GetSizePixel();
137 const auto& [qx1, qy1, qx2, qy2] = *quotients;
138 const tools::Long l = std::round(bmpSize.Width() * qx1);
139 const tools::Long t = std::round(bmpSize.Height() * qy1);
140 const tools::Long r = std::round(bmpSize.Width() * qx2);
141 const tools::Long b = std::round(bmpSize.Height() * qy2);
142
143 aBitmapEx.Crop({ l, t, bmpSize.Width() - r - 1, bmpSize.Height() - b - 1 });
144 }
145
146 ::Graphic aReturnGraphic(aBitmapEx);
147 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
148
149 return aReturnGraphic.GetXGraphic();
150}
151
152Reference< XGraphic > lclMirrorGraphic(uno::Reference<graphic::XGraphic> const & xGraphic, bool bFlipH, bool bFlipV)
153{
154 ::Graphic aGraphic(xGraphic);
155 ::Graphic aReturnGraphic;
156
157 assert (aGraphic.GetType() == GraphicType::Bitmap);
158
159 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
160 BmpMirrorFlags nMirrorFlags = BmpMirrorFlags::NONE;
161
162 if(bFlipH)
163 nMirrorFlags |= BmpMirrorFlags::Horizontal;
164 if(bFlipV)
165 nMirrorFlags |= BmpMirrorFlags::Vertical;
166
167 aBitmapEx.Mirror(nMirrorFlags);
168
169 aReturnGraphic = ::Graphic(aBitmapEx);
170 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
171
172 return aReturnGraphic.GetXGraphic();
173}
174
175Reference< XGraphic > lclGreysScaleGraphic(uno::Reference<graphic::XGraphic> const & xGraphic)
176{
177 ::Graphic aGraphic(xGraphic);
178 ::Graphic aReturnGraphic;
179
180 assert (aGraphic.GetType() == GraphicType::Bitmap);
181
182 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
183 aBitmapEx.Convert(BmpConversion::N8BitGreys);
184
185 aReturnGraphic = ::Graphic(aBitmapEx);
186 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
187
188 return aReturnGraphic.GetXGraphic();
189}
190
192Reference<XGraphic> lclApplyBlackWhiteEffect(const BlipFillProperties& aBlipProps,
193 const uno::Reference<graphic::XGraphic>& xGraphic)
194{
195 const auto& oBiLevelThreshold = aBlipProps.moBiLevelThreshold;
196 if (oBiLevelThreshold.has_value())
197 {
198 sal_uInt8 nThreshold
199 = static_cast<sal_uInt8>(oBiLevelThreshold.value() * 255 / MAX_PERCENT);
200
201 ::Graphic aGraphic(xGraphic);
202 ::Graphic aReturnGraphic;
203
204 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
205 AlphaMask aMask(aBitmapEx.GetAlphaMask());
206
207 BitmapEx aTmpBmpEx(aBitmapEx.GetBitmap());
208 BitmapFilter::Filter(aTmpBmpEx, BitmapMonochromeFilter{ nThreshold });
209
210 aReturnGraphic = ::Graphic(BitmapEx(aTmpBmpEx.GetBitmap(), aMask));
211 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
212 return aReturnGraphic.GetXGraphic();
213 }
214 return xGraphic;
215}
216
217Reference< XGraphic > lclCheckAndApplyChangeColorTransform(const BlipFillProperties &aBlipProps, uno::Reference<graphic::XGraphic> const & xGraphic,
218 const GraphicHelper& rGraphicHelper, const ::Color nPhClr)
219{
220 if( aBlipProps.maColorChangeFrom.isUsed() && aBlipProps.maColorChangeTo.isUsed() )
221 {
222 ::Color nFromColor = aBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
223 ::Color nToColor = aBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
224 if ( (nFromColor != nToColor) || aBlipProps.maColorChangeTo.hasTransparency() )
225 {
226 sal_Int16 nToTransparence = aBlipProps.maColorChangeTo.getTransparency();
227 sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) * 2.55 );
228
229 sal_uInt8 nTolerance = 9;
230 Graphic aGraphic{ xGraphic };
231 if( aGraphic.IsGfxLink() )
232 {
233 // tdf#149670: Try to guess tolerance depending on image format
234 switch (aGraphic.GetGfxLink().GetType())
235 {
236 case GfxLinkType::NativeJpg:
237 nTolerance = 15;
238 break;
239 case GfxLinkType::NativePng:
240 case GfxLinkType::NativeTif:
241 nTolerance = 1;
242 break;
243 case GfxLinkType::NativeBmp:
244 nTolerance = 0;
245 break;
246 default:
247 break;
248 }
249 }
250
251 uno::Reference<graphic::XGraphicTransformer> xTransformer(aBlipProps.mxFillGraphic, uno::UNO_QUERY);
252 if (xTransformer.is())
253 return xTransformer->colorChange(xGraphic, sal_Int32(nFromColor), nTolerance, sal_Int32(nToColor), nToAlpha);
254 }
255 }
256 return xGraphic;
257}
258
259uno::Reference<graphic::XGraphic> applyBrightnessContrast(uno::Reference<graphic::XGraphic> const & xGraphic, sal_Int32 brightness, sal_Int32 contrast)
260{
261 uno::Reference<graphic::XGraphicTransformer> xTransformer(xGraphic, uno::UNO_QUERY);
262 if (xTransformer.is())
263 return xTransformer->applyBrightnessContrast(xGraphic, brightness, contrast, true);
264 return xGraphic;
265}
266
267BitmapMode lclGetBitmapMode( sal_Int32 nToken )
268{
269 OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
270 switch( nToken )
271 {
272 case XML_tile: return BitmapMode_REPEAT;
273 case XML_stretch: return BitmapMode_STRETCH;
274 }
275
276 // tdf#128596 Default value is XML_tile for MSO.
277 return BitmapMode_REPEAT;
278}
279
280RectanglePoint lclGetRectanglePoint( sal_Int32 nToken )
281{
282 OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
283 switch( nToken )
284 {
285 case XML_tl: return RectanglePoint_LEFT_TOP;
286 case XML_t: return RectanglePoint_MIDDLE_TOP;
287 case XML_tr: return RectanglePoint_RIGHT_TOP;
288 case XML_l: return RectanglePoint_LEFT_MIDDLE;
289 case XML_ctr: return RectanglePoint_MIDDLE_MIDDLE;
290 case XML_r: return RectanglePoint_RIGHT_MIDDLE;
291 case XML_bl: return RectanglePoint_LEFT_BOTTOM;
292 case XML_b: return RectanglePoint_MIDDLE_BOTTOM;
293 case XML_br: return RectanglePoint_RIGHT_BOTTOM;
294 }
295 return RectanglePoint_LEFT_TOP;
296}
297
298awt::Size lclGetOriginalSize( const GraphicHelper& rGraphicHelper, const Reference< XGraphic >& rxGraphic )
299{
300 awt::Size aSizeHmm( 0, 0 );
301 try
302 {
303 Reference< beans::XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW );
304 if( xGraphicPropertySet->getPropertyValue( "Size100thMM" ) >>= aSizeHmm )
305 {
306 if( !aSizeHmm.Width && !aSizeHmm.Height )
307 { // MAPMODE_PIXEL USED :-(
308 awt::Size aSourceSizePixel( 0, 0 );
309 if( xGraphicPropertySet->getPropertyValue( "SizePixel" ) >>= aSourceSizePixel )
310 aSizeHmm = rGraphicHelper.convertScreenPixelToHmm( aSourceSizePixel );
311 }
312 }
313 }
314 catch( Exception& )
315 {
316 }
317 return aSizeHmm;
318}
319
324void extractGradientBorderFromStops(const GradientFillProperties& rGradientProps,
325 const GraphicHelper& rGraphicHelper, ::Color nPhClr,
326 awt::Gradient& rGradient)
327{
328 if (rGradientProps.maGradientStops.size() <= 1)
329 return;
330
331 auto it = rGradientProps.maGradientStops.rbegin();
332 double fLastPos = it->first;
333 Color aLastColor = it->second;
334 ++it;
335 double fLastButOnePos = it->first;
336 Color aLastButOneColor = it->second;
337 if (!aLastColor.equals(aLastButOneColor, rGraphicHelper, nPhClr))
338 return;
339
340 // Last transition has the same color, we can map that to a border.
341 rGradient.Border = rtl::math::round((fLastPos - fLastButOnePos) * 100);
342}
343
344} // namespace
345
347{
348 if( !rSourceProps.maGradientStops.empty() )
349 maGradientStops = rSourceProps.maGradientStops;
350 assignIfUsed( moFillToRect, rSourceProps.moFillToRect );
351 assignIfUsed( moTileRect, rSourceProps.moTileRect );
353 assignIfUsed( moShadeAngle, rSourceProps.moShadeAngle );
354 assignIfUsed( moShadeFlip, rSourceProps.moShadeFlip );
357}
358
360{
363 assignIfUsed( moPattPreset, rSourceProps.moPattPreset );
364}
365
367{
368 if(rSourceProps.mxFillGraphic.is())
369 mxFillGraphic = rSourceProps.mxFillGraphic;
370 assignIfUsed( moBitmapMode, rSourceProps.moBitmapMode );
371 assignIfUsed( moFillRect, rSourceProps.moFillRect );
374 assignIfUsed( moTileScaleX, rSourceProps.moTileScaleX );
375 assignIfUsed( moTileScaleY, rSourceProps.moTileScaleY );
376 assignIfUsed( moTileAlign, rSourceProps.moTileAlign );
377 assignIfUsed( moTileFlip, rSourceProps.moTileFlip );
380 assignIfUsed( moBrightness, rSourceProps.moBrightness );
381 assignIfUsed( moContrast, rSourceProps.moContrast );
385 maDuotoneColors[0].assignIfUsed( rSourceProps.maDuotoneColors[0] );
386 maDuotoneColors[1].assignIfUsed( rSourceProps.maDuotoneColors[1] );
387 maEffect.assignUsed( rSourceProps.maEffect );
389}
390
392{
393 assignIfUsed( moFillType, rSourceProps.moFillType );
394 maFillColor.assignIfUsed( rSourceProps.maFillColor );
395 assignIfUsed( moUseBgFill, rSourceProps.moUseBgFill );
398 maBlipProps.assignUsed( rSourceProps.maBlipProps );
399}
400
402{
403 Color aSolidColor;
404 if( moFillType.has_value() ) switch( moFillType.value() )
405 {
406 case XML_solidFill:
407 aSolidColor = maFillColor;
408 break;
409 case XML_gradFill:
410 if( !maGradientProps.maGradientStops.empty() )
411 {
412 GradientFillProperties::GradientStopMap::const_iterator aGradientStop =
414 if (maGradientProps.maGradientStops.size() > 2)
415 ++aGradientStop;
416 aSolidColor = aGradientStop->second;
417 }
418 break;
419 case XML_pattFill:
421 break;
422 }
423 return aSolidColor;
424}
425
427 sal_Int32 nShapeRotation, ::Color nPhClr,
428 const css::awt::Size& rSize, sal_Int16 nPhClrTheme, bool bFlipH,
429 bool bFlipV, bool bIsCustomShape) const
430{
431 if( !moFillType.has_value() )
432 return;
433
434 FillStyle eFillStyle = FillStyle_NONE;
435 OSL_ASSERT((moFillType.value() & sal_Int32(0xFFFF0000))==0);
436 switch( moFillType.value() )
437 {
438 case XML_noFill:
439 {
440 eFillStyle = FillStyle_NONE;
442 }
443 break;
444
445 case XML_solidFill:
446 if( maFillColor.isUsed() )
447 {
448 ::Color aFillColor = maFillColor.getColor(rGraphicHelper, nPhClr);
449 rPropMap.setProperty(ShapeProperty::FillColor, aFillColor);
452
453 model::ThemeColor aThemeColor;
454 if (aFillColor == nPhClr)
455 {
456 aThemeColor.setType(model::convertToThemeColorType(nPhClrTheme));
458 }
459 else
460 {
462 if (maFillColor.getLumMod() != 10000)
464 if (maFillColor.getLumOff() != 0)
466 if (maFillColor.getTintOrShade() > 0)
468 if (maFillColor.getTintOrShade() < 0)
469 {
470 sal_Int16 nShade = o3tl::narrowing<sal_Int16>(-maFillColor.getTintOrShade());
472 }
474 }
475
476 eFillStyle = FillStyle_SOLID;
477 }
478 break;
479
480 case XML_gradFill:
481 // do not create gradient struct if property is not supported...
483 {
484 sal_Int32 nEndTrans = 0;
485 sal_Int32 nStartTrans = 0;
486 awt::Gradient aGradient;
487 aGradient.Angle = 900;
488 aGradient.StartIntensity = 100;
489 aGradient.EndIntensity = 100;
490
491 // Old code, values in aGradient overwritten in many cases by newer code below
492 if( maGradientProps.maGradientStops.size() > 1 )
493 {
494 aGradient.StartColor = sal_Int32(maGradientProps.maGradientStops.begin()->second.getColor( rGraphicHelper, nPhClr ));
495 aGradient.EndColor = sal_Int32(maGradientProps.maGradientStops.rbegin()->second.getColor( rGraphicHelper, nPhClr ));
496 if( maGradientProps.maGradientStops.rbegin()->second.hasTransparency() )
497 nEndTrans = maGradientProps.maGradientStops.rbegin()->second.getTransparency()*255/100;
498 if( maGradientProps.maGradientStops.begin()->second.hasTransparency() )
499 nStartTrans = maGradientProps.maGradientStops.begin()->second.getTransparency()*255/100;
500 }
501
502 // "rotate with shape" set to false -> do not rotate
503 if ( !maGradientProps.moRotateWithShape.value_or( true ) )
504 nShapeRotation = 0;
505
506 if( maGradientProps.moGradientPath.has_value() )
507 {
508 IntegerRectangle2D aFillToRect = maGradientProps.moFillToRect.value_or( IntegerRectangle2D( 0, 0, MAX_PERCENT, MAX_PERCENT ) );
509 sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - aFillToRect.X2) / 2;
510 aGradient.XOffset = getLimitedValue<sal_Int16, sal_Int32>(
511 nCenterX / PER_PERCENT, 0, 100);
512 sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - aFillToRect.Y2) / 2;
513 aGradient.YOffset = getLimitedValue<sal_Int16, sal_Int32>(
514 nCenterY / PER_PERCENT, 0, 100);
515
516 if( maGradientProps.moGradientPath.value() == XML_circle )
517 {
518 // Style should be radial at least when the horizontal center is at 50%.
519 // Otherwise import as a linear gradient, because it is the most similar to the MSO radial style.
520 aGradient.Style = awt::GradientStyle_LINEAR;
521 if( aGradient.XOffset == 100 && aGradient.YOffset == 100 )
522 aGradient.Angle = 450;
523 else if( aGradient.XOffset == 0 && aGradient.YOffset == 100 )
524 aGradient.Angle = 3150;
525 else if( aGradient.XOffset == 100 && aGradient.YOffset == 0 )
526 aGradient.Angle = 1350;
527 else if( aGradient.XOffset == 0 && aGradient.YOffset == 0 )
528 aGradient.Angle = 2250;
529 else
530 aGradient.Style = awt::GradientStyle_RADIAL;
531 }
532 else
533 {
534 aGradient.Style = awt::GradientStyle_RECT;
535 }
536
537 ::std::swap( aGradient.StartColor, aGradient.EndColor );
538 ::std::swap( nStartTrans, nEndTrans );
539
540 extractGradientBorderFromStops(maGradientProps, rGraphicHelper, nPhClr,
541 aGradient);
542 }
543 else if (!maGradientProps.maGradientStops.empty())
544 {
545 // A copy of the gradient stops for local modification
547
548 // Add a fake gradient stop at 0% and 100% if necessary, so that the gradient always starts
549 // at 0% and ends at 100%, to make following logic clearer (?).
550 auto a0 = aGradientStops.find( 0.0 );
551 if( a0 == aGradientStops.end() )
552 {
553 // temp variable required
554 Color aFirstColor(aGradientStops.begin()->second);
555 aGradientStops.emplace( 0.0, aFirstColor );
556 }
557
558 auto a1 = aGradientStops.find( 1.0 );
559 if( a1 == aGradientStops.end() )
560 {
561 // ditto
562 Color aLastColor(aGradientStops.rbegin()->second);
563 aGradientStops.emplace( 1.0, aLastColor );
564 }
565
566 // Check if the gradient is symmetric, which we will emulate with an "axial" gradient.
567 bool bSymmetric(true);
568 {
569 GradientFillProperties::GradientStopMap::const_iterator aItA( aGradientStops.begin() );
570 GradientFillProperties::GradientStopMap::const_iterator aItZ(std::prev(aGradientStops.end()));
571 assert(aItZ != aGradientStops.end());
572 while( bSymmetric && aItA->first < aItZ->first )
573 {
574 if (!aItA->second.equals(aItZ->second, rGraphicHelper, nPhClr))
575 bSymmetric = false;
576 else
577 {
578 ++aItA;
579 aItZ = std::prev(aItZ);
580 }
581 }
582 // Don't be fooled if the middlemost stop isn't at 0.5.
583 if( bSymmetric && aItA == aItZ && aItA->first != 0.5 )
584 bSymmetric = false;
585
586 // If symmetric, do the rest of the logic for just a half.
587 if( bSymmetric )
588 {
589 // aItZ already points to the colour for the middle, but insert a fake stop at the
590 // exact middle if necessary.
591 if( aItA->first != aItZ->first )
592 {
593 Color aMiddleColor = aItZ->second;
594 auto a05 = aGradientStops.find( 0.5 );
595
596 if( a05 != aGradientStops.end() )
597 a05->second = aMiddleColor;
598 else
599 aGradientStops.emplace( 0.5, aMiddleColor );
600 }
601 // Drop the rest of the stops
602 while( aGradientStops.rbegin()->first > 0.5 )
603 aGradientStops.erase( aGradientStops.rbegin()->first );
604 }
605 }
606
607 SAL_INFO("oox.drawingml.gradient", "symmetric: " << (bSymmetric ? "YES" : "NO") <<
608 ", number of stops: " << aGradientStops.size());
609 size_t nIndex = 0;
610 for (auto const& gradientStop : aGradientStops)
611 SAL_INFO("oox.drawingml.gradient", " " << nIndex++ << ": " <<
612 gradientStop.first << ": " <<
613 std::hex << sal_Int32(gradientStop.second.getColor( rGraphicHelper, nPhClr )) << std::dec <<
614 "@" << (100 - gradientStop.second.getTransparency()) << "%");
615
616 // Now estimate the simple LO style gradient (only two stops, at n% and 100%, where n ==
617 // the "border") that best emulates the gradient between begin() and prior(end()).
618
619 // First look for the largest segment in the gradient.
620 GradientFillProperties::GradientStopMap::iterator aIt(aGradientStops.begin());
621 double nWidestWidth = -1;
622 GradientFillProperties::GradientStopMap::iterator aWidestSegmentStart;
623 ++aIt;
624 while( aIt != aGradientStops.end() )
625 {
626 if (aIt->first - std::prev(aIt)->first > nWidestWidth)
627 {
628 nWidestWidth = aIt->first - std::prev(aIt)->first;
629 aWidestSegmentStart = std::prev(aIt);
630 }
631 ++aIt;
632 }
633 assert( nWidestWidth >= 0 );
634
635 double nBorder = 0;
636 bool bSwap(false);
637
638 // Do we have just two segments, and either one is of uniform colour, or three or more
639 // segments, and the widest one is the first or last one, and is it of uniform colour? If
640 // so, deduce the border from it, and drop that segment.
641 if( aGradientStops.size() == 3 &&
642 aGradientStops.begin()->second.getColor(rGraphicHelper, nPhClr) == std::next(aGradientStops.begin())->second.getColor(rGraphicHelper, nPhClr) &&
643 aGradientStops.begin()->second.getTransparency() == std::next(aGradientStops.begin())->second.getTransparency())
644 {
645 // Two segments, first is uniformly coloured
646 SAL_INFO("oox.drawingml.gradient", "two segments, first is uniformly coloured");
647 nBorder = std::next(aGradientStops.begin())->first - aGradientStops.begin()->first;
648 aGradientStops.erase(aGradientStops.begin());
649 aWidestSegmentStart = aGradientStops.begin();
650 }
651 else if( !bSymmetric &&
652 aGradientStops.size() == 3 &&
653 std::next(aGradientStops.begin())->second.getColor(rGraphicHelper, nPhClr) == std::prev(aGradientStops.end())->second.getColor(rGraphicHelper, nPhClr) &&
654 std::next(aGradientStops.begin())->second.getTransparency() == std::prev(aGradientStops.end())->second.getTransparency())
655 {
656 // Two segments, second is uniformly coloured
657 SAL_INFO("oox.drawingml.gradient", "two segments, second is uniformly coloured");
658 auto aNext = std::next(aGradientStops.begin());
659 auto aPrev = std::prev(aGradientStops.end());
660 assert(aPrev != aGradientStops.end());
661 nBorder = aPrev->first - aNext->first;
662 aGradientStops.erase(aNext);
663 aWidestSegmentStart = aGradientStops.begin();
664 bSwap = true;
665 nShapeRotation = 180*60000 - nShapeRotation;
666 }
667 else if( !bSymmetric &&
668 aGradientStops.size() >= 4 &&
669 aWidestSegmentStart->second.getColor( rGraphicHelper, nPhClr ) == std::next(aWidestSegmentStart)->second.getColor(rGraphicHelper, nPhClr) &&
670 aWidestSegmentStart->second.getTransparency() == std::next(aWidestSegmentStart)->second.getTransparency() &&
671 ( aWidestSegmentStart == aGradientStops.begin() ||
672 std::next(aWidestSegmentStart) == std::prev(aGradientStops.end())))
673 {
674 // Not symmetric, three or more segments, the widest is first or last and is uniformly coloured
675 SAL_INFO("oox.drawingml.gradient", "first or last segment is widest and is uniformly coloured");
676 nBorder = std::next(aWidestSegmentStart)->first - aWidestSegmentStart->first;
677
678 // If it's the last segment that is uniformly coloured, rotate the gradient 180
679 // degrees and swap start and end colours
680 if (std::next(aWidestSegmentStart) == std::prev(aGradientStops.end()))
681 {
682 bSwap = true;
683 nShapeRotation = 180*60000 - nShapeRotation;
684 }
685
686 aGradientStops.erase( aWidestSegmentStart++ );
687
688 // Look for which is widest now
689 aIt = std::next(aGradientStops.begin());
690 nWidestWidth = -1;
691 while( aIt != aGradientStops.end() )
692 {
693 if (aIt->first - std::prev(aIt)->first > nWidestWidth)
694 {
695 nWidestWidth = aIt->first - std::prev(aIt)->first;
696 aWidestSegmentStart = std::prev(aIt);
697 }
698 ++aIt;
699 }
700 }
701 SAL_INFO("oox.drawingml.gradient", "widest segment start: " << aWidestSegmentStart->first << ", border: " << nBorder);
702 assert( (!bSymmetric && !bSwap) || !(bSymmetric && bSwap) );
703
704 // Now we have a potential border and a largest segment. Use those.
705
706 aGradient.Style = bSymmetric ? awt::GradientStyle_AXIAL : awt::GradientStyle_LINEAR;
707 sal_Int32 nShadeAngle = maGradientProps.moShadeAngle.value_or( 0 );
708 // Adjust for flips
709 if ( bFlipH )
710 nShadeAngle = 180*60000 - nShadeAngle;
711 if ( bFlipV )
712 nShadeAngle = -nShadeAngle;
713 sal_Int32 nDmlAngle = nShadeAngle + nShapeRotation;
714 // convert DrawingML angle (in 1/60000 degrees) to API angle (in 1/10 degrees)
715 aGradient.Angle = static_cast< sal_Int16 >( (8100 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 );
716 Color aStartColor, aEndColor;
717
718 // Make a note where the widest segment stops, because we will try to grow it next.
719 auto aWidestSegmentEnd = std::next(aWidestSegmentStart);
720
721 // Try to grow the widest segment backwards: if a previous segment has the same
722 // color, just different transparency, include it.
723 while (aWidestSegmentStart != aGradientStops.begin())
724 {
725 auto it = std::prev(aWidestSegmentStart);
726 if (it->second.getColor(rGraphicHelper, nPhClr)
727 != aWidestSegmentStart->second.getColor(rGraphicHelper, nPhClr))
728 {
729 break;
730 }
731
732 aWidestSegmentStart = it;
733 }
734
735 // Try to grow the widest segment forward: if a next segment has the same
736 // color, just different transparency, include it.
737 while (aWidestSegmentEnd != std::prev(aGradientStops.end()))
738 {
739 auto it = std::next(aWidestSegmentEnd);
740 if (it->second.getColor(rGraphicHelper, nPhClr)
741 != aWidestSegmentEnd->second.getColor(rGraphicHelper, nPhClr))
742 {
743 break;
744 }
745
746 aWidestSegmentEnd = it;
747 }
748
749 assert(aWidestSegmentEnd != aGradientStops.end());
750
751 if( bSymmetric )
752 {
753 aStartColor = aWidestSegmentEnd->second;
754 aEndColor = aWidestSegmentStart->second;
755 nBorder *= 2;
756 }
757 else if( bSwap )
758 {
759 aStartColor = aWidestSegmentEnd->second;
760 aEndColor = aWidestSegmentStart->second;
761 }
762 else
763 {
764 aStartColor = aWidestSegmentStart->second;
765 aEndColor = aWidestSegmentEnd->second;
766 }
767
768 SAL_INFO("oox.drawingml.gradient", "start color: " << std::hex << sal_Int32(aStartColor.getColor( rGraphicHelper, nPhClr )) << std::dec <<
769 "@" << (100-aStartColor.getTransparency()) << "%"
770 ", end color: " << std::hex << sal_Int32(aEndColor.getColor( rGraphicHelper, nPhClr )) << std::dec <<
771 "@" << (100-aEndColor.getTransparency()) << "%");
772
773 aGradient.StartColor = sal_Int32(aStartColor.getColor( rGraphicHelper, nPhClr ));
774 aGradient.EndColor = sal_Int32(aEndColor.getColor( rGraphicHelper, nPhClr ));
775
776 nStartTrans = aStartColor.hasTransparency() ? aStartColor.getTransparency()*255/100 : 0;
777 nEndTrans = aEndColor.hasTransparency() ? aEndColor.getTransparency()*255/100 : 0;
778
779 aGradient.Border = rtl::math::round(100*nBorder);
780 }
781
782 // push gradient or named gradient to property map
783 if( rPropMap.setProperty( ShapeProperty::FillGradient, aGradient ) )
784 eFillStyle = FillStyle_GRADIENT;
785
786 // push gradient transparency to property map
787 if( nStartTrans != 0 || nEndTrans != 0 )
788 {
789 awt::Gradient aGrad(aGradient);
790 uno::Any aVal;
791 aGrad.EndColor = static_cast<sal_Int32>( nEndTrans | nEndTrans << 8 | nEndTrans << 16 );
792 aGrad.StartColor = static_cast<sal_Int32>( nStartTrans | nStartTrans << 8 | nStartTrans << 16 );
793 aVal <<= aGrad;
795 }
796
797 }
798 break;
799
800 case XML_blipFill:
801 // do not start complex graphic transformation if property is not supported...
803 {
804 uno::Reference<graphic::XGraphic> xGraphic = lclCheckAndApplyDuotoneTransform(maBlipProps, maBlipProps.mxFillGraphic, rGraphicHelper, nPhClr);
805 // TODO: "rotate with shape" is not possible with our current core
806
807 if (xGraphic.is())
808 {
809 if (maBlipProps.moColorEffect.value_or(XML_TOKEN_INVALID) == XML_grayscl)
810 xGraphic = lclGreysScaleGraphic(xGraphic);
811
813 rPropMap.setProperty(ShapeProperty::FillBitmapName, xGraphic))
814 {
815 eFillStyle = FillStyle_BITMAP;
816 }
817 else if (rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic))
818 {
819 eFillStyle = FillStyle_BITMAP;
820 }
821 }
822
823 // set other bitmap properties, if bitmap has been inserted into the map
824 if( eFillStyle == FillStyle_BITMAP )
825 {
826 // bitmap mode (single, repeat, stretch)
827 BitmapMode eBitmapMode = lclGetBitmapMode( maBlipProps.moBitmapMode.value_or( XML_TOKEN_INVALID ) );
828
829 // additional settings for repeated bitmap
830 if( eBitmapMode == BitmapMode_REPEAT )
831 {
832 // anchor position inside bitmap
833 RectanglePoint eRectPoint = lclGetRectanglePoint( maBlipProps.moTileAlign.value_or( XML_tl ) );
835
836 awt::Size aOriginalSize = lclGetOriginalSize(rGraphicHelper, maBlipProps.mxFillGraphic);
837 if( (aOriginalSize.Width > 0) && (aOriginalSize.Height > 0) )
838 {
839 // size of one bitmap tile (given as 1/1000 percent of bitmap size), convert to 1/100 mm
840 double fScaleX = maBlipProps.moTileScaleX.value_or( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
841 sal_Int32 nFillBmpSizeX = getLimitedValue< sal_Int32, double >( aOriginalSize.Width * fScaleX, 1, SAL_MAX_INT32 );
842 rPropMap.setProperty( ShapeProperty::FillBitmapSizeX, nFillBmpSizeX );
843 double fScaleY = maBlipProps.moTileScaleY.value_or( MAX_PERCENT ) / static_cast< double >( MAX_PERCENT );
844 sal_Int32 nFillBmpSizeY = getLimitedValue< sal_Int32, double >( aOriginalSize.Height * fScaleY, 1, SAL_MAX_INT32 );
845 rPropMap.setProperty( ShapeProperty::FillBitmapSizeY, nFillBmpSizeY );
846
847 awt::Size aBmpSize(nFillBmpSizeX, nFillBmpSizeY);
848 // offset of the first bitmap tile (given as EMUs), convert to percent
849 sal_Int16 nTileOffsetX = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetX.value_or( 0 ) / 3.6 / aBmpSize.Width), 0, 100 );
850 rPropMap.setProperty( ShapeProperty::FillBitmapOffsetX, nTileOffsetX );
851 sal_Int16 nTileOffsetY = getDoubleIntervalValue< sal_Int16 >(std::round(maBlipProps.moTileOffsetY.value_or( 0 ) / 3.6 / aBmpSize.Height), 0, 100 );
852 rPropMap.setProperty( ShapeProperty::FillBitmapOffsetY, nTileOffsetY );
853 }
854 }
855 else if ( eBitmapMode == BitmapMode_STRETCH && maBlipProps.moFillRect.has_value() )
856 {
857 geometry::IntegerRectangle2D aFillRect( maBlipProps.moFillRect.value() );
858 awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
859 if ( aOriginalSize.Width && aOriginalSize.Height )
860 {
861 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
862 if ( aFillRect.X1 )
863 aGraphCrop.Left = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X1 ) / 100000 );
864 if ( aFillRect.Y1 )
865 aGraphCrop.Top = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y1 ) / 100000 );
866 if ( aFillRect.X2 )
867 aGraphCrop.Right = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Width ) * aFillRect.X2 ) / 100000 );
868 if ( aFillRect.Y2 )
869 aGraphCrop.Bottom = static_cast< sal_Int32 >( ( static_cast< double >( aOriginalSize.Height ) * aFillRect.Y2 ) / 100000 );
870
871 bool bHasCropValues = aGraphCrop.Left != 0 || aGraphCrop.Right !=0 || aGraphCrop.Top != 0 || aGraphCrop.Bottom != 0;
872 // Negative GraphicCrop values means "crop" here.
873 bool bNeedCrop = aGraphCrop.Left <= 0 && aGraphCrop.Right <= 0 && aGraphCrop.Top <= 0 && aGraphCrop.Bottom <= 0;
874
875 if (bHasCropValues)
876 {
877 if (bIsCustomShape && bNeedCrop)
878 {
879 // Physically crop the image
880 // In this case, don't set the PROP_GraphicCrop because that
881 // would lead to applying the crop twice after roundtrip
882 xGraphic = lclCropGraphic(xGraphic, CropQuotientsFromFillRect(aFillRect));
884 rPropMap.setProperty(ShapeProperty::FillBitmapName, xGraphic);
885 else
886 rPropMap.setProperty(ShapeProperty::FillBitmap, xGraphic);
887 }
888 else if ((aFillRect.X1 != 0 && aFillRect.X2 != 0
889 && aFillRect.X1 != aFillRect.X2)
890 || (aFillRect.Y1 != 0 && aFillRect.Y2 != 0
891 && aFillRect.Y1 != aFillRect.Y2))
892 {
893 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
894 }
895 else
896 {
897 double nL = aFillRect.X1 / static_cast<double>(MAX_PERCENT);
898 double nT = aFillRect.Y1 / static_cast<double>(MAX_PERCENT);
899 double nR = aFillRect.X2 / static_cast<double>(MAX_PERCENT);
900 double nB = aFillRect.Y2 / static_cast<double>(MAX_PERCENT);
901
902 sal_Int32 nSizeX;
903 if (nL || nR)
904 nSizeX = rSize.Width * (1 - (nL + nR));
905 else
906 nSizeX = rSize.Width;
908
909 sal_Int32 nSizeY;
910 if (nT || nB)
911 nSizeY = rSize.Height * (1 - (nT + nB));
912 else
913 nSizeY = rSize.Height;
915
916 RectanglePoint eRectPoint;
917 if (!aFillRect.X1 && aFillRect.X2)
918 {
919 if (!aFillRect.Y1 && aFillRect.Y2)
920 eRectPoint = lclGetRectanglePoint(XML_tl);
921 else if (aFillRect.Y1 && !aFillRect.Y2)
922 eRectPoint = lclGetRectanglePoint(XML_bl);
923 else
924 eRectPoint = lclGetRectanglePoint(XML_l);
925 }
926 else if (aFillRect.X1 && !aFillRect.X2)
927 {
928 if (!aFillRect.Y1 && aFillRect.Y2)
929 eRectPoint = lclGetRectanglePoint(XML_tr);
930 else if (aFillRect.Y1 && !aFillRect.Y2)
931 eRectPoint = lclGetRectanglePoint(XML_br);
932 else
933 eRectPoint = lclGetRectanglePoint(XML_r);
934 }
935 else
936 {
937 if (!aFillRect.Y1 && aFillRect.Y2)
938 eRectPoint = lclGetRectanglePoint(XML_t);
939 else if (aFillRect.Y1 && !aFillRect.Y2)
940 eRectPoint = lclGetRectanglePoint(XML_b);
941 else
942 eRectPoint = lclGetRectanglePoint(XML_ctr);
943 }
945 eBitmapMode = BitmapMode_NO_REPEAT;
946 }
947 }
948 }
949 }
950 rPropMap.setProperty(ShapeProperty::FillBitmapMode, eBitmapMode);
951 }
952
953 if (maBlipProps.moAlphaModFix.has_value())
954 rPropMap.setProperty(ShapeProperty::FillTransparency, static_cast<sal_Int16>(100 - (maBlipProps.moAlphaModFix.value() / PER_PERCENT)));
955 }
956 break;
957
958 case XML_pattFill:
959 {
961 {
963 if( aColor.isUsed() && maPatternProps.moPattPreset.has_value() )
964 {
965 eFillStyle = FillStyle_HATCH;
966 rPropMap.setProperty( ShapeProperty::FillHatch, createHatch( maPatternProps.moPattPreset.value(), aColor.getColor( rGraphicHelper, nPhClr ) ) );
967 if( aColor.hasTransparency() )
969
970 // Set background color for hatch
972 {
974 rPropMap.setProperty( ShapeProperty::FillBackground, aColor.getTransparency() != 100 );
975 rPropMap.setProperty( ShapeProperty::FillColor, aColor.getColor( rGraphicHelper, nPhClr ) );
976 }
977 }
979 {
981 rPropMap.setProperty( ShapeProperty::FillColor, aColor.getColor( rGraphicHelper, nPhClr ) );
982 if( aColor.hasTransparency() )
984 eFillStyle = FillStyle_SOLID;
985 }
986 }
987 }
988 break;
989
990 case XML_grpFill:
991 // todo
992 eFillStyle = FillStyle_NONE;
993 break;
994 }
995
996 // set final fill style property
997 rPropMap.setProperty( ShapeProperty::FillStyle, eFillStyle );
998}
999
1000void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, bool bFlipH, bool bFlipV) const
1001{
1002 sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.value_or( 0 ) / PER_PERCENT, -100, 100 );
1003 sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.value_or( 0 ) / PER_PERCENT, -100, 100 );
1004 ColorMode eColorMode = ColorMode_STANDARD;
1005
1006 switch( maBlipProps.moColorEffect.value_or( XML_TOKEN_INVALID ) )
1007 {
1008 case XML_biLevel: eColorMode = ColorMode_MONO; break;
1009 case XML_grayscl: eColorMode = ColorMode_GREYS; break;
1010 }
1011
1012 if (maBlipProps.mxFillGraphic.is())
1013 {
1014 // created transformed graphic
1015 uno::Reference<graphic::XGraphic> xGraphic = lclCheckAndApplyChangeColorTransform(maBlipProps, maBlipProps.mxFillGraphic, rGraphicHelper, API_RGB_TRANSPARENT);
1016 xGraphic = lclCheckAndApplyDuotoneTransform(maBlipProps, xGraphic, rGraphicHelper, API_RGB_TRANSPARENT);
1017
1018 if( eColorMode == ColorMode_MONO )
1019 {
1020 // ColorMode_MONO is the same with MSO's biLevel with 50000 (50%) threshold,
1021 // when threshold isn't 50000 bake the effect instead.
1022 if( maBlipProps.moBiLevelThreshold != 50000 )
1023 {
1024 xGraphic = lclApplyBlackWhiteEffect(maBlipProps, xGraphic);
1025 eColorMode = ColorMode_STANDARD;
1026 }
1027 }
1028
1029 if (eColorMode == ColorMode_STANDARD && nBrightness == 70 && nContrast == -70)
1030 {
1031 // map MSO 'washout' to our Watermark colormode
1032 eColorMode = ColorMode_WATERMARK;
1033 nBrightness = 0;
1034 nContrast = 0;
1035 }
1036 else if( nBrightness != 0 && nContrast != 0 )
1037 {
1038 // MSO uses a different algorithm for contrast+brightness, LO applies contrast before brightness,
1039 // while MSO apparently applies half of brightness before contrast and half after. So if only
1040 // contrast or brightness need to be altered, the result is the same, but if both are involved,
1041 // there's no way to map that, so just force a conversion of the image.
1042 xGraphic = applyBrightnessContrast( xGraphic, nBrightness, nContrast );
1043 nBrightness = 0;
1044 nContrast = 0;
1045 }
1046
1047 // cropping
1048 if ( maBlipProps.moClipRect.has_value() )
1049 {
1050 geometry::IntegerRectangle2D oClipRect( maBlipProps.moClipRect.value() );
1051 awt::Size aOriginalSize( rGraphicHelper.getOriginalSize( xGraphic ) );
1052 if ( aOriginalSize.Width && aOriginalSize.Height )
1053 {
1054 text::GraphicCrop aGraphCrop( 0, 0, 0, 0 );
1055 if ( oClipRect.X1 )
1056 aGraphCrop.Left = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X1 ) / 100000 );
1057 if ( oClipRect.Y1 )
1058 aGraphCrop.Top = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y1 ) / 100000 );
1059 if ( oClipRect.X2 )
1060 aGraphCrop.Right = rtl::math::round( ( static_cast< double >( aOriginalSize.Width ) * oClipRect.X2 ) / 100000 );
1061 if ( oClipRect.Y2 )
1062 aGraphCrop.Bottom = rtl::math::round( ( static_cast< double >( aOriginalSize.Height ) * oClipRect.Y2 ) / 100000 );
1063 rPropMap.setProperty(PROP_GraphicCrop, aGraphCrop);
1064
1065 bool bHasCropValues = aGraphCrop.Left != 0 || aGraphCrop.Right !=0 || aGraphCrop.Top != 0 || aGraphCrop.Bottom != 0;
1066 // Positive GraphicCrop values means "crop" here.
1067 bool bNeedCrop = aGraphCrop.Left >= 0 && aGraphCrop.Right >= 0 && aGraphCrop.Top >= 0 && aGraphCrop.Bottom >= 0;
1068
1069 if(mbIsCustomShape && bHasCropValues && bNeedCrop)
1070 {
1071 xGraphic = lclCropGraphic(xGraphic, CropQuotientsFromSrcRect(oClipRect));
1072 }
1073 }
1074 }
1075
1076 if(mbIsCustomShape)
1077 {
1078 // it is a cropped graphic.
1079 rPropMap.setProperty(PROP_FillStyle, FillStyle_BITMAP);
1080 rPropMap.setProperty(PROP_FillBitmapMode, BitmapMode_STRETCH);
1081
1082 // It is a bitmap filled and rotated graphic.
1083 // When custom shape is rotated, bitmap have to be rotated too.
1084 if(rPropMap.hasProperty(PROP_RotateAngle))
1085 {
1086 tools::Long nAngle = rPropMap.getProperty(PROP_RotateAngle).get<tools::Long>();
1087 xGraphic = lclRotateGraphic(xGraphic, Degree10(nAngle/10) );
1088 }
1089
1090 // We have not core feature that flips graphic in the shape.
1091 // Here we are applying flip property to bitmap directly.
1092 if(bFlipH || bFlipV)
1093 xGraphic = lclMirrorGraphic(xGraphic, bFlipH, bFlipV );
1094
1095 if(eColorMode == ColorMode_GREYS)
1096 xGraphic = lclGreysScaleGraphic( xGraphic );
1097
1098 rPropMap.setProperty(PROP_FillBitmap, xGraphic);
1099 }
1100 else
1101 rPropMap.setProperty(PROP_Graphic, xGraphic);
1102
1103
1104 if ( maBlipProps.moAlphaModFix.has_value() )
1105 {
1106 rPropMap.setProperty(PROP_Transparency, static_cast<sal_Int16>(100 - (maBlipProps.moAlphaModFix.value() / PER_PERCENT)));
1107 }
1108 }
1109 rPropMap.setProperty(PROP_GraphicColorMode, eColorMode);
1110
1111 // brightness and contrast
1112 if( nBrightness != 0 )
1113 rPropMap.setProperty(PROP_AdjustLuminance, nBrightness);
1114 if( nContrast != 0 )
1115 rPropMap.setProperty(PROP_AdjustContrast, nContrast);
1116
1117 // Media content
1118 if (!m_sMediaPackageURL.isEmpty())
1119 {
1120 rPropMap.setProperty(PROP_MediaURL, m_sMediaPackageURL);
1121 if (m_xMediaStream.is())
1122 rPropMap.setProperty(PROP_PrivateStream, m_xMediaStream);
1123 }
1124}
1125
1127{
1128 return msName.isEmpty();
1129}
1130
1131css::beans::PropertyValue ArtisticEffectProperties::getEffect()
1132{
1133 css::beans::PropertyValue aRet;
1134 if( msName.isEmpty() )
1135 return aRet;
1136
1137 css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() + 1 );
1138 auto pSeq = aSeq.getArray();
1139 sal_uInt32 i = 0;
1140 for (auto const& attrib : maAttribs)
1141 {
1142 pSeq[i].Name = attrib.first;
1143 pSeq[i].Value = attrib.second;
1144 i++;
1145 }
1146
1147 if( mrOleObjectInfo.maEmbeddedData.hasElements() )
1148 {
1149 css::uno::Sequence< css::beans::PropertyValue > aGraphicSeq{
1152 };
1153
1154 pSeq[i].Name = "OriginalGraphic";
1155 pSeq[i].Value <<= aGraphicSeq;
1156 }
1157
1158 aRet.Name = msName;
1159 aRet.Value <<= aSeq;
1160
1161 return aRet;
1162}
1163
1165{
1166 if( !rSourceProps.isEmpty() )
1167 {
1168 msName = rSourceProps.msName;
1169 maAttribs = rSourceProps.maAttribs;
1170 }
1171}
1172
1174{
1175 switch( nToken )
1176 {
1177 // effects
1178 case OOX_TOKEN( a14, artisticBlur ): return "artisticBlur";
1179 case OOX_TOKEN( a14, artisticCement ): return "artisticCement";
1180 case OOX_TOKEN( a14, artisticChalkSketch ): return "artisticChalkSketch";
1181 case OOX_TOKEN( a14, artisticCrisscrossEtching ): return "artisticCrisscrossEtching";
1182 case OOX_TOKEN( a14, artisticCutout ): return "artisticCutout";
1183 case OOX_TOKEN( a14, artisticFilmGrain ): return "artisticFilmGrain";
1184 case OOX_TOKEN( a14, artisticGlass ): return "artisticGlass";
1185 case OOX_TOKEN( a14, artisticGlowDiffused ): return "artisticGlowDiffused";
1186 case OOX_TOKEN( a14, artisticGlowEdges ): return "artisticGlowEdges";
1187 case OOX_TOKEN( a14, artisticLightScreen ): return "artisticLightScreen";
1188 case OOX_TOKEN( a14, artisticLineDrawing ): return "artisticLineDrawing";
1189 case OOX_TOKEN( a14, artisticMarker ): return "artisticMarker";
1190 case OOX_TOKEN( a14, artisticMosiaicBubbles ): return "artisticMosiaicBubbles";
1191 case OOX_TOKEN( a14, artisticPaintStrokes ): return "artisticPaintStrokes";
1192 case OOX_TOKEN( a14, artisticPaintBrush ): return "artisticPaintBrush";
1193 case OOX_TOKEN( a14, artisticPastelsSmooth ): return "artisticPastelsSmooth";
1194 case OOX_TOKEN( a14, artisticPencilGrayscale ): return "artisticPencilGrayscale";
1195 case OOX_TOKEN( a14, artisticPencilSketch ): return "artisticPencilSketch";
1196 case OOX_TOKEN( a14, artisticPhotocopy ): return "artisticPhotocopy";
1197 case OOX_TOKEN( a14, artisticPlasticWrap ): return "artisticPlasticWrap";
1198 case OOX_TOKEN( a14, artisticTexturizer ): return "artisticTexturizer";
1199 case OOX_TOKEN( a14, artisticWatercolorSponge ): return "artisticWatercolorSponge";
1200 case OOX_TOKEN( a14, brightnessContrast ): return "brightnessContrast";
1201 case OOX_TOKEN( a14, colorTemperature ): return "colorTemperature";
1202 case OOX_TOKEN( a14, saturation ): return "saturation";
1203 case OOX_TOKEN( a14, sharpenSoften ): return "sharpenSoften";
1204
1205 // attributes
1206 case XML_visible: return "visible";
1207 case XML_trans: return "trans";
1208 case XML_crackSpacing: return "crackSpacing";
1209 case XML_pressure: return "pressure";
1210 case XML_numberOfShades: return "numberOfShades";
1211 case XML_grainSize: return "grainSize";
1212 case XML_intensity: return "intensity";
1213 case XML_smoothness: return "smoothness";
1214 case XML_gridSize: return "gridSize";
1215 case XML_pencilSize: return "pencilSize";
1216 case XML_size: return "size";
1217 case XML_brushSize: return "brushSize";
1218 case XML_scaling: return "scaling";
1219 case XML_detail: return "detail";
1220 case XML_bright: return "bright";
1221 case XML_contrast: return "contrast";
1222 case XML_colorTemp: return "colorTemp";
1223 case XML_sat: return "sat";
1224 case XML_amount: return "amount";
1225 }
1226 SAL_WARN( "oox.drawingml", "ArtisticEffectProperties::getEffectString: unexpected token " << nToken );
1227 return OUString();
1228}
1229
1231{
1232 // effects
1233 if( sName == "artisticBlur" )
1234 return XML_artisticBlur;
1235 else if( sName == "artisticCement" )
1236 return XML_artisticCement;
1237 else if( sName == "artisticChalkSketch" )
1238 return XML_artisticChalkSketch;
1239 else if( sName == "artisticCrisscrossEtching" )
1240 return XML_artisticCrisscrossEtching;
1241 else if( sName == "artisticCutout" )
1242 return XML_artisticCutout;
1243 else if( sName == "artisticFilmGrain" )
1244 return XML_artisticFilmGrain;
1245 else if( sName == "artisticGlass" )
1246 return XML_artisticGlass;
1247 else if( sName == "artisticGlowDiffused" )
1248 return XML_artisticGlowDiffused;
1249 else if( sName == "artisticGlowEdges" )
1250 return XML_artisticGlowEdges;
1251 else if( sName == "artisticLightScreen" )
1252 return XML_artisticLightScreen;
1253 else if( sName == "artisticLineDrawing" )
1254 return XML_artisticLineDrawing;
1255 else if( sName == "artisticMarker" )
1256 return XML_artisticMarker;
1257 else if( sName == "artisticMosiaicBubbles" )
1258 return XML_artisticMosiaicBubbles;
1259 else if( sName == "artisticPaintStrokes" )
1260 return XML_artisticPaintStrokes;
1261 else if( sName == "artisticPaintBrush" )
1262 return XML_artisticPaintBrush;
1263 else if( sName == "artisticPastelsSmooth" )
1264 return XML_artisticPastelsSmooth;
1265 else if( sName == "artisticPencilGrayscale" )
1266 return XML_artisticPencilGrayscale;
1267 else if( sName == "artisticPencilSketch" )
1268 return XML_artisticPencilSketch;
1269 else if( sName == "artisticPhotocopy" )
1270 return XML_artisticPhotocopy;
1271 else if( sName == "artisticPlasticWrap" )
1272 return XML_artisticPlasticWrap;
1273 else if( sName == "artisticTexturizer" )
1274 return XML_artisticTexturizer;
1275 else if( sName == "artisticWatercolorSponge" )
1276 return XML_artisticWatercolorSponge;
1277 else if( sName == "brightnessContrast" )
1278 return XML_brightnessContrast;
1279 else if( sName == "colorTemperature" )
1280 return XML_colorTemperature;
1281 else if( sName == "saturation" )
1282 return XML_saturation;
1283 else if( sName == "sharpenSoften" )
1284 return XML_sharpenSoften;
1285
1286 // attributes
1287 else if( sName == "visible" )
1288 return XML_visible;
1289 else if( sName == "trans" )
1290 return XML_trans;
1291 else if( sName == "crackSpacing" )
1292 return XML_crackSpacing;
1293 else if( sName == "pressure" )
1294 return XML_pressure;
1295 else if( sName == "numberOfShades" )
1296 return XML_numberOfShades;
1297 else if( sName == "grainSize" )
1298 return XML_grainSize;
1299 else if( sName == "intensity" )
1300 return XML_intensity;
1301 else if( sName == "smoothness" )
1302 return XML_smoothness;
1303 else if( sName == "gridSize" )
1304 return XML_gridSize;
1305 else if( sName == "pencilSize" )
1306 return XML_pencilSize;
1307 else if( sName == "size" )
1308 return XML_size;
1309 else if( sName == "brushSize" )
1310 return XML_brushSize;
1311 else if( sName == "scaling" )
1312 return XML_scaling;
1313 else if( sName == "detail" )
1314 return XML_detail;
1315 else if( sName == "bright" )
1316 return XML_bright;
1317 else if( sName == "contrast" )
1318 return XML_contrast;
1319 else if( sName == "colorTemp" )
1320 return XML_colorTemp;
1321 else if( sName == "sat" )
1322 return XML_sat;
1323 else if( sName == "amount" )
1324 return XML_amount;
1325
1326 SAL_WARN( "oox.drawingml", "ArtisticEffectProperties::getEffectToken - unexpected token name: " << sName );
1327 return XML_none;
1328}
1329
1330} // namespace oox
1331
1332/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
const AlphaMask & GetAlphaMask() const
bool Convert(BmpConversion eConversion)
bool Mirror(BmpMirrorFlags nMirrorFlags)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
bool Crop(const tools::Rectangle &rRectPixel)
const Size & GetSizePixel() const
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
void setOriginURL(OUString const &rOriginURL)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void addTransformation(Transformation const &rTransform)
void setType(ThemeColorType eType)
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
css::awt::Size getOriginalSize(const css::uno::Reference< css::graphic::XGraphic > &rxGraphic) const
calculates the original size of a graphic which is necessary to be able to calculate cropping values
css::awt::Size convertScreenPixelToHmm(const css::awt::Size &rPixel) const
Converts the passed size from screen pixels to 1/100 mm.
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
css::uno::Any getProperty(sal_Int32 nPropId)
bool hasProperty(sal_Int32 nPropId) const
Returns true, if the map contains a property with the passed identifier.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
Definition: propertymap.hxx:72
sal_Int16 getTintOrShade() const
Definition: color.cxx:525
sal_Int16 getLumMod() const
Definition: color.cxx:542
sal_Int16 getTransparency() const
Returns the transparency of the color (0 = opaque, 100 = full transparent).
Definition: color.cxx:751
void assignIfUsed(const Color &rColor)
Overwrites this color with the passed color, if it is used.
Definition: color.hxx:87
sal_Int16 getLumOff() const
Definition: color.cxx:558
bool isUsed() const
Returns true, if the color is initialized.
Definition: color.hxx:90
bool hasTransparency() const
Returns true, if the color is transparent.
Definition: color.cxx:746
sal_Int16 getSchemeColorIndex() const
Definition: color.cxx:756
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
Returns the final RGB color value.
Definition: color.cxx:574
bool setProperty(ShapeProperty ePropId, const Type &rValue)
Sets the specified shape property to the passed value.
bool supportsProperty(ShapeProperty ePropId) const
Returns true, if the specified property is supported.
OString sName
Definition: drawingml.cxx:4304
static drawing::Hatch createHatch(sal_Int32 nHatchToken, ::Color nColor)
Definition: hatchmap.hxx:18
BmpMirrorFlags
sal_Int32 nIndex
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
tools::Long const nBorder
enum SAL_DLLPUBLIC_RTTI FillStyle
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
uno::Reference< util::XThemeColor > createXThemeColor(model::ThemeColor const &rThemeColor)
constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
@ FillBitmap
Explicit fill bitmap or name of a fill bitmap stored in a global container.
@ FillGradient
Explicit fill gradient or name of a fill gradient stored in a global container.
@ FillHatch
Explicit fill hatch or name of a fill hatch stored in a global container.
const sal_Int32 MAX_PERCENT
const sal_Int32 PER_DEGREE
const sal_Int32 PER_PERCENT
void assignIfUsed(std::optional< Type > &rDestValue, const std::optional< Type > &rSourceValue)
Definition: helper.hxx:174
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Transparent color for API calls.
XML_none
long Long
BitmapMode
XML_TOKEN_INVALID
DefTokenId nToken
bool isEmpty() const
The original graphic as embedded object.
css::beans::PropertyValue getEffect()
Returns the struct as a PropertyValue with Name = msName and Value = maAttribs as a Sequence< Propert...
void assignUsed(const ArtisticEffectProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
::oox::ole::OleObjectInfo mrOleObjectInfo
std::map< OUString, css::uno::Any > maAttribs
static OUString getEffectString(sal_Int32 nToken)
Translate effect tokens to strings.
static sal_Int32 getEffectToken(const OUString &sName)
Translate effect strings to tokens.
std::optional< css::geometry::IntegerRectangle2D > moClipRect
Stretch fill offsets.
Color maColorChangeTo
Start color of color transformation.
std::optional< css::geometry::IntegerRectangle2D > moFillRect
Bitmap tile or stretch.
std::optional< sal_Int32 > moColorEffect
True = rotate bitmap with shape.
std::optional< sal_Int32 > moBitmapMode
The fill graphic.
std::optional< sal_Int32 > moTileFlip
Anchor point inside bitmap.
Color maDuotoneColors[2]
Destination color of color transformation.
std::optional< sal_Int32 > moAlphaModFix
Artistic effect, not supported by core.
std::optional< sal_Int32 > moTileScaleY
Horizontal scaling of bitmap tiles (1/1000 percent).
std::optional< sal_Int32 > moTileOffsetY
Width of bitmap tiles (EMUs).
std::optional< sal_Int32 > moBrightness
XML token for a color effect.
Color maColorChangeFrom
Bi-Level (Black/White) effect threshold (1/1000 percent)
std::optional< bool > moRotateWithShape
Flip mode of bitmap tiles.
std::optional< sal_Int32 > moBiLevelThreshold
Contrast in the range [-100000,100000].
css::uno::Reference< css::graphic::XGraphic > mxFillGraphic
ArtisticEffectProperties maEffect
Duotone Colors.
void assignUsed(const BlipFillProperties &rSourceProps)
Overwrites all members that are explicitly set in rSourceProps.
std::optional< sal_Int32 > moTileAlign
Vertical scaling of bitmap tiles (1/1000 percent).
std::optional< sal_Int32 > moTileScaleX
Height of bitmap tiles (EMUs).
std::optional< sal_Int32 > moTileOffsetX
std::optional< sal_Int32 > moContrast
Brightness in the range [-100000,100000].
PatternFillProperties maPatternProps
Properties for gradient fills.
GradientFillProperties maGradientProps
Whether the background is used as fill type.
BlipFillProperties maBlipProps
Properties for pattern fills.
void pushToPropMap(ShapePropertyMap &rPropMap, const GraphicHelper &rGraphicHelper, sal_Int32 nShapeRotation=0, ::Color nPhClr=API_RGB_TRANSPARENT, const css::awt::Size &rSize={}, sal_Int16 nPhClrTheme=-1, bool bFlipH=false, bool bFlipV=false, bool bIsCustomShape=false) const
Writes the properties to the passed property map.
void assignUsed(const FillProperties &rSourceProps)
Properties for bitmap fills.
Color getBestSolidColor() const
Tries to resolve current settings to a solid color, e.g.
std::optional< bool > moUseBgFill
Solid fill color and transparence.
Color maFillColor
Fill type (OOXML token).
std::optional< sal_Int32 > moFillType
std::optional< css::geometry::IntegerRectangle2D > moFillToRect
Gradient stops (colors/transparence).
std::optional< sal_Int32 > moShadeFlip
Rotation angle of linear gradients.
std::optional< bool > moRotateWithShape
True = scale gradient into shape.
std::optional< sal_Int32 > moGradientPath
void assignUsed(const GradientFillProperties &rSourceProps)
True = rotate gradient with shape.
std::optional< css::geometry::IntegerRectangle2D > moTileRect
std::optional< bool > moShadeScaled
Flip mode of gradient, if not stretched to shape.
std::optional< sal_Int32 > moShadeAngle
If set, gradient follows rectangle, circle, or shape.
::std::multimap< double, Color > GradientStopMap
OUString m_sMediaPackageURL
Audio/Video URL.
css::uno::Reference< css::io::XInputStream > m_xMediaStream
Audio/Video input stream.
void pushToPropMap(PropertyMap &rPropMap, const GraphicHelper &rGraphicHelper, bool bFlipH=false, bool bFlipV=false) const
Writes the properties to the passed property map.
BlipFillProperties maBlipProps
Properties for the graphic.
Color maPattBgColor
Pattern foreground color.
std::optional< sal_Int32 > moPattPreset
Pattern background color.
void assignUsed(const PatternFillProperties &rSourceProps)
Preset pattern type.
StreamDataSequence maEmbeddedData
Data of an embedded OLE object.
unsigned char sal_uInt8
#define SAL_MAX_INT32
signed char sal_Int8
constexpr OUStringLiteral PROP_FillBitmapMode
constexpr OUStringLiteral PROP_GraphicColorMode
constexpr OUStringLiteral PROP_AdjustLuminance
constexpr OUStringLiteral PROP_RotateAngle
constexpr OUStringLiteral PROP_AdjustContrast
constexpr OUStringLiteral PROP_Transparency
constexpr OUStringLiteral PROP_FillColorThemeReference
constexpr OUStringLiteral PROP_GraphicCrop
constexpr OUStringLiteral PROP_FillStyle