Skip to content

Commit 00d6d6a

Browse files
committed
Prepare 1.0.0 release
- modernizing everything - adding github actions - test against modern ruby versions
1 parent ffb006c commit 00d6d6a

9 files changed

Lines changed: 133 additions & 106 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
ruby-version: ['3.2', '3.3', '3.4', 'head']
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: ${{ matrix.ruby-version }}
26+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27+
- name: Run tests
28+
run: bundle exec rake

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
## 1.0.0
2+
3+
There are no functional changes to 0.2.2 in this release, it is just a quick
4+
update to make sure it still runs on modern rubies and add modern tooling
5+
6+
* [chore] Add GitHub actions instead of travis (chuckle)
7+
* [chore] Set required ruby version to last maintained version
8+
* [chore] update dependencies
9+
* [chore] modernize gemspec
10+
* [chore] formatting all ruby files to modernish standards
11+
112
## 0.2.2
213

3-
* The gem was missing
14+
* The gem was missing
415

516
## 0.2.1
617

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
require 'rubygems'
2-
require 'bundler/setup'
3-
require 'rake'
1+
require "rubygems"
2+
require "bundler/setup"
3+
require "rake"
44

5-
require 'rake/testtask'
5+
require "rake/testtask"
66
Rake::TestTask.new(:test) do |test|
7-
test.libs << 'lib' << 'test'
8-
test.pattern = 'test/**/test_*.rb'
7+
test.libs << "lib" << "test"
8+
test.pattern = "test/**/test_*.rb"
99
test.verbose = true
1010
end
1111

12-
task :default => :test
12+
task default: :test
1313

14-
require 'rdoc/task'
14+
require "rdoc/task"
1515

1616
RDoc::Task.new do |rdoc|
17-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
17+
version = File.exist?("VERSION") ? File.read("VERSION") : ""
1818

19-
rdoc.rdoc_dir = 'rdoc'
19+
rdoc.rdoc_dir = "rdoc"
2020
rdoc.title = "afm #{version}"
21-
rdoc.rdoc_files.include('README*')
22-
rdoc.rdoc_files.include('lib/**/*.rb')
21+
rdoc.rdoc_files.include("README*")
22+
rdoc.rdoc_files.include("lib/**/*.rb")
2323
end

afm.gemspec

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
require 'rake'
1+
require "rake"
22
Gem::Specification.new do |s|
3-
s.name = %q{afm}
4-
s.version = File.read('VERSION')
5-
6-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
3+
s.name = "afm"
4+
s.version = File.read("VERSION")
75
s.authors = ["Jan Krutisch"]
8-
s.date = %q{2014-06-19}
9-
s.description = %q{a simple library to read afm files and use the data conveniently}
10-
s.email = %q{jan@krutisch.de}
6+
s.summary = "reading Adobe Font Metrics (afm) files"
7+
s.description = "a simple library to read afm files and use the data conveniently"
8+
s.email = "jan@krutisch.de"
119
s.extra_rdoc_files = [
1210
"LICENSE",
1311
"README.rdoc"
@@ -22,14 +20,10 @@ Gem::Specification.new do |s|
2220
"test/*",
2321
"test/fixtures/*"
2422
]
25-
s.homepage = %q{http://github.com/halfbyte/afm}
23+
s.homepage = "http://github.com/halfbyte/afm"
2624
s.require_paths = ["lib"]
27-
s.rubygems_version = %q{1.6.2}
28-
s.summary = %q{reading Adobe Font Metrics (afm) files}
2925
s.license = "MIT"
30-
s.add_development_dependency "rake", "~> 10.3"
31-
s.add_development_dependency "rdoc", "~> 4.1"
32-
s.add_development_dependency "minitest", "~> 5.3"
33-
26+
s.add_development_dependency "rake", "~> 13.3"
27+
s.add_development_dependency "rdoc", "~> 6.14"
28+
s.add_development_dependency "minitest", "~> 5.25"
3429
end
35-

lib/afm.rb

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
module AFM
2-
3-
ISO_LATIN1_ENCODING = %w(
4-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
5-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
7-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef space
8-
exclam quotedbl numbersign dollar percent ampersand quoteright
9-
parenleft parenright asterisk plus comma minus period slash zero one
10-
two three four five six seven eight nine colon semicolon less equal
11-
greater question at A B C D E F G H I J K L M N O P Q R S
12-
T U V W X Y Z bracketleft backslash bracketright asciicircum
13-
underscore quoteleft a b c d e f g h i j k l m n o p q r s
14-
t u v w x y z braceleft bar braceright asciitilde .notdef .notdef
15-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
16-
.notdef .notdef .notdef .notdef .notdef .notdef .notdef dotlessi grave
17-
acute circumflex tilde macron breve dotaccent dieresis .notdef ring
18-
cedilla .notdef hungarumlaut ogonek caron space exclamdown cent
19-
sterling currency yen brokenbar section dieresis copyright ordfeminine
20-
guillemotleft logicalnot hyphen registered macron degree plusminus
21-
twosuperior threesuperior acute mu paragraph periodcentered cedilla
22-
onesuperior ordmasculine guillemotright onequarter onehalf threequarters
23-
questiondown Agrave Aacute Acircumflex Atilde Adieresis Aring AE
24-
Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex
25-
Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis
26-
multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn
27-
germandbls agrave aacute acircumflex atilde adieresis aring ae
28-
ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex
29-
idieresis eth ntilde ograve oacute ocircumflex otilde odieresis divide
30-
oslash ugrave uacute ucircumflex udieresis yacute thorn ydieresis
31-
)
32-
33-
2+
ISO_LATIN1_ENCODING = %w[
3+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
4+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
5+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
6+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef space
7+
exclam quotedbl numbersign dollar percent ampersand quoteright
8+
parenleft parenright asterisk plus comma minus period slash zero one
9+
two three four five six seven eight nine colon semicolon less equal
10+
greater question at A B C D E F G H I J K L M N O P Q R S
11+
T U V W X Y Z bracketleft backslash bracketright asciicircum
12+
underscore quoteleft a b c d e f g h i j k l m n o p q r s
13+
t u v w x y z braceleft bar braceright asciitilde .notdef .notdef
14+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef .notdef
15+
.notdef .notdef .notdef .notdef .notdef .notdef .notdef dotlessi grave
16+
acute circumflex tilde macron breve dotaccent dieresis .notdef ring
17+
cedilla .notdef hungarumlaut ogonek caron space exclamdown cent
18+
sterling currency yen brokenbar section dieresis copyright ordfeminine
19+
guillemotleft logicalnot hyphen registered macron degree plusminus
20+
twosuperior threesuperior acute mu paragraph periodcentered cedilla
21+
onesuperior ordmasculine guillemotright onequarter onehalf threequarters
22+
questiondown Agrave Aacute Acircumflex Atilde Adieresis Aring AE
23+
Ccedilla Egrave Eacute Ecircumflex Edieresis Igrave Iacute Icircumflex
24+
Idieresis Eth Ntilde Ograve Oacute Ocircumflex Otilde Odieresis
25+
multiply Oslash Ugrave Uacute Ucircumflex Udieresis Yacute Thorn
26+
germandbls agrave aacute acircumflex atilde adieresis aring ae
27+
ccedilla egrave eacute ecircumflex edieresis igrave iacute icircumflex
28+
idieresis eth ntilde ograve oacute ocircumflex otilde odieresis divide
29+
oslash ugrave uacute ucircumflex udieresis yacute thorn ydieresis
30+
]
31+
3432
class Font
3533
attr_reader :metadata, :char_metrics, :char_metrics_by_code, :kern_pairs
36-
34+
3735
# Loading a Font Metrics file by absolute path (no automatic font path resolution)
3836
def initialize(filename)
3937
@metadata = {}
@@ -43,61 +41,62 @@ def initialize(filename)
4341
File.open(filename) do |file|
4442
mode = :meta
4543
file.each_line do |line|
46-
case(line)
47-
when /^StartFontMetrics/ ; mode = :meta
48-
when /^StartCharMetrics/ ; mode = :char_metrics
49-
when /^EndCharMetrics/ ; mode = :meta
50-
when /^StartKernData/ ; mode = :kern_data
51-
when /^StartKernPairs/ ; mode = :kern_pairs
52-
when /^EndKernPairs/ ; mode = :kern_data
53-
when /^EndKernData/ ; mode = :meta
44+
case line
45+
when /^StartFontMetrics/ then mode = :meta
46+
when /^StartCharMetrics/ then mode = :char_metrics
47+
when /^EndCharMetrics/ then mode = :meta
48+
when /^StartKernData/ then mode = :kern_data
49+
when /^StartKernPairs/ then mode = :kern_pairs
50+
when /^EndKernPairs/ then mode = :kern_data
51+
when /^EndKernData/ then mode = :meta
5452
else
55-
case(mode)
53+
case mode
5654
when :meta
57-
if match = line.match(/^([\w]+) (.*)$/)
55+
if (match = line.match(/^([\w]+) (.*)$/))
5856
@metadata[match[1]] = match[2]
5957
end
6058
when :char_metrics
6159
metrics = {}
62-
metrics[:charcode] = match[1].to_i if match = line.match(/C (-?\d+) *?;/)
63-
metrics[:wx] = match[1].to_i if match = line.match(/WX (-?\d+) *?;/)
64-
metrics[:name] = match[1] if match = line.match(/N ([.\w]+) *?;/)
65-
if match = line.match(/B (-?\d+) (-?\d+) (-?\d+) (-?\d+) *?;/)
66-
metrics[:boundingbox] = [match[1].to_i, match[2].to_i, match[3].to_i, match[4].to_i]
60+
metrics[:charcode] = match[1].to_i if (match = line.match(/C (-?\d+) *?;/))
61+
metrics[:wx] = match[1].to_i if (match = line.match(/WX (-?\d+) *?;/))
62+
metrics[:name] = match[1] if (match = line.match(/N ([.\w]+) *?;/))
63+
if (match = line.match(/B (-?\d+) (-?\d+) (-?\d+) (-?\d+) *?;/))
64+
metrics[:boundingbox] = [match[1].to_i, match[2].to_i, match[3].to_i, match[4].to_i]
6765
end
6866
@char_metrics[metrics[:name]] = metrics if metrics[:name]
6967
@char_metrics_by_code[metrics[:charcode]] = metrics if metrics[:charcode] && metrics[:charcode] > 0
7068
when :kern_pairs
71-
if match = line.match(/^KPX ([.\w]+) ([.\w]+) (-?\d+)$/)
69+
if (match = line.match(/^KPX ([.\w]+) ([.\w]+) (-?\d+)$/))
7270
@kern_pairs << [match[1], match[2], match[3].to_i]
7371
end
7472
end
7573
end
7674
end
7775
end
7876
end
79-
80-
#
77+
78+
#
8179
# alias for new()
8280
def self.from_file(file)
83-
self.new(file)
81+
new(file)
8482
end
85-
83+
8684
#
8785
# Get metadata by key
8886
def [](key)
8987
@metadata[key]
9088
end
89+
9190
#
9291
# Get metrics for character. Takes an integer (charcode) or
9392
# a one-char string. currently works only for Latin1 strings,
9493
# since we only have a chartable for the Latin1 charset so far.
9594
# (shamelessly stolen from AFM.pm by Gisle Aas)
9695
def metrics_for(char)
97-
glyph = if (char.kind_of?(Integer))
96+
glyph = if char.is_a?(Integer)
9897
ISO_LATIN1_ENCODING[char]
9998
else
100-
ISO_LATIN1_ENCODING[char.unpack("C*").first]
99+
ISO_LATIN1_ENCODING[char.unpack1("C")]
101100
end
102101
@char_metrics[glyph]
103102
end

mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
ruby = "3.4.2"

test/helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'rubygems'
2-
require 'bundler/setup'
3-
require 'minitest/autorun'
4-
require 'afm'
1+
require "rubygems"
2+
require "bundler/setup"
3+
require "minitest/autorun"
4+
require "afm"

test/test_afm.rb

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
require 'helper'
1+
require "helper"
22

33
class TestAfm < Minitest::Test
4-
54
def setup
6-
@font = AFM::Font.new(File.join(File.dirname(__FILE__), 'fixtures', 'Vera.afm'))
7-
end
8-
5+
@font = AFM::Font.new(File.join(File.dirname(__FILE__), "fixtures", "Vera.afm"))
6+
end
7+
98
def test_should_set_metadata
10-
assert_equal "BitstreamVeraSans-Roman", @font.metadata['FontName']
11-
assert_equal "BitstreamVeraSans-Roman", @font['FontName']
9+
assert_equal "BitstreamVeraSans-Roman", @font.metadata["FontName"]
10+
assert_equal "BitstreamVeraSans-Roman", @font["FontName"]
1211
end
1312

1413
def test_should_set_char_metrics
15-
assert_equal 400, @font.char_metrics['exclam'][:wx]
16-
assert_equal [85, -131, 310, 758], @font.char_metrics['parenleft'][:boundingbox]
14+
assert_equal 400, @font.char_metrics["exclam"][:wx]
15+
assert_equal [85, -131, 310, 758], @font.char_metrics["parenleft"][:boundingbox]
1716
end
1817

1918
def test_should_set_char_metrics_by_code
2019
assert_equal 400, @font.char_metrics_by_code[33][:wx]
2120
assert_equal [85, -131, 310, 758], @font.char_metrics_by_code[40][:boundingbox]
2221
end
23-
22+
2423
def test_should_get_char_metrics_by_char
2524
assert_equal 400, @font.metrics_for("!")[:wx]
2625
end
27-
26+
2827
def test_open_font_with_alternative_method
29-
assert !AFM::Font.from_file(File.join(File.dirname(__FILE__), 'fixtures', 'Vera.afm')).nil?
28+
assert !AFM::Font.from_file(File.join(File.dirname(__FILE__), "fixtures", "Vera.afm")).nil?
3029
end
31-
3230
end

0 commit comments

Comments
 (0)