diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs | 20 | ||||
| -rw-r--r-- | modules/svg/image_loader_svg.cpp | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index df67e075ac..d53bb9f536 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -729,6 +729,26 @@ namespace Godot } /// <summary> + /// Decodes a hexadecimal string. + /// </summary> + /// <param name="instance">The hexadecimal string.</param> + /// <returns>The byte array representation of this string.</returns> + public static byte[] HexDecode(this string instance) + { + if (instance.Length % 2 != 0) + { + throw new ArgumentException("Hexadecimal string of uneven length.", nameof(instance)); + } + int len = instance.Length / 2; + byte[] ret = new byte[len]; + for (int i = 0; i < len; i++) + { + ret[i] = (byte)int.Parse(instance.AsSpan(i * 2, 2), NumberStyles.AllowHexSpecifier); + } + return ret; + } + + /// <summary> /// Returns a hexadecimal representation of this byte as a string. /// </summary> /// <param name="b">The byte to encode.</param> diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index e239b33374..ad7feeda49 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -79,8 +79,8 @@ Error ImageLoaderSVG::create_image_from_utf8_buffer(Ref<Image> p_image, const Pa float fw, fh; picture->size(&fw, &fh); - uint32_t width = round(fw * p_scale); - uint32_t height = round(fh * p_scale); + uint32_t width = MAX(1, round(fw * p_scale)); + uint32_t height = MAX(1, round(fh * p_scale)); const uint32_t max_dimension = 16384; if (width > max_dimension || height > max_dimension) { |
