QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: bplus on October 23, 2021, 09:09:18 pm

Title: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 09:09:18 pm
I had a calendar making program spaced just right with Windows Font something happened when I went to make calendars for this year using QB64 v2.0, it turns out the Font change occurred in QB64 v1.5 just never caught it because was not working with fonts for awhile.

Something happened that stretches the f o n t  a l o n g  t h e  x - a x i s ??
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

The upper is the look from QB64 v 1.5 and v 2.0

The lower is the look from QB64 v 1.4 (I had changed form arial rounded bold to just arial to make sure it wasn't just the one font acting different.

I also noticed this "spread out look" trying different fonts in the Crypt-O-Gram variations and had to stick with the default because it was spreading out so wide across the screen.
Title: Re: Big ugly font difference between QB664 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SpriggsySpriggs on October 23, 2021, 09:13:01 pm
Looks to me like one is monospaced and one isn't
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 09:16:43 pm
Same exact code printed both those images just that one was done in QB64 v 1.4 and the other QB64 v1.5.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 09:27:07 pm
This is the start of the program with the font loading:
Code: QB64: [Select]
  1. CONST XMAX = 1100
  2. CONST YMAX = 700
  3. CONST tMar = 40 'top margin allows room for 3 hole binder punch on top (landscape orientation) or left side (portrait orientation)
  4. CONST sideMar = 10
  5. SCREEN _NEWIMAGE(XMAX, YMAX, 32)
  6. DIM dayNames$(0 TO 6), monthNames$(1 TO 12), monthDays(1 TO 12) AS INTEGER
  7. FOR i = 0 TO 6: READ dayNames$(i): NEXT
  8. DATA "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
  9. FOR i = 1 TO 12: READ monthNames$(i): NEXT
  10. DATA "January","February","March","April","May","June","July","August","September","October","November","December"
  11. FOR i = 1 TO 12: READ monthDays(i): NEXT
  12. DATA 31,28,31,30,31,30,31,31,30,31,30,31
  13.  
  14. ' this loads and checks fonts (Windows 10)
  15. DIM SHARED FH, CH, CW, FH2, CH2, CW2
  16. FH = _LOADFONT("Arial.ttf", 24, "MONOSPACE")
  17. IF FH <= 0 THEN PRINT "Trouble with font load file, goodbye.": SLEEP: END
  18. CH = _FONTHEIGHT(FH): CW = CH * .6 'this make printing char by char the same as printing a string for ARLRDBD.ttf
  19. 'test font, in box? for 5 above 5 below height = 30
  20. 'Line (5, 5)-Step(CW * Len(monthNames$(1) + Str$(2018)), 30), , B
  21. '_PrintString (10, 10), monthNames$(1) + Str$(2018)
  22.  
  23. FH2 = _LOADFONT("Arial.ttf", 18, "MONOSPACE")
  24. IF FH2 <= 0 THEN PRINT "Trouble with font load file, goodbye.": SLEEP: END
  25. CH2 = _FONTHEIGHT(FH2): CW2 = CH2 * .25 'this make printing char by char the same as printing a string for ARLRDBD.ttf
  26. _FONT FH2
  27. 'Line (5, 45)-Step(CW2 * Len("testing smaller font 1, 2, 3, 31"), 25), , B
  28. '_PrintString (10, 50), "testing smaller font 1, 2, 3, 31"
  29.  
  30. y = 2022 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< update for 2021
  31. DIM EasterMonth AS INTEGER, EasterDay AS INTEGER
  32. Easter y, EasterMonth, EasterDay
  33. 'PRINT EasterMonth, EasterDay, CH2
  34. 'END
  35.  

hmm looks like I set CW2 wrong but that does not make a difference to how wide it's printing.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 09:38:36 pm
Here is a simplified example to see it clearly:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: Pete on October 23, 2021, 09:41:28 pm
I got bit with some similar "font" bug earlier, in my Wheel of Fortune spoof. I ran perfectly in V2.0 and 1.5 but did not pick up _FONTWIDTH, _FONTHEIGHT the same in 1.3 and 1.4.

Pete
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 10:13:58 pm
Here is a simplified example to see it clearly:

  [ This attachment cannot be displayed inline in 'Print Page' view ]

Looks like an obvious bug fix to me.

The left one isn't monospaced.  Those 2 "l" use up less screenspace than the single "H" does.The one on the right is spacing everything the same width as that "W", which *does* make it monospaced.

If that's not what you're wanting then remove "MONOSPACE" from the load parameters for _LOADFONT".
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: FellippeHeitor on October 23, 2021, 10:17:51 pm
It indeed looks like loading monospaced fonts does work as expected beginning with v1.5.

@bplus as Steve said, removing “monospaced” should give you the results you expected.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 10:21:12 pm
I got bit with some similar "font" bug earlier, in my Wheel of Fortune spoof. I ran perfectly in V2.0 and 1.5 but did not pick up _FONTWIDTH, _FONTHEIGHT the same in 1.3 and 1.4.

Pete

Probably the same issue.  From the screenshots, it's obvious there was a bug fix introduced into the source.  Before 1.5, that "MONOSPACE" wasn't auto-spacing fonts at all. 

Run this as a print under Bplus's "Hello World" code.

PRINT "HWHW".
PRINT "llll".

If the fonts are monospaced, both outputs should use the same screen width.  In 1.5, they do.  Before that, they're bugged.

HWHW
llll


Vs.

HWHW
llll
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: Pete on October 23, 2021, 10:50:04 pm
Here's how I experienced the bug. I cut away non-essential code. In 1.5 up , it displays the _FONTWIDTH correctly, as 36. In 1.4 and 1.4, it displays 0, which is incorrect.

Code: QB64: [Select]
  1. DIM SHARED overlay
  2.  
  3. Screen0 = _NEWIMAGE(80, 25, 0)
  4. SCREEN Screen0
  5.  
  6. font = _LOADFONT("lucon.ttf", 60, "monospace")
  7. IF font <= 0 THEN font = 16
  8.  
  9. _DEST overlay
  10. _FONT font
  11. COLOR _RGB(255, 102, 0), 0
  12.  
  13.  
  14. y = 1: x = 1
  15. COLOR _RGB(255, 255, 255)
  16. t$ = "I'd like to solve the puzzle, please!"
  17. PSL y, x, t$
  18.  
  19. _FREEIMAGE overlay
  20.  
  21. _DELAY .66
  22.  
  23.  
  24.  
  25. SUB PSL (y, x, t$)
  26.     t$ = LTRIM$(STR$(_FONTWIDTH))
  27.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  28.     overlay_hardware = _COPYIMAGE(overlay, 33)
  29.     _PUTIMAGE (0, 0), overlay_hardware
  30.     _DISPLAY
  31.  

Pete
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 11:08:44 pm
It indeed looks like loading monospaced fonts does work as expected beginning with v1.5.

@bplus as Steve said, removing “monospaced” should give you the results you expected.

Thanks guys. Guess I am living in past. I remember "MONOSPACE" was required for .ttf, at one time. I do like a consistent width for characters but not the same as Height, yikes! it even looks more than that to me.

But now how can I get consistent width about .5 the height of a character? Like the default font, very easy to use and predict it's length, no matter the string, and looks normally spaced.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 11:10:07 pm
Here's how I experienced the bug. I cut away non-essential code. In 1.5 up , it displays the _FONTWIDTH correctly, as 36. In 1.4 and 1.4, it displays 0, which is incorrect.

Code: QB64: [Select]
  1. DIM SHARED overlay
  2.  
  3. Screen0 = _NEWIMAGE(80, 25, 0)
  4. SCREEN Screen0
  5.  
  6. font = _LOADFONT("lucon.ttf", 60, "monospace")
  7. IF font <= 0 THEN font = 16
  8.  
  9. _DEST overlay
  10. _FONT font
  11. COLOR _RGB(255, 102, 0), 0
  12.  
  13.  
  14. y = 1: x = 1
  15. COLOR _RGB(255, 255, 255)
  16. t$ = "I'd like to solve the puzzle, please!"
  17. PSL y, x, t$
  18.  
  19. _FREEIMAGE overlay
  20.  
  21. _DELAY .66
  22.  
  23.  
  24.  
  25. SUB PSL (y, x, t$)
  26.     t$ = LTRIM$(STR$(_FONTWIDTH))
  27.     _PRINTSTRING ((x - 1) * _FONTWIDTH, (y - 1) * _FONTHEIGHT), t$
  28.     overlay_hardware = _COPYIMAGE(overlay, 33)
  29.     _PUTIMAGE (0, 0), overlay_hardware
  30.     _DISPLAY
  31.  

Pete

0 is correct-- that's the result you get when the font is not loaded using MONOSPACE.

Since momospace was broken prior to v1.5, so that it didn't actually load and make fonts monospaced, then a 0 for fontwidth is the expected, and correct, result. 

V1.5 fixed the issue with loading monospace fonts, so that value will obviously change to reflect that for you.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 11:13:57 pm
Thanks guys. Guess I am living in past. I remember "MONOSPACE" was required for .ttf, at one time. I do like a consistent width for characters but not the same as Height, yikes! it even looks more than that to me.

But now how can I get consistent width about .5 the height of a character? Like the default font, very easy to use and predict it's length, no matter the string, and looks normally spaced.

It's not the same as height-- it sets it so each character has the same WIDTH.  Look at the width of the "W" on your screenshot and then look at the width of those "l"s.  Even from the beginning, everything had the same height (you specified it with the 24 in the second parameter), but the widths were inconsistent.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 11:28:09 pm
Notice the difference in the widths in the same font here, once loaded with monospace and once without:

Code: QB64: [Select]
  1. Screen _NewImage(1280, 1024, 32)
  2. t$ = "Hello World"
  3. For i = 0 To 10
  4.     text$(i) = Mid$(t$, i + 1, 1)
  5.  
  6.  
  7. FH = _LoadFont("Arial.ttf", 24)
  8. For i = 0 To 10
  9.     Locate i + 1, 1: Print text$(i); text$(i), _PrintWidth(text$(i))
  10.  
  11. FH2 = _LoadFont("Arial.ttf", 24, "MONOSPACE")
  12. _Font FH2
  13. For i = 0 To 10
  14.     Locate i + 1, 20: Print text$(i); text$(i), _PrintWidth(text$(i))
  15.  
  16.  

Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 23, 2021, 11:35:13 pm
Repeat:
Quote
But now how can I get consistent width about .5 the height of a character? Like the default font, very easy to use and predict it's length, no matter the string, and looks normally spaced.

That Monospace is worthless to me, it's way too wide. How can I get like a guaranteed 12 X 24, 32 X 64, 48 x 96, 10 X 20 for all characters?
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 23, 2021, 11:44:04 pm
Repeat:
That Monospace is worthless to me, it's way too wide. How can I get like a guaranteed 12 X 24, 32 X 64, 48 x 96, 10 X 20 for all characters?

Choose a font designed in that 2:1 ratio by its designer.  Arial isn't a monospaced font natively, as that "W" is 3 times the width as that "l".  Check your system for monospace fonts and see how they're designed.  Many are on a .5 ratio, a few are .6, and I've seen some that are .8 ratios.  It all depends on how they were created at design time.

The only monospaced TrueType fonts shipped by Microsoft are Courier New, which shipped with Windows 3.1, and Lucida Sans Typewriter, which was included in the TrueType Font Pack. All other TrueType fonts included with Windows 3.1 and the TrueType Font Pack are proportional fonts.

If neither of those work for you, get one from here that you like: https://www.1001fonts.com/monospaced-fonts.html
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 24, 2021, 12:04:21 am
Thankyou Steve, that link looks perfect but I will try the two as well.

Well looks like I have to rewrite my calendar code to fit in boxes, I am testing sub for centering unpredictable length text on x, y midpoints:

Code: QB64: [Select]
  1. Screen _NewImage(600, 600, 32)
  2. _Delay .25
  3.  
  4. Line (300, 50)-(500, 200), , B
  5. FH = _LoadFont("Arial.ttf", 24)
  6. If FH <= 0 Then Print "Trouble with font load file, goodbye.": Sleep: End
  7. CH = _FontHeight(FH): CW = _FontWidth(FH)
  8. Print "Hello World", CW, CH, _PrintWidth("Hello World")
  9. centerText (500 + 300) / 2, 100, "Hello World"
  10. FH2 = _LoadFont("Arial.ttf", 18)
  11. CH2 = _FontHeight(FH): CW2 = _FontWidth(FH2)
  12. _Font FH2
  13. Locate 2, 1
  14. Print "Hello World", CW, CH, _PrintWidth("Hello World")
  15. centerText (500 + 300) / 2, 150, "Hello World"
  16.  
  17.  
  18. Sub centerText (midx, midy, s$)
  19.     ' if you want to center fit a string between two goal posts x1, and x2
  20.     ' for midx plug in (x1+x2)/2 and let the computer do the calcs
  21.     pw = _PrintWidth(s$)
  22.     _PrintString (midx - pw / 2, midy - _FontHeight(_Font) / 2), s$
  23.  
  24.  
  25.  
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: SMcNeill on October 24, 2021, 12:18:14 am
As long as you're using PRINTWIDTH and not FONTWIDTH, the only real change you'll probably need to make is to remove that last parameter from your LOADFONT statement.
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 24, 2021, 12:44:01 am
Courier and Lucinda pretty good as Monospaced:
Code: QB64: [Select]
  1. Screen _NewImage(600, 600, 32)
  2. _Delay .25
  3.  
  4. 'center lines
  5. Line (300, 50)-(500, 200), , B
  6. Line (300, 100)-(500, 100)
  7. Line (300, 150)-(500, 150)
  8. Line (400, 50)-(400, 200)
  9.  
  10. FH = _LoadFont("courbd.ttf", 24, "MONOSPACE") 'Courier New Bold
  11. If FH <= 0 Then Print "Trouble with font load file, goodbye.": Sleep: End
  12. CH = _FontHeight(FH): CW = _FontWidth(FH)
  13. Print "Hello World"; CW; CH; _PrintWidth("Hello World")
  14. centerText 500, 300, 100, "Hello World"
  15. FH2 = _LoadFont("LTYPEB.TTF", 10, "MONOSPACE") 'Lucinda Sans Typewriter  Bold
  16. CH2 = _FontHeight(FH2): CW2 = _FontWidth(FH2)
  17. _Font FH2
  18. Locate 4, 1
  19. Print "Hello World"; CW2; CH2; _PrintWidth("Hello World")
  20. centerText 500, 300, 150, "Hello World"
  21.  
  22.  
  23. Sub centerText (x1, x2, midy, s$) ' ' if you want to center fit a string between two goal posts x1, and x2
  24.     _PrintString ((x1 + x2) / 2 - _PrintWidth(s$) / 2, midy - _FontHeight(_Font) / 2), s$
  25.  
  26.  
  27.  
Title: Re: Big ugly font difference between QB64 v1.4 and QB64 1.5 (and QB64 v2.0)
Post by: bplus on October 24, 2021, 10:01:53 am
Update: Just removing the "MONOSPACE" did easily fix my calendar update, thanks again plus, I now have a couple ways to manage fonts either by Monospace with a proper Monospace font or use CenterText sub perhaps with a mod for destination handle. I just got a new printer going and I am sure this issue of fitting font inside rectangles will come up again.

PS learned MONOSPACE no longer required for .ttf type files.