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

Implement text rendering modes in SVG backend #10022

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

janpe2
Copy link
Contributor

@janpe2 janpe2 commented Aug 28, 2018

This implements the operator Tr in the SVG backend.

Fixes #7017 (comment)
Fixes #9647
Fixes #9999

@janpe2
Copy link
Contributor Author

janpe2 commented Aug 28, 2018

Firefox seems to have a problem when SVG <text> elements are used as child nodes of <clipPath>. If the texts have fill="none", Firefox generates an empty clipping path that hides all graphics. The SVG Recommendation says that the fill and stroke attributes should not affect the generated clipping path. As a workaround I have used fill="transparent" instead of fill="none" when Tr specifies that glyphs should be used as a clipping path and not filled.

Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

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

Looks good! Some minor comments, but I'm glad that work is being done to improve the SVG back-end.

if (current.fillColor !== SVG_DEFAULTS.fillColor) {
current.tspan.setAttributeNS(null, 'fill', current.fillColor);

let fillStrokeMode = current.textRenderingMode &
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be const instead of let.

@@ -865,7 +890,16 @@ SVGGraphics = (function SVGGraphicsClosure() {
current.xcoords = [];
},

endText: function SVGGraphics_endText() {},
endText() {
let current = this.current;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be const instead of let.

endText() {
let current = this.current;
if ((current.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG) &&
current.txtElement && current.txtElement.hasChildNodes()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add one more space to this line to make it align with the inner parenthesis.


current.element.setAttributeNS(null, 'fill', 'none');

this.endPath();
}
},

setStrokeAttributes(element) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this private, i.e., _setStrokeAttributes, because it's not part of the public interface.


current.element.setAttributeNS(null, 'fill', 'none');

this.endPath();
}
},

setStrokeAttributes(element) {
let current = this.current;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be const instead of let.

@@ -978,7 +1012,8 @@ SVGGraphics = (function SVGGraphicsClosure() {
var clipPath = this.svgFactory.createElement('svg:clipPath');
clipPath.setAttributeNS(null, 'id', clipId);
clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
var clipElement = current.element.cloneNode();
// A deep clone is needed when text is used as a clipping path.
var clipElement = current.element.cloneNode(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change this from var to const too while we're touching the line. In general we only modernize if we either touch the line or we convert the entire file/class in a new commit, so the former is fine here.

@timvandermeij timvandermeij merged commit 283f2df into mozilla:master Aug 29, 2018
@timvandermeij
Copy link
Contributor

Great work! I tested this locally since we don't have reference tests for the SVG back-end and this works just fine.

@valgussev
Copy link

Good job! Any estimates on when it is going to be a part of a new release?

@timvandermeij
Copy link
Contributor

No exact date yet, but we have been talking about making a release really soon now that we have most patches merged.

@janpe2 janpe2 deleted the svg-Tr branch March 10, 2020 16:55
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.

3 participants