nswtopo 3.0 → 3.0.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 +4 -4
- data/lib/nswtopo/chrome.rb +7 -2
- data/lib/nswtopo/formats/pdf.rb +33 -4
- data/lib/nswtopo/map.rb +6 -4
- data/lib/nswtopo/version.rb +1 -1
- data/lib/nswtopo.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbc36bc0fcdc3467aad475f9ff3757bab270bba4fe81e7bed3c34b0c34a3b4f2
|
4
|
+
data.tar.gz: fb02ea3f103222c9424bbe9f1c750caa608f73e4e5815687f40c1a383f6fa8d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a794c2eaa6949d4754c62408d6d3358ee1d84c9dcfb10a2ab90ec9833b3916a84f5873f06657b5bca4e328765848d53ff1dafb150a58e42cd15085808e1e43
|
7
|
+
data.tar.gz: 83325ab407ea8a7fcc6675cfcb747a8d1f08932d228dbdcb18fa8dec48d328a38690dcbb0766be975f03d7b872caf6e60ef0706a5429713c8a86b09df16cecaa
|
data/lib/nswtopo/chrome.rb
CHANGED
@@ -177,9 +177,14 @@ module NSWTopo
|
|
177
177
|
raise Error
|
178
178
|
end
|
179
179
|
|
180
|
-
def print_to_pdf(pdf_path)
|
180
|
+
def print_to_pdf(pdf_path, &block)
|
181
181
|
data = command("Page.printToPDF", timeout: nil, preferCSSPageSize: true).fetch("data")
|
182
|
-
|
182
|
+
pdf = Base64.decode64 data
|
183
|
+
if defined? HexaPDF
|
184
|
+
HexaPDF::Document.new(io: StringIO.new(pdf)).tap(&block).write(pdf_path.to_s)
|
185
|
+
else
|
186
|
+
pdf_path.binwrite(pdf)
|
187
|
+
end
|
183
188
|
rescue KeyError
|
184
189
|
raise Error
|
185
190
|
end
|
data/lib/nswtopo/formats/pdf.rb
CHANGED
@@ -10,7 +10,7 @@ module NSWTopo
|
|
10
10
|
|
11
11
|
REXML::Document.new(svg_path.read).tap do |xml|
|
12
12
|
xml.elements["svg"].tap do |svg|
|
13
|
-
style = "@media print { @page { margin: 0; size: %s %s; } }"
|
13
|
+
style = "@media print { @page { margin: 0 0 -1mm 0; size: %s %s; } }"
|
14
14
|
svg.add_element("style").text = style % svg.attributes.values_at("width", "height")
|
15
15
|
end
|
16
16
|
|
@@ -83,11 +83,40 @@ module NSWTopo
|
|
83
83
|
svg_path.write xml
|
84
84
|
end
|
85
85
|
|
86
|
-
FileUtils.rm pdf_path if pdf_path.exist?
|
87
86
|
log_update "chrome: rendering PDF"
|
88
|
-
|
89
87
|
Chrome.with_browser("file://#{svg_path}") do |browser|
|
90
|
-
browser.print_to_pdf
|
88
|
+
browser.print_to_pdf(pdf_path) do |doc|
|
89
|
+
bbox = [0, 0, *dimensions.times(72/25.4)]
|
90
|
+
bounds = cutline.coordinates[0][...-1].map do |coords|
|
91
|
+
coords.zip(dimensions).map { |coord, dimension| coord / dimension }
|
92
|
+
end.flatten
|
93
|
+
lpts = [0, 0].zip( [1, 1]).inject(&:product).values_at(0,1,3,2).flatten
|
94
|
+
gpts = [0, 0].zip(dimensions).inject(&:product).values_at(0,1,3,2).then do |corners|
|
95
|
+
# corners.map(&:reverse) # ISO 32000-2 specifies this, but not observed in practice
|
96
|
+
GeoJSON.multipoint(corners, projection: projection).reproject_to_wgs84.coordinates.map(&:reverse)
|
97
|
+
end.flatten
|
98
|
+
pcsm = [25.4/72, 0, 0, 0, 25.4/72, 0, 0, 0, 1, 0, 0, 0]
|
99
|
+
|
100
|
+
doc.pages.first[:VP] = [doc.add({
|
101
|
+
Type: :Viewport,
|
102
|
+
BBox: bbox,
|
103
|
+
Measure: doc.add({
|
104
|
+
Type: :Measure,
|
105
|
+
Subtype: :GEO,
|
106
|
+
Bounds: bounds,
|
107
|
+
GCS: doc.add({
|
108
|
+
Type: :PROJCS,
|
109
|
+
WKT: projection.wkt2
|
110
|
+
}),
|
111
|
+
GPTS: gpts,
|
112
|
+
LPTS: lpts,
|
113
|
+
PCSM: pcsm
|
114
|
+
})
|
115
|
+
})]
|
116
|
+
|
117
|
+
doc.trailer.info[:Creator] = "nswtopo"
|
118
|
+
doc.version = "1.7"
|
119
|
+
end
|
91
120
|
end
|
92
121
|
end
|
93
122
|
end
|
data/lib/nswtopo/map.rb
CHANGED
@@ -130,10 +130,12 @@ module NSWTopo
|
|
130
130
|
def self.from_svg(archive, svg_path)
|
131
131
|
xml = REXML::Document.new(svg_path.read)
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
133
|
+
unless false == Config["versioning"]
|
134
|
+
creator_tool = xml.elements["svg/metadata/rdf:RDF/rdf:Description[@xmp:CreatorTool]/@xmp:CreatorTool"]&.value
|
135
|
+
version = Version[creator_tool]
|
136
|
+
raise "SVG nswtopo version too old: %s" % svg_path unless version >= MIN_VERSION
|
137
|
+
raise "SVG nswtopo version too new: %s" % svg_path unless version <= VERSION
|
138
|
+
end
|
137
139
|
|
138
140
|
/^0\s+0\s+(?<width>\S+)\s+(?<height>\S+)$/ =~ xml.elements["svg[@viewBox]/@viewBox"]&.value
|
139
141
|
width && xml.elements["svg[ @width='#{ width}mm']"] || raise(Version::Error)
|
data/lib/nswtopo/version.rb
CHANGED
data/lib/nswtopo.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nswtopo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Hollingworth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|