mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 14:01:10 +01:00
* [JSTF] Expose extender glyphs via hb_ot_layout_get_extender_glyphs The JSTF table is already parsed but never exposed to clients. Extender glyphs are the most widely populated part of it and are useful for cursive-script justification implementations that want to prefer a font-provided extender over the plain U+0640 TATWEEL fallback. Adds hb_ot_layout_get_extender_glyphs(face, script, language, start_offset, &count, glyphs) following the standard iterator idiom used by hb_ot_layout_get_attach_points and friends: NULL for size probing, inout count for pagination. Only the script tag is consulted: per the OT spec, extender glyphs live directly on JstfScript and do not vary by language. JstfLangSys carries per-language justification priorities, but exposing those is both harder and less common among fonts than the (already rare) JSTF table itself; that can be a separate accessor later. Co-authored-by: Helmut Januschka <helmut@januschka.com> * [JSTF] Minor simplification by refactoring exposed methods --------- Co-authored-by: Helmut Januschka <helmut@januschka.com> Co-authored-by: Behdad Esfahbod <behdad@behdad.org>
89 lines
3.4 KiB
C++
89 lines
3.4 KiB
C++
/*
|
|
* Copyright © 2026 Behdad Esfahbod
|
|
*
|
|
* 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"
|
|
#include "hb-ot-layout-jstf-table.hh"
|
|
|
|
static hb_face_t *
|
|
create_face (const char *data, unsigned length)
|
|
{
|
|
hb_face_t *face = hb_face_builder_create ();
|
|
hb_blob_t *blob = hb_blob_create (data, length, HB_MEMORY_MODE_READONLY,
|
|
nullptr, nullptr);
|
|
hb_always_assert (hb_face_builder_add_table (face, HB_OT_TAG_JSTF, blob));
|
|
hb_blob_destroy (blob);
|
|
return face;
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
/* This is a test mostly for JSTFv1.1, JSTFv1 is tested in test-ot-layout.cc */
|
|
static const char data[] = {
|
|
0, 1, 0, 1, /* version 1.1 */
|
|
0, 0, /* JstfScriptRecord count */
|
|
0, 1, /* JstfScriptRecord2 count */
|
|
'a', 'r', 'a', 'b', 0, 0, 0, 16, /* JstfScriptRecord2 */
|
|
0, 0, 0, 10, /* ExtenderGlyph2 offset */
|
|
0, 0, 0, 0, /* default JstfLangSys offset */
|
|
0, 0, /* JstfLangSysRecord count */
|
|
0, 1, 1, 0, 1, /* ExtenderGlyph2 */
|
|
};
|
|
|
|
hb_face_t *face = create_face (data, sizeof (data));
|
|
hb_blob_ptr_t<OT::JSTF> jstf =
|
|
hb_sanitize_context_t ().reference_table<OT::JSTF> (face);
|
|
#ifndef HB_NO_BEYOND_64K
|
|
hb_always_assert (jstf.get_length ());
|
|
hb_always_assert (jstf->get_script_count () == 1);
|
|
hb_always_assert (!jstf->get_lang_sys_count (HB_TAG ('a','r','a','b')));
|
|
hb_always_assert (0 == hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_BRAHMI, HB_LANGUAGE_INVALID, 0, NULL, NULL));
|
|
hb_always_assert (1 == hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, 0, NULL, NULL));
|
|
hb_codepoint_t buffer[2];
|
|
buffer[0] = HB_CODEPOINT_INVALID;
|
|
buffer[1] = HB_CODEPOINT_INVALID;
|
|
unsigned glyphs_count = 2;
|
|
hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, 0, &glyphs_count, buffer);
|
|
hb_always_assert (glyphs_count == 1);
|
|
hb_always_assert (buffer[0] == 0x10001);
|
|
hb_always_assert (buffer[1] == HB_CODEPOINT_INVALID);
|
|
#else
|
|
hb_always_assert (jstf.get_length ());
|
|
hb_always_assert (!jstf->get_script_count ());
|
|
hb_always_assert (0 == hb_ot_layout_get_extender_glyphs (face, HB_SCRIPT_ARABIC, HB_LANGUAGE_INVALID, 0, NULL, NULL));
|
|
#endif
|
|
jstf.destroy ();
|
|
hb_face_destroy (face);
|
|
|
|
#ifndef HB_NO_BEYOND_64K
|
|
face = create_face (data, sizeof (data) - 1);
|
|
jstf = hb_sanitize_context_t ().reference_table<OT::JSTF> (face);
|
|
hb_always_assert (!jstf.get_length ());
|
|
jstf.destroy ();
|
|
hb_face_destroy (face);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|