Skip to content

Commit 763c740

Browse files
committed
Allow glyphmaps to scale
1 parent c742aba commit 763c740

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/renderers/_base.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export interface IRendererOptionsIn {
100100
* This is a way of a user swapping out one glyph for another at render time.
101101
*
102102
*/
103-
glyphmap?: [string,string][];
103+
glyphmap?: ([string,string]|[string,string,number])[];
104104
/**
105105
* A callback attached to boards and pieces that is called whenever the user clicks on them.
106106
*
@@ -136,7 +136,7 @@ export interface IRendererOptionsOut {
136136
rotate: number;
137137
columnLabels: string;
138138
showAnnotations: boolean;
139-
glyphmap: [string,string][];
139+
glyphmap: [string,string,number][];
140140
boardClick?: (row: number, col: number, piece: string) => void;
141141
boardHover?: (row: number, col: number, piece: string) => void;
142142
}
@@ -393,7 +393,10 @@ export abstract class RendererBase {
393393

394394
// move any glyphmap option over
395395
if (opts.glyphmap !== undefined) {
396-
this.options.glyphmap = opts.glyphmap;
396+
this.options.glyphmap = [];
397+
for (const [from, to, scale] of opts.glyphmap) {
398+
this.options.glyphmap.push([from, to, scale ?? 1]);
399+
}
397400
}
398401

399402
if (opts.boardClick !== undefined) {
@@ -580,6 +583,7 @@ export abstract class RendererBase {
580583
let size = 0;
581584
// Layer the glyphs, manipulating as you go
582585
for (const [idx, g] of glyphs.entries()) {
586+
let baseScale = 1;
583587
let got: SVGSymbol;
584588
if ( ("name" in g) && (g.name !== undefined) ) {
585589
let player: number|undefined;
@@ -596,6 +600,13 @@ export abstract class RendererBase {
596600
// nested.attr(a, got.attr(a));
597601
// }
598602
// }
603+
// check for substituted glyph scaling
604+
if (this.options.glyphmap.length > 0) {
605+
const i = this.options.glyphmap.findIndex(t => t[0] === g.name);
606+
if (i >= 0) {
607+
baseScale = this.options.glyphmap[i][2];
608+
}
609+
}
599610
} else if ( ("text" in g) && (g.text !== undefined) && (g.text.length > 0) ) {
600611
const group = nested.symbol();
601612
const fontsize = 17;
@@ -775,9 +786,9 @@ export abstract class RendererBase {
775786
}
776787

777788
// Scale it appropriately
778-
let factor = 1;
789+
let factor = baseScale;
779790
if (g.scale !== undefined) {
780-
factor = g.scale;
791+
factor *= g.scale;
781792
}
782793
if ( ("board" in this.json) && (this.json.board !== undefined) && (this.json.board !== null) && ("style" in this.json.board) && (this.json.board.style !== undefined) ) {
783794
const style = this.json.board.style;
@@ -794,6 +805,7 @@ export abstract class RendererBase {
794805
factor *= 1.16;
795806
}
796807
}
808+
797809
if (factor !== 1) {
798810
scale(use, factor, 0, 0);
799811
}

0 commit comments

Comments
 (0)