Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Can't just invert the TO_UNICODE map to get FROM_UNICODE. Also, add S…

…ubset#includes?
  • Loading branch information...
commit 5e30ac32e53faa23085ca801894fb8f1d1709d66 1 parent 6fed25e
@jamis jamis authored
View
4 lib/ttfunk/encoding/mac_roman.rb
@@ -30,8 +30,8 @@ class MacRoman
0xFE => 0x02DB, 0xFF => 0x02C7
)
- FROM_UNICODE = Hash.new { |h,k| k > 0xFF ? nil : k }
- FROM_UNICODE.update(TO_UNICODE.invert)
+ FROM_UNICODE = {}
+ (0..255).each { |key| FROM_UNICODE[TO_UNICODE[key]] = key }
# Maps MacRoman codes to their corresponding index in the Postscript glyph
# table (see TTFunk::Table::Post::Format10). If any entry in this array is a string,
View
4 lib/ttfunk/encoding/windows_1252.rb
@@ -11,8 +11,8 @@ class Windows1252
0x9E => 0x017E, 0x9F => 0x0178
)
- FROM_UNICODE = Hash.new { |h,k| k > 0xFF ? nil : k }
- FROM_UNICODE.update(TO_UNICODE.invert)
+ FROM_UNICODE = {}
+ (0..255).each { |key| FROM_UNICODE[TO_UNICODE[key]] = key }
# Maps Windows-1252 codes to their corresponding index in the Postscript glyph
# table (see TTFunk::Table::Post::Format10). If any entry in this array is a string,
View
5 lib/ttfunk/subset/mac_roman.rb
@@ -18,6 +18,11 @@ def covers?(character)
Encoding::MacRoman.covers?(character)
end
+ def includes?(character)
+ code = Encoding::MacRoman::FROM_UNICODE[character]
+ code && @subset[code]
+ end
+
def from_unicode(character)
Encoding::MacRoman::FROM_UNICODE[character]
end
View
4 lib/ttfunk/subset/unicode.rb
@@ -17,6 +17,10 @@ def covers?(character)
true
end
+ def includes?(character)
+ @subset.includes(character)
+ end
+
def from_unicode(character)
character
end
View
4 lib/ttfunk/subset/unicode_8bit.rb
@@ -23,6 +23,10 @@ def covers?(character)
@unicodes.key?(character) || @next < 256
end
+ def includes?(character)
+ @unicodes.key?(character)
+ end
+
def from_unicode(character)
@unicodes[character]
end
View
5 lib/ttfunk/subset/windows_1252.rb
@@ -18,6 +18,11 @@ def covers?(character)
Encoding::Windows1252.covers?(character)
end
+ def includes?(character)
+ code = Encoding::Windows1252::FROM_UNICODE[character]
+ code && @subset[code]
+ end
+
def from_unicode(character)
Encoding::Windows1252::FROM_UNICODE[character]
end
Please sign in to comment.
Something went wrong with that request. Please try again.