O'Reilly logo

REALBasic: TDG, 2nd Edition by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Printing Text

Text without styles can be printed with the Graphics property’s DrawString method. Styled text contained in an EditField can be printed easily with the EditField’s StyledTextPrinter method. Recall that successive DrawBlock messages sent to the same StyledTextPrinter instance cause successive parts of the EditField’s text to be drawn; if the NextPage message is sent to the Graphics property between DrawBlock calls, the successive parts of the EditField’s text will end up on separate pages.

The text will probably have to be scaled to compensate for the printer’s resolution. (I fear that the necessity of this may depend on the particular printer.) If you’re using DrawString, that’s no challenge at all; just multiply values by the appropriate scale factor.

As an example, here’s the PrintReturnAddress method from my envelope-printing utility; g is passed to it as a parameter, and PS and MyAddress are properties:

dim s as string
dim x,y as integer
s = myAddress
g.textfont = "Helvetica"
g.textsize = 9 * ps.horizontalResolution / 72
g.bold = false
y = ps.height - 3.5*ps.verticalResolution + g.textheight
x = .2 * ps.horizontalResolution
g.drawstring s,x,y

Printing from an EditField is a bit more complicated, because there’s no simple command to let you scale up. However, recall that earlier (Section 13.4.5) we developed utility classes for parsing and manipulating EditField styles; we can use these to scale up. Since this will physically change the contents of the EditField, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required