Skip to content

Commit

Permalink
correct visibility and display handling for text
Browse files Browse the repository at this point in the history
  • Loading branch information
gomi42 committed Apr 13, 2022
1 parent 8268e7f commit bc50092
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static double GetNumberPercentFromTop(this CssStyleCascade cssStyleCascad
}

/// <summary>
/// Get an attribute as double from the level (0 = top)
/// Get an attribute as double from the given level (0 = top)
/// </summary>
public static double GetNumberPercentFromLevel(this CssStyleCascade cssStyleCascade, string name, int level, double defaultValue)
{
Expand Down Expand Up @@ -87,5 +87,27 @@ public static Matrix GetTransformMatrixFromTop(this CssStyleCascade cssStyleCasc

return Matrix.Identity;
}

/// <summary>
/// Is the current element visible
/// </summary>
/// <returns></returns>
public static bool IsVisible(this CssStyleCascade cssStyleCascade)
{
var visibility = cssStyleCascade.GetProperty("visibility");

return string.IsNullOrEmpty(visibility) || (visibility != "hidden" && visibility != "colapsed");
}

/// <summary>
/// Is the current element displayed
/// </summary>
/// <returns></returns>
public static bool IsDisplayed(this CssStyleCascade cssStyleCascade)
{
var display = cssStyleCascade.GetPropertyFromTop("display");

return display != "none";
}
}
}

This file was deleted.

3 changes: 1 addition & 2 deletions Shape Converter/BusinessLogic/Parser/Svg/Main/ShapeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public GraphicVisual Parse(XElement shape,
GraphicVisual graphicVisual = null;

cssStyleCascade.PushStyles(shape);
var strVal = cssStyleCascade.GetProperty("visibility");

if (string.IsNullOrEmpty(strVal) || strVal == "visible")
if (cssStyleCascade.IsVisible())
{
var transformMatrix = cssStyleCascade.GetTransformMatrixFromTop();
currentTransformationMatrix = transformMatrix * currentTransformationMatrix;
Expand Down
3 changes: 1 addition & 2 deletions Shape Converter/BusinessLogic/Parser/Svg/Main/SvgParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ private GraphicGroup ParseChildren(XElement groupElement, Matrix matrix)
foreach (var element in groupElement.Elements())
{
cssStyleCascade.PushStyles(element);
var strVal = cssStyleCascade.GetPropertyFromTop("display");

if (strVal != "none")
if (cssStyleCascade.IsDisplayed())
{
GraphicVisual graphicVisual = ParseElement(element, matrix);

Expand Down
17 changes: 8 additions & 9 deletions Shape Converter/BusinessLogic/Parser/Svg/Main/TextParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public TextParser(CssStyleCascade cssStyleCascade,
/// <summary>
/// Parse a single text
/// </summary>
public GraphicVisual Parse(XElement shape,
public GraphicVisual Parse(XElement textElement,
Matrix currentTransformationMatrix)
{
cssStyleCascade.PushStyles(shape);
cssStyleCascade.PushStyles(textElement);

var transformMatrix = cssStyleCascade.GetTransformMatrixFromTop();
currentTransformationMatrix = transformMatrix * currentTransformationMatrix;

var graphicVisual = ParseText(shape, currentTransformationMatrix);
var graphicVisual = ParseText(textElement, currentTransformationMatrix);

cssStyleCascade.Pop();

Expand Down Expand Up @@ -158,7 +158,9 @@ private GraphicVisual ParseText(XElement textElement,
{
case XElement embededElement:
{
if (!PresentationAttribute.IsElementVisible(embededElement))
cssStyleCascade.PushStyles(embededElement);

if (!cssStyleCascade.IsDisplayed())
{
continue;
}
Expand All @@ -168,9 +170,6 @@ private GraphicVisual ParseText(XElement textElement,
case "tspan":
{
var tspanElement = embededElement;
var isTspanDisplayed = PresentationAttribute.IsElementDisplayed(tspanElement);

cssStyleCascade.PushStyles(tspanElement);

var xChildList = GetLengthPercentList(tspanElement, "x", PercentBaseSelector.ViewBoxWidth);
var dxChildList = GetLengthPercentList(tspanElement, "dx", PercentBaseSelector.ViewBoxWidth);
Expand Down Expand Up @@ -203,7 +202,7 @@ private GraphicVisual ParseText(XElement textElement,
position.X.SetChildValues(null, null);
position.Y.SetChildValues(null, null);

if (isTspanDisplayed)
if (cssStyleCascade.IsVisible())
{
ColorBlock colorBlock;

Expand All @@ -230,7 +229,6 @@ private GraphicVisual ParseText(XElement textElement,
}
}

cssStyleCascade.Pop();
}
break;

Expand All @@ -240,6 +238,7 @@ private GraphicVisual ParseText(XElement textElement,
}
}

cssStyleCascade.Pop();
break;
}

Expand Down
1 change: 0 additions & 1 deletion Shape Converter/Shape Converter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@
<Compile Include="BusinessLogic\Parser\Svg\Helper\ColorParser.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Helper\DoubleAttributeParser.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Helper\DoubleParser.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Helper\PresentationAttribute.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Main\BrushParser.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Main\CharacterPositions.cs" />
<Compile Include="BusinessLogic\Parser\Svg\Main\Clipping.cs" />
Expand Down

0 comments on commit bc50092

Please sign in to comment.