news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

TextUtils

This XFCN lets you find out all sorts of interesting things about bits of text!

TextUtils XFCN. Version 1.0, by Sam Deane. Copyright ©1994 ULTRALAB. Compiled 15:42:52, 12/12/94.


[last exit to hypercard] [externals index] [download TextUtils]

Description

You can use this XCMD to find out how wide a piece of text is in a given font/style/size. I use this to resize buttons, so that their names fit in neatly.

You can also use it to find out how deep (in pixels) some text is in a field. This allows you to work out, on the fly, whether a field needs to be scrolling or not to fit a given bit of text into it.


Commands

width

You can use the width command to find out how wide a piece of text is in a given font/style/size.

The syntax is:

   get TextUtils(width,<string>,<font>)

The <string> parameter should contain the text to be measured.

The <font> parameter should contain the font, size, and style of text in the format:

  <font>,<size>,<style>

Example script for width

on mouseUp
  Ask "Text?"
  if it is not empty then
    put it into text
    put "Helvetica" into font
    put "10" into size
    put "bold" into style
    put font & comma & size & comma & style into fontStuff
    
    get TextUtils(width,text,fontStuff)
    put text & " was " & it & " pixels in Bold Helvetica 10."
  end if
end mouseUp

fieldHeight

You can use the fieldHeight command to find out how deep (in pixels) some text is in a field.

The syntax is:

  get TextUtils(fieldHeight,<name>,<background>)

The <name> parameter is the name of a field. The <background> parameter is a boolean, true if the field is on the background, false otherwise.

Example script for fieldHeight

on closeField
  get TextUtils(fieldHeight,"Test",TRUE)
  set the height of me to it+8
end closeField

[last exit to hypercard] [externals index] [download TextUtils]

This page was created automatically, on 25/03/1999 from version 3.0d4 of Last Exit To Hypercard.