-
Notifications
You must be signed in to change notification settings - Fork 670
Parse image dimensions #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,24 +525,37 @@ function BodyReader(options) { | |
| } | ||
|
|
||
| function readDrawingElement(element) { | ||
| var blips = element | ||
| var picture = element | ||
| .getElementsByTagName("a:graphic") | ||
| .getElementsByTagName("a:graphicData") | ||
| .getElementsByTagName("pic:pic") | ||
| var blips = picture | ||
| .getElementsByTagName("pic:blipFill") | ||
| .getElementsByTagName("a:blip"); | ||
|
|
||
| return combineResults(blips.map(readBlip.bind(null, element))); | ||
| var dimensions = | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some vendors (Microsoft, Google Docs) store image dimensions in |
||
| element.first('wp:extent') || | ||
| picture | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you implement safe nested property access in |
||
| .getElementsByTagName('pic:spPr') | ||
| .getElementsByTagName('x:xfrm') | ||
| .attributes['a:ext'] | ||
|
|
||
| return combineResults(blips.map((blip) => { | ||
| return readBlip(element, blip, dimensions) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unwrapping the map function because there's no benefit to keeping it inlined. It only confuses the argument order. |
||
| })); | ||
| } | ||
|
|
||
| function readBlip(element, blip) { | ||
| function readBlip(element, blip, dimensions) { | ||
| var properties = element.first("wp:docPr").attributes; | ||
| var altText = isBlank(properties.descr) ? properties.title : properties.descr; | ||
| var blipImageFile = findBlipImageFile(blip); | ||
| if (blipImageFile === null) { | ||
| return emptyResultWithMessages([warning("Could not find image file for a:blip element")]); | ||
| } else { | ||
| return readImage(blipImageFile, altText); | ||
| return readImage(blipImageFile, { | ||
| altText, | ||
| height: dimensions.attributes['cy'], | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Image dimensions are defined on a higher node than blips, so I assume dimensions apply to all blips. Let me know if I'm wrong in this assumption. |
||
| width: dimensions.attributes['cx'], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -586,13 +599,15 @@ function BodyReader(options) { | |
| }; | ||
| } | ||
|
|
||
| function readImage(imageFile, altText) { | ||
| function readImage(imageFile, options) { | ||
| var contentType = contentTypes.findContentType(imageFile.path); | ||
|
|
||
| var image = documents.Image({ | ||
| readImage: imageFile.read, | ||
| altText: altText, | ||
| contentType: contentType | ||
| altText: options.altText, | ||
| contentType: contentType, | ||
| height: options.height, | ||
| width: options.width | ||
| }); | ||
| var warnings = supportedImageTypes[contentType] ? | ||
| [] : warning("Image of type " + contentType + " is unlikely to display in web browsers"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm lifting up the picture node reference so we don't have to look it up multiple times. If this is premature, let me know.