diff --git a/Shape Converter/BusinessLogic/Parser/Svg/Css/CssStyleCascadeExtension.cs b/Shape Converter/BusinessLogic/Parser/Svg/Css/CssStyleCascadeExtension.cs index 6774574..5bf3630 100644 --- a/Shape Converter/BusinessLogic/Parser/Svg/Css/CssStyleCascadeExtension.cs +++ b/Shape Converter/BusinessLogic/Parser/Svg/Css/CssStyleCascadeExtension.cs @@ -56,7 +56,7 @@ public static double GetNumberPercentFromTop(this CssStyleCascade cssStyleCascad } /// - /// Get an attribute as double from the level (0 = top) + /// Get an attribute as double from the given level (0 = top) /// public static double GetNumberPercentFromLevel(this CssStyleCascade cssStyleCascade, string name, int level, double defaultValue) { @@ -87,5 +87,27 @@ public static Matrix GetTransformMatrixFromTop(this CssStyleCascade cssStyleCasc return Matrix.Identity; } + + /// + /// Is the current element visible + /// + /// + public static bool IsVisible(this CssStyleCascade cssStyleCascade) + { + var visibility = cssStyleCascade.GetProperty("visibility"); + + return string.IsNullOrEmpty(visibility) || (visibility != "hidden" && visibility != "colapsed"); + } + + /// + /// Is the current element displayed + /// + /// + public static bool IsDisplayed(this CssStyleCascade cssStyleCascade) + { + var display = cssStyleCascade.GetPropertyFromTop("display"); + + return display != "none"; + } } } diff --git a/Shape Converter/BusinessLogic/Parser/Svg/Helper/PresentationAttribute.cs b/Shape Converter/BusinessLogic/Parser/Svg/Helper/PresentationAttribute.cs deleted file mode 100644 index 80fb8c6..0000000 --- a/Shape Converter/BusinessLogic/Parser/Svg/Helper/PresentationAttribute.cs +++ /dev/null @@ -1,48 +0,0 @@ -// -// Author: -// Michael Göricke -// -// Copyright (c) 2019 -// -// This file is part of ShapeConverter. -// -// ShapeConverter is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see. - -using System.Xml.Linq; - -namespace ShapeConverter.BusinessLogic.Parser.Svg.Helper -{ - internal static class PresentationAttribute - { - /// - /// Check if the given element is visible - /// - public static bool IsElementVisible(XElement element) - { - var displayAttr = element.Attribute("display"); - - return displayAttr == null || displayAttr.Value != "none"; - } - - /// - /// Check if the given element is visible - /// - public static bool IsElementDisplayed(XElement element) - { - var displayAttr = element.Attribute("visibility"); - - return displayAttr == null || displayAttr.Value == "visible"; - } - } -} diff --git a/Shape Converter/BusinessLogic/Parser/Svg/Main/ShapeParser.cs b/Shape Converter/BusinessLogic/Parser/Svg/Main/ShapeParser.cs index d0e9dfe..767323c 100644 --- a/Shape Converter/BusinessLogic/Parser/Svg/Main/ShapeParser.cs +++ b/Shape Converter/BusinessLogic/Parser/Svg/Main/ShapeParser.cs @@ -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; diff --git a/Shape Converter/BusinessLogic/Parser/Svg/Main/SvgParser.cs b/Shape Converter/BusinessLogic/Parser/Svg/Main/SvgParser.cs index c2bbb89..e943b9e 100644 --- a/Shape Converter/BusinessLogic/Parser/Svg/Main/SvgParser.cs +++ b/Shape Converter/BusinessLogic/Parser/Svg/Main/SvgParser.cs @@ -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); diff --git a/Shape Converter/BusinessLogic/Parser/Svg/Main/TextParser.cs b/Shape Converter/BusinessLogic/Parser/Svg/Main/TextParser.cs index 522d6e9..cc30e82 100644 --- a/Shape Converter/BusinessLogic/Parser/Svg/Main/TextParser.cs +++ b/Shape Converter/BusinessLogic/Parser/Svg/Main/TextParser.cs @@ -68,15 +68,15 @@ public TextParser(CssStyleCascade cssStyleCascade, /// /// Parse a single text /// - 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(); @@ -158,7 +158,9 @@ private GraphicVisual ParseText(XElement textElement, { case XElement embededElement: { - if (!PresentationAttribute.IsElementVisible(embededElement)) + cssStyleCascade.PushStyles(embededElement); + + if (!cssStyleCascade.IsDisplayed()) { continue; } @@ -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); @@ -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; @@ -230,7 +229,6 @@ private GraphicVisual ParseText(XElement textElement, } } - cssStyleCascade.Pop(); } break; @@ -240,6 +238,7 @@ private GraphicVisual ParseText(XElement textElement, } } + cssStyleCascade.Pop(); break; } diff --git a/Shape Converter/Shape Converter.csproj b/Shape Converter/Shape Converter.csproj index 9339335..084d16a 100644 --- a/Shape Converter/Shape Converter.csproj +++ b/Shape Converter/Shape Converter.csproj @@ -428,7 +428,6 @@ -