ydocx 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/lib/ydocx/parser.rb +31 -21
  3. data/lib/ydocx.rb +1 -1
  4. metadata +5 -5
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.1 / 07.05.2012
2
+
3
+ * Added "a", "pic" namespace for image parse
4
+
1
5
  === 1.1.0 / 04.05.2012
2
6
 
3
7
  * Fixed bug for HTML ref of subscript
data/lib/ydocx/parser.rb CHANGED
@@ -145,27 +145,37 @@ module YDocx
145
145
  nil # default no block element
146
146
  end
147
147
  def parse_image(r)
148
- if pict = r.xpath('w:pict') and
149
- shape = pict.xpath('v:shape') and
150
- image = shape.xpath('v:imagedata').first
151
- if image and id = image['id'] # r:id
152
- @rel.xpath('/').children.each do |element|
153
- element.children.each do |rel|
154
- if rel['Id'] == id and rel['Target']
155
- target = rel['Target']
156
- source = id.downcase + '/'
157
- if defined? Magick::Image and
158
- ext = File.extname(target).match(/\.wmf$/).to_a[0]
159
- source << File.basename(target, ext) + '.png'
160
- else
161
- source << File.basename(target)
162
- end
163
- @pictures << {
164
- :origin => target,
165
- :source => source
166
- }
167
- return markup :img, [], {:src => source}
148
+ id = nil
149
+ additional_namespaces = {
150
+ 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main',
151
+ 'xmlns:pic' => 'http://schemas.openxmlformats.org/drawingml/2006/picture'
152
+ }
153
+ ns = r.namespaces.merge additional_namespaces
154
+ paths = {
155
+ :id => '//w:pict//v:shape//v:imagedata',
156
+ :embed => '//w:drawing//wp:anchor//a:graphic//a:graphicData//pic:pic//pic:blipFill//a:blip'
157
+ }.each do |attr, path|
158
+ if image = r.xpath(path, ns) and !image.empty?
159
+ id = image.first[attr.to_s]
160
+ end
161
+ end
162
+ if id
163
+ @rel.xpath('/').children.each do |element|
164
+ element.children.each do |rel|
165
+ if rel['Id'] == id and rel['Target']
166
+ target = rel['Target']
167
+ source = id.downcase + '/'
168
+ if defined? Magick::Image and
169
+ ext = File.extname(target).match(/\.wmf$/).to_a[0]
170
+ source << File.basename(target, ext) + '.png'
171
+ else
172
+ source << File.basename(target)
168
173
  end
174
+ @pictures << {
175
+ :origin => target,
176
+ :source => source
177
+ }
178
+ return markup :img, [], {:src => source}
169
179
  end
170
180
  end
171
181
  end
@@ -194,7 +204,7 @@ module YDocx
194
204
  content << optional_replace(code)
195
205
  pos += 1
196
206
  end
197
- unless r.xpath('w:pict').empty?
207
+ if !r.xpath('w:pict').empty? or !r.xpath('w:drawing').empty?
198
208
  content << parse_image(r)
199
209
  end
200
210
  end
data/lib/ydocx.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  require 'ydocx/document'
5
5
 
6
6
  module YDocx
7
- VERSION = '1.1.0'
7
+ VERSION = '1.1.1'
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ydocx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &11444240 !ruby/object:Gem::Requirement
16
+ requirement: &13563740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11444240
24
+ version_requirements: *13563740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &11443820 !ruby/object:Gem::Requirement
27
+ requirement: &13563320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11443820
35
+ version_requirements: *13563320
36
36
  description: ''
37
37
  email:
38
38
  - yasaka@ywesee.com, zdavatz@ywesee.com