Skip to content

Handle newly encountered cases in BDF files. #2108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2025

Conversation

MattHeffron
Copy link
Contributor

@MattHeffron MattHeffron commented Apr 17, 2025

Better handling of a glyph with ENCODING of -1. (From Monaco-10.bdf converted mac font)
I treat it as the slug glyph, instead of the default of a solid block.
This addresses issue: #2014
None of my test cases had that any glyph with that ENCODING.

This same bdf file also caused corrupted bitmap glyphs due to glyphs with zero width bitmap and zero advance (escapement). This has been corrected in a separate commit.

I treat it as the _slug_ glyph, instead of the _default_ of a solid block.
@MattHeffron MattHeffron added the bug Something isn't working (as per documentation) label Apr 17, 2025
@MattHeffron MattHeffron self-assigned this Apr 17, 2025
@MattHeffron MattHeffron linked an issue Apr 22, 2025 that may be closed by this pull request
@MattHeffron MattHeffron changed the title Better handling of a glyph with ENCODING of -1. Handle newly encountered cases in BDF files. Apr 22, 2025
Glyphs with zero width bitmap *and* zero advance (_escapement_) caused miscalculated glyph offsets into the CHARSETINFO bitmap.
Allow and ignore COMMENT lines preceding the STARTFONT line.
Add error checking for extracting font FAMILY, SIZE, FACE, etc. from the BDF-FONT object.
Add recommendation to documentation to write the DISPLAYFONT files to a directory separate from the system's IL:DISPLAYFONTDIRECTORIES locations.
@pamoroso
Copy link
Contributor

On Linux Mint 22.1 Cinnamon I tested the changes up to edcc0e3 and now BDF:WRITE-BDF-TO-DISPLAYFONT-FILES processes the Commodore 64 font with no errors.

But how can I determine the name of the converted font to feed to the TEdit charlooks menu? I added the directory with the new font to DISPLAYFONTDIRECTORIES but entering c64, c64d, c6416, c6416-mrr, or anything else in the Other field of TEdit's charlooks menu yields Can't find OTHER font c6416-mrr.

@MattHeffron
Copy link
Contributor Author

MattHeffron commented Apr 24, 2025

But how can I determine the name of the converted font to feed to the TEdit charlooks menu? I added the directory with the new font to DISPLAYFONTDIRECTORIES but entering c64, c64d, c6416, c6416-mrr, or anything else in the Other field of TEdit's charlooks menu yields Can't find OTHER font c6416-mrr.

This appears to be due to the way that font files are named.
Since there is no punctuation between the FAMILY and the SIZE in the file name (e.g. C6416 when FAMILY = C64 and SIZE = 16), calls to FONTSAVAILABLE will fail to report the font. (Internally, it does everything in UPPERCASE.)
It does find the file, then it takes apart that filename and checks that the pieces match the original FAMILY, SIZE, etc. original arguments. It takes the first character that is a digit as the beginning of the size. So, for c6416 it splits it to FAMILY = C and SIZE = 6416. The FAMILY doesn't match the C64 it was expecting, so it rejects the match.

Interestingly, calling (FONTCREATE 'C64 16) works correctly.
And, after creating that, FONTSAVAILABLE does succeed, as does using "Other" in TEDIT.

So, what should BDF:WRITE-BDF-TO-DISPLAYFONT-FILES do if the FAMILY argument provided, or internally determined FAMILY, contain any digits?

@nbriggs
Copy link
Contributor

nbriggs commented Apr 24, 2025

I don’t think it should do anything different, but the documentation should say “don’t name fonts with names that end in digits”

…MILY, FACE, etc.

Change &OPTIONAL parameters of WRITE-BDF-TO-DISPLAYFONT-FILES to &KEY to simplify calling. (No need to remember the order.)
Add CHAR-SETS and WRITE-UNMAPPED parameters to WRITE-BDF-TO-DISPLAYFONT-FILES to allow some level of control of which DISPLAYFONT files are written.
Updated documentation, and added warning note about font's FAMILY containing any digits.
@MattHeffron
Copy link
Contributor Author

“don’t name fonts with names that end in digits”

Actually the font FAMILY should not contain any digits, it's not just at the end.
Documented in latest commit, which includes some other ease of use changes.

@pamoroso
Copy link
Contributor

I actually pass to BDF:READ-BDF c64d.bdf which doesn't end in digits but the function picks the name in the font metadata which does:

STARTFONT 2.1
FONT c64
SIZE 16 75 75
FONTBOUNDINGBOX 16 16 0 -4
STARTPROPERTIES 3
FONT_DESCENT 4
FONT_ASCENT 12 
DEFAULT_CHAR 0 
ENDPROPERTIES
CHARS 95
STARTCHAR C0032
ENCODING 32
SWIDTH 666 0
DWIDTH 16 0
BBX 16 16 0 -4
BITMAP
0000
...

Anyway I'd say READ-BDF works pretty well:

tedit-c64

@MattHeffron
Copy link
Contributor Author

I actually pass to BDF:READ-BDF c64d.bdf which doesn't end in digits but the function picks the name in the font metadata which does

It isn't the name of the file in the call to BDF:READ-BDF that matters, it is in BDF:WRITE-BDF-TO-DISPLAYFONT-FILES that the FAMILY argument provided, or internally determined from the metadata, that shouldn't contain digits (not just end with digits).

So, if you had entered
(PROG1 T (SETQ C64D (BDF:READ-BDF "c64d.bdf" T))) ; Using the VERBOSE parameter
it would have displayed:

Name: c64
Family: c64
Size: 16
Weight: MEDIUM
Slant: REGULAR
Expansion: REGULAR

(Wrapping with the (PROG1 T ...) prevents the printing of the BDF::BDF-FONT structure returned and enables seeing that display.)

If then you called
(BDF:WRITE-BDF-TO-DISPLAYFONT-FILES C64D "{DSK}my-font-path>" :FAMILY "Commodore")
it would have returned five values:

{COMMODORE16-MRR/743,121356}
(0 33 34 35 225 226 227 236 238 239 253)
NIL
NIL
NIL

(The 743,121356 is the address of the IL:FONTDESCRIPTOR object, and would be different every time.)
This would have written files named like: {DSK}my-font-path>c0>Commodore16-MRR-C0.DISPLAYFONT and it would have been findable in the TEdit Char Looks menu Other with the name "Commodore".

Swapping the order of 2 parameters in WRITE-BDF-TO-DISPLAYFONT-FILES.
(Since they are &KEY parameters, it doesn't matter functionally, but match the documentation.)
@pamoroso
Copy link
Contributor

I updated to b3796eb and regenerated the font as you explained. Now TEdit detects the font with no issues.

Copy link
Contributor

@pamoroso pamoroso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@MattHeffron MattHeffron merged commit 39ebd40 into master Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working (as per documentation)
Projects
Status: Done
3 participants