f085be
From 28bd6fe0c4fdca575ef078d6e5ff2a5acb852ac3 Mon Sep 17 00:00:00 2001
f085be
From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= <tomaz.vajngerl@collabora.com>
f085be
Date: Sat, 19 Jul 2014 21:52:09 +0200
f085be
Subject: [PATCH 045/137] emf+: emulate hatch with color blend
f085be
f085be
Conflicts:
f085be
	cppcanvas/source/mtfrenderer/emfplus.cxx
f085be
f085be
Change-Id: I2ac8f790c79c269d4c1fa650e703c3645c567ca4
f085be
Reviewed-on: https://gerrit.libreoffice.org/10436
f085be
Reviewed-by: Andras Timar <andras.timar@collabora.com>
f085be
Tested-by: Andras Timar <andras.timar@collabora.com>
f085be
---
f085be
 cppcanvas/source/mtfrenderer/emfplus.cxx | 134 ++++++++++++++++++++++++++++++-
f085be
 1 file changed, 132 insertions(+), 2 deletions(-)
f085be
f085be
diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx
f085be
index 0c53c59..e6b1ea8 100644
f085be
--- a/cppcanvas/source/mtfrenderer/emfplus.cxx
f085be
+++ b/cppcanvas/source/mtfrenderer/emfplus.cxx
f085be
@@ -123,6 +123,63 @@ enum EmfPlusCombineMode
f085be
     EmfPlusCombineModeComplement = 0x00000005
f085be
 };
f085be
 
f085be
+enum EmfPlusHatchStyle
f085be
+{
f085be
+    HatchStyleHorizontal = 0x00000000,
f085be
+    HatchStyleVertical = 0x00000001,
f085be
+    HatchStyleForwardDiagonal = 0x00000002,
f085be
+    HatchStyleBackwardDiagonal = 0x00000003,
f085be
+    HatchStyleLargeGrid = 0x00000004,
f085be
+    HatchStyleDiagonalCross = 0x00000005,
f085be
+    HatchStyle05Percent = 0x00000006,
f085be
+    HatchStyle10Percent = 0x00000007,
f085be
+    HatchStyle20Percent = 0x00000008,
f085be
+    HatchStyle25Percent = 0x00000009,
f085be
+    HatchStyle30Percent = 0x0000000A,
f085be
+    HatchStyle40Percent = 0x0000000B,
f085be
+    HatchStyle50Percent = 0x0000000C,
f085be
+    HatchStyle60Percent = 0x0000000D,
f085be
+    HatchStyle70Percent = 0x0000000E,
f085be
+    HatchStyle75Percent = 0x0000000F,
f085be
+    HatchStyle80Percent = 0x00000010,
f085be
+    HatchStyle90Percent = 0x00000011,
f085be
+    HatchStyleLightDownwardDiagonal = 0x00000012,
f085be
+    HatchStyleLightUpwardDiagonal = 0x00000013,
f085be
+    HatchStyleDarkDownwardDiagonal = 0x00000014,
f085be
+    HatchStyleDarkUpwardDiagonal = 0x00000015,
f085be
+    HatchStyleWideDownwardDiagonal = 0x00000016,
f085be
+    HatchStyleWideUpwardDiagonal = 0x00000017,
f085be
+    HatchStyleLightVertical = 0x00000018,
f085be
+    HatchStyleLightHorizontal = 0x00000019,
f085be
+    HatchStyleNarrowVertical = 0x0000001A,
f085be
+    HatchStyleNarrowHorizontal = 0x0000001B,
f085be
+    HatchStyleDarkVertical = 0x0000001C,
f085be
+    HatchStyleDarkHorizontal = 0x0000001D,
f085be
+    HatchStyleDashedDownwardDiagonal = 0x0000001E,
f085be
+    HatchStyleDashedUpwardDiagonal = 0x0000001F,
f085be
+    HatchStyleDashedHorizontal = 0x00000020,
f085be
+    HatchStyleDashedVertical = 0x00000021,
f085be
+    HatchStyleSmallConfetti = 0x00000022,
f085be
+    HatchStyleLargeConfetti = 0x00000023,
f085be
+    HatchStyleZigZag = 0x00000024,
f085be
+    HatchStyleWave = 0x00000025,
f085be
+    HatchStyleDiagonalBrick = 0x00000026,
f085be
+    HatchStyleHorizontalBrick = 0x00000027,
f085be
+    HatchStyleWeave = 0x00000028,
f085be
+    HatchStylePlaid = 0x00000029,
f085be
+    HatchStyleDivot = 0x0000002A,
f085be
+    HatchStyleDottedGrid = 0x0000002B,
f085be
+    HatchStyleDottedDiamond = 0x0000002C,
f085be
+    HatchStyleShingle = 0x0000002D,
f085be
+    HatchStyleTrellis = 0x0000002E,
f085be
+    HatchStyleSphere = 0x0000002F,
f085be
+    HatchStyleSmallGrid = 0x00000030,
f085be
+    HatchStyleSmallCheckerBoard = 0x00000031,
f085be
+    HatchStyleLargeCheckerBoard = 0x00000032,
f085be
+    HatchStyleOutlinedDiamond = 0x00000033,
f085be
+    HatchStyleSolidDiamond = 0x00000034
f085be
+};
f085be
+
f085be
 using namespace ::com::sun::star;
f085be
 using namespace ::basegfx;
f085be
 
f085be
@@ -362,9 +419,28 @@ namespace cppcanvas
f085be
             sal_Int32 surroundColorsNumber;
f085be
             ::Color* surroundColors;
f085be
             EMFPPath *path;
f085be
+            EmfPlusHatchStyle hatchStyle;
f085be
 
f085be
         public:
f085be
             EMFPBrush ()
f085be
+                : type(0)
f085be
+                , additionalFlags(0)
f085be
+                , wrapMode(0)
f085be
+                , areaX(0.0)
f085be
+                , areaY(0.0)
f085be
+                , areaWidth(0.0)
f085be
+                , areaHeight(0.0)
f085be
+                , hasTransformation(false)
f085be
+                , blendPoints(0)
f085be
+                , blendPositions(NULL)
f085be
+                , blendFactors(NULL)
f085be
+                , colorblendPoints(0)
f085be
+                , colorblendPositions(NULL)
f085be
+                , colorblendColors(NULL)
f085be
+                , surroundColorsNumber(0)
f085be
+                , surroundColors(NULL)
f085be
+                , path(NULL)
f085be
+                , hatchStyle(HatchStyleHorizontal)
f085be
             {
f085be
                 blendPositions = NULL;
f085be
                 colorblendPositions = NULL;
f085be
@@ -418,7 +494,20 @@ namespace cppcanvas
f085be
                         s >> color;
f085be
                         solidColor = ::Color (0xff - (color >> 24), (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff);
f085be
                         SAL_INFO ("cppcanvas.emf", "EMF+\tsolid color: 0x" << std::hex << color << std::dec);
f085be
-
f085be
+                        break;
f085be
+                    }
f085be
+                case 1:
f085be
+                    {
f085be
+                        sal_uInt32 style;
f085be
+                        sal_uInt32 foregroundColor;
f085be
+                        sal_uInt32 backgroundColor;
f085be
+                        s >> style;
f085be
+                        s >> foregroundColor;
f085be
+                        s >> backgroundColor;
f085be
+
f085be
+                        hatchStyle = static_cast<EmfPlusHatchStyle>(style);
f085be
+                        solidColor  = ::Color(0xff - (foregroundColor >> 24), (foregroundColor >> 16) & 0xff, (foregroundColor >> 8) & 0xff, foregroundColor & 0xff);
f085be
+                        secondColor = ::Color(0xff - (backgroundColor >> 24), (backgroundColor >> 16) & 0xff, (backgroundColor >> 8) & 0xff, backgroundColor & 0xff);
f085be
                         break;
f085be
                     }
f085be
                 // path gradient
f085be
@@ -1157,8 +1246,49 @@ namespace cppcanvas
f085be
                 rState.isFillColorSet = false;
f085be
                 rState.isLineColorSet = false;
f085be
 
f085be
-                if (brush->type == 3 || brush->type == 4) {
f085be
+                if (brush->type == 1)
f085be
+                {
f085be
+                    // EMF+ like hatching is currently not supported. These are just color blends which serve as an approximation for some of them
f085be
+                    // for the others the hatch "background" color (secondColor in brush) is used.
f085be
 
f085be
+                    bool isHatchBlend = true;
f085be
+                    double blendFactor = 0.0;
f085be
+
f085be
+                    switch (brush->hatchStyle)
f085be
+                    {
f085be
+                        case HatchStyle05Percent: blendFactor = 0.05; break;
f085be
+                        case HatchStyle10Percent: blendFactor = 0.10; break;
f085be
+                        case HatchStyle20Percent: blendFactor = 0.20; break;
f085be
+                        case HatchStyle25Percent: blendFactor = 0.25; break;
f085be
+                        case HatchStyle30Percent: blendFactor = 0.30; break;
f085be
+                        case HatchStyle40Percent: blendFactor = 0.40; break;
f085be
+                        case HatchStyle50Percent: blendFactor = 0.50; break;
f085be
+                        case HatchStyle60Percent: blendFactor = 0.60; break;
f085be
+                        case HatchStyle70Percent: blendFactor = 0.70; break;
f085be
+                        case HatchStyle75Percent: blendFactor = 0.75; break;
f085be
+                        case HatchStyle80Percent: blendFactor = 0.80; break;
f085be
+                        case HatchStyle90Percent: blendFactor = 0.90; break;
f085be
+                        default:
f085be
+                            isHatchBlend = false;
f085be
+                            break;
f085be
+                    }
f085be
+                    rState.isFillColorSet = true;
f085be
+                    rState.isLineColorSet = false;
f085be
+                    ::Color fillColor;
f085be
+                    if (isHatchBlend)
f085be
+                    {
f085be
+                        fillColor = brush->solidColor;
f085be
+                        fillColor.Merge(brush->secondColor, static_cast<sal_uInt8>(255 * blendFactor));
f085be
+                    }
f085be
+                    else
f085be
+                    {
f085be
+                        fillColor = brush->secondColor;
f085be
+                    }
f085be
+                    rState.fillColor = ::vcl::unotools::colorToDoubleSequence(fillColor, rCanvas->getUNOCanvas()->getDevice()->getDeviceColorSpace());
f085be
+                    pPolyAction = ActionSharedPtr ( internal::PolyPolyActionFactory::createPolyPolyAction( localPolygon, rParms.mrCanvas, rState ) );
f085be
+                }
f085be
+                else if (brush->type == 3 || brush->type == 4)
f085be
+                {
f085be
                     if (brush->type == 3 && !(brush->additionalFlags & 0x1))
f085be
                         return;  // we are unable to parse these brushes yet
f085be
 
f085be
-- 
f085be
1.9.3
f085be