-
Notifications
You must be signed in to change notification settings - Fork 62
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
SVG FXL restrictions on height
and width
may be too restrictive
#1236
Comments
Hello,
SVG is very important to people with low vision. The SVG should be able to be enlarged by the user. I hope our incorporation of SVG in the spec supports this important feature.
Best
George
From: Romain Deltour <notifications@github.com>
Sent: Friday, February 22, 2019 8:52 AM
To: w3c/publ-epub-revision <publ-epub-revision@noreply.github.com>
Cc: Subscribed <subscribed@noreply.github.com>
Subject: [w3c/publ-epub-revision] SVG FXL restrictions on `height` and `width` may be too restrictive (#1236)
Looking at the rules on how the Initial Containing Block dimensions are expressed in SVG <https://w3c.github.io/publ-epub-revision/epub32/spec/epub-contentdocs.html#sec-fxl-icb-svg>
1. regarding their combination with viewBox, the spec says:
The spec says:
It is RECOMMENDED to use only the viewBox attribute to ensure proper rescaling of the SVG Content Document, as needed.
As far as I understand, percentage values do not negatively affect scalability, so should be fine in combination with viewBox.
This could be reworded to something along these lines:
It is RECOMMENDED to use the viewBox attribute to ensure proper rescaling of the SVG Content Document, as needed.
If height and width attribute are present, they values SHOULD NOT be set to absolute length when a viewBox attribute is present.
2. regarding the height and width pixel value
The spec says:
If only the x, y, height and width attributes are present, they SHOULD be defined in pixel values (establishing the ICB)
Given that all <https://www.w3.org/TR/css3-values/#absolute-lengths> absolute length units are compatible (they can all be converted to the canonical px unit), requiring a pixel value looks restrictive. The term "pixel value" itself might be a bit vague (does it mean "in pixel units" or "in units compatible with the pixel unit"?).
This could be open to any absolute length:
If only the x, y, height and width attributes are present, their value SHOULD be expressed in user units or in absolute length units. (establishing the ICB).
3. regarding the impact of x and y on the ICB
The spec says:
If only the x, y, height and width attributes are present, they SHOULD be defined in pixel values (establishing the ICB)
I'm not sure the value of x and y is relevant there? The intrinsic sizing <https://www.w3.org/TR/SVG/coords.html#SizingSVGInCSS> of SVG content is only impacted with width, height, and viewBox.
Suggested rewording:
If height and width attributes are present and there is viewBox attribute is not present, they SHOULD be defined in…
For reference, this section was discussed in #860 <#860> , #800 <#800> , #463 <#463> .
See also EPUBCheck issue w3c/epubcheck#902 <w3c/epubcheck#902> and PR w3c/epubcheck#973 <w3c/epubcheck#973>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#1236> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AG3HSB4Iu2rghzqBwnV1lGV9AcTyHzBwks5vQBIGgaJpZM4bJ3wv> . <https://github.com/notifications/beacon/AG3HSBloWGDTHNxynpt27Wj_ntaT-zvyks5vQBIGgaJpZM4bJ3wv.gif>
|
Taking this in parts:
But we are calculating the ICB here, so by definition we have no containing block yet. In that case, CSS says:
So yes, adding these percentages does not negatively impact scaling, but why allow them if they add no value? Am I missing a potential use? How would SVG content documents be improved by allowing percents in this case?
Honestly, the more I look at this, the more I want to change this to viewbox is required, x, y, width, and height are forbidden. For now, my instinct is to say "if it ain't broke, don't fix it". Are either content creators or reading system implementors asking for this? What are their use cases? |
Fortunately –and despite the complexity of how this works– the SVG spec is quite precise about this (as far as I understand), and is the browser implementations have good interoperability.
The SVG would be 400px wide and 1200px tall. You can test this with the following SVG, opened in a browser and setting the device size from the developer tools. <?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 50" width="50%" height="100%">
<desc>Test SVG</desc>
<rect x="0" y="0" width="100%" height="100%" fill="red" stroke="none"/>
</svg> I'm no SVG expert, but I think this comes from the definition of the initial viewport:
and
My own feeling is that this section is overly restrictive, and doesn't respect the priority of constituencies. SVG content is more often than not produced by authoring tool exports, so we should be as permissive as possible on what we accept. That said, I don't claim to fully understand this section, nor the related sections in the SVG spec. And this is another area where usage data would help making an informed decision 😉 |
The days when I did a lot of SVG are long gone, but I try to remember (without the FXL background). So I believe that:
All this under the control of @rkwright who knows more about SVG than I will ever do...:-) |
And by the way, this issue was created since we're implementing these rules in EPUBCheck v4.2.0. EPUB 3.0.1 only said:
So all these new RECOMMENDED and SHOULD rules will trigger warnings, where none were reported before. We could "not fix it" by ignoring these, but then why put'em in the spec? 🤔 The very example used in EPUB 3.0.1 would trigger such a warning, as it doesn't comply to the rules in EPUB 3.2: <svg xmlns="http://www.w3.org/2000/svg"
version="1.1" width="100%" height="100%"
viewBox="0 0 844 1200">
…
</svg> The "Sous le vent" EPUB 3 sample would trigger a warning too. I'm basically concerned that this section is another source of these small backward incompatibilities, which will start being noticed when EPUBCheck 4.2.0 is out. |
I'm not sure I understand. Consider this document, adapted from an example in the SVG <?xml version="1.0" standalone="no"?>
<svg
viewBox="0 0 1500 1000" preserveAspectRatio="xMidYMid" width="100%" height="100%"
xmlns="http://www.w3.org/2000/svg">
<desc>Example ViewBox - uses the viewBox
attribute to automatically create an initial user coordinate
system which causes the graphic to scale to fit into the
SVG viewport no matter what size the SVG viewport is.</desc>
<!-- This rectangle goes from (0,0) to (1500,1000) in user coordinate system.
Because of the viewBox attribute above,
the rectangle will end up filling the entire area
reserved for the SVG content. -->
<rect x="0" y="0" width="1500" height="1000"
fill="yellow" stroke="blue" stroke-width="12" />
<!-- A large, red triangle -->
<path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/>
<!-- A text string that spans most of the SVG viewport -->
<text x="100" y="600" font-size="200" font-family="Verdana" >
Stretch to fit
</text>
</svg> The presence of In this example, changing Doesn't it mean that we should at least allow If our intent is to use the maximum available space without distorting the graphics, then in my understanding the rules should be:
|
This change implements the new rules related to expressing the initial containing block dimensions for SVG documents in Fixed Layout EPUBs. New messages: - `HTM-054` (`WARNING`): when the size is given by `width`/`height` attributes, but the recommended `viewBox` attribute is missing - `HTM-055` (`WARNING`): when the values of the `height` and `width` attributes are not specified in pixels, and `viewBox` is not present Changed message: - `HTM-048` (`ERROR`): now says that either `viewBox` or `height` and `width` must be present Bug fix: - Only the outer SVG element is checked (previously, all the `svg` elements where checked). Fix #902. Note: the checking logic may need to be tweaked depending on the outcome of issue w3c/epub-specs#1236
This change implements the new rules related to expressing the initial containing block dimensions for SVG documents in Fixed Layout EPUBs. New messages: - `HTM-054` (`WARNING`): when the size is given by `width`/`height` attributes, but the recommended `viewBox` attribute is missing - `HTM-055` (`WARNING`): when the values of the `height` and `width` attributes are not specified in pixels, and `viewBox` is not present Changed message: - `HTM-048` (`ERROR`): now says that either `viewBox` or `height` and `width` must be present Bug fix: - Only the outer SVG element is checked (previously, all the `svg` elements where checked). Fix #902. Note: the checking logic may need to be tweaked depending on the outcome of issue w3c/epub-specs#1236
@rdeltour, I must admit, I do not understand it either. However, something may be fishy. Indeed, if I look at the original examples in the SVG document (that you reused) (which are identical in the SVG2 version), and I take the example: <?xml version="1.0" standalone="no"?>
<svg viewBox="0 0 1500 1000"
width="150px" height="200px" xmlns="http://www.w3.org/2000/svg">
<desc>Example ViewBox - uses the viewBox
attribute to automatically create an initial user coordinate
system which causes the graphic to scale to fit into the
SVG viewport no matter what size the SVG viewport is.</desc>
<!-- This rectangle goes from (0,0) to (1500,1000) in user coordinate system.
Because of the viewBox attribute above,
the rectangle will end up filling the entire area
reserved for the SVG content. -->
<rect x="0" y="0" width="1500" height="1000"
fill="yellow" stroke="blue" stroke-width="12" />
<!-- A large, red triangle -->
<path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/>
<!-- A text string that spans most of the SVG viewport -->
<text x="100" y="600" font-size="200" font-family="Verdana" >
Stretch to fit
</text>
</svg> (note that the width and height are set to explicit length values). Per specification, I should get this: However, this does not happen, neither in Chrome nor in Firefox. I get what you describe, ie:
I should add: rendering the graphics with the 1500×1000 aspect ratio intact. I am not sure what happens here; is this an implementation error? @rkwright or @svgeesus can you help out here?
We can allow it, but it does not have any effect. The missing |
I think it's expected: you'd get the graphics to fit the 150x200 px box if you'd add
Well, that's the point: these attributes have no effect, but allowing these have the direct effect of not rejecting perfectly acceptable SVG. In other word, we'd be on the good side of Postel's law and the priority of constituencies. |
@rdeltour yes, I have spotted my mistake: the initial value of the I have no experience with FXL deployment and requirements, but some of your statements sound right to me. Like
but, also,
Indeed. Why is it necessary to disallow the usage of the |
The problem is we are not looking at merely displaying content in a browser, we are displaying it in a reading system, and we want a vaguely reliable way for the reading system to determine the dimensions of the svg. If we start adding things that are undefined (like height 100% on the root element) that gets harder to do consistently. In general, the easiest way to deal with svg content documents in a non-borwser RS is to determine the aspect ratio, and make a webview that maximizes the size of the image, then color the letterboxing with any FXL specified background color. @iherman I am not sure why you say:
Where is that speced? As far as I can tell, height 100% on the root element is undefined if the ICB is not yet defined (which it can't be since these are the rules for calculating the ICB). |
@iherman I am not sure why you say:
A combination of width=100% height=100% preserveAspectRatio=none means that the SVG content will always fill up the full available space on the screen,
The spec does say that a 'none' value means scaling without keeping the aspect ratio, and the w/h set to 100% means use the full window of the browser. That is also the behavior on chrome based browsers (I didn't test on FF).
|
That is the bit I am curious about. My general feeling is the CSS box model is a nightmare to understand, and I fully believe that I do not understand it, but it doesn't look like height="100%" means the full height of the "window" in the browser (not sure even what window height means). Just because one browser interprets an undefined value one way doesn't make it right. Traditionally, I have seen undefined height values mean "the full height of the viewport", or "all the remaining space in the viewport", or "0". |
I agree with you on CSS:-) but this is not CSS. These are SVG-specific attributes; see https://www.w3.org/TR/SVG/geometry.html#Sizing. I could not locate the precise description that would be anything but the intuitive one ("x % of the visible area"), but here is the test file I used: <?xml version="1.0" standalone="no"?>
<svg viewBox="0 0 1500 1000" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none">
<rect x="0" y="0" width="1500" height="1000"
fill="yellow" stroke="blue" stroke-width="12" />
<!-- A large, red triangle -->
<path fill="red" d="M 750,100 L 250,900 L 1250,900 z"/>
<!-- A text string that spans most of the SVG viewport -->
<text x="100" y="600" font-size="200" font-family="Verdana" >
Stretch to fit
</text>
</svg> and the behavior is identical in Chrome, Firefox, and Safari |
That, unfortunately, defer to CSS:
Now, I have no idea what that is supposed to mean with reference to calculating the ICB for standalone SVG content documents in an epub. But viewing the sky from the bottom of this rat hole is making me lean more and more to "please don't do this because we have no idea what it means". |
width and height of 100% are simply the default values for these attributes, would be funny, if an epubcheck notes, that not setting the default values explicitly is ok, but it produces a warning, if one sets the default values explicitly. ;o) Percentages are simply related to the available viewport for the SVG document. If SVG is embedded in another document using CSS for styling, the size the element around the SVG part determines, what 100% means. If an SVG contains some relevant text, that should be readable, I'd recommend to use width and height with units like em or ex, but never px. Typically for SVG cover image title and author names are large enough, that using the 100% default for width and height is ok. Obviously viewers/user-agents have to provide a mechanism to scroll or move/pan the document relative to the viewport. If the viewport is smaller than width and height in other units than percentages, this is unavoidable. For a lot of text it is better for authors and the audience to use XHTML (with the text part) with embedded SVG for the graphics. |
To try and begin whittling away at what needs to change one piece at a time, is there agreement that the recommendation to "only" use viewbox is overly-restrictive and unnecessary, thus we only need to say:
This will retain compatibility with 3.0.1, which only defined viewbox for calculating the ICB. (Thumb up this comment if you agree.) |
For the rest, my rereading of the old issues is that we were trying to spell out what a reading system will attempt to do in the absence of a viewbox declaration. In that light, could we rewrite the following paragraphs as follows so authoring is only guidance:
|
Or we can always go back to the 3.0.1 wording that the ICB must be specified in the |
A link in the 'toc' can point to a view element resulting in another viewBox. Note that for preserveAspectRatio="xMidYMid slice" or other slice variants only parts of the viewBox are displayed, if the aspect ratio does not fit. With 'meet' instead of 'slice' typically the rendered part of the SVG is larger than the viewBox. Depending on the align part of preserveAspectRatio there is additional visible content left, right, top or bottom to the viewBox. Both cases show: The viewBox does not determine the containing block. The initial containing block for an SVG document finally is not determined by the SVG document, it is the viewport, as already the CSS definition explains. For SVG embedded as a fragment in XHTML, styled with CSS, it gets more complicated due to the interactions of the CSS box model with the different SVG model. If the SVG document is referenced with an XHTML img element, that has itself no width and height, it gets really problematic, if the SVG document contains no width and height, trying to use viewBox and preserveAspectRatio to get some width and height for the img might be necessary, authors should avoid this. SVG 1.1 and SVG tiny 1.2 have no CSS properties width and height for the outermost svg element, therefore the containing (CSS styled XHTML) element needs meaningful width and height. However, to use a viewBox and only units on width and height of the root svg element (the way, SVG tiny recommendations go), is more a pretty helpful hint for authors for other reasons, not something to recommend. Reading systems have to recognize such link issues (pointing to a view, having an svgView), have to take care of width, height, preserveAspectRatio and viewBox to render the intended part of the SVG document into the viewport, respectively the containing block. The viewport in SVG only: The attributes x and y of an svg element have no effect for the outermost svg element: SVG views: SVG view element: |
This issue is already fairly dense as it contains three issues, it would really help me to follow the discussion if we could limit it to the issue(s) at hand, specifically calculating the ICB for SVG content documents in fixed layout epub. If there are other issues with svg in epub, please open separate bugs, but please do reference them if appropriate so we can follow along. For the comments from @mattgarrish I am fine with the first since it seems to be no change. The third (revert to 3.0.1) is fine, but seems a step backwards. For the second option, I am concerned with encouraging the use of absolute lengths since this is almost always wrong in this case (content creators have no idea how much space they have). I think what we are trying to encourage here is a simple way to make an SVG that uses as much of the available space as possible without distortion, and allows the reading system to fill the remaining area with whatever background color was specified in the epub metadata. As far as height being 100% by default ... sort of. It really seems like this part of the svg spec is broken. The default value of height is auto, which is then "treated" as 100%, but it is not clear what the processing model for "treat" is. As far as I can tell, in this case, 100% computes to auto. I have no idea at what stage of CSS value calculation "treat" kicks in. |
bduga, the default is 100% (of the available viewport), not auto. What 100% means, depends on the media: a) Continuous media: width and height of the viewport. b) paged media (especially if the EPUB is printed on paper): Concerning fixed layout: There is for SVG not much difference to normal layout. If an author notes width="40em" height="6000em" you get a size depending on the preferred font-size of the current user. This might happen for example for an epic poem with additional visual effects. Would be useless to scale it down for example to the height of the screen, because nobody could read it anymore. Scale only the SVG to the size of the viewport or the sheet of paper, if width and height are given in percentage (including the default 100% if not specified explicitly). |
Thanks @Doktorchen for your valuable comments, this is really helpful. The more I think of it, the more I feel that this is not in the realm of specification, but in the real of best practices. No? Do Reading Systems actually need something specific from the author? |
Sorry, I might be confused about what we are talking about. My comments are specifically to epub content documents 3.2: https://w3c.github.io/publ-epub-revision/epub32/spec/epub-contentdocs.html#bib-svg Which in turn normatively references SVG here: https://w3c.github.io/publ-epub-revision/epub32/spec/epub-contentdocs.html#bib-svg Which has this link: That seems to be SVG 2, so our normative reference is not to 1 or 1.2. That spec seems to discuss height and width here: https://www.w3.org/TR/SVG/geometry.html#Sizing That section defines no default values, instead of a value description section it has the text:
It also has the text:
In the reference to CSS 2.1, in the text for height is a link that points at: https://www.w3.org/TR/CSS21/visudet.html#propdef-height That clearly defines the initial value to auto. Of course, a browser default could change that, so it is vaguely possible that the default in browsers for the svg element is 100%, but it doesn't change the computed value of 100% in this case being auto. Am I wrong about the specs in question? All these links create a maze of twisty paths. If only there was a linear reading order ... |
If the second option to remove authoring requirements doesn't work, how about we strip all of those paragraphs and simply say that the ICB must be specified either using the |
bduga - SVG 2 is not a recommendation yet, only SVG 1.0, 1.1, 12 tiny. And the SVG2 candidate recommendation seems to be borked somehow, if subsections are indicated to be 'Editors Draft' - this seems to be not ready to use now. But if it notes, that CSS auto is 100% for width and height, it is still the same as SVG 1.1 etc. mattgarrish: Helpful for authors and audience would be something, that results really in something readable, especially no naive scaling of the viewBox or width or height to 100% of the viewport, if authors do not note this with width and height in percentage. In my test ensemble I was surprised, that even XHTML+CSS fixed layout documents are scaled to 100% of the height of the viewport in some viewers, effectively resulting in unreadable text. This might be a result of providing size information in px, instead of em or ex together with naive scaling without taking into account readability of text content. |
Ok, but our normative reference is to 2.0. That might be an error, and we might want to normatively reference a different spec. But that is a different issue. Likely one that needs to be resolved before we can even start to discuss this, though I think we were deliberate in our choices for normative references.
It notes it in a highly underspecified way. Does it mean a specified value of auto turns into 100%? What happens if the computed value is auto? Does it also turn into 100%? Do you have to recompute in that case? Very confusing, and likely worth raising a bug in the svg group. As for a 6000 line epic poem as a single svg content document in a fixed layout epub, that will never work. While some readers might allow you to scroll, many will not. Even for reading systems that would allow you to scroll that content, location information would probably be lost. |
@bduga, that has been discussed in #1219. We added language to the spec around this. And I talked to Amelia the other day, who says SVG2 better describes what browsers actually do. |
The EPUB3.2 draft notes: 'This specification does not reference a specific version of [[SVG]], but instead uses an undated reference'. Therefore any version should be ok with this. But because these new property approach in SVG 2 referencing CSS can cause a lot of backwards incompatibilities, it is of course a good idea to ask the SVG working group about it, in doubt reporting a bug (maybe the mailing list is better, because the subsections are indicated only as editor's draft). Directly in a browser width="40em" height="6000em" causes no trouble, if it does for EPUB viewers, it is maybe useful to reuse/study libraries from browsers to get it right. But even if EBUB3.2 indicates, that for fixed layout everything has to be scaled down until it fits into the viewport, no matter what authors want or specify, authors at least know, that they cannot use fixed layout for their project. If it does not even work for normal layout in some viewer, they can at least give a hint to the audience with examples of viewers, which do not have the problem. |
Message changes: - `HTM-048` now checks that outermost `svg` elements in Fixed-Layout Documents MUST have a `viewBox` attribute. - remove `HTM-054` (`viewBox` recommended) - remove `HTM-055` (height+width in percent when `viewBox` is abstent) - remove old suppressed message `HTM-043` Internal changes: - move the SVG FXL logic out of the `ctc` package - add an `Optional<OPFItem>` field to the validator context (retrieved from the `XRefChecker` in the builder, or absent). See also w3c/epub-specs#1236 This PR (partially) reverts commit 17f5eee
Message changes: - `HTM-048` now checks that outermost `svg` elements in Fixed-Layout Documents MUST have a `viewBox` attribute. - remove `HTM-054` (`viewBox` recommended) - remove `HTM-055` (height+width in percent when `viewBox` is abstent) - remove old suppressed message `HTM-043` Internal changes: - move the SVG FXL logic out of the `ctc` package - add an `Optional<OPFItem>` field to the validator context (retrieved from the `XRefChecker` in the builder, or absent). See also w3c/epub-specs#1236 This PR (partially) reverts commit 17f5eee
I propose that we close this issue, as we have reverted to EPUB 3.0.1 language:
I don't think we'll accomplish anything by pursuing this further in the context of EPUB 3.2. |
@dauwhe 3.1? Do you mean 3.2? |
Sorry. Yes. Fixed in above comment. |
Closed via CG exhaustion |
Looking at the rules on how the Initial Containing Block dimensions are expressed in SVG
viewBox
, the spec says:The spec says:
As far as I understand, percentage values do not negatively affect scalability, so should be fine in combination with
viewBox
.This could be reworded to something along these lines:
height
andwidth
pixel valueThe spec says:
Given that all absolute length units are compatible (they can all be converted to the canonical
px
unit), requiring a pixel value looks restrictive. The term "pixel value" itself might be a bit vague (does it mean "in pixel units" or "in units compatible with the pixel unit"?).This could be open to any absolute length:
x
andy
on the ICBThe spec says:
I'm not sure the value of
x
andy
is relevant there? The intrinsic sizing of SVG content is only impacted withwidth
,height
, andviewBox
.Suggested rewording:
For reference, this section was discussed in #860, #800, #463.
See also EPUBCheck issue w3c/epubcheck#902 and PR w3c/epubcheck#973
The text was updated successfully, but these errors were encountered: