PostScript Printer Driver

No attempts yetTime limit1sMemory limit128 MB

Problem

The year is 1976, and a small upstart company has just built the first (crude) laser PostScript printer. You have been hired to write Release 1 of the printer's device driver. Release 1 is deliberately limited — it ships with only two very simple fonts — because some skeptics in the industry believe PostScript printers will never take off.

The device driver reads a series of commands that describe where text characters are placed on the output page. (Graphics will come in Release 2.) Each page is a 60 x 60 grid of character cells. A cell may hold only one of the following characters:

ABCDEFGHIJKLMNOPQRSTUVWXYZ .*

The 26 uppercase letters plus the blank make up the character set of the first font, C1. The asterisk (*) is the base pixel from which the enlarged Courier font, C5, is built. Each C5 character is drawn on a 5-row x 6-column grid made of asterisks (*) and periods (.). The C5 characters are:

.***..  ****..  .****.  ****..  *****.  *****.  .****.  *...*.  *****.
*...*.  *...*.  *...*.  *...*.  *.....  *.....  *.....  *...*.  ..*...
*****.  ****..  *.....  *...*.  ***...  ***...  *..**.  *****.  ..*...
*...*.  *...*.  *.....  *...*.  *.....  *.....  *...*.  *...*.  ..*...
*...*.  ****..  .****.  ****..  *****.  *.....  .***..  *...*.  *****.
  A       B       C       D       E       F       G       H       I

..***.  *...*.  *.....  *...*.  *...*.  .***..  ****..  .***..  ****..
...*..  *..*..  *.....  **.**.  **..*.  *...*.  *...*.  *...*.  *...*.
...*..  ***...  *.....  *.*.*.  *.*.*.  *...*.  ****..  *...*.  ****..
*..*..  *..*..  *.....  *...*.  *..**.  *...*.  *.....  *..**.  *..*..
.**...  *...*.  *****.  *...*.  *...*.  .***..  *.....  .****.  *...*.
  J       K       L       M       N       O       P       Q       R

.****.  *****.  *...*.  *...*.  *...*.  *...*.  *...*.  *****.  ......
*.....  *.*.*.  *...*.  *...*.  *...*.  .*.*..  .*.*..  ...*..  ......
.***..  ..*...  *...*.  .*.*..  *.*.*.  ..*...  ..*...  ..*...  ......
....*.  ..*...  *...*.  .*.*..  **.**.  .*.*..  ..*...  .*....  ......
****..  .***..  .***..  ..*...  *...*.  *...*.  ..*...  *****.  ......
  S       T       U       V       W       X       Y       Z     blank

Note that the sixth column of every C5 character is all periods. This provides natural spacing between characters in a string.

Your driver reads formatting commands from the input and renders characters from fonts C1 and C5 onto a 60 x 60 grid that initially holds a period (.) in every cell (a blank sheet of paper). Each command may change any cells, possibly overwriting cells that were already written. Blanks from either font, and empty cells (periods) inside a C5 glyph, do NOT overwrite whatever is already in a cell. Any formatting that would fall off either side or off the bottom of the page is simply truncated. Formatting continues until an end-of-page command is reached.

The input is a series of lines, each containing exactly one command and its argument(s). Every command begins in column 1 with a period, followed by 0 to 4 arguments. The commands are:

CommandArg 1: font (F)Arg 2: row (R)Arg 3: column (C)Arg 4: string (S)Description
.PC1 | C51 to 601 to 60yesPlace string at an absolute position
.LC1 | C51 to 60yesLeft-justify string on a row
.RC1 | C51 to 60yesRight-justify string on a row
.CC1 | C51 to 60yesCenter string on a row
.EOPnoEnd of page

Every command starts in column 1, and its arguments are separated by at least one space. Each command carries exactly the arguments shown above (no missing or extra arguments, and every value is within range).

  • .P (place): draws the string in font F with its top-left corner at (R, C); the first character sits at (R, C) and the rest continue to the right.
  • .L (left-justify): draws the string in font F with its top-left corner at (R, 1).
  • .R (right-justify): draws the string in font F with its top-right corner at (R, 60); the last character ends at column 60 and the string extends to the left.
  • .C (center): horizontally centers the string in font F, with its top row on row R. If it cannot be centered exactly (the string spans an odd number of cells), it is centered equally on either side of column 31.
  • .EOP (end of page): the driver flushes its buffer (outputs the page) and starts a new blank page with the next line. .EOP is guaranteed to be the last command in the input.

Argument 1 is the font. Argument 2 is the row R (for C5, the glyph occupies rows R through R+4). Argument 3, when present, is the leftmost column of the string. Argument 4 is a string of up to 60 valid characters (uppercase letters or spaces) delimited by | on both sides.

Input

The input is a series of commands and their arguments, exactly one per line. Start with a blank sheet of paper, then read and render the commands, flushing a page on each end-of-page command, until end of file.

Output

On each .EOP command, output the 60 x 60 grid representing the current page. To mark the end of a page, follow the grid with a blank line and then a line of 60 dashes (-).