lishka@uwslh.slh.wisc.edu (Chris Lishka (relaxing in the Mad-City) ) (07/03/90)
Posting-number: Volume 13, Issue 96 Submitted-by: lishka@uwslh.slh.wisc.edu (Chris Lishka (relaxing in the Mad-City) ) Archive-name: lj2ps/part11 ---- Cut Here and unpack ---- #!/bin/sh # This is part 11 of a multipart archive if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= ljfonts.c ============== if test X"$1" != X"-c" -a -f 'ljfonts.c'; then echo "File already exists: skipping 'ljfonts.c'" else echo "x - extracting ljfonts.c (Text)" sed 's/^X//' << 'SHAR_EOF' > ljfonts.c && X/* Project: lj2ps X** File: ljfonts.c X** X** Author: Christopher Lishka X** Organization: Wisconsin State Laboratory of Hygiene X** Data Processing Dept. X** X** Copyright (C) 1990 by Christopher Lishka. X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X*/ X Xstatic char * ModuleID = "Module ljfonts: v1.0, production"; X X /* Include files X */ X#include <strings.h> X#include "ljfonts.h" X#include "lj.h" X X /* External definitions X */ X X /* Global variables X */ X X /* Global function list X */ Xextern void lj_match_font(); /* Get a font (closest match) */ Xextern int lj_find_font(); /* Find font based on the name */ X X /* Local constants X */ X#define MAX_BUFFER 2048 X /* LJ_FONT_ERROR is used to determine if real number attributes (e.g. pitch) X ** are the same. 0.1 is currently used because otherwise 16.6 does not match X ** with 16.66. I have no idea how the LaserJet resolves this problem. - C.L. X */ X#define LJ_FONT_ERROR 0.1 X /* Font attribute priority values */ X#define FAP_ORIENTATION 1024 /* Orientation: landscape/portrait */ X#define FAP_SYM_SET 512 /* Symbol set */ X#define FAP_SPACING 256 /* Spacing: proportional/fixed */ X#define FAP_PITCH 128 /* Pitch (in chars per inch) */ X#define FAP_HEIGHT 64 /* Font height (in points) */ X#define FAP_STYLE 32 /* Style: normal/italic */ X#define FAP_STROKE 16 /* Stroke: -3(light) to 0(normal) to 3(bold) */ X#define FAP_TYPEFACE 8 /* Typeface */ X#define FAP_SOURCE_SOFT 4 /* Source: downloadable "soft" font */ X#define FAP_SOURCE_CART 2 /* Source: cartridge font */ X#define FAP_SOURCE_INT 1 /* Source: internal font */ X X /* Local structures and types X */ Xtypedef struct { X /* Identifier fields */ X int source; /* Font source: where the font is located */ X int number; /* Font number */ X /* Scaling fields */ X int scale; /* True if scaling should be performed */ X double scale_x; /* % to scale in x direction */ X double scale_y; /* % to scale in y direction */ X /* LaserJet font ID fields */ X int symbol_set; /* The symbol set of the font */ X int spacing; /* Proportional/fixed */ X double pitch; /* Pitch of fixed or space character */ X double point_size; /* Height of the character */ X int style; /* Upright/italic */ X int weight; /* Stroke weight: -3 to +3 */ X int typeface; /* Which typeface to use */ X char *ps_name; /* The postscript font used for emulation */ X} font_node; X X /* Local variables X */ X /* The table of LaserJet fonts, and the LaserWriter equivalents. X ** X ** Note: the fonts must be listed in priority order, from most important X ** to least important. X ** X ** Note: the pitch value for proportional fonts is the width of the space X ** character. X */ X/*DBX: static */ font_node lj_fonts[] = { X X /* X ** Left slot: HP F Font Cartridge X */ X X /* L00 (TMS-10): Times-Roman 8U prop. 10pt. upright normal */ X { LJ_FS_LEFT, 0, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_UPRIGHT, 0, LJ_TF_TIMES, X "Times-Roman" }, X X /* L01 (TMS-10): Times-Roman 0U prop. 10pt. upright normal */ X { LJ_FS_LEFT, 1, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_UPRIGHT, 0, LJ_TF_TIMES, X "Times-Roman" }, X X /* L02 (TMS-B-10): Times-Roman 0U prop. 10pt. upright bold */ X { LJ_FS_LEFT, 2, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_UPRIGHT, 3, LJ_TF_TIMES, X "Times-Bold" }, X X /* L03 (TMS-B-10): Times-Roman 8U prop. 10pt. upright bold */ X { LJ_FS_LEFT, 3, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_UPRIGHT, 3, LJ_TF_TIMES, X "Times-Bold" }, X X /* L04 (TMS-I-10): Times-Roman 0U prop. 10pt. italic normal */ X { LJ_FS_LEFT, 4, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_ITALIC, 0, LJ_TF_TIMES, X "Times-Italic" }, X X /* L05 (TMS-I-10): Times-Roman 8U prop. 10pt. italic normal */ X { LJ_FS_LEFT, 5, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_PROPORTIONAL, 17.7, 10.0, LJ_ST_ITALIC, 0, LJ_TF_TIMES, X "Times-Italic" }, X X /* L06 (HELV-B-14.4): Helvetica 0U prop. 14.4pt. upright bold */ X { LJ_FS_LEFT, 6, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_PROPORTIONAL, 15.0, 14.4, LJ_ST_UPRIGHT, 3, LJ_TF_HELV, X "Helvetica-Bold" }, X X /* L07 (HELV-B-14.4): Helvetica 8U prop. 14.4pt. upright bold */ X { LJ_FS_LEFT, 7, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_PROPORTIONAL, 15.0, 14.4, LJ_ST_UPRIGHT, 3, LJ_TF_HELV, X "Helvetica-Bold" }, X X /* L08 (TMS-8): Times-Roman 0U prop. 8pt. upright normal */ X { LJ_FS_LEFT, 8, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_PROPORTIONAL, 27.4, 8.0, LJ_ST_UPRIGHT, 0, LJ_TF_TIMES, X "Times-Roman" }, X X /* L09 (TMS-8): Times-Roman 8U prop. 8pt. upright normal */ X { LJ_FS_LEFT, 9, 0, 1.20, 1.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_PROPORTIONAL, 27.4, 8.0, LJ_ST_UPRIGHT, 0, LJ_TF_TIMES, X "Times-Roman" }, X X /* L10 (LP-8.5): Line-Printer 0U 16.6pitch 8.5pt upright normal */ X { LJ_FS_LEFT, 10, 1, 0.845, 1.00, /* Scaling *****ON***** */ X LJ_SS_0N, LJ_SP_FIXED, 16.67, 8.5, LJ_ST_UPRIGHT, 0, LJ_TF_LP, X "Courier" }, X X /* L11 (LP-8.5): Line-Printer 8U 16.6pitch 8.5pt upright normal */ X { LJ_FS_LEFT, 11, 1, 0.845, 1.00, /* Scaling *****ON***** */ X LJ_SS_8U, LJ_SP_FIXED, 16.67, 8.5, LJ_ST_UPRIGHT, 0, LJ_TF_LP, X "Courier" }, X X /* X ** Right slot: HP G Font Cartridge X */ X X /* R00 (PRES-10): Prestige 0U 12pitch 10pt. upright normal */ X { LJ_FS_RIGHT, 0, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_UPRIGHT, 0, LJ_TF_PRES, X "Courier" }, X X /* R01 (PRES-10): Prestige 1U 12pitch 10pt. upright normal */ X { LJ_FS_RIGHT, 1, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_1U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_UPRIGHT, 0, LJ_TF_PRES, X "Courier" }, X X /* R02 (PRES-B-10): Prestige 1U 12pitch 10pt. upright bold */ X { LJ_FS_RIGHT, 2, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_1U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_UPRIGHT, 3, LJ_TF_PRES, X "Courier-Bold" }, X X /* R03 (PRES-B-10): Prestige 0U 12pitch 10pt. upright bold */ X { LJ_FS_RIGHT, 3, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_UPRIGHT, 3, LJ_TF_PRES, X "Courier-Bold" }, X X /* R04 (PRES-I-10): Prestige 1U 12pitch 10pt. italic normal */ X { LJ_FS_RIGHT, 4, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_1U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_ITALIC, 0, LJ_TF_PRES, X "Courier-Oblique" }, X X /* R05 (PRES-I-10): Prestige 0U 12pitch 10pt. italic normal */ X { LJ_FS_RIGHT, 5, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_FIXED, 12.0, 10.0, LJ_ST_ITALIC, 0, LJ_TF_PRES, X "Courier-Oblique" }, X X /* R06 (PRES-7): Prestige 1U 16.6pitch 7pt. upright normal */ X { LJ_FS_RIGHT, 6, 1, 1.03, 1.00, /* Note: scaling is OFF */ X LJ_SS_1U, LJ_SP_FIXED, 16.67, 7.0, LJ_ST_UPRIGHT, 0, LJ_TF_PRES, X "Courier" }, X X /* R07 (PRES-7): Prestige 0U 16.6pitch 7pt. upright normal */ X { LJ_FS_RIGHT, 7, 1, 1.03, 1.00, /* Note: scaling is OFF */ X LJ_SS_0U, LJ_SP_FIXED, 16.67, 7.0, LJ_ST_UPRIGHT, 0, LJ_TF_PRES, X "Courier" }, X X /* R08: Line Draw is NOT AVAILABLE */ X/* "DRAW-12", "Line-Draw 12 point 12 pitch",*/ X/* Line draw is not supported! */ X X /* X ** LaserJet II Internal Fonts X */ X X /* I00 (COUR-12): Courier 8U 10pitch 12pt. upright normal */ X { LJ_FS_INTERNAL, 0, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 0, LJ_TF_COUR, X "Courier" }, X X /* I01 (COUR-12): Courier 10U 10pitch 12pt. upright normal */ X { LJ_FS_INTERNAL, 1, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_10U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 0, LJ_TF_COUR, X "Courier" }, X X /* I02 (COUR-12): Courier 11U 10pitch 12pt. upright normal */ X { LJ_FS_INTERNAL, 2, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_11U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 0, LJ_TF_COUR, X "Courier" }, X X /* I03 (COUR-12): Courier 0N 10pitch 12pt. upright normal */ X { LJ_FS_INTERNAL, 3, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0N, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 0, LJ_TF_COUR, X "Courier" }, X X /* I04 (COUR-B-12): Courier 8U 10pitch 12pt. upright bold */ X { LJ_FS_INTERNAL, 4, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_8U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 3, LJ_TF_COUR, X "Courier-Bold" }, X X /* I05 (COUR-B-12): Courier 10U 10pitch 12pt. upright bold */ X { LJ_FS_INTERNAL, 5, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_10U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 3, LJ_TF_COUR, X "Courier-Bold" }, X X /* I06 (COUR-B-12): Courier 11U 10pitch 12pt. upright bold */ X { LJ_FS_INTERNAL, 6, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_11U, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 3, LJ_TF_COUR, X "Courier-Bold" }, X X /* I07 (COUR-B-12): Courier 0N 10pitch 12pt. upright bold */ X { LJ_FS_INTERNAL, 7, 0, 0.00, 0.00, /* Note: scaling is OFF */ X LJ_SS_0N, LJ_SP_FIXED, 10.0, 12.0, LJ_ST_UPRIGHT, 3, LJ_TF_COUR, X "Courier-Bold" }, X X /* I08 (LP-8.5): Line-Printer 8U 16.6pitch 8.5pt. upright normal */ X { LJ_FS_INTERNAL, 8, 1, 0.845, 1.00, /* Scaling *****ON***** */ X LJ_SS_8U, LJ_SP_FIXED, 16.67, 8.5, LJ_ST_UPRIGHT, 0, LJ_TF_LP, X "Courier" }, X X /* I09 (LP-8.5): Line-Printer 10U 16.6pitch 8.5pt. upright normal */ X { LJ_FS_INTERNAL, 9, 1, 0.845, 1.00, /* Scaling *****ON***** */ X LJ_SS_10U, LJ_SP_FIXED, 16.67, 8.5, LJ_ST_UPRIGHT, 0, LJ_TF_LP, X "Courier" }, X X /* Last entry must be nulled out! */ X { 0, 0, 0, 0.00, 0.00, X 0, 0, 0.0, 0.0, 0, 0, 0, X "" } X}; X X /* Local macro definitions X */ X X /* Local function list X */ X X /* Function bodies X */ X X /* lj_get_font() returns in the argument font the closest match to the X ** requested font. The match *never* fails. X ** X ** "Closest match" is defined as the first font in the X ** list for which the attributes match. The attributes are in the X ** following priority order: X ** X ** (1) Orientation (always correct because PS has arbitrary rotation) X ** (2) Symbol set (once again, ignored here!) X ** (3) Spacing X ** (4) Pitch (ignored if the font is proportional) X ** (5) Height X ** (6) Style X ** (7) Stroke weight X ** (8) Typeface X ** (9) Soft font (ignored) X ** (10) Cartridge font (ignored) X ** (11) Internal font (ignored) X ** X ** Priority schemes based on the source of the font (i.e. soft fonts, X ** cartridge fonts, or internal fonts) are ignored. These can be X ** duplicated through careful ordering of the list. X */ Xvoid Xlj_match_font(font) X ljfont *font; X{ X int match_font; /* Highest matched font so far */ X int match_value; /* Highest matched value so far */ X int curr_value; /* The current font being tested */ X int curr_font; /* The match value for the current font */ X double tmp_double; /* Temporary value */ X X curr_font = 0; X match_font = curr_font; X match_value = 0; X do{ X curr_value = 0; X X /* Match the attributes */ X /* Orientation: *always* matches, because PS allows arbitrary rotation */ X curr_value += FAP_ORIENTATION; X /* Symbol set */ X if( font->symbol_set == lj_fonts[curr_font].symbol_set ){ X curr_value += FAP_SYM_SET; X } X /* Spacing: match to two decimal places */ X if( font->spacing == lj_fonts[curr_font].spacing ){ X curr_value += FAP_SPACING; X } X /* Pitch: ignore if proportional spacing */ X if( font->spacing == LJ_SP_FIXED ){ X tmp_double = font->pitch - lj_fonts[curr_font].pitch; X if( (-(LJ_FONT_ERROR) <= tmp_double) && (tmp_double <= LJ_FONT_ERROR) ){ X curr_value += FAP_PITCH; X } X } X /* Height */ X tmp_double = font->point_size - lj_fonts[curr_font].point_size; X if( (-(LJ_FONT_ERROR) <= tmp_double) && (tmp_double <= LJ_FONT_ERROR) ){ X curr_value += FAP_HEIGHT; X } X /* Style: exact match needed */ X if( font->style == lj_fonts[curr_font].style ){ X curr_value += FAP_STYLE; X } X /* Stroke weight: exact match needed */ X if( font->weight == lj_fonts[curr_font].weight ){ X curr_value += FAP_STROKE; X } X /* Typeface: exact match needed */ X if( font->typeface == lj_fonts[curr_font].typeface ){ X curr_value += FAP_TYPEFACE; X } X /* Source soft font: ignored */ X /* Source cartridge font: ignored */ X /* Source internal font: ignored */ X X /* Check to see if we currently have a better match */ X if( curr_value > match_value ){ X match_value = curr_value; X match_font = curr_font; X } X X curr_font++; X } while( (lj_fonts[curr_font].ps_name[0] != '\0') ); X X /* There had *better* be a matched font in match_font by this point. X ** If none of the attributes matched, match_font should at least hold X ** the default. X */ X X /* OK. Now copy over *everything* */ X font->scale = lj_fonts[match_font].scale; X font->scale_x = lj_fonts[match_font].scale_x; X font->scale_y = lj_fonts[match_font].scale_y; X font->symbol_set = lj_fonts[match_font].symbol_set; X font->spacing = lj_fonts[match_font].spacing; X if( font->spacing == LJ_SP_FIXED ){ X font->pitch = lj_fonts[match_font].pitch; X } X font->point_size = lj_fonts[match_font].point_size; X font->style = lj_fonts[match_font].style; X font->weight = lj_fonts[match_font].weight; X font->typeface = lj_fonts[match_font].typeface; X (void) strcpy(font->ps_name, lj_fonts[match_font].ps_name); X font->width = 1/(lj_fonts[match_font].pitch); X X} /* lj_match_font() */ X X X X /* lj_find_font() finds a font based on the name. A 0 is returned X ** if the search is successful, 1 otherwise. X */ Xint Xlj_find_font(source, number, font) X int source, number; ljfont *font; X{ X int found; X int counter; X X found = 0; X for( counter = 0; X !found && !(lj_fonts[counter].source == 0); X counter++ ){ X if( (source == lj_fonts[counter].source) X && (number == lj_fonts[counter].number) ){ X found = 1; X font->scale = lj_fonts[counter].scale; X font->scale_x = lj_fonts[counter].scale_x; X font->scale_y = lj_fonts[counter].scale_y; X font->symbol_set = lj_fonts[counter].symbol_set; X font->spacing = lj_fonts[counter].spacing; X if( font->spacing == LJ_SP_FIXED ){ X font->pitch = lj_fonts[counter].pitch; X } X font->point_size = lj_fonts[counter].point_size; X font->style = lj_fonts[counter].style; X font->weight = lj_fonts[counter].weight; X font->typeface = lj_fonts[counter].typeface; X (void) strcpy(font->ps_name, lj_fonts[counter].ps_name); X font->width = 1/(lj_fonts[counter].pitch); X } /* if */ X } /* for */ X X return( !found ); X} /* lj_find_font() */ SHAR_EOF $TOUCH -am 0630160790 ljfonts.c && chmod 0644 ljfonts.c || echo "restore of ljfonts.c failed" set `wc -c ljfonts.c`;Wc_c=$1 if test "$Wc_c" != "16148"; then echo original size 16148, current size $Wc_c fi fi # ============= ljfonts.h ============== if test X"$1" != X"-c" -a -f 'ljfonts.h'; then echo "File already exists: skipping 'ljfonts.h'" else echo "x - extracting ljfonts.h (Text)" sed 's/^X//' << 'SHAR_EOF' > ljfonts.h && X/* X** Project: lj2ps X** File: ljfonts.h X** X** Author: Christopher Lishka X** Organization: Wisconsin State Laboratory of Hygiene X** Data Processing Dept. X** X** Copyright (C) 1990 by Christopher Lishka. X** X** This program is free software; you can redistribute it and/or modify X** it under the terms of the GNU General Public License as published by X** the Free Software Foundation; either version 1, or (at your option) X** any later version. X** X** This program is distributed in the hope that it will be useful, X** but WITHOUT ANY WARRANTY; without even the implied warranty of X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X** GNU General Public License for more details. X** X** You should have received a copy of the GNU General Public License X** along with this program; if not, write to the Free Software X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. X*/ X X#ifndef LJFONTS_H X#define LJFONTS_H X X#include "lj.h" X X /* Global constants X */ X X /* Global structure and type definitions X */ X X /* Global variables X */ X X /* Global macro definitions X */ X X /* Global functions X */ Xextern void lj_match_font(); /* Get closest match for a laserjet font */ Xextern int lj_find_font(); /* Find font based on name */ X X#endif SHAR_EOF $TOUCH -am 0630160790 ljfonts.h && chmod 0644 ljfonts.h || echo "restore of ljfonts.h failed" set `wc -c ljfonts.h`;Wc_c=$1 if test "$Wc_c" != "1258"; then echo original size 1258, current size $Wc_c fi fi echo "End of part 11, continue with part 12" exit 0