Aspose.Font for JavaScript via C++ – FAQ
Q: What is Aspose.Font for JavaScript via C++?
A: Aspose.Font for JavaScript via C++ is a native C++ library wrapped for JavaScript that enables developers to create, convert, and manipulate font files programmatically without any external dependencies.
Q: Which font formats are supported for conversion?
A: The library supports TrueType (TTF), OpenType (OTF), Web Open Font Format (WOFF/WOFF2), Embedded OpenType (EOT), and font collections such as TTC and OTF collections. Conversion between any of these formats is fully supported.
Q: How do I install the Aspose.Font JavaScript via C++ package?
A: Use npm to install the pre‑built binary package:
1npm install aspose.font-cppThe package contains the native C++ binaries for Windows, Linux, and macOS, and the JavaScript wrapper that loads the correct binary at runtime.
Q: Do I need to compile the C++ source myself?
A: No. The npm package ships with pre‑compiled binaries for the major platforms. If you need a custom build (e.g., for a different architecture), you can download the source from the Aspose GitHub repository and compile it using CMake.
Q: How is licensing handled in the JavaScript‑via‑C++ version?
A: Licensing works the same as the .NET/Java versions. After purchasing a license, place the .lic file in your project and call aspose.font.Font.setLicense("path/to/license.lic") before any other API calls. The license file is embedded in the native binary at runtime.
Q: Can I extract glyph outlines and metrics from a font?
A: Yes. The API provides Font.getGlyph(glyphId) which returns an object containing the glyph’s vector outline (as a series of contour points), advance width, left side bearing, and Unicode mappings. This is useful for custom rendering engines.
Q: Is Unicode support complete for all scripts?
A: The library fully supports Unicode code points up to U+10FFFF, including surrogate pairs. It correctly maps Unicode characters to glyph indices, handles OpenType layout tables, and respects language‑specific features when requested.
Q: How do I convert a TTF font to WOFF2?
A: Example code:
1const aspose = require("aspose.font-cpp");
2aspose.Font.setLicense("Aspose.Total.lic");
3
4const font = aspose.Font.load("MyFont.ttf");
5font.save("MyFont.woff2", aspose.FontSaveOptions.createWoff2SaveOptions());The save method automatically selects the appropriate encoder based on the file extension or save options object.
Q: What are the performance characteristics for large font collections?
A: The native C++ core is optimized for low memory overhead and fast I/O. Loading a TTC (TrueType Collection) with up to 100 fonts typically takes under 100 ms on a modern CPU, and conversion of a single font averages 30–50 ms.
Q: Can the library be used in a serverless environment (e.g., AWS Lambda)?
A: Yes. The binary is statically linked and does not rely on external system fonts. Deploy the npm package with your Lambda function bundle, and ensure the execution role has permission to read the license file and any input font files.
Q: How do I handle errors when loading a corrupted font file?
A: All API calls throw aspose.font.FontException. You can catch this exception to retrieve a detailed error code and message:
1try {
2 const font = aspose.Font.load("corrupt.ttf");
3} catch (e) {
4 console.error("Font load failed:", e.message);
5}The exception hierarchy distinguishes between I/O errors, format errors, and license errors.
Q: Which operating systems and architectures are officially supported?
A: Windows (x64), Linux (x64, ARM64), and macOS (x64, ARM64). The npm package contains binaries for each of these platforms. For unsupported platforms, you can compile from source.
Q: How do I embed a generated WOFF2 font into a web page?
A: After conversion, serve the .woff2 file with the correct MIME type (font/woff2). In HTML:
1<link rel="stylesheet" href="styles.css">
2<style>
3@font-face {
4 font-family: "MyCustomFont";
5 src: url("MyFont.woff2") format("woff2");
6}
7</style>The generated font is fully compliant with the WOFF2 specification, so browsers will render it without additional processing.
Q: Where can I find sample code and API reference documentation?
A: Detailed documentation, API reference, and code snippets are available on the Aspose website at
https://docs.aspose.com/font/java/. The JavaScript‑via‑C++ section mirrors the .NET/Java docs, and a GitHub repository contains sample projects for common scenarios.
Q: How do I update the library to a newer version?
A: Run npm update aspose.font-cpp to fetch the latest package. Review the release notes for breaking changes, especially if new save options or deprecations are introduced. Always retest font conversion pipelines after an upgrade.