Skip to content

Commit

Permalink
Rename TextFont to TextFormatter.
Browse files Browse the repository at this point in the history
Rename TextFontTests to FontTests.
Remove unused code.
  • Loading branch information
ronyeh committed Nov 4, 2021
1 parent 978ed44 commit 6ad76d4
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 1,807 deletions.
4 changes: 2 additions & 2 deletions src/chordsymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class ChordSymbol extends Modifier {
protected reportWidth: boolean = true;

// Initialized by the constructor via this.setFont().
protected textFormatter!: TextFont;
protected textFormatter!: TextFormatter;

constructor() {
super();
Expand Down Expand Up @@ -627,7 +627,7 @@ export class ChordSymbol extends Modifier {
style: string = 'normal'
): this {
super.setFont(f, size, weight, style);
this.textFormatter = TextFont.createFormatter(this.font);
this.textFormatter = TextFormatter.create(this.font);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { TabStave } from './tabstave';
import { TabTie } from './tabtie';
import { TextBracket } from './textbracket';
import { TextDynamics } from './textdynamics';
import { TextFont } from './textfont';
import { TextFormatter } from './textformatter';
import { TextNote } from './textnote';
import { TickContext } from './tickcontext';
import { TimeSignature } from './timesignature';
Expand Down Expand Up @@ -97,6 +97,7 @@ export const Flow = {
Element,
Factory,
Font,
TextFormatter,
Fonts,
Formatter,
Fraction,
Expand Down Expand Up @@ -144,7 +145,6 @@ export const Flow = {
TabTie,
TextBracket,
TextDynamics,
TextFont, // TODO: RONYEH rename to FontFormatter
TextNote,
TickContext,
TimeSignature,
Expand Down
34 changes: 24 additions & 10 deletions src/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,26 @@ export interface FontData {
generatedOn?: string;
}

/** Specified in the `xxx_metrics.ts` files. */
export interface FontMetrics extends Record<string, any> {
name: string;
smufl: boolean;
stave?: Record<string, number>;
accidental?: Record<string, number>;
clef?: Record<string, any>;
pedalMarking?: Record<string, Record<string, number>>;
digits?: Record<string, number>;
// Not specified in gonville_metrics.ts.
articulation?: Record<string, Record<string, number>>;
tremolo?: Record<string, Record<string, number>>;
// Not specified in bravura_metrics.ts or gonville_metrics.ts.
noteHead?: Record<string, Record<string, number>>;
glyphs: Record<string, Record<string, any>>;
}

export interface FontDataMetrics {
fontData?: FontData;
// eslint-disable-next-line
metrics?: Record<string, any>;
metrics?: FontMetrics;
}

export interface FontGlyph {
Expand All @@ -43,7 +59,7 @@ export interface FontGlyph {
ha: number;
leftSideBearing?: number;
advanceWidth?: number;
o?: string; // RONYEH-FONT: Made this optional to be compatible with robotoslab_textmetrics & petalumascript_textmetrics.
o?: string; // RONYEH-FONT: Made this optional to be compatible with robotoslab_glyphs & petalumascript_glyphs.
cached_outline?: number[];
}

Expand Down Expand Up @@ -142,7 +158,6 @@ class Font {
}

/**
* Helper for `TextFont.createFormatter()`.
* @param weight a string (e.g., 'bold') or a number (e.g., 600 / semi-bold in the OpenType spec).
* @returns true if the font weight indicates bold.
*/
Expand All @@ -163,7 +178,6 @@ class Font {
}

/**
* Helper for `TextFont.createFormatter()`.
* @param style
* @returns true if the font style indicates 'italic'.
*/
Expand Down Expand Up @@ -193,7 +207,7 @@ class Font {
protected fontDataMetrics: FontDataMetrics;

// eslint-disable-next-line
constructor(name: string, metrics?: Record<string, any>, fontData?: FontData) {
constructor(name: string, metrics?: FontMetrics, fontData?: FontData) {
this.name = name;
this.fontDataMetrics = {};
switch (name) {
Expand Down Expand Up @@ -268,10 +282,10 @@ class Font {
}

const Fonts = {
Bravura: (): Font => new Font('Bravura'),
Gonville: (): Font => new Font('Gonville'),
Petaluma: (): Font => new Font('Petaluma'),
Custom: (): Font => new Font('Custom'),
Bravura: () => new Font('Bravura'),
Gonville: () => new Font('Gonville'),
Petaluma: () => new Font('Petaluma'),
Custom: () => new Font('Custom'),
};

export { Font, Fonts };
6 changes: 3 additions & 3 deletions src/fonts/custom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomFont } from "./custom_glyphs";
import { CustomMetrics } from "./custom_metrics";
import { CustomFont } from './custom_glyphs';
import { CustomMetrics } from './custom_metrics';

const Custom = {
const Custom = {
fontData: CustomFont,
metrics: CustomMetrics,
};
Expand Down
6 changes: 3 additions & 3 deletions src/fonts/gonville.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GonvilleFont } from "./gonville_glyphs";
import { GonvilleMetrics } from "./gonville_metrics";
import { GonvilleFont } from './gonville_glyphs';
import { GonvilleMetrics } from './gonville_metrics';

const Gonville = {
const Gonville = {
fontData: GonvilleFont,
metrics: GonvilleMetrics,
};
Expand Down
12 changes: 6 additions & 6 deletions src/fonts/gonville_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export const GonvilleMetrics = {
},
},

// These are for numeric digits, such as in time signatures
digits: {
point: 40,
tupletPoint: 28,
},

// articulation: {
// },

Expand All @@ -118,12 +124,6 @@ export const GonvilleMetrics = {
// noteHead: {
// },

// These are for numeric digits, such as in time signatures
digits: {
point: 40,
tupletPoint: 28,
},

stem: {
heightAdjustmentForFlag: -3,
// These are stem (Y) offsets to the note heads. To shift the
Expand Down
6 changes: 3 additions & 3 deletions src/fonts/petaluma.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PetalumaFont } from "./petaluma_glyphs";
import { PetalumaMetrics } from "./petaluma_metrics";
import { PetalumaFont } from './petaluma_glyphs';
import { PetalumaMetrics } from './petaluma_metrics';

const Petaluma = {
const Petaluma = {
fontData: PetalumaFont,
metrics: PetalumaMetrics,
};
Expand Down
Loading

0 comments on commit 6ad76d4

Please sign in to comment.