June 18, 2019, 07:16:40 PM

Author Topic: Why can't Image Fonts be loaded via LoadBank()?  (Read 296 times)

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Why can't Image Fonts be loaded via LoadBank()?
« on: June 08, 2019, 09:00:45 PM »
I keep all my fonts inside a personal binary..  TrueTypeFonts, anyways.

For all of my assets, i load them from my custom asset bundle via LoadBank()..  works fine for audio and graphics..   but not fonts?    Why can't i load a TTF or OTF after it's data is returned as a bank? What makes this so special?

Anyone have an idea?

Offline wombats

  • Jr. Member
  • **
  • Posts: 30
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #1 on: June 09, 2019, 02:17:42 AM »
I haven't tested it, but does this help?

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #2 on: June 13, 2019, 09:07:18 PM »
I haven't tested it, but does this help?

Sorry for the late reply.

No, this technique does not seem to work for me.  However, this seems to be for loading fonts from streams, instead, which isn't what i particularly need.

Maybe i'll just take this up with Brucey.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2154
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #3 on: June 13, 2019, 09:09:21 PM »
Try to import brl.bankstream and use TBankStream to connect your "bank" to the useable "stream".


bye
Ron

Offline Derron

  • Hero Member
  • *****
  • Posts: 2154
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #4 on: June 13, 2019, 10:57:28 PM »
Uploaded a Pull Request / Change to the brl.mod/freetypefont.mod code for bmx-ng.

Either Brucey accepts it - or comes up with a way better solution than me.


bye
Ron

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #5 on: June 14, 2019, 12:29:30 AM »
Uploaded a Pull Request / Change to the brl.mod/freetypefont.mod code for bmx-ng.

Either Brucey accepts it - or comes up with a way better solution than me.


bye
Ron

I asked something on the Git thread but i'll post here as well:

What is "override"?   Where is it defined? - It's currently reported as undefined and is preventing me from building.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #6 on: June 14, 2019, 07:15:04 AM »
Has anyone tried to INCBIN a font?  Seems to just crash for me...  invalid stream.

Really odd.

Offline Derron

  • Hero Member
  • *****
  • Posts: 2154
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #7 on: June 14, 2019, 07:18:16 AM »
Did not try "incbin::" but am already in discussion with Brucey.

Normally it _should_ work but maybe NG altered the way incbin:: is working and it needs an overhaul too.


bye
Ron

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #8 on: June 14, 2019, 07:21:08 AM »
Did not try "incbin::" but am already in discussion with Brucey.

Normally it _should_ work but maybe NG altered the way incbin:: is working and it needs an overhaul too.


bye
Ron

I saw you had some very recent updates just now.  Perhaps this may be the case, but i'm happy i could bring up this topic so we could improve NG as it's an amazing language.

I just built your latest updated commit;  I'll give it a whirl.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #9 on: June 14, 2019, 07:28:06 AM »
Code: [Select]
Local fontBankStream:TStream = CreateBankStream(fontBank)
Local font:TImageFont = LoadImageFont(fontBankStream, 12)
SetImageFont(font)

Works as your example did.  Of course, i still need proper TBank support so that i can use my format specifically, as it returns a bank.   I appreciate this work, however.

Looking forward to further improvements.

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #10 on: June 14, 2019, 09:09:55 PM »
Code: [Select]

FNT.FontFile = SDA.Config.Merge(11) 'Returns BANK from archive into TBANK VAR
FNT.FontLoader = CreateBankStream(FNT.FontFile) 'TBankStream
FNT.Font12 = LoadImageFont(FNT.FontLoader, 40, SMOOTHFONT) 'Load it
SetImageFont(FNT.Font12) 'Set it

Fails.

You said utilize TBankStream, so i tried.   Never used it before..   wanted absolute TBank support, but someone decided it should end on streams.....

I would like to know why this fails.   Is bankstream being used wrong?

Offline Derron

  • Hero Member
  • *****
  • Posts: 2154
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #11 on: June 14, 2019, 09:15:02 PM »
First of apl: Brucey wrote an official update for the module. Use this.

Also: you can check if the bankstream is valid, the bank is valid... Also check if the bank data is the same as in the original font file (compare size...and maybe even content)..

"Fails" is no helpful answer here...what exactly happens?

Bye
Ron

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #12 on: June 14, 2019, 09:17:49 PM »
First of apl: Brucey wrote an official update for the module. Use this.

Also: you can check if the bankstream is valid, the bank is valid... Also check if the bank data is the same as in the original font file (compare size...and maybe even content)..

"Fails" is no helpful answer here...what exactly happens?

Bye
Ron

It's the exact same file.   Same size and same contents;  Just merged into 1 big archive.

I use this method for all of my music, graphics and bitmap glyphs, so my format isn't the problem.

Fails, not crashes, so the app runs fine but the default font is still in place.

I am using Brucey's code...

Offline Derron

  • Hero Member
  • *****
  • Posts: 2154
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #13 on: June 14, 2019, 10:02:28 PM »
Code: BlitzMax
  1. FNT.FontFile = SDA.Config.Merge(11) 'Returns BANK from archive into TBANK VAR
  2. FNT.FontLoader = CreateBankStream(FNT.FontFile) 'TBankStream
  3. FNT.Font12 = LoadImageFont(FNT.FontLoader, 40, SMOOTHFONT) 'Load it
  4. SetImageFont(FNT.Font12) 'Set it
  5.  
  6. if not FNT.FontFile then Throw "FNT.FontFile not existing"
  7. if not FNT.FontLoader then Throw "FNT.FontLoader not existing"
  8. if not FNT.Font12 then Throw "FNT.Font12 not existing"
  9.  

If font12 is null then you might dive into freetypefont.bmx "function load" and add some throw's in the positions where it does "return null" - this way you could narrow down where it fails.


bye
Ron

Offline Yellownakji

  • Full Member
  • ***
  • Posts: 235
  • Whoop-de-doo-ba-dooo!
Re: Why can't Image Fonts be loaded via LoadBank()?
« Reply #14 on: June 14, 2019, 10:09:31 PM »
Code: BlitzMax
  1. FNT.FontFile = SDA.Config.Merge(11) 'Returns BANK from archive into TBANK VAR
  2. FNT.FontLoader = CreateBankStream(FNT.FontFile) 'TBankStream
  3. FNT.Font12 = LoadImageFont(FNT.FontLoader, 40, SMOOTHFONT) 'Load it
  4. SetImageFont(FNT.Font12) 'Set it
  5.  
  6. if not FNT.FontFile then Throw "FNT.FontFile not existing"
  7. if not FNT.FontLoader then Throw "FNT.FontLoader not existing"
  8. if not FNT.Font12 then Throw "FNT.Font12 not existing"
  9.  

If font12 is null then you might dive into freetypefont.bmx "function load" and add some throw's in the positions where it does "return null" - this way you could narrow down where it fails.


bye
Ron

It's the font variable itself (fnt.font12);  Appears to be null.

I checked the SIZE(S) of the tbankstream and the tbank;  They match the actual TTF file.

I wish TBANK would just be implemented......................