On 1/24/07, Boris Borcic <[EMAIL PROTECTED]> wrote:
> Chris Mellon wrote:
> >
> > Using either win32 or wxPython you will be able to produce bitmaps
> > directly, without needing to create a visible window.
> >
> >
> > Some quick & dirty wxPython code
> >
> > def getTextBitmap(text, font, fgcolor, bgcolor):
> >     dc = wx.MemoryDC()
> >     dc.SetFont(font)
> >     width, height= dc.GetTextExtent(text)
> >     bmp = wx.EmptyBitmap(width, height)
> >     dc.SelectObject(bmp)
> >     dc.SetBackground(wx.Brush(bgcolor))
> >     dc.Clear()
> >     dc.SetTextBackground(bgcolor)
> >     dc.SetTextForeground(fgcolor)
> >     dc.DrawText(text, 0, 0)
> >     dc.SelectObject(wx.NullBitmap)
> >     return bmp
> >
> >
> > Raw win32 code will look similar but will be much more verbose.
>
> Thx again for this base.
>
> Quickly testing this, it appears that the result is rendered half a pixel off 
> in
> the x-direction. Does this make sense ? Is it possible to position text with
> subpixel accuracy ?
>

The GDI text api, which is what wx is wrapping here, only provides
pixel accuracy. You are probably seeing a kerning effect from your
chosen font and perhaps the effects of ClearType.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to