Author Topic: Bug with Unicode fonts?  (Read 3227 times)

0 Members and 1 Guest are viewing this topic.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Bug with Unicode fonts?
« on: April 06, 2019, 11:05:44 pm »
When I enable the _LOADFONT option for "UNICODE", QB64 is no longer able to calculate the width of a string of text.  It displays the text on the screen fine, but it returns a width that is shorter than the real width.  I'm pretty sure my font is Unicode compatible.

Just load a font with the "UNICODE" option and the text "The quick brown fox jumped over the two lazy dogs", then try it again without the "UNICODE" option and it returns a different width.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Bug with Unicode fonts?
« Reply #1 on: April 07, 2019, 03:05:44 am »
Hi, this has been dealt with somewhere. MONOSPACE must be used to return the correct string width. With another choice it works badly. Another bug is known for fonts - some characters are rendered poorly - cropped from above. To enable UNICODE and map UNICODE characters to the ascii table, use _MAPUNICODE as here: https://www.qb64.org/forum/index.php?topic=1218.msg104190#msg104190

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Bug with Unicode fonts?
« Reply #2 on: April 08, 2019, 03:37:03 pm »
Why would I use MONOSPACE when I am trying to measure the width of a variable width font?  That makes no sense, and does not address the problem I mentioned.

I am trying to measure the width of a font string, works fine without UNICODE, but does not work with UNICODE.  Nothing to do with MONOSPACE.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bug with Unicode fonts?
« Reply #3 on: April 08, 2019, 03:40:16 pm »
If it’s a variable width character, use _PRINTWIDTH instead of _FONTWIDTH.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ryster

  • Newbie
  • Posts: 77
    • View Profile
Re: Bug with Unicode fonts?
« Reply #4 on: April 08, 2019, 03:46:15 pm »
I use the following code and it works flawlessly. After all, it's a SMcNeill job.

SCREEN _NEWIMAGE (130, 45, 0)
_SCREENMOVE _MIDDLE
X = _DESKTOPWIDTH
IF X <1,400 THEN Fontsize = 16 ELSE Fontsize = 18
_FONT _LOADFONT ("C: \ Windows \ Fonts \ lucon.ttf", Fontsize, "MONOSPACE")
_DELAY .2
_SCREENMOVE _MIDDLE
RESTORE Microsoft_pc_cp852
FOR ascii = 128 TO 255
     READ unicode &
     IF unicode & = 0 THEN unicode & = 9744
     _MAPUNICODE unicode & TO ascii
NEXT

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: Bug with Unicode fonts?
« Reply #5 on: April 08, 2019, 03:56:32 pm »
Again, this has nothing whatsoever to do with MONOSPACE!

I am trying to measure the width of a variable width string of text using _PRINTWIDTH.

It works fine without the UNICODE option of _LOADFONT, but is broken with the UNICODE option.  No other changes but that option on _LOADFONT breaks the _PRINTWIDTH calculation.


Edit:

I just tried a completely empty app with the minimal needed to produce the bug, but it didn't give me the bug.  I will have to isolate how it's behaving differently from within my app, but literally the only option I changed to fix my app was removing the "UNICODE" option to _LOADFONT.  On and off, it would produce different width numbers from _PRINTWIDTH.
« Last Edit: April 08, 2019, 04:07:22 pm by Raven_Singularity »