This chapter describes print enhancement with mp. It discusses the following topics:
An enhanced mp(1) print filter is available in the Solaris 9 environment that can print various input file formats including flat text files written in UTF-8. It uses TrueType and Type 1 scalable fonts and X11 bitmap fonts available on the Solaris system. It can also make use of printer resident fonts and can act as an X print server client.
The output from the utility is standard PostScript and can be sent to any PostScript printer. mp(1) can also output any page description language when working as an X Print server client, mp is supported by the print server.
To use the utility, type the following:
system% mp filename | lp
You can also use the utility as a filter, since the utility accepts stdin stream
system% cat filename | mp | lp:
You can set the utility as a printing filter for a line printer. For example, the following command sequence tells the printer service LP that the printer lp1 accepts only mp format files. This command also installs the printer lp1 on port /dev/ttya. See the lpadmin(1M) man page for more details.
system# lpadmin -p lp1 -v /dev/ttya -I MP system# accept lp1 system# enable lp1
Using lpfilter(1M), you can add the utility for a filter as follows:
system# lpfilter -f lp1 -F pathname
The command tells LP that a converter (in this case, mp) is available through the filter description file named pathname. pathname contains the following:
Input types: simple Output types: MP Command: /usr/bin/mp
The filter converts the default type file input to PostScript output using /usr/bin/mp.
To print a UTF-8 text file, use the following command
system% lp -T MP UTF-8-file
Refer to the mp man page for more detail.
The mp print filter is enhanced in the Solaris 9 release. The latest mp can work internally in three different modes to produce the output file in a locale to print international text. The available modes are:
mp working with locale-specific font configuration file mp.conf.
mp working with locale-specific PostScript prolog file prolog.ps.
mp working as an Xprt (X Print Server ) client.
The following sections describe when to use a specific printing method and which configuration and supporting files are used by mp for these printing methods.
If the -D or -P option is not given in the command line, this printing method is the default method, unless the prolog.ps file is present in either of the/usr/openwin/lib/locale/$LANG/print or /usr/lib/lp/locale/$LANG/mp directories. The prolog.ps file forces mp to print using PostScript embedded fonts in the file. Even if a prolog.ps exists in a locale, using the -M option ignores the prolog.ps file and uses a mp.conf file, if it exists, instead.
This method uses the /usr/lib/lp/locale/$LANG/mp/mp.conf font configuration file. You may not need to change this file unless you need to print using alternate fonts. This file can be configured with TrueType, Type 1 or .pcf fonts. /usr/lib/lp/locale/C/ contains .ps print page layout files common for this mode of printing as well as the next method. A description of how to customize these files is provided in Customizing Existing prolog Files and Adding New prolog Files.
If the -D or -P option is not given in the command line, and /usr/openwin/lib/locale/$LANG/print/prolog.ps exists, then the prolog.ps file is prepended to the output. Depending upon the print style of the .ps prolog page, the layout file is also prepended to the output.
This method of printing makes use of PostScript font files only. Customization of prolog.ps files is described in Using mp as an Xprt (X Print Server) Client.
This support enables mp to print output for any printer connected to the network supported by an X Print Server. PostScript and many versions of PCL are also supported with this command.
If either the -D or -P command opton is used, and no XPDISPLAY variable is set in your environment, the print server startup script starts an Xprt server at port 2100 in the machine in which the client is running. The script also terminates the print server after mp completes. If XPDISPLAY is set, the mp client tries to contact the print server running at XPDISPLAY. In this case, no attempt is made to start the server if it is not running.
.The /usr/lib/lp/locale/C/mp directory contains .xpr print page layout files for mp working as the Xprt client. These are sample files created for 300 dpi printers. If the target printer has a different dpi value, the dpi value will automatically be converted to the target printer's resolution.
Configuration files provide the flexibility for adding or changing font entries, or font group entries.
The system default configuration file /usr/lib/lp/locale/$LANG/mp/mp.conf where $LANG is a locale environment variable in the locale in which printing occurs. Users can have a personal configuration file that can be specified by the -u config.file path option.
A ligature or variant glyph that has been encoded as a character for compatibility is called a presentation form. The mp.conf file is used mainly for mapping the intermediate code points in a locale to the presentation forms in the encoding of the font that is used to print that code point.
Intermediate code points can either be wide characters, or output of the Portable Layout Services (PLS) layer. Complex Text Layout printing requires that the intermediate code points be PLS output. The default intermediate code generated by mp(1) is PLS output.
Font formats currently supported are Portable Compiled Format (PCF), TrueType, and Type1 format. Both system-resident and printer-resident Type1 fonts are supported. Keep in mind the following about the format and contents of the mp.conf configuration file:
Lines must begin with a valid keyword (directive).
Arguments to a keyword must appear on the same line as the keyword.
Lines that begin with a # character are treated as comments until the end of the line.
Numeric arguments that begin with 0x are interpreted as a hexadecimal number.
The different sections in the mp.conf file include:
Font aliasing
Font group definition
Mapping from the intermediate code ranges to the font group in a locale
Associating each font with the shared object that maps the intermediate code points to the presentation forms in the font encoding
The font aliasing section of the mp.conf file is used to define alias names for each font used for printing. Each line in this section is of the form:
FontNameAlias font-alias-name font-type font-path
The usual convention for aliasing a font name is to specify the encoding/script name of the font followed by a letter that indicates whether the font is Roman, Bold, Italic, or BoldItalic (R, B, I or BI).
For example, /usr/openwin/lib/X11/fonts/75dpi/courR18.pcf.Z, because it is an iso88591 Roman font, can be given the alias name iso88591R.
Specify PCF for .pcf fonts, Type1 for Adobe Type1 fonts, and TrueType for truetype fonts. Only these three kinds of fonts can be configured in this mp.config file.
Give the absolute path name for the font files here. For Type1 printer-resident fonts, just specify the font name, such as Helvetica.
FontNameAlias prnHelveticaR Type1 Helvetica
You can combine same-type fonts to form a font group. The format of the font group is as follows.
FontGroup.
The group name for the fonts.
The font type. Create font groups for the same type of fonts only (PCF, Type1, TrueType).
The Roman Font name in the font group.
The Bold Font name in the font group.
The Italic Font name in the font group.
The BoldItalic Font name in the font group.
For creating a group, only a Roman font entry is required. The Bold, Italic, and BoldItalic fonts are optional. The different types of fonts are used to display the header lines for mail/news articles, for example. If only the Roman font is defined, it is used in place of other fonts.
The mapping section of the mp.conf files maps from the intermediate code ranges to the font group in a locale. Each line in this section is as follows.
MapCode2Font.
A 4–byte hexadecimal value that starts with 0x, that indicates the start of the code range to map to one or more font group.
Indicates the end of the code range to map. It can be '-' in which case only a single intermediate code point is mapped to the target font.
A Type1, PCF, or TrueType font group, with which the presentation forms are to be printed.
The association section of the mp.conf file associates each font with the shared object that maps the intermediate code points to the presentation forms in the fonts encoding. Each line in this section is as follows.
CnvCode2Font.
The alias name defined for the font.
Takes in the intermediate code and returns presentation forms in fonts encoding, which is in turn used to get the glyph index, and draw the glyph.
The .so file name that contains the mapping function. You can use the utility in dumpcs to find out the intermediate codeset for EUC locales.
The current TrueType engine used by mp (1) can deal only with format 4 and PlatformID 3 cmap. That is, you can only configure Microsoft .ttf files. Additionally, the character map encoding has to be Unicode or Symbol for the TrueType font engine to work correctly. Because most of the .ttf fonts in the Solaris environment obey these restrictions, you can map all TrueType fonts in Solaris software within the mp.conf file.
When you create a shared object for mapping a font that corresponds to a PCF type1 X Logical Fonts Description (XLFD), then create the shared object that maps from the intermediate code range to the encoding specified by XLFD. For example:
-monotype-arial-bold-r-normal-bitmap-10-100-75-75-p-54-iso8859-8
The corresponding PCF font is:
/usr/openwin/lib/locale/iso_8859_8/X11/fonts/75dpi/ariabd10.pcf.Z
This font is encoded in isoISO 8859-8, so shared objects have to map between intermediate code and corresponding ISO 8859-8 code points.
If a TrueType font with XLFD:
-monotype-arial-medium-r-normal--0-0-0-0-p-0-iso8859-8
has the corresponding font:
/usr/openwin/lib/locale/iso_8859_8/X11/fonts/TrueType/arial__h.ttf
you should map between the intermediate code and Unicode, because the cmap encoding for the previous TrueType font is in Unicode. In the example of this TrueType font, suppose a sample intermediate code in the en_US.UTF-8 locale that corresponds to a Hebrew character (produced by the PLS layer) is 0xe50000e9. Because the font is Unicode encoded, design the function within the corresponding .so module in such a way that when you are passing 0xe50000e9, the output corresponds to presentation form in Unicode. The example here is 0x000005d9.
The function prototype for the mapping function should be:
unsigned int function(unsigned int inter_code_pt)
The following are optional keyword/value pairs that you can use in mp.conf:
PresentationForm WC/PLSOutput
The default value is PLSOutput. If the user specifies WC, then the intermediate code points that are generated are wide characters. For CTL printing, this default value should be used.
If the locale is a non-CTL locale and has the keyboard value is PLSOutput, that value is ignored and the mp(1) generates wide-character codes instead.
You can use the optional keyword/value pairs listed in the following table if the locale supports CTL. These variables can assume any of the possible values given in the middle column of the table.
Table 7–1 Optional Keyword/Value Pairs
Optional Keyword |
Optional Value |
Default |
---|---|---|
Orientation |
ORIENTATION_LTR/ ORIENTATION_RTL/ ORIENTATION_CONTEXTUAL |
ORIENTATION_LTR |
Numerals |
NUMERALS_NOMINAL/ NUMERALS_NATIONAL/ NUMERALS_CONTEXTUAL |
NUMERALS_NOMINAL |
TextShaping |
TEXT_SHAPED/ TEXT_NOMINAL/ TEXT_SHFORM1/ TEXT_SHFORM2/ TEXT_SHFORM3/ TEXT_SHFORM4 |
TEXT_SHAPED |
The following example illustrates the steps that you need to follow when you add a new PCF, TrueType, or Type1 printer-resident font to the configuration file.
Replace the font for displaying characters in the range 0x00000021 - 0x0000007f with a TrueType font instead of the currently configured PCF font.
Before adding a new font, look at various components in the configuration file that correspond to the currently configured font, as shown next.
FontNameAlias iso88591R PCF /usr/openwin/lib/X11/fonts/75dpi/courR18PCF.Z FontNameAlias iso88591B PCF /usr/openwin/lib/X11/fonts/75dpi/courB18PCF.Z . . . FontGroup iso88591 PCF iso88591R iso88591B . . . MapCode2Font 0x00000020 0x0000007f iso88591 . . . CnvCode2Font iso88591R _xuiso88591 /usr/lib/lp/locale/$LANG/mp/xuiso88591.so CnvCode2Font iso88591B _xuiso88591 /usr/lib/lp/locale/$LANG/mp/xuiso88591.so
Suppose you selected /usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf as your candidate for doing the mapping in the en_US.UTF-8 locale. Because this is a Unicode character-mapped TrueType font file, in the mapping function within the .so module you only need to have a function that directly returns the incoming ucs-2 code points.
unsigned short _ttfjis0201(unsigned short ucs2) { return(ucs2); }
Save this in a ttfjis0201.c file. Create a shared object as follows.
cc -G -Kpic -o ttfjis0201.so ttfjis0201.c
But if you are mapping a PCF file, such as /usr/openwin/lib/locale/ja/X11/fonts/75dpi/gotmrk20.pcf.Z, then look in the fonts.dir file in the /usr/openwin/lib/locale/ja/X11/fonts/75dpi/ directory. Become familiar with the encoding, corresponding to XLFD, which is:
-sun-gothic-medium-r-normal--22-200-75-75-c-100-jisx0201.1976-0
If jisx0201 is the encoding, prepare a shared object that maps from ucs-2 to jisx0201. You need to obtain the mapping table for creating the .so module (if one is not already provided). For a Unicode locale, find the mappings from the many charsets to Unicode under ftp.unicode.org/pub/MAPPINGS/. Follow these mappings(1)(1) in order to write a xu2jis0201.c file:
unsigned short _xu2jis0201(unsigned short ucs2) { if(ucs2 >= 0x20 && ucs2 <= 0x7d ) return (ucs2); if(ucs2==0x203e) return (0x7e); if(ucs2 >= 0xff61 && ucs2 <= 0xff9f) return (ucs2 - 0xff60 + 0xa0); return(0); }
When you create a mapping file, include all the UCS-2 to jisx0201 cases.
cc -G -o xu2jis0201.so xu2jis0201.c
This example creates a shared object file.
Add this font by adding the following lines to the corresponding sections of mp.conf. The following example shows how to add the TrueType font. The PCF font follows the same pattern except that you change the keyword to PCF instead of TrueType.
FontNameAlias jis0201R TrueType /home/fn/HG-Minchol.ttf FontGroup jis0201 TrueType jis0201R MapCode2Font 0x0020 0x007f jis0201 CnvCode2Font jis0201R _ttfjis0201 <.so path>
where the .so path points to the xu2jis0201.so file.
Invoking mp(1) with the changed mp.conf file causes the range 0x0020-0x007f to be printed in the new font. Map the other Japanese character ranges too with the same .so file, for example, the range 0x0000FF61 0x0000FF9F.
To maintain backward compatibility, the /usr/openwin/lib/locale/$LANG/print/prolog.ps file, if it exists, is used to create output in the current locale, where $LANG is one of the locale components. In that situation, no configuration file mechanism is used.
Refer to /usr/lib/lp/locale/en_US.UTF-8/mp/mp.conf, which is a sample mp.conf file.
The prolog files can be divided into two main categories:
PostScript prolog files (.ps)
X print server client prolog files(.xpr).
The PostScript files fall into the following categories:
Common prolog file
Print layout prolog files
The purpose of the prolog.ps file is to set up non-generic fonts. Applications use these predefined PostScript font names for printing. The prolog file must define at least the following font names for Desk Set Calendar manager and mp.
LC_Times-Roman
LC_Times-Bold
LC_Helvetica
LC_Helvetica-Bold
LC_Courier
LC_Helvetica-BoldOblique
LC_Times-Italic
The following example uses these fonts to print the particular local character set specified:
100 100 moveto /LC_Times-Roman findfont 24 scale font setfont (Any text string in your locale) show
The Solaris localization kit provides a sample prolog.ps file for the Japanese environment. Alternatively, this file is found in the /usr/openwin/lib/locale/ja/print/ directory.
The following example shwos how to add or change composite fonts in an existing prolog.ps.
% (Foo-Fine) makecodeset12 (Base-Font) makeEUCfont %
Suppose you want to define a composite font called LC_Base-Font:
LC_Base-Font is a composite font of Foo-Fine and a base font called Base-Font. Foo-Fine is a font that contains the local character set. You do not need any in-depth PostScript knowledge to add or change a font.
The best way to create a prolog.ps File is to study the example version. In the example prolog.ps, two routines need to be written, makecodeset12 and makeEUCfont. Makecodeset12 sets up local font-encoding information. This routine might differ from locale to locale. MakeEUCfont combines the base font and the locale font to form a composite font. The creator of the prolog file should have good knowledge of PostScript in order to write makecodeset12 and makeEUCfont.
prolog.ps file support is kept for backward compatibility only. Do not create a new prolog.ps file for the printing needs of a locale. Use mp.conf instead.
The path for prolog.ps is
/usr/openwin/lib/locale/$LANG/print/prolog.ps
The common prolog file is mp.common.ps.
Every other page layout prolog file needs to include this file.
The mp.common.ps file resides in the /usr/lib/lp/locale/C/mp/ directory, contains a PostScript routine to re-encode a font from the standard encoding to the ISO 8859–1 encoding. The .reencodeISO routine is called from the print layout prolog files to change encoding of the fonts. Usually this prolog file does not need any customization. If the users are creating their own prolog files, set the environment variable MP_PROLOGUE to point to the directory that contains the modified prolog files.
The print layout prolog files, mp.*.ps files, contain routines for controlling the page layout for printing. In addition to giving a header and a footer for a print page with user name, print date, and page number, these prolog files can provide other information. For example, the prolog files can give effective print area dimensions and landscape and portrait mode of printing to be used.
The Print Layout prolog files are:
mp.pro.ps
mp.pro.alt.ps
mp.pro.fp.ps
mp.pro.ps
mp.pro.ts.ps
mp.pro.altl.ps
mp.pro.ff.ps
mp.pro.l.ps
mp.pro.ll.ps
mp.pro.tm.ps
A set of standard functions needs to be defined in every prolog file. These functions are called when a new print page starts, a print page ends, or a new column ends. The implementations of these functions define the print attributes of the printout.
The following PostScript variables are defined at runtime by the mp(1) binary. All the print layout files can use these variables for printing dynamic information such as user name, subject, print time. This information taken from the variables normally appears in the header or footer of the print page.
The name of the user who is running mp, obtained from the system passwd file.
Variable used to hold the name of the type of article to print. The possible values for this variable are:
“Listing for” - When the input is a text file
“Mail for” - When the input is a mail file
“Article from” - When the input is an article from a news group
The subject taken from the mail and news headers. You can use the -s option to force a subject to the mail and news files as well as to normal text files.
The time of print that appears in the header and footer. This information is taken from the localtime() function.
The following functions are implemented in print layout prolog files. All these functions can use subfunctions.
usage : page_number endpage
Called when the bottom of a printed page is reached. This function restores the graphic context of the page and issues a “showpage.” In some prolog files the header and footer information is displayed in only a page-by-page mode rather than in a column-by-column mode. You can implement this function to call subfunctions that display the header and footer gray scale lozenges.
usage : page_number newpage
Routines or commands to be executed when a new page begins. Setting landscape print mode, saving the print graphic context, and translating the page coordinates are some of the functions for routine.
usage : page_number col_number endcol
Used to display header and footer information. Move to the new print position, and so forth.
For adding new print layout prolog files, you need to define the following variables explicitly within the print layout prolog file.
Number of columns in a print page. Default is 2.
Width of print area in inches. Default is 6.
Height of print area in inches. Default is 9.
These files are located by default at /usr/lib/lp/locale/C/mp/. An .xpr file corresponds to each PostScript prolog layout file, except for mp.common.ps. You can define an alternate prolog directory by defining the MP_PROLOGUE environment variable.
These files work as keyword/values pairs. Lines that start with # are considered comments. Spaces separate different tokens unless explicitly stated. Three main sections for each .xpr file are bound by the following keyword pairs:
STARTCOMMON/ENDCOMMON
STARTPAGE/ENDPAGE
STARTCOLUMN/ENDCOLUMN
STARTFORCEDPAGE/ENDFORCEDPAGE
STARTFORCEDCOLUMN/ENDFORCEDCOLUMN
All the keyword/value pairs that appear after the STARTCOMMON keyword and before the ENDCOMMON keyword define general properties of the print page. Different valid values for a keyword are separated by using "/".
"0" means the printing occurs in portrait and "1" means in landscape.
A value that indicates the number of lines per logical page.
A value that indicates the number of single column characters per line.
The number of logical pages per physical page.
The heading font point size in decipoints.
The body font point size in decipoints.
The dots-per-inch scale in which the current .xpr file is created.
This y-coordinate establishes the boundary for text printing in a page or logical page (column). This boundary is used as an additional check to see whether text printing is occurring within the expected area. This boundary is needed for Complex Text Layout and EUC printing, as character height information obtained from corresponding fonts can be wrong.
The decipoint x/y points where the actual text printing starts in the first logical page in a physical page.
The 1 indicates that a "Page" string needs to be appended before the page number in the heading.
0 indicates that only the page number is displayed.
The 'font string 1' to 'font string n' are X Logical Font Descriptions. The Token that separates the keyword EXTRAHDNGFONT from the comma separated font name list is ", not spaces or tabs. These fonts are given preference over the built-in fonts when the heading is printed. Usually, EXTRABODYFONT is used to assign printer-resident fonts that are configured in /usr/openwin/server/etc/XpConfig/C/print/models/<model name>/fonts directory.
The fonts.dir file contains the XLFD of the printer-resident fonts.
Usually a font is specified as
"-monotype-Gill Sans-Regular-r-normal- -*-%d-*-*-p-0-iso8859-2"
in the .xpr file. "%d", if present, is replaced by mp(1) to the point size of the current heading fonts in the .xpr file. The x resolution and y resolution are specified by * and the average width field is set as 0 to indicate selection of a scalable font, if possible. You can give more specific font names also.
The same as EXTRAHDNGFONT, except that these fonts are used to print the page body.
Gives the x coordinate displacement to be applied to the page for shifting the contents of the page in the x direction. This displacement can be a +ve or -ve value.
The same as x displacement except that the shifting happens in the y direction.
These two keywords are useful when you find that some printers have nonstandard margin widths and you need to shift the printed contents in a page.
The keyword value pairs in this section are bound by STARTPAGE and ENDPAGE keywords. This section contains drawings and heading information that is to be applied for a physical page. A physical page can contain many logical pages, but all the drawing routines that are contained between these keywords are applied only once to a physical page.
The valid drawing entities are LINE and ARC. XDrawLine() and XDrawArc() functions are executed on values of these keywords.
The dimensions within this section are mapped in PROLOGDPI units. Angles are in degrees.
The x/y unsigned coordinates define a pair of points for connecting a line.
x and y are both unsigned integers that represent the arc origin. Width and height are unsigned integers that represent the width and height of the arc.
Unsigned coordinates represent the position in which the user information is printed on the heading.
Unsigned coordinates represent the position in which the time for printing is printed on the heading.
Unsigned coordinates represent the position to print the page string for each printed page.
Unsigned coordinates represent the position to print the subject in the page.
When the -n option is given to mp, all the decorations given within a STARTPAGE/ENDPAGE section do not print. However, everything included within a STARTFORCEDPAGE/ENDFORCEDPAGE section prints even if the -n option is given.
All keywords are the same as secribed in STARTPAGE/ENDPAGE except that the entries in this section are applied to NUMCOLS times to a physical page.
If NUMCOLS is 3, then the printable area of the physical page is divided into three, and lines, arcs, or heading decorations appear three times per page.
When the -n option is given to mp, all the decorations given within a STARTCOLUMN/ENDCOLUMN section do not print. However, everything included within a STARTFORCEDCOLUMN/ENDFORCEDCOLUMN section prints even if the -n option is given.
The following values are the mp(1) program defaults for different keywords if these values are not specified in the .xpr file for the STARTCOMMON/ENDCOMMON section.
No default values are needed for the other two sections bound by STARTPAGE/ENDPAGE and STARTCOLUMN/ENDCOLUMN.
When you create a new .xpr prolog file, you need to specify only the values that differ from the default.
To create a page with no decoration, use four logical pages per physical page, in portrait format.
STARTCOMMON
NUMCOLS 04
LINELENGTH 20
ENDCOMMON
In this situation, you do not need the other two sections:
STARTPAGE/ENDPAGE
STARTCOLUMN/ENDCOLUMN
These parameters are not needed if you are not putting decorations on the printed page. All the coordinates are in 300 dpi default unless you are not specifying the PROLOGDPI keyword. If target printer resolution is different, the .xpr file is scaled to fit into that resolution by the program.
When you create a .xpr file, you must know the paper dimensions beforehand. For U.S. paper, 8.5x11 inches, for a printer of resolution 300 dpi, 2550X3300 are the total dimensions. Most printers cannot print from the top left corner of the paper. Instead, they put some margin around the physical paper. That means that even if you try to print from 0,0 the printing won't be in the top left corner of the page. You need to consider this limitation when you create a new .xpr file.