text-fit function?
[1/5] from: moliad:aei:ca at: 14-Aug-2004 1:28
does anyone know if there is a complement to the text-size function which tells you how
many chars fit inside a specific area or width?
or is there a style which, includes this data once enabled.
I was expecting the area style to store this info in its lines field... but upon inspecting
an allocated on, its lines attribute was still set to none...
TIA!
-MAx
[2/5] from: gabriele:colellachiara at: 14-Aug-2004 11:50
Hi Maxim,
On Saturday, August 14, 2004, 7:28:32 AM, you wrote:
MOA> does anyone know if there is a complement to the
MOA> text-size function which tells you how many chars fit inside
MOA> a specific area or width?
You can't know, fonts can be proportional. If your font is fixed
width, then you can just calculate the size of one character and
do a division.
MOA> I was expecting the area style to store this info in
MOA> its lines field... but upon inspecting an allocated on, its
MOA> lines attribute was still set to none...
Have a look at:
>> help textinfo
USAGE:
TEXTINFO face line-info line
DESCRIPTION:
Sets the line text information in an object for a face.
TEXTINFO is a native value.
ARGUMENTS:
face -- The face for which the information is defined. (Type: object)
line-info -- The object where the information will be set. (Type: object)
line -- The line to get information for. (Type: number any-string)
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[3/5] from: moliad:aei:ca at: 14-Aug-2004 13:10
Gabriele Santilli wrote:
> Hi Maxim,
> On Saturday, August 14, 2004, 7:28:32 AM, you wrote:
<<quoted lines omitted: 4>>
> width, then you can just calculate the size of one character and
> do a division.
in font handling gfx apis I've used before That is exactly why there is a text-fit function
which basically returns how many chars, using a proportional font will fit within a specific
width. This allows you change the font or break up your string as you wish... Like I
need to do right now... basically I need to handle word-wrapping manually....
> MOA> I was expecting the area style to store this info in
> MOA> its lines field... but upon inspecting an allocated on, its
<<quoted lines omitted: 10>>
> line-info -- The object where the information will be set. (Type: object)
> line -- The line to get information for. (Type: number any-string)
exactly what I needed, and more...
Although I did need to do some monitoring of rebol internals to find out exactly how
to use it... as is usually the case with VID and VIEW...
thanks!
Hi everyone, here is a function which splits up a face's word wrapping into a block.
:-)
;-------------------------------------------------------------------
get-word-wrap: func [
"Returns a block with a face's text, split up according to how it currently word-wraps."
face "Face to scan. It needs to have text, a size and a font"
/apply "Place the resulting block within the face's line-list property."
/offset "Include individual lines offset in resulting block (adds a pair! after each
text)"
/local txti counter blk offset
][
;only react if there is a font setup.
either none? face/font [
print "face/font is not set, cannot determine word wrapping"
][
counter: 0
txti: make system/view/line-info []
blk: copy []
while [textinfo face txti counter ] [
insert tail blk copy/part txti/start txti/num-chars
if offset [insert tail blk txti/offset]
counter: counter + 1
]
if apply [face/line-list: blk]
]
; free memory & return
txti: none
return first reduce [blk blk: none]
]
;-------------------------------------------------------------------
have fun!
-MAx
[4/5] from: gabriele::colellachiara::com at: 14-Aug-2004 21:00
Hi Maxim,
On Saturday, August 14, 2004, 7:10:59 PM, you wrote:
MOA> in font handling gfx apis I've used before That is
MOA> exactly why there is a text-fit function which basically
MOA> returns how many chars, using a proportional font will fit
MOA> within a specific width. This allows you change the font or
MOA> break up your string as you wish... Like I need to do right
MOA> now... basically I need to handle word-wrapping manually....
When needing to do that, I broke the string into words and then
measured them with SIZE-TEXT. Though that was because I was
actually positioning them in the face manually, word by word.
In your case TEXTINFO is much better.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[5/5] from: moliad:aei:ca at: 14-Aug-2004 16:10
> In your case TEXTINFO is much better.
yep, and it means I now have a text-to-draw function which supports fonts and word wrapping.
Current tests are conclusive enough to say that the text and draw are 100% overlapping,
when both are left within the face. Although the draw font is multicolored... :-)
I expect a VERY fast scrolling for my glayout table style. Irrelevant of the table size.
It will also allow multiple colored text per cell.
graham will be happy to read this, I am sure :-)
Again Thanks for guiding me to TEXTINFO ... I did not know that word existed, and its
not in the manuals... although its in view 1.2.1 !
-MAx
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted