[squeak-dev] The Inbox: TrueType-EG.72.mcz

Eric Gade eric.gade at gmail.com
Tue Feb 8 13:38:25 UTC 2022


Hello all,

Sorry about this commit message, I'm still getting used to monticello
apparently.

This commit deals with being able to render Unicode fonts that are in the
higher codepoint planes. Here are two commit messages I had locally that
explain it:


> Initial implementation of cmap format 12 from the ttf spec.
>
> Modifying font reading to better conform with apple's TTF guidelines. In
> two ways.
>
> First, Windows platform with encoding id 10 is actually a Unicode
> platform, so TTCharacterMappingTable will now have isUnicode respond true
> for such cases.
>
> Second, the TTF spec (
> https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html)
> says that *not only* should Unicode cmaps be preferred, but those with
> character encodings outside of the Unicode BMP (aka the base multilingual
> plane) should be preferred above all. We modify #processCharMap: here to
> try and determine the best Unicode mapping to use in the case of multiple
> options. For now, we simply pick the one with the larger character table.
>

On Tue, Feb 8, 2022 at 8:33 AM <commits at source.squeak.org> wrote:

> A new version of TrueType was added to project The Inbox:
> http://source.squeak.org/inbox/TrueType-EG.72.mcz
>
> ==================== Summary ====================
>
> Name: TrueType-EG.72
> Author: EG
> Time: 8 February 2022, 8:22:21.647553 am
> UUID: 30a1fb32-8d4c-45f6-853d-4b6727e2149c
> Ancestors: TrueType-EG.71
>
> Removing leftover halt message
>
> =============== Diff against TrueType-mt.68 ===============
>
> Item was changed:
>   ----- Method: TTCharacterMappingTable>>isUnicode (in category 'testing')
> -----
>   isUnicode
>
> +       "A cmap is considered Unicode if either:
> +        a) the platformID is 0, ie the Unicode platform; or
> +        b) The platformID is Windows (3) and the encodingID is Unicode
> for Windows (10).
> +        See the 'cmap encoding subtables' section of
> https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
> "
> +       ^ (platformID = 0) or: [
> +               (platformID = 3 and: [ encodingID = 10 ])]!
> -       ^ platformID = 0!
>
> Item was added:
> + ----- Method: TTFontReader>>decodeCmapFmtTable12: (in category
> 'private') -----
> + decodeCmapFmtTable12: entry
> +       "Segmented coverage for supplementary range unicode chars.
> +       See
> https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-0-byte-encoding-table
> "
> +       | length language numGroups cmap groups |
> +       entry nextUShort. "This is ignored, so we now align to 32-bit
> values"
> +       length := entry nextULong.
> +       language := entry nextULong.
> +       numGroups := entry nextULong.
> +       groups := Array new: numGroups.
> +
> +       1 to: numGroups do: [ :num |
> +               groups at: num put: {
> +                       entry nextULong. "startCharCode"
> +                       entry nextULong. "endCharCode"
> +                       entry nextULong. "startGlyphId"
> +                       0. "End glyph id will be calculated"}].
> +
> +       "Groups are in order, so the last group's endCharcode is
> +       the full size of the character map"
> +       cmap := Array new: (groups last second + 1) withAll: 0.
> +
> +       groups do: [ :groupData |
> +               | codeStart codeEnd |
> +               codeStart := groupData first.
> +               codeEnd := groupData second.
> +               codeStart to: codeEnd do: [ :index |
> +                       cmap at: (index + 1) put: (groupData third +
> (index - codeStart))]].
> +
> +       ^ {language. cmap}
> +       !
>
> Item was changed:
>   ----- Method: TTFontReader>>decodeCmapFmtTable: (in category 'private')
> -----
>   decodeCmapFmtTable: entry
>         "Decode cmap table. Currently supports formats 0, 4, and 6
>
> https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-0-byte-encoding-table
> "
>
>         | cmapFmt |
>         ^ (cmapFmt := entry nextUShort)
>                 caseOf: {
>                         [0] -> [self decodeCmapFmtTable0: entry].
>                         [4] -> [self decodeCmapFmtTable4: entry].
>                         [6] -> [self decodeCmapFmtTable6: entry].
> +                       [12] -> [self decodeCmapFmtTable12: entry].
>                 } otherwise: [
>                         Transcript showln: '[TTFontReader] Unsupported
> encoding of cmap: ', cmapFmt.
>                         {nil.nil}]!
>
> Item was changed:
>   ----- Method: TTFontReader>>processCharMap: (in category 'processing -
> support') -----
>   processCharMap: mappingTables
>         "Process the given character map. Prefer Unicode mappings"
> +       "According to
> https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6cmap.html
> +       we should not only prefer Unicode cmaps, but should prioritize
> cmaps not restricted to BMP. Therefore
> +       if there are multiple Unicode maps we need to select the first
> best option"
>
> +       "^ mappingTables
> -       ^ mappingTables
>                 detect: [:ea | ea isUnicode]
>                 ifFound: [:table | table map: glyphs]
> +               ifNone: [mappingTables last map: glyphs]"
> +
> +       | unicode result |
> +       unicode := mappingTables select: [ :cmap | cmap isUnicode ].
> +       unicode size = 1 ifTrue: [ ^ unicode first map: glyphs ].
> +       unicode size = 0 ifTrue: [ ^ mappingTables last map: glyphs ].
> +
> +       "Otherwise, we have multiple Unicode maps. In lieu of selecting
> +       the one not restricted to BMP, we pick the one with the largest
> +       character range. There might be a better way to handle this."
> +       result := unicode first.
> +       unicode do: [ :cmap |
> +               cmap characterMap size > result characterMap size
> +                       ifTrue: [ result := cmap]].
> +       ^ result map: glyphs!
> -               ifNone: [mappingTables last map: glyphs]!
>
>
>

-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220208/5f913b7c/attachment-0001.html>


More information about the Squeak-dev mailing list