@ohos-ports/canvas 3.2.3-beta.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.
Files changed (51) hide show
  1. package/Readme.md +657 -0
  2. package/binding.gyp +229 -0
  3. package/browser.js +31 -0
  4. package/index.d.ts +507 -0
  5. package/index.js +94 -0
  6. package/install-prebuilt.js +117 -0
  7. package/lib/DOMMatrix.js +678 -0
  8. package/lib/bindings.js +43 -0
  9. package/lib/canvas.js +113 -0
  10. package/lib/context2d.js +11 -0
  11. package/lib/image.js +97 -0
  12. package/lib/jpegstream.js +41 -0
  13. package/lib/pattern.js +15 -0
  14. package/lib/pdfstream.js +35 -0
  15. package/lib/pngstream.js +42 -0
  16. package/package.json +75 -0
  17. package/src/Backends.h +9 -0
  18. package/src/Canvas.cc +1026 -0
  19. package/src/Canvas.h +128 -0
  20. package/src/CanvasError.h +37 -0
  21. package/src/CanvasGradient.cc +113 -0
  22. package/src/CanvasGradient.h +20 -0
  23. package/src/CanvasPattern.cc +129 -0
  24. package/src/CanvasPattern.h +33 -0
  25. package/src/CanvasRenderingContext2d.cc +3527 -0
  26. package/src/CanvasRenderingContext2d.h +238 -0
  27. package/src/CharData.h +233 -0
  28. package/src/FontParser.cc +605 -0
  29. package/src/FontParser.h +115 -0
  30. package/src/Image.cc +1719 -0
  31. package/src/Image.h +146 -0
  32. package/src/ImageData.cc +138 -0
  33. package/src/ImageData.h +26 -0
  34. package/src/InstanceData.h +12 -0
  35. package/src/JPEGStream.h +157 -0
  36. package/src/PNG.h +292 -0
  37. package/src/Point.h +11 -0
  38. package/src/Util.h +9 -0
  39. package/src/bmp/BMPParser.cc +459 -0
  40. package/src/bmp/BMPParser.h +60 -0
  41. package/src/bmp/LICENSE.md +24 -0
  42. package/src/closure.cc +52 -0
  43. package/src/closure.h +98 -0
  44. package/src/color.cc +796 -0
  45. package/src/color.h +30 -0
  46. package/src/dll_visibility.h +20 -0
  47. package/src/init.cc +114 -0
  48. package/src/register_font.cc +352 -0
  49. package/src/register_font.h +7 -0
  50. package/util/has_lib.js +119 -0
  51. package/util/win_jpeg_lookup.js +21 -0
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Install script: tries to copy prebuilt binaries from the npm package
5
+ * canvas-prebuilt-openharmony-arm64. Falls back to node-gyp rebuild
6
+ * if the prebuilt package is not available (non-OpenHarmony platform).
7
+ *
8
+ * After copying, creates SONAME symlinks so the dynamic linker can find
9
+ * shared libraries at runtime (e.g. libpixman-1.so.0 -> libpixman-1.so.0.46.4).
10
+ */
11
+ const path = require("path");
12
+ const fs = require("fs");
13
+ const { execSync } = require("child_process");
14
+
15
+ function copyDirRecursive(src, dest) {
16
+ if (!fs.existsSync(src)) return;
17
+ fs.mkdirSync(dest, { recursive: true });
18
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
19
+ const srcPath = path.join(src, entry.name);
20
+ const destPath = path.join(dest, entry.name);
21
+ if (entry.isSymbolicLink()) {
22
+ const target = fs.readlinkSync(srcPath);
23
+ if (fs.existsSync(destPath)) fs.rmSync(destPath);
24
+ fs.symlinkSync(target, destPath);
25
+ } else if (entry.isDirectory()) {
26
+ copyDirRecursive(srcPath, destPath);
27
+ } else {
28
+ fs.copyFileSync(srcPath, destPath);
29
+ }
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Read the SONAME embedded in an ELF shared library via readelf.
35
+ * Returns null if readelf is unavailable or the file has no SONAME.
36
+ */
37
+ function readSoname(filePath) {
38
+ try {
39
+ const output = execSync(`readelf -d "${filePath}" 2>/dev/null`, {
40
+ encoding: "utf8",
41
+ timeout: 5000,
42
+ });
43
+ const match = output.match(/SONAME.*?\[(.+?)\]/);
44
+ return match ? match[1] : null;
45
+ } catch {
46
+ return null;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Create SONAME symlinks for all .so files in the given directory.
52
+ *
53
+ * The dynamic linker resolves libraries by SONAME (e.g. libpixman-1.so.0),
54
+ * but prebuilt packages ship the real file with its full version suffix
55
+ * (e.g. libpixman-1.so.0.46.4). This function bridges the gap.
56
+ *
57
+ * Also handles the special case where libffi's SONAME is "libffi.so" but
58
+ * libpango requires "libffi.so.8" at runtime.
59
+ */
60
+ function createSonameSymlinks(dir) {
61
+ if (!fs.existsSync(dir)) return;
62
+
63
+ const files = fs.readdirSync(dir);
64
+ let created = 0;
65
+
66
+ for (const file of files) {
67
+ // Skip symlinks and non-.so files
68
+ const filePath = path.join(dir, file);
69
+ const stat = fs.lstatSync(filePath);
70
+ if (stat.isSymbolicLink() || !file.includes(".so")) continue;
71
+
72
+ const soname = readSoname(filePath);
73
+ if (soname && soname !== file) {
74
+ const linkPath = path.join(dir, soname);
75
+ if (!fs.existsSync(linkPath)) {
76
+ fs.symlinkSync(file, linkPath);
77
+ console.log(`[canvas] ${soname} -> ${file}`);
78
+ created++;
79
+ }
80
+ }
81
+ }
82
+
83
+ // Special case: libffi.so.8
84
+ // libffi's ELF SONAME is "libffi.so", but libpango links against
85
+ // "libffi.so.8". Create the intermediate symlink if the real file exists.
86
+ const libffiReal = files.find(
87
+ (f) => f.startsWith("libffi.so.") && !fs.lstatSync(path.join(dir, f)).isSymbolicLink()
88
+ );
89
+ if (libffiReal) {
90
+ const ffiLink = path.join(dir, "libffi.so.8");
91
+ if (!fs.existsSync(ffiLink)) {
92
+ fs.symlinkSync(libffiReal, ffiLink);
93
+ console.log(`[canvas] libffi.so.8 -> ${libffiReal}`);
94
+ created++;
95
+ }
96
+ }
97
+
98
+ return created;
99
+ }
100
+
101
+ try {
102
+ const prebuiltPath = require.resolve(
103
+ "canvas-prebuilt-openharmony-arm64/build/Release/canvas.node"
104
+ );
105
+ const prebuiltDir = path.dirname(prebuiltPath);
106
+ const destDir = path.join(__dirname, "build", "Release");
107
+
108
+ copyDirRecursive(prebuiltDir, destDir);
109
+ console.log("[canvas] Installed prebuilt binaries from canvas-prebuilt-openharmony-arm64");
110
+
111
+ console.log("[canvas] Creating SONAME symlinks...");
112
+ const count = createSonameSymlinks(destDir);
113
+ console.log(`[canvas] Created ${count} symlink(s)`);
114
+ } catch {
115
+ console.log("[canvas] No prebuilt package available, falling back to node-gyp");
116
+ process.exit(1);
117
+ }