Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Check font faces markup for objects within groups #6187

wants to merge 1 commit into from

Conversation

yassilah
Copy link
Contributor

Currently, the "createSVGFontFacesMarkup" is only looking for fontFamilies among objects of the canvas. This PR allows it to check for fontFamilies within (nested) groups.

Comment on lines 1402 to 1409
fontPaths = fabric.fontPaths, objects = [];

this._objects.forEach(function add(object) {
objects.push(object);
if (object._objects) {
object._objects.forEach(add);
}
});
Copy link
Member

@asturur asturur Feb 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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?

@asturur
Copy link
Member

asturur commented Feb 29, 2020

Hi @yassipad , we need to make a test for this fix/feature.
Do you know how to do?

@yassilah
Copy link
Contributor Author

yassilah commented Mar 1, 2020

Hi @asturur, sure thing, i don't know how to do it though, do you have any guidelines?

@asturur
Copy link
Member

asturur commented Mar 1, 2020

there should already be some test around extracting font faces for svg.
modify the test in order to have a group with nested different fonts. please use 2 levels of nesting not just one.

@yassilah
Copy link
Contributor Author

yassilah commented Mar 2, 2020

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 :)

@yassilah
Copy link
Contributor Author

yassilah commented Mar 2, 2020

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;
}

}
else {
parser = new DOMParser();
}
Copy link
Member

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()

@yassilah
Copy link
Contributor Author

yassilah commented Mar 3, 2020

I'm moving the PR to another branch to fix the dist files issue on my other PR.
#6195

@yassilah yassilah closed this Mar 3, 2020
@asturur
Copy link
Member

asturur commented Mar 3, 2020

you could have checked from a commit.

git checkout ....goodcommit... dist

to recover the old dist folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants