text-shaper 0.1.12 → 0.1.13

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.
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { type Gradient } from "../raster/gradient.ts";
7
7
  import { type Bitmap, PixelMode, type RasterizedGlyph } from "../raster/types.ts";
8
+ import type { Matrix2D, Matrix3x3 } from "../render/outline-transform.ts";
8
9
  /**
9
10
  * BitmapBuilder provides a fluent interface for bitmap manipulations
10
11
  */
@@ -58,6 +59,38 @@ export declare class BitmapBuilder {
58
59
  * Embolden (dilate) bitmap
59
60
  */
60
61
  embolden(xStrength: number, yStrength?: number): BitmapBuilder;
62
+ /**
63
+ * Embolden bitmap and update bearing to avoid clipping
64
+ */
65
+ emboldenWithBearing(xStrength: number, yStrength?: number): BitmapBuilder;
66
+ /**
67
+ * Apply 2D affine transform to bitmap (bearing-aware)
68
+ */
69
+ transform2D(matrix: Matrix2D, options?: {
70
+ offsetX26?: number;
71
+ offsetY26?: number;
72
+ }): BitmapBuilder;
73
+ /**
74
+ * Apply 3D perspective transform to bitmap (bearing-aware)
75
+ */
76
+ transform3D(matrix: Matrix3x3, options?: {
77
+ offsetX26?: number;
78
+ offsetY26?: number;
79
+ }): BitmapBuilder;
80
+ /**
81
+ * Shear bitmap horizontally (synthetic italic)
82
+ */
83
+ shearX(amount: number, options?: {
84
+ offsetX26?: number;
85
+ offsetY26?: number;
86
+ }): BitmapBuilder;
87
+ /**
88
+ * Shear bitmap vertically
89
+ */
90
+ shearY(amount: number, options?: {
91
+ offsetX26?: number;
92
+ offsetY26?: number;
93
+ }): BitmapBuilder;
61
94
  /**
62
95
  * Shift bitmap position
63
96
  */
@@ -75,6 +108,45 @@ export declare class BitmapBuilder {
75
108
  */
76
109
  pad(left: number, top: number, right: number, bottom: number): BitmapBuilder;
77
110
  pad(all: number): BitmapBuilder;
111
+ /**
112
+ * Measure ascent/descent from bitmap coverage
113
+ */
114
+ measure(): {
115
+ ascent: number;
116
+ descent: number;
117
+ };
118
+ /**
119
+ * Get raster metrics for this bitmap (includes ascent/descent)
120
+ */
121
+ metrics(): {
122
+ width: number;
123
+ height: number;
124
+ bearingX: number;
125
+ bearingY: number;
126
+ ascent: number;
127
+ descent: number;
128
+ };
129
+ /**
130
+ * Expand raster metrics for blur/border/shadow padding
131
+ */
132
+ expandMetrics(options: {
133
+ blur?: number;
134
+ be?: number;
135
+ border?: number;
136
+ shadowX?: number;
137
+ shadowY?: number;
138
+ }): {
139
+ width: number;
140
+ height: number;
141
+ bearingX: number;
142
+ bearingY: number;
143
+ ascent: number;
144
+ descent: number;
145
+ padLeft: number;
146
+ padRight: number;
147
+ padTop: number;
148
+ padBottom: number;
149
+ };
78
150
  /**
79
151
  * Alpha blend another bitmap onto this one at position
80
152
  */
@@ -8,7 +8,7 @@
8
8
  import type { Font } from "../font/font.ts";
9
9
  import { atlasToAlpha, atlasToRGBA, buildAsciiAtlas, buildAtlas, buildStringAtlas, getGlyphUV } from "../raster/atlas.ts";
10
10
  import { buildMsdfAsciiAtlas, buildMsdfAtlas, buildMsdfStringAtlas, msdfAtlasToRGB, msdfAtlasToRGBA } from "../raster/msdf.ts";
11
- import { rasterizeGlyph, rasterizeText } from "../raster/rasterize.ts";
11
+ import { rasterizeGlyph, rasterizeGlyphWithTransform, rasterizeText } from "../raster/rasterize.ts";
12
12
  import type { AtlasOptions, Bitmap, GlyphAtlas, MsdfAtlasOptions } from "../raster/types.ts";
13
13
  import type { GlyphPath } from "../render/path.ts";
14
14
  import { renderShapedText, renderShapedTextWithVariation, shapedTextToSVG, shapedTextToSVGWithVariation } from "../render/path.ts";
@@ -94,9 +94,9 @@ export declare function bitmap(b: Bitmap): BitmapBuilder;
94
94
  * ```
95
95
  */
96
96
  export declare function combine(...paths: PathBuilder[]): PathBuilder;
97
- export { adaptiveBlur, blur, boxBlur, cascadeBlur, clone, combinePaths, condensePath, convert, copy, embolden, emboldenPath, fastBlur, fromGlyph, italic, matrix, obliquePath, pad, perspective, pipe, rasterize, rasterizeAuto, rasterizeWithGradient, renderMsdf, renderSdf, resize, resizeBilinear, rotate, rotateDeg, scale, shear, shift, strokeAsymmetric, strokeAsymmetricCombined, strokePath, toGray, toRGBA, toSVG, translate, } from "./pipe.ts";
97
+ export { adaptiveBlur, blur, boxBlur, cascadeBlur, clone, combinePaths, condensePath, convert, copy, embolden, emboldenGlyph, emboldenPath, fastBlur, fromGlyph, italic, matrix, obliquePath, pad, perspective, pipe, rasterize, rasterizeAuto, rasterizeWithGradient, renderMsdf, renderSdf, resize, resizeBilinear, rotate, rotateDeg, scale, shear, shearBitmapX, shearBitmapY, shearGlyphX, shearGlyphY, shift, strokeAsymmetric, strokeAsymmetricCombined, strokePath, toGray, toRGBA, toSVG, transformBitmap2D, transformBitmap3D, transformGlyph2D, transformGlyph3D, translate, } from "./pipe.ts";
98
98
  export { buildAtlas, buildAsciiAtlas, buildStringAtlas, atlasToRGBA, atlasToAlpha, getGlyphUV, };
99
99
  export { buildMsdfAtlas, buildMsdfAsciiAtlas, buildMsdfStringAtlas, msdfAtlasToRGB, msdfAtlasToRGBA, };
100
- export { rasterizeGlyph, rasterizeText };
100
+ export { rasterizeGlyph, rasterizeGlyphWithTransform, rasterizeText };
101
101
  export { renderShapedText, shapedTextToSVG, renderShapedTextWithVariation, shapedTextToSVGWithVariation, };
102
102
  export type { AtlasOptions, GlyphAtlas, MsdfAtlasOptions };
@@ -10,7 +10,7 @@ import type { Gradient } from "../raster/gradient.ts";
10
10
  import { type MsdfOptions } from "../raster/msdf.ts";
11
11
  import { type SdfOptions } from "../raster/sdf.ts";
12
12
  import type { LineCap, LineJoin, StrokerOptions } from "../raster/stroker.ts";
13
- import type { Bitmap, PixelMode, RasterizeOptions } from "../raster/types.ts";
13
+ import type { Bitmap, PixelMode, RasterizeOptions, RasterizedGlyph } from "../raster/types.ts";
14
14
  import type { Matrix2D, Matrix3x3 } from "../render/outline-transform.ts";
15
15
  import type { GlyphPath } from "../render/path.ts";
16
16
  import type { GlyphId } from "../types.ts";
@@ -158,6 +158,66 @@ export declare function fastBlur(radius: number): (bitmap: Bitmap) => Bitmap;
158
158
  * Embolden bitmap operator
159
159
  */
160
160
  export declare function embolden(xStrength: number, yStrength?: number): (bitmap: Bitmap) => Bitmap;
161
+ /**
162
+ * Embolden bitmap and expand bearings (for rasterized glyphs)
163
+ */
164
+ export declare function emboldenGlyph(xStrength: number, yStrength?: number): (glyph: RasterizedGlyph) => RasterizedGlyph;
165
+ /**
166
+ * Transform bitmap with 2D matrix (origin at top-left)
167
+ */
168
+ export declare function transformBitmap2D(matrix: Matrix2D, options?: {
169
+ offsetX26?: number;
170
+ offsetY26?: number;
171
+ }): (bitmap: Bitmap) => Bitmap;
172
+ /**
173
+ * Transform bitmap with 3D matrix (origin at top-left)
174
+ */
175
+ export declare function transformBitmap3D(matrix: Matrix3x3, options?: {
176
+ offsetX26?: number;
177
+ offsetY26?: number;
178
+ }): (bitmap: Bitmap) => Bitmap;
179
+ /**
180
+ * Transform rasterized glyph with 2D matrix (bearing-aware)
181
+ */
182
+ export declare function transformGlyph2D(matrix: Matrix2D, options?: {
183
+ offsetX26?: number;
184
+ offsetY26?: number;
185
+ }): (glyph: RasterizedGlyph) => RasterizedGlyph;
186
+ /**
187
+ * Transform rasterized glyph with 3D matrix (bearing-aware)
188
+ */
189
+ export declare function transformGlyph3D(matrix: Matrix3x3, options?: {
190
+ offsetX26?: number;
191
+ offsetY26?: number;
192
+ }): (glyph: RasterizedGlyph) => RasterizedGlyph;
193
+ /**
194
+ * Shear bitmap horizontally (origin at top-left)
195
+ */
196
+ export declare function shearBitmapX(amount: number, options?: {
197
+ offsetX26?: number;
198
+ offsetY26?: number;
199
+ }): (bitmap: Bitmap) => Bitmap;
200
+ /**
201
+ * Shear bitmap vertically (origin at top-left)
202
+ */
203
+ export declare function shearBitmapY(amount: number, options?: {
204
+ offsetX26?: number;
205
+ offsetY26?: number;
206
+ }): (bitmap: Bitmap) => Bitmap;
207
+ /**
208
+ * Shear rasterized glyph horizontally (bearing-aware)
209
+ */
210
+ export declare function shearGlyphX(amount: number, options?: {
211
+ offsetX26?: number;
212
+ offsetY26?: number;
213
+ }): (glyph: RasterizedGlyph) => RasterizedGlyph;
214
+ /**
215
+ * Shear rasterized glyph vertically (bearing-aware)
216
+ */
217
+ export declare function shearGlyphY(amount: number, options?: {
218
+ offsetX26?: number;
219
+ offsetY26?: number;
220
+ }): (glyph: RasterizedGlyph) => RasterizedGlyph;
161
221
  /**
162
222
  * Shift bitmap position
163
223
  */
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { processContextual, processInsertion, processLigature, processRearrangem
2
2
  export { execute, runCVTProgram, runFontProgram, runGlyphProgram, runProgram, setCodeRange, createHintingEngine, executeFontProgram, type GlyphOutline, type HintedGlyph, type HintingEngine, hintedToPixels, hintGlyph, loadCVTProgram, loadFontProgram, setSize, compensate, parseSuperRound, round, roundDownToGrid, roundOff, roundSuper, roundSuper45, roundToDoubleGrid, roundToGrid, roundToHalfGrid, roundUpToGrid, type CallRecord, CodeRange, createDefaultGraphicsState, createExecContext, createGlyphZone, type ExecContext, type F2Dot14, type F26Dot6, type FunctionDef, type GlyphZone, type GraphicsState, type InstructionDef, Opcode, type Point as HintingPoint, RoundMode, TouchFlag, type UnitVector, } from "./hinting/index.ts";
3
3
  export { GlyphBuffer } from "./buffer/glyph-buffer.ts";
4
4
  export { UnicodeBuffer } from "./buffer/unicode-buffer.ts";
5
- export { adaptiveBlur as $adaptiveBlur, BitmapBuilder, bitmap, blur as $blur, boxBlur as $boxBlur, cascadeBlur as $cascadeBlur, char, clone as $clone, combine, combinePaths as $combinePaths, condensePath as $condensePath, convert as $convert, copy as $copy, embolden as $embolden, emboldenPath as $emboldenPath, fastBlur as $fastBlur, fromGlyph as $fromGlyph, glyph, glyphVar, italic as $italic, matrix as $matrix, obliquePath as $obliquePath, PathBuilder, pad as $pad, path, perspective as $perspective, pipe, rasterize as $rasterize, rasterizeAuto as $rasterizeAuto, rasterizeWithGradient as $rasterizeWithGradient, renderMsdf as $renderMsdf, renderSdf as $renderSdf, resize as $resize, resizeBilinear as $resizeBilinear, rotate as $rotate, rotateDeg as $rotateDeg, scale as $scale, shear as $shear, shift as $shift, strokeAsymmetric as $strokeAsymmetric, strokeAsymmetricCombined as $strokeAsymmetricCombined, strokePath as $strokePath, toGray as $toGray, toRGBA as $toRGBA, toSVG as $toSVG, translate as $translate, } from "./fluent/index.ts";
5
+ export { adaptiveBlur as $adaptiveBlur, BitmapBuilder, bitmap, blur as $blur, boxBlur as $boxBlur, cascadeBlur as $cascadeBlur, char, clone as $clone, combine, combinePaths as $combinePaths, condensePath as $condensePath, convert as $convert, copy as $copy, embolden as $embolden, emboldenGlyph as $emboldenGlyph, emboldenPath as $emboldenPath, fastBlur as $fastBlur, fromGlyph as $fromGlyph, glyph, glyphVar, italic as $italic, matrix as $matrix, obliquePath as $obliquePath, PathBuilder, pad as $pad, path, perspective as $perspective, pipe, rasterize as $rasterize, rasterizeAuto as $rasterizeAuto, rasterizeWithGradient as $rasterizeWithGradient, renderMsdf as $renderMsdf, renderSdf as $renderSdf, resize as $resize, resizeBilinear as $resizeBilinear, rotate as $rotate, rotateDeg as $rotateDeg, scale as $scale, shear as $shear, shearBitmapX as $shearBitmapX, shearBitmapY as $shearBitmapY, shearGlyphX as $shearGlyphX, shearGlyphY as $shearGlyphY, shift as $shift, strokeAsymmetric as $strokeAsymmetric, strokeAsymmetricCombined as $strokeAsymmetricCombined, strokePath as $strokePath, toGray as $toGray, toRGBA as $toRGBA, toSVG as $toSVG, transformBitmap2D as $transformBitmap2D, transformBitmap3D as $transformBitmap3D, transformGlyph2D as $transformGlyph2D, transformGlyph3D as $transformGlyph3D, translate as $translate, } from "./fluent/index.ts";
6
6
  export type { AutoRasterOptions, CanvasOptions, RasterOptions, SVGElementOptions, SVGOptions, TransformState, } from "./fluent/types.ts";
7
7
  export { Reader } from "./font/binary/reader.ts";
8
8
  export { createFace, Face } from "./font/face.ts";
@@ -99,17 +99,18 @@ export { getExactBounds } from "./raster/bbox.ts";
99
99
  export { abs, ceilPixel, clamp, divFix, downscale, f26Dot6ToFloat, F16DOT16_ONE, F16DOT16_SHIFT, F26DOT6_ONE, F26DOT6_SHIFT, floatToF26Dot6, floatToPixel, floorPixel, fracPixel, hypot, mulDiv, mulFix, normalizeVector, ONE_PIXEL, PIXEL_BITS, PIXEL_MASK, roundPixel, sign, truncPixel, upscale, vectorLength, } from "./raster/fixed-point.ts";
100
100
  export type { ValidationResult } from "./raster/outline-decompose.ts";
101
101
  export { decomposePath, getFillRuleFromFlags, getPathBounds, OutlineError, validateOutline, } from "./raster/outline-decompose.ts";
102
- export { addBitmaps, blendBitmap, compositeBitmaps, convertBitmap, copyBitmap, emboldenBitmap, expandToFit, fixOutline, maxBitmaps, mulBitmaps, padBitmap, resizeBitmap, resizeBitmapBilinear, shiftBitmap, subBitmaps, } from "./raster/bitmap-utils.ts";
102
+ export { addBitmaps, blendBitmap, compositeBitmaps, convertBitmap, copyBitmap, emboldenBitmap, emboldenBitmapWithBearing, expandRasterMetrics, expandToFit, fixOutlineBitmap, fixOutline, maxBitmaps, mulBitmaps, padBitmap, resizeBitmap, resizeBitmapBilinear, shearBitmapX, shearBitmapY, shiftBitmap, subtractBitmap, subBitmaps, transformBitmap2D, transformBitmap3D, measureRasterGlyph, } from "./raster/bitmap-utils.ts";
103
103
  export { blurBitmap, boxBlur, createGaussianKernel, gaussianBlur, } from "./raster/blur.ts";
104
104
  export { adaptiveBlur, cascadeBlur, fastGaussianBlur, } from "./raster/cascade-blur.ts";
105
105
  export { type ColorStop as GradientColorStop, createGradientBitmap, type Gradient, interpolateGradient, type LinearGradient, type RadialGradient, rasterizePathWithGradient, } from "./raster/gradient.ts";
106
106
  export { LCD_FILTER_DEFAULT, LCD_FILTER_LEGACY, LCD_FILTER_LIGHT, lcdToRGBA, LcdMode, rasterizeLcd, } from "./raster/lcd-filter.ts";
107
107
  export { assignEdgeColors, buildMsdfAsciiAtlas, buildMsdfAtlas, buildMsdfStringAtlas, type MsdfEdge, type MsdfOptions, median, msdfAtlasToRGB, msdfAtlasToRGBA, type Point as MsdfPoint, renderMsdf, type SignedDistanceResult, signedDistanceToCubic, signedDistanceToLine, signedDistanceToQuadratic, } from "./raster/msdf.ts";
108
- export { bitmapToGray, bitmapToRGBA, rasterizeGlyph, rasterizePath, rasterizeText, } from "./raster/rasterize.ts";
108
+ export { bitmapToGray, bitmapToRGBA, rasterizeGlyph, rasterizeGlyphWithTransform, rasterizePath, rasterizeText, } from "./raster/rasterize.ts";
109
109
  export { renderSdf, type SdfOptions } from "./raster/sdf.ts";
110
110
  export { type LineCap, type LineJoin, type StrokerOptions, strokePath, } from "./raster/stroker.ts";
111
111
  export { condensePath, emboldenPath, obliquePath } from "./raster/synth.ts";
112
112
  export type { Bitmap, GlyphAtlas, GlyphMetrics, MsdfAtlasOptions, RasterizedGlyph, RasterizeOptions, Span, } from "./raster/types.ts";
113
+ export type { BitmapTransformOptions, RasterEffectOptions, RasterMetrics, } from "./raster/bitmap-utils.ts";
113
114
  export { clearBitmap, createBitmap, FillRule, PixelMode, } from "./raster/types.ts";
114
115
  export { type BoundingBox, type ControlBox, clonePath, combinePaths, computeControlBox, computeTightBounds, identity2D, identity3x3, italicizeOutline, type Matrix2D, type Matrix3x3, multiply2D, multiply3x3, perspectiveMatrix, rotate2D, rotateOutline, rotateOutline90, scale2D, scaleOutline, scaleOutlinePow2, shear2D, transformOutline2D, transformOutline3D, transformPoint2D, transformPoint3x3, translate2D, translateOutline, updateMinTransformedX, } from "./render/outline-transform.ts";
115
116
  export type { GlyphPath, PathCommand, ShapedGlyph } from "./render/path.ts";