Exemplo n.º 1
0
 public int ToPixel(float documentLength)
 {
     return((int)GraphicsUnitConvert.Convert(
                documentLength,
                this.MainDocument.DocumentGraphicsUnit,
                GraphicsUnit.Pixel));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 移动光标到新的光标区域
        /// </summary>
        /// <param name="vLeft">在视图中光标区域的左端位置</param>
        /// <param name="vTop">在视图中光标区域的顶端位置</param>
        /// <param name="vWidth">光标区域宽度</param>
        /// <param name="vHeight">光标区域高度</param>
        /// <returns>移动光标是否造成滚动</returns>
        public bool MoveCaretTo(
            int vLeft,
            int vTop,
            int vWidth,
            int vHeight)
        {
            //return false;

            if (this.IsUpdating)
            {
                return(false);
            }
            if (this.ForceShowCaret == false &&
                this.Focused == false)
            {
                if (this.CaretCreated)
                {
                    this.Caret.Hide();
                }
                //this.ScrollToView( vLeft , vTop , vWidth , vHeight );
                return(false);
            }

            int height = GraphicsUnitConvert.Convert(
                vHeight,
                this.GraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            if (vWidth > 0 && vHeight > 0)
            {
                bolCaretCreated = this.Caret.Create(0, vWidth, height);
                if (this.CaretCreated)
                {
                    if (bolMoveCaretWithScroll)
                    {
                        this.ScrollToView(vLeft, vTop, vWidth, vHeight);
                    }
                    System.Drawing.Point p = this.ViewPointToClient(vLeft, vTop);
                    myCaret.SetPos(p.X, p.Y);
                    myCaret.Show();
                    Win32Imm imm = new Win32Imm(this);
                    if (imm.IsImmOpen())
                    {
                        imm.SetImmPos(p);
                    }
                    myCaretBounds = new System.Drawing.Rectangle(
                        p.X,
                        p.Y,
                        vWidth,
                        height);
                    if (this.MoveCaretWithScroll)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 3
0
 private void dlgParagraphFormatcs_Load(object sender, EventArgs e)
 {
     if (_CommandParameter == null)
     {
         _CommandParameter = new ParagraphFormatCommandParameter();
     }
     this.txtLeftIndent.Value          = ( decimal )(GraphicsUnitConvert.ToTwips(_CommandParameter.LeftIndent, GraphicsUnit.Document) / 210.0);
     txtFirstLineIndent.Value          = (decimal)(GraphicsUnitConvert.Convert(_CommandParameter.FirstLineIndent, GraphicsUnit.Document, GraphicsUnit.Millimeter) / 10.0);
     txtSpacingBefore.Value            = (decimal)(GraphicsUnitConvert.ToTwips(_CommandParameter.SpacingBefore, GraphicsUnit.Document) / 312.0);
     txtSpacingAfter.Value             = (decimal)(GraphicsUnitConvert.ToTwips(_CommandParameter.SpacingAfter, GraphicsUnit.Document) / 312.0);
     cboLineSpacingStyle.SelectedIndex = (int)_CommandParameter.LineSpacingStyle;
     cboLineSpacingStyle_SelectedIndexChanged(null, null);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 输出对象到RTF文档中
        /// </summary>
        /// <param name="writer">RTF文档书写器</param>
        public override void WriteRTF(DCSoft.CSharpWriter.RTF.RTFContentWriter writer)
        {
            System.Drawing.SizeF size = new System.Drawing.SizeF(this.Width, this.Height);
            size = GraphicsUnitConvert.Convert(
                size,
                this.OwnerDocument.DocumentGraphicsUnit,
                GraphicsUnit.Pixel);

            writer.WriteImage(
                this.Image.Value,
                (int)size.Width,
                (int)size.Height,
                this.Image.ImageData,
                this.RuntimeStyle);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 创建预览用的图片
 /// </summary>
 /// <returns>创建的图片对象</returns>
 public override Image CreateContentImage()
 {
     if (this.Image.HasContent)
     {
         System.Drawing.SizeF size = new System.Drawing.SizeF(this.Width, this.Height);
         size = GraphicsUnitConvert.Convert(
             size,
             this.OwnerDocument.DocumentGraphicsUnit,
             GraphicsUnit.Pixel);
         return(this.Image.GetThumbnailImage((int)size.Width, (int)size.Height).Value);
     }
     else
     {
         return(base.CreateContentImage());
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 根据图片内容更新元素的大小
 /// </summary>
 public void UpdateSize()
 {
     if (this.Image.HasContent)
     {
         System.Drawing.Size size = myImage.Size;
         //base.WidthHeightRate = ( double )size.Width / ( double ) size.Height ;
         size = GraphicsUnitConvert.Convert(
             myImage.Value.Size,
             System.Drawing.GraphicsUnit.Pixel,
             this.OwnerDocument.DocumentGraphicsUnit);
         UpdateWidthHeightRate();
         this.EditorSize = new SizeF(size.Width, size.Height);
     }
     else
     {
         this.EditorSize = new SizeF(100, 100);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 创建包含元素内容的图片对象
        /// </summary>
        /// <returns>图片对象</returns>
        public virtual System.Drawing.Image CreateContentImage()
        {
            if (this.Width <= 0 || this.Height <= 0)
            {
                return(null);
            }
            System.Drawing.SizeF size = new System.Drawing.SizeF(this.Width, this.Height);
            size = GraphicsUnitConvert.Convert(
                size,
                this.OwnerDocument.DocumentGraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
                (int)Math.Ceiling(size.Width),
                (int)Math.Ceiling(size.Height));
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                g.Clear(Color.White);
                g.PageUnit = this.OwnerDocument.DocumentGraphicsUnit;
                RectangleF bounds = this.AbsBounds;
                g.TranslateTransform(-bounds.Left, -bounds.Top);
                DocumentPaintEventArgs args = new DocumentPaintEventArgs(g, Rectangle.Empty);
                args.Document          = this.OwnerDocument;
                args.PageClipRectangle = Rectangle.Ceiling(bounds);
                args.Render            = this.OwnerDocument.Render;
                args.RenderStyle       = DocumentRenderStyle.Bitmap;
                args.Style             = this.RuntimeStyle;
                args.Type           = this.DocumentContentElement.ContentPartyStyle;
                args.ViewBounds     = Rectangle.Ceiling(bounds);
                args.ActiveMode     = true;
                args.Bounds         = bounds;
                args.Element        = this;
                args.ForCreateImage = true;

                this.Draw(args);
            }//using
            return(bmp);
        }
Exemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            _CommandParameter.FirstLineIndent  = (float )GraphicsUnitConvert.Convert((double)txtFirstLineIndent.Value * 10.0, GraphicsUnit.Millimeter, GraphicsUnit.Document);
            _CommandParameter.LeftIndent       = (float )GraphicsUnitConvert.FromTwips((double)txtLeftIndent.Value * 210, GraphicsUnit.Document);
            _CommandParameter.SpacingBefore    = (float)GraphicsUnitConvert.FromTwips((double)txtSpacingBefore.Value * 312, GraphicsUnit.Document);
            _CommandParameter.SpacingAfter     = (float)GraphicsUnitConvert.FromTwips((double)txtSpacingAfter.Value * 312, GraphicsUnit.Document);
            _CommandParameter.LineSpacingStyle = (LineSpacingStyle)cboLineSpacingStyle.SelectedIndex;
            switch (_CommandParameter.LineSpacingStyle)
            {
            case LineSpacingStyle.SpaceSpecify:
                _CommandParameter.LineSpacing = (float)(GraphicsUnitConvert.FromTwips((double )txtLineSpacing.Value * 20, GraphicsUnit.Document));
                break;

            case LineSpacingStyle.SpaceMultiple:
                _CommandParameter.LineSpacing = (float)txtLineSpacing.Value;
                break;

            default:
                _CommandParameter.LineSpacing = 0;
                break;
            }
            this.Close();
        }
Exemplo n.º 9
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="UseMargin">是否启用页边距</param>
        public override void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            //XPageSettings pageSettings = myPage.PageSettings;
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = (int)myPage.ViewLeftMargin;
                TopMargin    = (int)myPage.ViewTopMargin;
                RightMargin  = (int)myPage.ViewRightMargin;
                BottomMargin = (int)myPage.ViewBottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);
            IntPtr          hdc = g.GetHdc();
            DeviceCapsClass dcc = new DeviceCapsClass(hdc);

            g.ReleaseHdc();

            DomDocument   document = (DomDocument)this.Document;
            XPageSettings ps       = myPage.PageSettings;

            if (ps == null)
            {
                ps = document.PageSettings;
            }
            g.PageUnit = document.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.PageHeadText != null)
            {
                // 绘制标题文本
                g.DrawString(
                    this.PageHeadText,
                    System.Windows.Forms.Control.DefaultFont,
                    System.Drawing.Brushes.Red,
                    20,
                    20,
                    System.Drawing.StringFormat.GenericDefault);
            }
            float printableAreaOffsetX = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.X / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);
            float printableAreaOffsetY = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.Y / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);

            float headerHeight    = Math.Max(ps.ViewHeaderHeight, document.Header.Height);
            int   headerHeightFix = 0;

            if (document.Header.Height > ps.ViewHeaderHeight - 10)
            {
                headerHeightFix = ( int )(document.Header.Height - (ps.ViewHeaderHeight - 10));
            }
            if (this.DrawHead)
            {
                // 绘制页眉
                g.ResetTransform();
                g.ResetClip();
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)headerHeight);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    ps.ViewHeaderDistance - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Header);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
                g.ResetClip();
                g.ResetTransform();
            }

            // 绘制页面正文
            ClipRect = new System.Drawing.Rectangle(
                0,
                myPage.Top,
                myPage.Width,
                myPage.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    TopMargin - myPage.Top + headerHeightFix - printableAreaOffsetY);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

                //				System.Drawing.RectangleF rect2 = g.ClipBounds ;
                //				if( rect.Top < rect2.Top )
                //				{
                //					float dy = rect2.Top - rect.Top ;
                //					rect.Y = rect.Y - dy * 2 ;
                //					rect.Height = rect.Height + dy * 4 ;
                //				}
                //				g.SetClip( rect );

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Body);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);

                //myDocument.DrawDocument( g , ClipRect );
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.DrawFooter)
            {
                // 绘制页脚
                g.ResetClip();
                g.ResetTransform();
                int   documentHeight = myPage.DocumentHeight;
                float footerHeight   = Math.Max(document.Footer.Height, ps.ViewFooterHeight);
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)footerHeight);
                int dy = 0;

                dy = (int)(myPage.ViewPaperHeight
                           - ps.ViewFooterDistance - document.Footer.Height);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    dy - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Footer);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
Exemplo n.º 10
0
 public void SetHeight(double vHeight, System.Drawing.GraphicsUnit unit)
 {
     intHeight = (int)(GraphicsUnitConvert.Convert(vHeight, unit, System.Drawing.GraphicsUnit.Document) / 3.0);
 }
Exemplo n.º 11
0
 public double GetHeight(System.Drawing.GraphicsUnit unit)
 {
     return((int)GraphicsUnitConvert.Convert(intHeight * 3, System.Drawing.GraphicsUnit.Document, unit));
 }
Exemplo n.º 12
0
 public void SetWidth(double vWidth, System.Drawing.GraphicsUnit unit)
 {
     intWidth = (int)(GraphicsUnitConvert.Convert(vWidth, unit, System.Drawing.GraphicsUnit.Document) / 3.0);
 }
Exemplo n.º 13
0
 public double GetWidth(System.Drawing.GraphicsUnit unit)
 {
     return(GraphicsUnitConvert.Convert(intWidth * 3, System.Drawing.GraphicsUnit.Document, unit));
 }
Exemplo n.º 14
0
        private void ParseStyleItem(DocumentContentStyle cstyle, string styleName, string styleValue)
        {
            switch (styleName)
            {
            case "width":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.WidthValue = v;
                }
            }
            break;

            case "height":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.HeightValue = v;
                }
            }
            break;

            case "background":
            {
                // 解析背景设置
                string[] items = SplitItems(styleValue);
                if (items != null)
                {
                    foreach (string item in items)
                    {
                        Color  c   = Color.Empty;
                        string url = GetAttributeUrl(item);
                        if (url != null)
                        {
                            url = this.HtmlDocument.GetAbsoluteURL(url);
                            XImageValue img = new XImageValue();
                            if (img.Load(url) <= 0)
                            {
                                cstyle.BackgroundImage = img;
                            }
                        }
                        else if (TryParseColor(item, out c))
                        {
                            cstyle.BackgroundColor = c;
                        }
                        else if (string.Equals(item, "repeat", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.BackgroundRepeat = true;
                        }
                        else if (string.Equals(item, "no-repeat", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.BackgroundRepeat = false;
                        }
                    }        //foreach
                }
            }
            break;

            case "background-color":
            {
                Color c = Color.Empty;
                if (TryParseColor(styleValue, out c))
                {
                    cstyle.BackgroundColor = c;
                }
            }
            break;

            case "background-repeat":
            {
                string text = Trim(styleValue);
                if (string.Equals(text, "repeat", StringComparison.CurrentCultureIgnoreCase))
                {
                    cstyle.BackgroundRepeat = true;
                }
                else if (string.Equals(text, "no-repeat", StringComparison.CurrentCultureIgnoreCase))
                {
                    cstyle.BackgroundRepeat = false;
                }
                else
                {
                    cstyle.BackgroundRepeat = true;
                }
            }
            break;

            case "border":
            {
                // 解析边框设置
                string[] items = SplitItems(styleValue);
                if (items != null)
                {
                    foreach (string item in items)
                    {
                        DashStyle ds = DashStyle.Custom;
                        Color     c  = Color.Empty;
                        float     w  = 0;
                        if (TryParseBorderStyle(item, out ds))
                        {
                            cstyle.BorderStyle = ds;
                            if (ds == DashStyle.Custom)
                            {
                                cstyle.BorderStyle = DashStyle.Solid;
                                cstyle.BorderWidth = 0;
                                break;
                            }
                        }
                        else if (TryParseColor(item, out c))
                        {
                            cstyle.BorderColor = c;
                        }
                        else if (TryParseBorderWidth(item, ref w))
                        {
                            cstyle.BorderWidth = w;
                        }
                    }        //foreach
                }
            }
            break;

            case "border-color":
            {
                Color c = Color.Empty;
                if (TryParseColor(styleValue, out c))
                {
                    cstyle.BorderColor = c;
                }
            }
            break;

            case "border-width":
            {
                float w = 0;
                if (TryParseBorderWidth(styleValue, ref w))
                {
                    cstyle.BorderWidth = w;
                }
            }
            break;

            case "border-style":
            {
                DashStyle bs = DashStyle.Solid;
                if (TryParseBorderStyle(styleValue, out bs))
                {
                    cstyle.BorderStyle = bs;
                    if (bs == DashStyle.Custom)
                    {
                        cstyle.BorderStyle = DashStyle.Solid;
                        cstyle.BorderWidth = 0;
                    }
                }
            }
            break;

            case "color":
            {
                Color c = Color.Empty;
                if (TryParseColor(styleValue, out c))
                {
                    cstyle.Color = c;
                }
            }
            break;

            case "font":
            {
                string[] items = SplitItems(styleValue);
                if (items != null)
                {
                    for (int iCount = 0; iCount < items.Length; iCount++)
                    {
                        string item = items[iCount];
                        float  size = 0;
                        if (string.Equals(item, "italic", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.Italic = true;
                        }
                        else if (string.Equals(item, "oblique", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.Italic = true;
                        }
                        else if (string.Equals(item, "bold", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.Bold = true;
                        }
                        else if (string.Equals(item, "bolder", StringComparison.CurrentCultureIgnoreCase))
                        {
                            cstyle.Bold = true;
                        }
                        else if (TryParseLength(item, out size))
                        {
                            cstyle.FontSize = GraphicsUnitConvert.Convert(size, this.DomDocument.DocumentGraphicsUnit, GraphicsUnit.Point);
                        }
                        else
                        {
                            string name2 = GetFontName(item);
                            if (name2 != null)
                            {
                                cstyle.FontName = name2;
                            }
                        }
                    }
                }
            }
            break;

            case "font-family":
            {
                string fn = GetFontName(styleValue);
                if (fn != null)
                {
                    cstyle.FontName = fn;
                }
            }
            break;

            case "font-size":
            {
                float size = 0;
                if (TryParseLength(styleValue, out size))
                {
                    cstyle.FontSize = GraphicsUnitConvert.Convert(
                        size,
                        this.DomDocument.DocumentGraphicsUnit,
                        GraphicsUnit.Point);
                }
            }
            break;

            case "font-style":
            {
                if (Contains(styleValue, "italic") ||
                    Contains(styleValue, "oblique"))
                {
                    cstyle.Italic = true;
                }
            }
            break;

            case "font-weight":
                if (Contains(styleValue, "bold"))
                {
                    cstyle.Bold = true;
                }
                else if (Contains(styleValue, "700"))
                {
                    cstyle.Bold = true;
                }
                break;

            case "line-height":
                break;

            case "text-align":
                if (Contains(styleValue, "left"))
                {
                    cstyle.Align = DocumentContentAlignment.Left;
                }
                else if (Contains(styleValue, "right"))
                {
                    cstyle.Align = DocumentContentAlignment.Right;
                }
                else if (Contains(styleValue, "center"))
                {
                    cstyle.Align = DocumentContentAlignment.Center;
                }
                else if (Contains(styleValue, "justify"))
                {
                    cstyle.Align = DocumentContentAlignment.Justify;
                }
                break;

            case "text-indent":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.FirstLineIndent = v;
                }
            }
            break;

            case "padding":
            {
                // 读取内边距
                float[] values = ParseLengths(styleValue);
                if (values != null)
                {
                    if (values.Length >= 4)
                    {
                        cstyle.PaddingTop    = values[0];
                        cstyle.PaddingRight  = values[1];
                        cstyle.PaddingBottom = values[2];
                        cstyle.PaddingLeft   = values[3];
                    }
                    else if (values.Length == 1)
                    {
                        cstyle.PaddingLeft   = values[0];
                        cstyle.PaddingTop    = values[0];
                        cstyle.PaddingRight  = values[0];
                        cstyle.PaddingBottom = values[0];
                    }
                    else if (values.Length == 2)
                    {
                        cstyle.PaddingTop    = values[0];
                        cstyle.PaddingBottom = values[0];
                        cstyle.PaddingLeft   = values[1];
                        cstyle.PaddingRight  = values[1];
                    }
                    else if (values.Length == 3)
                    {
                        cstyle.PaddingTop    = values[0];
                        cstyle.PaddingRight  = values[1];
                        cstyle.PaddingLeft   = values[1];
                        cstyle.PaddingBottom = values[2];
                    }
                }
            }
            break;

            case "padding-left":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.PaddingLeft = v;
                }
            }
            break;

            case "padding-top":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.PaddingTop = v;
                }
            }
            break;

            case "padding-right":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.PaddingRight = v;
                }
            }
            break;

            case "padding-bottom":
            {
                float v = 0;
                if (TryParseLength(styleValue, out v))
                {
                    cstyle.PaddingBottom = v;
                }
            }
            break;
            }//switch
        }
Exemplo n.º 15
0
        /// <summary>
        /// 重新计算对象大小
        /// </summary>
        /// <param name="g">图形绘制对象</param>
        protected virtual void RefreshSize(DomCharElement chr, System.Drawing.Graphics g)
        {
            DocumentViewOptions opt = this.Document.Options.ViewOptions;

            if (myMeasureFormat == null)
            {
                myMeasureFormat = new System.Drawing.StringFormat(
                    System.Drawing.StringFormat.GenericTypographic);
                myMeasureFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox
                                              | System.Drawing.StringFormatFlags.MeasureTrailingSpaces
                                              | StringFormatFlags.NoClip;
            }
            DomDocument document = chr.OwnerDocument;

            if (_EnableCharSizeBuffer)
            {
                if (chr.CharValue != '\t')
                {
                    if (charSizes != null)
                    {
                        if (charSizes.ContainsKey(chr.StyleIndex))
                        {
                            Dictionary <char, SizeF> sizes = charSizes[chr.StyleIndex];
                            if (sizes.ContainsKey(chr.CharValue))
                            {
                                // 从缓存区中获得字母大小
                                SizeF bsize = sizes[chr.CharValue];
                                chr.Width       = bsize.Width;
                                chr.Height      = bsize.Height;
                                chr._FontHeight = chr.RuntimeStyle.Font.GetHeight(g);
                                return;
                            }
                        }
                    }
                } //if
            }     //if

            DocumentContentStyle rs = chr.RuntimeStyle;

            System.Drawing.SizeF size = System.Drawing.SizeF.Empty;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
            //this.UseGDIFontSize = true;
            if (opt.RichTextBoxCompatibility)
            {
                // 使用GDI模式计算字符大小
                string  key  = rs.FontName + "|" + rs.FontSize + "|" + rs.FontStyle;
                GDIFont font = null;
                if (gdiFonts.ContainsKey(key))
                {
                    font = gdiFonts[key];
                }
                else
                {
                    font = new GDIFont(
                        rs.FontName,
                        //(int)( rs.FontSize *  1.3837 * 3 ),
                        (int)(GraphicsUnitConvert.Convert(
                                  rs.FontSize,
                                  GraphicsUnit.Point,
                                  GraphicsUnit.Document)),
                        rs.Bold,
                        rs.Italic,
                        rs.Underline,
                        rs.Strikeout);
                    gdiFonts[key] = font;
                }

                Size[] sizes = font.MeasureCharactersSize(g, chr.CharValue.ToString());
                size.Width  = sizes[0].Width;
                size.Height = sizes[0].Height;
                if (chr.CharValue == ' ')
                {
                    if (rs.FontName == "Times New Roman")
                    {
                        size.Width = size.Width * 1.28f;
                    }
                }
            }
            else
            {
                if (chr.CharValue == ' ')
                {
                    size = g.MeasureString(
                        " ",
                        rs.Font.Value,
                        10000,
                        System.Drawing.StringFormat.GenericDefault);
                    size.Width = size.Width * 0.57f;
                }
                else if (chr.CharValue == '\t')
                {
                }
                else
                {
                    size = g.MeasureString(
                        chr.CharValue.ToString(),
                        rs.Font.Value,
                        10000,
                        myMeasureFormat);
                    size.Width = size.Width;
                }
            }
            chr.Width       = size.Width;
            chr.Height      = size.Height + 1;
            chr._FontHeight = rs.Font.GetHeight(g);
            chr.Height      = chr._FontHeight;// size.Height;
            if (rs.Superscript)
            {
                chr.Height = chr.Height * 1.2f;
            }
            if (rs.Superscript || rs.Subscript)
            {
                chr.Width = chr.Width * 0.6f;
            }
            if (_EnableCharSizeBuffer)
            {
                if (charSizes != null)
                {
                    Dictionary <char, SizeF> sizes2 = null;
                    if (charSizes.ContainsKey(chr.StyleIndex))
                    {
                        sizes2 = charSizes[chr.StyleIndex];
                    }
                    else
                    {
                        sizes2 = new Dictionary <char, SizeF>();
                        charSizes[chr.StyleIndex] = sizes2;
                    }
                    sizes2[chr.CharValue] = new SizeF(chr.Width, chr.Height);
                }
            }
        }