center method

GenericGlyph center(
  1. int ascender,
  2. int descender,
  3. int offset
)

Implementation

GenericGlyph center(int ascender, int descender, int offset) {
  final metrics = this.metrics;

  final offsetX = -metrics.xMin;
  final offsetY =
      (ascender + descender) / 2 - metrics.height / 2 - metrics.yMin + offset;

  final newOutlines = outlines.map((o) {
    final newOutline = o.copy();
    final newPointList = newOutline.pointList
        .map((e) => math.Point<num>(e.x + offsetX, e.y + offsetY))
        .toList();
    newOutline.pointList
      ..clear()
      ..addAll(newPointList);
    return newOutline;
  }).toList();

  final newBounds = math.Rectangle(
    bounds.left + offsetX,
    bounds.bottom + offsetY,
    bounds.width,
    bounds.height,
  );

  return GenericGlyph(newOutlines, newBounds, metadata);
}