func New(w, h vg.Length) *Canvas { buf := new(bytes.Buffer) c := &Canvas{ svg: svgo.New(buf), w: w, h: h, buf: buf, ht: w.Points(), stk: []context{context{}}, } // This is like svg.Start, except it uses floats // and specifies the units. fmt.Fprintf(buf, `<?xml version="1.0"?> <!-- Generated by SVGo and Plotinum VG --> <svg width="%.*gin" height="%.*gin" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">`+"\n", pr, w.Inches(), pr, h.Inches()) // Swap the origin to the bottom left. // This must be matched with a </g> when saving, // before the closing </svg>. c.svg.Gtransform(fmt.Sprintf("scale(1, -1) translate(0, -%.*g)", pr, h.Dots(c))) vg.Initialize(c) return c }
// New returns a new image canvas with // the size specified rounded up to the // nearest pixel. func New(width, height vg.Length, name string) (*XImgCanvas, error) { w := width.Inches() * dpi h := height.Inches() * dpi img := image.NewRGBA(image.Rect(0, 0, int(w+0.5), int(h+0.5))) return NewImage(img, name) }
// New returns a new image canvas with // the size specified rounded up to the // nearest pixel. func New(width, height vg.Length) *Canvas { w := width.Inches() * dpi h := height.Inches() * dpi img := image.NewRGBA(image.Rect(0, 0, int(w+0.5), int(h+0.5))) return NewImage(img) }