forked from microsoft/AdaptiveCards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RendererUtil.cs
80 lines (70 loc) · 2.74 KB
/
RendererUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AdaptiveCards.Rendering.Wpf
{
static class RendererUtil
{
/// <summary>
/// Checks if any of the fonts to be used for the TexBlock is installed, and if so, returns it
/// </summary>
/// <param name="fontList">Font list to check if any exist</param>
/// <returns>First font in list that is installed, otherwise, default system font</returns>
public static string GetFontFamilyFromList(string fontList)
{
var installedFonts = new InstalledFontCollection();
string[] fontFamilies = fontList.Split(',');
for (int i = 0; i < fontFamilies.Length; ++i)
{
string fontFamily = fontFamilies[i].Trim('\'');
foreach (var installedFontFamily in installedFonts.Families)
{
if (installedFontFamily.Name == fontFamily)
{
return fontFamily;
}
}
}
// If no valid font was found in list, return the system default font
return SystemFonts.MessageFontFamily.ToString();
}
public static void ApplyVerticalContentAlignment(FrameworkElement uiElement, AdaptiveCollectionElement element)
{
switch (element.VerticalContentAlignment)
{
case AdaptiveVerticalContentAlignment.Center:
uiElement.VerticalAlignment = VerticalAlignment.Center;
break;
case AdaptiveVerticalContentAlignment.Bottom:
uiElement.VerticalAlignment = VerticalAlignment.Bottom;
break;
case AdaptiveVerticalContentAlignment.Top:
default:
break;
}
}
public static FrameworkElement ApplySelectAction(FrameworkElement uiElement, AdaptiveElement element, AdaptiveRenderContext context)
{
AdaptiveAction selectAction = null;
if (element is AdaptiveCollectionElement)
{
selectAction = (element as AdaptiveCollectionElement).SelectAction;
}
else if (element is AdaptiveImage)
{
selectAction = (element as AdaptiveImage).SelectAction;
}
if (selectAction != null)
{
return context.RenderSelectAction(selectAction, uiElement);
}
return uiElement;
}
}
}