createPath method
Implementation
Map<String, dynamic> createPath(
char, double scale, double offsetX, double offsetY, data) {
var glyph = data["glyphs"][char] ?? data["glyphs"]['?'];
if (glyph == null) {
print(
"THREE.Font: character $char does not exists in font family ${data.familyName}");
// return null;
glyph = data["glyphs"]["a"];
}
var path = ShapePath();
double x = 0.1;
double y = 0.1;
double cpx, cpy, cpx1, cpy1, cpx2, cpy2;
if (glyph["o"] != null) {
var outline = glyph["_cachedOutline"];
if (outline == null) {
glyph["_cachedOutline"] = glyph["o"].split(' ');
outline = glyph["_cachedOutline"];
}
print(" outline scale: $scale ");
print(outline);
for (int i = 0, l = outline.length; i < l;) {
var action = outline[i];
i = i + 1;
switch (action) {
case 'm': // moveTo
x = int.parse(outline[i++]) * scale + offsetX;
y = int.parse(outline[i++]) * scale + offsetY;
path.moveTo(x, y);
break;
case 'l': // lineTo
x = int.parse(outline[i++]) * scale + offsetX;
y = int.parse(outline[i++]) * scale + offsetY;
path.lineTo(x, y);
break;
case 'q': // quadraticCurveTo
cpx = int.parse(outline[i++]) * scale + offsetX;
cpy = int.parse(outline[i++]) * scale + offsetY;
cpx1 = int.parse(outline[i++]) * scale + offsetX;
cpy1 = int.parse(outline[i++]) * scale + offsetY;
path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
break;
case 'b': // bezierCurveTo
cpx = int.parse(outline[i++]) * scale + offsetX;
cpy = int.parse(outline[i++]) * scale + offsetY;
cpx1 = int.parse(outline[i++]) * scale + offsetX;
cpy1 = int.parse(outline[i++]) * scale + offsetY;
cpx2 = int.parse(outline[i++]) * scale + offsetX;
cpy2 = int.parse(outline[i++]) * scale + offsetY;
path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
break;
}
}
}
return {"offsetX": glyph["ha"] * scale, "path": path};
}