_PRINT A clean scalable print type

Previous topic - Next topic

backspace

This little project was inspired when I discovered that the print does not zoom very well. This solution uses a large font file, and allows you to zoom it smaller for different sizes.

The left alignment needs a little work, but I'll leave that to the experts to play with. Note that this does not use the built in PRINT command, but duplicates what it does.

Code (glbasic) Select

TYPE _PRINTX
chr []
fontID
base
border = 2   //font border if used
fw = 64 + self.border    //font width
fh = 72 + self.border    //font height
count = 15

FUNCTION Init: font$
LOCAL i, j, c=-1, x,y
self.fontID = RND(1000)+1000
self.base = RND(10000)+2000
LOADSPRITE font$, self.fontID
FOR j = 0 TO 15  //change this to 31 to include high ascii values
FOR i = 0 TO 15
c = c + 1
x = i * self.fw
y = j * self.fh
CLEARSCREEN
DRAWSPRITE self.fontID, -x,-y
GRABSPRITE self.base + c, 0,0, self.fw, self.fh 
DIMPUSH self.chr[], self.base + c
NEXT
NEXT
CLEARSCREEN
ENDFUNCTION


FUNCTION _print: text$, x, y, scale#
LOCAL i,c, s$
FOR i = 0 TO LEN(text$)-1
s$ = MID$(text$,i,1)
c = ASC(s$)
ZOOMSPRITE self.chr[c], x + (i * self.fw *scale#), y, scale#, scale#
NEXT
ENDFUNCTION

ENDTYPE



LOCAL font1 AS _PRINTX   //define your own font object

font1.Init("arial72.png")  //initialize the font here

font1._print ("AbCdEfG 123", 0, 0, 0.2) 
font1._print ("Hello world", 0, 20, 0.2)
font1._print ("!@#$%^&*()_+", 0, 40, 0.3)
font1._print ("Is it a bird, is it a plane? No it's Super-GLBasic", 0 ,60, 0.18)
font1._print ("Eat your food to grow", 0, 80, 0.4)
font1._print ("even bigger", 0, 110, 0.6)
font1._print ("and bigger", 0, 140, 0.8)
font1._print ("Yum !", 30, 200, 1.5)
font1._print ("...oooOOOoooooo...", 20, 300, 0.5)

SHOWSCREEN
MOUSEWAIT


[attachment deleted by admin]
I came, I saw, I coded.

mentalthink

Thanks very interesting... and usefully...

kanonet

Nice work, but a few thoughts:
-normally i like to have everything inside a type, but here it makes things to long, the print command should ge a function outside of the type.
-without kerning its not to useful.

Btw. do you know Moru's scalable font systems? He did a great work with them, years ago. Too bad his website is down and i dont have a copy of it.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Moru

Aw I totally forgot about putting that page up again.

It's not all my work though, just modified Peejays code to use colours, faster rendering on tiny computers and auto-kerning.
Original can be found here for the kerning code, centering and justifying text and so on:
http://www.glbasic.com/forum/index.php?topic=1521.0

Haven't used it for anything useful yet though, really a sin.
The attached file should be the last update I did to it about three years ago.

[attachment deleted by admin]

backspace

There is a large difference in the project when a novice like myself attempts something, against when someone with a lot of experience does it. But I'll get there one day. 
Thank you for the link, The code gives me something to aspire to.  :nw:
I came, I saw, I coded.

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Hemlos

Nice font objects  :good:
One note, as it were, you have a possibility(although not likely), you might end up with an ID collision.
You can use the GENSPRITE command to eliminate such an event.

Bing ChatGpt is pretty smart :O