Permalink
Browse files

Tweaks to make subsetting work in practice

It turns out that #use is not as useful as I predicted. Should just
merge that into #encode so it happens in a single pass.
  • Loading branch information...
1 parent 5d04018 commit b625caf9605ba4c0efbe9917ad992eb376d4fdcb @jamis jamis committed Jan 2, 2009
Showing with 19 additions and 6 deletions.
  1. +19 −6 lib/ttfunk/subset_collection.rb
@@ -7,6 +7,11 @@ def initialize(original)
@subsets = [Subset.for(@original, :mac_roman)]
end
+ def [](subset)
+ @subsets[subset]
+ end
+
+ # +characters+ should be an array of UTF-16 characters
def use(characters)
characters.each do |char|
covered = false
@@ -25,7 +30,19 @@ def use(characters)
end
end
- def convert_text(characters)
+ # +characters+ should be an array of UTF-16 characters. Returns
+ # an array of subset chunks, where each chunk is another array of
+ # two elements. The first element is the subset number, and the
+ # second element is the string of characters to render with that
+ # font subset. The strings will be encoded for their subset font,
+ # and so may not look (in the raw) like what was passed in, but
+ # they will render correctly with the indicated subset font.
+ def encode(characters)
+ # TODO: probably would be more optimal to nix the #use method,
+ # and merge it into this one, so it can be done in a single
+ # pass instead of two passes.
+ use(characters)
+
parts = []
current_subset = 0
current_char = 0
@@ -36,7 +53,7 @@ def convert_text(characters)
char = @subsets[current_subset].from_unicode(char)
if parts.empty? || parts.last[0] != current_subset
- parts << [current_subset, [char]]
+ parts << [current_subset, char.chr]
else
parts.last[1] << char
end
@@ -49,9 +66,5 @@ def convert_text(characters)
current_subset = (current_subset + 1) % @subsets.length
end
end
-
- def encode_subsets(options={})
- @subsets.map { |subset| subset.encode(options) }
- end
end
end

0 comments on commit b625caf

Please sign in to comment.