hasLowerRightStroke method

bool hasLowerRightStroke()

Detects ink density in the lower-right quadrant of the glyph.

This helps differentiate characters like 'R' from 'P' without hardcoding specific words, by checking for a diagonal or lower-right stroke.

Implementation

bool hasLowerRightStroke() {
  final IntRect content = getContentRect();
  if (content.isEmpty) {
    return false;
  }

  final int totalOn = countOnPixels(rect: content);
  final int totalArea = content.width * content.height;
  if (totalOn == 0 || totalArea == 0) {
    return false;
  }

  final int startX =
      content.left + (content.width * _lowerRightStrokeXRatio).round();
  final int startY =
      content.top + (content.height * _lowerRightStrokeYRatio).round();

  final IntRect region = IntRect.fromLTRB(
    startX.clamp(content.left, content.right),
    startY.clamp(content.top, content.bottom),
    content.right,
    content.bottom,
  );

  if (region.isEmpty) {
    return false;
  }

  final int regionOn = countOnPixels(rect: region);
  final int regionArea = region.width * region.height;
  if (regionArea == 0) {
    return false;
  }

  final double totalDensity = totalOn / totalArea;
  final double regionDensity = regionOn / regionArea;
  return regionDensity >= (totalDensity * _lowerRightStrokeDensityRatio);
}