Beispiel #1
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                string invariantDescriptionString = info.GetNodeContent();
                var    s = new FontX(invariantDescriptionString);

                return(s);
            }
Beispiel #2
0
		/// <summary>
		/// Measures 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, FontX font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
		{
			string[] titems = FormatItems(items);
			if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix))
			{
				for (int i = 0; i < titems.Length; ++i)
					titems[i] = _prefix + titems[i] + _suffix;
			}

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

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

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

			return litems;
		}
Beispiel #3
0
		/// <summary>
		/// Draws the item to a specified location.
		/// </summary>
		/// <param name="g">Graphics context.</param>
		/// <param name="brush">Brush used to draw the item.</param>
		/// <param name="font">Font used to draw the item.</param>
		/// <param name="strfmt">String format.</param>
		/// <param name="item">The item to draw.</param>
		/// <param name="morg">The location where the item is drawn to.</param>
		public virtual void DrawItem(System.Drawing.Graphics g, BrushX brush, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg)
		{
			string text = _prefix + FormatItem(item) + _suffix;
			g.DrawString(text, GdiFontManager.ToGdi(font), brush, morg, strfmt);
		}
Beispiel #4
0
		/// <summary>
		/// Measures the item, i.e. returns the size of the item.
		/// </summary>
		/// <param name="g">Graphics context.</param>
		/// <param name="font">The font that is used to draw the item.</param>
		/// <param name="strfmt">String format used to draw the item.</param>
		/// <param name="mtick">The item to draw.</param>
		/// <param name="morg">The location the item will be drawn.</param>
		/// <returns>The size of the item if it would be drawn.</returns>
		public virtual System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
		{
			string text = _prefix + FormatItem(mtick) + _suffix;
			return g.MeasureString(text, GdiFontManager.ToGdi(font), morg, strfmt);
		}
Beispiel #5
0
		public override bool CopyFrom(object obj)
		{
			var isCopied = base.CopyFrom(obj);
			if (isCopied && !object.ReferenceEquals(this, obj))
			{
				var from = obj as SimpleTextGraphic;
				if (null != from)
				{
					this._font = from._font;
					this._text = from._text;
					this._color = from._color;
				}
			}
			return isCopied;
		}
Beispiel #6
0
			public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
			{
				string invariantDescriptionString = info.GetNodeContent();
				FontX s = new FontX(invariantDescriptionString);
				return s;
			}
Beispiel #7
0
		/// <summary>Gets the height of the font in points (1/72 inch).</summary>
		/// <param name="fontX">The font instance.</param>
		public static double Height(FontX fontX)
		{
			return ToGdi(fontX).GetHeight(72);
		}
Beispiel #8
0
		/// <summary>
		/// Retrieves the Gdi+ font instance that the provided <see cref="FontX"/> argument is describing.
		/// </summary>
		/// <param name="fontX">The fontX instance.</param>
		/// <returns>The Gdi+ font instance that corresponds with the argument. If the font family of the fontX argument is not found, a default font (Microsoft Sans Serif) is returned.</returns>
		protected virtual Font InternalToGdi(FontX fontX)
		{
			string fontID = fontX.InvariantDescriptionString;
			Font result;
			if (!_descriptionToGdiFont.TryGetValue(fontID, out result))
			{
				result = _descriptionToGdiFont.AddOrUpdate(fontID,
					x => InternalGetGdiFontFromInvariantString(x),
					(x, y) => y);
			}

			return result;
		}
			public MeasuredLabelItem(Graphics g, FontX font1, FontX font2, StringFormat strfmt, string firstpart, string exponent, string lastpart, float maxexposize)
			{
				_firstpart = firstpart;
				_exponent = exponent;
				_lastpart = lastpart;
				_font1 = font1;
				_font2 = font2;
				_strfmt = strfmt;
				_size1 = g.MeasureString(_firstpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt);
				_size2 = g.MeasureString(_exponent, GdiFontManager.ToGdi(_font2), new PointF(_size1.Width, 0), strfmt);
				_size3 = g.MeasureString(_lastpart, GdiFontManager.ToGdi(_font1), new PointF(0, 0), strfmt);
				_rightPadding = maxexposize - _size2.Width;
			}
		public override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant[] items)
		{
			MeasuredLabelItem[] litems = new MeasuredLabelItem[items.Length];

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

			StringFormat 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((double)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;
		}
		public override void DrawItem(Graphics g, BrushX brush, FontX font, StringFormat strfmt, Altaxo.Data.AltaxoVariant item, PointF morg)
		{
			string firstpart, middelpart, exponent;
			double mant;
			SplitInFirstPartAndExponent((double)item, out firstpart, out mant, out middelpart, out exponent);

			var gdiFont = GdiFontManager.ToGdi(font);
			SizeF size1 = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, morg, strfmt);
			g.DrawString(_prefix + firstpart + middelpart, gdiFont, brush, morg, strfmt);
			var orginalY = morg.Y;
			morg.X += size1.Width;
			morg.Y += size1.Height / 3;
			FontX font2 = font.WithSize(font.Size * 2 / 3.0);
			var gdiFont2 = GdiFontManager.ToGdi(font2);
			g.DrawString(exponent, gdiFont2, brush, morg);
			if (!string.IsNullOrEmpty(_suffix))
			{
				morg.X += g.MeasureString(exponent, gdiFont2, morg, strfmt).Width;
				morg.Y = orginalY;
			}

			if (!string.IsNullOrEmpty(_suffix))
			{
				g.DrawString(_suffix, gdiFont, brush, morg, strfmt);
			}
		}
		public override System.Drawing.SizeF MeasureItem(System.Drawing.Graphics g, FontX font, System.Drawing.StringFormat strfmt, Altaxo.Data.AltaxoVariant mtick, System.Drawing.PointF morg)
		{
			string firstpart, middelpart, exponent;
			double mant;
			SplitInFirstPartAndExponent((double)mtick, out firstpart, out mant, out middelpart, out exponent);

			var gdiFont = GdiFontManager.ToGdi(font);
			SizeF size1 = g.MeasureString(_prefix + firstpart + middelpart, gdiFont, new PointF(0, 0), strfmt);
			SizeF size2 = g.MeasureString(exponent, gdiFont, new PointF(size1.Width, 0), strfmt);
			SizeF size3 = g.MeasureString(_suffix, gdiFont, new PointF(0, 0), strfmt);

			return new SizeF(size1.Width + size2.Width + size3.Width, size1.Height);
		}
			public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext, double lineSpacing, StringAlignment horizontalAlignment, StringAlignment verticalAlignment, StringAlignment textBlockAligment)
			{
				_text = itemtext.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
				_stringSize = new PointD2D[_text.Length];
				_font = font;
				_horizontalAlignment = horizontalAlignment;
				_verticalAlignment = verticalAlignment;
				_textBlockAligment = textBlockAligment;
				_strfmt = strfmt;
				_lineSpacing = lineSpacing;
				_size = SizeF.Empty;
				var bounds = RectangleD2D.Empty;
				var position = new PointD2D();
				for (int i = 0; i < _text.Length; ++i)
				{
					_stringSize[i] = g.MeasureString(_text[i], GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt);
					bounds.ExpandToInclude(new RectangleD2D(position, _stringSize[i]));
					position = position.WithYPlus(_stringSize[i].Y * _lineSpacing);
				}
				_size = bounds.Size;
			}
		/// <summary>
		/// Measures 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 override IMeasuredLabelItem[] GetMeasuredItems(Graphics g, FontX font, System.Drawing.StringFormat strfmt, AltaxoVariant[] items)
		{
			string[] titems = FormatItems(items);
			if (!string.IsNullOrEmpty(_prefix) || !string.IsNullOrEmpty(_suffix))
			{
				for (int i = 0; i < titems.Length; ++i)
					titems[i] = _prefix + titems[i] + _suffix;
			}

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

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

			StringAlignment horizontalAlignment = localstrfmt.Alignment;
			StringAlignment verticalAlignment = localstrfmt.LineAlignment;

			localstrfmt.Alignment = StringAlignment.Near;
			localstrfmt.LineAlignment = StringAlignment.Near;

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

			return litems;
		}
Beispiel #15
0
			public MeasuredLabelItem(Graphics g, FontX font, StringFormat strfmt, string itemtext)
			{
				_text = itemtext;
				_font = font;
				_strfmt = strfmt;
				_size = g.MeasureString(_text, GdiFontManager.ToGdi(_font), new PointF(0, 0), strfmt);
			}
Beispiel #16
0
		public SimpleTextGraphic(PointD2D graphicPosition, string text,
			FontX textFont, Color textColor)
			: base(new ItemLocationDirectAutoSize())
		{
			this.SetPosition(graphicPosition, Main.EventFiring.Suppressed);
			this.Font = textFont;
			this.Text = text;
			this.Color = textColor;
		}
Beispiel #17
0
		public SimpleTextGraphic(PointD2D graphicPosition,
			string text, FontX textFont,
			Color textColor, double Rotation)
			: this(graphicPosition, text, textFont, textColor)
		{
			this.Rotation = Rotation;
		}
Beispiel #18
0
		/// <summary>
		/// Retrieves the Gdi+ font instance that the provided <see cref="FontX"/> argument is describing.
		/// </summary>
		/// <param name="fontX">The fontX instance.</param>
		/// <returns>The Gdi+ font instance that corresponds with the argument. If the font family of the fontX argument is not found, a default font (Microsoft Sans Serif) is returned.</returns>
		public static Font ToGdi(FontX fontX)
		{
			return _instance.InternalToGdi(fontX);
		}
Beispiel #19
0
		public SimpleTextGraphic(double posX, double posY,
			string text,
			FontX textFont,
			Color textColor, double Rotation)
			: this(new PointD2D(posX, posY), text, textFont, textColor, Rotation)
		{
		}
Beispiel #20
0
		/// <summary>
		/// Gets the font family of the provided <see cref="FontX"/> instance. Be aware that the returned font family can differ from the font family which is coded within the <see cref="FontX"/> invariant description string.
		/// </summary>
		/// <param name="fontX">The provided FontX instance.</param>
		/// <returns>The Gdi font family of the Gdi font which is associated with the provided FontX instance.</returns>
		public static FontFamily GdiFontFamily(FontX fontX)
		{
			return ToGdi(fontX).FontFamily;
		}
Beispiel #21
0
		public FontX3D(FontX font, double depth)
		{
			_font = font;
			_depth = depth;
		}