@@ -49,9 +49,16 @@ type Highlight struct {
49
49
underdashed bool
50
50
}
51
51
52
+ // HlText is used in screen cache
53
+ type HlKey struct {
54
+ fg RGBA
55
+ italic bool
56
+ bold bool
57
+ }
58
+
52
59
// HlText is used in screen cache
53
60
type HlTextKey struct {
54
- fg * RGBA
61
+ fg RGBA
55
62
text string
56
63
italic bool
57
64
bold bool
@@ -2303,7 +2310,7 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2303
2310
}
2304
2311
2305
2312
line := w .content [y ]
2306
- chars := map [* Highlight ][]int {}
2313
+ chars := map [HlKey ][]int {}
2307
2314
specialChars := []int {}
2308
2315
cellBasedDrawing := editor .config .Editor .DisableLigatures || (editor .config .Editor .Letterspace > 0 )
2309
2316
wsfontLineHeight := y * wsfont .lineHeight
@@ -2367,7 +2374,11 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2367
2374
int (float64 (x )* wsfont .cellwidth )+ horScrollPixels ,
2368
2375
wsfontLineHeight + verScrollPixels ,
2369
2376
line [x ].char ,
2370
- line [x ].highlight ,
2377
+ HlKey {
2378
+ fg : * (line [x ].highlight .fg ()),
2379
+ bold : line [x ].highlight .bold ,
2380
+ italic : line [x ].highlight .italic ,
2381
+ },
2371
2382
true ,
2372
2383
line [x ].scaled ,
2373
2384
)
@@ -2381,19 +2392,24 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2381
2392
highlight .background = highlight .background .copy ()
2382
2393
}
2383
2394
2384
- colorSlice , ok := chars [highlight ]
2395
+ hlkey := HlKey {
2396
+ fg : * (highlight .fg ()),
2397
+ italic : highlight .italic ,
2398
+ bold : highlight .bold ,
2399
+ }
2400
+ colorSlice , ok := chars [hlkey ]
2385
2401
if ! ok {
2386
2402
colorSlice = []int {}
2387
2403
}
2388
2404
colorSlice = append (colorSlice , x )
2389
- chars [highlight ] = colorSlice
2405
+ chars [hlkey ] = colorSlice
2390
2406
}
2391
2407
}
2392
2408
2393
2409
// This is the normal rendering process for goneovim,
2394
2410
// we draw a word snippet of the same highlight on the screen for each of the highlights.
2395
2411
if ! cellBasedDrawing {
2396
- for highlight , colorSlice := range chars {
2412
+ for hlkey , colorSlice := range chars {
2397
2413
var buffer bytes.Buffer
2398
2414
slice := colorSlice
2399
2415
@@ -2409,7 +2425,7 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2409
2425
if editor .config .Editor .LineToScroll == 1 {
2410
2426
verScrollPixels += w .scrollPixels [1 ]
2411
2427
}
2412
- if highlight .isSignColumn () {
2428
+ if line [ x ]. highlight .isSignColumn () {
2413
2429
horScrollPixels = 0
2414
2430
}
2415
2431
if x < w .viewportMargins [2 ] || x > w .cols - w .viewportMargins [3 ]- 1 {
@@ -2483,7 +2499,7 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2483
2499
int (float64 (x - pos )* wsfont .cellwidth )+ horScrollPixels ,
2484
2500
wsfontLineHeight + verScrollPixels ,
2485
2501
buffer .String (),
2486
- highlight ,
2502
+ hlkey ,
2487
2503
true ,
2488
2504
false ,
2489
2505
)
@@ -2541,7 +2557,11 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2541
2557
int (float64 (x )* wsfont .cellwidth )+ horScrollPixels ,
2542
2558
wsfontLineHeight + verScrollPixels ,
2543
2559
line [x ].char ,
2544
- line [x ].highlight ,
2560
+ HlKey {
2561
+ fg : * (line [x ].highlight .fg ()),
2562
+ bold : line [x ].highlight .bold ,
2563
+ italic : line [x ].highlight .italic ,
2564
+ },
2545
2565
false ,
2546
2566
line [x ].scaled ,
2547
2567
)
@@ -2550,7 +2570,7 @@ func (w *Window) drawText(p *gui.QPainter, y int, col int, cols int) {
2550
2570
}
2551
2571
}
2552
2572
2553
- func (w * Window ) drawTextInPos (p * gui.QPainter , x , y int , text string , highlight * Highlight , isNormalWidth bool , scaled bool ) {
2573
+ func (w * Window ) drawTextInPos (p * gui.QPainter , x , y int , text string , hlkey HlKey , isNormalWidth bool , scaled bool ) {
2554
2574
wsfont := w .getFont ()
2555
2575
2556
2576
// var horScrollPixels int
@@ -2566,7 +2586,7 @@ func (w *Window) drawTextInPos(p *gui.QPainter, x, y int, text string, highlight
2566
2586
x , //+horScrollPixels,
2567
2587
y + wsfont .shift ,
2568
2588
text ,
2569
- highlight ,
2589
+ hlkey ,
2570
2590
isNormalWidth ,
2571
2591
scaled ,
2572
2592
)
@@ -2576,14 +2596,14 @@ func (w *Window) drawTextInPos(p *gui.QPainter, x, y int, text string, highlight
2576
2596
x , //+horScrollPixels,
2577
2597
y ,
2578
2598
text ,
2579
- highlight ,
2599
+ hlkey ,
2580
2600
isNormalWidth ,
2581
2601
scaled ,
2582
2602
)
2583
2603
}
2584
2604
}
2585
2605
2586
- func (w * Window ) drawTextInPosWithNoCache (p * gui.QPainter , x , y int , text string , highlight * Highlight , isNormalWidth bool , scaled bool ) {
2606
+ func (w * Window ) drawTextInPosWithNoCache (p * gui.QPainter , x , y int , text string , hlkey HlKey , isNormalWidth bool , scaled bool ) {
2587
2607
if text == "" {
2588
2608
return
2589
2609
}
@@ -2602,24 +2622,15 @@ func (w *Window) drawTextInPosWithNoCache(p *gui.QPainter, x, y int, text string
2602
2622
p .SetFont (fontfallbacked .qfont )
2603
2623
2604
2624
font := p .Font ()
2605
- fg := highlight .fg ( )
2625
+ fg := & ( hlkey .fg )
2606
2626
p .SetPen2 (fg .QColor ())
2607
2627
2608
- if highlight .bold {
2609
- font .SetBold (true )
2610
- } else {
2611
- font .SetBold (false )
2612
- }
2613
- if highlight .italic {
2614
- font .SetItalic (true )
2615
- } else {
2616
- font .SetItalic (false )
2617
- }
2618
- // p.DrawText(point, text)
2628
+ font .SetBold (hlkey .bold )
2629
+ font .SetItalic (hlkey .italic )
2619
2630
p .DrawText3 (x , y , text )
2620
2631
}
2621
2632
2622
- func (w * Window ) drawTextInPosWithCache (p * gui.QPainter , x , y int , text string , highlight * Highlight , isNormalWidth bool , scaled bool ) {
2633
+ func (w * Window ) drawTextInPosWithCache (p * gui.QPainter , x , y int , text string , hlkey HlKey , isNormalWidth bool , scaled bool ) {
2623
2634
if text == "" {
2624
2635
return
2625
2636
}
@@ -2628,15 +2639,15 @@ func (w *Window) drawTextInPosWithCache(p *gui.QPainter, x, y int, text string,
2628
2639
var image * gui.QImage
2629
2640
imagev , err := cache .get (HlTextKey {
2630
2641
text : text ,
2631
- fg : highlight .fg () ,
2632
- italic : highlight .italic ,
2633
- bold : highlight .bold ,
2642
+ fg : hlkey .fg ,
2643
+ italic : hlkey .italic ,
2644
+ bold : hlkey .bold ,
2634
2645
})
2635
2646
2636
2647
if err != nil {
2637
- image = w .newTextCache (text , highlight , isNormalWidth )
2648
+ image = w .newTextCache (text , hlkey , isNormalWidth )
2638
2649
if image != nil {
2639
- w .setTextCache (text , highlight , image )
2650
+ w .setTextCache (text , hlkey , image )
2640
2651
}
2641
2652
} else {
2642
2653
image = imagev .(* gui.QImage )
@@ -2745,15 +2756,15 @@ func (w *Window) newDecorationCache(char string, highlight *Highlight, isNormalW
2745
2756
return image
2746
2757
}
2747
2758
2748
- func (w * Window ) setTextCache (text string , highlight * Highlight , image * gui.QImage ) {
2759
+ func (w * Window ) setTextCache (text string , hlkey HlKey , image * gui.QImage ) {
2749
2760
if w .font != nil {
2750
2761
// If window has own font setting
2751
2762
w .cache .set (
2752
2763
HlTextKey {
2753
2764
text : text ,
2754
- fg : highlight .fg () ,
2755
- italic : highlight .italic ,
2756
- bold : highlight .bold ,
2765
+ fg : hlkey .fg ,
2766
+ italic : hlkey .italic ,
2767
+ bold : hlkey .bold ,
2757
2768
},
2758
2769
image ,
2759
2770
)
@@ -2762,9 +2773,9 @@ func (w *Window) setTextCache(text string, highlight *Highlight, image *gui.QIma
2762
2773
w .s .cache .set (
2763
2774
HlTextKey {
2764
2775
text : text ,
2765
- fg : highlight .fg () ,
2766
- italic : highlight .italic ,
2767
- bold : highlight .bold ,
2776
+ fg : hlkey .fg ,
2777
+ italic : hlkey .italic ,
2778
+ bold : hlkey .bold ,
2768
2779
},
2769
2780
image ,
2770
2781
)
@@ -2784,7 +2795,7 @@ func (w *Window) destroyImagePainter() {
2784
2795
}
2785
2796
}
2786
2797
2787
- func (w * Window ) newTextCache (text string , highlight * Highlight , isNormalWidth bool ) * gui.QImage {
2798
+ func (w * Window ) newTextCache (text string , hlkey HlKey , isNormalWidth bool ) * gui.QImage {
2788
2799
// * Ref: https://stackoverflow.com/questions/40458515/a-best-way-to-draw-a-lot-of-independent-characters-in-qt5/40476430#40476430
2789
2800
editor .putLog ("start creating word cache:" , text )
2790
2801
@@ -2813,11 +2824,11 @@ func (w *Window) newTextCache(text string, highlight *Highlight, isNormalWidth b
2813
2824
}
2814
2825
2815
2826
width := float64 (len (text ))* font .cellwidth + 1
2816
- if highlight .italic {
2827
+ if hlkey .italic {
2817
2828
width = float64 (len (text ))* font .italicWidth + 1
2818
2829
}
2819
2830
2820
- fg := highlight .fg ()
2831
+ fg := hlkey .fg
2821
2832
if ! isNormalWidth {
2822
2833
advance := fontfallbacked .fontMetrics .HorizontalAdvance (text , - 1 )
2823
2834
if advance > 0 {
@@ -2859,12 +2870,11 @@ func (w *Window) newTextCache(text string, highlight *Highlight, isNormalWidth b
2859
2870
w .imagePainter .SetPen2 (fg .QColor ())
2860
2871
w .imagePainter .SetFont (fontfallbacked .qfont )
2861
2872
2862
- if highlight .bold {
2863
- w .imagePainter .Font ().SetBold (true )
2864
- // w.imagePainter.Font().SetWeight(font.qfont.Weight() + 50)
2873
+ if hlkey .bold {
2874
+ w .imagePainter .Font ().SetBold (hlkey .bold )
2865
2875
}
2866
- if highlight .italic {
2867
- w .imagePainter .Font ().SetItalic (true )
2876
+ if hlkey .italic {
2877
+ w .imagePainter .Font ().SetItalic (hlkey . italic )
2868
2878
}
2869
2879
2870
2880
w .imagePainter .DrawText6 (
0 commit comments