Skip to content

Commit

Permalink
Merge pull request #3991 from andydotxyz/feature/emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jun 30, 2023
2 parents 348e88b + 33edeca commit 07d3354
Show file tree
Hide file tree
Showing 31 changed files with 80 additions and 184 deletions.
2 changes: 1 addition & 1 deletion cmd/hello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
w.SetContent(container.NewVBox(
hello,
widget.NewButton("Hi!", func() {
hello.SetText("Welcome :)")
hello.SetText("Welcome 😀")
}),
))

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ require (
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b
github.com/go-ole/go-ole v1.2.6
github.com/go-text/render v0.0.0-20230327192424-adef04305ec0
github.com/go-text/typesetting v0.0.0-20230618175549-b5753034b590
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8
github.com/go-text/typesetting v0.0.0-20230616162802-9c17dd34aa4a
github.com/godbus/dbus/v5 v5.1.0
github.com/gopherjs/gopherjs v1.17.2
github.com/jackmordaunt/icns/v2 v2.2.1
github.com/josephspurrier/goversioninfo v1.4.0
github.com/lucor/goinfo v0.0.0-20210802170112-c078a2b0f08b
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
github.com/stretchr/testify v1.8.0
github.com/urfave/cli/v2 v2.4.0
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOY
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-text/render v0.0.0-20230327192424-adef04305ec0 h1:1F5PnpZdOJnVRxfy378mjm2j6HYBA5suRLlqA+RndhA=
github.com/go-text/render v0.0.0-20230327192424-adef04305ec0/go.mod h1:+qxdVKijbZKOO8XX9gt6gnHnu3qNU3APpPLiSQSgvXM=
github.com/go-text/typesetting v0.0.0-20230326213217-3355bdaa7d70/go.mod h1:zvWM81wAVW6QfVDI6yxfbCuoLnobSYTuMsrXU/u11y8=
github.com/go-text/typesetting v0.0.0-20230618175549-b5753034b590 h1:n6u3xKVUsKptNLSgG4IbJIuha5tS++YpMHVBCNk4ssE=
github.com/go-text/typesetting v0.0.0-20230618175549-b5753034b590/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k=
github.com/go-text/typesetting-utils v0.0.0-20230326210548-458646692de6/go.mod h1:RaqFwjcYyM5BjbYGwON0H5K0UqwO3sJlo9ukKha80ZE=
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 h1:VkKnvzbvHqgEfm351rfr8Uclu5fnwq8HP2ximUzJsBM=
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8/go.mod h1:h29xCucjNsDcYb7+0rJokxVwYAq+9kQ19WiFuBKkYtc=
github.com/go-text/typesetting v0.0.0-20230616162802-9c17dd34aa4a h1:VjN8ttdfklC0dnAdKbZqGNESdERUxtE3l8a/4Grgarc=
github.com/go-text/typesetting v0.0.0-20230616162802-9c17dd34aa4a/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k=
github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22 h1:LBQTFxP2MfsyEDqSKmUBZaDuDHN1vpqDyOZjcqS7MYI=
github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -275,8 +273,8 @@ github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t6
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76 h1:Ga2uagHhDeGysCixLAzH0mS2TU+CrbQavmsHUNkEEVA=
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE=
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ=
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
Expand Down
2 changes: 0 additions & 2 deletions internal/driver/mobile/gl/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ const (
DepthTest = 0x0B71
Blend = 0x0BE2
ScissorTest = 0x0C11
UnpackAlignment = 0x0CF5
Texture2D = 0x0DE1

UnsignedByte = 0x1401
Float = 0x1406
RED = 0x1903
RGBA = 0x1908
LUMINANCE = 0x1909

Nearest = 0x2600
Linear = 0x2601
Expand Down
1 change: 0 additions & 1 deletion internal/driver/mobile/gl/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const (
glfnGetShaderiv
glfnGetTexParameteriv
glfnGetUniformLocation
glfnPixelStorei
glfnLinkProgram
glfnReadPixels
glfnScissor
Expand Down
10 changes: 0 additions & 10 deletions internal/driver/mobile/gl/gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,6 @@ func (ctx *context) LinkProgram(p Program) {
})
}

func (ctx *context) PixelStorei(pname Enum, param int32) {
ctx.enqueue(call{
args: fnargs{
fn: glfnPixelStorei,
a0: pname.c(),
a1: uintptr(param),
},
})
}

func (ctx *context) ReadPixels(dst []byte, x, y, width, height int, format, ty Enum) {
ctx.enqueue(call{
args: fnargs{
Expand Down
5 changes: 0 additions & 5 deletions internal/driver/mobile/gl/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ type Context interface {
// http://www.khronos.org/opengles/sdk/docs/man3/html/glLinkProgram.xhtml
LinkProgram(p Program)

// PixelStorei set pixel storage modes
//
// https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glPixelStorei.xhtml
PixelStorei(pname Enum, param int32)

// ReadPixels returns pixel data from a buffer.
//
// In GLES 3, the source buffer is controlled with ReadBuffer.
Expand Down
3 changes: 0 additions & 3 deletions internal/driver/mobile/gl/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ uintptr_t processFn(struct fnargs* args, char* parg) {
case glfnLinkProgram:
glLinkProgram((GLint)args->a0);
break;
case glfnPixelStorei:
glPixelStorei((GLenum)args->a0, (GLint)args->a1);
break;
case glfnReadPixels:
glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)parg);
break;
Expand Down
1 change: 0 additions & 1 deletion internal/driver/mobile/gl/work.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typedef enum {
glfnGetShaderiv,
glfnGetTexParameteriv,
glfnGetUniformLocation,
glfnPixelStorei,
glfnLinkProgram,
glfnReadPixels,
glfnScissor,
Expand Down
4 changes: 0 additions & 4 deletions internal/driver/mobile/gl/work_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ var glfnMap = map[glfn]func(c call) (ret uintptr){
ret, _, _ = syscall.Syscall(glGetUniformLocation.Addr(), 2, c.args.a0, c.args.a1, 0)
return ret
},
glfnPixelStorei: func(c call) (ret uintptr) {
syscall.Syscall(glPixelStorei.Addr(), 2, c.args.a0, c.args.a1, 0)
return
},
glfnLinkProgram: func(c call) (ret uintptr) {
syscall.Syscall(glLinkProgram.Addr(), 1, c.args.a0, 0, 0)
return
Expand Down
20 changes: 12 additions & 8 deletions internal/painter/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func CachedFontFace(style fyne.TextStyle, fontDP float32, texScale float32) *Fon
if f1 == nil {
f1 = f2
}
val = &FontCacheItem{Fonts: []font.Face{f1, f2}}
faces := []font.Face{f1, f2}
if emoji := theme.DefaultEmojiFont(); emoji != nil {
faces = append(faces, loadMeasureFont(emoji))
}
val = &FontCacheItem{Fonts: faces}
fontCache.Store(style, val)
}

Expand Down Expand Up @@ -186,7 +190,7 @@ func walkString(faces []font.Face, s string, textSize fixed.Int26_6, tabWidth in
if pending {
in.RunEnd = i
out = shaper.Shape(in)
x = shapeCallback(shaper, in, out, x, cb)
x = shapeCallback(shaper, in, out, x, scale, cb)
}
x = tabStop(spacew, x, tabWidth)

Expand All @@ -198,15 +202,15 @@ func walkString(faces []font.Face, s string, textSize fixed.Int26_6, tabWidth in
}
}

x = shapeCallback(shaper, in, out, x, cb)
x = shapeCallback(shaper, in, out, x, scale, cb)
}

*advance = x
return fyne.NewSize(*advance, fixed266ToFloat32(out.LineBounds.LineHeight())),
fixed266ToFloat32(out.LineBounds.Ascent)
}

func shapeCallback(shaper shaping.Shaper, in shaping.Input, out shaping.Output, x float32, cb func(shaping.Output, float32)) float32 {
func shapeCallback(shaper shaping.Shaper, in shaping.Input, out shaping.Output, x, scale float32, cb func(shaping.Output, float32)) float32 {
out = shaper.Shape(in)
glyphs := out.Glyphs
start := 0
Expand All @@ -217,13 +221,13 @@ func shapeCallback(shaper shaping.Shaper, in shaping.Input, out shaping.Output,
if pending {
out.Glyphs = glyphs[start:i]
cb(out, x)
x += fixed266ToFloat32(adv)
x += fixed266ToFloat32(adv) * scale
adv = 0
}

out.Glyphs = glyphs[i : i+1]
cb(out, x)
x += fixed266ToFloat32(glyphs[i].XAdvance)
x += fixed266ToFloat32(glyphs[i].XAdvance) * scale
adv = 0

start = i + 1
Expand All @@ -237,10 +241,10 @@ func shapeCallback(shaper shaping.Shaper, in shaping.Input, out shaping.Output,
if pending {
out.Glyphs = glyphs[start:]
cb(out, x)
x += fixed266ToFloat32(adv)
x += fixed266ToFloat32(adv) * scale
adv = 0
}
return x + fixed266ToFloat32(adv)
return x + fixed266ToFloat32(adv)*scale
}

type FontCacheItem struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/painter/font_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestDrawString(t *testing.T) {
color: color.Black,
style: fyne.TextStyle{},
size: 40,
string: "Missing: ",
string: "Missing: ",
tabWidth: 4,
want: "missing_glyph.png",
},
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestMeasureString(t *testing.T) {
"missing glyph": {
style: fyne.TextStyle{},
size: 40,
string: "Missing: ",
string: "Missing: ",
tabWidth: 4,
want: 213.65625,
},
Expand Down
1 change: 0 additions & 1 deletion internal/painter/gl/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type context interface {
GetShaderInfoLog(shader Shader) string
GetUniformLocation(program Program, name string) Uniform
LinkProgram(program Program)
PixelStorei(pname uint32, param int32)
ReadBuffer(src uint32)
ReadPixels(x, y, width, height int, colorFormat, typ uint32, pixels []uint8)
Scissor(x, y, w, h int32)
Expand Down
38 changes: 1 addition & 37 deletions internal/painter/gl/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
paint "fyne.io/fyne/v2/internal/painter"
"fyne.io/fyne/v2/theme"
)

func (p *painter) createBuffer(points []float32) Buffer {
Expand Down Expand Up @@ -182,45 +181,10 @@ func (p *painter) drawText(text *canvas.Text, pos fyne.Position, frame fyne.Size
pos = fyne.NewPos(pos.X, pos.Y+(containerSize.Height-size.Height)/2)
}

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

// text size is sensitive to position on screen
size, _ = roundToPixelCoords(size, text.Position(), p.pixScale)
size.Width += roundToPixel(paint.VectorPad(text), p.pixScale)
p.drawSingleChannelTexture(text, p.newGlTextTexture, pos, size, frame, color, 0)
}

func (p *painter) drawSingleChannelTexture(o fyne.CanvasObject, creator func(canvasObject fyne.CanvasObject) Texture,
pos fyne.Position, size, frame fyne.Size, c color.Color, pad float32) {
texture, err := p.getTexture(o, creator)
if err != nil {
return
}

points := p.rectCoords(size, pos, frame, canvas.ImageFillStretch, 0, pad)
p.ctx.UseProgram(p.singleChannelProgram)
vbo := p.createBuffer(points)
p.defineVertexArray(p.singleChannelProgram, "vert", 3, 5, 0)
p.defineVertexArray(p.singleChannelProgram, "vertTexCoord", 2, 5, 3)

p.ctx.BlendFunc(srcAlpha, oneMinusSrcAlpha)
p.logError()

shaderColor := p.ctx.GetUniformLocation(p.singleChannelProgram, "color")
r, g, b, a := getFragmentColor(c)
p.ctx.Uniform4f(shaderColor, r, g, b, a)

p.ctx.ActiveTexture(texture0)
p.ctx.BindTexture(texture2D, texture)
p.logError()

p.ctx.DrawArrays(triangleStrip, 0, 4)
p.logError()
p.freeBuffer(vbo)

p.drawTextureWithDetails(text, p.newGlTextTexture, pos, size, frame, canvas.ImageFillStretch, 1.0, 0)
}

func (p *painter) drawTextureWithDetails(o fyne.CanvasObject, creator func(canvasObject fyne.CanvasObject) Texture,
Expand Down
9 changes: 0 additions & 9 deletions internal/painter/gl/gl_const_darwin.go

This file was deleted.

17 changes: 0 additions & 17 deletions internal/painter/gl/gl_const_mobile.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/painter/gl/gl_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
bitDepthBuffer = gl.DEPTH_BUFFER_BIT
clampToEdge = gl.CLAMP_TO_EDGE
colorFormatRGBA = gl.RGBA
colorFormatR = gl.RED
compileStatus = gl.COMPILE_STATUS
constantAlpha = gl.CONSTANT_ALPHA
float = gl.FLOAT
Expand All @@ -39,7 +38,6 @@ const (
textureWrapT = gl.TEXTURE_WRAP_T
triangles = gl.TRIANGLES
triangleStrip = gl.TRIANGLE_STRIP
unpackAlignment = gl.UNPACK_ALIGNMENT
unsignedByte = gl.UNSIGNED_BYTE
vertexShader = gl.VERTEX_SHADER
)
Expand Down Expand Up @@ -74,7 +72,6 @@ func (p *painter) Init() {
gl.Enable(gl.BLEND)
p.logError()
p.program = p.createProgram("simple")
p.singleChannelProgram = p.createProgram("single_channel")
p.lineProgram = p.createProgram("line")
p.rectangleProgram = p.createProgram("rectangle")
p.roundRectangleProgram = p.createProgram("round_rectangle")
Expand Down Expand Up @@ -213,10 +210,6 @@ func (c *coreContext) LinkProgram(program Program) {
gl.LinkProgram(uint32(program))
}

func (c *coreContext) PixelStorei(pname uint32, param int32) {
gl.PixelStorei(pname, param)
}

func (c *coreContext) ReadBuffer(src uint32) {
gl.ReadBuffer(src)
}
Expand Down
7 changes: 0 additions & 7 deletions internal/painter/gl/gl_es.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
bitDepthBuffer = gl.DEPTH_BUFFER_BIT
clampToEdge = gl.CLAMP_TO_EDGE
colorFormatRGBA = gl.RGBA
colorFormatR = gl.LUMINANCE
compileStatus = gl.COMPILE_STATUS
constantAlpha = gl.CONSTANT_ALPHA
float = gl.FLOAT
Expand All @@ -46,7 +45,6 @@ const (
textureWrapT = gl.TEXTURE_WRAP_T
triangles = gl.TRIANGLES
triangleStrip = gl.TRIANGLE_STRIP
unpackAlignment = gl.UNPACK_ALIGNMENT
unsignedByte = gl.UNSIGNED_BYTE
vertexShader = gl.VERTEX_SHADER
)
Expand Down Expand Up @@ -81,7 +79,6 @@ func (p *painter) Init() {
gl.Enable(gl.BLEND)
p.logError()
p.program = p.createProgram("simple_es")
p.singleChannelProgram = p.createProgram("single_channel_es")
p.lineProgram = p.createProgram("line_es")
p.rectangleProgram = p.createProgram("rectangle_es")
p.roundRectangleProgram = p.createProgram("round_rectangle_es")
Expand Down Expand Up @@ -220,10 +217,6 @@ func (c *esContext) LinkProgram(program Program) {
gl.LinkProgram(uint32(program))
}

func (c *esContext) PixelStorei(pname uint32, param int32) {
gl.PixelStorei(pname, param)
}

func (c *esContext) ReadBuffer(src uint32) {
gl.ReadBuffer(src)
}
Expand Down
Loading

0 comments on commit 07d3354

Please sign in to comment.