Skip to content
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

Issue 74b: IABookreader, please cooperate with old friend PDF? #83

Merged
merged 7 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/mirador_strawberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
//@TODO add an extra Manifests key with every other one so people can select the others.
var miradorInstance = Mirador.viewer($options);
console.log('initializing Mirador 3.0.0-beta.4')
console.log('initializing Mirador 3.0.0-RC3')
}
})}}
})(jQuery, Drupal, drupalSettings, window.Mirador);
97 changes: 77 additions & 20 deletions js/plugin.iiif-iabookreader_strawberry.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,56 @@ BookReader.prototype.parseSequence = function (sequenceId) {
var tmpdata = [];
jQuery.each(self.IIIFsequence.imagesList, function(index,image) {
var imageuri = null;
var infojson = null;

// If serviceURL is null then we can not call infoJSON which also means, if width and height are not
// present, render will fail
// Options we have here
// If either width or height is missing, use canvas ratio, which will have to require if all fails then simply
// use the default 4:3 and log into console so the user/admin/webmaster knows this is happening
// Example of what can happen with Service Level 0 and no correct dimensions
/*
aspectRatio: Infinity // HAHAHA
canvasHeight: 4
canvasWidth: 3
height: 0
imageGetArgument: "?page=2"
imageUrl: "http://localhost:8183/iiif/2/65f%2Fapplication-williams-college-yearbook-01-d708c989-229b-4ba9-a547-ed2faf568e0f.pdf/full/full/0/default.jpg…"
serviceUrl: null
width: 800
*/

if (image.width == 0 || image.width == null) {
if ((image.canvasWidth != 0 && image.canvasWidth != null) &&
(image.canvasHeight != 0 && image.canvasHeight != null)
) {
// We have a full ration
var aspectRatio = (image.canvasWidth / image.canvasHeight) || 0.75;
image.width = Math.round(image.height * aspectRatio);
} else {
console.log('canvas is incorrect and has no ratio for ' + image.imageUrl);
console.log('usign a fallback of 3:4, please correct your manifest');
image.width = Math.round(image.height * 0.75);
}
} else if (image.height == 0 || image.height == null) {
if ((image.canvasWidth != 0 && image.canvasWidth != null) &&
(image.canvasHeight != 0 && image.canvasHeight != null)
) {
// We have a full ration
var aspectRatio = (image.canvasWidth / image.canvasHeight) || 0.75;
image.height = Math.round(image.width / aspectRatio);
} else {
image.height = Math.round(image.width / 0.75);
console.log('canvas is incorrect and has no ratio for ' + image.imageUrl);
console.log('usign a fallback of 3:4, please correct your manifest');
}
}

// infojson will be empty if service URL is empty

if (image.serviceUrl != null) {
// Pass also the imageGerArgument to the info.json -- Cantaloupe 4.1.6
infojson = image.serviceUrl + "/info.json" + image.imageGetArgument;
imageuri = image.serviceUrl + "/full/" + image.width + ",/0/default.jpg" + image.imageGetArgument;
} else {
imageuri = image.imageUrl;
Expand All @@ -112,10 +161,11 @@ BookReader.prototype.parseSequence = function (sequenceId) {
height: image.height,
uri: imageuri,
pageNum: index+1,
infojson: image.serviceUrl + "/info.json",
infojson: infojson,
});
});
self.options.data.push(tmpdata);

delete self.jsonLd;

function getImagesList(sequence) {
Expand Down Expand Up @@ -291,28 +341,35 @@ BookReader.prototype.getRemoteInfoJson = function(index) {
var remotedimensions = {};

var infojsonurl = this.getPageProp(index, 'infojson');
if (infojsonurl == null) {
console.log('Service Level 0, Defaulting to fixed Dimensions ' + self.options.maxWidth + ' px')
console.log(this.getPageProp(index, 'width'));
console.log(this.getPageProp(index, 'height'));
remotedimensions.width = self.options.maxWidth;
remotedimensions.height = self.options.maxWidth;
} else {
jQuery.ajax({
url: infojsonurl.replace(/^\s+|\s+$/g, ''),
dataType: 'json',
async: false,
success: function (infojson) {
remotedimensions.width = infojson.width;
remotedimensions.height = infojson.height;

jQuery.ajax({
url: infojsonurl.replace(/^\s+|\s+$/g, ''),
dataType: 'json',
async: false,
success: function (infojson) {
remotedimensions.width = infojson.width;
remotedimensions.height = infojson.height;

},

error: function () {
console.log('Failed loading ' + infojsonurl);
// default to our only known number
// Chances whole manifest is wrong
console.log('Defaulting to fixed Dimensions ' + self.options.maxWidth + ' px')
remotedimensions.width = self.options.maxWidth;
remotedimensions.height = self.options.maxWidth;
}
},

error: function () {
console.log('Failed loading ' + infojsonurl);
// default to our only known number
// Chances whole manifest is wrong
console.log('Defaulting to fixed Dimensions ' + self.options.maxWidth + ' px')
remotedimensions.width = self.options.maxWidth;
remotedimensions.height = self.options.maxWidth;
}


});
});
}

return remotedimensions;
}