I'm working with graphcis2d in Java and am currently using this to draw text into a bufferedImage
Font font1 = new Font("Arial", Font.PLAIN, 120);
g2d.setFont(font1);
FontMetrics fm1 = g2d.getFontMetrics(font1);
g2d.drawString(s[1], width/2-fm1.stringWidth(s[1])/2, height/4-70);
I want to draw this text with an different color outline.
GlyphVector gv = font1.createGlyphVector(g2d.getFontRenderContext(), s[1]);
Shape shape = gv.getOutline();
g2d.setStroke(new BasicStroke(4.0f));
g2d.translate(width/2-fm1.stringWidth(s[1])/2, height/4-70);
g2d.draw(shape);
The problem with using this method, which works, is that I am working with arabic characters and using GlyphVector reverses the order and doesn't make the letters flow with one another.
Can someone please explain to me how to render arabic text in one color and have an outline with another?
Heres a sample of the text I would be using: الرحمن
One trick is to draw the text several times in the outline color, varying the position by the outline width in +/- x and +/- y directions, then draw in the foreground color at the nominal position. It isn't perfect, but it tends to look pretty good provided the outline isn't too thick with respect to the stroke width of the letters.
You may be able to use the method createStrokedShape()
on the glyph's Shape
returned by getOutline()
. See also CompositeStroke
, demonstrated here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With