UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

122 lines (121 loc) 4.24 kB
import type { ColorArray } from 'style/color/index.js'; import type { S2CellId } from 'gis-tools/index.js'; import type { ImageMetadata, ImageSourceMetadata } from 'workers/source/imageSource.js'; /** A Glyph Container. Tracks all the glyph's properties, shape, size, etc. */ export interface Glyph { /** code represents either the unicode value or substitution value */ code: string; /** texX is the x position on the texture sheet */ texX: number; /** texY is the y position on the texture sheet */ texY: number; /** texW is the width of the glyph on the texture sheet */ texW: number; /** texH is the height of the glyph on the texture sheet */ texH: number; /** xOffset is the x offset for the glyph */ xOffset: number; /** yOffset is the y offset for the glyph */ yOffset: number; /** width is the width of the glyph */ width: number; /** height is the height of the glyph */ height: number; /** advanceWidth is how far to move the cursor */ advanceWidth: number; } /** An Icon's id/name and it's associative color */ export interface IconPiece { /** glyphID is the glyphID of the icon */ glyphID: string; /** colorID is the colorID of the icon */ color: ColorArray; } /** List of IconPieces */ export type Icon = IconPiece[]; /** Ligature Substitution Tree Node */ export interface LigatureSubstitute { type: 4; substitute: string; components: string[]; } /** Ligature Substitution Tree */ export interface LigatureTree extends Record<number, LigatureTree> { /** unicode substitute if it ends here */ substitute?: string; } /** Icon's name id and color id, whereas an `IconPiece`, the color is mapped */ export interface IconDefinition { glyphID: string; colorID: number; } /** Map of icons to their collection of images that make them up */ export type IconMap = Record<string, IconDefinition[]>; /** Set of unicodes that are part of the family */ export type GlyphSet = Set<string>; /** Map of IDs to RGBA colors */ export type ColorMap = Record<number, ColorArray>; /** * # Family Source * * Maintain a store of the Font/Icon family, it's glyphs, ligatures, icons, and colors associated * with it. Make requests to the source worker for missing glyphs. */ export default class FamilySource { #private; name: string; extent: number; defaultAdvance: number; glyphSet: GlyphSet; ligatures: LigatureTree; glyphCache: Map<string, Glyph>; iconCache: Map<string, Icon>; glyphRequestList: Map<bigint, Set<string>>; isIcon: boolean; /** * @param name - the name of the family * @param metadata - the raw metadata to unpack */ constructor(name: string, metadata?: ArrayBuffer); /** * Given an image metadata input, build a FamilySource * @param imageSource - the image metadata * @returns a new FamilySource */ static FromImageMetadata(imageSource: ImageSourceMetadata): FamilySource; /** * Check if the Family Source has an existing glyph/icon * @param code - glyph code * @returns true if the glyph/icon exists */ has(code: string): boolean; /** * Check if this source is missing a glyph/icon * @param code - the code of the glyph/icon * @returns true if the glyph/icon is missing */ missingGlyph(code: string): boolean; /** * Add image metadata to the source * @param metadata - the image metadata */ addMetadata(metadata: ImageMetadata): void; /** * Add a glyph request to be processed * @param tileID - the id of the tile that requested the glyph * @param code - the code of the glyph/icon */ addGlyphRequest(tileID: S2CellId, code: string): void; /** * Get the glyph requests for a tile * @param tileID - the id of the tile that requested the glyph/icon * @returns the list of glyph/icon requests */ getRequests(tileID: S2CellId): string[]; /** * Zero Width Joiner pass goes first * @param strCodes - array of codes to parse * @param zwjPass - true if we are in the zero width joiner pass */ parseLigatures(strCodes: string[], zwjPass?: boolean): void; }