func cutLines(c *xgb.Conn, w uint32, font xproto.Font, text string) []string { wds := strings.Split(text, " ") var words []_word = make([]_word, len(wds)) for i, word := range wds { words[i].wd = word + " " words[i].length = 0 ch2dstr, ln := prepString(words[i].wd) words[i].cookie = xproto.QueryTextExtents(c, xproto.Fontable(font), ch2dstr, ln) } var lines []string = make([]string, 0, 10) var line string = "" var ln uint32 = 0 for i := 0; i < len(words); i++ { rep, _ := words[i].cookie.Reply() words[i].length = uint32(rep.OverallWidth) ln += words[i].length if ln >= w { lines = append(lines, line) line = "" ln = words[i].length } line += words[i].wd } if ln != 0 { lines = append(lines, line) } return lines }
func loadGC(name string, c *xgb.Conn, scr *xproto.ScreenInfo) error { var gc gcontext /* Foreground GC */ id, err := xproto.NewGcontextId(c) if err != nil { return err } var mask uint32 = xproto.GcForeground | xproto.GcBackground | xproto.GcLineWidth | xproto.GcFont values := defaultGCValues(c) { cl, e := config.String(name + ".gc.fg") if e == nil { values[0], e = openColor(c, scr, readColor(cl)) if e != nil { return e } } cl, e = config.String(name + ".gc.bg") if e == nil { values[1], e = openColor(c, scr, readColor(cl)) if e != nil { return e } } wd, e := config.Int(name + ".gc.width") if e == nil { values[2] = uint32(wd) } cl, e = config.String(name + ".gc.font") if e == nil { fn, e := openFont(c, cl) if e != nil { return e } values[3] = uint32(fn) } } err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check() if err != nil { return err } gc.fg = id gc.font = xproto.Font(values[3]) gc.border = values[2] /* Query the font height */ { rep, e := xproto.QueryFont(c, xproto.Fontable(gc.font)).Reply() if e != nil { return e } gc.fontHeight = uint32(rep.FontAscent) + uint32(rep.FontDescent) gc.fontUp = uint32(rep.FontAscent) } /* Background GC */ id, err = xproto.NewGcontextId(c) if err != nil { return err } mask = xproto.GcForeground | xproto.GcBackground | xproto.GcLineWidth values[0], values[1] = values[1], values[0] err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check() if err != nil { return err } gc.bg = id /* Border GC */ id, err = xproto.NewGcontextId(c) if err != nil { return err } { cl, e := config.String(name + ".gc.bc") if e == nil { values[0], e = openColor(c, scr, readColor(cl)) if e != nil { return e } } else { values[0] = defaultgc.bc } } values[1] = values[0] err = xproto.CreateGCChecked(c, id, xproto.Drawable(scr.Root), mask, values).Check() if err != nil { return err } gc.bc = id /* Width */ { wd, e := config.Int(name + ".width") if e == nil { gc.width = uint32(wd) } else { gc.width = defaultgc.width } } ctxs[name] = &gc return nil }