Resolves: tdf#112145 pdf export of editengine highlight color fails sometimes

When setting a fill or line color on the outputdevice, put it back to its previous
setting when finished with the record, PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
was the one in this case but protect the other similar ones here too

Change-Id: Ifb9b182d72bb6c48a9d9480270fde4384be6291e
Reviewed-on: https://gerrit.libreoffice.org/41761
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
index 4b02e95..d9455af 100644
--- a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
@@ -1223,6 +1223,8 @@ namespace drawinglayer
                    }
                    else
                    {
                        mpOutputDevice->Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);

                        // support SvtGraphicStroke MetaCommentAction
                        SvtGraphicStroke* pSvtGraphicStroke = impTryToCreateSvtGraphicStroke(
                            rBasePolygon, nullptr,
@@ -1278,6 +1280,8 @@ namespace drawinglayer
                        }

                        impEndSvtGraphicStroke(pSvtGraphicStroke);

                        mpOutputDevice->Pop();
                    }

                    break;
@@ -1657,6 +1661,7 @@ namespace drawinglayer
                }
                case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
                {
                    mpOutputDevice->Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
                    const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
                    basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());

@@ -1712,6 +1717,7 @@ namespace drawinglayer
                        impEndSvtGraphicFill(pSvtGraphicFill);
                    }

                    mpOutputDevice->Pop();
                    break;
                }
                case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
@@ -1782,6 +1788,7 @@ namespace drawinglayer
                }
                case PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D :
                {
                    mpOutputDevice->Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
                    // for metafile: Need to examine what the pure vcl version is doing here actually
                    // - uses DrawTransparent with metafile for content and a gradient
                    // - uses DrawTransparent for single PolyPolygons directly. Can be detected by
@@ -1915,6 +1922,7 @@ namespace drawinglayer
                        }
                    }

                    mpOutputDevice->Pop();
                    break;
                }
                case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 30bb746..475f290 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1281,10 +1281,10 @@ DECLARE_OOXMLIMPORT_TEST(testTdf100072, "tdf100072.docx")
    xmlDocPtr pXmlDoc = dumper.dumpAndParse(rMetaFile);

    // Get first polyline rightside x coordinate
    sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/polyline[1]/point[2]", "x").toInt32();
    sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/push[1]/polyline[1]/point[2]", "x").toInt32();

    // Get last stroke x coordinate
    sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/polyline[last()]/point[2]", "x").toInt32();
    sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/push[last()]/polyline[last()]/point[2]", "x").toInt32();

    // Assert that the difference is less than half point.
    CPPUNIT_ASSERT_MESSAGE("Shape line width does not match", abs(nFirstEnd - nSecondEnd) < 10);
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 198b714..e36ca6e 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -1492,10 +1492,10 @@ void SwUiWriterTest::testFdo87448()

    // The first polyline in the document has a number of points to draw arcs,
    // the last one jumps back to the start, so we call "end" the last but one.
    sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/polyline[1]/point[last()-1]", "x").toInt32();
    sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/push[2]/polyline[1]/point[last()-1]", "x").toInt32();
    // The second polyline has a different start point, but the arc it draws
    // should end at the ~same position as the first polyline.
    sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/polyline[2]/point[last()]", "x").toInt32();
    sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/push[5]/polyline[1]/point[last()]", "x").toInt32();

    // nFirstEnd was 6023 and nSecondEnd was 6648, now they should be much closer, e.g. nFirstEnd = 6550, nSecondEnd = 6548
    OString aMsg = "nFirstEnd is " + OString::number(nFirstEnd) + ", nSecondEnd is " + OString::number(nSecondEnd);