[HarfBuzz] Overwrite certain font characters

Behdad Esfahbod behdad at behdad.org
Tue Jun 28 23:05:31 UTC 2016


HarfBuzz already takes care of spaces if the font does not support:


https://github.com/behdad/harfbuzz/blob/master/src/hb-unicode-private.hh#L204

On Sun, Jun 26, 2016 at 10:56 AM, Kelvin Ma <kelvinsthirteen at gmail.com>
wrote:

> Knockout overwrites most whitespace characters to a hardcoded width and
> special codepoint since most fonts can’t be trusted to properly construct
> or even contain these characters.
>
> ## Codepoints ##
>
> nonbreaking_spaces = {
>             '\u00A0': -30, # nbsp
>             '\u2007': -36, # figure
>             '\u202F': -40, # narrow nbsp
>             }
>
> breaking_spaces = {
>             '\u2003': -31, # em
>             '\u2002': -32, # en
>             '\u2004': -33, # 1/3
>             '\u2005': -34, # 1/4
>             '\u2006': -35, # 1/6
>
>             '\u2008': -37, # punctuation
>             '\u2009': -38, # thin
>             '\u200A': -39, # hair
>
>             '\u205F': -41, # math med
>             }
>
>
> ## Widths (as fraction of em) ##
>
> space = self.get_advance(self.character_index(' '), True)/UPM
> fig = self.get_advance(self.character_index('0'), True)/UPM
> punc = self.get_advance(self.character_index(','), True)/UPM
>
> self._widths = {
>         None: 0,
>         ' ': space,
>         '\t': 0,
>         '\u00A0': space,
>         '\u2003': 1, # em
>         '\u2002': 0.5, # en
>         '\u2004': 1/3, # 1/3
>         '\u2005': 0.25, # 1/4
>         '\u2006': 1/6, # 1/6
>         '\u2007': fig, # figure
>         '\u2008': punc, # punctuation
>         '\u2009': 0.2, # thin
>         '\u200A': 0.1, # hair
>         '\u202F': 0.2, # narrow nbsp
>         '\u205F': 4/18, # math med
>         }
>
>
> ## character labels (for UI) ##
>
> self.spacenames = {
>         -30: 'nb', # nbsp
>         -31: 'em', # em
>         -32: 'en', # en
>         -33: '1/3', # 1/3
>         -34: '1/4', # 1/4
>         -35: '1/6', # 1/6
>         -36: 'fig', # figure
>         -37: 'pn', # punctuation
>         -38: '1/5', # thin
>         -39: 'h', # hair
>         -40: 'nnb', # narrow nbsp
>         -41: 'mt', # math med
>         }
>
> My old layout engine would simply output the special negative codepoint
> and advance like with any other character when it encountered those unicode
> whitespace characters. (The negative codepoints are so that Knockout’s
> renderer knows how to display them.) How do I do this in Harfbuzz? They are
> important for mathematical typesetting.
>
> [image: Inline image 1]
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
>


-- 
behdad
http://behdad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20160628/ff1aec3e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Selection_050.png
Type: image/png
Size: 9373 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20160628/ff1aec3e/attachment-0001.png>


More information about the HarfBuzz mailing list