Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public static SpannableString ToSpannableString(
if (characterSpacing >= 0)
spannable.SetSpan(new PlatformFontSpan(characterSpacing.ToEm()), start, end, SpanTypes.InclusiveInclusive);

// Font
var font = span.ToFont(defaultFontSize);
if (font.IsDefault && defaultFont.HasValue)
font = defaultFont.Value;
// Inherit FontFamily from defaultFont if not explicitly set
var fontFamily = span.IsSet(Span.FontFamilyProperty) ? span.FontFamily : defaultFont?.Family;
var fontSize = span.FontSize >= 0 ? span.FontSize : defaultFontSize;
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated
var font = Font.OfSize(fontFamily, fontSize);
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated
if (!font.IsDefault)
spannable.SetSpan(new PlatformFontSpan(context ?? AAplication.Context, font.ToTypeface(fontManager), font.AutoScalingEnabled, (float)fontManager.GetFontSize(font).Value), start, end, SpanTypes.InclusiveInclusive);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ public static Tuple<Run, Color, Color> ToRunAndColorsTuple(

var run = new Run { Text = text ?? string.Empty };

var font = span.ToFont(defaultFontSize);
if (font.IsDefault && defaultFont.HasValue)
font = defaultFont.Value;

// Inherit FontFamily from defaultFont if not explicitly set
var fontFamily = span.IsSet(Span.FontFamilyProperty) ? span.FontFamily : defaultFont?.Family;
var fontSize = span.FontSize >= 0 ? span.FontSize : defaultFontSize;
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated
var font = Font.OfSize(fontFamily, fontSize);
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated

if (!font.IsDefault)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static NSAttributedString ToNSAttributedString(
_ => UITextAlignment.Left
};

var font = span.ToFont(defaultFontSize);
if (font.IsDefault && defaultFont.HasValue)
font = defaultFont.Value;

// Inherit FontFamily from defaultFont if not explicitly set
var fontFamily = span.IsSet(Span.FontFamilyProperty) ? span.FontFamily : defaultFont?.Family;
var fontSize = span.FontSize >= 0 ? span.FontSize : defaultFontSize;
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated
var font = Font.OfSize(fontFamily, fontSize);
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Outdated
var hasUnderline = false;
var hasStrikethrough = false;
if (span.IsSet(Span.TextDecorationsProperty))
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21326.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 21326, "Span does not inherit text styling from Label if that styling is applied using Style", PlatformAffected.All)]
public partial class Issue21326 : ContentPage
{
public Issue21326()
{
var Issue21326resourceDictionary = new ResourceDictionary();

var headingStyle = new Style(typeof(Label));
headingStyle.Setters.Add(new Setter { Property = Label.FontFamilyProperty, Value = "MontserratBold" });
headingStyle.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 20.0 });
Issue21326resourceDictionary.Add("HeadingStyle", headingStyle);

Resources = Issue21326resourceDictionary;

var Issue21326testLabel = new Label
{
Style = headingStyle,
AutomationId = "Issue21326Label"
};

var formattedString = new FormattedString();
formattedString.Spans.Add(new Span
{
Text = "SHOULD BE MONTSERRATBOLD from Style"
});
Issue21326testLabel.FormattedText = formattedString;

Content = new VerticalStackLayout
{
Padding = 10,
Spacing = 20,
Children =
{
new Label { Text = "Test Passes if below label rendered in MontserratBold font from Style" },
Issue21326testLabel
}
};
}
}
Comment thread
Vignesh-SF3580 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue21326 : _IssuesUITest
{
public override string Issue => "Span does not inherit text styling from Label if that styling is applied using Style";

public Issue21326(TestDevice device) : base(device) { }

[Test]
[Category(UITestCategories.Label)]
public void SpanShouldInheritStyleFromLabel()
{
App.WaitForElement("Issue21326Label");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading