FontView 5
Posted: Wed Oct 11, 2017 4:14 pm
I missed publishing version 4, but no matter. This version has buttons loaded from images (introduced in SPL update 24) and buttons modified with the new parameters font name, fontcolor and font size (introduced in SPL update 25). I used Ranchers font, available free at 1001fonts.com. If you don't want to install it, you will need to insert a different font name for buttons.
The four button images will need to be downloaded and placed in a folder called Fontview at the same path as the program.
The four button images will need to be downloaded and placed in a folder called Fontview at the same path as the program.
Code: Select all
''
FontView 5 by rbytes
October 2017
View all of the fonts on your device
at any size you wish.
V5 shows buttons using fontname, fontsize and fontcolor parameters
V4 introduces the new V24 features
- #.listbox object to show fonts
- #.relax() function as a CPU slowdown in main loop
- .image parameter for buttons, to add a background image
V3 resizes the interface to work
on any Windows 10 device
V2 improves the layout and improves
the button functions
''
' hide the control menu - screenwidth increases by 48 points
#.scrview(#.normal)
' get screen size and calculate scaling for device
x,y = #.scrsize()
rw = x/1280 ; rh = y/813
z = #.int(46*rw)
q = 1 ; base = 0
#.scrclear(.8,.8,.8)
#.drawcolor(0,0,1)
#.fillcolor(.8,.8,.8)
e = "The Quick Brown Fox Jumps Over The Lazy Dog"
fn = "fontchoice.txt"
ff = #.fexist(fn)
? ff, #.fdelete(fn)
l = #.fontlist() ; n = #.size(l,1)
' draw frame around listbox
#.drawsize(2)
#.drawrect(19*rw,19*rh,381*rw,367*rh)
' create listbox
t = #.listbox
t.source = l
fl = 0 ' flag to work around slider bug
> g, 1..n
d += g+": "+ l[g] + #.lf
<
t.width = 360*rw ; t.height = 346*rh
t.x = 20*rw ; t.y = 20*rh
t.index = 1
#.show(t)
' create button template
h = #.button ; h.height = 70*rh
h.width = 100*rw ; h.y = 70*rh
h.fontsize = 30 ; h.fontname = "Ranchers"
h.fontcolor(1,1,1)
' create buttons from template
f,g,j,k = h ; f.x = 530*rw ; g.x = 980
j.x = 680*rw ; k.x = 830*rw
f.image = "Fontview/redbutt.png"
g.image = "Fontview/greenbutt.png"
j.image = "Fontview/bluebutt.png"
k.image = "Fontview/yellowbutt.png"
f.text = "STOP" ; g.text = "SAVE"
j.text = "PREV" ; k.text = "NEXT"
#.show(f,g,j,k)
' create sliders
sh,sv = #.slider ' font name slider and size slider
sh.x = 360*rw ; sh.y = 710*rh
sh.min = 1 ; sh.max = n
sh.size = 600*rw ; sv.x = 360*rw
sv.y = 760*rh ; sv.value = z
sv.min = 10 ; sv.max = #.int(220*rw)
sv.size = 600*rw
#.show(sh,sv)
#.fontsize = #.int(35*rw)
#.drawtext(180*rw,690*rh,"FONT NAME")
#.drawtext(180*rw,740*rh,"FONT SIZE")
' show first font in list
#.drawrect(450*rw,265*rh,1200*rw,365*rh)
#.fontsize(z)
#.fontname(l[1])
#.fontname(#.default)
#.drawtext(460*rw,275*rh,l[1])
#.drawtext(20*rw,400*rh+base,e)
' show font name and point size
#.drawrect(450*rw,205*rh,1200*rw,265*rh)
#.fillrect(451*rw,260*rh,822*rw,280*rw)
#.fontsize(#.int(35*rw))
#.fontname(#.default)
#.drawline(825*rw,205*rh,823*rw,265*rh)
#.drawtext(460*rw,205*rh,"Font Name:")
#.drawtext(835*rw,205*rh,"Font Size:")
#.drawtext(1060*rw,205*rh,z)
' main program loop
>
? #.act(sh) ' font name slider
q = #.int(sh.value)
t.index = q
print <->
.
? #.act(sv) ' size slider
? fl
z = #.int(sv.value*rw)
.
fl = 1
print <->
.
? #.act(f) ' stop button
#.end()
.
? #.act(g) ' save button
#.writeline(fn,l[q])
#.writeline(fn,z)
#.clipboard("' " + l[q] +", size " + z)
#.drawrect(590,155,710,195)
#.drawtext(600,150,"SAVED")
#.delay(2)
#.fillrect(585,150,715,200)
.
? #.act(j) ' prev button
? q > 0
q -= 1
sh.value = q
t.index = q
print <->
.
.
? #.act(k) ' next button
? q < n -1
q += 1
sh.value = q
t.index = q
print <->
.
.
? #.act(t) ' font list selected
q = t.index
sh.value = q
print <->
.
#.relax()
<
:print ' draw font subroutine
#.fillrect(452*rw,267*rh,1198*rw,363*rh)
#.fillrect(0*rw,390*rh,x,y-125)
#.fontsize(46*rw)
#.fontname(#.default)
' Gabriola baseline shifts too far
? l[q] = "Gabriola" & z > 120
base=-90*rh
!
base=0
.
' display font name, size and sample text
#.drawtext(460*rw,275*rh,l[q])
#.fillrect(451*rw,260*rh,822*rw,280*rw)
#.fontsize(#.int(35*rw))
#.fillrect(1020*rw,210*rh,1198*rw,260*rh)
#.drawtext(1060*rw,205*rh,z)
#.fontsize(z)
#.fontname(l[q])
#.drawtext(20*rw,400*rh+base,e)
<-