admin管理员组

文章数量:1312774

I want to shape a string of text with harfbuzz where some portions of the string (a word) is BOLD, whereas the rest remain REGULAR. The text buffer is entirely a single script, language and direction.

I'm uncertain how to use the API to specify which portions of the text is REGULAR, and which is BOLD.

The following documentation describes the basic overview of shaping text, which I'm following, and here it mentions:

The safest approach is to add all of the text available (even if your text contains a mix of scripts, directions, languages and fonts), then use item_offset and item_length to indicate which characters you want shaped (which must all have the same script, direction, language and font), so that HarfBuzz has access to any context.

Given the above I've so far assumed that for the given sample string: A test sentence with uniform formatting I would simply:

  1. Add the entire string of text in one go using hb_buffer_add_utf8 (and specify the entire length of the buffer)
  2. Set thte language, script and direction
  3. Call hb_shape with a single font (REGULAR.ttf etc)

However, how do I shape the string if I want the word test to be BOLD, but the rest REGULAR?

Do I:

  • call hb_buffer_add_utf8 three times?
  • the first to shape offsets 0 to 1 (inclusive) to shape A
  • then a second call to shape offsets 2 to 5, for test
  • then lastly another call to shape sentence

The issue I'm having is that hb_shape doesn't accept offsets like hb_buffer_add_utf8, and takes a single font.

Does this imply that I call hb_shape three times as well? where in the second call I just pass it the BOLD font?

本文标签: fontsharfbuzz shaping text with different formattingStack Overflow