No viewbox in svg results in 1x1 px image

Bug #1245989 reported by David Mathog
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Triaged
Medium
Unassigned

Bug Description

The example SVG attached here has no viewbox information and opens in current trunk at a size of 1x1 px.

In older versions of Inkscape like 0.48.4 it opened at the default page size (A4).

The previous behavior was better than the current behavior.

Revision history for this message
David Mathog (mathog) wrote :
Revision history for this message
su_v (suv-lp) wrote :

As commented on the mailing list:
- not reproduced with rev <= 12552
- reproduced with rev >= 12554

<http://sourceforge.net/mailarchive/message.php?msg_id=31573822>

tags: added: regression units viewbox
Changed in inkscape:
importance: Undecided → Medium
milestone: none → 0.49
status: New → Triaged
ScislaC (scislac)
tags: added: blocker
Revision history for this message
su_v (suv-lp) wrote :

Related earlier report (<svg> has "width='100%' height='100%'" and no viewBox attribute):
- Bug 1235809 "trunk: incorrect page size for XAML file (rev >= 12554)”
  <https://bugs.launchpad.net/inkscape/+bug/1235809>

Revision history for this message
David Mathog (mathog) wrote :

I can tell you what is wrong and how to fix it, but I do not have time to work on it now.

The core issue is that the "units" code falls over and dies when there is no viewbox. This problem came up in
the context of EMF/WMF import too. To work around it there, after the document is created, a call must be made to this:

   Metafile::setViewBoxIfMissing(SPDocument *doc) {}

which will apply a bunch of hacks to work around this and an assortment of other bugs in and or caused by the units implementation. The document height and width must have been set, or it will not work. (This method was not needed before units was added to Inkscape, hence my annoyance with the units implementation, which has repeatedly broken EMF/WMF import.) Note especially the call in that function to

  scaleChildItemsRec

with a "true" final parameter. This disables the normal units behavior of rescaling all coordinates and lengths and replaces it with a single scale transform at the topmost group. If that is not done clipping, patterns, and most likely other effects that use <defs> will break on import, because scaleChildItemsRec rescales objects but not <defs>. (The test case in this bug has that sort of reference.)

Revision history for this message
Johan Engelen (johanengelen) wrote :

To me it seems pretty obvious that this is not related to units or viewbox.
The only reason Inkscape does not know how to open this file is that width and height are specified in percentages. AFAIK, Inkscape has never known how to handle that. Before it opened an A4 page, which is just as wrong as 1x1px. No real change there.

I think we can remove the "blocker", "regression", and "viewbox" tags, as none of them apply imo.

Revision history for this message
ScislaC (scislac) wrote :

@Johan

I dropped the "blocker" and "viewbox" tags. This is still a regression as far as user experience is concerned, so I think it's appropriate to keep that tag intact. If a change in our codebase reveals that we weren't doing things "right" to begin with, but it previously appeared to work in a sensible way, we did break something as far as the user is concerned.

tags: removed: blocker viewbox
ScislaC (scislac)
Changed in inkscape:
milestone: 0.91 → 0.92
Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

width="100%" and height="100%" are valid, in fact they are the default values (See: http://www.w3.org/TR/SVG/struct.html#SVGElementWidthAttribute)

We handle width="100%" and height="100%" fine if there is a viewBox. If there is no width/height and no viewBox then one assumes a scaling of 1 (1user-unit is the same as 1px). So absolute units work. This will render the above file (clipRect.svg) correctly. (Note: The browsers render the file correctly.)

We do need an "effective page" to calculate % values against but we can choose what ever we want. I would suggest using something like 500x500 px. So the 'viewBox' should default to (0 0 500 500).

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

Here is a file that has no absolute lengths and no 'viewBox'. It renders fine in Firefox and Chrome. We should render it correctly too.

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :

My example file does render fine in trunk using a default A4 page (where is this being set?). It is just that the canvas has been scaled to show a 1x1 px page.

The example file clipRect.svg is probably not rendered for a completely different reason. It is using the <set> element which we do not support to control visibility of elements.

Revision history for this message
su_v (suv-lp) wrote :

On 2014-11-26 15:56 (+0100), Tavmjong Bah wrote:
> The example file clipRect.svg is probably not rendered (…)

It is rendered (in trunk), but not where the user expects it to be (based on the experience in stable Inkscape versions <= 0.48) - inside the document page area (zoom to page, or '5'). The content AFAICT is shown correctly when zooming to drawing content ('4').

See also my reply on the mailing list:
http://thread.gmane.org/gmane.comp.graphics.inkscape.devel/41914/focus=41922

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.