Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<properties>
<graphcompose.version>1.6.0</graphcompose.version>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.release>17</maven.compiler.release>

<junit.bom.version>5.12.2</junit.bom.version>
<assertj.version>3.27.3</assertj.version>
Expand Down
36 changes: 24 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,31 @@
<properties>
<!-- Toolchain -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>21</maven.compiler.release>
<maven.compiler.release>17</maven.compiler.release>

<!-- Runtime / library dependencies -->
<assertj.version>3.27.3</assertj.version>
<flexmark.version>0.64.8</flexmark.version>
<jackson.bom.version>2.20.1</jackson.bom.version>
<jackson.bom.version>2.21.3</jackson.bom.version>
<kotlin.version>2.2.20</kotlin.version>
<logback.version>1.5.18</logback.version>
<lombok.version>1.18.38</lombok.version>
<logback.version>1.5.32</logback.version>
<lombok.version>1.18.46</lombok.version>
<pdfbox.version>3.0.7</pdfbox.version>
<poi.version>5.4.0</poi.version>
<poi.version>5.5.1</poi.version>
<javafx.version>21.0.2</javafx.version>
<slf4j.version>2.0.17</slf4j.version>
<snakeyaml.version>2.4</snakeyaml.version>
<snakeyaml.version>2.6</snakeyaml.version>
<zxing.version>3.5.3</zxing.version>

<!-- Test dependencies -->
<junit.bom.version>5.12.2</junit.bom.version>
<mockito.version>5.20.0</mockito.version>
<assertj.version>3.27.6</assertj.version>
<junit.bom.version>5.14.4</junit.bom.version>
<mockito.version>5.23.0</mockito.version>
<byteBuddy.version>1.18.7</byteBuddy.version>

<!-- Build plugins -->
<maven.compiler.plugin.version>3.13.0</maven.compiler.plugin.version>
<maven.javadoc.plugin.version>3.8.0</maven.javadoc.plugin.version>
<maven.surefire.plugin.version>3.2.5</maven.surefire.plugin.version>
<maven.compiler.plugin.version>3.15.0</maven.compiler.plugin.version>
<maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
<maven.surefire.plugin.version>3.5.5</maven.surefire.plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -208,6 +209,17 @@
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byteBuddy.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ public void render(PlacedFragment fragment,
if (policy == ClipPolicy.CLIP_BOUNDS) {
stream.addRect(x, y, width, height);
} else { // CLIP_PATH
switch (outline) {
case ShapeOutline.Ellipse ignored -> addEllipsePath(stream, x, y, width, height);
case ShapeOutline.RoundedRectangle r -> addRoundedRectanglePath(
stream, x, y, width, height,
/*
* This is code that the java 21 switch pattern matching was designed to avoid.
*/
if (outline instanceof ShapeOutline.Ellipse) {
addEllipsePath(stream, x, y, width, height);
} else if (outline instanceof ShapeOutline.RoundedRectangle r) {
addRoundedRectanglePath(stream, x, y, width, height,
(float) Math.min(r.cornerRadius(), Math.min(width, height) / 2.0f));
case ShapeOutline.Rectangle ignored -> stream.addRect(x, y, width, height);
} else if (outline instanceof ShapeOutline.Rectangle) {
stream.addRect(x, y, width, height);
} else {
throw new IllegalStateException("Unknown outline: " + outline);
}
}
// clip() pushes the current path onto the clipping path; the path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static PreparedSplitResult<ListNode> splitList(PreparedNode<ListNode> pre
return new PreparedSplitResult<>(head, tail);
}

PreparedListItemLayout firstItem = layout.items().getFirst();
PreparedListItemLayout firstItem = layout.items().get(0);
PreparedParagraphLayout itemLayout = firstItem.paragraphLayout();
int maxLines = maxLinesThatFit(
itemLayout.visualLines(),
Expand Down Expand Up @@ -796,7 +796,7 @@ private static List<String> wrapParagraph(List<String> logicalLines,
result.add(currentPrefix + chunks.get(index));
currentPrefix = continuationPrefix;
}
currentLine = currentPrefix + chunks.getLast();
currentLine = currentPrefix + chunks.get(chunks.size() - 1);
hasContent = true;
}

Expand Down Expand Up @@ -1451,7 +1451,7 @@ private static int maxLinesThatFit(List<ParagraphLine> lines, double lineGap, do
if (lines.isEmpty()) {
return 0;
}
if (availableHeight + EPS < lines.getFirst().lineHeight()) {
if (availableHeight + EPS < lines.get(0).lineHeight()) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,37 @@ public List<LayoutFragment> emitFragments(PreparedNode<ShapeContainerNode> prepa
}
Color awtFill = node.fillColor() == null ? null : node.fillColor().color();
Stroke stroke = toStroke(node.stroke());
LayoutFragment outlineFragment = switch (outline) {
case ShapeOutline.Ellipse ignored -> new LayoutFragment(
LayoutFragment outlineFragment;
if (outline instanceof ShapeOutline.Ellipse) {
outlineFragment = new LayoutFragment(
placement.path(),
0,
padLeft,
padBottom,
width,
height,
new EllipseFragmentPayload(awtFill, stroke, null, null));
case ShapeOutline.Rectangle ignored -> new LayoutFragment(
} else if (outline instanceof ShapeOutline.Rectangle) {
outlineFragment = new LayoutFragment(
placement.path(),
0,
padLeft,
padBottom,
width,
height,
new ShapeFragmentPayload(awtFill, stroke, 0.0, null, null, null));
case ShapeOutline.RoundedRectangle r -> new LayoutFragment(
} else if (outline instanceof ShapeOutline.RoundedRectangle r) {
outlineFragment = new LayoutFragment(
placement.path(),
0,
padLeft,
padBottom,
width,
height,
new ShapeFragmentPayload(awtFill, stroke, r.cornerRadius(), null, null, null));
};
} else {
throw new IllegalStateException("Unsupported shape outline: " + outline);
}

List<LayoutFragment> opening = new ArrayList<>(4);
boolean hasTransform = !node.transform().isIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,25 @@ private DocumentTextStyle bodyStyle(BusinessTheme theme) {
}

private DocumentNode renderBody(BusinessTheme theme, Spacing spacing) {
return switch (body) {
case ParagraphBlock p -> renderParagraph(p, theme, spacing);
case BulletListBlock b -> renderList(b.items(), ListMarker.bullet(),
"bullet", theme, spacing);
case NumberedListBlock n -> renderList(n.items(), ListMarker.custom("1."),
"numbered", theme, spacing);
case MultiParagraphBlock m -> renderMultiParagraph(m, theme, spacing);
case IndentedBlock i -> renderIndented(i, theme, spacing);
case KeyValueBlock k -> renderKeyValue(k, theme, spacing);
};
if (body instanceof ParagraphBlock p) {
return renderParagraph(p, theme, spacing);
}
if (body instanceof BulletListBlock b) {
return renderList(b.items(), ListMarker.bullet(), "bullet", theme, spacing);
}
if (body instanceof NumberedListBlock n) {
return renderList(n.items(), ListMarker.custom("1."), "numbered", theme, spacing);
}
if (body instanceof MultiParagraphBlock m) {
return renderMultiParagraph(m, theme, spacing);
}
if (body instanceof IndentedBlock i) {
return renderIndented(i, theme, spacing);
}
if (body instanceof KeyValueBlock k) {
return renderKeyValue(k, theme, spacing);
}
throw new IllegalStateException("Unsupported module body: " + body);
}

private ParagraphNode renderParagraph(ParagraphBlock block, BusinessTheme theme, Spacing spacing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,39 +215,33 @@ private void addModuleBody(SectionBuilder section, CvModule module) {
}

private void renderBody(SectionBuilder section, Block body) {
switch (body) {
case ParagraphBlock p -> renderParagraph(section, p.text());
case MultiParagraphBlock m -> {
for (String line : m.paragraphs()) {
WorkEntry entry = parseWorkEntry(line);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderParagraph(section, line);
}
if (body instanceof ParagraphBlock p) {
renderParagraph(section, p.text());
} else if (body instanceof MultiParagraphBlock m) {
for (String line : m.paragraphs()) {
WorkEntry entry = parseWorkEntry(line);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderParagraph(section, line);
}
}
case BulletListBlock b -> renderBulletList(section, b.items());
case NumberedListBlock n -> {
for (String item : n.items()) {
renderParagraph(section, item);
}
}
case IndentedBlock i -> {
for (IndentedBlock.Item item : i.items()) {
String inline = (item.title().isBlank() ? "" : item.title())
+ (item.title().isBlank() || item.body().isBlank() ? "" : " - ")
+ (item.body().isBlank() ? "" : item.body());
renderParagraph(section, inline);
}
} else if (body instanceof BulletListBlock b) {
renderBulletList(section, b.items());
} else if (body instanceof NumberedListBlock n) {
for (String item : n.items()) {
renderParagraph(section, item);
}
case KeyValueBlock kv -> {
for (KeyValueBlock.Entry entry : kv.entries()) {
renderKeyValueEntry(section, entry);
}
} else if (body instanceof IndentedBlock i) {
for (IndentedBlock.Item item : i.items()) {
String inline = (item.title().isBlank() ? "" : item.title())
+ (item.title().isBlank() || item.body().isBlank() ? "" : " - ")
+ (item.body().isBlank() ? "" : item.body());
renderParagraph(section, inline);
}
default -> {
// ignore other block kinds
} else if (body instanceof KeyValueBlock kv) {
for (KeyValueBlock.Entry entry : kv.entries()) {
renderKeyValueEntry(section, entry);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,48 +189,40 @@ private void addModuleBody(SectionBuilder section, CvModule module) {
}

private void renderBody(SectionBuilder section, Block body) {
switch (body) {
case ParagraphBlock p -> renderParagraph(section, p.text());
case MultiParagraphBlock m -> {
for (String line : m.paragraphs()) {
WorkEntry entry = parseWorkEntry(line);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderParagraph(section, line);
}
if (body instanceof ParagraphBlock p) {
renderParagraph(section, p.text());
} else if (body instanceof MultiParagraphBlock m) {
for (String line : m.paragraphs()) {
WorkEntry entry = parseWorkEntry(line);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderParagraph(section, line);
}
}
case BulletListBlock b -> {
for (String item : b.items()) {
WorkEntry entry = parseWorkEntry(item);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderBulletItem(section, item);
}
} else if (body instanceof BulletListBlock b) {
for (String item : b.items()) {
WorkEntry entry = parseWorkEntry(item);
if (entry != null) {
renderWorkEntry(section, entry);
} else {
renderBulletItem(section, item);
}
}
case NumberedListBlock n -> {
for (String item : n.items()) {
renderParagraph(section, item);
}
}
case IndentedBlock i -> {
for (IndentedBlock.Item item : i.items()) {
String inline = (item.title().isBlank() ? "" : item.title())
+ (item.title().isBlank() || item.body().isBlank() ? "" : " - ")
+ (item.body().isBlank() ? "" : item.body());
renderParagraph(section, inline);
}
} else if (body instanceof NumberedListBlock n) {
for (String item : n.items()) {
renderParagraph(section, item);
}
case KeyValueBlock kv -> {
for (KeyValueBlock.Entry entry : kv.entries()) {
renderParagraph(section, entry.key() + ": " + entry.value());
}
} else if (body instanceof IndentedBlock i) {
for (IndentedBlock.Item item : i.items()) {
String inline = (item.title().isBlank() ? "" : item.title())
+ (item.title().isBlank() || item.body().isBlank() ? "" : " - ")
+ (item.body().isBlank() ? "" : item.body());
renderParagraph(section, inline);
}
default -> {
// ignore other block kinds
} else if (body instanceof KeyValueBlock kv) {
for (KeyValueBlock.Entry entry : kv.entries()) {
renderParagraph(section, entry.key() + ": " + entry.value());
}
}
}
Expand Down
Loading