Add API for setting invisible-codepoint

Fixes https://github.com/harfbuzz/harfbuzz/issues/1216

New API:
hb_buffer_set_invisible_codepoint()
hb_buffer_get_invisible_codepoint()

hb-shape / hb-view --invisible-codepoint
This commit is contained in:
Behdad Esfahbod 2018-10-07 18:41:52 +02:00
parent 13da3be0b3
commit 71b65eb27d
7 changed files with 60 additions and 4 deletions

View File

@ -67,6 +67,8 @@ hb_buffer_set_user_data
hb_buffer_get_user_data
hb_buffer_get_glyph_infos
hb_buffer_get_glyph_positions
hb_buffer_get_invisible_codepoint
hb_buffer_set_invisible_codepoint
hb_buffer_set_replacement_codepoint
hb_buffer_get_replacement_codepoint
hb_buffer_normalize_glyphs

View File

@ -219,6 +219,7 @@ hb_buffer_t::reset (void)
unicode = hb_unicode_funcs_reference (hb_unicode_funcs_get_default ());
flags = HB_BUFFER_FLAG_DEFAULT;
replacement = HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT;
invisible = 0;
clear ();
}
@ -665,6 +666,7 @@ DEFINE_NULL_INSTANCE (hb_buffer_t) =
HB_BUFFER_FLAG_DEFAULT,
HB_BUFFER_CLUSTER_LEVEL_DEFAULT,
HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT,
0, /* invisible */
HB_BUFFER_SCRATCH_FLAG_DEFAULT,
HB_BUFFER_MAX_LEN_DEFAULT,
HB_BUFFER_MAX_OPS_DEFAULT,
@ -1166,6 +1168,46 @@ hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer)
}
/**
* hb_buffer_set_invisible_codepoint:
* @buffer: an #hb_buffer_t.
* @invisible: the invisible #hb_codepoint_t
*
* Sets the #hb_codepoint_t that replaces invisible characters in
* the shaping result. If set to zero (default), the glyph for the
* U+0020 SPACE character is used. Otherwise, this value is used
* verbatim.
*
* Since: REPLACEME
**/
void
hb_buffer_set_invisible_codepoint (hb_buffer_t *buffer,
hb_codepoint_t invisible)
{
if (unlikely (hb_object_is_inert (buffer)))
return;
buffer->invisible = invisible;
}
/**
* hb_buffer_get_invisible_codepoint:
* @buffer: an #hb_buffer_t.
*
* See hb_buffer_set_invisible_codepoint().
*
* Return value:
* The @buffer invisible #hb_codepoint_t.
*
* Since: REPLACEME
**/
hb_codepoint_t
hb_buffer_get_invisible_codepoint (hb_buffer_t *buffer)
{
return buffer->invisible;
}
/**
* hb_buffer_reset:
* @buffer: an #hb_buffer_t.

View File

@ -341,6 +341,13 @@ hb_buffer_set_replacement_codepoint (hb_buffer_t *buffer,
HB_EXTERN hb_codepoint_t
hb_buffer_get_replacement_codepoint (hb_buffer_t *buffer);
HB_EXTERN void
hb_buffer_set_invisible_codepoint (hb_buffer_t *buffer,
hb_codepoint_t invisible);
HB_EXTERN hb_codepoint_t
hb_buffer_get_invisible_codepoint (hb_buffer_t *buffer);
HB_EXTERN void
hb_buffer_reset (hb_buffer_t *buffer);

View File

@ -93,6 +93,7 @@ struct hb_buffer_t
hb_buffer_flags_t flags; /* BOT / EOT / etc. */
hb_buffer_cluster_level_t cluster_level;
hb_codepoint_t replacement; /* U+FFFD or something else. */
hb_codepoint_t invisible; /* 0 or something else. */
hb_buffer_scratch_flags_t scratch_flags; /* Have space-fallback, etc. */
unsigned int max_len; /* Maximum allowed len. */
int max_ops; /* Maximum allowed operations. */

View File

@ -548,15 +548,15 @@ hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c)
if (i == count)
return;
hb_codepoint_t space;
hb_codepoint_t invisible = c->buffer->invisible;
if (!(buffer->flags & HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES) &&
c->font->get_nominal_glyph (' ', &space))
(invisible || c->font->get_nominal_glyph (' ', &invisible)))
{
/* Replace default-ignorables with a zero-advance space glyph. */
/* Replace default-ignorables with a zero-advance invisible glyph. */
for (/*continue*/; i < count; i++)
{
if (_hb_glyph_info_is_default_ignorable (&info[i]))
info[i].codepoint = space;
info[i].codepoint = invisible;
}
}
else

View File

@ -415,6 +415,7 @@ shape_options_t::add_options (option_parser_t *parser)
{"eot", 0, 0, G_OPTION_ARG_NONE, &this->eot, "Treat text as end-of-paragraph", nullptr},
{"preserve-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->preserve_default_ignorables, "Preserve Default-Ignorable characters", nullptr},
{"remove-default-ignorables",0, 0, G_OPTION_ARG_NONE, &this->remove_default_ignorables, "Remove Default-Ignorable characters", nullptr},
{"invisible-codepoint",0, 0, G_OPTION_ARG_INT, &this->invisible_codepoint, "Value to replace Default-Ignorables with", nullptr},
{"utf8-clusters", 0, 0, G_OPTION_ARG_NONE, &this->utf8_clusters, "Use UTF8 byte indices, not char indices", nullptr},
{"cluster-level", 0, 0, G_OPTION_ARG_INT, &this->cluster_level, "Cluster merging level (default: 0)", "0/1/2"},
{"normalize-glyphs",0, 0, G_OPTION_ARG_NONE, &this->normalize_glyphs, "Rearrange glyph clusters in nominal order", nullptr},

View File

@ -155,6 +155,7 @@ struct shape_options_t : option_group_t
num_features = 0;
shapers = nullptr;
utf8_clusters = false;
invisible_codepoint = 0;
cluster_level = HB_BUFFER_CLUSTER_LEVEL_DEFAULT;
normalize_glyphs = false;
verify = false;
@ -185,6 +186,7 @@ struct shape_options_t : option_group_t
(preserve_default_ignorables ? HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES : 0) |
(remove_default_ignorables ? HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES : 0) |
0));
hb_buffer_set_invisible_codepoint (buffer, invisible_codepoint);
hb_buffer_set_cluster_level (buffer, cluster_level);
hb_buffer_guess_segment_properties (buffer);
}
@ -435,6 +437,7 @@ struct shape_options_t : option_group_t
unsigned int num_features;
char **shapers;
hb_bool_t utf8_clusters;
hb_codepoint_t invisible_codepoint;
hb_buffer_cluster_level_t cluster_level;
hb_bool_t normalize_glyphs;
hb_bool_t verify;