[HarfBuzz] harfbuzz: Branch 'master' - 4 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Sun Jul 21 14:19:19 PDT 2013


 configure.ac                |    2 
 src/hb-open-type-private.hh |   10 ++
 src/hb-ot-name-table.hh     |    4 -
 src/hb-uniscribe.cc         |  157 ++++++++++++++++++++++++++++++++++++--------
 4 files changed, 144 insertions(+), 29 deletions(-)

New commits:
commit 05bad3b8c25a89bc0f20f99f9215e492f48f03fe
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sun Jul 21 17:05:02 2013 -0400

    [uniscribe] Use OT::* types

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 6a8b98b..ee3a21d 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -642,15 +642,21 @@ struct LongOffset : ULONG
 /* CheckSum */
 struct CheckSum : ULONG
 {
-  static uint32_t CalcTableChecksum (ULONG *Table, uint32_t Length)
+  /* This is reference implementation from the spec. */
+  static inline uint32_t CalcTableChecksum (const ULONG *Table, uint32_t Length)
   {
     uint32_t Sum = 0L;
-    ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size;
+    const ULONG *EndPtr = Table+((Length+3) & ~3) / ULONG::static_size;
 
     while (Table < EndPtr)
       Sum += *Table++;
     return Sum;
   }
+
+  /* Note: data should be 4byte aligned and have 4byte padding at the end. */
+  inline void set_for_data (const void *data, unsigned int length)
+  { set (CalcTableChecksum ((const ULONG *) data, length)); }
+
   public:
   DEFINE_SIZE_STATIC (4);
 };
diff --git a/src/hb-ot-name-table.hh b/src/hb-ot-name-table.hh
index 75a1b94..e36b0f7 100644
--- a/src/hb-ot-name-table.hh
+++ b/src/hb-ot-name-table.hh
@@ -98,6 +98,9 @@ struct name
     return length;
   }
 
+  inline unsigned int get_size (void) const
+  { return min_size + count * nameRecord[0].min_size; }
+
   inline bool sanitize_records (hb_sanitize_context_t *c) {
     TRACE_SANITIZE (this);
     char *string_pool = (char *) this + stringOffset;
@@ -116,7 +119,6 @@ struct name
   }
 
   /* We only implement format 0 for now. */
-  protected:
   USHORT	format;			/* Format selector (=0/1). */
   USHORT	count;			/* Number of name records. */
   Offset	stringOffset;		/* Offset to start of string storage (from start of table). */
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index f4512d2..93c0529 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -305,87 +305,84 @@ _hb_generate_unique_face_name (wchar_t *face_name, unsigned int *plen)
 static hb_blob_t *
 _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
 {
+  /* Create a copy of the font data, with the 'name' table replaced by a
+   * table that names the font with our private F_* name created above.
+   * For simplicity, we just append a new 'name' table and update the
+   * sfnt directory; the original table is left in place, but unused.
+   *
+   * The new table will contain just 5 name IDs: family, style, unique,
+   * full, PS. All of them point to the same name data with our unique name.
+   */
+
   unsigned int length, new_length, name_str_len;
   const char *orig_sfnt_data = hb_blob_get_data (blob, &length);
 
   _hb_generate_unique_face_name (new_name, &name_str_len);
 
-  /* Create a copy of the font data, with the 'name' table replaced by a table
-   * that names the font with our private F_* name created above.
-   * For simplicity, we just append a new 'name' table and update the sfnt directory;
-   * the original table is left in place, but unused. */
-
-  /* The new table will contain just 5 name IDs: family, style, unique, full, PS.
-   * All of them point to the same name data with our unique F_* name. */
-
   static const uint16_t name_IDs[] = { 1, 2, 3, 4, 6 };
 
-  const unsigned int name_header_size = 3 * 2; /* NameTableHeader: USHORT x 3 */
-  const unsigned int name_record_size = 6 * 2; /* NameRecord: USHORT x 6 */
-  const unsigned int name_count = sizeof (name_IDs) / sizeof (name_IDs[0]);
-  unsigned int name_table_length = name_header_size +
-                                   name_count * name_record_size +
+  unsigned int name_table_length = OT::name::min_size +
+                                   ARRAY_LENGTH (name_IDs) * OT::NameRecord::static_size +
                                    name_str_len * 2; /* for name data in UTF16BE form */
-
   unsigned int name_table_offset = (length + 3) & ~3;
 
-  new_length = name_table_offset + (name_table_length + 3) & ~3;
-  char *new_sfnt_data = (char *) calloc (1, new_length);
+  new_length = name_table_offset + ((name_table_length + 3) & ~3);
+  void *new_sfnt_data = calloc (1, new_length);
   if (!new_sfnt_data)
+  {
+    hb_blob_destroy (blob);
     return NULL;
+  }
 
   memcpy(new_sfnt_data, orig_sfnt_data, length);
 
-  unsigned char *name_table_data = (unsigned char *) (new_sfnt_data + name_table_offset);
-
-  unsigned char *p = name_table_data;
-  *p++ = 0x00; *p++ = 0x00; /* format = 0 */
-  *p++ = 0x00; *p++ = name_count; /* number of name records */
-  *p++ = 0x00; *p++ = name_header_size + name_count * name_record_size; /* offset to string data */
-
-  for (unsigned int i = 0; i < name_count; i++) {
-    *p++ = 0x00; *p++ = 0x03; /* platformID */
-    *p++ = 0x00; *p++ = 0x01; /* encodingID */
-    *p++ = 0x04; *p++ = 0x09; /* languageID = 0x0409 */
-    *p++ = 0x00; *p++ = name_IDs[i]; /* nameID */
-    *p++ = 0x00; *p++ = name_str_len * 2; /* string length (bytes) */
-    *p++ = 0x00; *p++ = 0x00; /* string offset */
+  OT::name &name = OT::StructAtOffset<OT::name> (new_sfnt_data, name_table_offset);
+  name.format.set (0);
+  name.count.set (ARRAY_LENGTH (name_IDs));
+  name.stringOffset.set (name.get_size ());
+  for (unsigned int i = 0; i < ARRAY_LENGTH (name_IDs); i++)
+  {
+    OT::NameRecord &record = name.nameRecord[i];
+    record.platformID.set (3);
+    record.encodingID.set (1);
+    record.languageID.set (0x0409); /* English */
+    record.nameID.set (name_IDs[i]);
+    record.length.set (name_str_len * 2);
+    record.offset.set (0);
   }
 
-  for (unsigned int i = 0; i < name_str_len; i++) {
-    /* copy string data from face_name, converting wchar_t to UTF16BE */
+  /* Copy string data from new_name, converting wchar_t to UTF16BE. */
+  unsigned char *p = &OT::StructAfter<unsigned char> (name);
+  for (unsigned int i = 0; i < name_str_len; i++)
+  {
     *p++ = new_name[i] >> 8;
     *p++ = new_name[i] & 0xff;
   }
 
-  /* calculate new name table checksum */
-  uint32_t checksum = 0;
-  while (name_table_data < p) {
-    checksum += (name_table_data[0] << 24) +
-                (name_table_data[1] << 16) +
-                (name_table_data[2] << 8) +
-                 name_table_data[3];
-    name_table_data += 4;
-  }
-
-  /* adjust name table entry to point to new name table */
+  /* Adjust name table entry to point to new name table */
   OT::OpenTypeFontFace *face = (OT::OpenTypeFontFace *) (new_sfnt_data);
   unsigned int index;
   if (face->find_table_index (HB_OT_TAG_name, &index))
   {
-    const OT::TableRecord& record = face->get_table (index);
-    OT::TableRecord *rp = const_cast<OT::TableRecord *> (&record);
-    rp->checkSum.set(checksum);
-    rp->offset.set(name_table_offset);
-    rp->length.set(name_table_length);
+    OT::TableRecord &record = const_cast<OT::TableRecord &> (face->get_table (index));
+    record.checkSum.set_for_data (&name, name_table_length);
+    record.offset.set (name_table_offset);
+    record.length.set (name_table_length);
+  }
+  else
+  {
+    free (new_sfnt_data);
+    hb_blob_destroy (blob);
+    return NULL;
   }
 
   /* The checkSumAdjustment field in the 'head' table is now wrong,
-     but AFAIK that doesn't actually cause any problems so I haven't
-     bothered to fix it. */
+   * but that doesn't actually seem to cause any problems so we don't
+   * bother. */
 
   hb_blob_destroy (blob);
-  return hb_blob_create (new_sfnt_data, new_length, HB_MEMORY_MODE_WRITABLE, NULL, free);
+  return hb_blob_create ((const char *) new_sfnt_data, new_length,
+			 HB_MEMORY_MODE_WRITABLE, NULL, free);
 }
 
 hb_uniscribe_shaper_face_data_t *
@@ -407,12 +404,18 @@ _hb_uniscribe_shaper_face_data_create (hb_face_t *face)
     DEBUG_MSG (UNISCRIBE, face, "Face has empty blob");
 
   blob = _hb_rename_font (blob, data->face_name);
+  if (unlikely (!blob))
+  {
+    free (data);
+    return NULL;
+  }
 
   DWORD num_fonts_installed;
   data->fh = AddFontMemResourceEx ((void *) hb_blob_get_data (blob, NULL),
 				   hb_blob_get_length (blob),
 				   0, &num_fonts_installed);
-  if (unlikely (!data->fh)) {
+  if (unlikely (!data->fh))
+  {
     DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
     free (data);
     return NULL;
commit bdeea605fe597bff4430eaae3317189bb81ec76e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sun Jul 21 16:22:10 2013 -0400

    [uniscribe] Move name generation into separate function

diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 6c186bd..f4512d2 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -272,20 +272,18 @@ struct hb_uniscribe_shaper_face_data_t {
   wchar_t face_name[LF_FACESIZE];
 };
 
-/* Destroys blob. */
-static hb_blob_t *
-_hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
+/* face_name should point to a wchar_t[LF_FACESIZE] object. */
+static void
+_hb_generate_unique_face_name (wchar_t *face_name, unsigned int *plen)
 {
-  unsigned int length, new_length = 0;
-  const char *orig_sfnt_data = hb_blob_get_data (blob, &length);
   /* We'll create a private name for the font from a UUID using a simple,
    * somewhat base64-like encoding scheme */
   const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
   UUID id;
   UuidCreate ((UUID*) &id);
   unsigned int name_str_len = 0;
-  new_name[name_str_len++] = 'F';
-  new_name[name_str_len++] = '_';
+  face_name[name_str_len++] = 'F';
+  face_name[name_str_len++] = '_';
   unsigned char *p = (unsigned char *) &id;
   for (unsigned int i = 0; i < 16; i += 2)
   {
@@ -294,11 +292,23 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
      * This will generate 24 characters; with the 'F_' prefix we already provided,
      * the name will be 26 chars (plus the NUL terminator), so will always fit within
      * face_name (LF_FACESIZE = 32). */
-    new_name[name_str_len++] = enc[p[i] >> 3];
-    new_name[name_str_len++] = enc[((p[i] << 2) | (p[i + 1] >> 6)) & 0x1f];
-    new_name[name_str_len++] = enc[p[i + 1] & 0x3f];
+    face_name[name_str_len++] = enc[p[i] >> 3];
+    face_name[name_str_len++] = enc[((p[i] << 2) | (p[i + 1] >> 6)) & 0x1f];
+    face_name[name_str_len++] = enc[p[i + 1] & 0x3f];
   }
-  new_name[name_str_len] = 0;
+  face_name[name_str_len] = 0;
+  if (plen)
+    *plen = name_str_len;
+}
+
+/* Destroys blob. */
+static hb_blob_t *
+_hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
+{
+  unsigned int length, new_length, name_str_len;
+  const char *orig_sfnt_data = hb_blob_get_data (blob, &length);
+
+  _hb_generate_unique_face_name (new_name, &name_str_len);
 
   /* Create a copy of the font data, with the 'name' table replaced by a table
    * that names the font with our private F_* name created above.
@@ -328,7 +338,7 @@ _hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
 
   unsigned char *name_table_data = (unsigned char *) (new_sfnt_data + name_table_offset);
 
-  p = name_table_data;
+  unsigned char *p = name_table_data;
   *p++ = 0x00; *p++ = 0x00; /* format = 0 */
   *p++ = 0x00; *p++ = name_count; /* number of name records */
   *p++ = 0x00; *p++ = name_header_size + name_count * name_record_size; /* offset to string data */
commit 73f947e2a7bc5b29d731da2e9d1fafe958be839e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sun Jul 21 16:16:35 2013 -0400

    [uniscribe] Use blob to pass data around

diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 73af43d..6c186bd 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -272,10 +272,12 @@ struct hb_uniscribe_shaper_face_data_t {
   wchar_t face_name[LF_FACESIZE];
 };
 
-static char *
-_hb_rename_font (const char *orig_sfnt_data, unsigned int length,
-                 unsigned int *new_length, wchar_t *new_name)
+/* Destroys blob. */
+static hb_blob_t *
+_hb_rename_font (hb_blob_t *blob, wchar_t *new_name)
 {
+  unsigned int length, new_length = 0;
+  const char *orig_sfnt_data = hb_blob_get_data (blob, &length);
   /* We'll create a private name for the font from a UUID using a simple,
    * somewhat base64-like encoding scheme */
   const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
@@ -317,8 +319,8 @@ _hb_rename_font (const char *orig_sfnt_data, unsigned int length,
 
   unsigned int name_table_offset = (length + 3) & ~3;
 
-  *new_length = name_table_offset + (name_table_length + 3) & ~3;
-  char *new_sfnt_data = (char *) calloc (1, *new_length);
+  new_length = name_table_offset + (name_table_length + 3) & ~3;
+  char *new_sfnt_data = (char *) calloc (1, new_length);
   if (!new_sfnt_data)
     return NULL;
 
@@ -372,7 +374,8 @@ _hb_rename_font (const char *orig_sfnt_data, unsigned int length,
      but AFAIK that doesn't actually cause any problems so I haven't
      bothered to fix it. */
 
-  return new_sfnt_data;
+  hb_blob_destroy (blob);
+  return hb_blob_create (new_sfnt_data, new_length, HB_MEMORY_MODE_WRITABLE, NULL, free);
 }
 
 hb_uniscribe_shaper_face_data_t *
@@ -390,18 +393,15 @@ _hb_uniscribe_shaper_face_data_create (hb_face_t *face)
   }
 
   hb_blob_t *blob = hb_face_reference_blob (face);
-  unsigned int blob_length;
-  const char *blob_data = hb_blob_get_data (blob, &blob_length);
-  if (unlikely (!blob_length))
+  if (unlikely (!hb_blob_get_length (blob)))
     DEBUG_MSG (UNISCRIBE, face, "Face has empty blob");
 
-  unsigned int new_length;
-  char *new_font_data = _hb_rename_font (blob_data, blob_length, &new_length, data->face_name);  
-  hb_blob_destroy (blob);
+  blob = _hb_rename_font (blob, data->face_name);
 
   DWORD num_fonts_installed;
-  data->fh = AddFontMemResourceEx (new_font_data, new_length, 0, &num_fonts_installed);
-  free (new_font_data);
+  data->fh = AddFontMemResourceEx ((void *) hb_blob_get_data (blob, NULL),
+				   hb_blob_get_length (blob),
+				   0, &num_fonts_installed);
   if (unlikely (!data->fh)) {
     DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
     free (data);
commit 8ac2e88deff3d069c19fd59d0fbbfb88a762b113
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sun Jul 21 16:06:49 2013 -0400

    [uniscribe] Use unique font name
    
    When installing per-process fonts using AddFontMemResourceEx(),
    if a font with the same family name is already installed, sometimes
    that one gets used.  Which is problematic for us.  As such, we
    now mangle the font to install a new 'name' table with a unique
    name, which we then use to choose the font.
    
    Patch from Jonathan Kew.

diff --git a/configure.ac b/configure.ac
index 4ce1f59..015ab9e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -298,7 +298,7 @@ if test "x$with_uniscribe" = "xyes" -a "x$have_uniscribe" != "xtrue"; then
 fi
 if $have_uniscribe; then
 	UNISCRIBE_CFLAGS=
-	UNISCRIBE_LIBS="-lusp10 -lgdi32"
+	UNISCRIBE_LIBS="-lusp10 -lgdi32 -lrpcrt4"
 	AC_SUBST(UNISCRIBE_CFLAGS)
 	AC_SUBST(UNISCRIBE_LIBS)
 	AC_DEFINE(HAVE_UNISCRIBE, 1, [Have Uniscribe library])
diff --git a/src/hb-uniscribe.cc b/src/hb-uniscribe.cc
index 4d27b9b..73af43d 100644
--- a/src/hb-uniscribe.cc
+++ b/src/hb-uniscribe.cc
@@ -32,9 +32,11 @@
 
 #include <windows.h>
 #include <usp10.h>
+#include <rpc.h>
 
 #include "hb-uniscribe.h"
 
+#include "hb-open-file-private.hh"
 #include "hb-ot-name-table.hh"
 #include "hb-ot-tag.h"
 
@@ -267,8 +269,112 @@ HB_SHAPER_DATA_ENSURE_DECLARE(uniscribe, font)
 struct hb_uniscribe_shaper_face_data_t {
   HANDLE fh;
   hb_uniscribe_shaper_funcs_t *funcs;
+  wchar_t face_name[LF_FACESIZE];
 };
 
+static char *
+_hb_rename_font (const char *orig_sfnt_data, unsigned int length,
+                 unsigned int *new_length, wchar_t *new_name)
+{
+  /* We'll create a private name for the font from a UUID using a simple,
+   * somewhat base64-like encoding scheme */
+  const char *enc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
+  UUID id;
+  UuidCreate ((UUID*) &id);
+  unsigned int name_str_len = 0;
+  new_name[name_str_len++] = 'F';
+  new_name[name_str_len++] = '_';
+  unsigned char *p = (unsigned char *) &id;
+  for (unsigned int i = 0; i < 16; i += 2)
+  {
+    /* Spread the 16 bits from two bytes of the UUID across three chars of face_name,
+     * using the bits in groups of 5,5,6 to select chars from enc.
+     * This will generate 24 characters; with the 'F_' prefix we already provided,
+     * the name will be 26 chars (plus the NUL terminator), so will always fit within
+     * face_name (LF_FACESIZE = 32). */
+    new_name[name_str_len++] = enc[p[i] >> 3];
+    new_name[name_str_len++] = enc[((p[i] << 2) | (p[i + 1] >> 6)) & 0x1f];
+    new_name[name_str_len++] = enc[p[i + 1] & 0x3f];
+  }
+  new_name[name_str_len] = 0;
+
+  /* Create a copy of the font data, with the 'name' table replaced by a table
+   * that names the font with our private F_* name created above.
+   * For simplicity, we just append a new 'name' table and update the sfnt directory;
+   * the original table is left in place, but unused. */
+
+  /* The new table will contain just 5 name IDs: family, style, unique, full, PS.
+   * All of them point to the same name data with our unique F_* name. */
+
+  static const uint16_t name_IDs[] = { 1, 2, 3, 4, 6 };
+
+  const unsigned int name_header_size = 3 * 2; /* NameTableHeader: USHORT x 3 */
+  const unsigned int name_record_size = 6 * 2; /* NameRecord: USHORT x 6 */
+  const unsigned int name_count = sizeof (name_IDs) / sizeof (name_IDs[0]);
+  unsigned int name_table_length = name_header_size +
+                                   name_count * name_record_size +
+                                   name_str_len * 2; /* for name data in UTF16BE form */
+
+  unsigned int name_table_offset = (length + 3) & ~3;
+
+  *new_length = name_table_offset + (name_table_length + 3) & ~3;
+  char *new_sfnt_data = (char *) calloc (1, *new_length);
+  if (!new_sfnt_data)
+    return NULL;
+
+  memcpy(new_sfnt_data, orig_sfnt_data, length);
+
+  unsigned char *name_table_data = (unsigned char *) (new_sfnt_data + name_table_offset);
+
+  p = name_table_data;
+  *p++ = 0x00; *p++ = 0x00; /* format = 0 */
+  *p++ = 0x00; *p++ = name_count; /* number of name records */
+  *p++ = 0x00; *p++ = name_header_size + name_count * name_record_size; /* offset to string data */
+
+  for (unsigned int i = 0; i < name_count; i++) {
+    *p++ = 0x00; *p++ = 0x03; /* platformID */
+    *p++ = 0x00; *p++ = 0x01; /* encodingID */
+    *p++ = 0x04; *p++ = 0x09; /* languageID = 0x0409 */
+    *p++ = 0x00; *p++ = name_IDs[i]; /* nameID */
+    *p++ = 0x00; *p++ = name_str_len * 2; /* string length (bytes) */
+    *p++ = 0x00; *p++ = 0x00; /* string offset */
+  }
+
+  for (unsigned int i = 0; i < name_str_len; i++) {
+    /* copy string data from face_name, converting wchar_t to UTF16BE */
+    *p++ = new_name[i] >> 8;
+    *p++ = new_name[i] & 0xff;
+  }
+
+  /* calculate new name table checksum */
+  uint32_t checksum = 0;
+  while (name_table_data < p) {
+    checksum += (name_table_data[0] << 24) +
+                (name_table_data[1] << 16) +
+                (name_table_data[2] << 8) +
+                 name_table_data[3];
+    name_table_data += 4;
+  }
+
+  /* adjust name table entry to point to new name table */
+  OT::OpenTypeFontFace *face = (OT::OpenTypeFontFace *) (new_sfnt_data);
+  unsigned int index;
+  if (face->find_table_index (HB_OT_TAG_name, &index))
+  {
+    const OT::TableRecord& record = face->get_table (index);
+    OT::TableRecord *rp = const_cast<OT::TableRecord *> (&record);
+    rp->checkSum.set(checksum);
+    rp->offset.set(name_table_offset);
+    rp->length.set(name_table_length);
+  }
+
+  /* The checkSumAdjustment field in the 'head' table is now wrong,
+     but AFAIK that doesn't actually cause any problems so I haven't
+     bothered to fix it. */
+
+  return new_sfnt_data;
+}
+
 hb_uniscribe_shaper_face_data_t *
 _hb_uniscribe_shaper_face_data_create (hb_face_t *face)
 {
@@ -289,9 +395,13 @@ _hb_uniscribe_shaper_face_data_create (hb_face_t *face)
   if (unlikely (!blob_length))
     DEBUG_MSG (UNISCRIBE, face, "Face has empty blob");
 
-  DWORD num_fonts_installed;
-  data->fh = AddFontMemResourceEx ((void *) blob_data, blob_length, 0, &num_fonts_installed);
+  unsigned int new_length;
+  char *new_font_data = _hb_rename_font (blob_data, blob_length, &new_length, data->face_name);  
   hb_blob_destroy (blob);
+
+  DWORD num_fonts_installed;
+  data->fh = AddFontMemResourceEx (new_font_data, new_length, 0, &num_fonts_installed);
+  free (new_font_data);
   if (unlikely (!data->fh)) {
     DEBUG_MSG (UNISCRIBE, face, "Face AddFontMemResourceEx() failed");
     free (data);
@@ -328,26 +438,10 @@ populate_log_font (LOGFONTW  *lf,
   lf->lfHeight = -font->y_scale;
   lf->lfCharSet = DEFAULT_CHARSET;
 
-  hb_blob_t *blob = OT::Sanitizer<OT::name>::sanitize (hb_face_reference_table (font->face, HB_TAG ('n','a','m','e')));
-  const OT::name *name_table = OT::Sanitizer<OT::name>::lock_instance (blob);
-  unsigned int len = name_table->get_name (3, 1, 0x409, 4,
-					   lf->lfFaceName,
-					   sizeof (lf->lfFaceName[0]) * LF_FACESIZE)
-					  / sizeof (lf->lfFaceName[0]);
-  hb_blob_destroy (blob);
-
-  if (unlikely (!len)) {
-    DEBUG_MSG (UNISCRIBE, NULL, "Didn't find English name table entry");
-    return false;
-  }
-  if (unlikely (len >= LF_FACESIZE)) {
-    DEBUG_MSG (UNISCRIBE, NULL, "Font name too long");
-    return false;
-  }
+  hb_face_t *face = font->face;
+  hb_uniscribe_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
 
-  for (unsigned int i = 0; i < len; i++)
-    lf->lfFaceName[i] = hb_be_uint16 (lf->lfFaceName[i]);
-  lf->lfFaceName[len] = 0;
+  memcpy (lf->lfFaceName, face_data->face_name, sizeof (lf->lfFaceName));
 
   return true;
 }



More information about the HarfBuzz mailing list