Example #1
0
        /// <summary>
        /// 从笔转化为系统笔;
        /// </summary>
        /// <param name="pen"></param>
        /// <returns></returns>
        public static SystemMedia.Pen ConverterToSystemPen(Pen pen)
        {
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            if (_frozenPenDict.TryGetValue(pen, out var sysPen))
            {
                return(sysPen);
            }

            sysPen = new SystemMedia.Pen(BrushAdapter.ConvertToSystemBrush(pen.Brush), pen.Thickness);
            if (pen.DashStyle != null)
            {
                sysPen.DashStyle = DashStyleAdapter.ConvertToSystemDashStyle(pen.DashStyle);
            }

            if (pen.IsFrozen)
            {
                sysPen.Freeze();
                _frozenPenDict.Add(pen, sysPen);
            }

            return(sysPen);
        }
Example #2
0
        public static SystemMedia.FormattedText ConvertToSystemFormattedText(FormattedText formattedText)
        {
            if (formattedText == null)
            {
                throw new ArgumentNullException(nameof(formattedText));
            }

            var brush = BrushAdapter.ConvertToSystemBrush(formattedText.ForegroundBlocks.FirstOrDefault()?.Brush);
            var ft    = new SystemMedia.FormattedText(
                formattedText.Text,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                _typeFace,
                formattedText.FontSize,
                brush
                );

            if (formattedText.ForegroundBlocks != null)
            {
                foreach (var item in formattedText.ForegroundBlocks)
                {
                    ft.SetForegroundBrush(BrushAdapter.ConvertToSystemBrush(item.Brush), item.Start, item.Length);
                }
            }

            return(ft);
        }