Skip to content

Commit

Permalink
PopupViewer bugfix roundup (#516)
Browse files Browse the repository at this point in the history
- Parse font sizes expressed in pt
- Don't let image load errors take down the app
- Fix handling of align attr in HTML popups
  • Loading branch information
mstefarov authored Jun 23, 2023
1 parent 93dbb52 commit d03aa50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ private static Inline VisitInline(MarkupNode node)
var img = (Image)sender;
var taggedUri = (Uri)img.Tag;
var ri = new RuntimeImage(taggedUri); // Use Runtime's caching and authentication
img.Source = await ri.ToImageSourceAsync();
try
{
img.Source = await ri.ToImageSourceAsync();
}
catch
{
// Don't let one bad image take down the whole app. Better to ignore a failed image load.
}
};
return new InlineUIContainer(imageElement);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Toolkit/Toolkit/Internal/HtmlUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ internal static MarkupNode BuildDocumentTree(string snippet)
break;
}

if (name is "div" or "td" or "th" or "tr")
if (name is "div" or "p" or "td" or "th" or "tr")
{
if (!attr.TryGetValue("align", out var alignStr) && Enum.TryParse<HtmlAlignment>(alignStr, true, out var align))
if (attr.TryGetValue("align", out var alignStr) && Enum.TryParse<HtmlAlignment>(alignStr, true, out var align))
newNode.Alignment = align;
}

Expand Down Expand Up @@ -461,11 +461,13 @@ private static bool TryParseCssFontSize(string fontSizeString, out double emValu
return false;

fontSizeString = fontSizeString.Trim().ToLowerInvariant();
if (fontSizeString.EndsWith("px"))
if (fontSizeString.EndsWith("px") || fontSizeString.EndsWith("pt"))
{
if (double.TryParse(fontSizeString.Substring(0, fontSizeString.Length - 2), out var pxValue))
if (double.TryParse(fontSizeString.Substring(0, fontSizeString.Length - 2), out var pValue))
{
emValue = pxValue / 16d; // 1em == 16px (approx)
// Approximate conversion: 1em == 16px == 12pt
var conversionFactor = fontSizeString.EndsWith("px") ? 16 : 12;
emValue = pValue / conversionFactor;
return true;
}
}
Expand Down

0 comments on commit d03aa50

Please sign in to comment.