]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_scaleText.py
6 class TestPanel(wx
.Panel
):
8 Shows some ways to scale text down
10 def __init__(self
, *args
, **kw
):
11 wx
.Panel
.__init
__(self
, *args
, **kw
)
12 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
14 def OnPaint(self
, evt
):
15 pdc
= wx
.PaintDC(self
)
16 font
= wx
.FFont(28, wx
.SWISS
)
18 txt
= "Here is some text"
20 # draw the original unscaled text
21 pdc
.DrawText(txt
, 10, 10)
24 # Create a new font that is scaled
25 points
= font
.GetPointSize() * SCALE
26 font
.SetPointSize(points
)
28 pdc
.DrawText(txt
, 10, 100)
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()))
38 mdc
.DrawText(txt
, 0,0)
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())
46 pdc
.DrawBitmap(bmp
, 10,100)
50 # Just scale the DC and draw the text again
51 pdc
.SetUserScale(SCALE
, SCALE
)
52 pdc
.DrawText(txt
, 10/SCALE
, 100/SCALE
)
56 # Use a GraphicsContext for scaling. Since it uses a
57 # floating point coordinate system, it can be more
59 gc
= wx
.GraphicsContext
.Create(pdc
)
60 gc
.Scale(SCALE
, SCALE
)
62 gc
.DrawText(txt
, 10/SCALE
, 100/SCALE
)
67 frm
= wx
.Frame(None, title
="test_scaleText")