Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
StructurizrPlantUMLExporter: Adds the ability to set a default font, …
Browse files Browse the repository at this point in the history
…based upon the branding font defined in the workspace (#41).
  • Loading branch information
Simon Brown committed Feb 8, 2023
1 parent 8be463e commit b206f46
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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("}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<User>> {\n" +
" BackgroundColor #dddddd\n" +
" FontColor #000000\n" +
" BorderColor #9a9a9a\n" +
"}\n" +
"\n" +
"rectangle \"==User\\n<size:10>[Person]</size>\" <<User>> 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());
}

}

0 comments on commit b206f46

Please sign in to comment.