simonkrauter / NiGui

Cross-platform desktop GUI toolkit written in Nim
MIT License
718 stars 50 forks source link

Black pseudoshadow around text #83

Closed Guevara-chan closed 4 years ago

Guevara-chan commented 4 years ago

Consider following easy code:

import nigui
app.init()

proc render_text(text: string, font: string): Image =
    result = newImage()
    result.resize 1, 1
    let canvas          = result.canvas
    canvas.fontFamily   = font
    canvas.fontSize     = 20
    canvas.textColor    = rgb(255, 0, 0)
    canvas.areaColor    = rgb(0, 0, 0, 0)
    result.resize canvas.getTextWidth(text), canvas.getTextLineHeight()
    canvas.fill()
    canvas.drawText text, 0, 0

let img = render_text("Hello, world !", "Sylfaen")

Save img. Look at img. See this: image

simonkrauter commented 4 years ago

I can reproduce it under Windows. I think the reason is the transparent areaColor. Maybe GdipDrawString() can't handle a transparent background or there is the need to set a special mode. I will search for a solution.

Related:

simonkrauter commented 4 years ago

With TextRenderingHint_AntiAlias the black shadow is gone. Before: before After: after