sogoumap2pdf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +30 -0
- data/PostInstall.txt +7 -0
- data/README.txt +49 -0
- data/Rakefile +4 -0
- data/bin/sogoumap2pdf +52 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/sogoumap2pdf/image_to_pdf.rb +226 -0
- data/lib/sogoumap2pdf/sogou_map_image.rb +149 -0
- data/lib/sogoumap2pdf/version.rb +9 -0
- data/lib/sogoumap2pdf.rb +12 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/sogoumap2pdf_spec.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/website/index.html +86 -0
- data/website/index.txt +83 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +105 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/sogoumap2pdf
|
8
|
+
config/hoe.rb
|
9
|
+
config/requirements.rb
|
10
|
+
lib/sogoumap2pdf.rb
|
11
|
+
lib/sogoumap2pdf/version.rb
|
12
|
+
lib/sogoumap2pdf/image_to_pdf.rb
|
13
|
+
lib/sogoumap2pdf/sogou_map_image.rb
|
14
|
+
script/console
|
15
|
+
script/destroy
|
16
|
+
script/generate
|
17
|
+
script/txt2html
|
18
|
+
setup.rb
|
19
|
+
spec/sogoumap2pdf_spec.rb
|
20
|
+
spec/spec.opts
|
21
|
+
spec/spec_helper.rb
|
22
|
+
tasks/deployment.rake
|
23
|
+
tasks/environment.rake
|
24
|
+
tasks/rspec.rake
|
25
|
+
tasks/website.rake
|
26
|
+
website/index.html
|
27
|
+
website/index.txt
|
28
|
+
website/javascripts/rounded_corners_lite.inc.js
|
29
|
+
website/stylesheets/screen.css
|
30
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
= sogoumap2pdf
|
2
|
+
|
3
|
+
* sogoumap2pdf.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
* Download map and convert to pdf
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Download map and convert to pdf
|
12
|
+
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
sogoumap2pdf link map_width map_height row column save_file_name mode
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
* pdf-writer
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
* sudo gem install sogoumap2pdf
|
25
|
+
|
26
|
+
== LICENSE:
|
27
|
+
|
28
|
+
(The MIT License)
|
29
|
+
|
30
|
+
Copyright (c) 2008 FIXME full name
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
'Software'), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/sogoumap2pdf
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
+
g=SogouMapImage.new(ARGV[0], ARGV[6])
|
47
|
+
gmpdf=ImageToPdf.new(".JPG")
|
48
|
+
xres, yres = gmpdf.perfect_fit(ARGV[1].to_i,ARGV[2].to_i,ARGV[3].to_i,ARGV[4].to_i)
|
49
|
+
g.fill_map(xres,yres)
|
50
|
+
gmpdf.front_page(g)
|
51
|
+
gmpdf.create_pages(g)
|
52
|
+
gmpdf.save
|
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'sogoumap2pdf/version'
|
2
|
+
|
3
|
+
AUTHOR = 'David Ruan' # can also be an array of Authors
|
4
|
+
EMAIL = "ruanwz@gmail.com"
|
5
|
+
DESCRIPTION = "download the map and convert to pdf"
|
6
|
+
GEM_NAME = 'sogoumap2pdf' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'sogoumap2pdf' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['pdf-writer', '>= 1.1.8']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "ruanwz"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = Sogoumap2pdf::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'sogoumap2pdf documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
end
|
68
|
+
|
69
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
70
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
71
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
72
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
73
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pdf/writer'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'RMagick'
|
6
|
+
include Magick
|
7
|
+
|
8
|
+
module Sogoumap2pdf
|
9
|
+
class ImageToPdf
|
10
|
+
def initialize(link_end)
|
11
|
+
#@page_width=600
|
12
|
+
@page_width=1280
|
13
|
+
#@page_width=800
|
14
|
+
#@page_height=768
|
15
|
+
@page_height=1024
|
16
|
+
#@page_height=480
|
17
|
+
@page_overlap=50
|
18
|
+
@text_height=15
|
19
|
+
@pdf=PDF::Writer.new(:paper=>[0,0,@page_width,@page_height])
|
20
|
+
@pdf.margins_pt(0,0,0,0)
|
21
|
+
# initialize icons
|
22
|
+
@icon_size=20
|
23
|
+
@link_end=link_end
|
24
|
+
end
|
25
|
+
def big_img_crop(x,y,w,h)
|
26
|
+
g=@g
|
27
|
+
nx0=x/256
|
28
|
+
ny0=y/256
|
29
|
+
nxn=(x+w)/256+1
|
30
|
+
nyn=(y+h)/256+1
|
31
|
+
delta_x=x-nx0*256
|
32
|
+
delta_y=y-ny0*256
|
33
|
+
p "x #{x}"
|
34
|
+
p "y #{y}"
|
35
|
+
p "delta_x #{delta_x}"
|
36
|
+
p "delta_y #{delta_y}"
|
37
|
+
ci=ImageList.new # image list to hold results
|
38
|
+
page=Rectangle.new( 0, 0, 0, 0)
|
39
|
+
|
40
|
+
for i in nx0..nxn
|
41
|
+
for j in ny0..nyn
|
42
|
+
p "big_img_crop #{i},#{j}"
|
43
|
+
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
|
44
|
+
picture_file_name=File.expand_path(picture_file_name)
|
45
|
+
if File.exist?(picture_file_name) && File.size(picture_file_name)!= 0 then
|
46
|
+
tumb=ImageList.new.read(picture_file_name)[0] # image list to hold results
|
47
|
+
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"
|
48
|
+
path_file_name=File.expand_path(path_file_name)
|
49
|
+
|
50
|
+
if g.satellite_path && File.exist?(path_file_name) && File.size(path_file_name)!=0 then
|
51
|
+
|
52
|
+
path_tumb=ImageList.new.read(path_file_name)[0] # image list to hold results
|
53
|
+
tumb.composite!(path_tumb, 0, 0, OverCompositeOp)
|
54
|
+
end
|
55
|
+
|
56
|
+
#append tumb
|
57
|
+
ci << tumb
|
58
|
+
#update page
|
59
|
+
page.x=(i-nx0)*256
|
60
|
+
page.y=(nyn-j)*256
|
61
|
+
ci.page=page
|
62
|
+
else
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
if ci.length==0 then
|
67
|
+
resimg=ImageList.new.read("NULL:white") { self.size = "#{g.npx*@tumb_x}x#{g.npy*@tumb_y}"}
|
68
|
+
else
|
69
|
+
resimg=ci.mosaic
|
70
|
+
end
|
71
|
+
return resimg.crop(SouthWestGravity,delta_x,delta_y,w,h,true)
|
72
|
+
end
|
73
|
+
|
74
|
+
def perfect_fit(nh256,nw256,r,c)
|
75
|
+
@row=r
|
76
|
+
@column=c
|
77
|
+
@tumb_x=@page_width*256/(c*@page_width-(c-1)*@page_overlap)
|
78
|
+
@tumb_y=@page_height*256/(r*@page_height-(r-1)*@page_overlap)
|
79
|
+
@big_img_width,@big_img_height=c*@page_width-(c-1)*@page_overlap, r*@page_height-(r-1)*@page_overlap
|
80
|
+
|
81
|
+
if nh256==0 then
|
82
|
+
return c*@page_width-(c-1)*@page_overlap, r*@page_height-(r-1)*@page_overlap
|
83
|
+
else
|
84
|
+
return c*nw256*256, r*nh256*256
|
85
|
+
end
|
86
|
+
end
|
87
|
+
def create_pages(g)
|
88
|
+
# get the size of the image
|
89
|
+
size_x=@big_img_width
|
90
|
+
size_y=@big_img_height
|
91
|
+
|
92
|
+
# calculate the number of requred rows and columns
|
93
|
+
cols=(size_x-@page_overlap)/(@page_width-@page_overlap)
|
94
|
+
rows=(size_y-@page_overlap)/(@page_height-@page_overlap)
|
95
|
+
# create pdf
|
96
|
+
for i in 0...rows
|
97
|
+
for j in 0...cols
|
98
|
+
p "creating page #{i} #{j}"
|
99
|
+
p Time.now
|
100
|
+
@pdf.new_page
|
101
|
+
@pdf.add_destination("map part #{i},#{j}", "Fit")
|
102
|
+
pgimg=big_img_crop(j*(@page_width-@page_overlap),
|
103
|
+
(rows-1-i)*(@page_height-@page_overlap),@page_width,@page_height)
|
104
|
+
|
105
|
+
# pgimg=big_image.crop(j*(@page_width-@page_overlap),
|
106
|
+
# i*(@page_height-@page_overlap),@page_width,@page_height,true)
|
107
|
+
pgimg.write("itptmp#{@link_end}") { self.quality = 70 }
|
108
|
+
@pdf.add_image_from_file("itptmp#{@link_end}",0,0)
|
109
|
+
ss = PDF::Writer::StrokeStyle.new(4,:cap=>:round)
|
110
|
+
@pdf.stroke_style ss
|
111
|
+
if j>0 then
|
112
|
+
@pdf.add_internal_link("map part #{i},#{j-1}",0,@page_height/2,
|
113
|
+
@icon_size,@page_height/2+@icon_size)
|
114
|
+
@pdf.line(@icon_size,@page_height/2,0,@page_height/2+@icon_size/2).stroke
|
115
|
+
@pdf.line(0,@page_height/2+@icon_size/2,@icon_size,@page_height/2+@icon_size).stroke
|
116
|
+
end
|
117
|
+
if j<cols-1 then
|
118
|
+
@pdf.add_internal_link("map part #{i},#{j+1}",
|
119
|
+
@page_width-@icon_size,@page_height/2,
|
120
|
+
@page_width,@page_height/2+@icon_size)
|
121
|
+
@pdf.line(@page_width-@icon_size,@page_height/2,
|
122
|
+
@page_width,@page_height/2+@icon_size/2).stroke
|
123
|
+
@pdf.line(@page_width,@page_height/2+@icon_size/2,
|
124
|
+
@page_width-@icon_size,@page_height/2+@icon_size).stroke
|
125
|
+
end
|
126
|
+
if i>0 then
|
127
|
+
@pdf.add_internal_link("map part #{i-1},#{j}",@page_width/2,@page_height,
|
128
|
+
@page_width/2+@icon_size,@page_height-@icon_size)
|
129
|
+
@pdf.line(@page_width/2,@page_height-@icon_size,
|
130
|
+
@page_width/2+@icon_size/2,@page_height).stroke
|
131
|
+
@pdf.line(@page_width/2+@icon_size/2,@page_height,
|
132
|
+
@page_width/2+@icon_size,@page_height-@icon_size).stroke
|
133
|
+
end
|
134
|
+
if i<rows-1 then
|
135
|
+
@pdf.add_internal_link("map part #{i+1},#{j}",@page_width/2,0,
|
136
|
+
@page_width/2+@icon_size,@icon_size)
|
137
|
+
@pdf.line(@page_width/2,@icon_size,
|
138
|
+
@page_width/2+@icon_size/2,0).stroke
|
139
|
+
@pdf.line(@page_width/2+@icon_size/2,0,
|
140
|
+
@page_width/2+@icon_size,@icon_size).stroke
|
141
|
+
end
|
142
|
+
# @pdf.restore_state
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
def front_page(g)
|
147
|
+
size_x=@big_img_width
|
148
|
+
size_y=@big_img_height
|
149
|
+
# calculate the number of requred rows and columns
|
150
|
+
cols=(size_x-@page_overlap)/(@page_width-@page_overlap)
|
151
|
+
rows=(size_y-@page_overlap)/(@page_height-@page_overlap)
|
152
|
+
|
153
|
+
ci=ImageList.new # image list to hold results
|
154
|
+
page=Rectangle.new( 0, 0, 0, 0)
|
155
|
+
@g=g
|
156
|
+
for i in 0... g.npx
|
157
|
+
p "resizing #{i} j"
|
158
|
+
for j in 0...g.npy
|
159
|
+
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
|
160
|
+
picture_file_name=File.expand_path(picture_file_name)
|
161
|
+
if File.exist?(picture_file_name) && File.size(picture_file_name)!= 0 then
|
162
|
+
tumb=ImageList.new.read(picture_file_name)[0] # image list to hold results
|
163
|
+
|
164
|
+
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"
|
165
|
+
path_file_name=File.expand_path(path_file_name)
|
166
|
+
if g.satellite_path && File.exist?(path_file_name) && File.size(path_file_name)!=0 then
|
167
|
+
path_tumb=ImageList.new.read(path_file_name)[0] # image list to hold results
|
168
|
+
tumb.composite!(path_tumb, 0, 0, OverCompositeOp)
|
169
|
+
end
|
170
|
+
#resize each to tumb
|
171
|
+
tumb.resize!(@tumb_x,@tumb_y)
|
172
|
+
#append tumb
|
173
|
+
ci << tumb
|
174
|
+
#update page
|
175
|
+
page.x=i*@tumb_x
|
176
|
+
page.y=(g.npy-1-j)*@tumb_y
|
177
|
+
ci.page=page
|
178
|
+
else
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
#mosaic
|
183
|
+
if ci.length==0 then
|
184
|
+
p "@tumb_x,@tumb_y"
|
185
|
+
p @tumb_x
|
186
|
+
p @tumb_y
|
187
|
+
p "g.npx,g.npy"
|
188
|
+
p g.npx
|
189
|
+
p g.npy
|
190
|
+
p "#{g.npx*@tumb_x}x#{g.npy*@tumb_y}"
|
191
|
+
## can't work
|
192
|
+
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}"}
|
193
|
+
else
|
194
|
+
resimg=ci.mosaic
|
195
|
+
end
|
196
|
+
#crop
|
197
|
+
#map2pdf.rb:339:in `crop!': bignum too big to convert into `long' (RangeError)
|
198
|
+
resimg.crop!(SouthWestGravity,@page_width,@page_height)
|
199
|
+
resimg.write("itptmp#{@link_end}"){ self.quality = 70 }
|
200
|
+
@pdf.add_image_from_file("itptmp#{@link_end}",0,0)
|
201
|
+
ss = PDF::Writer::StrokeStyle.new(2)
|
202
|
+
@pdf.stroke_style ss
|
203
|
+
for i in 1...cols
|
204
|
+
@pdf.line(i*@page_width/cols,0,
|
205
|
+
i*@page_width/cols,@page_height).stroke
|
206
|
+
end
|
207
|
+
for i in 1...rows
|
208
|
+
@pdf.line(0,i*@page_height/rows,
|
209
|
+
@page_width,i*@page_height/rows).stroke
|
210
|
+
end
|
211
|
+
for i in 0...rows
|
212
|
+
for j in 0...cols
|
213
|
+
p "adding #{i} #{j} link in front page"
|
214
|
+
p Time.now
|
215
|
+
@pdf.add_internal_link("map part #{i},#{j}",
|
216
|
+
j*@page_width/cols, @page_height-i*@page_height/rows,
|
217
|
+
(j+1)*@page_width/cols, @page_height-(i+1)*@page_height/rows)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
def save()
|
222
|
+
#@pdf.save_as("map4eeepc.pdf")
|
223
|
+
@pdf.save_as(ARGV[5])
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|