ntk 8.18.1 → 8.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/app.js +214 -35
- package/lib/image.js +125 -4
- package/lib/index.js +2 -1
- package/lib/renderingcontext_2d.js +1036 -397
- package/lib/text/layout.js +12 -6
- package/package.json +1 -1
package/lib/text/layout.js
CHANGED
|
@@ -916,6 +916,9 @@ export class TextLayout {
|
|
|
916
916
|
draw(ctx, x = 0, y = 0) {
|
|
917
917
|
const app = ctx.window.app;
|
|
918
918
|
const Render = app.display.Render;
|
|
919
|
+
// The context's composite op, as `fillText` takes it. A context that is
|
|
920
|
+
// not ntk's has none to give, and its text goes source-over.
|
|
921
|
+
const op = ctx._op?.() ?? Render.PictOp.Over;
|
|
919
922
|
// One batch for the whole layout, not one per line: every positioned
|
|
920
923
|
// run carries its own absolute baseline, so a uniformly coloured
|
|
921
924
|
// paragraph becomes a single glyph composite instead of one per line.
|
|
@@ -929,9 +932,9 @@ export class TextLayout {
|
|
|
929
932
|
// (drawGlyphRuns composites straight onto the picture and can see
|
|
930
933
|
// neither)
|
|
931
934
|
if (typeof ctx.drawGlyphs === 'function') {
|
|
932
|
-
ctx.drawGlyphs(
|
|
935
|
+
ctx.drawGlyphs(op, src, batch);
|
|
933
936
|
} else {
|
|
934
|
-
drawGlyphRuns(app,
|
|
937
|
+
drawGlyphRuns(app, op, src.id, ctx.picture.id, batch);
|
|
935
938
|
}
|
|
936
939
|
batch = [];
|
|
937
940
|
};
|
|
@@ -942,7 +945,7 @@ export class TextLayout {
|
|
|
942
945
|
// height and its font's extent again on either side for ink that
|
|
943
946
|
// overhangs the box, is outside the rows the clip lets through: nothing
|
|
944
947
|
// of it could have landed on a pixel.
|
|
945
|
-
const rows = visibleRows(ctx, y);
|
|
948
|
+
const rows = visibleRows(ctx, y, op);
|
|
946
949
|
for (const line of this.lines) {
|
|
947
950
|
if (rows) {
|
|
948
951
|
const reach = line.height + line.ascent + line.descent;
|
|
@@ -1493,12 +1496,15 @@ function sliceLevels(key, start, end) {
|
|
|
1493
1496
|
* The rows of a layout drawn at `y` that the context can show — its clip's
|
|
1494
1497
|
* box, or the whole surface with no clip — in the layout's own coordinates.
|
|
1495
1498
|
* Null where that cannot be said, and the whole layout is drawn: a context
|
|
1496
|
-
* that is not ntk's, a transform that is more than a translation,
|
|
1497
|
-
* shadow, which lands where the text is not
|
|
1499
|
+
* that is not ntk's, a transform that is more than a translation, a
|
|
1500
|
+
* shadow, which lands where the text is not, or an `op` like `copy` that
|
|
1501
|
+
* clears the box round all the glyphs drawn — a line the clip hides still
|
|
1502
|
+
* widens that box along the rows it does not hide.
|
|
1498
1503
|
*/
|
|
1499
|
-
function visibleRows(ctx, y) {
|
|
1504
|
+
function visibleRows(ctx, y, op) {
|
|
1500
1505
|
if (typeof ctx.drawGlyphs !== 'function') return null;
|
|
1501
1506
|
if (typeof ctx._clipExtents !== 'function') return null;
|
|
1507
|
+
if (typeof ctx._maskBounded === 'function' && !ctx._maskBounded(op)) return null;
|
|
1502
1508
|
const m = ctx._m;
|
|
1503
1509
|
if (!m || m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1) return null;
|
|
1504
1510
|
if (typeof ctx._shadowed !== 'function' || ctx._shadowed()) return null;
|