Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when no text color is provided #2349

Merged
merged 1 commit into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,7 +3,7 @@
This file lists the main changes with each version of the Fyne toolkit.
More detailed release notes can be found on the [releases page](https://github.com/fyne-io/fyne/releases).

## 2.0.4 - 4 August 2021
## 2.0.4 - 6 August 2021

### Changed

Expand All @@ -28,6 +28,8 @@ More detailed release notes can be found on the [releases page](https://github.c
* ScrollToBottom not always scrolling all the way when items added to container.Scroller
* Fixed scrollbar disappearing after changing content (#2303)
* Calling SetContent a second time with the same content will not show
* Drawing text can panic when Color is nil (#2347)
* Optimisations when drawing transparent rectangle or whitespace strings


## 2.0.3 - 30 April 2021
Expand Down
7 changes: 6 additions & 1 deletion internal/painter/gl/gl_common.go
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"runtime"

"fyne.io/fyne/v2/theme"
"github.com/goki/freetype"
"github.com/goki/freetype/truetype"
"golang.org/x/image/font"
Expand Down Expand Up @@ -72,6 +73,10 @@ func (p *glPainter) newGlStrokedRectTexture(obj fyne.CanvasObject) Texture {

func (p *glPainter) newGlTextTexture(obj fyne.CanvasObject) Texture {
text := obj.(*canvas.Text)
color := text.Color
if color == nil {
color = theme.ForegroundColor()
}

bounds := text.MinSize()
width := int(p.textureScale(bounds.Width))
Expand All @@ -86,7 +91,7 @@ func (p *glPainter) newGlTextTexture(obj fyne.CanvasObject) Texture {

d := font.Drawer{}
d.Dst = img
d.Src = &image.Uniform{C: text.Color}
d.Src = &image.Uniform{C: color}
d.Face = face
d.Dot = freetype.Pt(0, height-face.Metrics().Descent.Ceil())
d.DrawString(text.Text)
Expand Down
8 changes: 7 additions & 1 deletion internal/painter/software/draw.go
Expand Up @@ -9,6 +9,7 @@ import (
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/internal"
"fyne.io/fyne/v2/internal/painter"
"fyne.io/fyne/v2/theme"

"github.com/goki/freetype"
"github.com/goki/freetype/truetype"
Expand Down Expand Up @@ -139,6 +140,11 @@ func drawText(c fyne.Canvas, text *canvas.Text, pos fyne.Position, base *image.N
height := internal.ScaleInt(c, bounds.Height)
txtImg := image.NewRGBA(image.Rect(0, 0, width, height))

color := text.Color
if color == nil {
color = theme.ForegroundColor()
}

var opts truetype.Options
fontSize := text.TextSize * c.Scale()
opts.Size = float64(fontSize)
Expand All @@ -147,7 +153,7 @@ func drawText(c fyne.Canvas, text *canvas.Text, pos fyne.Position, base *image.N

d := font.Drawer{}
d.Dst = txtImg
d.Src = &image.Uniform{C: text.Color}
d.Src = &image.Uniform{C: color}
d.Face = face
d.Dot = freetype.Pt(0, height-face.Metrics().Descent.Ceil())
d.DrawString(text.Text)
Expand Down
1 change: 1 addition & 0 deletions widget/form.go
Expand Up @@ -111,6 +111,7 @@ func (f *Form) createInput(item *FormItem) fyne.CanvasObject {
func (f *Form) createLabel(text string) *canvas.Text {
return &canvas.Text{Text: text,
Alignment: fyne.TextAlignTrailing,
Color: theme.ForegroundColor(),
TextSize: theme.TextSize(),
TextStyle: fyne.TextStyle{Bold: true}}
}
Expand Down