all: apply suggestions from staticcheck.io

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-06-03 12:22:52 +02:00
committed by Elias Naur
parent 11192a5142
commit 916efb4612
13 changed files with 7 additions and 219 deletions
+1 -2
View File
@@ -71,7 +71,6 @@ type Window struct {
animating bool
hasNextFrame bool
nextFrame time.Time
delayedDraw *time.Timer
// viewport is the latest frame size with insets applied.
viewport image.Rectangle
// metric is the metric from the most recent frame.
@@ -147,7 +146,7 @@ func NewWindow(options ...Option) *Window {
w := &Window{
out: make(chan event.Event),
immediateRedraws: make(chan struct{}, 0),
immediateRedraws: make(chan struct{}),
redraws: make(chan struct{}, 1),
scheduledRedraws: make(chan time.Time, 1),
frames: make(chan *op.Ops),
+1 -10
View File
@@ -100,7 +100,6 @@ func computeGlyphClusters(l *text.Layout) {
clusters = append(clusters, newlineCluster)
}
l.Clusters = clusters
return
}
// langConfig describes the language and writing system of a body of text.
@@ -396,10 +395,6 @@ func toGioGlyphs(in []shaping.Glyph) []text.Glyph {
// ToLine converts the output into a text.Line
func (o output) ToLine() text.Line {
advances := make([]fixed.Int26_6, 0, len(o.Shaped.Glyphs))
for _, glyph := range o.Shaped.Glyphs {
advances = append(advances, glyph.XAdvance)
}
layout := text.Layout{
Glyphs: toGioGlyphs(o.Shaped.Glyphs),
Runes: o.RuneRange,
@@ -458,11 +453,7 @@ func Document(shaper Shaper, face font.Face, ppem fixed.Int26_6, maxWidth int, l
}
paragraphText = append(paragraphText, r)
script := language.LookupScript(r)
if _, ok := langs[script]; ok {
langs[script]++
} else {
langs[script] = 1
}
langs[script]++
bytes += sz
runes++
if r == '\n' {
-2
View File
@@ -890,7 +890,6 @@ func TestEngineLineWrap(t *testing.T) {
func TestEngineDocument(t *testing.T) {
const doc = `Rutrum quisque non tellus orci ac auctor augue.
At risus viverra adipiscing at.`
const numLines = 2
english := system.Locale{
Language: "EN",
Direction: system.LTR,
@@ -980,7 +979,6 @@ func TestLayoutComputeClusters(t *testing.T) {
type testcase struct {
name string
line text.Layout
lastLine bool
expected []text.GlyphCluster
}
for _, tc := range []testcase{
-106
View File
@@ -1,23 +1,13 @@
package opentype
import (
"bytes"
"compress/gzip"
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"golang.org/x/image/font/gofont/goregular"
"golang.org/x/image/math/fixed"
"gioui.org/internal/ops"
"gioui.org/io/system"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/text"
)
var english = system.Locale{
@@ -53,99 +43,3 @@ func TestEmptyString(t *testing.T) {
t.Errorf("got bounds %+v for empty string; expected %+v", got, exp)
}
}
func decompressFontFile(name string) (*Font, []byte, error) {
f, err := os.Open(name)
if err != nil {
return nil, nil, fmt.Errorf("could not open file for reading: %s: %v", name, err)
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
return nil, nil, fmt.Errorf("font file contains invalid gzip data: %v", err)
}
src, err := ioutil.ReadAll(gz)
if err != nil {
return nil, nil, fmt.Errorf("failed to decompress font file: %v", err)
}
fnt, err := Parse(src)
if err != nil {
return nil, nil, fmt.Errorf("file did not contain a valid font: %v", err)
}
return fnt, src, nil
}
// mergeFonts produces a trivial OpenType Collection (OTC) file for two source fonts.
// It makes many assumptions and is not meant for general use.
// For file format details, see https://docs.microsoft.com/en-us/typography/opentype/spec/otff
// For a robust tool to generate these files, see https://pypi.org/project/afdko/
func mergeFonts(ttf1, ttf2 []byte) []byte {
// Locations to place the two embedded fonts. All of the offsets to the fonts' internal tables will need to be
// shifted from the start of the file by the appropriate amount, and then everything will work as expected.
offset1 := uint32(20) // Length of OpenType collection headers
offset2 := offset1 + uint32(len(ttf1))
var buf bytes.Buffer
_, _ = buf.Write([]byte("ttcf\x00\x01\x00\x00\x00\x00\x00\x02"))
_ = binary.Write(&buf, binary.BigEndian, offset1)
_ = binary.Write(&buf, binary.BigEndian, offset2)
// Inline function to copy a font into the collection verbatim, except for adding an offset to all of the font's
// table positions.
copyOffsetTTF := func(ttf []byte, offset uint32) {
_, _ = buf.Write(ttf[:12])
numTables := binary.BigEndian.Uint16(ttf[4:6])
for i := uint16(0); i < numTables; i++ {
p := 12 + 16*i
_, _ = buf.Write(ttf[p : p+8])
tblLoc := binary.BigEndian.Uint32(ttf[p+8:p+12]) + offset
_ = binary.Write(&buf, binary.BigEndian, tblLoc)
_, _ = buf.Write(ttf[p+12 : p+16])
}
_, _ = buf.Write(ttf[12+16*numTables:])
}
copyOffsetTTF(ttf1, offset1)
copyOffsetTTF(ttf2, offset2)
return buf.Bytes()
}
// shapeRune uses a given Face to shape exactly one rune at a fixed size, then returns the resulting shape data.
func shapeRune(f text.Face, r rune) (clip.PathSpec, error) {
ppem := fixed.I(200)
lines, err := f.Layout(ppem, 2000, english, strings.NewReader(string(r)))
if err != nil {
return clip.PathSpec{}, err
}
if len(lines) != 1 {
return clip.PathSpec{}, fmt.Errorf("unexpected rendering for \"U+%08X\": got %d lines (expected: 1)", r, len(lines))
}
return f.Shape(ppem, lines[0].Layout), nil
}
// areShapesEqual returns true iff both given text shapes are produced with identical operations.
func areShapesEqual(shape1, shape2 clip.PathSpec) bool {
var ops1, ops2 op.Ops
clip.Outline{Path: shape1}.Op().Push(&ops1).Pop()
clip.Outline{Path: shape2}.Op().Push(&ops2).Pop()
var r1, r2 ops.Reader
r1.Reset(&ops1.Internal)
r2.Reset(&ops2.Internal)
for {
encOp1, ok1 := r1.Decode()
encOp2, ok2 := r2.Decode()
if ok1 != ok2 {
return false
}
if !ok1 {
break
}
if len(encOp1.Refs) > 0 || len(encOp2.Refs) > 0 {
panic("unexpected ops with refs in font shaping test")
}
if !bytes.Equal(encOp1.Data, encOp2.Data) {
return false
}
}
return true
}
-18
View File
@@ -265,7 +265,6 @@ type clipState struct {
path []byte
pathKey ops.Key
intersect f32.Rectangle
push bool
clipKey
}
@@ -308,11 +307,6 @@ type encoder struct {
ntrans int
}
type encodeState struct {
trans f32.Affine2D
clip f32.Rectangle
}
// sizedBuffer holds a GPU buffer, or its equivalent CPU memory.
type sizedBuffer struct {
size int
@@ -1612,13 +1606,6 @@ func (e *encoder) numElements() int {
return len(e.scene)
}
func (e *encoder) append(e2 encoder) {
e.scene = append(e.scene, e2.scene...)
e.npath += e2.npath
e.npathseg += e2.npathseg
e.ntrans += e2.ntrans
}
func (e *encoder) transform(m f32.Affine2D) {
e.scene = append(e.scene, scene.Transform(m))
e.ntrans++
@@ -1666,11 +1653,6 @@ func (e *encoder) line(start, end f32.Point) {
e.npathseg++
}
func (e *encoder) quad(start, ctrl, end f32.Point) {
e.scene = append(e.scene, scene.Quad(start, ctrl, end))
e.npathseg++
}
func (c *collector) reset() {
c.prevFrame, c.frame = c.frame, c.prevFrame
c.profile = false
-20
View File
@@ -49,7 +49,6 @@ type Backend struct {
type glState struct {
drawFBO gl.Framebuffer
readFBO gl.Framebuffer
renderBuf gl.Renderbuffer
vertAttribs [5]struct {
obj gl.Buffer
enabled bool
@@ -154,11 +153,6 @@ type uniformLocation struct {
size int
}
type inputLayout struct {
inputs []shader.InputLocation
layout []driver.InputDesc
}
// textureTriple holds the type settings for
// a TexImage2D call.
type textureTriple struct {
@@ -426,13 +420,6 @@ func (s *glState) activeTexture(f *gl.Functions, unit gl.Enum) {
}
}
func (s *glState) bindRenderbuffer(f *gl.Functions, target gl.Enum, r gl.Renderbuffer) {
if !r.Equal(s.renderBuf) {
f.BindRenderbuffer(gl.RENDERBUFFER, r)
s.renderBuf = r
}
}
func (s *glState) bindTexture(f *gl.Functions, unit int, t gl.Texture) {
s.activeTexture(f, gl.TEXTURE0+gl.Enum(unit))
if !t.Equal(s.texUnits.binds[unit]) {
@@ -448,13 +435,6 @@ func (s *glState) bindVertexArray(f *gl.Functions, a gl.VertexArray) {
}
}
func (s *glState) deleteRenderbuffer(f *gl.Functions, r gl.Renderbuffer) {
f.DeleteRenderbuffer(r)
if r.Equal(s.renderBuf) {
s.renderBuf = gl.Renderbuffer{}
}
}
func (s *glState) deleteFramebuffer(f *gl.Functions, fbo gl.Framebuffer) {
f.DeleteFramebuffer(fbo)
if fbo.Equal(s.drawFBO) {
+3 -1
View File
@@ -58,7 +58,6 @@ type coverUniforms struct {
uvCoverTransform [4]float32
uvTransformR1 [4]float32
uvTransformR2 [4]float32
z float32
}
type stenciler struct {
@@ -239,6 +238,9 @@ func newStenciler(ctx driver.Device) *stenciler {
Topology: driver.TopologyTriangleStrip,
})
st.ipipeline.pipeline = &pipeline{ipipe, vertUniforms}
if err != nil {
panic(err)
}
return st
}
+1 -8
View File
@@ -69,12 +69,6 @@ type strokeState struct {
type StrokeQuads []StrokeQuad
func (qs *StrokeQuads) setContour(n uint32) {
for i := range *qs {
(*qs)[i].Contour = n
}
}
func (qs *StrokeQuads) pen() f32.Point {
return (*qs)[len(*qs)-1].Quad.To
}
@@ -330,8 +324,7 @@ func strokePathNorm(p0, p1, p2 f32.Point, t, d float32) f32.Point {
panic("impossible")
}
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
func rot90CCW(p f32.Point) f32.Point { return f32.Pt(-p.Y, +p.X) }
func rot90CW(p f32.Point) f32.Point { return f32.Pt(+p.Y, -p.X) }
// cosPt returns the cosine of the opening angle between p and q.
func cosPt(p, q f32.Point) float32 {
+1 -1
View File
@@ -1750,7 +1750,7 @@ func AllocateDescriptorSets(d Device, pool DescriptorPool, layout DescriptorSetL
descriptorSetCount: C.uint32_t(count),
pSetLayouts: &layouts[0],
}
sets := make([]DescriptorSet, count, count)
sets := make([]DescriptorSet, count)
if err := vkErr(C.vkAllocateDescriptorSets(funcs.vkAllocateDescriptorSets, d, inf, &sets[0])); err != nil {
return nil, fmt.Errorf("vulkan: vkAllocateDescriptorSets: %w", err)
}
-4
View File
@@ -283,10 +283,6 @@ func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
cross = (maxCross - sz.Y) / 2
}
childSize := sz.X
max := childSize + pos
if max > mainMax {
max = mainMax
}
min := pos
if min < 0 {
min = 0
-21
View File
@@ -128,27 +128,6 @@ func (l Layout) Slice(start, end int) Layout {
return out
}
// equals returns true when l2 is logically equivalent to l.
func (l Layout) equals(l2 Layout) bool {
if len(l.Glyphs) != len(l2.Glyphs) || len(l.Clusters) != len(l2.Clusters) {
return false
}
if l.Runes != l2.Runes || l.Direction != l2.Direction {
return false
}
for i := range l.Clusters {
if l.Clusters[i] != l2.Clusters[i] {
return false
}
}
for i := range l.Glyphs {
if l.Glyphs[i] != l2.Glyphs[i] {
return false
}
}
return true
}
// Style is the font style.
type Style int
-18
View File
@@ -126,8 +126,6 @@ type maskReader struct {
maskBuf [utf8.UTFMax]byte
// mask is the utf-8 encoded mask rune.
mask []byte
// overflow contains excess mask bytes left over after the last Read call.
overflow []byte
}
// combinedPos is a point in the editor.
@@ -198,14 +196,6 @@ type SubmitEvent struct {
// Editor.SelectedText() (which can be empty).
type SelectEvent struct{}
type line struct {
offset image.Point
clip clip.Op
selected bool
selectionYOffs int
selectionSize image.Point
}
const (
blinksPerSecond = 1
maxBlinkDuration = 10 * time.Second
@@ -1460,14 +1450,6 @@ func sign(n int) int {
}
}
// sortPoints returns a and b sorted such that a2 <= b2.
func sortPoints(a, b screenPos) (a2, b2 screenPos) {
if b.Less(a) {
return b, a
}
return a, b
}
func nullLayout(rr io.RuneReader) ([]text.Line, error) {
var rerr error
var n int
-8
View File
@@ -993,11 +993,3 @@ func printLines(e *Editor) {
fmt.Printf("%d: %s\n", n, text)
}
}
// sortInts returns a and b sorted such that a2 <= b2.
func sortInts(a, b int) (a2, b2 int) {
if b < a {
return b, a
}
return a, b
}