ElinamLLC/SharpVectors

rect without "fill" property is not resolved

Handsome08 opened this issue · 4 comments

svg like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg width="68px" height="40px" viewBox="0 0 68 40" version="1.1" xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink">
    <title>ic_dottedline@2x</title>
    <g id="ic_dottedline" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g>
            <rect id="11" x="0" y="0" width="68" height="40"></rect>
            <path d="M16,21 L16,23 L11,23 L11,21 L16,21 Z M23,21 L23,23 L18,23 L18,21 L23,21 Z 
M30,21 L30,23 L25,23 L25,21 L30,21 Z M37,21 L37,23 L32,23 L32,21 L37,21 Z 
M44,21 L44,23 L39,23 L39,21 L44,21 Z M51,21 L51,23 L46,23 L46,21 L51,21 Z 
M58,21 L58,23 L53,23 L53,21 L58,21 Z" id="22" fill="#36415A" fill-rule="nonzero"></path>
        </g>
    </g>
</svg>

after resolve:

<DrawingImage x:Key="ic_dottedline">
  <DrawingImage.Drawing>
    <GeometryDrawing Brush="#FF36415A">
      <GeometryDrawing.Geometry>
        <PathGeometry FillRule="Nonzero" Figures="M53,21L58,21 58,23 53,23 53,21z M46,21L51,21 51,23 46,23 46,21z 
M39,21L44,21 44,23 39,23 39,21z M32,21L37,21 37,23 32,23 32,21z M25,21L30,21 30,23 25,23 25,21z 
M18,21L23,21 23,23 18,23 18,21z M11,21L16,21 16,23 11,23 11,21z" />
      </GeometryDrawing.Geometry>
    </GeometryDrawing>
  </DrawingImage.Drawing>
</DrawingImage>`

it seems the "rect" without "fill" property is ignored,but what I need is:

<DrawingImage x:Key="ic_dottedline">
  <DrawingImage.Drawing>
    <DrawingGroup>
      <DrawingGroup.Children>
        <GeometryDrawing>
          <GeometryDrawing.Brush>
            <SolidColorBrush Color="#FFFFFFFF" Opacity="0" />
          </GeometryDrawing.Brush>
          <GeometryDrawing.Geometry>
            <RectangleGeometry RadiusX="0" RadiusY="0" Rect="0,0,68,40" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
        <GeometryDrawing Brush="#FF36415A">
          <GeometryDrawing.Geometry>
            <PathGeometry FillRule="Nonzero" Figures="M16,21L16,23 11,23 11,21 16,21z M23,21L23,23 18,23 18,21 23,21z
M30,21L30,23 25,23 25,21 30,21z M37,21L37,23 32,23 32,21 37,21z 
M44,21L44,23 39,23 39,21 44,21z M51,21L51,23 46,23 46,21 51,21z M58,21L58,23 53,23 53,21 58,21z" />
          </GeometryDrawing.Geometry>
        </GeometryDrawing>
      </DrawingGroup.Children>
    </DrawingGroup>
  </DrawingImage.Drawing>
</DrawingImage>

The line <g id="ic_dottedline" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
sets the stroke and fill explicitly to none. These properties are inheritable and if not specified, will be inherited. And if the inherited fill is none it cannot be set to Color="#FFFFFFFF" Opacity="0"
To get the results you want, explicitly set the properties as following:

<rect id="11" x="0" y="0" width="68" height="40" fill="#FFFFFFFF" opacity="0"/>

The line <g id="ic_dottedline" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> sets the stroke and fill explicitly to none. These properties are inheritable and if not specified, will be inherited. And if the inherited fill is none it cannot be set to Color="#FFFFFFFF" Opacity="0" To get the results you want, explicitly set the properties as following:

<rect id="11" x="0" y="0" width="68" height="40" fill="#FFFFFFFF" opacity="0"/>

but I think the “rect” should not be ignored,maybe its fill can be set to Color="#00000000" Opacity="0"

but I think the “rect” should not be ignored,maybe its fill can be set to Color="#00000000" Opacity="0"

I know what you want, but it not normal to be given a property it never has, its presence adds to the bounds of the rendered image so it has effect and can result in breaking change. Such are added through options, if there are real needs.
If you are using files generated by other programs, add a visitor to modify it. See the ISvgElementVisitor.

@Handsome08 I have added initial support through settings properties:

SolidColorBrush noneBrush = new SolidColorBrush(Colors.White);
noneBrush.Opacity = 0f;

WpfDrawingSettings wpfSettings = new WpfDrawingSettings();
wpfSettings[WpfDrawingSettings.PropertyNoneBrush] = noneBrush;

You can also set the pen to apply in this case.