Beispiel #1
0
func DrawLabel(s *svg.SVG, bs string) *BrailleCanvas {
	var c BrailleCanvas

	// TODO: they hard coded
	c.dotSize = 12
	c.pageMarginTop = 3
	c.pageMarginBottom = 3
	c.pageMarginLeft = 3
	c.pageMarginRight = 3
	c.gapCell = 3

	c.canvasW = c.pageMarginLeft + c.pageMarginRight
	c.canvasW += c.dotSize * 2 * utf8.RuneCountInString(bs)
	c.canvasW += c.gapCell*utf8.RuneCountInString(bs) - 1

	c.canvasH = c.pageMarginTop + c.pageMarginBottom
	c.canvasH += c.dotSize * 3

	s.Start(c.canvasW, c.canvasH)

	x := c.pageMarginLeft
	y := c.pageMarginTop
	for _, b := range bs {
		if b&0x2800 != 0x2800 {
			log.Printf("0x%x is not a braille character!\n", b)
			continue
		}
		Draw(s, b, x, y, c.dotSize)
		x += (c.dotSize * 2) + c.gapCell
	}

	return &c
}
Beispiel #2
0
func DrawPage30(s *svg.SVG, bs string) *BrailleCanvas {
	var c BrailleCanvas

	// TODO: they hard coded
	c.dotSize = 12
	c.pageMarginTop = 10
	c.pageMarginBottom = 10
	c.pageMarginLeft = 10
	c.pageMarginRight = 10
	c.gapCell = 3
	c.gapLine = 16
	c.lineCellsCnt = 30

	c.canvasW = c.pageMarginLeft + c.pageMarginRight
	c.canvasW += c.dotSize * 2 * 30
	c.canvasW += c.gapCell*30 - 1

	lineCnt := calcLines(bs, 30)
	c.canvasH = c.pageMarginTop + c.pageMarginBottom
	c.canvasH += c.dotSize * 3 * lineCnt
	c.canvasH += c.gapLine*lineCnt - 1

	s.Start(c.canvasW, c.canvasH)

	x := c.pageMarginLeft
	y := c.pageMarginTop

	lines := strings.Split(bs, "\n")
	ri := 0
	for _, line := range lines {
		for _, b := range line {
			if ri == 30 {
				x = c.pageMarginLeft
				y += (c.dotSize * 3) + c.gapLine
				ri = 0
			}

			if b&0x2800 != 0x2800 {
				log.Printf("0x%x is not a braille character!\n", b)
				continue
			}

			Draw(s, b, x, y, c.dotSize)
			ri += 1
			x += (c.dotSize * 2) + c.gapCell
		}
		x = c.pageMarginLeft
		y += (c.dotSize * 3) + c.gapLine
		ri = 0
	}

	return &c
}