|
|
PostScript Template LanguageFrom $1Table of contents
Synapse uses a template language to describe the page layout in letters, prescriptions, and various request forms. The language is designed to be similar to postscript, but does not allow full postscript functionality. You can draw simple shapes, lines and place text on the page in different fonts and colors. You can also include external images, but they do have to be in EPS, or encapsulated postscript format. The main requirement for documents is to be able to place text at certain positions on the first page, and then have longer text spill over to subsequent pages without the need to place text at specific locations - apart from footers, and page numbers. So, Synapse allows just this, and uses the gonzo.ps text formatter to provider footers, and micro-justification. There are a few important things to remember when writing templates
Testing the ExamplesSynapse has a preview system that allows you to test your template code, and therefore the examples that follow. Simply navigate to Settings/PostScript, and in the blank text box on the right, enter
and then click on the "Test" button. A display comes up with the print preview of a page with "Hello World" near the center of the page. Co-ordinate SystemAs in PostScript, the bottom left hand corner of the page is 0,0 or 0x0 in our template language, and the top right of the page is 595x842 for A4 paper, and 612x792 for American Letter paper. Each of these divisions is called a point, and there are 72 points per inch. So, at 72x72 we are one inch from the bottom and left edges. These are the same points as used to describe the size of fonts eg. 10 point font size. OperatorsThe postscript template language ( or PTL for short ) has a number of operators that direct the placement of text, and the drawing of graphical elements. We shall cover these one by one.
The pagesize operator should be the first command on each template. It defines the size of the page. It is then followed by the actual page size. You can use A4, letter, A5 or specify the actual size in points. Eg:
All the default templates use A4 as they were developed outside the USA. You should modify them to use letter if you use American letter paper. atThe at operator is followed by a pair of x-y coordinates. These tell the PTL where the next object is going to be placed on the page. The x-y coordinates should be within the visible page boundaries otherwise they will not be printed, or visible in the preview screen. The x-y position is kept until the very next drawing operation, and is then generally discarded. Now if we wish to place some text on the page, we can just write "Some text" like this
but if we now wish to place some text directly after this, we can't do this
as you will see the "This won't work" text appear above the "Some text" instead of at the end as you might expect. So, instead you need to do:
ShowpageThe showpage operator is not needed in these examples to view the preview screen, but is necessary if you want the page to print properly. It tells the postscript printer or interpreter to put all the preceding on the current print page and move on to the next page. TextAs you will have seen from the above, literal text strings are placed on the page simply by enclosing them in double quotes. If you want to place text that is derived from the patient's demographics, or your details, you will use keywords that do not use double quotes, eg.
which places at 120x500 the text that is stored in Settings/User/Full name field. So, double quotes are used for literal text. Keywords
FontThe font command allows you to change the font used for the page. That font then remains active until changed again. Normally you would want to set the font right after the pagesize command. Since it is not actually doing any printing, it does not need to be preceded by an at operator.
Note that the operator font is followed by the name of the font family, and then the font size. If you are using ghostscript, you are limited to the fonts included in the distribution. If you are using a postscript printer, you are limited to those fonts included with the printer, or those you can download to the printer. Standard PostScript Fonts
ColorThe color operator changes the current pen color. It defaults to black. It can then be followed by an rgb tuple ( red green blue ) such as
or, it can use the named Rebol colors but these must be enclosed by parentheses
The named colors are: black blue navy orange gold tan
coal green leaf forest brown coffee
gray cyan teal aqua water sky
pewter red maroon brick crimson pink
silver magenta purple violet papaya rebolor
snow yellow olive oldrab khaki mint
white ivory linen beige
linewidthThe linewidth operator specifies the width of a line drawn including those in lines, boxes, circles etc. It takes an integer. So, a thin line would be
and a thick line
The linewidth remains operative until changed by another command. newpathThe newpath operator tells the postscript printer to start a new drawing command. Otherwise it might continue drawing from the previous position. This is one instance in which it can remember where it was before. So, you should use the newpath operator before each new line or other graphic object. lineThe line operator draws a line in the current color, and linewidth from one position to another.
says we are going to draw a new straight line from the point 75x740 to 530x740, ie. a horizontal line. boxThe box operator draws a closed rectangle using the current linewidth. If followed by the operator fill, it then fills in the box with the current color.
So, you can use this to setup check boxes on the page. FillThe fill operator as shown above will fill in any closed path drawing eg. box, circle with the current color. CircleThe circle operator ( available in R211B25 and higher ) take a location and a radius. It can also be filled in.
pagesize A4
In this example a couple of circles of differing fill colors and radii are drawn to the screen. setgrayThe setgray operator sets the grayscale level of any black lines drawn. By default, setgray is 0, so that any lines drawn will be black. If you use a value of 1, then lines will drawn in white.
In the example above, an oblique black line is drawn, then a white line parallel to it, and then a gray line parallel to the white line. The lines slightly overlap each other. GsaveThis allows the postscript printer to save the current working state. You can then change various parameters, colors, etc, and return to that state by using a grestore. GrestoreGrestore restores the postscript interpreter to a previously saved state reset-matrixrotateDon't use scaleDon't use translateDon't use textboxIn the text examples we looked at before, we usually placed a literal text string on the page, at a spot we determined using the at operator. However, we also want to be able to place columns of text such as lists of diagnoses, and medications where the length of that column remains undetermined until print time. We therefore have created a textbox which is a region on the page into which you can pour text. The text will fill as much of the textbox as it can, and if there is more text than space, the extra text will be lost. So, textboxes need to be created to be able to hold as much text as reasonably one expect there to be. The textbox takes two sets of coordinates, the bottom left and the top right of the box - which acts as an invisible restraint on any text poured into it.
In the templates as distributed appears the above. This textbox is used to hold the diagnoses and starts at the bottom of the page 100 points from the left edge, and ends its top right corner at 280x530. Once a textbox has been defined, it must be filled immediately with text. textbox 100x0 280x530
Here the flow operator is fed two parameters - the first returns all the diagnoses for the current patient, and the only modifier tells the flow operator to ignore any text that does not fit the textbox. Flow takes the diagnoses column of data and puts it into the textbox. It also internally records the bottom line where it stops putting text. The other modifiers are left and gonzo. The left modifier leaves text unjusified. flowboxA flowbox is a textbox which can have its contents modified in several ways. Any text put into a flowbox can be justified, paginated, and can spill into another flowbox on the following page. Unlike textboxes, flowboxes must be defined as a group before text can be flowed into them.
This group of commands first off tells the postscript to reset any translations in operation. A translation is where one point is moved to another arithmetically. It then defines the flowbox as being something which largely covers the whole page at 75x150 540x700. But it then follows this with the float modifier. This basically says that if any text is poured into this flowbox, it must start 20 points below the lowest y value of any text in any textboxes. In this way we can get the consult text to start below the diagnoses and medications. The operator gonzo tells Synapse to include the gonzo text formatter utility written by PostScript guru Don Lancaster. Finally the flow operator is told to take the consult text, flow it into all the available flowboxes, and apply the gonzo text formatter to the contents so that they are fully justified, and paginated. Synapse will place each flowbox on separate pages. This is why the second flowbox in the above example lacks the float modifier because it will be printing onto a blank page, and therefore does not need to drop below any other text. EPSThe eps operator allows you to specify an image in EPS format which is to be placed upon the page. This might be letterhead, or a signature for a prescription or request. In all of these cases, the image will appear at the same place, so it does not work if you wish to have your signature at the end of the consult as that location remains unknown until print time. The eps operator takes a REBOL path to an eps image like this:
A yellow square will appear on the preview screen to show that there is an eps image there, but at this time it is not possible to show a screen preview of that image. Eps images will have some instructions in them to place the image somewhere on the page, so you willl have to experiment to get the location correct. So, even though we have placed the image at 450 points below the bottom of the page, this makes this particular image appear in the middle of the page! Using eps images is a black art. Our experience is that eps images created by Adobe products don't work, and those created on Macintosh computers often do not work. Eps images are just postscript code, so in some instances it is possible to fix them by recoding the instructions in the image. If you are going to use an eps image, make sure it is on a mapped drive so that the server and your PC can both see it at the same drive letter and location. Otherwise, when you do a server generated PDF, it won't fail because the image is actually on your local PC! BarcodesYou can print words in the 3of9 bar code font by enclosing them in surrounding "*". For example the following code placed just before the "showpage" prints a vertically oriented barcode on the left edge of the superbill gsave at 50x200 rotate 90 (uppercase rejoin ["*" ssnfld/text "*"]) grestore |
||||||||||||||||||||||||||||||||||||||||||||||