modern-canvas 0.25.2 → 0.26.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.
|
@@ -107,6 +107,11 @@ export declare class Element2D extends Node2D implements Rectangulable {
|
|
|
107
107
|
protected _updateGlobalAabb(): void;
|
|
108
108
|
protected _updateMask(): void;
|
|
109
109
|
protected _updateGlobalDisplay(): void;
|
|
110
|
+
/**
|
|
111
|
+
* 批量修改:fn 内对 style 的多次改动只在结束时合并触发一次 text.update()(文字重栅格)。
|
|
112
|
+
* 否则逐个改 width/height/fontSize 会各自重栅一次(如 resize 时每帧重栅 3 次)。
|
|
113
|
+
*/
|
|
114
|
+
batch(fn: () => void): void;
|
|
110
115
|
protected _beginBatch(): void;
|
|
111
116
|
protected _endBatch(): void;
|
|
112
117
|
onUpdateStyleProperty(key: string, value: any, oldValue: any): void;
|
|
@@ -27,7 +27,16 @@ export declare class Element2DText extends CoreObject implements NormalizedText
|
|
|
27
27
|
set textContent(val: string);
|
|
28
28
|
protected _textContent: string;
|
|
29
29
|
protected _autoDrawMode?: TextDrawMode;
|
|
30
|
+
protected _atlasEligible: boolean;
|
|
31
|
+
protected _textureStale: boolean;
|
|
30
32
|
protected _texture: CanvasTexture;
|
|
33
|
+
protected _tiles: {
|
|
34
|
+
texture: CanvasTexture;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
w: number;
|
|
38
|
+
h: number;
|
|
39
|
+
}[];
|
|
31
40
|
protected _textureMap: Map<string, {
|
|
32
41
|
texture: Texture2D | undefined;
|
|
33
42
|
box: RectangleLike;
|
|
@@ -37,6 +46,9 @@ export declare class Element2DText extends CoreObject implements NormalizedText
|
|
|
37
46
|
protected _updateProperty(key: string, value: any, oldValue: any): void;
|
|
38
47
|
load(): Promise<void>;
|
|
39
48
|
update(): void;
|
|
49
|
+
protected _rasterTexture(): void;
|
|
50
|
+
protected _renderTiles(width: number, height: number, pixelRatio: number, maxTile: number): void;
|
|
51
|
+
protected _releaseTiles(): void;
|
|
40
52
|
protected _updateTextureMap(): void;
|
|
41
53
|
protected _updateTexture(key: string, fill: NormalizedFill | undefined, box: BoundingBox): Promise<void>;
|
|
42
54
|
protected _loadTexture(fill: NormalizedFill, box: any): Promise<Texture2D | undefined>;
|
|
@@ -48,6 +60,9 @@ export declare class Element2DText extends CoreObject implements NormalizedText
|
|
|
48
60
|
useTextureDraw(): boolean;
|
|
49
61
|
protected _pathDraw(ctx: CanvasContext): void;
|
|
50
62
|
protected _textureDraw(ctx: CanvasContext): void;
|
|
63
|
+
protected _drawTextureRect(ctx: CanvasContext, texture: Texture2D, rx: number, ry: number, rw: number, rh: number): void;
|
|
64
|
+
protected _computeAtlasEligible(): boolean;
|
|
65
|
+
protected _atlasDraw(ctx: CanvasContext): boolean;
|
|
51
66
|
draw(): void;
|
|
52
67
|
process(_delta: number): void;
|
|
53
68
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CanvasTexture } from './CanvasTexture';
|
|
2
|
+
export interface GlyphSlot {
|
|
3
|
+
texture: CanvasTexture;
|
|
4
|
+
u0: number;
|
|
5
|
+
v0: number;
|
|
6
|
+
u1: number;
|
|
7
|
+
v1: number;
|
|
8
|
+
}
|
|
9
|
+
export type GlyphRasterFn = (ctx: CanvasRenderingContext2D) => void;
|
|
10
|
+
interface AtlasPage {
|
|
11
|
+
texture: CanvasTexture;
|
|
12
|
+
ctx: CanvasRenderingContext2D;
|
|
13
|
+
penX: number;
|
|
14
|
+
penY: number;
|
|
15
|
+
rowH: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 共享字形 atlas:把每个唯一字形(字 + 字体 + 字号桶 + 字重 + 斜体 + 颜色)只栅格化一次到
|
|
19
|
+
* 共享纹理页,文字渲染时改为「逐字形 quad 批渲染」(见 Element2DText._atlasDraw)。同一纹理的
|
|
20
|
+
* quad 经 GlBatch2DSystem 自动塌缩进 ~1 个 draw call,编辑/缩放/resize 只重定位 quad,不再整篇重栅。
|
|
21
|
+
*/
|
|
22
|
+
export declare class GlyphAtlas {
|
|
23
|
+
readonly superSample = 2;
|
|
24
|
+
protected _pages: AtlasPage[];
|
|
25
|
+
protected _slots: Map<string, GlyphSlot | null>;
|
|
26
|
+
protected _newPage(): AtlasPage;
|
|
27
|
+
/**
|
|
28
|
+
* 取(必要时栅格化)一个字形 slot。`inkW/inkH` 为字形 ink 盒的逻辑尺寸;`raster` 在
|
|
29
|
+
* 已预置变换的 2D 上下文里绘制该字形。返回 null 表示该字形超过单页容量(调用方应回退到整段栅格)。
|
|
30
|
+
*/
|
|
31
|
+
acquire(key: string, inkW: number, inkH: number, raster: GlyphRasterFn): GlyphSlot | null;
|
|
32
|
+
clear(): void;
|
|
33
|
+
}
|
|
34
|
+
export declare const sharedGlyphAtlas: GlyphAtlas;
|
|
35
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.26.0",
|
|
5
5
|
"packageManager": "pnpm@10.19.0",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine. only the ESM.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"modern-font": "^0.6.1",
|
|
66
66
|
"modern-idoc": "^0.12.3",
|
|
67
67
|
"modern-path2d": "^1.8.6",
|
|
68
|
-
"modern-text": "^2.0
|
|
68
|
+
"modern-text": "^2.1.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"echarts": "^5 || ^6",
|