Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java2D : TextLayout drawing right to left  RSS feed

 
kenny de smedt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

This is a first posting for me but I found lot's of sollutions to common java problems allready in this forum so I have good hope I might get the help I need for this probably obvious problem. However at the moment I'm out of ideas and google search strings.

I've been trying to draw a string on a buffered image from a certain x,y. The default behaviour is that you draw left to right. However my x,y is on the right side of my bufferd image and I want it to draw right to left. I've tried several things allready with TextAttributes and Font changes but nothing seemed to work. I hope you can help me out here. This is my last attempt before I posted



thanks in advance

Kenny
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to AWT / Swing.
 
Stanislav Lapitsky
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about correcting the coordinate by width of the text
tl.draw(imageG, 640-t1.getBounds().width, 79);

Regards,
Stas
 
kenny de smedt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stanislav Lapitsky wrote:What about correcting the coordinate by width of the text
tl.draw(imageG, 640-t1.getBounds().width, 79);

Regards,
Stas


I was thinking of that, but then I need to know the exact size of my font, it's spacing, it's bottom and height. I have looked at the class FontMetrics but I'm confuzzled how to use it. I did found a few examples but they are not that clear and to the point as I would like to understand them.

I'll take another look at this example it is probably the right way to do it , I just need to get the measurements right.

thnx
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking of that, but then I need to know the exact size of my font, it's spacing, it's bottom and height.


Isn't that what TextLayout.getBounds()...) method does?
 
kenny de smedt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
I was thinking of that, but then I need to know the exact size of my font, it's spacing, it's bottom and height.


Isn't that what TextLayout.getBounds()...) method does?


I tried it with FontMetrics and TextLayout.getBounds() and both worked. Thanks guys , seems drawing in java is a lot of mathematical adding and subtracting according to a set scale and origin point. I'm starting to get the hang of it.

thnx for the help
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!