[HarfBuzz] Support for 'rand' (randomize) feature?

Behdad Esfahbod behdad at behdad.org
Thu Jun 9 14:50:17 PDT 2011

Hi Khaled,

On 06/05/11 08:27, Khaled Hosny wrote:
> As its name suggests, 'rand' is used to list multiple glyph variants
> that the engine should select from (pseudo)randomly, see:
> http://www.microsoft.com/typography/otspec/features_pt.htm#rand

I like to do that.  However, the main problem with doing so is how to make the
glyph selection deterministic.  It may not be a huge deal for, say, generating
a PDF.  But for a GUI, you just can't shape differently every time the
expose() event is called.

There are two different concerns in fact:

  - We HAVE to guarantee that same inputs to hb_shape() will produce the same
outputs, Every Time.  This in itself is not in conflict with the rand
features, as we can let the user set a "random seed" kind of number to
reproduce different start conditions.  The value can be set, say, in a 'rand'
feature passed to the shaper, or maybe with something like
hb_buffer_set_serial().  At any rate, this means that, unless the application
goes out of its way to set the random seed, any two paragraphs containing the
exact same text will shape exactly the same.  That's kinda by design.  There
are ways around it though, if the user uses different item_offset's for the
two paragraphs.

  - Ideally, if one breaks the text at word boundaries and other "safe"
locations and shape the two segments separately and concatenate the resulting
glyph strings, it should be equivalent to shaping the text as a whole.  I wish
to make hb_shape() compute those "safe" locations and output it.  Now, what
this means for the rand feature is that if a rand feature is available, no
place is safe to break, since breaking the text at any point will affect the
random seed.

I'll think about this more and see what I can do.


> For testing, my OpenType implementation of Knuth's Punk font can be a
> good test:
> https://github.com/khaledhosny/punk-otf
> (though it is not a serious font, 'rand' can have good application in
> calligraphic and fonts that tries to capture irregularities of hand
> writing.)
> Regards,
>  Khaled

More information about the HarfBuzz mailing list