Skip to content

Commit

Permalink
wpf: PopupViewer bugfixes wave 2 (#518)
Browse files Browse the repository at this point in the history
* Fix parsing of "large" CSS font size
* wpf: Apply style to links within popup text elements
* wpf: Apply text-alignment to TableCell and ListItem in addition to Block
* wpf: Implement colspan and rowspan support for table cells
* wpf: Fix default font size
  • Loading branch information
mstefarov authored Jul 11, 2023
1 parent 855f22c commit f720225
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Toolkit/Toolkit/Internal/HtmlUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private static bool TryParseCssFontSize(string fontSizeString, out double emValu
"x-small" => ParseHtmlFontSize(1),
"small" => ParseHtmlFontSize(2),
"medium" => ParseHtmlFontSize(3),
"large " => ParseHtmlFontSize(4),
"large" => ParseHtmlFontSize(4),
"x-large" => ParseHtmlFontSize(5),
"xx-large" => ParseHtmlFontSize(6),
"xxx-large" => ParseHtmlFontSize(7),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void OnElementPropertyChanged()
// Full list of supported tags and attributes here: https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm
if (!string.IsNullOrEmpty(Element?.Text) && GetTemplateChild(TextAreaName) is RichTextBox rtb)
{
var doc = new FlowDocument();
var doc = new FlowDocument { FontSize = 14d }; // match the default "content" font size on AGOL
try
{
var htmlRoot = HtmlUtility.BuildDocumentTree(Element.Text);
Expand Down Expand Up @@ -153,6 +153,14 @@ private static Block VisitBlock(MarkupNode node)
{
var cell = new TableCell();
ApplyStyle(cell, cellNode);

// Apply colspan and rowspan, for non-uniform tables
var attr = HtmlUtility.ParseAttributes(cellNode.Token?.Attributes);
if (attr.TryGetValue("colspan", out var colSpanStr) && byte.TryParse(colSpanStr, out var colSpan))
cell.ColumnSpan = colSpan;
if (attr.TryGetValue("rowspan", out var rowSpanStr) && byte.TryParse(rowSpanStr, out var rowSpan))
cell.RowSpan = rowSpan;

cell.Blocks.AddRange(VisitAndAddBlocks(cellNode.Children));
row.Cells.Add(cell);
}
Expand All @@ -178,6 +186,7 @@ private static Inline VisitInline(MarkupNode node)
link.RequestNavigate += NavigateToUri;
} // else If we can't create a URL, we can't make a link clickable
link.Inlines.AddRange(VisitAndAddInlines(node.Children));
ApplyStyle(link, node);
return link;

case MarkupType.Image:
Expand Down Expand Up @@ -268,8 +277,16 @@ private static void ApplyStyle(TextElement el, MarkupNode node)
el.Background = new SolidColorBrush(ConvertColor(node.BackColor.Value));
if (node.FontSize.HasValue)
el.FontSize = 16d * node.FontSize.Value; // based on AGOL's default font size
if (node.Alignment.HasValue && el is Block blockEl)
blockEl.TextAlignment = ConvertAlignment(node.Alignment);
if (node.Alignment.HasValue)
{
// Unfortunately the TextAlignment property is separately defined for these FlowDocument elements
if (el is Block blockEl)
blockEl.TextAlignment = ConvertAlignment(node.Alignment);
else if (el is TableCell cellEl)
cellEl.TextAlignment = ConvertAlignment(node.Alignment);
else if (el is ListItem itemEl)
itemEl.TextAlignment = ConvertAlignment(node.Alignment);
}
if (node.IsUnderline.HasValue)
{
if (el is Inline inlineEl)
Expand Down

0 comments on commit f720225

Please sign in to comment.