aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-12-06 15:39:16 +0000
committerMichael Williamson <mike@zwobble.org>2015-12-06 15:39:16 +0000
commit9878af20ba8c637853308323dab3e06c8ebbfed4 (patch)
tree56a9f5f7b229b0aab201e4aae3b0bb24cf43f4c0 /lib
parent647b99931c20f1ba145ad8638707f53c2c76274a (diff)
Split up image reading into separate functions
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/body-reader.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index c5d9b02..d6a20b0 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -218,22 +218,37 @@ function BodyReader(options) {
}
function readBlip(element, blip) {
+ var altText = element.first("wp:docPr").attributes.descr;
+ return readImage(findBlipImageFile(blip), altText);
+ }
+
+ function findBlipImageFile(blip) {
var embedRelationshipId = blip.attributes["r:embed"];
var linkRelationshipid = blip.attributes["r:link"];
- var imagePath;
- var readImage;
if (embedRelationshipId) {
- imagePath = joinZipPath("word", relationships[embedRelationshipId].target);
- readImage = docxFile.read.bind(docxFile, imagePath);
+ return findEmbeddedImageFile(embedRelationshipId);
} else {
- imagePath = relationships[linkRelationshipid].target;
- readImage = files.read.bind(files, imagePath);
+ var imagePath = relationships[linkRelationshipid].target;
+ return {
+ path: imagePath,
+ read: files.read.bind(files, imagePath)
+ };
}
- var altText = element.first("wp:docPr").attributes.descr;
- var contentType = contentTypes.findContentType(imagePath);
+ }
+
+ function findEmbeddedImageFile(relationshipId) {
+ var path = joinZipPath("word", relationships[relationshipId].target);
+ return {
+ path: path,
+ read: docxFile.read.bind(docxFile, path)
+ };
+ }
+
+ function readImage(imageFile, altText) {
+ var contentType = contentTypes.findContentType(imageFile.path);
var image = documents.Image({
- readImage: readImage,
+ readImage: imageFile.read,
altText: altText,
contentType: contentType
});