Skip to content

Instantly share code, notes, and snippets.

@znz
Created November 24, 2009 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save znz/241850 to your computer and use it in GitHub Desktop.
Save znz/241850 to your computer and use it in GitHub Desktop.
unset isFixedPitch for otf-ipafont
#!/usr/bin/ruby -Kn
# http://www.microsoft.com/typography/otspec/
# http://www.microsoft.com/typography/otspec/otff.htm
# http://www.microsoft.com/typography/otspec/post.htm
def dp(*args)
p(*args) if $DEBUG
end
filename = ARGV.shift || 'ipam.otf'
otf = open(filename, 'rb')
sfnt_version = otf.read(4)
dp sfnt_version
raise unless sfnt_version == "\0\1\0\0"
ushort = proc { otf.read(2).unpack("n")[0] }
ulong = proc { otf.read(4).unpack('N')[0] }
fword = proc { otf.read(2).unpack("s")[0] }
numTables = ushort.call
dp [:numTables, numTables]
dp [:searchRange, ushort.call]
dp [:entrySelector, ushort.call]
dp [:rangeShift, ushort.call]
post_check_sum = nil
post_check_sum_pos = nil
post_offset = nil
numTables.times do
tag = otf.read(4)
check_sum_pos = otf.pos
checkSum = ulong.call
offset = ulong.call
length = ulong.call
dp [tag, checkSum, offset, length]
if tag == "post"
post_offset = offset
post_check_sum = checkSum
post_check_sum_pos = check_sum_pos
end
end
otf.seek(post_offset, IO::SEEK_SET)
dp [:Version, otf.read(4)]
dp [:italicAngle, otf.read(4)]
dp [:underlinePosition, fword.call]
dp [:underlineThickness, fword.call]
is_fixed_pitch_pos = otf.pos
isFixedPitch = ulong.call
dp [:isFixedPitch, isFixedPitch]
raise "already isFixedPitch != 1" unless isFixedPitch == 1
system("cp", filename, "out.otf")
open("out.otf", "r+b") do |o|
o.seek(is_fixed_pitch_pos, IO::SEEK_SET)
o.write [0].pack("N")
o.seek(post_check_sum_pos, IO::SEEK_SET)
o.write [post_check_sum-1].pack("N")
dp [post_check_sum, post_check_sum_pos]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment