Skip to content

Commit

Permalink
Fix number of issues with percentage spacing as well as negative spac…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
therahedwig committed May 2, 2022
1 parent bfefd29 commit d33b18d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/raqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ _raqm_set_spacing (raqm_t *rq,
if (!rq->text_info)
return false;

for (size_t i = start; i < end-1; i++)
for (size_t i = start; i < end; i++)
if (word_spacing)
{
for (size_t j = 0; j < word_separators_len; j++)
Expand All @@ -1291,16 +1291,16 @@ _raqm_set_spacing (raqm_t *rq,
/**
* raqm_set_letter_spacing_range:
* @rq: a #raqm_t.
* @spacing: amount of spacing in Freetype Font Units (26.6 format), or percentages of the letter (0 - 100)
* @spacing: amount of spacing in Freetype Font Units (26.6 format), or percentages of the advance (0 - 100)
* @percentage: whether to interpret the @spacing amount as a percentage of
* the character advance.
* @start: index of first character that should use @spacing.
* @len: number of characters using @spacing.
*
* Set the letter spacing or tracking for a given range, the value
* will be added onto the advance and offset for RTL, and the advance for
* other directions. Letter spacing will be applied after all characters in
* the range.
* other directions. Letter spacing will be applied between characters, so
* the last character will not have spacing applied after it.
* Note that not all scripts have a letter-spacing tradition,
* for example, Arabic does not, while Devanagari does.
*
Expand All @@ -1316,7 +1316,7 @@ raqm_set_letter_spacing_range(raqm_t *rq,
size_t start,
size_t len)
{
size_t end = start + len;
size_t end = start + (len-1);

if (!rq)
return false;
Expand All @@ -1341,7 +1341,7 @@ raqm_set_letter_spacing_range(raqm_t *rq,
/**
* raqm_set_word_spacing_range:
* @rq: a #raqm_t.
* @spacing: amount of spacing in Freetype Font Units (26.6 format), or percentages of the letter (0 - 100)
* @spacing: amount of spacing in Freetype Font Units (26.6 format), or percentages of the advance (0 - 100)
* @percentage: whether to interpret the @spacing amount as a percentage of
* the character advance.
* @start: index of first character that should use @spacing.
Expand Down Expand Up @@ -2358,24 +2358,26 @@ _raqm_shape (raqm_t *rq)
_raqm_ft_transform (&pos[i].x_advance, &pos[i].y_advance, matrix);
_raqm_ft_transform (&pos[i].x_offset, &pos[i].y_offset, matrix);

if (rq->text_info[info[i].cluster].spacing_after > 0)
if (rq->text_info[info[i].cluster].spacing_after != 0)
{
if (run->direction == HB_DIRECTION_TTB)
{
if (rq->text_info[info[i].cluster].spacing_is_percentage)
{
pos[i].y_advance *= 1.0 + (rq->text_info[info[i].cluster].spacing_after * 0.01);
int spacing = pos[i].y_advance * (rq->text_info[info[i].cluster].spacing_after * 0.01);
pos[i].y_advance += spacing;
}
else {
pos[i].y_advance += rq->text_info[info[i].cluster].spacing_after;
pos[i].y_advance -= rq->text_info[info[i].cluster].spacing_after;
}
}
else if (run->direction == HB_DIRECTION_RTL)
{
{
if (rq->text_info[info[i].cluster].spacing_is_percentage)
{
pos[i].x_offset += pos[i].x_advance * (rq->text_info[info[i].cluster].spacing_after * 0.01);
pos[i].x_advance *= 1.0 + (rq->text_info[info[i].cluster].spacing_after * 0.01);
int spacing = pos[i].x_advance * (rq->text_info[info[i].cluster].spacing_after * 0.01);
pos[i].x_offset += spacing;
pos[i].x_advance += spacing;
}
else {
pos[i].x_advance += rq->text_info[info[i].cluster].spacing_after;
Expand Down

0 comments on commit d33b18d

Please sign in to comment.