Skip to content

Commit

Permalink
Default to adding border and rounding corners of macOS icons
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed May 10, 2023
1 parent b1d74e2 commit 3e17fe7
Show file tree
Hide file tree
Showing 34 changed files with 9,461 additions and 2 deletions.
26 changes: 25 additions & 1 deletion cmd/fyne/internal/commands/package-darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package commands
import (
"fmt"
"image"
"image/color"
"os"
"path/filepath"
"strings"

"fyne.io/fyne/v2/cmd/fyne/internal/templates"
"github.com/fogleman/gg"
"github.com/nfnt/resize"

"github.com/jackmordaunt/icns/v2"
)
Expand Down Expand Up @@ -69,9 +72,30 @@ func (p *Packager) packageDarwin() (err error) {
err = r
}
}()
if err := icns.Encode(dest, srcImg); err != nil {
if err := icns.Encode(dest, processMacOSIcon(srcImg)); err != nil {
return fmt.Errorf("failed to encode icns: %w", err)
}

return nil
}

func processMacOSIcon(in image.Image) image.Image {
size := 1024
border := 100
radius := 185.4

innerSize := int(float64(size) - float64(border*2)) // how many pixels inside border
sized := resize.Resize(uint(innerSize), uint(innerSize), in, resize.Lanczos3)

dc := gg.NewContext(size, size)
dc.DrawRoundedRectangle(float64(border), float64(border), float64(innerSize), float64(innerSize), radius)
dc.SetColor(color.Black)
dc.Fill()
mask := dc.AsMask()

dc = gg.NewContext(size, size)
_ = dc.SetMask(mask) // ignore error if size was not equal, as it is
dc.DrawImage(sized, border, border)

return dc.Image()
}
20 changes: 20 additions & 0 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package commands

import (
"image"
"os"
"path/filepath"
"runtime"
"testing"
Expand All @@ -9,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2/cmd/fyne/internal/metadata"
"fyne.io/fyne/v2/test"
)

func Test_calculateExeName(t *testing.T) {
Expand Down Expand Up @@ -69,6 +72,23 @@ func Test_combinedVersion(t *testing.T) {
}
}

func Test_processMacOSIcon(t *testing.T) {
f, err := os.Open("testdata/icon.png")
if err != nil {
t.Error(err)
return
}
defer f.Close()
icon, _, err := image.Decode(f)
if err != nil {
t.Error(err)
return
}
processed := processMacOSIcon(icon)

test.AssertImageMatches(t, "icon-darwin.png", processed)
}

func Test_MergeMetata(t *testing.T) {
p := &Packager{appData: &appData{}}
p.AppVersion = "v0.1"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/fyne/internal/commands/testdata/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
fyne.io/systray v1.10.1-0.20230403195833-7dc3c09283d6
github.com/BurntSushi/toml v1.1.0
github.com/fogleman/gg v1.3.0
github.com/fredbi/uri v0.1.0
github.com/fsnotify/fsnotify v1.5.4
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe
Expand All @@ -21,6 +22,7 @@ require (
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/rasterx v0.0.0-20220730225603-2ab79fcdd4ef
github.com/stretchr/testify v1.8.0
Expand All @@ -38,8 +40,8 @@ require (
github.com/akavel/rsrc v0.10.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tevino/abool v1.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fredbi/uri v0.1.0 h1:8XBBD74STBLcWJ5smjEkKCZivSxSKMhFB0FbQUKeNyM=
github.com/fredbi/uri v0.1.0/go.mod h1:1xC40RnIOGCaQzswaOvrzvG/3M3F0hyDVb3aO/1iGy0=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand Down Expand Up @@ -109,6 +111,8 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/fogleman/gg/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/fogleman/gg/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

221 changes: 221 additions & 0 deletions vendor/github.com/fogleman/gg/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e17fe7

Please sign in to comment.