예제 #1
0
// API: POST /braille
func brailleHandler(w http.ResponseWriter, r *http.Request) {
	src := r.FormValue("input")
	lang := r.FormValue("lang")
	if lang == "" {
		// TODO: lang이 없거나 auto이면 언어 판단해야함
		lang = "ko"
	}
	format := r.FormValue("format")
	if format == "" {
		format = "svg"
	}

	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	var bStr string

	if lang == "ko" {
		bStr, _ = brl_ko.Encode(src)
	} else if lang == "en" {
		bStr, _ = brl_en.Encode(src)
	}

	if format == "svg" {
		canvas := svg.New(w)
		defer canvas.End()
		brl_svg.DrawPage30(canvas, bStr)
	} else {
		fmt.Fprint(w, bStr)
	}
}
예제 #2
0
func TestDraw(t *testing.T) {
	f, err := os.Create("test_label.svg")
	if err != nil {
		t.Errorf("failed to create test.svg : %s\n", err)
	}
	defer f.Close()

	canvas := svg.New(f)
	defer canvas.End()

	s := "Braille Printer"
	bs, _ := brl.Encode(s)
	DrawLabel(canvas, bs)
}
예제 #3
0
// API: POST /printq/add
//   input: text to translation
//   lang: auto|ko|en
//   key: examplekey (TODO: OAuth implementation)
func printqAddHandler(w http.ResponseWriter, r *http.Request) {
	if strings.ToUpper(r.Method) != "POST" {
		http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
		return
	}

	/*
		var authKey string
		if strings.Contains(r.Referer(), "http://localhost") ||
			strings.Contains(r.Referer(), "http://braille-printer.appspot.com") {
			authKey = EXAMPLE_AUTHKEY
		} else {
			http.Error(w, "Unauthorized", http.StatusUnauthorized)
			return
		}
	*/

	authKey := r.FormValue("key")
	if authKey == "" {
		authKey = EXAMPLE_AUTHKEY
	}
	input := r.FormValue("input")
	lang := r.FormValue("lang")
	if lang == "" {
		// TODO: lang이 없거나 auto이면 언어 판단해야함
		lang = "ko"
	}

	label := "label"

	if strings.Contains(input, "\n") {
		label = "paper"
	}

	var bStr string

	if lang == "ko" {
		bStr, _ = brl_ko.Encode(input)
	} else if lang == "en" {
		bStr, _ = brl_en.Encode(input)
	}

	buf := bytes.NewBuffer(make([]byte, 24288))

	canvas := svg.New(buf)
	defer canvas.End()
	brl_svg.DrawPage30(canvas, bStr)

	printq := PrintQ{
		Type:       label,
		Key:        authKey,
		Origin:     input,
		ResultText: bStr,
		ResultSVG:  buf.Bytes(),
		Status:     0,
		CTime:      time.Now(),
	}

	c := appengine.NewContext(r)
	_, err := datastore.Put(c, datastore.NewIncompleteKey(c, "PrintQ", nil), &printq)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}