Add 'w'avy style to textedit

Change-Id: I337f4dff10f30aa248ebc520449f3b763ede0ed8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414096
Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2021-05-31 16:41:48 -04:00
parent 8942247ae4
commit 77724af76c
2 changed files with 18 additions and 1 deletions
demos.skia.org/demos/textedit

View File

@ -138,6 +138,7 @@ canvas {
case 'i': editor.applyStyleToSelection({italic:'toggle'}); return;
case 'b': editor.applyStyleToSelection({bold:'toggle'}); return;
case 'w': editor.applyStyleToSelection({wavy:'toggle'}); return;
case ']': editor.applyStyleToSelection({size_add:1}); return;
case '[': editor.applyStyleToSelection({size_add:-1}); return;

View File

@ -217,6 +217,9 @@ function MakeStyle(length) {
if (src.italic) {
this.italic = this._check_toggle(src.italic, this.italic);
}
if (src.wavy) {
this.wavy = this._check_toggle(src.wavy, this.wavy);
}
if (src.size_add) {
this.size += src.size_add;
@ -485,7 +488,20 @@ function MakeEditor(text, style, cursor, width) {
} else {
LOG(' use entire glyph run');
}
canvas.drawGlyphs(gly, pos, 0, 0, f, p);
let working_pos = pos;
if (s.wavy) {
const xscale = 0.05;
const yscale = r.size * 0.125;
let wavy = [];
for (let i = 0; i < pos.length; i += 2) {
const x = pos[i + 0];
wavy.push(x);
wavy.push(pos[i + 1] + Math.sin(x * xscale) * yscale);
}
working_pos = new Float32Array(wavy);
}
canvas.drawGlyphs(gly, working_pos, 0, 0, f, p);
p.setShader(null); // in case our caller deletes their shader(s)