コード例 #1
0
        public virtual IEnumerable <TRenderObject> RenderLabel(Label2D label)
        {
            Size2D textSize = TextRenderer.MeasureString(label.Text, label.Font);
            //Size2D size = new Size2D(textSize.Width + 2*label.CollisionBuffer.Width, textSize.Height + 2*label.CollisionBuffer.Height);
            //Rectangle2D layoutRectangle =
            //    new Rectangle2D(new Point2D(label.Location.X-label.CollisionBuffer.Width, label.Location.Y-label.CollisionBuffer.Height), size);

            LabelStyle style = label.Style;
            Int32      x = 0, y = 0;

            if (style.HorizontalAlignment != HorizontalAlignment.Right || style.VerticalAlignment != VerticalAlignment.Bottom)
            {
                switch (style.HorizontalAlignment)
                {
                case HorizontalAlignment.Center:
                    x -= (Int32)(textSize.Width / 2.0f);
                    break;

                case HorizontalAlignment.Left:
                    x -= (Int32)textSize.Width;
                    break;

                default:
                    break;
                }

                switch (style.VerticalAlignment)
                {
                case VerticalAlignment.Middle:
                    y += (Int32)(textSize.Height / 2.0f);
                    break;

                case VerticalAlignment.Top:
                    y += (Int32)textSize.Height;
                    break;

                default:
                    break;
                }
            }

            Point2D     location        = RenderTransform.TransformVector(label.Location.X, label.Location.Y).Add(new Point2D(x, y));
            Rectangle2D layoutRectangle = new Rectangle2D(location, textSize);

            if (label.Style.Halo != null)
            {
                StylePen   halo       = label.Style.Halo;
                StyleBrush background = label.Style.Background;

                IEnumerable <TRenderObject> haloPath = VectorRenderer.RenderPaths(
                    generateHaloPath(layoutRectangle), background, background, background,
                    halo, halo, halo, RenderState.Normal);

                foreach (TRenderObject ro in haloPath)
                {
                    yield return(ro);
                }
            }

            IEnumerable <TRenderObject> renderedText = TextRenderer.RenderText(
                label.Text, label.Font, layoutRectangle, label.FlowPath, label.Style.Foreground, label.Transform);

            foreach (TRenderObject ro in renderedText)
            {
                yield return(ro);
            }
        }
コード例 #2
0
        private static IEnumerable <Path2D> generateHaloPath(Rectangle2D layoutRectangle)
        {
            Path2D path = new Path2D(layoutRectangle.GetVertexes(), true);

            yield return(path);
        }