Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tweaks so that font subsetting works with unicode-8bit subsets

Specifically, always explicitly include glyph 0 in the subset
at glyph index 0, and never assign characters to codes less
than 32 (PDF doesn't, apparently, like that).
  • Loading branch information...
commit 62c766b039b238309a0ed7fa252aa0250e0789f2 1 parent 4c9f18c
Jamis Buck authored January 02, 2009
9  lib/ttfunk/subset/base.rb
... ...
@@ -1,10 +1,13 @@
1 1
 require 'ttfunk/table/cmap'
2 2
 require 'ttfunk/table/glyf'
  3
+require 'ttfunk/table/head'
  4
+require 'ttfunk/table/hhea'
3 5
 require 'ttfunk/table/hmtx'
4 6
 require 'ttfunk/table/kern'
5 7
 require 'ttfunk/table/loca'
6  
-require 'ttfunk/encoding/mac_roman'
7  
-require 'ttfunk/encoding/windows_1252'
  8
+require 'ttfunk/table/maxp'
  9
+require 'ttfunk/table/name'
  10
+require 'ttfunk/table/post'
8 11
 
9 12
 module TTFunk
10 13
   module Subset
@@ -19,7 +22,7 @@ def encode(options={})
19 22
         cmap_table = new_cmap_table(options)
20 23
         glyphs = collect_glyphs(original_glyph_ids)
21 24
 
22  
-        old2new_glyph = cmap_table[:charmap].inject({}) { |map, (code, ids)| map[ids[:old]] = ids[:new]; map }
  25
+        old2new_glyph = cmap_table[:charmap].inject({ 0 => 0 }) { |map, (code, ids)| map[ids[:old]] = ids[:new]; map }
23 26
         next_glyph_id = cmap_table[:max_glyph_id]
24 27
 
25 28
         glyphs.keys.each do |old_id|
4  lib/ttfunk/subset/unicode_8bit.rb
@@ -8,14 +8,14 @@ def initialize(original)
8 8
         super
9 9
         @subset = { 0x20 => 0x20 }
10 10
         @unicodes = { 0x20 => 0x20 }
11  
-        @next = 0
  11
+        @next = 0x21 # apparently, PDF's don't like to use chars between 0-31
12 12
       end
13 13
 
14 14
       def use(character)
15 15
         if !@unicodes.key?(character)
16 16
           @subset[@next] = character
17 17
           @unicodes[character] = @next
18  
-          @next += 1 while @subset[@next]
  18
+          @next += 1
19 19
         end
20 20
       end
21 21
 

0 notes on commit 62c766b

Please sign in to comment.
Something went wrong with that request. Please try again.