-
Notifications
You must be signed in to change notification settings - Fork 208
/
Fonts.ts
72 lines (65 loc) · 2.1 KB
/
Fonts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Symbology
*/
/** The type of a font.
* @public
* @extensions
*/
export enum FontType { TrueType = 1, Rsc = 2, Shx = 3 }
/** An iModel-local identifier for a font.
* @public
* @extensions
*/
export type FontId = number;
/** The properties of a Font.
* @public
*/
export interface FontProps {
/** the Id, within an iModel, of this font. */
id: FontId;
/** The type of font */
type: FontType;
/** The name of the font. */
name: string;
}
/** The properties of a FontMap
* @public
* @extensions
*/
export interface FontMapProps { fonts: FontProps[] }
/**
* A FontMap holds the set of font names available in an iModel.
* Within the GeometryStream of an Element, a specific font is referenced by its FontId that is local to the iModel.
* This class maps FontIds to FontProps.
* @note The font map is generally established when the iModel is first created to specify the set of fonts available
* for editors. Adding new entries requires that the schema lock be held.
* @public
*/
export class FontMap {
public readonly fonts = new Map<FontId, FontProps>();
constructor(props?: FontMapProps) {
if (undefined !== props)
this.addFonts(props.fonts);
}
public addFonts(fonts: FontProps[]) {
fonts.forEach((font) => this.fonts.set(font.id, font));
}
public toJSON(): FontMapProps {
const fonts: FontProps[] = [];
this.fonts.forEach((font) => fonts.push(font));
return { fonts };
}
/** look up a font by name or number and return its FontProps */
public getFont(arg: string | FontId): FontProps | undefined {
if (typeof arg === "number")
return this.fonts.get(arg);
for (const font of this.fonts.values())
if (font.name === arg)
return font;
return undefined;
}
}