@@ -866,7 +866,9 @@ - (void)drawBackground:(CTFrameRef)frame
866866 CFIndex lineIndex = 0 ;
867867 for (id line in lines) {
868868 CGFloat ascent = 0 .0f , descent = 0 .0f , leading = 0 .0f ;
869- CGFloat width = (CGFloat)CTLineGetTypographicBounds ((__bridge CTLineRef)line, &ascent, &descent, &leading) ;
869+ CGFloat width = (CGFloat)CTLineGetTypographicBounds ((__bridge CTLineRef)line, &ascent, &descent, &leading);
870+ CGFloat maxHeight = 0 .0f ;
871+ CGFloat maxRunDescent = 0 .0f ;
870872
871873 for (id glyphRun in (__bridge NSArray *)CTLineGetGlyphRuns ((__bridge CTLineRef)line)) {
872874 NSDictionary *attributes = (__bridge NSDictionary *)CTRunGetAttributes ((__bridge CTRunRef) glyphRun);
@@ -894,10 +896,26 @@ - (void)drawBackground:(CTFrameRef)frame
894896 xOffset = CTLineGetOffsetForStringIndex ((__bridge CTLineRef)line, glyphRange.location , NULL );
895897 break ;
896898 }
899+
900+ if (fillColor) {
901+ maxHeight = MAX (maxHeight, runBounds.size .height );
902+ runBounds.size .height = maxHeight;
903+
904+ maxRunDescent = MAX (maxRunDescent, runDescent);
905+
906+ if (maxRunDescent == 0 ) {
907+ maxRunDescent = runDescent;
908+ }
909+ }
897910
898911 runBounds.origin .x = origins[lineIndex].x + rect.origin .x + xOffset - fillPadding.left - rect.origin .x ;
899912 runBounds.origin .y = origins[lineIndex].y + rect.origin .y - fillPadding.bottom - rect.origin .y ;
900- runBounds.origin .y -= runDescent;
913+
914+ if (fillColor) {
915+ runBounds.origin .y -= maxRunDescent;
916+ } else {
917+ runBounds.origin .y -= runDescent;
918+ }
901919
902920 // Don't draw higlightedLinkBackground too far to the right
903921 if (CGRectGetWidth (runBounds) > width) {
0 commit comments