Skip to content

Commit

Permalink
fix: added try-catch block in TryGetPixelSize (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchellc authored Aug 7, 2024
2 parents 4efa9b6 + 439d993 commit 009d304
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions LabExtended/Utilities/HintUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@ public static void TrimStartNewLines(ref string str, out int count)

public static bool TryGetPixelSize(string tag, out int size)
{
if (tag.EndsWith("%") && float.TryParse(tag.Substring(0, tag.Length - 1), out var result))
{
size = (int)(result * PixelsPerEm / 100f);
return true;
}
else if (tag.EndsWith("em") && float.TryParse(tag.Substring(0, tag.Length - 2), out result))
{
size = (int)(result * PixelsPerEm);
return true;
}
else if (char.IsDigit(tag[tag.Length - 1]) && int.TryParse(tag, out size))
return true;
else if (tag.EndsWith("px") && int.TryParse(tag.Substring(0, tag.Length - 2), out size))
return true;

try {
if (tag.EndsWith("%") && float.TryParse(tag.Substring(0, tag.Length - 1), out var result)) {
size = (int)(result * PixelsPerEm / 100f);
return true;
} else if (tag.EndsWith("em") && float.TryParse(tag.Substring(0, tag.Length - 2), out result)) {
size = (int)(result * PixelsPerEm);
return true;
} else if (char.IsDigit(tag[tag.Length - 1]) && int.TryParse(tag, out size))
return true;
else if (tag.EndsWith("px") && int.TryParse(tag.Substring(0, tag.Length - 2), out size))
return true;
} catch { }
size = PixelsPerEm;
return false;
}
Expand Down

0 comments on commit 009d304

Please sign in to comment.