]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_scaleText.py
make PositionTextCtrl() virtual (patch 1734405)
[wxWidgets.git] / wxPython / tests / test_scaleText.py
1 import wx
2
3 METHOD = 1
4 SCALE = 0.5
5
6 class TestPanel(wx.Panel):
7 """
8 Shows some ways to scale text down
9 """
10 def __init__(self, *args, **kw):
11 wx.Panel.__init__(self, *args, **kw)
12 self.Bind(wx.EVT_PAINT, self.OnPaint)
13
14 def OnPaint(self, evt):
15 pdc = wx.PaintDC(self)
16 font = wx.FFont(28, wx.SWISS)
17 pdc.SetFont(font)
18 txt = "Here is some text"
19
20 # draw the original unscaled text
21 pdc.DrawText(txt, 10, 10)
22
23 if METHOD == 0:
24 # Create a new font that is scaled
25 points = font.GetPointSize() * SCALE
26 font.SetPointSize(points)
27 pdc.SetFont(font)
28 pdc.DrawText(txt, 10, 100)
29
30 if METHOD == 1:
31 # Draw to a bitmap and scale that
32 w,h = pdc.GetTextExtent(txt)
33 bmp = wx.EmptyBitmap(w, h)
34 mdc = wx.MemoryDC(bmp)
35 mdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
36 mdc.Clear()
37 mdc.SetFont(font)
38 mdc.DrawText(txt, 0,0)
39 del mdc
40
41 image = bmp.ConvertToImage()
42 image = image.Scale(w*SCALE, h*SCALE, wx.IMAGE_QUALITY_HIGH)
43 bmp = wx.BitmapFromImage(image)
44 bmp.SetMaskColour(self.GetBackgroundColour())
45
46 pdc.DrawBitmap(bmp, 10,100)
47
48
49 elif METHOD == 2:
50 # Just scale the DC and draw the text again
51 pdc.SetUserScale(SCALE, SCALE)
52 pdc.DrawText(txt, 10/SCALE, 100/SCALE)
53
54
55 elif METHOD == 3:
56 # Use a GraphicsContext for scaling. Since it uses a
57 # floating point coordinate system, it can be more
58 # accurate.
59 gc = wx.GraphicsContext.Create(pdc)
60 gc.Scale(SCALE, SCALE)
61 gc.SetFont(font)
62 gc.DrawText(txt, 10/SCALE, 100/SCALE)
63
64
65
66 app = wx.App()
67 frm = wx.Frame(None, title="test_scaleText")
68 pnl = TestPanel(frm)
69 frm.Show()
70 app.MainLoop()
71