Commit 5e8bc44e authored by Julie Blanc's avatar Julie Blanc

snap image script, style and example

parent d4b33e40
This diff is collapsed.
This diff is collapsed.
......@@ -6,17 +6,14 @@ figure {
width: 100%;
text-align: center;
margin-bottom: 0pt;
float-reference: column;
float: top;
float-defer: last;
/* max-height: calc(var(--page-height)/3); */
figcaption {
font-size: 12px;
font-style: normal;
text-indent: 0;
text-align: left;
/* // counter-increment: map; */
font-size: 8pt;
line-height: 11pt;
......@@ -26,9 +23,16 @@ figure {
}
img {
margin-top: 6px;
margin-bottom: 1px;
width: 100%;
/* // margin-top: 13pt; */
object-fit: cover;
object-position: center center;
/* opacity: 0.3; */
}
}
#img-1{
/* height: calc(var(--font-lineHeight)*14 + 6px); */
}
\ No newline at end of file
This diff is collapsed.
class SnapImages extends Paged.Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
afterPageLayout(pageElement, page, breakToken){
let images = pageElement.getElementsByClassName("img-snap");
for(let i=0;i<images.length;i++){
let imgwidth = images[i].clientWidth;
let imgheight = images[i].clientHeight;
let varBaseline = getComputedStyle(images[i]).getPropertyValue('--font-lineHeight');
let baseline = parseInt(varBaseline.replace("px", ""));
let varHeightx = getComputedStyle(images[i]).getPropertyValue('--height-x');
let heightx = parseInt(varHeightx.replace("px", ""));
let ratio = Math.round((imgheight - heightx)/baseline);
if(ratio < 18){
images[i].style.height = "calc(var(--font-lineHeight)*" + ratio + " + var(--height-x))";
}else{
images[i].style.height = "calc(var(--font-lineHeight)*18 + var(--height-x))";
images[i].style.objectFit = "contain";
}
}
}
}
Paged.registerHandlers(SnapImages);
class MyHandler extends Paged.Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
beforePageLayout(page) {
// let pageContent = document.getElementsByClassName("pagejs_page");
// console.log(pageContent);
// for(let p=0;p<pageContent.length;p++){
// console.log(pageContent[p]);
// }
console.log(page.area);
let images = page.area.getElementsByClassName("img-snap");
console.log(images.length);
// let pageContent = page.area;
}
}
Paged.registerHandlers(MyHandler);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment