afm 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/afm.gemspec +2 -2
  3. data/lib/afm.rb +59 -1
  4. data/test/test_afm.rb +9 -0
  5. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{afm}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Krutisch"]
12
- s.date = %q{2010-09-29}
12
+ s.date = %q{2010-09-30}
13
13
  s.description = %q{a simple library to read afm files and use the data conveniently}
14
14
  s.email = %q{jan@krutisch.de}
15
15
  s.extra_rdoc_files = [
data/lib/afm.rb CHANGED
@@ -1,7 +1,40 @@
1
-
2
1
  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
+
3
34
  class Font
4
35
  attr_reader :metadata, :char_metrics, :kern_pairs
36
+
37
+ # Loading a Font Metrics file by absolute path (no automatic font path resolution)
5
38
  def initialize(filename)
6
39
  @metadata = {}
7
40
  @char_metrics = {}
@@ -41,5 +74,30 @@ module AFM
41
74
  end
42
75
  end
43
76
  end
77
+
78
+ #
79
+ # alias for new()
80
+ def self.from_file(file)
81
+ self.new(file)
82
+ end
83
+
84
+ #
85
+ # Get metadata by key
86
+ def [](key)
87
+ @metadata[key]
88
+ end
89
+ #
90
+ # Get metrics for character. Takes an integer (charcode) or
91
+ # a one-char string. currently works only for Latin1 strings,
92
+ # since we only have a chartable for the Latin1 charset so far.
93
+ # (shamelessly stolen from AFM.pm by Gisle Aas)
94
+ def metrics_for(char)
95
+ glyph = if (char.kind_of?(Integer))
96
+ ISO_LATIN1_ENCODING[char]
97
+ else
98
+ ISO_LATIN1_ENCODING[char[0]]
99
+ end
100
+ @char_metrics[glyph]
101
+ end
44
102
  end
45
103
  end
@@ -13,4 +13,13 @@ class TestAfm < Test::Unit::TestCase
13
13
  assert_equal 400, @font.char_metrics['exclam'][:wx]
14
14
  assert_equal [85, -131, 310, 758], @font.char_metrics['parenleft'][:boundingbox]
15
15
  end
16
+
17
+ should "get char metrics by char" do
18
+ assert_equal 400, @font.metrics_for("!")[:wx]
19
+ end
20
+
21
+ should "open font with alternative method" do
22
+ assert_not_nil AFM::Font.from_file(File.join(File.dirname(__FILE__), 'fixtures', 'Vera.afm'))
23
+ end
24
+
16
25
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Krutisch
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-29 00:00:00 +02:00
17
+ date: 2010-09-30 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency