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() {
updateStatistics();
if (artifacts.isEmpty || artifacts.length <= 1) {
return;
}
// Calculate a more adaptive threshold based on both average width and kerning
final int spaceThreshold = calculateSpaceThreshold();
for (int i = 1; i < artifacts.length; i++) {
final Artifact leftArtifact = artifacts[i - 1];
final Artifact rightArtifact = artifacts[i];
final int leftEdge = leftArtifact.rectFound.right;
final int rightEdge = rightArtifact.rectFound.left;
final int gap = rightEdge - leftEdge;
if (gap >= spaceThreshold) {
const int borderWidth = 2;
final int spaceWidth = (gap - (borderWidth * 2)).toInt();
if (spaceWidth > 1) {
// this space is big enough
insertArtifactForSpace(
artifacts: artifacts,
insertAtIndex: i,
cols: spaceWidth,
rows: rectangleOriginal.height.toInt(),
locationFoundAt: IntOffset(
leftArtifact.rectFound.right + 2,
leftArtifact.rectFound.top,
),
);
i++;
}
}
}
}