diff options
author | wlemb <wlemb> | 2002-06-02 07:53:29 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-06-02 07:53:29 +0000 |
commit | 0e0a7ffad1d5d273a7343d57bf2c6633ec135f9a (patch) | |
tree | 416d853315470c1426565e93f8ff5508b1708f92 | |
parent | 9a0ec6f8ca061d6c7c20f90f21d9882cadfb1141 (diff) | |
download | groff-0e0a7ffad1d5d273a7343d57bf2c6633ec135f9a.tar.gz |
Adding a new keyword `papersize' to the DESC file format (similar
but not completely identical to grolbp's extension). grops now has
a -p command line option to override `papersize'. Finally, grolbp
has been adapted to the new syntax.
* src/libs/libgroff/paper.cc, src/include/paper.h: New files. It
defines and initializes the `papersizes[]' array with NUM_PAPERSIZES
elements.
* src/libs/libgroff/Makefile.sub (OBJS): Add `paper.o'.
(CCSRCS): Add `paper.cc'.
* src/include/font.h (font): Add `papersize' element.
* src/libs/libgroff/font.cc (font::unit_scale): New helper function.
(font::scan_papersize): New function.
(font::load_desc): Use it for handling `papersize' keyword.
* src/libs/libgroff/fontfile.cc: Initialize `font::papersize'.
* src/devices/grops/ps.cc: Include paper.h.
(user_paper_length): New global variable.
(ps_printer): Use paper length as initializer.
(make_printer): Updated.
(main): Handle new `-p' option.
* src/devices/grops/grops.man: Updated.
* src/devices/grolbp/lbp.cc: Include paper.h.
s/papersizes/lbp_papersizes/.
(set_papersize): Use new `papersizes' array.
(handle_unknown_desc_command): Don't handle `papersize'.
(main): Use `font::scan_papersize' for handling `-p' option.
* src/devices/grolbp/grolbp.man: Updated.
* man/groff_font.man: Document `papersize'.
* NEWS: Updated.
-rw-r--r-- | ChangeLog | 42 | ||||
-rw-r--r-- | NEWS | 24 | ||||
-rw-r--r-- | man/groff_font.man | 381 | ||||
-rw-r--r-- | src/devices/grolbp/grolbp.man | 57 | ||||
-rw-r--r-- | src/devices/grolbp/lbp.cc | 124 | ||||
-rw-r--r-- | src/devices/grops/TODO | 3 | ||||
-rw-r--r-- | src/devices/grops/grops.man | 45 | ||||
-rw-r--r-- | src/devices/grops/ps.cc | 42 | ||||
-rw-r--r-- | src/include/font.h | 6 | ||||
-rw-r--r-- | src/include/paper.h | 37 | ||||
-rw-r--r-- | src/libs/libgroff/Makefile.sub | 2 | ||||
-rw-r--r-- | src/libs/libgroff/font.cc | 112 | ||||
-rw-r--r-- | src/libs/libgroff/fontfile.cc | 3 | ||||
-rw-r--r-- | src/libs/libgroff/paper.cc | 79 |
14 files changed, 683 insertions, 274 deletions
@@ -1,3 +1,45 @@ +2002-06-02 Werner LEMBERG <wl@gnu.org> + + Adding a new keyword `papersize' to the DESC file format (similar + but not completely identical to grolbp's extension). grops now has + a -p command line option to override `papersize'. Finally, grolbp + has been adapted to the new syntax. + + * src/libs/libgroff/paper.cc, src/include/paper.h: New files. It + defines and initializes the `papersizes[]' array with NUM_PAPERSIZES + elements. + * src/libs/libgroff/Makefile.sub (OBJS): Add `paper.o'. + (CCSRCS): Add `paper.cc'. + + * src/include/font.h (font): Add `papersize' element. + * src/libs/libgroff/font.cc (font::unit_scale): New helper function. + (font::scan_papersize): New function. + (font::load_desc): Use it for handling `papersize' keyword. + * src/libs/libgroff/fontfile.cc: Initialize `font::papersize'. + + * src/devices/grops/ps.cc: Include paper.h. + (user_paper_length): New global variable. + (ps_printer): Use paper length as initializer. + (make_printer): Updated. + (main): Handle new `-p' option. + * src/devices/grops/grops.man: Updated. + + * src/devices/grolbp/lbp.cc: Include paper.h. + s/papersizes/lbp_papersizes/. + (set_papersize): Use new `papersizes' array. + (handle_unknown_desc_command): Don't handle `papersize'. + (main): Use `font::scan_papersize' for handling `-p' option. + * src/devices/grolbp/grolbp.man: Updated. + + * man/groff_font.man: Document `papersize'. + * NEWS: Updated. + +2002-05-30 Werner LEMBERG <wl@gnu.org> + + * src/devices/grops/TODO: Updated. + * src/devices/grops/grops.man: More info on paper formats. + * man/groff_font.man: Document `paperheight' and `paperwidth'. + 2002-05-29 Werner LEMBERG <wl@gnu.org> * doc/Makefile.sub (CLEANADD): Add grnexmpl.g, groff, and groff-* @@ -290,6 +290,9 @@ Grops o Color support has been added. +o A new option `-p' is available to select the output paper size. It has + the same syntax as the new `papersize' keyword in the DESC file. + Grodvi ------ @@ -358,6 +361,13 @@ o New options `-a' and `-g' to control the number of bits for anti-aliasing used for text and graphics, respectively. Default value is 4; 0 means no anti-aliasing. +Grolbp +------ + +o Valid paper sizes are now specified as with the new `papersize' keyword + in the DESC file. Specifically, the old custom paper type format + `custAAAxBBB' is no longer supported. + Miscellaneous ------------- @@ -366,6 +376,20 @@ o A new manual page `ditroff.7' is available. o The groff texinfo manual will now be installed, together with a bunch of examples. +o A new keyword `papersize' has been added to the DESC file format. Its + argument is either + + . a predefined paper format (e.g. `A4' or `letter') + + . a file name pointing to a file which must contain a paper size + specification in its first line (e.g. `/etc/papersize') + + . a custom paper size definition like `35c,4i' + + See groff_font(5) for more details. This keyword only affects the + physical dimensions of the output medium; grops and grolbp use it + currently. troff completely ignores it. + VERSION 1.17.2 ============== diff --git a/man/groff_font.man b/man/groff_font.man index a7118f04..dbeaa369 100644 --- a/man/groff_font.man +++ b/man/groff_font.man @@ -16,27 +16,37 @@ versions, except that this permission notice may be included in translations approved by the Free Software Foundation instead of in the original English. .. +. .de TQ .br .ns .TP \\$1 .. +. .\" Like TP, but if specified indent is more than half .\" the current line-length - indent, use the default indent. .de Tp .ie \\n(.$=0:((0\\$1)*2u>(\\n(.lu-\\n(.iu)) .TP .el .TP "\\$1" .. +. +. .TH GROFF_FONT @MAN5EXT@ "@MDATE@" "Groff Version @VERSION@" +. +. .SH NAME groff_font \- format of groff device and font description files +. +. .SH DESCRIPTION The groff font format is roughly a superset of the ditroff font format. +. The font files for device .I name are stored in a directory .BI dev name. +. There are two types of file: a device description file called .B DESC @@ -44,132 +54,237 @@ and for each font .I F a font file called .IR F . +. These are text files; unlike the ditroff font format, there is no associated binary format. +. +. .SS DESC file format -The DESC file can contain the following types of line: +. +The DESC file can contain the following types of line as shown below. +. +Later entries in the file override previous values. +. .TP -.BI res\ n -There are -.I n -machine units per inch. +.B charset +This line and everything following in the file are ignored. +. +It is allowed for the sake of backwards compatibility. +. +.TP +.BI family\ fam +The default font family is +.IR fam . +. +.TP +.BI fonts\ n\ F1\ F2\ F3\|.\|.\|.\|Fn +Fonts +.I F1\|.\|.\|.\|Fn +will be mounted in the font positions +.IR m +1,\|.\|.\|., m + n +where +.I m +is the number of styles. +. +This command may extend over more than one line. +. +A font name of +.B 0 +will cause no font to be mounted on the corresponding font position. +. .TP .BI hor\ n The horizontal resolution is .I n machine units. +. .TP -.BI vert\ n -The vertical resolution is -.I n -machine units. +.BI paperheight\ n +The physical vertical dimension of the output medium in machine units. +. +This isn't used by +.B troff +itself; currently, only +.B grops +uses it. +. .TP -.BI sizescale\ n -The scale factor for pointsizes. -By default this has a value of 1. -One -.I -scaled point -is equal to -one -.RI point/ n . -The arguments to the -.B unitwidth +.BI paperwidth\ n +The physical horizontal dimension of the output medium in machine units. +. +This isn't used by +.BR troff . +. +Currently, only the +.B grolbp +output device uses it. +. +.TP +.BI papersize\ string +Select a paper size. +. +Valid values for +.I string +are the ISO paper types A0-A7, B0-B7, C0-C7, D0-D7, and the US paper +types letter, legal, tabloid, ledger, statement, and executive. +. +Case is not significant for +.IR string +for predefined paper types. +. +Alternatively, +.I string +can be a file name (e.g.\& `/etc/papersize'); if the file can be opened, +.B groff +reads the first line and tests for the above paper sizes. +. +Finally, +.I string +can be a custom paper size in the format +.IB length , width +(no spaces before and after the comma). +. +Both +.I length and -.B sizes -commands are given in scaled points. +.I width +must have a unit appended; valid values are `i' for inches, `c' for +centimeters, `p' for points, and `P' for picas. +. +Example: +.BR 12c,235p . +. +An argument which starts with a digit is always treated as a custom paper +format. +. +.B papersize +sets both the vertical and horizontal dimension of the output medium. +. +. .TP -.BI unitwidth\ n -Quantities in the font files are given in machine units -for fonts whose point size is -.I n -scaled points. +.B pass_filenames +Make troff tell the driver the source file name being processed. +. +This is achieved by another tcommand: +.B F +.IR filename . +. +.TP +.BI postpro\ program +Use +.I program +as the postprocessor. +. .TP .BI prepro\ program Call .I program as a preprocessor. +. .TP -.BI postpro\ program +.BI print\ program Use .I program -as the postprocessor. -.TP -.B tcommand -This means that the postprocessor can handle the -.B t +as the spooler program for printing. +. +If omitted, the +.B \-l and -.B u -output commands. +.B \-L +options of +.B groff +are ignored. +. +.TP +.BI res\ n +There are +.I n +machine units per inch. +. .TP .BI sizes\ s1\ s2\|.\|.\|.\|sn\ 0 This means that the device has fonts at .IR s1 , .IR s2 ,\|.\|.\|.\| sn scaled points. +. The list of sizes must be terminated by a .BR 0 . +. Each .I si can also be a range of sizes .IR m \- n . +. The list can extend over more than one line. +. +.TP +.BI sizescale\ n +The scale factor for pointsizes. +. +By default this has a value of 1. +. +One +.I +scaled point +is equal to +one +.RI point/ n . +. +The arguments to the +.B unitwidth +and +.B sizes +commands are given in scaled points. +. .TP .BI styles\ S1\ S2\|.\|.\|.\|Sm The first .I m font positions will be associated with styles .IR S1\|.\|.\|.\|Sm . +. .TP -.BI fonts\ n\ F1\ F2\ F3\|.\|.\|.\|Fn -Fonts -.I F1\|.\|.\|.\|Fn -will be mounted in the font positions -.IR m +1,\|.\|.\|., m + n -where -.I m -is the number of styles. -This command may extend over more than one line. -A font name of -.B 0 -will cause no font to be mounted on the corresponding font position. +.B tcommand +This means that the postprocessor can handle the +.B t +and +.B u +output commands. +. .TP -.BI family\ fam -The default font family is -.IR fam . +.BI unitwidth\ n +Quantities in the font files are given in machine units +for fonts whose point size is +.I n +scaled points. +. .TP .B use_charnames_in_special This command indicates that troff should encode named characters inside special commands. +. .TP -.B pass_filenames -requests that troff tells the driver the source file name being processed. -This is achieved by another tcommand: -.B F -.IR filename . -.TP -.B charset -This line and everything following in the file are ignored. -It is allowed for the sake of backwards compatibility. -.TP -.BI print\ program -Use -.I program -as the spooler program for printing. -If omitted, the -.B \-l -and -.B \-L -options of -.B groff -are ignored. +.BI vert\ n +The vertical resolution is +.I n +machine units. +. .LP -The res, unitwidth, fonts and sizes lines are compulsory. +The +.BR res , +.BR unitwidth , +.BR fonts , +and +.B sizes +lines are compulsory. +. Other commands are ignored by .B troff but may be used by postprocessors to store arbitrary information about the device in the DESC file. +. .LP Here a list of obsolete keywords which are recognized by .B groff @@ -177,29 +292,21 @@ but completely ignored: .BR spare1 , .BR spare2 , .BR biggestfont . +. +. .SS Font file format -A font file has two sections. The first section is a sequence +. +A font file has two sections. +The first section is a sequence of lines each containing a sequence of blank delimited words; the first word in the line is a key, and subsequent words give a value for that key. -.TP -.BI name\ F -The name of the font is -.IR F . -.TP -.BI spacewidth\ n -The normal width of a space is -.IR n . -.TP -.BI slant\ n -The characters of the font have a slant of -.I n -degrees. (Positive means forward.) +. .TP .BI ligatures\ lig1\ lig2\|.\|.\|.\|lign\ \fR[ 0 \fR] Characters .IR lig1 , -.IR lig2 ,\|.\|.\|., lign +.IR lig2 ,\ \|.\|.\|.,\ lign are ligatures; possible ligatures are .BR ff , .BR fi , @@ -207,10 +314,31 @@ are ligatures; possible ligatures are .B ffi and .BR ffl . +. For backwards compatibility, the list of ligatures may be terminated with a .BR 0. +. The list of ligatures may not extend over more than one line. +. +.TP +.BI name\ F +The name of the font is +.IR F . +. +.TP +.BI slant\ n +The characters of the font have a slant of +.I n +degrees. +. +(Positive means forward.) +. +.TP +.BI spacewidth\ n +The normal width of a space is +.IR n . +. .TP .B special The font is @@ -218,40 +346,54 @@ The font is this means that when a character is requested that is not present in the current font, it will be searched for in any special fonts that are mounted. +. .LP Other commands are ignored by .B troff but may be used by postprocessors to store arbitrary information about the font in the font file. +. .LP The first section can contain comments which start with the .B # character and extend to the end of a line. +. .LP The second section contains one or two subsections. +. It must contain a .I charset subsection and it may also contain a .I kernpairs subsection. +. These subsections can appear in any order. +. Each subsection starts with a word on a line by itself. +. .LP The word .B charset starts the charset subsection. +. The .B charset line is followed by a sequence of lines. +. Each line gives information for one character. +. A line comprises a number of fields separated -by blanks or tabs. The format is +by blanks or tabs. +. +The format is +. .IP .I name metrics type code .RI [ entity_name ] .RB [ -- .IR comment ] +. .LP .I name identifies the character: @@ -268,24 +410,30 @@ corresponds to the special character .BI \[rs][ c ]\fR; otherwise it corresponds to the groff input character .BI \[rs][ name ]\fR. +. If it is exactly two characters .I xx it can be entered as .BI \[rs]( xx\fR. +. Note that single-letter special characters can't be accessed as .BI \[rs] c\fR; the only exception is `\[rs]-' which is identical to `\[rs][-]'. +. .LP Groff supports eight-bit characters; however some utilities have difficulties with eight-bit characters. +. For this reason, there is a convention that the name .BI char n is equivalent to the single character whose code is .IR n . +. For example, .B char163 would be equivalent to the character with code 163 which is the pounds sterling sign in ISO Latin-1. +. The name .B \-\-\- is special and indicates that the character is unnamed; @@ -293,28 +441,36 @@ such characters can only be used by means of the .B \[rs]N escape sequence in .BR troff . +. .LP The .I type field gives the character type: +. .TP 1 means the character has a descender, for example, p; +. .TP 2 means the character has an ascender, for example, b; +. .TP 3 means the character has both an ascender and a descender, for example, (. +. .LP The .I code field gives the code which the postprocessor uses to print the character. +. The character can also be input to groff using this code by means of the .B \[rs]N escape sequence. +. The code can be any integer. +. If it starts with a .B 0 it will be interpreted as octal; @@ -323,41 +479,56 @@ if it starts with or .B 0X it will be intepreted as hexadecimal. +. .LP The .I entity_name field gives an ascii string identifying the glyph which the postprocessor uses to print the character. +. This field is optional and has been introduced so that the html device driver can encode its character set. +. For example, the character `\[rs][Po]' is represented as `£' in html\~4.0. +. .LP Anything on the line after the encoding field resp. after `-\&-' will be ignored. +. .LP The .I metrics -field has the form: +field has the form (in one line; it is broken here for the sake of +readability): +. .IP -.IR width [\fB, height [\fB, depth [\fB, italic_correction [\fB, \ -left_italic_correction [\fB, subscript_correction ]]]]] +.IR width [\fB, height [\fB, depth [\fB, italic-correction +.br +.RI [\fB, left-italic-correction [\fB, subscript-correction ]]]]] +. .LP There must not be any spaces between these subfields. +. Missing subfields are assumed to be 0. +. The subfields are all decimal integers. +. Since there is no associated binary format, these values are not required to fit into a variable of type .B char as they are in ditroff. +. The .I width subfields gives the width of the character. +. The .I height subfield gives the height of the character (upwards is positive); if a character does not extend above the baseline, it should be given a zero height, rather than a negative height. +. The .I depth subfield gives the depth of the character, that is, the distance @@ -365,39 +536,49 @@ below the lowest point below the baseline to which the character extends (downwards is positive); if a character does not extend below above the baseline, it should be given a zero depth, rather than a negative depth. +. The -.I italic_correction +.I italic-correction subfield gives the amount of space that should be added after the character when it is immediately to be followed by a character from a roman font. +. The -.I left_italic_correction +.I left-italic-correction subfield gives the amount of space that should be added before the character when it is immediately to be preceded by a character from a roman font. +. The -.I subscript_correction +.I subscript-correction gives the amount of space that should be added after a character before adding a subscript. +. This should be less than the italic correction. +. .LP A line in the charset section can also have the format +. .IP .I name \fB" +. .LP This indicates that .I name is just another name for the character mentioned in the preceding line. +. .LP The word .B kernpairs starts the kernpairs section. +. This contains a sequence of lines of the form: +. .IP -.I -c1 c2 n +.I c1 c2 n +. .LP This means that when character .I c1 @@ -405,20 +586,28 @@ appears next to character .I c2 the space between them should be increased by .IR n . +. Most entries in kernpairs section will have a negative value for .IR n . +. +. .SH FILES +. .Tp \w'@FONTDIR@/devname/DESC'u+3n .BI @FONTDIR@/dev name /DESC Device description file for device .IR name . +. .TP .BI @FONTDIR@/dev name / F Font file for font .I F of device .IR name . +. +. .SH "SEE ALSO" +. .BR groff_out (@MAN5EXT@), .BR @g@troff (@MAN1EXT@). . diff --git a/src/devices/grolbp/grolbp.man b/src/devices/grolbp/grolbp.man index d567c1aa..ed3682f8 100644 --- a/src/devices/grolbp/grolbp.man +++ b/src/devices/grolbp/grolbp.man @@ -3,7 +3,7 @@ .\" vim: set syntax=nroff : .\" The above line should set vim into nroff mode .ig -Copyright (C) 1994-2000 Free Software Foundation, Inc. +Copyright (C) 1994-2000, 2002 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice @@ -160,74 +160,35 @@ precedence over the contents of the .B DESC file (this applies to the page orientation too). .PP -To set the paper size in the +See +.BR groff_font (@MAN1EXT@) +how to set the paper dimensions in the .B DESC -file, insert in that file a line containing -.B papersize -.IR desired_papersize , -where -.I desired_papersize -is: -.IP \(bu 4 -One of the recognized paper sizes: `a4', `letter', `legal' or `executive'. -.IP \(bu 4 -A custom defined paper size, as described in the -.B CUSTOM PAPER SIZES -subsection below. -.IP \(bu 4 -The name of a file (e.g. -.IR /etc/papersize ) -whose first line must be the desired paper size in one of the above formats. -.PP -If there are various papersize lines in the -.B DESC -file, only the first valid one is used. +file. .PP To set the paper size in the command line, add .sp 1 .in +2m -.BI \-p \ desired_papersize +.BI \-p \ paper-size .in -2m .sp 1 or .sp 1 .in +2m -.BI \-\-papersize= desired_papersize +.BI \-\-papersize= paper-size .in -2m .sp 1 to the other .B grolbp options, where -.B desired_papersize +.I paper-size is in the same format as in the .B DESC file. .PP -Paper sizes are case insensitive (i.e., `A4' is the same as `a4'). -.PP If no paper size is specified in the .B DESC file or the command line, a default size of A4 is used. -.TP -.SH CUSTOM PAPER SIZES -Custom defined paper sizes are in the form -.BI cust length x width -where -.I length -and -.I width -are the dimensions of the paper you want to to use, specified in printer -units (1/300 of an inch). -For instance, to print in a postcard sized paper which is two inches long -and four inches wide you can insert a line containing -.sp 1 -.in +2m -.B papersize cust600x1200 -.in -2m -.sp 1 -at the beginning of the -.B DESC -file. .SH PAGE ORIENTATION As with the page size, the orientation of the printed page .RB ( portrait @@ -247,7 +208,7 @@ file, insert a line with the following content: .RB [ portrait | landscape ] .in -2m .sp 1 -As with paper sizes, only the first valid orientation command in the +Only the first valid orientation command in the .B DESC file is used. .PP diff --git a/src/devices/grolbp/lbp.cc b/src/devices/grolbp/lbp.cc index 9ab69de0..adac4f63 100644 --- a/src/devices/grolbp/lbp.cc +++ b/src/devices/grolbp/lbp.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1994, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1994, 2000, 2001, 2002 Free Software Foundation, Inc. Written by Francisco Andrés Verdú <pandres@dragonet.es> with many ideas taken from the other groff drivers. @@ -30,6 +30,7 @@ TODO #include "driver.h" #include "lbp.h" #include "charset.h" +#include "paper.h" #include "nonposix.h" @@ -543,7 +544,7 @@ static struct { const char *name; int code; -} papersizes[] = +} lbp_papersizes[] = {{ "A4", 14 }, { "letter", 30 }, { "legal", 32 }, @@ -551,92 +552,25 @@ static struct }; -static int set_papersize(const char *papersize) +static int set_papersize(const char *paperformat) { unsigned int i; // First test for a standard (i.e. supported directly by the printer) - // papersize - for (i = 0 ; i < sizeof(papersizes)/sizeof(papersizes[0]); i++) + // paper size + for (i = 0 ; i < sizeof(lbp_papersizes)/sizeof(lbp_papersizes[0]); i++) { - if (strcasecmp(papersizes[i].name,papersize) == 0) - return papersizes[i].code; - }; + if (strcasecmp(lbp_papersizes[i].name,paperformat) == 0) + return lbp_papersizes[i].code; + } - // Now test for a custom papersize - if (strncasecmp("cust",papersize,4) == 0) - { - char *p , - *p1, - *papsize; - - p = papsize = strsave(&papersize[4]); - if (papsize == NULL) return -1; - p1 = strsep(&p,"x"); - if (p == NULL) - { // let's test for an uppercase x - p = papsize ; - p1 = strsep(&p,"X"); - if (p == NULL) { a_delete papsize; return -1;}; - }; // if (p1 == NULL) - paperlength = atoi(p1); - if (paperlength == 0) { a_delete papsize; return -1;}; - paperwidth = atoi(p); - if (paperwidth == 0) { a_delete papsize; return -1;}; - a_delete papsize; - return 82; - }; // if (strcnasecmp("cust",papersize,4) == 0) - - return -1; + // Otherwise, we assume a custom paper size + return 82; }; -static int handle_papersize_command(const char *arg) -{ - int n = set_papersize(arg); - - if (n < 0) - { // If is not a standard nor custom paper size - // let's see if it's a file (i.e /etc/papersize ) - FILE *f = fopen(arg,"r"); - if (f != NULL) - { // the file exists and is readable - char psize[255],*p; - fgets(psize,254,f); - fclose(f); - // set_papersize doesn't like the trailing \n - p = psize; while (*p) p++; - if (*(--p) == '\n') *p = 0x00; - - n = set_papersize(psize); - }; // if (f != NULL) - }; // if (n < 0) - - return n; -}; // handle_papersize_command - - static void handle_unknown_desc_command(const char *command, const char *arg, const char *filename, int lineno) { - // papersize command - if (strcasecmp(command, "papersize") == 0) { - // We give priority to command line options - if (papersize > 0) return; - if (arg == 0) - error_with_file_and_line(filename, lineno, - "`papersize' command requires an argument"); - else - { - int n = handle_papersize_command(arg); - if (n < 0) - error_with_file_and_line(filename, lineno, - "unknown paper size `%1'", arg); - else - papersize = n; - - }; // if (arg == 0) ... else ... - }; // if (strcasecmp(command, "papersize") - // orientation command if (strcasecmp(command, "orientation") == 0) { // We give priority to command line options @@ -670,13 +604,13 @@ static void usage(FILE *stream) fprintf(stream, "usage: %s [-lvh] [-c n] [-p paper_size] [-F dir] [-o or] "\ " [files ...]\n"\ - " -o --orientation=[portrait|landscape]\n"\ - " -v --version\n"\ - " -c --copies=numcopies\n"\ - " -l --landscape\n"\ - " -p --papersize=paper_size\n"\ - " -F --fontdir=dir\n"\ - " -h --help\n", + " -o --orientation=[portrait|landscape]\n"\ + " -v --version\n"\ + " -c --copies=numcopies\n"\ + " -l --landscape\n"\ + " -p --papersize=paper_size\n"\ + " -F --fontdir=dir\n"\ + " -h --help\n", program_name); }; // usage @@ -697,11 +631,23 @@ int main(int argc, char **argv) case 'F' : font::command_line_font_dir(optarg); break; case 'p' : { - int n = handle_papersize_command(optarg); - if (n < 0) - error("unknown paper size `%1'", optarg); - else - papersize = n; + const char *s; + double unscaled_paperlength; + double unscaled_paperwidth; + if (!font::scan_papersize(optarg, s, + &unscaled_paperlength, + &unscaled_paperwidth)) + error("invalid paper size `%1' ignored", + optarg); + else { + papersize = set_papersize(s); + paperlength = (short int) + (unscaled_paperlength + * font::res + 0.5); + paperwidth = (short int) + (unscaled_paperwidth + * font::res + 0.5); + } break; }; case 'l' : orientation = 1; diff --git a/src/devices/grops/TODO b/src/devices/grops/TODO index da67973a..7ab3b698 100644 --- a/src/devices/grops/TODO +++ b/src/devices/grops/TODO @@ -6,9 +6,6 @@ Generate %%For comment. Generate %%Title comment. -For efficiency it might be better to have the printer interface have -support for the t and u commands. - Angles in arc command: don't generate more digits after the decimal point than are necessary. diff --git a/src/devices/grops/grops.man b/src/devices/grops/grops.man index b8b65ec4..e3a49f1f 100644 --- a/src/devices/grops/grops.man +++ b/src/devices/grops/grops.man @@ -42,16 +42,17 @@ grops \- PostScript driver for groff .B grops . .de OP -.ie \\n(.$-1 .RI "[\ \fB\\$1\fP" "\\$2" "\ ]" +.ie \\n(.$-1 .RI "[\ \fB\\$1\fP" "\%\\$2" "\ ]" .el .RB "[\ " "\\$1" "\ ]" .. . .OP \-glmv .OP \-b n .OP \-c n -.OP \-w n .OP \-F dir +.OP \-p papersize .OP \-P prologue +.OP \-w n .RI "[\ " files\|.\|.\|. "\ ]" .br .ad \na @@ -175,6 +176,15 @@ Print copies of each page. . .TP +.BI \-F dir +Prepend directory +.IB dir /dev name +to the search path for prologue, font, and device description files; +.I name +is the name of the device, usually +.BR ps . +. +.TP .BI \-g Guess the page length. . @@ -195,13 +205,18 @@ Print the document in landscape format. Turn manual feed on for the document. . .TP -.BI \-F dir -Prepend directory -.IB dir /dev name -to the search path for prologue, font, and device description files; -.I name -is the name of the device, usually -.BR ps . +.BI \-p paper-size +Set physical dimension of output medium. +. +This overrides the +.B papersize +and +.B paperlength +commands in the +.B DESC +file; it accepts the same arguments as the +.B papersize +command. . .TP .BI \-P prologue-file @@ -816,6 +831,16 @@ printing on a page whose length is .IR n \~\c machine units. . +Common values are 792000 for letter paper and 841890 for paper in A4 format. +. +Alternatively, it can contain +.IP +.BI papersize\ string +.LP +to specify a paper size; see +.BR groff_font (@MAN5EXT@) +for more information. +. Each font description file must contain a command .IP .BI internalname\ psname @@ -881,7 +906,7 @@ this should consist of lines of the form . .IP .I -font filename +font filename . .LP where diff --git a/src/devices/grops/ps.cc b/src/devices/grops/ps.cc index 07aa8ae3..b70e62bd 100644 --- a/src/devices/grops/ps.cc +++ b/src/devices/grops/ps.cc @@ -23,6 +23,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "stringclass.h" #include "cset.h" #include "nonposix.h" +#include "paper.h" #include "ps.h" #include <time.h> @@ -42,6 +43,7 @@ static int linewidth = -1; // Non-zero means generate PostScript code that guesses the paper // length using the imageable area. static int guess_flag = 0; +static double user_paper_length = 0; // Non-zero if -b was specified on the command line. static int bflag = 0; @@ -532,7 +534,7 @@ class ps_printer : public printer { void set_color(color *c, int fill = 0); public: - ps_printer(); + ps_printer(double); ~ps_printer(); void set_char(int i, font *f, const environment *env, int w, const char *name); void draw(int code, int *p, int np, const environment *env); @@ -543,7 +545,8 @@ public: void end_of_line(); }; -ps_printer::ps_printer() +// `pl' is in inches +ps_printer::ps_printer(double pl) : out(0, MAX_LINE_LENGTH), pages_output(0), sbuf_len(0), @@ -574,9 +577,12 @@ ps_printer::ps_printer() res = r; out.set_fixed_point(point); space_char_index = font::name_to_index("space"); - paper_length = font::paperlength; + if (pl == 0) + paper_length = font::paperlength; + else + paper_length = int(pl * font::res + 0.5); if (paper_length == 0) - paper_length = 11*font::res; + paper_length = 11 * font::res; equalise_spaces = font::res >= 72000; } @@ -1538,7 +1544,7 @@ void ps_printer::do_endinvis(char *, const environment *) printer *make_printer() { - return new ps_printer; + return new ps_printer(user_paper_length); } static void usage(FILE *stream); @@ -1555,12 +1561,13 @@ int main(int argc, char **argv) { "version", no_argument, 0, 'v' }, { NULL, 0, 0, 0 } }; - while ((c = getopt_long(argc, argv, "F:P:glmc:w:vb:", long_options, NULL)) + while ((c = getopt_long(argc, argv, "b:c:F:glmp:P:vw:", long_options, NULL)) != EOF) switch(c) { - case 'v': - printf("GNU grops (groff) version %s\n", Version_string); - exit(0); + case 'b': + // XXX check this + broken_flags = atoi(optarg); + bflag = 1; break; case 'c': if (sscanf(optarg, "%d", &ncopies) != 1 || ncopies <= 0) { @@ -1568,6 +1575,9 @@ int main(int argc, char **argv) ncopies = 1; } break; + case 'F': + font::command_line_font_dir(optarg); + break; case 'g': guess_flag = 1; break; @@ -1577,8 +1587,9 @@ int main(int argc, char **argv) case 'm': manual_feed_flag = 1; break; - case 'F': - font::command_line_font_dir(optarg); + case 'p': + if (!font::scan_papersize(optarg, 0, &user_paper_length, 0)) + error("invalid custom paper size `%1' ignored", optarg); break; case 'P': env = "GROPS_PROLOGUE"; @@ -1588,17 +1599,16 @@ int main(int argc, char **argv) if (putenv(strsave(env.contents()))) fatal("putenv failed"); break; + case 'v': + printf("GNU grops (groff) version %s\n", Version_string); + exit(0); + break; case 'w': if (sscanf(optarg, "%d", &linewidth) != 1 || linewidth < 0) { error("bad linewidth `%1'", optarg); linewidth = -1; } break; - case 'b': - // XXX check this - broken_flags = atoi(optarg); - bflag = 1; - break; case CHAR_MAX + 1: // --help usage(stdout); exit(0); diff --git a/src/include/font.h b/src/include/font.h index 099f97be..6faf2626 100644 --- a/src/include/font.h +++ b/src/include/font.h @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -54,6 +54,8 @@ public: const char *get_name(); const char *get_internal_name(); + static int scan_papersize(const char *, const char *, double *, double *); + static font *load_font(const char *, int *not_found = 0); static void command_line_font_dir(const char *path); static FILE *open_file(const char *name, char **pathp); @@ -69,6 +71,7 @@ public: static int unitwidth; static int paperwidth; static int paperlength; + static const char *papersize; static int biggestfont; static int spare2; static int sizescale; @@ -107,6 +110,7 @@ private: void compact(); static int scale(int w, int pointsize); + static int unit_scale(double *value, char unit); virtual void handle_unknown_font_command(const char *command, const char *arg, const char *file, int lineno); diff --git a/src/include/paper.h b/src/include/paper.h new file mode 100644 index 00000000..380cda70 --- /dev/null +++ b/src/include/paper.h @@ -0,0 +1,37 @@ +// -*- C++ -*- +/* Copyright (C) 2002 Free Software Foundation, Inc. + Written by Werner Lemberg (wl@gnu.org) + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with groff; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +struct paper { + char *name; + double length; // in PS points + double width; // in PS points +}; + +// global constructor +static class papersize_init { + static int initialised; +public: + papersize_init(); +} _papersize_init; + +// A0-A7, B0-B7, C0-C7, D0-D7, 6 American paper sizes */ +#define NUM_PAPERSIZES 4 * 8 + 6 + +extern paper papersizes[]; diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub index d7a81e91..a62e7fbd 100644 --- a/src/libs/libgroff/Makefile.sub +++ b/src/libs/libgroff/Makefile.sub @@ -24,6 +24,7 @@ OBJS=\ mksdir.o \ nametoindex.o \ new.o \ + paper.o \ prime.o \ progname.o \ ptable.o \ @@ -61,6 +62,7 @@ CCSRCS=\ $(srcdir)/mkstemp.cc \ $(srcdir)/nametoindex.cc \ $(srcdir)/new.cc \ + $(srcdir)/paper.cc \ $(srcdir)/prime.cc \ $(srcdir)/progname.cc \ $(srcdir)/ptable.cc \ diff --git a/src/libs/libgroff/font.cc b/src/libs/libgroff/font.cc index e97e4b2c..122b3e3d 100644 --- a/src/libs/libgroff/font.cc +++ b/src/libs/libgroff/font.cc @@ -29,6 +29,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "error.h" #include "cset.h" #include "font.h" +#include "paper.h" const char *const WS = " \t\n\r"; @@ -207,6 +208,34 @@ inline int font::scale(int w, int sz) return sz == unitwidth ? w : scale_round(w, sz, unitwidth); } +int font::unit_scale(double *value, char unit) +{ + // we scale everything to inch + double divisor = 0; + switch (unit) { + case 'i': + divisor = 1; + break; + case 'p': + divisor = 72; + break; + case 'P': + divisor = 6; + break; + case 'c': + divisor = 2.54; + break; + default: + assert(0); + break; + } + if (divisor) { + *value /= divisor; + return 1; + } + return 0; +} + int font::get_skew(int c, int point_size, int sl) { int h = get_height(c, point_size); @@ -473,6 +502,58 @@ static char *trim_arg(char *p) return p; } +int font::scan_papersize(const char *p, + const char *size, double *length, double *width) +{ + double l, w; + char lu[2], wu[2]; + const char *pp = p; + int test_file = 1; + char line[255]; +again: + if (csdigit(*pp)) { + if (sscanf(pp, "%lf%1[ipPc],%lf%1[ipPc]", &l, lu, &w, wu) == 4 + && l > 0 && w > 0 + && unit_scale(&l, lu[0]) && unit_scale(&w, wu[0])) { + if (length) + *length = l; + if (width) + *width = w; + if (size) + size = "custom"; + return 1; + } + } + else { + int i; + for (i = 0; i < NUM_PAPERSIZES; i++) + if (strcasecmp(papersizes[i].name, pp) == 0) { + if (length) + *length = papersizes[i].length; + if (width) + *width = papersizes[i].width; + if (size) + size = papersizes[i].name; + return 1; + } + if (test_file) { + FILE *f = fopen(p, "r"); + if (f) { + fgets(line, 254, f); + fclose(f); + test_file = 0; + char *linep = line; + // skip final newline, if any + if (*(--linep) == '\n') + *linep = '\0'; + pp = line; + goto again; + } + } + } + return 0; +} + // If the font can't be found, then if not_found is non-NULL, it will be set // to 1 otherwise a message will be printed. @@ -732,9 +813,9 @@ static struct { { "sizescale", &font::sizescale } }; - int font::load_desc() { + double unscaled_paperwidth, unscaled_paperlength; int nfonts = 0; FILE *fp; char *path; @@ -765,15 +846,6 @@ int font::load_desc() return 0; } } - else if (strcmp("tcommand", p) == 0) { - tcommand = 1; - } - else if (strcmp("pass_filenames", p) == 0) { - pass_filenames = 1; - } - else if (strcmp("use_charnames_in_special", p) == 0) { - use_charnames_in_special = 1; - } else if (strcmp("family", p) == 0) { p = strtok(0, WS); if (!p) { @@ -811,6 +883,20 @@ int font::load_desc() } font_name_table[nfonts] = 0; } + else if (strcmp("papersize", p) == 0) { + p = strtok(0, WS); + if (!p) { + t.error("papersize command requires an argument"); + return 0; + } + if (!scan_papersize(p, papersize, &unscaled_paperlength, + &unscaled_paperwidth)) { + t.error("bad paper size"); + return 0; + } + } + else if (strcmp("pass_filenames", p) == 0) + pass_filenames = 1; else if (strcmp("sizes", p) == 0) { int n = 16; sizes = new int[n]; @@ -881,6 +967,10 @@ int font::load_desc() style_table[i++] = tem; } } + else if (strcmp("tcommand", p) == 0) + tcommand = 1; + else if (strcmp("use_charnames_in_special", p) == 0) + use_charnames_in_special = 1; else if (strcmp("charset", p) == 0) break; else if (unknown_desc_command_handler) { @@ -917,6 +1007,8 @@ int font::load_desc() t.error("bad `vert' value"); return 0; } + paperwidth = int(unscaled_paperwidth * res + 0.5); + paperlength = int(unscaled_paperlength * res + 0.5); return 1; } diff --git a/src/libs/libgroff/fontfile.cc b/src/libs/libgroff/fontfile.cc index 659cd7d1..8502d12f 100644 --- a/src/libs/libgroff/fontfile.cc +++ b/src/libs/libgroff/fontfile.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -39,6 +39,7 @@ int font::vert = 1; int font::unitwidth = 0; int font::paperwidth = 0; int font::paperlength = 0; +const char *font::papersize = 0; int font::biggestfont = 0; int font::spare2 = 0; int font::sizescale = 1; diff --git a/src/libs/libgroff/paper.cc b/src/libs/libgroff/paper.cc new file mode 100644 index 00000000..22570141 --- /dev/null +++ b/src/libs/libgroff/paper.cc @@ -0,0 +1,79 @@ +// -*- C++ -*- +/* Copyright (C) 2002 + Free Software Foundation, Inc. + Written by Werner Lemberg (wl@gnu.org) + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with groff; see the file COPYING. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#include "lib.h" +#include "paper.h" + +paper papersizes[NUM_PAPERSIZES]; + +// length and width in mm +static void add_iso_paper(char series, int offset, + int start_length, int start_width) +{ + int length = start_length; + int width = start_width; + for (int i = 0; i < 8; i++) + { + char *p = new char[3]; + p[0] = series; + p[1] = '0' + i; + p[2] = '\0'; + papersizes[offset + i].name = p; + // convert mm to inch + papersizes[offset + i].length = (double)length / 25.4; + papersizes[offset + i].width = (double)width / 25.4; + // after division by two, values must be rounded down to the next + // integer (as specified by ISO) + int tmp = width; + width = length; + length = tmp / 2; + } +} + +// length and width in inch +static void add_american_paper(const char *name, int index, + double length, double width ) +{ + char *p = new char[strlen(name) + 1]; + strcpy(p, name); + papersizes[index].name = p; + papersizes[index].length = length; + papersizes[index].width = width; +} + +int papersize_init::initialised = 0; + +papersize_init::papersize_init() +{ + if (initialised) + return; + initialised = 1; + add_iso_paper('a', 0, 1189, 841); + add_iso_paper('b', 8, 1414, 1000); + add_iso_paper('c', 16, 1297, 917); + add_iso_paper('d', 24, 1090, 771); + add_american_paper("letter", 32, 11, 8.5); + add_american_paper("legal", 33, 14, 8.5); + add_american_paper("tabloid", 34, 17, 11); + add_american_paper("ledger", 35, 11, 17); + add_american_paper("statement", 36, 8.5, 5.5); + add_american_paper("executive", 37, 10, 7.5); +} |