rrtf 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc70901e84aadb460e92e00edce17a81a70cd993
4
- data.tar.gz: 9cbfde57e949d1479bf77b7f0773d9502a4436e9
3
+ metadata.gz: 4696bbf7c9772c7cf36a9fa33e10d2c5ddb0b60e
4
+ data.tar.gz: cb8b674323d9ad87c4d75386994c8554c956ef5b
5
5
  SHA512:
6
- metadata.gz: 01d07f75d2b50486c3e55174e10dff2954e235ce6c999be4b8a9d6abb1d5904df7c7a6578c9cebc3606d7ad59fd829031e3d5210233d1d172dd56b1a8cf6bb33
7
- data.tar.gz: 0a74b57a08c94e549579b21196109718c3e2eac0fb042c760f3820224a21898e249997e4483ce2511cbccdc90527c7484c464c5755282768fc2fd574f3c1ba30
6
+ metadata.gz: '0827d3f9ce0bfb0c9e92efa91e0ef6dbfff0bc0008801d377ca261472baa3b5ab2854d2366ec8a82fd77d422cccae58db2b8533e8d2f94ae528ea73987172f8a'
7
+ data.tar.gz: 05eb44acdc466d1e1fd3a27669fcde7a2a65a09e07ebc7e678394551a3f10a8003d46a47c6dca281b449405fd0e0d777ee096ae1e4277efab11ddce5131f9901
data/CHANGELOG.md CHANGED
@@ -22,3 +22,8 @@ _Version 1.0.0:_
22
22
  - Add BorderFormatting module and BorderStyle class to allow border definition on paragraphs and images.
23
23
  - Add ShadingFormatting module and ShadingStyle class to allow paragraph shading.
24
24
  - Add ShapeNode class to implement basic shapes.
25
+
26
+ _Version 1.0.1:_
27
+
28
+ - Allow remote source for images with open-uri.
29
+ - Fix issue with setting "text_margin" for text boxes.
data/examples/08.rtf CHANGED
@@ -7,11 +7,11 @@
7
7
  \red255\green0\blue0;
8
8
  }
9
9
  {\info
10
- {\createim\yr2017\mo7\dy30\hr23\min44}
10
+ {\createim\yr2017\mo8\dy1\hr11\min6}
11
11
  }
12
12
 
13
13
  \hyphauto1\paperw12247\paperh15819\margl1440\margr1440\margt1440\margb1440
14
- {\pict \box\brdrdot\brdrw100\brsp240\brdrcf1\picwgoal2880\pichgoal2880\picw500\pich500\bliptag3007171\pngblip
14
+ {\pict \box\brdrdot\brdrw100\brsp240\brdrcf1\picwgoal2880\pichgoal2880\picw500\pich500\bliptag0108171\pngblip
15
15
  89504e470d0a1a0a0000000d49484452000001f4000001f40806000000cbd6df8a00000009704859
16
16
  73000016250000162501495224f00000200049444154785eec5d077c5455f6fe26939e50549a2288
17
17
  8282aeae2b56545ceb2a8a34459705114511e952a45705040ba0880a289d208a8a7f51b161050545
data/examples/09.rtf CHANGED
@@ -7,7 +7,7 @@
7
7
  \red255\green255\blue255;
8
8
  }
9
9
  {\info
10
- {\createim\yr2017\mo7\dy31\hr20\min2}
10
+ {\createim\yr2017\mo8\dy1\hr11\min8}
11
11
  }
12
12
 
13
13
  \hyphauto1\paperw12247\paperh15819\margl1440\margr1440\margt1440\margb1440
@@ -22,10 +22,6 @@
22
22
  {\sp{\sn fFilled}{\sv 1}}
23
23
  {\sp{\sn fillColor}{\sv 13421772}}
24
24
  {\sp{\sn fLine}{\sv 0}}
25
- {\sp{\sn geoLeft}{\sv 0}}
26
- {\sp{\sn geoTop}{\sv 0}}
27
- {\sp{\sn geoRight}{\sv 30000}}
28
- {\sp{\sn geoBottom}{\sv 30000}}
29
25
  {\sp{\sn fLineOK}{\sv 1}}
30
26
  {\sp{\sn fFillOK}{\sv 1}}
31
27
  {\sp{\sn f3DOK}{\sv 1}}
@@ -43,10 +39,10 @@
43
39
  {\sp{\sn fLine}{\sv 1}}
44
40
  {\sp{\sn lineColor}{\sv 0}}
45
41
  {\sp{\sn lineWidth}{\sv 38100}}
46
- {\sp{\sn geoLeft}{\sv 0}}
47
- {\sp{\sn geoTop}{\sv 0}}
48
- {\sp{\sn geoRight}{\sv 30000}}
49
- {\sp{\sn geoBottom}{\sv 30000}}
42
+ {\sp{\sn dxTextLeft}{\sv 457200}}
43
+ {\sp{\sn dxTextRight}{\sv 457200}}
44
+ {\sp{\sn dyTextTop}{\sv 457200}}
45
+ {\sp{\sn dyTextBottom}{\sv 457200}}
50
46
  {\sp{\sn fLineOK}{\sv 1}}
51
47
  {\sp{\sn fFillOK}{\sv 1}}
52
48
  {\sp{\sn f3DOK}{\sv 1}}
@@ -72,11 +68,11 @@ red
72
68
  {\sp{\sn lineColor}{\sv 10027008}}
73
69
  {\sp{\sn geoLeft}{\sv 0}}
74
70
  {\sp{\sn geoTop}{\sv 0}}
75
- {\sp{\sn geoRight}{\sv 30000}}
76
- {\sp{\sn geoBottom}{\sv 30000}}
77
- {\sp{\sn pVerticies}{\sv 8;6;(0,0);(20000,0);(30000,0);(30000,15000);(30000,30000);(0,0)}}
71
+ {\sp{\sn geoRight}{\sv 21600}}
72
+ {\sp{\sn geoBottom}{\sv 21600}}
73
+ {\sp{\sn pVerticies}{\sv 8;6;(0,0);(14400,0);(21600,0);(21600,10800);(21600,21600);(0,0)}}
78
74
  {\sp{\sn pSegmentInfo}{\sv 2;6;16384;1;8193;1;24577;32768}}
79
- {\sp{\sn pConnectionSites}{\sv 8;4;(0,0);(20000,0);(30000,30000);(0,0)}}
75
+ {\sp{\sn pConnectionSites}{\sv 8;4;(0,0);(14400,0);(21600,21600);(0,0)}}
80
76
  {\sp{\sn fLineOK}{\sv 1}}
81
77
  {\sp{\sn fFillOK}{\sv 1}}
82
78
  {\sp{\sn f3DOK}{\sv 1}}
@@ -23,7 +23,8 @@ rtf.geometry(
23
23
  "width" => "3in",
24
24
  "height" => "3in",
25
25
  "horizontal_reference" => "PAGE",
26
- "vertical_reference" => "PAGE"
26
+ "vertical_reference" => "PAGE",
27
+ "text_margin" => "0.5in"
27
28
  ) do |box|
28
29
  box.paragraph("foreground_color" => '#ffffff') do |p|
29
30
  p << "Should you ever find yourself on a spacefaring vessel wearing a "
@@ -1,4 +1,5 @@
1
1
  require 'fastimage'
2
+ require 'open-uri'
2
3
 
3
4
  module RRTF
4
5
  # This class represents an image within a RTF document. Currently only the
@@ -60,7 +61,7 @@ module RRTF
60
61
  # This is the constructor for the ImageNode class.
61
62
  #
62
63
  # @param parent [Node] a reference to the node that owns the new image node.
63
- # @param source [String, File] a reference to the image source; this must be a String or a File.
64
+ # @param source [String, File] a reference to the image source; this must be a String, String URL, or a File.
64
65
  # @param id [Integer] a unique 32-bit identifier for the image.
65
66
  # @param options [Hash] a hash of options.
66
67
  # @option options [String] "width" (nil) the display width of the image in twips (can be a string, see {Utilities.value2twips}).
@@ -72,7 +73,7 @@ module RRTF
72
73
  # specified source does not exist or cannot be accessed.
73
74
  def initialize(parent, source, id, options = {})
74
75
  super(parent)
75
- @source = nil
76
+ @source = source
76
77
  @id = id
77
78
 
78
79
  # load default options
@@ -95,16 +96,19 @@ module RRTF
95
96
  end
96
97
 
97
98
  # Store path to image.
98
- @source = source if source.instance_of?(String) || source.instance_of?(Tempfile)
99
- @source = source.path if source.instance_of?(File)
99
+ if @source.is_a?(String)
100
+ begin
101
+ @source = open(@source)
102
+ rescue OpenURI::HTTPError => error
103
+ response = error.io
104
+ RTFError.fire("Could not open '#{@source}'. Server responded with #{response.status.join(',')}.")
105
+ rescue Exception => error
106
+ RTFError.fire("Could not open '#{@source}'. #{error.message}.")
107
+ end # rescue block
108
+ elsif !@source.respond_to?(:each_byte)
109
+ RTFError.fire("A string or object that responds to :each_byte must be supplied - '#{@source}' given.")
110
+ end # unless
100
111
 
101
- # Check the file's existence and accessibility.
102
- if !File.exist?(@source)
103
- RTFError.fire("Unable to find the #{File.basename(@source)} file.")
104
- end
105
- if !File.readable?(@source)
106
- RTFError.fire("Access to the #{File.basename(@source)} file denied.")
107
- end
108
112
  # Attempt to determine image type and dimensions.
109
113
  @type, @width, @height = self.class.inspect(@source)
110
114
  if @type.nil?
@@ -128,18 +132,16 @@ module RRTF
128
132
  text << "\\picw#{@width}\\pich#{@height}\\bliptag#{@id}"
129
133
  text << "\\#{@type}\n"
130
134
 
131
- open_file do |file|
132
- file.each_byte do |byte|
133
- hex_str = byte.to_s(16)
134
- hex_str.insert(0,'0') if hex_str.length == 1
135
- text << hex_str
136
- count += 1
137
- if count == 40
138
- text << "\n"
139
- count = 0
140
- end # if
141
- end # each_byte
142
- end # open_file
135
+ @source.each_byte do |byte|
136
+ hex_str = byte.to_s(16)
137
+ hex_str.insert(0,'0') if hex_str.length == 1
138
+ text << hex_str
139
+ count += 1
140
+ if count == 40
141
+ text << "\n"
142
+ count = 0
143
+ end # if
144
+ end # each_byte
143
145
  text << "\n}"
144
146
 
145
147
  text.string
@@ -162,14 +164,6 @@ module RRTF
162
164
  [(@width*scale_factor).to_i, (@height*scale_factor).to_i]
163
165
  end
164
166
  end # case
165
- end
166
-
167
- def open_file(&block)
168
- if block
169
- File.open(@source, 'rb', &block)
170
- else
171
- File.open(@source, 'rb')
172
- end # if
173
- end # open_file()
167
+ end # size_image()
174
168
  end # End of the ImageNode class.
175
169
  end # module RRTF
@@ -320,10 +320,10 @@ module RRTF
320
320
  next if margin.nil?
321
321
 
322
322
  margin = Page::Margin.new(margin)
323
- left = Utilities.value2emu(margin.left+'twip')
324
- right = Utilities.value2emu(margin.right+'twip')
325
- top = Utilities.value2emu(margin.top+'twip')
326
- bottom = Utilities.value2emu(margin.bottom+'twip')
323
+ left = Utilities.value2emu("#{margin.left}twip")
324
+ right = Utilities.value2emu("#{margin.right}twip")
325
+ top = Utilities.value2emu("#{margin.top}twip")
326
+ bottom = Utilities.value2emu("#{margin.bottom}twip")
327
327
 
328
328
  instance_variable_set("@#{margin_attr}", margin)
329
329
  instance_variable_set("@#{margin_attr}_left", left)
data/lib/rrtf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RRTF
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrtf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Hileman