1+ import type { Font , FontAtlas , FontEntry , FontSizeMode } from "../fonts" ;
2+ import type {
3+ AtlasOptions ,
4+ GlyphRasterizeOptions ,
5+ Matrix2D ,
6+ Matrix3x3 ,
7+ RasterizedGlyph ,
8+ } from "text-shaper" ;
9+
110/**
211 * Metadata for constrained glyph rendering.
312 * - cp: Unicode code point
@@ -39,24 +48,82 @@ export type AtlasConstraintContext = {
3948 iconHeight : number ;
4049 iconHeightSingle : number ;
4150 } ;
42- fontEntry : any ;
51+ fontEntry : FontEntry ;
52+ } ;
53+
54+ type RasterizeGlyphTransformOptions = GlyphRasterizeOptions & {
55+ offsetX26 ?: number ;
56+ offsetY26 ?: number ;
57+ } ;
58+
59+ type RasterizeGlyphFn = (
60+ font : Font ,
61+ glyphId : number ,
62+ fontSize : number ,
63+ options ?: GlyphRasterizeOptions ,
64+ ) => RasterizedGlyph | null ;
65+
66+ type RasterizeGlyphWithTransformFn = (
67+ font : Font ,
68+ glyphId : number ,
69+ fontSize : number ,
70+ matrix : Matrix2D | Matrix3x3 ,
71+ options ?: RasterizeGlyphTransformOptions ,
72+ ) => RasterizedGlyph | null ;
73+
74+ type BuildGlyphAtlasWithConstraintsOptions = {
75+ font : Font ;
76+ glyphIds : number [ ] ;
77+ fontSize : number ;
78+ sizeMode : FontSizeMode ;
79+ padding : number ;
80+ maxWidth : number ;
81+ maxHeight : number ;
82+ pixelMode : number ;
83+ hinting : boolean ;
84+ rasterizeGlyph ?: RasterizeGlyphFn ;
85+ rasterizeGlyphWithTransform ?: RasterizeGlyphWithTransformFn ;
86+ glyphMeta ?: Map < number , GlyphConstraintMeta > ;
87+ constraintContext ?: AtlasConstraintContext ;
88+ } ;
89+
90+ type BuildGlyphAtlasWithConstraintsResult = {
91+ atlas : FontAtlas | null ;
92+ constrainedGlyphWidths ?: Map < number , number > | null ;
93+ } ;
94+
95+ type BuildColorEmojiAtlasWithCanvasOptions = {
96+ font : Font ;
97+ fontEntry : FontEntry ;
98+ glyphIds : number [ ] ;
99+ fontSize : number ;
100+ sizeMode : FontSizeMode ;
101+ padding : number ;
102+ maxWidth : number ;
103+ maxHeight : number ;
104+ pixelMode : number ;
43105} ;
44106
45107type BuildAtlasDeps = {
46108 fontScaleOverrides : Array < { match : RegExp ; scale : number } > ;
47- sizeMode : string ;
48- isSymbolFont : ( entry : any ) => boolean ;
49- fontScaleOverride : ( entry : any , overrides : Array < { match : RegExp ; scale : number } > ) => number ;
50- resolveGlyphPixelMode : ( entry : any ) => number ;
51- atlasBitmapToRGBA : ( atlas : any ) => Uint8Array | null ;
52- padAtlasRGBA : ( rgba : Uint8Array , atlas : any , padding : number ) => Uint8Array ;
53- buildAtlas : ( font : any , glyphIds : number [ ] , options : any ) => any ;
109+ sizeMode : FontSizeMode ;
110+ isSymbolFont : ( entry : FontEntry | null | undefined ) => boolean ;
111+ fontScaleOverride : (
112+ entry : FontEntry | null | undefined ,
113+ overrides : Array < { match : RegExp ; scale : number } > ,
114+ ) => number ;
115+ resolveGlyphPixelMode : ( entry : FontEntry ) => number ;
116+ atlasBitmapToRGBA : ( atlas : FontAtlas ) => Uint8Array | null ;
117+ padAtlasRGBA : ( rgba : Uint8Array , atlas : FontAtlas , padding : number ) => Uint8Array ;
118+ buildAtlas : ( font : Font , glyphIds : number [ ] , options : AtlasOptions ) => FontAtlas ;
54119 buildGlyphAtlasWithConstraints : (
55- options : any ,
56- ) => { atlas : any ; constrainedGlyphWidths ?: any } | null ;
57- buildColorEmojiAtlasWithCanvas : ( options : any ) => { atlas : any } | null ;
58- rasterizeGlyph ?: any ;
59- rasterizeGlyphWithTransform ?: any ;
120+ options : BuildGlyphAtlasWithConstraintsOptions ,
121+ ) => BuildGlyphAtlasWithConstraintsResult | null ;
122+ buildColorEmojiAtlasWithCanvas : (
123+ options : BuildColorEmojiAtlasWithCanvasOptions ,
124+ ) => { atlas : FontAtlas } | null ;
125+ rasterizeGlyph ?: RasterizeGlyphFn ;
126+ rasterizeGlyphWithTransform ?: RasterizeGlyphWithTransformFn ;
60127 nerdConstraintSignature : (
61128 glyphMeta : Map < number , GlyphConstraintMeta > | undefined ,
62129 constraintContext : AtlasConstraintContext | null | undefined ,
@@ -87,7 +154,7 @@ type BuildAtlasDeps = {
87154 * - deps: external dependencies for atlas building
88155 */
89156export type BuildFontAtlasParams = {
90- entry : any ;
157+ entry : FontEntry ;
91158 neededGlyphIds : Set < number > ;
92159 glyphMeta ?: Map < number , GlyphConstraintMeta > ;
93160 fontSizePx : number ;
@@ -107,7 +174,7 @@ export type BuildFontAtlasParams = {
107174 */
108175export type BuildFontAtlasResult = {
109176 rebuilt : boolean ;
110- atlas : any | null ;
177+ atlas : FontAtlas | null ;
111178 rgba : Uint8Array | null ;
112179 colorGlyphs ?: Set < number > ;
113180 preferNearest : boolean ;
@@ -220,7 +287,7 @@ export function buildFontAtlasIfNeeded(params: BuildFontAtlasParams): BuildFontA
220287 const colorGlyphAtlas = glyphPixelMode === constants . pixelModeRgbaValue || glyphPixelMode === 4 ;
221288 const useCanvasColorAtlas = colorGlyphAtlas ;
222289
223- let atlas = null ;
290+ let atlas : FontAtlas | null = null ;
224291 if ( isSymbol && rasterizeGlyph && rasterizeGlyphWithTransform && constraintContext && glyphMeta ) {
225292 const result = buildGlyphAtlasWithConstraints ( {
226293 font : entry . font ,
0 commit comments