Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: text-fit function?

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: > > 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.
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 > 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)
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