fontsize in textlayout

Discussion in 'Java' started by Michael Mueller, Jun 30, 2007.

  1. Hi

    I like to print some elements includind bib test in a special font size.
    Everything is printed in that size (g2d.drawString), except my big text
    (layout.draw(g2d, ...), which is allways printed in something like 6 points.
    This is my code:

    font = new Font("Sans-serif", Font.PLAIN, 11);
    g2d.setFont(font);

    ....

    g2d.drawString(out, xPos, yPos); // printed 11 points

    ....

    out = doc.getDocItem(i).getDescription();

    if (out.length() > 0){
    AttributedString styledText = new AttributedString(out);
    AttributedCharacterIterator charIterator = styledText.getIterator();
    FontRenderContext frc = g2d.getFontRenderContext();
    LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, frc);
    float wrappingWidth = (float) ((some calculated value)
    xPos = (wAmount + 2 * wGap) * scale;

    while (measurer.getPosition() < charIterator.getEndIndex()) {
    TextLayout layout = measurer.nextLayout(wrappingWidth);

    layout.draw(g2d, xPos, yPos); // printed using apx. 6 points

    if (measurer.getPosition() < charIterator.getEndIndex()) {
    yPos += metrics.getHeight();
    }

    }
    }

    Any help is welcome

    Michael
    Michael Mueller, Jun 30, 2007
    #1
    1. Advertising

  2. Michael Mueller schrieb:
    > Hi
    >
    > I like to print some elements includind bib test in a special font size.
    > Everything is printed in that size (g2d.drawString), except my big text
    > (layout.draw(g2d, ...), which is allways printed in something like 6 points.
    > This is my code:
    >
    > font = new Font("Sans-serif", Font.PLAIN, 11);
    > g2d.setFont(font);
    >
    > ....
    >
    > g2d.drawString(out, xPos, yPos); // printed 11 points
    >
    > ....
    >
    > out = doc.getDocItem(i).getDescription();
    >
    > if (out.length() > 0){
    > AttributedString styledText = new AttributedString(out);
    > AttributedCharacterIterator charIterator = styledText.getIterator();
    > FontRenderContext frc = g2d.getFontRenderContext();
    > LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, frc);
    > float wrappingWidth = (float) ((some calculated value)
    > xPos = (wAmount + 2 * wGap) * scale;
    >
    > while (measurer.getPosition() < charIterator.getEndIndex()) {
    > TextLayout layout = measurer.nextLayout(wrappingWidth);
    >
    > layout.draw(g2d, xPos, yPos); // printed using apx. 6 points
    >
    > if (measurer.getPosition() < charIterator.getEndIndex()) {
    > yPos += metrics.getHeight();
    > }
    >
    > }
    > }
    >
    > Any help is welcome
    >
    > Michael


    I got it.

    I just added an attribute...
    AttributedString styledText = new AttributedString(out);
    styledText.addAttribute( TextAttribute.FONT, font );
    AttributedCharacterIterator charIterator = styledText.getIterator();
    Michael Mueller, Jun 30, 2007
    #2
    1. Advertising

  3. Michael Mueller

    Roedy Green Guest

    On Sat, 30 Jun 2007 23:20:32 +0200, Michael Mueller <"news_
    "@_mueller-bruehl.de> wrote, quoted or indirectly quoted someone who
    said :

    >font = new Font("Sans-serif", Font.PLAIN, 11);


    the logical font is "SansSerif" not "Sans-serif"

    see http://mindprod.com/jgloss/font.html#LOGICAL
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jul 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZnJlZA==?=

    fontsize/stylesheet problem

    =?Utf-8?B?ZnJlZA==?=, Jun 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    427
    =?Utf-8?B?ZnJlZA==?=
    Jun 9, 2004
  2. Veeresh

    HTML Literal Control & FontSize

    Veeresh, Jun 28, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,329
    Veeresh
    Jun 28, 2004
  3. Tushar
    Replies:
    1
    Views:
    296
    Thomas Weidenfeller
    Feb 14, 2005
  4. Tom Parson
    Replies:
    12
    Views:
    56,424
    Benoit Peltier
    Jan 11, 2006
  5. Samuël van Laere

    Fontsize questions

    Samuël van Laere, Nov 20, 2003, in forum: HTML
    Replies:
    9
    Views:
    404
    Samuël van Laere
    Nov 21, 2003
Loading...

Share This Page