]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Listen to changes in page settings in DiagramSceneGraphProvider release/1.44.0
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 14 Aug 2020 08:37:58 +0000 (11:37 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 14 Aug 2020 08:46:36 +0000 (11:46 +0300)
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)

bundles/org.simantics.diagram/src/org/simantics/diagram/export/ExportDiagramPdf.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/pdf/PDFPainter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java

index 23cb9f970f36acd3761e1ee009b3375250125b6d..25e72d984b81a277a7eda60dc1cf0ca656dae37a 100644 (file)
@@ -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;
index bec1e5408ae414c82c568b102cff6743cefec5ac..0b7cd63e4c55eed107eb552c9707a382beffc974 100644 (file)
@@ -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);
index 8f223a62285bbf6892240019deea73d6ed68a31b..302e074fce35fe9a202c743119e15afd397eb23f 100644 (file)
@@ -26,6 +26,7 @@ import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
 import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.exception.ServiceException;
 import org.simantics.db.management.ISessionContext;
+import org.simantics.db.procedure.Listener;
 import org.simantics.db.request.Read;
 import org.simantics.diagram.adapter.DefaultConnectionClassFactory;
 import org.simantics.diagram.adapter.FlagClassFactory;
@@ -98,6 +99,7 @@ import org.simantics.utils.page.PageDesc;
 import org.simantics.utils.page.PageOrientation;
 import org.simantics.utils.threads.AWTThread;
 import org.simantics.utils.threads.IThreadWorkQueue;
+import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.ErrorLogger;
 
 
@@ -290,6 +292,30 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi
             DiagramDesc diagramDesc = Simantics.getSession().syncRequest(DiagramRequests.getDiagramDesc(diagramResource));
             if (diagramDesc != null)
                 setDiagramDesc(ctx, diagramDesc);
+
+            // Create a listener to react to page setting changes.
+            Simantics.getSession().asyncRequest(DiagramRequests.getDiagramDesc(diagramResource), new Listener<DiagramDesc>() {
+                @Override
+                public void execute(DiagramDesc result) {
+                    if (result != null && ctx != null) {
+                        ThreadUtils.asyncExec(ctx.getThreadAccess(), () -> {
+                            if (ctx != null) {
+                                setDiagramDesc(ctx, result);
+                            }
+                        });
+                    }
+                }
+
+                @Override
+                public void exception(Throwable t) {
+                    ErrorLogger.defaultLogError(t);
+                }
+
+                @Override
+                public boolean isDisposed() {
+                    return DiagramSceneGraphProvider.this.ctx == null;
+                }
+            });
         } catch (DatabaseException e) {
             ErrorLogger.defaultLogError(e);
         }
@@ -298,7 +324,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi
     protected void setDiagramDesc(ICanvasContext ctx, DiagramDesc diagramDesc) {
         IHintContext hints = ctx.getDefaultHintContext();
         hints.setHint(Hints.KEY_PAGE_DESC, diagramDesc.getPageDesc());
-        //hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
+        hints.setHint(Hints.KEY_DISPLAY_PAGE, diagramDesc.isPageBordersVisible());
         hints.setHint(Hints.KEY_DISPLAY_MARGINS, diagramDesc.isMarginsVisible());
     }