Skip to content
15 changes: 5 additions & 10 deletions draw/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,18 @@ func allocImage(d *Display, ai *Image, r image.Rectangle, pix Pix, repl bool, va
return i, nil
}

/*
func namedimage(d *Display, name string) (*Image, nil) {
panic("namedimage")
}

/* implements message 'N' */
func nameimage(i *Image, name string, in bool) error {
a := i.Display.bufimage(1+4+1+1+len(name))
a := i.Display.bufimage(1 + 4 + 1 + 1 + len(name))
a[0] = 'N'
bplong(a[1:], i.ID)
bplong(a[1:], i.id)
if in {
a[5] = 1
}
a[6] = len(name)
a[6] = byte(len(name))
copy(a[7:], name)
return d.flushimage(false)
return i.Display.flush(false)
}
*/

func (i *Image) free() error {
if i == nil || i.Display == nil {
Expand Down
5 changes: 4 additions & 1 deletion draw/draw.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Package draw is a port of Plan 9's libdraw to Go.
// It connects to the 'devdraw' binary built as part of Plan 9 from User Space (http://swtch.com/plan9port/).
//
// On Plan 9 it talks to /dev/draw and rio(4) at $wsys directly.
// On unix, it connects to the 'devdraw' binary built as part of Plan 9 from User Space (http://swtch.com/plan9port/).
//
// All graphics operations are done in the remote server. The functions
// in this package typically send a message to the server.
//
Expand Down
28 changes: 0 additions & 28 deletions draw/getsubfont.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
package draw

import (
"bytes"
"fmt"
"image"
"io/ioutil"
"log"
"os"
"strings"
)

func getsubfont(d *Display, name string) (*Subfont, error) {
scale, fname := parsefontscale(name)
data, err := ioutil.ReadFile(fname)
if err != nil && strings.HasPrefix(fname, "/mnt/font/") {
data1, err1 := fontPipe(fname[len("/mnt/font/"):])
if err1 == nil {
data, err = data1, err1
}
}
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: %v\n", err)
return nil, err
}
f, err := d.readSubfont(name, bytes.NewReader(data), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: can't read %s: %v\n", fname, err)
}
if scale > 1 {
scalesubfont(f, scale)
}
return f, err
}

func scalesubfont(f *Subfont, scale int) {
r := f.Bits.R
r2 := r
Expand Down
34 changes: 34 additions & 0 deletions draw/getsubfont_devdraw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build !plan9

package draw

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
)

func getsubfont(d *Display, name string) (*Subfont, error) {
scale, fname := parsefontscale(name)
data, err := ioutil.ReadFile(fname)
if err != nil && strings.HasPrefix(fname, "/mnt/font/") {
data1, err1 := fontPipe(fname[len("/mnt/font/"):])
if err1 == nil {
data, err = data1, err1
}
}
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: %v\n", err)
return nil, err
}
f, err := d.readSubfont(name, bytes.NewReader(data), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: can't read %s: %v\n", fname, err)
}
if scale > 1 {
scalesubfont(f, scale)
}
return f, err
}
27 changes: 27 additions & 0 deletions draw/getsubfont_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// +build plan9

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can elide the build directive here - having _plan9.go file suffix is sufficient.


package draw

import (
"bytes"
"fmt"
"io/ioutil"
"os"
)

func getsubfont(d *Display, name string) (*Subfont, error) {
scale, fname := parsefontscale(name)
data, err := ioutil.ReadFile(fname)
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: %v\n", err)
return nil, err
}
f, err := d.readSubfont(name, bytes.NewReader(data), nil)
if err != nil {
fmt.Fprintf(os.Stderr, "getsubfont: can't read %s: %v\n", fname, err)
}
if scale > 1 {
scalesubfont(f, scale)
}
return f, err
}
7 changes: 6 additions & 1 deletion draw/init.go → draw/init_devdraw.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

package draw

import (
Expand Down Expand Up @@ -88,6 +90,9 @@ func Init(errch chan<- error, fontname, label, winsize string) (*Display, error)
if err != nil {
return nil, err
}
if errch == nil {
errch = make(chan error)
}
d := &Display{
conn: c,
errch: errch,
Expand Down Expand Up @@ -361,7 +366,7 @@ func bpshort(b []byte, n uint16) {
}

func (d *Display) HiDPI() bool {
return d.DPI >= DefaultDPI*3/2
return d.DPI >= DefaultDPI*3/2
}

func (d *Display) ScaleSize(n int) int {
Expand Down
Loading