Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clarion - AdjustFontSizeByHeight
! Code by MarkG on the skype cw-chat
AdjustFontSizeByHeight PROCEDURE(LONG xDesiredHInPixels, UNSIGNED xFEQ)
holdPixels LONG
CODE
holdPixels = 0{PROP:Pixels}
0{PROP:Pixels} = TRUE
IF xFEQ{PROP:Height} < xDesiredHInPixels
DO SearchByIncreasing
ELSIF xFEQ{PROP:Height} > xDesiredHInPixels
DO SearchByDecreasing
END
0{PROP:Pixels} = HoldPixels
SearchByIncreasing ROUTINE
LOOP
IF xFEQ{PROP:Height} = xDesiredHInPixels
BREAK
ELSIF xFEQ{PROP:Height} > xDesiredHInPixels
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1
BREAK
ELSE
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1
END
END
SearchByDecreasing ROUTINE
LOOP
IF xFEQ{PROP:Height} = xDesiredHInPixels
BREAK
ELSIF xFEQ{PROP:Height} < xDesiredHInPixels
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1
BREAK
ELSE
xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1
END
END
!------------------------
! Additional comments and things to change
Omit('***demo***')
AlterFontSizeToFit PROCEDURE(LONG xProp, LONG xDesired, UNSIGNED xFEQ)
CODE
IF xFEQ{xProp} < xDesired THEN DO SearchByIncreasing
ELSIF xFEQ{xProp} > xDesired THEN DO SearchByDecreasing
END
SearchByIncreasing ROUTINE
LOOP
IF xFEQ{xProp} = xDesired THEN BREAK
ELSIF xFEQ{xProp} > xDesired THEN xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1; BREAK
ELSE xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1
END
END
SearchByDecreasing ROUTINE
LOOP
IF xFEQ{xProp} = xDesired THEN BREAK
ELSIF xFEQ{xProp} < xDesired THEN xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} + 1; BREAK
ELSE xFEQ{PROP:FontSize} = xFEQ{PROP:FontSize} - 1
END
END[4:37 PM] Mark.Goldberg:
<<< AlterFontSizeToFitHeight PROCEDURE(LONG xDesired, UNSINGED xFEQ)
CODE
SELF.AlterFontSizeToFit( PROP:Height, xDesired, xFEQ)
AlterFontSizeToFitWidth PROCEDURE(LONG xDesired, UNSINGED xFEQ)
CODE
SELF.AlterFontSizeToFit( PROP:Width, xDesired, xFEQ)
***demo***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.