Пример #1
0
            protected SVGElement GetBorderContainer(SVGDocument parentDocument, BorderDescription description)
            {
                var gBorderContainer =
                    (SVGGElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "g");

                gBorderContainer.SetAttribute("stroke", description.StrokeColor);
                gBorderContainer.SetAttribute("stroke-width", GetCulturedString(description.Stroke));
                gBorderContainer.SetAttribute("stroke-linecap", "round");
                gBorderContainer.SetAttribute("stroke-linejoin", "round");

                // Lines around content
                // ================================
                // Border Line top
                var lineTop =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineTop.SetAttribute("x1", GetCulturedString(description.X));
                lineTop.SetAttribute("y1", GetCulturedString(description.Y));
                lineTop.SetAttribute("x2", GetCulturedString(description.X + description.Width));
                lineTop.SetAttribute("y2", GetCulturedString(description.Y));
                // Border Line right
                var lineRight =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineRight.SetAttribute("x1", GetCulturedString(description.X + description.Width));
                lineRight.SetAttribute("y1", GetCulturedString(description.Y));
                lineRight.SetAttribute("x2", GetCulturedString(description.X + description.Width));
                lineRight.SetAttribute("y2", GetCulturedString(description.Y + description.Height));
                // Border Line bottom
                var lineBottom =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineBottom.SetAttribute("x1", GetCulturedString(description.X + description.Width));
                lineBottom.SetAttribute("y1", GetCulturedString(description.Y + description.Height));
                lineBottom.SetAttribute("x2", GetCulturedString(description.X));
                lineBottom.SetAttribute("y2", GetCulturedString(description.Y + description.Height));
                // Border Line left
                var lineLeft =
                    (SVGLineElement)parentDocument.CreateElementNS("http://www.w3.org/2000/svg", "line");

                lineLeft.SetAttribute("x1", GetCulturedString(description.X));
                lineLeft.SetAttribute("y1", GetCulturedString(description.Y + description.Height));
                lineLeft.SetAttribute("x2", GetCulturedString(description.X));
                lineLeft.SetAttribute("y2", GetCulturedString(description.Y));

                gBorderContainer.AppendChild(lineTop);
                gBorderContainer.AppendChild(lineRight);
                gBorderContainer.AppendChild(lineBottom);
                gBorderContainer.AppendChild(lineLeft);

                return(gBorderContainer);
            }
Пример #2
0
            protected override void Merge_Internal(string[] svgFiles, MergeOptions options, SVGDocument svgContainer)
            {
                double borderStrokeFloat    = options.BorderStroke;
                double separatorStrokeFloat = options.SeparatorStroke;

                var gRootContainer =
                    (SVGGElement)svgContainer.CreateElementNS("http://www.w3.org/2000/svg", "g");

                var viewBoxWidth = 400f;                 //100f; //300f;

                float widthDocumentRootElement = 0;

                for (int i = 0; i < svgFiles.Length; i++)
                {
                    using (var svgDocument = new SVGDocument(svgFiles[i]))
                    {
                        var currentWidth = svgDocument.RootElement.GetBBox().Width;
                        if (widthDocumentRootElement < currentWidth)
                        {
                            widthDocumentRootElement = currentWidth;
                        }
                    }
                }
                var childWidthFloat = widthDocumentRootElement;

                int separatorAmount = svgFiles.Length - 1;

                // 1. First Step
                // Obtain height of single SVG block and total height
                // ================================
                double ratio;
                float  svgFirstDocumentHeight;

                using (var svgFirstDocument = new SVGDocument(svgFiles[0]))
                {
                    var widthFirstDocumentRootElement = svgFirstDocument.RootElement.GetBBox().Width;
                    ratio = childWidthFloat / widthFirstDocumentRootElement;
                    svgFirstDocumentHeight = svgFirstDocument.RootElement.GetBBox().Height;
                }
                var currentHeightFloat  = ratio * svgFirstDocumentHeight;
                var currentHeightString = GetCulturedString(currentHeightFloat);
                var totalHeightFloat    =
                    currentHeightFloat * svgFiles.Length + separatorStrokeFloat * svgFiles.Length - 1;

                // 2. RootElement attributes
                // ================================
                svgContainer.RootElement.ViewBox.BaseVal.X      = 0;
                svgContainer.RootElement.ViewBox.BaseVal.Y      = 0;
                svgContainer.RootElement.ViewBox.BaseVal.Width  = viewBoxWidth;
                svgContainer.RootElement.ViewBox.BaseVal.Height =
                    (float)(totalHeightFloat + 2 * borderStrokeFloat + 2 * separatorStrokeFloat);

                svgContainer.RootElement.SetAttribute("width", "100%");
                svgContainer.RootElement.SetAttribute("height", "100%");

                // 3. Border Container
                // ================================
                if (options.IsBordered && options.BorderStroke > 0)
                {
                    var borderDescription = new BorderDescription(
                        borderStrokeFloat,
                        borderStrokeFloat / 2,
                        borderStrokeFloat / 2,
                        childWidthFloat + 2 * separatorStrokeFloat + borderStrokeFloat,
                        totalHeightFloat + 2 * separatorStrokeFloat + borderStrokeFloat,
                        options.BorderColor);
                    var gBorderContainer = GetBorderContainer(svgContainer, borderDescription);
                    gRootContainer.AppendChild(gBorderContainer);
                }

                // 4. Separator Container
                // ================================
                if (options.IsWithSeparator && options.SeparatorStroke > 0)
                {
                    var separatorDescription = new SeparatorDescription(
                        separatorAmount,
                        separatorStrokeFloat,
                        borderStrokeFloat,
                        borderStrokeFloat + separatorStrokeFloat,
                        childWidthFloat + 2 * separatorStrokeFloat,
                        currentHeightFloat,
                        options.SeparatorColor);
                    var gSeparatorContainer = GetSeparatorContainer(svgContainer, separatorDescription);
                    gRootContainer.AppendChild(gSeparatorContainer);
                }

                // 5. Add child svg content
                // ================================
                double currentY        = borderStrokeFloat + separatorStrokeFloat;
                var    childWidthSting = GetCulturedString(childWidthFloat);
                var    xOffsetString   = GetCulturedString(borderStrokeFloat + separatorStrokeFloat);

                foreach (var svgFile in svgFiles)
                {
                    var svgDocument = new SVGDocument(svgFile);
                    svgDocument.RootElement.SetAttribute("width", childWidthSting);
                    svgDocument.RootElement.SetAttribute("height", currentHeightString);
                    svgDocument.RootElement.SetAttribute("x", xOffsetString);
                    svgDocument.RootElement.SetAttribute("y", GetCulturedString(currentY));

                    var gSampleContainer =
                        (SVGGElement)svgContainer.CreateElementNS("http://www.w3.org/2000/svg", "g");

                    currentY += currentHeightFloat + separatorStrokeFloat;
                    gSampleContainer.AppendChild(svgDocument.RootElement);

                    gRootContainer.AppendChild(gSampleContainer);
                    svgDocument.Dispose();
                }
                svgContainer.RootElement.AppendChild(gRootContainer);
            }