当前位置: 首页>>代码示例>>C#>>正文


C# FormattedText.BuildGeometry方法代码示例

本文整理汇总了C#中System.Windows.Media.FormattedText.BuildGeometry方法的典型用法代码示例。如果您正苦于以下问题:C# FormattedText.BuildGeometry方法的具体用法?C# FormattedText.BuildGeometry怎么用?C# FormattedText.BuildGeometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.FormattedText的用法示例。


在下文中一共展示了FormattedText.BuildGeometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawHelpText

        /// <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);
        }
开发者ID:biki3507,项目名称:FreeCapture,代码行数:30,代码来源:CaptureSurface.cs

示例2: DrawFormattedText

        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;
        }
开发者ID:blinds52,项目名称:WPF-Samples,代码行数:35,代码来源:MainWindow.xaml.cs

示例3: Transform

		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);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:31,代码来源:TextBlockPainter.cs

示例4: FleetRender

        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();
        }
开发者ID:mt-inside,项目名称:Google-AI-Challenge-2010,代码行数:31,代码来源:FleetRender.cs

示例5: CreateText

        /// <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;

        }
开发者ID:step4u,项目名称:CallService,代码行数:32,代码来源:OutlinedText.cs

示例6: Read

        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);
        }
开发者ID:ste10k41,项目名称:nettopologysuite,代码行数:8,代码来源:FontGlyphReader.cs

示例7: DrawText

 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);
 }
开发者ID:W0dan,项目名称:physicsExperiments,代码行数:9,代码来源:DrawingGroupExtensions.cs

示例8: CreateTextGeometry

 /// <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);
 }
开发者ID:cedianoost,项目名称:3DS-Theme-Editor,代码行数:13,代码来源:TextPath.cs

示例9: GetOutlinedText

		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;
		}
开发者ID:ChuckJrster,项目名称:Hearthstone-Deck-Tracker,代码行数:19,代码来源:CardTextImageBuilder.cs

示例10: ProvideValue

        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));
        }
开发者ID:SmartFire,项目名称:LogWatch,代码行数:12,代码来源:TextGeometry.cs

示例11: MakeCharacterGeometry

 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;
 }
开发者ID:katu07,项目名称:babysmash,代码行数:13,代码来源:CoolLetter.xaml.cs

示例12: DrawBoldText

        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);
        }
开发者ID:samuto,项目名称:designscript,代码行数:14,代码来源:Utilities.cs

示例13: Text2Path

        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();
        }
开发者ID:stevenh77,项目名称:Text2Path,代码行数:14,代码来源:MainWindow.xaml.cs

示例14: ProvideValue

        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;
        }
开发者ID:JackWangCUMT,项目名称:Plainion.Whiteboard,代码行数:14,代码来源:TextGeometryExtension.cs

示例15: Text2Path

        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();
        }
开发者ID:waynebaby,项目名称:Code-For-Fun,代码行数:49,代码来源:TextToPathService.cs


注:本文中的System.Windows.Media.FormattedText.BuildGeometry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。