Exemple #1
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            var commands = new List <IPathCommand>(Commands.Count);
            var flipType = layout.GetFlipType();

            foreach (IPathCommand command in Commands)
            {
                var flippedCommand = command;
                if ((flipType & FlipType.Horizontal) == FlipType.Horizontal)
                {
                    flippedCommand = flippedCommand.Flip(true);
                }
                if ((flipType & FlipType.Vertical) == FlipType.Vertical)
                {
                    flippedCommand = flippedCommand.Flip(false);
                }
                commands.Add(flippedCommand);
            }

            Point start = Start.Resolve(layout, layoutContext.Options);

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawPath(Point.Add(start, layout.Location), commands, Thickness, Fill);
            }
            else
            {
                drawingContext.DrawPath(start, commands, Thickness, Fill);
            }
        }
Exemple #2
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point location = Location.Resolve(layout, layoutContext.Options);
            var   drawRect = new Rect(location, new Size(Width, Height));

            switch (layout.GetFlipType())
            {
            case FlipType.Horizontal:
                drawRect = new Rect(drawRect.X - Width, drawRect.Y, Width, Height);
                break;

            case FlipType.Vertical:
                drawRect = new Rect(drawRect.X, drawRect.Y - Height, Width, Height);
                break;

            case FlipType.Both:
                drawRect = new Rect(drawRect.X - Width, drawRect.Y - Height, Width, Height);
                break;
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawRectangle(Point.Add(drawRect.TopLeft, layout.Location), drawRect.Size, StrokeThickness, Fill);
            }
            else
            {
                drawingContext.DrawRectangle(drawRect.TopLeft, drawRect.Size, StrokeThickness, Fill);
            }
        }
        public Point Resolve(LayoutInformation layout, LayoutOptions options)
        {
            var            flipType  = layout.GetFlipType();
            ComponentPoint tempPoint = Flip(flipType, layout.Flip);

            double x = tempPoint.Offset.X;
            double y = tempPoint.Offset.Y;

            if (tempPoint.RelativeToX == ComponentPosition.Middle && layout.Orientation == Orientation.Horizontal)
            {
                x += layout.Size / 2;
            }
            else if (tempPoint.RelativeToY == ComponentPosition.Middle && layout.Orientation == Orientation.Vertical)
            {
                y += layout.Size / 2;
            }

            if (tempPoint.RelativeToX == ComponentPosition.End && layout.Orientation == Orientation.Horizontal)
            {
                x += layout.Size;
            }
            else if (tempPoint.RelativeToY == ComponentPosition.End && layout.Orientation == Orientation.Vertical)
            {
                y += layout.Size;
            }

            if (options.AlignMiddle)
            {
                if (layout.Orientation == Orientation.Horizontal && tempPoint.RelativeToX == ComponentPosition.Middle)
                {
                    if ((x - tempPoint.Offset.X) % options.GridSize != 0d)
                    {
                        x += 5d;
                    }
                }
                else if (tempPoint.RelativeToY == ComponentPosition.Middle)
                {
                    if ((y - tempPoint.Offset.Y) % options.GridSize != 0d)
                    {
                        y += 5d;
                    }
                }
            }

            return(new Point(x, y));
        }
Exemple #4
0
        public void Render(LayoutInformation layout, ILayoutContext layoutContext, IDrawingContext drawingContext)
        {
            Point renderLocation = Location.Resolve(layout, layoutContext.Options);

            TextAlignment tempAlignment = Alignment;
            var           flipType      = layout.GetFlipType();

            if ((flipType & FlipType.Horizontal) == FlipType.Horizontal)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.BottomRight;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.CentreLeft:
                    tempAlignment = TextAlignment.CentreRight;
                    break;

                case TextAlignment.CentreRight:
                    tempAlignment = TextAlignment.CentreLeft;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.TopLeft;
                    break;
                }
            }

            if ((flipType & FlipType.Vertical) == FlipType.Vertical)
            {
                switch (Alignment)
                {
                case TextAlignment.BottomCentre:
                    tempAlignment = TextAlignment.TopCentre;
                    break;

                case TextAlignment.BottomLeft:
                    tempAlignment = TextAlignment.TopLeft;
                    break;

                case TextAlignment.BottomRight:
                    tempAlignment = TextAlignment.TopRight;
                    break;

                case TextAlignment.TopCentre:
                    tempAlignment = TextAlignment.BottomCentre;
                    break;

                case TextAlignment.TopLeft:
                    tempAlignment = TextAlignment.BottomLeft;
                    break;

                case TextAlignment.TopRight:
                    tempAlignment = TextAlignment.BottomRight;
                    break;
                }
            }

            List <TextRun> renderTextRuns = new List <TextRun>(TextRuns.Count);

            // Build runs
            foreach (TextRun run in TextRuns)
            {
                // Resolve value
                string renderValue;
                if (run.Text.StartsWith("$"))
                {
                    renderValue = layoutContext.GetFormattedVariable(run.Text);
                }
                else
                {
                    renderValue = run.Text;
                }

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\\[uU]([0-9A-F]{4})");
                renderValue = regex.Replace(renderValue, match => ((char)int.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString());

                renderTextRuns.Add(new TextRun(renderValue, run.Formatting));
            }

            if (layoutContext.Options.Absolute)
            {
                drawingContext.DrawText(Point.Add(renderLocation, layout.Location), tempAlignment, (int)Rotation * 90, renderTextRuns);
            }
            else
            {
                drawingContext.DrawText(renderLocation, tempAlignment, (int)Rotation * 90, renderTextRuns);
            }
        }