Example #1
0
 public Font(System.Drawing.Font font, Color color, Color backdrop)
     : this()
 {
     SystemFont = (System.Drawing.Font)font.Clone();
     Color      = color;
     Backdrop   = backdrop;
 }
Example #2
0
 public Entry(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
 {
     this.s               = s;
     this.font            = (Font)font.Clone();      // An owner could possibly call Dispose()!
     this.brush           = (Brush)brush.Clone();
     this.layoutRectangle = layoutRectangle;
     this.format          = (StringFormat)format.Clone();
 }
Example #3
0
		public static ABC GetCharWidthABC(char ch, Font font, System.Drawing.Graphics gr)
		{
			ABC[] _temp = new ABC[1];
			IntPtr hDC = gr.GetHdc();
			Font ft = (Font)font.Clone();
			IntPtr hFt = ft.ToHfont();
			SelectObject(hDC, hFt);
			GetCharABCWidthsW(hDC, ch, ch, _temp);
			DeleteObject(hFt);
			gr.ReleaseHdc();

			return _temp[0];
		}
Example #4
0
        /// <summary>
        /// Measured a couple of items and prepares them for being drawn.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="font">Font used.</param>
        /// <param name="strfmt">String format used.</param>
        /// <param name="items">Array of items to be drawn.</param>
        /// <returns>An array of <see cref="IMeasuredLabelItem" /> that can be used to determine the size of each item and to draw it.</returns>
        public virtual IMeasuredLabelItem[] GetMeasuredItems(Graphics g, System.Drawing.Font font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
        {
            string[] titems = FormatItems(items);

            MeasuredLabelItem[] litems = new MeasuredLabelItem[titems.Length];

            Font         localfont   = (Font)font.Clone();
            StringFormat localstrfmt = (StringFormat)strfmt.Clone();

            for (int i = 0; i < titems.Length; ++i)
            {
                litems[i] = new MeasuredLabelItem(g, localfont, localstrfmt, titems[i]);
            }

            return(litems);
        }
Example #5
0
		public void TestClone()
		{		
			Font f = new Font("Arial",12);	
			Font f2 = (Font) f.Clone();
			
			Assert.AreEqual (f.Bold, f2.Bold, "Bold");
			Assert.AreEqual (f.FontFamily, f2.FontFamily, "FontFamily");
			Assert.AreEqual (f.GdiCharSet, f2.GdiCharSet, "GdiCharSet");
			Assert.AreEqual (f.GdiVerticalFont, f2.GdiVerticalFont, "GdiVerticalFont");
			Assert.AreEqual (f.Height, f2.Height, "Height");
			Assert.AreEqual (f.Italic, f2.Italic, "Italic");
			Assert.AreEqual (f.Name, f2.Name, "Name");
			Assert.AreEqual (f.Size, f2.Size, "Size");
			Assert.AreEqual (f.SizeInPoints, f2.SizeInPoints, "SizeInPoints");
			Assert.AreEqual (f.Strikeout, f2.Strikeout, "Strikeout");
			Assert.AreEqual (f.Style, f2.Style, "Style");
			Assert.AreEqual (f.Underline, f2.Underline, "Underline");
			Assert.AreEqual (f.Unit, f2.Unit, "Unit");
		}
Example #6
0
        // This isn't used anymore. It's left here as reference for how to get kerning data in C#.
        public static KerningPair[] GetKerningPairs( Font font, Graphics graphics )
        {
            // Select the HFONT into the HDC.
            IntPtr hDC = graphics.GetHdc();
            Font fontClone = (Font)font.Clone();
            IntPtr hFont = fontClone.ToHfont();
            SelectObject( hDC, hFont );

            // Find out how many pairs there are and allocate them.
            int numKerningPairs = GetKerningPairs( hDC.ToInt32(), 0, null );
            KerningPair[] kerningPairs = new KerningPair[ numKerningPairs ];

            // Get the pairs.
            GetKerningPairs( hDC.ToInt32(), kerningPairs.Length, kerningPairs );

            DeleteObject( hFont );
            graphics.ReleaseHdc();

            return kerningPairs;
        }
Example #7
0
        // update input font
        private void updateSelectedFont(Font fnt)
        {
            // set text name in the text box
            txtInputFont.Text = fnt.Name;

            // add to text
            txtInputFont.Text += " " + Math.Round(fnt.Size) + "pts";

            // check if bold
            if (fnt.Bold)
            {
                // add to text
                txtInputFont.Text += " / Bold";
            }

            // check if italic
            if (fnt.Italic)
            {
                // add to text
                txtInputFont.Text += " / Italic";
            }

            // set the font in the text box
            txtInputText.Font = (Font)fnt.Clone();

            // save into settings
            Properties.Settings.Default.InputFont = fnt;
            Properties.Settings.Default.Save();
        }
Example #8
0
 public TextItem(Font ft)
 {
   m_Type = InnerType.Empty;
   m_Text = "";
   m_Font = (null == ft) ? null : (Font)ft.Clone();
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the ColorizationStyle class.
 /// </summary>
 /// <param name="newFixationPen">The new fixation pen to set.</param>
 /// <param name="newConnectionPen">The new fixation connection pen to set.</param>
 /// <param name="newFont">The new font to set.</param>
 /// <param name="newFontColor">The new font color to set.</param>
 public ColorizationStyle(Pen newFixationPen, Pen newConnectionPen, Font newFont, Color newFontColor)
 {
   this.fixationPen = (Pen)newFixationPen.Clone();
   this.connectionPen = (Pen)newConnectionPen.Clone();
   this.font = (Font)newFont.Clone();
   this.fontColor = newFontColor;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the VGElement class.
 /// </summary>
 /// <param name="newShapeDrawAction">Drawing action: Edge, Fill, Both</param>
 /// <param name="newBrush">Brush for text and fills</param>
 /// <param name="newFont">Font for text</param>
 /// <param name="newFontColor">Color for text</param>
 /// <param name="newBounds">Bounds of element</param>
 /// <param name="newStyleGroup">Group Enumeration, <see cref="VGStyleGroup"/></param>
 /// <param name="newName">Name of Element</param>
 /// <param name="newElementGroup">Element group description</param>
 public VGElement(
   ShapeDrawAction newShapeDrawAction,
   Brush newBrush,
   Font newFont,
   Color newFontColor,
   RectangleF newBounds,
   VGStyleGroup newStyleGroup,
   string newName,
   string newElementGroup)
 {
   this.InitStandards();
   this.styleGroup = newStyleGroup;
   this.name = newName;
   this.elementGroup = newElementGroup;
   this.shapeDrawAction = newShapeDrawAction;
   this.Brush = newBrush == null ? null : (Brush)newBrush.Clone();
   this.Font = newFont == null ? null : (Font)newFont.Clone();
   this.FontColor = newFontColor;
   this.Bounds = newBounds;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the VGElement class.
 /// </summary>
 /// <param name="newShapeDrawAction">Drawing action: Edge, Fill, Both</param>
 /// <param name="newPen">Pen for edges</param>
 /// <param name="newFont">Font for text</param>
 /// <param name="newFontColor">Color for text</param>
 /// <param name="newStyleGroup">Group Enumeration, <see cref="VGStyleGroup"/></param>
 /// <param name="newName">Name of Element</param>
 /// <param name="newElementGroup">Element group description</param>
 public VGElement(
   ShapeDrawAction newShapeDrawAction,
   Pen newPen,
   Font newFont,
   Color newFontColor,
   VGStyleGroup newStyleGroup,
   string newName,
   string newElementGroup)
 {
   this.InitStandards();
   this.styleGroup = newStyleGroup;
   this.name = newName;
   this.elementGroup = newElementGroup;
   this.Font = newFont == null ? null : (Font)newFont.Clone();
   this.FontColor = newFontColor;
   this.shapeDrawAction = newShapeDrawAction;
   this.pen = newPen == null ? null : (Pen)newPen.Clone();
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the VGElement class.
 /// </summary>
 /// <param name="newShapeDrawAction">Drawing action: Edge, Fill, Both</param>
 /// <param name="newPen">Pen for edges</param>
 /// <param name="newBrush">Brush for text and fills</param>
 /// <param name="newFont">Font for text</param>
 /// <param name="newFontColor">Color for text</param>
 /// <param name="newBounds">Bounds of element</param>
 /// <param name="newStyleGroup">Group Enumeration, <see cref="VGStyleGroup"/></param>
 /// <param name="newName">Name of Element</param>
 /// <param name="newElementGroup">Element group description</param>
 /// <param name="newSound">The <see cref="AudioFile"/> to play with this element.</param>
 public VGElement(
   ShapeDrawAction newShapeDrawAction,
   Pen newPen,
   Brush newBrush,
   Font newFont,
   Color newFontColor,
   RectangleF newBounds,
   VGStyleGroup newStyleGroup,
   string newName,
   string newElementGroup,
   AudioFile newSound)
 {
   this.InitStandards();
   this.pen = newPen == null ? null : (Pen)newPen.Clone();
   this.Brush = newBrush == null ? null : (Brush)newBrush.Clone();
   this.Bounds = newBounds;
   this.styleGroup = newStyleGroup;
   this.name = newName;
   this.elementGroup = newElementGroup;
   this.Font = newFont == null ? null : (Font)newFont.Clone();
   this.FontColor = newFontColor;
   this.shapeDrawAction = newShapeDrawAction;
   if (newSound != null)
   {
     this.Sound = (AudioFile)newSound.Clone();
   }
 }
    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 #14
0
		private float DrawFitString(Graphics g, string value, Font font, Brush brush, RectangleF rect, StringFormat sf)
		{
			SizeF size = g.MeasureString(value, font);
			Font measureFont = font;
			smallFont = font;

			while ((size.Width > rect.Width) && measureFont.Size >= 1)
			{
				float shrinkFactor = (float)Math.Sqrt(rect.Height / size.Height);
				using (measureFont = new Font(font.FontFamily, (int)Math.Min(measureFont.Size - 1, measureFont.Size * shrinkFactor)))
				{
					size = g.MeasureString(value, measureFont);
					smallFont = (Font)(measureFont.Clone());
				}
			}

			g.DrawString(value, smallFont, brush, rect, sf);
			return size.Height;
		}