-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen] Add handing Label.TextType (#11692)
### Description of Change This PR backports #11389 to net6.0
- Loading branch information
Showing
7 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/Controls/src/Core/Platform/Tizen/Extensions/FormattedStringExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Microsoft.Maui.Controls.Internals; | ||
using TFormattedString = Tizen.UIExtensions.Common.FormattedString; | ||
using TSpan = Tizen.UIExtensions.Common.Span; | ||
|
||
namespace Microsoft.Maui.Controls.Platform | ||
{ | ||
public static class FormattedStringExtensions | ||
{ | ||
public static TFormattedString ToFormattedString(this Label label) | ||
=> ToFormattedText( | ||
label.FormattedText, | ||
label.TextColor, | ||
label.RequireFontManager(), | ||
label.ToFont(), | ||
label.TextTransform, | ||
label.TextDecorations); | ||
|
||
internal static TFormattedString ToFormattedText( | ||
this FormattedString formattedString, | ||
Graphics.Color defaultColor, | ||
IFontManager fontManager, | ||
Font? defaultFont = null, | ||
TextTransform defaultTextTransform = TextTransform.Default, | ||
TextDecorations defaultTextDecorations = TextDecorations.None) | ||
{ | ||
if (formattedString == null) | ||
return new TFormattedString(); | ||
|
||
var defaultFontSize = defaultFont?.Size ?? fontManager.DefaultFontSize; | ||
var formattedText = new TFormattedString(); | ||
|
||
for (int i = 0; i < formattedString.Spans.Count; i++) | ||
{ | ||
Span span = formattedString.Spans[i]; | ||
var transform = span.TextTransform != TextTransform.Default ? span.TextTransform : defaultTextTransform; | ||
var text = TextTransformUtilites.GetTransformedText(span.Text, transform); | ||
|
||
if (text == null) | ||
continue; | ||
|
||
var nativeSpan = new TSpan() { Text = text }; | ||
var textColor = span.TextColor ?? defaultColor; | ||
|
||
if (textColor is not null) | ||
nativeSpan.ForegroundColor = textColor.ToPlatform(); | ||
|
||
if (span.BackgroundColor is not null) | ||
nativeSpan.BackgroundColor = span.BackgroundColor.ToPlatform(); | ||
|
||
var font = span.ToFont(defaultFontSize); | ||
if (font.IsDefault && defaultFont.HasValue) | ||
font = defaultFont.Value; | ||
|
||
if (!font.IsDefault) | ||
{ | ||
nativeSpan.FontSize = font.Size.ToScaledPoint(); | ||
nativeSpan.FontFamily = fontManager.GetFontFamily(span.FontFamily); | ||
} | ||
|
||
nativeSpan.LineHeight = span.LineHeight; | ||
|
||
var textDecorations = span.IsSet(Span.TextDecorationsProperty) | ||
? span.TextDecorations | ||
: defaultTextDecorations; | ||
if (textDecorations.HasFlag(TextDecorations.Strikethrough) || textDecorations.HasFlag(TextDecorations.Underline)) | ||
nativeSpan.TextDecorations = span.TextDecorations.ToPlatform(); | ||
|
||
formattedText.Spans.Add(nativeSpan); | ||
} | ||
return formattedText; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters