Product: Aspose.Words for Java
Versions tested: 22.2, 23.2, 25.9 and 26.9 (latest; 25.9/26.9 run in evaluation mode, same timings). JDK 17.0.2, Windows 11 x64; also seen on Linux (Debian 12).
Problem
ShapeRenderer.save() on a group shape that contains one ellipse with a path gradient fill (DrawingML <a:gradFill> with <a:path path="shape">, i.e. GradientStyle.FROM_CENTER) takes minutes. The time grows steeply with resolution, even though the rendered image is tiny:
| Resolution | Time (26.9) |
|---|---|
| 24 dpi | 60 ms |
| 72 dpi | 17.8 s |
| 150 dpi | 71.4 s |
| 300 dpi | about 5 minutes |
| 150 dpi, same group with the gradient replaced by a solid fill | 4 ms |
The attached document is a minimal repro, cut down from a real exam paper: one paragraph containing a group shape (four nested groups, one rotated 90°, with large child-coordinate scaling) whose only leaf is a single ellipse with a white→grey path gradient. In the original page the ellipse is only about 7×7 device pixels, yet the render still takes this long.
setUseHighQualityRendering, setDmlEffectsRenderingMode (SIMPLIFIED / NONE / FINE) and setDmlRenderingMode (FALLBACK / DRAWING_ML) make no difference. A thread dump shows the time inside one paint call: SunGraphics2D.fill → AlphaPaintPipe.renderPathTile → com.aspose.words.internal.*.getRaster(...), i.e. the PaintContext of the internal path-gradient paint (the class that holds a GeneralPath and a Map<Point2D, Color>).
Steps to reproduce
- Unzip the attachment:
path-gradient-slow.docxandPathGradientRepro.java. javac -cp aspose-words-26.9-jdk17.jar PathGradientRepro.javajava -cp aspose-words-26.9-jdk17.jar:. PathGradientRepro path-gradient-slow.docx(use;on Windows)
Document doc = new Document("path-gradient-slow.docx");
GroupShape group = (GroupShape) doc.getChildNodes(NodeType.GROUP_SHAPE, true).get(0);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.setResolution(150);
long start = System.nanoTime();
group.getShapeRenderer().save(new ByteArrayOutputStream(), options); // ~71 s
System.out.println((System.nanoTime() - start) / 1_000_000 + " ms");
Output on 26.9:
24 dpi: 60 ms
72 dpi: 17791 ms
150 dpi: 71375 ms
150 dpi, gradients flattened: 4 ms
Expected
The shape renders in milliseconds, as it does once the path gradient is replaced by a solid fill (or as other documents with the same kind of gradient do).
Notes
- Flattening only helps on a freshly loaded document: after the group has been rendered once, changing the fill and rendering again is still slow, so some render state appears to be cached on the shape.
- Our current workaround is to time-box the render on a separate thread and, on timeout, re-render a copy with gradient fills replaced by solid colours.
path-gradient-repro.zip (11.5 KB)