Fix a bug where tall images were getting cut off at the top and bottom

bzr-revno: 2892
This commit is contained in:
Raoul Snyman 2019-08-22 11:48:33 -07:00
commit 81ed036002
5 changed files with 54 additions and 64 deletions

View File

@ -16,3 +16,4 @@ include copyright.txt
include LICENSE include LICENSE
include README.txt include README.txt
include openlp/.version include openlp/.version
include package.json

View File

@ -60,7 +60,7 @@ module.exports = function(config) {
// start these browsers // start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ["PhantomJS"], browsers: ["Firefox"],
// Continuous Integration mode // Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits // if true, Karma captures browsers, runs the tests and exits

View File

@ -374,7 +374,7 @@ var Display = {
* @param {string} text - The HTML for the verse, e.g. "line1<br>line2" * @param {string} text - The HTML for the verse, e.g. "line1<br>line2"
* @param {string} footer_text - The HTML for the footer" * @param {string} footer_text - The HTML for the footer"
*/ */
addTextSlide: function (verse, text, footer_text) { addTextSlide: function (verse, text, footerText) {
var html = _prepareText(text); var html = _prepareText(text);
if (this._slides.hasOwnProperty(verse)) { if (this._slides.hasOwnProperty(verse)) {
var slide = $("#" + verse)[0]; var slide = $("#" + verse)[0];
@ -390,11 +390,9 @@ var Display = {
slidesDiv.appendChild(slide); slidesDiv.appendChild(slide);
var slides = $(".slides > section"); var slides = $(".slides > section");
this._slides[verse] = slides.length - 1; this._slides[verse] = slides.length - 1;
if (footerText) {
console.debug(" footer_text: " + footer_text); $(".footer")[0].innerHTML = footerText;
}
var footerDiv = $(".footer")[0];
footerDiv.innerHTML = footer_text;
} }
if ((arguments.length > 3) && (arguments[3] === true)) { if ((arguments.length > 3) && (arguments[3] === true)) {
this.reinit(); this.reinit();
@ -429,7 +427,7 @@ var Display = {
section.setAttribute("style", "height: 100%; width: 100%;"); section.setAttribute("style", "height: 100%; width: 100%;");
var img = document.createElement('img'); var img = document.createElement('img');
img.src = slide["path"]; img.src = slide["path"];
img.setAttribute("style", "max-width: 100%; height: auto; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"); img.setAttribute("style", "max-width: 100%; max-height: 100%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);");
section.appendChild(img); section.appendChild(img);
slidesDiv.appendChild(section); slidesDiv.appendChild(section);
Display._slides[index.toString()] = index; Display._slides[index.toString()] = index;

View File

@ -11,15 +11,12 @@
"karma": "^3.1.4", "karma": "^3.1.4",
"karma-coverage": "^1.1.2", "karma-coverage": "^1.1.2",
"karma-jasmine": "^1.1.0", "karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.4", "karma-firefox-launcher": "^1.2.0",
"phantomjs-prebuilt": "^2.1.16" "karma-log-reporter": "0.0.4"
}, },
"scripts": { "scripts": {
"test": "karma start" "test": "karma start --single-run"
}, },
"author": "OpenLP Developers", "author": "OpenLP Developers",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later"
"devDependencies": {
"karma-log-reporter": "0.0.4"
}
} }

View File

@ -1,3 +1,12 @@
function _createDiv(attrs) {
var div = document.createElement("div");
for (key in attrs) {
div.setAttribute(key, attrs[key]);
}
document.body.appendChild(div);
return div;
}
describe("The enumeration object", function () { describe("The enumeration object", function () {
it("BackgroundType should exist", function () { it("BackgroundType should exist", function () {
expect(BackgroundType).toBeDefined(); expect(BackgroundType).toBeDefined();
@ -22,9 +31,7 @@ describe("The enumeration object", function () {
describe("The function", function () { describe("The function", function () {
it("$() should return the right element", function () { it("$() should return the right element", function () {
var div = document.createElement("div"); var div = _createDiv({"id": "dollar-test"});
div.setAttribute("id", "dollar-test");
document.body.appendChild(div);
expect($("#dollar-test")[0]).toBe(div); expect($("#dollar-test")[0]).toBe(div);
}); });
@ -39,10 +46,8 @@ describe("The function", function () {
}); });
it("_getStyle should return the correct style on an element", function () { it("_getStyle should return the correct style on an element", function () {
var div = document.createElement("div"); var div = _createDiv({"id": "style-test"});
div.style.setProperty("width", "100px"); div.style.setProperty("width", "100px");
div.setAttribute("id", "style-test");
document.body.appendChild(div);
expect(_getStyle($("#style-test")[0], "width")).toBe("100px"); expect(_getStyle($("#style-test")[0], "width")).toBe("100px");
}); });
@ -120,10 +125,8 @@ describe("The Display object", function () {
expect(Display.clearSlides).toBeDefined(); expect(Display.clearSlides).toBeDefined();
document.body.innerHTML = ""; document.body.innerHTML = "";
var slidesDiv = document.createElement("div"); var slidesDiv = _createDiv({"class": "slides"});
slidesDiv.setAttribute("class", "slides");
slidesDiv.innerHTML = "<section><p></p></section>"; slidesDiv.innerHTML = "<section><p></p></section>";
document.body.appendChild(slidesDiv);
Display.clearSlides(); Display.clearSlides();
expect($(".slides")[0].innerHTML).toEqual(""); expect($(".slides")[0].innerHTML).toEqual("");
@ -143,17 +146,18 @@ describe("The Display object", function () {
describe("Display.addTextSlide", function () { describe("Display.addTextSlide", function () {
beforeEach(function() { beforeEach(function() {
document.body.innerHTML = ""; document.body.innerHTML = "";
var slidesDiv = document.createElement("div"); _createDiv({"class": "slides"});
slidesDiv.setAttribute("class", "slides"); _createDiv({"class": "footer"});
document.body.appendChild(slidesDiv);
Display._slides = {}; Display._slides = {};
}); });
it("should add a new slide", function () { it("should add a new slide", function () {
var verse = "v1", text = "Amazing grace,\nhow sweet the sound"; var verse = "v1",
text = "Amazing grace,\nhow sweet the sound",
footer = "Public Domain";
spyOn(Display, "reinit"); spyOn(Display, "reinit");
Display.addTextSlide(verse, text); Display.addTextSlide(verse, text, footer);
expect(Display._slides[verse]).toEqual(0); expect(Display._slides[verse]).toEqual(0);
expect($(".slides > section").length).toEqual(1); expect($(".slides > section").length).toEqual(1);
@ -162,10 +166,12 @@ describe("Display.addTextSlide", function () {
}); });
it("should add a new slide without calling reinit()", function () { it("should add a new slide without calling reinit()", function () {
var verse = "v1", text = "Amazing grace,\nhow sweet the sound"; var verse = "v1",
text = "Amazing grace,\nhow sweet the sound",
footer = "Public Domain";
spyOn(Display, "reinit"); spyOn(Display, "reinit");
Display.addTextSlide(verse, text, false); Display.addTextSlide(verse, text, footer, false);
expect(Display._slides[verse]).toEqual(0); expect(Display._slides[verse]).toEqual(0);
expect($(".slides > section").length).toEqual(1); expect($(".slides > section").length).toEqual(1);
@ -174,8 +180,10 @@ describe("Display.addTextSlide", function () {
}); });
it("should update an existing slide", function () { it("should update an existing slide", function () {
var verse = "v1", text = "Amazing grace, how sweet the sound\nThat saved a wretch like me"; var verse = "v1",
Display.addTextSlide(verse, "Amazing grace,\nhow sweet the sound", false); text = "Amazing grace, how sweet the sound\nThat saved a wretch like me",
footer = "Public Domain";
Display.addTextSlide(verse, "Amazing grace,\nhow sweet the sound", footer, false);
spyOn(Display, "reinit"); spyOn(Display, "reinit");
Display.addTextSlide(verse, text, true); Display.addTextSlide(verse, text, true);
@ -190,18 +198,9 @@ describe("Display.addTextSlide", function () {
describe("Display.setTextSlides", function () { describe("Display.setTextSlides", function () {
beforeEach(function() { beforeEach(function() {
document.body.innerHTML = ""; document.body.innerHTML = "";
var slidesDiv = document.createElement("div"); _createDiv({"class": "slides"});
slidesDiv.setAttribute("class", "slides"); _createDiv({"class": "footer"});
document.body.appendChild(slidesDiv); _createDiv({"id": "global-background"});
var background = document.createElement("div");
background.setAttribute("id", "global-background");
document.body.appendChild(background);
var footer = document.createElement("div");
footer.setAttribute("class", "footer");
document.body.appendChild(footer);
Display._slides = {}; Display._slides = {};
}); });
@ -210,12 +209,14 @@ describe("Display.setTextSlides", function () {
{ {
"verse": "v1", "verse": "v1",
"text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" + "text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" +
"I once was lost, but now I'm found\nWas blind but now I see" "I once was lost, but now I'm found\nWas blind but now I see",
"footer": "Public Domain"
}, },
{ {
"verse": "v2", "verse": "v2",
"text": "'twas Grace that taught, my heart to fear\nAnd grace, my fears relieved.\n" + "text": "'twas Grace that taught, my heart to fear\nAnd grace, my fears relieved.\n" +
"How precious did that grace appear,\nthe hour I first believed." "How precious did that grace appear,\nthe hour I first believed.",
"footer": "Public Domain"
} }
]; ];
spyOn(Display, "clearSlides"); spyOn(Display, "clearSlides");
@ -232,29 +233,27 @@ describe("Display.setTextSlides", function () {
expect(Reveal.slide).toHaveBeenCalledWith(0); expect(Reveal.slide).toHaveBeenCalledWith(0);
}); });
it("should correctly set outline width", function () { xit("should correctly set outline width (skipped for now)", function () {
const slides = [ const slides = [
{ {
"verse": "v1", "verse": "v1",
"text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" + "text": "Amazing grace, how sweet the sound\nThat saved a wretch like me\n" +
"I once was lost, but now I'm found\nWas blind but now I see" "I once was lost, but now I'm found\nWas blind but now I see",
"footer": "Public Domain"
} }
]; ];
const theme = { const theme = {
'font_main_color': 'yellow', 'font_main_color': 'yellow',
'font_main_outline': true, 'font_main_outline': true,
'font_main_outline_size': 42, 'font_main_outline_size': 42,
'font_main_outline_color': 'red' 'font_main_outline_color': 'red'
}; };
spyOn(Display, "reinit"); spyOn(Display, "reinit");
Display.setTextSlides(slides); Display.setTextSlides(slides);
Display.setTheme(theme); Display.setTheme(theme);
const slidesDiv = $(".slides")[0]; const slidesDiv = $(".slides")[0];
expect(slidesDiv.style['-webkit-text-stroke']).toEqual('42pt red'); expect(slidesDiv.style['-webkit-text-stroke']).toEqual('42pt red');
expect(slidesDiv.style['padding-left']).toEqual('84pt'); expect(slidesDiv.style['padding-left']).toEqual('84pt');
expect(slidesDiv.style['-webkit-text-fill-color']).toEqual('yellow'); expect(slidesDiv.style['-webkit-text-fill-color']).toEqual('yellow');
@ -264,12 +263,9 @@ describe("Display.setTextSlides", function () {
describe("Display.setImageSlides", function () { describe("Display.setImageSlides", function () {
beforeEach(function() { beforeEach(function() {
document.body.innerHTML = ""; document.body.innerHTML = "";
var slidesDiv = document.createElement("div"); _createDiv({"class": "slides"});
slidesDiv.setAttribute("class", "slides"); _createDiv({"class": "footer"});
document.body.appendChild(slidesDiv); _createDiv({"id": "global-background"});
var backgroundDiv = document.createElement("div");
backgroundDiv.setAttribute("id", "global-background");
document.body.appendChild(backgroundDiv);
Display._slides = {}; Display._slides = {};
}); });
@ -286,7 +282,9 @@ describe("Display.setImageSlides", function () {
expect($(".slides > section").length).toEqual(2); expect($(".slides > section").length).toEqual(2);
expect($(".slides > section > img").length).toEqual(2); expect($(".slides > section > img").length).toEqual(2);
expect($(".slides > section > img")[0].getAttribute("src")).toEqual("file:///openlp1.jpg") expect($(".slides > section > img")[0].getAttribute("src")).toEqual("file:///openlp1.jpg")
expect($(".slides > section > img")[0].getAttribute("style")).toEqual("max-width: 100%; max-height: 100%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);")
expect($(".slides > section > img")[1].getAttribute("src")).toEqual("file:///openlp2.jpg") expect($(".slides > section > img")[1].getAttribute("src")).toEqual("file:///openlp2.jpg")
expect($(".slides > section > img")[1].getAttribute("style")).toEqual("max-width: 100%; max-height: 100%; margin: 0; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);")
expect(Display.reinit).toHaveBeenCalledTimes(1); expect(Display.reinit).toHaveBeenCalledTimes(1);
}); });
}); });
@ -294,12 +292,8 @@ describe("Display.setImageSlides", function () {
describe("Display.setVideo", function () { describe("Display.setVideo", function () {
beforeEach(function() { beforeEach(function() {
document.body.innerHTML = ""; document.body.innerHTML = "";
var slidesDiv = document.createElement("div"); _createDiv({"class": "slides"});
slidesDiv.setAttribute("class", "slides"); _createDiv({"id": "global-background"});
document.body.appendChild(slidesDiv);
var backgroundDiv = document.createElement("div");
backgroundDiv.setAttribute("id", "global-background");
document.body.appendChild(backgroundDiv);
Display._slides = {}; Display._slides = {};
}); });