Fit font-size to screenwidth V2
Posted: Mon Feb 20, 2017 12:15 pm
With monospaced fonts, e.g. “Courier” or "Menlo-Regular", the number of characters per line can be fixed.
In the following code the number of characters per line can be set for the editor and for the output:
In the manual some notes are added about this subject.
In the following code the number of characters per line can be set for the editor and for the output:
Code: Select all
'Set Editor and Output V2
'by Dutchman febr. 2017
'Adjust fontsize to the picture-width
'fonts should be monospace: "Menlo-Regular" or "Courier"
'
'--- presets for iPad
Neditor=100 'number of chatacters per line on minimum width
Noutput=80 'number of chatacters per line on minimum width
CALL SetEditor(Neditor)
CALL SetOutput(Noutput)
'
'--- test
FOR i=1 TO Noutput
q$&=i%10
NEXT i
PRINT q$
'check editor-width. Next line is 100 characters long
'234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
END
'==== Functions
DEF SetEditor(n) 'set style and characters per minimum width
'--- set fontsize
GET SCREEN SIZE sw,sh
fmin=9 'minimum fontsize
fsize=MAX((MIN(sw,sh)-20)/(0.6*n),fmin)
'--- set style
SET EDITOR FONT COLOR 0,0,0
SET EDITOR BACK COLOR 1,.94,.86
SET EDITOR FONT NAME "Menlo-Regular"
SET EDITOR FONT SIZE fsize
'SET EDITOR FONT NAME "Courier"
'SET EDITOR DEFAULT
TEXT CLEAR
END DEF
'
DEF SetOutput(n)'set style and characters per minimum width
GET SCREEN SIZE sw,sh
fmin=9 'minimum fontsize
fsize=MAX((MIN(sw,sh)-20)/(0.6*n),fmin)
SET OUTPUT FONT COLOR 0,0,0
SET OUTPUT BACK COLOR 1,1,1
SET OUTPUT FONT NAME "Menlo-Regular"
SET OUTPUT FONT SIZE fsize
END DEF