Exemplo n.º 1
0
func (t *SvgTextT) widths(font string) (r *cmapt.CMapT) {
	if t.fontw == nil {
		t.fontw = make(map[string]*cmapt.CMapT)
	} else if r, ok := t.fontw[font]; ok {
		return r
	}
	// initialize like for Courier.
	r = cmapt.New()
	r.AddDef(0, 256, 600*WIDTH_DENSITY/1000)
	if t.fonts == nil {
		t.fonts = t.Pdf.PageFonts(t.Pdf.Pages()[t.Page])
		if t.fonts == nil {
			return
		}
	}
	if dr, ok := t.fonts[font]; ok {
		d := t.Pdf.Dic(dr)
		fc, ok := d["/FirstChar"]
		if !ok {
			return
		}
		lc, ok := d["/LastChar"]
		if !ok {
			return
		}
		wd, ok := d["/Widths"]
		if !ok {
			return
		}
		p := strm.Int(string(fc), 1)
		q := strm.Int(string(lc), 1)
		a := t.Pdf.Arr(wd)
		for k := p; k < q; k++ {
			r.Add(k, strm.Int(string(a[k-p]), WIDTH_DENSITY/1000))
		}
	}
	return
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) == 1 || len(os.Args) > 3 {
		complain("")
	}
	page := 0
	if len(os.Args) > 2 {
		page = strm.Int(os.Args[2], 1) - 1
		if page < 0 {
			complain("Bad page!\n\n")
		}
	}
	pd := pdfread.Load(os.Args[1])
	if pd == nil {
		complain("Could not load pdf file!\n\n")
	}
	fmt.Printf("%s", svg.Page(pd, page))
}
Exemplo n.º 3
0
// hello world, the web server
func HelloServer(c *http.Conn, req *http.Request) {
	c.SetHeader("Content-Type", "image/svg+xml; charset=utf-8")
	page := strm.Int(req.URL.RawQuery, 1) - 1
	io.WriteString(c, string(svg.Page(pd, page)))
}