Let hb_shape() guess script and direction...
- Rename HB_SCRIPT_INVALID_CODE to HB_SCRIPT_INVALID - Add HB_DIRECTION_INVALID - Make hb_script_get_horizontal_direction() public - Make hb_shape() guess script from buffer text (first non-common non-inherit script) if buffer script is set to HB_SCRIPT_INVALID (this is NOT the default.) - Make hb_shape() guess direction from buffer script if buffer direction is set to HB_DIRECTION_INVALID (this is NOT the default.) - Make hb-view.c set INVALID script and direction on the buffer. The above changes are meant to make hb-view fairly useful for uni-script uni-direction text. The guessing behavior however is NOT the default of hb_shape() and must be asked for explicitly. This is intended, because the guess is not a suitable substitute to full-fledged bidi and script segmentation. It's just a testing tool.
This commit is contained in:
parent
b7b29684df
commit
3286fc0e9a
|
@ -78,7 +78,8 @@ typedef uint32_t hb_mask_t;
|
||||||
typedef void (*hb_destroy_func_t) (void *user_data);
|
typedef void (*hb_destroy_func_t) (void *user_data);
|
||||||
|
|
||||||
typedef enum _hb_direction_t {
|
typedef enum _hb_direction_t {
|
||||||
HB_DIRECTION_LTR,
|
HB_DIRECTION_INVALID = -1,
|
||||||
|
HB_DIRECTION_LTR = 0,
|
||||||
HB_DIRECTION_RTL,
|
HB_DIRECTION_RTL,
|
||||||
HB_DIRECTION_TTB,
|
HB_DIRECTION_TTB,
|
||||||
HB_DIRECTION_BTT
|
HB_DIRECTION_BTT
|
||||||
|
|
|
@ -118,7 +118,7 @@ hb_icu_get_script (hb_codepoint_t unicode)
|
||||||
U_ICU_VERSION_MAJOR_NUM > (major) || (U_ICU_VERSION_MAJOR_NUM == (major) && U_ICU_VERSION_MINOR_NUM >= (minor))
|
U_ICU_VERSION_MAJOR_NUM > (major) || (U_ICU_VERSION_MAJOR_NUM == (major) && U_ICU_VERSION_MINOR_NUM >= (minor))
|
||||||
#define MATCH_SCRIPT(C) case USCRIPT_##C: return HB_SCRIPT_##C
|
#define MATCH_SCRIPT(C) case USCRIPT_##C: return HB_SCRIPT_##C
|
||||||
#define MATCH_SCRIPT2(C1, C2) case USCRIPT_##C1: return HB_SCRIPT_##C2
|
#define MATCH_SCRIPT2(C1, C2) case USCRIPT_##C1: return HB_SCRIPT_##C2
|
||||||
MATCH_SCRIPT (INVALID_CODE);
|
|
||||||
MATCH_SCRIPT (COMMON); /* Zyyy */
|
MATCH_SCRIPT (COMMON); /* Zyyy */
|
||||||
MATCH_SCRIPT (INHERITED); /* Qaai */
|
MATCH_SCRIPT (INHERITED); /* Qaai */
|
||||||
MATCH_SCRIPT (ARABIC); /* Arab */
|
MATCH_SCRIPT (ARABIC); /* Arab */
|
||||||
|
|
|
@ -64,6 +64,7 @@ hb_ot_shape_collect_features (hb_ot_shape_plan_t *plan,
|
||||||
break;
|
break;
|
||||||
case HB_DIRECTION_TTB:
|
case HB_DIRECTION_TTB:
|
||||||
case HB_DIRECTION_BTT:
|
case HB_DIRECTION_BTT:
|
||||||
|
case HB_DIRECTION_INVALID:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +171,7 @@ hb_ensure_native_direction (hb_ot_shape_context_t *c)
|
||||||
|
|
||||||
/* TODO vertical */
|
/* TODO vertical */
|
||||||
if (HB_DIRECTION_IS_HORIZONTAL (direction) &&
|
if (HB_DIRECTION_IS_HORIZONTAL (direction) &&
|
||||||
direction != _hb_script_get_horizontal_direction (c->buffer->props.script))
|
direction != hb_script_get_horizontal_direction (c->buffer->props.script))
|
||||||
{
|
{
|
||||||
hb_buffer_reverse_clusters (c->buffer);
|
hb_buffer_reverse_clusters (c->buffer);
|
||||||
c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction);
|
c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction);
|
||||||
|
|
|
@ -39,12 +39,12 @@
|
||||||
HB_BEGIN_DECLS
|
HB_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
void
|
static void
|
||||||
hb_shape (hb_font_t *font,
|
hb_shape_internal (hb_font_t *font,
|
||||||
hb_face_t *face,
|
hb_face_t *face,
|
||||||
hb_buffer_t *buffer,
|
hb_buffer_t *buffer,
|
||||||
hb_feature_t *features,
|
hb_feature_t *features,
|
||||||
unsigned int num_features)
|
unsigned int num_features)
|
||||||
{
|
{
|
||||||
#if 0 && defined(HAVE_GRAPHITE)
|
#if 0 && defined(HAVE_GRAPHITE)
|
||||||
hb_blob_t *silf_blob;
|
hb_blob_t *silf_blob;
|
||||||
|
@ -61,5 +61,45 @@ hb_shape (hb_font_t *font,
|
||||||
hb_ot_shape (font, face, buffer, features, num_features);
|
hb_ot_shape (font, face, buffer, features, num_features);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hb_shape (hb_font_t *font,
|
||||||
|
hb_face_t *face,
|
||||||
|
hb_buffer_t *buffer,
|
||||||
|
hb_feature_t *features,
|
||||||
|
unsigned int num_features)
|
||||||
|
{
|
||||||
|
hb_segment_properties_t orig_props;
|
||||||
|
|
||||||
|
orig_props = buffer->props;
|
||||||
|
|
||||||
|
/* If script is set to INVALID, guess from buffer contents */
|
||||||
|
if (buffer->props.script == HB_SCRIPT_INVALID) {
|
||||||
|
hb_unicode_get_script_func_t get_script = buffer->unicode->v.get_script;
|
||||||
|
unsigned int count = buffer->len;
|
||||||
|
for (unsigned int i = 0; i < count; i++) {
|
||||||
|
hb_script_t script = get_script (buffer->info[i].codepoint);
|
||||||
|
if (likely (script > HB_SCRIPT_INHERITED)) {
|
||||||
|
buffer->props.script = script;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If direction is set to INVALID, guess from script */
|
||||||
|
if (buffer->props.direction == HB_DIRECTION_INVALID) {
|
||||||
|
buffer->props.direction = hb_script_get_horizontal_direction (buffer->props.script);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If language is not set, use default language from locale */
|
||||||
|
if (buffer->props.language == NULL) {
|
||||||
|
/* TODO get_default_for_script? using $LANGUAGE */
|
||||||
|
//buffer->props.language = hb_language_get_default ();
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_shape_internal (font, face, buffer, features, num_features);
|
||||||
|
|
||||||
|
buffer->props = orig_props;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
|
@ -55,10 +55,6 @@ struct _hb_unicode_funcs_t {
|
||||||
extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
|
extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
|
||||||
|
|
||||||
|
|
||||||
HB_INTERNAL hb_direction_t
|
|
||||||
_hb_script_get_horizontal_direction (hb_script_t script);
|
|
||||||
|
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
||||||
#endif /* HB_UNICODE_PRIVATE_H */
|
#endif /* HB_UNICODE_PRIVATE_H */
|
||||||
|
|
|
@ -352,7 +352,7 @@ const hb_direction_t horiz_dir[] =
|
||||||
#undef RTL
|
#undef RTL
|
||||||
|
|
||||||
hb_direction_t
|
hb_direction_t
|
||||||
_hb_script_get_horizontal_direction (hb_script_t script)
|
hb_script_get_horizontal_direction (hb_script_t script)
|
||||||
{
|
{
|
||||||
if (unlikely ((unsigned int) script >= ARRAY_LENGTH (horiz_dir)))
|
if (unlikely ((unsigned int) script >= ARRAY_LENGTH (horiz_dir)))
|
||||||
return HB_DIRECTION_LTR;
|
return HB_DIRECTION_LTR;
|
||||||
|
|
|
@ -70,7 +70,8 @@ typedef enum
|
||||||
/* Unicode Script property */
|
/* Unicode Script property */
|
||||||
typedef enum
|
typedef enum
|
||||||
{ /* ISO 15924 code */
|
{ /* ISO 15924 code */
|
||||||
HB_SCRIPT_INVALID_CODE = -1,
|
HB_SCRIPT_INVALID = -1,
|
||||||
|
|
||||||
HB_SCRIPT_COMMON = 0, /* Zyyy */
|
HB_SCRIPT_COMMON = 0, /* Zyyy */
|
||||||
HB_SCRIPT_INHERITED, /* Qaai */
|
HB_SCRIPT_INHERITED, /* Qaai */
|
||||||
HB_SCRIPT_ARABIC, /* Arab */
|
HB_SCRIPT_ARABIC, /* Arab */
|
||||||
|
@ -289,6 +290,11 @@ hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
|
||||||
hb_codepoint_t unicode);
|
hb_codepoint_t unicode);
|
||||||
|
|
||||||
|
|
||||||
|
/* Misc functions */
|
||||||
|
|
||||||
|
hb_direction_t
|
||||||
|
hb_script_get_horizontal_direction (hb_script_t script);
|
||||||
|
|
||||||
HB_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
||||||
#endif /* HB_UNICODE_H */
|
#endif /* HB_UNICODE_H */
|
||||||
|
|
|
@ -184,8 +184,8 @@ _hb_cr_text_glyphs (cairo_t *cr,
|
||||||
hb_buffer_set_unicode_funcs (hb_buffer, hb_glib_get_unicode_funcs ());
|
hb_buffer_set_unicode_funcs (hb_buffer, hb_glib_get_unicode_funcs ());
|
||||||
|
|
||||||
hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
|
hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
|
||||||
/* hb_buffer_set_script (hb_buffer, HB_SCRIPT_LATIN); */
|
hb_buffer_set_script (hb_buffer, HB_SCRIPT_INVALID);
|
||||||
/* hb_buffer_set_direction (hb_buffer, HB_DIRECTION_LTR); */
|
hb_buffer_set_direction (hb_buffer, HB_DIRECTION_INVALID);
|
||||||
hb_buffer_set_language (hb_buffer, hb_language_from_string (language));
|
hb_buffer_set_language (hb_buffer, hb_language_from_string (language));
|
||||||
|
|
||||||
hb_shape (hb_font, hb_face, hb_buffer, NULL, 0);
|
hb_shape (hb_font, hb_face, hb_buffer, NULL, 0);
|
||||||
|
|
Loading…
Reference in New Issue