diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2018-02-28 13:19:40 +0330 |
---|---|---|
committer | Ebrahim Byagowi <ebrahim@gnu.org> | 2018-02-28 13:19:40 +0330 |
commit | f671f7f0a8caa7b5763e00146e1ec4b9a7258227 (patch) | |
tree | 67d6a62d9d9101b178f92f9057bffccd63e327d2 | |
parent | 772274625e9f17d726f2a1da8192ec3ec24793a3 (diff) |
[colr] Implement
-rw-r--r-- | src/Makefile.sources | 1 | ||||
-rw-r--r-- | src/hb-ot-color.cc | 9 | ||||
-rw-r--r-- | src/hb-ot-color.h | 9 | ||||
-rw-r--r-- | src/hb-ot-colr-table.hh | 98 | ||||
-rw-r--r-- | src/hb-ot-cpal-table.hh | 6 | ||||
-rw-r--r-- | src/hb-ot-layout-private.hh | 6 | ||||
-rw-r--r-- | src/hb-ot-layout.cc | 11 |
7 files changed, 122 insertions, 18 deletions
diff --git a/src/Makefile.sources b/src/Makefile.sources index fc3383b8..a3bd1565 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -97,6 +97,7 @@ HB_OT_sources = \ hb-ot-layout-jstf-table.hh \ hb-ot-layout-private.hh \ hb-ot-color.cc \ + hb-ot-colr-table.hh \ hb-ot-cpal-table.hh \ hb-ot-map.cc \ hb-ot-map-private.hh \ diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index f89e58ac..da4fa408 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -26,6 +26,7 @@ */ #include "hb-open-type-private.hh" +#include "hb-ot-colr-table.hh" #include "hb-ot-cpal-table.hh" #include "hb-ot.h" @@ -40,6 +41,14 @@ HB_MARK_AS_FLAG_T (hb_ot_color_palette_flags_t) //HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) Hmm? +static inline const OT::COLR& +_get_colr (hb_face_t *face) +{ + if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(OT::COLR); + hb_ot_layout_t * layout = hb_ot_layout_from_face (face); + return *(layout->colr.get ()); +} + static inline const OT::CPAL& _get_cpal (hb_face_t *face) { diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h index 8f485667..8c276e59 100644 --- a/src/hb-ot-color.h +++ b/src/hb-ot-color.h @@ -38,15 +38,6 @@ HB_BEGIN_DECLS /** - * HB_OT_TAG_CPAL: - * a four-letter tag for identifying the CPAL table with color palettes - * - * Since: REPLACEME - */ -#define HB_OT_TAG_CPAL HB_TAG('C','P','A','L') - - -/** * hb_ot_color_t: * @red: the intensity of the red channel * @green: the intensity of the green channel diff --git a/src/hb-ot-colr-table.hh b/src/hb-ot-colr-table.hh new file mode 100644 index 00000000..c5bc2ccb --- /dev/null +++ b/src/hb-ot-colr-table.hh @@ -0,0 +1,98 @@ +/* + * Copyright © 2018 Ebrahim Byagowi + * + * 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. + */ + +#ifndef HB_OT_COLR_TABLE_HH +#define HB_OT_COLR_TABLE_HH + +#include "hb-open-type-private.hh" + +/* + * Color Palette + * http://www.microsoft.com/typography/otspec/colr.htm + */ + +#define HB_OT_TAG_COLR HB_TAG('C','O','L','R') + +namespace OT { + + +struct LayerRecord +{ + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (true); + } + + HBUINT16 gID; /* Glyph ID of layer glyph */ + HBUINT16 paletteIndex; /* Index value to use with a selected color palette */ + public: + DEFINE_SIZE_STATIC (4); +}; + +struct BaseGlyphRecord +{ + inline bool sanitize (hb_sanitize_context_t *c, unsigned int palettes) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this)); + } + + HBUINT16 gID; /* Glyph ID of reference glyph */ + OffsetTo<LayerRecord> + firstLayerIndex; /* Index to the layer record */ + HBUINT16 numLayers; /* Number of color layers associated with this glyph */ + public: + DEFINE_SIZE_STATIC (6); +}; + +struct COLR +{ + static const hb_tag_t tableTag = HB_OT_TAG_COLR; + + inline bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (c->check_struct (this) && + c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords) && + c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords)); + } + + protected: + HBUINT16 version; /* Table version number */ + HBUINT16 numBaseGlyphRecords; /* Number of Base Glyph Records */ + LOffsetTo<BaseGlyphRecord> + baseGlyphRecords; /* Offset to Base Glyph records. */ + LOffsetTo<LayerRecord> + layerRecordsOffset; /* Offset to Layer Records */ + HBUINT16 numLayerRecords; /* Number of Layer Records */ + + public: + DEFINE_SIZE_STATIC (14); +}; + +} /* namespace OT */ + + +#endif /* HB_OT_COLR_TABLE_HH */ diff --git a/src/hb-ot-cpal-table.hh b/src/hb-ot-cpal-table.hh index 4369a7d3..aade0e73 100644 --- a/src/hb-ot-cpal-table.hh +++ b/src/hb-ot-cpal-table.hh @@ -30,9 +30,6 @@ #include "hb-open-type-private.hh" - -namespace OT { - /* * Color Palette * http://www.microsoft.com/typography/otspec/cpal.htm @@ -40,6 +37,9 @@ namespace OT { #define HB_OT_TAG_CPAL HB_TAG('C','P','A','L') +namespace OT { + + struct ColorRecord { inline bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index a8f06f6a..870ba73f 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -123,10 +123,11 @@ hb_ot_layout_position_finish_offsets (hb_font_t *font, namespace OT { struct BASE; + struct COLR; + struct CPAL; struct GDEF; struct GSUB; struct GPOS; - struct CPAL; struct MATH; struct fvar; struct avar; @@ -172,8 +173,9 @@ struct hb_ot_layout_t /* TODO Move the following out of this struct. */ OT::hb_lazy_table_loader_t<struct OT::BASE> base; - OT::hb_lazy_table_loader_t<struct OT::MATH> math; + OT::hb_lazy_table_loader_t<struct OT::COLR> colr; OT::hb_lazy_table_loader_t<struct OT::CPAL> cpal; + OT::hb_lazy_table_loader_t<struct OT::MATH> math; OT::hb_lazy_table_loader_t<struct OT::fvar> fvar; OT::hb_lazy_table_loader_t<struct OT::avar> avar; OT::hb_lazy_table_loader_t<struct AAT::ankr> ankr; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index beef8419..e4cb68d8 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -37,6 +37,7 @@ #include "hb-ot-layout-gpos-table.hh" #include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise. #include "hb-ot-name-table.hh" // Just so we compile it; unused otherwise. +#include "hb-ot-colr-table.hh" #include "hb-ot-cpal-table.hh" #include "hb-ot-map-private.hh" @@ -63,9 +64,10 @@ _hb_ot_layout_create (hb_face_t *face) layout->gpos_blob = OT::Sanitizer<OT::GPOS>().sanitize (face->reference_table (HB_OT_TAG_GPOS)); layout->gpos = OT::Sanitizer<OT::GPOS>::lock_instance (layout->gpos_blob); - layout->math.init (face); - layout->cpal.init (face); layout->base.init (face); + layout->colr.init (face); + layout->cpal.init (face); + layout->math.init (face); layout->fvar.init (face); layout->avar.init (face); layout->ankr.init (face); @@ -218,9 +220,10 @@ _hb_ot_layout_destroy (hb_ot_layout_t *layout) hb_blob_destroy (layout->gsub_blob); hb_blob_destroy (layout->gpos_blob); - layout->math.fini (); - layout->cpal.fini (); layout->base.fini (); + layout->colr.fini (); + layout->cpal.fini (); + layout->math.fini (); layout->fvar.fini (); layout->avar.fini (); layout->ankr.fini (); |