sogoumap2pdf 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -8,6 +8,7 @@ TODO
8
8
  bin/sogoumap2pdf
9
9
  bin/sogoumap2disk
10
10
  bin/sogoumap2pdf_from_disk
11
+ bin/sogoumap2pdf_from_disk_front_page
11
12
  config/hoe.rb
12
13
  config/requirements.rb
13
14
  lib/sogoumap2pdf.rb
data/TODO CHANGED
@@ -1 +1,2 @@
1
1
  * fix the type errors when the pixels are to large
2
+ * fix front page error
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-8-19.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+ require 'sogoumap2pdf'
14
+ include Sogoumap2pdf
15
+ # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
16
+
17
+ OPTIONS = {
18
+ :path => '~'
19
+ }
20
+ MANDATORY_OPTIONS = %w( )
21
+
22
+ parser = OptionParser.new do |opts|
23
+ opts.banner = <<BANNER
24
+ This application is wonderful because...
25
+
26
+ Usage: #{File.basename($0)} [options]
27
+
28
+ Options are:
29
+ BANNER
30
+ opts.separator ""
31
+ opts.on("-p", "--path=PATH", String,
32
+ "The root path for selecting files",
33
+ "Default: ~") { |OPTIONS[:path]| }
34
+ opts.on("-h", "--help",
35
+ "Show this help message.") { puts opts; exit }
36
+ opts.parse!(ARGV)
37
+
38
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
39
+ puts opts; exit
40
+ end
41
+ end
42
+
43
+ path = OPTIONS[:path]
44
+
45
+ # do stuff
46
+ #
47
+ # guangzhou: ruby map2pdf.rb http://hbpic3.go2map.com/seamless/0/180/792/504/105/100899_21033.JPG 0 0 30 30 guangzhou.pdf sp
48
+ # guangzhou: ruby map2pdf.rb http://hbpic3.go2map.com/seamless/0/180/792/504/105/100899_21033.JPG 0x0 30x30 guangzhou.pdf sp
49
+ link=ARGV[0]
50
+ option=ARGV[4]
51
+ x,y=ARGV[1].split("x")
52
+ r,c=ARGV[2].split("x")
53
+ g=SogouMapImage.new(link, option)
54
+ gmpdf=ImageToPdf.new(".JPG",x,y)
55
+ xres, yres = gmpdf.perfect_fit(x.to_i,y.to_i,r.to_i,c.to_i)
56
+ g.fill_map(xres,yres)
57
+ gmpdf.front_page_only(g)
58
+ #gmpdf.create_pages(g)
59
+ gmpdf.save(ARGV[3])
@@ -101,7 +101,7 @@ module Sogoumap2pdf
101
101
 
102
102
  # pgimg=big_image.crop(j*(@page_width-@page_overlap),
103
103
  # i*(@page_height-@page_overlap),@page_width,@page_height,true)
104
- pgimg.write("itptmp#{@link_end}") { self.quality = 70 }
104
+ pgimg.write("itptmp#{@link_end}") { self.quality = 100 }
105
105
  @pdf.add_image_from_file("itptmp#{@link_end}",0,0)
106
106
  ss = PDF::Writer::StrokeStyle.new(4,:cap=>:round)
107
107
  @pdf.stroke_style ss
@@ -192,11 +192,16 @@ module Sogoumap2pdf
192
192
  end
193
193
  #crop
194
194
  #map2pdf.rb:339:in `crop!': bignum too big to convert into `long' (RangeError)
195
- x_string,y_string=resimg.density.split("x")
196
- resx=x_string.to_i
197
- resy=y_string.to_i
198
- resimg.crop!(SouthWestGravity,resx<@page_width?resx:@page_width,resy<@page_height?resy:@page_height)
199
- resimg.write("itptmp#{@link_end}"){ self.quality = 70 }
195
+ resx=@tumb_x*g.npx
196
+ resy=@tumb_y*g.npy
197
+
198
+ p "front_page size"
199
+ p resx
200
+ p resy
201
+ resx=@page_width if resx>@page_width
202
+ resy=@page_height if resy>@page_height
203
+ resimg.crop!(SouthWestGravity,resx,resy)
204
+ resimg.write("itptmp#{@link_end}"){ self.quality = 100 }
200
205
  @pdf.add_image_from_file("itptmp#{@link_end}",0,0)
201
206
  ss = PDF::Writer::StrokeStyle.new(2)
202
207
  @pdf.stroke_style ss
@@ -218,6 +223,89 @@ module Sogoumap2pdf
218
223
  end
219
224
  end
220
225
  end
226
+ def front_page_only(g)
227
+ size_x=@big_img_width
228
+ size_y=@big_img_height
229
+ # calculate the number of requred rows and columns
230
+ cols=(size_x-@page_overlap)/(@page_width-@page_overlap)
231
+ rows=(size_y-@page_overlap)/(@page_height-@page_overlap)
232
+
233
+ ci=ImageList.new # image list to hold results
234
+ page=Rectangle.new( 0, 0, 0, 0)
235
+ @g=g
236
+ for i in 0... g.npx
237
+ p "resizing #{i} j"
238
+ for j in 0...g.npy
239
+ picture_file_name="~/.sogoumap/0/"+ [g.resource_type,g.resource_level,((g.start_link_x+i)/200).to_s,((g.start_link_y+j)/200).to_s].join("/")+"/"+(g.start_link_x+i).to_s+"_"+(g.start_link_y+j).to_s+g.link_end
240
+ picture_file_name=File.expand_path(picture_file_name)
241
+ if File.exist?(picture_file_name) && File.size(picture_file_name)!= 0 then
242
+ tumb=ImageList.new.read(picture_file_name)[0] # image list to hold results
243
+
244
+ path_file_name="~/.sogoumap/0/"+ ["179",g.resource_level,((g.start_link_x+i)/200).to_s,((g.start_link_y+j)/200).to_s].join("/")+"/"+(g.start_link_x+i).to_s+"_"+(g.start_link_y+j).to_s+".PNG"
245
+ path_file_name=File.expand_path(path_file_name)
246
+ if g.satellite_path && File.exist?(path_file_name) && File.size(path_file_name)!=0 then
247
+ path_tumb=ImageList.new.read(path_file_name)[0] # image list to hold results
248
+ tumb.composite!(path_tumb, 0, 0, OverCompositeOp)
249
+ end
250
+ #resize each to tumb
251
+ tumb.resize!(@tumb_x,@tumb_y)
252
+ #append tumb
253
+ ci << tumb
254
+ #update page
255
+ page.x=i*@tumb_x
256
+ page.y=(g.npy-1-j)*@tumb_y
257
+ ci.page=page
258
+ else
259
+ end
260
+ end
261
+ end
262
+ #mosaic
263
+ if ci.length==0 then
264
+ p "@tumb_x,@tumb_y"
265
+ p @tumb_x
266
+ p @tumb_y
267
+ p "g.npx,g.npy"
268
+ p g.npx
269
+ p g.npy
270
+ p "#{g.npx*@tumb_x}x#{g.npy*@tumb_y}"
271
+ ## can't work
272
+ resimg=ImageList.new.read("null:white") { self.size = "#{g.npx.to_i*@tumb_x.to_i}x#{g.npy.to_i*@tumb_y.to_i}"}
273
+ else
274
+ resimg=ci.mosaic
275
+ end
276
+ #crop
277
+ #map2pdf.rb:339:in `crop!': bignum too big to convert into `long' (RangeError)
278
+ resx=@tumb_x*g.npx
279
+ resy=@tumb_y*g.npy
280
+ p "front_page size"
281
+ p resx
282
+ p resy
283
+ resx=@page_width if resx>@page_width
284
+ resy=@page_height if resy>@page_height
285
+ resimg.crop!(SouthWestGravity,resx,resy)
286
+ resimg.write("itptmp#{@link_end}"){ self.quality = 100 }
287
+ @pdf.add_image_from_file("itptmp#{@link_end}",0,0)
288
+ ss = PDF::Writer::StrokeStyle.new(2)
289
+ @pdf.stroke_style ss
290
+ for i in 1...cols
291
+ @pdf.line(i*@page_width/cols,0,
292
+ i*@page_width/cols,@page_height).stroke
293
+ end
294
+ for i in 1...rows
295
+ @pdf.line(0,i*@page_height/rows,
296
+ @page_width,i*@page_height/rows).stroke
297
+ end
298
+ # for i in 0...rows
299
+ # for j in 0...cols
300
+ # p "adding #{i} #{j} link in front page"
301
+ # p Time.now
302
+ # @pdf.add_internal_link("map part #{i},#{j}",
303
+ # j*@page_width/cols, @page_height-i*@page_height/rows,
304
+ # (j+1)*@page_width/cols, @page_height-(i+1)*@page_height/rows)
305
+ # end
306
+ # end
307
+ end
308
+
221
309
  def save(save_file)
222
310
  @pdf.save_as(save_file)
223
311
  end
@@ -1,7 +1,7 @@
1
1
  module Sogoumap2pdf
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
data/website/index.html CHANGED
@@ -35,7 +35,7 @@
35
35
  <h1>sogoumap2pdf</h1>
36
36
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/sogoumap2pdf"; return false'>
37
37
  <p>Get Version</p>
38
- <a href="http://rubyforge.org/projects/sogoumap2pdf" class="numbers">0.0.11</a>
38
+ <a href="http://rubyforge.org/projects/sogoumap2pdf" class="numbers">0.1.0</a>
39
39
  </div>
40
40
  <h2>What</h2>
41
41
  <p>download map from map.sogou.com and convert to pdf</p>
@@ -75,7 +75,7 @@ rake install_gem</pre>
75
75
  <h2>Screencast</h2>
76
76
  <object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/SxEZ1lhUDH4"> </param> <embed src="http://www.youtube.com/v/SxEZ1lhUDH4" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>
77
77
  <p class="coda">
78
- <a href="mailto:ruanwz@gmail.com">David Ruan</a>, 4th September 2008<br>
78
+ <a href="mailto:ruanwz@gmail.com">David Ruan</a>, 9th September 2008<br>
79
79
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
80
80
  </p>
81
81
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sogoumap2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ruan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-09 00:00:00 +08:00
12
+ date: 2008-09-11 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ executables:
49
49
  - sogoumap2pdf
50
50
  - sogoumap2disk
51
51
  - sogoumap2pdf_from_disk
52
+ - sogoumap2pdf_from_disk_front_page
52
53
  extensions: []
53
54
 
54
55
  extra_rdoc_files:
@@ -69,6 +70,7 @@ files:
69
70
  - bin/sogoumap2pdf
70
71
  - bin/sogoumap2disk
71
72
  - bin/sogoumap2pdf_from_disk
73
+ - bin/sogoumap2pdf_from_disk_front_page
72
74
  - config/hoe.rb
73
75
  - config/requirements.rb
74
76
  - lib/sogoumap2pdf.rb