UNPKG

beatprints.js

Version:

A Node.js version of the original Python BeatPrints project (https://github.com/TrueMyst/BeatPrints/) by TrueMyst. Create eye-catching, Pinterest-style music posters effortlessly. BeatPrints integrates with Spotify and LRClib API to help you design custom

85 lines (84 loc) 4.34 kB
import { type Font } from 'opentype.js'; import { type CanvasRenderingContext2D } from '@napi-rs/canvas'; export declare const fontCache: FontMap; export declare const registeredFonts: Set<string>; export declare const getFontAlias: (fontPath: string, alias: Record<string, string>) => string; /** * Registers custom fonts from specified paths and aliases. * * Each font file must follow the naming pattern: `Family-Weight.ttf`, e.g., `MyFont-Bold.ttf`. * You must provide an alias for each family used, e.g., `'MyFont': 'My Font'`. * * @param {string[]} fontPaths - Full paths to font files. * @param {Record<string, string>} aliases - Maps folder (family) name to display name. */ export declare function registerCustomFonts(fontPaths: string[], aliases: Record<string, string>): void; export declare function fontPaths(weight: FontWeight): string[]; /** * Checks if a specified glyph exists in the given font. * @param {Font} font The font to check the glyph in. * @param {string} glyph The glyph to check for. * @returns {boolean} True if the glyph exists in the font, false otherwise. */ export declare function checkGlyph(font: Font, glyph: string): boolean; /** * Groups consecutive characters in a string based on the font required to render them. * @param {string} text The text to be grouped by font. * @param {string[]} fontPaths A map mapping font paths to font objects. */ export declare function groupByFont(text: string, fontPaths: string[]): FontGroup[]; /** * Utility to clear font caches (for debugging or memory management). */ export declare function clearFontCache(): void; /** * Renders a single line of text on the image with specified styling. * @param {CanvasRenderingContext2D} ctx The canvas rendering context. * @param {[x: number, y: number]} pos The position of the text. * @param {string} text The text to be rendered. * @param {RGB} color The text color in RGB format. * @param {string[]} fontPaths An array of font paths. * @param {number} size The font size. * @param {Align} align The text alignment. */ export declare function renderSingleLine(ctx: CanvasRenderingContext2D, pos: Readonly<[x: number, y: number]>, text: string, color: RGB, fontPaths: string[], size: number, align?: Align, anchor?: Anchor): void; /** * Returns the width of the text without drawing it. * * @param {string} text The text to measure * @param {string[]} fontPaths An array of font paths to use * @param {number} size The font size * @returns {number} The width of the text *} */ export declare function textWidth(text: string, fontPaths: string[], size: number): number; /** * Renders text on an image at a specified position with customizable font, size, color, alignment, spacing and anchor. * @param {CanvasRenderingContext2D} ctx The canvas context. * @param pos The position of the text. * @param text The text to render. * @param color The text color in RGB format. * @param fonts A map of fonts to use. * @param size The font size. * @param align Text alignment (left, center, right). * @param spacing Vertical spacing between lines. * @param anchor Text anchor of alignment. */ export declare function text(ctx: CanvasRenderingContext2D, pos: Readonly<[x: number, y: number]>, text: string, color: RGB, fontPaths: string[], size: number, align?: Align, spacing?: number, anchor?: Anchor): void; /** * Draws a heading within a specified width limit on an image. * @param {CanvasRenderingContext2D} ctx The canvas rendering context. * @param {[x: number, y: number]} pos The position of the text. * @param {number} maxWidth The maximum width allowed for the heading. * @param {string} text The text to render. * @param {RGB} color The text color in RGB format. * @param {FontMap} fontPaths An array of font paths to use. * @param {number} initialSize The font size. */ export declare function heading(ctx: CanvasRenderingContext2D, pos: Readonly<[x: number, y: number]>, maxWidth: number, text: string, color: RGB, fontPaths: string[], initialSize: number): void; export type FontWeight = 'Regular' | 'Bold' | 'Light'; export type Align = 'left' | 'center' | 'right'; export type Anchor = 'lt' | 'mm' | 'rb' | 'lb' | 'rt'; export type RGB = [r: number, g: number, b: number]; export type FontMap = Map<string, Font>; export type FontGroup = [string, string];