aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2023-03-01 11:08:32 -0700
committerBehdad Esfahbod <behdad@behdad.org>2023-03-01 14:23:12 -0700
commitaa10deaf4283822f8c368ecbdebd01330dd76fe5 (patch)
tree39a43de3b265004135b7fe3d691be3de0327bf6a /util
parent93252c6fc3585f6c226514e9c476af82b7c55d86 (diff)
downloadharfbuzz_ng-aa10deaf4283822f8c368ecbdebd01330dd76fe5.tar.gz
[justify] Print default buffer width in hb-shape --width=-1
Diffstat (limited to 'util')
-rw-r--r--util/shape-options.hh25
1 files changed, 22 insertions, 3 deletions
diff --git a/util/shape-options.hh b/util/shape-options.hh
index 0d8977cd6..8e38244f0 100644
--- a/util/shape-options.hh
+++ b/util/shape-options.hh
@@ -161,7 +161,7 @@ struct shape_options_t
}
else
{
- if (!width)
+ if (width <= 0)
{
if (!hb_shape_full (font, buffer, features, num_features, shapers))
{
@@ -169,6 +169,25 @@ struct shape_options_t
*error = "Shaping failed.";
goto fail;
}
+
+ if (width < 0)
+ {
+ float unit = (1 << SUBPIXEL_BITS);
+
+ /* Calculate buffer width */
+ float w = 0;
+ unsigned count = 0;
+ hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &count);
+ if (HB_DIRECTION_IS_HORIZONTAL (hb_buffer_get_direction (buffer)))
+ for (unsigned i = 0; i < count; i++)
+ w += pos[i].x_advance;
+ else
+ for (unsigned i = 0; i < count; i++)
+ w += pos[i].y_advance;
+
+ printf ("Default width: %u\n", (unsigned) roundf (w / unit));
+ exit (0);
+ }
}
else
{
@@ -221,7 +240,7 @@ struct shape_options_t
hb_feature_t *features = nullptr;
unsigned int num_features = 0;
char **shapers = nullptr;
- unsigned width = 0;
+ signed width = 0;
hb_bool_t utf8_clusters = false;
hb_codepoint_t invisible_glyph = 0;
hb_codepoint_t not_found_glyph = 0;
@@ -349,7 +368,7 @@ shape_options_t::add_options (option_parser_t *parser)
{"bot", 0, 0, G_OPTION_ARG_NONE, &this->bot, "Treat text as beginning-of-paragraph", nullptr},
{"eot", 0, 0, G_OPTION_ARG_NONE, &this->eot, "Treat text as end-of-paragraph", nullptr},
{"width", 'w',0,
- G_OPTION_ARG_INT, &this->width, "Target width to justify to", "WIDTH"},
+ G_OPTION_ARG_INT, &this->width, "Target width to justify to", "WIDTH, or -1"},
{"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-glyph", 0, 0, G_OPTION_ARG_INT, &this->invisible_glyph, "Glyph value to replace Default-Ignorables with", nullptr},