@unmade/text-renderer 0.1.0 → 0.1.2
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/dist/index.cjs +8 -1
- package/dist/index.d.ts +80 -2
- package/dist/index.js +2358 -2100
- package/dist/node/index.cjs +8 -1
- package/dist/node/index.d.ts +80 -2
- package/dist/node/index.js +2361 -2102
- package/dist/worker/index.cjs +8 -1
- package/dist/worker/index.d.ts +80 -2
- package/dist/worker/index.js +2358 -2100
- package/package.json +2 -2
package/dist/node/index.d.ts
CHANGED
|
@@ -1,13 +1,91 @@
|
|
|
1
1
|
import { default as default_2 } from 'opentype.js';
|
|
2
2
|
import { SVGGlyphData } from '@unmade/svg-glyphs';
|
|
3
3
|
|
|
4
|
+
export declare type BaselineType = 'flat' | 'curved';
|
|
5
|
+
|
|
6
|
+
export declare type BoxDimensions = {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
physicalWidth: number;
|
|
10
|
+
physicalHeight: number;
|
|
11
|
+
physicalUnits: MeasurementUnits;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export declare const DEFAULT_OUTLINE_FACTOR = 0.03125;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Generate a path command to curve text and align that text to the top of the box
|
|
18
|
+
* We use two quadratic bezier curves[1] - one from the bottom left to the peak of the path, and a second, mirrored, from the peak to the end of the path
|
|
19
|
+
* Using two curves allows us to explicitly define the peak of the curve, which will be at the horizontal centre of the box, far enough down from the top of the box that there's space for the text
|
|
20
|
+
* SVG Quadratic curves require two sets of coordinates - a control point and end point, with the start point being the end point of the previous command
|
|
21
|
+
* [1] https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#B%C3%A9zier_Curves
|
|
22
|
+
*
|
|
23
|
+
* Curved text is not currently supported for multiline text so this does not handle multiline parameters
|
|
24
|
+
*
|
|
25
|
+
* @param boxWidth - the width of the box
|
|
26
|
+
* @param boxHeight - the height of the box
|
|
27
|
+
* @param textBaselineYPosition - the distance from the top of rendered text to the baseline
|
|
28
|
+
* @param textHeight - the height of the text being rendered
|
|
29
|
+
* @param verticalAlignment - the vertical alignment of the text
|
|
30
|
+
* @returns an SVG path command to draw the curve
|
|
31
|
+
*/
|
|
32
|
+
export declare const generateCurvedBaseline: (boxDimensions: BoxDimensions, textBaselineYPosition: number, textHeight: number, verticalAlignment: VerticalTextAlignmentValues) => string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate a path as a baseline for straight text
|
|
36
|
+
* This can be called multiple times for multiline text by incrementing the lineNumber parameter
|
|
37
|
+
*
|
|
38
|
+
* @param boxDimensions - dimensions of the box into which the text will be rendered
|
|
39
|
+
* @param totalHeightOfAllTextLines - combined measured height of all lines of text
|
|
40
|
+
* @param textBaselineYPosition - the y position of the measured baseline for this specific line of text
|
|
41
|
+
* @param heightOfThisTextLine - the height of this specific line of text
|
|
42
|
+
* @param verticalAlignment - vertical alignment of the text within the box
|
|
43
|
+
* @param lineNumber - the line number of this text line (starting from 0)
|
|
44
|
+
* @returns an SVG path command to draw the curve
|
|
45
|
+
*/
|
|
46
|
+
export declare const generateFlatBaseline: (boxDimensions: BoxDimensions, totalHeightOfAllTextLines: number, textBaselineYPosition: number, heightOfThisTextLine: number, verticalAlignment?: VerticalTextAlignmentValues, lineNumber?: number) => string;
|
|
47
|
+
|
|
4
48
|
export declare const getFontCache: () => Map<any, any>;
|
|
5
49
|
|
|
6
|
-
export declare
|
|
7
|
-
|
|
50
|
+
export declare const getFontSizeFromPhysicalSize: (font: LoadedFont, boxDimensions: BoxDimensions, physicalFontSize: PhysicalSize, textOutlineFactor?: number) => number;
|
|
51
|
+
|
|
52
|
+
export declare const getRenderedText: (options: RenderTextOptions) => Promise<string>;
|
|
53
|
+
|
|
54
|
+
export declare const getTextMetricsAtFontSize: (font: LoadedFont, text: string, fontSize: number, outlineFactor?: number) => {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
baseline: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export declare type HorizontalTextAlignmentValues = 'left' | 'centre' | 'right' | 'distributed';
|
|
61
|
+
|
|
62
|
+
export declare const LINE_HEIGHT = 1.1;
|
|
63
|
+
|
|
64
|
+
export declare type LoadedFont = default_2.Font & LoadedFontExtras;
|
|
65
|
+
|
|
66
|
+
declare interface LoadedFontExtras {
|
|
8
67
|
svgGlyphs?: Map<number, SVGGlyphData>;
|
|
9
68
|
}
|
|
10
69
|
|
|
11
70
|
export declare const loadOpentypeFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
|
|
12
71
|
|
|
72
|
+
export declare type MeasurementUnits = 'mm' | 'in';
|
|
73
|
+
|
|
74
|
+
export declare type PhysicalSize = [height: number, units: MeasurementUnits];
|
|
75
|
+
|
|
76
|
+
export declare interface RenderTextOptions {
|
|
77
|
+
text: string;
|
|
78
|
+
fontUrl: string;
|
|
79
|
+
physicalSize: PhysicalSize;
|
|
80
|
+
boxDimensions: BoxDimensions;
|
|
81
|
+
outlineFactor?: number;
|
|
82
|
+
verticalAlignment?: VerticalTextAlignmentValues;
|
|
83
|
+
baseline?: BaselineType;
|
|
84
|
+
horizontalAlignment?: HorizontalTextAlignmentValues;
|
|
85
|
+
fillColour?: string;
|
|
86
|
+
strokeColour?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export declare type VerticalTextAlignmentValues = 'centre' | 'top' | 'bottom';
|
|
90
|
+
|
|
13
91
|
export { }
|