Author Topic: True Type Fonts  (Read 2075 times)

Offline Drex

  • Mc. Print
  • *
  • Posts: 3
    • View Profile
True Type Fonts
« on: 2021-Jun-27 »
Hi,

Have been using the trial version of GLbasic for about a year, so have been loading fonts, in the .png format.

I have just purchased the steam version, which says, it supports .ttf fonts, but I can't get them to load.

Can anyone, point me in the right direction ?

Thanks.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 374
  • to program what I have do how should programming?
    • View Profile
Re: True Type Fonts
« Reply #1 on: 2021-Jun-27 »
I confirm I tried it but it doesn't work

Offline Drex

  • Mc. Print
  • *
  • Posts: 3
    • View Profile
Re: True Type Fonts
« Reply #2 on: 2021-Jun-27 »
Thanks for the reply……

I don’t understand, as it’s advertised, as supported in version 1.6 ?

Oh well, back to steam for a refund, what a waste of time.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 374
  • to program what I have do how should programming?
    • View Profile
Re: True Type Fonts
« Reply #3 on: 2021-Jun-27 »
if I were you I would wait. Surely the GLB update will come out in a while. Somewhere in the forum I read that there will be and then ..... an excellent language like GLB cannot be discarded for a lack, even if temporary. I'm having a lot of fun with this language

Offline Drex

  • Mc. Print
  • *
  • Posts: 3
    • View Profile
Re: True Type Fonts
« Reply #4 on: 2021-Jun-27 »
I'm  having fun too, with GLbasic.....

I tried Python for a little while, but found it too slow, so I am switching between GLbasic & Javascript\p5.js.

The one downside to using Javascript is, that everything has to be done in the browser window, which can get annoying
at times, but it does support .ttf fonts :)

Hopefully they will implement .ttf in GLbasic soon, still can't understand why it is advertised as being in version 1.6 though  ::)


Offline Qedo

  • Dr. Type
  • ****
  • Posts: 374
  • to program what I have do how should programming?
    • View Profile
Re: True Type Fonts
« Reply #5 on: 2021-Jun-28 »
Counterorder ..... :S

tried with GLB 16,793 and it works.

LOADFONT "FORTE_system.TTF", 1
SETFONT 1.3
PRINT "Print TTF font", 0,0,1 // GLBasic IDE, Version: 16,793
SHOWSCREEN
MOUSEWAIT
END

only it seems with other zoon values, in example 3, the quality is not high

ad maiora

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 374
  • to program what I have do how should programming?
    • View Profile
Re: True Type Fonts
« Reply #6 on: 2021-Jun-28 »
and also works with the third color parameter.
Great
 =D

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 443
    • View Profile
    • my personal website
Re: True Type Fonts
« Reply #7 on: 2021-Oct-21 »
Please dont get me wrong but bug happens to everyone, or I would quote now popular catch phrase "mistakes were made" :-)
If you see that something isn't working as it should/feature isn't complete or something post it on forum, such things could get unnoticed. TTF or custom font face swapping is nice but for simpler multi-language support I'm sticking to sprite fonts - much easier to prepare let's say Chinese buttons for small games without messing with Unicode. TTF also has its place and it's own strength.
One good thing in JS is no compilation time, and instant preview for small things, good way is to write small parts of code in JS to check everything and later translate that to final programming language.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 443
    • View Profile
    • my personal website
Re: True Type Fonts
« Reply #8 on: 2022-Jan-20 »
Recently I checked few standard TTF font's and they are working properly, higher scale value shows not highest quality (as Qedo mentioned) but it's sufficient for most use cases. Didn't check some more artistic fonts from web, so maybe there are additional limits, but can't say that.

But I'm bumping this from other TTF related reason. Is there a 'simple' way to display/render UTF8 text with use of TTF fonts (or some other trick) in GLB? Standard bitmap font is limited to 128/256 characters, and TTF font's also have such 256 char limit.
For static/predefined text (like menu, buttons, labels) I'm using auto-generated earlier bitmaps, so I can have any language versions that I want.
The deal is to display runtime defined text, like user nicknames from for example Steam Leaderboards where entries are encoded in UTF8 and can contain national specific characters (like Chinese, Russian and so on). Simplest thing will be just replace any-non-standard-char with '?' but this may look bad :D Is there any work around for that, anyone has some clever function that will convert UTF8 to ASCII using extended 256 character set, so at least west Europe languages would be covered by it?

There are some crazy workarounds but all have some negatives:
- use php server to generate bitmap with proper coding/charset, based on input UTF8 string, GLB would download such bitmap and display it, this would increase server load and take some from transfer limit,
- include small local native app, that would do same as above script, but it's solution only for Windows,
- port FreeType lib (that's powering SDL_ttf) to GLB, quite big task just to have nice highscores in a game,
- or maybe something smaller like this lib: Font Stash,
Most likely if there will be no simple solution I will stick to '?' replacement, hopefully with adding player avatars to mitigate the issue.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10832
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: True Type Fonts
« Reply #9 on: 2022-Jan-24 »
I see. The standalone TTF library might be able to render unicode characters.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 374
  • to program what I have do how should programming?
    • View Profile
Re: True Type Fonts
« Reply #10 on: 2022-Jan-26 »
but unfortunately the TTF library only renders segments and not curves

Offline Youkaisan

  • Community Developer
  • Mr. Drawsprite
  • ******
  • Posts: 68
    • View Profile
Re: True Type Fonts
« Reply #11 on: 2022-Jan-28 »
Hi, Gernot, any plan to integrate UTF-8 and FreeType into GLBasic?

Or a paid module for this would be nice, I tried to using the bitmap font solution, but the Chinese glyphs are really big and hard to maintain, the main benefit of GLB is very small and efficient executable, that makes it a good choice to make games, but a proper i18n solution is required.

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 443
    • View Profile
    • my personal website
Re: True Type Fonts
« Reply #12 on: 2022-Jan-30 »
The lib that I linked is quite small and looks cross-platform so shouldn't be to hard to use it with inline, but crucial thing here is to have multi-platform solution that would be simple to use, on other hand targets with SDL2 subsystem could most likely use sdl_ttf, so only solution for Windows would be needed (don't know how HTML5 WebGL target is working atm).
It could even use some kind of pre-caching stage for creating glyphs bitmap - in menus all text is predefined during transition, same high scores, only dialog text in rpg like game would need more often available glyph updates.
But it would be just better to have such feature built-in GLB.

But for a moment I have something like this to force extended ASCII charset:
Code: (glbasic) [Select]
// simple UTF8 to ASCII conversion
// converts only Latin based characters, other are replaced with '?'
FUNCTION UTF8toLatin$: utf8$
    LOCAL copy$ = utf8$
    LOCAL i1%, i2% = LEN(utf8$), i3%, i4%, txt$ = "", txt_len% = LEN(utf8$)
    LOCAL asc_tab%[], cjump%, fchar%, utfhex%
    DIM asc_tab%[txt_len%]

    // conver to array
    FOR i1% = 0 TO txt_len% - 1
        asc_tab%[i1%] = ASC(utf8$, i1%)
    NEXT
   
    i1% = 0
    WHILE i1% < txt_len% - 1
        i3% = asc_tab[i1%]
        IF (i3% < 32)
            cjump% = 1; fchar% = 63
        ELSEIF (i3% > 127)      // two chars
            cjump% = 2
            // simplified
            i4% = asc_tab%[i1%+1]
            utfhex% = i3% * 256 + i4%
            IF (utfhex% >= 49792 AND utfhex% <= 50111); fchar% = 128 + (i3% - 194) * 64 + i4% - 128     // extended ASCII
            ELSEIF (utfhex% >= 50304 AND utfhex% <= 50309); fchar% = IIF(MOD(utfhex%, 2) = 0, 65, 97)       // c4 80 - to - c4 85 -> A/a
            ELSEIF (utfhex% >= 50310 AND utfhex% <= 50317); fchar% = IIF(MOD(utfhex%, 2) = 0, 67, 99)       // c4 86 - to - c4 8d -> C/c
            ELSEIF (utfhex% >= 50318 AND utfhex% <= 50321); fchar% = IIF(MOD(utfhex%, 2) = 0, 68, 100)      // c4 8e - to - c4 91 -> D/d
            ELSEIF (utfhex% >= 50322 AND utfhex% <= 50331); fchar% = IIF(MOD(utfhex%, 2) = 0, 69, 101)      // c4 92 - to - c4 9b -> E/e
            ELSEIF (utfhex% >= 50332 AND utfhex% <= 50339); fchar% = IIF(MOD(utfhex%, 2) = 0, 71, 103)      // c4 9c - to - c4 a3 -> G/g
            ELSEIF (utfhex% >= 50340 AND utfhex% <= 50343); fchar% = IIF(MOD(utfhex%, 2) = 0, 72, 104)      // c4 a4 - to - c4 a7 -> H/h
            ELSEIF (utfhex% >= 50344 AND utfhex% <= 50354); fchar% = IIF(MOD(utfhex%, 2) = 0, 73, 105)      // c4 a8 - to - c4 b1 -> I/i
            ELSEIF (utfhex% >= 50354 AND utfhex% <= 50357); fchar% = IIF(MOD(utfhex%, 2) = 0, 74, 106)      // c4 b2 - to - c4 b5 -> J/j
            ELSEIF (utfhex% >= 50358 AND utfhex% <= 50360); fchar% = IIF(MOD(utfhex%, 2) = 0, 75, 107)      // c4 b6 - to - c4 b8 -> K/k
            ELSEIF (utfhex% >= 50361 AND utfhex% <= 50562); fchar% = IIF(MOD(utfhex%, 2) = 1, 76, 108)      // c4 b9 - to - c5 82 -> L/l
            ELSEIF (utfhex% >= 50563 AND utfhex% <= 50571); fchar% = IIF(MOD(utfhex%, 2) = 1, 78, 110)      // c5 83 - to - c5 8b -> N/n
            ELSEIF (utfhex% >= 50572 AND utfhex% <= 50579); fchar% = IIF(MOD(utfhex%, 2) = 0, 79, 111)      // c5 8c - to - c5 93 -> O/o
            ELSEIF (utfhex% >= 50580 AND utfhex% <= 50585); fchar% = IIF(MOD(utfhex%, 2) = 0, 82, 114)      // c5 94 - to - c5 99 -> R/r
            ELSEIF (utfhex% >= 50586 AND utfhex% <= 50593); fchar% = IIF(MOD(utfhex%, 2) = 0, 83, 115)      // c5 9a - to - c5 a1 -> S/s
            ELSEIF (utfhex% >= 50594 AND utfhex% <= 50599); fchar% = IIF(MOD(utfhex%, 2) = 0, 84, 116)      // c5 a2 - to - c5 a7 -> T/t
            ELSEIF (utfhex% >= 50600 AND utfhex% <= 50611); fchar% = IIF(MOD(utfhex%, 2) = 0, 85, 117)      // c5 a8 - to - c5 b3 -> U/u
            ELSEIF (utfhex% >= 50612 AND utfhex% <= 50613); fchar% = IIF(MOD(utfhex%, 2) = 0, 87, 119)      // c5 b4 - to - c5 b5 -> W/w
            ELSEIF (utfhex% >= 50614 AND utfhex% <= 50616); fchar% = IIF(MOD(utfhex%, 2) = 0, 89, 121)      // c5 b6 - to - c5 b8 -> Y/y
            ELSEIF (utfhex% >= 50617 AND utfhex% <= 50622); fchar% = IIF(MOD(utfhex%, 2) = 1, 90, 122)      // c5 b9 - to - c5 be -> Z/z
            ELSE; fchar% = 63
            ENDIF
        ELSEIF (i3% >= 224)      // three chars
            cjump% = 3; fchar% = 63
        ELSEIF (i3% >= 240)      // four chars
            cjump% = 4; fchar% = 63
        ELSE    // normal char
            cjump% = 1; fchar% = i3
        ENDIF
       
        INC i1%, cjump%
        INC txt$, CHR$(fchar%)
       
    WEND
copy$ = txt$
RETURN copy$

ENDFUNCTION
nothing special, unpolished, no error checking, but works for European languages, other like Asian will be converted to '?' chars, it's fast solution for online high scores, and as I got Steam Leaderboards working with fetching user avatars this will be sufficient for some time.
Check my source code editor for GLBasic - link Update: 20.04.2020