示例#1
0
        //渲染图片核心方法
        private void RenderImageCore(LayoutData layout)
        {
            layout.DoLayout();                                                                                                                                                              //执行布局
            this.CurrentImagePreferredRect = layout.OutImageBounds;                                                                                                                         //保存图片区域矩形
            bool      needRotate  = !(float.IsNaN(this.m_ImageRotateAngle) || this.m_ImageRotateAngle % 360f == 0f);                                                                        //是否需要旋转
            Rectangle imageBounds = needRotate ? RenderEngine.RotateRect(this.m_Graphics, this.CurrentImagePreferredRect, this.m_ImageRotateAngle, false) : this.CurrentImagePreferredRect; //新绘图区域(如果旋转则为旋转后的区域)

            //开始绘制
            if (this.m_State == State.Disabled && this.m_ImageGrayOnDisabled)
            {
                using (Image grayImg = RenderEngine.GetGrayImage(this.CurrentImage))
                {
                    this.m_Graphics.DrawImage(grayImg, imageBounds);
                }
            }
            else
            {
                this.m_Graphics.DrawImage(this.CurrentImage, imageBounds);
            }

            //恢复旋转
            if (needRotate)
            {
                this.m_Graphics.ResetTransform();
            }
        }
示例#2
0
        //渲染文本核心方法
        private void RenderTextCore(LayoutData layout)
        {
            layout.DoLayout();                                                                                                                                                          //执行布局
            this.CurrentTextPreferredRect = layout.OutTextBounds;                                                                                                                       //保存文本区域矩形
            bool      needRotate = !(Single.IsNaN(this.m_TextRotateAngle) || this.m_TextRotateAngle % 360f == 0f);                                                                      //是否需要旋转
            Rectangle textRect   = needRotate ? RenderEngine.RotateRect(this.m_Graphics, this.CurrentTextPreferredRect, this.m_TextRotateAngle, false) : this.CurrentTextPreferredRect; //新绘图区域(如果旋转则为旋转后的区域)

            //绘制阴影或描边
            if (this.m_TextShadowShapeStyle != 0)
            {
                using (new SmoothingModeGraphics(this.m_Graphics, SmoothingMode.AntiAlias))
                {
                    using (GraphicsPath textPath = new GraphicsPath())
                    {
                        //添加文本
                        textPath.AddString(this.m_Text, this.m_Font.FontFamily, (int)this.m_Font.Style, this.m_Graphics.DpiY * this.m_Font.SizeInPoints / 72f, textRect, layout.CurrentStringFormat);

                        //绘制阴影和阴影描边
                        if (((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0) || ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f))
                        {
                            using (GraphicsPath shadowPath = textPath.Clone() as GraphicsPath)
                            {
                                using (Matrix shadowMatrix = new Matrix(1, 0, 0, 1, this.m_TextShadowMatrixOffset.X, this.m_TextShadowMatrixOffset.Y))
                                {
                                    shadowPath.Transform(shadowMatrix);
                                }

                                //绘制阴影
                                if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.Shadow) != 0)
                                {
                                    using (Brush shadowBrush = new SolidBrush(this.m_TextShadowColor))
                                    {
                                        this.m_Graphics.FillPath(shadowBrush, shadowPath);
                                    }
                                }
                                //阴影描边
                                if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfShadow) != 0 && this.m_TextShapeOfShadowWidth > 0f)
                                {
                                    using (Pen shapeOfShadowPen = new Pen(this.m_TextShapeOfShadowColor, this.m_TextShapeOfShadowWidth))
                                    {
                                        this.m_Graphics.DrawPath(shapeOfShadowPen, shadowPath);
                                    }
                                }
                            }
                        }

                        //绘制文本
                        using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
                        {
                            this.m_Graphics.FillPath(textBrush, textPath);
                        }

                        //文本描边
                        if ((this.m_TextShadowShapeStyle & ShadowShapeStyle.ShapeOfText) != 0 && this.m_TextShapeOfTextWidth > 0f)
                        {
                            using (Pen shapeOfTextPen = new Pen(this.m_TextShapeOfTextColor, this.m_TextShapeOfTextWidth))
                            {
                                this.m_Graphics.DrawPath(shapeOfTextPen, textPath);
                            }
                        }
                    }
                }
            }
            else
            {
                using (new TextRenderingHintGraphics(this.m_Graphics, this.m_TextRenderingHint))
                {
                    using (Brush textBrush = new SolidBrush(this.CurrentForeColor))
                    {
                        this.m_Graphics.DrawString(this.m_Text, this.m_Font, textBrush, textRect, layout.CurrentStringFormat);
                    }
                }
            }

            //恢复旋转
            if (needRotate)
            {
                this.m_Graphics.ResetTransform();
            }
        }