Skip to content

Commit

Permalink
Make sure only one copy of a background image is stored in the font file
Browse files Browse the repository at this point in the history
  • Loading branch information
johanmattssonm committed Feb 10, 2022
1 parent ed8f36b commit 8eeace3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
@@ -1,6 +1,7 @@
birdfont (2.30.0) stable;

* Smaller .birdfont files
* Make sure only one copy of a background image is stored in the font file.

-- Johan Mattsson <johan.mattsson.m@gmail.com> Tue Feb 8 03:03:27 CET 2022

Expand Down
14 changes: 13 additions & 1 deletion libbirdfont/BirdFontFile.vala
Expand Up @@ -24,12 +24,14 @@ class BirdFontFile : GLib.Object {
Font font;

public const int FORMAT_MAJOR = 2;
public const int FORMAT_MINOR = 2;
public const int FORMAT_MINOR = 3;

public const int MIN_FORMAT_MAJOR = 0;
public const int MIN_FORMAT_MINOR = 0;

public bool has_svg_glyphs = false;

Gee.ArrayList<string> written_images = new Gee.ArrayList<string> ();

public BirdFontFile (Font f) {
font = f;
Expand Down Expand Up @@ -252,6 +254,16 @@ class BirdFontFile : GLib.Object {
}

public void write_image (DataOutputStream os, string sha1, string data) throws GLib.Error {
if (written_images.contains (sha1)) {
warning ("Font file already contains " + sha1);
return;
}

if (sha1 == "" || data == "") {
warning ("No data in background image.");
return;
}

os.put_string (@"<background-image sha1=\"");
os.put_string (sha1);
os.put_string ("\" ");
Expand Down

0 comments on commit 8eeace3

Please sign in to comment.