Use proper textBaseline in canvas renderer

This commit is contained in:
Marcin Kulik 2012-03-15 21:37:48 +01:00
parent 501c989c8a
commit 1e4864e51e

View File

@ -28,17 +28,12 @@ class AsciiIo.Renderer.Canvas extends AsciiIo.Renderer.Base
@font = "#{size} #{family}" @font = "#{size} #{family}"
@ctx.font = @font @ctx.font = @font
@prevFont = @font @prevFont = @font
@ctx.textBaseline = 'bottom'
renderLine: (n, data, cursorX) -> renderLine: (n, data, cursorX) ->
left = 0 left = 0
width = @cols * @cellWidth width = @cols * @cellWidth
top = n * @cellHeight top = n * @cellHeight
# bottom = (n + 1) * @cellHeight
# @ctx.clearRect(left, top + 1, width, @cellHeight)
# ctx.fillStyle = "#FFA500";
# @ctx.font = "12px monospace"
for i in [0...@cols] for i in [0...@cols]
d = data[i] d = data[i]
@ -46,14 +41,12 @@ class AsciiIo.Renderer.Canvas extends AsciiIo.Renderer.Base
if d if d
[char, brush] = d [char, brush] = d
char = char.replace('&', '&amp;').replace('<', '&lt;')
@setBackgroundAttributes(brush) @setBackgroundAttributes(brush)
@ctx.fillRect left + i * @cellWidth, top + 1, @cellWidth, @cellHeight @ctx.fillRect left + i * @cellWidth, top, @cellWidth, @cellHeight
if char != ' ' if char != ' '
@setTextAttributes(brush) @setTextAttributes(brush)
@ctx.fillText char, i * @cellWidth, top + @cellHeight - 2 @ctx.fillText char, i * @cellWidth, top + @cellHeight
setBackgroundAttributes: (brush) -> setBackgroundAttributes: (brush) ->
if brush.bg isnt undefined if brush.bg isnt undefined