# Printing with Phaedra [ rev. 1.3 ]
-------------------------------------------------------------------------------
Phaedra supports raw mode printing on PCL (experimental) and PostScript (solid and tested) printers. You can set margins, and select fonts and styles. You will get the best results when using PostScript.

## PCL vs. PostScript
-------------------------------------------------------------------------------
Notes for PostScript:
- Tested and works solidly on paper as well as for PDF creation.
- For best results, Phaedra leverages the 'intelligence' of your printer.
- Margins and page breaks work as designed.
- Support for basic Markdown formatting.
- Print Fontlist feature is supported.
- For PDF creation: use only Adobe standard fonts (Helvetica, Courier, Times-Roman).
- The entry for "Max characters per line" will be ignored during PostScript printing.

Notes for PCL:
- Highly experimental.
- Right margin is not fully supported. Phaedra calculates it by page size and sets characters per line with a safety space.
- Markdown is not yet supported.
- Print Fontlist may not work on some printers, as the PCL command is not strictly standardized.
- For the best page layout results (especially line breaks) in PCL, use a non-proportional font like Courier.
- The entry for "Max characters per line" will be used during PCL printing to avoid overprinting line ends.

## Codepages and Extended ASCII
-------------------------------------------------------------------------------
To support 'Extended ASCII', all text is converted to ISOLatin1 (the PostScript printer default) before being sent to the printer. Extended ASCII needs to be remapped for this. It is designed to work in the Western world (Europe and the Americas) and might lead to issues with codepages in other regions (e.g., Russia or Asia), depending on your system codepage and your printer. 

### Printing Extended ASCII and Control Characters
-------------------------------------------------------------------------------
In OS/2, the Presentation Manager visually represents non-printable control characters (ASCII 0-31) as graphical symbols, such as bullets or arrows (e.g., entered via Alt+7). 

However, hardware printers (both PCL and PostScript) interpret these bytes strictly as mechanical control commands. For example, ASCII 07 is the "Bell" command, and ASCII 12 is a "Form Feed". Sending these raw bytes directly to a printer can result in corrupted print jobs, unexpected page ejects, or complete printer crashes.

To ensure safe and reliable printing, Phaedra intercepts these characters and automatically substitutes them with safe, printable equivalents before sending the text to the spooler:

- Bullets (Alt+7 / ASCII 07): Mapped to a standard printable middle dot ().
- Arrows (Alt+24 to 27): Mapped to standard text equivalents (^, v, >, <).
- Other Control Characters: All other unsafe control codes (except standard formatting like Tab, CR, and LF) are replaced with a blank space to protect the printer hardware.

## Ports
-------------------------------------------------------------------------------
Phaedra prints directly to a port. Printer drivers are not necessary and will not be used to print from the editor.

Supported ports are LPT, COM, USB, or network addresses.

If you have the ePDF subsystem and GhostScript installed, you can create PDFs by selecting "\PIPE\ePDF" from the port list.

For network printing, Phaedra uses lpr, which must be installed on your system. You have to enter the IP address of your printer into the corresponding entry field.

Phaedra defaults to the classic IBM lpr for network printing (automatically checked at \TCPIP\bin\lpr.exe and \MPTN\bin\lpr.exe on the boot drive). The detected path is saved to PHAEDRA.INI after opening the print dialog for the first time and can be modified via an INI editor if needed. This manual step should not be necessary on most systems. 

As a fallback, Phaedra searches the system PATH for the CUPS lpr (Unixroot) and automatically applies the specific CUPS command-line syntax. (Note: This CUPS fallback is currently untested.)

## Margins, Fonts and Styles
-------------------------------------------------------------------------------
You can easily set up page margins for your document.

The print dialog offers a selection of fonts, font sizes, and styles. 
Note: Only your printer's built-in fonts are supported. Phaedra offers 7 standard fonts which should be available on most PostScript and PCL printers. If you select a font which is not supported by your printer, it will usually fall back to Courier.

The [Print Fontlist] button prints a list of all built-in fonts of your printer. 

## Markdown Support
-------------------------------------------------------------------------------
Phaedra follows a "graceful degradation" design philosophy for document printing. The built-in Markdown support is intentionally kept lightweight ("Lite-Markdown") so that your raw text files remain clean, perfectly readable, and easy to edit directly inside the editor without visual clutter. 

When printed via PCL or standard text mode, these lightweight tags act as clean text markers. However, when printed using PostScript, Phaedra automatically transforms them into fully styled typography - such as proportional headings, font weight adjustments, vector-based horizontal separation lines, and smart orphan control for page breaks.

Currently, you can add 5 levels of headings with different font sizes, print text in bold or italic, print a horizontal line (using 10 or more hyphens), or trigger a page break (`\pageend`). Check "Render Markup" in the print dialog to interpret these tags.

Please note: Phaedra is not intended to be a full-fledged Markdown editor. The implemented Markdown support is strictly limited to a few basic formatting options for printing. The supported tags were deliberately chosen to ensure they do not disrupt the reading flow of the unrendered text inside the editor, but rather act as natural and useful structuring elements for your plain text.

Tagging has been implemented for simple and sequential formatting only. Nesting of tags is not supported.


### Supported Tags and Examples
#### Headings
-------------------------------------------------------------------------------
# Heading 1
Font size = Base font size from print dialog + 8.

## Heading 2
Font size = Base font size from print dialog + 6.

### Heading 3
Font size = Base font size from print dialog + 4.

#### Heading 4
Font size = Base font size from print dialog + 2.

##### Heading 5
Font size = Base font size from print dialog.

The "#" to "#####" tags must be the first characters on a line and must be followed by a space. All headings will be printed bold.

Tip: If you want to print "# Heading" on paper without triggering the markup rendering, simply escape the character with a backslash like this: "\# Heading". The backslash will be hidden and the text will be printed normally.


#### Font Style
-------------------------------------------------------------------------------
A single asterisk is used to set text to *Italic*, and a double asterisk is used to print text in **bold**.

Tip: If you want to use an actual asterisk in your text without triggering markup, you need to escape the character like this: \* or \**.


#### Horizontal Rules (Lines)
-------------------------------------------------------------------------------
If you type a line consisting exclusively of at least 10 hyphens (e.g. ----------------------), the print engine will render it as a continuous graphical vector line across the full width of the page in PostScript. This looks great as a separator in the editor and prints beautifully on paper.



#### Page Breaks
-------------------------------------------------------------------------------
The command \pageend triggers a page break. It must be the first string on a new line.

\pageend

We are on the next page now. All Markdown tags will be interpreted by the print engine and will not appear on the paper. 

##### Orphan Control (Smart Page Breaks)
-------------------------------------------------------------------------------
When printing in PostScript mode with Markdown enabled, Phaedra automatically manages page breaks for headings and horizontal lines (Orphan Control). Before printing a heading or a horizontal line, the engine calculates the remaining space on the page. If it is too close to the bottom margin and there is no room left for at least one following line of text, Phaedra will automatically insert a page break. This ensures your headings and separators are never left stranded at the very bottom of a page.


#### Test Text
-------------------------------------------------------------------------------
Just a test for the line spacing:

# Heading
## Heading
### Heading
#### Heading
##### Heading
#### Heading
### Heading
## Heading
# Heading