QB64 Phoenix Edition
Confusing Chr$ explanation - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Confusing Chr$ explanation (/showthread.php?tid=1820)

Pages: 1 2 3 4 5


RE: Confusing Chr$ explanation - PhilOfPerth - 07-12-2023

While experimenting with Chr$(), I find that Chr$(95) (the underscore) is the only one that is not displayed in a 16-bit screen mode. (it displays in 32 - bit mode) 
I suspect this is because the character uses the lowest row of the cell (row 8). Is this the reason? 
But Chr$ 92, 93, 103, 106, 112, 113, and 121 (mostly serif characters) all appear to use row 8, and they display in full.  Confused


RE: Confusing Chr$ explanation - SagaraS - 07-15-2023

(07-12-2023, 06:03 AM)PhilOfPerth Wrote: While experimenting with Chr$(), I find that Chr$(95) (the underscore) is the only one that is not displayed in a 16-bit screen mode. (it displays in 32 - bit mode) 
I suspect this is because the character uses the lowest row of the cell (row 8). Is this the reason? 
But Chr$ 92, 93, 103, 106, 112, 113, and 121 (mostly serif characters) all appear to use row 8, and they display in full.  Confused
Screen Mode 0 is text based exklusiv screen
SCREEN 0
or
SCREEN _NEWIMAGE(640, 400, 0)

Screen Mode 1-15 are palette based exklusiv screens.

As an example:
SCREEN 13
or
SCREEN _NEWIMAGE(320, 200, 13)

SCREEN 10
or
SCREEN _NEWIMAGE(640, 350, 10)


Screen Mode 256 is a full 256 palette based screen. Almost identical to Screen Mode 13.
SCREEN _NEWIMAGE(800, 600, 256)


Screen Mode 32 is the True color Mode
SCREEN _NEWIMAGE(800, 600, 32)

16 Bit color or High color Mode does not exist in QB64.
However, 16-bit graphics can be displayed on 32-bit.


Each screen mode has its own text width and height.
This is calculated from the screen width, screen height, font width and font height
As an example:

640 x 480 Screen

courbd.ttf in 32 height have a 22 width

640 / 22 = about 29,1 Text width on screen
480 / 32 = 15 Text height on screen

You have a 29,1 x 15 Text Screen on a 640x480 Screen with the courbd.ttf font in 32 height
An error would then occur as soon as the 'Locate' command addresses the 16th row or 30nd cell.

CHR$(95) may not be displayed because the text height may be an odd number?
Example:
320 x 200 Screen +  courbd.ttf in 32 height have a 22 width

320 / 22 = about 14,55 Text width on screen
200 / 32 = 6,25 Text height on screen

You can displayed the text with 'Locate' command.
Code: (Select All)
LOCATE 6, 14: print CHR$(95);

You can't displayed the text with normal Print for the last rows when text height have odd numbers
With the normal print command you can displayed 4 rows. With ; on the print command, you can displayed 5 rows.
When the last row is reached, the content moves up the screen, leaving the last row empty.

The font cannot be scaled to comma values. That means you need integers for it.
QB64 convert all Fonts to a new Raster fonts with fixed width and height.
A filter scales the characters down to a certain size. Could be 'Nearest Neighbor' filter.
Then some sizes of the fonts would explain that they can't be displayed.

Example by courbd.ttf

✅  show the CHR$(95)
❌  Do not show CHF$(95)

is the Font height 32, then the width is 22 ✅
is the Font height 31, then the width is 22 ✅
is the Font height 30, then the width is 22 ✅

is the Font height 29, then the width is 23 ✅
is the Font height 28, then the width is 20 ✅
is the Font height 27, then the width is 17 ✅

is the Font height 26, then the width is 18 ✅
is the Font height 25, then the width is 18 ❌
is the Font height 24, then the width is 18 ✅

is the Font height 23, then the width is 19 ✅
is the Font height 22, then the width is 19 ✅
is the Font height 21, then the width is 11 ✅

is the Font height 20, then the width is 13 ✅
is the Font height 19, then the width is 11 ✅
is the Font height 18, then the width is 18 ✅

is the Font height 17, then the width is 12 ✅
is the Font height 16, then the width is 12 ❌
is the Font height 15, then the width is 12 ❌

is the Font height 14, then the width is 10 ✅
is the Font height 13, then the width is 10 ❌
is the Font height 12, then the width is 10 ❌
is the Font height 11, then the width is 10 ✅

is the Font height 10, then the width is 8 ✅
is the Font height 9, then the width is 8 ❌
is the Font height 8, then the width is 5 ❌
is the Font height 7, then the width is 4 ✅
is the Font height 6, then the width is 4 ✅
...

Code: (Select All)
Print CHR$(95);
Uses only the memory for the character. And ends after the char.

Code: (Select All)
Print CHR$(95)
Still uses the memory for CR + LF. And only ends afterwards.

Example for the last row:
Code: (Select All)
SCREEN 13

LOCATE 1, 1: PRINT "Hello"
LOCATE 25, 1: PRINT "Hello world" ' <-- First Picture without ; and the second Picture with ;
SLEEP

First Picture without ;
The text is wrote in the 26th row, because the screen is move down. (See the right picture with background color)
[Image: print12kce9.png]  [Image: print3iuekg.png]

Second Picture with ;
[Image: print2hrcap.png]


RE: Confusing Chr$ explanation - PhilOfPerth - 07-16-2023

(07-15-2023, 08:47 AM)SagaraS Wrote:
(07-12-2023, 06:03 AM)PhilOfPerth Wrote: While experimenting with Chr$(), I find that Chr$(95) (the underscore) is the only one that is not displayed in a 16-bit screen mode. (it displays in 32 - bit mode) 
I suspect this is because the character uses the lowest row of the cell (row 8). Is this the reason? 
But Chr$ 92, 93, 103, 106, 112, 113, and 121 (mostly serif characters) all appear to use row 8, and they display in full.  Confused
Screen Mode 0 is text based exklusiv screen
SCREEN 0
or
SCREEN _NEWIMAGE(640, 400, 0)

Screen Mode 1-15 are palette based exklusiv screens.

As an example:
SCREEN 13
or
SCREEN _NEWIMAGE(320, 200, 13)

SCREEN 10
or
SCREEN _NEWIMAGE(640, 350, 10)


Screen Mode 256 is a full 256 palette based screen. Almost identical to Screen Mode 13.
SCREEN _NEWIMAGE(800, 600, 256)


Screen Mode 32 is the True color Mode
SCREEN _NEWIMAGE(800, 600, 32)

16 Bit color or High color Mode does not exist in QB64.
However, 16-bit graphics can be displayed on 32-bit.


Each screen mode has its own text width and height.
This is calculated from the screen width, screen height, font width and font height
As an example:

640 x 480 Screen

courbd.ttf in 32 height have a 22 width

640 / 22 = about 29,1 Text width on screen
480 / 32 = 15 Text height on screen

You have a 29,1 x 15 Text Screen on a 640x480 Screen with the courbd.ttf font in 32 height
An error would then occur as soon as the 'Locate' command addresses the 16th row or 30nd cell.

CHR$(95) may not be displayed because the text height may be an odd number?
Example:
320 x 200 Screen +  courbd.ttf in 32 height have a 22 width

320 / 22 = about 14,55 Text width on screen
200 / 32 = 6,25 Text height on screen

You can displayed the text with 'Locate' command.
Code: (Select All)
LOCATE 6, 14: print CHR$(95);

You can't displayed the text with normal Print for the last rows when text height have odd numbers
With the normal print command you can displayed 4 rows. With ; on the print command, you can displayed 5 rows.
When the last row is reached, the content moves up the screen, leaving the last row empty.

The font cannot be scaled to comma values. That means you need integers for it.
QB64 convert all Fonts to a new Raster fonts with fixed width and height.
A filter scales the characters down to a certain size. Could be 'Nearest Neighbor' filter.
Then some sizes of the fonts would explain that they can't be displayed.

Example by courbd.ttf

✅  show the CHR$(95)
❌  Do not show CHF$(95)

is the Font height 32, then the width is 22 ✅
is the Font height 31, then the width is 22 ✅
is the Font height 30, then the width is 22 ✅

is the Font height 29, then the width is 23 ✅
is the Font height 28, then the width is 20 ✅
is the Font height 27, then the width is 17 ✅

is the Font height 26, then the width is 18 ✅
is the Font height 25, then the width is 18 ❌
is the Font height 24, then the width is 18 ✅

is the Font height 23, then the width is 19 ✅
is the Font height 22, then the width is 19 ✅
is the Font height 21, then the width is 11 ✅

is the Font height 20, then the width is 13 ✅
is the Font height 19, then the width is 11 ✅
is the Font height 18, then the width is 18 ✅

is the Font height 17, then the width is 12 ✅
is the Font height 16, then the width is 12 ❌
is the Font height 15, then the width is 12 ❌

is the Font height 14, then the width is 10 ✅
is the Font height 13, then the width is 10 ❌
is the Font height 12, then the width is 10 ❌
is the Font height 11, then the width is 10 ✅

is the Font height 10, then the width is 8 ✅
is the Font height 9, then the width is 8 ❌
is the Font height 8, then the width is 5 ❌
is the Font height 7, then the width is 4 ✅
is the Font height 6, then the width is 4 ✅
...

Code: (Select All)
Print CHR$(95);
Uses only the memory for the character. And ends after the char.

Code: (Select All)
Print CHR$(95)
Still uses the memory for CR + LF. And only ends afterwards.

Example for the last row:
Code: (Select All)
SCREEN 13

LOCATE 1, 1: PRINT "Hello"
LOCATE 25, 1: PRINT "Hello world" ' <-- First Picture without ; and the second Picture with ;
SLEEP

First Picture without ;
The text is wrote in the 26th row, because the screen is move down. (See the right picture with background color)
[Image: print12kce9.png]  [Image: print3iuekg.png]

Second Picture with ;
[Image: print2hrcap.png]

Thanks SagaraS. A very detailed explanation. Thank you for your work.
But a lot of that goes over my head; I'm not very experienced, only experimental - maybe experi- and -mental ?  Big Grin
The examples with "pass" or "fail" should help clarify things though... I'll put some time into going through those.
And the Locate... Print... seems to work too.


RE: Confusing Chr$ explanation - SagaraS - 07-16-2023

Here you have a code that demonstrates the whole thing

With the arrow keys left and right can you change the height of the TTF Font

Code: (Select All)
OPTION _EXPLICIT

' Screen mode 13 with 640x480 
SCREEN _NEWIMAGE(640, 480, 13)

DIM keyin AS STRING
DIM curHeight AS INTEGER ' current height of TTF Font
DIM oldHeight AS INTEGER ' old height of TTF Font 
DIM FNThandle AS LONG '    Image handle

' This is for the TEXTfield positions
DIM MAXwidth AS INTEGER
DIM MAXheight AS INTEGER

curHeight = 32

FNThandle = _LOADFONT("C:\WINDOWS\fonts\courbd.ttf", curHeight, "monospace")
_FONT FNThandle

DO

  IF oldHeight <> curHeight THEN
    _FONT 16
    _FREEFONT FNThandle
    FNThandle = _LOADFONT("C:\WINDOWS\fonts\courbd.ttf", curHeight, "monospace")
    _FONT FNThandle
    oldHeight = curHeight
  END IF

  ' Rounding down the TEXTfield to a Integer
  MAXwidth = FIX(_WIDTH / _FONTWIDTH)
  MAXheight = FIX(_HEIGHT / _FONTHEIGHT)

  CLS , 7

  COLOR 7, 1
  LOCATE 1, 1: PRINT SPACE$(MAXwidth);
  LOCATE MAXheight, 1: PRINT SPACE$(MAXwidth);
  LOCATE 1, 2: PRINT "This is a TTF Font Example";
  LOCATE MAXheight, 2: PRINT "ESC - EXIT";

  COLOR 0, 7
  LOCATE 3, 2: PRINT "Screen Res : " + LTRIM$(STR$(_WIDTH)) + "x" + LTRIM$(STR$(_HEIGHT));
  LOCATE 4, 2: PRINT "Font   Res : " + LTRIM$(STR$(_FONTWIDTH)) + "x" + LTRIM$(STR$(_FONTHEIGHT));
  LOCATE 5, 2: PRINT "TextRes RD : " + LTRIM$(STR$(CLNG((_WIDTH / _FONTWIDTH) * 100) / 100)) + "x" + LTRIM$(STR$(CLNG((_HEIGHT / _FONTHEIGHT) * 100) / 100));
  LOCATE 6, 2: PRINT "TextRes INT: " + LTRIM$(STR$(MAXwidth)) + "x" + LTRIM$(STR$(MAXheight));
  LOCATE 7, 2: PRINT "FNT handle : " + LTRIM$(STR$(_FONT));

  LOCATE 9, 2: PRINT "<- Size -1";
  LOCATE 9, MAXwidth - 10: PRINT "Size +1 ->";

  DO
    COLOR 7, 1
    LOCATE MAXheight, MAXwidth - LEN(TIME$) + 1: PRINT TIME$;
    keyin = INKEY$
  LOOP WHILE keyin = ""

  IF keyin = CHR$(0) + CHR$(77) THEN IF curHeight < 32 THEN curHeight = curHeight + 1
  IF keyin = CHR$(0) + CHR$(75) THEN IF curHeight > 1 THEN curHeight = curHeight - 1

LOOP WHILE keyin <> CHR$(27)
SYSTEM



RE: Confusing Chr$ explanation - mnrvovrfc - 07-16-2023

It's not recommended to use FIX() to wrap a division. Do this instead:

Code: (Select All)
' Rounding down the TEXTfield to a Integer
  MAXwidth = _WIDTH \ _FONTWIDTH
  MAXheight = _HEIGHT \ _FONTHEIGHT

The larger "slash" key which is the directory separator in Windows, which in QBasic/QB64 is called "integer division".

There are other fonts that have that problem with displaying underscores and stuff like that. On Linux as well. While using Geany I had to change a font because of it, although it looked great for source code.

PRINT on the bottom-most line of SCREEN 0 should be avoided as much as possible and otherwise, use a trailing semicolon for anything used with PRINT.


RE: Confusing Chr$ explanation - bplus - 07-16-2023

Looks good to me! Fine demo @SagaraS (almost a palindrome).

A <= 100 LOC demo is worth a 1000 words ;-))


RE: Confusing Chr$ explanation - mnrvovrfc - 07-16-2023

Should have been "Saragaras" but I guess that was already taken...


RE: Confusing Chr$ explanation - SagaraS - 07-16-2023

(07-16-2023, 07:35 PM)mnrvovrfc Wrote: Should have been "Saragaras" but I guess that was already taken...
Nope. SagaraS is correct.
Originates from Sousuke Sagara from the anime Full Metal Panic.


RE: Confusing Chr$ explanation - SMcNeill - 07-16-2023

(07-12-2023, 06:03 AM)PhilOfPerth Wrote: While experimenting with Chr$(), I find that Chr$(95) (the underscore) is the only one that is not displayed in a 16-bit screen mode. (it displays in 32 - bit mode) 
I suspect this is because the character uses the lowest row of the cell (row 8). Is this the reason? 
But Chr$ 92, 93, 103, 106, 112, 113, and 121 (mostly serif characters) all appear to use row 8, and they display in full.  Confused
This should actually be fixed, if you use the new UPrintString functions.  The issue here is a glitch in the print routines with certain fonts basically suffering from clipping/truncating in the old versions of QB64 with PRINT.  

Kindly share what version of QB64 you were testing on which had the underscore disappear on you, (and then give it a shot in the latest release and see if the issue still persists), along with the font name and size, and we'll test it and see if it's something we can fix, if it's a bug in QB64's side of thing.  Properly rendering fonts is a little more complex than most folks think it is, and clipping due to rounding issues and other such things isn't all that uncommon.  Sometimes, it takes a little persistence and a lot of debugging grease, before everything works 100% as expected.  (If it ever does.)


RE: Confusing Chr$ explanation - PhilOfPerth - 07-16-2023

Thanks Steve.
It's comforting to know that there really is an issue, and not just my dumbness  Big Grin.
I'll do that test and let you know the version and stuff. My choice of screen size may also be a factor, as it
seems I'm choosing some "illegal" sizes.