@ohos-ports/canvas 3.2.3-beta.0 → 3.2.3-beta.1

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/index.js CHANGED
@@ -76,7 +76,12 @@ exports.createCanvas = createCanvas
76
76
  exports.createImageData = createImageData
77
77
  exports.loadImage = loadImage
78
78
 
79
- exports.backends = bindings.Backends
79
+ // Backends is declared in src/Backends.h but not yet implemented (no
80
+ // Backends.cc, not registered in init.cc). Only export it when the
81
+ // native module actually provides it.
82
+ if (bindings.Backends) {
83
+ exports.backends = bindings.Backends
84
+ }
80
85
 
81
86
  /** Library version. */
82
87
  exports.version = packageJson.version
@@ -98,19 +98,44 @@ function createSonameSymlinks(dir) {
98
98
  return created;
99
99
  }
100
100
 
101
+ /**
102
+ * Create a minimal fontconfig configuration file if the system does not
103
+ * provide one (e.g. OpenHarmony). The config points fontconfig at the
104
+ * system font directory so that text rendering works without warnings.
105
+ */
106
+ function ensureFontconfigConfig(dir) {
107
+ const fontsConfPath = path.join(dir, "fonts.conf");
108
+ if (fs.existsSync(fontsConfPath)) return;
109
+
110
+ // HarmonyOS keeps system fonts in /system/fonts
111
+ const fontsConf = `<?xml version="1.0"?>
112
+ <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
113
+ <fontconfig>
114
+ <dir>/system/fonts</dir>
115
+ <cachedir>/tmp/.fontconfig-cache</cachedir>
116
+ </fontconfig>
117
+ `;
118
+
119
+ fs.writeFileSync(fontsConfPath, fontsConf, "utf8");
120
+ console.log("[canvas] Created fonts.conf for fontconfig");
121
+ }
122
+
101
123
  try {
102
124
  const prebuiltPath = require.resolve(
103
- "canvas-prebuilt-openharmony-arm64/build/Release/canvas.node"
125
+ "@ohos-ports/canvas-prebuilt-openharmony-arm64/build/Release/canvas.node"
104
126
  );
105
127
  const prebuiltDir = path.dirname(prebuiltPath);
106
128
  const destDir = path.join(__dirname, "build", "Release");
107
129
 
108
130
  copyDirRecursive(prebuiltDir, destDir);
109
- console.log("[canvas] Installed prebuilt binaries from canvas-prebuilt-openharmony-arm64");
131
+ console.log("[canvas] Installed prebuilt binaries from @ohos-ports/canvas-prebuilt-openharmony-arm64");
110
132
 
111
133
  console.log("[canvas] Creating SONAME symlinks...");
112
134
  const count = createSonameSymlinks(destDir);
113
135
  console.log(`[canvas] Created ${count} symlink(s)`);
136
+
137
+ // Ensure fontconfig has a config file to read on OpenHarmony
138
+ ensureFontconfigConfig(destDir);
114
139
  } catch {
115
140
  console.log("[canvas] No prebuilt package available, falling back to node-gyp");
116
141
  process.exit(1);
package/lib/bindings.js CHANGED
@@ -1,5 +1,18 @@
1
1
  'use strict'
2
2
 
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+
6
+ // On OpenHarmony the system fontconfig config file may be missing.
7
+ // Set FONTCONFIG_PATH so the .so bundled with this package picks up
8
+ // the fonts.conf that install-prebuilt.js drops next to canvas.node.
9
+ if (!process.env.FONTCONFIG_PATH) {
10
+ const buildDir = path.join(__dirname, '..', 'build', 'Release')
11
+ if (fs.existsSync(path.join(buildDir, 'fonts.conf'))) {
12
+ process.env.FONTCONFIG_PATH = buildDir
13
+ }
14
+ }
15
+
3
16
  const bindings = require('../build/Release/canvas.node')
4
17
 
5
18
  module.exports = bindings
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ohos-ports/canvas",
3
3
  "description": "Canvas graphics API backed by Cairo",
4
- "version": "3.2.3-beta.0",
4
+ "version": "3.2.3-beta.1",
5
5
  "author": "TJ Holowaychuk <tj@learnboost.com>",
6
6
  "main": "index.js",
7
7
  "browser": "browser.js",
package/src/Backends.h DELETED
@@ -1,9 +0,0 @@
1
- #pragma once
2
-
3
- #include "backend/Backend.h"
4
- #include <napi.h>
5
-
6
- class Backends : public Napi::ObjectWrap<Backends> {
7
- public:
8
- static void Initialize(Napi::Env env, Napi::Object exports);
9
- };