hierogloss 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Hierogloss
4
+ # :nodoc: Internal utilities for measuring hieroglyphs for layout
5
+ # purposes.
6
+ class Metrics
7
+ # The nominal size of a quadrat relative to Data::SIGN_SIZES.
8
+ QUADRAT_DATA_SIZE = 0.55
9
+
10
+ # The nominal size of a quadrat in our API units.
11
+ QUADRAT_SIZE = 12
12
+
13
+ # A conversion factor.
14
+ QUADRAT_CONV = QUADRAT_SIZE / QUADRAT_DATA_SIZE
15
+
16
+ class << self
17
+ def find(char)
18
+ size = Data::SIGN_SIZES[char]
19
+ new(conv(size[0]),conv(size[1]))
20
+ end
21
+
22
+ protected
23
+
24
+ # Round things to reasonable sizes. This is ad hoc and will require
25
+ # extensive adjustment.
26
+ def conv(x)
27
+ rounded = (x*QUADRAT_CONV).round
28
+ case rounded
29
+ when 1..4 then 3
30
+ when 5..7 then 6
31
+ when 8..9 then 9
32
+ when 10..14 then 12
33
+ else rounded
34
+ end
35
+ end
36
+ end
37
+
38
+ attr_reader :width, :height
39
+
40
+ def initialize(width, height)
41
+ @width = width
42
+ @height = height
43
+ end
44
+ end
45
+ end
46
+
47
+ require "hierogloss/metrics/data"
@@ -1,3 +1,3 @@
1
1
  module Hierogloss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/hierogloss.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'kramdown'
2
2
  require "hierogloss/version"
3
3
  require "hierogloss/dictionary"
4
+ require "hierogloss/metrics"
5
+ require "hierogloss/mdc"
4
6
  require "hierogloss/gloss"
5
7
  require "kramdown/parser/hierogloss"
6
8
  require "kramdown/converter/bbcode"
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ # Requires ttfunk 1.1 to operate, which conflicts with the
5
+ # currently-released version of prawn.
6
+
7
+ require "ttfunk"
8
+
9
+ def metrics(file, codepoint)
10
+ glyph_id = file.cmap.unicode.first[codepoint]
11
+ return nil if glyph_id == 0
12
+ glyph = file.glyph_outlines.for(glyph_id)
13
+ [codepoint, glyph.x_max-glyph.x_min, glyph.y_max-glyph.y_min]
14
+ end
15
+
16
+ f = TTFunk::File.open(File.join(File.dirname(__FILE__), 'Gardiner.ttf'))
17
+
18
+ metrics = (0x13000..0x1342F).map {|cp| metrics(f, cp) }.compact
19
+ max_width = metrics.map {|m| m[1] }.max
20
+ max_height = metrics.map {|m| m[2] }.max
21
+ unit = 1.0*([max_width, max_height].max)
22
+
23
+ print <<EOD
24
+ # -*- coding: utf-8 -*-
25
+
26
+ # :nodoc: This file is generated automatically using dump_metrics.rb.
27
+ # It contains the relative width and height of each sign in the Gardiner.ttf
28
+ # font for use in layout algorithms.
29
+ module Hierogloss
30
+ class Metrics
31
+ module Data
32
+ SIGN_SIZES = {
33
+ EOD
34
+
35
+ metrics.each do |cp, w, h|
36
+ c = [cp].pack("U")
37
+ printf "\"%s\"=>[%0.2f,%0.2f],\n", c, w/unit, h/unit
38
+ end
39
+
40
+ print <<EOD
41
+ }
42
+ end
43
+ end
44
+ end
45
+ EOD
@@ -37,14 +37,7 @@ class TestDictionary < Minitest::Test
37
37
  end
38
38
 
39
39
  def test_should_provide_gardiner_signs_for_most_signs
40
- assert_equal("A1", Hierogloss::Dictionary.gardiner("𓀀"))
41
- assert_equal("D4", Hierogloss::Dictionary.gardiner("𓁹"))
42
- end
43
-
44
- def test_should_not_provide_gardiner_signs_for_uniliterals
45
- # Let's not link these common characters.
46
- "𓄿𓇋𓏭𓂝𓅱𓏲𓃀𓊪𓆑𓅓𓈖𓂋𓉔𓎛𓐍𓄡𓊃𓋴𓈙𓈎𓎡𓎼𓏏𓍿𓂧𓆓".each_char do |c|
47
- assert_nil(Hierogloss::Dictionary.gardiner(c), "should not translate #{c}")
48
- end
40
+ assert_equal("A1", Hierogloss::Dictionary.sign_to_gardiner("𓀀"))
41
+ assert_equal("D4", Hierogloss::Dictionary.sign_to_gardiner("𓁹"))
49
42
  end
50
43
  end
data/test/test_gloss.rb CHANGED
@@ -6,7 +6,7 @@ class TestGloss < MiniTest::Test
6
6
 
7
7
  def setup
8
8
  input = <<EOD
9
- H: 𓊃𓀀𓏤 | 𓊃𓏏𓁐
9
+ H: 𓊃:𓀀*𓏤 | z:t*B1
10
10
  L: s | s.t
11
11
  G: homme | femme
12
12
  T: l'homme et la femme
@@ -22,7 +22,9 @@ EOD
22
22
 
23
23
  def test_should_parse_gloss_into_appropriate_rows
24
24
  assert_equal(4, @gloss.rows.length)
25
- assert_row(HieroglyphRow, ["𓊃𓀀𓏤", "𓊃𓏏𓁐"], @gloss.rows[0])
25
+ assert_row(HieroglyphRow, ["𓊃:𓀀*𓏤", "z:t*B1"], @gloss.rows[0])
26
+ assert_equal(["𓊃𓀀𓏤", "𓊃𓏏𓁐"],
27
+ @gloss.rows[0].cells.map {|c| c.to_linear_hieroglyphs })
26
28
  assert_row(TransliterationRow, ["s", "s.t"], @gloss.rows[1])
27
29
  assert_row(Row, ["homme", "femme"], @gloss.rows[2])
28
30
 
data/test/test_mdc.rb ADDED
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest_helper'
3
+
4
+ class TestCodage < MiniTest::Test
5
+ def assert_parse(expected, input)
6
+ assert_equal(expected, Hierogloss::MdC.parse(input).to_debug)
7
+ end
8
+
9
+ def test_should_parse_separated_signs
10
+ assert_parse(["i"], "i")
11
+ assert_parse(["i", "A2"], "i-A2")
12
+ assert_parse(["i", "A2"], "i A2")
13
+ assert_parse(["i", "A2"], "i A2")
14
+ assert_parse(["i", "A2"], "i_A2")
15
+ assert_parse(["i", "A2"], "i__A2")
16
+ # A non-standard extension, but I rather like using a proper input
17
+ # method to type hieroglyphs.
18
+ assert_parse(["𓇋", "𓀁"], "𓇋𓀁")
19
+ end
20
+
21
+ def test_should_parse_stacked_signs
22
+ assert_parse([[:stack, "D", "d"], "n"], "D:d-n")
23
+ assert_parse([[:stack, "D", "d", "n"]], "D:d:n")
24
+ assert_parse([[:stack, "𓆓", "𓂧"], "𓈖"], "𓆓:𓂧𓈖")
25
+ assert_parse([[:stack, "𓆓", "𓂧", "𓈖"]], "𓆓:𓂧:𓈖")
26
+ end
27
+
28
+ def test_should_parse_juxtaposed_signs
29
+ assert_parse([[:stack, "𓇾", ["𓏤", "𓈇"]]], "𓇾:𓏤*𓈇")
30
+ end
31
+
32
+ def test_should_honor_parens
33
+ assert_parse([[:stack, ["p", [:stack, "t", "Z4"]], "pt"]], "p*(t:Z4):pt")
34
+ end
35
+
36
+ def assert_linear_hieroglyphs(expected, input)
37
+ assert_equal(expected, Hierogloss::MdC.parse(input).to_linear_hieroglyphs)
38
+ end
39
+
40
+ def test_should_convert_mdc_to_linear_hieroglyphs
41
+ assert_linear_hieroglyphs("𓆓𓂧𓈖", "𓆓:𓂧𓈖")
42
+ assert_linear_hieroglyphs("𓊪𓏏𓏭𓇯", "p*(t:Z4):pt")
43
+ end
44
+
45
+ def assert_mdc(expected, input)
46
+ assert_equal(expected, Hierogloss::MdC.parse(input).to_mdc)
47
+ end
48
+
49
+ def test_should_convert_mdc_to_mdc_string
50
+ assert_mdc("D:d-n", "𓆓:𓂧𓈖")
51
+ assert_mdc("p*(t:Z4):pt", "p*(t:Z4):pt")
52
+ # Compound signs are always placed in parens.
53
+ assert_mdc("(N33*N33:N33*N33)", "𓃌")
54
+ end
55
+ end
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest_helper'
3
+
4
+ class TestMetrics < MiniTest::Test
5
+ # For our purposes, an ordinary quadrat is 12 units by 12 units, mostly
6
+ # because this allows us to use most small fractions (1/1 through 1/4)
7
+ # easily.
8
+ def assert_metrics(width, height, char)
9
+ m = Hierogloss::Metrics.find(char)
10
+ assert_equal width, m.width, "Expected width of #{char} to be #{width}"
11
+ assert_equal height, m.height, "Expected hieght of #{char} to be #{height}"
12
+ end
13
+
14
+ def test_signs_should_have_plausible_metrics
15
+ # These numbers are a bit arbitrary. They're based on my
16
+ # interpretation of common hieroglyphic layouts and the sizes of the
17
+ # signs extracted from the Gardiner font. The idea is that anything
18
+ # adding up to 12x12 should make a nice square quadrat without any
19
+ # further scaling. The ultimate answer here, of course, is whatever
20
+ # looks good.
21
+ assert_metrics(9, 12, "𓀀")
22
+ assert_metrics(6, 12, "𓁐")
23
+ assert_metrics(3, 12, "𓋴")
24
+ assert_metrics(12, 3, "𓈖")
25
+ assert_metrics(12, 3, "𓆑")
26
+ assert_metrics(12, 6, "𓂧")
27
+ assert_metrics(12, 12, "𓆓")
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hierogloss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kidd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: parslet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: prawn
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -115,16 +129,22 @@ files:
115
129
  - lib/hierogloss.rb
116
130
  - lib/hierogloss/dictionary.rb
117
131
  - lib/hierogloss/gloss.rb
132
+ - lib/hierogloss/mdc.rb
133
+ - lib/hierogloss/metrics.rb
134
+ - lib/hierogloss/metrics/data.rb
118
135
  - lib/hierogloss/version.rb
119
136
  - lib/kramdown/converter/bbcode.rb
120
137
  - lib/kramdown/converter/htlal.rb
121
138
  - lib/kramdown/parser/hierogloss.rb
122
139
  - src/Gardiner.ttf
140
+ - src/dump_metrics.rb
123
141
  - test/minitest_helper.rb
124
142
  - test/test_dictionary.rb
125
143
  - test/test_gloss.rb
126
144
  - test/test_hierogloss.rb
127
145
  - test/test_kramdown_extensions.rb
146
+ - test/test_mdc.rb
147
+ - test/test_metrics.rb
128
148
  homepage: https://github.com/emk/hierogloss
129
149
  licenses:
130
150
  - Public domain + other open source licenses
@@ -155,3 +175,5 @@ test_files:
155
175
  - test/test_gloss.rb
156
176
  - test/test_hierogloss.rb
157
177
  - test/test_kramdown_extensions.rb
178
+ - test/test_mdc.rb
179
+ - test/test_metrics.rb