How to make an always readable text?

Example object for this post can be downloaded here.

When displaying texts in 2D, a text’s readability and rotation might be requested. If the current view or the 2D symbol which contains the text is rotated, then the displayed text rotates with the symbol (Align with Symbol). The following example provides two further options for the text’s behavior in case of rotation: readable text and text which stays always horizontal. The “iTypeTextRotation” controlled by the user could be 0 (Align with Symbol), 1 (Always Horizontal) or 2 (Readable).

For providing these options the angle of the actual rotation of the texts should be known. The “View_Rotangle” request is used for getting the rotation angle of the current view, the SYMB_ROTANGLE global gives the rotation of the library part. The sum of these angles could be more than 360°, so the MOD operation cuts off the whole 360°-s from it.

In case of readable text when the actual rotation is between 90° and 270° the coordinate system of the text should be rotated by 180° to maintain readability. The _nTrans variable counts the number of transformation of the coordinate system, which should be deleted after displaying the required text. It is not relevant whether the library part is mirrored or not, the 180° always concerns the angle between 90° and 270°.

In case of always horizontal text the coordinate system of the text should be rotated by the actual rotation. If the library part is mirrored (check SYMB_MIRRORED global), the text should be rotated by the negation of the actual rotation.

! ------------------------------------------------------------------------------
! Input parameters controlled by the user:
! ------------------------------------------------------------------------------
! ZZYZX 		- (Length) height of the block whose data are displayed
! blockWidth 		- (Length) width of the block whose data are displayed
! blockDepth 		- (Length) depth of the block whose data are displayed
! 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
! iTypeTextRotation 	- (Integer) type of the text rotation:
! 		 	  0 - Align with Symbol, 1 - Always Horizontal, 
! 		 	  2 - Readable
! 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

! ------------------------------------------------------------------------------
! Draw the block in 2D
! ------------------------------------------------------------------------------
rect2 0, 0, blockWidth, blockDepth

! ------------------------------------------------------------------------------
! 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

! ------------------------------------------------------------------------------
! Text Rotation - Readable / Always Horizontal / Align with Symbol
! ------------------------------------------------------------------------------
r = request ("View_Rotangle", "", _angleViewRot)

! Actual rotation of the 2D symbol:	
_totalRotate	= (SYMB_ROTANGLE + _angleViewRot) MOD 360

! Count the number of transformations of the 
! coordinate system in different cases
_nTrans = 0					  
 
if iTypeTextRotation = 2 then					! Readable
    if (_totalRotate > (90 + EPS) & _totalRotate < (270 + EPS)) then
        rot2 180
        _nTrans = _nTrans + 1
    endif
else
    if iTypeTextRotation = 1 then				! Horizontal
        rot2 _totalRotate * (SYMB_MIRRORED - not(SYMB_MIRRORED))
        _nTrans = _nTrans + 1
    endif
endif
 
! ------------------------------------------------------------------------------
! 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 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

! ------------------------------------------------------------------------------
! Delete transformation after Text Rotation
! ------------------------------------------------------------------------------
del _nTrans

This example produces the result below:
TipsAndTricks_TextRead_Ex1

Command and function pool:
RECT2
DEFINE STYLE
“View_Rotangle”
SYMB_ROTANGLE
MOD
ROT2
SYMB_MIRRORED
GLOB_SCALE
[SET] STYLE
TEXT2
DEL