Merge recent changes from 2.8 branch.
Make updates for recent changes on CVS HEAD. Remove or workaround deprecated items. Fix compile errors. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45088 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
71
wxPython/tests/test_scaleText.py
Normal file
71
wxPython/tests/test_scaleText.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import wx
|
||||
|
||||
METHOD = 1
|
||||
SCALE = 0.5
|
||||
|
||||
class TestPanel(wx.Panel):
|
||||
"""
|
||||
Shows some ways to scale text down
|
||||
"""
|
||||
def __init__(self, *args, **kw):
|
||||
wx.Panel.__init__(self, *args, **kw)
|
||||
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||
|
||||
def OnPaint(self, evt):
|
||||
pdc = wx.PaintDC(self)
|
||||
font = wx.FFont(28, wx.SWISS)
|
||||
pdc.SetFont(font)
|
||||
txt = "Here is some text"
|
||||
|
||||
# draw the original unscaled text
|
||||
pdc.DrawText(txt, 10, 10)
|
||||
|
||||
if METHOD == 0:
|
||||
# Create a new font that is scaled
|
||||
points = font.GetPointSize() * SCALE
|
||||
font.SetPointSize(points)
|
||||
pdc.SetFont(font)
|
||||
pdc.DrawText(txt, 10, 100)
|
||||
|
||||
if METHOD == 1:
|
||||
# Draw to a bitmap and scale that
|
||||
w,h = pdc.GetTextExtent(txt)
|
||||
bmp = wx.EmptyBitmap(w, h)
|
||||
mdc = wx.MemoryDC(bmp)
|
||||
mdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
|
||||
mdc.Clear()
|
||||
mdc.SetFont(font)
|
||||
mdc.DrawText(txt, 0,0)
|
||||
del mdc
|
||||
|
||||
image = bmp.ConvertToImage()
|
||||
image = image.Scale(w*SCALE, h*SCALE, wx.IMAGE_QUALITY_HIGH)
|
||||
bmp = wx.BitmapFromImage(image)
|
||||
bmp.SetMaskColour(self.GetBackgroundColour())
|
||||
|
||||
pdc.DrawBitmap(bmp, 10,100)
|
||||
|
||||
|
||||
elif METHOD == 2:
|
||||
# Just scale the DC and draw the text again
|
||||
pdc.SetUserScale(SCALE, SCALE)
|
||||
pdc.DrawText(txt, 10/SCALE, 100/SCALE)
|
||||
|
||||
|
||||
elif METHOD == 3:
|
||||
# Use a GraphicsContext for scaling. Since it uses a
|
||||
# floating point coordinate system, it can be more
|
||||
# accurate.
|
||||
gc = wx.GraphicsContext.Create(pdc)
|
||||
gc.Scale(SCALE, SCALE)
|
||||
gc.SetFont(font)
|
||||
gc.DrawText(txt, 10/SCALE, 100/SCALE)
|
||||
|
||||
|
||||
|
||||
app = wx.App()
|
||||
frm = wx.Frame(None, title="test_scaleText")
|
||||
pnl = TestPanel(frm)
|
||||
frm.Show()
|
||||
app.MainLoop()
|
||||
|
Reference in New Issue
Block a user