From b206f46c3935ed541a3272d368ece93c97a66f0c Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Wed, 8 Feb 2023 13:26:55 +0000 Subject: [PATCH] StructurizrPlantUMLExporter: Adds the ability to set a default font, based upon the branding font defined in the workspace (#41). --- docs/changelog.md | 4 ++ .../plantuml/StructurizrPlantUMLExporter.java | 15 +++++ ...ructurizrPlantUMLDiagramExporterTests.java | 64 +++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 273976d..0254a19 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.8.5 (unreleased) + +- StructurizrPlantUMLExporter: Adds the ability to set a default font, based upon the branding font defined in the workspace (#41). + ## 1.8.4 (3rd February 2023) - Fixes #39 (WebSequenceDiagrams exporter only shows relationship descriptions defined in the dynamic view). diff --git a/src/main/java/com/structurizr/export/plantuml/StructurizrPlantUMLExporter.java b/src/main/java/com/structurizr/export/plantuml/StructurizrPlantUMLExporter.java index c345c3e..1c52570 100644 --- a/src/main/java/com/structurizr/export/plantuml/StructurizrPlantUMLExporter.java +++ b/src/main/java/com/structurizr/export/plantuml/StructurizrPlantUMLExporter.java @@ -52,6 +52,14 @@ protected void writeHeader(View view, IndentingWriter writer) { writer.writeLine(); } + Font font = view.getViewSet().getConfiguration().getBranding().getFont(); + if (font != null) { + String fontName = font.getName(); + if (!StringUtils.isNullOrEmpty(fontName)) { + addSkinParam("defaultFontName", fontName); + } + } + writeSkinParams(writer); writeIncludes(view, writer); @@ -437,6 +445,13 @@ protected Legend createLegend(View view) { writer.writeLine("defaultTextAlignment center"); writer.writeLine("wrapWidth 100"); writer.writeLine("maxMessageSize 100"); + Font font = view.getViewSet().getConfiguration().getBranding().getFont(); + if (font != null) { + String fontName = font.getName(); + if (!StringUtils.isNullOrEmpty(fontName)) { + writer.writeLine("defaultFontName " + fontName); + } + } writer.outdent(); writer.writeLine("}"); diff --git a/src/test/java/com/structurizr/export/plantuml/StructurizrPlantUMLDiagramExporterTests.java b/src/test/java/com/structurizr/export/plantuml/StructurizrPlantUMLDiagramExporterTests.java index d3df7d3..9242d9e 100644 --- a/src/test/java/com/structurizr/export/plantuml/StructurizrPlantUMLDiagramExporterTests.java +++ b/src/test/java/com/structurizr/export/plantuml/StructurizrPlantUMLDiagramExporterTests.java @@ -973,4 +973,68 @@ public void staticDiagramsAreUnchangedWhenSequenceDiagramsAreEnabled() { assertEquals(expected, diagram.getDefinition()); } + @Test + public void testFont() { + Workspace workspace = new Workspace("Name", "Description"); + workspace.getModel().addPerson("User"); + SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "Description"); + view.addAllElements(); + workspace.getViews().getConfiguration().getBranding().setFont(new Font("Courier")); + + Diagram diagram = new StructurizrPlantUMLExporter().export(view); + assertEquals("@startuml\n" + + "title System Landscape\n" + + "\n" + + "top to bottom direction\n" + + "\n" + + "skinparam {\n" + + " shadowing false\n" + + " arrowFontSize 10\n" + + " defaultTextAlignment center\n" + + " wrapWidth 200\n" + + " maxMessageSize 100\n" + + " defaultFontName Courier\n" + + "}\n" + + "\n" + + "hide stereotype\n" + + "\n" + + "skinparam rectangle<> {\n" + + " BackgroundColor #dddddd\n" + + " FontColor #000000\n" + + " BorderColor #9a9a9a\n" + + "}\n" + + "\n" + + "rectangle \"==User\\n[Person]\" <> as User\n" + + "\n" + + "@enduml", diagram.getDefinition().toString()); + + assertEquals("@startuml\n" + + "\n" + + "skinparam {\n" + + " shadowing false\n" + + " arrowFontSize 15\n" + + " defaultTextAlignment center\n" + + " wrapWidth 100\n" + + " maxMessageSize 100\n" + + " defaultFontName Courier\n" + + "}\n" + + "hide stereotype\n" + + "\n" + + "skinparam rectangle<<_transparent>> {\n" + + " BorderColor transparent\n" + + " BackgroundColor transparent\n" + + " FontColor transparent\n" + + "}\n" + + "\n" + + "skinparam rectangle<<1>> {\n" + + " BackgroundColor #dddddd\n" + + " FontColor #000000\n" + + " BorderColor #9a9a9a\n" + + "}\n" + + "rectangle \"==Element\" <<1>>\n" + + "\n" + + "\n" + + "@enduml", diagram.getLegend().getDefinition()); + } + } \ No newline at end of file