GRAphical Programming for Eiffel index contents

Appendix F. Device Independent Units

Different devices might have different resolutions. It means that if you want, for example, to paint a rectangle with 100x100 pixels on the screen it can look O.K. But after you have tried to output the same rectangle to a printer it might look very small. This is caused by the different resolution that a display and printer device has (normally printers has 600 dpi resolution and screen only about 60 dpi).

You can implement two device-specific drawing procedures in your code. One is for the Display Graphics Context and one - for the Printer one. But there is another way. You can specify all coordinates in device independent units (e.g. in millimeters) and your figures will occupy the proper size on any device.

Classes PEN, FONT and ABSTRACT_GRAPHICS_CONTEXT have special features to support this measurement. Here we explain only class PEN. There is special PEN's creation procedure make_di.

make_di ( a_style, unit_type : INTEGER, a_width : REAL, a_color : COLOR ) 

Parameter unit_type specifies one of the available units:

POINT_UNIT, PIXEL_UNIT, MILLIMENTER_UNIT

For example we can create a pen of one millimeter in width.

!!my_pen.make_di (PS_SOLID, MILLIMENTER_UNIT, 1, black )

© Object Tools -- info@object-tools.com -- December 1999