Example #1
0
func (i *TypeOneI) Dic(id string) map[string][]byte {
	if id[0] != 'D' {
		panic("Wrong dictionary!\n")
	}
	idn := strm.Int(id[1:], 1)
	return i.Dicts[idn].Defs
}
Example #2
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
}
Example #3
0
func init() {
	var ops = map[string]func(t *TypeOneI){
		"array": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(t.NewArray(strm.Int(string(a), 1)))
		},
		"begin": func(t *TypeOneI) {
			a := t.St.Pop()
			if a[0] != 'D' {
				panic("Wrong dictionary!\n")
			}
			t.DicSp++
			t.DicSt[t.DicSp] = t.Dicts[strm.Int(string(a[1:]), 1)]
		},
		"bind": func(t *TypeOneI) {
		},
		"cleartomark": func(t *TypeOneI) {
			a := t.St.Pop()
			for string(a) != "mark" {
				a = t.St.Pop()
			}
		},
		"closefile": func(t *TypeOneI) {
			a := t.St.Pop()
			t.Done = true
			_ = a
		},
		"currentdict": func(t *TypeOneI) {
			t.St.Push(t.DicSt[t.DicSp].Name)
		},
		"currentfile": func(t *TypeOneI) {
			t.St.Push([]byte{'?'})
		},
		"def": func(t *TypeOneI) {
			a := t.St.Drop(2)
			t.DicSt[t.DicSp].Defs[string(a[0])] = a[1]
		},
		"definefont": func(t *TypeOneI) {
			a := t.St.Drop(2)
			t.Fonts[string(a[0])] = string(a[1])
			t.St.Push(util.Bytes("<FONT>")) // FIXME, we need this.
			_ = a
		},
		"defineresource": func(t *TypeOneI) {
			a := t.St.Drop(3)
			t.St.Push([]byte{'?'})
			_ = a
		},
		"dict": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(t.NewDic())
			_ = a
		},
		"dup": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(a)
			t.St.Push(a)
		},
		"eexec": func(t *TypeOneI) {
			a := t.St.Pop()
			b := eexec(t.Rdr)
			old := t.Rdr
			t.Rdr = fancy.SliceReader(b)
			//proceed(t, t.Rdr)
			t.Rdr = old
			t.Done = false
			_ = a
		},
		"end": func(t *TypeOneI) {
			t.DicSp--
		},
		"exch": func(t *TypeOneI) {
			a := t.St.Drop(2)
			a0 := a[0]
			t.St.Push(a[1])
			t.St.Push(a0)
		},
		"executeonly": func(t *TypeOneI) {
		},
		"findresource": func(t *TypeOneI) {
			a := t.St.Drop(2)
			t.St.Push([]byte{'?'})
			_ = a
		},
		"for": func(t *TypeOneI) {
			a := t.St.Drop(4)
			// FIXME
			_ = a
		},
		"get": func(t *TypeOneI) {
			a := t.St.Drop(2)
			i := strm.Int(string(a[0][1:]), 1)
			if a[0][0] == 'D' {
				t.St.Push(t.Dicts[i].Defs[string(a[1])])
			} else if a[0][0] == 'A' {
				t.St.Push(t.Arrays[i][strm.Int(string(a[1]), 1)])
			} else {
				panic("Can not 'get' from!\n")
			}
		},
		"if": func(t *TypeOneI) {
			a := t.St.Drop(2)
			t.op_ifelse([][]byte{a[0], a[1], []byte{}})
		},
		"ifelse": func(t *TypeOneI) {
			a := t.St.Drop(3)
			t.op_ifelse(a)
		},
		"index": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(t.St.Index(strm.Int(string(a), 1) + 1))
		},
		"known": func(t *TypeOneI) {
			a := t.St.Drop(2)
			t.St.Push(util.Bytes("false")) // FIX ME knows nothing ;)
			_ = a
		},
		"noaccess": func(t *TypeOneI) {
		},
		"pop": func(t *TypeOneI) {
			a := t.St.Pop()
			_ = a
		},
		"put": func(t *TypeOneI) {
			a := t.St.Drop(3)
			if a[0][0] == 'D' {
				t.Dicts[strm.Int(string(a[0][1:]), 1)].Defs[string(a[1])] = a[2]
			} else if a[0][0] == 'A' {
				t.Arrays[strm.Int(string(a[0][1:]), 1)][strm.Int(string(a[1]), 1)] = a[2]
			} else {
				panic("Wrong dictionary or array!\n")
			}
		},
		"readonly": func(t *TypeOneI) {
		},
		"readstring": func(t *TypeOneI) {
			a := t.St.Drop(2)
			c, _ := t.Rdr.Read(a[1])
			t.St.Push(a[1][0:c])
			t.St.Push(util.Bytes("true"))
		},
		"string": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(make([]byte, strm.Int(string(a), 1)))
		},
		"userdict": func(t *TypeOneI) {
			t.St.Push(util.Bytes("D0"))
		},
		"where": func(t *TypeOneI) {
			a := t.St.Pop()
			t.St.Push(util.Bytes("false"))
			_ = a
		},
	}

	for k, v := range ops {
		Ops[k] = v
	}
}
Example #4
0
// hello world, the web server
func HelloServer(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "image/svg+xml; charset=utf-8")
	page := strm.Int(req.URL.RawQuery, 1) - 1
	w.Write(svg.Page(pd, page, true))
}