From edc737dce19957915d4369fc5107c267d730c88f Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 26 Jan 2023 23:44:50 +0400 Subject: [PATCH] Translation fixes --- .../Display/Source/LinkHighlightingNode.swift | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/submodules/Display/Source/LinkHighlightingNode.swift b/submodules/Display/Source/LinkHighlightingNode.swift index e650de2c46..9d5ac326c4 100644 --- a/submodules/Display/Source/LinkHighlightingNode.swift +++ b/submodules/Display/Source/LinkHighlightingNode.swift @@ -78,8 +78,37 @@ public func generateRectsImage(color: UIColor, rects: [CGRect], inset: CGFloat, context.setBlendMode(.copy) if useModernPathCalculation { - var rects = rects.map { $0.insetBy(dx: -inset, dy: -inset).offsetBy(dx: -topLeft.x, dy: -topLeft.y) } - if rects.count > 1 { + if rects.count == 1 { + let path = UIBezierPath(roundedRect: rects[0], cornerRadius: outerRadius).cgPath + context.addPath(path) + + if stroke { + context.setStrokeColor(color.cgColor) + context.setLineWidth(2.0) + context.strokePath() + } else { + context.fillPath() + } + return + } + + var combinedRects: [[CGRect]] = [] + var currentRects: [CGRect] = [] + for rect in rects { + if rect.width.isZero { + combinedRects.append(currentRects) + currentRects.removeAll() + } else { + currentRects.append(rect) + } + } + if !currentRects.isEmpty { + combinedRects.append(currentRects) + } + + for rects in combinedRects { + var rects = rects.map { $0.insetBy(dx: -inset, dy: -inset).offsetBy(dx: -topLeft.x, dy: -topLeft.y) } + let minRadius: CGFloat = 2.0 for _ in 0 ..< rects.count * rects.count { @@ -186,20 +215,8 @@ public func generateRectsImage(color: UIColor, rects: [CGRect], inset: CGFloat, } else { context.fillPath() } - return - } else { - let path = UIBezierPath(roundedRect: rects[0], cornerRadius: outerRadius).cgPath - context.addPath(path) - - if stroke { - context.setStrokeColor(color.cgColor) - context.setLineWidth(2.0) - context.strokePath() - } else { - context.fillPath() - } - return } + return } for i in 0 ..< rects.count {