src/Makefile.sources               |    1 
 src/hb-ot-font.cc                  |    1 
 src/hb-ot-layout-common-private.hh |    8 +
 src/hb-ot-var-avar-table.hh        |    1 
 src/hb-ot-var-fvar-table.hh        |    1 
 src/hb-ot-var-hvar-table.hh        |  165 +++++++++++++++++++++++++++++++++++++
 6 files changed, 175 insertions(+), 2 deletions(-)

New commits:
commit a4fca9f0051dbc177390a4e555b2d0fe642f724e
Author: Behdad Esfahbod <beh...@behdad.org>
Date:   Mon Jan 23 11:56:08 2017 -0800

    [var] Implement DeltaSetIndexMap and advance delta fetching
    
    Not hooked up to hb-ot-font yet.

diff --git a/src/hb-ot-layout-common-private.hh 
b/src/hb-ot-layout-common-private.hh
index 92b5c17..180e5f0 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -1323,6 +1323,14 @@ struct VariationStore
                                             this+regions);
   }
 
+  inline float get_delta (unsigned int index,
+                         int *coords, unsigned int coord_count) const
+  {
+    unsigned int outer = index >> 16;
+    unsigned int inner = index & 0xFFFF;
+    return get_delta (outer, inner, coords, coord_count);
+  }
+
   inline bool sanitize (hb_sanitize_context_t *c) const
   {
     TRACE_SANITIZE (this);
diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh
index 0cb24d2..cf22c9d 100644
--- a/src/hb-ot-var-hvar-table.hh
+++ b/src/hb-ot-var-hvar-table.hh
@@ -39,12 +39,52 @@ struct DeltaSetIndexMap
   {
     TRACE_SANITIZE (this);
     return_trace (c->check_struct (this) &&
-                 c->check_array (this, 1, 12));
+                 c->check_array (mapData, get_width (), mapCount));
   }
 
-  USHORT x;
+  unsigned int map (unsigned int v) const /* Returns 16.16 outer.inner. */
+  {
+    /* If count is zero, pass value unchanged.  This takes
+     * care of direct mapping for advance map. */
+    if (!mapCount)
+      return v;
+
+    if (v >= mapCount)
+      v = mapCount - 1;
+
+    unsigned int u = 0;
+    { /* Fetch it. */
+      unsigned int w = get_width ();
+      const BYTE *p = mapData + w * v;
+      for (; w; w--)
+       u = (u << 8) + *p++;
+    }
+
+    { /* Repack it. */
+      unsigned int n = get_inner_bitcount ();
+      unsigned int outer = u >> n;
+      unsigned int inner = u & ((1 << n) - 1);
+      u = (outer<<16) | inner;
+    }
+
+    return u;
+  }
+
+  protected:
+  inline bool get_width (void) const
+  { return ((format >> 4) & 3) + 1; }
+
+  inline bool get_inner_bitcount (void) const
+  { return (format & 0xF) + 1; }
+
+  protected:
+  USHORT format;               /* A packed field that describes the compressed
+                                * representation of delta-set indices. */
+  USHORT mapCount;             /* The number of mapping entries. */
+  BYTE mapData[VAR];           /* The delta-set index mapping data. */
+
   public:
-  DEFINE_SIZE_STATIC (2);
+  DEFINE_SIZE_ARRAY (4, mapData);
 };
 
 
@@ -72,6 +112,16 @@ struct HVARVVAR
                  rsbMap.sanitize (c, this));
   }
 
+  inline float get_advance_delta (hb_codepoint_t glyph,
+                                 int *coords, unsigned int coord_count) const
+  {
+    unsigned int varidx = (this+advMap).map (glyph);
+    return (this+varStore).get_delta (varidx, coords, coord_count);
+  }
+
+  inline bool has_sidebearing_deltas (void) const
+  { return lsbMap && rsbMap; }
+
   protected:
   FixedVersion<>version;       /* Version of the metrics variation table
                                 * initially set to 0x00010000u */
commit 7b399f73efa76cd97131fd123a9a1566f8639cfd
Author: Behdad Esfahbod <beh...@behdad.org>
Date:   Mon Jan 23 11:41:43 2017 -0800

    [var] Start adding HVAR/VVAR

diff --git a/src/Makefile.sources b/src/Makefile.sources
index c74147c..8d7f1a0 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -111,6 +111,7 @@ HB_OT_sources = \
        hb-ot-var.cc \
        hb-ot-var-avar-table.hh \
        hb-ot-var-fvar-table.hh \
+       hb-ot-var-hvar-table.hh \
        $(NULL)
 
 HB_OT_headers = \
diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc
index f84dbc2..c7286b7 100644
--- a/src/hb-ot-font.cc
+++ b/src/hb-ot-font.cc
@@ -37,6 +37,7 @@
 #include "hb-ot-hhea-table.hh"
 #include "hb-ot-hmtx-table.hh"
 #include "hb-ot-os2-table.hh"
+#include "hb-ot-var-hvar-table.hh"
 //#include "hb-ot-post-table.hh"
 
 
diff --git a/src/hb-ot-var-avar-table.hh b/src/hb-ot-var-avar-table.hh
index 7c8449a..ace0f5f 100644
--- a/src/hb-ot-var-avar-table.hh
+++ b/src/hb-ot-var-avar-table.hh
@@ -28,7 +28,6 @@
 #define HB_OT_VAR_AVAR_TABLE_HH
 
 #include "hb-open-type-private.hh"
-#include "hb-ot-var.h"
 
 namespace OT {
 
diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh
index 0c48769..9f6fb32 100644
--- a/src/hb-ot-var-fvar-table.hh
+++ b/src/hb-ot-var-fvar-table.hh
@@ -28,7 +28,6 @@
 #define HB_OT_VAR_FVAR_TABLE_HH
 
 #include "hb-open-type-private.hh"
-#include "hb-ot-var.h"
 
 namespace OT {
 
diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh
new file mode 100644
index 0000000..0cb24d2
--- /dev/null
+++ b/src/hb-ot-var-hvar-table.hh
@@ -0,0 +1,115 @@
+/*
+ * Copyright © 2017  Google, Inc.
+ *
+ *  This is part of HarfBuzz, a text shaping library.
+ *
+ * Permission is hereby granted, without written agreement and without
+ * license or royalty fees, to use, copy, modify, and distribute this
+ * software and its documentation for any purpose, provided that the
+ * above copyright notice and the following two paragraphs appear in
+ * all copies of this software.
+ *
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
+ * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Google Author(s): Behdad Esfahbod
+ */
+
+#ifndef HB_OT_VAR_HVAR_TABLE_HH
+#define HB_OT_VAR_HVAR_TABLE_HH
+
+#include "hb-ot-layout-common-private.hh"
+
+
+namespace OT {
+
+
+struct DeltaSetIndexMap
+{
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    return_trace (c->check_struct (this) &&
+                 c->check_array (this, 1, 12));
+  }
+
+  USHORT x;
+  public:
+  DEFINE_SIZE_STATIC (2);
+};
+
+
+/*
+ * HVAR -- The Horizontal Metrics Variations Table
+ * VVAR -- The Vertical Metrics Variations Table
+ */
+
+#define HB_OT_TAG_HVAR HB_TAG('H','V','A','R')
+#define HB_OT_TAG_VVAR HB_TAG('V','V','A','R')
+
+struct HVARVVAR
+{
+  static const hb_tag_t HVARTag        = HB_OT_TAG_hmtx;
+  static const hb_tag_t VVARTag        = HB_OT_TAG_vmtx;
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    return_trace (version.sanitize (c) &&
+                 likely (version.major == 1) &&
+                 varStore.sanitize (c, this) &&
+                 advMap.sanitize (c, this) &&
+                 lsbMap.sanitize (c, this) &&
+                 rsbMap.sanitize (c, this));
+  }
+
+  protected:
+  FixedVersion<>version;       /* Version of the metrics variation table
+                                * initially set to 0x00010000u */
+  LOffsetTo<VariationStore>
+               varStore;       /* Offset to item variation store table. */
+  LOffsetTo<DeltaSetIndexMap>
+               advMap;         /* Offset to advance var-idx mapping. */
+  LOffsetTo<DeltaSetIndexMap>
+               lsbMap;         /* Offset to lsb/tsb var-idx mapping. */
+  LOffsetTo<DeltaSetIndexMap>
+               rsbMap;         /* Offset to rsb/bsb var-idx mapping. */
+
+  public:
+  DEFINE_SIZE_STATIC (20);
+};
+
+struct HVAR : HVARVVAR {
+  static const hb_tag_t tableTag       = HB_OT_TAG_HVAR;
+};
+struct VVAR : HVARVVAR {
+  static const hb_tag_t tableTag       = HB_OT_TAG_VVAR;
+
+  inline bool sanitize (hb_sanitize_context_t *c) const
+  {
+    TRACE_SANITIZE (this);
+    return_trace (static_cast<const HVARVVAR *> (this)->sanitize (c) &&
+                 vorgMap.sanitize (c, this));
+  }
+
+  protected:
+  LOffsetTo<DeltaSetIndexMap>
+               vorgMap;        /* Offset to vertical-origin var-idx mapping. */
+
+  public:
+  DEFINE_SIZE_STATIC (24);
+};
+
+} /* namespace OT */
+
+
+#endif /* HB_OT_VAR_HVAR_TABLE_HH */
_______________________________________________
HarfBuzz mailing list
HarfBuzz@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/harfbuzz

Reply via email to