X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=src%2Flibclo%2FbreakLines.ts;h=f761b1868525b52e2e76b491110e1a2d98b82ac6;hb=2b1a59e963a3610c8f664af3dd6b03afb8d89646;hp=0392a23062743c6031a8d885e15af3cea3dfa357;hpb=f12842e5a4ef531e38024e16f91b21c99ce1de92;p=clo diff --git a/src/libclo/breakLines.ts b/src/libclo/breakLines.ts index 0392a23..f761b18 100644 --- a/src/libclo/breakLines.ts +++ b/src/libclo/breakLines.ts @@ -2,7 +2,7 @@ * Algorithms and functions for LineBreaking */ import { join } from "path"; -import {BreakPoint, BoxesItem, HGlue} from "./index.js"; +import {BreakPoint, BoxesItem, HGlue, CharBox} from "./index.js"; import { listenerCount } from "process"; import { unwatchFile } from "fs"; /** @@ -51,9 +51,9 @@ export class BreakLineAlgorithm { } segmentedNodes(items : BoxesItem[], lineWidth : number) : BoxesItem[][]{ - this.totalCost(items ,lineWidth); + let lineWidthFixed = lineWidth; + this.totalCost(items ,lineWidthFixed); let nodeList = this.generateBreakLineNodeList(); - console.log("~~~", nodeList); let res = []; let low = -1; let up = nodeList[0]; @@ -91,20 +91,30 @@ export class BreakLineAlgorithm { * check all the total cost of paragraphes of the segnemt */ totalCost(items : BoxesItem[], lineWidth: number) : number{ - + let lineWidthFixed = lineWidth * 0.75; let itemsLength = items.length; this.lineCostStorage = Array(itemsLength); this.prevNodes = Array(itemsLength).fill(null); for (var i=0; i tmp){ + this.prevNodes[itemsLength-1] = k + a = tmp; + } } - this.totalCostAuxStorage = Array(itemsLength).fill(undefined); - console.log("===", itemsLength); - let a = this.totalCostAux(items, itemsLength-1, lineWidth); - console.log(this.lineCostStorage); + console.log("~~~", lineWidth); + console.log((items[itemsLength-2])); return a; } @@ -117,18 +127,18 @@ export class BreakLineAlgorithm { */ totalCostAux(items : BoxesItem[], j : number, lineWidth: number): number{ - if (this.totalCostAuxStorage[j] !== undefined){ + if (this.totalCostAuxStorage[j] !== null){ return this.totalCostAuxStorage[j]; } let rawLineCost = this.lineCost(items, 0, j, lineWidth); if (rawLineCost != Infinity){ - this.totalCostAuxStorage[j] = rawLineCost; - return rawLineCost; + this.totalCostAuxStorage[j] = rawLineCost**3.0; + return rawLineCost**3.0; }else{ var returnCost = Infinity; for(var k=0; k tmp){ this.prevNodes[j] = k; returnCost = tmp; @@ -140,7 +150,6 @@ export class BreakLineAlgorithm { } - return returnCost; } @@ -154,7 +163,7 @@ export class BreakLineAlgorithm { * @param lineWidth line width */ lineCost(items : BoxesItem[], i : number, j : number, lineWidth: number) : number{ - if (this.lineCostStorage[i] !== undefined && this.lineCostStorage[i][j] !== undefined){ + if (this.lineCostStorage[i] !== null && this.lineCostStorage[i][j] !== null){ return this.lineCostStorage[i][j]; } @@ -173,7 +182,7 @@ export class BreakLineAlgorithm { this.lineCostStorage[i][j] = Infinity; return Infinity; }else{ - let returnValue = (lineWidth - tmpItemWidth)**3.0; + let returnValue = (lineWidth - tmpItemWidth); this.lineCostStorage[i][j] = returnValue; return returnValue; }