Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Created August 16, 2022 21:28
Show Gist options
  • Save yjbanov/8ec2437f8110c45949a238916b405b65 to your computer and use it in GitHub Desktop.
Save yjbanov/8ec2437f8110c45949a238916b405b65 to your computer and use it in GitHub Desktop.
Attempts to reproduce CanvasKit issue on Nexus 5X
const transforms = [
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -0.01, 1],
[1, 0, 0, 0, 0, 0.996917333733128, -0.07845909572784494, -2.353772871835348, 0, 0.07845909572784494, 0.996917333733128, -0.0924799880061613, 0, -0.0007845909572784495, -0.00996917333733128,
1.0009247998800617],
[1, 0, 0, 0, 0, 0.9876883405951378, -0.15643446504023087, -4.693033951206926, 0, 0.15643446504023087, 0.9876883405951378, -0.3693497821458678, 0, -0.0015643446504023087, -0.009876883405951378,
1.0036934978214587],
[1, 0, 0, 0, 0, 0.9723699203976766, -0.2334453638559054, -7.0033609156771615, 0, 0.2334453638559054, 0.9723699203976766, -0.8289023880697037, 0, -0.002334453638559054, -0.009723699203976767,
1.008289023880697],
[1, 0, 0, 0, 0, 0.9510565162951535, -0.3090169943749474, -9.270509831248422, 0, 0.3090169943749474, 0.9510565162951535, -1.4683045111453943, 0, -0.0030901699437494742, -0.009510565162951536,
1.014683045111454],
[1, 0, 0, 0, 0, 0.9238795325112867, -0.3826834323650898, -11.480502970952694, 0, 0.3826834323650898, 0.9238795325112867, -2.2836140246613965, 0, -0.003826834323650898, -0.009238795325112868,
1.022836140246614],
[1, 0, 0, 0, 0, 0.8910065241883679, -0.45399049973954675, -13.619714992186402, 0, 0.45399049973954675, 0.8910065241883679, -3.2698042743489637, 0, -0.004539904997395467, -0.00891006524188368,
1.0326980427434898],
[1, 0, 0, 0, 0, 0.8526401643540923, -0.5224985647159488, -15.674956941478463, 0, 0.5224985647159488, 0.8526401643540923, -4.420795069377231, 0, -0.005224985647159488, -0.008526401643540923,
1.0442079506937723],
[1, 0, 0, 0, 0, 0.8090169943749475, -0.5877852522924731, -17.633557568774194, 0, 0.5877852522924731, 0.8090169943749475, -5.729490168751575, 0, -0.0058778525229247315, -0.008090169943749474,
1.0572949016875157],
[1, 0, 0, 0, 0, 0.7604059656000309, -0.6494480483301837, -19.48344144990551, 0, 0.6494480483301837, 0.7604059656000309, -7.187821031999071, 0, -0.0064944804833018364, -0.0076040596560003094,
1.0718782103199906]
];
async function runEverything() {
let resp = await fetch('https://storage.googleapis.com/skia-cdn/google-web-fonts/Roboto-Regular.ttf');
let robotoData = await resp.arrayBuffer();
const surface = CanvasKit.MakeCanvasSurface(canvas.id);
const fontPaint = new CanvasKit.Paint();
fontPaint.setStyle(CanvasKit.PaintStyle.Fill);
fontPaint.setAntiAlias(true);
function drawFrame(canvas) {
const fontMgr = CanvasKit.FontMgr.FromData([robotoData]);
canvas.clear(CanvasKit.WHITE);
for (var i = 0; i < transforms.length; i++) {
canvas.save();
canvas.concat(transforms[i]);
const paraStyle = new CanvasKit.ParagraphStyle({
textStyle: {
color: CanvasKit.BLACK,
fontFamilies: ['Roboto'],
fontSize: 20,
},
textAlign: CanvasKit.TextAlign.Left,
});
const builder = CanvasKit.ParagraphBuilder.Make(paraStyle, fontMgr);
builder.addText('The quick brown fox ate a zesty hamburgerfons.');
paragraph = builder.build();
paragraph.layout(1000);
canvas.drawParagraph(paragraph, 0, 0);
canvas.restore();
canvas.translate(0, 30);
}
}
surface.requestAnimationFrame(drawFrame);
};
runEverything();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment