-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check font faces markup for objects within groups #6187
Conversation
src/static_canvas.class.js
Outdated
fontPaths = fabric.fontPaths, objects = []; | ||
|
||
this._objects.forEach(function add(object) { | ||
objects.push(object); | ||
if (object._objects) { | ||
object._objects.forEach(add); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fontPaths = fabric.fontPaths, objects = []; | |
this._objects.forEach(function add(object) { | |
objects.push(object); | |
if (object._objects) { | |
object._objects.forEach(add); | |
} | |
}); | |
fontPaths = fabric.fontPaths, objects = this.objects; | |
this._objects.forEach(function add(object) { | |
var subObjects = object._objects; | |
if (subObjects) { | |
objects = objects.concat(subObjects); | |
subObjects.forEach(add); | |
} | |
}); |
i wonder if this version would be eventually more efficient, changing the array size once for all objects rather than each object. Just a curiosity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean changing the array size once and for all? Doesn't concatenating the objects array with all subObjects change the array size as well?
Hi @yassipad , we need to make a test for this fix/feature. |
Hi @asturur, sure thing, i don't know how to do it though, do you have any guidelines? |
there should already be some test around extracting font faces for svg. |
Hey @asturur, just pushed the new test, let me know if that's enough :) Also i noticed maybe another flaw in the process of checking for custom font-faces while running the initial test: if fontFamilies are only set in the "styles" attribute and not as a general property of the text object, it simply gets skipped because of this line: if (obj.type.indexOf('text') === -1 || fontList[fontFamily] || !fontPaths[fontFamily]) {
continue;
} Shouldn't it rather be something like: if (obj.type.indexOf('text') === -1) {
continue;
}
if (fontFamily && fontPaths[fontFamily]) {
fontList[fontFamily] = true;
} There may be a reason for it not to be the case, just checking :) |
PS/ it could also be slightly faster by adding another condition to skip as in: if (obj.type.indexOf('text') === -1 || (!fontFamily && !obj.styles)) {
continue;
}
if (fontFamily && fontPaths[fontFamily]) {
fontList[fontFamily] = true;
} |
test/unit/itext.js
Outdated
} | ||
else { | ||
parser = new DOMParser(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this parser switch is not more necessary since fabric 3, please if it works without, remove it and use just new DOMParsers()
I'm moving the PR to another branch to fix the dist files issue on my other PR. |
you could have checked from a commit.
to recover the old dist folder. |
Currently, the "createSVGFontFacesMarkup" is only looking for fontFamilies among objects of the canvas. This PR allows it to check for fontFamilies within (nested) groups.