lxsang / PTerm

MIT License
35 stars 8 forks source link

Update the DejaVu fonts and add a package ‘PTerm-Fonts’ embedding DejaVu Sans Mono #57

Closed Rinzwind closed 1 year ago

Rinzwind commented 1 year ago

This pull request updates the DejaVu fonts to v2.37 and adds a package ‘PTerm-Fonts’ embedding DejaVu Sans Mono. In the baseline, the package is only added to the list of packages, we could maybe also add it to the ‘default’ group.

Note that after loading the package, it is still necessary to do FreeTypeFontProvider current updateEmbeddedFreeTypeFonts to make the font available. I’m not sure whether it would be appropriate to include that in the class initialization method of PTermDejaVuSansMono. It’s also done by #updateFreeType in FreeTypeSettings class which is used in its #startUp: method.

A more compact representation of the font data is used in PTermDejaVuSansMono compared to what is used in SourceCodeProRegular and SourceSansProRegular. Those two classes each have a method #fontContentsData that uses a literal byte array with the contents of the ‘.ttf’ file. PTermDejaVuSansMono has a method #fontContentsEncodedData that uses a literal array of strings with the base64 encoding of the gzip-compressed ‘.ttf’ file. The method was generated through the following snippet, it uses the ‘gzip’ command because I couldn’t tell how to do ‘best’ compression with GZipWriteStream:

gzipData := (LibC resultOfCommand: ('gzip --stdout --no-name --best ''{1}''' format: {
    ((IceRepository repositoryNamed: 'PTerm') location / 'fonts' / 'DejaVuSansMono.ttf') fullName }))
        asByteArray.
PTermDejaVuSansMono class compile: (String streamContents: [ :stream |
    stream nextPutAll: 'fontContentsEncodedData'; cr; cr.
    stream tab; nextPutAll: '^ #('; cr.
    (gzipData base64Encoded groupsOf: 92)
        do: [ :group | stream tab; tab; nextPutAll: group printString ]
        separatedBy: [ stream cr ].
    stream nextPutAll: ')' ]).
Rinzwind commented 1 year ago

Using a literal byte array will make the source larger, but that maybe doesn’t matter so much as the source is mostly just stored in the changes file. Less memory will be needed for the object stored in the literals of the compiled method, that’s probably better. I have dropped the base64 encoding.

Rinzwind commented 1 year ago

I added the package ‘PTerm-Fonts’ to the ‘default’ group and changed TerminalEmulator to not download the font files anymore.

I looked into embedding Unifont as well, but I’m not sure I understand the license. The page ‘GNU Unifont’ on unifoundry.com says: “As of Unifont version 13.0.04, the fonts are dual-licensed under the SIL Open Font License (OFL) version 1.1 and the GNU GPL 2+ with the GNU font embedding exception.” The file ‘LICENSE.txt’ says: “The license for the compiled fonts is covered by the SIL Open Font License version 1.1 and by the above GPL terms with the GNU font embedding exception”. It’s not clear to me whether they mean one of the two licenses can be chosen, or whether the terms of both licenses apply. The GNU font embedding exception seems to only apply to documents.

lxsang commented 1 year ago

The file ‘LICENSE.txt’ says: “The license for the compiled fonts is covered by the SIL Open Font License version 1.1 and by the above GPL terms with the GNU font embedding exception”

Yeah, it's ambiguous... and The GPL may not be compatible with PTerm (MIT) if we want to embed the font- (Unifont).

It is better to keep the font out of the PTerm source code for now.