ttfunk icon indicating copy to clipboard operation
ttfunk copied to clipboard

cmap.unicode doesn't work for symbol fonts

Open graza opened this issue 12 years ago • 7 comments

When getting the Unicode character map from the cmap table list, TTFunk only allows a value of 1 for "encoding_id" (which seems to equate to language code although I'm not sure).

According to Apple's spec for the cmap table the language code in Format 4 can be 0 for language independent fonts. This seems to be the case for Microsoft's symbol fonts (Webdings and Wingdings*).

So I think the unicode? method of subtable should allow encoding_id of 1 or 0. Currently symbol fonts' unicode character mapping can't be used. This is preventing me from outputting symbols to PDFs generated by Prawn, even though there's a Unicode mapping to the glyphs.

require 'ttfunk'
cmap = TTFunk::File.open("Webdings.ttf").cmap

cmap.tables[1].platform_id # => 3
cmap.tables[1].encoding_id # => 0
cmap.tables[1].format $ => 4
cmap.unicode # => []

graza avatar Feb 13 '12 16:02 graza

Hi, can you submit a pull request, and then give an example that shows it works as expected? Happy to consider a patch if you send one in.

Sorry for the very long delay, Prawn (and its dependencies) went through a period of inactivity, but we're back actively working on things now!

practicingruby avatar Jan 21 '14 02:01 practicingruby

Yes, for fsymbols.org/css/AndroidEmoji.ttf

require 'ttfunk'

file = TTFunk::File.open("AndroidEmoji.ttf")
cmap = file.cmap

chars = {}
unicode_chars = []

cmap.tables.each do |subtable|
  next if !subtable.unicode?
  chars = chars.merge( subtable.code_map )
end

unicode_chars = chars.keys.map{ |dec| dec.to_s(16) }

puts "\n -- Found #{unicode_chars.length} characters in this font \n\n"
p unicode_chars
p file.name.font_name

outputs

 -- Found 156 characters in this font 

["0", "d", "20", "23", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "a0", "a9", "ae", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "200a", "200b", "203c", "2049", "20e3", "2122", "2139", "2194", "2195", "2196", "2197", "2198", "2199", "21a9", "21aa", "231a", "231b", "23e9", "23ea", "23eb", "23ec", "23f0", "23f3", "24c2", "25aa", "25ab", "25b6", "25c0", "25ca", "25fb", "25fc", "25fd", "25fe", "2600", "2601", "263a", "2648", "2649", "264a", "264b", "264c", "264d", "264e", "264f", "2650", "2651", "2652", "2653", "2660", "2663", "2665", "2666", "2668", "267b", "267f", "2693", "26a0", "26a1", "26aa", "26ab", "26bd", "26be", "26c4", "26c5", "26ce", "26d4", "26ea", "26f2", "26f3", "26f5", "26fa", "26fd", "2702", "2705", "2708", "2709", "270a", "270b", "270c", "270f", "2712", "2714", "2716", "2728", "2733", "2734", "2744", "2747", "274c", "274e", "2753", "2754", "2755", "2757", "2764", "2795", "2796", "2797", "27a1", "27b0", "27bf", "2934", "2935", "2b05", "2b06", "2b07", "2b1b", "2b1c", "2b50", "2b55", "3030", "303d", "3297", "3299", "e023", "e030", "e031", "e032", "e033", "e034", "e035", "e036", "e037", "e038", "e039", "feff", "fffc", "fffd", "ffff"]
["Android Emoji", "\x00A\x00n\x00d\x00r\x00o\x00i\x00d\x00 \x00E\x00m\x00o\x00j\x00i"]

The tool definitely can't see Emoji.

ibmua avatar May 24 '15 14:05 ibmua

@ibmua Can you provide a link so we can download the font file itself to reproduce the error?

packetmonkey avatar Jul 29 '15 19:07 packetmonkey

I did.

ibmua avatar Jul 29 '15 19:07 ibmua

My apologies, I didn't see the url in the text, I was looking for a clickable URL.

I have a situation coming that may need better emoji support so hopefully I'll get a chance to look into this soon-ish.

Thanks again for the code snippets, it will help a lot!

packetmonkey avatar Jul 29 '15 19:07 packetmonkey

≥^.^≤

ibmua avatar Jul 29 '15 20:07 ibmua