createPath method
Implementation
@override
Map<String, dynamic> createPath(
String char, double scale, double offsetX, double offsetY, data) {
final font = data["font"];
List<int> glyphs = List<int>.from(font.stringToGlyphs(char));
final gid = glyphs[0];
final charPath = font.glyphToPath(gid);
final preScale = (100000) / ((font.head["unitsPerEm"] ?? 2048) * 72);
// final _preScale = 1;
final ha = (font.hmtx["aWidth"][gid] * preScale).round();
final path = ShapePath();
double x = 0.1;
double y = 0.1;
double cpx, cpy, cpx1, cpy1, cpx2, cpy2;
final cmds = charPath["cmds"];
List<double> crds = List<double>.from(charPath["crds"].map((e) => e.toDouble()));
crds = crds.map((n) => (n * preScale).roundToDouble()).toList();
int i = 0;
int l = cmds.length;
for (int j = 0; j < l; j++) {
final action = cmds[j];
switch (action) {
case 'M': // moveTo
x = crds[i++] * scale + offsetX;
y = crds[i++] * scale + offsetY;
path.moveTo(x, y);
break;
case 'L': // lineTo
x = crds[i++] * scale + offsetX;
y = crds[i++] * scale + offsetY;
path.lineTo(x, y);
break;
case 'Q': // quadraticCurveTo
cpx = crds[i++] * scale + offsetX;
cpy = crds[i++] * scale + offsetY;
cpx1 = crds[i++] * scale + offsetX;
cpy1 = crds[i++] * scale + offsetY;
path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
break;
case 'B':
case 'C': // bezierCurveTo
cpx = crds[i++] * scale + offsetX;
cpy = crds[i++] * scale + offsetY;
cpx1 = crds[i++] * scale + offsetX;
cpy1 = crds[i++] * scale + offsetY;
cpx2 = crds[i++] * scale + offsetX;
cpy2 = crds[i++] * scale + offsetY;
path.bezierCurveTo(cpx, cpy, cpx1, cpy1, cpx2, cpy2);
break;
}
}
return {"offsetX": ha * scale, "path": path};
}