Skip to content

Commit

Permalink
JDK-8316741: fixed BasicStroke.createStrokedShape miter-limits failin…
Browse files Browse the repository at this point in the history
…g on small shapes
  • Loading branch information
bourgesl committed Oct 1, 2023
1 parent 6b1e9b3 commit 121125d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>org.marlin</groupId>
<artifactId>marlin</artifactId>
<packaging>jar</packaging>
<version>0.9.4.7-Unsafe-OpenJDK11</version>
<version>0.9.4.8-Unsafe-OpenJDK11</version>
<name>Marlin software rasterizer</name>

<url>https://github.com/bourgesl/marlin-renderer</url>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/sun/java2d/marlin/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ Renderer init(final int pix_boundsX, final int pix_boundsY,
final int pix_boundsWidth, final int pix_boundsHeight,
final int windingRule)
{
this.rdrCtx.doRender = true;
this.windingRule = windingRule;

// bounds as half-open intervals: minX <= x < maxX and minY <= y < maxY
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/sun/java2d/marlin/RendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ static RendererContext createContext() {
final MarlinCache cache;
// flag indicating the shape is stroked (1) or filled (0)
int stroking = 0;
// flag indicating to render the shape
boolean doRender = false;
// flag indicating to clip the shape
boolean doClip = false;
// flag indicating if the path is closed or not (in advance) to handle properly caps
Expand Down Expand Up @@ -172,6 +174,7 @@ void dispose() {
stats.totalOffHeap = 0L;
}
stroking = 0;
doRender = false;
doClip = false;
closedPath = false;
clipInvScale = 0.0d;
Expand Down
45 changes: 27 additions & 18 deletions src/main/java/sun/java2d/marlin/Stroker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -171,25 +171,34 @@ Stroker init(final DPathConsumer2D pc2d,
miterScaledLimit = miterLimit * lineWidth2;
this.miterLimitSq = miterScaledLimit * miterScaledLimit;

final double limitMin = ((this.rdrCtx.clipInvScale == 0.0d) ? JOIN_ERROR
: (JOIN_ERROR * this.rdrCtx.clipInvScale))
+ lineWidth2;

this.joinLimitMinSq = limitMin * limitMin;
if (rdrCtx.doRender) {
final double limitMin = ((this.rdrCtx.clipInvScale == 0.0d) ? JOIN_ERROR
: (JOIN_ERROR * this.rdrCtx.clipInvScale))
+ lineWidth2;

this.joinLimitMinSq = limitMin * limitMin;
} else {
// createStrokedShape(): disable limit checks:
this.joinLimitMinSq = 0.0;
}
} else if (joinStyle == JOIN_ROUND) {
// chord: s = 2 r * sin( phi / 2)
// height: h = 2 r * sin( phi / 4)^2
// small angles (phi < 90):
// h = s^2 / (8 r)
// so s^2 = (8 h * r)

// height max (note ROUND_JOIN_ERROR = 8 * JOIN_ERROR)
final double limitMin = ((this.rdrCtx.clipInvScale == 0.0d) ? ROUND_JOIN_ERROR
: (ROUND_JOIN_ERROR * this.rdrCtx.clipInvScale));

// chord limit (s^2):
this.joinLimitMinSq = limitMin * this.lineWidth2;
if (rdrCtx.doRender) {
// chord: s = 2 r * sin( phi / 2)
// height: h = 2 r * sin( phi / 4)^2
// small angles (phi < 90):
// h = s^2 / (8 r)
// so s^2 = (8 h * r)

// height max (note ROUND_JOIN_ERROR = 8 * JOIN_ERROR)
final double limitMin = ((this.rdrCtx.clipInvScale == 0.0d) ? ROUND_JOIN_ERROR
: (ROUND_JOIN_ERROR * this.rdrCtx.clipInvScale));

// chord limit (s^2):
this.joinLimitMinSq = limitMin * this.lineWidth2;
} else {
// createStrokedShape(): disable limit checks:
this.joinLimitMinSq = 0.0;
}
}
this.prev = CLOSE;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sun/java2d/marlin/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public final class Version {

private static final String VERSION = "marlin-0.9.4.7-Unsafe-OpenJDK";
private static final String VERSION = "marlin-0.9.4.8-Unsafe-OpenJDK";

public static String getVersion() {
return VERSION;
Expand Down

0 comments on commit 121125d

Please sign in to comment.