diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-11-20 16:15:39 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-11-20 19:04:36 +0100 |
commit | 81b0d5393ca4cf2ff0954e53b05928cde047c2e0 (patch) | |
tree | a321e67d3426e66d1a6a9a33436e92400377e161 | |
parent | d1bf39a78ed239d4493f0470ca937852265e79d6 (diff) |
svx: add rendering for semi-transparent shape text
The color's alpha is normally lost when we roundtrip SvxColorItem's
tools Color via TextSimplePortionPrimitive2D's basegfx::BColor.
One way would be to add an extra transparency member to the primitive,
like BackgroundColorPrimitive2D does that.
However, a much easier way is to go via UnifiedTransparencePrimitive2D,
that way we handle transparency in
drawinglayer::impBufferDevice::paint(), rather than platform-specific
code like CairoTextRender::DrawTextLayout() in the Linux case.
Change-Id: Ie7aebe77ad9ac776dd27fc50538a5045200c8010
Reviewed-on: https://gerrit.libreoffice.org/83307
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | svx/CppunitTest_svx_unit.mk | 7 | ||||
-rw-r--r-- | svx/qa/unit/svdraw.cxx | 114 | ||||
-rw-r--r-- | svx/source/svdraw/svdotextdecomposition.cxx | 9 |
3 files changed, 129 insertions, 1 deletions
diff --git a/svx/CppunitTest_svx_unit.mk b/svx/CppunitTest_svx_unit.mk index c6c30138f4db..8514f438c8f0 100644 --- a/svx/CppunitTest_svx_unit.mk +++ b/svx/CppunitTest_svx_unit.mk @@ -9,7 +9,10 @@ $(eval $(call gb_CppunitTest_CppunitTest,svx_unit)) -$(eval $(call gb_CppunitTest_use_external,svx_unit,boost_headers)) +$(eval $(call gb_CppunitTest_use_externals,svx_unit,\ + boost_headers \ + libxml2 \ +)) $(eval $(call gb_CppunitTest_use_sdk_api,svx_unit)) @@ -22,6 +25,7 @@ $(eval $(call gb_CppunitTest_set_include,svx_unit,\ $(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \ svx/qa/unit/svdraw/test_SdrTextObject \ svx/qa/unit/customshapes \ + svx/qa/unit/svdraw \ svx/qa/unit/unodraw \ svx/qa/unit/xoutdev \ svx/qa/unit/XTableImportExportTest \ @@ -29,6 +33,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,svx_unit, \ $(eval $(call gb_CppunitTest_use_libraries,svx_unit, \ basegfx \ + drawinglayer \ sal \ sfx \ svxcore \ diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx new file mode 100644 index 000000000000..d702effe2dbe --- /dev/null +++ b/svx/qa/unit/svdraw.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> +#include <test/xmltesttools.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +#include <drawinglayer/tools/primitive2dxmldump.hxx> +#include <rtl/ustring.hxx> +#include <svx/sdr/contact/displayinfo.hxx> +#include <svx/sdr/contact/viewcontact.hxx> +#include <svx/sdr/contact/viewobjectcontact.hxx> +#include <svx/sdrpagewindow.hxx> +#include <svx/svdpage.hxx> +#include <svx/svdpagv.hxx> +#include <svx/svdview.hxx> +#include <svx/unopage.hxx> +#include <vcl/virdev.hxx> + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for svx/source/svdraw/ code. +class SvdrawTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools +{ +protected: + uno::Reference<lang::XComponent> mxComponent; + +public: + virtual void setUp() override + { + test::BootstrapFixture::setUp(); + mxDesktop.set(frame::Desktop::create(m_xContext)); + } + + virtual void tearDown() override + { + if (mxComponent.is()) + { + mxComponent->dispose(); + } + test::BootstrapFixture::tearDown(); + } + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } +}; + +CPPUNIT_TEST_FIXTURE(SvdrawTest, testSemiTransparentText) +{ + // Create a new Draw document with a rectangle. + getComponent() = loadFromDesktop("private:factory/sdraw"); + uno::Reference<lang::XMultiServiceFactory> xFactory(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape( + xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY); + xShape->setSize(awt::Size(10000, 10000)); + xShape->setPosition(awt::Point(1000, 1000)); + + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + xDrawPage->add(xShape); + + // Add semi-transparent text on the rectangle. + uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); + xShapeText->getText()->setString("hello"); + + uno::Reference<beans::XPropertySet> xShapeProperties(xShape, uno::UNO_QUERY); + xShapeProperties->setPropertyValue("CharColor", uno::makeAny(COL_RED)); + sal_Int16 nTransparence = 75; + xShapeProperties->setPropertyValue("CharTransparence", uno::makeAny(nTransparence)); + + // Generates drawinglayer primitives for the page. + auto pDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPage.get()); + CPPUNIT_ASSERT(pDrawPage); + SdrPage* pSdrPage = pDrawPage->GetSdrPage(); + ScopedVclPtrInstance<VirtualDevice> aVirtualDevice; + SdrView aSdrView(pSdrPage->getSdrModelFromSdrPage(), aVirtualDevice); + SdrPageView aSdrPageView(pSdrPage, aSdrView); + SdrPageWindow* pSdrPageWindow = aSdrPageView.GetPageWindow(0); + sdr::contact::ObjectContact& rObjectContactOfPageView = pSdrPageWindow->GetObjectContact(); + const sdr::contact::ViewObjectContact& rDrawPageVOContact + = pSdrPage->GetViewContact().GetViewObjectContact(rObjectContactOfPageView); + sdr::contact::DisplayInfo aDisplayInfo; + drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence + = rDrawPageVOContact.getPrimitive2DSequenceHierarchy(aDisplayInfo); + + // Make sure the text is semi-transparent. + drawinglayer::tools::Primitive2dXmlDump aDumper; + xmlDocPtr pDocument = aDumper.dumpAndParse(xPrimitiveSequence); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//unifiedtransparence' number of nodes is incorrect + // i.e. the text was just plain red, not semi-transparent. + double fTransparence = getXPath(pDocument, "//unifiedtransparence", "transparence").toDouble(); + CPPUNIT_ASSERT_EQUAL(nTransparence, + static_cast<sal_Int16>(basegfx::fround(fTransparence * 100))); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx index 1cc2b8a1df37..ff3b839710b2 100644 --- a/svx/source/svdraw/svdotextdecomposition.cxx +++ b/svx/source/svdraw/svdotextdecomposition.cxx @@ -54,6 +54,7 @@ #include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx> #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> #include <drawinglayer/primitive2d/textlayoutdevice.hxx> +#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> #include <svx/unoapi.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx> #include <editeng/outlobj.hxx> @@ -356,6 +357,14 @@ namespace aTextFillColor); } + if (aFontColor.GetTransparency() != 0) + { + // Handle semi-transparent text for both the decorated and simple case here. + pNewPrimitive = new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D( + drawinglayer::primitive2d::Primitive2DContainer{ pNewPrimitive }, + aFontColor.GetTransparency() / 255.0); + } + if(rInfo.mbEndOfBullet) { // embed in TextHierarchyBulletPrimitive2D |