@@ -2638,13 +2638,15 @@ func (w *Window) drawTextInPosWithCache(p *gui.QPainter, x, y int, text string,
2638
2638
2639
2639
if err != nil {
2640
2640
image = w .newTextCache (text , highlight , isNormalWidth )
2641
- w .setTextCache (text , highlight , image )
2641
+ if image != nil {
2642
+ w .setTextCache (text , highlight , image )
2643
+ }
2642
2644
} else {
2643
2645
image = imagev .(* gui.QImage )
2644
2646
}
2645
2647
2646
2648
// return if image is invalid
2647
- if image . Width () == 0 && image . Height () == 0 {
2649
+ if image == nil {
2648
2650
return
2649
2651
}
2650
2652
@@ -2826,6 +2828,12 @@ func (w *Window) newTextCache(text string, highlight *Highlight, isNormalWidth b
2826
2828
}
2827
2829
}
2828
2830
2831
+ imageWidth := int (math .Ceil (w .devicePixelRatio * width ))
2832
+ imageHeight := int (w .devicePixelRatio * float64 (font .lineHeight ))
2833
+ if imageWidth <= 0 || imageHeight <= 0 {
2834
+ return nil
2835
+ }
2836
+
2829
2837
// QImage default device pixel ratio is 1.0,
2830
2838
// So we set the correct device pixel ratio
2831
2839
@@ -2839,8 +2847,8 @@ func (w *Window) newTextCache(text string, highlight *Highlight, isNormalWidth b
2839
2847
// gui.QImage__Format_ARGB32_Premultiplied,
2840
2848
// )
2841
2849
image := gui .NewQImage3 (
2842
- int ( math . Ceil ( w . devicePixelRatio * width )) ,
2843
- int ( w . devicePixelRatio * float64 ( font . lineHeight )) ,
2850
+ imageWidth ,
2851
+ imageHeight ,
2844
2852
gui .QImage__Format_ARGB32_Premultiplied ,
2845
2853
)
2846
2854
0 commit comments