[pango/simple-fontmap: 34/37] serializer: Improve font serialization




commit aca9110b016f22774faea291e352c7e7aca1c501
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 26 12:42:30 2021 -0500

    serializer: Improve font serialization
    
    Include index and instance_id in the output
    when serializing fonts.
    
    Update all affected tests.

 pango/serializer.c              | 28 ++++++++++++++++++++++++++++
 tests/layouts/bratwurst.layout  |  2 ++
 tests/layouts/bratwurst2.layout |  1 +
 tests/layouts/bratwurst3.layout |  4 ++++
 tests/layouts/bratwurst4.layout |  2 ++
 tests/layouts/kebab.layout      |  2 ++
 6 files changed, 39 insertions(+)
---
diff --git a/pango/serializer.c b/pango/serializer.c
index 2dab93b4..37969e1b 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -26,6 +26,7 @@
 #include <pango/pango-context-private.h>
 #include <pango/pango-enum-types.h>
 #include <pango/pango-font-private.h>
+#include <pango/pango-hbface.h>
 
 #include <hb-ot.h>
 #include "pango/json/gtkjsonparserprivate.h"
@@ -549,6 +550,9 @@ add_font (GtkJsonPrinter *printer,
   const int *coords;
   hb_feature_t features[32];
   PangoMatrix matrix;
+  unsigned int index;
+  int instance_id;
+  gboolean embolden;
 
   gtk_json_printer_start_object (printer, member);
 
@@ -567,6 +571,30 @@ add_font (GtkJsonPrinter *printer,
 
   gtk_json_printer_add_string (printer, "checksum", str);
 
+  if (PANGO_IS_HB_FACE (pango_font_get_face (font)))
+    {
+      PangoHbFace *hbface = PANGO_HB_FACE (pango_font_get_face (font));
+
+      index = pango_hb_face_get_face_index (hbface);
+      instance_id = pango_hb_face_get_instance_id (hbface);
+      embolden = pango_hb_face_get_embolden (hbface);
+    }
+  else
+    {
+      index = hb_face_get_index (face);
+      instance_id = (index >> 16) - 1;
+      index = index & 0xffff;
+      embolden = FALSE;
+    }
+
+  if (index != 0)
+    gtk_json_printer_add_integer (printer, "index", index);
+  if (instance_id != -1)
+    gtk_json_printer_add_integer (printer, "instance-id", instance_id);
+
+  if (embolden)
+    gtk_json_printer_add_boolean (printer, "embolden", embolden);
+
   g_free (str);
   hb_blob_destroy (blob);
 
diff --git a/tests/layouts/bratwurst.layout b/tests/layouts/bratwurst.layout
index 06ec8272..3940da79 100644
--- a/tests/layouts/bratwurst.layout
+++ b/tests/layouts/bratwurst.layout
@@ -112,6 +112,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -166,6 +167,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
diff --git a/tests/layouts/bratwurst2.layout b/tests/layouts/bratwurst2.layout
index 0c3be229..d9d7e40a 100644
--- a/tests/layouts/bratwurst2.layout
+++ b/tests/layouts/bratwurst2.layout
@@ -105,6 +105,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
diff --git a/tests/layouts/bratwurst3.layout b/tests/layouts/bratwurst3.layout
index 42c6a487..1ebec843 100644
--- a/tests/layouts/bratwurst3.layout
+++ b/tests/layouts/bratwurst3.layout
@@ -106,6 +106,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -161,6 +162,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -216,6 +218,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -271,6 +274,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
diff --git a/tests/layouts/bratwurst4.layout b/tests/layouts/bratwurst4.layout
index 34a4e1aa..9a189941 100644
--- a/tests/layouts/bratwurst4.layout
+++ b/tests/layouts/bratwurst4.layout
@@ -111,6 +111,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -184,6 +185,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
diff --git a/tests/layouts/kebab.layout b/tests/layouts/kebab.layout
index a0efe11d..eb3b8984 100644
--- a/tests/layouts/kebab.layout
+++ b/tests/layouts/kebab.layout
@@ -120,6 +120,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },
@@ -194,6 +195,7 @@
             "font" : {
               "description" : "Cantarell Bold 32",
               "checksum" : "5bcb6ee14ee9d210b2e91d643de1fe456e9d1aea770983fdb05951545efebbe2",
+              "instance-id" : 3,
               "variations" : {
                 "wght" : 8374
               },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]