/// <summary> /// Crea la geometría /// </summary> private Geometry CreateGeometry() { PathGeometry pathGeometry = new PathGeometry(); // Obtiene la figura de los recursos si es necesario _shape = GetShape(_shape); // Añade las figuras a la geometría foreach (FigureModel figure in _shape.Figures) { pathGeometry.AddGeometry(Geometry.Combine(Geometry.Empty, Geometry.Parse(figure.Data), GeometryCombineMode.Union, ViewTransformTools.GetTransforms(figure.Transforms))); } // Asigna el método de relleno pathGeometry.FillRule = ViewTools.Convert(_shape.FillMode); // Añade las geometrías a la geometría principal //! Esto no parece añadir nada en especial pathGeometry.Transform = ViewTransformTools.GetTransforms(_shape.Transforms); // Devuelve la geometría creada return(pathGeometry); }
/// <summary> /// Crea la geometría basándose en el texto formateado /// </summary> private Geometry CreateGeometry() { FormattedText formattedText; FontStyle fontStyle = FontStyles.Normal; FontWeight fontWeight = FontWeights.Medium; Geometry textGeometry; // Obtiene el estilo del texto if (Bold) { fontWeight = FontWeights.Bold; } if (Italic) { fontStyle = FontStyles.Italic; } // Asigna el ancho de la fuente if (FontSize == 0) { FontSize = 10; } // Crea el texto formateado basándose en el conjunto de propiedades //! En este caso la brocha no importa porque simplemente se crea la geometría formattedText = new FormattedText(Text ?? string.Empty, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily(Font), fontStyle, fontWeight, FontStretches.Normal), FontSize, Brushes.Black, VisualTreeHelper.GetDpi(this).PixelsPerDip); // Asigna el ancho máximo del texto if (MaxTextWidth == 0) { formattedText.MaxTextWidth = 80; } else { formattedText.MaxTextWidth = MaxTextWidth; } if (MaxTextHeight == 0) { formattedText.MaxTextHeight = 80; } else { formattedText.MaxTextHeight = MaxTextHeight; } // Obtiene la geometría del texto if (Highlight) { textGeometry = formattedText.BuildHighlightGeometry(new Point(TextLeft, TextTop)); } else { textGeometry = formattedText.BuildGeometry(new Point(TextLeft, TextTop)); } // Asigna las transformaciones textGeometry.Transform = ViewTransformTools.GetTransforms(PageItem.Transforms); // Devuelve la geometría return(textGeometry); /* * string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"; * * // Create the initial formatted text string. * FormattedText formattedText = new FormattedText( * testString, * CultureInfo.GetCultureInfo("en-us"), * FlowDirection.LeftToRight, * new Typeface("Verdana"), * 32, * Brushes.Black); * * // Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears. * formattedText.MaxTextWidth = 300; * formattedText.MaxTextHeight = 240; * * // Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters. * // The font size is calculated in terms of points -- not as device-independent pixels. * formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5); * * // Use a Bold font weight beginning at the 6th character and continuing for 11 characters. * formattedText.SetFontWeight(FontWeights.Bold, 6, 11); * * // Use a linear gradient brush beginning at the 6th character and continuing for 11 characters. * formattedText.SetForegroundBrush( * new LinearGradientBrush( * Colors.Orange, * Colors.Teal, * 90.0), * 6, 11); * * // Use an Italic font style beginning at the 28th character and continuing for 28 characters. * formattedText.SetFontStyle(FontStyles.Italic, 28, 28); * * // Draw the formatted text string to the DrawingContext of the control. * drawingContext.DrawText(formattedText, new Point(10, 0)); */ }