From bed3fd357b5b6aad39e372cf40d7148e1cdcc5f7 Mon Sep 17 00:00:00 2001 From: Johannes Zillmann Date: Sat, 18 Feb 2017 12:33:21 +0100 Subject: [PATCH] WIP merge successive code blocks --- .../transformations/DetectCodeBlocks.jsx | 24 ++++++++++++++----- .../transformations/DetectPdfBlocks.jsx | 4 ---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/javascript/models/transformations/DetectCodeBlocks.jsx b/src/javascript/models/transformations/DetectCodeBlocks.jsx index 84f488b..b2d2c9b 100644 --- a/src/javascript/models/transformations/DetectCodeBlocks.jsx +++ b/src/javascript/models/transformations/DetectCodeBlocks.jsx @@ -23,7 +23,7 @@ export default class DetectCodeBlocks extends ToPdfBlockViewTransformation { // TODO ==> combine quotes follow each other transform(parseResult:ParseResult) { - const {mostUsedHeight} = parseResult.globals; + const {mostUsedHeight, mostUsedDistance} = parseResult.globals; var foundBlocks = 0; const textCombiner = new TextItemCombiner({}); @@ -49,20 +49,32 @@ export default class DetectCodeBlocks extends ToPdfBlockViewTransformation { return true; }; const newBlocks = []; + var preceedingCodeBlock; page.blocks.forEach(block => { if (block.type) { newBlocks.push(block); + preceedingCodeBlock = null; } else { if (itemAreSuitable(block.textItems)) { + const mergeWithPreceedingCodeBlock = preceedingCodeBlock && preceedingCodeBlock.textItems[preceedingCodeBlock.textItems.length - 1].y - block.textItems[0].y < mostUsedDistance * 2; + if (mergeWithPreceedingCodeBlock) { + newBlocks.pop(); + } block.annotation = REMOVED_ANNOTATION; newBlocks.push(block); - newBlocks.push(new PdfBlock({ - type: CODE_BLOCK, - annotation: ADDED_ANNOTATION, - textItems: textCombiner.combine(block.textItems) - })); + if (mergeWithPreceedingCodeBlock) { + preceedingCodeBlock.textItems = preceedingCodeBlock.textItems.concat(textCombiner.combine(block.textItems)); + } else { + preceedingCodeBlock = new PdfBlock({ + type: CODE_BLOCK, + annotation: ADDED_ANNOTATION, + textItems: textCombiner.combine(block.textItems) + }); + } + newBlocks.push(preceedingCodeBlock); } else { newBlocks.push(block); + preceedingCodeBlock = null; } } }); diff --git a/src/javascript/models/transformations/DetectPdfBlocks.jsx b/src/javascript/models/transformations/DetectPdfBlocks.jsx index 56b1987..318ad47 100644 --- a/src/javascript/models/transformations/DetectPdfBlocks.jsx +++ b/src/javascript/models/transformations/DetectPdfBlocks.jsx @@ -10,10 +10,6 @@ export default class DetectPdfBlocks extends ToPdfBlockViewTransformation { super("Detect Blocks"); } - showModificationCheckbox() { - return false; - } - createSummaryView(parseResult:ParseResult) { return
Splitted into