From 15a025f0981f33f15d39a3d2de3b0f9bf7a18c79 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 14 Aug 2020 11:37:58 +0300 Subject: [PATCH] Listen to changes in page settings in DiagramSceneGraphProvider This is needed for use cases where diagrams are transformed to SVG and viewed through browsers. These changes also fix PDF printing to force page border rendering off when not fitting PDF pages to diagram content, but to diagram page size. This avoids printing ugly black half-visible borders around diagrams where page borders are enabled. gitlab #563 Change-Id: I7f666dec34c650489264f3d23cbd72d5102b2f14 (cherry picked from commit 2ccc058ac6c303b64a70ad0f0c48ca501bf4aa6a) --- .../simantics/diagram/export/ExportDiagramPdf.java | 8 +++++++- .../org/simantics/modeling/ui/pdf/PDFPainter.java | 10 +++++++++- .../modeling/ui/sg/DiagramSceneGraphProvider.java | 13 ++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java index 23cb9f970..25e72d984 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java @@ -183,8 +183,14 @@ public class ExportDiagramPdf implements ExportClass { ThreadUtils.syncExec(workerThread, new Runnable() { @Override public void run() { - try { + try { cctx.getDefaultHintContext().setHint(Hints.KEY_PAGE_DESC, _marginaaliViiva); + if (!fitDiagramContentsToPageMargins) { + // Prevent PDF printing from drawing page borders if the + // print area is fitted directly to the page size. + // This avoids unwanted black half-visible edges. + cctx.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_PAGE, false); + } String bottomLabel = diagramName; if ( drawingTemplate != null && activeProfileEntries.contains(TMPL.DrawingTemplate) ) bottomLabel = null; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java index bec1e5408..0b7cd63e4 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java @@ -89,7 +89,15 @@ public class PDFPainter { ThreadUtils.asyncExec(thread, () -> { try { - PDFBuilder chassis = new PDFBuilder(writer, mapper, pageSize, pageDesc, fitDiagramContentsToPageMargins || isSymbol); + boolean fitToContent = fitDiagramContentsToPageMargins || isSymbol; + if (!fitToContent) { + // Prevent PDF printing from drawing page borders if the + // print area is fitted directly to the page size. + // This avoids unwanted black half-visible edges. + ctx.getDefaultHintContext().setHint(Hints.KEY_DISPLAY_PAGE, false); + } + + PDFBuilder chassis = new PDFBuilder(writer, mapper, pageSize, pageDesc, fitToContent); chassis.paint(ctx, true); } catch (Throwable e) { exception[0] = new DatabaseException(e); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java index ca6d6d04c..3ca0cf698 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java @@ -293,16 +293,12 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi // Create a listener to react to page setting changes. Simantics.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource), new Listener() { - @Override public void execute(DiagramDesc result) { if (result != null && ctx != null) { - ThreadUtils.asyncExec(ctx.getThreadAccess(), new Runnable() { - @Override - public void run() { - if (ctx != null) { - setDiagramDesc(ctx, result); - } + ThreadUtils.asyncExec(ctx.getThreadAccess(), () -> { + if (ctx != null) { + setDiagramDesc(ctx, result); } }); } @@ -315,9 +311,8 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi @Override public boolean isDisposed() { - return ctx == null; + return DiagramSceneGraphProvider.this.ctx == null; } - }); } catch (DatabaseException e) { ErrorLogger.defaultLogError(e); -- 2.47.1