@bitbybit-dev/base 1.6.2 → 1.8.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/NOTICE +24 -0
- package/README.md +3 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +40 -7
- package/lib/api/inputs/base-inputs.js +32 -0
- package/lib/api/inputs/io-inputs.d.ts +927 -59
- package/lib/api/inputs/io-inputs.js +769 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/inputs/mesh-inputs.d.ts +20 -1
- package/lib/api/inputs/mesh-inputs.js +23 -0
- package/lib/api/inputs/recipes-inputs.d.ts +13 -5
- package/lib/api/inputs/recipes-inputs.js +10 -5
- package/lib/api/kernel-calls/index.d.ts +2 -0
- package/lib/api/kernel-calls/index.js +2 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +3 -1
- package/lib/api/kernel-calls/resolve-dto.js +7 -2
- package/lib/api/kernel-calls/settings.d.ts +101 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/kernel-calls/up-axis-aliases.d.ts +25 -0
- package/lib/api/kernel-calls/up-axis-aliases.js +70 -0
- package/lib/api/models/simplex.d.ts +2 -0
- package/lib/api/models/simplex.js +10 -1
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +32 -3
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.js +2 -3
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +3 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +1 -0
- package/lib/api/services/helpers/color/color-forms.js +4 -1
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +26 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +87 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +34 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.js +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.d.ts +4 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.js +271 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +101 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.js +123 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.js +91 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +336 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.d.ts +2 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.js +47 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.d.ts +9 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.js +25 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +117 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +41 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +46 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.js +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +196 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +97 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.js +312 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +115 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.js +151 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +134 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +95 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +446 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +248 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +89 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +43 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +47 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +132 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +18 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +230 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +14 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/loop-fill.d.ts +2 -0
- package/lib/api/services/helpers/geometry/loop-fill.js +37 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/helpers/helper-types.d.ts +33 -0
- package/lib/api/services/helpers/text/stroke-font.d.ts +6 -0
- package/lib/api/services/helpers/text/stroke-font.js +177 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.d.ts +2 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.js +18 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.d.ts +14 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.js +34 -0
- package/lib/api/services/io/drawing.d.ts +368 -0
- package/lib/api/services/io/drawing.js +454 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +66 -0
- package/lib/api/services/io/svg.js +105 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +6 -2
- package/lib/api/services/text.d.ts +7 -4
- package/lib/api/services/text.js +14 -27
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { STROKE_LETTERS } from "./stroke-letters.constants";
|
|
2
|
+
import { BASELINE_REACH, FIRST_COMPOSED, FULL_MARK_ADVANCE, LAST_UNIT, LEAST_RISE_SHARE, MARK_GAP, MARK_RISE, MOST_UNITS, OGONEK, SOFT_DOTTED, SOFT_DOT_FLOOR, STROKE_MARKS, UNKNOWN_GLYPH } from "./stroke-marks.constants";
|
|
3
|
+
const HALF = 2;
|
|
4
|
+
const facts = new WeakMap();
|
|
5
|
+
function strokesOf(points) {
|
|
6
|
+
const strokes = [];
|
|
7
|
+
let stroke = [];
|
|
8
|
+
let at = 0;
|
|
9
|
+
while (at < points.length) {
|
|
10
|
+
const x = points[at];
|
|
11
|
+
if (x === undefined) {
|
|
12
|
+
strokes.push(stroke);
|
|
13
|
+
stroke = [];
|
|
14
|
+
at += 1;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
stroke.push([x, points[at + 1]]);
|
|
18
|
+
at += 2;
|
|
19
|
+
}
|
|
20
|
+
if (stroke.length > 0) {
|
|
21
|
+
strokes.push(stroke);
|
|
22
|
+
}
|
|
23
|
+
return strokes;
|
|
24
|
+
}
|
|
25
|
+
function readGlyph(font, code) {
|
|
26
|
+
const [advance = 0, ...points] = font[code];
|
|
27
|
+
return { advance, strokes: strokesOf(points) };
|
|
28
|
+
}
|
|
29
|
+
function factsOf(font) {
|
|
30
|
+
const known = facts.get(font);
|
|
31
|
+
if (known !== undefined) {
|
|
32
|
+
return known;
|
|
33
|
+
}
|
|
34
|
+
let highest = -Infinity;
|
|
35
|
+
let lowest = Infinity;
|
|
36
|
+
for (const key of Object.keys(font)) {
|
|
37
|
+
const code = Number(key);
|
|
38
|
+
if (!Number.isInteger(code)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
for (const stroke of readGlyph(font, code).strokes) {
|
|
42
|
+
for (const point of stroke) {
|
|
43
|
+
highest = Math.max(highest, point[1]);
|
|
44
|
+
lowest = Math.min(lowest, point[1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const read = { lowest, highest, glyphs: new Map() };
|
|
49
|
+
facts.set(font, read);
|
|
50
|
+
return read;
|
|
51
|
+
}
|
|
52
|
+
function compositionOf(font, code) {
|
|
53
|
+
if (!Number.isInteger(code) || code < FIRST_COMPOSED || code > LAST_UNIT) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
const units = String.fromCharCode(code).normalize("NFD");
|
|
57
|
+
if (units.length < 2 || units.length > MOST_UNITS) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const base = units.charCodeAt(0);
|
|
61
|
+
if (font[base] === undefined) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
let above;
|
|
65
|
+
let below;
|
|
66
|
+
for (let at = 1; at < units.length; at += 1) {
|
|
67
|
+
const mark = units.charCodeAt(at);
|
|
68
|
+
if (above === undefined && STROKE_MARKS.above[mark] !== undefined) {
|
|
69
|
+
above = mark;
|
|
70
|
+
}
|
|
71
|
+
else if (below === undefined && STROKE_MARKS.below[mark] !== undefined) {
|
|
72
|
+
below = mark;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { base, above, below };
|
|
79
|
+
}
|
|
80
|
+
function placed(mark, x, y, wide, tall) {
|
|
81
|
+
return strokesOf(mark).map(stroke => stroke.map((point) => [x + point[0] * wide, y + point[1] * tall]));
|
|
82
|
+
}
|
|
83
|
+
function middleOf(points) {
|
|
84
|
+
let least = Infinity;
|
|
85
|
+
let most = -Infinity;
|
|
86
|
+
for (const point of points) {
|
|
87
|
+
least = Math.min(least, point[0]);
|
|
88
|
+
most = Math.max(most, point[0]);
|
|
89
|
+
}
|
|
90
|
+
return (least + most) / HALF;
|
|
91
|
+
}
|
|
92
|
+
function composedGlyph(font, composition) {
|
|
93
|
+
const base = readGlyph(font, composition.base);
|
|
94
|
+
const unit = font.height / STROKE_MARKS.height;
|
|
95
|
+
const dotless = composition.above !== undefined && SOFT_DOTTED.has(composition.base);
|
|
96
|
+
const kept = dotless ? base.strokes.filter(stroke => stroke.some(point => point[1] < SOFT_DOT_FLOOR * unit)) : base.strokes;
|
|
97
|
+
const ink = kept.flat();
|
|
98
|
+
if (ink.length === 0) {
|
|
99
|
+
return base;
|
|
100
|
+
}
|
|
101
|
+
const strokes = [...kept];
|
|
102
|
+
if (composition.above !== undefined) {
|
|
103
|
+
const top = ink.reduce((most, point) => Math.max(most, point[1]), -Infinity);
|
|
104
|
+
const floor = top + MARK_GAP * unit;
|
|
105
|
+
const rise = Math.min(1, Math.max(LEAST_RISE_SHARE, (factsOf(font).highest - floor) / (MARK_RISE * unit)));
|
|
106
|
+
const narrow = Math.min(1, base.advance / (FULL_MARK_ADVANCE * unit));
|
|
107
|
+
strokes.push(...placed(STROKE_MARKS.above[composition.above], middleOf(ink), floor, unit * narrow, unit * rise));
|
|
108
|
+
}
|
|
109
|
+
if (composition.below !== undefined) {
|
|
110
|
+
const mark = STROKE_MARKS.below[composition.below];
|
|
111
|
+
const feet = ink.filter(point => Math.abs(point[1]) <= BASELINE_REACH * unit);
|
|
112
|
+
const stood = feet.length > 0 ? feet : ink;
|
|
113
|
+
const x = composition.below === OGONEK ? stood.reduce((most, point) => Math.max(most, point[0]), -Infinity) : middleOf(stood);
|
|
114
|
+
const reach = strokesOf(mark).flat();
|
|
115
|
+
const right = reach.reduce((most, point) => Math.max(most, point[0]), 0) * unit;
|
|
116
|
+
const left = reach.reduce((least, point) => Math.min(least, point[0]), 0) * unit;
|
|
117
|
+
const narrow = Math.min(1, right > 0 ? (base.advance - x) / right : 1, left < 0 ? x / -left : 1);
|
|
118
|
+
strokes.push(...placed(mark, x, 0, unit * narrow, unit));
|
|
119
|
+
}
|
|
120
|
+
return { advance: base.advance, strokes };
|
|
121
|
+
}
|
|
122
|
+
function heldLetter(font, code) {
|
|
123
|
+
const overlay = STROKE_LETTERS.overlaid[code];
|
|
124
|
+
return STROKE_LETTERS.drawn[code] !== undefined || (overlay !== undefined && font[overlay.base] !== undefined);
|
|
125
|
+
}
|
|
126
|
+
function letterGlyph(font, code) {
|
|
127
|
+
const unit = font.height / STROKE_LETTERS.height;
|
|
128
|
+
const { lowest, highest } = factsOf(font);
|
|
129
|
+
const inked = (points) => placed(points, 0, 0, unit, unit)
|
|
130
|
+
.map(stroke => stroke.map((point) => [point[0], Math.min(highest, Math.max(lowest, point[1]))]));
|
|
131
|
+
const drawn = STROKE_LETTERS.drawn[code];
|
|
132
|
+
if (drawn !== undefined) {
|
|
133
|
+
const [advance = 0, ...points] = drawn;
|
|
134
|
+
return { advance: advance * unit, strokes: inked(points) };
|
|
135
|
+
}
|
|
136
|
+
const overlay = STROKE_LETTERS.overlaid[code];
|
|
137
|
+
const base = readGlyph(font, overlay.base);
|
|
138
|
+
return { advance: base.advance, strokes: [...base.strokes, ...inked(overlay.strokes)] };
|
|
139
|
+
}
|
|
140
|
+
export function strokeGlyph(font, code) {
|
|
141
|
+
const glyphs = factsOf(font).glyphs;
|
|
142
|
+
const own = Number.isFinite(code) && code !== 0 && font[code] !== undefined;
|
|
143
|
+
const lettered = !own && heldLetter(font, code);
|
|
144
|
+
const composition = own || lettered ? undefined : compositionOf(font, code);
|
|
145
|
+
const key = own || lettered || composition !== undefined ? code : UNKNOWN_GLYPH;
|
|
146
|
+
const cached = glyphs.get(key);
|
|
147
|
+
if (cached !== undefined) {
|
|
148
|
+
return cached;
|
|
149
|
+
}
|
|
150
|
+
const glyph = lettered ? letterGlyph(font, code) : composition === undefined ? readGlyph(font, key) : composedGlyph(font, composition);
|
|
151
|
+
glyphs.set(key, glyph);
|
|
152
|
+
return glyph;
|
|
153
|
+
}
|
|
154
|
+
export function strokeFontInk(font) {
|
|
155
|
+
const { lowest, highest } = factsOf(font);
|
|
156
|
+
return { lowest: lowest / font.height, highest: highest / font.height };
|
|
157
|
+
}
|
|
158
|
+
export function strokeTextAdvance(font, text) {
|
|
159
|
+
let advance = 0;
|
|
160
|
+
for (let unit = 0; unit < text.length; unit += 1) {
|
|
161
|
+
advance += strokeGlyph(font, text.charCodeAt(unit)).advance;
|
|
162
|
+
}
|
|
163
|
+
return advance / font.height;
|
|
164
|
+
}
|
|
165
|
+
export function strokeTextStrokes(font, text) {
|
|
166
|
+
const strokes = [];
|
|
167
|
+
let left = 0;
|
|
168
|
+
for (let unit = 0; unit < text.length; unit += 1) {
|
|
169
|
+
const glyph = strokeGlyph(font, text.charCodeAt(unit));
|
|
170
|
+
const start = left;
|
|
171
|
+
for (const stroke of glyph.strokes) {
|
|
172
|
+
strokes.push(stroke.map((point) => [(start + point[0]) / font.height, point[1] / font.height]));
|
|
173
|
+
}
|
|
174
|
+
left += glyph.advance;
|
|
175
|
+
}
|
|
176
|
+
return strokes;
|
|
177
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const STROKE_LETTERS = {
|
|
2
|
+
height: 21,
|
|
3
|
+
overlaid: {
|
|
4
|
+
216: { base: 79, strokes: [4, -1, 18, 22] },
|
|
5
|
+
248: { base: 111, strokes: [3, -1, 16, 15] },
|
|
6
|
+
272: { base: 68, strokes: [1, 11, 10, 11] },
|
|
7
|
+
273: { base: 100, strokes: [11, 18, 18, 18] },
|
|
8
|
+
321: { base: 76, strokes: [1, 8, 9, 13] },
|
|
9
|
+
322: { base: 108, strokes: [1, 9, 7, 13] },
|
|
10
|
+
},
|
|
11
|
+
drawn: {
|
|
12
|
+
198: [23, 10, 21, 1, 0, undefined, 10, 21, 10, 0, undefined, 10, 21, 21, 21, undefined, 6, 11, 18, 11, undefined, 10, 0, 21, 0],
|
|
13
|
+
223: [20, 4, 0, 4, 17, 5, 20, 7, 21, 10, 21, 12, 20, 13, 19, 14, 17, 13, 15, 10, 13, 13, 13, 15, 12, 16, 11, 17, 8, 17, 6, 16, 3, 14, 1, 11, 0, 8, 0],
|
|
14
|
+
230: [30, 15, 14, 15, 0, undefined, 15, 11, 13, 13, 11, 14, 8, 14, 6, 13, 4, 11, 3, 8, 3, 6, 4, 3, 6, 1, 8, 0, 11, 0, 13, 1, 15, 3, undefined, 15, 8, 27, 8, 27, 10, 26, 12, 25, 13, 23, 14, 20, 14, 18, 13, 16, 11, 15, 8, undefined, 15, 6, 16, 3, 18, 1, 20, 0, 23, 0, 25, 1, 27, 3],
|
|
15
|
+
338: [26, 13, 21, 9, 21, 7, 20, 5, 18, 4, 16, 3, 13, 3, 8, 4, 5, 5, 3, 7, 1, 9, 0, 13, 0, undefined, 13, 21, 13, 0, undefined, 13, 21, 24, 21, undefined, 13, 11, 21, 11, undefined, 13, 0, 24, 0],
|
|
16
|
+
339: [31, 8, 14, 6, 13, 4, 11, 3, 8, 3, 6, 4, 3, 6, 1, 8, 0, 11, 0, 13, 1, 15, 3, 16, 6, 16, 8, 15, 11, 13, 13, 11, 14, 8, 14, undefined, 16, 8, 28, 8, 28, 10, 27, 12, 26, 13, 24, 14, 21, 14, 19, 13, 17, 11, 16, 8, undefined, 16, 6, 17, 3, 19, 1, 21, 0, 24, 0, 26, 1, 28, 3],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StrokeFontMarks } from "../helper-types";
|
|
2
|
+
export declare const UNKNOWN_GLYPH = 63;
|
|
3
|
+
export declare const FIRST_COMPOSED = 128;
|
|
4
|
+
export declare const LAST_UNIT = 65535;
|
|
5
|
+
export declare const MOST_UNITS = 3;
|
|
6
|
+
export declare const SOFT_DOTTED: ReadonlySet<number>;
|
|
7
|
+
export declare const SOFT_DOT_FLOOR = 15;
|
|
8
|
+
export declare const MARK_GAP = 1.25;
|
|
9
|
+
export declare const MARK_RISE = 4;
|
|
10
|
+
export declare const LEAST_RISE_SHARE = 0.25;
|
|
11
|
+
export declare const FULL_MARK_ADVANCE = 10;
|
|
12
|
+
export declare const BASELINE_REACH = 1;
|
|
13
|
+
export declare const OGONEK = 808;
|
|
14
|
+
export declare const STROKE_MARKS: StrokeFontMarks;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const UNKNOWN_GLYPH = 63;
|
|
2
|
+
export const FIRST_COMPOSED = 0x80;
|
|
3
|
+
export const LAST_UNIT = 0xFFFF;
|
|
4
|
+
export const MOST_UNITS = 3;
|
|
5
|
+
export const SOFT_DOTTED = new Set([105, 106]);
|
|
6
|
+
export const SOFT_DOT_FLOOR = 15;
|
|
7
|
+
export const MARK_GAP = 1.25;
|
|
8
|
+
export const MARK_RISE = 4;
|
|
9
|
+
export const LEAST_RISE_SHARE = 0.25;
|
|
10
|
+
export const FULL_MARK_ADVANCE = 10;
|
|
11
|
+
export const BASELINE_REACH = 1;
|
|
12
|
+
export const OGONEK = 808;
|
|
13
|
+
export const STROKE_MARKS = {
|
|
14
|
+
height: 21,
|
|
15
|
+
above: {
|
|
16
|
+
768: [-2.5, 4, 1, 0],
|
|
17
|
+
769: [-1, 0, 2.5, 4],
|
|
18
|
+
770: [-3, 0, 0, 4, 3, 0],
|
|
19
|
+
771: [-4, 1, -3, 3, -1.5, 3.5, 1.5, 0.5, 3, 1, 4, 3],
|
|
20
|
+
772: [-3.5, 2, 3.5, 2],
|
|
21
|
+
774: [-3, 4, -2.5, 1.5, -1, 0, 1, 0, 2.5, 1.5, 3, 4],
|
|
22
|
+
775: [0, 3, -1, 2, 0, 1, 1, 2, 0, 3],
|
|
23
|
+
776: [-3, 3, -4, 2, -3, 1, -2, 2, -3, 3, undefined, 3, 3, 2, 2, 3, 1, 4, 2, 3, 3],
|
|
24
|
+
778: [-1, 4, -2, 3, -2, 1, -1, 0, 1, 0, 2, 1, 2, 3, 1, 4, -1, 4],
|
|
25
|
+
779: [-3, 0, -0.5, 4, undefined, 0.5, 0, 3, 4],
|
|
26
|
+
780: [-3, 4, 0, 0, 3, 4],
|
|
27
|
+
},
|
|
28
|
+
below: {
|
|
29
|
+
803: [0, -2, -1, -3, 0, -4, 1, -3, 0, -2],
|
|
30
|
+
806: [0, -2, 0.5, -3.5, -1, -5.5],
|
|
31
|
+
807: [0, 0, 0, -2, 1.5, -2.5, 1.5, -4.5, 0, -5.5, -2, -5],
|
|
32
|
+
808: [0, 0, -2, -2, -2.5, -3.5, -1.5, -5, 0.5, -5.5, 2, -5],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import * as Inputs from "../../inputs";
|
|
2
|
+
import type { Dxf } from "./dxf";
|
|
3
|
+
import type { Svg } from "./svg";
|
|
4
|
+
/**
|
|
5
|
+
* Builds drawings as data, for any file format: segments of every kind, paths joined from segments,
|
|
6
|
+
* and parts that put paths on a layer with a color and a line type. `io.dxf.dxfCreate` writes the
|
|
7
|
+
* parts as DXF and `io.svg.svgCreate` as SVG; `svgToDxf` and `dxfToSvg` convert one file into the
|
|
8
|
+
* other through these parts.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Drawing {
|
|
11
|
+
private readonly dxfOf;
|
|
12
|
+
private readonly svgOf;
|
|
13
|
+
constructor(dxfOf: () => Dxf, svgOf: () => Svg);
|
|
14
|
+
/**
|
|
15
|
+
* Makes a straight segment of a drawing path, from `start` to `end`.
|
|
16
|
+
* @param inputs - The start and the end point
|
|
17
|
+
* @returns The line segment
|
|
18
|
+
* @group drawing
|
|
19
|
+
* @shortname line segment
|
|
20
|
+
* @drawable false
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const edge = bitbybit.io.drawing.lineSegment({ start: [0, 0], end: [40, 0] });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
lineSegment(inputs: Inputs.IO.DrawingLineSegmentDto): Inputs.IO.DrawingLineSegmentDto;
|
|
27
|
+
/**
|
|
28
|
+
* Makes a circular arc of a drawing path, running counterclockwise about its `center` from
|
|
29
|
+
* `startAngle` to `endAngle`, in degrees, in the XY plane unless a `normal` tilts it.
|
|
30
|
+
* @param inputs - The center, the radius, the start and end angles and the plane's normal
|
|
31
|
+
* @returns The arc segment
|
|
32
|
+
* @group drawing
|
|
33
|
+
* @shortname arc segment
|
|
34
|
+
* @drawable false
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const corner = bitbybit.io.drawing.arcSegment({ center: [0, 0], radius: 10, startAngle: 0, endAngle: 90 });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
arcSegment(inputs: Inputs.IO.DrawingArcSegmentDto): Inputs.IO.DrawingArcSegmentDto;
|
|
41
|
+
/**
|
|
42
|
+
* Makes a whole circle of a drawing path from its `center` and `radius`, in the XY plane unless a
|
|
43
|
+
* `normal` tilts it.
|
|
44
|
+
* @param inputs - The center, the radius and the plane's normal
|
|
45
|
+
* @returns The circle segment
|
|
46
|
+
* @group drawing
|
|
47
|
+
* @shortname circle segment
|
|
48
|
+
* @drawable false
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const hole = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
circleSegment(inputs: Inputs.IO.DrawingCircleSegmentDto): Inputs.IO.DrawingCircleSegmentDto;
|
|
55
|
+
/**
|
|
56
|
+
* Makes connected straight segments through `points`, which `bulges` can bend into arcs;
|
|
57
|
+
* `closed` joins the last point back to the first.
|
|
58
|
+
* @param inputs - The points, whether the polyline is closed, and the bulges
|
|
59
|
+
* @returns The polyline segment
|
|
60
|
+
* @group drawing
|
|
61
|
+
* @shortname polyline segment
|
|
62
|
+
* @drawable false
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const slot = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [30, 0], [30, 10], [0, 10]], closed: true, bulges: [0, 1, 0, 1] });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
polylineSegment(inputs: Inputs.IO.DrawingPolylineSegmentDto): Inputs.IO.DrawingPolylineSegmentDto;
|
|
69
|
+
/**
|
|
70
|
+
* Makes a B-spline or NURBS curve of a drawing path from its control points and degree, with
|
|
71
|
+
* its knots and weights when they are given.
|
|
72
|
+
* @param inputs - The control points, the degree, whether it is closed, the knots and the weights
|
|
73
|
+
* @returns The spline segment
|
|
74
|
+
* @group drawing
|
|
75
|
+
* @shortname spline segment
|
|
76
|
+
* @drawable false
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const wave = bitbybit.io.drawing.splineSegment({ controlPoints: [[0, 0], [10, 8], [20, -8], [30, 0]], degree: 3 });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
splineSegment(inputs: Inputs.IO.DrawingSplineSegmentDto): Inputs.IO.DrawingSplineSegmentDto;
|
|
83
|
+
/**
|
|
84
|
+
* Makes an ellipse, or an arc of one, for a drawing path.
|
|
85
|
+
*
|
|
86
|
+
* The ellipse is given by its center, the vector to the end of its major axis and the minor to
|
|
87
|
+
* major ratio; parameters in radians pick the arc, running counterclockwise about the normal.
|
|
88
|
+
* @param inputs - The center, the major axis, the ratio, the start and end parameters and the plane's normal
|
|
89
|
+
* @returns The ellipse segment
|
|
90
|
+
* @group drawing
|
|
91
|
+
* @shortname ellipse segment
|
|
92
|
+
* @drawable false
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const lens = bitbybit.io.drawing.ellipseSegment({ center: [0, 0], majorAxis: [20, 0], ratio: 0.5, startParameter: 0, endParameter: Math.PI });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
ellipseSegment(inputs: Inputs.IO.DrawingEllipseSegmentDto): Inputs.IO.DrawingEllipseSegmentDto;
|
|
99
|
+
/**
|
|
100
|
+
* Joins segments into one path, drawn in order like the edges of a wire; segments that meet
|
|
101
|
+
* are drawn as one stroke in SVG.
|
|
102
|
+
* @param inputs - The segments, in order
|
|
103
|
+
* @returns The path
|
|
104
|
+
* @group drawing
|
|
105
|
+
* @shortname path
|
|
106
|
+
* @drawable false
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const edge = bitbybit.io.drawing.lineSegment({ start: [0, 0], end: [40, 0] });
|
|
110
|
+
* const corner = bitbybit.io.drawing.arcSegment({ center: [40, 10], radius: 10, startAngle: 270, endAngle: 360 });
|
|
111
|
+
* const outline = bitbybit.io.drawing.path({ segments: [edge, corner] });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
path(inputs: Inputs.IO.DrawingPathDto): Inputs.IO.DrawingPathDto;
|
|
115
|
+
/**
|
|
116
|
+
* Puts paths on a named layer with a color and a line type, making one part of a drawing.
|
|
117
|
+
*
|
|
118
|
+
* A drawing may hold several parts; `io.dxf.dxfCreate` writes them as DXF and `io.svg.svgCreate`
|
|
119
|
+
* as SVG.
|
|
120
|
+
* @param inputs - The layer name, the color, the paths and the line type
|
|
121
|
+
* @returns The part
|
|
122
|
+
* @group drawing
|
|
123
|
+
* @shortname part
|
|
124
|
+
* @drawable false
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const square = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
128
|
+
* const cut = bitbybit.io.drawing.part({ layer: "cut", color: "#ff0000", paths: [{ segments: [square] }] });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
part(inputs: Inputs.IO.DrawingPartDto): Inputs.IO.DrawingPartDto;
|
|
132
|
+
/**
|
|
133
|
+
* Scales drawing parts about the origin, returning new parts and leaving the given ones unchanged.
|
|
134
|
+
*
|
|
135
|
+
* Points, radii, axes, text heights, hatch spacings and line weights are multiplied by `factor`;
|
|
136
|
+
* angles, bulges, knots and weights stay. Scale before writing with `io.dxf.dxfCreate` or
|
|
137
|
+
* `io.svg.svgCreate`: their `unit` labels the drawing and never scales it. A factor not above 0
|
|
138
|
+
* throws.
|
|
139
|
+
* @param inputs - The parts and the factor
|
|
140
|
+
* @returns New parts, scaled
|
|
141
|
+
* @group drawing
|
|
142
|
+
* @shortname scale parts
|
|
143
|
+
* @drawable false
|
|
144
|
+
* @beta
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const plate = bitbybit.io.drawing.part({ layer: "cut", paths: [{ segments: [{ center: [0, 0], radius: 25.4 }] }], lineWeight: 0.5 });
|
|
148
|
+
* const inches = bitbybit.io.drawing.scaleParts({ parts: [plate], factor: 1 / 25.4 });
|
|
149
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: inches, unit: Bit.Inputs.Base.unitOfLengthEnum.inch });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
scaleParts(inputs: Inputs.IO.DrawingScalePartsDto): Inputs.IO.DrawingPartDto[];
|
|
153
|
+
/**
|
|
154
|
+
* Makes a line of text for a drawing part's `texts`, in the single-line stroke font.
|
|
155
|
+
*
|
|
156
|
+
* The text is placed by a point on its baseline; `anchor` says whether that point is its start,
|
|
157
|
+
* middle or end, `rotation` turns it and `widthFactor` narrows or widens its letters.
|
|
158
|
+
* @param inputs - The text, its position and height, its anchor, its angle and its width factor
|
|
159
|
+
* @returns The text
|
|
160
|
+
* @group drawing
|
|
161
|
+
* @shortname text
|
|
162
|
+
* @drawable false
|
|
163
|
+
* @beta
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const title = bitbybit.io.drawing.text({ text: "BRACKET", position: [20, 10], height: 5 });
|
|
167
|
+
* const notes = bitbybit.io.drawing.part({ layer: "text", paths: [], texts: [title], lineWeight: 0.35 });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
text(inputs: Inputs.IO.DrawingTextDto): Inputs.IO.DrawingTextDto;
|
|
171
|
+
/**
|
|
172
|
+
* Makes a hatched region for a drawing part's `hatches`: what the boundaries enclose, filled with
|
|
173
|
+
* a pattern of lines or with solid ink.
|
|
174
|
+
*
|
|
175
|
+
* A boundary inside another cuts a hole, and a boundary whose ends do not meet is closed by a
|
|
176
|
+
* straight line.
|
|
177
|
+
* @param inputs - The boundary paths, the pattern, and the angle and spacing of its lines
|
|
178
|
+
* @returns The hatch
|
|
179
|
+
* @group drawing
|
|
180
|
+
* @shortname hatch
|
|
181
|
+
* @drawable false
|
|
182
|
+
* @beta
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
186
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
187
|
+
* const cut = bitbybit.io.drawing.hatch({ boundaries: [{ segments: [outline] }, { segments: [bore] }], angle: 45, spacing: 3 });
|
|
188
|
+
* const section = bitbybit.io.drawing.part({ layer: "hatch", paths: [], hatches: [cut], lineWeight: 0.18 });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
hatch(inputs: Inputs.IO.DrawingHatchDto): Inputs.IO.DrawingHatchDto;
|
|
192
|
+
/**
|
|
193
|
+
* Gives the lines of a hatch's pattern, each from side to side of the box around its
|
|
194
|
+
* boundaries, for a renderer that draws them itself and clips them to the region.
|
|
195
|
+
*
|
|
196
|
+
* The lines stand where `io.svg.svgCreate` and `io.dxf.dxfCreate` put them, each whole. `solid`
|
|
197
|
+
* gives none, and a spacing too fine for the region throws.
|
|
198
|
+
* @param inputs - The boundary paths, the pattern, and the angle and spacing of its lines
|
|
199
|
+
* @returns The lines, each a start and an end point
|
|
200
|
+
* @group drawing
|
|
201
|
+
* @shortname hatch lines
|
|
202
|
+
* @drawable false
|
|
203
|
+
* @beta
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
207
|
+
* const lines = bitbybit.io.drawing.hatchLines({ boundaries: [{ segments: [outline] }], angle: 45, spacing: 3 });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
hatchLines(inputs: Inputs.IO.DrawingHatchDto): Inputs.Base.Segment2[];
|
|
211
|
+
/**
|
|
212
|
+
* Gives the lines of a hatch's pattern clipped to its region, for a renderer that draws them
|
|
213
|
+
* itself.
|
|
214
|
+
*
|
|
215
|
+
* Inside follows the even-odd rule over every boundary, as `io.svg.svgCreate` fills a hatch, and
|
|
216
|
+
* curves are followed within `tolerance`. The lines stand where `hatchLines` puts them. `solid`
|
|
217
|
+
* gives none; a spacing too fine for the region throws.
|
|
218
|
+
* @param inputs - The boundary paths, the pattern, the angle and spacing of its lines, and the tolerance for curves
|
|
219
|
+
* @returns The pieces of the lines inside the region, each a start and an end point
|
|
220
|
+
* @group drawing
|
|
221
|
+
* @shortname clipped hatch lines
|
|
222
|
+
* @drawable false
|
|
223
|
+
* @beta
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
227
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
228
|
+
* const lines = bitbybit.io.drawing.clippedHatchLines({ boundaries: [{ segments: [outline] }, { segments: [bore] }], angle: 45, spacing: 3, tolerance: 0.01 });
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
clippedHatchLines(inputs: Inputs.IO.DrawingHatchRegionDto): Inputs.Base.Segment2[];
|
|
232
|
+
/**
|
|
233
|
+
* Gives the outlines of a hatch's region as closed loops of points, curves followed within
|
|
234
|
+
* `tolerance`, for a renderer that fills the region itself.
|
|
235
|
+
*
|
|
236
|
+
* Each loop lists every corner once. Fill them under the even-odd rule, as
|
|
237
|
+
* `mesh.triangulateLoops` does, to keep the holes open.
|
|
238
|
+
* Example: a circle of radius 5 at tolerance 0.01 -> one loop of 50 points
|
|
239
|
+
* @param inputs - The boundary paths and the tolerance for curves; the pattern, angle and spacing play no part
|
|
240
|
+
* @returns The loops, each a list of points
|
|
241
|
+
* @group drawing
|
|
242
|
+
* @shortname hatch outlines
|
|
243
|
+
* @drawable false
|
|
244
|
+
* @beta
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
248
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
249
|
+
* const loops = bitbybit.io.drawing.hatchOutlines({ boundaries: [{ segments: [outline] }, { segments: [bore] }], tolerance: 0.01 });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
hatchOutlines(inputs: Inputs.IO.DrawingHatchRegionDto): Inputs.Base.Point2[][];
|
|
253
|
+
/**
|
|
254
|
+
* Measures a drawing text: its length along the baseline, and how far the font's ink reaches
|
|
255
|
+
* above and below it.
|
|
256
|
+
*
|
|
257
|
+
* The width is what `io.svg.svgCreate` draws and `io.dxf.dxfCreate` fits the text to; the
|
|
258
|
+
* position is not needed to measure it. A text that is not one line throws.
|
|
259
|
+
* Example: 'I' at height 21 -> width 8, above 25, below 7
|
|
260
|
+
* @param inputs - The text with its height and width factor
|
|
261
|
+
* @returns The width, and the reach of the font's ink above and below the baseline
|
|
262
|
+
* @group drawing
|
|
263
|
+
* @shortname text size
|
|
264
|
+
* @drawable false
|
|
265
|
+
* @beta
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const size = bitbybit.io.drawing.textSize({ text: "SECTION A-A", position: [0, 0], height: 3.5 });
|
|
269
|
+
* const cellWidth = size.width + 2;
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
textSize(inputs: Inputs.IO.DrawingTextDto): Inputs.IO.DrawingTextSizeDto;
|
|
273
|
+
/**
|
|
274
|
+
* Draws a drawing text as the strokes of its letters, each a list of points in the drawing's
|
|
275
|
+
* coordinates, placed, turned and narrowed as the text says.
|
|
276
|
+
*
|
|
277
|
+
* These are the strokes `io.svg.svgCreate` writes. A text that is not one line throws.
|
|
278
|
+
* Example: 'I' at height 21 from [10, 20] -> one stroke, [[14, 41, 0], [14, 20, 0]]
|
|
279
|
+
* @param inputs - The text, its position and height, its anchor, its angle and its width factor
|
|
280
|
+
* @returns The strokes, each a list of points
|
|
281
|
+
* @group drawing
|
|
282
|
+
* @shortname text strokes
|
|
283
|
+
* @drawable false
|
|
284
|
+
* @beta
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const strokes = bitbybit.io.drawing.textStrokes({ text: "A-A", position: [0, 0], height: 5, anchor: "middle" });
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
textStrokes(inputs: Inputs.IO.DrawingTextDto): Inputs.Base.Point3[][];
|
|
291
|
+
/**
|
|
292
|
+
* Draws a dimension in the drawing's plane: its dimension line or arc, its extension lines, filled
|
|
293
|
+
* arrowheads touching them, and its value in the stroke font.
|
|
294
|
+
*
|
|
295
|
+
* The text reads from left to right or from bottom to top, past the line's end when the line is
|
|
296
|
+
* too short for it; arrows go outside a span too short for them.
|
|
297
|
+
* @param inputs - What the dimension measures, its points, its tolerance and the size of its text and arrows
|
|
298
|
+
* @returns The lines, the arrowheads to fill, the text as strokes and as a drawing text, and the box they fill
|
|
299
|
+
* @group drawing
|
|
300
|
+
* @shortname dimension picture
|
|
301
|
+
* @drawable false
|
|
302
|
+
* @beta
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const picture = bitbybit.io.drawing.dimensionPicture({ kind: Bit.Inputs.IO.dimensionKindEnum.linear, start: [0, 0], end: [60, 0], offset: 12, upperTolerance: 0.1, lowerTolerance: 0.1 });
|
|
306
|
+
* const edges = bitbybit.io.drawing.part({ layer: "dimensions", paths: [...picture.lines, ...picture.textStrokes].map(points => ({ segments: [{ points }] })) });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
dimensionPicture(inputs: Inputs.IO.DrawingDimensionDto): Inputs.IO.DrawingDimensionPictureDto;
|
|
310
|
+
/**
|
|
311
|
+
* Measures the box a dimension's picture fills, the box `dimensionPicture` gives, without drawing
|
|
312
|
+
* the letters.
|
|
313
|
+
*
|
|
314
|
+
* The box holds the whole height the stroke font's letters may reach, so a layout can make room
|
|
315
|
+
* before drawing.
|
|
316
|
+
* Example: a linear dimension from [0, 0] to [60, 0] at offset 12 -> min [0, 0.875], max [60, 17.04]
|
|
317
|
+
* @param inputs - What the dimension measures, its points, its tolerance and the size of its text and arrows
|
|
318
|
+
* @returns The lowest and highest corners of the box
|
|
319
|
+
* @group drawing
|
|
320
|
+
* @shortname dimension extent
|
|
321
|
+
* @drawable false
|
|
322
|
+
* @beta
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* const box = bitbybit.io.drawing.dimensionExtent({ kind: Bit.Inputs.IO.dimensionKindEnum.diameter, start: [0, 0], end: [5, 0] });
|
|
326
|
+
* const width = box.max[0] - box.min[0];
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
dimensionExtent(inputs: Inputs.IO.DrawingDimensionDto): Inputs.IO.DrawingExtentDto;
|
|
330
|
+
/**
|
|
331
|
+
* Converts an SVG file into a DXF file, reading it as `io.svg.svgRead` does and writing it as
|
|
332
|
+
* `io.dxf.dxfCreate` does.
|
|
333
|
+
*
|
|
334
|
+
* Inkscape layers, stroke colors and dash patterns become DXF layers, colors and line types, and
|
|
335
|
+
* curves stay exact. With `unit` the drawing is read at true size and the DXF states that unit. A
|
|
336
|
+
* drawing too large to write throws.
|
|
337
|
+
* @param inputs - The SVG text, the unit, whether hidden elements are written, and the DXF's color format, version and curve tolerance
|
|
338
|
+
* @returns The DXF text and the reading's warnings
|
|
339
|
+
* @group convert
|
|
340
|
+
* @shortname svg to dxf
|
|
341
|
+
* @drawable false
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const converted = bitbybit.io.drawing.svgToDxf({ svg: svgText, unit: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
|
|
345
|
+
* const drawing = bitbybit.io.dxf.dxfRead({ dxf: converted.dxf });
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
svgToDxf(inputs: Inputs.IO.SvgToDxfDto): Inputs.IO.SvgToDxfResultDto;
|
|
349
|
+
/**
|
|
350
|
+
* Converts a DXF file into an SVG file, reading it as `io.dxf.dxfRead` does and writing it as
|
|
351
|
+
* `io.svg.svgCreate` does.
|
|
352
|
+
*
|
|
353
|
+
* Layers become Inkscape layers and the SVG takes its true size from the unit the DXF states.
|
|
354
|
+
* Splines given only by fit points are left out and named in `warnings`; a drawing too large to
|
|
355
|
+
* write throws.
|
|
356
|
+
* @param inputs - The DXF file as text or bytes, whether hidden layers are written, and the SVG's line width, border and curve tolerance
|
|
357
|
+
* @returns The SVG text and the reading's warnings
|
|
358
|
+
* @group convert
|
|
359
|
+
* @shortname dxf to svg
|
|
360
|
+
* @drawable false
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const converted = bitbybit.io.drawing.dxfToSvg({ dxf: dxfText, includeHiddenLayers: true });
|
|
364
|
+
* const drawing = bitbybit.io.svg.svgRead({ svg: converted.svg });
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
dxfToSvg(inputs: Inputs.IO.DxfToSvgDto): Inputs.IO.DxfToSvgResultDto;
|
|
368
|
+
}
|