Avoid generating zero size bitmaps

This commit is contained in:
James Magahern
2023-04-14 19:37:31 -07:00
parent 748023d330
commit f8d19414d5
3 changed files with 8 additions and 2 deletions

View File

@@ -31,8 +31,9 @@ class GradientView: UIImageView
}
private func gradientImage(forSize size: CGSize) -> UIImage? {
var image: UIImage? = nil
guard size != .zero else { return nil }
var image: UIImage? = nil
UIGraphicsBeginImageContext(size)
if let context = UIGraphicsGetCurrentContext() {
let gradientColorsArray = self.colors.map { $0.cgColor }

View File

@@ -281,8 +281,9 @@ class URLBar: ReliefButton
}
private func fadeBackgroundImageForSize(_ size: CGSize, cutoffLocation: CGFloat) -> UIImage? {
var image: UIImage? = nil
guard size != .zero else { return nil }
var image: UIImage? = nil
UIGraphicsBeginImageContext(CGSize(width: size.width, height: 1.0))
if let context = UIGraphicsGetCurrentContext() {
let gradientColorsArray = [

View File

@@ -77,6 +77,10 @@ static CGFloat RoundToScale(CGFloat v, CGFloat s) {
+ (UIImage *)iconRepresentationForPolicyType:(SBRScriptOriginPolicyType)policyType withConfiguration:(nonnull SBRScriptPolicyIconConfiguration *)configuration
{
const CGSize size = [configuration size];
if (CGSizeEqualToSize(size, CGSizeZero)) {
return nil;
}
UIFont *font = [UIFont boldSystemFontOfSize:size.height - 2];
NSDictionary<NSAttributedStringKey, id> *attrs = @{
NSFontAttributeName : font,