コード例 #1
0
        private CanvasTextLayout CreateTextLayout(ICanvasResourceCreator resourceCreator, float canvasWidth, float canvasHeight)
        {
            string testString;

            if (CurrentTextLengthOption == TextLengthOption.Short)
            {
                testString = "one two";
            }
            else
            {
                testString = "This is some text which demonstrates Win2D's text-to-geometry option; there are sub-options of this test which apply lining options such as underline or strike-through. Additionally, this example applies different text directions to ensure glyphs are transformed correctly.";
            }

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                testString = "a";
            }

            everyOtherWordBoundary = Utils.GetEveryOtherWord(testString);

            float sizeDim = Math.Min(canvasWidth, canvasHeight);

            CanvasTextFormat textFormat = new CanvasTextFormat()
            {
                FontSize  = CurrentTextLengthOption == TextLengthOption.Paragraph? sizeDim * 0.09f : sizeDim * 0.3f,
                Direction = CurrentTextDirection,
            };

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                textFormat.FontSize = sizeDim * 0.75f;
            }

            CanvasTextLayout textLayout = new CanvasTextLayout(resourceCreator, testString, textFormat, canvasWidth, canvasHeight);

            if (CurrentTextEffectOption == TextEffectOption.UnderlineEveryOtherWord)
            {
                foreach (var wb in everyOtherWordBoundary)
                {
                    textLayout.SetUnderline(wb.Start, wb.Length, true);
                }
            }
            else if (CurrentTextEffectOption == TextEffectOption.StrikeEveryOtherWord)
            {
                foreach (var wb in everyOtherWordBoundary)
                {
                    textLayout.SetStrikethrough(wb.Start, wb.Length, true);
                }
            }

            textLayout.TrimmingGranularity = CanvasTextTrimmingGranularity.Character;
            textLayout.TrimmingSign        = CanvasTrimmingSign.Ellipsis;

            textLayout.VerticalGlyphOrientation = CurrentVerticalGlyphOrientation;

            return(textLayout);
        }
コード例 #2
0
ファイル: GlyphRotation.xaml.cs プロジェクト: N500/Win2D
        public GlyphRotation()
        {
            this.InitializeComponent();

            DataContext = this;

            CurrentTextEffectOption         = TextEffectOption.UnderlineEveryOtherWord;
            CurrentTextDirection            = CanvasTextDirection.RightToLeftThenBottomToTop;
            CurrentVerticalGlyphOrientation = CanvasVerticalGlyphOrientation.Default;

            ShowNonCustomText = true;

            testString = "This demonstrates the correct way to do glyph rotation from a custom text renderer in Win2D. Of course, if your script is always read left-to-right then top-to-bottom, there is no need to handle rotation. However, in general, callers of DrawGlyphRun should ensure that the correct transform is used- particularly for vertical text.";

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                testString           = "Glyph rotation";
                CurrentTextDirection = CanvasTextDirection.TopToBottomThenLeftToRight;
            }

            everyOtherWordBoundary = Utils.GetEveryOtherWord(testString);
        }