Skip to content

Commit c70ab35

Browse files
committed
more meaningful names are generated for a use and text tags. Empty text nodes are removed from an output.
1 parent 678f445 commit c70ab35

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

SvgFileType/SvgFileType.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public SvgFileType()
2323
{
2424
}
2525

26-
// Dont change this text! It's used by a PSD import plugin to keep photoshop folder strure.
26+
// Dont change this text! It's used by a PSD import plugin to keep photoshop folder structure.
2727
public const string LayerGroupBegin = "Layer Group: {0}";
2828
public const string LayerGroupEnd = "End Layer Group: {0}";
2929

@@ -248,7 +248,7 @@ private static void RenderElements( List<SvgVisualElement> elements, Document ou
248248
{
249249
if (element is PaintGroupBoundaries)
250250
{
251-
// Render empty boundary and continue
251+
// Render empty group boundary and continue
252252
var pdnLayer = new BitmapLayer(outputDocument.Width, outputDocument.Height);
253253
pdnLayer.Name = ((PaintGroupBoundaries)element).ID;
254254
outputDocument.Layers.Add(pdnLayer);
@@ -262,6 +262,7 @@ private static void RenderElements( List<SvgVisualElement> elements, Document ou
262262
}
263263

264264
bool itemShouldBeIgnored = false;
265+
265266
// Turn on visibility from node to parent
266267
var toCheck = (SvgElement)element;
267268
while (toCheck != null)
@@ -413,10 +414,31 @@ private static string GetLayerTitle(SvgElement element)
413414
layerName = getter.Invoke(element, null) as string;
414415
}
415416

416-
if(string.IsNullOrEmpty(layerName))
417+
if (string.IsNullOrEmpty(layerName))
417418
{
418419
layerName = element.GetType().Name;
419420
}
421+
422+
// Generate more meanfull name for a svg use node. Add reference element name in a case if it's local document.
423+
var useElement = element as SvgUse;
424+
if (useElement != null && useElement.ReferencedElement != null && !string.IsNullOrEmpty(useElement.ReferencedElement.OriginalString))
425+
{
426+
var str = useElement.ReferencedElement.OriginalString.Trim();
427+
if(str.StartsWith("#"))
428+
{
429+
layerName += str.Replace('#', ' ');
430+
}
431+
}
432+
433+
// Genearte more meanfull name for a svg text.
434+
var text = element as SvgTextBase;
435+
if (text != null && !string.IsNullOrEmpty(text.Text))
436+
{
437+
var textToUse = text.Text;
438+
if (text.Text.Length > 35)
439+
textToUse = text.Text.Substring(0, 35);
440+
layerName += " " + textToUse;
441+
}
420442
}
421443

422444
return layerName;
@@ -435,12 +457,6 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
435457
continue;
436458
}
437459

438-
// Dont prepare def lists for a separate rendering.
439-
if (toRender is SvgDefinitionList)
440-
{
441-
continue;
442-
}
443-
444460
var isGroup = toRender is SvgGroup;
445461
if (isGroup)
446462
{
@@ -489,6 +505,11 @@ private static IEnumerable<SvgElement> PrepareFlatElements(SvgElementCollection
489505
yield return new PaintGroupBoundaries() { ID = string.Format(LayerGroupBegin, groupName), IsStart = true };
490506
}
491507

508+
// Skip text with empty content. But keep all children nodes.
509+
var textNode = toRender as SvgTextBase;
510+
if (textNode != null && string.IsNullOrEmpty(textNode.Text))
511+
continue;
512+
492513
yield return toRender;
493514
}
494515
}

0 commit comments

Comments
 (0)