Code Monkey home page Code Monkey logo

Comments (10)

mattleibow avatar mattleibow commented on August 18, 2024

Looking closer, I see this:

Exception thrown: 'System.InvalidCastException' in Svg.Custom.dll
testhost Warning: 0 : Attribute 'stroke' cannot be set - type 'Svg.SvgPath' cannot convert from string '#FF0000FF'.
Exception thrown: 'System.InvalidCastException' in Svg.Custom.dll
testhost Warning: 0 : Attribute 'fill' cannot be set - type 'Svg.SvgPath' cannot convert from string '#FF0000FF'.

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

The inner exception that triggers this is:

Unable to cast object of type 'Svg.SvgColourServer' to type 'System.Drawing.Color'.

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

Seems it is because the colors have transparency and then the SvgColourConverter only checks for color lengths of 4 or 7, so basically #RGB or #RRGGBB... I am pretty sure alpha is supposed to be working in there?

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

Seems it was this commit:
wieslawsoltes/SVG@8c9b1f2#diff-2d8975b837b07567b22b03dbddeb4d6d8dc96107c7dbbcd3baf921f1c0e2ed19

image

Not sure why this was changed in the commit that was adding ExCSS.

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

Another scary thing with the converters from System.Drawing is that it expects ARGB:

https://github.com/dotnet/runtime/blob/74d927967dcf9dc1801c310603d6dc843dc28ad6/src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs#L56-L59

// We support 1, 3, or 4 arguments:
// 1 -- full ARGB encoded
// 3 -- RGB
// 4 -- ARGB

However, the SVG spec uses CSS colors which is RGBA:

https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color

#RGB        // The three-value syntax
#RGBA       // The four-value syntax
#RRGGBB     // The six-value syntax
#RRGGBBAA   // The eight-value syntax

EDIT: Actually, the SVG spec says only 3 or 6 digits: https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#color but I see my edge is using the full alpha as well making it all a lie if you ask me.

image

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

I am trying this:

else if (colour.StartsWith("#", StringComparison.InvariantCulture))
{
    // There are 4 types of #-based colors:
    //   4 chars: #RGB
    //   5 chars: #RGBA
    //   7 chars: #RRGGBB
    //   9 chars: #RRGGBBAA
    if (colour.Length == 4)
        colour = string.Format(culture, "#{0}{0}{1}{1}{2}{2}", colour[1], colour[2], colour[3]);
    else if (colour.Length == 5)
        colour = string.Format(culture, "#{0}{0}{1}{1}{2}{2}{3}{3}", colour[1], colour[2], colour[3], colour[4]);
    else if (colour.Length != 7 && colour.Length != 9)
        throw new SvgException("Colour is in an invalid format: '" + colour + "'");

    return base.ConvertFrom(context, culture, colour);
}

from svg.skia.

wieslawsoltes avatar wieslawsoltes commented on August 18, 2024

You are referring to css color but it's different specification from svg. Alpha is not supported you have to use stroke-opacity.

from svg.skia.

wieslawsoltes avatar wieslawsoltes commented on August 18, 2024

https://www.w3.org/TR/2008/REC-CSS2-20080411/syndata.html#color-units

The format of an RGB value in hexadecimal notation is a '#' immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.

from svg.skia.

wieslawsoltes avatar wieslawsoltes commented on August 18, 2024

https://www.w3.org/TR/2008/REC-CSS2-20080411/colors.html#propdef-color

from svg.skia.

mattleibow avatar mattleibow commented on August 18, 2024

OK, that is sort of where I eventually got to :)

We can close this as a design goal. BUT, Edge supports alpha. So yeah, it is all a lie anyway

from svg.skia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.