Results 1 to 5 of 5
  1. #1
    LyraM is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default Drawing strings in Java

    Hello,

    I have some questions regarding drawing strings in Java, more exactly regarding the determination and measurement of the size of strings.

    The API says that the unit of the parameter size in the constructor Font(String name, int style, int size) is point. But how is the relationship between points and pixels in Java? I found serveral resources on the web which all say different things.

    Some states that in Java one point is equal to one pixel. Others say that Java knows points as well as pixels and that one point is not necessarily one pixel. But what's right? I searched the API and others official Sun documents (eg. the tutorials), but I can't find any official resource from Sun in which the relation between pixels and points is explained - neither statements that one point is equal to one pixel nor statements against that. Does any one have a link where Sun explains that?

    Second question: What exactly is the size of a font which I give the constructor Font(String name, int style, int size)? Is it the distance from the font's baseline to the top of most alphanumeric characters? Or the distance from the bottom of most alphanumeric characters with descenders to the top of most alphanumeric characters?

    Third question: Do the methods of the class FontMetrics such as getLeading(), getAscent() or getDescent() return pixel values or point values? If there is a difference at all...

    Best regards

  2. #2
    rtc1 is offline Member
    Join Date
    May 2010
    Location
    northern california
    Posts
    7
    Rep Power
    0

    Default

    Take a look at this URL: Javadoc error confuses Pixels with Points

    In general, pixel vs. point size is platform/device/implementation dependent.

    Chapter 5 of "Java 2D API Graphics" has a good introduction to the FontMetrics, TextLayout, LineMetrics, and FontRenderContext classes.

    Finally, when using getLeading() etc. for screen drawing, I have always found the return values to have pixel units.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Has this question been cross-posted in the sun forums? OP, did you read the users agreement that you signed on joining this forum? Have you checked the Sun forum for their policy on cross-posts?

  4. #4
    rtc1 is offline Member
    Join Date
    May 2010
    Location
    northern california
    Posts
    7
    Rep Power
    0

    Default

    Fubarable, were you referring to my reply to the original posting or the original posting? rtc1

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by rtc1 View Post
    Fubarable, were you referring to my reply to the original posting or the original posting? rtc1
    Sorry for being unclear. I was referring to the OP as it looked familiar. I have found the cross-posted here: Java 2D - Drawing strings in Java

Similar Threads

  1. drawing shapes in java help
    By alphajoseph in forum Java 2D
    Replies: 2
    Last Post: 09-29-2009, 06:35 PM
  2. The java Strings
    By greenteachacha in forum Jobs Discussion
    Replies: 8
    Last Post: 04-16-2009, 05:08 AM
  3. Sorting strings in java?
    By alexander.s in forum New To Java
    Replies: 10
    Last Post: 09-01-2008, 04:14 AM
  4. Java Drawing PUZZLE
    By Cyorxamp in forum AWT / Swing
    Replies: 3
    Last Post: 06-09-2008, 10:35 AM
  5. Help with drawing strings!
    By JavaInLove in forum AWT / Swing
    Replies: 1
    Last Post: 02-05-2008, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •