[meta] New API, hb_ot_metadata_reference_entry for fetching meta entries

This commit is contained in:
Ebrahim Byagowi 2019-07-22 23:35:08 +04:30 committed by Behdad Esfahbod
parent aab8e08487
commit 3ac03bd67c
14 changed files with 208 additions and 2 deletions

View File

@ -607,6 +607,12 @@ hb_ot_math_get_min_connector_overlap
hb_ot_math_get_glyph_assembly
</SECTION>
<SECTION>
<FILE>hb-ot-metadata</FILE>
hb_ot_metadata_reference_entry
hb_ot_metadata_t
</SECTION>
<SECTION>
<FILE>hb-ot-metrics</FILE>
hb_ot_metrics_t

View File

@ -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 \

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -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<meta> (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<meta> 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 */

57
src/hb-ot-metadata.cc Normal file
View File

@ -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

57
src/hb-ot-metadata.h Normal file
View File

@ -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 <hb-ot.h> 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 */

View File

@ -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"

View File

@ -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 \

BIN
test/api/fonts/meta.ttf Normal file

Binary file not shown.

View File

@ -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 <hb-ot.h>
/* 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 ();
}