### Platform Setup Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/COMPLETION_REPORT.txt Documentation for the Platform class, which handles addon setup and platform-specific configurations. ```APIDOC ## Platform ### Description Handles addon setup and platform-specific configurations for AlphaSkia. ### Methods - **[Method Signature]** - [Description of method] - Parameters: [Parameter table details] - Returns: [Return type and value details] - Code Example: [Example usage] ### Example Usage ```typescript // Example demonstrating platform setup Platform.setup(...); ``` ``` -------------------------------- ### Development Setup for AlphaSkia Native Libraries Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/Platform.md During development, use `addSearchPaths` to include local directories containing native libraries. This example shows how to add a project-local lib directory and a fallback path within `node_modules`. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; import * as path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); // For development, add project-local lib directory addSearchPaths(path.join(__dirname, '..', 'lib')); // Also add node_modules path as fallback addSearchPaths(path.join(__dirname, '..', 'node_modules', '@coderline', 'alphaskia-linux', 'lib')); ``` -------------------------------- ### Monorepo Setup for AlphaSkia Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Configure AlphaSkia paths within a monorepo for development. This example adds paths relative to the project root and for a specific platform's addon. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; import * as path from 'path'; // Add paths for development environment const projectRoot = path.resolve(__dirname, '..', '..'); addSearchPaths(path.join(projectRoot, 'packages', 'native', 'lib')); addSearchPaths(path.join(projectRoot, 'node_modules', '@coderline', 'alphaskia-linux', 'lib')); ``` -------------------------------- ### Font Loading and Registration Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Shows the process of loading and registering fonts for use with AlphaSkia. This example is part of the font management documentation. ```typescript // Example: Font loading and registration // (Actual code not provided in source text) ``` -------------------------------- ### Resource Management Patterns Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Shows how to effectively manage resources, such as memory and file handles, using patterns like the Disposable pattern. This example is relevant for preventing leaks and ensuring efficient operation. ```typescript // Example: Resource management patterns // (Actual code not provided in source text) ``` -------------------------------- ### Install AlphaSkia npm Package Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/00_START_HERE.md Install the AlphaSkia npm package and its platform-specific addon. Ensure Node.js version 18.0.0 or higher and TypeScript 5.2+ are installed. ```bash npm install @coderline/alphaskia ``` -------------------------------- ### Start a New Path Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Begins a new dynamic path for rendering. This should be followed by path-building commands and then `fill()` or `stroke()`. ```typescript canvas.beginPath(); canvas.moveTo(10, 10); canvas.lineTo(100, 10); canvas.lineTo(100, 100); canvas.closePath(); canvas.fill(); ``` -------------------------------- ### Start AlphaSkiaCanvas Rendering Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Starts a new rendering session on the canvas. Specify the width, height, and an optional render scale. Throws a `ReferenceError` if the canvas has been disposed. ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(800, 600, 1); canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 800, 600); ``` -------------------------------- ### Image Composition Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Provides an example of how to compose images using AlphaSkia's image manipulation features. This snippet is related to image input/output functionalities. ```typescript // Example: Image composition // (Actual code not provided in source text) ``` -------------------------------- ### Error Handling Patterns Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Demonstrates best practices for handling errors and exceptions within an AlphaSkia application. This example is crucial for robust application development. ```typescript // Example: Error handling patterns // (Actual code not provided in source text) ``` -------------------------------- ### Text Rendering with Various Alignments Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Demonstrates how to render text using different alignment options provided by AlphaSkia. This is one of many examples focusing on text manipulation and display. ```typescript // Example: Text rendering with various alignments // (Actual code not provided in source text) ``` -------------------------------- ### Basic Rendering Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/INDEX.md Demonstrates how to create a canvas, begin rendering, draw a filled rectangle, and end the render to obtain an image. Ensure AlphaSkiaCanvas is imported. ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(400, 300); canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.fillRect(0, 0, 400, 300); const image = canvas.endRender(); const png = image?.toPng(); ``` -------------------------------- ### Use Operating System Fonts Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md After switching to operating system fonts, you can create typefaces using system-available fonts like Arial. Ensure the font is installed on the target system. ```typescript import { AlphaSkiaCanvas, AlphaSkiaTypeface } from '@coderline/alphaskia'; AlphaSkiaCanvas.switchToOperatingSystemFonts(); // Now can use system fonts const typeface = AlphaSkiaTypeface.create('Arial', 400, false); if (typeface) { // Use Arial from system } ``` -------------------------------- ### Pixel Data Manipulation Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Illustrates techniques for manipulating pixel data directly using AlphaSkia. This example is part of the pixel data handling documentation. ```typescript // Example: Pixel data manipulation // (Actual code not provided in source text) ``` -------------------------------- ### AlphaSkiaCanvas.beginRender Method Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Starts a new rendering session on the canvas. This method prepares the canvas for drawing operations by setting its dimensions and scale. ```APIDOC ## AlphaSkiaCanvas.beginRender(width: number, height: number, renderScale: number = 1) ### Description Starts a new rendering session on the canvas. This method prepares the canvas for drawing operations by setting its dimensions and scale. ### Method Signature ```typescript public beginRender(width: number, height: number, renderScale: number = 1): void ``` ### Parameters #### Parameters - **width** (number) - Required - Width of the output image in pixels - **height** (number) - Required - Height of the output image in pixels - **renderScale** (number) - Optional - Default: 1 - Scale factor for rendering (e.g., 2 for high-DPI displays) ### Throws `ReferenceError` if the canvas has been disposed ### Example ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(800, 600, 1); canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 800, 600); ``` ``` -------------------------------- ### Docker Configuration for AlphaSkia Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Set up a Dockerfile to run an application using AlphaSkia. This includes installing dependencies and copying application code, with the native addon located in node_modules. ```dockerfile FROM node:18 WORKDIR /app # Copy dependencies COPY package.json package-lock.json ./ RUN npm install # Copy application COPY src ./src COPY fonts ./fonts # alphaSkia native addon is in node_modules/@coderline/alphaskia-linux/lib CMD ["node", "src/index.js"] ``` -------------------------------- ### Basic Shape Drawing Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Illustrates fundamental shape drawing capabilities within the AlphaSkia library. This snippet is part of a larger set of examples covering core rendering functionalities. ```typescript // Example: Basic shape drawing // (Actual code not provided in source text) ``` -------------------------------- ### Text Rendering Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/INDEX.md Shows how to render text on a canvas using AlphaSkiaTextStyle, specifying text content, style, position, alignment, and baseline. Requires an initialized AlphaSkiaCanvas. ```typescript const textStyle = new AlphaSkiaTextStyle(['Arial'], 400, false); canvas.fillText( 'Hello', textStyle, 24, 100, 100, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Middle ); ``` -------------------------------- ### Basic AlphaSkia Rendering Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/README.md Demonstrates basic canvas rendering with AlphaSkia, including drawing shapes and text, and saving the output as a PNG image. Ensure you have the necessary font files available for text rendering. ```typescript import { AlphaSkiaCanvas, AlphaSkiaImage, AlphaSkiaTypeface, AlphaSkiaTextStyle, AlphaSkiaTextAlign, AlphaSkiaTextBaseline } from '@coderline/alphaskia'; import * as fs from 'fs'; // Create canvas using canvas = new AlphaSkiaCanvas(); // Begin rendering canvas.beginRender(400, 300); // Draw background canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 400, 300); // Draw shape canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.fillCircle(200, 150, 50); // Draw text const textStyle = new AlphaSkiaTextStyle(['Arial'], 400, false); canvas.color = AlphaSkiaCanvas.rgbaToColor(0, 0, 0, 255); canvas.fillText( 'Hello World', textStyle, 24, 200, 250, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Middle ); // Get rendered image using image = canvas.endRender(); if (image) { const png = image.toPng(); if (png) { fs.writeFileSync('output.png', Buffer.from(png)); console.log('Saved output.png'); } } ``` -------------------------------- ### Electron Main Process Configuration for AlphaSkia Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Configure AlphaSkia in the main process of an Electron application. This example adds a path to bundled native libraries within the application's resources. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; import { app } from 'electron'; import * as path from 'path'; // Main process setup app.on('ready', () => { // Add bundled native libs path const resourcePath = path.join(app.getAppPath(), 'resources', 'native'); addSearchPaths(resourcePath); // Create windows... }); ``` -------------------------------- ### Find Native Addon Path Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Use this snippet to check if the native addon for AlphaSkia is found. If not, it provides instructions to install it. ```typescript import { findAddonPath } from '@coderline/alphaskia'; const addon = findAddonPath(); if (!addon) { console.error('Addon not found'); console.error('Install: npm install @coderline/alphaskia'); } ``` -------------------------------- ### Setup AlphaSkia in a Docker Container Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/Platform.md Configure AlphaSkia within a Docker container by adding the path where native libraries are mounted. It's recommended to verify the addon's availability after setting the path. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; // In Docker container where libs are mounted at /app/libs addSearchPaths('/app/libs'); // Verify the addon is available import { findAddonPath } from '@coderline/alphaskia'; const addon = findAddonPath(); if (!addon) throw new Error('Native addon not found in /app/libs'); ``` -------------------------------- ### AlphaSkiaTextAlign Usage Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/types.md Demonstrates how to use the AlphaSkiaTextAlign enum when drawing text on a canvas. Ensure AlphaSkiaCanvas and AlphaSkiaTextStyle are imported. ```typescript import { AlphaSkiaTextAlign, AlphaSkiaCanvas } from '@coderline/alphaskia'; const canvas = new AlphaSkiaCanvas(); const textStyle = new AlphaSkiaTextStyle(['Arial'], 400, false); // Left aligned canvas.fillText('Left', textStyle, 24, 10, 50, AlphaSkiaTextAlign.Left, AlphaSkiaTextBaseline.Top); // Center aligned canvas.fillText('Center', textStyle, 24, 200, 50, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Top); // Right aligned canvas.fillText('Right', textStyle, 24, 390, 50, AlphaSkiaTextAlign.Right, AlphaSkiaTextBaseline.Top); ``` -------------------------------- ### AlphaSkia Usage in Docker Application Code Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Example of how AlphaSkia finds its native addon within a Docker container. Custom paths can be optionally added if needed. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; // Optional: add custom paths if needed // addSearchPaths('/app/native-libs'); // alphaSkia will find addon in node_modules automatically ``` -------------------------------- ### Resource Management with 'using' Statement Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/errors.md This example demonstrates using the 'using' statement for automatic resource management of AlphaSkia objects like the canvas and image. It simplifies error handling by ensuring resources are disposed of even if errors occur within the 'using' block. ```typescript import { AlphaSkiaCanvas } from '@coderline/alphaskia'; function renderWithUsing() { try { using canvas = new AlphaSkiaCanvas(); canvas.beginRender(400, 300); canvas.fillRect(0, 0, 400, 300); using image = canvas.endRender(); if (!image) { throw new Error('Rendering failed'); } const png = image.toPng(); if (!png) { throw new Error('PNG encoding failed'); } return png; } catch (error) { if (error instanceof ReferenceError) { console.error('Disposed object used:', error.message); } else { console.error('Rendering error:', error); } return null; } } ``` -------------------------------- ### Handle Large Images with Prompt Disposal Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md When rendering large images, it's essential to dispose of them promptly after use to free up memory. This example demonstrates rendering a large canvas, converting it to PNG, and ensuring the image object is disposed of efficiently. ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(4000, 3000, 2); canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 4000, 3000); using image = canvas.endRender(); if (image) { const png = image.toPng(); // Use PNG data quickly } // Image disposed here canvas[Symbol.dispose](); ``` -------------------------------- ### beginPath Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Begins a new dynamic path for rendering. This method should be called before any path-building commands and must be followed by `fill()` or `stroke()` to render the path. It throws a `ReferenceError` if the canvas has been disposed. ```APIDOC ## beginPath ### Description Begins a new dynamic path for rendering. Must be followed by path-building commands and then `fill()` or `stroke()`. ### Method `public beginPath(): void` ### Throws `ReferenceError` if the canvas has been disposed ### Example ```typescript canvas.beginPath(); canvas.moveTo(10, 10); canvas.lineTo(100, 10); canvas.lineTo(100, 100); canvas.closePath(); canvas.fill(); ``` ``` -------------------------------- ### AlphaSkiaTextBaseline Usage Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/types.md Demonstrates how to use the AlphaSkiaTextBaseline enum when drawing text on a canvas. This example shows different vertical alignments relative to a Y position. ```typescript import { AlphaSkiaTextBaseline } from '@coderline/alphaskia'; // Top aligned canvas.fillText('Top', textStyle, 24, 100, 10, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Top); // Alphabetic baseline (typical) canvas.fillText('Alphabetic', textStyle, 24, 100, 50, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Alphabetic); // Middle aligned (vertically centered) canvas.fillText('Middle', textStyle, 24, 100, 100, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Middle); // Bottom aligned canvas.fillText('Bottom', textStyle, 24, 100, 150, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Bottom); ``` -------------------------------- ### Basic AlphaSkia Initialization Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/Platform.md Initialize AlphaSkia by first verifying the availability of the native addon using `findAddonPath` and then creating a new `AlphaSkiaCanvas`. ```typescript import { AlphaSkiaCanvas, findAddonPath } from '@coderline/alphaskia'; // Verify addon is available const addonPath = findAddonPath(); if (!addonPath) { console.error('alphaSkia native addon not found'); process.exit(1); } console.log(`Using addon: ${addonPath}`); // Now safe to create canvas const canvas = new AlphaSkiaCanvas(); ``` -------------------------------- ### Create and Use Text Styles Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/types.md Demonstrates how to create a TextStyle object and use it with AlphaSkiaCanvas to render text. Ensure AlphaSkiaTextStyle and AlphaSkiaCanvas are imported. ```typescript import { AlphaSkiaTextAlign, AlphaSkiaTextBaseline, AlphaSkiaCanvas } from '@coderline/alphaskia'; const canvas = new AlphaSkiaCanvas(); const textStyle = new AlphaSkiaTextStyle(['Arial'], 400, false); canvas.beginRender(400, 100); canvas.fillText( 'Hello', textStyle, 24, 200, 50, AlphaSkiaTextAlign.Center, // Enum value AlphaSkiaTextBaseline.Middle // Enum value ); const image = canvas.endRender(); ``` -------------------------------- ### Basic Canvas Rendering with AlphaSkia Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/00_START_HERE.md Use this snippet to initialize a canvas, draw a background and a shape, and then render the image. It utilizes the `using` statement for resource management and demonstrates basic color and shape drawing functions. ```typescript import { AlphaSkiaCanvas } from '@coderline/alphaskia'; using canvas = new AlphaSkiaCanvas(); // Begin rendering canvas.beginRender(400, 300); // Draw background canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 400, 300); // Draw a red circle canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.fillCircle(200, 150, 50); // Get the rendered image using image = canvas.endRender(); if (image) { const png = image.toPng(); // Save PNG data to file... } ``` -------------------------------- ### Register and Use FreeType Fonts Example Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md When using FreeType fonts, you must explicitly register custom fonts by loading their data. System fonts are not accessible in this mode. The example demonstrates loading and registering a TTF font file. ```typescript import { AlphaSkiaCanvas, AlphaSkiaTypeface } from '@coderline/alphaskia'; import * as fs from 'fs'; AlphaSkiaCanvas.switchToFreeTypeFonts(); // Load custom fonts const robotoPath = 'fonts/Roboto-Regular.ttf'; const robotoData = fs.readFileSync(robotoPath).buffer; const roboto = AlphaSkiaTypeface.register(robotoData); // Now can use the registered font if (roboto) { // Use Roboto } ``` -------------------------------- ### AlphaSkiaCanvas.lineWidth Property Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Gets or sets the line width for stroke operations. ```APIDOC ## AlphaSkiaCanvas.lineWidth ### Description Gets or sets the line width for stroke operations. ### Getter Signature ```typescript public get lineWidth(): number ``` ### Setter Signature ```typescript public set lineWidth(lineWidth: number): void ``` ### Type `number` - Width in pixels ### Example ```typescript canvas.lineWidth = 2.5; canvas.strokeCircle(100, 100, 50); ``` ``` -------------------------------- ### isBold Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Gets whether this typeface is bold. A typeface is considered bold if its weight is 600 or greater. ```APIDOC ## isBold ### Description Gets whether this typeface is bold. A typeface is considered bold if its weight is 600 or greater. ### Returns `boolean` — `true` if weight >= 600, `false` otherwise ### Example ```typescript const boldTypeface = AlphaSkiaTypeface.create('Arial', 700, false); if (boldTypeface) { console.log(boldTypeface.isBold); // true } const normalTypeface = AlphaSkiaTypeface.create('Arial', 400, false); if (normalTypeface) { console.log(normalTypeface.isBold); // false } ``` ``` -------------------------------- ### Get AlphaSkiaImage Height Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaImage.md Retrieves the height of a rendered AlphaSkiaImage. Ensure the image has not been disposed before accessing this property. ```typescript const image = canvas.endRender(); if (image) { console.log(`Image dimensions: ${image.width}x${image.height}`); } ``` -------------------------------- ### Get AlphaSkiaImage Width Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaImage.md Retrieves the width of a rendered AlphaSkiaImage. Ensure the image has not been disposed before accessing this property. ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(800, 600); canvas.fillRect(0, 0, 800, 600); const image = canvas.endRender(); if (image) { console.log(`Image width: ${image.width}`); // 800 } ``` -------------------------------- ### AlphaSkiaCanvas.color Property Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Gets or sets the color used for drawing operations. Use `rgbaToColor()` to create color values. ```APIDOC ## AlphaSkiaCanvas.color ### Description Gets or sets the color used for drawing operations. Use `rgbaToColor()` to create color values. ### Getter Signature ```typescript public get color(): number ``` ### Setter Signature ```typescript public set color(color: number): void ``` ### Type `number` - The color in the internal format ### Example ```typescript const canvas = new AlphaSkiaCanvas(); const redColor = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.color = redColor; ``` ``` -------------------------------- ### Set AlphaSkiaCanvas Line Width Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Gets or sets the line width for stroke operations. The width is specified in pixels. ```typescript canvas.lineWidth = 2.5; canvas.strokeCircle(100, 100, 50); ``` -------------------------------- ### isItalic Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Gets whether this typeface is italic. This property returns true if the typeface is set to italic, and false otherwise. ```APIDOC ## isItalic ### Description Gets whether this typeface is italic. ### Returns `boolean` — `true` if the typeface is italic, `false` otherwise ### Example ```typescript const italicTypeface = AlphaSkiaTypeface.create('Arial', false, true); if (italicTypeface) { console.log(italicTypeface.isItalic); // true } ``` ``` -------------------------------- ### Loading and Using Custom Fonts Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/README.md Demonstrates loading font data from a file and registering it with AlphaSkia to render text using the custom font. Ensure the font file exists. ```typescript const fontData = fs.readFileSync('roboto.ttf').buffer; const typeface = AlphaSkiaTypeface.register(fontData); if (typeface) { const textStyle = new AlphaSkiaTextStyle( [typeface.familyName], typeface.weight, typeface.isItalic ); canvas.fillText('Custom Font', textStyle, 24, 100, 100, AlphaSkiaTextAlign.Left, AlphaSkiaTextBaseline.Top); } ``` -------------------------------- ### Initialize and Render a Canvas Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/README.md Initializes a new AlphaSkiaCanvas, begins rendering, draws a red rectangle, and ends the render to obtain image data. Ensure to handle the returned image data appropriately. ```typescript import { AlphaSkiaCanvas, AlphaSkiaColorType } from '@coderline/alphaskia'; const canvas = new AlphaSkiaCanvas(); canvas.beginRender(800, 600); // Draw rectangle canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.fillRect(10, 10, 100, 100); // Get rendered image const image = canvas.endRender(); if (image) { const pngData = image.toPng(); // Use PNG bytes... } ``` -------------------------------- ### familyName Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Gets the font family name of this typeface. This property returns the name of the font family, such as 'Arial' or 'Helvetica'. ```APIDOC ## familyName ### Description Gets the font family name of this typeface. ### Returns `string` — The family name (e.g., "Arial", "Helvetica") ### Example ```typescript const typeface = AlphaSkiaTypeface.create('Arial', false, false); if (typeface) { console.log(typeface.familyName); // "Arial" } ``` ``` -------------------------------- ### Basic Canvas Rendering to PNG Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaImage.md Renders a simple image with a background and a circle, then exports it as a PNG file. Ensures both the image and canvas are disposed. ```typescript const canvas = new AlphaSkiaCanvas(); canvas.beginRender(800, 600, 1); // Draw background canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 800, 600); // Draw shapes canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); canvas.fillCircle(400, 300, 50); // Render and export const image = canvas.endRender(); if (image) { const pngData = image.toPng(); if (pngData) { import * as fs from 'fs'; fs.writeFileSync('output.png', Buffer.from(pngData)); console.log(`Saved: ${image.width}x${image.height}`); } image[Symbol.dispose](); } canvas[Symbol.dispose](); ``` -------------------------------- ### Custom Font Loading and Usage Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/INDEX.md Illustrates how to load font data from a file, register it as a typeface, and then use its properties to create a text style for rendering. Requires the 'fs' module for file reading. ```typescript const fontData = fs.readFileSync('font.ttf').buffer; const typeface = AlphaSkiaTypeface.register(fontData); const textStyle = new AlphaSkiaTextStyle([typeface.familyName], typeface.weight, false); ``` -------------------------------- ### Measure Text with AlphaSkiaCanvas Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextMetrics.md Demonstrates how to obtain AlphaSkiaTextMetrics by calling AlphaSkiaCanvas.measureText(). This is the primary method for getting text measurement data. ```typescript const canvas = new AlphaSkiaCanvas(); const textStyle = new AlphaSkiaTextStyle(['Arial'], 400, false); const metrics = canvas.measureText( 'Hello World', textStyle, 24, AlphaSkiaTextAlign.Left, AlphaSkiaTextBaseline.Top ); ``` -------------------------------- ### Configure AlphaSkiaTextStyle with Typeface Properties Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Illustrates how to use properties of a created typeface object (familyName, weight, isItalic) to initialize an AlphaSkiaTextStyle. This ensures text styling matches the font's characteristics. ```typescript const typeface = AlphaSkiaTypeface.create('Arial', true, false); if (typeface) { // Use typeface properties to create text style const textStyle = new AlphaSkiaTextStyle( [typeface.familyName], typeface.weight, typeface.isItalic ); } ``` -------------------------------- ### Initialize AlphaSkiaTextStyle Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextStyle.md Use the constructor to create a new AlphaSkiaTextStyle instance. Specify an array of font family names for fallback rendering, the font weight, and whether the style should be italic. ```typescript public constructor(familyNames: string[], weight: number, isItalic: boolean) ``` ```typescript // Create a text style with Arial as primary, sans-serif as fallback const textStyle = new AlphaSkiaTextStyle(['Arial', 'sans-serif'], 400, false); // Create a bold italic text style const boldItalic = new AlphaSkiaTextStyle(['Arial', 'Helvetica'], 700, true); // Create a light text style with multiple fallbacks const light = new AlphaSkiaTextStyle(['Roboto', 'Arial', 'sans-serif'], 300, false); ``` -------------------------------- ### Get Alphabetic Baseline Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextMetrics.md Returns the distance from the baseline to the alphabetic baseline. This value is typically 0 when the alphabetic baseline is the reference point. ```typescript public get alphabeticBaseline(): number ``` -------------------------------- ### Platform API Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Reference for platform-specific functions, including adding search paths and finding addon paths. ```APIDOC ## Platform Functions ### Description Provides utility functions for platform-specific operations, such as managing resource search paths and locating native addons. ### Functions - **addSearchPaths(paths)**: Adds directories to the search path for resources. - **findAddonPath(name)**: Finds the path to a native addon. ### Platform Detection - Details on the platform detection logic. ### Installation and Setup - Documentation related to installation and setup across different platforms. ### Custom Library Locations - Examples for specifying custom library locations. ### Cross-Platform Considerations - Notes on developing cross-platform applications. ### Debugging Guide - Guidance for debugging platform-specific issues. ``` -------------------------------- ### Get Font Weight Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Retrieves the numerical font weight of a typeface instance. Use to determine or set the boldness level of the font. ```typescript const typeface = AlphaSkiaTypeface.create('Roboto', 600, false); if (typeface) { console.log(typeface.weight); // 600 } ``` -------------------------------- ### Render Multi-Line Text with Different Styles Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextStyle.md Demonstrates how to create and use AlphaSkiaTextStyle objects to render text with varying styles (heading, body, emphasis) on an AlphaSkiaCanvas. Includes setting canvas color, drawing rectangles, and filling text with specified styles and alignments. ```typescript const canvas = new AlphaSkiaCanvas(); // Different text styles const headingStyle = new AlphaSkiaTextStyle(['Arial'], 700, false); const bodyStyle = new AlphaSkiaTextStyle(['Arial', 'sans-serif'], 400, false); const emphasisStyle = new AlphaSkiaTextStyle(['Arial'], 400, true); canvas.beginRender(600, 400); // White background canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 255, 255, 255); canvas.fillRect(0, 0, 600, 400); // Black text canvas.color = AlphaSkiaCanvas.rgbaToColor(0, 0, 0, 255); // Heading canvas.fillText( 'Document Title', headingStyle, 32, 300, 50, AlphaSkiaTextAlign.Center, AlphaSkiaTextBaseline.Top ); // Body text canvas.fillText( 'This is the body text.', bodyStyle, 14, 50, 120, AlphaSkiaTextAlign.Left, AlphaSkiaTextBaseline.Top ); // Emphasized text canvas.fillText( 'This is emphasized.', emphasisStyle, 14, 50, 150, AlphaSkiaTextAlign.Left, AlphaSkiaTextBaseline.Top ); const image = canvas.endRender(); if (image) { const png = image.toPng(); // Save or use PNG data } ``` -------------------------------- ### Get Font Family Name Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Retrieves the font family name of a typeface instance. Use when you need to identify the font family. ```typescript const typeface = AlphaSkiaTypeface.create('Arial', false, false); if (typeface) { console.log(typeface.familyName); // "Arial" } ``` -------------------------------- ### AlphaSkiaTextStyle.weight Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextStyle.md Gets the font weight value used for selecting typefaces. It accepts standard weight values from 100 (Thin) to 900 (Black). ```APIDOC ## AlphaSkiaTextStyle.weight ### Description Gets the font weight used for finding typefaces. ### Type `number` (read-only) ### Standard weight values: | Value | Description | |-------|-------------| | 100 | Thin/Hairline | | 200 | Extra Light | | 300 | Light | | 400 | Normal/Regular | | 500 | Medium | | 600 | Semi Bold | | 700 | Bold | | 800 | Extra Bold | | 900 | Black | ### Example ```typescript const textStyle = new AlphaSkiaTextStyle(['Arial'], 700, false); console.log(textStyle.weight); // 700 ``` ``` -------------------------------- ### Create and Register Font Typeface Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md This code demonstrates how to create a typeface and provides guidance on registering custom fonts if the typeface is not found. ```typescript import { AlphaSkiaTypeface } from '@coderline/alphaskia'; const typeface = AlphaSkiaTypeface.create('MyFont', 400, false); if (!typeface) { console.error('Font not found'); console.error('Register custom fonts: AlphaSkiaTypeface.register(fontBuffer)'); } ``` -------------------------------- ### Get Hanging Baseline Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextMetrics.md Returns the distance from the alphabetic baseline to the hanging baseline. This is particularly relevant for scripts that use a hanging baseline for alignment. ```typescript public get hangingBaseline(): number ``` -------------------------------- ### AlphaSkiaCanvas Constructor Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Initializes a new empty canvas for drawing. The canvas is created with a default 100x100 size and must be resized via `beginRender()` before use. ```APIDOC ## new AlphaSkiaCanvas() ### Description Initializes a new empty canvas for drawing. The canvas is created with a default 100x100 size and must be resized via `beginRender()` before use. ### Constructor Signature ```typescript public constructor() ``` ### Example ```typescript const canvas = new AlphaSkiaCanvas(); try { // Use canvas for drawing } finally { canvas[Symbol.dispose](); } ``` ``` -------------------------------- ### Load Image and Get Dimensions Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaImage.md Loads a PNG image from a file buffer and displays its dimensions. The decoded image must be disposed after use. ```typescript import * as fs from 'fs'; const pngBytes = fs.readFileSync('input.png').buffer; const image = AlphaSkiaImage.decode(pngBytes); if (image) { console.log(`Image size: ${image.width}x${image.height}`); image[Symbol.dispose](); } ``` -------------------------------- ### Add Custom Native Addon Path (Windows) Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/configuration.md Specify a custom directory for native addon libraries on Windows. Ensure the path is correctly formatted for the Windows file system. ```typescript import { addSearchPaths } from '@coderline/alphaskia'; addSearchPaths('C:\\custom\\lib\\path'); ``` -------------------------------- ### Begin and End Rotation Transformation Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Use beginRotate to start a rotation transformation and endRotate to restore the canvas state. Ensure beginRotate is paired with endRotate. ```typescript canvas.color = AlphaSkiaCanvas.rgbaToColor(255, 0, 0, 255); cavas.beginRotate(100, 100, 45); // Rotate 45 degrees cavas.fillRect(75, 75, 50, 50); cavas.endRotate(); ``` ```typescript canvas.beginRotate(100, 100, 90); cavas.fillRect(50, 50, 100, 100); cavas.endRotate(); // Subsequent drawing is no longer rotated ``` -------------------------------- ### AlphaSkiaCanvas.colorType Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Gets the color type used by AlphaSkiaCanvas for generating images. This can be either RGBA888 or BGRA888, depending on the system's native color type. ```APIDOC ## AlphaSkiaCanvas.colorType ### Description Gets the color type used when generating images. AlphaSkia attempts to use the native color type of the system, which may vary based on operating system. ### Returns `AlphaSkiaColorType` — Either `Rgba888` (RGBA format) or `Bgra888` (BGRA format) ### Example ```typescript const canvas = new AlphaSkiaCanvas(); const colorType = AlphaSkiaCanvas.colorType; console.log(colorType); // e.g., AlphaSkiaColorType.Rgba888 ``` ``` -------------------------------- ### Get Em Height Ascent Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTextMetrics.md Retrieves the distance from the baseline to the top of the em square. This value is crucial for understanding vertical text spacing and layout. ```typescript public get emHeightAscent(): number ``` -------------------------------- ### findAddonPath Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/Platform.md Attempts to resolve the path to the native Node.js addon for alphaSkia, automatically detecting the operating system and architecture. ```APIDOC ## findAddonPath ### Description Attempts to resolve the native Node.js addon for alphaSkia, which is typically placed in an operating system platform and architecture-specific folder. ### Method `findAddonPath(): string | undefined` ### Returns `string | undefined` — The resolved path to the native addon, or `undefined` if it could not be found. ### Search Paths The function searches in the following locations: 1. `/lib` 2. `/lib` 3. `node_modules/@coderline/alphaskia-/lib` (when installed via npm) 4. Any paths added via `addSearchPaths()` Within each search path, it looks for: - **Directory**: `libalphaskianode---node` - **File**: `libalphaskianode.node` The complete search pattern is: `/libalphaskianode---node/libalphaskianode.node` ### Platform and Architecture Detection The function automatically detects: - **Platforms**: win32 (mapped to 'win'), linux, darwin (mapped to 'macos'), android, ios, iossimulator - **Architectures**: x64, x86, arm, arm64 ### Example ```typescript import { findAddonPath } from '@coderline/alphaskia'; const addonPath = findAddonPath(); if (addonPath) { console.log(`Found addon at: ${addonPath}`); } else { console.error('alphaSkia native addon not found'); process.exit(1); } ``` ``` -------------------------------- ### weight Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaTypeface.md Gets the font weight value of this typeface. This property returns a numerical value representing the font's weight, typically between 100 and 900. ```APIDOC ## weight ### Description Gets the font weight value of this typeface. ### Returns `number` — Font weight (typically 100-900, with common values: 400 for normal, 700 for bold) ### Example ```typescript const typeface = AlphaSkiaTypeface.create('Roboto', 600, false); if (typeface) { console.log(typeface.weight); // 600 } ``` ``` -------------------------------- ### AlphaSkiaImage Methods and Properties Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/COMPLETION_REPORT.txt Reference for the AlphaSkiaImage class, used for image output and manipulation. Includes static and instance methods, along with properties. ```APIDOC ## AlphaSkiaImage ### Description Handles image output and manipulation within the AlphaSkia library. ### Static Methods - **[Static Method Signature]** - [Description of static method] - Parameters: [Parameter table details] - Returns: [Return type and value details] - Code Example: [Example usage] ### Instance Methods - **[Instance Method Signature]** - [Description of instance method] - Parameters: [Parameter table details] - Returns: [Return type and value details] - Code Example: [Example usage] ### Properties - **[Property Name]** ([Type]) - [Description] ### Example Usage ```typescript // Example demonstrating usage of AlphaSkiaImage const image = AlphaSkiaImage.create(...); // ... use image instance methods and properties ... ``` ``` -------------------------------- ### Initialize AlphaSkiaCanvas Source: https://github.com/coderline/alphaskia/blob/main/_autodocs/api-reference/AlphaSkiaCanvas.md Initializes a new AlphaSkiaCanvas. The canvas is created with a default 100x100 size and must be resized via `beginRender()` before use. Remember to dispose of the canvas when done. ```typescript const canvas = new AlphaSkiaCanvas(); try { // Use canvas for drawing } finally { canvas[Symbol.dispose](); } ```