Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to determine width of text in a text field in page units or p ixels

1 view
Skip to first unread message

Trent Schwartz

unread,
Oct 23, 2002, 11:54:18 AM10/23/02
to
Greetings,

Is there a way to determine the width of text in a field in page units or
pixels?

I want to automatically draw a text field that fits the width and height of
the text. The number of characters, font, and size will vary. I don't want
to draw just a standard sized text field. For example, I could draw a
standard sized text field that is 7000 X 400 page units, when I only need
1300 X 200, the standard sized field would be 6 times larger than what I
need. Likewise, I don't want to draw too small of a text box so that the
text would be cut off or word wrapped. I don't mind word wrapping for a long
sentence, but I want to be able to determine what the width text would be
and then decide if it should be word wrapped.

For example, text "This is text" in a field with: font-MS San Serif,
style-Bold, Size-24 is exactly 2445 X 345 (W X H in page units), so the
field can be 2655 X 495. While the same text with: font-courier,
style-regular, size-12 is exactly 1605 X 150 the field can be 1800 X 225.


Trent

Daniel Kirsch

unread,
Oct 23, 2002, 1:21:04 PM10/23/02
to
Trent Schwartz schrieb:

> Is there a way to determine the width of text in a field in page units or
> pixels?

Trent,
one easy way would be to select your text, create a hotword, get the
bounds of that hotword and set everything back. This way, you don't need
to check anything else like fontface, fontsize etc:

refField = field "foo" of page "fooPage"
origText = richText of refField
select text of refField
send createHotword
fieldBounds = bounds of selectedHotwords
bounds of field "dynamicField" = fieldBounds
-- or draw it dynamically:
--pop fieldBounds into x1
--pop fieldBounds into y1
--pop fieldBounds into x2
--pop fieldBounds into y2
--draw field from x1,y1 to x2,y2

richText of refField = origText
-- or
--send removeHotword

HTH
Daniel

(Note: this one is not tested, hope it works anyway)

John Ballard

unread,
Oct 23, 2002, 12:51:22 PM10/23/02
to
Hi Trent,

I think the textrightoverflow property of the field
might be what you're looking for. You can check its value and do a step to
increment the bounds of the text field until textrightoverflow is 0. There
are a few other textoverflow properties that might be worth validating
too--I can't remember their names of the top of my head.

Hope this helps,
John Ballard

Ballard Publishing Co.
8815 Green Castle Way
Houston, TX 77095

Toll Free: 866-300-3535
Toll Free Fax: 866-390-3535
Houston: 281-550-9422
jo...@ballardpublishing.com


----- Original Message -----
From: "Trent Schwartz" <Tsch...@JACKSONGRAPHICS.COM>
To: <TOO...@listserv.arizona.edu>
Sent: Wednesday, October 23, 2002 10:55 AM
Subject: How to determine width of text in a text field in page units or p
ixels


> Greetings,


>
> Is there a way to determine the width of text in a field in page units or
> pixels?
>

Trent Schwartz

unread,
Oct 23, 2002, 1:20:03 PM10/23/02
to
Thanks John! This will work...

Trent

0 new messages