Fit font-size to screenwidth V2

Post Reply
User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Fit font-size to screenwidth V2

Post by Dutchman »

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:

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
In the manual some notes are added about this subject.
Last edited by Dutchman on Tue Mar 28, 2017 8:34 am, edited 2 times in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Fit font-size to screenwidth

Post by rbytes »

Nice coding! This will be very useful.

Incidentally, I am a big fan of Menlo. I think it is the best-looking monospaced font - and very readable.
The only thing that gets me down is gravity...

Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

Re: Fit font-size to screenwidth

Post by Joel »

please be careful. this program changes your customized editor settings!!

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Fit font-size to screenwidth

Post by Dutchman »

Joel wrote:
Thu Feb 23, 2017 10:20 am
please be careful. this program changes your customized editor settings!!
Yes and it can be restored with SET EDITOR DEFAULT ;)

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Fit font-size to screenwidth V2

Post by Dutchman »

I updated the code so that fontsize remains the same if device is in horizontal or vertical position.

Post Reply