abstract-image 3.3.2 → 3.4.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/CHANGELOG.md +54 -38
- package/LICENSE +21 -21
- package/README.md +73 -73
- package/lib/_tests_/exporters/svg-export-image.test.d.ts.map +1 -0
- package/lib/_tests_/exporters/svg-export-image.test.js.map +1 -0
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-ellipse.js +379 -379
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-group.js +123 -123
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-line.js +55 -55
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polygon.js +89 -89
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polyline.js +79 -79
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-rectangle.js +99 -99
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text-growth-directions.js +135 -135
- package/lib/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text.js +63 -63
- package/lib/exporters/__tests__/eps-export-image/export.test.js +1 -1
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-ellipse.js +24 -24
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-empty-text.js +26 -26
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-group.js +31 -31
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-line.js +20 -20
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-polygon.js +34 -34
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-polyline.js +26 -26
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-rectangle.js +20 -20
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-growth-directions.js +59 -59
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-iso-latin1-encoding.d.ts +3 -0
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-iso-latin1-encoding.d.ts.map +1 -0
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-iso-latin1-encoding.js +71 -0
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text-iso-latin1-encoding.js.map +1 -0
- package/lib/exporters/__tests__/eps-export-image/test-defs/eps-text.js +26 -26
- package/lib/exporters/eps-export-image.d.ts +2 -0
- package/lib/exporters/eps-export-image.d.ts.map +1 -1
- package/lib/exporters/eps-export-image.js +113 -32
- package/lib/exporters/eps-export-image.js.map +1 -1
- package/package.json +4 -2
- package/src/__stories__/react-svg-export/example-1.stories.tsx +54 -54
- package/src/__stories__/svg-export/example-1.stories.tsx +42 -42
- package/src/exporters/__tests__/dxf2d-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/dxf2d-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-ellipse.ts +405 -405
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-group.ts +166 -166
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-line.ts +80 -80
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polygon.ts +114 -114
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-polyline.ts +103 -103
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-rectangle.ts +125 -125
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text-growth-directions.ts +214 -214
- package/src/exporters/__tests__/dxf2d-export-image/test-defs/dxf2d-text.ts +97 -97
- package/src/exporters/__tests__/eps-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/eps-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-ellipse.ts +50 -50
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-empty-text.ts +60 -60
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-group.ts +74 -74
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-line.ts +45 -45
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-polygon.ts +65 -65
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-polyline.ts +58 -58
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-rectangle.ts +46 -46
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-text-growth-directions.ts +138 -138
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-text-iso-latin1-encoding.ts +71 -0
- package/src/exporters/__tests__/eps-export-image/test-defs/eps-text.ts +60 -60
- package/src/exporters/__tests__/exception/png-unsupported.test.tsx +25 -25
- package/src/exporters/__tests__/exception/react-svg-direction-exception.test.tsx +65 -65
- package/src/exporters/__tests__/exception/svg-direction-exception.test.tsx +65 -65
- package/src/exporters/__tests__/png-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/png-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/png-export-image/test-defs/png-createPNG.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/export-test-def.tsx +13 -13
- package/src/exporters/__tests__/react-svg-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary-png.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary-url.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-binary.tsx +25 -25
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-callback.tsx +60 -60
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-ellipse.tsx +28 -28
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-empty-text.tsx +35 -35
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-group.tsx +44 -44
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-line.tsx +26 -26
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-polygon.tsx +32 -32
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-polyline.tsx +33 -33
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-rectangle.tsx +27 -27
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-subimage.tsx +36 -36
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-bold.tsx +50 -50
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-growth-directions.tsx +80 -80
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-italic.tsx +65 -65
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text-sub.tsx +35 -35
- package/src/exporters/__tests__/react-svg-export-image/test-defs/react-svg-text.tsx +35 -35
- package/src/exporters/__tests__/svg-export-image/export-test-def.ts +11 -11
- package/src/exporters/__tests__/svg-export-image/export.test.tsx +13 -13
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-binary.tsx +25 -25
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-ellipse.ts +27 -27
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-empty-text.ts +34 -34
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-group.ts +44 -44
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-line.ts +26 -26
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-polygon.ts +32 -32
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-polyline.ts +33 -33
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-rectangle.ts +27 -27
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-bold.ts +50 -50
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-growth-directions.ts +80 -80
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text-italic.ts +65 -65
- package/src/exporters/__tests__/svg-export-image/test-defs/svg-text.ts +35 -35
- package/src/exporters/dxf2d-export-image.ts +218 -218
- package/src/exporters/eps-export-image.ts +233 -154
- package/src/exporters/index.ts +3 -3
- package/src/exporters/png-export-image.ts +12 -12
- package/src/exporters/react-svg-export-image.tsx +315 -315
- package/src/exporters/svg-export-image.ts +309 -309
- package/src/index.ts +11 -11
- package/src/model/__tests__/color/export-test-def.ts +13 -13
- package/src/model/__tests__/color/export.test.tsx +14 -14
- package/src/model/__tests__/color/test-defs/color-from-string.ts +46 -46
- package/src/model/__tests__/color/test-defs/color-to-string.ts +35 -35
- package/src/model/__tests__/color/test-defs/color-undefined-2.ts +8 -8
- package/src/model/__tests__/color/test-defs/color-undefined.ts +8 -8
- package/src/model/abstract-image.ts +25 -25
- package/src/model/color.ts +52 -52
- package/src/model/component.ts +279 -279
- package/src/model/index.ts +5 -5
- package/src/model/point.ts +11 -11
- package/src/model/size.ts +11 -11
- package/lib/exporters/__tests__/svg-export-image.test.d.ts.map +0 -1
- package/lib/exporters/__tests__/svg-export-image.test.js.map +0 -1
- /package/lib/{exporters/__tests__ → _tests_/exporters}/svg-export-image.test.d.ts +0 -0
- /package/lib/{exporters/__tests__ → _tests_/exporters}/svg-export-image.test.js +0 -0
|
@@ -1,154 +1,233 @@
|
|
|
1
|
-
import * as AI from "../model/index";
|
|
2
|
-
import * as R from "ramda";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
]
|
|
94
|
-
...
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function
|
|
130
|
-
if (c.
|
|
131
|
-
return `
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
} else
|
|
135
|
-
return `
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
];
|
|
154
|
-
}
|
|
1
|
+
import * as AI from "../model/index";
|
|
2
|
+
import * as R from "ramda";
|
|
3
|
+
|
|
4
|
+
type CharacterEncoding = "standard-encoding" | "iso-latin-1-encoding";
|
|
5
|
+
|
|
6
|
+
export function epsExportImage(root: AI.AbstractImage): string;
|
|
7
|
+
export function epsExportImage(root: AI.AbstractImage, characterEncoding: "standard-encoding"): string;
|
|
8
|
+
export function epsExportImage(root: AI.AbstractImage, characterEncoding: "iso-latin-1-encoding"): Uint8Array;
|
|
9
|
+
export function epsExportImage(root: AI.AbstractImage, characterEncoding?: CharacterEncoding): string | Uint8Array {
|
|
10
|
+
if (characterEncoding === "iso-latin-1-encoding") {
|
|
11
|
+
const eps = [
|
|
12
|
+
...createEpsHeaderLines(root),
|
|
13
|
+
...createIsoLatin1FontLines(root),
|
|
14
|
+
...R.unnest<string>(root.components.map((c) => epsExportComponent(c, root.size.height, "iso-latin-1-encoding"))),
|
|
15
|
+
].join("\n");
|
|
16
|
+
return encodeLatin1Encoding(eps);
|
|
17
|
+
} else {
|
|
18
|
+
return [
|
|
19
|
+
...createEpsHeaderLines(root),
|
|
20
|
+
...R.unnest<string>(root.components.map((c) => epsExportComponent(c, root.size.height, "standard-encoding"))),
|
|
21
|
+
].join("\n");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createEpsHeaderLines(root: AI.AbstractImage): ReadonlyArray<string> {
|
|
26
|
+
return [
|
|
27
|
+
"%!PS-Adobe-3.0 EPSF-3.0",
|
|
28
|
+
`%%BoundingBox: 0 0 ${root.size.width} ${root.size.height}`,
|
|
29
|
+
"/ellipse {7 dict begin",
|
|
30
|
+
"/endangle exch def",
|
|
31
|
+
"/startangle exch def",
|
|
32
|
+
"/yradius exch def",
|
|
33
|
+
"/xradius exch def",
|
|
34
|
+
"/yC exch def",
|
|
35
|
+
"/xC exch def",
|
|
36
|
+
"/savematrix matrix currentmatrix def",
|
|
37
|
+
"xC yC translate",
|
|
38
|
+
"xradius yradius scale",
|
|
39
|
+
"0 0 1 startangle endangle arc",
|
|
40
|
+
"savematrix setmatrix",
|
|
41
|
+
"end",
|
|
42
|
+
"} def",
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function epsExportComponent(c: AI.Component, height: number, characterEncoding: CharacterEncoding): Array<string> {
|
|
47
|
+
switch (c.type) {
|
|
48
|
+
case "ellipse": {
|
|
49
|
+
const cx = (c.topLeft.x + c.bottomRight.x) * 0.5;
|
|
50
|
+
const cy = height - (c.topLeft.y + c.bottomRight.y) * 0.5;
|
|
51
|
+
const rx = 0.5 * (c.bottomRight.x - c.topLeft.x);
|
|
52
|
+
const ry = 0.5 * (c.bottomRight.y - c.topLeft.y);
|
|
53
|
+
return [
|
|
54
|
+
...getColored(c.fillColor, [`${cx} ${cy} ${rx} ${ry} 0 360 ellipse`, "closepath", "fill"]),
|
|
55
|
+
...getColored(c.strokeColor, [
|
|
56
|
+
`${cx} ${cy} ${rx} ${ry} 0 360 ellipse`,
|
|
57
|
+
"closepath",
|
|
58
|
+
`${c.strokeThickness} setlinewidth`,
|
|
59
|
+
"stroke",
|
|
60
|
+
]),
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
case "group": {
|
|
64
|
+
return R.unnest<string>(c.children.map((cc) => epsExportComponent(cc, height, characterEncoding)));
|
|
65
|
+
}
|
|
66
|
+
case "line": {
|
|
67
|
+
return getColored(c.strokeColor, [
|
|
68
|
+
`${c.start.x} ${height - c.start.y} moveto`,
|
|
69
|
+
`${c.end.x} ${height - c.end.y} lineto`,
|
|
70
|
+
`${c.strokeThickness} setlinewidth`,
|
|
71
|
+
"stroke",
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
case "polygon": {
|
|
75
|
+
return [
|
|
76
|
+
...getColored(c.fillColor, [
|
|
77
|
+
`${c.points[0].x} ${height - c.points[0].y} moveto`,
|
|
78
|
+
...c.points.map((p) => `${p.x} ${height - p.y} lineto`),
|
|
79
|
+
"closepath",
|
|
80
|
+
`${c.strokeThickness} setlinewidth`,
|
|
81
|
+
"fill",
|
|
82
|
+
]),
|
|
83
|
+
...getColored(c.strokeColor, [
|
|
84
|
+
`${c.points[0].x} ${height - c.points[0].y} moveto`,
|
|
85
|
+
...c.points.map((p) => `${p.x} ${height - p.y} lineto`),
|
|
86
|
+
"closepath",
|
|
87
|
+
"stroke",
|
|
88
|
+
]),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
case "polyline": {
|
|
92
|
+
return getColored(c.strokeColor, [
|
|
93
|
+
`${c.points[0].x} ${height - c.points[0].y} moveto`,
|
|
94
|
+
...c.points.map((p) => `${p.x} ${height - p.y} lineto`),
|
|
95
|
+
`${c.strokeThickness} setlinewidth`,
|
|
96
|
+
"stroke",
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
case "rectangle": {
|
|
100
|
+
const w = c.bottomRight.x - c.topLeft.x;
|
|
101
|
+
const h = c.bottomRight.y - c.topLeft.y;
|
|
102
|
+
return [
|
|
103
|
+
...getColored(c.fillColor, [`${c.topLeft.x} ${height - c.bottomRight.y} ${w} ${h} rectfill`]),
|
|
104
|
+
...getColored(c.strokeColor, [
|
|
105
|
+
`${c.strokeThickness} setlinewidth`,
|
|
106
|
+
`${c.topLeft.x} ${height - c.bottomRight.y} ${w} ${h} rectstroke`,
|
|
107
|
+
]),
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
case "text": {
|
|
111
|
+
return getColored(c.textColor, [
|
|
112
|
+
`gsave`,
|
|
113
|
+
`/${createFontName(characterEncoding, c.fontFamily)} findfont`,
|
|
114
|
+
`${c.fontSize} scalefont setfont`,
|
|
115
|
+
`${c.position.x} ${height - c.position.y} moveto`,
|
|
116
|
+
getTextXOffset(c),
|
|
117
|
+
getTextYOffset(c),
|
|
118
|
+
`rmoveto`,
|
|
119
|
+
`${-c.clockwiseRotationDegrees} rotate`,
|
|
120
|
+
`(${c.text}) show`,
|
|
121
|
+
`grestore`,
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getTextXOffset(c: AI.Text): string {
|
|
130
|
+
if (c.horizontalGrowthDirection === "left") {
|
|
131
|
+
return `(${c.text}) stringwidth pop neg`;
|
|
132
|
+
} else if (c.horizontalGrowthDirection === "uniform") {
|
|
133
|
+
return `(${c.text}) stringwidth pop neg 0.5 mul`;
|
|
134
|
+
} else {
|
|
135
|
+
return `0`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getTextYOffset(c: AI.Text): string {
|
|
140
|
+
if (c.verticalGrowthDirection === "down") {
|
|
141
|
+
return `gsave (${c.text}) true charpath pathbbox exch pop 3 -1 roll pop sub grestore`;
|
|
142
|
+
} else if (c.verticalGrowthDirection === "uniform") {
|
|
143
|
+
return `gsave (${c.text}) true charpath pathbbox exch pop 3 -1 roll pop sub 0.5 mul grestore`;
|
|
144
|
+
} else {
|
|
145
|
+
return `0`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getColored(color: AI.Color, instructions: Array<string>): Array<string> {
|
|
150
|
+
if (color.a === 0) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
return [`${color.r / 255} ${color.g / 255} ${color.b / 255} setrgbcolor`, ...instructions];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function createFontName(characterEncoding: CharacterEncoding, fontFamily: string): string {
|
|
157
|
+
if (characterEncoding === "iso-latin-1-encoding") {
|
|
158
|
+
return `${fontFamily}-ISOLatin1`;
|
|
159
|
+
} else {
|
|
160
|
+
return fontFamily;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function encodeLatin1Encoding(text: string): Uint8Array {
|
|
165
|
+
// ISOLatin1Encoding is close to iso-8859-1 encoding (https://en.wikipedia.org/wiki/PostScript_Latin_1_Encoding)
|
|
166
|
+
// Code points 0-256 returned by codePointAt() maps to iso-8859-1
|
|
167
|
+
const unknownCharacter = "?".codePointAt(0) || 32;
|
|
168
|
+
const output: Array<number> = [];
|
|
169
|
+
// Array.from() to handle characters consisting of multiple code points
|
|
170
|
+
for (const c of Array.from(text)) {
|
|
171
|
+
if (c.length > 1) {
|
|
172
|
+
output.push(unknownCharacter);
|
|
173
|
+
} else {
|
|
174
|
+
const cp = c.codePointAt(0) || 32;
|
|
175
|
+
if (cp > 255) {
|
|
176
|
+
output.push(unknownCharacter);
|
|
177
|
+
}
|
|
178
|
+
output.push(cp);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return new Uint8Array(output);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function createIsoLatin1FontLines(root: AI.AbstractImage): ReadonlyArray<string> {
|
|
185
|
+
const fontFamilies = getUsedFontFamilies(root.components);
|
|
186
|
+
const lines = [];
|
|
187
|
+
for (const fontFamily of fontFamilies) {
|
|
188
|
+
// 1. Makes a copy of the font dictionary, including all entries except the one whose
|
|
189
|
+
// key is FID. (This exclusion is necessary only in LanguageLevel 1; in Language-
|
|
190
|
+
// Level 2, the interpreter ignores any existing FID entry in a font being defined.)
|
|
191
|
+
//
|
|
192
|
+
// 2. Installs the desired change: replaces the font’s Encoding array with the value of
|
|
193
|
+
// ISOLatin1Encoding, which is a built-in, 256-element array of character names
|
|
194
|
+
// defined in systemdict.
|
|
195
|
+
//
|
|
196
|
+
// 3. Registers this modified font under a new name (Helvetica-ISOLatin1).
|
|
197
|
+
//
|
|
198
|
+
// https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf
|
|
199
|
+
lines.push(
|
|
200
|
+
...[
|
|
201
|
+
`/${fontFamily} findfont`,
|
|
202
|
+
"dup length dict begin",
|
|
203
|
+
" { 1 index /FID ne",
|
|
204
|
+
" {def}",
|
|
205
|
+
" {pop pop}",
|
|
206
|
+
" ifelse",
|
|
207
|
+
" } forall",
|
|
208
|
+
" /Encoding ISOLatin1Encoding def",
|
|
209
|
+
" currentdict",
|
|
210
|
+
"end",
|
|
211
|
+
`/${createFontName("iso-latin-1-encoding", fontFamily)} exch definefont pop`,
|
|
212
|
+
]
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return lines;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function getUsedFontFamilies(components: ReadonlyArray<AI.Component>): ReadonlyArray<string> {
|
|
219
|
+
const families = [];
|
|
220
|
+
for (const c of components) {
|
|
221
|
+
switch (c.type) {
|
|
222
|
+
case "text":
|
|
223
|
+
families.push(c.fontFamily);
|
|
224
|
+
break;
|
|
225
|
+
case "group":
|
|
226
|
+
families.push(...getUsedFontFamilies(c.children));
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return R.uniq(families);
|
|
233
|
+
}
|
package/src/exporters/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./svg-export-image";
|
|
2
|
-
export * from "./png-export-image";
|
|
3
|
-
export * from "./dxf2d-export-image";
|
|
1
|
+
export * from "./svg-export-image";
|
|
2
|
+
export * from "./png-export-image";
|
|
3
|
+
export * from "./dxf2d-export-image";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as AbstractImage from "../model/index";
|
|
2
|
-
|
|
3
|
-
export function createPNG(image: AbstractImage.AbstractImage): Uint8Array {
|
|
4
|
-
if (image.components.length !== 1) {
|
|
5
|
-
throw new Error("Not supported!");
|
|
6
|
-
}
|
|
7
|
-
const component = image.components[0];
|
|
8
|
-
if (component.type === "binaryimage" && component.format === "png" && component.data.type === "bytes") {
|
|
9
|
-
return component.data.bytes;
|
|
10
|
-
}
|
|
11
|
-
throw new Error("Not supported!");
|
|
12
|
-
}
|
|
1
|
+
import * as AbstractImage from "../model/index";
|
|
2
|
+
|
|
3
|
+
export function createPNG(image: AbstractImage.AbstractImage): Uint8Array {
|
|
4
|
+
if (image.components.length !== 1) {
|
|
5
|
+
throw new Error("Not supported!");
|
|
6
|
+
}
|
|
7
|
+
const component = image.components[0];
|
|
8
|
+
if (component.type === "binaryimage" && component.format === "png" && component.data.type === "bytes") {
|
|
9
|
+
return component.data.bytes;
|
|
10
|
+
}
|
|
11
|
+
throw new Error("Not supported!");
|
|
12
|
+
}
|