fontsize in textlayout

M

Michael Mueller

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
 
M

Michael Mueller

Michael said:
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();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top