diff --git a/src/raqm.c b/src/raqm.c index 7729030..92c18c0 100644 --- a/src/raqm.c +++ b/src/raqm.c @@ -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++) @@ -1291,7 +1291,7 @@ _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. @@ -1299,8 +1299,8 @@ _raqm_set_spacing (raqm_t *rq, * * 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. * @@ -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; @@ -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. @@ -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;