indie-raster 0.0.8 → 0.0.9

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.
Binary file
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ ! " # $ % & ( ) *
2
+ + , - . / 0 1 2 3 4
3
+ 5 6 7 8 9 : ; < = >
4
+ ? @ A B C D E F G H
5
+ I J K L M N O P Q R
6
+ S T U V W X Y Z [ \
7
+ ] ^ _ ` a b c d e f
8
+ g h i j k l m n o p
9
+ q r s t u v w x y z
10
+ { | } ~ ¡ ¢ £ ¤ ¥ ¦
11
+ § ¨ © ª « ¬ ® ¯ ° ±
12
+ ² ³ ´ µ ¶ · ¸ ¹ º »
13
+ ¼ ½ ¾ ¿ À Á Â Ã Ä Å
14
+ Æ Ç È É Ê Ë Ì Í Î Ï
15
+ Ð Ñ Ò Ó Ô Õ Ö × Ø Ù
16
+ Ú Û Ü Ý Þ ß à á â ã
17
+ ä å æ ç è é ê ë ì í
18
+ î ï ð ñ ò ó ô õ ö ÷
19
+ ø ù ú û ü ý þ ÿ – —
20
+ ‘ ’ ‚ “ ” „ • ‹ ›
21
+
Binary file
Binary file
Binary file
Binary file
data/fonts/make-fonts.sh CHANGED
@@ -2,19 +2,23 @@
2
2
 
3
3
  cd scripts;
4
4
 
5
-
6
5
  # dsm-56-bold-inverted
7
- bash splitter.sh ../glyphs/dsm-56-bold-inverted.png 34 56 4 20 21 199 10
6
+ bash splitter.sh ../glyphs/dsm-56-bold-inverted.png 34 56 4 20 34 21 199 10
8
7
  coffee pack-font.coffee --chars=../fonts_vector/dsm/chars-all.json > ../fonts_prf1/dsm-56-bold-inverted.prf1
9
8
 
9
+ # dsm-24-bold-inverted
10
+ bash splitter.sh ../glyphs/dsm-24-bold-inverted.png 14 24 4 11 14 10 199 10
11
+ coffee pack-font.coffee --chars=../fonts_vector/dsm/chars-all.json > ../fonts_prf1/dsm-24-bold-inverted.prf1
12
+
13
+
10
14
  # dsm-22
11
- bash splitter.sh ../glyphs/dsm-22.png 13 22 4 11 10 199 10
15
+ bash splitter.sh ../glyphs/dsm-22.png 13 22 4 11 13 10 199 10
12
16
  coffee pack-font.coffee --chars=../fonts_vector/dsm/chars-all.json > ../fonts_prf1/dsm-22.prf1
13
17
 
14
- # dsm-22-italic
15
- bash splitter.sh ../glyphs/dsm-22-italic.png 13 22 6 11 10 199 10
18
+ # dsm-22-italic (TODO: proper {w, hs} when kerning gets added)
19
+ bash splitter.sh ../glyphs/dsm-22-italic.png 13 22 6 11 13 10 199 10
16
20
  coffee pack-font.coffee --chars=../fonts_vector/dsm/chars-all.json > ../fonts_prf1/dsm-22-italic.prf1
17
21
 
18
22
  # dsm-24
19
- bash splitter.sh ../glyphs/dsm-24.png 14 24 4 11 10 199 10
23
+ bash splitter.sh ../glyphs/dsm-24.png 14 24 4 11 14 10 199 10
20
24
  coffee pack-font.coffee --chars=../fonts_vector/dsm/chars-all.json > ../fonts_prf1/dsm-24.prf1
@@ -14,9 +14,10 @@ int main(int argc, char *argv[]) {
14
14
  long h = atol(argv[3]);
15
15
  long x0 = atol(argv[4]);
16
16
  long y0 = atol(argv[5]);
17
- long vs = atol(argv[6]);
18
- long n = atol(argv[7]);
19
- long wrap = atol(argv[8]);
17
+ long hs = atol(argv[6]);
18
+ long vs = atol(argv[7]);
19
+ long n = atol(argv[8]);
20
+ long wrap = atol(argv[9]);
20
21
 
21
22
  // glyphs.pbm
22
23
  char cmd[1000];
@@ -41,7 +42,7 @@ int main(int argc, char *argv[]) {
41
42
  for (i = 0; i < n; i++) {
42
43
  x = (i % wrap);
43
44
  y = (i / wrap);
44
- pixelX = x0 + w * x;
45
+ pixelX = x0 + (w + hs) * x;
45
46
  pixelY = y0 + (h + vs) * y;
46
47
 
47
48
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  mkdir -p temp
3
3
 
4
- gcc -o temp/splitter splitter.c ../../src-c/pnm.c ../../src-c/canvas.c && temp/splitter $1 $2 $3 $4 $5 $6 $7 $8
4
+ gcc -o temp/splitter splitter.c ../../src-c/pnm.c ../../src-c/canvas.c && temp/splitter $1 $2 $3 $4 $5 $6 $7 $8 $9
5
5
 
data/indie-raster.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
 
4
4
  s.name = "indie-raster"
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
 
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["ShopKeep"]
@@ -32,32 +32,42 @@ INDIE_RASTER_PATH = File.expand_path(File.dirname(__FILE__) + "/../build-c/indie
32
32
 
33
33
  class IndieRasterSession
34
34
 
35
- def initialize
36
- @c = []
35
+ def initialize(opt = {})
36
+ @commandsAppended = []
37
+ @commandsPrepended = []
37
38
  @fonts = {}
39
+ @imageDims = {}
40
+
41
+ @_curX = 0
42
+ @_curY = 0
43
+
44
+ @maxX = 0
45
+ @maxY = 0
46
+
38
47
  end
39
48
 
40
- def createBlank(opt)
41
- @c.push "createBlank #{opt[:id] or 1} #{opt[:w]} #{opt[:h]}\n"
49
+ def appendCommand(data)
50
+ @commandsAppended.push data
42
51
  end
43
52
 
44
- def loadImage(opt)
45
- data = dataFromOpt opt
46
- @c.push "loadImage #{opt[:id]} #{data.length}\n"
47
- @c.push data
53
+ def prependCommand(c)
54
+ @commandsPrepended.push c
48
55
  end
49
56
 
50
- def loadFont(opt)
51
- data = dataFromOpt opt
52
- @fonts[opt[:id]] = data
53
- @c.push "loadFont #{opt[:id]} #{data.length}\n"
54
- @c.push data
57
+ def commandsData()
58
+ @commandsPrepended.reverse.join('') + @commandsAppended.join('')
55
59
  end
56
60
 
57
- def drawImage(opt)
58
- @c.push "drawImage #{opt[:on] or 1} #{opt[:x]} #{opt[:y]} #{opt[:id]}\n"
61
+ def curX()
62
+ @_curX
59
63
  end
60
64
 
65
+ def curY()
66
+ @_curY
67
+ end
68
+
69
+ #### Helpers
70
+
61
71
  def widthOfText(opt)
62
72
  glyphWidth = ith_byte 8, @fonts[opt[:font]] #ASSUMPTION: glyph width < 256px
63
73
  return glyphWidth * opt[:text].length
@@ -67,6 +77,68 @@ class IndieRasterSession
67
77
  return ith_byte 12, @fonts[opt[:font]] #ASSUMPTION: height < 256
68
78
  end
69
79
 
80
+ def down(dy)
81
+ @_curY += dy
82
+ end
83
+
84
+ #TODO: rename
85
+ def cursorForOpt(opt)
86
+ x = opt[:x]
87
+ x = @_curX if x.nil?
88
+ y = opt[:y]
89
+ y = @_curY if y.nil?
90
+
91
+ x += (opt[:dx] or 0)
92
+ y += (opt[:dy] or 0)
93
+
94
+ return [x, y]
95
+ end
96
+
97
+ def rectDrawn(opt, x, y, w, h)
98
+ if (opt[:on] or 1) == 1
99
+ x2 = x + w
100
+ y2 = y + h
101
+ @maxX = x2 if x2 > @maxX
102
+ @maxY = y2 if y2 > @maxY
103
+ end
104
+ end
105
+
106
+ def prependCanvasCreation(opt)
107
+ w = opt[:w].nil? ? @maxX : opt[:w]
108
+ h = opt[:h].nil? ? @maxY : opt[:h]
109
+ prependCommand "createBlank 1 #{w} #{h}\n"
110
+ end
111
+
112
+ #### Commands
113
+
114
+ def createBlank(opt)
115
+ appendCommand("createBlank #{opt[:id] or 1} #{opt[:w]} #{opt[:h]}\n")
116
+ end
117
+
118
+ def loadImage(opt)
119
+ id = opt[:id]
120
+ data = dataFromOpt opt
121
+ @imageDims[id] = parse_pnm(data)
122
+ appendCommand("loadImage #{id} #{data.length}\n")
123
+ appendCommand(data)
124
+ end
125
+
126
+ def loadFont(opt)
127
+ data = dataFromOpt opt
128
+ @fonts[opt[:id]] = data
129
+ appendCommand("loadFont #{opt[:id]} #{data.length}\n")
130
+ appendCommand(data)
131
+ end
132
+
133
+ def drawImage(opt)
134
+ x, y = cursorForOpt opt
135
+ on, id = (opt[:on] or 1), opt[:id]
136
+ dim = @imageDims[id]
137
+ w, h = dim[:w], dim[:h]
138
+ rectDrawn opt, x, y, w, h
139
+ appendCommand("drawImage #{on} #{x} #{y} #{id}\n")
140
+ end
141
+
70
142
  def drawText(opt)
71
143
  data = ascii_to_utf32 opt[:text]
72
144
 
@@ -91,7 +163,6 @@ class IndieRasterSession
91
163
  w = _w
92
164
  end
93
165
  end
94
-
95
166
  if bestFont
96
167
  h = heightOfFont :font => bestFont
97
168
  opt[:x] = rx + ((rw - w) / 2).round
@@ -103,18 +174,25 @@ class IndieRasterSession
103
174
  end
104
175
 
105
176
  if opt[:toLeftOf]
106
- opt[:x] = opt[:toLeftOf] - self.widthOfText(opt)
177
+ opt[:x] = opt[:toLeftOf] - widthOfText(opt)
107
178
  end
108
- @c.push "drawText #{opt[:on] or 1} #{opt[:x]} #{opt[:y]} #{opt[:font]} #{data.length / 4}\n"
109
- @c.push data
110
- end
111
179
 
112
- def drawUPC(opt)
113
- @c.push "drawUPC #{opt[:on] or 1} #{opt[:x]} #{opt[:y]} #{opt[:digits]} #{opt[:w]} #{opt[:h]} #{opt[:guard_bar_extra_h] or 0} #{opt[:middle_font] or 0} #{opt[:side_font] or 0}\n"
180
+ x, y = cursorForOpt opt
181
+ w = widthOfText :text => opt[:text], :font => opt[:font]
182
+ h = heightOfFont opt
183
+ rectDrawn opt, x, y, w, h
184
+
185
+ appendCommand("drawText #{opt[:on] or 1} #{x} #{y} #{opt[:font]} #{data.length / 4}\n" + data)
114
186
  end
115
187
 
116
- def commandsData()
117
- @c.join ''
188
+ def drawUPC(opt)
189
+ on = opt[:on] or 1
190
+ x, y = cursorForOpt opt
191
+ w = opt[:w]
192
+ h = opt[:h] + opt[:guard_bar_extra_h]
193
+ rectDrawn opt, x, y, w, h
194
+
195
+ appendCommand("drawUPC #{on} #{x} #{y} #{opt[:digits]} #{opt[:w]} #{opt[:h]} #{opt[:guard_bar_extra_h] or 0} #{opt[:middle_font] or 0} #{opt[:side_font] or 0}\n")
118
196
  end
119
197
 
120
198
  def exportP4(opt = {})
@@ -127,7 +205,7 @@ class IndieRasterSession
127
205
 
128
206
  def export(command, opt)
129
207
 
130
- input = @c.join('') + "#{command} #{opt[:id] or 1}\n"
208
+ input = commandsData + "#{command} #{opt[:id] or 1}\n"
131
209
 
132
210
  tmppath = opt[:commands_temp_path]
133
211
  if tmppath
@@ -150,11 +228,11 @@ class IndieRasterSession
150
228
  return out
151
229
  end
152
230
 
153
- #TODO: refactor
231
+ #### TODO: refactor
154
232
  def parse_pnm(data)
155
233
  # assumes standard whitespace
156
234
 
157
- if (data[i] == "1" or data[i] == 0x31) or (data[i] == "4" or data[i] == 0x34)
235
+ if (data[1] == "1" or data[1] == 0x31) or (data[1] == "4" or data[1] == 0x34)
158
236
  num_breaks_expected = 2
159
237
  regex = /P[14]\n([0-9]+) ([0-9]+)\n/
160
238
  else
data/test/expected.pbm CHANGED
Binary file