@@ -471,10 +471,48 @@ private LineDrawInfo makeLineDrawInfo(int lineIndex) {
471
471
}
472
472
473
473
int drawLines (int startLine , int endLine , int begX , int begY , int endY , GC gc , Color widgetBackground , Color widgetForeground ) {
474
- final boolean drawBackBeforeFore = false ;
474
+ // When fixed line metrics is in effect, tall unicode characters
475
+ // will not always fit line's height. In this case, they will
476
+ // draw out of line's bounds. To prevent them from being clipped
477
+ // by next line's background, paint entire background before any
478
+ // foreground.
479
+ // I considered to make this mode default, but was worried about
480
+ // potential regressions in various legacy code. For example, it
481
+ // could change something about line heights/colors during
482
+ // painting. While this doesn't sound like a good thing to do, yet
483
+ // still, I'd rather stay safe.
484
+ final boolean drawBackBeforeFore = (fixedLineMetrics != null );
475
485
476
486
if (drawBackBeforeFore ) {
477
- return 0 ;
487
+ // Cache drawing information
488
+ final List <LineDrawInfo > drawInfos = new ArrayList <>();
489
+ int y = begY ;
490
+ for (int iLine = startLine ; y < endY && iLine < endLine ; iLine ++) {
491
+ LineDrawInfo lineInfo = makeLineDrawInfo (iLine );
492
+ drawInfos .add (lineInfo );
493
+ y += lineInfo .height ;
494
+ }
495
+
496
+ // Draw background
497
+ y = begY ;
498
+ for (LineDrawInfo lineInfo : drawInfos ) {
499
+ drawLineBackground (lineInfo , y , gc , widgetBackground );
500
+ y += lineInfo .height ;
501
+ }
502
+
503
+ // Draw foreground
504
+ y = begY ;
505
+ for (LineDrawInfo lineInfo : drawInfos ) {
506
+ drawLineForeground (lineInfo , begX , y , gc , widgetForeground );
507
+ y += lineInfo .height ;
508
+ }
509
+
510
+ // cleanup
511
+ for (LineDrawInfo lineInfo : drawInfos ) {
512
+ disposeTextLayout (lineInfo .layout );
513
+ }
514
+
515
+ return y - begY ;
478
516
}
479
517
480
518
int y = begY ;
0 commit comments