Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df83112

Browse files
committed
Fix for combining bold with italic in WPF
Checking if the RFontStyle flag is set instead of checking the value only, (Bold | Italic) would fall through to default instead of the desired values. Adding bold and italic font style span to sample html.
1 parent 314b8ec commit df83112

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

Source/Demo/Common/Samples/02.Text.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h2>Formatting
2323
<li><span style="color: red">Colors</span>, <span style="color: #8dd">Colors</span>,
2424
<span style="color: rgb(160, 80, 90)">Colors</span></li>
2525
<li><span style="background-color: red">Back colors</span>, <span style="background-color: #8dd">Back colors</span>, <span style="background-color: rgb(160, 80, 90)">Back colors</span></li>
26-
<li><span style="font-style: normal">Font style</span>, <span style="font-style: italic">Font style</span>, <span style="font-weight: bolder">Font style</span>, <span style="text-decoration: underline">Font style</span>, <span style="text-decoration: line-through">Font style</span></li>
26+
<li><span style="font-style: normal">Font style</span>, <span style="font-style: italic">Font style</span>, <span style="font-weight: bolder">Font style</span>, <span style="font-style: italic;font-weight: bolder">Font style</span>, <span style="text-decoration: underline">Font style</span>, <span style="text-decoration: line-through">Font style</span></li>
2727
</ul>
2828
<p>
2929
Lorem ipsum <span style="font-style: italic; text-decoration: underline">dolor sit amet</span>,

Source/Demo/Common/Samples/03.Tables.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h2>
7777
<li><span style="background-color: red">Back colors</span>, <span style="background-color: #8dd">
7878
Back colors</span>, <span style="background-color: rgb(160, 80, 90)">Back colors</span></li>
7979
<li><span style="font-style: normal">Font style</span>, <span style="font-style: italic">
80-
Font style</span>, <span style="font-weight: bolder">Font style</span>, <span style="text-decoration: underline">
80+
Font style</span>, <span style="font-weight: bolder">Font style</span>, <span style="font-style: italic;font-weight: bolder">Font style</span>, <span style="text-decoration: underline">
8181
Font style</span>, <span style="text-decoration: line-through">Font style</span></li>
8282
</ul>
8383
</td>

Source/HtmlRenderer.WPF/Adapters/WpfAdapter.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,21 @@ private static Brush GetSolidColorBrush(RColor color)
207207
/// </summary>
208208
private static FontStyle GetFontStyle(RFontStyle style)
209209
{
210-
switch (style)
211-
{
212-
case RFontStyle.Italic:
213-
return FontStyles.Italic;
214-
default:
215-
return FontStyles.Normal;
216-
}
210+
if ((style & RFontStyle.Italic) == RFontStyle.Italic)
211+
return FontStyles.Italic;
212+
213+
return FontStyles.Normal;
217214
}
218215

219216
/// <summary>
220217
/// Get WPF font style for the given style.
221218
/// </summary>
222219
private static FontWeight GetFontWidth(RFontStyle style)
223220
{
224-
switch (style)
225-
{
226-
case RFontStyle.Bold:
227-
return FontWeights.Bold;
228-
default:
229-
return FontWeights.Normal;
230-
}
221+
if ((style & RFontStyle.Bold) == RFontStyle.Bold)
222+
return FontWeights.Bold;
223+
224+
return FontWeights.Normal;
231225
}
232226

233227
#endregion

0 commit comments

Comments
 (0)