Inkscape.org
Beyond the Basics Expanding Style Attribute
  1. #1
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    Manipulating objects expands the style attribute without no visual benefit

    When I draw a path with the Bezier tool, the default svg style is:

    style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"

    I changed the stroke colour & width, duplicated the path, edited nodes, grouped and ungrouped, moved between layers, etc.  This is a completely normal drawing workflow but these manipulations expanded the style attribute, eventually leading to this:

    style="font-variation-settings:normal;display:inline;mix-blend-mode:darken;vector-effect:none;fill:none;fill-opacity:1;stroke:#ffe680;stroke-width:11.3386;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"

    What I actually need is this:

    style="fill:none;stroke:#ffe680;stroke-width:11;stroke-linecap:round;stroke-linejoin:round"

    Why does my path need a font setting?  Most of the added entries are pointless, and this is a modest example.  In a drawing with hundreds of objects, these expanded styles can drastically increase the svg file size. 

    I could clear the object styles manually in the XML Editor but this is too tedious for me.  Maybe the Selectors and CSS dialog is the right place for a [Clear Styles] button, or the [Edit] menu where we already have the [Edit>Paste Style] function.  Perhaps somebody out there already has an efficient workflow they can share with us.

  2. #2
    Tyler Durden Tyler Durden @TylerDurden
    *

    Maybe the settings for erroneous styles?

    Preferences Svg Output
  3. #3
    Paddy_CAD Paddy_CAD @Paddy_CAD

    Thanks Tyler. These settings are new to me. I'll try these and report back. 

  4. #4
    Paddy_CAD Paddy_CAD @Paddy_CAD
    *

    Here are my findings.  I took a bloated svg file, applied all the settings, and saved a copy.  The file size fell from 428k to 287k, though some unnecessary style properties still appear.  For example, a simple rectangle still retains the following properties:

    style="color:#000000;display:inline;overflow:visible;visibility:visible;fill:#ffffff;stroke:#000000;stroke-width:0.88583;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate"

    This could be reduced to:

    style="fill:#ffffff;stroke:#000000;stroke-width:0.88583;stroke-linecap:round;stroke-linejoin:round"

    To find a theoretical minimum file size, I replaced all 1117 style attributes with this:

    style=""

    The file size fell to 207k but it's visually useless of course.  This shows that the automatic culling of unnecessary styles is more than respectable.  I could probably get below this minimum if I removed all shape and text styles and instead used a few group and layer styles. 

    In conclusion I'm reporting good results, but further experiments are in order.  More steps on the endless path to the mythical file size zero.