diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 43fd76115..888859e28 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -607,6 +607,12 @@ hb_ot_math_get_min_connector_overlap hb_ot_math_get_glyph_assembly +
+hb-ot-metadata +hb_ot_metadata_reference_entry +hb_ot_metadata_t +
+
hb-ot-metrics hb_ot_metrics_t diff --git a/src/Makefile.sources b/src/Makefile.sources index 21fb1b6e1..a024381ab 100644 --- a/src/Makefile.sources +++ b/src/Makefile.sources @@ -89,6 +89,7 @@ HB_BASE_sources = \ hb-ot-math.cc \ hb-ot-maxp-table.hh \ hb-ot-meta-table.hh \ + hb-ot-metadata.cc \ hb-ot-metrics.cc \ hb-ot-metrics.hh \ hb-ot-name-language-static.hh \ @@ -194,6 +195,7 @@ HB_BASE_headers = \ hb-ot-font.h \ hb-ot-layout.h \ hb-ot-math.h \ + hb-ot-metadata.h \ hb-ot-metrics.h \ hb-ot-name.h \ hb-ot-shape.h \ diff --git a/src/harfbuzz.cc b/src/harfbuzz.cc index e39913761..d97143981 100644 --- a/src/harfbuzz.cc +++ b/src/harfbuzz.cc @@ -16,6 +16,7 @@ #include "hb-ot-layout.cc" #include "hb-ot-map.cc" #include "hb-ot-math.cc" +#include "hb-ot-metadata.cc" #include "hb-ot-metrics.cc" #include "hb-ot-name.cc" #include "hb-ot-shape-complex-arabic.cc" diff --git a/src/hb-config.hh b/src/hb-config.hh index bd440050e..b6db206a3 100644 --- a/src/hb-config.hh +++ b/src/hb-config.hh @@ -66,6 +66,7 @@ #define HB_NO_LAYOUT_COLLECT_GLYPHS #define HB_NO_LAYOUT_UNUSED #define HB_NO_MATH +#define HB_NO_META #define HB_NO_METRICS #define HB_NO_MMAP #define HB_NO_NAME diff --git a/src/hb-ot-face-table-list.hh b/src/hb-ot-face-table-list.hh index 4ec622c57..97fb765a2 100644 --- a/src/hb-ot-face-table-list.hh +++ b/src/hb-ot-face-table-list.hh @@ -62,7 +62,9 @@ HB_OT_ACCELERATOR (OT, name) #ifndef HB_NO_STAT HB_OT_TABLE (OT, STAT) #endif -//HB_OT_TABLE (OT, meta) +#ifndef HB_NO_META +HB_OT_ACCELERATOR (OT, meta) +#endif /* Vertical layout. */ HB_OT_TABLE (OT, vhea) diff --git a/src/hb-ot-face.cc b/src/hb-ot-face.cc index f54d0b639..5ef8df43c 100644 --- a/src/hb-ot-face.cc +++ b/src/hb-ot-face.cc @@ -32,6 +32,7 @@ #include "hb-ot-cff2-table.hh" #include "hb-ot-hmtx-table.hh" #include "hb-ot-kern-table.hh" +#include "hb-ot-meta-table.hh" #include "hb-ot-name-table.hh" #include "hb-ot-post-table.hh" #include "hb-ot-color-cbdt-table.hh" diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index dcd50a25e..4cd65b4a9 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -48,7 +48,6 @@ #include "hb-ot-layout-gpos-table.hh" #include "hb-ot-layout-base-table.hh" // Just so we compile it; unused otherwise. #include "hb-ot-layout-jstf-table.hh" // Just so we compile it; unused otherwise. -#include "hb-ot-meta-table.hh" // Just so we compile it; unused otherwise. #include "hb-ot-name-table.hh" #include "hb-ot-os2-table.hh" diff --git a/src/hb-ot-meta-table.hh b/src/hb-ot-meta-table.hh index dac55e47f..d36c3e94f 100644 --- a/src/hb-ot-meta-table.hh +++ b/src/hb-ot-meta-table.hh @@ -40,6 +40,11 @@ namespace OT { struct DataMap { + int cmp (hb_tag_t a) const { return tag.cmp (a); } + + hb_blob_t *reference_entry (hb_blob_t *meta_blob) const + { return hb_blob_create_sub_blob (meta_blob, dataZ, dataLength); } + bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); @@ -62,6 +67,19 @@ struct meta { static constexpr hb_tag_t tableTag = HB_OT_TAG_meta; + struct accelerator_t + { + void init (hb_face_t *face) + { table = hb_sanitize_context_t ().reference_table (face); } + void fini () { table.destroy (); } + + hb_blob_t *reference_entry (hb_tag_t tag) const + { return table->dataMaps.lsearch (tag, Null (DataMap)).reference_entry (table.get_blob ()); } + + private: + hb_blob_ptr_t table; + }; + bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -83,6 +101,8 @@ struct meta DEFINE_SIZE_ARRAY (16, dataMaps); }; +struct meta_accelerator_t : meta::accelerator_t {}; + } /* namespace OT */ diff --git a/src/hb-ot-metadata.cc b/src/hb-ot-metadata.cc new file mode 100644 index 000000000..42153be73 --- /dev/null +++ b/src/hb-ot-metadata.cc @@ -0,0 +1,57 @@ +/* + * Copyright © 2019 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. + */ + +#include "hb.hh" + +#ifndef HB_NO_META + +#include "hb-ot-meta-table.hh" + +/** + * SECTION:hb-ot-metadata + * @title: hb-ot-metadata + * @short_description: OpenType Metadata + * @include: hb-ot.h + * + * Functions for fetching metadata from fonts. + **/ + +/** + * hb_ot_meta_reference_entry: + * @face: a #hb_face_t object. + * @meta_tag: tag of metadata you like to have. + * + * It fetches metadata entry of a given tag from a font. + * + * Returns: (transfer full): A blob containing the blob. + * + * Since: REPLACEME + **/ +hb_blob_t * +hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t meta_tag) +{ + return face->table.meta->reference_entry (meta_tag); +} + +#endif diff --git a/src/hb-ot-metadata.h b/src/hb-ot-metadata.h new file mode 100644 index 000000000..3654458a1 --- /dev/null +++ b/src/hb-ot-metadata.h @@ -0,0 +1,57 @@ +/* + * Copyright © 2019 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_H_IN +#error "Include instead." +#endif + +#ifndef HB_OT_METADATA_H +#define HB_OT_METADATA_H + +#include "hb.h" + +HB_BEGIN_DECLS + +/** + * hb_ot_metadata_t: + * + * From https://docs.microsoft.com/en-us/typography/opentype/spec/meta + * + * Since: REPLACEME + **/ +typedef enum { +/* + HB_OT_METADATA_APPL = HB_TAG ('a','p','p','l'), + HB_OT_METADATA_BILD = HB_TAG ('b','i','l','d'), +*/ + HB_OT_METADATA_DESIGN_LANGUAGES = HB_TAG ('d','l','n','g'), + HB_OT_METADATA_SUPPORTED_LANGUAGES = HB_TAG ('s','l','n','g') +} hb_ot_metadata_t; + +HB_EXTERN hb_blob_t * +hb_ot_metadata_reference_entry (hb_face_t *face, hb_ot_metadata_t tag); + +HB_END_DECLS + +#endif /* HB_OT_METADATA_H */ diff --git a/src/hb-ot.h b/src/hb-ot.h index d00ee80ae..411d0936f 100644 --- a/src/hb-ot.h +++ b/src/hb-ot.h @@ -35,6 +35,7 @@ #include "hb-ot-font.h" #include "hb-ot-layout.h" #include "hb-ot-math.h" +#include "hb-ot-metadata.h" #include "hb-ot-metrics.h" #include "hb-ot-name.h" #include "hb-ot-shape.h" diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 63c7195fa..a675c50ff 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -84,6 +84,7 @@ TEST_PROGS += \ test-ot-color \ test-ot-ligature-carets \ test-ot-name \ + test-ot-metadata \ test-ot-metrics \ test-ot-tag \ test-ot-extents-cff \ diff --git a/test/api/fonts/meta.ttf b/test/api/fonts/meta.ttf new file mode 100644 index 000000000..414d7e671 Binary files /dev/null and b/test/api/fonts/meta.ttf differ diff --git a/test/api/test-ot-metadata.c b/test/api/test-ot-metadata.c new file mode 100644 index 000000000..d5f922415 --- /dev/null +++ b/test/api/test-ot-metadata.c @@ -0,0 +1,58 @@ +/* + * Copyright © 2019 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. + */ + +#include "hb-test.h" + +#include + +/* Unit tests for hb-ot-metadata.h */ + +static void +test_ot_metadata_reference_entry (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/meta.ttf"); + hb_blob_t *dlng = hb_ot_metadata_reference_entry (face, HB_OT_METADATA_DESIGN_LANGUAGES); + g_assert_cmpint (hb_blob_get_length (dlng), ==, 8); + g_assert_cmpmem (hb_blob_get_data (dlng, NULL), 8, "ar,de,fa", 8); + hb_blob_destroy (dlng); + hb_blob_t *fslf = hb_ot_metadata_reference_entry (face, (hb_ot_metadata_t) HB_TAG ('f','s','l','f')); + g_assert_cmpint (hb_blob_get_length (fslf), ==, 12); + hb_blob_destroy (fslf); + hb_blob_t *nacl = hb_ot_metadata_reference_entry (face, (hb_ot_metadata_t) HB_TAG ('n','a','c','l')); + g_assert_cmpint (hb_blob_get_length (nacl), ==, 0); + hb_blob_destroy (nacl); + hb_blob_t *slng = hb_ot_metadata_reference_entry (face, HB_OT_METADATA_SUPPORTED_LANGUAGES); + g_assert_cmpint (hb_blob_get_length (slng), ==, 11); + g_assert_cmpmem (hb_blob_get_data (slng, NULL), 11, "ar,de,en,fa", 11); + hb_blob_destroy (slng); + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + hb_test_add (test_ot_metadata_reference_entry); + return hb_test_run (); +}