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 / July 2006

Tip: Looking for answers? Try searching our database.

How to calculate the amount of space taken by a given text?

Thread view: 
Stefan Waldmann - 13 Jul 2006 09:48 GMT
Hello Everyone,

in a Java web application, a user can enter a text (HTML textarea) which
is then sent to a Servlet. This text should later appear in a Text Box
of a PowerPoint presentation, which can be downloaded by the user. The
width of the Text Box is fixed, as is the font type and size in which
the text should appear (it's a true type font).

To get the text into the PowerPoint Text box is not the problem; for
this we are using a commercial PPT library by tonic systems.

However, the Servlet should send a warning message to the user, if the
text given by him wouldn't fit into the PowerPoint Text Box. If too much
text is given, the Box would automatically extend downwards, and the
text would overlap with the text from another Text Box below. But this
should not happen, so in this case the warning should be displayed.

Does anyone have an idea how to do a calculation if the given text would
fit into the box or if it wouldn't? The problem is that the text can
wrap automatically when it hits the rightmost boundary of the box, and
that the letters of a TrueType font have different widths; so a
calculation based on newlines and number of characters wouldn't work.

I would be grateful for any hint or suggestion (or even a ready solution
;-) how to solve this problem

Thanks and regards
Stefan
Andrew T. - 13 Jul 2006 10:26 GMT
...
> in a Java web application, a user can enter a text (HTML textarea) which
> is then sent to a Servlet. This text should later appear in a Text Box
> of a PowerPoint presentation, which can be downloaded by the user. The
> width of the Text Box is fixed, as is the font type and size in which
> the text should appear (it's a true type font).
...
> However, the Servlet should send a warning message to the user, if the
> text given by him wouldn't fit into the PowerPoint Text Box.

Assuming you can get a Font object of this TrueType font, the
java.awt.FontMetrics.stringWidth(java.lang.String) method
should give you the 'length of a piece of string'.

Andrew T.


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.