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


C# DrawingGroup.Open方法代码示例

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


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

示例1: Convert

		public object Convert (object [] values, Type targetType, object parameter, CultureInfo culture)
		{
			Brush foreground;
			//FIXME: How is it used?
			bool is_indeterminate;
			double indicator_lenght_in_orientation_direction;
			double indicator_lenght_in_other_direction;
			double track_lenght_in_orientation_direction;
			try {
				foreground = (Brush)values [0];
				is_indeterminate = (bool)values [1];
				indicator_lenght_in_orientation_direction = (double)values [2];
				indicator_lenght_in_other_direction = (double)values [3];
				track_lenght_in_orientation_direction = (double)values [4];
			} catch (InvalidCastException) {
				return null;
			}
			const double LineWidth = 6;
			const double LineSpacing = 2;
			DrawingGroup drawing = new DrawingGroup ();
			DrawingContext drawing_context = drawing.Open ();
			int lines = (int)Math.Ceiling (indicator_lenght_in_orientation_direction / (LineWidth + LineSpacing));
			int line_index;
			for (line_index = 0; line_index < lines - 1; line_index++)
				drawing_context.DrawRectangle (foreground, null, new Rect (line_index * (LineWidth + LineSpacing), 0, LineWidth, indicator_lenght_in_other_direction));
			drawing_context.DrawRectangle (foreground, null, new Rect (line_index * (LineWidth + LineSpacing), 0, indicator_lenght_in_orientation_direction - (lines - 1) * (LineWidth + LineSpacing), indicator_lenght_in_other_direction));
			drawing_context.Close ();
			DrawingBrush result = new DrawingBrush (drawing);
			result.Stretch = Stretch.None;
			result.Viewbox = new Rect (new Size (indicator_lenght_in_orientation_direction, indicator_lenght_in_other_direction));
			result.Viewport = result.Viewbox;
			return result;
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:33,代码来源:ProgressBarBrushConverter.cs

示例2: SelectionRectVisual

        /// <summary>
        /// Construct new SelectionRectVisual object for the given rectangle
        /// </summary>
        public SelectionRectVisual(Point firstPointP, Point secondPointP, double zoomP)
        {
            DrawingGroup drawing = new DrawingGroup();
            DrawingContext context = drawing.Open();
            context.DrawRectangle(Brushes.White, null, new Rect(-1, -1, 3, 3));
            context.DrawRectangle(Brushes.Black, null, new Rect(0.25, -1, 0.5, 3));
            context.Close();
            drawing.Freeze();

            // Create a drawing brush that tiles the unit square from the drawing created above.
            // The size of the viewport and the rotation angle will be updated as we use the
            // dashed pen.
            DrawingBrush drawingBrush = new DrawingBrush(drawing);
            drawingBrush.ViewportUnits = BrushMappingMode.Absolute;
            drawingBrush.Viewport = new Rect(0, 0, _dashRepeatLength, _dashRepeatLength);
            drawingBrush.ViewboxUnits = BrushMappingMode.Absolute;
            drawingBrush.Viewbox = new Rect(0, 0, 1, 1);
            drawingBrush.Stretch = Stretch.Uniform;
            drawingBrush.TileMode = TileMode.Tile;

            // Store the drawing brush and a copy that's rotated by 90 degrees.
            _horizontalDashBrush = drawingBrush;
            _verticalDashBrush = drawingBrush.Clone();
            _verticalDashBrush.Transform = new RotateTransform(90);

            this._firstPoint = firstPointP;
            this._secondPoint = secondPointP;
            this._zoom = zoomP;
            _visualForRect = new DrawingVisual();
            this.AddVisualChild(_visualForRect);
            this.AddLogicalChild(_visualForRect);      
        }
开发者ID:hultqvist,项目名称:Eto,代码行数:35,代码来源:SelectionRectVisual.cs

示例3: BitmapToDrawing

        public static Drawing BitmapToDrawing(BitmapSource bitmap)
        {
            var dg = new DrawingGroup();

            using (var dc = dg.Open())
            {
                dc.DrawImage(bitmap, new Rect(0, 0, 100, 100));
            }

            return dg;
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:11,代码来源:TileSetHelpers.cs

示例4: DrawBackground

 private void DrawBackground(Image image)
 {
     var drawingGroup = new DrawingGroup();
     var imageSource = new DrawingImage(drawingGroup);
     image.Source = imageSource;
     using (DrawingContext dc = drawingGroup.Open())
     {
         dc.DrawRectangle(BackgroundBrush, null, new Rect(0, 0, pwidth, pheight));
         for (int x = 0; x <= pwidth; x += ppgridLine)
         {
             dc.DrawLine(linePen, new Point(x, 0), new Point(x, pheight));
         }
         for (int y = 0; y <= pheight; y += ppgridLine)
         {
             dc.DrawLine(linePen, new Point(0, y), new Point(pwidth, y));
         }
     }
 }
开发者ID:virrkharia,项目名称:dynamight,代码行数:18,代码来源:OverviewWindow.xaml.cs

示例5: NormalizeDrawing

        static Drawing NormalizeDrawing(Drawing drawing, Point location, Size size, double angle)
        {
            DrawingGroup dGroup = new DrawingGroup();
            using (DrawingContext dc = dGroup.Open())
            {
                dc.DrawRectangle(Brushes.Transparent, null, new Rect(new Size(100, 100)));

                dc.PushTransform(new RotateTransform(angle, 50, 50));
                dc.PushTransform(new TranslateTransform(location.X, location.Y));
                dc.PushTransform(new ScaleTransform(size.Width / drawing.Bounds.Width, size.Height / drawing.Bounds.Height));
                dc.PushTransform(new TranslateTransform(-drawing.Bounds.Left, -drawing.Bounds.Top));

                dc.DrawDrawing(drawing);

                dc.Pop();
                dc.Pop();
                dc.Pop();
                dc.Pop();
            }

            return dGroup;
        }
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:22,代码来源:SymbolDrawingCache.cs

示例6: Convert

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Type type = typeof(double);
            if ((((values == null) || (values.Length != 3)) || ((values[0] == null) || (values[1] == null))) || (((values[2] == null) || !typeof(Brush).IsAssignableFrom(values[0].GetType())) || (!type.IsAssignableFrom(values[1].GetType()) || !type.IsAssignableFrom(values[2].GetType()))))
            {
                return null;
            }
            Brush brush = (Brush)values[0];
            double d = (double)values[1];
            double num2 = (double)values[2];
            if ((((d <= 0) || double.IsInfinity(d)) || (double.IsNaN(d) || (num2 <= 0))) || (double.IsInfinity(num2) || double.IsNaN(num2)))
            {
                return null;
            }
            DrawingBrush brush2 = new DrawingBrush();
            double width = d * 2;
            brush2.Viewport = brush2.Viewbox = new Rect(-d, 0, width, num2);
            brush2.ViewportUnits = brush2.ViewboxUnits = BrushMappingMode.Absolute;
            brush2.TileMode = TileMode.None;
            brush2.Stretch = Stretch.None;
            DrawingGroup group = new DrawingGroup();
            DrawingContext context = group.Open();
            context.DrawRectangle(brush, null, new Rect(-d, 0, d, num2));
            TimeSpan keyTime = TimeSpan.FromSeconds(width / 200);
            TimeSpan span2 = TimeSpan.FromSeconds(1);
            DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();
            animation.BeginTime = new TimeSpan?(TimeSpan.Zero);
            animation.Duration = new Duration(keyTime + span2);
            animation.RepeatBehavior = RepeatBehavior.Forever;

            animation.KeyFrames.Add(new LinearDoubleKeyFrame(width, keyTime));
            TranslateTransform transform = new TranslateTransform();
            transform.BeginAnimation(TranslateTransform.XProperty, animation);
            brush2.Transform = transform;
            context.Close();
            brush2.Drawing = group;
            return brush2;
        }
开发者ID:alexsharoff,项目名称:wpf-office-theme,代码行数:38,代码来源:ProgressBarHighlightConverter.cs

示例7: BeforeRender

        public override void BeforeRender(WpfDrawingRenderer renderer)
        {
            _isTextPath   = false;
            _isGroupAdded = false;
            _textWidth    = 0;
            _isMeasuring  = false;

            WpfDrawingContext context = renderer.Context;

            SvgRenderingHint hint = _svgElement.RenderingHint;
            if (hint == SvgRenderingHint.Clipping)
            {
                return;
            }
            // We do not directly render the contents of the clip-path, unless specifically requested...
            if (String.Equals(_svgElement.ParentNode.LocalName, "clipPath") &&
                !context.RenderingClipRegion)
            {
                return;
            }

            string sVisibility = _textElement.GetPropertyValue("visibility");
            string sDisplay    = _textElement.GetPropertyValue("display");
            if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none"))
            {
                return;
            }

            _context = renderer.Context;

            SetQuality(context);
            SetTransform(context);

            SetClip(_context);

            SetMask(_context);

            _drawGroup = new DrawingGroup();

            string elementId = this.GetElementName();
            if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId))
            {
                _drawGroup.SetValue(FrameworkElement.NameProperty, elementId);

                context.RegisterId(elementId);

                if (context.IncludeRuntime)
                {
                    SvgObject.SetId(_drawGroup, elementId);
                }
            }

            Transform textTransform = this.Transform;
            if (textTransform != null && !textTransform.Value.IsIdentity)
            {
                _drawGroup.Transform = textTransform;
            }
            else
            {
                textTransform = null; // render any identity transform useless...
            }
            Geometry textClip = this.ClipGeometry;
            if (textClip != null && !textClip.IsEmpty())
            {
                _drawGroup.ClipGeometry = textClip;
            }
            else
            {
                textClip = null; // render any empty geometry useless...
            }
            Brush textMask = this.Masking;
            if (textMask != null)
            {
                _drawGroup.OpacityMask = textMask;
            }

            if (textTransform != null || textClip != null || textMask != null)
            {
                DrawingGroup curGroup = _context.Peek();
                Debug.Assert(curGroup != null);
                if (curGroup != null)
                {
                    curGroup.Children.Add(_drawGroup);
                    context.Push(_drawGroup);

                    _isGroupAdded = true;
                }
            }

            _drawContext = _drawGroup.Open();

            _horzRenderer.Initialize(_drawContext, _context);
            _vertRenderer.Initialize(_drawContext, _context);
            _pathRenderer.Initialize(_drawContext, _context);
        }
开发者ID:udayanroy,项目名称:SvgSharp,代码行数:95,代码来源:WpfTextRendering.cs

示例8: DrawImage

        //drawing color image and skeleton
        private DrawingImage DrawImage(ColorImageFrame colorFrame, WagSkeleton[] skeletons)
        {
            DrawingGroup dgColorImageAndSkeleton = new DrawingGroup();
              DrawingImage drawingImage = new DrawingImage(dgColorImageAndSkeleton);
              skeletonDrawer = new SkeletonDrawer(KinectSensor);

              using (DrawingContext drawingContext = dgColorImageAndSkeleton.Open())
              {
            InitializeDrawingImage(colorFrame, drawingContext);

            if (skeletons != null && skeletons.Count() > 0)
            {
              foreach (WagSkeleton skeleton in skeletons)
              {
            if (skeleton.FramesNotSeen > 0 && !(VisitorCtr.IsBlocked && skeleton.TrackingId == ClosestVisitor.TrackingId))
              continue;

            skeletonDrawer.DrawUpperSkeleton(skeleton, drawingContext);

            Joint head = skeleton.Joints.SingleOrDefault(temp => temp.JointType == JointType.Head);
            System.Windows.Point headP = skeletonDrawer.SkeletonPointToScreen(head.Position);
            headP.X -= 30; //These two hardcoded numbers are the displacements in X,Y of the white box content holder
            headP.Y -= 25;
            drawingContext.DrawRectangle(Brushes.White, new Pen(Brushes.White, 1), new System.Windows.Rect(headP, new Size(100, 100)));

            //FormattedText
            drawingContext.DrawText(
                new FormattedText(
                  String.Format("ID: {0}", skeleton.TrackingId),
                  CultureInfo.GetCultureInfo("en-us"),
                  FlowDirection.LeftToRight, new Typeface("Verdana"), 15, System.Windows.Media.Brushes.Red),
                headP);

            if (STimSettings.IncludeStatusRender)
            {
              System.Windows.Point socialDataPos = headP;
              socialDataPos.Y = headP.Y + 25;
              drawingContext.DrawText(
                  new FormattedText(
                    skeleton.AttentionSocial.ToString(),
                    CultureInfo.GetCultureInfo("en-us"),
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 15, System.Windows.Media.Brushes.Green),
                  socialDataPos);

              System.Windows.Point simpleDataPos = headP;
              simpleDataPos.Y = socialDataPos.Y + 30;
              drawingContext.DrawText(
                  new FormattedText(
                    skeleton.AttentionSimple.ToString(),
                    CultureInfo.GetCultureInfo("en-us"),
                    FlowDirection.LeftToRight, new Typeface("Verdana"), 15, System.Windows.Media.Brushes.Green),
                  simpleDataPos);
            }
              }
            }
              }

              //Make sure the image remains within the defined width and height
              dgColorImageAndSkeleton.ClipGeometry = new RectangleGeometry(new System.Windows.Rect(0.0, 0.0, Constants.RENDER_WIDTH, Constants.RENDER_HEIGHT));
              return drawingImage;
        }
开发者ID:hcilab-um,项目名称:STim,代码行数:62,代码来源:Core.cs

示例9: BuildGeometry

        /// <summary>
        /// Obtains geometry for the text, including underlines and strikethroughs. 
        /// </summary>
        /// <param name="origin">The left top origin of the resulting geometry.</param>
        /// <returns>The geometry returned contains the combined geometry
        /// of all of the glyphs, underlines and strikeThroughs that represent the formatted text.
        /// Overlapping contours are merged by performing a Boolean union operation.</returns>
        public Geometry BuildGeometry(Point origin)
        {
            GeometryGroup accumulatedGeometry = null;
            Point lineOrigin = origin;

            DrawingGroup drawing = new DrawingGroup();
            DrawingContext ctx = drawing.Open();

            // we can't use foreach because it requires GetEnumerator and associated classes to be public
            // foreach (TextLine currentLine in this)

            using (LineEnumerator enumerator = GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    using (TextLine currentLine = enumerator.Current)
                    {
                        currentLine.Draw(ctx, lineOrigin, InvertAxes.None);
                        AdvanceLineOrigin(ref lineOrigin, currentLine);
                    }
                }
            }

            ctx.Close();

            //  recursively go down the DrawingGroup to build up the geometry
            CombineGeometryRecursive(drawing, ref accumulatedGeometry);

            // Make sure to always return Geometry.Empty from public methods for empty geometries.
            if (accumulatedGeometry == null || accumulatedGeometry.IsEmpty())
                return Geometry.Empty;
            return accumulatedGeometry;
        }        
开发者ID:JianwenSun,项目名称:cc,代码行数:40,代码来源:FormattedText.cs

示例10: MeasureLines

        public static IEnumerable<TextLine> MeasureLines(string text, int width, TextParagraphProperties format, DrawingGroup drawTarget)
        {
            using (var dc = drawTarget.Open())
            using (var formatter = TextFormatter.Create()) {
                int index = 0;
                double y = 0;

                var source = new BasicSource(text, format.DefaultTextRunProperties);
                while (index < text.Length) {
                    var line = formatter.FormatLine(source, index, width, format, null);
                    line.Draw(dc, new Point(0, y), InvertAxes.None);
                    y += line.Height;
                    index += line.Length;

                    yield return line;
                }
            }
        }
开发者ID:Amichai,项目名称:Prax,代码行数:18,代码来源:Measurer.cs

示例11: GetVectorGfx

        Drawing GetVectorGfx(VectorGfxBase gfx)
        {
            if (gfx is CharGfx)
            {
                var g = (CharGfx)gfx;
                var drawing = CreateCharDrawing(g);
                return drawing;
            }
            else if (gfx is DrawingGfx)
            {
                var g = (DrawingGfx)gfx;
                var drawing = CreateVectorDrawing(g);
                return drawing;
            }
            else if (gfx is CombinedGfx)
            {
                var g = (CombinedGfx)gfx;

                var dg = new DrawingGroup();
                using (var dc = dg.Open())
                {
                    foreach (var bs in g.Symbols)
                    {
                        var t = GetVectorGfx(bs);
                        dc.DrawDrawing(t);
                    }
                }

                return dg;
            }
            else
            {
                throw new Exception();
            }
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:35,代码来源:TileSet.cs

示例12: skeleton

        private void skeleton(KinectSensor sensor, Image Image)
        {
            var drawingGroup = new DrawingGroup();
            var imageSource = new DrawingImage(drawingGroup);
            Image.Source = imageSource;

            sensor.SkeletonStream.Enable();
            sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;

            sensor.SkeletonFrameReady += (o, arg) =>
            {
                var skeletons = new Skeleton[0];
                using (var frame = arg.OpenSkeletonFrame())
                {
                    if (frame != null)
                    {
                        skeletons = new Skeleton[frame.SkeletonArrayLength];
                        frame.CopySkeletonDataTo(skeletons);
                    }

                }
                if (record)
                {
                    ExportFrame frame = new ExportFrame();
                    frame.Time = DateTime.Now;
                    frame.TrackedSkeletons = skeletons.Where(row => row.TrackingState == SkeletonTrackingState.Tracked).ToArray();
                    exports.Add(frame);
                }

                using (DrawingContext dc = drawingGroup.Open())
                {
                    dc.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, 640, 480));
                    if (skeletons.Length > 0)
                    {
                        foreach (var skeleton in skeletons)
                        {
                            if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                DrawBonesAndJoints(sensor, skeleton, dc);
                                dc.DrawEllipse(Brushes.Turquoise, null, SkeletonPointToScreen(sensor, skeleton.Position), BodyCenterThickness, BodyCenterThickness);
                            }
                            else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                dc.DrawEllipse(Brushes.Turquoise, null, SkeletonPointToScreen(sensor, skeleton.Position), BodyCenterThickness, BodyCenterThickness);
                            }
                        }
                    }
                }
            };
        }
开发者ID:virrkharia,项目名称:dynamight,代码行数:50,代码来源:KinectDataExportWindow.xaml.cs

示例13: DrawCharacter

        public static Drawing DrawCharacter(char ch, Typeface typeFace, double fontSize, GameColor color, GameColor bgColor,
			bool drawOutline, double outlineThickness, bool reverse, CharRenderMode mode)
        {
            Color c;
            if (color == GameColor.None)
                c = Colors.White;
            else
                c = color.ToWindowsColor();

            DrawingGroup dGroup = new DrawingGroup();
            var brush = new SolidColorBrush(c);
            var bgBrush = bgColor != GameColor.None ? new SolidColorBrush(bgColor.ToWindowsColor()) : Brushes.Transparent;
            using (DrawingContext dc = dGroup.Open())
            {
                var formattedText = new FormattedText(
                        ch.ToString(),
                        System.Globalization.CultureInfo.InvariantCulture,
                        FlowDirection.LeftToRight,
                        typeFace,
                        fontSize, Brushes.Black);

                var geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
                var pen = drawOutline ? new Pen(Brushes.Black, outlineThickness) : null;
                var bounds = pen != null ? geometry.GetRenderBounds(pen) : geometry.Bounds;

                Rect bb;

                switch (mode)
                {
                    case CharRenderMode.Full:
                        {
                            double size = formattedText.Height;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, 0, size, size);
                        }
                        break;

                    case CharRenderMode.Caps:
                        {
                            double size = typeFace.CapsHeight * fontSize;
                            bb = new Rect(bounds.X + bounds.Width / 2 - size / 2, formattedText.Baseline - size,
                                size, size);
                        }
                        break;

                    case CharRenderMode.Free:
                        bb = bounds;
                        break;

                    default:
                        throw new Exception();
                }

                if (reverse)
                    geometry = new CombinedGeometry(GeometryCombineMode.Exclude, new RectangleGeometry(bb), geometry);

                //dc.DrawRectangle(bgBrush, new Pen(Brushes.Red, 1), bb);
                dc.DrawRectangle(bgBrush, null, bb);

                dc.DrawGeometry(brush, pen, geometry);

                /*
                var dl = new Action<double>((y) =>
                    dc.DrawLine(new Pen(Brushes.Red, 1), new Point(bb.Left, y), new Point(bb.Right, y)));

                dl(0);
                dl(formattedText.Baseline);
                dl(fontSize);
                dl(formattedText.Height);
                dl(formattedText.Baseline - typeFace.CapsHeight * fontSize);
                */
            }

            return dGroup;
        }
开发者ID:Fulborg,项目名称:dwarrowdelf,代码行数:74,代码来源:TileSetHelpers.cs

示例14: InkCanvasSelectionAdorner

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="adornedElement">The adorned InkCanvas</param>
        internal InkCanvasSelectionAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
            Debug.Assert(adornedElement is InkCanvasInnerCanvas, 
                "InkCanvasSelectionAdorner only should be used by InkCanvas internally");

            // Initialize the internal data.
            _adornerBorderPen = new Pen(Brushes.Black, 1.0);
            DoubleCollection dashes = new DoubleCollection( );
            dashes.Add(4.5);
            dashes.Add(4.5);
            _adornerBorderPen.DashStyle = new DashStyle(dashes, 2.25);
            _adornerBorderPen.DashCap = PenLineCap.Flat;
            _adornerBorderPen.Freeze();

            _adornerPenBrush = new Pen(new SolidColorBrush(Color.FromRgb(132, 146, 222)), 1);
            _adornerPenBrush.Freeze();

            _adornerFillBrush = new LinearGradientBrush(  Color.FromRgb(240, 242, 255), //start color
                                            Color.FromRgb(180, 207, 248),               //end color
                                            45f                                         //angle
                                            );
            _adornerFillBrush.Freeze();

            // Create a hatch pen
            DrawingGroup hatchDG = new DrawingGroup( );
            DrawingContext dc = null;

            try
            {
                dc = hatchDG.Open( );

                dc.DrawRectangle(
                    Brushes.Transparent,
                    null,
                    new Rect(0.0, 0.0, 1f, 1f));

                Pen squareCapPen = new Pen(Brushes.Black, LineThickness);
                squareCapPen.StartLineCap = PenLineCap.Square;
                squareCapPen.EndLineCap = PenLineCap.Square;

                dc.DrawLine(squareCapPen,
                    new Point(1f, 0f), new Point(0f, 1f));
            }
            finally
            {
                if ( dc != null )
                {
                    dc.Close( );
                }
            }
            hatchDG.Freeze();

            DrawingBrush tileBrush = new DrawingBrush(hatchDG);
            tileBrush.TileMode = TileMode.Tile;
            tileBrush.Viewport = new Rect(0, 0, HatchBorderMargin, HatchBorderMargin);
            tileBrush.ViewportUnits = BrushMappingMode.Absolute;
            tileBrush.Freeze();

            _hatchPen = new Pen(tileBrush, HatchBorderMargin);
            _hatchPen.Freeze();

            _elementsBounds = new List<Rect>();
            _strokesBounds = Rect.Empty;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:69,代码来源:InkCanvasSelectionAdorner.cs

示例15: RenderSingleLineText

        public override void RenderSingleLineText(SvgTextContentElement element,
            ref Point ctp, string text, double rotate, WpfTextPlacement placement)
        {
            if (String.IsNullOrEmpty(text))
                return;

            int vertOrientation    = -1;
            int horzOrientation    = -1;
            string orientationText = element.GetPropertyValue("glyph-orientation-vertical");
            if (!String.IsNullOrEmpty(orientationText))
            {
                double orientationValue = 0;
                if (Double.TryParse(orientationText, out orientationValue))
                {
                    vertOrientation = (int)orientationValue;
                }
            }
            orientationText = element.GetPropertyValue("glyph-orientation-horizontal");
            if (!String.IsNullOrEmpty(orientationText))
            {
                double orientationValue = 0;
                if (Double.TryParse(orientationText, out orientationValue))
                {
                    horzOrientation = (int)orientationValue;
                }
            }

            Point startPoint      = ctp;
            IList<WpfTextRun> textRunList = WpfTextRun.BreakWords(text,
                vertOrientation, horzOrientation);

            for (int tr = 0; tr < textRunList.Count; tr++)
            {
                // For unknown reasons, FormattedText will split a text like "-70%" into two parts "-"
                // and "70%". We provide a shift to account for the split...
                double baselineShiftX = 0;
                double baselineShiftY = 0;

                WpfTextRun textRun = textRunList[tr];

                DrawingGroup verticalGroup = new DrawingGroup();

                DrawingContext verticalContext = verticalGroup.Open();
                DrawingContext currentContext  = _textContext;

                _textContext = verticalContext;

                this.DrawSingleLineText(element, ref ctp, textRun, rotate, placement);

                verticalContext.Close();

                _textContext = currentContext;

                if (verticalGroup.Children.Count == 1)
                {
                    DrawingGroup textGroup = verticalGroup.Children[0] as DrawingGroup;
                    if (textGroup != null)
                    {
                        verticalGroup = textGroup;
                    }
                }

                string runText = textRun.Text;
                int charCount = runText.Length;

                double totalHeight = 0;
                DrawingCollection drawings = verticalGroup.Children;
                int itemCount = drawings != null ? drawings.Count : 0;
                for (int i = 0; i < itemCount; i++)
                {
                    Drawing textDrawing = drawings[i];
                    DrawingGroup textGroup = textDrawing as DrawingGroup;

                    if (vertOrientation == -1)
                    {
                        if (textGroup != null)
                        {
                            for (int j = 0; j < textGroup.Children.Count; j++)
                            {
                                GlyphRunDrawing glyphDrawing = textGroup.Children[j] as GlyphRunDrawing;
                                if (glyphDrawing != null)
                                {
                                    if (textRun.IsLatin)
                                    {
                                        GlyphRun glyphRun = glyphDrawing.GlyphRun;

                                        IList<UInt16> glyphIndices = glyphRun.GlyphIndices;
                                        IDictionary<ushort, double> allGlyphWeights = glyphRun.GlyphTypeface.AdvanceWidths;
                                        double lastAdvanceWeight =
                                            allGlyphWeights[glyphIndices[glyphIndices.Count - 1]] * glyphRun.FontRenderingEmSize;

                                        totalHeight += glyphRun.ComputeAlignmentBox().Width + lastAdvanceWeight / 2d;
                                    }
                                    else
                                    {
                                        totalHeight += ChangeGlyphOrientation(glyphDrawing,
                                            baselineShiftX, baselineShiftY, false);
                                    }
                                }
                            }
//.........这里部分代码省略.........
开发者ID:udayanroy,项目名称:SvgSharp,代码行数:101,代码来源:WpfVertTextRenderer.cs


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