Skip to content

SVGParseException marker orient="auto-start-reverse" #296

@zuntan

Description

@zuntan

I'm using your library. Thank you.

The following code throws an exception.

It seems the orient="auto-start-reverse" attribute in the marker tag is causing the issue.

According to the following, “auto” and “auto-start-reverse” are valid values:
https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/orient

I noticed this and wanted to let you know.
Thank you.

import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import com.caverock.androidsvg.SVG

@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {

    @Test
    fun loadSvg() {

        val SVG_WITHOUT_ARROW = """
            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <!-- Created with Inkscape (http://www.inkscape.org/) -->
            
            <svg
               width="256"
               height="256"
               viewBox="0 0 256 256"
               version="1.1"
               id="svg5"
               xmlns="http://www.w3.org/2000/svg"
               xmlns:svg="http://www.w3.org/2000/svg">
              <defs
                 id="defs2" />
              <g
                 id="layer1">
                <path
                   style="fill:none;fill-opacity:0.999903;stroke:#000000;stroke-width:1.28505;stroke-linecap:round;"
                   d="M 28.642517,227.35748 227.35748,28.642524"
                   id="path236" />
              </g>
            </svg>
        """.trimIndent()

        val SVG_WITH_ARROW_OK = """
            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <!-- Created with Inkscape (http://www.inkscape.org/) -->
            
            <svg
               width="256"
               height="256"
               viewBox="0 0 256 256"
               version="1.1"
               id="svg5"
               xmlns="http://www.w3.org/2000/svg"
               xmlns:svg="http://www.w3.org/2000/svg">
              <defs
                 id="defs2">
                <marker
                   style="overflow:visible"
                   id="TriangleStart"
                   refX="0"
                   refY="0"
                   orient="-45"
                   markerWidth="5.3244081"
                   markerHeight="6.155385"
                   viewBox="0 0 5.3244081 6.1553851"
                   preserveAspectRatio="xMidYMid">
                  <path
                     transform="scale(0.5)"
                     style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:1pt"
                     d="M 5.77,0 -2.88,5 V -5 Z"
                     id="path135" />
                </marker>
              </defs>
              <g
                 id="layer1">
                <path
                   style="fill:none;fill-opacity:0.999903;stroke:#000000;stroke-width:1.28505;stroke-linecap:round;marker-end:url(#TriangleStart)"
                   d="M 28.642517,227.35748 227.35748,28.642524"
                   id="path236" />
              </g>
            </svg>    
        """.trimIndent()

        val SVG_WITH_ARROW_NG = """
            <?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <!-- Created with Inkscape (http://www.inkscape.org/) -->
            
            <svg
               width="256"
               height="256"
               viewBox="0 0 256 256"
               version="1.1"
               id="svg5"
               xmlns="http://www.w3.org/2000/svg"
               xmlns:svg="http://www.w3.org/2000/svg">
              <defs
                 id="defs2">
                <marker
                   style="overflow:visible"
                   id="TriangleStart"
                   refX="0"
                   refY="0"
                   orient="auto-start-reverse"
                   markerWidth="5.3244081"
                   markerHeight="6.155385"
                   viewBox="0 0 5.3244081 6.1553851"
                   preserveAspectRatio="xMidYMid">
                  <path
                     transform="scale(0.5)"
                     style="fill:context-stroke;fill-rule:evenodd;stroke:context-stroke;stroke-width:1pt"
                     d="M 5.77,0 -2.88,5 V -5 Z"
                     id="path135" />
                </marker>
              </defs>
              <g
                 id="layer1">
                <path
                   style="fill:none;fill-opacity:0.999903;stroke:#000000;stroke-width:1.28505;stroke-linecap:round;marker-end:url(#TriangleStart)"
                   d="M 28.642517,227.35748 227.35748,28.642524"
                   id="path236" />
              </g>
            </svg>            
        """.trimIndent()

        val diff = """
            diff -u c.svg b.svg 
            --- c.svg	2025-10-01 12:01:37.068276239 +0900
            +++ b.svg	2025-10-01 12:01:07.374413195 +0900
            @@ -16,7 +16,7 @@
                    id="TriangleStart"
                    refX="0"
                    refY="0"
            -       orient="-45"
            +       orient="auto-start-reverse"
                    markerWidth="5.3244081"
                    markerHeight="6.155385"
                    viewBox="0 0 5.3244081 6.1553851"
        """.trimIndent()        
        
        // OK
        SVG.getFromString( SVG_WITHOUT_ARROW )

        // OK
        SVG.getFromString( SVG_WITH_ARROW_OK )

        // com.caverock.androidsvg.SVGParseException: Invalid float value: auto-start-reverse
        // at com.caverock.androidsvg.SVGParser.parseFloat(SVGParser.java:3499)
        SVG.getFromString( SVG_WITH_ARROW_NG )
    }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions