1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
require 'spec_helper'
require 'ttfunk/table/vorg'
RSpec.describe TTFunk::Table::Vorg do
let(:font_path) { test_font('NotoSansCJKsc-Thin', :otf) }
let(:font) { TTFunk::File.open(font_path) }
let(:cmap) { font.cmap.unicode.first }
let(:vorg_table) { font.vertical_origins }
let(:origins) { vorg_table.origins }
describe '#origins' do
it 'includes origins for certain chars traditionally written vertically' do
code_points = %w[〱 0 1 2 3 4 5 6 7 8 9].map { |c| c.unpack1('U*') }
glyph_ids = code_points.map { |cp| cmap[cp] }
glyph_ids.each { |glyph_id| expect(origins).to include(glyph_id) }
end
end
describe '#for' do
it 'finds the vertical origin when explicitly available' do
glyph_id = cmap['〱'.unpack1('U*')]
expect(vorg_table.origins).to include(glyph_id)
expect(vorg_table.for(glyph_id)).to_not eq(vorg_table.default_vert_origin_y)
end
it 'falls back to the default vertical origin' do
glyph_id = cmap['ろ'.unpack1('U*')]
expect(vorg_table.origins).to_not include(glyph_id)
expect(vorg_table.for(glyph_id)).to eq(vorg_table.default_vert_origin_y)
end
end
describe '.encode' do
let(:encoded) { described_class.encode(vorg_table) }
let(:reconstituted) do
described_class.new(TestFile.new(StringIO.new(encoded)))
end
it 'includes all the same vertical origins' do
expect(reconstituted.origins.size).to eq(origins.size)
origins.each do |glyph_id, origin|
expect(reconstituted.origins[glyph_id]).to eq(origin)
end
end
it 'includes the same version information' do
expect(reconstituted.major_version).to eq(vorg_table.major_version)
expect(reconstituted.minor_version).to eq(vorg_table.minor_version)
end
it 'includes the same default vertical origin' do
expect(reconstituted.default_vert_origin_y).to eq(vorg_table.default_vert_origin_y)
end
end
end
|