Skip to content

Commit

Permalink
Fixed problem in first example almende#3408
Browse files Browse the repository at this point in the history
  • Loading branch information
wimrijnders committed Sep 14, 2017
1 parent 4860af5 commit a26643a
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions lib/network/modules/components/shared/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,16 @@ class Label {
//
// In all cases, only own properties apply!
//
// newOptions.font.bold -> newOptions.font ->
// this.fontOptions.bold -> this.fontOptions ->
// this.fontOptions.proto.bold -> this.fontOptions.proto ->
// nodeOptions.font.bold -> nodeOptions.font ->
// defaultOptions.font.bold -> defaultOptions.font
// newOptions.font.bold ->
// this.fontOptions.bold ->
// this.fontOptions.proto.bold ->
// nodeOptions.font.bold ->
// defaultOptions.font.bold ->
// newOptions.font ->
// this.fontOptions ->
// this.fontOptions.proto ->
// nodeOptions.font ->
// defaultOptions.font
//
// Assumptions:
// - newOptions multi-fonts have no chained prototype; if they do, they are the same as proto's in
Expand Down Expand Up @@ -422,22 +427,17 @@ class Label {
};

var getFontOption = (multiName, option) => {
// First, the multi font
for (var n in pile) {
var [fontOptions, handleProto] = pile[n];

// First, the multi font
if (fontOptions.hasOwnProperty(multiName)) {
var multiFont = fontOptions[multiName];
if (multiFont.hasOwnProperty(option)) {
return multiFont[option];
}
}

// Try the local font-options
if (fontOptions.hasOwnProperty(option)) {
return fontOptions[option];
}

if (handleProto) {
// Do the same thing as above, but not for own properties
// The proto for the multi-font is expressly skipped
Expand All @@ -447,7 +447,19 @@ class Label {
return multiFont[option];
}
}

}
}


// Try the local font-options
for (var n in pile) {
var [fontOptions, handleProto] = pile[n];

if (fontOptions.hasOwnProperty(option)) {
return fontOptions[option];
}

if (handleProto) {
if (!font.hasOwnProperty(option)) {
return font[option];
}
Expand Down Expand Up @@ -1139,7 +1151,7 @@ class Label {
return fontOptions[option];
}

if (fontOptions[mod][option]) {
if (fontOptions[mod][option] !== undefined) { // Grumbl leaving out test on undefined equals false for ""
return fontOptions[mod][option];
} else {
// Take from parent font option
Expand All @@ -1165,7 +1177,14 @@ class Label {
}
}
}
ctx.font = (values.mod + " " + values.size + "px " + values.face).replace(/"/g, "");

var fontString = "";
if (values.mod !== undefined && values.mod !== "") { // safeguard for undefined - this happened
fontString += values.mod = " ";
}
fontString += values.size + "px " + values.face;

ctx.font = fontString.replace(/"/g, "");
values.font = ctx.font;
values.height = values.size;
return values;
Expand Down

0 comments on commit a26643a

Please sign in to comment.