public FontKey(string fontFamily, float fontSize, Windows.UI.Text.FontWeight fontWeight, Windows.UI.Text.FontStyle fontStyle)
 {
     this.FontFamily = fontFamily;
     this.FontSize   = fontSize;
     this.FontWeight = fontWeight;
     this.FontStyle  = fontStyle;
 }
        private FontKey FontKeyFromStyle(Style style)
        {
            var fontSize   = mm2px(style.FontSize, dpiY);
            var fontWeight = new Windows.UI.Text.FontWeight()
            {
                Weight = (ushort)style.FontWeight
            };
            var fontStyle = Windows.UI.Text.FontStyle.Normal;

            if (style.FontStyle == "italic")
            {
                fontStyle = Windows.UI.Text.FontStyle.Italic;
            }
            else if (style.FontStyle == "oblique")
            {
                fontStyle = Windows.UI.Text.FontStyle.Oblique;
            }

            return(new FontKey(style.FontFamily, fontSize, fontWeight, fontStyle));
        }
Esempio n. 3
0
 public static string GetWeightName(Windows.UI.Text.FontWeight weight)
 {
     return($"{Utils.GetWeightName(weight)} - {weight.Weight}");
 }
        public Rectangle[] GetCharacterBoundingBoxes(Text text, TextSpan[] spans)
        {
            var label      = text.Label;
            var rects      = new List <Rectangle>();
            var firstStyle = spans.First().Style;

            var myTEE      = StringInfo.GetTextElementEnumerator(label);
            var textFormat = new CanvasTextFormat()
            {
                FontSize = mm2px(firstStyle.FontSize, dpiY),
            };

            var firstChar = label.FirstOrDefault();

            textFormat.FontFamily = firstStyle.FontFamily;

            var canvasTextLayout = new CanvasTextLayout(CanvasDevice.GetSharedDevice(), label, textFormat, float.MaxValue, float.MaxValue);

            var beginCharPosition = 0;
            var charCount         = label.Length - 1;

            // Construct the string with different styles
            for (var i = 0; i < spans.Length; ++i)
            {
                var style = spans[i].Style;
                if (spans.Length > 0)
                {
                    var interval = spans.ElementAt(i);
                    beginCharPosition = interval.BeginPosition;
                    charCount         = (int)(interval.EndPosition - interval.BeginPosition) + 1;
                }
                var fontWeight = new Windows.UI.Text.FontWeight();
                fontWeight.Weight = (ushort)style.FontWeight;
                var fontStyle = Windows.UI.Text.FontStyle.Normal;
                if (style.FontStyle == "italic")
                {
                    fontStyle = Windows.UI.Text.FontStyle.Italic;
                }
                else if (style.FontStyle == "oblique")
                {
                    fontStyle = Windows.UI.Text.FontStyle.Oblique;
                }
                canvasTextLayout.SetFontSize(beginCharPosition, charCount, mm2px(firstStyle.FontSize, dpiY));
                canvasTextLayout.SetFontWeight(beginCharPosition, charCount, fontWeight);
                canvasTextLayout.SetFontStyle(beginCharPosition, charCount, fontStyle);
                canvasTextLayout.SetFontFamily(beginCharPosition, charCount, style.FontFamily);
            }

            var baseline = canvasTextLayout.LineMetrics[0].Baseline;

            while (myTEE.MoveNext())
            {
                var canvasCharLayout = new CanvasTextLayout(CanvasDevice.GetSharedDevice(), myTEE.GetTextElement(), textFormat, 2000, 1000);
                canvasCharLayout.SetFontSize(0, 1, canvasTextLayout.GetFontSize(myTEE.ElementIndex));
                canvasCharLayout.SetFontStyle(0, 1, canvasTextLayout.GetFontStyle(myTEE.ElementIndex));
                canvasCharLayout.SetFontWeight(0, 1, canvasTextLayout.GetFontWeight(myTEE.ElementIndex));
                canvasCharLayout.SetFontFamily(0, 1, canvasTextLayout.GetFontFamily(myTEE.ElementIndex));
                var drawCharBounds = canvasCharLayout.DrawBounds;

                var v2   = canvasTextLayout.GetCaretPosition(myTEE.ElementIndex, false);
                var newX = (float)drawCharBounds.X + v2.X;
                var newY = (float)drawCharBounds.Y - baseline;

                //Need to do little translation to clip to the line
                rects.Add(new Rectangle(px2mm(newX, dpiX), px2mm(newY, dpiY), px2mm((float)drawCharBounds.Width, dpiX), px2mm((float)drawCharBounds.Height, dpiY)));
            }
            return(rects.ToArray());
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a <see cref="FontWeight"/> from <see cref="windows.UI.Text.FontWeight"/>.
 /// </summary>
 /// <param name="args">The <see cref="windows.UI.Text.FontWeight"/> instance containing the event data.</param>
 /// <returns><see cref="FontWeight"/></returns>
 public static FontWeight FromFontWeight(windows.UI.Text.FontWeight args)
 {
     return(new FontWeight(args));
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FontWeight"/> class, a
 /// Wpf-enabled wrapper for <see cref="windows.UI.Text.FontWeight"/>
 /// </summary>
 public FontWeight(windows.UI.Text.FontWeight instance)
 {
     this.UwpInstance = instance;
 }