Adafruit-GFX-Font-Customiser
Adafruit-GFX-Font-Customiser copied to clipboard
Import XOR packed
Made import preview, with optional UnXor - nice to see under the hood sometimes :-) And there are 2 old fonts from ArduinoSimulator project in test folder.
Got lof of problems trying to add export - quite random bugs in the middle of some chars. At the moment have only C# compression recovered from unfinished version (created 7 years ago...). There is a special logic - GFXglyph / bitmapOffset holds bit size of char or compressed data now. In case compression fail (size increase) there is full size and original bitmap is used
There were multiple compression versions like row bitmap array and column data bitmap and some others forgotten, but suppose bit 1 prefix was best version as it was latest I used in my old project.
https://github.com/tchapi/Adafruit-GFX-Font-Customiser/issues/39
Let me know if you prefer JS compression implementation or if C# (/cmd project) will be enough.
Here temporary C# packer version https://github.com/eltomjan/ETEhomeTools/tree/master/CSharp/GFXpack
Done !!! It was not so complicated to translate C# back to JS.
- packed is autodetected no need for separate button anymore
- unXor optional feature - does not make much sense for standard user, but could be used for further font optimization(?)
Not sure if design fits nice and do not like useless jQuery - trying live without :-)
Just in case short description of current format: Bitmaps is now single packed bit array.
- 1B holds blockSize (<~ 256B), then
- 1 prefix marks original data of blockSize
- 0 blockSize * zeros (reduction by blockSize - 1)
- Each char is trimmed right (useless end is not stored)
Glyphs offset now points to bit (almost)
- suppose there could be overflow (if packed data are >8192B). for this case there is another calculation - average char position is substracted from original offset
- 1st glyph offset is often useless - is 0 so they are moved back - 0 is known and offset holds first bit of next char used to get bit size
- in case there is space in font (empty 1st char) there could be 0, for this case I am using workaround of I16_MIN (-32768) and adjust position to zero in code
- during JS import glyphs positions are recalculated to simplify position calculations
Compressor is almost 1:1 picked from latest C# version, btw there is also small optimisation - to speedup check of non-/zero blocks - array holding sum of 1-s and I can compare 2 sum indexes instead of iterate all bits again and again. And I need to update glyphs, so they are not text anymore (could be optional, but is it worth ??). And there is size as line comment next to Bitmaps declaration to know if compression has any sense :-)
Sorry @eltomjan for not coming back to you early on this — it's complicated to find personal time to contribute these days.
💪🏼 Thanks for the hard work on that.
- I understand jQuery is not your preference, I'll rework the JS later (don't take it personally :))
- I'm not sure of the unXor feature as, like you said, it's rather for very advanced user and will probably confuse most people
- The "pack" option should rather be a checkbox to toggle when you export (but same, it's JS / jQuery, I'll take care of it)
👉🏼 What I would still need from you if you don't mind:
- some comprehensive paragraph to add to the readme, for a normal user, so they can understand what the feature does, how to use it, etc. Basically: why packing the font, what's the use case? What does it do in practice? and the most important in my opinion: How to use the packed font in your Arduino project?
Thank you!
Made also a demo in meantime here eltomjan.github.io ... Adafruit-GFX-Font-Customiser.htm.
I respect your preferences - this great repo is your...
- ok if you think there is any benefit or you prefer jQ...
- yes, it is probably worthless for most users
- no problem I made "backend" logic only and did not care much about UI design, logic, etc.
In short my usecase was out of FLASH (32kB), but client wanted better UI, big fonts and extend logic...
I found a way to pack these big fonts to aprox. 50% and was able to continue without problems...
Also made faster print for my Adafruit_ILI9340 LCD - it was possible to sent bitmap instead of X,Y + point color each time (inspired by fillRect
method).
My old LinkedIn post contains most informations on one place. First link shows commit https://github.com/eltomjan/Adafruit-GFX-Library/commit/8e89c8f7192095b2554ea526317efd894c7c0af6 with Adafruit_GFX.cpp changes, visual and xor demos, etc.
Finished test in Wokwi simulator (FreeSerifBoldItalic9pt7b) https://wokwi.com/projects/394882822504014849
XorPack changes commit (change from default GFX to XorPacked font on ILI9341) - changed files are in project folder(s)
In case you do not have time, just give me instructions how to update PR and I can do that. I do not like jQuery as it does not bring much new to JS except renaming and useless mangling existing JS/DOM methods. Also had to live with jQ in DELMIA Apriso, but there it was real pain - lot of mixed parts, hard to be sure which one can appear, often no way to address them - most were named same / almost same and if you have jQ here, these unpredictable/repeated parts did unexpected things often - in JS/DOM you know what are you working with, but in jQ any event, etc. may be auto attached or refer to anything similar. Also when code is not structured much, you have element, have to think how it can be refered and then search whole "universe" (neverending file-s) for handler - it was good idea to split UI and logic, but also context often get hidden/lost in real world. And something used exceptions for normal run - jQ(?) - that is code smell - exceptions lost there exceptionality ??