gtk2html 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b81efb096425aecfebf68214bf408e611cd28ee
4
- data.tar.gz: 326fc3bb1f2d4b7fb92a7c641852cabc9f03fcb8
3
+ metadata.gz: 2c71c9bf3bcd28dc51ea164bda94b482e0ce3ee7
4
+ data.tar.gz: 1a42d43901620e37f640e58af6bf6f3a813214b1
5
5
  SHA512:
6
- metadata.gz: a2cd659cebe59ea8420966134300b4b32538e255989d69221f8d3b01feda70b10c60302b2f1c994d74c2d0701fc0a8cdee3834097f33c8e90546e305c31090da
7
- data.tar.gz: e1ce4bf4c31357354b112c6fcefde89a9a4778ee2e269385cf0f00cc703ca5dbcae439673d5f3f94aad61a3c3360d459603f42300da9bd0e40b4525b6840e458
6
+ metadata.gz: b5d3685e45170d735b58133c936684e42257f6008f0184f041d73f9eb7a90187f805001252d282cb04867f3e3142e7f80625942672130c3f3f6e05ae818d3e6b
7
+ data.tar.gz: 3caf8a98e72ec960d47f137afc8414710d4bc40a9d2e139f1cf0010dec7338c3e188975598a2c15c1da6a554f741ad42af33e4839296c2706bdd3317592896f0
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/gtk2html.rb CHANGED
@@ -6,13 +6,51 @@ require 'gtk2svg'
6
6
  require 'htmle'
7
7
 
8
8
 
9
+ module InspectArray
10
+
11
+ def scan(a, i=0)
12
+
13
+ if a.first.is_a? Symbol
14
+
15
+ puts a.inspect
16
+
17
+ else
18
+
19
+ puts (' ' * i) + '['
20
+
21
+ a.each.with_index do |row, j|
22
+
23
+ if row.is_a? String or row.is_a? Symbol then
24
+ print (' ' * (i+1)) + row.inspect
25
+ print ',' unless a.length - 1 == j
26
+ puts
27
+ elsif row.first.is_a? Symbol or row.first.is_a? String
28
+ puts (' ' * (i+1)) + '['
29
+ puts (' ' * (i+2)) + row.inspect[1..-2]
30
+ print (' ' * (i+1)) + ']'
31
+ print ',' unless a.length - 1 == j
32
+ puts
33
+ else
34
+ scan(row,i+1)
35
+ print ',' unless a.length - 1 == j
36
+ puts
37
+ end
38
+ end
39
+
40
+ print indent = (' ' * i) + ']'
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+
9
47
  module Gtk2HTML
10
48
 
11
49
  class Render < DomRender
12
50
 
13
51
  def initialize(x, width, height)
14
52
 
15
- @width, @height = width, height
53
+ @width, @height = width.to_i, height.to_i
16
54
  super x
17
55
 
18
56
  end
@@ -20,17 +58,30 @@ module Gtk2HTML
20
58
  def body(e, attributes, raw_style)
21
59
 
22
60
  style = style_filter(attributes).merge(raw_style)
23
-
24
- h = attributes
61
+ margin = style[:margin].values
62
+ coords = [nil, nil, nil, nil]
63
+ padding = style[:padding].values
25
64
 
26
- [[:draw_box, [x1,y1,x2,y2], style], render_all(e)]
65
+ [[:draw_box, margin, coords, padding, style], render_all(e)]
27
66
  end
67
+
68
+ def strong(e, attributes, raw_style)
69
+
70
+ style = style_filter(attributes).merge(raw_style)
71
+ margin = style[:margin].values
72
+ coords = [nil, nil, nil, nil]
73
+ padding = style[:padding].values
74
+
75
+ [[:draw_box, margin, coords, padding, style], render_all(e)]
76
+ end
77
+
78
+ alias b strong
28
79
 
29
80
  def div(e, attributes, raw_style)
30
81
 
31
82
  style = style_filter(attributes).merge(raw_style)
32
83
  margin = style[:margin].values
33
- coords = [0, nil, @width, @height/2]
84
+ coords = [nil, nil, nil, nil]
34
85
  padding = style[:padding].values
35
86
 
36
87
  [[:draw_box, margin, coords, padding, style], render_all(e)]
@@ -43,7 +94,11 @@ module Gtk2HTML
43
94
  padding = style[:padding].values
44
95
 
45
96
  [[:draw_box, margin, coords, padding, style], render_all(e)]
46
- end
97
+ end
98
+
99
+ def style(*args)
100
+
101
+ end
47
102
 
48
103
  private
49
104
 
@@ -51,12 +106,17 @@ module Gtk2HTML
51
106
 
52
107
  h = super attribute
53
108
 
54
- %i(margin padding).inject(h) do |r,x|
109
+ r2 = %i(margin padding).inject(h) do |r,x|
55
110
 
56
111
  if h.has_key? x then
57
112
 
58
113
  a = expand_shorthand(h[x])
59
- a.map!(&:to_i) # assumes everything is in pixels not em
114
+
115
+ a.map! do |v|
116
+ # note: there is 16px in 1em, see http://pxtoem.com/
117
+ v =~ /em$/i ? v.to_f * 16 : v.to_f
118
+ end
119
+
60
120
  r.merge!(x => Hash[%i(top right bottom left).zip(a)])
61
121
  else
62
122
  r
@@ -64,6 +124,8 @@ module Gtk2HTML
64
124
 
65
125
  end
66
126
 
127
+ r2
128
+
67
129
  end
68
130
 
69
131
  def style_filter(attributes)
@@ -77,55 +139,82 @@ module Gtk2HTML
77
139
  end
78
140
 
79
141
  class Layout
142
+ include InspectArray
80
143
 
81
144
  attr_reader :to_a
82
145
 
83
146
  def initialize(instructions, width: 320, height: 240)
84
147
 
85
- @width, @height = width, height
86
- a = lay_out(instructions, pcoords: [0, 0, @width, @height])
87
- @to_a = a
148
+ @pcoords = [0, 0, width, height]
149
+ @a = lay_out(instructions)
88
150
 
89
151
  end
90
152
 
153
+ def to_a(inspect: false, verbose: false)
154
+
155
+ if inspect or verbose then
156
+ scan @a
157
+ puts
158
+ else
159
+ @a
160
+ end
161
+
162
+ end
163
+
91
164
 
92
165
  private
93
166
 
94
- def lay_out(a, pcoords: [])
167
+ def lay_out(a)
95
168
 
96
- item, children = a
97
-
98
- name, margin, raw_coords, padding, style = item
169
+ if a.first.is_a? Symbol then
170
+
171
+ @text_style = %i(font-size color).inject({}){|r,x| r.merge(x => a[4][x]) }
172
+
173
+ set_row(a)
174
+
175
+ elsif a.first.is_a? String then
176
+ a.concat [@pcoords.take(2), @text_style]
177
+ elsif a.first.is_a? Array and a.first.empty?
178
+ a.delete a.first
179
+ lay_out a
180
+ else
181
+
182
+ a.map do |row|
183
+
184
+ if a.first.is_a? String then
185
+ a.concat [@pcoords.take(2), style]
186
+ else
187
+ lay_out(row)
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
195
+ def set_row(row)
196
+
197
+ name, margin, raw_coords, padding, style = row
99
198
 
100
- coords = raw_coords.map.with_index {|x,i| x ? x : pcoords[i]}
199
+ coords = raw_coords.map.with_index {|x,i| x ? x : @pcoords[i]}
101
200
 
102
201
  x1 = coords[0] + margin[0]
103
202
  y1 = coords[1] + margin[1]
104
203
  x2 = coords[2] - margin[2]
105
204
  y2 = coords[3] - margin[3]
106
205
 
107
- item[2] = [x1, y1, x2, y2]
108
-
109
- nested = if children and children.length > 1 then
110
- lay_out(children, pcoords: coords)
111
- else
112
- children
113
- end
114
- #[owidth=(coords[2] - coords[0]), oheight=(coords[3] - coords[1])]
115
- r = [item]
116
- r << nested if nested
117
- r
118
- end
119
-
120
- def lay_out2(a, pcoords: [])
206
+ new_coords = [x1, y1, x2, y2]
121
207
 
122
- name, raw_coords, attributes, style, children = a
123
- coords = raw_coords.map.with_index {|x,i| x ? x : pcoords[i]}
124
-
125
- owidth, oheight = lay_out(children, pcoords: coords) if children
208
+ curpos = new_coords.zip(padding).map{|x| x.inject(&:+)}
126
209
 
127
- [(coords[2] - coords[0]), (coords[3] - coords[1])]
128
- end
210
+ @pcoords[0] = x1 + padding[0]
211
+ @pcoords[1] = y1 + padding[1]
212
+ @pcoords[2] = x2 - padding[2]
213
+ @pcoords[3] = y2 - padding[3]
214
+
215
+ r = [name, margin, new_coords, padding, style]
216
+
217
+ end
129
218
 
130
219
  end
131
220
 
@@ -140,15 +229,12 @@ module Gtk2HTML
140
229
 
141
230
  end
142
231
 
143
- def draw_box(margin, raw_coords, padding, style)
144
-
145
- coords = raw_coords.map.with_index {|x,i| x ? x : @curpos[i] }
232
+ def draw_box(margin, coords, padding, style)
146
233
 
147
234
  h2 = style.clone
148
235
  h2.delete :color
236
+
149
237
  x1, y1, x2, y2 = coords
150
-
151
- @curpos = coords
152
238
 
153
239
  width = x2 - x1
154
240
  height = y2 - y1
@@ -157,10 +243,10 @@ module Gtk2HTML
157
243
  @area.window.draw_rectangle(gc, 1, x1, y1, width, height)
158
244
  end
159
245
 
160
- def draw_layout(text, style)
161
-
162
- x, y = @curpos
163
-
246
+ def draw_layout(text, coords, style)
247
+
248
+ x, y = coords
249
+
164
250
  text ||= ''
165
251
  h2 = style.clone
166
252
  h2.delete :'background-color'
@@ -195,33 +281,39 @@ module Gtk2HTML
195
281
  a.each do |row|
196
282
 
197
283
  next unless row
198
- x, remaining = row
199
284
 
200
- case x[0].class.to_s.to_sym
285
+ x = row
286
+
287
+ case row[0].class.to_s.to_sym
201
288
 
202
289
  when :Symbol
203
290
 
204
- name, *args = x
291
+ name, margin, coords, padding, style, *children = x
205
292
 
206
- @latest_style = args[3]
207
-
208
- method(name).call(*args)
209
- draw remaining
293
+ @latest_style = style
294
+ method(name).call(margin, coords, padding, style)
295
+ draw children
210
296
 
211
297
  when :String then
212
298
 
213
299
  next if x.empty?
214
300
 
215
- method(:draw_layout).call(x, @latest_style)
301
+ coords, style = row[1..-1]#remaining
302
+ method(:draw_layout).call(x,coords, style)
216
303
 
217
304
  when :Array
218
- draw remaining
305
+
306
+ if row[-1][0].is_a? String then
307
+ method(:draw_layout).call(*row[-1])
308
+ else
309
+ draw row[-1]
310
+ end
219
311
  else
220
312
 
221
313
  name, *args = x
222
314
 
223
315
  method(name).call(args)
224
- draw remaining
316
+ draw row[-1]
225
317
  end
226
318
 
227
319
  end
@@ -298,11 +390,12 @@ module Gtk2HTML
298
390
 
299
391
  @width, @height = window.size
300
392
  instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a
393
+
301
394
  @layout_instructions = Gtk2HTML::Layout.new(instructions).to_a
302
395
 
303
396
  end
304
397
 
305
- drawing = DrawingInstructions.new area
398
+ drawing = Gtk2HTML::DrawingInstructions.new area
306
399
  drawing.render @layout_instructions
307
400
  @dirty = false
308
401
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  XW00gFE4S5Cq4J0/5Y8BLyxXWUTTXHeLXwfiIfffKOUtTUjlivG+dvqexj8Qbbv9
32
32
  bW25tpA1jigdbQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-11-27 00:00:00.000000000 Z
34
+ date: 2015-11-29 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gtk2svg
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '0.3'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 0.3.11
45
+ version: 0.3.12
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  version: '0.3'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 0.3.11
55
+ version: 0.3.12
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: htmle
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '0.1'
63
63
  - - ">="
64
64
  - !ruby/object:Gem::Version
65
- version: 0.1.0
65
+ version: 0.1.3
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
@@ -72,7 +72,7 @@ dependencies:
72
72
  version: '0.1'
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.0
75
+ version: 0.1.3
76
76
  description:
77
77
  email: james@r0bertson.co.uk
78
78
  executables: []
metadata.gz.sig CHANGED
Binary file