Ejemplo n.º 1
0
        public void Render(Component component, CircuitDiagram.Render.IRenderContext dc, bool absolute)
        {
            Point renderLocation = Location.Resolve(component);

            TextAlignment tempAlignment = Alignment;
            if (component.IsFlipped && component.Orientation == Orientation.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;
                }
            }
            else if (component.IsFlipped && component.Orientation == Orientation.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("$"))
                {
                    ComponentProperty property = component.FindProperty(run.Text);
                    renderValue = component.GetFormattedProperty(property);
                }
                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)Int32.Parse(match.Value.Substring(2), System.Globalization.NumberStyles.HexNumber)).ToString());

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

            if (absolute)
                dc.DrawText(Point.Add(renderLocation, component.Location), tempAlignment, renderTextRuns);
            else
                dc.DrawText(renderLocation, tempAlignment, renderTextRuns);
        }