Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash fix on some non-us Windows locale #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion Source/HtmlRenderer.WPF/Adapters/FontFamilyAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public override string Name
{
get
{
string name = _fontFamily.FamilyNames[_xmlLanguage];
var name = string.Empty;
if (_fontFamily.FamilyNames.ContainsKey(_xmlLanguage))
{
name = _fontFamily.FamilyNames[_xmlLanguage];
}

if (string.IsNullOrEmpty(name))
{
foreach (var familyName in _fontFamily.FamilyNames)
Expand Down
11 changes: 10 additions & 1 deletion Source/HtmlRenderer.WPF/Adapters/GraphicsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,17 @@ public override void DrawString(string str, RFont font, RColor color, RPoint poi
point.X += rtl ? 96d / 72d * font.Size * width : 0;

glyphRendered = true;
var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0, false, 96d / 72d * font.Size, glyphs, Utils.ConvertRound(point), widths, null, null, null, null, null, null);
var wpfPoint = Utils.ConvertRound(point);
var glyphRun = new GlyphRun(glyphTypeface, rtl ? 1 : 0,
false, 96d / 72d * font.Size, glyphs,
wpfPoint, widths, null, null, null, null, null, null);

var guidelines = new GuidelineSet();
guidelines.GuidelinesX.Add(wpfPoint.X);
guidelines.GuidelinesY.Add(wpfPoint.Y);
_g.PushGuidelineSet(guidelines);
_g.DrawGlyphRun(colorConv, glyphRun);
_g.Pop();
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/HtmlRenderer/Adapters/Entities/RRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ public void Inflate(double x, double y)
{
X -= x;
Y -= y;
Width += 2f * x;
Height += 2f * y;
Width += 2 * x;
Height += 2 * y;
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions Source/HtmlRenderer/Core/Dom/CssBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ internal double GetMinimumWidth()
CssRect maxWidthWord = null;
GetMinimumWidth_LongestWord(this, ref maxWidth, ref maxWidthWord);

double padding = 0f;
double padding = 0;
if (maxWidthWord != null)
{
var box = maxWidthWord.OwnerBox;
Expand Down Expand Up @@ -949,7 +949,7 @@ private static void GetMinimumWidth_LongestWord(CssBox box, ref double maxWidth,
/// <returns>the total margin</returns>
private static double GetWidthMarginDeep(CssBox box)
{
double sum = 0f;
double sum = 0;
if (box.Size.Width > 90999 || (box.ParentBox != null && box.ParentBox.Size.Width > 90999))
{
while (box != null)
Expand Down Expand Up @@ -989,10 +989,10 @@ internal double GetMaximumBottom(CssBox startBox, double currentMaxBottom)
/// <param name="maxWidth">The total width the content can take without line wrapping (with padding).</param>
internal void GetMinMaxWidth(out double minWidth, out double maxWidth)
{
double min = 0f;
double maxSum = 0f;
double paddingSum = 0f;
double marginSum = 0f;
double min = 0;
double maxSum = 0;
double paddingSum = 0;
double marginSum = 0;
GetMinMaxSumWords(this, ref min, ref maxSum, ref paddingSum, ref marginSum);

maxWidth = paddingSum + maxSum;
Expand Down Expand Up @@ -1112,7 +1112,7 @@ protected double MarginTopCollapse(CssBoxProperties prevSibling)
// fix for hr tag
if (value < 0.1 && HtmlTag != null && HtmlTag.Name == "hr")
{
value = GetEmHeight() * 1.1f;
value = GetEmHeight() * 1.1;
}

return value;
Expand Down Expand Up @@ -1422,14 +1422,14 @@ protected void PaintDecoration(RGraphics g, RRect rectangle, bool isFirst, bool
if (string.IsNullOrEmpty(TextDecoration) || TextDecoration == CssConstants.None)
return;

double y = 0f;
double y = 0;
if (TextDecoration == CssConstants.Underline)
{
y = Math.Round(rectangle.Top + ActualFont.UnderlineOffset);
}
else if (TextDecoration == CssConstants.LineThrough)
{
y = rectangle.Top + rectangle.Height / 2f;
y = rectangle.Top + rectangle.Height / 2;
}
else if (TextDecoration == CssConstants.Overline)
{
Expand Down
8 changes: 4 additions & 4 deletions Source/HtmlRenderer/Core/Dom/CssBoxFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private void DrawTitle(RGraphics g, RRect rect)
{
if (_videoTitle != null && _imageWord.Width > 40 && _imageWord.Height > 40)
{
var font = HtmlContainer.Adapter.GetFont("Arial", 9f, RFontStyle.Regular);
var font = HtmlContainer.Adapter.GetFont("Arial", 9.0, RFontStyle.Regular);
g.DrawRectangle(g.GetSolidBrush(RColor.FromArgb(160, 0, 0, 0)), rect.Left, rect.Top, rect.Width, ActualFont.Height + 7);

var titleRect = new RRect(rect.Left + 3, rect.Top + 3, rect.Width - 6, rect.Height - 6);
Expand All @@ -540,9 +540,9 @@ private void DrawPlay(RGraphics g, RRect rect)

RPoint[] points =
{
new RPoint(left + size.Width / 3f + 1,top + 3 * size.Height / 4f),
new RPoint(left + size.Width / 3f + 1, top + size.Height / 4f),
new RPoint(left + 2 * size.Width / 3f + 1, top + size.Height / 2f)
new RPoint(left + size.Width / 3.0 + 1,top + 3 * size.Height / 4.0),
new RPoint(left + size.Width / 3.0 + 1, top + size.Height / 4.0),
new RPoint(left + 2 * size.Width / 3.0 + 1, top + size.Height / 2.0)
};
g.DrawPolygon(g.GetSolidBrush(RColor.White), points);

Expand Down
29 changes: 19 additions & 10 deletions Source/HtmlRenderer/Core/Dom/CssBoxProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,16 @@ public string Position
public string LineHeight
{
get { return _lineHeight; }
set { _lineHeight = string.Format(NumberFormatInfo.InvariantInfo, "{0}px", CssValueParser.ParseLength(value, Size.Height, this, CssConstants.Em)); }
set
{
_lineHeight = string.Format(
NumberFormatInfo.InvariantInfo,
"{0}px",
Double.TryParse(value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var val)
? CssValueParser.ParseLength((val * ActualFont.Size).ToString(CultureInfo.InvariantCulture), Size.Height, this, CssConstants.Pt)
: CssValueParser.ParseLength(value, Size.Height, this, CssConstants.Em)
);
}
}

public string VerticalAlign
Expand Down Expand Up @@ -976,7 +985,7 @@ public double ActualBorderTopWidth
_actualBorderTopWidth = CssValueParser.GetActualBorderWidth(BorderTopWidth, this);
if (string.IsNullOrEmpty(BorderTopStyle) || BorderTopStyle == CssConstants.None)
{
_actualBorderTopWidth = 0f;
_actualBorderTopWidth = 0.0f;
}
}
return _actualBorderTopWidth;
Expand All @@ -995,7 +1004,7 @@ public double ActualBorderLeftWidth
_actualBorderLeftWidth = CssValueParser.GetActualBorderWidth(BorderLeftWidth, this);
if (string.IsNullOrEmpty(BorderLeftStyle) || BorderLeftStyle == CssConstants.None)
{
_actualBorderLeftWidth = 0f;
_actualBorderLeftWidth = 0.0;
}
}
return _actualBorderLeftWidth;
Expand All @@ -1014,7 +1023,7 @@ public double ActualBorderBottomWidth
_actualBorderBottomWidth = CssValueParser.GetActualBorderWidth(BorderBottomWidth, this);
if (string.IsNullOrEmpty(BorderBottomStyle) || BorderBottomStyle == CssConstants.None)
{
_actualBorderBottomWidth = 0f;
_actualBorderBottomWidth = 0.0;
}
}
return _actualBorderBottomWidth;
Expand All @@ -1033,7 +1042,7 @@ public double ActualBorderRightWidth
_actualBorderRightWidth = CssValueParser.GetActualBorderWidth(BorderRightWidth, this);
if (string.IsNullOrEmpty(BorderRightStyle) || BorderRightStyle == CssConstants.None)
{
_actualBorderRightWidth = 0f;
_actualBorderRightWidth = 0.0;
}
}
return _actualBorderRightWidth;
Expand Down Expand Up @@ -1169,7 +1178,7 @@ public double ActualCornerSw
/// </summary>
public bool IsRounded
{
get { return ActualCornerNe > 0f || ActualCornerNw > 0f || ActualCornerSe > 0f || ActualCornerSw > 0f; }
get { return ActualCornerNe > 0.0 || ActualCornerNw > 0.0 || ActualCornerSe > 0.0 || ActualCornerSw > 0.0; }
}

/// <summary>
Expand Down Expand Up @@ -1237,7 +1246,7 @@ public double ActualBackgroundGradientAngle
{
if (double.IsNaN(_actualBackgroundGradientAngle))
{
_actualBackgroundGradientAngle = CssValueParser.ParseNumber(BackgroundGradientAngle, 360f);
_actualBackgroundGradientAngle = CssValueParser.ParseNumber(BackgroundGradientAngle, 360.0);
}

return _actualBackgroundGradientAngle;
Expand Down Expand Up @@ -1322,7 +1331,7 @@ public RFont ActualFont
break;
}

if (fsize <= 1f)
if (fsize <= 1.0)
{
fsize = CssConstants.FontSize;
}
Expand All @@ -1344,7 +1353,7 @@ public double ActualLineHeight
{
if (double.IsNaN(_actualLineHeight))
{
_actualLineHeight = .9f * CssValueParser.ParseLength(LineHeight, Size.Height, this);
_actualLineHeight = .9 * CssValueParser.ParseLength(LineHeight, Size.Height, this);
}
return _actualLineHeight;
}
Expand Down Expand Up @@ -1499,7 +1508,6 @@ protected void InheritStyle(CssBox p, bool everything)
_visibility = p._visibility;
_textIndent = p._textIndent;
_textAlign = p._textAlign;
_verticalAlign = p._verticalAlign;
_fontFamily = p._fontFamily;
_fontSize = p._fontSize;
_fontStyle = p._fontStyle;
Expand Down Expand Up @@ -1560,6 +1568,7 @@ protected void InheritStyle(CssBox p, bool everything)
_width = p._width;
_maxWidth = p._maxWidth;
_wordSpacing = p._wordSpacing;
_verticalAlign = p._verticalAlign;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions Source/HtmlRenderer/Core/Dom/CssLayoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void MeasureImageSize(CssRectImage imageWord)
}
else
{
imageWord.Width = hasImageTagHeight ? height.Number / 1.14f : 20;
imageWord.Width = hasImageTagHeight ? height.Number / 1.14 : 20.0;
}

var maxWidth = new CssLength(imageWord.OwnerBox.MaxWidth);
Expand Down Expand Up @@ -88,7 +88,7 @@ public static void MeasureImageSize(CssRectImage imageWord)
}
else
{
imageWord.Height = imageWord.Width > 0 ? imageWord.Width * 1.14f : 22.8f;
imageWord.Height = imageWord.Width > 0 ? imageWord.Width * 1.14 : 22.8;
}

if (imageWord.Image != null)
Expand Down Expand Up @@ -181,8 +181,8 @@ public static void ApplyCellVerticalAlignment(RGraphics g, CssBox cell)
return;

double cellbot = cell.ClientBottom;
double bottom = cell.GetMaximumBottom(cell, 0f);
double dist = 0f;
double bottom = cell.GetMaximumBottom(cell, 0.0);
double dist = 0.0;

if (cell.VerticalAlign == CssConstants.Bottom)
{
Expand Down Expand Up @@ -542,10 +542,10 @@ private static void ApplyVerticalAlignment(RGraphics g, CssLineBox lineBox)
switch (box.VerticalAlign)
{
case CssConstants.Sub:
lineBox.SetBaseLine(g, box, baseline + lineBox.Rectangles[box].Height * .5f);
lineBox.SetBaseLine(g, box, baseline + lineBox.Rectangles[box].Height * .5);
break;
case CssConstants.Super:
lineBox.SetBaseLine(g, box, baseline - lineBox.Rectangles[box].Height * .2f);
lineBox.SetBaseLine(g, box, baseline - lineBox.Rectangles[box].Height * .2);
break;
case CssConstants.TextTop:

Expand Down Expand Up @@ -580,19 +580,19 @@ private static void ApplyJustifyAlignment(RGraphics g, CssLineBox lineBox)
if (lineBox.Equals(lineBox.OwnerBox.LineBoxes[lineBox.OwnerBox.LineBoxes.Count - 1]))
return;

double indent = lineBox.Equals(lineBox.OwnerBox.LineBoxes[0]) ? lineBox.OwnerBox.ActualTextIndent : 0f;
double textSum = 0f;
double words = 0f;
double indent = lineBox.Equals(lineBox.OwnerBox.LineBoxes[0]) ? lineBox.OwnerBox.ActualTextIndent : 0.0;
double textSum = 0.0;
double words = 0.0;
double availWidth = lineBox.OwnerBox.ClientRectangle.Width - indent;

// Gather text sum
foreach (CssRect w in lineBox.Words)
{
textSum += w.Width;
words += 1f;
words += 1.0;
}

if (words <= 0f)
if (words <= 0.0)
return; //Avoid Zero division
double spacing = (availWidth - textSum) / words; //Spacing that will be used
double curx = lineBox.OwnerBox.ClientLeft + indent;
Expand Down
Loading