<div dir="ltr">Hi all,<br><br>I've run into a bug [1] in the drawing of strings via Graphics2D.drawString(), when used with a Font derived from a rotated + scaled AffineTransform. If the AffineTransform scaling is small, the text draws correctly. But if the scale is too large, the text does not draw. [3]<br><br>It looks like it's an effect of the OutlineTextRenderer.THRESHHOLD; text larger than this threshold is sent to the OutlineTextRenderer and fails to draw. The fix [2] seems to be to apply the position translation transformation *after* the text outline shape is created, rather than passing it into TextLayout.getOutline(). However, I do not know if this is the correct fix, or if it is just a workaround to a deeper issue in TextLayout.getOutline(), which in theory might need to wait to apply the provided translation until after the layout path has had a chance to map to user space.<br><br>Can someone familiar with this code comment on whether the proposed fix is the correct fix, or whether deeper surgery is needed in TextLayout.getOutline()?<br><br>My other small worry with the current fix [2] is that it creates an extra copy of the Shape object, so it's going to allocate a bit more memory than the current implementation. Not sure if there's a better way to update the Shape in-place.<br><br>Take care,<br><br>Daniel<br><div><br></div><div>---<br></div><div><br></div>[1] Oracle internal review ID 9077538, no public bug ID yet<br>[2] <a href="https://github.com/openjdk/jdk/compare/master...gredler:jdk:draw-string-bug">https://github.com/openjdk/jdk/compare/master...gredler:jdk:draw-string-bug</a><br>[3]<br>import java.awt.Color;<br>import java.awt.Font;<br>import java.awt.Graphics2D;<br>import java.awt.geom.AffineTransform;<br>import java.awt.image.BufferedImage;<br>import java.io.File;<br><br>import javax.imageio.ImageIO;<br><br>/**<br> * <p>The "TEST 2" text does not draw. NOTE: Reducing the AffineTransform scale<br> * from 12 to 10 seems to allow it to draw?!?<br> *<br> * <p>Oracle internal review ID : 9077538<br> */<br>public class DrawStringTest {<br><br>    public static void main(String[] args) throws Exception {<br><br>        AffineTransform at = AffineTransform.getRotateInstance(3 * Math.PI / 2);<br>        at.scale(12, 12);<br><br>        Font font1 = new Font("SansSerif", Font.PLAIN, 10);<br>        Font font2 = font1.deriveFont(at);<br><br>        BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_BYTE_GRAY);<br>        Graphics2D g2d = image.createGraphics();<br>        g2d.setColor(Color.WHITE);<br>        g2d.fillRect(0, 0, image.getWidth(), image.getHeight());<br>        g2d.setColor(Color.BLACK);<br>        g2d.setFont(font1);<br>        g2d.drawString("TEST 1", 200, 400); // draws text<br>        g2d.setFont(font2);<br>        g2d.drawString("TEST 2", 200, 400); // does not draw text<br>        g2d.dispose();<br><br>        ImageIO.write(image, "png", new File("test.png"));<br>    }<br><br><div>}</div><div><br></div></div>