tdf#148526 sdext,pdfimport: Expand path to contour

Poppler's 'ClipToStroke' call wants to clip to a paths rendered
shape, i.e. with line thickness and possibly other attributes.

Use get2DDecomposition to do that.

Change-Id: I3ca54621dcb859520504e5c7d6cd41106f5c34d1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172924
Reviewed-by: David Gilbert <freedesktop@treblig.org>
Tested-by: Jenkins
This commit is contained in:
Dr. David Alan Gilbert 2024-08-22 01:03:57 +01:00 committed by David Gilbert
parent f488136a72
commit 53d5b3119f
5 changed files with 49 additions and 3 deletions

View file

@ -29,7 +29,10 @@ $(eval $(call gb_CppunitTest_use_libraries,sdext_pdfimport,\
comphelper \
cppu \
cppuhelper \
drawinglayercore \
drawinglayer \
sal \
salhelper \
test \
unotest \
tl \

View file

@ -27,9 +27,12 @@ $(eval $(call gb_Executable_use_libraries,pdf2xml,\
vcl \
comphelper \
cppu \
drawinglayercore \
drawinglayer \
unotest \
cppuhelper \
sal \
salhelper \
tl \
xo \
i18nutil \

View file

@ -26,7 +26,10 @@ $(eval $(call gb_Executable_use_libraries,pdfunzip,\
comphelper \
cppu \
cppuhelper \
drawinglayercore \
drawinglayer \
sal \
salhelper \
vcl \
tl \
xo \

View file

@ -23,10 +23,13 @@ $(eval $(call gb_Library_set_include,pdfimport,\
$(eval $(call gb_Library_use_libraries,pdfimport,\
basegfx \
comphelper \
drawinglayercore \
drawinglayer \
vcl \
cppu \
cppuhelper \
sal \
salhelper \
tl \
xo \
i18nutil \

View file

@ -33,6 +33,7 @@
#include <comphelper/sequence.hxx>
#include <basegfx/polygon/b2dpolygonclipper.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygoncutter.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <i18nutil/unicode.hxx>
@ -40,6 +41,10 @@
using namespace com::sun::star;
#include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
#include <drawinglayer/processor2d/linegeometryextractor2d.hxx>
#include <iostream>
namespace pdfi
{
@ -530,11 +535,40 @@ void PDFIProcessor::intersectEoClip(const uno::Reference< rendering::XPolyPolygo
void PDFIProcessor::intersectClipToStroke(const uno::Reference< rendering::XPolyPolygon2D >& rPath)
{
// TODO! Expand the path to the outline of the stroked path
// TODO(F3): interpret fill mode
basegfx::B2DPolyPolygon aNewClip = basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(rPath);
aNewClip.transform(getCurrentContext().Transformation);
basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip;
const GraphicsContext& rGC(getCurrentContext());
aNewClip.transform(rGC.Transformation);
basegfx::B2DPolyPolygon aCurClip = rGC.Clip;
double nScale = GetAverageTransformationScale(rGC.Transformation);
// We need to get a path that corresponds to a 'stroked path' - i.e. with whatever line
// thickness etc is set. PolyPolygonStrokePrimitive2D::create2DDecomposition does most
// of the work.
const basegfx::BColor aBlack(0.0, 0.0, 0.0);
drawinglayer::attribute::LineAttribute aLineAttribute(aBlack, rGC.LineWidth * nScale /*, aJoin */);
rtl::Reference<drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D> aStrokePrimitive(
new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(aNewClip, aLineAttribute));
drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer;
const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
aStrokePrimitive->get2DDecomposition(aPrimitiveContainer, aViewInformation2D);
// Based on extractLineContourFromPrimitive2DSequence and ImpConvertToContourObj
drawinglayer::processor2d::LineGeometryExtractor2D aExtractor(aViewInformation2D);
aExtractor.process(aPrimitiveContainer);
basegfx::B2DPolygonVector aHairlines = aExtractor.getExtractedHairlines();
auto aFills = aExtractor.getExtractedLineFills();
basegfx::B2DPolyPolygon aTmpClip = basegfx::utils::mergeToSinglePolyPolygon(std::move(aFills));
for (const basegfx::B2DPolygon & rExtractedHairline : aHairlines)
{
aTmpClip.append(rExtractedHairline);
}
aNewClip = aTmpClip;
if( aCurClip.count() ) // #i92985# adapted API from (..., false, false) to (..., true, false)
aNewClip = basegfx::utils::clipPolyPolygonOnPolyPolygon( aCurClip, aNewClip, true, false );