Commit da6a7f9f authored by Julie Blanc's avatar Julie Blanc

rename and clean baseline script

parent 18aa3753
function snapBaseline(config){ function snapBaseline(config){
const baselineDoc = config.baseline; const baselineDoc = config.baseline;
const strict = config.strict; const strict = config.strict;
// 'true' = all the text elements snap strictly on the baseline (by default)
// 'false' = If the element have padding, it's not snap on the baseline
const showBaseline = config.showBaseline; const showBaseline = config.showBaseline;
const elementBaseline = config.element; const elementBaseline = config.element;
...@@ -26,7 +23,6 @@ function snapBaseline(config){ ...@@ -26,7 +23,6 @@ function snapBaseline(config){
/* baseline position + vertical Rythm of paragraphs */ /* baseline position + vertical Rythm of paragraphs */
const paragraph = 'p'; const paragraph = 'p';
// verticalRythm(paragraph, '', '', baselineDoc, strict);
let baselinePosition = verticalRythm(paragraph, '', '', baselineDoc, strict); let baselinePosition = verticalRythm(paragraph, '', '', baselineDoc, strict);
let baselinePositionCSS = ':root{ --pagedjs-baseline-position : -' + baselinePosition + 'px; }' let baselinePositionCSS = ':root{ --pagedjs-baseline-position : -' + baselinePosition + 'px; }'
addcss(baselinePositionCSS); addcss(baselinePositionCSS);
...@@ -51,7 +47,6 @@ function snapTextElement(elementSelector, baselinePosition, baselineDoc, strict) ...@@ -51,7 +47,6 @@ function snapTextElement(elementSelector, baselinePosition, baselineDoc, strict)
// do calculation on each tag element // do calculation on each tag element
// verticalRythm(elementSelector, '', '', baselineDoc, configStrict);
let gapBaselineElem = verticalRythm(elementSelector, '', '', baselineDoc, configStrict); let gapBaselineElem = verticalRythm(elementSelector, '', '', baselineDoc, configStrict);
let newgapBaselineElem = gapBaselineElem - baselinePosition; let newgapBaselineElem = gapBaselineElem - baselinePosition;
...@@ -65,7 +60,6 @@ function snapTextElement(elementSelector, baselinePosition, baselineDoc, strict) ...@@ -65,7 +60,6 @@ function snapTextElement(elementSelector, baselinePosition, baselineDoc, strict)
let allClasses = elem[i].classList; let allClasses = elem[i].classList;
let elemId = elem[i].id; let elemId = elem[i].id;
if(allClasses.length != 0 || elemId != ""){ if(allClasses.length != 0 || elemId != ""){
// verticalRythm(elementSelector, allClasses, elemId, baselineDoc, configStrict);
let gapBaselineThisElem = verticalRythm(elementSelector, allClasses, elemId, baselineDoc, configStrict); let gapBaselineThisElem = verticalRythm(elementSelector, allClasses, elemId, baselineDoc, configStrict);
let newgapBaselineThisElem = gapBaselineThisElem - baselinePosition; let newgapBaselineThisElem = gapBaselineThisElem - baselinePosition;
elem[i].style.top = newgapBaselineThisElem + "px"; elem[i].style.top = newgapBaselineThisElem + "px";
...@@ -122,8 +116,6 @@ ________________________________________________________________________________ ...@@ -122,8 +116,6 @@ ________________________________________________________________________________
function verticalRythm(elem, elemClass, elemId, base, strict){ function verticalRythm(elem, elemClass, elemId, base, strict){
let baseline = base; let baseline = base;
let configStrict = strict; let configStrict = strict;
// let elemClass = elemClass;
// let elemId = elemId;
/* render element */ /* render element */
let element = document.createElement(elem); let element = document.createElement(elem);
...@@ -134,7 +126,7 @@ function verticalRythm(elem, elemClass, elemId, base, strict){ ...@@ -134,7 +126,7 @@ function verticalRythm(elem, elemClass, elemId, base, strict){
/* get styles of the font */ /* get styles of the font */
let styles = getStyle(element); let styles = getStyle(element);
/* get font metrics */ /* get font metrics (unsing FontMetrics.js) */
const metrics = FontMetrics({ const metrics = FontMetrics({
fontFamily: styles.fontFamily, fontFamily: styles.fontFamily,
fontWeight: styles.fontWeight, fontWeight: styles.fontWeight,
...@@ -235,10 +227,7 @@ function verticalRythm(elem, elemClass, elemId, base, strict){ ...@@ -235,10 +227,7 @@ function verticalRythm(elem, elemClass, elemId, base, strict){
elementSpecificId.style.marginBottom = newMarginBottom + "px"; elementSpecificId.style.marginBottom = newMarginBottom + "px";
} }
/* distance between baseline font and baseline document */ /* distance between baseline font and baseline document */
let gapBaseline = ((computedLineHeight + baseline*ceilLineHeight)/2) - (metrics.top * -1 * styles.fontSize); let gapBaseline = ((computedLineHeight + baseline*ceilLineHeight)/2) - (metrics.top * -1 * styles.fontSize);
return gapBaseline; return gapBaseline;
......
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