in ExampleGallery/TextOutlines.xaml.cs [233:289]
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;
}