wizport 0.1.5 → 0.1.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f599ae695fa960b9e048e9f822d2abc82d7754
|
4
|
+
data.tar.gz: f767cb682c80b1183bdd84cf58933c4f9d7427a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d082abbab53dcdc6a8a26ca702356e6d4c8f6946e78b5baff9bc0055d6b1a2a7502600adb6011d6647775ad666d031ddf176b2a2295e91101cc23e4c69987d55
|
7
|
+
data.tar.gz: 89e941967dfed7fed1b37178055ed20dc2245ae8540ef75056fef5a3622fadbcc8ba07f1f551927829ad244c27a30519c1f5a934c2663671deac77e1141cf645
|
data/lib/wizport.rb
CHANGED
@@ -14,10 +14,10 @@ require "wizport/visitor"
|
|
14
14
|
require "wizport/document/rtf/element"
|
15
15
|
require "wizport/document/rtf/text"
|
16
16
|
require "wizport/document/rtf/table"
|
17
|
+
require "wizport/document/rtf/image"
|
17
18
|
require "wizport/document/rtf/document"
|
18
19
|
require "wizport/document/rtf"
|
19
20
|
|
20
|
-
|
21
21
|
require "wizport/document/pdf/element"
|
22
22
|
require "wizport/document/pdf/catalog"
|
23
23
|
require "wizport/document/pdf/pages"
|
@@ -26,7 +26,6 @@ require "wizport/document/pdf/document"
|
|
26
26
|
require "wizport/document/pdf/x_ref_tbl"
|
27
27
|
require "wizport/document/pdf/pdf_builder"
|
28
28
|
|
29
|
-
|
30
29
|
require "wizport/builder/pdf"
|
31
30
|
require "wizport/builder/rtf"
|
32
31
|
|
@@ -43,10 +43,6 @@ module Wizport
|
|
43
43
|
save file if file
|
44
44
|
end
|
45
45
|
|
46
|
-
def write(txt)
|
47
|
-
@rtf << txt
|
48
|
-
end
|
49
|
-
|
50
46
|
def text(str, styles = {:align => :left})
|
51
47
|
Wizport::Rtf::Text.new(self, str, styles)
|
52
48
|
end
|
@@ -56,8 +52,8 @@ module Wizport
|
|
56
52
|
Wizport::Rtf::Table.new(self, rows, options, &block)
|
57
53
|
end
|
58
54
|
|
59
|
-
def image
|
60
|
-
|
55
|
+
def image(file)
|
56
|
+
Wizport::Rtf::Image.new(self, file)
|
61
57
|
end
|
62
58
|
|
63
59
|
def line_break
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Wizport: A gem for creating reports by specifying columns, groups, styles, etc.
|
4
|
+
# Copyright 2012 by sgzhe@163.com
|
5
|
+
|
6
|
+
module Wizport
|
7
|
+
module Rtf
|
8
|
+
class Image < Element
|
9
|
+
JPEG_SOF_BLOCKS = [0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF]
|
10
|
+
PIC_TYPE = {png: :pngblip, jpg: :jpegblip, bmp: :pngblip, gif: :pngblip}
|
11
|
+
|
12
|
+
def initialize(rtf, file)
|
13
|
+
super(rtf)
|
14
|
+
begin
|
15
|
+
@io = IO.binread(file)
|
16
|
+
rescue Exception => e
|
17
|
+
STDERR.puts "** error parsing #{file}: #{e.inspect}"
|
18
|
+
return
|
19
|
+
end
|
20
|
+
@width, @height = self.size
|
21
|
+
group do
|
22
|
+
cmd '*'
|
23
|
+
cmd 'shppict'
|
24
|
+
group do
|
25
|
+
cmd :pict
|
26
|
+
cmd PIC_TYPE[@type]
|
27
|
+
cmd :picscalex, 99
|
28
|
+
cmd :picscaley, 99
|
29
|
+
cmd :picw, @width
|
30
|
+
cmd :pich, @height
|
31
|
+
write "\n"
|
32
|
+
@io.each_byte do |b|
|
33
|
+
hex_str = b.to_s(16)
|
34
|
+
hex_str.insert(0,'0') if hex_str.length == 1
|
35
|
+
write hex_str
|
36
|
+
end
|
37
|
+
write "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def type
|
44
|
+
png = Regexp.new("\x89PNG".force_encoding("binary"))
|
45
|
+
jpg = Regexp.new("\xff\xd8\xff\xe0\x00\x10JFIF".force_encoding("binary"))
|
46
|
+
jpg2 = Regexp.new("\xff\xd8\xff\xe1(.*){2}Exif".force_encoding("binary"))
|
47
|
+
|
48
|
+
@type = case @io
|
49
|
+
when /^GIF8/
|
50
|
+
:gif
|
51
|
+
when /^#{png}/
|
52
|
+
:png
|
53
|
+
when /^#{jpg}/
|
54
|
+
:jpg
|
55
|
+
when /^#{jpg2}/
|
56
|
+
:jpg
|
57
|
+
when /^BM/
|
58
|
+
:bmp
|
59
|
+
else
|
60
|
+
:unknown
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def size
|
65
|
+
case self.type
|
66
|
+
when :gif
|
67
|
+
@io[6..10].unpack('SS')
|
68
|
+
when :png
|
69
|
+
@io[16..24].unpack('NN')
|
70
|
+
when :bmp
|
71
|
+
d = @io[14..28]
|
72
|
+
d.unpack('C')[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
|
73
|
+
when :jpg
|
74
|
+
d = StringIO.new(@io)
|
75
|
+
section_marker = 0xff # Section marker.
|
76
|
+
d.seek(2) # Skip the first two bytes of JPEG identifier.
|
77
|
+
loop do
|
78
|
+
marker, code, length = d.read(4).unpack('CCn')
|
79
|
+
fail "JPEG marker not found!" if marker != section_marker
|
80
|
+
if JPEG_SOF_BLOCKS.include?(code)
|
81
|
+
#@bits, @height, @width, @channels = d.read(6).unpack("CnnC")
|
82
|
+
return d.read(6).unpack('CnnC')[1..2].reverse
|
83
|
+
end
|
84
|
+
d.seek(length - 2, IO::SEEK_CUR)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/lib/wizport/version.rb
CHANGED
@@ -7,6 +7,10 @@ describe Wizport::Rtf::Document do
|
|
7
7
|
it "a simple example of Rtf" do
|
8
8
|
rtf = Wizport::Rtf::Document.new do
|
9
9
|
text "学生综合素质评价", :align => :center, 'font-size' => 48
|
10
|
+
image('h:\f.gif')
|
11
|
+
image('h:\ua.bmp')
|
12
|
+
image('h:\eahey.jpg')
|
13
|
+
image('h:\eahey.png')
|
10
14
|
page_break
|
11
15
|
text "ss"
|
12
16
|
table [[{content:'e',rowspan:4},{content:'4',rowspan:4},1,{content:'1',colspan:2}],
|
@@ -14,6 +18,8 @@ describe Wizport::Rtf::Document do
|
|
14
18
|
add_row [1]
|
15
19
|
end
|
16
20
|
|
21
|
+
|
22
|
+
|
17
23
|
#table [["姓名", "person.name", "性别", {content: "{Core::Person::GENDER_TYPE[person.gender]}", colspan: 3}, "出生日期", {content: "nil}", colspan: 2}, {content: "一寸照片", colspan: 2, rowspan: 3}],
|
18
24
|
# ["民族", {content: "{Core}", colspan: 2}, "入队(团)时间", {content: '', colspan: 5}],
|
19
25
|
# ["家庭住址", {content: "person", colspan: 8}]]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wizport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- songgz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/wizport/document/rtf.rb
|
84
84
|
- lib/wizport/document/rtf/document.rb
|
85
85
|
- lib/wizport/document/rtf/element.rb
|
86
|
+
- lib/wizport/document/rtf/image.rb
|
86
87
|
- lib/wizport/document/rtf/spec.rb
|
87
88
|
- lib/wizport/document/rtf/table.rb
|
88
89
|
- lib/wizport/document/rtf/text.rb
|