gtk2html 0.1.0 → 0.1.1

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: 9c5ab0a506063f7cb0b41a80b527a8865c64a721
4
- data.tar.gz: 2fcf59b16e5c4415c652474733501ed7588de53f
3
+ metadata.gz: 4b81efb096425aecfebf68214bf408e611cd28ee
4
+ data.tar.gz: 326fc3bb1f2d4b7fb92a7c641852cabc9f03fcb8
5
5
  SHA512:
6
- metadata.gz: 8237d4275b5115807d8e00a9b4d104e6aea077f6acfe730e4436aa8acc346d82b606b40878520bb6fe9eff3a7996857e4f43d90aea20eb338f4bf79207e35c10
7
- data.tar.gz: 0bec2392905037ccbf3d796a34b9db8f55ac04c663db39554979435d1817abd07d9986ad3d9450c624abb5a9e1c44fafbc174ea24255d9c6993dc274fec8e31e
6
+ metadata.gz: a2cd659cebe59ea8420966134300b4b32538e255989d69221f8d3b01feda70b10c60302b2f1c994d74c2d0701fc0a8cdee3834097f33c8e90546e305c31090da
7
+ data.tar.gz: e1ce4bf4c31357354b112c6fcefde89a9a4778ee2e269385cf0f00cc703ca5dbcae439673d5f3f94aad61a3c3360d459603f42300da9bd0e40b4525b6840e458
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/gtk2html.rb CHANGED
@@ -23,7 +23,7 @@ module Gtk2HTML
23
23
 
24
24
  h = attributes
25
25
 
26
- [:draw_box, [x1,y1,x2,y2], style, render_all(e)]
26
+ [[:draw_box, [x1,y1,x2,y2], style], render_all(e)]
27
27
  end
28
28
 
29
29
  def div(e, attributes, raw_style)
@@ -33,7 +33,7 @@ module Gtk2HTML
33
33
  coords = [0, nil, @width, @height/2]
34
34
  padding = style[:padding].values
35
35
 
36
- [:draw_box, margin, coords, padding, style, render_all(e)]
36
+ [[:draw_box, margin, coords, padding, style], render_all(e)]
37
37
  end
38
38
 
39
39
  def html(e, attributes, style)
@@ -42,7 +42,7 @@ module Gtk2HTML
42
42
  coords = [0, 0, @width, @height]
43
43
  padding = style[:padding].values
44
44
 
45
- [:draw_box, margin, coords, padding, style, render_all(e)]
45
+ [[:draw_box, margin, coords, padding, style], render_all(e)]
46
46
  end
47
47
 
48
48
  private
@@ -56,7 +56,7 @@ module Gtk2HTML
56
56
  if h.has_key? x then
57
57
 
58
58
  a = expand_shorthand(h[x])
59
-
59
+ a.map!(&:to_i) # assumes everything is in pixels not em
60
60
  r.merge!(x => Hash[%i(top right bottom left).zip(a)])
61
61
  else
62
62
  r
@@ -76,6 +76,59 @@ module Gtk2HTML
76
76
 
77
77
  end
78
78
 
79
+ class Layout
80
+
81
+ attr_reader :to_a
82
+
83
+ def initialize(instructions, width: 320, height: 240)
84
+
85
+ @width, @height = width, height
86
+ a = lay_out(instructions, pcoords: [0, 0, @width, @height])
87
+ @to_a = a
88
+
89
+ end
90
+
91
+
92
+ private
93
+
94
+ def lay_out(a, pcoords: [])
95
+
96
+ item, children = a
97
+
98
+ name, margin, raw_coords, padding, style = item
99
+
100
+ coords = raw_coords.map.with_index {|x,i| x ? x : pcoords[i]}
101
+
102
+ x1 = coords[0] + margin[0]
103
+ y1 = coords[1] + margin[1]
104
+ x2 = coords[2] - margin[2]
105
+ y2 = coords[3] - margin[3]
106
+
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: [])
121
+
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
126
+
127
+ [(coords[2] - coords[0]), (coords[3] - coords[1])]
128
+ end
129
+
130
+ end
131
+
79
132
  class DrawingInstructions
80
133
 
81
134
  attr_accessor :area
@@ -87,24 +140,24 @@ module Gtk2HTML
87
140
 
88
141
  end
89
142
 
90
- def draw_box(args)
143
+ def draw_box(margin, raw_coords, padding, style)
91
144
 
92
- margin, raw_coords, padding, style = args
93
145
  coords = raw_coords.map.with_index {|x,i| x ? x : @curpos[i] }
94
146
 
95
147
  h2 = style.clone
96
148
  h2.delete :color
97
149
  x1, y1, x2, y2 = coords
98
150
 
99
- @curpos = coords
151
+ @curpos = coords
152
+
153
+ width = x2 - x1
154
+ height = y2 - y1
100
155
 
101
156
  gc = gc_ini(h2)
102
- @area.window.draw_rectangle(gc, 1, x1, y1, x2, y2)
157
+ @area.window.draw_rectangle(gc, 1, x1, y1, width, height)
103
158
  end
104
159
 
105
- def draw_layout(args)
106
-
107
- text, style = args
160
+ def draw_layout(text, style)
108
161
 
109
162
  x, y = @curpos
110
163
 
@@ -124,10 +177,8 @@ module Gtk2HTML
124
177
  def window(args)
125
178
  end
126
179
 
127
- def render(a)
128
- @latest_style = a[4]
129
- method(a[0]).call(args=a[1..4])
130
- draw a[5]
180
+ def render(a)
181
+ draw [a]
131
182
  end
132
183
 
133
184
  def script(args)
@@ -138,31 +189,43 @@ module Gtk2HTML
138
189
  private
139
190
 
140
191
  def draw(a)
192
+
193
+ return unless a
194
+
195
+ a.each do |row|
196
+
197
+ next unless row
198
+ x, remaining = row
141
199
 
142
- a.each do |rawx|
143
-
144
- x, *remaining = rawx
200
+ case x[0].class.to_s.to_sym
145
201
 
146
- if x.is_a? Symbol then
202
+ when :Symbol
203
+
204
+ name, *args = x
205
+
206
+ @latest_style = args[3]
147
207
 
148
- @latest_style = remaining[3]
149
- method(x).call(args=remaining.shift(4))
208
+ method(name).call(*args)
150
209
  draw remaining
151
- elsif x.is_a? String then
152
-
153
- next unless x.length > 0
210
+
211
+ when :String then
154
212
 
155
- method(:draw_layout).call(args=[x, @latest_style]) unless x.empty?
213
+ next if x.empty?
156
214
 
157
- elsif x.is_a? Array
215
+ method(:draw_layout).call(x, @latest_style)
158
216
 
217
+ when :Array
159
218
  draw remaining
160
219
  else
161
- method(x).call(remaining.take 4)
220
+
221
+ name, *args = x
222
+
223
+ method(name).call(args)
224
+ draw remaining
162
225
  end
163
-
164
- end
165
226
 
227
+ end
228
+
166
229
  end
167
230
 
168
231
  def set_colour(c)
@@ -202,7 +265,7 @@ module Gtk2HTML
202
265
 
203
266
 
204
267
  attr_accessor :doc, :html
205
- attr_reader :width, :height
268
+ attr_reader :width, :height, :window
206
269
 
207
270
  def initialize(html, irb: false)
208
271
 
@@ -216,6 +279,7 @@ module Gtk2HTML
216
279
 
217
280
  @width = 320
218
281
  @height = 240
282
+ @window = window
219
283
  window.set_default_size(@width, @height)
220
284
 
221
285
  @dirty = true
@@ -223,15 +287,23 @@ module Gtk2HTML
223
287
 
224
288
  area.signal_connect("expose_event") do
225
289
 
290
+ width, height = window.size
291
+
292
+ @dirty = true if [@width, @height] != [width, height]
293
+
294
+
226
295
  if @dirty then
227
296
 
228
297
  Thread.new { @doc.root.xpath('//script').each {|x| eval x.text.unescape } }
298
+
299
+ @width, @height = window.size
300
+ instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a
301
+ @layout_instructions = Gtk2HTML::Layout.new(instructions).to_a
229
302
 
230
- @instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a
231
303
  end
232
304
 
233
305
  drawing = DrawingInstructions.new area
234
- drawing.render @instructions
306
+ drawing.render @layout_instructions
235
307
  @dirty = false
236
308
 
237
309
  end
@@ -280,4 +352,4 @@ module Gtk2HTML
280
352
 
281
353
  end
282
354
 
283
- end
355
+ end
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.0
4
+ version: 0.1.1
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-25 00:00:00.000000000 Z
34
+ date: 2015-11-27 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gtk2svg
metadata.gz.sig CHANGED
Binary file