Пример #1
1
        /// <summary>
        /// Draw some helpful text.
        /// </summary>
        /// <param name="dc"></param>
        protected virtual void DrawHelpText(DrawingContext dc)
        {
            System.Windows.Media.Typeface backType =
                new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily("sans courier"),
                                                  FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            System.Windows.Media.FormattedText formatted = new System.Windows.Media.FormattedText(
                                                            "Click & move the mouse to select a capture area.\nENTER/F10: Capture\nBACKSPACE/DEL: Start over\nESC: Exit",
                                                            System.Globalization.CultureInfo.CurrentCulture,
                                                            FlowDirection.LeftToRight,
                                                            backType,
                                                            32.0f,
                                                            new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White));
            // Make sure the text shows at 0,0 on the primary screen
            System.Drawing.Point primScreen = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Location;
            Point clientBase = PointFromScreen(new Point(primScreen.X + 5, primScreen.Y + 5));
            Geometry textGeo = formatted.BuildGeometry(clientBase);
            dc.DrawGeometry(
                System.Windows.Media.Brushes.White,
                null,
                textGeo);

            dc.DrawGeometry(
                null,
                new System.Windows.Media.Pen(System.Windows.Media.Brushes.White, 1),
                textGeo);
        }
Пример #2
0
        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();
            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();
            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
Пример #3
0
		public override void Transform()
		{
			base.Transform();
			IElementTextBlock elementText = (IElementTextBlock)Element;
			var height = Rect.Height > Element.BorderThickness ? Rect.Height - Element.BorderThickness : 0;
			var width = Rect.Width > Element.BorderThickness ? Rect.Width - Element.BorderThickness : 0;
			Rect bound = new Rect(Rect.Left + Element.BorderThickness / 2, Rect.Top + Element.BorderThickness / 2, width, height);
			var typeface = new Typeface(new FontFamily(elementText.FontFamilyName), elementText.FontItalic ? FontStyles.Italic : FontStyles.Normal, elementText.FontBold ? FontWeights.Bold : FontWeights.Normal, new FontStretch());
			var formattedText = new FormattedText(elementText.Text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, elementText.FontSize, PainterCache.BlackBrush);
			formattedText.TextAlignment = (TextAlignment)elementText.TextAlignment;
			Point point = bound.TopLeft;
			switch (formattedText.TextAlignment)
			{
				case TextAlignment.Right:
					point = bound.TopRight;
					break;
				case TextAlignment.Center:
					point = new Point(bound.Left + bound.Width / 2, bound.Top);
					break;
			}
			if (_clipGeometry != null)
				_clipGeometry.Rect = bound;
			if (_scaleTransform != null)
			{
				_scaleTransform.CenterX = point.X;
				_scaleTransform.CenterY = point.Y;
				_scaleTransform.ScaleX = bound.Width / formattedText.Width;
				_scaleTransform.ScaleY = bound.Height / formattedText.Height;
			}
			_textDrawing.Geometry = formattedText.BuildGeometry(point);
		}
Пример #4
0
        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        public void CreateText()
        {
            FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (Bold == true) fontWeight = FontWeights.Bold;
            if (Italic == true) fontStyle = FontStyles.Italic;

            // Create the formatted text based on the properties set.
            FormattedText formattedText = new FormattedText(
                Text,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(Font, fontStyle, fontWeight, FontStretches.Normal),
                FontSize,
                Brushes.Black // This brush does not matter since we use the geometry of the text. 
                );

            // Build the geometry object that represents the text.
            _textGeometry = formattedText.BuildGeometry(new Point(0, 0));




            //set the size of the custome control based on the size of the text
            this.MinWidth = formattedText.Width;
            this.MinHeight = formattedText.Height;

        }
        public FleetRender( Fleet fleet, bool? lines )
        {
            LineGeometry line;
            FormattedText text;
            Geometry textGeom;

            double x = fleet.SourcePlanet.X +
                       ((fleet.DestinationPlanet.X - fleet.SourcePlanet.X) *
                        ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength));
            double y = fleet.SourcePlanet.Y +
                       ((fleet.DestinationPlanet.Y - fleet.SourcePlanet.Y) *
                        ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength));

            if (lines ?? false)
            {
                line = new LineGeometry(new Point(x, y), new Point(fleet.DestinationPlanet.X, fleet.DestinationPlanet.Y));
                m_gg.Children.Add(line);
            }

            text = new FormattedText(
                fleet.ShipCount.ToString(),
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface("Tahoma"),
                0.8,
                Brushes.Black);
            textGeom = text.BuildGeometry(new Point(x - text.Width / 2, y - text.Height / 2));
            m_gg.Children.Add(textGeom);

            m_gg.Freeze();
        }
Пример #6
0
        /// <summary>
        /// Draw some helpful text.
        /// </summary>
        /// <param name="dc"></param>
        protected virtual void DrawHelpText(DrawingContext dc)
        {
            System.Windows.Media.Typeface backType =
                new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily("sans courier"),
                                                  FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            System.Windows.Media.FormattedText formatted = new System.Windows.Media.FormattedText(
                "Click & move the mouse to select a capture area.\nENTER/F10: Capture\nBACKSPACE/DEL: Start over\nESC: Exit",
                System.Globalization.CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                backType,
                32.0f,
                new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.White));
            // Make sure the text shows at 0,0 on the primary screen
            System.Drawing.Point primScreen = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Location;
            Point    clientBase             = PointFromScreen(new Point(primScreen.X + 5, primScreen.Y + 5));
            Geometry textGeo = formatted.BuildGeometry(clientBase);

            dc.DrawGeometry(
                System.Windows.Media.Brushes.White,
                null,
                textGeo);

            dc.DrawGeometry(
                null,
                new System.Windows.Media.Pen(System.Windows.Media.Brushes.White, 1),
                textGeo);
        }
Пример #7
0
        /// <summary>
        /// Create the outline geometry based on the formatted text.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="bold"></param>
        /// <param name="italic"></param>
        /// <param name="family"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private PathGeometry CreateText(string text, bool bold, bool italic, FontFamily family, double size, System.Windows.Point location)
        {
            System.Windows.FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (bold == true)
            {
                fontWeight = FontWeights.Bold;
            }

            if (italic == true)
            {
                fontStyle = FontStyles.Italic;
            }

            System.Windows.Media.FormattedText formattedText = new System.Windows.Media.FormattedText(
                text,
                System.Globalization.CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(family, fontStyle, fontWeight, FontStretches.Normal),
                size, System.Windows.Media.Brushes.Black
                );

            Geometry textGeometry = formattedText.BuildGeometry(location);

            return(textGeometry.GetFlattenedPathGeometry());
        }
Пример #8
0
        public static IGeometry Read(string text, Typeface font, double size, Point origin, FlowDirection flowDirection, IGeometryFactory geomFact)
        {
            var formattedText = new FormattedText(text, System.Globalization.CultureInfo.CurrentUICulture,
                                                  flowDirection, font, size, Brushes.Black);

            var geom = formattedText.BuildGeometry(origin);
            return WpfGeometryReader.Read(geom.GetFlattenedPathGeometry(FlatnessFactor, ToleranceType.Relative), geomFact);
        }
 public static void DrawText(this DrawingGroup drawingGroup, int x, int y, string text)
 {
     var typeface = new Typeface("Arial");
     var formattedText = new FormattedText(text, CultureInfo.CurrentUICulture,
                                  FlowDirection.LeftToRight, typeface, 10, Brushes.Gray);
     var textgeometry = formattedText.BuildGeometry(new Point(x, y));
     var textDrawing = new GeometryDrawing(Brushes.Gray, new Pen(Brushes.Gray, 0), textgeometry);
     drawingGroup.Children.Add(textDrawing);
 }
Пример #10
0
 /// <summary>
 ///     This method creates the text geometry.
 /// </summary>
 private void CreateTextGeometry()
 {
     var formattedText = new FormattedText(Text,
         Thread.CurrentThread.CurrentUICulture,
         FlowDirection.LeftToRight,
         new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
         FontSize,
         Brushes.Black);
     _textGeometry = formattedText.BuildGeometry(Origin);
 }
		public static GeometryDrawing[] GetOutlinedText(string text, double maxFontSize, Rect rect, Brush fill, Brush stroke, Typeface typeFace,
												  double strokeThickness = 2, bool centered = false)
		{
			var fText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, typeFace, maxFontSize, fill);
			if(!double.IsNaN(rect.Width))
			{
				if(fText.Width > rect.Width)
					fText.SetFontSize((int)(maxFontSize * rect.Width / fText.Width));
				fText.MaxTextWidth = rect.Width;
			}

			var point = new Point(rect.X + (centered && !double.IsNaN(rect.Width) ? (rect.Width - fText.Width) / 2 : 0), !double.IsNaN(rect.Height) ? (rect.Height - fText.Height) / 2 + fText.Height  * 0.05: rect.Y);
			var drawings = new[]
			{
				new GeometryDrawing(stroke, new Pen(Brushes.Black, strokeThickness) {LineJoin = PenLineJoin.Round}, fText.BuildGeometry(point)),
				new GeometryDrawing(fill, new Pen(Brushes.White, 0), fText.BuildGeometry(point))
			};
			return drawings;
		}
Пример #12
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var text = new FormattedText(
                this.Text,
                CultureInfo.CurrentCulture,
                this.FlowDirection,
                new Typeface(this.FontFamily, this.FontStyle, this.FontWeight, this.FontStretch),
                this.FontSize,
                this.Brush);

            return text.BuildGeometry(new Point(0, 0));
        }
Пример #13
0
 private static Geometry MakeCharacterGeometry(char character)
 {
     var fontFamily = new FontFamily(Settings.Default.FontFamily);
     var typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Heavy, FontStretches.Normal);
     var formattedText = new FormattedText(
         character.ToString(),
         CultureInfo.CurrentCulture,
         FlowDirection.LeftToRight,
         typeface,
         300,
         Brushes.Black);
     return formattedText.BuildGeometry(new Point(0, 0)).GetAsFrozen() as Geometry;
 }
Пример #14
0
        public static void DrawBoldText(DrawingContext drawingContext, string str, Point pt)
        {
            FormattedText newText = new FormattedText(str,
                Configurations.culture,
                FlowDirection.LeftToRight,
                Configurations.TypeFace,
                Configurations.TextSize,
                Configurations.TextBoldColor);

            newText.SetFontWeight(FontWeights.SemiBold);
            Geometry textGeometry = newText.BuildGeometry(pt);
            drawingContext.DrawGeometry(Configurations.TextBoldColor, null, textGeometry);
            //drawingContext.DrawText(newText, pt);
        }
        public override object ProvideValue( IServiceProvider serviceProvider )
        {
            var text = new FormattedText(
                Value,
                Thread.CurrentThread.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface( "Verdana" ),
                8,
                Brushes.Black );

            var geometry = text.BuildGeometry( StartPoint );

            return geometry;
        }
Пример #16
0
        public static string Text2Path(String text, string culture, bool leftToRight, string font, int fontSize)
        {
            if (culture == "") culture = "en-us";

            var ci = new CultureInfo(culture);
            var fd = leftToRight ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;
            var ff = new FontFamily(font);
            var tf = new Typeface(ff, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            var t = new FormattedText(text, ci, fd, tf, fontSize, Brushes.Black);
            var g = t.BuildGeometry(new Point(0, 0));
            var p = g.GetFlattenedPathGeometry();

            return p.ToString();
        }
Пример #17
0
        public string Text2Path(String strText, string strCulture, bool LtoR, string strTypeFace, int nSize, Thickness masks)
        {
            // Set up the Culture
            if (strCulture == "")
                strCulture = "en-us";
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(strCulture);

            // Set up the flow direction
            System.Windows.FlowDirection fd;
            if (LtoR)
                fd = FlowDirection.LeftToRight;
            else
                fd = FlowDirection.RightToLeft;

            // Set up the font family from the parameter
            FontFamily ff = new FontFamily(strTypeFace);

            // Create the new typeface
            System.Windows.Media.Typeface tf = new System.Windows.Media.Typeface(ff,

                FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

            // Create a formatted text object from the text,

            // culture, flowdirection, typeface, size and black

            FormattedText t = new FormattedText(strText, ci, fd, tf, nSize,

                System.Windows.Media.Brushes.Black);

            // Build a Geometry out of this
            Geometry g = t.BuildGeometry(new Point(0, 0));

            // Get the Path info from the geometry
            PathGeometry p = g.GetFlattenedPathGeometry();
            var x = nSize - masks.Left - masks.Right;
            var y = nSize - masks.Top - masks.Bottom;
            var size = new Size(x < 0 ? 0 : x, y < 0 ? 0 : y);
            var rectv = new Rect(new Point(masks.Left, masks.Top), size);

            RectangleGeometry rg = new RectangleGeometry(rectv);
            var cg = new CombinedGeometry(p, rg);
            cg.GeometryCombineMode = GeometryCombineMode.Intersect;

            p = cg.GetFlattenedPathGeometry();

            // Return the path info
            return p.ToString();
        }
Пример #18
0
        public string Text2Path(String strText, string strCulture, bool LtoR, string strTypeFace, int nSize)
        {
            if (strCulture == "")
                strCulture = "en-us";

            CultureInfo ci = new CultureInfo(strCulture);
            FlowDirection fd = LtoR ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;
            FontFamily ff = new FontFamily(strTypeFace);
            Typeface tf = new Typeface(ff, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            FormattedText t = new FormattedText(strText, ci, fd, tf, nSize, Brushes.Black);
            Geometry g = t.BuildGeometry(new Point(0, 0));
            PathGeometry p = g.GetFlattenedPathGeometry();

            return p.ToString();
        }
		public override void Transform()
		{
			base.Transform();
			var height = Rect.Height > Element.BorderThickness ? Rect.Height - Element.BorderThickness : 0;
			var width = Rect.Width > Element.BorderThickness ? Rect.Width - Element.BorderThickness : 0;
			var bound = new Rect(Rect.Left + Element.BorderThickness / 2, Rect.Top + Element.BorderThickness / 2, width, height);
			var typeface = new Typeface(SystemFonts.CaptionFontFamily, FontStyles.Normal, FontWeights.Normal, new FontStretch());
			var formattedText = new FormattedText(((ElementPassCardImageProperty)Element).Text ?? string.Empty, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeface, SystemFonts.CaptionFontSize, PainterCache.BlackBrush);
			formattedText.TextAlignment = TextAlignment.Center;
			Point point = new Point(bound.Left + bound.Width / 2, bound.Top);
			_scaleTransform.CenterX = point.X;
			_scaleTransform.CenterY = point.Y;
			_scaleTransform.ScaleX = bound.Width / formattedText.Width;
			_scaleTransform.ScaleY = bound.Height / formattedText.Height;
			_textDrawing.Geometry = formattedText.BuildGeometry(point);
		}
Пример #20
0
 private static Geometry MakeCharacterGeometry(string t)
 {
     var fText = new FormattedText(
         t,
         CultureInfo.CurrentCulture,
         FlowDirection.LeftToRight,
         new Typeface(
             new FontFamily(Properties.Settings.Default.FontFamily),
             FontStyles.Normal,
             FontWeights.Heavy,
             FontStretches.Normal),
         300,
         Brushes.Black
         );
     return fText.BuildGeometry(new Point(0, 0)).GetAsFrozen() as Geometry;
 }
		protected override void OnTextPropertyChanged(DependencyPropertyChangedEventArgs args)
		{
			if (string.IsNullOrEmpty(base.Text))
			{
				this.flattenedTextPathGeometry = null;
			}
			else
			{
				FormattedText formattedText = new FormattedText(base.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, this.typeface, 100.0, base.Foreground);
				this.textLength = formattedText.Width;
				this.baseline = formattedText.Baseline;
				Geometry geometry = formattedText.BuildGeometry(default(Point));
				this.flattenedTextPathGeometry = PathGeometry.CreateFromGeometry(geometry).GetFlattenedPathGeometry();
				this.warpedTextPathGeometry = this.flattenedTextPathGeometry.CloneCurrentValue();
				this.GenerateWarpedGeometry();
			}
		}
Пример #22
0
        /// <summary>
        ///     This method creates the text geometry.
        /// </summary>
        private void CreateTextGeometry()
        {
            var formattedText = new FormattedText(Text,
                Thread.CurrentThread.CurrentUICulture,
                FlowDirection.LeftToRight,
                new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
                FontSize,
                Brushes.Black);

            var textGeometry = formattedText.BuildGeometry(Origin);
            if (FauxBold)
            {
                _textGeometry = Geometry.Combine(textGeometry,
                    textGeometry.GetWidenedPathGeometry(new Pen(Stroke, StrokeThickness)),
                    GeometryCombineMode.Union,
                    null);
            }
            else
            {
                _textGeometry = textGeometry;
            }
        }
Пример #23
0
        private static Brush CreateFaceBrush(Color c, string text)
        {
            var db = new DrawingBrush
            {
                TileMode = TileMode.None,
                ViewportUnits = BrushMappingMode.Absolute,
                Viewport = new Rect(0, 0, 1, 1),
                Viewbox = new Rect(0, 0, 1, 1),
                ViewboxUnits = BrushMappingMode.Absolute
            };
            var dg = new DrawingGroup();
            dg.Children.Add(new GeometryDrawing { Geometry = new RectangleGeometry(new Rect(0, 0, 1, 1)), Brush = Brushes.Black });
            dg.Children.Add(new GeometryDrawing
                                {
                                    Geometry = new RectangleGeometry(new Rect(0.05, 0.05, 0.9, 0.9)) { RadiusX = 0.05, RadiusY = 0.05 },
                                    Brush = new SolidColorBrush(c)
                                });

            if (text != null)
            {
                var ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                                           new Typeface("Segoe UI"), 0.3, Brushes.Black);
                ft.TextAlignment = TextAlignment.Center;
                var geometry = ft.BuildGeometry(new Point(0, -0.2));
                var tg = new TransformGroup();
                tg.Children.Add(new RotateTransform(45));
                tg.Children.Add(new TranslateTransform(0.5, 0.5));
                geometry.Transform = tg;
                dg.Children.Add(new GeometryDrawing
                                    {
                                        Geometry = geometry,
                                        Brush = Brushes.Black

                                    });
            }
            db.Drawing = dg;
            return db;
        }
        public PlanetRender( Planet planet )
        {
            EllipseGeometry planetGeom;
            FormattedText text;
            Geometry textGeom;

            double radius = Math.Sqrt(planet.GrowthRate) / c_RadiusScale; /* Area proportional to growth rate */

            planetGeom = new EllipseGeometry(new Point(planet.X, planet.Y), radius, radius);
            m_gg.Children.Add(planetGeom);

            text = new FormattedText(
                planet.ShipCount.ToString(),
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface("Tahoma"),
                radius < 0.6 ? 0.6 : radius,
                Brushes.Black);
            textGeom = text.BuildGeometry(new Point(planet.X - text.Width / 2, planet.Y - text.Height / 2));

            m_gg.Children.Add(textGeom);

            m_gg.Freeze(  );
        }
Пример #25
0
        private void DrawTextLabels(Point leftTop, Point rightBottom,
            double minValueX, double stepX, double graphStepX,
            double minValueY, double stepY, double graphStepY,
            Path path)
        {
            double x = leftTop.X + 10;
            double y = leftTop.Y + 15;
            var geometryGroup = new GeometryGroup();
            
            while (y <= rightBottom.Y)
            {
                var text = new FormattedText(minValueY.ToString(minValueY > 2 ? "###" : "##.###"),
                    CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                    new Typeface("Arial"), 10,
                    Brushes.Black);
                geometryGroup.Children.Add(text.BuildGeometry(new Point(10, rightBottom.Y - y)));
                y += graphStepY;
                minValueY += stepY;
            }

            y = rightBottom.Y - 15;
            while (x <= rightBottom.X)
            {
                var text = new FormattedText(minValueX.ToString(minValueX > 2 ? "###" : "##.###"),
                    CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                    new Typeface("Arial"), 10,
                    Brushes.Black);
                geometryGroup.Children.Add(text.BuildGeometry(new Point(x, y)));
                x += graphStepX;
                minValueX += stepX;
            }
            if (path.Data != null)
                geometryGroup.Children.Add(path.Data);

            path.Data = geometryGroup;
        }
Пример #26
0
        private void BuildGeometries()
        {
            // Create Type face
            Typeface typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch);

            // Create text
            FormattedText formattedText = new FormattedText(
                Text,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                typeface,
                FontSize,
                Brushes.Black
            );

            // Find point based on alignment
            _textGeometry = formattedText.BuildGeometry(new Point(0, 0));
        }
Пример #27
0
        private void drawUnits(DrawingContext dc)
        {
            Coordonnee currentUnit = SmallWorld.Instance.getUniteCourante().coordonnees;
            SolidColorBrush scb = Brushes.Red;
            int x = (currentUnit.getX() - 1) * imgSize;
            int y = (currentUnit.getY() - 1) * imgSize;
            Pen p = new Pen(scb, 3);
            dc.DrawLine(p, new Point(x, y), new Point(x + imgSize, y));
            dc.DrawLine(p, new Point(x + imgSize, y), new Point(x + imgSize, y + imgSize));
            dc.DrawLine(p, new Point(x + imgSize, y + imgSize), new Point(x, y + imgSize));
            dc.DrawLine(p, new Point(x, y + imgSize), new Point(x, y));

            foreach (Joueur joueur in SmallWorld.Instance.joueurs)
            {
                foreach (Unite unite in joueur.getUnites())
                {
                    Coordonnee coords = unite.coordonnees;
                    int ellipseX = (coords.getX() - 1) * imgSize + 9;
                    int ellipseY = (coords.getY() - 1) * imgSize + 9;

                    dc.DrawImage(App.getImageFromPeuple(joueur.Peuple), new Rect(ellipseX, ellipseY, 32, 32));

                    int nb = SmallWorld.Instance.carte.getNombreUnites(coords);

                    if (nb > 1)
                    {
                        FormattedText text = new FormattedText(nb.ToString(),
                            CultureInfo.GetCultureInfo("fr-fr"),
                            FlowDirection.LeftToRight,
                            new Typeface("Verdana"),
                            15,
                            Brushes.White);
                        Geometry border = text.BuildGeometry(new Point(ellipseX - 5, ellipseY - 10));
                        dc.DrawGeometry(null, new Pen(Brushes.Black, 3), border);
                        dc.DrawText(text, new Point(ellipseX - 5, ellipseY - 10));
                    }
                }
            }
        }
Пример #28
0
 private void DrawText(Canvas canvas, Point centre, float arcRadius, int i, float rotationAngle)
 {
     var text = new FormattedText((1 + i).ToString(), CultureInfo.CurrentUICulture, FlowDirection, _typeFace, FontSize, _whiteColour);
     var textLocation = new Point
     {
         X = centre.X + ((arcRadius / 1.5) * (float)Math.Cos(rotationAngle * Math.PI / 180f)) - (text.Width / 2),
         Y = centre.Y + ((arcRadius / 1.5) * (float)Math.Sin(rotationAngle * Math.PI / 180f)) - (text.Height / 2),
     };
     var geometry = text.BuildGeometry(textLocation);
     var path = new System.Windows.Shapes.Path() { Data = geometry, Fill = _whiteColour };
     canvas.Children.Add(path);
 }
        public void CreateText()
        {
            FontStyle fontStyle = FontStyles.Normal;
            FontWeight fontWeight = FontWeights.Medium;

            if (Bold)
                fontWeight = FontWeights.Bold;
            if (Italic)
                fontStyle = FontStyles.Italic;

            var formattedText = new FormattedText(
                Text,
                CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.Name),
                FlowDirection.LeftToRight,
                new Typeface(FontFamily, fontStyle, fontWeight, FontStretches.Normal),
                FontSize,
                Brushes.Black // This brush does not matter since we use the geometry of the text.
                );

            _textGeometry = formattedText.BuildGeometry(new Point(0, 0));
            MinWidth = formattedText.Width;
            MinHeight = formattedText.Height;
        }
Пример #30
0
        public override void RenderTextRun(SvgTextContentElement element, ref Point ctp,
            string text, double rotate, WpfTextPlacement placement)
        {
            if (String.IsNullOrEmpty(text))
                return;

            double emSize         = GetComputedFontSize(element);
            FontFamily fontFamily = GetTextFontFamily(element, emSize);

            FontStyle fontStyle   = GetTextFontStyle(element);
            FontWeight fontWeight = GetTextFontWeight(element);

            FontStretch fontStretch = GetTextFontStretch(element);

            WpfTextStringFormat stringFormat = GetTextStringFormat(element);

            // Fix the use of Postscript fonts...
            WpfFontFamilyVisitor fontFamilyVisitor = _drawContext.FontFamilyVisitor;
            if (!String.IsNullOrEmpty(_actualFontName) && fontFamilyVisitor != null)
            {
                WpfFontFamilyInfo currentFamily = new WpfFontFamilyInfo(fontFamily, fontWeight,
                    fontStyle, fontStretch);
                WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName,
                    currentFamily,_drawContext);
                if (familyInfo != null && !familyInfo.IsEmpty)
                {
                    fontFamily  = familyInfo.Family;
                    fontWeight  = familyInfo.Weight;
                    fontStyle   = familyInfo.Style;
                    fontStretch = familyInfo.Stretch;
                }
            }

            WpfSvgPaint fillPaint = new WpfSvgPaint(_drawContext, element, "fill");
            Brush textBrush = fillPaint.GetBrush();

            WpfSvgPaint strokePaint = new WpfSvgPaint(_drawContext, element, "stroke");
            Pen textPen = strokePaint.GetPen();

            if (textBrush == null && textPen == null)
            {
                return;
            }
            else if (textBrush == null)
            {
                // If here, then the pen is not null, and so the fill cannot be null.
                // We set this to transparent for stroke only text path...
                textBrush = Brushes.Transparent;
            }

            TextDecorationCollection textDecors = GetTextDecoration(element);
            if (textDecors == null)
            {
                SvgTextElement textElement = element.ParentNode as SvgTextElement;

                if (textElement != null)
                {
                    textDecors = GetTextDecoration(textElement);
                }
            }

            TextAlignment alignment = stringFormat.Alignment;

            bool hasWordSpacing  = false;
            string wordSpaceText = element.GetAttribute("word-spacing");
            double wordSpacing = 0;
            if (!String.IsNullOrEmpty(wordSpaceText) &&
                Double.TryParse(wordSpaceText, out wordSpacing) && (float)wordSpacing != 0)
            {
                hasWordSpacing = true;
            }

            bool hasLetterSpacing = false;
            string letterSpaceText = element.GetAttribute("letter-spacing");
            double letterSpacing = 0;
            if (!String.IsNullOrEmpty(letterSpaceText) &&
                Double.TryParse(letterSpaceText, out letterSpacing) && (float)letterSpacing != 0)
            {
                hasLetterSpacing = true;
            }

            bool isRotatePosOnly = false;

            IList<WpfTextPosition> textPositions = null;
            int textPosCount = 0;
            if ((placement != null && placement.HasPositions))
            {
                textPositions   = placement.Positions;
                textPosCount    = textPositions.Count;
                isRotatePosOnly = placement.IsRotateOnly;
            }

            if (hasLetterSpacing || hasWordSpacing || textPositions != null)
            {
                double spacing = Convert.ToDouble(letterSpacing);
                for (int i = 0; i < text.Length; i++)
                {
                    FormattedText formattedText = new FormattedText(new string(text[i], 1),
                        _drawContext.CultureInfo, stringFormat.Direction,
                        new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                        emSize, textBrush);

                    if (this.IsMeasuring)
                    {
                        this.AddTextWidth(formattedText.WidthIncludingTrailingWhitespace);
                        continue;
                    }

                    formattedText.Trimming      = stringFormat.Trimming;
                    formattedText.TextAlignment = stringFormat.Alignment;

                    if (textDecors != null && textDecors.Count != 0)
                    {
                        formattedText.SetTextDecorations(textDecors);
                    }

                    WpfTextPosition? textPosition = null;
                    if (textPositions != null && i < textPosCount)
                    {
                        textPosition = textPositions[i];
                    }

                    //float xCorrection = 0;
                    //if (alignment == TextAlignment.Left)
                    //    xCorrection = emSize * 1f / 6f;
                    //else if (alignment == TextAlignment.Right)
                    //    xCorrection = -emSize * 1f / 6f;

                    double yCorrection = formattedText.Baseline;

                    float rotateAngle = (float)rotate;
                    if (textPosition != null)
                    {
                        if (!isRotatePosOnly)
                        {
                            Point pt = textPosition.Value.Location;
                            ctp.X = pt.X;
                            ctp.Y = pt.Y;
                        }
                        rotateAngle = (float)textPosition.Value.Rotation;
                    }
                    Point textStart = ctp;

                    RotateTransform rotateAt = null;
                    if (rotateAngle != 0)
                    {
                        rotateAt = new RotateTransform(rotateAngle, textStart.X, textStart.Y);
                        _textContext.PushTransform(rotateAt);
                    }

                    Point textPoint = new Point(ctp.X, ctp.Y - yCorrection);

                    if (textPen != null || _drawContext.TextAsGeometry)
                    {
                        Geometry textGeometry = formattedText.BuildGeometry(textPoint);
                        if (textGeometry != null && !textGeometry.IsEmpty())
                        {
                            _textContext.DrawGeometry(textBrush, textPen,
                                ExtractTextPathGeometry(textGeometry));

                            this.IsTextPath = true;
                        }
                        else
                        {
                            _textContext.DrawText(formattedText, textPoint);
                        }
                    }
                    else
                    {
                        _textContext.DrawText(formattedText, textPoint);
                    }

                    //float bboxWidth = (float)formattedText.Width;
                    double bboxWidth = formattedText.WidthIncludingTrailingWhitespace;
                    if (alignment == TextAlignment.Center)
                        bboxWidth /= 2f;
                    else if (alignment == TextAlignment.Right)
                        bboxWidth = 0;

                    //ctp.X += bboxWidth + emSize / 4 + spacing;
                    if (hasLetterSpacing)
                    {
                        ctp.X += bboxWidth + letterSpacing;
                    }
                    if (hasWordSpacing && Char.IsWhiteSpace(text[i]))
                    {
                        if (hasLetterSpacing)
                        {
                            ctp.X += wordSpacing;
                        }
                        else
                        {
                            ctp.X += bboxWidth + wordSpacing;
                        }
                    }
                    else
                    {
                        if (!hasLetterSpacing)
                        {
                            ctp.X += bboxWidth;
                        }
                    }

                    if (rotateAt != null)
                    {
                        _textContext.Pop();
                    }
                }
            }
            else
            {
                FormattedText formattedText = new FormattedText(text, _drawContext.CultureInfo,
                    stringFormat.Direction, new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                    emSize, textBrush);

                if (this.IsMeasuring)
                {
                    this.AddTextWidth(formattedText.WidthIncludingTrailingWhitespace);
                    return;
                }

                if (alignment == TextAlignment.Center && this.TextWidth > 0)
                {
                    alignment = TextAlignment.Left;
                }

                formattedText.TextAlignment = alignment;
                formattedText.Trimming      = stringFormat.Trimming;

                if (textDecors != null && textDecors.Count != 0)
                {
                    formattedText.SetTextDecorations(textDecors);
                }

                //float xCorrection = 0;
                //if (alignment == TextAlignment.Left)
                //    xCorrection = emSize * 1f / 6f;
                //else if (alignment == TextAlignment.Right)
                //    xCorrection = -emSize * 1f / 6f;

                double yCorrection = formattedText.Baseline;

                float rotateAngle  = (float)rotate;
                Point textPoint    = new Point(ctp.X, ctp.Y - yCorrection);

                RotateTransform rotateAt = null;
                if (rotateAngle != 0)
                {
                    rotateAt = new RotateTransform(rotateAngle, ctp.X, ctp.Y);
                    _textContext.PushTransform(rotateAt);
                }

                if (textPen != null || _drawContext.TextAsGeometry)
                {
                    Geometry textGeometry = formattedText.BuildGeometry(textPoint);
                    if (textGeometry != null && !textGeometry.IsEmpty())
                    {
                        _textContext.DrawGeometry(textBrush, textPen,
                            ExtractTextPathGeometry(textGeometry));

                        this.IsTextPath = true;
                    }
                    else
                    {
                        _textContext.DrawText(formattedText, textPoint);
                    }
                }
                else
                {
                    _textContext.DrawText(formattedText, textPoint);
                }

                //float bboxWidth = (float)formattedText.Width;
                double bboxWidth = formattedText.WidthIncludingTrailingWhitespace;
                if (alignment == TextAlignment.Center)
                    bboxWidth /= 2f;
                else if (alignment == TextAlignment.Right)
                    bboxWidth = 0;

                //ctp.X += bboxWidth + emSize / 4;
                ctp.X += bboxWidth;

                if (rotateAt != null)
                {
                    _textContext.Pop();
                }
            }
        }
Пример #31
0
        // Draw a string with shadow or line framing effects, if specified. The font from this symdef is used.
        private void DrawStringWithEffects(GraphicsTarget g, SymColor color, string text, PointF pt)
        {
            if (color == fontColor) {
                DrawSingleLineString(g, text, fontColor.Brush, pt);
            }

            if (framing.framingStyle != FramingStyle.None && color == framing.framingColor) {
                if (framing.framingStyle == FramingStyle.Line) {
            #if false
                    FormattedText formattedText = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black);
                    Geometry geometry = formattedText.BuildGeometry(new Point(pt.X, pt.Y));
                    foreach (Pen p in framingPens)
                        g.DrawingContext.DrawGeometry(null, p, geometry);
            #else
                    GraphicsPath grPath = new GraphicsPath(FillMode.Winding);
                    Debug.Assert(font.Unit == GraphicsUnit.World);
                    grPath.AddString(text, font.FontFamily, (int) font.Style, font.Size, pt, stringFormat);

                    foreach (Pen p in framingPens)
                        g.Graphics.DrawPath(p, grPath);
            #endif
                }
                else if (framing.framingStyle == FramingStyle.Shadow) {
                    DrawSingleLineString(g, text, framing.framingColor.Brush, new PointF(pt.X + framing.shadowX, pt.Y - framing.shadowY));
                }
            }
        }
Пример #32
0
        public void Render(double bpm, double ratio)
        {
            using (DrawingContext dc = rDg.Open())
            {
                dc.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, 200, 200));
                dc.DrawRectangle(Brushes.White, null,
                    new Rect(180 * (ratio <= 0.5 ? ratio : 1.0 - ratio) * 2,
                        200 / 2.0 - 10, 20, 20));

                FormattedText text = new FormattedText(
                    bpm.ToString("F1"), System.Globalization.CultureInfo.CurrentCulture,
                    FlowDirection.LeftToRight, new Typeface("Consolas"), 32, Brushes.Blue);
                Point p = new Point(10, 10);
                Geometry g = text.BuildGeometry(p);
                PathGeometry pg = g.GetOutlinedPathGeometry();
                dc.DrawGeometry(Brushes.Blue, new Pen(Brushes.White, 4), g);
                dc.DrawGeometry(Brushes.Blue, null, g);
            }
        }