wiz_rtf 0.5.5 → 0.6.0

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: 5bdfb9f57957a4df13b3a1868ebae1e08fffb311
4
- data.tar.gz: b9c674c3b322a70f1cbeb4e9edf2bb2f8a8d1ffa
3
+ metadata.gz: 750294995f94f17825b1d378fdad60a6adb2bfaf
4
+ data.tar.gz: e1cddfe7fb6e8365ef0d32e03749c2efcd4e3e98
5
5
  SHA512:
6
- metadata.gz: 47a68b671a2a4b6d1ea99286bf0b2fdfbc5b10940739f0a6341ceaa84c0017219086044b82a929caf124874ce02e875c54aa68c23b0ef9aaf44c62aee475942c
7
- data.tar.gz: 54ffa1244939ebce8a17ed3da0053a0e1162ae7ba7963965433b97273b7a3567d2e1e797960b0b985c34a3b73f7c11b0980ae6b7102fe8b922a9055df3244042
6
+ metadata.gz: ca22e903392cf22fb1c17fe9ac2e44e8701f1e7850d71a6d7a6f8202659521c67bb19884083387d5693203e2b644da5e520b955e0c8f8bea7bdd40f7af98a962
7
+ data.tar.gz: 721f1d84373e322543bc94ec831c6ca616c81293fad2fcb99e340d72e3e64afb2bb52ab2fc58ea6098fe732d384eff708b1054923ad2f21812f48ada0e7311ce
data/README.md CHANGED
@@ -21,11 +21,11 @@ Or install it yourself as:
21
21
  ## Usage
22
22
  ```ruby
23
23
  doc = WizRtf::Document.new do
24
- text "学生综合素质报告", :align => :center, 'font-size' => 48
24
+ text "学生综合素质报告", 'text-align' => :center, 'font-family' => 'Microsoft YaHei', 'font-size' => 48, 'font-bold' => true, 'font-italic' => true, 'font-underline' => true
25
25
  image('h:\eahey.png')
26
26
  page_break
27
- text "A Table Demo"
28
- table [[{content:'e',rowspan:4},{content:'4',rowspan:4},1,{content:'1',colspan:2}],
27
+ text "A Table Demo", 'foreground-color' => WizRtf::Color::RED, 'background-color' => '#0f00ff'
28
+ table [[{content: WizRtf::Image.new('h:\eahey.png'),rowspan:4},{content:'4',rowspan:4},1,{content:'1',colspan:2}],
29
29
  [{content:'4',rowspan:3,colspan:2},8],[11]], column_widths:{1=>100,2 => 100,3 => 50,4 => 50,5 => 50} do
30
30
  add_row [1]
31
31
  end
data/lib/wiz_rtf/color.rb CHANGED
@@ -7,10 +7,48 @@
7
7
  module WizRtf
8
8
  class Color
9
9
 
10
- def initialize(red, green, blue)
11
- @red = red
12
- @green = green
13
- @blue = blue
10
+ RED = '#FF0000'
11
+ YELLOW = '#FFFF00'
12
+ LIME = '#00FF00'
13
+ CYAN = '#00FFFF'
14
+ BLUE = '#0000FF'
15
+ MAGENTA = '#FF00FF'
16
+ MAROON = '#800000'
17
+ OLIVE = '#808000'
18
+ GREEN = '#008000'
19
+ TEAL = '#008080'
20
+ NAVY = '#000080'
21
+ PURPLE = '#800080'
22
+ WHITE = '#FFFFFF'
23
+ SILVER = '#C0C0C0'
24
+ GRAY = '#808080'
25
+ BLACK = '#000000'
26
+
27
+ def initialize(*rgb)
28
+ case rgb.size
29
+ when 1
30
+ from_rgb_hex(rgb.first)
31
+ when 3
32
+ from_rgb(*rgb)
33
+ end
34
+ end
35
+
36
+ def from_rgb_hex(color)
37
+ color = '#%.6x' % color if color.is_a? Integer
38
+ rgb = color[1,7].scan(/.{2}/).map{ |c| c.to_i(16) }
39
+ from_rgb(*rgb)
40
+ end
41
+
42
+ def from_rgb(*rgb)
43
+ @red, @green, @blue = rgb
44
+ end
45
+
46
+ def to_rgb
47
+ [@red, @green, @blue]
48
+ end
49
+
50
+ def to_rgb_hex
51
+ "#" + to_rgb.map {|c| "%02X" % c }.join
14
52
  end
15
53
 
16
54
  def render(io)
@@ -20,5 +58,6 @@ module WizRtf
20
58
  io.cmd :blue, @blue
21
59
  end
22
60
  end
61
+
23
62
  end
24
63
  end
@@ -10,28 +10,38 @@ module WizRtf
10
10
  @fonts = []
11
11
  @colors = []
12
12
  @parts = []
13
- font 0, 'fswiss', 'Arial', 0, 2
14
- font 1, 'fmodern', 'Courier New', 0, 1
15
- font 2, 'fnil', '宋体', 2, 2
16
- color 0, 0, 0
17
- color 255, 0, 0
18
- color 255, 0, 255
13
+ font 'Courier New'
19
14
  block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
20
15
  end
21
16
 
22
- def head
23
-
17
+ def head(&block)
18
+ block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
24
19
  end
25
20
 
26
- def font(num, family, name, character_set = 0, prq = 2)
27
- @fonts << WizRtf::Font.new(num, family, name, character_set, prq)
21
+ def font(name, family = nil, character_set = 0, prq = 2)
22
+ unless index = @fonts.index {|f| f.name == name}
23
+ index = @fonts.size
24
+ opts = WizRtf::Font::FONTS.detect {|f| f[:name] == name}
25
+ @fonts << WizRtf::Font.new(index, opts[:name], opts[:family], opts[:character], opts[:prq])
26
+ end
27
+ index
28
28
  end
29
29
 
30
- def color(red, green, blue)
31
- @colors << WizRtf::Color.new(red, green, blue)
30
+ def color(*rgb)
31
+ color = WizRtf::Color.new(*rgb)
32
+ if index = @colors.index {|c| c.to_rgb_hex == color.to_rgb_hex}
33
+ index += 1
34
+ else
35
+ @colors << color
36
+ index = @colors.size
37
+ end
38
+ index
32
39
  end
33
40
 
34
- def text(str, styles = {:align => :left})
41
+ def text(str, styles = {})
42
+ styles['foreground-color'] = color(styles['foreground-color']) if styles['foreground-color']
43
+ styles['background-color'] = color(styles['background-color']) if styles['background-color']
44
+ styles['font-family'] = font(styles['font-family']) if styles['font-family']
35
45
  @parts << WizRtf::Text.new(str, styles)
36
46
  end
37
47
 
data/lib/wiz_rtf/font.rb CHANGED
@@ -6,9 +6,60 @@
6
6
 
7
7
  module WizRtf
8
8
  class Font
9
- def initialize(num, family, name, character_set = 0, prq = 2)
9
+ FAMILIES = {
10
+ default: 'fnil',
11
+ roman: 'froman',
12
+ swiss: 'fswiss',
13
+ fixed_pitch: 'fmodern',
14
+ script: 'fscript',
15
+ decorative: 'fdecor',
16
+ technical: 'ftech',
17
+ bidirectional: 'fbidi'
18
+ }
19
+
20
+ CHARACTER_SET = {
21
+ ansi: 0,
22
+ default: 1,
23
+ symbol: 2,
24
+ invalid: 3,
25
+ mac: 77,
26
+ shiftJis: 128,
27
+ hangul: 129,
28
+ johab: 130,
29
+ gb2312: 134,
30
+ big5: 136,
31
+ greek: 161,
32
+ turkish: 162,
33
+ vietnamese: 163,
34
+ hebrew: 177,
35
+ arabic: 178,
36
+ arabicTraditional: 179,
37
+ arabic_user: 180,
38
+ hebrew_user: 181,
39
+ baltic: 186,
40
+ russian: 204,
41
+ thai: 222,
42
+ eastern_european: 238,
43
+ pc437: 254,
44
+ oem: 255
45
+ }
46
+
47
+ FONTS = [
48
+ {family:'fswiss', name:'Arial', character:0, prq:2},
49
+ {family:'froman', name:'Courier New', character:0, prq:1},
50
+ {family:'froman', name:'Times New Roman', character:0, prq:2},
51
+ {family:'fnil', name:'SimSun', character:134, prq:2},
52
+ {family:'fmodern', name:'KaiTi', character:134, prq:1},
53
+ {family:'fnil', name:'FangSong', character:134, prq:1},
54
+ {family:'fmodern', name:'SimHei', character:134, prq:1},
55
+ {family:'fmodern', name:'NSimSun', character:134, prq:1},
56
+ {family:'fswiss', name:'Microsoft YaHei', character:134, prq:2}
57
+ ]
58
+
59
+ attr_accessor :name, :num
60
+ def initialize(num, name, family = 'fnil', character_set = 0, prq = 2)
10
61
  @num = num
11
- @family = family
62
+ @family = family if family
12
63
  @name = name
13
64
  @character_set = character_set
14
65
  @prq = prq
data/lib/wiz_rtf/text.rb CHANGED
@@ -10,13 +10,14 @@ module WizRtf
10
10
 
11
11
  def initialize(str = '', styles = {})
12
12
  @str = str
13
- @styles = {'text-align' => :left, 'font-size' => 24, 'font-bold' => false, 'font-italic' => false, 'font-underline' => false, 'foreground-color' => 1, 'background-color' => 0 }.merge(styles)
13
+ @styles = {'text-align' => :left, 'font-family' => 0, 'font-size' => 24, 'font-bold' => false, 'font-italic' => false, 'font-underline' => false, 'foreground-color' => 0, 'background-color' => 0 }.merge(styles)
14
14
  end
15
15
 
16
16
  def render(io)
17
17
  io.group do
18
18
  io.cmd :pard
19
19
  io.cmd TEXT_ALIGN_MAP[@styles['text-align']]
20
+ io.cmd :f, @styles['font-family']
20
21
  io.cmd :fs, @styles['font-size']
21
22
  io.cmd @styles['font-bold'] ? 'b' : 'b0'
22
23
  io.cmd @styles['font-italic'] ? 'i' : 'i0'
@@ -1,3 +1,3 @@
1
1
  module WizRtf
2
- VERSION = "0.5.5"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiz_rtf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - songgz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler