UNPKG

@osbjs/txtgen-tiny-osbjs

Version:

A text-to-image generator wrapper for tiny-osbjs.

128 lines (127 loc) 5.72 kB
import { Layer, Origin, Vector2 } from "@osbjs/tiny-osbjs"; type Padding = { left: number; right: number; top: number; bottom: number; }; type FontProps = { name: string; size: number; padding: Padding; isItalic: boolean; }; /** * Eject all text images into osu storyboard folder. */ declare function ejectAllTextImages(): Promise<void[]>; type TextImage = { width: number; height: number; text: string; path: string; osbPath: string; isOutline: boolean; }; /** * Create a new sprite for a given text. * Note that this won't generate the image and you need to call `ejectAllTextImages` after you have created all the sprites, * usually after `generateOsbString`. * * @param text Text to generate * @param layer The layer the object appears on. * @param origin The sprite's origin * @param initialPosition Where the sprite should be by default. * @param invokeFunction The commands that should be run when the sprite is created. */ declare function createText(text: string, layer: Layer, origin: Origin, initialPosition: Vector2, invokeFunction: (textImage: TextImage, getTopLeftPosition: (position: Vector2, scale?: number) => Vector2) => void): void; /** * Create a new sprite for a given text but with only outline. * It's recommended to use a seperate context for this. * Note that this won't generate the image and you need to call `ejectAllTextImages` after you have created all the sprites, * usually after `generateOsbString`. * * @param text Text to generate * @param layer The layer the object appears on. * @param origin The sprite's origin * @param initialPosition Where the sprite should be by default. * @param invokeFunction The commands that should be run when the sprite is created. */ declare function createOutlineText(text: string, layer: Layer, origin: Origin, initialPosition: Vector2, invokeFunction: (textImage: TextImage, getTopLeftPosition: (position: Vector2, scale?: number) => Vector2) => void): void; type TextGeneratorContext = { fontProps: FontProps; osbFolderPath: string; beatmapFolderPath: string; createdTextImages: TextImage[]; memoizedMetrics: { width: number; height: number; text: string; }[]; }; /** * Create a new text generator context. * * @param osbFolderPath Subfolder where the images will be generated into. * @param beatmapFolderPath Full path to beatmap folder. * @param fontProps Font properties used to generate text. */ declare function createTxtGenContext(osbFolderPath: string, beatmapFolderPath: string, fontProps: FontProps): TextGeneratorContext; /** * Specify the text generator context to use. * * @param context Text generator context. */ declare function useTxtGenContext(context: TextGeneratorContext): void; /** * Specify a non-system font to use. * * @param path Full path to the font file. Relative path will not work as intended. * @param family Font family name. */ declare function useFont(path: string, family: string): void; /** * Clear output folder of this current context. This should be called once for each text generator context right after it is created. * @param context Context to be selected. */ declare function clearOutputFolder(context: TextGeneratorContext): void; declare function isValidPadding(padding: Padding): padding is Padding; declare function isValidFontProps(fontProps: FontProps): fontProps is FontProps; declare function isValidTxtGenContext(context: TextGeneratorContext): context is TextGeneratorContext; declare function measureText(text: string): { width: number; height: number; }; /** * Get total line width by calling reducer on each character/word in the line of text. * * @param line Line of text to measure. * @param mode Whether you want to measure character or word. * Will default to character mode if specified anything but 'char' or 'word'. * @param reducer How the calculation should process. */ declare function measureLineWidth(line: string, mode?: "char" | "word" | any, reducer?: (prevWidth: number, currentWidth: number) => number): number; /** * Get total line height by calling reducer on each letter in the line of text. * * @param line Line of text to measure. * @param mode Whether you want to measure character or word. * Will default to character mode if specified anything but 'char' or 'word'. * @param reducer How the calculation should process. */ declare function measureLineHeight(line: string, mode?: "char" | "word" | any, reducer?: (prevHeight: number, currentHeight: number) => number): number; /** * Get the maximum width of each character/word of the line of text. * @param line Line of text to measure * @param mode Whether you want to measure character or word. * Will default to character mode if specified anything but 'char' or 'word'. */ declare function maxLineWidth(line: string, mode?: "char" | "word" | any): number; /** * Get the maximum height of each character/word of the line of text. * @param line Line of text to measure * @param mode Whether you want to measure character or word. * Will default to character mode if specified anything but 'char' or 'word'. */ declare function maxLineHeight(line: string, mode?: "char" | "word" | any): number; export { ejectAllTextImages, createOutlineText, createText, isValidPadding, isValidFontProps, isValidTxtGenContext, measureText, clearOutputFolder, createTxtGenContext, TextGeneratorContext, useFont, useTxtGenContext, FontProps, Padding, TextImage, measureLineWidth, measureLineHeight, maxLineWidth, maxLineHeight };