Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

fontsize in textlayout

Thread view: 
Michael Mueller - 30 Jun 2007 22:20 GMT
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 - 30 Jun 2007 22:44 GMT
Michael Mueller schrieb:
> Hi
>
[quoted text clipped - 37 lines]
>
> Michael

I got it.

I just added an attribute...
   AttributedString styledText = new AttributedString(out);
   styledText.addAttribute( TextAttribute.FONT, font );
   AttributedCharacterIterator charIterator = styledText.getIterator();
Roedy Green - 01 Jul 2007 00:28 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.