Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- combineParagraphs(lines) {
- const scatter = this.scatter;
- return lines.reduce((paragraphsObj, line, index, arr) => {
- if (index > 0) {
- const before = arr[index - 1];
- const after = (arr.length - 1 != index) ? arr[index + 1] : { spaceAfter: 0, lineSpace: 0 };
- const A = before.spaceAfter;
- const B = line.spaceAfter;
- const C = after.spaceAfter;
- const AR = before.lineSpace;
- const BR = line.lineSpace;
- const CR = after.lineSpace;
- const form = (a, b, s) => {
- return this.util.scatterDiff(a, b, s || scatter);
- }
- let f1 = form(B, C) && !form(A, B);
- let f2 = !form(AR, A) && !form(A, B);
- let f3 = form(A, B) && form(B, C);
- let f4 = form(A, B);
- const rangeSizeBefore = this.util.likely(before.chars, 'fontSize', { isCeil: true });
- const rangeSizeCurrent = this.util.likely(line.chars, 'fontSize', { isCeil: true });
- const rangeFontFamilyBef = before.chars[0].font; //this.util.likely(before.chars, 'font');
- const rangeFontFamilyCur = this.util.likely(line.chars, 'font');
- const isHave = rangeFontFamilyBef && rangeFontFamilyCur && rangeSizeBefore && rangeSizeCurrent;
- const textConfirmed = isHave && rangeFontFamilyBef == rangeFontFamilyCur && rangeSizeBefore == rangeSizeCurrent;
- const myE = !form(A, AR) && (textConfirmed && !form(BR, CR) && paragraphsObj.arr[paragraphsObj.arr.length - 1].length == 1);
- const ff = (form(A, B) && form(B, C)) || (form(A, B) && paragraphsObj.arr[paragraphsObj.arr.length - 1].length == 1);
- const beforeLeft = this.util.likely(before.chars, 'blockLeft', { isCeil: true });
- const currentLeft = this.util.likely(line.chars, 'blockLeft', { isCeil: true });
- // 1. https://i.imgur.com/2vU48bY.png
- // 2. https://i.imgur.com/c8Ga50m.png
- const byBlockLeft = line.chars[0].blockLeft > Math.max(...before.chars.map(char => char.charLeft))
- || before.chars[0].charLeft > Math.max(...line.chars.map(char => char.charLeft));
- if (this.util.likely(before.chars, 'color') != this.util.likely(line.chars, 'color') || byBlockLeft) {
- paragraphsObj.compare = false;
- }
- // const currFontDiff = rangeFontFamilyBef == rangeFontFamilyCur;
- // if(!currFontDiff) {
- // paragraphsObj.compare = false;
- // }
- if ((ff || myE) && A < (this.util.likely(line.chars, 'fontSize', { isCeil: true }) * 1.5) && this.util.likely(line.chars, 'color') == this.util.likely(before.chars, 'color') && !byBlockLeft /* && currFontDiff */) {
- if (!form(before.chars[0].blockLeft, line.chars[0].blockLeft, 1) && paragraphsObj.arr[paragraphsObj.arr.length - 1].length > 1) {
- paragraphsObj.compare = false;
- paragraphsObj.arr.push([line]);
- } else {
- paragraphsObj.arr[paragraphsObj.arr.length - 1].push(line);
- if (ff && !myE) {
- paragraphsObj.compare = true;
- }
- }
- } else {
- if (paragraphsObj.compare) {
- paragraphsObj.arr[paragraphsObj.arr.length - 1].push(line);
- paragraphsObj.compare = form(AR, BR) && form(CR, BR);
- } else {
- paragraphsObj.arr.push([line]);
- }
- }
- } else {
- paragraphsObj.arr.push([line]);
- }
- return paragraphsObj;
- }, { arr: [] }).arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement