Example #1
0
        static GraficadorGDI()
        {
            Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            bmp.SetResolution(10000, 10000);
            _GraficadorConsultas = new GraficadorGDI(Graphics.FromImage(bmp));
            _GraficadorConsultas.CambiarResolucion(10000, 10000);
            _GraficadorConsultas.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            FormatoMedicion             = new StringFormat(StringFormat.GenericTypographic);
            FormatoMedicion.FormatFlags = 0;
            FormatoMedicion.FormatFlags = StringFormatFlags.FitBlackBox |
                                          StringFormatFlags.MeasureTrailingSpaces;
            //FormatoMedicion.FormatFlags|=StringFormatFlags.

            FormatoMedicion.FormatFlags  |= StringFormatFlags.MeasureTrailingSpaces;
            FormatoMedicion.Alignment     = StringAlignment.Near;
            FormatoMedicion.LineAlignment = StringAlignment.Near;

            FormatoPresentacion = (StringFormat)FormatoMedicion.Clone();
            familias            = new Dictionary <string, FontFamily>();
            foreach (FontFamily f in FontFamily.Families)
            {
                familias.Add(f.Name, f);
            }
        }
Example #2
0
        public void CheckCaption(Graphics g, Font f, StringFormat s, Rectangle rect)
        {
            StringFormat newS = null;
            SizeF        area = SizeF.Empty;;
            Size         size;

            if (!_captionChecked)
            {
                try
                {
                    newS        = (StringFormat)s.Clone();
                    area.Width  = StringFormatFlags.NoWrap == (StringFormatFlags.NoWrap & s.FormatFlags) ? Int32.MaxValue : rect.Width;
                    area.Height = Int32.MaxValue;

                    newS.Trimming = StringTrimming.None;

                    size = g.MeasureString(_caption, f, area, newS).ToSize();

                    _captionChecked = true;

                    if (size.Width > rect.Width || size.Height > rect.Height)
                    {
                        _forceCaptionToolTip = true;
                    }
                    else
                    {
                        _forceCaptionToolTip = false;
                    }
                }
                catch
                {
                }
            }
        }
        public void Clone_Complex()
        {
            using (StringFormat sf = new StringFormat()) {
                CharacterRange[] ranges = new CharacterRange [2];
                ranges[0].First  = 1;
                ranges[0].Length = 2;
                ranges[1].First  = 3;
                ranges[1].Length = 4;
                sf.SetMeasurableCharacterRanges(ranges);

                float[] stops = new float [2];
                stops [0] = 6.0f;
                stops [1] = 7.0f;
                sf.SetTabStops(5.0f, stops);

                using (StringFormat clone = (StringFormat)sf.Clone()) {
                    CheckDefaults(clone);

                    float   first;
                    float[] cloned_stops = clone.GetTabStops(out first);
                    Assert.AreEqual(5.0f, first, "first");
                    Assert.AreEqual(6.0f, cloned_stops[0], "cloned_stops[0]");
                    Assert.AreEqual(7.0f, cloned_stops[1], "cloned_stops[1]");
                }
            }
        }
 /// <summary>
 /// Draws the specified text string at the specified location with the specified Brush and Font objects using the formatting properties of the specified StringFormat object.
 /// </summary>
 /// <param name="s">String to draw.</param>
 /// <param name="font">Font object that defines the text format of the string.</param>
 /// <param name="brush">Brush object that determines the color and texture of the drawn text.</param>
 /// <param name="point">PointF structure that specifies the upper-left corner of the drawn text.</param>
 /// <param name="format">StringFormat object that specifies formatting properties, such as line spacing and alignment, that are applied to the drawn text.</param>
 internal void DrawString(
     string s,
     Font font,
     Brush brush,
     PointF point,
     StringFormat format
     )
 {
     if (IsRightToLeft)
     {
         using (StringFormat fmt = (StringFormat)format.Clone())
         {
             fmt.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
             if (fmt.Alignment == StringAlignment.Far)
             {
                 fmt.Alignment = StringAlignment.Near;
             }
             else if (fmt.Alignment == StringAlignment.Near)
             {
                 fmt.Alignment = StringAlignment.Far;
             }
             RenderingObject.DrawString(s, font, brush, point, fmt);
         }
     }
     else
     {
         RenderingObject.DrawString(s, font, brush, point, format);
     }
 }
Example #5
0
        public void Clone_Disposed_ThrowsArgumentException()
        {
            var format = new StringFormat();

            format.Dispose();
            Assert.Throws <ArgumentException>(null, () => format.Clone());
        }
Example #6
0
        static int GetTotalRenderWidth(Brush brush, StringFormat format, IEnumerable <DisplayText> displayTexts)
        {
            var   result = 0;
            Image image  = new Bitmap(1000, 1000);

            using var g    = Graphics.FromImage(image);
            using var copy = (StringFormat)format.Clone();
            var rect = new Rectangle(0, 0, 1000, 1000);

            foreach (var displayText in displayTexts)
            {
                if (!string.IsNullOrWhiteSpace(displayText.Text))
                {
                    copy.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, displayText.Text.Length) });
                    var regions = g.MeasureCharacterRanges(displayText.Text, displayText.Font, rect, copy);
                    rect.X += displayText.XAxisAdjustment;
                    g.DrawString(displayText.Text, displayText.Font, brush, rect, format);
                    var bounds = regions[0].GetBounds(g);
                    var width  = (int)bounds.Width;
                    result      = rect.X + width;
                    rect.X     += width;
                    rect.Width -= width;
                }
            }
            return(result);
        }
 public void Clone()
 {
     using (StringFormat sf = new StringFormat()) {
         using (StringFormat clone = (StringFormat)sf.Clone()) {
             CheckDefaults(clone);
         }
     }
 }
Example #8
0
        public object Clone()
        {
            StateCanvas p = this.MemberwiseClone() as StateCanvas;

            p._pen          = _pen.Clone() as Pen;
            p._brush        = _brush.Clone() as Brush;
            p._stringFormat = _stringFormat.Clone() as StringFormat;
            return(p);
        }
 void DrawVString(GraphicsCache cache, string text, Font font, Brush foreBrush, StringFormat format, Rectangle bounds, int angle,
                  System.Drawing.Text.HotkeyPrefix?hotkeyDrawModeOverride)
 {
     using (StringFormat strFormat = format.Clone() as StringFormat) {
         if (hotkeyDrawModeOverride.HasValue)
         {
             strFormat.HotkeyPrefix = hotkeyDrawModeOverride.Value;
         }
         cache.DrawVString(text, font, foreBrush, bounds, strFormat, angle);
     }
 }
Example #10
0
 static void DrawString(Graphics g, Brush brush, ref Rectangle rect, StringFormat format, DisplayText displayText)
 {
     if (!string.IsNullOrWhiteSpace(displayText.Text))
     {
         using var copy = (StringFormat)format.Clone();
         copy.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, displayText.Text.Length) });
         var regions = g.MeasureCharacterRanges(displayText.Text, displayText.Font, rect, copy);
         rect.X += displayText.XAxisAdjustment;
         g.DrawString(displayText.Text, displayText.Font, brush, rect, format);
         var bounds = regions[0].GetBounds(g);
         var width  = (int)bounds.Width;
         rect.X     += width;
         rect.Width -= width;
     }
 }
Example #11
0
        //Measures the characters provided into the control character ranges
        private void MeasureCharactersImplementation(Graphics graphics)
        {
            //Set the character rectangles defined by the character ranges
            string text = Text;

            Region[]         regions   = null;
            CharacterRange[] ranges    = new CharacterRange[1];
            StringFormat     format    = (StringFormat)StringFormat.Clone();
            RectangleF       scaleRect = DisplayRectangle;
            float            scale     = mZoom / 100;

            if (mZoom != 100)
            {
                scaleRect = new RectangleF(0, 0, DisplayRectangle.Width / scale, DisplayRectangle.Height / scale);
                graphics.ScaleTransform(scale, scale);
            }

            //Initialise
            if (text == "")
            {
                text = ".";
            }
            mCharacterRectangles = new RectangleF[text.Length + 1];
            RectangleF rect;

            //Measure into rectangles starting at position 1 in the array
            try
            {
                for (int i = 0; i <= text.Length - 1; i++)
                {
                    ranges[0].First  = i;
                    ranges[0].Length = 1;
                    format.SetMeasurableCharacterRanges(ranges);
                    regions = graphics.MeasureCharacterRanges(text, Font, scaleRect, format);
                    rect    = regions[0].GetBounds(graphics);
                    mCharacterRectangles[i + 1] = rect;
                }

                mCharacterRectangles[0]       = mCharacterRectangles[1];
                mCharacterRectangles[0].Width = 1;
                mCharacterRectangles[0].X    -= 1;
            }
            catch (Exception objEx)
            {
                System.Diagnostics.Debug.WriteLine("Error measuring characters" + objEx.ToString());
            }
        }
Example #12
0
        public void Clone_Valid_Success()
        {
            var original = new StringFormat(StringFormatFlags.NoClip, EnglishLanguageCode);
            var format   = (StringFormat)original.Clone();

            Assert.Equal(StringAlignment.Near, format.Alignment);
            Assert.Equal(0, format.DigitSubstitutionLanguage);
            Assert.Equal(StringDigitSubstitute.User, format.DigitSubstitutionMethod);
            Assert.Equal(StringFormatFlags.NoClip, format.FormatFlags);
            Assert.Equal(HotkeyPrefix.None, format.HotkeyPrefix);
            Assert.Equal(StringAlignment.Near, format.LineAlignment);
            Assert.Equal(StringTrimming.Character, format.Trimming);

            // The new format is a clone.
            original.FormatFlags = StringFormatFlags.NoFontFallback;
            Assert.Equal(StringFormatFlags.NoClip, format.FormatFlags);
        }
Example #13
0
File: SVG.cs Project: stuart2w/SAW
        public override void DrawString(string text, Font font, Fill fill, PointF start, StringFormat format = null)
        {
            StringFormat create;

            if (format == null)
            {
                create = new StringFormat();
            }
            else
            {
                create = (StringFormat)format.Clone();
            }
            // Presumably the alignment starts from the point, and does not centre on the point
            create.LineAlignment = StringAlignment.Near;
            create.Alignment     = StringAlignment.Near;
            DrawString(text, font, fill, new RectangleF(start.X, start.Y, 10000, 10000), create);
        }
Example #14
0
        public static void DrawTextWaveLine(Graphics g, Pen pen, string s, Font font, Brush brush, RectangleF r, StringFormat sf)
        {
            Size         txtSize = TextRenderer.MeasureText(s, font);
            PointF       start   = new PointF();
            PointF       end     = new PointF();
            StringFormat sfCopy  = (StringFormat)sf.Clone();

            CharacterRange[] characterRanges = { new CharacterRange(0, s.Length) };
            sfCopy.SetMeasurableCharacterRanges(characterRanges);

            Region[]   rr   = g.MeasureCharacterRanges(s, font, r, sfCopy);
            RectangleF txtR = rr[0].GetBounds(g);

            start.Y = end.Y = txtR.Y + txtR.Height;
            start.X = txtR.X;
            end.X   = txtR.X + txtR.Width;
            g.DrawString(s, font, brush, r, sf);
            DrawWave(g, pen, start, end);
        }
Example #15
0
        public override void Draw(Graphics g)
        {
            if (rectChk == Rectangle.Empty)
            {
                rectChk  = new Rectangle(this.Rectangle.X, this.Rectangle.Y, this.Rectangle.Height, this.Rectangle.Height);
                rectText = new Rectangle(this.Rectangle.X + this.rectChk.Width, this.Rectangle.Y, this.Rectangle.Width - this.rectChk.Width, this.Rectangle.Height);
            }
            if (isChecked)
            {
                g.RendererBackground(isEnter ? Resources.chk_4 : Resources.chk_3, rectChk, 5);
            }
            else
            {
                g.RendererBackground(isEnter ? Resources.chk_1 : Resources.chk_2, rectChk, 5);
            }
            var sf = StringFormat.Clone() as StringFormat;

            sf.Alignment = StringAlignment.Near;
            g.DrawString(this.Text, this.Font, Brushes.Black, rectText, sf);
        }
Example #16
0
 /// <summary>
 /// Draws the specified text string in the specified rectangle with the specified Brush and Font objects using the formatting properties of the specified StringFormat object.
 /// </summary>
 /// <param name="s">String to draw.</param>
 /// <param name="font">Font object that defines the text format of the string.</param>
 /// <param name="brush">Brush object that determines the color and texture of the drawn text.</param>
 /// <param name="layoutRectangle">RectangleF structure that specifies the location of the drawn text.</param>
 /// <param name="format">StringFormat object that specifies formatting properties, such as line spacing and alignment, that are applied to the drawn text.</param>
 internal void DrawString(
     string s,
     Font font,
     Brush brush,
     RectangleF layoutRectangle,
     StringFormat format
     )
 {
     using (StringFormat fmt = (StringFormat)format.Clone())
     {
         if (IsRightToLeft)
         {
             fmt.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
         }
         if (!IsTextClipped && (fmt.FormatFlags & StringFormatFlags.NoClip) != StringFormatFlags.NoClip)
         {
             fmt.FormatFlags |= StringFormatFlags.NoClip;
         }
         RenderingObject.DrawString(s, font, brush, layoutRectangle, fmt);
     }
 }
Example #17
0
 public void CreateSFormat()
 {
     using (StringFormat sfTemplate = StringFormat.GenericTypographic) //GenericTypographic returns a NEW instance. It has to be disposed.
     {
         FSFormat = (StringFormat)sfTemplate.Clone();                  //Even when sfTemplate is a new instance, changing directly on it will change the standard generic typographic :(
         try
         {
             FSFormat.Alignment     = StringAlignment.Near; //this should be set, but just in case someone changed it.
             FSFormat.Trimming      = StringTrimming.None;
             FSFormat.FormatFlags  |= StringFormatFlags.NoClip | StringFormatFlags.MeasureTrailingSpaces;
             FSFormat.FormatFlags  &= ~StringFormatFlags.LineLimit;
             FSFormat.LineAlignment = StringAlignment.Far;
         }
         catch
         {
             FSFormat.Dispose();
             FSFormat = null;
             throw;
         }
     }
 }
Example #18
0
        private static real DoFullGetFont0Width(TFlxFont Fx)
        {
#if (MONOTOUCH)
            using (Font MyFont = ExcelFont.CreateFont(Fx.Name, (Fx.Size20 / 20F), ExcelFont.ConvertFontStyle(Fx)))
            {
                using (MonoTouch.Foundation.NSString o = new MonoTouch.Foundation.NSString("0"))
                {
                    return(o.StringSize(MyFont).Width);
                }
            }
#else
            using (Font MyFont = ExcelFont.CreateFont(Fx.Name, (Fx.Size20 / 20F), ExcelFont.ConvertFontStyle(Fx)))
            {
                using (Bitmap bm = new Bitmap(1, 1))
                {
                    using (Graphics gr = Graphics.FromImage(bm))
                        using (StringFormat sfTemplate = StringFormat.GenericTypographic)                 //GenericTypographic returns a NEW instance. It has to be disposed.
                        {
                            using (StringFormat sf = (StringFormat)sfTemplate.Clone())                    //Even when sfTemplate is a new instance, changing directly on it will change the standard generic typographic :(
                            {
                                //sf.SetMeasurableCharacterRanges was causing a deadlock here.
                                //DONT DO!!

                                /*CharacterRange[] r = {new CharacterRange(0,1)};
                                 * sf.SetMeasurableCharacterRanges(r);*/

                                sf.Alignment     = StringAlignment.Near; //this should be set, but just in case someone changed it.
                                sf.LineAlignment = StringAlignment.Far;  //this should be set, but just in case someone changed it.
                                sf.FormatFlags   = 0;
                                gr.PageUnit      = GraphicsUnit.Pixel;
                                SizeF sz = gr.MeasureString("0", MyFont, 1000, sf);
                                return((real)Math.Round(sz.Width));
                            }
                        }
                }
            }
#endif
        }
        public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, Font font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
        {
            MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];

            Font localfont1 = (Font)font.Clone();
            Font localfont2 = new Font(font.FontFamily, font.Size * 2 / 3, font.Style, GraphicsUnit.World);

            StringFormat localstrfmt = (StringFormat)strfmt.Clone();

            string[] firstp = new string[items.Length];
            string[] expos  = new string[items.Length];

            float maxexposize = 0;

            for (int i = 0; i < items.Length; ++i)
            {
                string firstpart, exponent;
                if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
                {
                    SplitInFirstPartAndExponent((double)items[i], out firstpart, out exponent);
                }
                else
                {
                    firstpart = items[i].ToString(); exponent = string.Empty;
                }
                firstp[i]   = firstpart;
                expos[i]    = exponent;
                maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, localfont2, new PointF(0, 0), strfmt).Width);
            }


            for (int i = 0; i < items.Length; ++i)
            {
                litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, firstp[i], expos[i], maxexposize);
            }

            return(litems);
        }
Example #20
0
        private void DrawString(Graphics g, Brush brush, ref Rectangle rect, out Size used,
                                StringFormat format, string text, Font font)
        {
            using (StringFormat copy = (StringFormat)format.Clone())
            {
                copy.SetMeasurableCharacterRanges(new CharacterRange[]
                {
                    new CharacterRange(0, text.Length)
                });
                Region[] regions = g.MeasureCharacterRanges(text, font, rect, copy);

                g.DrawString(text, font, brush, rect, format);

                int height = (int)(regions[0].GetBounds(g).Height);
                int width  = (int)(regions[0].GetBounds(g).Width);

                // First just one line...
                used = new Size(width, height);

                rect.X     += width;
                rect.Width -= width;
            }
        }
Example #21
0
        public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
        {
            var litems = new MeasuredLabelItem[items.Length];

            FontX localfont1 = font;
            FontX localfont2 = font.WithSize(font.Size * 2 / 3);

            var localstrfmt = (StringFormat)strfmt.Clone();

            string[] firstp = new string[items.Length];
            string[] middel = new string[items.Length];
            string[] expos  = new string[items.Length];
            double[] mants  = new double[items.Length];

            float maxexposize  = 0;
            int   firstpartmin = int.MaxValue;
            int   firstpartmax = int.MinValue;

            for (int i = 0; i < items.Length; ++i)
            {
                string firstpart, exponent;
                if (items[i].IsType(Altaxo.Data.AltaxoVariant.Content.VDouble))
                {
                    SplitInFirstPartAndExponent(items[i], out firstpart, out mants[i], out middel[i], out exponent);
                    if (exponent.Length > 0)
                    {
                        firstpartmin = Math.Min(firstpartmin, firstpart.Length);
                        firstpartmax = Math.Max(firstpartmax, firstpart.Length);
                    }
                }
                else
                {
                    firstpart = items[i].ToString();
                    middel[i] = string.Empty;
                    exponent  = string.Empty;
                }
                firstp[i]   = firstpart;
                expos[i]    = exponent;
                maxexposize = Math.Max(maxexposize, g.MeasureString(exponent, GdiFontManager.ToGdi(localfont2), new PointF(0, 0), strfmt).Width);
            }

            if (firstpartmax > 0 && firstpartmax > firstpartmin) // then we must use special measures to equilibrate the mantissa
            {
                firstp = NumericLabelFormattingAuto.FormatItems(mants);
            }

            for (int i = 0; i < items.Length; ++i)
            {
                string mid = string.Empty;
                if (!string.IsNullOrEmpty(expos[i]))
                {
                    if (string.IsNullOrEmpty(firstp[i]))
                    {
                        mid = "10";
                    }
                    else
                    {
                        mid = "\u00D710";
                    }
                }
                litems[i] = new MeasuredLabelItem(g, localfont1, localfont2, localstrfmt, _prefix + firstp[i] + mid, expos[i], _suffix, maxexposize);
            }

            return(litems);
        }
Example #22
0
        private void PaintItem(int index, Graphics graphics)
        {
            int left = 1;
            // draw the tree lines
            bool lastLine = index == entries.Length - 1;

            if (!lastLine)
            {
                lastLine = entries[index + 1].IndentLevel < entries[index].IndentLevel;
            }
            bool firstLine = index == 0;

            if (!firstLine)
            {
                firstLine = entries[index - 1].IndentLevel == 0;
            }
            Rectangle area = new Rectangle(0, index * lineHeight + AutoScrollPosition.Y, ClientSize.Width, lineHeight);

            graphics.FillRectangle(SystemBrushes.Window, area);
            graphics.DrawRectangle(SystemPens.ControlLight, area);
            Rectangle indent = area;

            indent.Width = entries[index].IndentLevel * buttonWidth;
            graphics.FillRectangle(SystemBrushes.ControlLight, indent);
            left = entries[index].IndentLevel * buttonWidth + buttonWidth + 1; // left side of the label text
            if (entries[index].Flags.HasFlag(PropertyEntryType.HasSubEntries))
            {                                                                  // draw a square with a "+" or "-" sign in front of the label
                int ym = (area.Top + area.Bottom) / 2;
                int xm = entries[index].IndentLevel * buttonWidth + buttonWidth / 2 + 1;
                int s2 = square / 2;
                int s3 = square / 3;
                graphics.DrawRectangle(SystemPens.ControlText, xm - s2, ym - s2, square, square);
                graphics.DrawLine(SystemPens.ControlText, xm - s3, ym, xm + s3, ym); // the horizontal "minus" line
                if (!entries[index].IsOpen)
                {
                    graphics.DrawLine(SystemPens.ControlText, xm, ym - s3, xm, ym + s3);                         // the vertical "plus" line
                }
            }
            bool showValue = (entries[index].Value != null) && !entries[index].Flags.HasFlag(PropertyEntryType.Checkable);

            if (showValue)
            {
                graphics.DrawLine(SystemPens.ControlLight, middle, area.Top, middle, area.Bottom);            // the vertical divider line
            }
            Rectangle labelRect;

            if (showValue)
            {
                labelRect = new Rectangle(left, area.Top, middle - left, area.Height);
            }
            else
            {
                labelRect = new Rectangle(left, area.Top, area.Right - left, area.Height);
            }
            if (graphics.MeasureString(entries[index].Label, Font).Width > labelRect.Width)
            {
                labelNeedsExtension[index] = true;
            }
            if (index == selected)
            {
                graphics.FillRectangle(SystemBrushes.Highlight, labelRect);
                if (entries[index].Flags.HasFlag(PropertyEntryType.Bold))
                {
                    graphics.DrawString(entries[index].Label, new Font(Font, FontStyle.Bold), SystemBrushes.HighlightText, labelRect, stringFormat);
                }
                else
                {
                    graphics.DrawString(entries[index].Label, Font, SystemBrushes.HighlightText, labelRect, stringFormat);
                }
            }
            else if (entries[index].Flags.HasFlag(PropertyEntryType.Seperator))
            {
                int ym = (labelRect.Top + labelRect.Bottom) / 2;
                labelRect.Width -= buttonWidth;
                graphics.DrawLine(SystemPens.ControlLight, labelRect.Left, ym, labelRect.Right, ym); // the horizontal separator line
                StringFormat seperatorFormat = stringFormat.Clone() as StringFormat;
                seperatorFormat.Alignment = StringAlignment.Center;
                graphics.DrawString(entries[index].Label, Font, SystemBrushes.ControlText, labelRect, seperatorFormat);
            }
            else
            {
                if (entries[index].Flags.HasFlag(PropertyEntryType.Highlight))
                {
                    graphics.DrawString(entries[index].Label, Font, new SolidBrush(Color.Red), labelRect, stringFormat);
                }
                else if (entries[index].Flags.HasFlag(PropertyEntryType.Bold))
                {
                    graphics.DrawString(entries[index].Label, new Font(Font, FontStyle.Bold), SystemBrushes.ControlText, labelRect, stringFormat);
                }
                else
                {
                    graphics.DrawString(entries[index].Label, Font, SystemBrushes.ControlText, labelRect, stringFormat);
                }
            }
            if (showValue)
            {
                int right = area.Right;
                if (entries[index].Flags.HasFlag(PropertyEntryType.ContextMenu) || entries[index].Flags.HasFlag(PropertyEntryType.DropDown))
                {
                    right -= buttonWidth;
                }
                Rectangle valueRect = new Rectangle(middle, area.Top, right - middle, area.Height);
                DrawString(graphics, entries[index].Value, Font, SystemBrushes.ControlText, valueRect, false);
            }
            if (entries[index].Flags.HasFlag(PropertyEntryType.ContextMenu))
            {   // draw three vertical dots (maybe we could also use the Unicode "⁞" character
                Rectangle buttonRect = new Rectangle(area.Right - buttonWidth, area.Top, buttonWidth, area.Height);
                ControlPaint.DrawButton(graphics, buttonRect, ButtonState.Flat);
                int d  = Math.Max(area.Height / 9, 2);
                int dy = (area.Height - 5 * d) / 2;
                int xm = (int)(area.Right - buttonWidth / 2.0);
                for (int i = 0; i < 3; i++)
                {
                    graphics.FillRectangle(SystemBrushes.ControlText, xm - d / 2, buttonRect.Top + dy, d, d);
                    dy += 2 * d;
                }
            }
            else if (entries[index].Flags.HasFlag(PropertyEntryType.DropDown))
            {   // draw a combo button
                Rectangle buttonRect = new Rectangle(area.Right - buttonWidth, area.Top, buttonWidth, area.Height);
                ControlPaint.DrawComboButton(graphics, buttonRect, ButtonState.Flat);
                //int numLines = (int)(0.25 * buttonWidth);
                //int xm = (int)(area.Right - buttonWidth / 2.0);
                //int ym = (int)(area.Top + 0.4 * area.Height);
                //graphics.DrawLine(SystemPens.ControlText, xm - numLines, ym - 3, xm + numLines, ym - 3); // the horizontal above line
                //for (int i = 0; i <= numLines; i++)
                //{
                //    int w2 = numLines - i;
                //    if (w2 == 0) graphics.FillRectangle(SystemBrushes.ControlText, xm, ym + i, 1, 1); // a single pixel
                //    else graphics.DrawLine(SystemPens.ControlText, xm - w2, ym + i, xm + w2, ym + i); // the horizontal "minus" line
                //}
            }
            else if (entries[index].Flags.HasFlag(PropertyEntryType.CancelButton) || entries[index].Flags.HasFlag(PropertyEntryType.OKButton))
            {
                Font         fontForSymbols = Font; // new Font(FontFamily.GenericSansSerif, Font.Size, FontStyle.Bold);
                StringFormat sf             = new StringFormat(StringFormatFlags.LineLimit);
                sf.SetMeasurableCharacterRanges(new CharacterRange[] { new CharacterRange(0, 1) });
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Near;
                System.Drawing.Text.TextRenderingHint txtrendr = graphics.TextRenderingHint;
                graphics.TextContrast      = 0;
                graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                if (entries[index].Flags.HasFlag(PropertyEntryType.CancelButton))
                {
                    Rectangle buttonRect = new Rectangle(area.Right - area.Height, area.Top, area.Height, area.Height); // square rect at the right end
                    ControlPaint.DrawButton(graphics, buttonRect, ButtonState.Flat);
                    Region[]   rgn  = graphics.MeasureCharacterRanges("✖", fontForSymbols, buttonRect, sf);
                    RectangleF bnds = rgn[0].GetBounds(graphics);
                    SizeF      sz   = graphics.MeasureString("✖", fontForSymbols);
                    PointF     p    = new PointF(buttonRect.Left + (buttonRect.Width - bnds.Width) / 2.0f, buttonRect.Top + (buttonRect.Height - bnds.Height) / 2.0f);
                    graphics.DrawString("✖", fontForSymbols, SystemBrushes.ControlText, p, sf); // ✓✔✗✘✕✖⋮
                }
                if (entries[index].Flags.HasFlag(PropertyEntryType.OKButton))
                {
                    Rectangle buttonRect = new Rectangle(area.Right - 2 * area.Height, area.Top, area.Height, area.Height); // square rect at the right end
                    ControlPaint.DrawButton(graphics, buttonRect, ButtonState.Flat);
                    Region[]   rgn  = graphics.MeasureCharacterRanges("✔", fontForSymbols, buttonRect, sf);
                    RectangleF bnds = rgn[0].GetBounds(graphics);
                    SizeF      sz   = graphics.MeasureString("✔", fontForSymbols);
                    PointF     p    = new PointF(buttonRect.Left + (buttonRect.Width - bnds.Width) / 2.0f, buttonRect.Top + (buttonRect.Height - bnds.Height) / 2.0f);
                    graphics.DrawString("✔", fontForSymbols, SystemBrushes.ControlText, p, sf); // ✓✔✗✘✕✖⋮⁞
                }
                graphics.TextRenderingHint = txtrendr;
            }
            if (entries[index].Flags.HasFlag(PropertyEntryType.Checkable))
            {
                Rectangle cbrect = new Rectangle(entries[index].IndentLevel * buttonWidth, area.Top, area.Height, area.Height);
                cbrect.Inflate(-1, -1);
                ButtonState bs = ButtonState.Flat;
                if (entries[index].Value == "1")
                {
                    bs |= ButtonState.Checked;
                }
                ControlPaint.DrawCheckBox(graphics, cbrect, bs);
            }
        }
        private static void HighlightString(Graphics g, PageText dtext, RectangleF r, Font f, StringFormat sf, CanvasProperties cp)
        {
            if (cp.HighlightText == null || cp.HighlightText.Length == 0)
            {
                return;         // nothing to highlight
            }
            bool bhighlightItem = dtext == cp.HighlightItem ||
                                  (cp.HighlightItem != null && dtext.HtmlParent == cp.HighlightItem);

            if (!(cp.HighlightAll || bhighlightItem))
            {
                return;         // not highlighting all and not on current highlight item
            }
            string hlt  = cp.HighlightCaseSensitive ? cp.HighlightText : cp.HighlightText.ToLower();
            string text = cp.HighlightCaseSensitive ? dtext.Text : dtext.Text.ToLower();

            if (text.IndexOf(hlt) < 0)
            {
                return;         // string not in text
            }
            StringFormat sf2 = null;

            try
            {
                // Create a CharacterRange array with the highlight location and length
                // Handle multiple occurences of text
                List <CharacterRange> rangel = new List <CharacterRange>();
                int loc  = text.IndexOf(hlt);
                int hlen = hlt.Length;
                int len  = text.Length;
                while (loc >= 0)
                {
                    rangel.Add(new CharacterRange(loc, hlen));
                    if (loc + hlen < len)  // out of range of text
                    {
                        loc = text.IndexOf(hlt, loc + hlen);
                    }
                    else
                    {
                        loc = -1;
                    }
                }

                if (rangel.Count <= 0)      // we should have gotten one; but
                {
                    return;
                }

                CharacterRange[] ranges = rangel.ToArray();

                // Construct a new StringFormat object.
                sf2 = sf.Clone() as StringFormat;

                // Set the ranges on the StringFormat object.
                sf2.SetMeasurableCharacterRanges(ranges);

                // Get the Regions to highlight by calling the
                // MeasureCharacterRanges method.
                if (r.Width <= 0 || r.Height <= 0)
                {
                    SizeF ts = g.MeasureString(dtext.Text, f);
                    r.Height = ts.Height;
                    r.Width  = ts.Width;
                }
                Region[] charRegion = g.MeasureCharacterRanges(dtext.Text, f, r, sf2);

                // Fill in the region using a semi-transparent color to highlight
                foreach (Region rg in charRegion)
                {
                    Color hl = bhighlightItem ? cp.HighlightItemColor : cp.HighlightAllColor;
                    g.FillRegion(new SolidBrush(Color.FromArgb(50, hl)), rg);
                }
            }
            catch { }   // if highlighting fails we don't care; need to continue
            finally
            {
                if (sf2 != null)
                {
                    sf2.Dispose();
                }
            }
        }
Example #24
0
 public virtual StringFormat GetStringFormat()
 {
     return((StringFormat)StringFormat.Clone());
 }