Skip to content

Commit

Permalink
Replace JPEG by PDF for PlantUML, C4 PlantUML and Structurizr (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored May 7, 2023
1 parent a542857 commit 834f6aa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ci/tasks/update-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ try {
}
}

const d2GoModContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'go.mod'), 'utf8')
for (const line of d2GoModContent.split('\n')) {
const d2VersionFound = line.match(/^require oss.terrastruct.com\/d2 v(?<version>.+)$/)
if (d2VersionFound) {
const { version } = d2VersionFound.groups
diagramLibraryVersions.d2 = version
}
}

const svgbobCargoContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'Cargo.toml'), 'utf8')
for (const line of svgbobCargoContent.split('\n')) {
const svgbobVersionFound = line.match(/^svgbob_cli\s*=\s*"(?<version>.+)"$/)
Expand Down
7 changes: 4 additions & 3 deletions ci/tests/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const tests = [
{engine: 'seqdiag', file: 'sequence.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'actdiag', file: 'actions.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'nwdiag', file: 'network.diag', options: {}, outputFormat: ['svg', 'png']},
{engine: 'c4plantuml', file: 'banking-system.puml', options: {}, outputFormat: ['svg']},
{engine: 'c4plantuml', file: 'banking-system.puml', options: {}, outputFormat: ['svg', 'pdf', 'png', 'txt']},
{engine: 'dbml', file: 'dbml.dbml', options: {}, outputFormat: ['svg']},
{engine: 'ditaa', file: 'components.ditaa', options: {}, outputFormat: ['svg']},
{engine: 'erd', file: 'schema.erd', options: {}, outputFormat: ['svg']},
{engine: 'mermaid', file: 'contribute.mmd', options: {}, outputFormat: ['svg']},
{engine: 'bpmn', file: 'example.bpmn', options: {}, outputFormat: ['svg']},
{engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg']},
{engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg', 'pdf', 'png', 'txt']},
{engine: 'svgbob', file: 'cloud.bob', options: {}, outputFormat: ['svg']},
{engine: 'nomnoml', file: 'pirate.nomnoml', options: {}, outputFormat: ['svg']},
{engine: 'packetdiag', file: 'packet.diag', options: {}, outputFormat: ['svg', 'png']},
Expand Down Expand Up @@ -50,7 +50,8 @@ const mimeType = {
svg: 'image/svg+xml',
png: 'image/png',
pdf: 'application/pdf',
jpeg: 'image/jpeg'
jpeg: 'image/jpeg',
txt: 'text/plain'
}

const sendRequest = async (testCase, outputFormat) => {
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/io/kroki/server/service/Plantuml.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class Plantuml implements DiagramService {
private static final Pattern START_BLOCK_RX = Pattern.compile("^(@start.*\\n)");

private static final Logger logger = LoggerFactory.getLogger(Plantuml.class);
private static final List<FileFormat> SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.JPEG, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT);
private static final List<FileFormat> SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.PDF, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT);
private static final Pattern STDLIB_PATH_RX = Pattern.compile("<([a-zA-Z0-9]+)/[^>]+>");

private final Vertx vertx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Structurizr implements DiagramService {
private final PlantumlCommand plantumlCommand;

// same as PlantUML since we convert Structurizr DSL to PlantUML
private static final List<FileFormat> SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.JPEG, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT);
private static final List<FileFormat> SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.PDF, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT);

private static final String aws = read("structurizr/amazon-web-services.json");
private static final String gcp = read("structurizr/google-cloud-platform.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -98,4 +99,27 @@ void should_not_use_network() throws IOException, InterruptedException {
System.clearProperty("socksProxyPort");
}
}

@Test
void should_convert_to_pdf() throws IOException, InterruptedException {
String diagram = "@startuml\n" +
"!include C4_Context.puml\n" +
"\n" +
"title System Context diagram for Internet Banking System\n" +
"\n" +
"Person(customer, \"Banking Customer\", \"A customer of the bank, with personal bank accounts.\")\n" +
"System(banking_system, \"Internet Banking System\", \"Allows customers to check their accounts.\")\n" +
"\n" +
"System_Ext(mail_system, \"E-mail system\", \"The internal Microsoft Exchange e-mail system.\")\n" +
"System_Ext(mainframe, \"Mainframe Banking System\", \"Stores all of the core banking information.\")\n" +
"\n" +
"Rel(customer, banking_system, \"Uses\")\n" +
"Rel_Back(customer, mail_system, \"Sends e-mails to\")\n" +
"Rel_Neighbor(banking_system, mail_system, \"Sends e-mails\", \"SMTP\")\n" +
"Rel(banking_system, mainframe, \"Uses\")\n" +
"@enduml";
byte[] convert = plantumlCommand.convert(Plantuml.sanitize(diagram, SafeMode.SAFE), FileFormat.PDF, new JsonObject());
assertThat(convert).isNotEmpty();
assertThat(new String(convert, StandardCharsets.UTF_8)).contains("%PDF-1.4");
}
}

0 comments on commit 834f6aa

Please sign in to comment.