************************************* * * * DB/C Newsletter * * July 1996 * * * ************************************* Editor's Notes The conversion to GUI programs continues to be a major concern for many DB/C customers, as well as the computer industry as a whole. In this month's newsletter, as well as in months to come, we will focus on the advantages of using DB/C to convert to a GUI environment. Data processing applications use printing for many output operations. Much paper is still used to print reports, but in many cases, the output will never actually be printed to a physical media. In either case, the expressive power of a programming language's print operation is important for the programmer to be able to provide attractive, useful reports. Standard PL/B does not provide the features required to build reports that are attractive by today's higher standard. In this month's article, we describe the features of DB/C 9.0 GUI printing which do provide the features necessary to create attractive, useful reports. don.wills@swc.com GUI Printing In the GUI environment, DB/C 9.0 provides several enhancements to aid in the creation better looking, more portable printed output. Standard PL/B provides the basic capability for mono-spaced, single font printed output. To go beyond this basic printing capability, a PL/B program must output special escape sequences that cause the printer to create the desired output. These escape sequences are different for most printers, so if the program must support several different printers, several groups of escape sequences must be included in the programs. Debugging can be a major problem, because the programmer must have access to each of the printers that is to be supported. Maintenance is also problematical. The GUI printing model in DB/C 9.0 solves each of the problems. A page is an output canvas that is drawn on by the DB/C print statement. Each print statement feature works the same way regardless of destination printer. The page is an idealized page that consists of a two dimensional array of pixels. Each pixel can be any color. By default, if you don't draw a given pixel, it will be white, which is the assumed background color. The pixel at the upper left corner of the page has a horizontal position value of 1 and vertical position value of 1. The horizontal pixel position value increases from left to right and the vertical pixel position value increases from top to bottom. The next symbol or graphic to be printed will be located at the position called the current print position. When printing to a new page, the initial current print position is set to (1,1). The *P=h:v print control code changes the current print position. For example: print *p=40:100; sets the current print position to the 40th pixel from the left and the 100th pixel from the top of the page. The *LINE=h:v print control code draws a line from the current print position to the position specified by h:v. For example: print *p=100:100, *line=200:100; draws a horizontal line that is 101 pixels long from the pixel at (100,100) to the pixel at (200,100). In addition, the *LINE print control code changes the current print position to be the at the pixel at the end of the line. In the example above, after the print statement is complete, the current print position is (200,100). The *LINEWIDTH=n print control code specifies the width of the line in pixels. For example: print *p=100:100, *linewidth=5, *line=200:100; draws a horizontal line that is 5 pixels wide. The default line width is 1 pixel wide. The *LINEWIDTH print control code is persistent across print statements for a single print destination. For example: prt1 pfile prt2 pfile print prt1; *linewidth=5; print prt2; *linewidth=9; print prt1; *p=100:100, *line=200:100; will cause a 5 pixel wide line to be drawn on the page associated with the print file variable named prt1. The default drawing color is black. This can be modified with any of the color print control codes. These control codes are: *WHITE, *BLACK, *BLUE, *GREEN, *YELLOW, *RED, *CYAN and *MAGENTA. Characters are printed such that the upper left corner of the printed character is located at the current print position. As each character is printed, the current print position is moved to the right such that the next character to be printed is located the appropriate distance to the right of the previous character. The font is specified with the *FONT=fontinfo print control code. The fontinfo value is a character variable or literal. Here are some examples: ti init "Times(italic)" print *font="Courier(14,bold)", "Hello world" print *font="Helvetica", "Hello two" print *font="(10,italic,nobold)", "Hello three!" print *font="Courier(11,plain)", "Hello four" print *font=ti, "Hello five" The font specification is cumulative. Thus in the above example, these strings would be printed in these fonts: Hello world Courier 14pt bold Hello two Helvetica 14pt bold Hello three Helvetica 10pt italic Hello four Courier 11pt Hello five Times Roman 11pt italic The newline print control code (*N) causes the vertical component of the current print position to be increased (moved down) an appropriate number of pixels such that characters will be drawn with the proper leading. Leading (pronounced ledding) is the term used in typography to denote the empty space between successive print lines. The newline print control code also sets the horizontal component of the current print position to 1. The linefeed print control code (*L) works in the same manner as the newline print control code on the vertical component of the current print position, but does not affect the horizontal component. The carriage return print control code (*C) sets the horizontal component of the current print position to 1 and does not affect the vertical component. An important aspect of this print model for characters is that it is upwardly compatible with the mono-spaced font, character-oriented print model of Standard PL/B. Thus, printed output will be what is expected from existing programs that are ported to the GUI environment. Proportional fonts (e.g. Helvetica and Times Roman) can cause problems with existing programs because different characters are different widths. This is especially true when using the tab print control character (*TAB=n). The tab print control code uses the current font to alter the current print position. For mono-spaced fonts, *TAB=n works as expected. But for proportional fonts, the resulting print position is undefined. Therefore, we recommend that *TAB not be used when proportional fonts are used. DB/C 9.0 also allows the contents of image variables to be printed. This is done by just including the image variable in the list of printed variables. For example: dev1 device img1 image h=600,v=600,colorbits=1 open dev1, "LOGO.TIF" load img1 from dev1 print *p=975:1350, img1; will cause the image in the LOGO.TIF file to be printed. Also, if the resolution of the print page is 300 dots per inch and the page is an 8.5 by 11 inch page, the image will be centered on the page. The destination printer and the size of each print pixel is controlled with the splopen statement. For example: prt1 pfile splopen prt1, "DEFAULT(300)" causes the print file variable named prt1 to be associated with the default GUI printer and for the size of the pixel in the print model to be 300 pixels per inch. The pixel size metric works regardless of the actual printer resolution. In the GUI environment, there are typically two different dialog boxes displayed that allow the operator to control print destination and parameters. The first of these dialog boxes is typically called the "Print Setup" dialog or the "Page Setup" dialog. To display it, just use this statement: splopt "S" This will set the appropriate parameters for the default printer. The second of these special dialog boxes is usually displayed at the start of printing and contains the OK and Cancel buttons to actually start printing. This dialog box is displayed with the "J" operand of the splopen statement. Here is an example: prt1 pfile splopen prt1, "DEFAULT(300)", "J" In this example, this splopen statement will fail with a P 405 error if the Cancel button is pressed. GUI printing in DB/C 9.0 offers many features that are unavailable in Standard PL/B. It is one of the many factors that you should consider when choosing your GUI development environment. DB/C Class Schedule Class Date Location DB/C 9 Fundamentals September 1996 Oak Brook, IL DB/C 9 Advanced Features October 1996 Oak Brook, IL For information, contact Judi Tamkevic at: voice 708.572.0240 fax 708.572.0390 email dbc@swc.com