public override void CreateFont(string faceName, int height, Guid uniqueID)
        {
            Font newFont = new GDIFont(faceName, height, uniqueID);

            BufferChunk chunk = new BufferChunk(1024);

            chunk += GDI32.EMR_EXTCREATEFONTINDIRECTW;

            chunk += faceName.Length;
            chunk += faceName;
            chunk += (int)height;
            chunk += (byte)1; // newFont.fLogFont.lfCharSet;
            chunk += (byte)0; // newFont.fLogFont.lfClipPrecision;
            chunk += (int)0;  // newFont.fLogFont.lfEscapement;
            chunk += (byte)0; // newFont.fLogFont.lfItalic;
            chunk += (int)0;  // newFont.fLogFont.lfOrientation;
            chunk += (byte)0; // newFont.fLogFont.lfOutPrecision;
            chunk += (byte)0; // newFont.fLogFont.lfPitchAndFamily;
            chunk += (byte)0; // newFont.fLogFont.lfQuality;
            chunk += (byte)0; // newFont.fLogFont.lfStrikeOut;
            chunk += (byte)0; // newFont.fLogFont.lfUnderline;
            chunk += (int)0;  // newFont.fLogFont.lfWeight;
            chunk += (int)0;  // newFont.fLogFont.lfWidth;

            // Write the GUID
            chunk += (int)16; // For size of the following array
            chunk += newFont.UniqueID.ToByteArray();

            PackCommand(chunk);
        }
        private GDIFont GetFont(Font font)
        {
            if (!_Fonts.TryGetValue(GetFontKey(font), out GDIFont gf))
            {
                gf = new GDIFont(font.Name, font.Size, font.Bold, font.Italic, font.Underline, false);
                _Fonts[GetFontKey(font)] = gf;
            }

            return(gf);
        }
Example #3
0
        private GDIFont GetFont(Font font)
        {
            GDIFont gf = (GDIFont)_Fonts[GetFontKey(font)];

            if (gf == null)
            {
                gf = new GDIFont(font.Name, font.Size, font.Bold, font.Italic, font.Underline, false);
                _Fonts[GetFontKey(font)] = gf;
            }
            return(gf);
        }
Example #4
0
        public static void Pack(BufferChunk chunk, GDIFont aFont)
        {
            chunk += GDI32.EMR_EXTCREATEFONTINDIRECTW;

            chunk += aFont.FaceName.Length;
            chunk += aFont.FaceName;
            chunk += (int)aFont.Height;
            chunk += (byte)1; // newFont.fLogFont.lfCharSet;
            chunk += (byte)0; // newFont.fLogFont.lfClipPrecision;
            chunk += (int)0;  // newFont.fLogFont.lfEscapement;
            chunk += (byte)0; // newFont.fLogFont.lfItalic;
            chunk += (int)0;  // newFont.fLogFont.lfOrientation;
            chunk += (byte)0; // newFont.fLogFont.lfOutPrecision;
            chunk += (byte)0; // newFont.fLogFont.lfPitchAndFamily;
            chunk += (byte)0; // newFont.fLogFont.lfQuality;
            chunk += (byte)0; // newFont.fLogFont.lfStrikeOut;
            chunk += (byte)0; // newFont.fLogFont.lfUnderline;
            chunk += (int)0;  // newFont.fLogFont.lfWeight;
            chunk += (int)0;  // newFont.fLogFont.lfWidth;

            // Write the GUID
            Pack(chunk, aFont.UniqueID);
        }
Example #5
0
        public GDIBrush OutlineBrush;         //background brush

        #region IDisposable Members

        public void Dispose()
        {
            if (BackBuffer != null)
            {
                BackBuffer.Dispose();
                BackBuffer = null;
            }
            if (SelectionBuffer != null)
            {
                SelectionBuffer.Dispose();
                SelectionBuffer = null;
            }
            if (StringBuffer != null)
            {
                StringBuffer.Dispose();
                StringBuffer = null;
            }
            if (FontNormal != null)
            {
                FontNormal.Dispose();
                FontNormal = null;
            }
            if (FontBold != null)
            {
                FontBold.Dispose();
                FontBold = null;
            }
            if (FontItalic != null)
            {
                FontItalic.Dispose();
                FontItalic = null;
            }
            if (FontBoldItalic != null)
            {
                FontBoldItalic.Dispose();
                FontBoldItalic = null;
            }
            if (FontUnderline != null)
            {
                FontUnderline.Dispose();
                FontUnderline = null;
            }
            if (FontBoldUnderline != null)
            {
                FontBoldUnderline.Dispose();
                FontBoldUnderline = null;
            }
            if (FontItalicUnderline != null)
            {
                FontItalicUnderline.Dispose();
                FontItalicUnderline = null;
            }
            if (FontBoldItalicUnderline != null)
            {
                FontBoldItalicUnderline.Dispose();
                FontBoldItalicUnderline = null;
            }
            if (GutterMarginBrush != null)
            {
                GutterMarginBrush.Dispose();
                GutterMarginBrush = null;
            }
            if (GutterMarginBrush != null)
            {
                GutterMarginBrush.Dispose();
                GutterMarginBrush = null;
            }
            if (LineNumberMarginBrush != null)
            {
                LineNumberMarginBrush.Dispose();
                LineNumberMarginBrush = null;
            }
            if (LineNumberMarginBorderBrush != null)
            {
                LineNumberMarginBorderBrush.Dispose();
                LineNumberMarginBorderBrush = null;
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
                BackgroundBrush = null;
            }
            if (HighLightLineBrush != null)
            {
                HighLightLineBrush.Dispose();
                HighLightLineBrush = null;
            }
            if (OutlineBrush != null)
            {
                OutlineBrush.Dispose();
                OutlineBrush = null;
            }
        }
Example #6
0
        private void RedrawBuffer()
        {
            if (_bufferSurface != null)
            {
                _bufferSurface.Dispose();
            }

            _bufferSurface = new GDISurface(this.Width, this.Height, this, true);

            using (Graphics gfx = Graphics.FromHdc(_bufferSurface.hDC))
            {
                //try
                //{
                _bufferSurface.FontTransparent = true;

                if (this.BackgroundImage != null)
                {
                    gfx.DrawImage(this.BackgroundImage, 0, 0, this.Width, this.Height);
                }
                else
                {
                    _bufferSurface.Clear(this.BackColor);
                }
                int x = LabelMargin;
                int y = LabelMargin;
                for (int i = vScroll.Value; i < _Rows.Count; i++)
                {
                    FormatLabelRow r = (FormatLabelRow)_Rows[i];
                    x         = LabelMargin;
                    r.Visible = true;
                    r.Top     = y;
                    if (r.RenderSeparator)
                    {
                        Color c1 = Color.FromArgb(120, 0, 0, 0);
                        Brush b1 = new SolidBrush(c1);
                        gfx.FillRectangle(b1, 0, y, this.Width, 1);

                        Color c2 = Color.FromArgb(120, 255, 255, 255);
                        Brush b2 = new SolidBrush(c2);
                        gfx.FillRectangle(b2, 0, y + 1, this.Width, 1);

                        b1.Dispose();
                        b2.Dispose();


                        //bbuff.DrawLine (this.ForeColor,new Point (0,y),new Point (this.Width,y));
                    }

                    foreach (FormatLabelWord w in r.Words)
                    {
                        int ypos = r.Height - w.Height + y;

                        if (w.Image != null)
                        {
                            gfx.DrawImage(w.Image, x, y);
                            //bbuff.FillRect (Color.Red ,x,ypos,w.Width ,w.Height);
                        }
                        else
                        {
                            GDIFont gf = null;
                            if (w.Element.Link != null)
                            {
                                Font f = null;

                                FontStyle fs = w.Element.Font.Style;
                                if (w.Element.Link == _ActiveElement)
                                {
                                    if (_Link_UnderLine_Hover)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }
                                else
                                {
                                    if (_Link_UnderLine)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }

                                gf = GetFont(f);
                            }
                            else
                            {
                                gf = GetFont(w.Element.Font);
                            }

                            _bufferSurface.Font = gf;
                            if (w.Element.Effect != TextEffect.None)
                            {
                                _bufferSurface.TextForeColor = w.Element.EffectColor;

                                if (w.Element.Effect == TextEffect.Outline)
                                {
                                    for (int xx = -1; xx <= 1; xx++)
                                    {
                                        for (int yy = -1; yy <= 1; yy++)
                                        {
                                            _bufferSurface.DrawTabbedString(w.Text, x + xx, ypos + yy, 0, 0);
                                        }
                                    }
                                }
                                else if (w.Element.Effect != TextEffect.None)
                                {
                                    _bufferSurface.DrawTabbedString(w.Text, x + 1, ypos + 1, 0, 0);
                                }
                            }


                            if (w.Element.Link != null)
                            {
                                if (w.Element.Link == _ActiveElement)
                                {
                                    _bufferSurface.TextForeColor = Link_Color_Hover;
                                }
                                else
                                {
                                    _bufferSurface.TextForeColor = Link_Color;
                                }
                            }
                            else
                            {
                                _bufferSurface.TextForeColor = w.Element.ForeColor;
                            }

                            _bufferSurface.TextBackColor = w.Element.BackColor;
                            _bufferSurface.DrawTabbedString(w.Text, x, ypos, 0, 0);
                        }

                        w.ScreenArea = new Rectangle(new Point(x, ypos), w.ScreenArea.Size);
                        //w.ScreenArea.Y = ypos;
                        x += w.Width;
                    }

                    y += r.Height + r.BottomPadd;
                    if (y > this.Height)
                    {
                        break;
                    }
                }

                //}
                //catch (Exception x)
                //{
                //    Console.WriteLine(x.Message);
                //}
            }
        }
Example #7
0
        private void LB_DrawItem(object sender, DrawItemEventArgs e)
        {
            bool selected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            if (e.Index == -1)
                return;

            object li = FontListbox.Items[e.Index];
            string text = li.ToString();

            Brush fg = selected ? SystemBrushes.HighlightText : SystemBrushes.WindowText;

            if (selected)
            {
                const int ofs = 37;
                e.Graphics.FillRectangle(SystemBrushes.Window,
                                         new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs, FontListbox.ItemHeight));
                e.Graphics.FillRectangle(SystemBrushes.Highlight,
                                         new Rectangle(ofs + 1, e.Bounds.Top + 1, e.Bounds.Width - ofs - 2,
                                                       FontListbox.ItemHeight - 2));
                ControlPaint.DrawFocusRectangle(e.Graphics,
                                                new Rectangle(ofs, e.Bounds.Top, e.Bounds.Width - ofs,
                                                              FontListbox.ItemHeight));
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Window, 0, e.Bounds.Top, e.Bounds.Width, FontListbox.ItemHeight);
            }

            e.Graphics.DrawString(text, e.Font, fg, 38, e.Bounds.Top + 4);

            e.Graphics.SetClip(new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));

            e.Graphics.FillRectangle(SystemBrushes.Highlight,
                                     new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));

            IntPtr hdc = e.Graphics.GetHdc();
            var gf = new GDIFont(text, 9);
            int a = 0;
            IntPtr res = NativeMethods.SelectObject(hdc, gf.hFont);
            NativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(SystemColors.Window));
            NativeMethods.SetBkMode(hdc, 0);
            NativeMethods.TabbedTextOut(hdc, 3, e.Bounds.Top + 5, "abc", 3, 0, ref a, 0);
            NativeMethods.SelectObject(hdc, res);
            gf.Dispose();
            e.Graphics.ReleaseHdc(hdc);
            e.Graphics.DrawRectangle(Pens.Black, new Rectangle(1, e.Bounds.Top + 2, 34, FontListbox.ItemHeight - 4));
            e.Graphics.ResetClip();
        }
Example #8
0
        public override void PaintValue(PaintValueEventArgs e)
        {
            string text = e.Value.ToString();
            var bp = new Bitmap(e.Bounds.Width, e.Bounds.Height);
            Graphics g = Graphics.FromImage(bp);

            g.FillRectangle(SystemBrushes.Highlight, e.Bounds);

            IntPtr hdc = g.GetHdc();
            var gf = new GDIFont(text, 9);
            int a = 0;
            IntPtr res = NativeMethods.SelectObject(hdc, gf.hFont);
            NativeMethods.SetTextColor(hdc, ColorTranslator.ToWin32(SystemColors.Window));
            NativeMethods.SetBkMode(hdc, 0);
            NativeMethods.TabbedTextOut(hdc, 1, 1, "abc", 3, 0, ref a, 0);
            NativeMethods.SelectObject(hdc, res);
            gf.Dispose();
            g.ReleaseHdc(hdc);
            e.Graphics.DrawImage(bp, e.Bounds.Left, e.Bounds.Top);

            //	e.Graphics.DrawString ("abc",new Font (text,10f),SystemBrushes.Window,3,0);
        }
Example #9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.SetAutoSize();
            //base.OnPaint (e);

            if (_HasImageError)
            {
                CreateAll();
            }

            GDISurface bbuff = new GDISurface(this.Width, this.Height, this, true);
            Graphics   g     = Graphics.FromHdc(bbuff.hDC);

            try
            {
                bbuff.FontTransparent = true;

                if (this.BackgroundImage != null)
                {
                    g.DrawImage(this.BackgroundImage, 0, 0, this.Width, this.Height);
                }
                else
                {
                    bbuff.Clear(this.BackColor);
                }
                int x = Margin;
                int y = Margin;
                for (int i = vScroll.Value; i < _Rows.Count; i++)
                {
                    Row r = (Row)_Rows[i];
                    x         = Margin;
                    r.Visible = true;
                    r.Top     = y;
                    if (r.RenderSeparator)
                    {
                        Color c1 = Color.FromArgb(120, 0, 0, 0);
                        Brush b1 = new SolidBrush(c1);
                        g.FillRectangle(b1, 0, y, this.Width, 1);

                        Color c2 = Color.FromArgb(120, 255, 255, 255);
                        Brush b2 = new SolidBrush(c2);
                        g.FillRectangle(b2, 0, y + 1, this.Width, 1);

                        b1.Dispose();
                        b2.Dispose();


                        //bbuff.DrawLine (this.ForeColor,new Point (0,y),new Point (this.Width,y));
                    }

                    foreach (Word w in r.Words)
                    {
                        int ypos = r.Height - w.Height + y;

                        if (w.Image != null)
                        {
                            g.DrawImage(w.Image, x, y);
                            //bbuff.FillRect (Color.Red ,x,ypos,w.Width ,w.Height);
                        }
                        else
                        {
                            GDIFont gf = null;
                            if (w.Element.Link != null)
                            {
                                Font f = null;

                                FontStyle fs = w.Element.Font.Style;
                                if (w.Element.Link == _ActiveElement)
                                {
                                    if (_Link_UnderLine_Hover)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }
                                else
                                {
                                    if (_Link_UnderLine)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }

                                gf = GetFont(f);
                            }
                            else
                            {
                                gf = GetFont(w.Element.Font);
                            }

                            bbuff.Font = gf;
                            if (w.Element.Effect != TextEffect.None)
                            {
                                bbuff.TextForeColor = w.Element.EffectColor;

                                if (w.Element.Effect == TextEffect.Outline)
                                {
                                    for (int xx = -1; xx <= 1; xx++)
                                    {
                                        for (int yy = -1; yy <= 1; yy++)
                                        {
                                            bbuff.DrawTabbedString(w.Text, x + xx, ypos + yy, 0, 0);
                                        }
                                    }
                                }
                                else if (w.Element.Effect != TextEffect.None)
                                {
                                    bbuff.DrawTabbedString(w.Text, x + 1, ypos + 1, 0, 0);
                                }
                            }


                            if (w.Element.Link != null)
                            {
                                if (w.Element.Link == _ActiveElement)
                                {
                                    bbuff.TextForeColor = Link_Color_Hover;
                                }
                                else
                                {
                                    bbuff.TextForeColor = Link_Color;
                                }
                            }
                            else
                            {
                                bbuff.TextForeColor = w.Element.ForeColor;
                            }

                            bbuff.TextBackColor = w.Element.BackColor;
                            bbuff.DrawTabbedString(w.Text, x, ypos, 0, 0);
                        }

                        w.ScreenArea.X = x;
                        w.ScreenArea.Y = ypos;
                        x += w.Width;
                    }

                    y += r.Height + r.BottomPadd;
                    if (y > this.Height)
                    {
                        break;
                    }
                }
            }
            catch (Exception x)
            {
                Console.WriteLine(x.Message);
            }
            bbuff.RenderToControl(0, 0);
            bbuff.Dispose();
            g.Dispose();
        }
Example #10
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);
                }
            }
        }
Example #11
0
        public GDISurface StringBuffer; //backbuffer surface

        #endregion Fields

        #region Methods

        public void Dispose()
        {
            if (BackBuffer != null)
            {
                BackBuffer.Dispose();
                BackBuffer = null;
            }
            if (SelectionBuffer != null)
            {
                SelectionBuffer.Dispose();
                SelectionBuffer = null;
            }
            if (StringBuffer != null)
            {
                StringBuffer.Dispose();
                StringBuffer = null;
            }
            if (FontNormal != null)
            {
                FontNormal.Dispose();
                FontNormal = null;
            }
            if (FontBold != null)
            {
                FontBold.Dispose();
                FontBold = null;
            }
            if (FontItalic != null)
            {
                FontItalic.Dispose();
                FontItalic = null;
            }
            if (FontBoldItalic != null)
            {
                FontBoldItalic.Dispose();
                FontBoldItalic = null;
            }
            if (FontUnderline != null)
            {
                FontUnderline.Dispose();
                FontUnderline = null;
            }
            if (FontBoldUnderline != null)
            {
                FontBoldUnderline.Dispose();
                FontBoldUnderline = null;
            }
            if (FontItalicUnderline != null)
            {
                FontItalicUnderline.Dispose();
                FontItalicUnderline = null;
            }
            if (FontBoldItalicUnderline != null)
            {
                FontBoldItalicUnderline.Dispose();
                FontBoldItalicUnderline = null;
            }
            if (GutterMarginBrush != null)
            {
                GutterMarginBrush.Dispose();
                GutterMarginBrush = null;
            }
            if (GutterMarginBrush != null)
            {
                GutterMarginBrush.Dispose();
                GutterMarginBrush = null;
            }
            if (LineNumberMarginBrush != null)
            {
                LineNumberMarginBrush.Dispose();
                LineNumberMarginBrush = null;
            }
            if (LineNumberMarginBorderBrush != null)
            {
                LineNumberMarginBorderBrush.Dispose();
                LineNumberMarginBorderBrush = null;
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
                BackgroundBrush = null;
            }
            if (HighLightLineBrush != null)
            {
                HighLightLineBrush.Dispose();
                HighLightLineBrush = null;
            }
            if (OutlineBrush != null)
            {
                OutlineBrush.Dispose();
                OutlineBrush = null;
            }
        }