Created
August 10, 2021 16:48
-
-
Save craigmarvelley/59777cf7fb94e507a90ff12942b4bbc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pseudocode for checking if there is a large gap between the | |
// current and next candidate's bounding box. | |
var isNextItemOnNewParagraph: Bool { | |
let avgHeight = (currentObservationCandidateHeight + currentObservationCandidateHeight / 2) | |
let currentItemHeight = currentObservationCandidateHeight | |
let nextItemHeight = currentObservationCandidateHeight | |
let isSeparationLargerThanCurrentItemHeight = avgHeight >= currentItemHeight | |
let isSeparationLargerThanNextItemHeight = avgHeight >= nextItemHeight | |
return isSeparationLargerThanCurrentItemHeight || isSeparationLargerThanNextItemHeight | |
} | |
// Pseudocode for checking if next candidate is on a new line and is there | |
// an indentation for the next candidate. | |
let isNextItemOnNewLine = avgBottomYOfNextItem > avgBottomYOfCurrentItem | |
if isNextItemOnNewParagraph { | |
addNewLineToText() | |
resetMinimumXPositionOfAParagraphs() | |
} else if isNextItemOnNewLine { | |
let nextItemTopLeftX = nextItemTopLeftXPosition | |
let minimumParagraphXposition = aParagraphMinX | |
let isNextItemPartOfCurrentParagraph = nextItemTopLeftX <= minimumParagraphXposition | |
// Assumption: if there is no sufficient gap between paragraphs then new paragraphs | |
// are started with an indentation | |
if isNextItemPartOfCurrentParagraph { | |
addSpacingAndAppendThenNextCandidateString() | |
updateMinimumXPositionOfAParagraphs(with: nextItemTopLeftX) | |
} else { | |
addNewLineToText() | |
resetMinimumXPositionOfAParagraphs() | |
} | |
} else { | |
addSpacingAndAppendThenNextCandidateString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment