Skip to content

Commit 19cd5b0

Browse files
committed
Avoid duplication of font properties
They are inherit, therefore can be applied only once
1 parent 5c7f6d8 commit 19cd5b0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

scripts/JSRoot.latex.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
926926
};
927927

928928
const createSubPos = fscale => {
929-
return { lvl: curr.lvl + 1, x: 0, y: 0, fsize: curr.fsize*(fscale || 1), bold: curr.bold, italic: curr.italic, color: curr.color, font: curr.font, parent: curr, painter: curr.painter };
929+
return { lvl: curr.lvl + 1, x: 0, y: 0, fsize: curr.fsize*(fscale || 1), color: curr.color, font: curr.font, parent: curr, painter: curr.painter };
930930
};
931931

932932
while (label) {
@@ -952,17 +952,22 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
952952

953953
if (alone && !curr.g) curr.g = elem;
954954

955-
if (curr.font)
956-
curr.font.setFont(elem, 'without-size');
957-
958-
if (curr.color || arg.color) elem.attr("fill", curr.color || arg.color);
959-
if (curr.fsize) elem.attr("font-size", Math.round(curr.fsize));
955+
// apply font attributes only once, inherited by all other elements
956+
if (curr.ufont)
957+
curr.font.setFont(curr.g /*, 'without-size' */);
960958

961959
if (curr.bold !== undefined)
962-
elem.attr('font-weight', curr.bold ? 'bold' : 'normal');
960+
curr.g.attr('font-weight', curr.bold ? 'bold' : 'normal');
963961

964962
if (curr.italic !== undefined)
965-
elem.attr('font-style', curr.italic ? 'italic' : 'normal');
963+
curr.g.attr('font-style', curr.italic ? 'italic' : 'normal');
964+
965+
// set fill color directly to element
966+
elem.attr("fill", curr.color || arg.color || null);
967+
968+
// set font size directly to element to avoid complex control
969+
if (curr.fisze !== curr.font.size)
970+
elem.attr("font-size", Math.round(curr.fsize));
966971

967972
elem.text(s);
968973

@@ -1304,9 +1309,10 @@ JSROOT.define(['d3', 'painter'], (d3, jsrp) => {
13041309

13051310
if (found.name == "#color[")
13061311
subpos.color = curr.painter.getColor(foundarg);
1307-
else if (found.name == "#font[")
1312+
else if (found.name == "#font[") {
13081313
subpos.font = new JSROOT.FontHandler(foundarg);
1309-
else
1314+
subpos.ufont = true; // mark that custom font is applied
1315+
} else
13101316
subpos.fsize *= foundarg;
13111317

13121318
parseLatex(currG(), arg, sublabel, subpos);

0 commit comments

Comments
 (0)