15. Text handling

 

  Example object for this post

Usage of TEXT2 or RICHTEXT2

Depending on the complicity of the text needed to be displayed, you are able to choose between two text commands: the TEXT2 and the RICHTEXT2 commands. The RICHTEXT2 command is recommended in the following cases:

  • different text styles are required in one text
  • different pens are required in one text (different materials in case of 3D texts)
  • automatic line breaking is required
  • superscript, subscript or strikethrough texts are required

The following diagram shows the recommended usage of the commands related to TEXT2 and RICHTEXT2:
GDLBasics_TextHandling_Ex1

The usage of DEFINE STYLE{2} is not recommended for the TEXT2 command because the additional superscript, subscript and strikethrough flags do not work with the TEXT2 command, and the anchor is not available in DEFINE STYLE{2}.

The usage of DEFINE STYLE is not recommended for the RICHTEXT2 command because the anchor has no effect on the PARAGRAPH, and the the additional superscript, subscript and strikethrough flags are not available in DEFINE STYLE.

The DEFINE STYLE command

The DEFINE STYLE command is an option for affecting the representation of the texts needed to be displayed.

! ------------------------------------------------------------------------------
! Input parameters controlled by the user:
! ------------------------------------------------------------------------------
! sampleSize 		- (RealNum) indicates the height of the font from the
! 		 	  baseline to the cap height, given in Paper size - mm
! fontType 		- (String) font family of the displayed text
! stAreaName 		- (String) the name of the block area value
! stVolumeName 		- (String) the name of the block volume value
! stWidthName 		- (String) the name of the block width value
! stDepthName 		- (String) the name of the block depth value
! stHeightName 		- (String) the name of the block height value

! ------------------------------------------------------------------------------
! Define styles
! ------------------------------------------------------------------------------
! Not all of the following variables are used in this example, but the kind of
! definition showed below is the GRAPHISOFT standard constant definition

! Text styles
NORMAL		= 0
BOLD 		= 1
ITALIC 		= 2
UNDERLINE 	= 4

! Anchor positions
LEFT_UPPER	= 1
MIDDLE_UPPER	= 2
RIGHT_UPPER	= 3
LEFT_MIDDLE	= 4
MIDDLE		= 5
RIGHT_MIDDLE	= 6
LEFT_LOWER	= 7
MIDDLE_LOWER	= 8
RIGHT_LOWER	= 9

! Define the different text styles
define style "ItalicStyle" 	fontType, sampleSize, LEFT_UPPER, ITALIC
define style "NormalStyle" 	fontType, sampleSize, LEFT_UPPER, NORMAL

GDLBasics_TextHandling_Ex2

Note that the anchor position and the Text styles (face_code in GDL Reference Guide) could also be parameters available for the users. For the font family the “fontType” parameter name is recommended, because using this name provides the value list for the font family automatically.

! ------------------------------------------------------------------------------
! Set input data for the text drawing
! ------------------------------------------------------------------------------

! Set the multiplier of the paper scale
PAPER_TO_MODEL = GLOB_SCALE / 1000

! Set text coordinate variable:
! samplesize parameter is given in Paper Size - mm, 
! convert it into Model size  - m, calculate the row height from it, 
! therefore the row height will not depend on the font family
dy = - sampleSize * 1.5 * PAPER_TO_MODEL

! ------------------------------------------------------------------------------
! Display the texts
! ------------------------------------------------------------------------------
style "ItalicStyle"			! Set the previously defined style

text2 0, 0, 	stAreaName
text2 0, dy, 	stVolumeName

style "NormalStyle"			! Set the previously defined style

text2 0, dy * 2, stWidthName
text2 0, dy * 3, stDepthName
text2 0, dy * 4, stHeightName

In the script above the “samplesize” parameter is controlled by the user and it is given in “mm”. To use this value for displaying the text, it has to converted into Model Size (m). For this conversion the GLOB_SCALE global is needed, for getting the actual scale in which the text is displayed. The samplesize parameter indicates the height of the font from the baseline to the cap height. Using this parameter for the vertical coordinates, the position of each texts will not depend on the font family. If the distance of the texts is required to depend on the font family, the font height of the actual font family should be requested:

! ------------------------------------------------------------------------------
! Set input data for the text drawing
! ------------------------------------------------------------------------------

! Set the multiplier of the paper scale
PAPER_TO_MODEL = GLOB_SCALE / 1000

! Get the height of the actual text style in Paper Size - mm
r = request ("Height_of_style", "NormalStyle", _textSize)

! Set text coordinate variable:
! _textSize variable is given in Paper Size - mm,
! convert it into Model size  - m, calculate the row height from it, 
! therefore the row height will depend on the font family
dy = - _textSize * PAPER_TO_MODEL

GDLBasics_TextHandling_Ex3
For the usage of the DEFINE STYLE{2} command see the Advanced Text Handling Tutorial.

Command and function pool:
DEFINE STYLE
GLOB_SCALE
[SET] STYLE
TEXT2
“Height_of_style”