public TextBlockPropertiesViewModel(IElementTextBlock element, CommonDesignerCanvas designerCanvas)
		{
			Title = "Свойства фигуры: Надпись";
			ElementTextBlock = element;
			PositionSettingsViewModel = new PositionSettingsViewModel(element as ElementBase, designerCanvas);

			CopyProperties();

			Fonts = new List<string>();
			foreach (var fontfamily in System.Drawing.FontFamily.Families)
				Fonts.Add(fontfamily.Name);
			TextAlignments = new List<string>()
			{
				"По левому краю",
				"По правому краю",
				"По центру",
			};
			VerticalAlignments = new List<string>()
			{
				"По верхнему краю",
				"По середине",
				"По нижнему краю",
			};
		}
Exemplo n.º 2
0
		/// <summary>
		///     Рендерит IElementTextBlock
		/// </summary>
		/// <param name="item">Элемент</param>
		/// <param name="size">Размеры контейнера</param>
		/// <param name="left">Координата X</param>
		/// <param name="top">Координата Y</param>
		/// <param name="showHint">Показывать всплывающую подсказку.</param>
		/// <returns></returns>
		private static PlanElement FromTextElement(IElementTextBlock item, System.Windows.Size size, double left, double top, bool showHint)
		{
			if (string.IsNullOrWhiteSpace(item.Text))
			{
				return null;
			}
			var fontFamily = new System.Windows.Media.FontFamily(item.FontFamilyName);
			var fontStyle = item.FontItalic ? FontStyles.Italic : FontStyles.Normal;
			var fontWeight = item.FontBold ? FontWeights.Bold : FontWeights.Normal;
			var text = new FormattedText(
				item.Text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
				new Typeface(fontFamily, fontStyle, fontWeight, FontStretches.Normal), item.FontSize, new SolidColorBrush(item.ForegroundColor.ToWindowsColor()))
				{
					Trimming = TextTrimming.WordEllipsis,
					MaxLineCount = item.WordWrap ? int.MaxValue : 1
				};
			// Делаем первый рендер без трансформаций
			var pathGeometry = text.BuildGeometry(new Point(left + item.BorderThickness, top + item.BorderThickness));
			// Добавляем Scale-трансформацию, если включен Stretch, либо Translate-трансформацию
			if (item.Stretch)
			{
				var scaleFactorX = (size.Width - item.BorderThickness * 2) / text.Width;
				var scaleFactorY = (size.Height - item.BorderThickness * 2) / text.Height;
				pathGeometry = Geometry.Combine(Geometry.Empty, pathGeometry, GeometryCombineMode.Union, new ScaleTransform(
					scaleFactorX, scaleFactorY, left + item.BorderThickness, top + item.BorderThickness));
			}
			else
			{
				double offsetX = 0;
				double offsetY = 0;
				switch (item.TextAlignment)
				{
					case 1:
						{
							offsetX = size.Width - item.BorderThickness * 2 - text.Width;
							break;
						}
					case 2:
						{
							offsetX = (size.Width - item.BorderThickness * 2 - text.Width) / 2;
							break;
						}
				}
				switch (item.VerticalAlignment)
				{
					case 1:
						{
							offsetY = (size.Height - item.BorderThickness * 2 - text.Height) / 2;
							break;
						}
					case 2:
						{
							offsetY = size.Height - item.BorderThickness * 2 - text.Height;
							break;
						}
				}
				pathGeometry = Geometry.Combine(Geometry.Empty, pathGeometry, GeometryCombineMode.Union, new TranslateTransform(offsetX, offsetY));
			}
			// Делаем финальный рендер
			var path = pathGeometry.GetFlattenedPathGeometry().ToString(CultureInfo.InvariantCulture).Substring(2);

			var shape = new PlanElement
			{
				Path = path,
				Border = InternalConverter.ConvertColor(Colors.Transparent),
				Fill = InternalConverter.ConvertColor(item.ForegroundColor.ToWindowsColor()),
				Name = item.PresentationName,
				Id = "pe" + item.UID,
				Hint = (item as ElementBase) != null && showHint ? GetElementHint((ElementBase)item) : null,
				BorderThickness = 0,
				Type = ShapeTypes.Path.ToString(),
				HasOverlay = false
			};
			return shape;
		}