@@ -58,12 +58,19 @@ export interface ElementStyle {
58
58
/**
59
59
* Element implements a generic base class for VexFlow, with implementations
60
60
* of general functions and properties that can be inherited by all VexFlow elements.
61
+ *
62
+ * The Element is an abstract class that needs to be subclassed to work. It handles
63
+ * style and text-font properties for the Element and any child elements, along with
64
+ * working with the Registry to create unique ids, but does not have any tools for
65
+ * formatting x or y positions or connections to a Stave.
61
66
*/
62
67
export abstract class Element {
63
68
static get CATEGORY ( ) : string {
64
69
return Category . Element ;
65
70
}
66
71
72
+ // all Element objects keep a list of children that they are responsible and which
73
+ // inherit the style of their parents.
67
74
protected children : Element [ ] = [ ] ;
68
75
protected static ID : number = 1000 ;
69
76
protected static newID ( ) : string {
@@ -108,6 +115,15 @@ export abstract class Element {
108
115
Registry . getDefaultRegistry ( ) ?. register ( this ) ;
109
116
}
110
117
118
+ /**
119
+ * Adds a child Element to the Element, which lets it inherit the
120
+ * same style as the parent when setGroupStyle() is called.
121
+ *
122
+ * Examples of children are noteheads and stems. Modifiers such
123
+ * as Accidentals are generally not set as children.
124
+ *
125
+ * Note that StaveNote calls setGroupStyle() when setStyle() is called.
126
+ */
111
127
addChildElement ( child : Element ) : this {
112
128
this . children . push ( child ) ;
113
129
return this ;
@@ -186,7 +202,7 @@ export abstract class Element {
186
202
187
203
/**
188
204
* Draw the element and all its sub-elements (ie.: Modifiers in a Stave)
189
- * with the element style.
205
+ * with the element's style (see `getStyle()` and `setStyle()`)
190
206
*/
191
207
drawWithStyle ( ) : void {
192
208
this . checkContext ( ) ;
@@ -258,7 +274,7 @@ export abstract class Element {
258
274
return this . attrs ;
259
275
}
260
276
261
- /** Return an attribute. */
277
+ /** Return an attribute, such as 'id', 'type' or 'class' . */
262
278
// eslint-disable-next-line
263
279
getAttribute ( name : string ) : any {
264
280
return this . attrs [ name ] ;
@@ -271,7 +287,7 @@ export abstract class Element {
271
287
if ( element ) return element as unknown as SVGElement ;
272
288
}
273
289
274
- /** Set an attribute. */
290
+ /** Set an attribute such as 'id', 'class', or 'type' . */
275
291
setAttribute ( name : string , value : string | undefined ) : this {
276
292
const oldID = this . attrs . id ;
277
293
const oldValue = this . attrs [ name ] ;
@@ -286,18 +302,18 @@ export abstract class Element {
286
302
return this . boundingBox ;
287
303
}
288
304
289
- /** Return the context. */
305
+ /** Return the context, such as an SVGContext or CanvasContext object . */
290
306
getContext ( ) : RenderContext | undefined {
291
307
return this . context ;
292
308
}
293
309
294
- /** Set the context. */
310
+ /** Set the context to an SVGContext or CanvasContext object */
295
311
setContext ( context ?: RenderContext ) : this {
296
312
this . context = context ;
297
313
return this ;
298
314
}
299
315
300
- /** Validate and return the context. */
316
+ /** Validate and return the rendering context. */
301
317
checkContext ( ) : RenderContext {
302
318
return defined ( this . context , 'NoContext' , 'No rendering context attached to instance.' ) ;
303
319
}
@@ -306,19 +322,24 @@ export abstract class Element {
306
322
// Font Handling
307
323
308
324
/**
309
- * Provide a CSS compatible font string (e.g., 'bold 16px Arial').
325
+ * Provide a CSS compatible font string (e.g., 'bold 16px Arial') that will be applied
326
+ * to text (not glyphs).
310
327
*/
311
328
set font ( f : string ) {
312
329
this . setFont ( f ) ;
313
330
}
314
331
315
- /** Returns the CSS compatible font string. */
332
+ /** Returns the CSS compatible font string for the text font . */
316
333
get font ( ) : string {
317
334
return Font . toCSSString ( this . textFont ) ;
318
335
}
319
336
320
337
/**
321
- * Set the element's font family, size, weight, style (e.g., `Arial`, `10pt`, `bold`, `italic`).
338
+ * Set the element's text font family, size, weight, style
339
+ * (e.g., `Arial`, `10pt`, `bold`, `italic`).
340
+ *
341
+ * This attribute does not determine the font used for musical Glyphs like treble clefs.
342
+ *
322
343
* @param font is 1) a `FontInfo` object or
323
344
* 2) a string formatted as CSS font shorthand (e.g., 'bold 10pt Arial') or
324
345
* 3) a string representing the font family (at least one of `size`, `weight`, or `style` must also be provided).
@@ -364,6 +385,10 @@ export abstract class Element {
364
385
return this ;
365
386
}
366
387
388
+ /**
389
+ * Get the css string describing this Element's text font. e.g.,
390
+ * 'bold 10pt Arial'.
391
+ */
367
392
getFont ( ) : string {
368
393
if ( ! this . textFont ) {
369
394
this . resetFont ( ) ;
0 commit comments