}
+/* hb_direction_t */
+
+const char direction_strings[][4] = {
+ "ltr",
+ "rtl",
+ "ttb",
+ "btt"
+};
+
+hb_direction_t
+hb_direction_from_string (const char *str)
+{
+ if (unlikely (!str || !*str))
+ return HB_DIRECTION_INVALID;
+
+ /* Lets match loosely: just match the first letter, such that
+ * all of "ltr", "left-to-right", etc work!
+ */
+ char c = TOLOWER (str[0]);
+ for (unsigned int i = 0; i < ARRAY_LENGTH (direction_strings); i++)
+ if (c == direction_strings[i][0])
+ return (hb_direction_t) i;
+
+ return HB_DIRECTION_INVALID;
+}
+
+const char *
+hb_direction_to_string (hb_direction_t direction)
+{
+ if (likely ((unsigned int) direction < ARRAY_LENGTH (direction_strings)))
+ return direction_strings[direction];
+
+ return "invalid";
+}
+
+
/* hb_language_t */
struct _hb_language_t {
static const char *text = NULL;
static const char *font_file = NULL;
static const char *out_file = "/dev/stdout";
-static const char *language = NULL;
+static const char *direction = NULL;
static const char *script = NULL;
+static const char *language = NULL;
static hb_feature_t *features = NULL;
static unsigned int num_features;
static hb_bool_t debug = FALSE;
static struct option long_options[] = {
{"background", 1, 0, 'B'},
{"debug", 0, &debug, TRUE},
+ {"direction", 1, 0, 'd'},
{"features", 1, 0, 'f'},
{"font-size", 1, 0, 's'},
{"foreground", 1, 0, 'F'},
case 't':
text = optarg;
break;
- case 'L':
- language = optarg;
+ case 'd':
+ direction = optarg;
break;
case 'S':
script = optarg;
break;
+ case 'L':
+ language = optarg;
+ break;
case 'o':
out_file = optarg;
break;
hb_buffer = hb_buffer_create (0);
+ if (direction)
+ hb_buffer_set_direction (hb_buffer, hb_direction_from_string (direction));
if (script)
hb_buffer_set_script (hb_buffer, hb_script_from_string (script));
if (language)
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_RTL), ==, HB_DIRECTION_LTR);
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_TTB), ==, HB_DIRECTION_BTT);
g_assert_cmpint (HB_DIRECTION_REVERSE (HB_DIRECTION_BTT), ==, HB_DIRECTION_TTB);
+
+ g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string (NULL));
+ g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string (""));
+ g_assert_cmpint (HB_DIRECTION_INVALID, ==, hb_direction_from_string ("x"));
+ g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("r"));
+ g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("rtl"));
+ g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("RtL"));
+ g_assert_cmpint (HB_DIRECTION_RTL, ==, hb_direction_from_string ("right-to-left"));
+ g_assert_cmpint (HB_DIRECTION_TTB, ==, hb_direction_from_string ("ttb"));
}
static void
hb_tag_t x123 = HB_TAG_CHAR4 ("x123");
- g_assert_cmpint ((hb_tag_t) HB_SCRIPT_INVALID, ==, HB_TAG_NONE);
+ g_assert_cmpint (HB_SCRIPT_INVALID, ==, (hb_script_t) HB_TAG_NONE);
g_assert_cmphex (HB_SCRIPT_ARABIC, !=, HB_SCRIPT_LATIN);
+ g_assert_cmphex (HB_SCRIPT_INVALID, ==, hb_script_from_string (NULL));
+ g_assert_cmphex (HB_SCRIPT_INVALID, ==, hb_script_from_string (""));
+ g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_string ("x"));
+
+ g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("arab"));
+ g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("Arab"));
+ g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_string ("ARAB"));
+
g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (arab));
g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (Arab));
g_assert_cmphex (HB_SCRIPT_ARABIC, ==, hb_script_from_iso15924_tag (ARAB));
/* Arbitrary tags that look like may be valid ISO 15924 should be preserved. */
+ g_assert_cmphex (HB_SCRIPT_UNKNOWN, !=, hb_script_from_string ("wWyZ"));
g_assert_cmphex (HB_SCRIPT_UNKNOWN, !=, hb_script_from_iso15924_tag (wWyZ));
/* Otherwise, UNKNOWN should be returned. */
+ g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_string ("x123"));
g_assert_cmphex (HB_SCRIPT_UNKNOWN, ==, hb_script_from_iso15924_tag (x123));
g_assert_cmphex (hb_script_to_iso15924_tag (HB_SCRIPT_ARABIC), ==, Arab);