identifySpacesInBand method
void
identifySpacesInBand()
Identifies and inserts space artifacts between existing artifacts in the band.
This method analyzes the Kerning between artifacts and inserts space artifacts where the Kerning exceeds a certain threshold.
The process involves:
- Calculating a threshold Kerning size based on the average width.
- Iterating through artifacts to identify Kerning exceeding the threshold.
- Creating a list of artifacts that need spaces inserted before them.
- Inserting space artifacts at the appropriate positions.
The threshold is set at 50% of the average width of artifacts in the band.
Implementation
void identifySpacesInBand() {
final double exceeding = this.averageWidth * 0.50; // in %
final List<Artifact> insertInFrontOfTheseArtifacts = [];
for (int indexOfArtifact = 0;
indexOfArtifact < this.artifacts.length;
indexOfArtifact++) {
if (indexOfArtifact > 0) {
// Left
final Artifact artifactLeft = this.artifacts[indexOfArtifact - 1];
final double x1 = artifactLeft.matrix.rectangle.right;
// Right
final Artifact artifactRight = this.artifacts[indexOfArtifact];
final double x2 = artifactRight.matrix.rectangle.left;
final double kerning = x2 - x1;
if (kerning >= exceeding) {
// insert Artifact for Space
insertInFrontOfTheseArtifacts.add(artifactRight);
}
}
}
for (final Artifact artifactOnTheRightSide
in insertInFrontOfTheseArtifacts) {
final int indexOfArtifact =
this.artifacts.indexOf(artifactOnTheRightSide);
insertArtifactForSpace(
indexOfArtifact,
artifactOnTheRightSide.matrix.rectangle.left -
averageWidth -
averageKerning,
artifactOnTheRightSide.matrix.rectangle.left - averageKerning,
);
}
}