Comparar commits
1 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 11236b767a |
+7
-7
@@ -1,4 +1,4 @@
|
||||
README - CUPS v1.0b8 - 08/31/1999
|
||||
README - CUPS v1.0b6 - 07/30/1999
|
||||
---------------------------------
|
||||
|
||||
BETA SOFTWARE BETA SOFTWARE BETA SOFTWARE BETA SOFTWARE BETA SOFTWARE
|
||||
@@ -57,7 +57,7 @@ the binary distributions from Easy Software Products:
|
||||
- Digital UNIX (aka OSF1 aka Compaq Tru64 UNIX) 4.0 or higher
|
||||
- HP-UX 10.20 or higher
|
||||
- IRIX 5.3 or higher
|
||||
- Linux 2.0 with glibc2 or higher (tested with RedHat 5.2)
|
||||
- Linux 2.0.36 with glibc2 or higher (tested with RedHat 5.2)
|
||||
- Solaris 2.5 or higher (SPARC or Intel)
|
||||
|
||||
|
||||
@@ -124,11 +124,6 @@ Similarly, for the sample LaserJet driver you can use "LaserJet" and
|
||||
For other printers and interfaces see the CUPS System Administator's
|
||||
Manual included with this software.
|
||||
|
||||
If you're interested in a complete, commercial printing solution for
|
||||
UNIX, check out our ESP Print Pro software at:
|
||||
|
||||
http://www.easysw.com/printpro
|
||||
|
||||
|
||||
PRINTING FILES
|
||||
|
||||
@@ -193,3 +188,8 @@ licensing information, please contact:
|
||||
Voice: +1.301.373.9603
|
||||
Email: cups-info@cups.org
|
||||
WWW: http://www.cups.org
|
||||
|
||||
If you're interested in a complete, commercial printing solution for
|
||||
UNIX, check out our ESP Print Pro software at:
|
||||
|
||||
http://www.easysw.com/printpro
|
||||
|
||||
+8
-6
@@ -294,12 +294,12 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
|
||||
*/
|
||||
|
||||
if (httpPost(http, resource))
|
||||
{
|
||||
fputs("INFO: Unable to POST print request; retrying...\n", stderr);
|
||||
sleep(10);
|
||||
httpReconnect(http);
|
||||
continue;
|
||||
}
|
||||
if (httpPost(http, resource))
|
||||
{
|
||||
fputs("INFO: Unable to POST print request; retrying...\n", stderr);
|
||||
sleep(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
fputs("INFO: POST successful, sending IPP request...\n", stderr);
|
||||
|
||||
@@ -336,6 +336,8 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
|
||||
}
|
||||
}
|
||||
|
||||
httpWrite(http, buffer, 0);
|
||||
|
||||
fputs("INFO: Print file sent; checking status...\n", stderr);
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
|
||||
int bytes; /* Number of bytes read */
|
||||
|
||||
|
||||
if ((fp = fopen(cupsTempFile(filename, sizeof(filename)), "w")) == NULL)
|
||||
if ((fp = fopen(tmpnam(filename), "w")) == NULL)
|
||||
{
|
||||
perror("ERROR: unable to create temporary file");
|
||||
return (1);
|
||||
|
||||
+1
-3
@@ -209,7 +209,7 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
return (1);
|
||||
}
|
||||
|
||||
temp = fopen(cupsTempFile(tempfile, sizeof(tempfile)), "w");
|
||||
temp = fopen(tmpnam(tempfile), "w");
|
||||
|
||||
if (temp == NULL)
|
||||
{
|
||||
@@ -234,8 +234,6 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
else
|
||||
job_id = cupsPrintFile(dest, tempfile, "(stdin)", num_options, options);
|
||||
|
||||
unlink(tempfile);
|
||||
|
||||
if (job_id < 1)
|
||||
{
|
||||
fputs("lpr: unable to print standard input.\n", stderr);
|
||||
|
||||
@@ -107,23 +107,14 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"95,10,175,30\" HREF=\"/classes\" ALT=\"Current Printer Classes Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"185,10,235,30\" HREF=\"/jobs\" ALT=\"Current Jobs Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"245,10,395,30\" HREF=\"/documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.easysw.com/printpro/software.html\" ALT=\"Download the Current ESP Print Pro Software\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"505,10,585,30\" HREF=\"http://www.easysw.com/printpro/support.html\" ALT=\"Get Tech Support for Current ESP Print Pro\">");
|
||||
#else
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.cups.org\" ALT=\"Download the Current CUPS Software\">");
|
||||
#endif /* ESPPRINTPRO */
|
||||
puts("</MAP>");
|
||||
puts("</HEAD>");
|
||||
puts("<BODY>");
|
||||
puts("<P ALIGN=CENTER>");
|
||||
puts("<A HREF=\"http://www.easysw.com\" ALT=\"Easy Software Products Home Page\">");
|
||||
puts("<IMG SRC=\"/images/logo.gif\" WIDTH=\"71\" HEIGHT=\"40\" BORDER=0 ALT=\"Easy Software Products Home Page\"></A>");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"600\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#else
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"540\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#endif /* ESPPRINTPRO */
|
||||
|
||||
printf("<H1>%s on %s</H1>\n", name == NULL ? "Classes" : name,
|
||||
getenv("SERVER_NAME"));
|
||||
|
||||
+2
-9
@@ -62,6 +62,8 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
http_t *http; /* Connection to the server */
|
||||
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
|
||||
/*
|
||||
* Get the request language...
|
||||
*/
|
||||
@@ -107,23 +109,14 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"95,10,175,30\" HREF=\"/classes\" ALT=\"Current Printer Classes Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"185,10,235,30\" HREF=\"/jobs\" ALT=\"Current Jobs Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"245,10,395,30\" HREF=\"/documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.easysw.com/printpro/software.html\" ALT=\"Download the Current ESP Print Pro Software\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"505,10,585,30\" HREF=\"http://www.easysw.com/printpro/support.html\" ALT=\"Get Tech Support for Current ESP Print Pro\">");
|
||||
#else
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.cups.org\" ALT=\"Download the Current CUPS Software\">");
|
||||
#endif /* ESPPRINTPRO */
|
||||
puts("</MAP>");
|
||||
puts("</HEAD>");
|
||||
puts("<BODY>");
|
||||
puts("<P ALIGN=CENTER>");
|
||||
puts("<A HREF=\"http://www.easysw.com\" ALT=\"Easy Software Products Home Page\">");
|
||||
puts("<IMG SRC=\"/images/logo.gif\" WIDTH=\"71\" HEIGHT=\"40\" BORDER=0 ALT=\"Easy Software Products Home Page\"></A>");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"600\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#else
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"540\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#endif /* ESPPRINTPRO */
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
|
||||
@@ -107,23 +107,14 @@ main(int argc, /* I - Number of command-line arguments */
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"95,10,175,30\" HREF=\"/classes\" ALT=\"Current Printer Classes Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"185,10,235,30\" HREF=\"/jobs\" ALT=\"Current Jobs Status\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"245,10,395,30\" HREF=\"/documentation.html\" ALT=\"Read CUPS Documentation On-Line\">");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.easysw.com/printpro/software.html\" ALT=\"Download the Current ESP Print Pro Software\">");
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"505,10,585,30\" HREF=\"http://www.easysw.com/printpro/support.html\" ALT=\"Get Tech Support for Current ESP Print Pro\">");
|
||||
#else
|
||||
puts("<AREA SHAPE=\"RECT\" COORDS=\"405,10,490,30\" HREF=\"http://www.cups.org\" ALT=\"Download the Current CUPS Software\">");
|
||||
#endif /* ESPPRINTPRO */
|
||||
puts("</MAP>");
|
||||
puts("</HEAD>");
|
||||
puts("<BODY>");
|
||||
puts("<P ALIGN=CENTER>");
|
||||
puts("<A HREF=\"http://www.easysw.com\" ALT=\"Easy Software Products Home Page\">");
|
||||
puts("<IMG SRC=\"/images/logo.gif\" WIDTH=\"71\" HEIGHT=\"40\" BORDER=0 ALT=\"Easy Software Products Home Page\"></A>");
|
||||
#ifdef ESPPRINTPRO
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"600\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#else
|
||||
puts("<IMG SRC=\"/images/navbar.gif\" WIDTH=\"540\" HEIGHT=\"40\" USEMAP=\"#navbar\" BORDER=0>");
|
||||
#endif /* ESPPRINTPRO */
|
||||
|
||||
printf("<H1>%s on %s</H1>\n", printer == NULL ? "Printers" : printer,
|
||||
getenv("SERVER_NAME"));
|
||||
|
||||
+8
-30
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# "$Id: cupsd.conf 628 1999-08-23 15:24:48Z mike $"
|
||||
# "$Id: cupsd.conf 510 1999-07-09 14:20:15Z mike $"
|
||||
#
|
||||
# Sample configuration file for the Common UNIX Printing System (CUPS)
|
||||
# scheduler.
|
||||
@@ -70,25 +70,20 @@ Port 631
|
||||
# program is run...
|
||||
#
|
||||
|
||||
#User lp
|
||||
#Group sys
|
||||
User lp
|
||||
Group sys
|
||||
|
||||
#
|
||||
# SystemGroup: the group name for "System" (printer administration)
|
||||
# access. The default varies depending on the operating system, but
|
||||
# will be "sys", "system", or "root" (checked for in that order.)
|
||||
# access.
|
||||
#
|
||||
|
||||
#SystemGroup sys
|
||||
SystemGroup sys
|
||||
|
||||
#
|
||||
# ServerName: the hostname of your server, as advertised to the world.
|
||||
# By default CUPS will use the hostname of the system.
|
||||
#
|
||||
# This is also the name used by clients when connecting to the local
|
||||
# server, so you can use this to configure a client machine without
|
||||
# a local server running.
|
||||
#
|
||||
|
||||
#ServerName myhost.domain.com
|
||||
|
||||
@@ -310,23 +305,6 @@ LogLevel info
|
||||
# Deny: denies access from the specified hostname, domain, IP address, or
|
||||
# network.
|
||||
#
|
||||
# Both "Allow" and "Deny" accept the following notations for addresses:
|
||||
#
|
||||
# All
|
||||
# None
|
||||
# *.domain.com
|
||||
# .domain.com
|
||||
# host.domain.com
|
||||
# nnn.*
|
||||
# nnn.nnn.*
|
||||
# nnn.nnn.nnn.*
|
||||
# nnn.nnn.nnn.nnn
|
||||
# nnn.nnn.nnn.nnn/mm
|
||||
# nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
|
||||
#
|
||||
# The host and domain address require that you enable hostname lookups
|
||||
# with "HostNameLookups On" above.
|
||||
#
|
||||
|
||||
<Location />
|
||||
</Location>
|
||||
@@ -351,8 +329,8 @@ LogLevel info
|
||||
#
|
||||
# You definitely will want to limit access to the administration tools.
|
||||
# The default configuration requires a local connection from a user who
|
||||
# is a member of the system group to do any admin tasks. You can change
|
||||
# the group name using the SystemGroup directive.
|
||||
# is a member of group "sys" to do any admin tasks. You can change the
|
||||
# group name using the SystemGroup directive.
|
||||
#
|
||||
|
||||
AuthType Basic
|
||||
@@ -365,5 +343,5 @@ Allow From 127.0.0.1
|
||||
</Location>
|
||||
|
||||
#
|
||||
# End of "$Id: cupsd.conf 628 1999-08-23 15:24:48Z mike $".
|
||||
# End of "$Id: cupsd.conf 510 1999-07-09 14:20:15Z mike $".
|
||||
#
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
* Version of software...
|
||||
*/
|
||||
|
||||
#define CUPS_SVERSION "CUPS v1.0b8"
|
||||
#define CUPS_SVERSION "CUPS v1.0"
|
||||
|
||||
/*
|
||||
* Where are files stored?
|
||||
|
||||
+11
-13
@@ -46,7 +46,12 @@ AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging [default=no]],
|
||||
OPTIM="-g "
|
||||
fi])
|
||||
AC_ARG_ENABLE(shared, [ --disable-shared turn off shared libraries [default=no]])
|
||||
if test "$disable_shared" != "yes"; then
|
||||
if eval "test x$disable_shared = xyes"; then
|
||||
PICFLAG=0
|
||||
LIBCUPS="libcups.a"
|
||||
LIBCUPSIMAGE="libcupsimage.a"
|
||||
DSO=":"
|
||||
else
|
||||
case "$uname" in
|
||||
SunOS* | UNIX_S*)
|
||||
LIBCUPS="libcups.so.1"
|
||||
@@ -58,7 +63,7 @@ if test "$disable_shared" != "yes"; then
|
||||
LIBCUPSIMAGE="libcupsimage.sl.1"
|
||||
DSO="ld -b -z +h \$@ -o"
|
||||
;;
|
||||
OSF1* | Linux* | FreeBSD*)
|
||||
OSF1* | Linux*)
|
||||
LIBCUPS="libcups.so.1"
|
||||
LIBCUPSIMAGE="libcupsimage.so.1"
|
||||
DSO="\$(CC) -Wl,-soname,\$@ -shared \$(OPTIM) -o"
|
||||
@@ -76,11 +81,6 @@ if test "$disable_shared" != "yes"; then
|
||||
DSO="\$(CC) -Wl,-soname,\$@ -shared \$(OPTIM) -o"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
PICFLAG=0
|
||||
LIBCUPS="libcups.a"
|
||||
LIBCUPSIMAGE="libcupsimage.a"
|
||||
DSO=":"
|
||||
fi
|
||||
|
||||
dnl Checks for programs...
|
||||
@@ -91,14 +91,13 @@ AC_PROG_RANLIB
|
||||
AC_PATH_PROG(AR,ar)
|
||||
AC_PATH_PROG(CHMOD,chmod)
|
||||
AC_PATH_PROG(CP,cp)
|
||||
AC_PATH_PROG(MV,mv)
|
||||
AC_PATH_PROG(NROFF,nroff)
|
||||
if test "$NROFF" = ""; then
|
||||
AC_PATH_PROG(GROFF,groff)
|
||||
if test "$GROFF" = ""; then
|
||||
AC_PATH_PROG(NROFF,groff)
|
||||
if test "$NROFF" = ""; then
|
||||
NROFF="echo"
|
||||
else
|
||||
NROFF="$GROFF -T ascii"
|
||||
NROFF="$NROFF -T ascii"
|
||||
fi
|
||||
fi
|
||||
AC_PATH_PROG(HTMLDOC,htmldoc)
|
||||
@@ -213,7 +212,6 @@ else
|
||||
if test -z "$OPTIM"; then
|
||||
OPTIM="+O2"
|
||||
fi
|
||||
OPTIM="-Ae $OPTIM"
|
||||
;;
|
||||
SunOS*)
|
||||
# Solaris
|
||||
@@ -273,7 +271,7 @@ if test "$prefix" = "NONE"; then
|
||||
fi
|
||||
|
||||
dnl Fix "libdir" variable for IRIX 6.x...
|
||||
if test "$uname" = "IRIX" -a $uversion -ge 65; then
|
||||
if test "$uname" = "IRIX" -a $uversion -ge 62; then
|
||||
libdir="/usr/lib32"
|
||||
fi
|
||||
|
||||
|
||||
-150
@@ -1,150 +0,0 @@
|
||||
#
|
||||
# "$Id$"
|
||||
#
|
||||
# Support library Makefile for the Common UNIX Printing System (CUPS).
|
||||
#
|
||||
# Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
#
|
||||
# These coded instructions, statements, and computer programs are the
|
||||
# property of Easy Software Products and are protected by Federal
|
||||
# copyright law. Distribution and use rights are outlined in the file
|
||||
# "LICENSE.txt" which should have been included with this file. If this
|
||||
# file is missing or damaged please contact Easy Software Products
|
||||
# at:
|
||||
#
|
||||
# Attn: CUPS Licensing Information
|
||||
# Easy Software Products
|
||||
# 44141 Airport View Drive, Suite 204
|
||||
# Hollywood, Maryland 20636-3111 USA
|
||||
#
|
||||
# Voice: (301) 373-9603
|
||||
# EMail: cups-info@cups.org
|
||||
# WWW: http://www.cups.org
|
||||
#
|
||||
|
||||
include ../Makedefs
|
||||
|
||||
#
|
||||
# Object files...
|
||||
#
|
||||
|
||||
LIBOBJS = emit.o filter.o http.o ipp.o language.o mark.o mime.o \
|
||||
options.o page.o ppd.o raster.o string.o type.o usersys.o \
|
||||
util.o
|
||||
OBJS = $(LIBOBJS) testhttp.o testmime.o testppd.o
|
||||
|
||||
#
|
||||
# Header files to install...
|
||||
#
|
||||
|
||||
HEADERS = cups.h http.h ipp.h language.h mime.h ppd.h raster.h
|
||||
|
||||
#
|
||||
# Targets in this directory...
|
||||
#
|
||||
|
||||
TARGETS = $(LIBCUPS) testhttp testmime testppd
|
||||
|
||||
#
|
||||
# Make all targets...
|
||||
#
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
#
|
||||
# Remove object and target files...
|
||||
#
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(TARGETS)
|
||||
|
||||
#
|
||||
# Install object and target files...
|
||||
#
|
||||
|
||||
install: all
|
||||
-$(MKDIR) $(INCLUDEDIR)/cups
|
||||
$(CP) $(HEADERS) $(INCLUDEDIR)/cups
|
||||
-$(MKDIR) $(LIBDIR)
|
||||
$(CP) $(LIBCUPS) $(LIBDIR)
|
||||
if test $(LIBCUPS) != "libcups.a"; then \
|
||||
$(LN) $(LIBCUPS) `basename $(LIBCUPS) .1`; \
|
||||
fi
|
||||
|
||||
#
|
||||
# libcups.so.1, libcups.sl.1
|
||||
#
|
||||
|
||||
libcups.so.1 libcups.sl.1: $(LIBOBJS) ../Makedefs
|
||||
echo Linking $@...
|
||||
$(DSO) $@ $(LIBOBJS)
|
||||
-$(LN) $@ `basename $@ .1`
|
||||
|
||||
#
|
||||
# libcups.a
|
||||
#
|
||||
|
||||
libcups.a: $(LIBOBJS)
|
||||
echo Archiving $@...
|
||||
$(RM) $@
|
||||
$(AR) $(ARFLAGS) $@ $(LIBOBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
#
|
||||
# cups_C.h - the default POSIX locale that is compiled in.
|
||||
#
|
||||
|
||||
cups_C.h: ../locale/C/cups_C
|
||||
echo Generating $@...
|
||||
$(RM) cups_C.h
|
||||
$(AWK) '{print "\"" $$0 "\","}' < ../locale/C/cups_C > cups_C.h
|
||||
|
||||
emit.o: ppd.h ../config.h ../Makedefs
|
||||
filter.o: mime.h ../config.h ../Makedefs
|
||||
http.o: http.h ipp.h string.h ../config.h ../Makedefs
|
||||
ipp.o: http.h ipp.h ../config.h ../Makedefs
|
||||
language.o: cups_C.h language.h string.h ../config.h ../Makedefs
|
||||
mark.o: ppd.h ../config.h ../Makedefs
|
||||
mime.o: mime.h ../config.h ../Makedefs
|
||||
options.o: cups.h ../config.h ../Makedefs
|
||||
page.o: ppd.h ../config.h ../Makedefs
|
||||
ppd.o: language.h ppd.h ../config.h ../Makedefs
|
||||
raster.o: raster.h ../config.h ../Makedefs
|
||||
string.o: string.h ../config.h ../Makedefs
|
||||
type.o: mime.h ../config.h ../Makedefs
|
||||
usersys.o: cups.h ../config.h ../Makedefs
|
||||
util.o: cups.h http.h ipp.h ../config.h ../Makedefs
|
||||
|
||||
#
|
||||
# testhttp (dependency on static CUPS library is intentional)
|
||||
#
|
||||
|
||||
testhttp: testhttp.o libcups.a
|
||||
echo Linking $@...
|
||||
$(CC) $(LDFLAGS) -o $@ testhttp.o libcups.a $(NETLIBS)
|
||||
|
||||
testhttp.o: http.h ../Makedefs
|
||||
|
||||
#
|
||||
# testmime (dependency on static CUPS library is intentional)
|
||||
#
|
||||
|
||||
testmime: testmime.o libcups.a
|
||||
echo Linking $@...
|
||||
$(CC) $(LDFLAGS) -o $@ testmime.o libcups.a
|
||||
|
||||
testmime.o: mime.h ../Makedefs
|
||||
|
||||
#
|
||||
# testppd (dependency on static CUPS library is intentional)
|
||||
#
|
||||
|
||||
testppd: testppd.o libcups.a
|
||||
echo Linking $@...
|
||||
$(CC) $(LDFLAGS) -o $@ testppd.o libcups.a $(NETLIBS)
|
||||
|
||||
testppd.o: ppd.h ../Makedefs
|
||||
|
||||
#
|
||||
# End of "$Id$".
|
||||
#
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="cups" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=cups - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "cups.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "cups.mak" CFG="cups - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "cups - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "cups - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "cups - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\visualc" /I ".." /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"cups.lib"
|
||||
|
||||
!ELSEIF "$(CFG)" == "cups - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\visualc" /I ".." /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo /out:"cupsd.lib"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "cups - Win32 Release"
|
||||
# Name "cups - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\emit.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\filter.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\http.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ipp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\language.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mark.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mime.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\options.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\page.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ppd.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\raster.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\string.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\type.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\util.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cups.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\http.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ipp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\language.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mime.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ppd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\raster.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* API definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_CUPS_H_
|
||||
# define _CUPS_CUPS_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <cups/ipp.h>
|
||||
# include <cups/mime.h>
|
||||
# include <cups/ppd.h>
|
||||
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
# define CUPS_VERSION 1.0
|
||||
# define CUPS_DATE_ANY -1
|
||||
|
||||
|
||||
/*
|
||||
* Types and structures...
|
||||
*/
|
||||
|
||||
typedef unsigned cups_ptype_t; /**** Printer Type/Capability Bits ****/
|
||||
enum /* Not a typedef'd enum so we can OR */
|
||||
{
|
||||
CUPS_PRINTER_LOCAL = 0x0000, /* Local printer or class */
|
||||
CUPS_PRINTER_CLASS = 0x0001, /* Printer class */
|
||||
CUPS_PRINTER_REMOTE = 0x0002, /* Remote printer or class */
|
||||
CUPS_PRINTER_BW = 0x0004, /* Can do B&W printing */
|
||||
CUPS_PRINTER_COLOR = 0x0008, /* Can do color printing */
|
||||
CUPS_PRINTER_DUPLEX = 0x0010, /* Can do duplexing */
|
||||
CUPS_PRINTER_STAPLE = 0x0020, /* Can staple output */
|
||||
CUPS_PRINTER_COPIES = 0x0040, /* Can do copies */
|
||||
CUPS_PRINTER_COLLATE = 0x0080, /* Can collage copies */
|
||||
CUPS_PRINTER_PUNCH = 0x0100, /* Can punch output */
|
||||
CUPS_PRINTER_COVER = 0x0200, /* Can cover output */
|
||||
CUPS_PRINTER_BIND = 0x0400, /* Can bind output */
|
||||
CUPS_PRINTER_SORT = 0x0800, /* Can sort output */
|
||||
CUPS_PRINTER_SMALL = 0x1000, /* Can do Letter/Legal/A4 */
|
||||
CUPS_PRINTER_MEDIUM = 0x2000, /* Can do Tabloid/B/C/A3/A2 */
|
||||
CUPS_PRINTER_LARGE = 0x4000, /* Can do D/E/A1/A0 */
|
||||
CUPS_PRINTER_VARIABLE = 0x8000, /* Can do variable sizes */
|
||||
CUPS_PRINTER_IMPLICIT = 0x10000, /* Implicit class */
|
||||
CUPS_PRINTER_OPTIONS = 0xfffc /* ~(CLASS | REMOTE | IMPLICIT) */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Types & structures...
|
||||
*/
|
||||
|
||||
typedef struct /**** Printer Information ****/
|
||||
{
|
||||
char name[IPP_MAX_NAME], /* Printer or class name */
|
||||
uri[HTTP_MAX_URI]; /* Universal resource identifier */
|
||||
unsigned char info[IPP_MAX_NAME], /* Printer or class info/description */
|
||||
location[IPP_MAX_NAME]; /* Location text */
|
||||
ipp_pstate_t state; /* Printer state */
|
||||
unsigned char message[IPP_MAX_NAME]; /* State text */
|
||||
cups_ptype_t type; /* Printer type/capability codes */
|
||||
} cups_browse_t;
|
||||
|
||||
typedef struct /**** Printer Options ****/
|
||||
{
|
||||
char *name; /* Name of option */
|
||||
char *value; /* Value of option */
|
||||
} cups_option_t;
|
||||
|
||||
|
||||
/*
|
||||
* Functions...
|
||||
*/
|
||||
|
||||
extern int cupsCancelJob(const char *printer, int job);
|
||||
#define cupsDoRequest(http,request,resource) cupsDoFileRequest((http),(request),(resource),NULL)
|
||||
extern ipp_t *cupsDoFileRequest(http_t *http, ipp_t *request,
|
||||
const char *resource, const char *filename);
|
||||
extern int cupsGetClasses(char ***classes);
|
||||
extern const char *cupsGetDefault(void);
|
||||
extern const char *cupsGetPPD(const char *printer);
|
||||
extern int cupsGetPrinters(char ***printers);
|
||||
extern int cupsPrintFile(const char *printer, const char *filename,
|
||||
const char *title, int num_options,
|
||||
cups_option_t *options);
|
||||
extern char *cupsTempFile(char *filename, int len);
|
||||
extern int cupsAddOption(const char *name, const char *value,
|
||||
int num_options, cups_option_t **options);
|
||||
extern void cupsFreeOptions(int num_options, cups_option_t *options);
|
||||
extern const char *cupsGetOption(const char *name, int num_options,
|
||||
cups_option_t *options);
|
||||
extern int cupsParseOptions(const char *arg, int num_options,
|
||||
cups_option_t **options);
|
||||
extern int cupsMarkOptions(ppd_file_t *ppd, int num_options,
|
||||
cups_option_t *options);
|
||||
|
||||
extern const char *cupsGetPassword(const char *prompt);
|
||||
extern const char *cupsServer(void);
|
||||
extern const char *cupsUser(void);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
|
||||
#endif /* !_CUPS_CUPS_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-123
@@ -1,123 +0,0 @@
|
||||
"us-ascii",
|
||||
"OK",
|
||||
"Cancel",
|
||||
"Help",
|
||||
"Quit",
|
||||
"Close",
|
||||
"Yes",
|
||||
"No",
|
||||
"On",
|
||||
"Off",
|
||||
"Save",
|
||||
"Discard",
|
||||
"Default",
|
||||
"Options",
|
||||
"More Info",
|
||||
"Black",
|
||||
"Color",
|
||||
"Cyan",
|
||||
"Magenta",
|
||||
"Yellow",
|
||||
"Copyright 1993-1999 by Easy Software Products, All Rights Reserved.",
|
||||
"General",
|
||||
"Printer",
|
||||
"Image Options",
|
||||
"HP-GL/2 Options",
|
||||
"Extra",
|
||||
"Document",
|
||||
"Other",
|
||||
"Print Pages: ",
|
||||
"Entire Document",
|
||||
"Page Range:",
|
||||
"Reverse Order: ",
|
||||
"Page Format: ",
|
||||
" 1-Up",
|
||||
" 2-Up",
|
||||
" 4-Up",
|
||||
"Image Scaling: ",
|
||||
"Use Natural Image Size",
|
||||
"Zoom by Percent",
|
||||
"Zoom by PPI",
|
||||
"Mirror Image: ",
|
||||
"Color Saturation: ",
|
||||
"Color Hue: ",
|
||||
"Fit to Page: ",
|
||||
"Shading: ",
|
||||
"Pen Width: ",
|
||||
"Gamma Correction: ",
|
||||
"Brightness: ",
|
||||
"Add",
|
||||
"Delete",
|
||||
"Modify",
|
||||
"Printer URI",
|
||||
"Printer Name",
|
||||
"Printer Location",
|
||||
"Printer Info",
|
||||
"Printer Make and Model",
|
||||
"Device URI",
|
||||
"Formatting Page",
|
||||
"Printing Page",
|
||||
"Initializing Printer",
|
||||
"Printer State",
|
||||
"Accepting Jobs",
|
||||
"Not Accepting Jobs",
|
||||
"Print Jobs",
|
||||
"Class",
|
||||
"Local",
|
||||
"Remote",
|
||||
"Duplexing",
|
||||
"Stapling",
|
||||
"Fast Copies",
|
||||
"Collated Copies",
|
||||
"Hole Punching",
|
||||
"Covering",
|
||||
"Binding",
|
||||
"Sorting",
|
||||
"Small (up to 9.5x14in)",
|
||||
"Medium (9.5x14in to 13x19in)",
|
||||
"Large (13x19in and larger)",
|
||||
"Custom Size",
|
||||
"Idle",
|
||||
"Processing",
|
||||
"Stopped",
|
||||
"All",
|
||||
"Odd",
|
||||
"Even Pages",
|
||||
"Darker Lighter",
|
||||
"Media Size",
|
||||
"Media Type",
|
||||
"Media Source",
|
||||
"Orientation: ",
|
||||
"Portrait",
|
||||
"Landscape",
|
||||
"Job State",
|
||||
"Job Name",
|
||||
"User Name",
|
||||
"Priority",
|
||||
"Copies",
|
||||
"File Size",
|
||||
"Pending",
|
||||
"Output Mode",
|
||||
"Resolution",
|
||||
"400 Your browser sent a request that this server could not understand.",
|
||||
"This server could not verify that you are authorized to access the resource.",
|
||||
"You must pay to access this server.",
|
||||
"You don't have permission to access the resource on this server.",
|
||||
"The requested resource was not found on this server.",
|
||||
"The requested method is not allowed with the resource.",
|
||||
"An appropriate representation for the resource was not found on this server.",
|
||||
"You don't have permission to use this server as a proxy host.",
|
||||
"The request has taken too long to complete and has been aborted.",
|
||||
"The requested resource has more than one value.",
|
||||
"The requested resource is gone and has not been replaced.",
|
||||
"The requested method requires a valid Content-Length.",
|
||||
"The precondition on the request evaluated to false.",
|
||||
"The request is too large for this server to process.",
|
||||
"The request URI is too large for this server to process.",
|
||||
"The request format is not understood by this server.",
|
||||
"500 The server has detected an unrecoverable error and cannot process your request.",
|
||||
"The requested method is not implemented by this server.",
|
||||
"The proxy server received an invalid response from an upstream server.",
|
||||
"The requested resource is currently unavailable on this server.",
|
||||
"The proxy server has taken too long to respond to this server.",
|
||||
"This server does not support the HTTP version required by your browser.",
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Debugging macros for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_DEBUG_H_
|
||||
# define _CUPS_DEBUG_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <stdio.h>
|
||||
|
||||
/*
|
||||
* The debug macros are used if you compile with DEBUG defined.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* DEBUG_puts("string")
|
||||
* DEBUG_printf(("format string", arg, arg, ...));
|
||||
*
|
||||
* Note the extra parenthesis around the DEBUG_printf macro...
|
||||
*/
|
||||
|
||||
# ifdef DEBUG
|
||||
# define DEBUG_puts(x) puts(x)
|
||||
# define DEBUG_printf(x) printf x
|
||||
# else
|
||||
# define DEBUG_puts(x)
|
||||
# define DEBUG_printf(x)
|
||||
# endif /* DEBUG */
|
||||
|
||||
#endif /* !_CUPS_DEBUG_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-301
@@ -1,301 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PPD code emission routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* PostScript is a trademark of Adobe Systems, Inc.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ppdEmit() - Emit code for marked options to a file.
|
||||
* ppdEmitFd() - Emit code for marked options to a file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "ppd.h"
|
||||
#include <stdlib.h>
|
||||
#include "string.h"
|
||||
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int ppd_sort(ppd_choice_t **c1, ppd_choice_t **c2);
|
||||
static int ppd_collect(ppd_file_t *ppd, ppd_section_t section,
|
||||
ppd_choice_t ***choices);
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdEmit()' - Emit code for marked options to a file.
|
||||
*/
|
||||
|
||||
int /* O - 0 on success, -1 on failure */
|
||||
ppdEmit(ppd_file_t *ppd, /* I - PPD file record */
|
||||
FILE *fp, /* I - File to write to */
|
||||
ppd_section_t section) /* I - Section to write */
|
||||
{
|
||||
int i, /* Looping var */
|
||||
count; /* Number of choices */
|
||||
ppd_choice_t **choices; /* Choices */
|
||||
ppd_size_t *size; /* Custom page size */
|
||||
|
||||
|
||||
if ((count = ppd_collect(ppd, section, &choices)) == 0)
|
||||
return (0);
|
||||
|
||||
for (i = 0; i < count; i ++)
|
||||
if (section != PPD_ORDER_EXIT && section != PPD_ORDER_JCL)
|
||||
{
|
||||
/*
|
||||
* Send DSC comments with option...
|
||||
*/
|
||||
|
||||
if (fprintf(fp, "%%%%BeginFeature: %s %s\n",
|
||||
((ppd_option_t *)choices[i]->option)->keyword,
|
||||
choices[i]->choice) < 0)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (strcmp(((ppd_option_t *)choices[i]->option)->keyword, "PageSize") == 0 &&
|
||||
strcmp(choices[i]->choice, "Custom") == 0)
|
||||
{
|
||||
/*
|
||||
* Variable size; write out standard size options (this should
|
||||
* eventually be changed to use the parameter positions defined
|
||||
* in the PPD file...)
|
||||
*/
|
||||
|
||||
size = ppdPageSize(ppd, "Custom");
|
||||
fprintf(fp, "%.0f %.0f 0 0 0\n", size->width, size->length);
|
||||
|
||||
if (choices[i]->code == NULL)
|
||||
{
|
||||
/*
|
||||
* This can happen with certain buggy PPD files that don't include
|
||||
* a CustomPageSize command sequence... We just use a generic
|
||||
* Level 2 command sequence...
|
||||
*/
|
||||
|
||||
fputs("pop pop pop\n", fp);
|
||||
fputs("<</PageSize[7 -2 roll]/ImagingBBox null>>setpagedevice\n", fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (choices[i]->code != NULL && choices[i]->code[0] != '\0')
|
||||
{
|
||||
if (fputs(choices[i]->code, fp) < 0)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (choices[i]->code[strlen(choices[i]->code) - 1] != '\n')
|
||||
putc('\n', fp);
|
||||
}
|
||||
|
||||
if (fputs("%%EndFeature\n", fp) < 0)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
else if (fputs(choices[i]->code, fp) < 0)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
free(choices);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdEmitFd()' - Emit code for marked options to a file.
|
||||
*/
|
||||
|
||||
int /* O - 0 on success, -1 on failure */
|
||||
ppdEmitFd(ppd_file_t *ppd, /* I - PPD file record */
|
||||
int fd, /* I - File to write to */
|
||||
ppd_section_t section) /* I - Section to write */
|
||||
{
|
||||
int i, /* Looping var */
|
||||
count; /* Number of choices */
|
||||
ppd_choice_t **choices; /* Choices */
|
||||
char buf[1024]; /* Output buffer for feature */
|
||||
|
||||
|
||||
if ((count = ppd_collect(ppd, section, &choices)) == 0)
|
||||
return (0);
|
||||
|
||||
for (i = 0; i < count; i ++)
|
||||
if (section != PPD_ORDER_EXIT && section != PPD_ORDER_JCL)
|
||||
{
|
||||
/*
|
||||
* Send DSC comments with option...
|
||||
*/
|
||||
|
||||
sprintf(buf, "%%%%BeginFeature: %s %s\n",
|
||||
((ppd_option_t *)choices[i]->option)->keyword, choices[i]->choice);
|
||||
|
||||
if (write(fd, buf, strlen(buf)) < 1)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(fd, choices[i]->code, strlen(choices[i]->code)) < 1)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(fd, "%%EndFeature\n", 13) < 1)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
else if (write(fd, choices[i]->code, strlen(choices[i]->code)) < 1)
|
||||
{
|
||||
free(choices);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
free(choices);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppd_sort()' - Sort options by ordering numbers...
|
||||
*/
|
||||
|
||||
static int /* O - -1 if c1 < c2, 0 if equal, 1 otherwise */
|
||||
ppd_sort(ppd_choice_t **c1, /* I - First choice */
|
||||
ppd_choice_t **c2) /* I - Second choice */
|
||||
{
|
||||
if (((ppd_option_t *)(*c1)->option)->order < ((ppd_option_t *)(*c2)->option)->order)
|
||||
return (-1);
|
||||
else if (((ppd_option_t *)(*c1)->option)->order > ((ppd_option_t *)(*c2)->option)->order)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppd_collect()' - Collect all marked options that reside in the specified
|
||||
* section.
|
||||
*/
|
||||
|
||||
static int /* O - Number of options marked */
|
||||
ppd_collect(ppd_file_t *ppd, /* I - PPD file data */
|
||||
ppd_section_t section, /* I - Section to collect */
|
||||
ppd_choice_t ***choices) /* O - Pointers to choices */
|
||||
{
|
||||
int i, j, k, m; /* Looping vars */
|
||||
ppd_group_t *g, /* Current group */
|
||||
*sg; /* Current sub-group */
|
||||
ppd_option_t *o; /* Current option */
|
||||
ppd_choice_t *c; /* Current choice */
|
||||
int count; /* Number of choices collected */
|
||||
ppd_choice_t **collect; /* Collected choices */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Allocate memory for up to 1000 selected choices...
|
||||
*/
|
||||
|
||||
count = 0;
|
||||
collect = calloc(sizeof(ppd_choice_t *), 1000);
|
||||
|
||||
/*
|
||||
* Loop through all options and add choices as needed...
|
||||
*/
|
||||
|
||||
for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
|
||||
{
|
||||
for (j = g->num_options, o = g->options; j > 0; j --, o ++)
|
||||
if (o->section == section)
|
||||
for (k = o->num_choices, c = o->choices; k > 0; k --, c ++)
|
||||
if (c->marked && count < 1000)
|
||||
{
|
||||
collect[count] = c;
|
||||
count ++;
|
||||
}
|
||||
|
||||
for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
|
||||
for (k = sg->num_options, o = sg->options; k > 0; k --, o ++)
|
||||
if (o->section == section)
|
||||
for (m = o->num_choices, c = o->choices; m > 0; m --, c ++)
|
||||
if (c->marked && count < 1000)
|
||||
{
|
||||
collect[count] = c;
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have more than 1 marked choice, sort them...
|
||||
*/
|
||||
|
||||
if (count > 1)
|
||||
qsort(collect, count, sizeof(ppd_choice_t *),
|
||||
(int (*)(const void *, const void *))ppd_sort);
|
||||
|
||||
/*
|
||||
* Return the array and number of choices; if 0, free the array since
|
||||
* it isn't needed.
|
||||
*/
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
*choices = collect;
|
||||
return (count);
|
||||
}
|
||||
else
|
||||
{
|
||||
*choices = NULL;
|
||||
free(collect);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-297
@@ -1,297 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* File type conversion routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* mimeAddFilter() - Add a filter to the current MIME database.
|
||||
* mimeFilter() - Find the fastest way to convert from one type to another.
|
||||
* compare() - Compare two filter types...
|
||||
* lookup() - Lookup a filter...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "string.h"
|
||||
#include "mime.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int compare(mime_filter_t *, mime_filter_t *);
|
||||
static mime_filter_t *lookup(mime_t *, mime_type_t *, mime_type_t *);
|
||||
|
||||
|
||||
/*
|
||||
* 'mimeAddFilter()' - Add a filter to the current MIME database.
|
||||
*/
|
||||
|
||||
mime_filter_t * /* O - New filter */
|
||||
mimeAddFilter(mime_t *mime, /* I - MIME database */
|
||||
mime_type_t *src, /* I - Source type */
|
||||
mime_type_t *dst, /* I - Destination type */
|
||||
int cost, /* I - Relative time/resource cost */
|
||||
const char *filter) /* I - Filter program to run */
|
||||
{
|
||||
mime_filter_t *temp; /* New filter */
|
||||
|
||||
|
||||
/*
|
||||
* Range-check the input...
|
||||
*/
|
||||
|
||||
if (mime == NULL || src == NULL || dst == NULL || filter == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (strlen(filter) > (MIME_MAX_FILTER - 1))
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* See if we already have an existing filter for the given source and
|
||||
* destination...
|
||||
*/
|
||||
|
||||
if ((temp = lookup(mime, src, dst)) != NULL)
|
||||
{
|
||||
/*
|
||||
* Yup, does the existing filter have a higher cost? If so, copy the
|
||||
* filter and cost to the existing filter entry and return it...
|
||||
*/
|
||||
|
||||
if (temp->cost > cost)
|
||||
{
|
||||
temp->cost = cost;
|
||||
strcpy(temp->filter, filter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Nope, add a new one...
|
||||
*/
|
||||
|
||||
if (mime->num_filters == 0)
|
||||
temp = malloc(sizeof(mime_filter_t));
|
||||
else
|
||||
temp = realloc(mime->filters, sizeof(mime_filter_t) * (mime->num_filters + 1));
|
||||
|
||||
if (temp == NULL)
|
||||
return (NULL);
|
||||
|
||||
mime->filters = temp;
|
||||
temp += mime->num_filters;
|
||||
mime->num_filters ++;
|
||||
|
||||
/*
|
||||
* Copy the information over and sort if necessary...
|
||||
*/
|
||||
|
||||
temp->src = src;
|
||||
temp->dst = dst;
|
||||
temp->cost = cost;
|
||||
strcpy(temp->filter, filter);
|
||||
|
||||
if (mime->num_filters > 1)
|
||||
qsort(mime->filters, mime->num_filters, sizeof(mime_filter_t),
|
||||
(int (*)(const void *, const void *))compare);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the new/updated filter...
|
||||
*/
|
||||
|
||||
return (temp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'mimeFilter()' - Find the fastest way to convert from one type to another.
|
||||
*/
|
||||
|
||||
mime_filter_t * /* O - Array of filters to run */
|
||||
mimeFilter(mime_t *mime, /* I - MIME database */
|
||||
mime_type_t *src, /* I - Source file type */
|
||||
mime_type_t *dst, /* I - Destination file type */
|
||||
int *num_filters) /* O - Number of filters to run */
|
||||
{
|
||||
int i, j, /* Looping vars */
|
||||
num_temp, /* Number of temporary filters */
|
||||
num_mintemp, /* Number of filters in the minimum */
|
||||
cost, /* Current cost */
|
||||
mincost; /* Current minimum */
|
||||
mime_filter_t *temp, /* Temporary filter */
|
||||
*mintemp, /* Current minimum */
|
||||
*mincurrent, /* Current filter for minimum */
|
||||
*current, /* Current filter */
|
||||
*filters; /* Filters to use */
|
||||
|
||||
|
||||
/*
|
||||
* Range-check the input...
|
||||
*/
|
||||
|
||||
if (mime == NULL || src == NULL || dst == NULL || num_filters == NULL)
|
||||
return (NULL);
|
||||
|
||||
*num_filters = 0;
|
||||
|
||||
/*
|
||||
* See if there is a filter that can convert the files directly...
|
||||
*/
|
||||
|
||||
if ((temp = lookup(mime, src, dst)) != NULL)
|
||||
{
|
||||
/*
|
||||
* Got a direct filter!
|
||||
*/
|
||||
|
||||
if ((filters = (mime_filter_t *)malloc(sizeof(mime_filter_t))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
memcpy(filters, temp, sizeof(mime_filter_t));
|
||||
*num_filters = 1;
|
||||
return (filters);
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, now look for filters from the source type to any other type...
|
||||
*/
|
||||
|
||||
mincost = 9999999;
|
||||
mintemp = NULL;
|
||||
|
||||
for (i = mime->num_filters, current = mime->filters; i > 0; i --, current ++)
|
||||
if (current->src == src)
|
||||
{
|
||||
/*
|
||||
* See if we have any filters that can convert from the destination type
|
||||
* of this filter to the final type...
|
||||
*/
|
||||
|
||||
if ((temp = mimeFilter(mime, current->dst, dst, &num_temp)) == NULL)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Found a match; see if this one is less costly than the last (if
|
||||
* any...)
|
||||
*/
|
||||
|
||||
for (j = 0, cost = 0; j < num_temp; j ++)
|
||||
cost += temp->cost;
|
||||
|
||||
if (cost < mincost)
|
||||
{
|
||||
if (mintemp != NULL)
|
||||
free(mintemp);
|
||||
|
||||
mincost = cost;
|
||||
mintemp = temp;
|
||||
num_mintemp = num_temp;
|
||||
mincurrent = current;
|
||||
}
|
||||
else
|
||||
free(temp);
|
||||
}
|
||||
|
||||
if (mintemp != NULL)
|
||||
{
|
||||
/*
|
||||
* Hey, we got a match! Add the current filter to the beginning of the
|
||||
* filter list...
|
||||
*/
|
||||
|
||||
filters = (mime_filter_t *)realloc(mintemp, sizeof(mime_filter_t) *
|
||||
(num_mintemp + 1));
|
||||
|
||||
if (filters == NULL)
|
||||
{
|
||||
*num_filters = 0;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
memmove(filters + 1, filters, num_mintemp * sizeof(mime_filter_t));
|
||||
memcpy(filters, mincurrent, sizeof(mime_filter_t));
|
||||
|
||||
*num_filters = num_mintemp + 1;
|
||||
|
||||
return (filters);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'compare()' - Compare two filter types...
|
||||
*/
|
||||
|
||||
static int /* O - Comparison result */
|
||||
compare(mime_filter_t *f0, /* I - First filter */
|
||||
mime_filter_t *f1) /* I - Second filter */
|
||||
{
|
||||
int i; /* Result of comparison */
|
||||
|
||||
|
||||
if ((i = strcmp(f0->src->super, f1->src->super)) == 0)
|
||||
if ((i = strcmp(f0->src->type, f1->src->type)) == 0)
|
||||
if ((i = strcmp(f0->dst->super, f1->dst->super)) == 0)
|
||||
i = strcmp(f0->dst->type, f1->dst->type);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'lookup()' - Lookup a filter...
|
||||
*/
|
||||
|
||||
static mime_filter_t * /* O - Filter for src->dst */
|
||||
lookup(mime_t *mime, /* I - MIME database */
|
||||
mime_type_t *src, /* I - Source type */
|
||||
mime_type_t *dst) /* I - Destination type */
|
||||
{
|
||||
mime_filter_t key; /* Key record for filter search */
|
||||
|
||||
|
||||
if (mime->num_filters == 0)
|
||||
return (NULL);
|
||||
|
||||
key.src = src;
|
||||
key.dst = dst;
|
||||
|
||||
return ((mime_filter_t *)bsearch(&key, mime->filters, mime->num_filters,
|
||||
sizeof(mime_filter_t),
|
||||
(int (*)(const void *, const void *))compare));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-1461
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
-291
@@ -1,291 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Hyper-Text Transport Protocol definitions for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_HTTP_H_
|
||||
# define _CUPS_HTTP_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# if defined(WIN32) || defined(__EMX__)
|
||||
# include <winsock.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
# include <netinet/in.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <netinet/in_systm.h>
|
||||
# include <netinet/ip.h>
|
||||
# include <netinet/tcp.h>
|
||||
# endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* Limits...
|
||||
*/
|
||||
|
||||
# define HTTP_MAX_URI 1024 /* Max length of URI string */
|
||||
# define HTTP_MAX_HOST 256 /* Max length of hostname string */
|
||||
# define HTTP_MAX_BUFFER 2048 /* Max length of data buffer */
|
||||
# define HTTP_MAX_VALUE 256 /* Max header field value length */
|
||||
|
||||
|
||||
/*
|
||||
* HTTP state values...
|
||||
*/
|
||||
|
||||
typedef enum /* States are server-oriented */
|
||||
{
|
||||
HTTP_WAITING, /* Waiting for command */
|
||||
HTTP_OPTIONS, /* OPTIONS command, waiting for blank line */
|
||||
HTTP_GET, /* GET command, waiting for blank line */
|
||||
HTTP_GET_SEND, /* GET command, sending data */
|
||||
HTTP_HEAD, /* HEAD command, waiting for blank line */
|
||||
HTTP_POST, /* POST command, waiting for blank line */
|
||||
HTTP_POST_RECV, /* POST command, receiving data */
|
||||
HTTP_POST_SEND, /* POST command, sending data */
|
||||
HTTP_PUT, /* PUT command, waiting for blank line */
|
||||
HTTP_PUT_RECV, /* PUT command, receiving data */
|
||||
HTTP_DELETE, /* DELETE command, waiting for blank line */
|
||||
HTTP_TRACE, /* TRACE command, waiting for blank line */
|
||||
HTTP_CLOSE, /* CLOSE command, waiting for blank line */
|
||||
HTTP_STATUS /* Command complete, sending status */
|
||||
} http_state_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP version numbers...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_0_9 = 9, /* HTTP/0.9 */
|
||||
HTTP_1_0 = 100, /* HTTP/1.0 */
|
||||
HTTP_1_1 = 101 /* HTTP/1.1 */
|
||||
} http_version_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP keep-alive values...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_KEEPALIVE_OFF = 0,
|
||||
HTTP_KEEPALIVE_ON
|
||||
} http_keepalive_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP transfer encoding values...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_ENCODE_LENGTH, /* Data is sent with Content-Length */
|
||||
HTTP_ENCODE_CHUNKED /* Data is chunked */
|
||||
} http_encoding_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP status codes...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_ERROR = -1, /* An error response from httpXxxx() */
|
||||
|
||||
HTTP_CONTINUE = 100, /* Everything OK, keep going... */
|
||||
|
||||
HTTP_OK = 200, /* OPTIONS/GET/HEAD/POST/TRACE command was successful */
|
||||
HTTP_CREATED, /* PUT command was successful */
|
||||
HTTP_ACCEPTED, /* DELETE command was successful */
|
||||
HTTP_NOT_AUTHORITATIVE, /* Information isn't authoritative */
|
||||
HTTP_NO_CONTENT, /* Successful command, no new data */
|
||||
HTTP_RESET_CONTENT, /* Content was reset/recreated */
|
||||
HTTP_PARTIAL_CONTENT, /* Only a partial file was recieved/sent */
|
||||
|
||||
HTTP_MULTIPLE_CHOICES = 300, /* Multiple files match request */
|
||||
HTTP_MOVED_PERMANENTLY, /* Document has moved permanently */
|
||||
HTTP_MOVED_TEMPORARILY, /* Document has moved temporarily */
|
||||
HTTP_SEE_OTHER, /* See this other link... */
|
||||
HTTP_NOT_MODIFIED, /* File not modified */
|
||||
HTTP_USE_PROXY, /* Must use a proxy to access this URI */
|
||||
|
||||
HTTP_BAD_REQUEST = 400, /* Bad request */
|
||||
HTTP_UNAUTHORIZED, /* Unauthorized to access host */
|
||||
HTTP_PAYMENT_REQUIRED, /* Payment required */
|
||||
HTTP_FORBIDDEN, /* Forbidden to access this URI */
|
||||
HTTP_NOT_FOUND, /* URI was not found */
|
||||
HTTP_METHOD_NOT_ALLOWED, /* Method is not allowed */
|
||||
HTTP_NOT_ACCEPTABLE, /* Not Acceptable */
|
||||
HTTP_PROXY_AUTHENTICATION, /* Proxy Authentication is Required */
|
||||
HTTP_REQUEST_TIMEOUT, /* Request timed out */
|
||||
HTTP_CONFLICT, /* Request is self-conflicting */
|
||||
HTTP_GONE, /* Server has gone away */
|
||||
HTTP_LENGTH_REQUIRED, /* A content length or encoding is required */
|
||||
HTTP_PRECONDITION, /* Precondition failed */
|
||||
HTTP_REQUEST_TOO_LARGE, /* Request entity too large */
|
||||
HTTP_URI_TOO_LONG, /* URI too long */
|
||||
HTTP_UNSUPPORTED_MEDIATYPE, /* The requested media type is unsupported */
|
||||
|
||||
HTTP_SERVER_ERROR = 500, /* Internal server error */
|
||||
HTTP_NOT_IMPLEMENTED, /* Feature not implemented */
|
||||
HTTP_BAD_GATEWAY, /* Bad gateway */
|
||||
HTTP_SERVICE_UNAVAILABLE, /* Service is unavailable */
|
||||
HTTP_GATEWAY_TIMEOUT, /* Gateway connection timed out */
|
||||
HTTP_NOT_SUPPORTED /* HTTP version not supported */
|
||||
} http_status_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP field names...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HTTP_FIELD_UNKNOWN = -1,
|
||||
HTTP_FIELD_ACCEPT_LANGUAGE,
|
||||
HTTP_FIELD_ACCEPT_RANGES,
|
||||
HTTP_FIELD_AUTHORIZATION,
|
||||
HTTP_FIELD_CONNECTION,
|
||||
HTTP_FIELD_CONTENT_ENCODING,
|
||||
HTTP_FIELD_CONTENT_LANGUAGE,
|
||||
HTTP_FIELD_CONTENT_LENGTH,
|
||||
HTTP_FIELD_CONTENT_LOCATION,
|
||||
HTTP_FIELD_CONTENT_MD5,
|
||||
HTTP_FIELD_CONTENT_RANGE,
|
||||
HTTP_FIELD_CONTENT_TYPE,
|
||||
HTTP_FIELD_CONTENT_VERSION,
|
||||
HTTP_FIELD_DATE,
|
||||
HTTP_FIELD_HOST,
|
||||
HTTP_FIELD_IF_MODIFIED_SINCE,
|
||||
HTTP_FIELD_IF_UNMODIFIED_SINCE,
|
||||
HTTP_FIELD_KEEP_ALIVE,
|
||||
HTTP_FIELD_LAST_MODIFIED,
|
||||
HTTP_FIELD_LINK,
|
||||
HTTP_FIELD_LOCATION,
|
||||
HTTP_FIELD_RANGE,
|
||||
HTTP_FIELD_REFERER,
|
||||
HTTP_FIELD_RETRY_AFTER,
|
||||
HTTP_FIELD_TRANSFER_ENCODING,
|
||||
HTTP_FIELD_UPGRADE,
|
||||
HTTP_FIELD_USER_AGENT,
|
||||
HTTP_FIELD_WWW_AUTHENTICATE,
|
||||
HTTP_FIELD_MAX
|
||||
} http_field_t;
|
||||
|
||||
|
||||
/*
|
||||
* HTTP connection structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* File descriptor for this socket */
|
||||
int blocking; /* To block or not to block */
|
||||
time_t activity; /* Time since last read/write */
|
||||
http_state_t state; /* State of client */
|
||||
http_status_t status; /* Status of last request */
|
||||
http_version_t version; /* Protocol version */
|
||||
http_keepalive_t keep_alive; /* Keep-alive supported? */
|
||||
struct sockaddr_in hostaddr; /* Address of connected host */
|
||||
char hostname[HTTP_MAX_HOST],
|
||||
/* Name of connected host */
|
||||
fields[HTTP_FIELD_MAX][HTTP_MAX_VALUE];
|
||||
/* Field values */
|
||||
char *data; /* Pointer to data buffer */
|
||||
http_encoding_t data_encoding; /* Chunked or not */
|
||||
int data_remaining; /* Number of bytes left */
|
||||
int used; /* Number of bytes used in buffer */
|
||||
char buffer[HTTP_MAX_BUFFER];
|
||||
/* Buffer for messages */
|
||||
} http_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
# define httpBlocking(http,b) (http)->blocking = (b)
|
||||
extern int httpCheck(http_t *http);
|
||||
# define httpClearFields(http) memset((http)->fields, 0, sizeof((http)->fields)),\
|
||||
httpSetField((http), HTTP_FIELD_HOST, (http)->hostname)
|
||||
extern void httpClose(http_t *http);
|
||||
extern http_t *httpConnect(const char *host, int port);
|
||||
extern int httpDelete(http_t *http, const char *uri);
|
||||
extern void httpFlush(http_t *http);
|
||||
extern int httpGet(http_t *http, const char *uri);
|
||||
extern char *httpGets(char *line, int length, http_t *http);
|
||||
extern const char *httpGetDateString(time_t t);
|
||||
extern time_t httpGetDateTime(const char *s);
|
||||
# define httpGetField(http,field) (http)->fields[field]
|
||||
extern int httpHead(http_t *http, const char *uri);
|
||||
extern void httpInitialize(void);
|
||||
extern int httpOptions(http_t *http, const char *uri);
|
||||
extern int httpPost(http_t *http, const char *uri);
|
||||
extern int httpPrintf(http_t *http, const char *format, ...);
|
||||
extern int httpPut(http_t *http, const char *uri);
|
||||
extern int httpRead(http_t *http, char *buffer, int length);
|
||||
extern int httpReconnect(http_t *http);
|
||||
extern void httpSeparate(const char *uri, char *method, char *username,
|
||||
char *host, int *port, char *resource);
|
||||
extern void httpSetField(http_t *http, http_field_t field, const char *value);
|
||||
extern const char *httpStatus(http_status_t status);
|
||||
extern int httpTrace(http_t *http, const char *uri);
|
||||
extern http_status_t httpUpdate(http_t *http);
|
||||
extern int httpWrite(http_t *http, const char *buffer, int length);
|
||||
extern char *httpEncode64(char *out, const char *in);
|
||||
extern char *httpDecode64(char *out, const char *in);
|
||||
extern int httpGetLength(http_t *http);
|
||||
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
#endif /* !_CUPS_HTTP_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-1459
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
-343
@@ -1,343 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Internet Printing Protocol definitions for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_IPP_H_
|
||||
# define _CUPS_IPP_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <cups/http.h>
|
||||
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* IPP version string...
|
||||
*/
|
||||
|
||||
# define IPP_VERSION "\001\000"
|
||||
|
||||
/*
|
||||
* IPP registered port number... This is the default value - applications
|
||||
* should use the ippPort() function so that you can customize things in
|
||||
* /etc/services if needed!
|
||||
*/
|
||||
|
||||
# define IPP_PORT 631
|
||||
|
||||
/*
|
||||
* Common limits...
|
||||
*/
|
||||
|
||||
# define IPP_MAX_NAME 256
|
||||
# define IPP_MAX_VALUES 100
|
||||
|
||||
|
||||
/*
|
||||
* Types and structures...
|
||||
*/
|
||||
|
||||
typedef enum /**** Format tags for attribute formats... ****/
|
||||
{
|
||||
IPP_TAG_ZERO = 0x00,
|
||||
IPP_TAG_OPERATION,
|
||||
IPP_TAG_JOB,
|
||||
IPP_TAG_END,
|
||||
IPP_TAG_PRINTER,
|
||||
IPP_TAG_EXTENSION,
|
||||
IPP_TAG_UNSUPPORTED = 0x10,
|
||||
IPP_TAG_DEFAULT,
|
||||
IPP_TAG_UNKNOWN,
|
||||
IPP_TAG_NOVALUE,
|
||||
IPP_TAG_INTEGER = 0x21,
|
||||
IPP_TAG_BOOLEAN,
|
||||
IPP_TAG_ENUM,
|
||||
IPP_TAG_STRING = 0x30,
|
||||
IPP_TAG_DATE,
|
||||
IPP_TAG_RESOLUTION,
|
||||
IPP_TAG_RANGE,
|
||||
IPP_TAG_COLLECTION,
|
||||
IPP_TAG_TEXTLANG,
|
||||
IPP_TAG_NAMELANG,
|
||||
IPP_TAG_TEXT = 0x41,
|
||||
IPP_TAG_NAME,
|
||||
IPP_TAG_KEYWORD = 0x44,
|
||||
IPP_TAG_URI,
|
||||
IPP_TAG_URISCHEME,
|
||||
IPP_TAG_CHARSET,
|
||||
IPP_TAG_LANGUAGE,
|
||||
IPP_TAG_MIMETYPE
|
||||
} ipp_tag_t;
|
||||
|
||||
typedef enum /**** Resolution units... ****/
|
||||
{
|
||||
IPP_RES_PER_INCH = 3,
|
||||
IPP_RES_PER_CM
|
||||
} ipp_res_t;
|
||||
|
||||
typedef enum /**** Multiple Document Handling ****/
|
||||
{
|
||||
IPP_DOC_SINGLE,
|
||||
IPP_DOC_UNCOLLATED,
|
||||
IPP_DOC_COLLATED,
|
||||
IPP_DOC_SEPARATE
|
||||
} ipp_doc_t;
|
||||
|
||||
typedef enum /**** Finishings... ****/
|
||||
{
|
||||
IPP_FINISH_NONE = 3,
|
||||
IPP_FINISH_STAPLE,
|
||||
IPP_FINISH_PUNCH,
|
||||
IPP_FINISH_COVER,
|
||||
IPP_FINISH_BIND
|
||||
} ipp_finish_t;
|
||||
|
||||
typedef enum /**** Orientation... ****/
|
||||
{
|
||||
IPP_PORTRAIT = 3, /* No rotation */
|
||||
IPP_LANDSCAPE, /* 90 degrees counter-clockwise */
|
||||
IPP_REVERSE_LANDSCAPE, /* 90 degrees clockwise */
|
||||
IPP_REVERSE_PORTRAIT /* 180 degrees */
|
||||
} ipp_orient_t;
|
||||
|
||||
typedef enum /**** Qualities... ****/
|
||||
{
|
||||
IPP_QUALITY_DRAFT = 3,
|
||||
IPP_QUALITY_NORMAL,
|
||||
IPP_QUALITY_HIGH
|
||||
} ipp_quality_t;
|
||||
|
||||
typedef enum /**** Job States.... */
|
||||
{
|
||||
IPP_JOB_PENDING = 3,
|
||||
IPP_JOB_HELD,
|
||||
IPP_JOB_PROCESSING,
|
||||
IPP_JOB_STOPPED,
|
||||
IPP_JOB_CANCELED,
|
||||
IPP_JOB_ABORTED,
|
||||
IPP_JOB_COMPLETED
|
||||
} ipp_jstate_t;
|
||||
|
||||
typedef enum /**** Printer States.... */
|
||||
{
|
||||
IPP_PRINTER_IDLE = 3,
|
||||
IPP_PRINTER_PROCESSING,
|
||||
IPP_PRINTER_STOPPED
|
||||
} ipp_pstate_t;
|
||||
|
||||
typedef enum /**** IPP states... ****/
|
||||
{
|
||||
IPP_ERROR = -1, /* An error occurred */
|
||||
IPP_IDLE, /* Nothing is happening/request completed */
|
||||
IPP_HEADER, /* The request header needs to be sent/received */
|
||||
IPP_ATTRIBUTE, /* One or more attributes need to be sent/received */
|
||||
IPP_DATA /* IPP request data needs to be sent/received */
|
||||
} ipp_state_t;
|
||||
|
||||
typedef enum /**** IPP operations... ****/
|
||||
{
|
||||
IPP_PRINT_JOB = 0x0002,
|
||||
IPP_PRINT_URI,
|
||||
IPP_VALIDATE_JOB,
|
||||
IPP_CREATE_JOB,
|
||||
IPP_SEND_DOCUMENT,
|
||||
IPP_SEND_URI,
|
||||
IPP_CANCEL_JOB,
|
||||
IPP_GET_JOB_ATTRIBUTES,
|
||||
IPP_GET_JOBS,
|
||||
IPP_GET_PRINTER_ATTRIBUTES,
|
||||
IPP_HOLD_JOB = 0x000c,
|
||||
IPP_RELEASE_JOB,
|
||||
IPP_RESTART_JOB,
|
||||
IPP_PAUSE_PRINTER = 0x0010,
|
||||
IPP_RESUME_PRINTER,
|
||||
IPP_PURGE_JOBS,
|
||||
IPP_PRIVATE = 0x4000,
|
||||
CUPS_GET_DEFAULT,
|
||||
CUPS_GET_PRINTERS,
|
||||
CUPS_ADD_PRINTER,
|
||||
CUPS_DELETE_PRINTER,
|
||||
CUPS_GET_CLASSES,
|
||||
CUPS_ADD_CLASS,
|
||||
CUPS_DELETE_CLASS,
|
||||
CUPS_ACCEPT_JOBS,
|
||||
CUPS_REJECT_JOBS,
|
||||
CUPS_SET_DEFAULT
|
||||
} ipp_op_t;
|
||||
|
||||
typedef enum /**** IPP status codes... ****/
|
||||
{
|
||||
IPP_OK = 0x0000,
|
||||
IPP_OK_SUBST,
|
||||
IPP_OK_CONFLICT,
|
||||
IPP_BAD_REQUEST = 0x0400,
|
||||
IPP_FORBIDDEN,
|
||||
IPP_NOT_AUTHENTICATED,
|
||||
IPP_NOT_AUTHORIZED,
|
||||
IPP_NOT_POSSIBLE,
|
||||
IPP_TIMEOUT,
|
||||
IPP_NOT_FOUND,
|
||||
IPP_GONE,
|
||||
IPP_REQUEST_ENTITY,
|
||||
IPP_REQUEST_VALUE,
|
||||
IPP_DOCUMENT_FORMAT,
|
||||
IPP_ATTRIBUTES,
|
||||
IPP_URI_SCHEME,
|
||||
IPP_CHARSET,
|
||||
IPP_CONFLICT,
|
||||
IPP_INTERNAL_ERROR = 0x0500,
|
||||
IPP_OPERATION_NOT_SUPPORTED,
|
||||
IPP_SERVICE_UNAVAILABLE,
|
||||
IPP_VERSION_NOT_SUPPORTED,
|
||||
IPP_DEVICE_UNAVAILABLE,
|
||||
IPP_TEMPORARY_ERROR,
|
||||
IPP_NOT_ACCEPTING,
|
||||
IPP_PRINTER_BUSY
|
||||
} ipp_status_t;
|
||||
|
||||
typedef unsigned char ipp_uchar_t;/**** Unsigned 8-bit integer/character ****/
|
||||
|
||||
typedef union /**** Request Header ****/
|
||||
{
|
||||
struct /* Any Header */
|
||||
{
|
||||
ipp_uchar_t version[2]; /* Protocol version number */
|
||||
int op_status; /* Operation ID or status code*/
|
||||
int request_id; /* Request ID */
|
||||
} any;
|
||||
|
||||
struct /* Operation Header */
|
||||
{
|
||||
ipp_uchar_t version[2]; /* Protocol version number */
|
||||
ipp_op_t operation_id; /* Operation ID */
|
||||
int request_id; /* Request ID */
|
||||
} op;
|
||||
|
||||
struct /* Status Header */
|
||||
{
|
||||
ipp_uchar_t version[2]; /* Protocol version number */
|
||||
ipp_status_t status_code; /* Status code */
|
||||
int request_id; /* Request ID */
|
||||
} status;
|
||||
} ipp_request_t;
|
||||
|
||||
|
||||
typedef union /**** Attribute Value ****/
|
||||
{
|
||||
int integer; /* Integer/enumerated value */
|
||||
|
||||
char boolean; /* Boolean value */
|
||||
|
||||
ipp_uchar_t date[11]; /* Date/time value */
|
||||
|
||||
struct
|
||||
{
|
||||
int xres, /* Horizontal resolution */
|
||||
yres; /* Vertical resolution */
|
||||
ipp_res_t units; /* Resolution units */
|
||||
} resolution; /* Resolution value */
|
||||
|
||||
struct
|
||||
{
|
||||
int lower, /* Lower value */
|
||||
upper; /* Upper value */
|
||||
} range; /* Range of integers value */
|
||||
|
||||
struct
|
||||
{
|
||||
char *charset; /* Character set */
|
||||
char *text; /* String */
|
||||
} string; /* String with language value */
|
||||
} ipp_value_t;
|
||||
|
||||
typedef struct ipp_attribute_s /**** Attribute ****/
|
||||
{
|
||||
struct ipp_attribute_s *next;
|
||||
/* Next atrtribute in list */
|
||||
ipp_tag_t group_tag, /* Job/Printer/Operation group tag */
|
||||
value_tag; /* What type of value is it? */
|
||||
char *name; /* Name of attribute */
|
||||
int num_values; /* Number of values */
|
||||
ipp_value_t values[1]; /* Values */
|
||||
} ipp_attribute_t;
|
||||
|
||||
typedef struct /**** Request State ****/
|
||||
{
|
||||
ipp_state_t state; /* State of request */
|
||||
ipp_request_t request; /* Request header */
|
||||
ipp_attribute_t *attrs, /* Attributes */
|
||||
*last, /* Last attribute in list */
|
||||
*current; /* Current attribute (for read/write) */
|
||||
ipp_tag_t curtag; /* Current attribute group tag */
|
||||
} ipp_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
extern time_t ippDateToTime(const ipp_uchar_t *date);
|
||||
extern ipp_attribute_t *ippAddBoolean(ipp_t *ipp, ipp_tag_t group, const char *name, char value);
|
||||
extern ipp_attribute_t *ippAddBooleans(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, const char *values);
|
||||
extern ipp_attribute_t *ippAddDate(ipp_t *ipp, ipp_tag_t group, const char *name, const ipp_uchar_t *value);
|
||||
extern ipp_attribute_t *ippAddInteger(ipp_t *ipp, ipp_tag_t group, ipp_tag_t type, const char *name, int value);
|
||||
extern ipp_attribute_t *ippAddIntegers(ipp_t *ipp, ipp_tag_t group, ipp_tag_t type, const char *name, int num_values, const int *values);
|
||||
extern ipp_attribute_t *ippAddRange(ipp_t *ipp, ipp_tag_t group, const char *name, int lower, int upper);
|
||||
extern ipp_attribute_t *ippAddRanges(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, const int *lower, const int *upper);
|
||||
extern ipp_attribute_t *ippAddResolution(ipp_t *ipp, ipp_tag_t group, const char *name, ipp_res_t units, int xres, int yres);
|
||||
extern ipp_attribute_t *ippAddResolutions(ipp_t *ipp, ipp_tag_t group, const char *name, int num_values, ipp_res_t units, const int *xres, const int *yres);
|
||||
extern ipp_attribute_t *ippAddSeparator(ipp_t *ipp);
|
||||
extern ipp_attribute_t *ippAddString(ipp_t *ipp, ipp_tag_t group, ipp_tag_t type, const char *name, const char *charset, const char *value);
|
||||
extern ipp_attribute_t *ippAddStrings(ipp_t *ipp, ipp_tag_t group, ipp_tag_t type, const char *name, int num_values, const char *charset, const char **values);
|
||||
extern void ippDelete(ipp_t *ipp);
|
||||
extern ipp_attribute_t *ippFindAttribute(ipp_t *ipp, const char *name, ipp_tag_t type);
|
||||
extern size_t ippLength(ipp_t *ipp);
|
||||
extern ipp_t *ippNew(void);
|
||||
extern ipp_state_t ippRead(http_t *http, ipp_t *ipp);
|
||||
extern const ipp_uchar_t *ippTimeToDate(time_t t);
|
||||
extern ipp_state_t ippWrite(http_t *http, ipp_t *ipp);
|
||||
extern int ippPort(void);
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
#endif /* !_CUPS_IPP_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,374 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* I18N/language support for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* cupsLangEncoding() - Return the character encoding (us-ascii, etc.)
|
||||
* for the given language.
|
||||
* cupsLangFlush() - Flush all language data out of the cache.
|
||||
* cupsLangFree() - Free language data.
|
||||
* cupsLangGet() - Get a language.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "string.h"
|
||||
#include "language.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local globals...
|
||||
*/
|
||||
|
||||
static cups_lang_t *lang_cache = NULL; /* Language string cache */
|
||||
static char *lang_blank = ""; /* Blank constant string */
|
||||
static char *lang_encodings[] = /* Encoding strings */
|
||||
{
|
||||
"us-ascii",
|
||||
"iso8859-1",
|
||||
"iso8859-2",
|
||||
"iso8859-3",
|
||||
"iso8859-4",
|
||||
"iso8859-5",
|
||||
"iso8859-6",
|
||||
"iso8859-7",
|
||||
"iso8859-8",
|
||||
"iso8859-9",
|
||||
"iso8859-10",
|
||||
"utf8"
|
||||
};
|
||||
static char *lang_default[] = /* Default POSIX locale */
|
||||
{
|
||||
#include "cups_C.h"
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsLangEncoding()' - Return the character encoding (us-ascii, etc.)
|
||||
* for the given language.
|
||||
*/
|
||||
|
||||
char * /* O - Character encoding */
|
||||
cupsLangEncoding(cups_lang_t *lang) /* I - Language data */
|
||||
{
|
||||
if (lang == NULL)
|
||||
return (lang_encodings[0]);
|
||||
else
|
||||
return (lang_encodings[lang->encoding]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsLangFlush()' - Flush all language data out of the cache.
|
||||
*/
|
||||
|
||||
void
|
||||
cupsLangFlush(void)
|
||||
{
|
||||
int i; /* Looping var */
|
||||
cups_lang_t *lang, /* Current language */
|
||||
*next; /* Next language */
|
||||
|
||||
|
||||
for (lang = lang_cache; lang != NULL; lang = next)
|
||||
{
|
||||
for (i = 0; i < CUPS_MSG_MAX; i ++)
|
||||
if (lang->messages[i] != NULL && lang->messages[i] != lang_blank)
|
||||
free(lang->messages[i]);
|
||||
|
||||
next = lang->next;
|
||||
free(lang);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsLangFree()' - Free language data.
|
||||
*
|
||||
* This does not actually free anything; use cupsLangFlush() for that.
|
||||
*/
|
||||
|
||||
void
|
||||
cupsLangFree(cups_lang_t *lang) /* I - Language to free */
|
||||
{
|
||||
if (lang != NULL && lang->used > 0)
|
||||
lang->used --;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsLangGet()' - Get a language.
|
||||
*/
|
||||
|
||||
cups_lang_t * /* O - Language data */
|
||||
cupsLangGet(const char *language) /* I - Language or locale */
|
||||
{
|
||||
int i, count; /* Looping vars */
|
||||
char langname[16], /* Requested language name */
|
||||
real[16], /* Real language name */
|
||||
filename[1024], /* Filename for language locale file */
|
||||
*localedir; /* Directory for locale files */
|
||||
FILE *fp; /* Language locale file pointer */
|
||||
char line[1024]; /* Line from file */
|
||||
cups_msg_t msg; /* Message number */
|
||||
char *text; /* Message text */
|
||||
cups_lang_t *lang; /* Current language... */
|
||||
|
||||
|
||||
/*
|
||||
* Convert the language string passed in to a locale string. "C" is the
|
||||
* standard POSIX locale and is copied unchanged. Otherwise the
|
||||
* language string is converted from ll-cc (language-country) to ll_CC
|
||||
* to match the file naming convention used by all POSIX-compliant
|
||||
* operating systems.
|
||||
*/
|
||||
|
||||
if (language == NULL || language[0] == '\0' ||
|
||||
strcmp(language, "POSIX") == 0)
|
||||
strcpy(langname, "C");
|
||||
else
|
||||
strcpy(langname, language);
|
||||
|
||||
if (strlen(langname) < 2)
|
||||
strcpy(real, "C");
|
||||
else
|
||||
{
|
||||
real[0] = tolower(langname[0]);
|
||||
real[1] = tolower(langname[1]);
|
||||
|
||||
if (langname[2] == '_' || langname[2] == '-')
|
||||
{
|
||||
real[2] = '_';
|
||||
real[3] = toupper(langname[3]);
|
||||
real[4] = toupper(langname[4]);
|
||||
real[5] = '\0';
|
||||
langname[5] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
langname[2] = '\0';
|
||||
real[2] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Next try to open a locale file; we will try the country-localized file
|
||||
* first, and then look for generic language file. If all else fails we
|
||||
* will use the POSIX locale.
|
||||
*/
|
||||
|
||||
if ((localedir = getenv("LOCALEDIR")) == NULL)
|
||||
localedir = CUPS_LOCALEDIR;
|
||||
|
||||
sprintf(filename, "%s/%s/cups_%s", localedir, real, real);
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL)
|
||||
if (strlen(real) > 2)
|
||||
{
|
||||
/*
|
||||
* Nope, see if we can open a generic language file...
|
||||
*/
|
||||
|
||||
real[2] = '\0';
|
||||
sprintf(filename, "%s/%s/cups_%s", localedir, real, real);
|
||||
fp = fopen(filename, "r");
|
||||
}
|
||||
|
||||
/*
|
||||
* Then see if we already have this language loaded...
|
||||
*/
|
||||
|
||||
for (lang = lang_cache; lang != NULL; lang = lang->next)
|
||||
if (strcmp(lang->language, langname) == 0)
|
||||
{
|
||||
lang->used ++;
|
||||
|
||||
if (fp != NULL)
|
||||
fclose(fp);
|
||||
|
||||
return (lang);
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, we have an open messages file; the first line will contain the
|
||||
* language encoding (us-ascii, iso-8859-1, etc.), and the rest will
|
||||
* be messages consisting of:
|
||||
*
|
||||
* #### SP message text
|
||||
*
|
||||
* or:
|
||||
*
|
||||
* message text
|
||||
*
|
||||
* If the line starts with a number, then message processing picks up
|
||||
* where the number indicates. Otherwise the last message number is
|
||||
* incremented.
|
||||
*
|
||||
* All leading whitespace is deleted.
|
||||
*/
|
||||
|
||||
if (fp == NULL)
|
||||
strcpy(line, lang_default[0]);
|
||||
else if (fgets(line, sizeof(line), fp) == NULL)
|
||||
{
|
||||
/*
|
||||
* Can't read encoding!
|
||||
*/
|
||||
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
i = strlen(line) - 1;
|
||||
if (line[i] == '\n')
|
||||
line[i] = '\0'; /* Strip LF */
|
||||
|
||||
/*
|
||||
* See if there is a free language available; if so, use that
|
||||
* record...
|
||||
*/
|
||||
|
||||
for (lang = lang_cache; lang != NULL; lang = lang->next)
|
||||
if (lang->used == 0)
|
||||
break;
|
||||
|
||||
if (lang == NULL)
|
||||
{
|
||||
/*
|
||||
* Allocate memory for the language and add it to the cache.
|
||||
*/
|
||||
|
||||
if ((lang = calloc(sizeof(cups_lang_t), 1)) == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
lang->next = lang_cache;
|
||||
lang_cache = lang;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Free all old strings as needed...
|
||||
*/
|
||||
|
||||
for (i = 0; i < CUPS_MSG_MAX; i ++)
|
||||
{
|
||||
if (lang->messages[i] != NULL && lang->messages[i] != lang_blank)
|
||||
free(lang->messages[i]);
|
||||
|
||||
lang->messages[i] = lang_blank;
|
||||
}
|
||||
|
||||
/*
|
||||
* Then assign the language and encoding fields...
|
||||
*/
|
||||
|
||||
lang->used ++;
|
||||
strcpy(lang->language, langname);
|
||||
|
||||
for (i = 0; i < (sizeof(lang_encodings) / sizeof(lang_encodings[0])); i ++)
|
||||
if (strcmp(lang_encodings[i], line) == 0)
|
||||
{
|
||||
lang->encoding = (cups_encoding_t)i;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the strings from the file...
|
||||
*/
|
||||
|
||||
msg = (cups_msg_t)-1;
|
||||
count = 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
* Read a line from memory or from a file...
|
||||
*/
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
if (lang_default[count] == NULL)
|
||||
break;
|
||||
|
||||
strcpy(line, lang_default[count]);
|
||||
}
|
||||
else if (fgets(line, sizeof(line), fp) == NULL)
|
||||
break;
|
||||
|
||||
count ++;
|
||||
|
||||
/*
|
||||
* Ignore blank lines...
|
||||
*/
|
||||
|
||||
i = strlen(line) - 1;
|
||||
if (line[i] == '\n')
|
||||
line[i] = '\0'; /* Strip LF */
|
||||
|
||||
if (line[0] == '\0')
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Grab the message number and text...
|
||||
*/
|
||||
|
||||
if (isdigit(line[0]))
|
||||
msg = (cups_msg_t)atoi(line);
|
||||
else
|
||||
msg ++;
|
||||
|
||||
if (msg < 0 || msg >= CUPS_MSG_MAX)
|
||||
continue;
|
||||
|
||||
text = line;
|
||||
while (isdigit(*text))
|
||||
text ++;
|
||||
while (isspace(*text))
|
||||
text ++;
|
||||
|
||||
lang->messages[msg] = strdup(text);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close the file and return...
|
||||
*/
|
||||
|
||||
if (fp != NULL)
|
||||
fclose(fp);
|
||||
|
||||
return (lang);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Multi-language support for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_LANGUAGE_H_
|
||||
# define _CUPS_LANGUAGE_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <locale.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Messages...
|
||||
*/
|
||||
|
||||
typedef enum /**** Message Indices ****/
|
||||
{
|
||||
CUPS_MSG_OK,
|
||||
CUPS_MSG_CANCEL,
|
||||
CUPS_MSG_HELP,
|
||||
CUPS_MSG_QUIT,
|
||||
CUPS_MSG_CLOSE,
|
||||
CUPS_MSG_YES,
|
||||
CUPS_MSG_NO,
|
||||
CUPS_MSG_ON,
|
||||
CUPS_MSG_OFF,
|
||||
CUPS_MSG_SAVE,
|
||||
CUPS_MSG_DISCARD,
|
||||
CUPS_MSG_DEFAULT,
|
||||
CUPS_MSG_OPTIONS,
|
||||
CUPS_MSG_MORE_INFO,
|
||||
CUPS_MSG_BLACK,
|
||||
CUPS_MSG_COLOR,
|
||||
CUPS_MSG_CYAN,
|
||||
CUPS_MSG_MAGENTA,
|
||||
CUPS_MSG_YELLOW,
|
||||
CUPS_MSG_COPYRIGHT,
|
||||
CUPS_MSG_GENERAL,
|
||||
CUPS_MSG_PRINTER,
|
||||
CUPS_MSG_IMAGE,
|
||||
CUPS_MSG_HPGL2,
|
||||
CUPS_MSG_EXTRA,
|
||||
CUPS_MSG_DOCUMENT,
|
||||
CUPS_MSG_OTHER,
|
||||
CUPS_MSG_PRINT_PAGES,
|
||||
CUPS_MSG_ENTIRE_DOCUMENT,
|
||||
CUPS_MSG_PAGE_RANGE,
|
||||
CUPS_MSG_REVERSE_ORDER,
|
||||
CUPS_MSG_PAGE_FORMAT,
|
||||
CUPS_MSG_1_UP,
|
||||
CUPS_MSG_2_UP,
|
||||
CUPS_MSG_4_UP,
|
||||
CUPS_MSG_IMAGE_SCALING,
|
||||
CUPS_MSG_USE_NATURAL_IMAGE_SIZE,
|
||||
CUPS_MSG_ZOOM_BY_PERCENT,
|
||||
CUPS_MSG_ZOOM_BY_PPI,
|
||||
CUPS_MSG_MIRROR_IMAGE,
|
||||
CUPS_MSG_COLOR_SATURATION,
|
||||
CUPS_MSG_COLOR_HUE,
|
||||
CUPS_MSG_FIT_TO_PAGE,
|
||||
CUPS_MSG_SHADING,
|
||||
CUPS_MSG_DEFAULT_PEN_WIDTH,
|
||||
CUPS_MSG_GAMMA_CORRECTION,
|
||||
CUPS_MSG_BRIGHTNESS,
|
||||
CUPS_MSG_ADD,
|
||||
CUPS_MSG_DELETE,
|
||||
CUPS_MSG_MODIFY,
|
||||
CUPS_MSG_PRINTER_URI,
|
||||
CUPS_MSG_PRINTER_NAME,
|
||||
CUPS_MSG_PRINTER_LOCATION,
|
||||
CUPS_MSG_PRINTER_INFO,
|
||||
CUPS_MSG_PRINTER_MAKE_AND_MODEL,
|
||||
CUPS_MSG_DEVICE_URI,
|
||||
CUPS_MSG_FORMATTING_PAGE,
|
||||
CUPS_MSG_PRINTING_PAGE,
|
||||
CUPS_MSG_INITIALIZING_PRINTER,
|
||||
CUPS_MSG_PRINTER_STATE,
|
||||
CUPS_MSG_ACCEPTING_JOBS,
|
||||
CUPS_MSG_NOT_ACCEPTING_JOBS,
|
||||
CUPS_MSG_PRINT_JOBS,
|
||||
CUPS_MSG_CLASS,
|
||||
CUPS_MSG_LOCAL,
|
||||
CUPS_MSG_REMOTE,
|
||||
CUPS_MSG_DUPLEXING,
|
||||
CUPS_MSG_STAPLING,
|
||||
CUPS_MSG_FAST_COPIES,
|
||||
CUPS_MSG_COLLATED_COPIES,
|
||||
CUPS_MSG_PUNCHING,
|
||||
CUPS_MSG_COVERING,
|
||||
CUPS_MSG_BINDING,
|
||||
CUPS_MSG_SORTING,
|
||||
CUPS_MSG_SMALL,
|
||||
CUPS_MSG_MEDIUM,
|
||||
CUPS_MSG_LARGE,
|
||||
CUPS_MSG_VARIABLE,
|
||||
CUPS_MSG_IDLE,
|
||||
CUPS_MSG_PROCESSING,
|
||||
CUPS_MSG_STOPPED,
|
||||
CUPS_MSG_ALL,
|
||||
CUPS_MSG_ODD,
|
||||
CUPS_MSG_EVEN_PAGES,
|
||||
CUPS_MSG_DARKER_LIGHTER,
|
||||
CUPS_MSG_MEDIA_SIZE,
|
||||
CUPS_MSG_MEDIA_TYPE,
|
||||
CUPS_MSG_MEDIA_SOURCE,
|
||||
CUPS_MSG_ORIENTATION,
|
||||
CUPS_MSG_PORTRAIT,
|
||||
CUPS_MSG_LANDSCAPE,
|
||||
CUPS_MSG_JOB_STATE,
|
||||
CUPS_MSG_JOB_NAME,
|
||||
CUPS_MSG_USER_NAME,
|
||||
CUPS_MSG_PRIORITY,
|
||||
CUPS_MSG_COPIES,
|
||||
CUPS_MSG_FILE_SIZE,
|
||||
CUPS_MSG_PENDING,
|
||||
CUPS_MSG_OUTPUT_MODE,
|
||||
CUPS_MSG_RESOLUTION,
|
||||
CUPS_MSG_HTTP_BASE = 200,
|
||||
CUPS_MSG_HTTP_END = 505,
|
||||
CUPS_MSG_MAX
|
||||
} cups_msg_t;
|
||||
|
||||
typedef enum /**** Language Encodings ****/
|
||||
{
|
||||
CUPS_US_ASCII,
|
||||
CUPS_ISO8859_1,
|
||||
CUPS_ISO8859_2,
|
||||
CUPS_ISO8859_3,
|
||||
CUPS_ISO8859_4,
|
||||
CUPS_ISO8859_5,
|
||||
CUPS_ISO8859_6,
|
||||
CUPS_ISO8859_7,
|
||||
CUPS_ISO8859_8,
|
||||
CUPS_ISO8859_9,
|
||||
CUPS_ISO8859_10,
|
||||
CUPS_UTF8
|
||||
} cups_encoding_t;
|
||||
|
||||
typedef struct cups_lang_str /**** Language Cache Structure ****/
|
||||
{
|
||||
struct cups_lang_str *next; /* Next language in cache */
|
||||
int used; /* Number of times this entry has been used. */
|
||||
cups_encoding_t encoding; /* Text encoding */
|
||||
char language[16]; /* Language/locale name */
|
||||
char *messages[CUPS_MSG_MAX];
|
||||
/* Message array */
|
||||
} cups_lang_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
# ifdef WIN32
|
||||
# define cupsLangDefault() cupsLangGet(setlocale(LC_ALL, ""))
|
||||
# else /* This fix works around bugs in the Linux and HP-UX setlocale() */
|
||||
# define cupsLangDefault() cupsLangGet(getenv("LANG"))
|
||||
# endif /* WIN32 */
|
||||
|
||||
extern char *cupsLangEncoding(cups_lang_t *lang);
|
||||
extern void cupsLangFlush(void);
|
||||
extern void cupsLangFree(cups_lang_t *lang);
|
||||
extern cups_lang_t *cupsLangGet(const char *language);
|
||||
# define cupsLangString(lang,msg) (lang)->messages[(msg)]
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
|
||||
#endif /* !_CUPS_LANGUAGE_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-412
@@ -1,412 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Option marking routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* PostScript is a trademark of Adobe Systems, Inc.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ppdConflicts() - Check to see if there are any conflicts.
|
||||
* ppdFindChoice() - Return a pointer to an option choice.
|
||||
* ppdFindMarkedChoice() - Return the marked choice for the specified option.
|
||||
* ppdFindOption() - Return a pointer to the specified option.
|
||||
* ppdIsMarked() - Check to see if an option is marked...
|
||||
* ppdMarkDefaults() - Mark all default options in the PPD file.
|
||||
* ppdMarkOption() - Mark an option in a PPD file.
|
||||
* ppd_defaults() - Set the defaults for this group and all sub-groups.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "ppd.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void ppd_defaults(ppd_file_t *ppd, ppd_group_t *g);
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdConflicts()' - Check to see if there are any conflicts.
|
||||
*/
|
||||
|
||||
int /* O - Number of conflicts found */
|
||||
ppdConflicts(ppd_file_t *ppd) /* I - PPD to check */
|
||||
{
|
||||
int i, j, k, /* Looping variables */
|
||||
conflicts; /* Number of conflicts */
|
||||
ppd_const_t *c; /* Current constraint */
|
||||
ppd_group_t *g, *sg; /* Groups */
|
||||
ppd_option_t *o1, *o2; /* Options */
|
||||
ppd_choice_t *c1, *c2; /* Choices */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Clear all conflicts...
|
||||
*/
|
||||
|
||||
conflicts = 0;
|
||||
|
||||
for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
|
||||
{
|
||||
for (j = g->num_options, o1 = g->options; j > 0; j --, o1 ++)
|
||||
o1->conflicted = 0;
|
||||
|
||||
for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
|
||||
for (k = sg->num_options, o1 = sg->options; k > 0; k --, o1 ++)
|
||||
o1->conflicted = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop through all of the UI constraints and flag any options
|
||||
* that conflict...
|
||||
*/
|
||||
|
||||
for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
|
||||
{
|
||||
/*
|
||||
* Grab pointers to the first option...
|
||||
*/
|
||||
|
||||
o1 = ppdFindOption(ppd, c->option1);
|
||||
|
||||
if (o1 == NULL)
|
||||
continue;
|
||||
else if (c->choice1[0] != '\0')
|
||||
{
|
||||
/*
|
||||
* This constraint maps to a specific choice.
|
||||
*/
|
||||
|
||||
c1 = ppdFindChoice(o1, c->choice1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* This constraint applies to any choice for this option.
|
||||
*/
|
||||
|
||||
for (j = o1->num_choices, c1 = o1->choices; j > 0; j --, c1 ++)
|
||||
if (c1->marked)
|
||||
break;
|
||||
|
||||
if (j == 0)
|
||||
c1 = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Grab pointers to the second option...
|
||||
*/
|
||||
|
||||
o2 = ppdFindOption(ppd, c->option2);
|
||||
|
||||
if (o2 == NULL)
|
||||
continue;
|
||||
else if (c->choice2[0] != '\0')
|
||||
{
|
||||
/*
|
||||
* This constraint maps to a specific choice.
|
||||
*/
|
||||
|
||||
c2 = ppdFindChoice(o2, c->choice2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* This constraint applies to any choice for this option.
|
||||
*/
|
||||
|
||||
for (j = o2->num_choices, c2 = o2->choices; j > 0; j --, c2 ++)
|
||||
if (c2->marked)
|
||||
break;
|
||||
|
||||
if (j == 0)
|
||||
c2 = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If both options are marked then there is a conflict...
|
||||
*/
|
||||
|
||||
if (c1 != NULL && c1->marked &&
|
||||
c2 != NULL && c2->marked)
|
||||
{
|
||||
conflicts ++;
|
||||
o1->conflicted = 1;
|
||||
o2->conflicted = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of conflicts found...
|
||||
*/
|
||||
|
||||
return (conflicts);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdFindChoice()' - Return a pointer to an option choice.
|
||||
*/
|
||||
|
||||
ppd_choice_t * /* O - Choice pointer or NULL */
|
||||
ppdFindChoice(ppd_option_t *o, /* I - Pointer to option */
|
||||
const char *choice) /* I - Name of choice */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
ppd_choice_t *c; /* Current choice */
|
||||
|
||||
|
||||
if (o == NULL || choice == NULL)
|
||||
return (NULL);
|
||||
|
||||
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
|
||||
if (strcmp(c->choice, choice) == 0)
|
||||
return (c);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdFindMarkedChoice()' - Return the marked choice for the specified option.
|
||||
*/
|
||||
|
||||
ppd_choice_t * /* O - Pointer to choice or NULL */
|
||||
ppdFindMarkedChoice(ppd_file_t *ppd, /* I - PPD file */
|
||||
const char *option) /* I - Keyword/option name */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
ppd_option_t *o; /* Pointer to option */
|
||||
ppd_choice_t *c; /* Pointer to choice */
|
||||
|
||||
|
||||
if ((o = ppdFindOption(ppd, option)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
|
||||
if (c->marked)
|
||||
return (c);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdFindOption()' - Return a pointer to the specified option.
|
||||
*/
|
||||
|
||||
ppd_option_t * /* O - Pointer to option or NULL */
|
||||
ppdFindOption(ppd_file_t *ppd, /* I - PPD file data */
|
||||
const char *option) /* I - Option/Keyword name */
|
||||
{
|
||||
int i, j, k; /* Looping vars */
|
||||
ppd_option_t *o; /* Pointer to option */
|
||||
ppd_group_t *g, /* Pointer to group */
|
||||
*sg; /* Pointer to subgroup */
|
||||
|
||||
|
||||
if (ppd == NULL || option == NULL)
|
||||
return (NULL);
|
||||
|
||||
for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
|
||||
{
|
||||
for (j = g->num_options, o = g->options; j > 0; j --, o ++)
|
||||
if (strcmp(o->keyword, option) == 0)
|
||||
return (o);
|
||||
|
||||
for (j = g->num_subgroups, sg = g->subgroups; j > 0; j --, sg ++)
|
||||
for (k = sg->num_options, o = sg->options; k > 0; k --, o ++)
|
||||
if (strcmp(o->keyword, option) == 0)
|
||||
return (o);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdIsMarked()' - Check to see if an option is marked...
|
||||
*/
|
||||
|
||||
int /* O - Non-zero if option is marked */
|
||||
ppdIsMarked(ppd_file_t *ppd, /* I - PPD file data */
|
||||
const char *option, /* I - Option/Keyword name */
|
||||
const char *choice) /* I - Choice name */
|
||||
{
|
||||
ppd_option_t *o; /* Option pointer */
|
||||
ppd_choice_t *c; /* Choice pointer */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return (0);
|
||||
|
||||
if ((o = ppdFindOption(ppd, option)) == NULL)
|
||||
return (0);
|
||||
|
||||
if ((c = ppdFindChoice(o, choice)) == NULL)
|
||||
return (0);
|
||||
|
||||
return (c->marked);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdMarkDefaults()' - Mark all default options in the PPD file.
|
||||
*/
|
||||
|
||||
void
|
||||
ppdMarkDefaults(ppd_file_t *ppd)/* I - PPD file record */
|
||||
{
|
||||
int i; /* Looping variables */
|
||||
ppd_group_t *g; /* Current group */
|
||||
ppd_option_t *o; /* PageSize option */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return;
|
||||
|
||||
for (i = ppd->num_groups, g = ppd->groups; i > 0; i --, g ++)
|
||||
ppd_defaults(ppd, g);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdMarkOption()' - Mark an option in a PPD file.
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* -1 is returned if the given option would conflict with any currently
|
||||
* selected option.
|
||||
*/
|
||||
|
||||
int /* O - Number of conflicts */
|
||||
ppdMarkOption(ppd_file_t *ppd, /* I - PPD file record */
|
||||
const char *option, /* I - Keyword */
|
||||
const char *choice) /* I - Option name */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
ppd_option_t *o; /* Option pointer */
|
||||
ppd_choice_t *c; /* Choice pointer */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return (0);
|
||||
|
||||
if (strcmp(option, "PageSize") == 0 && strncmp(choice, "Custom.", 7) == 0)
|
||||
{
|
||||
/*
|
||||
* Handle variable page sizes...
|
||||
*/
|
||||
|
||||
ppdPageSize(ppd, choice);
|
||||
choice = "Custom";
|
||||
}
|
||||
|
||||
if ((o = ppdFindOption(ppd, option)) == NULL)
|
||||
return (0);
|
||||
|
||||
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
|
||||
if (strcmp(c->choice, choice) == 0)
|
||||
break;
|
||||
|
||||
if (i)
|
||||
{
|
||||
/*
|
||||
* Option found; mark it and then handle unmarking any other options.
|
||||
*/
|
||||
|
||||
c->marked = 1;
|
||||
|
||||
if (o->ui != PPD_UI_PICKMANY)
|
||||
for (i = o->num_choices, c = o->choices; i > 0; i --, c ++)
|
||||
if (strcmp(c->choice, choice) != 0)
|
||||
c->marked = 0;
|
||||
|
||||
if (strcmp(option, "PageSize") == 0 || strcmp(option, "PageRegion") == 0)
|
||||
{
|
||||
/*
|
||||
* Mark current page size...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ppd->num_sizes; i ++)
|
||||
ppd->sizes[i].marked = strcmp(ppd->sizes[i].name, choice) == 0;
|
||||
|
||||
/*
|
||||
* Unmark the current PageSize or PageRegion setting, as appropriate...
|
||||
*/
|
||||
|
||||
if (strcmp(option, "PageSize") == 0)
|
||||
{
|
||||
o = ppdFindOption(ppd, "PageRegion");
|
||||
for (i = 0; i < o->num_choices; i ++)
|
||||
o->choices[i].marked = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
o = ppdFindOption(ppd, "PageSize");
|
||||
for (i = 0; i < o->num_choices; i ++)
|
||||
o->choices[i].marked = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (ppdConflicts(ppd));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppd_defaults()' - Set the defaults for this group and all sub-groups.
|
||||
*/
|
||||
|
||||
static void
|
||||
ppd_defaults(ppd_file_t *ppd, /* I - PPD file */
|
||||
ppd_group_t *g) /* I - Group to default */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
ppd_option_t *o; /* Current option */
|
||||
ppd_group_t *sg; /* Current sub-group */
|
||||
|
||||
|
||||
if (g == NULL)
|
||||
return;
|
||||
|
||||
for (i = g->num_options, o = g->options; i > 0; i --, o ++)
|
||||
if (strcmp(o->keyword, "PageRegion") != 0)
|
||||
ppdMarkOption(ppd, o->keyword, o->defchoice);
|
||||
|
||||
for (i = g->num_subgroups, sg = g->subgroups; i > 0; i --, sg ++)
|
||||
ppd_defaults(ppd, sg);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-617
@@ -1,617 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* MIME database file routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* mimeDelete() - Delete (free) a MIME database.
|
||||
* mimeMerge() - Merge a MIME database from disk with the current one.
|
||||
* mimeNew() - Create a new, empty MIME database.
|
||||
* load_types() - Load a xyz.types file...
|
||||
* delete_rules() - Free all memory for the given rule tree.
|
||||
* load_convs() - Load a xyz.convs file...
|
||||
*
|
||||
* Revision History:
|
||||
*
|
||||
* $Log: mime.c,v $
|
||||
* Revision 1.14 1999/07/12 16:09:38 mike
|
||||
* Fixed all constant arrays to use "const" modifier.
|
||||
*
|
||||
* Revision 1.13 1999/06/18 18:36:10 mike
|
||||
* Fixed address to 44141 Airport View Drive...
|
||||
*
|
||||
* Revision 1.12 1999/04/21 21:19:33 mike
|
||||
* Changes for HP-UX.
|
||||
*
|
||||
* Revision 1.11 1999/04/21 19:31:29 mike
|
||||
* Changed the directory header stuff to use the autoconf-recommended
|
||||
* sequence of #ifdef's.
|
||||
*
|
||||
* Changed the language routines to look for the LOCALEDIR environment
|
||||
* variable, and if it is not defined to use the LOCALEDIR string defined
|
||||
* in config.h.
|
||||
*
|
||||
* Revision 1.10 1999/03/01 20:51:53 mike
|
||||
* Code cleanup - removed extraneous semi-colons...
|
||||
*
|
||||
* Revision 1.9 1999/02/26 22:00:51 mike
|
||||
* Added more debug statements.
|
||||
*
|
||||
* Fixed bugs in cupsPrintFile() - wasn't setting the IPP_TAG_MIMETYPE
|
||||
* value tag for the file type.
|
||||
*
|
||||
* Updated conversion filter code to handle wildcards for super-type.
|
||||
*
|
||||
* Revision 1.8 1999/02/20 16:04:38 mike
|
||||
* Updated mime.c to scan directories under WIN32.
|
||||
*
|
||||
* Fixed some compiler warnings under WIN32.
|
||||
*
|
||||
* Updated VC++ project files.
|
||||
*
|
||||
* Updated mime.types and mime.convs files for actual registered
|
||||
* MIME type names.
|
||||
*
|
||||
* Revision 1.7 1999/02/05 17:40:53 mike
|
||||
* Added IPP client read/write code.
|
||||
*
|
||||
* Added string functions missing from some UNIXs.
|
||||
*
|
||||
* Added option parsing functions.
|
||||
*
|
||||
* Added IPP convenience functions (not implemented yet).
|
||||
*
|
||||
* Updated source files to use local string.h as needed (for
|
||||
* missing string functions)
|
||||
*
|
||||
* Revision 1.6 1999/02/01 22:08:39 mike
|
||||
* Restored original directory-scanning functionality of mimeLoad().
|
||||
*
|
||||
* Revision 1.4 1999/01/27 18:31:56 mike
|
||||
* Updated PPD routines to handle emulations and patch files.
|
||||
*
|
||||
* Added DSC comments to emit output as appropriate.
|
||||
*
|
||||
* Revision 1.3 1999/01/24 14:18:43 mike
|
||||
* Check-in prior to CVS use.
|
||||
*
|
||||
* Revision 1.2 1998/08/06 14:38:38 mike
|
||||
* Finished coding and testing for CUPS 1.0.
|
||||
*
|
||||
* Revision 1.1 1998/06/11 20:50:53 mike
|
||||
* Initial revision
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "string.h"
|
||||
#include "mime.h"
|
||||
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
# include <windows.h>
|
||||
#elif HAVE_DIRENT_H
|
||||
# include <dirent.h>
|
||||
typedef struct dirent DIRENT;
|
||||
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
||||
#else
|
||||
# if HAVE_SYS_NDIR_H
|
||||
# include <sys/ndir.h>
|
||||
# endif
|
||||
# if HAVE_SYS_DIR_H
|
||||
# include <sys/dir.h>
|
||||
# endif
|
||||
# if HAVE_NDIR_H
|
||||
# include <ndir.h>
|
||||
# endif
|
||||
typedef struct direct DIRENT;
|
||||
# define NAMLEN(dirent) (dirent)->d_namlen
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void load_types(mime_t *mime, char *filename);
|
||||
static void load_convs(mime_t *mime, char *filename);
|
||||
static void delete_rules(mime_magic_t *rules);
|
||||
|
||||
|
||||
/*
|
||||
* 'mimeDelete()' - Delete (free) a MIME database.
|
||||
*/
|
||||
|
||||
void
|
||||
mimeDelete(mime_t *mime) /* I - MIME database */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
if (mime == NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Loop through the file types and delete any rules...
|
||||
*/
|
||||
|
||||
for (i = 0; i < mime->num_types; i ++)
|
||||
{
|
||||
delete_rules(mime->types[i]->rules);
|
||||
free(mime->types[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the types and filters arrays, and then the MIME database structure.
|
||||
*/
|
||||
|
||||
free(mime->types);
|
||||
free(mime->filters);
|
||||
free(mime);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'mimeMerge()' - Merge a MIME database from disk with the current one.
|
||||
*/
|
||||
|
||||
mime_t * /* O - Updated MIME database */
|
||||
mimeMerge(mime_t *mime, /* I - MIME database to add to */
|
||||
const char *pathname) /* I - Directory to load */
|
||||
{
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
HANDLE dir; /* Directory handle */
|
||||
WIN32_FIND_DATA dent; /* Directory entry */
|
||||
char filename[1024], /* Full filename of types/converts file */
|
||||
*pathsep; /* Last character in path */
|
||||
|
||||
|
||||
/*
|
||||
* First open the directory specified by pathname... Return NULL if nothing
|
||||
* was read or if the pathname is NULL...
|
||||
*/
|
||||
|
||||
if (pathname == NULL)
|
||||
return (NULL);
|
||||
|
||||
strcpy(filename, pathname);
|
||||
pathsep = filename + strlen(filename);
|
||||
if (pathsep == filename ||
|
||||
(pathsep[-1] != '/' && pathsep[-1] != '\\'))
|
||||
{
|
||||
strcpy(pathsep, "/");
|
||||
pathsep ++;
|
||||
}
|
||||
|
||||
strcpy(pathsep, "*.types");
|
||||
|
||||
if ((dir = FindFirstFile(filename, &dent)) == 0)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* If "mime" is NULL, make a new, blank database...
|
||||
*/
|
||||
|
||||
if (mime == NULL)
|
||||
if ((mime = mimeNew()) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Read all the .types files...
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
/*
|
||||
* Load a mime.types file...
|
||||
*/
|
||||
|
||||
strcpy(pathsep, dent.cFileName);
|
||||
load_types(mime, filename);
|
||||
}
|
||||
while (FindNextFile(dir, &dent));
|
||||
|
||||
FindClose(dir);
|
||||
|
||||
/*
|
||||
* Read all the .convs files...
|
||||
*/
|
||||
|
||||
strcpy(pathsep, "*.convs");
|
||||
|
||||
if ((dir = FindFirstFile(filename, &dent)) == 0)
|
||||
return (mime);
|
||||
|
||||
do
|
||||
{
|
||||
/*
|
||||
* Load a mime.convs file...
|
||||
*/
|
||||
|
||||
strcpy(pathsep, dent.cFileName);
|
||||
load_convs(mime, filename);
|
||||
}
|
||||
while (FindNextFile(dir, &dent));
|
||||
|
||||
FindClose(dir);
|
||||
|
||||
return (mime);
|
||||
#else
|
||||
DIR *dir; /* Directory */
|
||||
DIRENT *dent; /* Directory entry */
|
||||
char filename[1024]; /* Full filename of types/converts file */
|
||||
|
||||
|
||||
/*
|
||||
* First open the directory specified by pathname... Return NULL if nothing
|
||||
* was read or if the pathname is NULL...
|
||||
*/
|
||||
|
||||
if (pathname == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((dir = opendir(pathname)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* If "mime" is NULL, make a new, blank database...
|
||||
*/
|
||||
|
||||
if (mime == NULL)
|
||||
if ((mime = mimeNew()) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Read all the .types files...
|
||||
*/
|
||||
|
||||
while ((dent = readdir(dir)) != NULL)
|
||||
{
|
||||
if (NAMLEN(dent) > 6 &&
|
||||
strcmp(dent->d_name + NAMLEN(dent) - 6, ".types") == 0)
|
||||
{
|
||||
/*
|
||||
* Load a mime.types file...
|
||||
*/
|
||||
|
||||
sprintf(filename, "%s/%s", pathname, dent->d_name);
|
||||
load_types(mime, filename);
|
||||
}
|
||||
}
|
||||
|
||||
rewinddir(dir);
|
||||
|
||||
/*
|
||||
* Read all the .convs files...
|
||||
*/
|
||||
|
||||
while ((dent = readdir(dir)) != NULL)
|
||||
{
|
||||
if (NAMLEN(dent) > 6 &&
|
||||
strcmp(dent->d_name + NAMLEN(dent) - 6, ".convs") == 0)
|
||||
{
|
||||
/*
|
||||
* Load a mime.convs file...
|
||||
*/
|
||||
|
||||
sprintf(filename, "%s/%s", pathname, dent->d_name);
|
||||
load_convs(mime, filename);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
return (mime);
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'mimeNew()' - Create a new, empty MIME database.
|
||||
*/
|
||||
|
||||
mime_t * /* O - MIME database */
|
||||
mimeNew(void)
|
||||
{
|
||||
return ((mime_t *)calloc(1, sizeof(mime_t)));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'load_types()' - Load a xyz.types file...
|
||||
*/
|
||||
|
||||
static void
|
||||
load_types(mime_t *mime, /* I - MIME database */
|
||||
char *filename) /* I - Types file to load */
|
||||
{
|
||||
FILE *fp; /* Types file */
|
||||
int linelen; /* Length of line */
|
||||
char line[65536], /* Input line from file */
|
||||
*lineptr, /* Current position in line */
|
||||
super[MIME_MAX_SUPER], /* Super-type name */
|
||||
type[MIME_MAX_TYPE], /* Type name */
|
||||
*temp; /* Temporary pointer */
|
||||
mime_type_t *typeptr; /* New MIME type */
|
||||
|
||||
|
||||
/*
|
||||
* First try to open the file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Then read each line from the file, skipping any comments in the file...
|
||||
*/
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL)
|
||||
{
|
||||
linelen = strlen(line);
|
||||
|
||||
/*
|
||||
* While the last character in the line is a backslash, continue on to the
|
||||
* next line (and the next, etc.)
|
||||
*/
|
||||
|
||||
if (line[linelen - 1] == '\n')
|
||||
{
|
||||
line[linelen - 1] = '\0';
|
||||
linelen --;
|
||||
}
|
||||
|
||||
while (line[linelen - 1] == '\\')
|
||||
{
|
||||
linelen --;
|
||||
|
||||
if (fgets(line + linelen, sizeof(line) - linelen, fp) == NULL)
|
||||
line[linelen] = '\0';
|
||||
else
|
||||
{
|
||||
linelen += strlen(line + linelen);
|
||||
if (line[linelen - 1] == '\n')
|
||||
{
|
||||
line[linelen - 1] = '\0';
|
||||
linelen --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip blank lines and lines starting with a #...
|
||||
*/
|
||||
|
||||
if (line[0] == '\n' || line[0] == '#')
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Extract the super-type and type names from the beginning of the line.
|
||||
*/
|
||||
|
||||
lineptr = line;
|
||||
temp = super;
|
||||
|
||||
while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' &&
|
||||
(temp - super + 1) < MIME_MAX_SUPER)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
if (*lineptr != '/')
|
||||
continue;
|
||||
|
||||
lineptr ++;
|
||||
temp = type;
|
||||
|
||||
while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' &&
|
||||
*lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
/*
|
||||
* Add the type and rules to the MIME database...
|
||||
*/
|
||||
|
||||
typeptr = mimeAddType(mime, super, type);
|
||||
mimeAddTypeRule(typeptr, lineptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'load_convs()' - Load a xyz.convs file...
|
||||
*/
|
||||
|
||||
static void
|
||||
load_convs(mime_t *mime, /* I - MIME database */
|
||||
char *filename) /* I - Convs file to load */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
FILE *fp; /* Convs file */
|
||||
char line[1024], /* Input line from file */
|
||||
*lineptr, /* Current position in line */
|
||||
super[MIME_MAX_SUPER], /* Super-type name */
|
||||
type[MIME_MAX_TYPE], /* Type name */
|
||||
*temp, /* Temporary pointer */
|
||||
*filter; /* Filter program */
|
||||
mime_type_t **temptype, /* MIME type looping var */
|
||||
*dsttype; /* Destination MIME type */
|
||||
int cost; /* Cost of filter */
|
||||
|
||||
|
||||
/*
|
||||
* First try to open the file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Then read each line from the file, skipping any comments in the file...
|
||||
*/
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL)
|
||||
{
|
||||
/*
|
||||
* Skip blank lines and lines starting with a #...
|
||||
*/
|
||||
|
||||
if (line[0] == '\n' || line[0] == '#')
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Extract the destination super-type and type names from the middle of
|
||||
* the line.
|
||||
*/
|
||||
|
||||
lineptr = line;
|
||||
while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\0')
|
||||
lineptr ++;
|
||||
|
||||
while (*lineptr == ' ' || *lineptr == '\t')
|
||||
lineptr ++;
|
||||
|
||||
temp = super;
|
||||
|
||||
while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' &&
|
||||
(temp - super + 1) < MIME_MAX_SUPER)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
if (*lineptr != '/')
|
||||
continue;
|
||||
|
||||
lineptr ++;
|
||||
temp = type;
|
||||
|
||||
while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' &&
|
||||
*lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
if (*lineptr == '\0' || *lineptr == '\n')
|
||||
continue;
|
||||
|
||||
if ((dsttype = mimeType(mime, super, type)) == NULL)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Then get the cost and filter program...
|
||||
*/
|
||||
|
||||
while (*lineptr == ' ' || *lineptr == '\t')
|
||||
lineptr ++;
|
||||
|
||||
if (*lineptr < '0' || *lineptr > '9')
|
||||
continue;
|
||||
|
||||
cost = atoi(lineptr);
|
||||
|
||||
while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\0')
|
||||
lineptr ++;
|
||||
while (*lineptr == ' ' || *lineptr == '\t')
|
||||
lineptr ++;
|
||||
|
||||
if (*lineptr == '\0' || *lineptr == '\n')
|
||||
continue;
|
||||
|
||||
filter = lineptr;
|
||||
if (filter[strlen(filter) - 1] == '\n')
|
||||
filter[strlen(filter) - 1] = '\0';
|
||||
|
||||
/*
|
||||
* Finally, get the source super-type and type names from the beginning of
|
||||
* the line. We do it here so we can support wildcards...
|
||||
*/
|
||||
|
||||
lineptr = line;
|
||||
temp = super;
|
||||
|
||||
while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' &&
|
||||
(temp - super + 1) < MIME_MAX_SUPER)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
if (*lineptr != '/')
|
||||
continue;
|
||||
|
||||
lineptr ++;
|
||||
temp = type;
|
||||
|
||||
while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' &&
|
||||
*lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE)
|
||||
*temp++ = tolower(*lineptr++);
|
||||
|
||||
*temp = '\0';
|
||||
|
||||
/*
|
||||
* Add the filter to the MIME database, supporting wildcards as needed...
|
||||
*/
|
||||
|
||||
for (temptype = mime->types, i = 0; i < mime->num_types; i ++, temptype ++)
|
||||
if ((super[0] == '*' || strcmp((*temptype)->super, super) == 0) &&
|
||||
(type[0] == '*' || strcmp((*temptype)->type, type) == 0))
|
||||
mimeAddFilter(mime, *temptype, dsttype, cost, filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'delete_rules()' - Free all memory for the given rule tree.
|
||||
*/
|
||||
|
||||
static void
|
||||
delete_rules(mime_magic_t *rules) /* I - Rules to free */
|
||||
{
|
||||
mime_magic_t *next; /* Next rule to free */
|
||||
|
||||
|
||||
/*
|
||||
* Free the rules list, descending recursively to free any child rules.
|
||||
*/
|
||||
|
||||
while (rules != NULL)
|
||||
{
|
||||
next = rules->next;
|
||||
|
||||
if (rules->child != NULL)
|
||||
delete_rules(rules->child);
|
||||
|
||||
free(rules);
|
||||
rules = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-137
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* MIME type/conversion database definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _MIME_H_
|
||||
# define _MIME_H_
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef _cplusplus
|
||||
extern "C" {
|
||||
# endif /* _cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
# define MIME_MAX_SUPER 16 /* Maximum size of supertype name */
|
||||
# define MIME_MAX_TYPE 32 /* Maximum size of type name */
|
||||
# define MIME_MAX_FILTER 256 /* Maximum size of filter pathname */
|
||||
# define MIME_MAX_BUFFER 8192 /* Maximum size of file buffer */
|
||||
|
||||
|
||||
/*
|
||||
* Types/structures...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MIME_MAGIC_NOP, /* No operation */
|
||||
MIME_MAGIC_AND, /* Logical AND of all children */
|
||||
MIME_MAGIC_OR, /* Logical OR of all children */
|
||||
MIME_MAGIC_MATCH, /* Filename match */
|
||||
MIME_MAGIC_ASCII, /* ASCII characters in range */
|
||||
MIME_MAGIC_PRINTABLE, /* Printable characters (32-255) in range */
|
||||
MIME_MAGIC_STRING, /* String matches */
|
||||
MIME_MAGIC_CHAR, /* Character/byte matches */
|
||||
MIME_MAGIC_SHORT, /* Short/16-bit word matches */
|
||||
MIME_MAGIC_INT, /* Integer/32-bit word matches */
|
||||
MIME_MAGIC_LOCALE /* Current locale matches string */
|
||||
} mime_op_t;
|
||||
|
||||
typedef struct mime_magic_str /**** MIME Magic Data ****/
|
||||
{
|
||||
struct mime_magic_str *prev, /* Previous rule */
|
||||
*next, /* Next rule */
|
||||
*parent, /* Parent rules */
|
||||
*child; /* Child rules */
|
||||
short op, /* Operation code (see above) */
|
||||
invert; /* Invert the result */
|
||||
int offset, /* Offset in file */
|
||||
length; /* Length of data */
|
||||
union
|
||||
{
|
||||
char matchv[64]; /* Match value */
|
||||
char localev[64]; /* Locale value */
|
||||
char stringv[64]; /* String value */
|
||||
char charv; /* Byte value */
|
||||
short shortv; /* Short value */
|
||||
int intv; /* Integer value */
|
||||
} value;
|
||||
} mime_magic_t;
|
||||
|
||||
typedef struct /**** MIME Type Data ****/
|
||||
{
|
||||
char super[MIME_MAX_SUPER], /* Super-type name ("image", "application", etc.) */
|
||||
type[MIME_MAX_TYPE]; /* Type name ("png", "postscript", etc.) */
|
||||
mime_magic_t *rules; /* Rules used to detect this type */
|
||||
} mime_type_t;
|
||||
|
||||
typedef struct /**** MIME Conversion Filter Data ****/
|
||||
{
|
||||
mime_type_t *src, /* Source type */
|
||||
*dst; /* Destination type */
|
||||
int cost; /* Relative cost */
|
||||
char filter[MIME_MAX_FILTER];/* Filter program to use */
|
||||
} mime_filter_t;
|
||||
|
||||
typedef struct /**** MIME Database ****/
|
||||
{
|
||||
int num_types; /* Number of file types */
|
||||
mime_type_t **types; /* File types */
|
||||
int num_filters; /* Number of type conversion filters */
|
||||
mime_filter_t *filters; /* Type conversion filters */
|
||||
} mime_t;
|
||||
|
||||
|
||||
/*
|
||||
* Functions...
|
||||
*/
|
||||
|
||||
extern void mimeDelete(mime_t *mime);
|
||||
#define mimeLoad(pathname) mimeMerge((mime_t *)0, (pathname));
|
||||
extern mime_t *mimeMerge(mime_t *mime, const char *pathname);
|
||||
extern mime_t *mimeNew(void);
|
||||
|
||||
extern mime_type_t *mimeAddType(mime_t *mime, const char *super, const char *type);
|
||||
extern int mimeAddTypeRule(mime_type_t *mt, const char *rule);
|
||||
extern mime_type_t *mimeFileType(mime_t *mime, const char *pathname);
|
||||
extern mime_type_t *mimeType(mime_t *mime, const char *super, const char *type);
|
||||
|
||||
extern mime_filter_t *mimeAddFilter(mime_t *mime, mime_type_t *src, mime_type_t *dst,
|
||||
int cost, const char *filter);
|
||||
extern mime_filter_t *mimeFilter(mime_t *mime, mime_type_t *src, mime_type_t *dst,
|
||||
int *num_filters);
|
||||
|
||||
# ifdef _cplusplus
|
||||
}
|
||||
# endif /* _cplusplus */
|
||||
#endif /* !_MIME_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,378 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Option routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* cupsAddOption() - Add an option to an option array.
|
||||
* cupsFreeOptions() - Free all memory used by options.
|
||||
* cupsGetOption() - Get an option value.
|
||||
* cupsParseOptions() - Parse options from a command-line argument.
|
||||
* cupsMarkOptions() - Mark command-line options in a PPD file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "cups.h"
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "string.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsAddOption()' - Add an option to an option array.
|
||||
*/
|
||||
|
||||
int /* O - Number of options */
|
||||
cupsAddOption(const char *name, /* I - Name of option */
|
||||
const char *value, /* I - Value of option */
|
||||
int num_options, /* I - Number of options */
|
||||
cups_option_t **options) /* IO - Pointer to options */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
cups_option_t *temp; /* Pointer to new option */
|
||||
|
||||
|
||||
if (name == NULL || value == NULL || options == NULL)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Look for an existing option with the same name...
|
||||
*/
|
||||
|
||||
for (i = 0, temp = *options; i < num_options; i ++, temp ++)
|
||||
if (strcmp(temp->name, name) == 0)
|
||||
break;
|
||||
|
||||
if (i >= num_options)
|
||||
{
|
||||
/*
|
||||
* No matching option name...
|
||||
*/
|
||||
|
||||
if (num_options == 0)
|
||||
temp = (cups_option_t *)malloc(sizeof(cups_option_t));
|
||||
else
|
||||
temp = (cups_option_t *)realloc(*options, sizeof(cups_option_t) *
|
||||
(num_options + 1));
|
||||
|
||||
if (temp == NULL)
|
||||
return (0);
|
||||
|
||||
*options = temp;
|
||||
temp += num_options;
|
||||
temp->name = strdup(name);
|
||||
num_options ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Match found; free the old value...
|
||||
*/
|
||||
|
||||
free(temp->value);
|
||||
}
|
||||
|
||||
temp->value = strdup(value);
|
||||
|
||||
return (num_options);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsFreeOptions()' - Free all memory used by options.
|
||||
*/
|
||||
|
||||
void
|
||||
cupsFreeOptions(int num_options, /* I - Number of options */
|
||||
cups_option_t *options) /* I - Pointer to options */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
if (num_options == 0 || options == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; i < num_options; i ++)
|
||||
{
|
||||
free(options[i].name);
|
||||
free(options[i].value);
|
||||
}
|
||||
|
||||
free(options);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetOption()' - Get an option value.
|
||||
*/
|
||||
|
||||
const char * /* O - Option value or NULL */
|
||||
cupsGetOption(const char *name, /* I - Name of option */
|
||||
int num_options,/* I - Number of options */
|
||||
cups_option_t *options) /* I - Options */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
if (name == NULL || num_options == 0 || options == NULL)
|
||||
return (NULL);
|
||||
|
||||
for (i = 0; i < num_options; i ++)
|
||||
if (strcmp(options[i].name, name) == 0)
|
||||
return (options[i].value);
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsParseOptions()' - Parse options from a command-line argument.
|
||||
*/
|
||||
|
||||
int /* O - Number of options found */
|
||||
cupsParseOptions(const char *arg, /* I - Argument to parse */
|
||||
int num_options, /* I - Number of options */
|
||||
cups_option_t **options) /* O - Options found */
|
||||
{
|
||||
char *copyarg, /* Copy of input string */
|
||||
*ptr, /* Pointer into string */
|
||||
*name, /* Pointer to name */
|
||||
*value; /* Pointer to value */
|
||||
|
||||
|
||||
if (arg == NULL || options == NULL)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Make a copy of the argument string and then divide it up...
|
||||
*/
|
||||
|
||||
copyarg = strdup(arg);
|
||||
ptr = copyarg;
|
||||
|
||||
while (*ptr != '\0')
|
||||
{
|
||||
/*
|
||||
* Get the name up to a SPACE, =, or end-of-string...
|
||||
*/
|
||||
|
||||
name = ptr;
|
||||
while (!isspace(*ptr) && *ptr != '=' && *ptr != '\0')
|
||||
ptr ++;
|
||||
|
||||
/*
|
||||
* Skip trailing spaces...
|
||||
*/
|
||||
|
||||
while (isspace(*ptr))
|
||||
*ptr++ = '\0';
|
||||
|
||||
if (*ptr != '=')
|
||||
{
|
||||
/*
|
||||
* Start of another option...
|
||||
*/
|
||||
|
||||
num_options = cupsAddOption(name, "", num_options, options);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove = and parse the value...
|
||||
*/
|
||||
|
||||
*ptr++ = '\0';
|
||||
|
||||
if (*ptr == '\'')
|
||||
{
|
||||
/*
|
||||
* Quoted string constant...
|
||||
*/
|
||||
|
||||
ptr ++;
|
||||
value = ptr;
|
||||
|
||||
while (*ptr != '\'' && *ptr != '\0')
|
||||
ptr ++;
|
||||
|
||||
if (*ptr != '\0')
|
||||
*ptr++ = '\0';
|
||||
}
|
||||
else if (*ptr == '\"')
|
||||
{
|
||||
/*
|
||||
* Double-quoted string constant...
|
||||
*/
|
||||
|
||||
ptr ++;
|
||||
value = ptr;
|
||||
|
||||
while (*ptr != '\"' && *ptr != '\0')
|
||||
ptr ++;
|
||||
|
||||
if (*ptr != '\0')
|
||||
*ptr++ = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Normal space-delimited string...
|
||||
*/
|
||||
|
||||
value = ptr;
|
||||
|
||||
while (!isspace(*ptr) && *ptr != '\0')
|
||||
ptr ++;
|
||||
|
||||
while (isspace(*ptr))
|
||||
*ptr++ = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the string value...
|
||||
*/
|
||||
|
||||
num_options = cupsAddOption(name, value, num_options, options);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the copy of the argument we made and return the number of options
|
||||
* found.
|
||||
*/
|
||||
|
||||
free(copyarg);
|
||||
|
||||
return (num_options);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsMarkOptions()' - Mark command-line options in a PPD file.
|
||||
*/
|
||||
|
||||
int /* O - 1 if conflicting */
|
||||
cupsMarkOptions(ppd_file_t *ppd, /* I - PPD file */
|
||||
int num_options, /* I - Number of options */
|
||||
cups_option_t *options) /* I - Options */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
int conflict; /* Option conflicts */
|
||||
char *val, /* Pointer into value */
|
||||
*ptr, /* Pointer into string */
|
||||
s[255]; /* Temporary string */
|
||||
|
||||
|
||||
conflict = 0;
|
||||
|
||||
for (i = num_options; i > 0; i --, options ++)
|
||||
if (strcmp(options->name, "media") == 0)
|
||||
{
|
||||
/*
|
||||
* Loop through the option string, separating it at commas and
|
||||
* marking each individual option.
|
||||
*/
|
||||
|
||||
for (val = options->value; *val;)
|
||||
{
|
||||
/*
|
||||
* Extract the sub-option from the string...
|
||||
*/
|
||||
|
||||
for (ptr = s; *val && *val != ',' && (ptr - s) < (sizeof(s) - 1);)
|
||||
*ptr++ = *val++;
|
||||
*ptr++ = '\0';
|
||||
|
||||
if (*val == ',')
|
||||
val ++;
|
||||
|
||||
/*
|
||||
* Mark it...
|
||||
*/
|
||||
|
||||
if (ppdMarkOption(ppd, "PageSize", s))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "InputSlot", s))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "MediaType", s))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "EFMediaQualityMode", s)) /* EFI */
|
||||
conflict = 1;
|
||||
if (strcasecmp(s, "manual") == 0)
|
||||
if (ppdMarkOption(ppd, "ManualFeed", "True"))
|
||||
conflict = 1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(options->name, "sides") == 0)
|
||||
{
|
||||
if (strcmp(options->value, "one-sided") == 0)
|
||||
{
|
||||
if (ppdMarkOption(ppd, "Duplex", "None"))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "EFDuplex", "None")) /* EFI */
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "KD03Duplex", "None")) /* Kodak */
|
||||
conflict = 1;
|
||||
}
|
||||
else if (strcmp(options->value, "two-sided-long-edge") == 0)
|
||||
{
|
||||
if (ppdMarkOption(ppd, "Duplex", "DuplexNoTumble"))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "EFDuplex", "DuplexNoTumble")) /* EFI */
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "KD03Duplex", "DuplexNoTumble")) /* Kodak */
|
||||
conflict = 1;
|
||||
}
|
||||
else if (strcmp(options->value, "two-sided-short-edge") == 0)
|
||||
{
|
||||
if (ppdMarkOption(ppd, "Duplex", "DuplexTumble"))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "EFDuplex", "DuplexTumble")) /* EFI */
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "KD03Duplex", "DuplexTumble")) /* Kodak */
|
||||
conflict = 1;
|
||||
}
|
||||
}
|
||||
else if (strcmp(options->name, "resolution") == 0)
|
||||
{
|
||||
if (ppdMarkOption(ppd, "Resolution", options->value))
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "SetResolution", options->value))
|
||||
/* Calcomp, Linotype, QMS, Summagraphics, Tektronix, Varityper */
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "JCLResolution", options->value)) /* HP */
|
||||
conflict = 1;
|
||||
if (ppdMarkOption(ppd, "CNRes_PGP", options->value)) /* Canon */
|
||||
conflict = 1;
|
||||
}
|
||||
else if (ppdMarkOption(ppd, options->name, options->value))
|
||||
conflict = 1;
|
||||
|
||||
return (conflict);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-189
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Page size functions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* PostScript is a trademark of Adobe Systems, Inc.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ppdPageSize() - Get the page size record for the given size.
|
||||
* ppdPageWidth() - Get the page width for the given size.
|
||||
* ppdPageLength() - Get the page length for the given size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "ppd.h"
|
||||
#include "string.h"
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdPageSize()' - Get the page size record for the given size.
|
||||
*/
|
||||
|
||||
ppd_size_t * /* O - Size record for page or NULL */
|
||||
ppdPageSize(ppd_file_t *ppd, /* I - PPD file record */
|
||||
const char *name) /* I - Size name */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
float w, l; /* Width and length of page */
|
||||
char units[255]; /* Page size units... */
|
||||
|
||||
|
||||
if (ppd == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
if (strncmp(name, "Custom.", 7) == 0 && ppd->variable_sizes)
|
||||
{
|
||||
/*
|
||||
* Find the custom page size...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ppd->num_sizes; i ++)
|
||||
if (strcmp("Custom", ppd->sizes[i].name) == 0)
|
||||
break;
|
||||
|
||||
if (i == ppd->num_sizes)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Variable size; size name can be one of the following:
|
||||
*
|
||||
* Custom.WIDTHxLENGTHin - Size in inches
|
||||
* Custom.WIDTHxLENGTHcm - Size in centimeters
|
||||
* Custom.WIDTHxLENGTHmm - Size in millimeters
|
||||
* Custom.WIDTHxLENGTH[pt] - Size in points
|
||||
*/
|
||||
|
||||
units[0] = '\0';
|
||||
if (sscanf(name + 7, "%fx%f%s", &w, &l, units) < 2)
|
||||
return (NULL);
|
||||
|
||||
if (strcasecmp(units, "in") == 0)
|
||||
{
|
||||
ppd->sizes[i].width = w * 72.0;
|
||||
ppd->sizes[i].length = l * 72.0;
|
||||
ppd->sizes[i].left = ppd->custom_margins[0];
|
||||
ppd->sizes[i].bottom = ppd->custom_margins[1];
|
||||
ppd->sizes[i].right = w * 72.0 - ppd->custom_margins[2];
|
||||
ppd->sizes[i].top = l * 72.0 - ppd->custom_margins[3];
|
||||
}
|
||||
else if (strcasecmp(units, "cm") == 0)
|
||||
{
|
||||
ppd->sizes[i].width = w * 2.54 * 72.0;
|
||||
ppd->sizes[i].length = l * 2.54 * 72.0;
|
||||
ppd->sizes[i].left = ppd->custom_margins[0];
|
||||
ppd->sizes[i].bottom = ppd->custom_margins[1];
|
||||
ppd->sizes[i].right = w * 2.54 * 72.0 - ppd->custom_margins[2];
|
||||
ppd->sizes[i].top = l * 2.54 * 72.0 - ppd->custom_margins[3];
|
||||
}
|
||||
else if (strcasecmp(units, "mm") == 0)
|
||||
{
|
||||
ppd->sizes[i].width = w * 25.4 * 72.0;
|
||||
ppd->sizes[i].length = l * 25.4 * 72.0;
|
||||
ppd->sizes[i].left = ppd->custom_margins[0];
|
||||
ppd->sizes[i].bottom = ppd->custom_margins[1];
|
||||
ppd->sizes[i].right = w * 25.4 * 72.0 - ppd->custom_margins[2];
|
||||
ppd->sizes[i].top = l * 25.4 * 72.0 - ppd->custom_margins[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
ppd->sizes[i].width = w;
|
||||
ppd->sizes[i].length = l;
|
||||
ppd->sizes[i].left = ppd->custom_margins[0];
|
||||
ppd->sizes[i].bottom = ppd->custom_margins[1];
|
||||
ppd->sizes[i].right = w - ppd->custom_margins[2];
|
||||
ppd->sizes[i].top = l - ppd->custom_margins[3];
|
||||
}
|
||||
|
||||
return (ppd->sizes + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Lookup by name...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ppd->num_sizes; i ++)
|
||||
if (strcmp(name, ppd->sizes[i].name) == 0)
|
||||
return (ppd->sizes + i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Find default...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ppd->num_sizes; i ++)
|
||||
if (ppd->sizes[i].marked)
|
||||
return (ppd->sizes + i);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdPageWidth()' - Get the page width for the given size.
|
||||
*/
|
||||
|
||||
float /* O - Width of page in points or 0.0 */
|
||||
ppdPageWidth(ppd_file_t *ppd, /* I - PPD file record */
|
||||
const char *name) /* I - Size name */
|
||||
{
|
||||
ppd_size_t *size; /* Page size */
|
||||
|
||||
|
||||
if ((size = ppdPageSize(ppd, name)) == NULL)
|
||||
return (0.0);
|
||||
else
|
||||
return (size->width);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ppdPageLength()' - Get the page length for the given size.
|
||||
*/
|
||||
|
||||
float /* O - Length of page in points or 0.0 */
|
||||
ppdPageLength(ppd_file_t *ppd, /* I - PPD file */
|
||||
const char *name) /* I - Size name */
|
||||
{
|
||||
ppd_size_t *size; /* Page size */
|
||||
|
||||
|
||||
if ((size = ppdPageSize(ppd, name)) == NULL)
|
||||
return (0.0);
|
||||
else
|
||||
return (size->length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-1771
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
-239
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PostScript Printer Description definitions for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* PostScript is a trademark of Adobe Systems, Inc.
|
||||
*
|
||||
* This code and any derivative of it may be used and distributed
|
||||
* freely under the terms of the GNU General Public License when
|
||||
* used with GNU Ghostscript or its derivatives. Use of the code
|
||||
* (or any derivative of it) with software other than GNU
|
||||
* GhostScript (or its derivatives) is governed by the CUPS license
|
||||
* agreement.
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_PPD_H_
|
||||
# define _CUPS_PPD_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <stdio.h>
|
||||
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
|
||||
/*
|
||||
* PPD version...
|
||||
*/
|
||||
|
||||
# define PPD_VERSION 4.3 /* Kept in sync with Adobe version number */
|
||||
|
||||
|
||||
/*
|
||||
* Types and structures...
|
||||
*/
|
||||
|
||||
typedef enum /**** UI types ****/
|
||||
{
|
||||
PPD_UI_BOOLEAN, /* True or False option */
|
||||
PPD_UI_PICKONE, /* Pick one from a list */
|
||||
PPD_UI_PICKMANY /* Pick zero or more from a list */
|
||||
} ppd_ui_t;
|
||||
|
||||
typedef enum /**** Order dependency sections ****/
|
||||
{
|
||||
PPD_ORDER_ANY, /* Option code can be anywhere in the file */
|
||||
PPD_ORDER_DOCUMENT, /* ... must be in the DocumentSetup section */
|
||||
PPD_ORDER_EXIT, /* ... must be sent prior to the document */
|
||||
PPD_ORDER_JCL, /* ... must be sent as a JCL command */
|
||||
PPD_ORDER_PAGE, /* ... must be in the PageSetup section */
|
||||
PPD_ORDER_PROLOG /* ... must be in the Prolog section */
|
||||
} ppd_section_t;
|
||||
|
||||
typedef enum /**** Colorspaces ****/
|
||||
{
|
||||
PPD_CS_CMYK = -4, /* CMYK colorspace */
|
||||
PPD_CS_CMY, /* CMY colorspace */
|
||||
PPD_CS_GRAY = 1, /* Grayscale colorspace */
|
||||
PPD_CS_RGB = 3, /* RGB colorspace */
|
||||
PPD_CS_RGBK, /* RGBK (K = gray) colorspace */
|
||||
PPD_CS_N /* DeviceN colorspace */
|
||||
} ppd_cs_t;
|
||||
|
||||
typedef struct /**** Option choices ****/
|
||||
{
|
||||
char marked, /* 0 if not selected, 1 otherwise */
|
||||
choice[41], /* Computer-readable option name */
|
||||
text[81], /* Human-readable option name */
|
||||
*code; /* Code to send for this option */
|
||||
void *option; /* Pointer to parent option structure */
|
||||
} ppd_choice_t;
|
||||
|
||||
typedef struct /**** Options ****/
|
||||
{
|
||||
char conflicted, /* 0 if no conflicts exist, 1 otherwise */
|
||||
keyword[41], /* Option keyword name ("PageSize", etc.) */
|
||||
defchoice[41], /* Default option choice */
|
||||
text[81]; /* Human-readable text */
|
||||
ppd_ui_t ui; /* Type of UI option */
|
||||
ppd_section_t section; /* Section for command */
|
||||
float order; /* Order number */
|
||||
int num_choices; /* Number of option choices */
|
||||
ppd_choice_t *choices; /* Option choices */
|
||||
} ppd_option_t;
|
||||
|
||||
typedef struct ppd_group_str /**** Groups ****/
|
||||
{
|
||||
char text[81]; /* Human-readable group name */
|
||||
int num_options; /* Number of options */
|
||||
ppd_option_t *options; /* Options */
|
||||
int num_subgroups; /* Number of sub-groups */
|
||||
struct ppd_group_str *subgroups;
|
||||
/* Sub-groups (max depth = 1) */
|
||||
} ppd_group_t;
|
||||
|
||||
typedef struct /**** Constraints ****/
|
||||
{
|
||||
char option1[41], /* First keyword */
|
||||
choice1[41], /* First option/choice (blank for all) */
|
||||
option2[41], /* Second keyword */
|
||||
choice2[41]; /* Second option/choice (blank for all) */
|
||||
} ppd_const_t;
|
||||
|
||||
typedef struct /**** Page Sizes ****/
|
||||
{
|
||||
int marked; /* Page size selected? */
|
||||
char name[41]; /* Media size option */
|
||||
float width, /* Width of media in points */
|
||||
length, /* Length of media in points */
|
||||
left, /* Left printable margin in points */
|
||||
bottom, /* Bottom printable margin in points */
|
||||
right, /* Right printable margin in points */
|
||||
top; /* Top printable margin in points */
|
||||
} ppd_size_t;
|
||||
|
||||
typedef struct /**** Emulators ****/
|
||||
{
|
||||
char name[41], /* Emulator name */
|
||||
*start, /* Code to switch to this emulation */
|
||||
*stop; /* Code to stop this emulation */
|
||||
} ppd_emul_t;
|
||||
|
||||
typedef struct /**** sRGB Color Profiles ****/
|
||||
{
|
||||
char resolution[41], /* Resolution or "-" */
|
||||
media_type[41]; /* Media type of "-" */
|
||||
float density, /* Ink density to use */
|
||||
gamma, /* Gamma correction to use */
|
||||
matrix[3][3]; /* Transform matrix */
|
||||
} ppd_profile_t;
|
||||
|
||||
typedef struct /**** Files ****/
|
||||
{
|
||||
int language_level, /* Language level of device */
|
||||
color_device, /* 1 = color device, 0 = grayscale */
|
||||
variable_sizes, /* 1 = supports variable sizes, 0 = doesn't */
|
||||
accurate_screens,/* 1 = supports accurate screens, 0 = not */
|
||||
contone_only, /* 1 = continuous tone only, 0 = not */
|
||||
landscape, /* -90 or 90 */
|
||||
model_number, /* Device-specific model number */
|
||||
manual_copies; /* 1 = Copies done manually, 0 = hardware */
|
||||
ppd_cs_t colorspace; /* Default colorspace */
|
||||
char *patches; /* Patch commands to be sent to printer */
|
||||
int num_emulations; /* Number of emulations supported */
|
||||
ppd_emul_t *emulations; /* Emulations and the code to invoke them */
|
||||
char *jcl_begin, /* Start JCL commands */
|
||||
*jcl_ps, /* Enter PostScript interpreter */
|
||||
*jcl_end, /* End JCL commands */
|
||||
*lang_encoding, /* Language encoding */
|
||||
*lang_version, /* Language version (English, Spanish, etc.) */
|
||||
*modelname, /* Model name (general) */
|
||||
*ttrasterizer, /* Truetype rasterizer */
|
||||
*manufacturer, /* Manufacturer name */
|
||||
*product, /* Product name (from PS RIP/interpreter) */
|
||||
*nickname, /* Nickname (specific) */
|
||||
*shortnickname; /* Short version of nickname */
|
||||
int num_groups; /* Number of UI groups */
|
||||
ppd_group_t *groups; /* UI groups */
|
||||
int num_sizes; /* Number of page sizes */
|
||||
ppd_size_t *sizes; /* Page sizes */
|
||||
float custom_min[2], /* Minimum variable page size */
|
||||
custom_max[2], /* Maximum variable page size */
|
||||
custom_margins[4];/* Margins around page */
|
||||
int num_consts; /* Number of UI/Non-UI constraints */
|
||||
ppd_const_t *consts; /* UI/Non-UI constraints */
|
||||
int num_fonts; /* Number of pre-loaded fonts */
|
||||
char **fonts; /* Pre-loaded fonts */
|
||||
int num_profiles; /* Number of sRGB color profiles */
|
||||
ppd_profile_t *profiles; /* sRGB color profiles */
|
||||
int num_filters; /* Number of filters */
|
||||
char **filters; /* Filter strings... */
|
||||
} ppd_file_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
extern void ppdClose(ppd_file_t *ppd);
|
||||
extern int ppdConflicts(ppd_file_t *ppd);
|
||||
extern int ppdEmit(ppd_file_t *ppd, FILE *fp,
|
||||
ppd_section_t section);
|
||||
extern int ppdEmitFd(ppd_file_t *ppd, int fd,
|
||||
ppd_section_t section);
|
||||
extern int ppdIsMarked(ppd_file_t *ppd, const char *keyword,
|
||||
const char *option);
|
||||
extern void ppdMarkDefaults(ppd_file_t *ppd);
|
||||
extern int ppdMarkOption(ppd_file_t *ppd, const char *keyword,
|
||||
const char *option);
|
||||
extern ppd_choice_t *ppdFindChoice(ppd_option_t *o, const char *option);
|
||||
extern ppd_choice_t *ppdFindMarkedChoice(ppd_file_t *ppd, const char *keyword);
|
||||
extern ppd_option_t *ppdFindOption(ppd_file_t *ppd, const char *keyword);
|
||||
extern ppd_file_t *ppdOpen(FILE *fp);
|
||||
extern ppd_file_t *ppdOpenFd(int fd);
|
||||
extern ppd_file_t *ppdOpenFile(const char *filename);
|
||||
extern float ppdPageLength(ppd_file_t *ppd, const char *name);
|
||||
extern ppd_size_t *ppdPageSize(ppd_file_t *ppd, const char *name);
|
||||
extern float ppdPageWidth(ppd_file_t *ppd, const char *name);
|
||||
|
||||
/*
|
||||
* C++ magic...
|
||||
*/
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
#endif /* !_CUPS_PPD_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-252
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Raster file routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights for the CUPS Raster source
|
||||
* files are outlined in the GNU Library General Public License, located
|
||||
* in the "pstoraster" directory. If this file is missing or damaged
|
||||
* please contact Easy Software Products at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* This code and any derivative of it may be used and distributed
|
||||
* freely under the terms of the GNU General Public License when
|
||||
* used with GNU Ghostscript or its derivatives. Use of the code
|
||||
* (or any derivative of it) with software other than GNU
|
||||
* GhostScript (or its derivatives) is governed by the CUPS license
|
||||
* agreement.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* cupsRasterClose() - Close a raster stream.
|
||||
* cupsRasterOpen() - Open a raster stream.
|
||||
* cupsRasterReadHeader() - Read a raster page header.
|
||||
* cupsRasterReadPixels() - Read raster pixels.
|
||||
* cupsRasterWriteHeader() - Write a raster page header.
|
||||
* cupsRasterWritePixels() - Write raster pixels.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "raster.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterClose()' - Close a raster stream.
|
||||
*/
|
||||
|
||||
void
|
||||
cupsRasterClose(cups_raster_t *r) /* I - Stream to close */
|
||||
{
|
||||
if (r != NULL)
|
||||
free(r);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterOpen()' - Open a raster stream.
|
||||
*/
|
||||
|
||||
cups_raster_t * /* O - New stream */
|
||||
cupsRasterOpen(int fd, /* I - File descriptor */
|
||||
cups_mode_t mode) /* I - Mode */
|
||||
{
|
||||
cups_raster_t *r; /* New stream */
|
||||
|
||||
|
||||
if ((r = calloc(sizeof(cups_raster_t), 1)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
r->fd = fd;
|
||||
r->mode = mode;
|
||||
|
||||
if (mode == CUPS_RASTER_READ)
|
||||
{
|
||||
/*
|
||||
* Open for read - get sync word...
|
||||
*/
|
||||
|
||||
if (read(fd, &(r->sync), sizeof(r->sync)) < sizeof(r->sync))
|
||||
{
|
||||
free(r);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (r->sync != CUPS_RASTER_SYNC &&
|
||||
r->sync != CUPS_RASTER_REVSYNC)
|
||||
{
|
||||
free(r);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Open for write - put sync word...
|
||||
*/
|
||||
|
||||
r->sync = CUPS_RASTER_SYNC;
|
||||
if (write(fd, &(r->sync), sizeof(r->sync)) < sizeof(r->sync))
|
||||
{
|
||||
free(r);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterReadHeader()' - Read a raster page header.
|
||||
*/
|
||||
|
||||
unsigned /* O - 1 on success, 0 on fail */
|
||||
cupsRasterReadHeader(cups_raster_t *r, /* I - Raster stream */
|
||||
cups_page_header_t *h) /* I - Pointer to header data */
|
||||
{
|
||||
int len; /* Number of words to swap */
|
||||
union swap_s /* Swapping structure */
|
||||
{
|
||||
unsigned char b[4];
|
||||
unsigned v;
|
||||
} *s;
|
||||
|
||||
|
||||
if (r == NULL || r->mode != CUPS_RASTER_READ)
|
||||
return (0);
|
||||
|
||||
if (cupsRasterReadPixels(r, (unsigned char *)h, sizeof(cups_page_header_t)) <
|
||||
sizeof(cups_page_header_t))
|
||||
return (0);
|
||||
|
||||
if (r->sync == CUPS_RASTER_REVSYNC)
|
||||
for (len = (sizeof(cups_page_header_t) - 256) / 4,
|
||||
s = (union swap_s *)&(h->AdvanceDistance);
|
||||
len > 0;
|
||||
len --, s ++)
|
||||
s->v = (((((s->b[3] << 8) | s->b[2]) << 8) | s->b[1]) << 8) | s->b[0];
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterReadPixels()' - Read raster pixels.
|
||||
*/
|
||||
|
||||
unsigned /* O - Number of bytes read */
|
||||
cupsRasterReadPixels(cups_raster_t *r, /* I - Raster stream */
|
||||
unsigned char *p, /* I - Pointer to pixel buffer */
|
||||
unsigned len) /* I - Number of bytes to read */
|
||||
{
|
||||
int bytes; /* Bytes read */
|
||||
unsigned remaining; /* Bytes remaining */
|
||||
|
||||
|
||||
if (r == NULL || r->mode != CUPS_RASTER_READ)
|
||||
return (0);
|
||||
|
||||
remaining = len;
|
||||
|
||||
while (remaining > 0)
|
||||
{
|
||||
bytes = read(r->fd, p, remaining);
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
if (errno != EAGAIN && errno != EINTR)
|
||||
return (0);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
remaining -= bytes;
|
||||
p += bytes;
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterWriteHeader()' - Write a raster page header.
|
||||
*/
|
||||
|
||||
unsigned
|
||||
cupsRasterWriteHeader(cups_raster_t *r,
|
||||
cups_page_header_t *h)
|
||||
{
|
||||
if (r == NULL || r->mode != CUPS_RASTER_WRITE)
|
||||
return (0);
|
||||
|
||||
return (cupsRasterWritePixels(r, (unsigned char *)h,
|
||||
sizeof(cups_page_header_t)) ==
|
||||
sizeof(cups_page_header_t));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsRasterWritePixels()' - Write raster pixels.
|
||||
*/
|
||||
|
||||
unsigned /* O - Number of bytes written */
|
||||
cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */
|
||||
unsigned char *p, /* I - Bytes to write */
|
||||
unsigned len)/* I - Number of bytes to write */
|
||||
{
|
||||
int bytes; /* Bytes read */
|
||||
unsigned remaining; /* Bytes remaining */
|
||||
|
||||
|
||||
if (r == NULL || r->mode != CUPS_RASTER_WRITE)
|
||||
return (0);
|
||||
|
||||
remaining = len;
|
||||
|
||||
while (remaining > 0)
|
||||
{
|
||||
bytes = write(r->fd, p, remaining);
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
if (errno != EAGAIN && errno != EINTR)
|
||||
return (0);
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
remaining -= bytes;
|
||||
p += bytes;
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-233
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Raster file definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights for the CUPS Raster source
|
||||
* files are outlined in the GNU Library General Public License, located
|
||||
* in the "pstoraster" directory. If this file is missing or damaged
|
||||
* please contact Easy Software Products at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* This code and any derivative of it may be used and distributed
|
||||
* freely under the terms of the GNU General Public License when
|
||||
* used with GNU Ghostscript or its derivatives. Use of the code
|
||||
* (or any derivative of it) with software other than GNU
|
||||
* GhostScript (or its derivatives) is governed by the CUPS license
|
||||
* agreement.
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_RASTER_H_
|
||||
# define _CUPS_RASTER_H_
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Every non-PostScript printer driver that supports raster images should
|
||||
* use the application/vnd.cups-raster image file format. Since both the
|
||||
* PostScript RIP (pstoraster, based on GNU Ghostscript 4.03) and Image RIP
|
||||
* (imagetoraster, located in the filter directory) use it, using this format
|
||||
* saves you a lot of work. Also, the PostScript RIP passes any printer
|
||||
* options that are in a PS file to your driver this way as well...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
# define CUPS_RASTER_SYNC 0x52615374 /* RaSt */
|
||||
# define CUPS_RASTER_REVSYNC 0x74536152 /* tSaR */
|
||||
|
||||
|
||||
/*
|
||||
* Types...
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_RASTER_READ, /* Open stream for reading */
|
||||
CUPS_RASTER_WRITE /* Open stream for writing */
|
||||
} cups_mode_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_FALSE, /* Logical false */
|
||||
CUPS_TRUE /* Logical true */
|
||||
} cups_bool_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_JOG_NONE, /* Never move pages */
|
||||
CUPS_JOG_FILE, /* Move pages after this file */
|
||||
CUPS_JOG_JOB, /* Move pages after this job */
|
||||
CUPS_JOG_SET /* Move pages after this set */
|
||||
} cups_jog_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_ORIENT_0, /* Don't rotate the page */
|
||||
CUPS_ORIENT_90, /* Rotate the page counter-clockwise */
|
||||
CUPS_ORIENT_180, /* Turn the page upside down */
|
||||
CUPS_ORIENT_270 /* Rotate the page clockwise */
|
||||
} cups_orient_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_CUT_NONE, /* Never cut the roll */
|
||||
CUPS_CUT_FILE, /* Cut the roll after this file */
|
||||
CUPS_CUT_JOB, /* Cut the roll after this job */
|
||||
CUPS_CUT_SET, /* Cut the roll after this set */
|
||||
CUPS_CUT_PAGE /* Cut the roll after this page */
|
||||
} cups_cut_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_ADVANCE_NONE, /* Never advance the roll */
|
||||
CUPS_ADVANCE_FILE, /* Advance the roll after this file */
|
||||
CUPS_ADVANCE_JOB, /* Advance the roll after this job */
|
||||
CUPS_ADVANCE_SET, /* Advance the roll after this set */
|
||||
CUPS_ADVANCE_PAGE /* Advance the roll after this page */
|
||||
} cups_adv_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_EDGE_TOP, /* Leading edge is the top of the page */
|
||||
CUPS_EDGE_RIGHT, /* Leading edge is the right of the page */
|
||||
CUPS_EDGE_BOTTOM, /* Leading edge is the bottom of the page */
|
||||
CUPS_EDGE_LEFT /* Leading edge is the left of the page */
|
||||
} cups_edge_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_ORDER_CHUNKED, /* CMYK CMYK CMYK ... */
|
||||
CUPS_ORDER_BANDED, /* CCC MMM YYY KKK ... */
|
||||
CUPS_ORDER_PLANAR /* CCC ... MMM ... YYY ... KKK ... */
|
||||
} cups_order_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CUPS_CSPACE_W, /* Luminance */
|
||||
CUPS_CSPACE_RGB, /* Red, green, blue */
|
||||
CUPS_CSPACE_RGBA, /* Red, green, blue, alpha */
|
||||
CUPS_CSPACE_K, /* Black */
|
||||
CUPS_CSPACE_CMY, /* Cyan, magenta, yellow */
|
||||
CUPS_CSPACE_YMC, /* Yellow, magenta, cyan */
|
||||
CUPS_CSPACE_CMYK, /* Cyan, magenta, yellow, black */
|
||||
CUPS_CSPACE_YMCK, /* Yellow, magenta, cyan, black */
|
||||
CUPS_CSPACE_KCMY, /* Black, cyan, magenta, yellow */
|
||||
CUPS_CSPACE_KCMYcm, /* Black, cyan, magenta, yellow, *
|
||||
* light-cyan, light-magenta */
|
||||
CUPS_CSPACE_GMCK, /* Gold, magenta, yellow, black */
|
||||
CUPS_CSPACE_GMCS, /* Gold, magenta, yellow, silver */
|
||||
CUPS_CSPACE_WHITE, /* White ink (as black) */
|
||||
CUPS_CSPACE_GOLD, /* Gold foil */
|
||||
CUPS_CSPACE_SILVER /* Silver foil */
|
||||
} cups_cspace_t;
|
||||
|
||||
|
||||
/*
|
||||
* The page header structure contains the standard PostScript page device
|
||||
* dictionary, along with some CUPS-specific parameters that are provided
|
||||
* by the RIPs...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/**** Standard Page Device Dictionary String Values ****/
|
||||
char MediaClass[64]; /* MediaClass string */
|
||||
char MediaColor[64]; /* MediaColor string */
|
||||
char MediaType[64]; /* MediaType string */
|
||||
char OutputType[64]; /* OutputType string */
|
||||
|
||||
/**** Standard Page Device Dictionary Integer Values ****/
|
||||
unsigned AdvanceDistance; /* AdvanceDistance value in points */
|
||||
cups_adv_t AdvanceMedia; /* AdvanceMedia value (see above) */
|
||||
cups_bool_t Collate; /* Collated copies value */
|
||||
cups_cut_t CutMedia; /* CutMedia value (see above) */
|
||||
cups_bool_t Duplex; /* Duplexed (double-sided) value */
|
||||
unsigned HWResolution[2]; /* Resolution in dots-per-inch */
|
||||
unsigned ImagingBoundingBox[4]; /* Pixel region that is painted (points) */
|
||||
cups_bool_t InsertSheet; /* InsertSheet value */
|
||||
cups_jog_t Jog; /* Jog value (see above) */
|
||||
cups_edge_t LeadingEdge; /* LeadingEdge value (see above) */
|
||||
unsigned Margins[2]; /* Lower-lefthand margins in points */
|
||||
cups_bool_t ManualFeed; /* ManualFeed value */
|
||||
unsigned MediaPosition; /* MediaPosition value */
|
||||
unsigned MediaWeight; /* MediaWeight value in grams/m^2 */
|
||||
cups_bool_t MirrorPrint; /* MirrorPrint value */
|
||||
cups_bool_t NegativePrint; /* NegativePrint value */
|
||||
unsigned NumCopies; /* Number of copies to produce */
|
||||
cups_orient_t Orientation; /* Orientation value (see above) */
|
||||
cups_bool_t OutputFaceUp; /* OutputFaceUp value */
|
||||
unsigned PageSize[2]; /* Width and length of page in points */
|
||||
cups_bool_t Separations; /* Separations value */
|
||||
cups_bool_t TraySwitch; /* TraySwitch value */
|
||||
cups_bool_t Tumble; /* Tumble value */
|
||||
|
||||
/**** CUPS Page Device Dictionary Values ****/
|
||||
unsigned cupsWidth; /* Width of page image in pixels */
|
||||
unsigned cupsHeight; /* Height of page image in pixels */
|
||||
unsigned cupsMediaType; /* Media type code */
|
||||
unsigned cupsBitsPerColor; /* Number of bits for each color */
|
||||
unsigned cupsBitsPerPixel; /* Number of bits for each pixel */
|
||||
unsigned cupsBytesPerLine; /* Number of bytes per line */
|
||||
cups_order_t cupsColorOrder; /* Order of colors */
|
||||
cups_cspace_t cupsColorSpace; /* True colorspace */
|
||||
unsigned cupsCompression; /* Device compression to use */
|
||||
unsigned cupsRowCount; /* Rows per band */
|
||||
unsigned cupsRowFeed; /* Feed between bands */
|
||||
unsigned cupsRowStep; /* Spacing between lines */
|
||||
} cups_page_header_t;
|
||||
|
||||
|
||||
/*
|
||||
* The raster structure maintains information about a raster data
|
||||
* stream...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned sync; /* Sync word from start of stream */
|
||||
int fd; /* File descriptor */
|
||||
cups_mode_t mode; /* Read/write mode */
|
||||
} cups_raster_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
extern void cupsRasterClose(cups_raster_t *r);
|
||||
extern cups_raster_t *cupsRasterOpen(int fd, cups_mode_t mode);
|
||||
extern unsigned cupsRasterReadHeader(cups_raster_t *r,
|
||||
cups_page_header_t *h);
|
||||
extern unsigned cupsRasterReadPixels(cups_raster_t *r,
|
||||
unsigned char *p, unsigned len);
|
||||
extern unsigned cupsRasterWriteHeader(cups_raster_t *r,
|
||||
cups_page_header_t *h);
|
||||
extern unsigned cupsRasterWritePixels(cups_raster_t *r,
|
||||
unsigned char *p, unsigned len);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif /* __cplusplus */
|
||||
|
||||
#endif /* !_CUPS_RASTER_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* String functions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* strdup() - Duplicate a string.
|
||||
* strcasecmp() - Do a case-insensitive comparison.
|
||||
* strncasecmp() - Do a case-insensitive comparison on up to N chars.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'strdup()' - Duplicate a string.
|
||||
*/
|
||||
|
||||
# ifndef HAVE_STRDUP
|
||||
char * /* O - New string pointer */
|
||||
strdup(const char *s) /* I - String to duplicate */
|
||||
{
|
||||
char *t; /* New string pointer */
|
||||
|
||||
|
||||
if (s == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((t = malloc(strlen(s) + 1)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
return (strcpy(t, s));
|
||||
}
|
||||
# endif /* !HAVE_STRDUP */
|
||||
|
||||
|
||||
/*
|
||||
* 'strcasecmp()' - Do a case-insensitive comparison.
|
||||
*/
|
||||
|
||||
# ifndef HAVE_STRCASECMP
|
||||
int /* O - Result of comparison (-1, 0, or 1) */
|
||||
strcasecmp(const char *s, /* I - First string */
|
||||
const char *t) /* I - Second string */
|
||||
{
|
||||
while (*s != '\0' && *t != '\0')
|
||||
{
|
||||
if (tolower(*s) < tolower(*t))
|
||||
return (-1);
|
||||
else if (tolower(*s) > tolower(*t))
|
||||
return (1);
|
||||
|
||||
s ++;
|
||||
t ++;
|
||||
}
|
||||
|
||||
if (*s == '\0' && *t == '\0')
|
||||
return (0);
|
||||
else if (*s != '\0')
|
||||
return (1);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
# endif /* !HAVE_STRCASECMP */
|
||||
|
||||
/*
|
||||
* 'strncasecmp()' - Do a case-insensitive comparison on up to N chars.
|
||||
*/
|
||||
|
||||
# ifndef HAVE_STRNCASECMP
|
||||
int /* O - Result of comparison (-1, 0, or 1) */
|
||||
strncasecmp(const char *s, /* I - First string */
|
||||
const char *t, /* I - Second string */
|
||||
size_t n) /* I - Maximum number of characters to compare */
|
||||
{
|
||||
while (*s != '\0' && *t != '\0' && n > 0)
|
||||
{
|
||||
if (tolower(*s) < tolower(*t))
|
||||
return (-1);
|
||||
else if (tolower(*s) > tolower(*t))
|
||||
return (1);
|
||||
|
||||
s ++;
|
||||
t ++;
|
||||
n --;
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
return (0);
|
||||
else if (*s == '\0' && *t == '\0')
|
||||
return (0);
|
||||
else if (*s != '\0')
|
||||
return (1);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
# endif /* !HAVE_STRNCASECMP */
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* String definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _CUPS_STRING_H_
|
||||
# define _CUPS_STRING_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <config.h>
|
||||
# include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* Stuff for WIN32 and OS/2...
|
||||
*/
|
||||
|
||||
# if defined(WIN32) || defined(__EMX__)
|
||||
# define strcasecmp stricmp
|
||||
# define strncasecmp strnicmp
|
||||
# endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
# ifndef HAVE_STRDUP
|
||||
extern char *strdup(const char *);
|
||||
# endif /* !HAVE_STRDUP */
|
||||
|
||||
# ifndef HAVE_STRCASECMP
|
||||
extern int strcasecmp(const char *, const char *);
|
||||
# endif /* !HAVE_STRCASECMP */
|
||||
|
||||
# ifndef HAVE_STRNCASECMP
|
||||
extern int strncasecmp(const char *, const char *, size_t n);
|
||||
# endif /* !HAVE_STRNCASECMP */
|
||||
|
||||
#endif /* !_CUPS_STRING_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HTTP test program for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "http.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
http_t *http; /* HTTP connection */
|
||||
http_status_t status; /* Status of GET command */
|
||||
char buffer[1024]; /* Input buffer */
|
||||
int bytes; /* Number of bytes read */
|
||||
FILE *out; /* Output file */
|
||||
|
||||
#define HOST "dns.easysw.com"
|
||||
#define PORT 80
|
||||
|
||||
puts("Connecting to " HOST "...");
|
||||
|
||||
httpInitialize();
|
||||
http = httpConnect(HOST, PORT);
|
||||
if (http == NULL)
|
||||
{
|
||||
puts("Unable to connect to " HOST "!");
|
||||
return (1);
|
||||
}
|
||||
|
||||
puts("Connected to " HOST "...");
|
||||
|
||||
out = stdout;
|
||||
|
||||
for (i = 1; i < argc; i ++)
|
||||
{
|
||||
if (strcmp(argv[i], "-o") == 0)
|
||||
{
|
||||
i ++;
|
||||
out = fopen(argv[i], "wb");
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("Requesting file \"%s\"...\n", argv[i]);
|
||||
httpClearFields(http);
|
||||
httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
|
||||
httpGet(http, argv[i]);
|
||||
status = httpUpdate(http);
|
||||
|
||||
if (status == HTTP_OK)
|
||||
puts("GET OK:");
|
||||
else
|
||||
printf("GET failed with status %d...\n", status);
|
||||
|
||||
while ((bytes = httpRead(http, buffer, sizeof(buffer))) > 0)
|
||||
{
|
||||
fwrite(buffer, bytes, 1, out);
|
||||
if (out != stdout)
|
||||
printf("Read %d bytes, %d total...\n", bytes, ftell(out));
|
||||
}
|
||||
}
|
||||
|
||||
puts("Closing connection to server...");
|
||||
httpClose(http);
|
||||
|
||||
if (out != stdout)
|
||||
fclose(out);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* MIME test program for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry for the test program.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mime.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void print_rules(mime_magic_t *rules);
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry for the test program.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line args */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
char super[MIME_MAX_SUPER], /* Super-type name */
|
||||
type[MIME_MAX_TYPE]; /* Type name */
|
||||
mime_t *mime; /* MIME database */
|
||||
mime_type_t *src, /* Source type */
|
||||
*dst, /* Destination type */
|
||||
**types; /* File type array pointer */
|
||||
mime_filter_t *filters; /* Filters for the file */
|
||||
int num_filters; /* Number of filters for the file */
|
||||
|
||||
|
||||
mime = mimeLoad("../conf");
|
||||
|
||||
puts("MIME database types:");
|
||||
for (i = 0, types = mime->types; i < mime->num_types; i ++, types ++)
|
||||
{
|
||||
printf("\t%s/%s: ", (*types)->super, (*types)->type);
|
||||
print_rules((*types)->rules);
|
||||
puts("");
|
||||
}
|
||||
|
||||
puts("");
|
||||
|
||||
puts("MIME database filters:");
|
||||
for (i = 0, filters = mime->filters; i < mime->num_filters; i ++, filters ++)
|
||||
printf("\t%s/%s to %s/%s: %s (%d)\n",
|
||||
filters->src->super, filters->src->type,
|
||||
filters->dst->super, filters->dst->type,
|
||||
filters->filter, filters->cost);
|
||||
|
||||
puts("");
|
||||
|
||||
switch (argc)
|
||||
{
|
||||
default :
|
||||
fputs("Usage: testmime source-file [destination-type]\n", stderr);
|
||||
return (1);
|
||||
|
||||
case 2 :
|
||||
src = mimeFileType(mime, argv[1]);
|
||||
|
||||
if (src != NULL)
|
||||
{
|
||||
printf("%s: %s/%s\n", argv[1], src->super, src->type);
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s: unknown\n", argv[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
case 3 :
|
||||
src = mimeFileType(mime, argv[1]);
|
||||
|
||||
sscanf(argv[2], "%[^/]/%s", super, type);
|
||||
dst = mimeType(mime, super, type);
|
||||
|
||||
filters = mimeFilter(mime, src, dst, &num_filters);
|
||||
|
||||
if (filters == NULL)
|
||||
{
|
||||
printf("No filters to convert from %s to %s.\n", argv[1], argv[2]);
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < num_filters; i ++)
|
||||
if (i < (num_filters - 1))
|
||||
printf("%s | ", filters[i].filter);
|
||||
else
|
||||
puts(filters[i].filter);
|
||||
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'print_rules()' - Print the rules for a file type...
|
||||
*/
|
||||
|
||||
static void
|
||||
print_rules(mime_magic_t *rules) /* I - Rules to print */
|
||||
{
|
||||
char logic; /* Logic separator */
|
||||
|
||||
|
||||
if (rules == NULL)
|
||||
return;
|
||||
|
||||
if (rules->parent == NULL ||
|
||||
rules->parent->op == MIME_MAGIC_OR)
|
||||
logic = ',';
|
||||
else
|
||||
logic = '+';
|
||||
|
||||
while (rules != NULL)
|
||||
{
|
||||
if (rules->prev != NULL)
|
||||
putchar(logic);
|
||||
|
||||
switch (rules->op)
|
||||
{
|
||||
case MIME_MAGIC_MATCH :
|
||||
printf("match(%s)", rules->value.matchv);
|
||||
break;
|
||||
case MIME_MAGIC_LOCALE :
|
||||
printf("locale(%s)", rules->value.localev);
|
||||
break;
|
||||
case MIME_MAGIC_ASCII :
|
||||
printf("ascii(%d,%d)", rules->offset, rules->length);
|
||||
break;
|
||||
case MIME_MAGIC_PRINTABLE :
|
||||
printf("printable(%d,%d)", rules->offset, rules->length);
|
||||
break;
|
||||
case MIME_MAGIC_STRING :
|
||||
printf("string(%d,%s)", rules->offset, rules->value.stringv);
|
||||
break;
|
||||
case MIME_MAGIC_CHAR :
|
||||
printf("char(%d,%d)", rules->offset, rules->value.charv);
|
||||
break;
|
||||
case MIME_MAGIC_SHORT :
|
||||
printf("short(%d,%d)", rules->offset, rules->value.shortv);
|
||||
break;
|
||||
case MIME_MAGIC_INT :
|
||||
printf("int(%d,%d)", rules->offset, rules->value.intv);
|
||||
break;
|
||||
default :
|
||||
if (rules->child != NULL)
|
||||
{
|
||||
putchar('(');
|
||||
print_rules(rules->child);
|
||||
putchar(')');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rules = rules->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,102 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="testmime" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=testmime - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "testmime.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "testmime.mak" CFG="testmime - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "testmime - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "testmime - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "testmime - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 cups.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"testmime.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "testmime - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "testmime___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "testmime___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 cupsd.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"testmimed.exe" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "testmime - Win32 Release"
|
||||
# Name "testmime - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\testmime.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mime.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PPD test program for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products, all rights reserved.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* PostScript is a trademark of Adobe Systems, Inc.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry for test program.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "cups.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry for test program.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
int i, j, k, m, n; /* Looping vars */
|
||||
const char *filename; /* File to load */
|
||||
ppd_file_t *ppd; /* PPD file record */
|
||||
ppd_size_t *size; /* Size record */
|
||||
ppd_group_t *group; /* UI group */
|
||||
ppd_option_t *option; /* Standard UI option */
|
||||
ppd_choice_t *choice; /* Standard UI option choice */
|
||||
static char *uis[] = { "BOOLEAN", "PICKONE", "PICKMANY" };
|
||||
static char *sections[] = { "ANY", "DOCUMENT", "EXIT",
|
||||
"JCL", "PAGE", "PROLOG" };
|
||||
|
||||
|
||||
/*
|
||||
* Display PPD files for each file listed on the command-line...
|
||||
*/
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
fputs("Usage: ppdtest filename1.ppd [... filenameN.ppd]\n", stderr);
|
||||
return (1);
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i ++)
|
||||
{
|
||||
if (strstr(argv[i], ".ppd"))
|
||||
filename = argv[i];
|
||||
else
|
||||
filename = cupsGetPPD(argv[i]);
|
||||
|
||||
if ((ppd = ppdOpenFile(filename)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Unable to open \'%s\' as a PPD file!\n", filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("FILE: %s\n", filename);
|
||||
printf(" language_level = %d\n", ppd->language_level);
|
||||
printf(" color_device = %s\n", ppd->color_device ? "TRUE" : "FALSE");
|
||||
printf(" variable_sizes = %s\n", ppd->variable_sizes ? "TRUE" : "FALSE");
|
||||
printf(" landscape = %d\n", ppd->landscape);
|
||||
|
||||
switch (ppd->colorspace)
|
||||
{
|
||||
case PPD_CS_CMYK :
|
||||
puts(" colorspace = PPD_CS_CMYK");
|
||||
break;
|
||||
case PPD_CS_CMY :
|
||||
puts(" colorspace = PPD_CS_CMY");
|
||||
break;
|
||||
case PPD_CS_GRAY :
|
||||
puts(" colorspace = PPD_CS_GRAY");
|
||||
break;
|
||||
case PPD_CS_RGB :
|
||||
puts(" colorspace = PPD_CS_RGB");
|
||||
break;
|
||||
default :
|
||||
puts(" colorspace = <unknown>");
|
||||
break;
|
||||
}
|
||||
|
||||
printf(" num_emulations = %d\n", ppd->num_emulations);
|
||||
for (j = 0; j < ppd->num_emulations; j ++)
|
||||
printf(" emulations[%d] = %s\n", j, ppd->emulations[j].name);
|
||||
|
||||
printf(" lang_encoding = %s\n", ppd->lang_encoding);
|
||||
printf(" lang_version = %s\n", ppd->lang_version);
|
||||
printf(" modelname = %s\n", ppd->modelname);
|
||||
printf(" ttrasterizer = %s\n",
|
||||
ppd->ttrasterizer == NULL ? "None" : ppd->ttrasterizer);
|
||||
printf(" manufacturer = %s\n", ppd->manufacturer);
|
||||
printf(" product = %s\n", ppd->product);
|
||||
printf(" nickname = %s\n", ppd->nickname);
|
||||
printf(" shortnickname = %s\n", ppd->shortnickname);
|
||||
printf(" patches = %d bytes\n",
|
||||
ppd->patches == NULL ? 0 : strlen(ppd->patches));
|
||||
|
||||
printf(" num_groups = %d\n", ppd->num_groups);
|
||||
for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
|
||||
{
|
||||
printf(" group[%d] = %s\n", j, group->text);
|
||||
|
||||
for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
|
||||
{
|
||||
printf(" options[%d] = %s (%s) %s %s %.0f\n", k,
|
||||
option->keyword, option->text, uis[option->ui],
|
||||
sections[option->section], option->order);
|
||||
|
||||
if (strcmp(option->keyword, "PageSize") == 0 ||
|
||||
strcmp(option->keyword, "PageRegion") == 0)
|
||||
{
|
||||
for (m = option->num_choices, choice = option->choices;
|
||||
m > 0;
|
||||
m --, choice ++)
|
||||
{
|
||||
size = ppdPageSize(ppd, choice->choice);
|
||||
|
||||
if (size == NULL)
|
||||
printf(" %s (%s) = ERROR", choice->choice, choice->text);
|
||||
else
|
||||
printf(" %s (%s) = %.2fx%.2fin (%.1f,%.1f,%.1f,%.1f)", choice->choice,
|
||||
choice->text, size->width / 72.0, size->length / 72.0,
|
||||
size->left / 72.0, size->bottom / 72.0,
|
||||
size->right / 72.0, size->top / 72.0);
|
||||
|
||||
if (strcmp(option->defchoice, choice->choice) == 0)
|
||||
puts(" *");
|
||||
else
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (m = option->num_choices, choice = option->choices;
|
||||
m > 0;
|
||||
m --, choice ++)
|
||||
{
|
||||
printf(" %s (%s)", choice->choice, choice->text);
|
||||
|
||||
if (strcmp(option->defchoice, choice->choice) == 0)
|
||||
puts(" *");
|
||||
else
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ppdClose(ppd);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,102 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="testppd" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=testppd - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "testppd.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "testppd.mak" CFG="testppd - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "testppd - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "testppd - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "testppd - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 cups.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"testppd.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "testppd - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "testppd___Win32_Debug"
|
||||
# PROP BASE Intermediate_Dir "testppd___Win32_Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 cupsd.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /debug /machine:I386 /out:"testppdd.exe" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "testppd - Win32 Release"
|
||||
# Name "testppd - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\testppd.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ppd.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
-1011
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* User, system, and password routines for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "cups.h"
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
/*
|
||||
* WIN32 and OS/2 username and password stuff...
|
||||
*/
|
||||
|
||||
/*
|
||||
* 'cupsUser()' - Return the current user's name.
|
||||
*/
|
||||
|
||||
const char * /* O - User name */
|
||||
cupsUser(void)
|
||||
{
|
||||
return ("WindowsUser");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetPassword()' - Get a password from the user...
|
||||
*/
|
||||
|
||||
const char * /* O - Password */
|
||||
cupsGetPassword(const char *prompt) /* I - Prompt string */
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* UNIX username and password stuff...
|
||||
*/
|
||||
|
||||
# include <pwd.h>
|
||||
|
||||
/*
|
||||
* 'cupsUser()' - Return the current user's name.
|
||||
*/
|
||||
|
||||
const char * /* O - User name */
|
||||
cupsUser(void)
|
||||
{
|
||||
struct passwd *pwd; /* User/password entry */
|
||||
|
||||
|
||||
/*
|
||||
* Rewind the password file...
|
||||
*/
|
||||
|
||||
setpwent();
|
||||
|
||||
/*
|
||||
* Lookup the password entry for the current user.
|
||||
*/
|
||||
|
||||
if ((pwd = getpwuid(getuid())) == NULL)
|
||||
return ("unknown"); /* Unknown user! */
|
||||
|
||||
/*
|
||||
* Rewind the password file again and return the username...
|
||||
*/
|
||||
|
||||
setpwent();
|
||||
|
||||
return (pwd->pw_name);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetPassword()' - Get a password from the user...
|
||||
*/
|
||||
|
||||
const char * /* O - Password */
|
||||
cupsGetPassword(const char *prompt) /* I - Prompt string */
|
||||
{
|
||||
return (getpass(prompt));
|
||||
}
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsServer()' - Return the hostname of the default server...
|
||||
*/
|
||||
|
||||
const char * /* O - Server name */
|
||||
cupsServer(void)
|
||||
{
|
||||
FILE *fp; /* cupsd.conf file */
|
||||
char *server; /* Pointer to server name */
|
||||
static char line[1024]; /* Line from file */
|
||||
|
||||
|
||||
/*
|
||||
* First see if the CUPS_SERVER environment variable is set...
|
||||
*/
|
||||
|
||||
if ((server = getenv("CUPS_SERVER")) != NULL)
|
||||
return (server);
|
||||
|
||||
/*
|
||||
* Next check to see if we have a cupsd.conf file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(CUPS_SERVERROOT "/conf/cupsd.conf", "r")) == NULL)
|
||||
return ("localhost");
|
||||
|
||||
/*
|
||||
* Read the cupsd.conf file and look for a ServerName line...
|
||||
*/
|
||||
|
||||
while (fgets(line, sizeof(line), fp) != NULL)
|
||||
if (strncmp(line, "ServerName ", 11) == 0)
|
||||
{
|
||||
/*
|
||||
* Got it! Drop any trailing newline and find the name...
|
||||
*/
|
||||
|
||||
server = line + strlen(line) - 1;
|
||||
if (*server == '\n')
|
||||
*server = '\0';
|
||||
|
||||
for (server = line + 11; isspace(*server); server ++);
|
||||
|
||||
if (*server)
|
||||
return (server);
|
||||
}
|
||||
|
||||
/*
|
||||
* Didn't see a ServerName line, so return "localhost"...
|
||||
*/
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return ("localhost");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
-986
@@ -1,986 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Printing utilities for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* cupsCancelJob() - Cancel a print job.
|
||||
* cupsDoFileRequest() - Do an IPP request...
|
||||
* cupsGetClasses() - Get a list of printer classes.
|
||||
* cupsGetDefault() - Get the default printer or class.
|
||||
* cupsGetPPD() - Get the PPD file for a printer.
|
||||
* cupsGetPrinters() - Get a list of printers.
|
||||
* cupsPrintFile() - Print a file to a printer or class.
|
||||
* cups_connect() - Connect to the specified host...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "cups.h"
|
||||
#include "ipp.h"
|
||||
#include "language.h"
|
||||
#include "string.h"
|
||||
#include "debug.h"
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
|
||||
|
||||
/*
|
||||
* Local globals...
|
||||
*/
|
||||
|
||||
static http_t *cups_server = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static char *cups_connect(const char *name, char *printer, char *hostname);
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsCancelJob()' - Cancel a print job.
|
||||
*/
|
||||
|
||||
int /* O - 1 on success, 0 on failure */
|
||||
cupsCancelJob(const char *name, /* I - Name of printer or class */
|
||||
int job) /* I - Job ID */
|
||||
{
|
||||
char printer[HTTP_MAX_URI], /* Printer name */
|
||||
hostname[HTTP_MAX_URI], /* Hostname */
|
||||
uri[HTTP_MAX_URI]; /* Printer URI */
|
||||
ipp_t *request, /* IPP request */
|
||||
*response; /* IPP response */
|
||||
cups_lang_t *language; /* Language info */
|
||||
|
||||
|
||||
/*
|
||||
* See if we can connect to the server...
|
||||
*/
|
||||
|
||||
if (!cups_connect(name, printer, hostname))
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Build an IPP_CANCEL_JOB request, which requires the following
|
||||
* attributes:
|
||||
*
|
||||
* attributes-charset
|
||||
* attributes-natural-language
|
||||
* printer-uri
|
||||
* job-id
|
||||
*/
|
||||
|
||||
request = ippNew();
|
||||
|
||||
request->request.op.operation_id = IPP_CANCEL_JOB;
|
||||
request->request.op.request_id = 1;
|
||||
|
||||
language = cupsLangDefault();
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
|
||||
"attributes-charset", NULL, cupsLangEncoding(language));
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
|
||||
"attributes-natural-language", NULL,
|
||||
language != NULL ? language->language : "C");
|
||||
|
||||
sprintf(uri, "ipp://%s:%d/printers/%s", hostname, ippPort(), printer);
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
|
||||
NULL, uri);
|
||||
|
||||
ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", job);
|
||||
|
||||
/*
|
||||
* Do the request...
|
||||
*/
|
||||
|
||||
if ((response = cupsDoRequest(cups_server, request, "/jobs/")) == NULL)
|
||||
return (0);
|
||||
|
||||
ippDelete(response);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsDoFileRequest()' - Do an IPP request...
|
||||
*/
|
||||
|
||||
ipp_t * /* O - Response data */
|
||||
cupsDoFileRequest(http_t *http, /* I - HTTP connection to server */
|
||||
ipp_t *request, /* I - IPP request */
|
||||
const char *resource, /* I - HTTP resource for POST */
|
||||
const char *filename) /* I - File to send or NULL */
|
||||
{
|
||||
ipp_t *response; /* IPP response data */
|
||||
char length[255]; /* Content-Length field */
|
||||
http_status_t status; /* Status of HTTP request */
|
||||
FILE *file; /* File to send */
|
||||
struct stat fileinfo; /* File information */
|
||||
int bytes; /* Number of bytes read/written */
|
||||
char buffer[8192]; /* Output buffer */
|
||||
const char *password; /* Password string */
|
||||
char plain[255], /* Plaintext username:password */
|
||||
encode[255]; /* Encoded username:password */
|
||||
static char authstring[255] = "";
|
||||
/* Authorization string */
|
||||
|
||||
|
||||
DEBUG_printf(("cupsDoFileRequest(%08x, %08s, \'%s\', \'%s\')\n",
|
||||
http, request, resource, filename ? filename : "(null)"));
|
||||
|
||||
/*
|
||||
* See if we have a file to send...
|
||||
*/
|
||||
|
||||
if (filename != NULL)
|
||||
{
|
||||
if (stat(filename, &fileinfo))
|
||||
{
|
||||
/*
|
||||
* Can't get file information!
|
||||
*/
|
||||
|
||||
ippDelete(request);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((file = fopen(filename, "rb")) == NULL)
|
||||
{
|
||||
/*
|
||||
* Can't open file!
|
||||
*/
|
||||
|
||||
ippDelete(request);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop until we can send the request without authorization problems.
|
||||
*/
|
||||
|
||||
response = NULL;
|
||||
|
||||
while (response == NULL)
|
||||
{
|
||||
DEBUG_puts("cupsDoFileRequest: setup...");
|
||||
|
||||
/*
|
||||
* Setup the HTTP variables needed...
|
||||
*/
|
||||
|
||||
if (filename != NULL)
|
||||
sprintf(length, "%u", ippLength(request) + (size_t)fileinfo.st_size);
|
||||
else
|
||||
sprintf(length, "%u", ippLength(request));
|
||||
|
||||
httpClearFields(http);
|
||||
httpSetField(http, HTTP_FIELD_CONTENT_LENGTH, length);
|
||||
httpSetField(http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
|
||||
httpSetField(http, HTTP_FIELD_AUTHORIZATION, authstring);
|
||||
|
||||
/*
|
||||
* Try the request...
|
||||
*/
|
||||
|
||||
DEBUG_puts("cupsDoFileRequest: post...");
|
||||
|
||||
if (httpPost(http, resource))
|
||||
{
|
||||
httpReconnect(http);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the IPP data and wait for the response...
|
||||
*/
|
||||
|
||||
DEBUG_puts("cupsDoFileRequest: ipp write...");
|
||||
|
||||
request->state = IPP_IDLE;
|
||||
if (ippWrite(http, request) != IPP_ERROR)
|
||||
if (filename != NULL)
|
||||
{
|
||||
DEBUG_puts("cupsDoFileRequest: file write...");
|
||||
|
||||
/*
|
||||
* Send the file...
|
||||
*/
|
||||
|
||||
rewind(file);
|
||||
|
||||
while ((bytes = fread(buffer, 1, sizeof(buffer), file)) > 0)
|
||||
if (httpWrite(http, buffer, bytes) < bytes)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the server's return status...
|
||||
*/
|
||||
|
||||
DEBUG_puts("cupsDoFileRequest: update...");
|
||||
|
||||
while ((status = httpUpdate(http)) == HTTP_CONTINUE);
|
||||
|
||||
if (status == HTTP_UNAUTHORIZED)
|
||||
{
|
||||
DEBUG_puts("cupsDoFileRequest: unauthorized...");
|
||||
|
||||
/*
|
||||
* Flush any error message...
|
||||
*/
|
||||
|
||||
httpFlush(http);
|
||||
|
||||
if ((password = cupsGetPassword("Password:")) != NULL)
|
||||
{
|
||||
/*
|
||||
* Got a password; send it to the server...
|
||||
*/
|
||||
|
||||
if (!password[0])
|
||||
break;
|
||||
sprintf(plain, "%s:%s", cupsUser(), password);
|
||||
httpEncode64(encode, plain);
|
||||
sprintf(authstring, "Basic %s", encode);
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (status != HTTP_OK)
|
||||
{
|
||||
DEBUG_printf(("cupsDoFileRequest: error %d...\n", status));
|
||||
|
||||
/*
|
||||
* Flush any error message...
|
||||
*/
|
||||
|
||||
httpFlush(http);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Read the response...
|
||||
*/
|
||||
|
||||
DEBUG_puts("cupsDoFileRequest: response...");
|
||||
|
||||
response = ippNew();
|
||||
|
||||
if (ippRead(http, response) == IPP_ERROR)
|
||||
{
|
||||
/*
|
||||
* Delete the response...
|
||||
*/
|
||||
|
||||
ippDelete(response);
|
||||
response = NULL;
|
||||
|
||||
/*
|
||||
* Flush any remaining data...
|
||||
*/
|
||||
|
||||
httpFlush(http);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Close the file if needed...
|
||||
*/
|
||||
|
||||
if (filename != NULL)
|
||||
fclose(file);
|
||||
|
||||
/*
|
||||
* Delete the original request and return the response...
|
||||
*/
|
||||
|
||||
ippDelete(request);
|
||||
|
||||
return (response);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetClasses()' - Get a list of printer classes.
|
||||
*/
|
||||
|
||||
int /* O - Number of classes */
|
||||
cupsGetClasses(char ***classes) /* O - Classes */
|
||||
{
|
||||
int n; /* Number of classes */
|
||||
ipp_t *request, /* IPP Request */
|
||||
*response; /* IPP Response */
|
||||
ipp_attribute_t *attr; /* Current attribute */
|
||||
cups_lang_t *language; /* Default language */
|
||||
|
||||
|
||||
/*
|
||||
* Try to connect to the server...
|
||||
*/
|
||||
|
||||
if (!cups_connect("default", NULL, NULL))
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Build a CUPS_GET_CLASSES request, which requires the following
|
||||
* attributes:
|
||||
*
|
||||
* attributes-charset
|
||||
* attributes-natural-language
|
||||
*/
|
||||
|
||||
request = ippNew();
|
||||
|
||||
request->request.op.operation_id = CUPS_GET_CLASSES;
|
||||
request->request.op.request_id = 1;
|
||||
|
||||
language = cupsLangDefault();
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
|
||||
"attributes-charset", NULL, cupsLangEncoding(language));
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
|
||||
"attributes-natural-language", NULL, language->language);
|
||||
|
||||
/*
|
||||
* Do the request and get back a response...
|
||||
*/
|
||||
|
||||
n = 0;
|
||||
*classes = NULL;
|
||||
|
||||
if ((response = cupsDoRequest(cups_server, request, "/classes/")) != NULL)
|
||||
{
|
||||
for (attr = response->attrs; attr != NULL; attr = attr->next)
|
||||
if (strcmp(attr->name, "printer-name") == 0 &&
|
||||
attr->value_tag == IPP_TAG_NAME)
|
||||
{
|
||||
if (n == 0)
|
||||
*classes = malloc(sizeof(char *));
|
||||
else
|
||||
*classes = realloc(*classes, sizeof(char *) * (n + 1));
|
||||
|
||||
if (*classes == NULL)
|
||||
{
|
||||
ippDelete(response);
|
||||
return (0);
|
||||
}
|
||||
|
||||
(*classes)[n] = strdup(attr->values[0].string.text);
|
||||
n ++;
|
||||
}
|
||||
|
||||
ippDelete(response);
|
||||
}
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetDefault()' - Get the default printer or class.
|
||||
*/
|
||||
|
||||
const char * /* O - Default printer or NULL */
|
||||
cupsGetDefault(void)
|
||||
{
|
||||
ipp_t *request, /* IPP Request */
|
||||
*response; /* IPP Response */
|
||||
ipp_attribute_t *attr; /* Current attribute */
|
||||
cups_lang_t *language; /* Default language */
|
||||
static char def_printer[64];/* Default printer */
|
||||
|
||||
|
||||
/*
|
||||
* First see if the LPDEST or PRINTER environment variables are
|
||||
* set...
|
||||
*/
|
||||
|
||||
if (getenv("LPDEST") != NULL)
|
||||
return (getenv("LPDEST"));
|
||||
else if (getenv("PRINTER") != NULL)
|
||||
return (getenv("PRINTER"));
|
||||
|
||||
/*
|
||||
* Try to connect to the server...
|
||||
*/
|
||||
|
||||
if (!cups_connect("default", NULL, NULL))
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Build a CUPS_GET_DEFAULT request, which requires the following
|
||||
* attributes:
|
||||
*
|
||||
* attributes-charset
|
||||
* attributes-natural-language
|
||||
*/
|
||||
|
||||
request = ippNew();
|
||||
|
||||
request->request.op.operation_id = CUPS_GET_DEFAULT;
|
||||
request->request.op.request_id = 1;
|
||||
|
||||
language = cupsLangDefault();
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
|
||||
"attributes-charset", NULL, cupsLangEncoding(language));
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
|
||||
"attributes-natural-language", NULL, language->language);
|
||||
|
||||
/*
|
||||
* Do the request and get back a response...
|
||||
*/
|
||||
|
||||
if ((response = cupsDoRequest(cups_server, request, "/printers/")) != NULL)
|
||||
{
|
||||
if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL)
|
||||
{
|
||||
strcpy(def_printer, attr->values[0].string.text);
|
||||
ippDelete(response);
|
||||
return (def_printer);
|
||||
}
|
||||
|
||||
ippDelete(response);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetPPD()' - Get the PPD file for a printer.
|
||||
*/
|
||||
|
||||
const char * /* O - Filename for PPD file */
|
||||
cupsGetPPD(const char *name) /* I - Printer name */
|
||||
{
|
||||
FILE *fp; /* PPD file */
|
||||
int bytes; /* Number of bytes read */
|
||||
char buffer[8192]; /* Buffer for file */
|
||||
char printer[HTTP_MAX_URI], /* Printer name */
|
||||
hostname[HTTP_MAX_URI], /* Hostname */
|
||||
resource[HTTP_MAX_URI]; /* Resource name */
|
||||
static char filename[HTTP_MAX_URI]; /* Local filename */
|
||||
char *tempdir; /* Temporary file directory */
|
||||
|
||||
|
||||
/*
|
||||
* See if we can connect to the server...
|
||||
*/
|
||||
|
||||
if (!cups_connect(name, printer, hostname))
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Then check for the cache file...
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(__EMX__)
|
||||
tempdir = "C:/WINDOWS/TEMP";
|
||||
|
||||
sprintf(filename, "%s/%s.ppd", tempdir, printer);
|
||||
#else
|
||||
if ((tempdir = getenv("TMPDIR")) == NULL)
|
||||
tempdir = "/tmp";
|
||||
|
||||
sprintf(filename, "%s/%d.%s.ppd", tempdir, getuid(), printer);
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
|
||||
/*
|
||||
* And send a request to the HTTP server...
|
||||
*/
|
||||
|
||||
sprintf(resource, "/printers/%s.ppd", printer);
|
||||
|
||||
httpClearFields(cups_server);
|
||||
httpSetField(cups_server, HTTP_FIELD_HOST, hostname);
|
||||
httpGet(cups_server, resource);
|
||||
|
||||
switch (httpUpdate(cups_server))
|
||||
{
|
||||
case HTTP_OK : /* New file - get it! */
|
||||
break;
|
||||
default :
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, we need to copy the file; open the file and copy it...
|
||||
*/
|
||||
|
||||
unlink(filename);
|
||||
if ((fp = fopen(filename, "w")) == NULL)
|
||||
{
|
||||
/*
|
||||
* Can't open file; close the server connection and return NULL...
|
||||
*/
|
||||
|
||||
httpClose(cups_server);
|
||||
cups_server = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
while ((bytes = httpRead(cups_server, buffer, sizeof(buffer))) > 0)
|
||||
fwrite(buffer, bytes, 1, fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (filename);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsGetPrinters()' - Get a list of printers.
|
||||
*/
|
||||
|
||||
int /* O - Number of printers */
|
||||
cupsGetPrinters(char ***printers) /* O - Printers */
|
||||
{
|
||||
int n; /* Number of printers */
|
||||
ipp_t *request, /* IPP Request */
|
||||
*response; /* IPP Response */
|
||||
ipp_attribute_t *attr; /* Current attribute */
|
||||
cups_lang_t *language; /* Default language */
|
||||
|
||||
|
||||
/*
|
||||
* Try to connect to the server...
|
||||
*/
|
||||
|
||||
if (!cups_connect("default", NULL, NULL))
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Build a CUPS_GET_PRINTERS request, which requires the following
|
||||
* attributes:
|
||||
*
|
||||
* attributes-charset
|
||||
* attributes-natural-language
|
||||
*/
|
||||
|
||||
request = ippNew();
|
||||
|
||||
request->request.op.operation_id = CUPS_GET_PRINTERS;
|
||||
request->request.op.request_id = 1;
|
||||
|
||||
language = cupsLangDefault();
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
|
||||
"attributes-charset", NULL, cupsLangEncoding(language));
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
|
||||
"attributes-natural-language", NULL, language->language);
|
||||
|
||||
/*
|
||||
* Do the request and get back a response...
|
||||
*/
|
||||
|
||||
n = 0;
|
||||
*printers = NULL;
|
||||
|
||||
if ((response = cupsDoRequest(cups_server, request, "/printers/")) != NULL)
|
||||
{
|
||||
for (attr = response->attrs; attr != NULL; attr = attr->next)
|
||||
if (strcmp(attr->name, "printer-name") == 0 &&
|
||||
attr->value_tag == IPP_TAG_NAME)
|
||||
{
|
||||
if (n == 0)
|
||||
*printers = malloc(sizeof(char *));
|
||||
else
|
||||
*printers = realloc(*printers, sizeof(char *) * (n + 1));
|
||||
|
||||
if (*printers == NULL)
|
||||
{
|
||||
ippDelete(response);
|
||||
return (0);
|
||||
}
|
||||
|
||||
(*printers)[n] = strdup(attr->values[0].string.text);
|
||||
n ++;
|
||||
}
|
||||
|
||||
ippDelete(response);
|
||||
}
|
||||
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsPrintFile()' - Print a file to a printer or class.
|
||||
*/
|
||||
|
||||
int /* O - Job ID */
|
||||
cupsPrintFile(const char *name, /* I - Printer or class name */
|
||||
const char *filename, /* I - File to print */
|
||||
const char *title, /* I - Title of job */
|
||||
int num_options,/* I - Number of options */
|
||||
cups_option_t *options) /* I - Options */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
int n, n2; /* Attribute values */
|
||||
char *option, /* Name of option */
|
||||
*val, /* Pointer to option value */
|
||||
*s; /* Pointer into option value */
|
||||
ipp_t *request; /* IPP request */
|
||||
ipp_t *response; /* IPP response */
|
||||
ipp_attribute_t *attr; /* IPP job-id attribute */
|
||||
char hostname[HTTP_MAX_URI], /* Hostname */
|
||||
printer[HTTP_MAX_URI], /* Printer or class name */
|
||||
uri[HTTP_MAX_URI]; /* Printer URI */
|
||||
cups_lang_t *language; /* Language to use */
|
||||
int jobid; /* New job ID */
|
||||
|
||||
|
||||
DEBUG_printf(("cupsPrintFile(\'%s\', \'%s\', %d, %08x)\n",
|
||||
printer, filename, num_options, options));
|
||||
|
||||
if (name == NULL || filename == NULL)
|
||||
return (0);
|
||||
|
||||
/*
|
||||
* Setup a connection and request data...
|
||||
*/
|
||||
|
||||
if ((request = ippNew()) == NULL)
|
||||
return (0);
|
||||
|
||||
if (!cups_connect(name, printer, hostname))
|
||||
{
|
||||
DEBUG_printf(("cupsPrintFile: Unable to open connection - %s.\n",
|
||||
strerror(errno)));
|
||||
ippDelete(request);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a standard CUPS URI for the printer and fill the standard IPP
|
||||
* attributes...
|
||||
*/
|
||||
|
||||
request->request.op.operation_id = IPP_PRINT_JOB;
|
||||
request->request.op.request_id = 1;
|
||||
|
||||
sprintf(uri, "ipp://%s:%d/printers/%s", hostname, ippPort(), printer);
|
||||
|
||||
language = cupsLangDefault();
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
|
||||
"attributes-charset", NULL, cupsLangEncoding(language));
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
|
||||
"attributes-natural-language", NULL,
|
||||
language != NULL ? language->language : "C");
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
|
||||
NULL, uri);
|
||||
|
||||
/*
|
||||
* Handle raw print files...
|
||||
*/
|
||||
|
||||
if (cupsGetOption("raw", num_options, options))
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
|
||||
NULL, "application/vnd.cups-raw");
|
||||
else
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
|
||||
NULL, "application/octet-stream");
|
||||
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
|
||||
NULL, cupsUser());
|
||||
|
||||
if (title)
|
||||
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL, title);
|
||||
|
||||
/*
|
||||
* Then add all options on the command-line...
|
||||
*/
|
||||
|
||||
for (i = 0; i < num_options; i ++)
|
||||
{
|
||||
/*
|
||||
* Skip the "raw" option - handled above...
|
||||
*/
|
||||
|
||||
if (strcmp(options[i].name, "raw") == 0)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* See what the option value is; for compatibility with older interface
|
||||
* scripts, we have to support single-argument options as well as
|
||||
* option=value, option=low-high, and option=MxN.
|
||||
*/
|
||||
|
||||
option = options[i].name;
|
||||
val = options[i].value;
|
||||
|
||||
if (*val == '\0')
|
||||
val = NULL;
|
||||
|
||||
if (val != NULL)
|
||||
{
|
||||
if (strcasecmp(val, "true") == 0 ||
|
||||
strcasecmp(val, "on") == 0 ||
|
||||
strcasecmp(val, "yes") == 0)
|
||||
{
|
||||
/*
|
||||
* Boolean value - true...
|
||||
*/
|
||||
|
||||
n = 1;
|
||||
val = "";
|
||||
}
|
||||
else if (strcasecmp(val, "false") == 0 ||
|
||||
strcasecmp(val, "off") == 0 ||
|
||||
strcasecmp(val, "no") == 0)
|
||||
{
|
||||
/*
|
||||
* Boolean value - false...
|
||||
*/
|
||||
|
||||
n = 0;
|
||||
val = "";
|
||||
}
|
||||
|
||||
n = strtol(val, &s, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strncmp(option, "no", 2) == 0)
|
||||
{
|
||||
option += 2;
|
||||
n = 0;
|
||||
}
|
||||
else
|
||||
n = 1;
|
||||
|
||||
s = "";
|
||||
}
|
||||
|
||||
if (*s != '\0' && *s != '-' && (*s != 'x' || s == val))
|
||||
{
|
||||
/*
|
||||
* String value(s)...
|
||||
*/
|
||||
|
||||
DEBUG_printf(("cupsPrintFile: Adding string option \'%s\' with value \'%s\'...\n",
|
||||
option, val));
|
||||
|
||||
ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, option, NULL, val);
|
||||
}
|
||||
else if (val != NULL)
|
||||
{
|
||||
/*
|
||||
* Numeric value, range, or resolution...
|
||||
*/
|
||||
|
||||
if (*s == '-')
|
||||
{
|
||||
n2 = strtol(s + 1, NULL, 0);
|
||||
ippAddRange(request, IPP_TAG_JOB, option, n, n2);
|
||||
|
||||
DEBUG_printf(("cupsPrintFile: Adding range option \'%s\' with value %d-%d...\n",
|
||||
option, n, n2));
|
||||
}
|
||||
else if (*s == 'x')
|
||||
{
|
||||
n2 = strtol(s + 1, &s, 0);
|
||||
|
||||
if (strcmp(s, "dpc") == 0)
|
||||
ippAddResolution(request, IPP_TAG_JOB, option, IPP_RES_PER_CM, n, n2);
|
||||
else if (strcmp(s, "dpi") == 0)
|
||||
ippAddResolution(request, IPP_TAG_JOB, option, IPP_RES_PER_INCH, n, n2);
|
||||
else
|
||||
ippAddString(request, IPP_TAG_JOB, IPP_TAG_KEYWORD, option, NULL, val);
|
||||
|
||||
DEBUG_printf(("cupsPrintFile: Adding resolution option \'%s\' with value %s...\n",
|
||||
option, val));
|
||||
}
|
||||
else
|
||||
{
|
||||
ippAddInteger(request, IPP_TAG_JOB, IPP_TAG_INTEGER, option, n);
|
||||
|
||||
DEBUG_printf(("cupsPrintFile: Adding integer option \'%s\' with value %d...\n",
|
||||
option, n));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Boolean value...
|
||||
*/
|
||||
|
||||
DEBUG_printf(("cupsPrintFile: Adding boolean option \'%s\' with value %d...\n",
|
||||
option, n));
|
||||
ippAddBoolean(request, IPP_TAG_JOB, option, (char)n);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try printing the file...
|
||||
*/
|
||||
|
||||
sprintf(uri, "/printers/%s", printer);
|
||||
|
||||
if ((response = cupsDoFileRequest(cups_server, request, uri, filename)) == NULL)
|
||||
jobid = 0;
|
||||
else if (response->request.status.status_code > IPP_OK_CONFLICT)
|
||||
{
|
||||
DEBUG_printf(("IPP response code was 0x%x!\n",
|
||||
response->request.status.status_code));
|
||||
jobid = 0;
|
||||
}
|
||||
else if ((attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER)) == NULL)
|
||||
{
|
||||
DEBUG_puts("No job ID!");
|
||||
jobid = 0;
|
||||
}
|
||||
else
|
||||
jobid = attr->values[0].integer;
|
||||
|
||||
if (response != NULL)
|
||||
ippDelete(response);
|
||||
|
||||
return (jobid);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cupsTempFile()' - Generate a temporary filename.
|
||||
*/
|
||||
|
||||
char * /* O - Filename */
|
||||
cupsTempFile(char *filename, /* I - Pointer to buffer */
|
||||
int len) /* I - Size of buffer */
|
||||
{
|
||||
char *tmpdir; /* TMPDIR environment var */
|
||||
static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
|
||||
|
||||
|
||||
/*
|
||||
* See if a filename was specified...
|
||||
*/
|
||||
|
||||
if (filename == NULL)
|
||||
{
|
||||
filename = buf;
|
||||
len = sizeof(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* See if TMPDIR is defined...
|
||||
*/
|
||||
|
||||
if ((tmpdir = getenv("TMPDIR")) == NULL)
|
||||
tmpdir = "/var/tmp";
|
||||
|
||||
if ((strlen(tmpdir) + 8) > len)
|
||||
{
|
||||
/*
|
||||
* The specified directory exceeds the size of the buffer; default it...
|
||||
*/
|
||||
|
||||
strcpy(buf, "/var/tmp/XXXXXX");
|
||||
return (mktemp(buf));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Make the temporary name using the specified directory...
|
||||
*/
|
||||
|
||||
sprintf(filename, "%s/XXXXXX", tmpdir);
|
||||
return (mktemp(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'cups_connect()' - Connect to the specified host...
|
||||
*/
|
||||
|
||||
static char * /* I - Printer name or NULL */
|
||||
cups_connect(const char *name, /* I - Destination (printer[@host]) */
|
||||
char *printer, /* O - Printer name */
|
||||
char *hostname) /* O - Hostname */
|
||||
{
|
||||
char hostbuf[HTTP_MAX_URI];
|
||||
/* Name of host */
|
||||
static char printerbuf[HTTP_MAX_URI];
|
||||
/* Name of printer or class */
|
||||
|
||||
|
||||
if (name == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (sscanf(name, "%[^@]@%s", printerbuf, hostbuf) == 1)
|
||||
strcpy(hostbuf, cupsServer());
|
||||
|
||||
if (hostname != NULL)
|
||||
strcpy(hostname, hostbuf);
|
||||
else
|
||||
hostname = hostbuf;
|
||||
|
||||
if (printer != NULL)
|
||||
strcpy(printer, printerbuf);
|
||||
else
|
||||
printer = printerbuf;
|
||||
|
||||
if (cups_server != NULL)
|
||||
{
|
||||
if (strcasecmp(cups_server->hostname, hostname) == 0)
|
||||
return (printer);
|
||||
|
||||
httpClose(cups_server);
|
||||
}
|
||||
|
||||
if ((cups_server = httpConnect(hostname, ippPort())) == NULL)
|
||||
return (NULL);
|
||||
else
|
||||
return (printer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Common filter routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* SetCommonOptions() - Set common filter options for media size, etc.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
int Orientation = 0, /* 0 = portrait, 1 = landscape, etc. */
|
||||
Duplex = 0, /* Duplexed? */
|
||||
LanguageLevel = 1, /* Language level of printer */
|
||||
ColorDevice = 1; /* Do color text? */
|
||||
float PageLeft = 18.0f, /* Left margin */
|
||||
PageRight = 594.0f, /* Right margin */
|
||||
PageBottom = 36.0f, /* Bottom margin */
|
||||
PageTop = 756.0f, /* Top margin */
|
||||
PageWidth = 612.0f, /* Total page width */
|
||||
PageLength = 792.0f; /* Total page length */
|
||||
|
||||
|
||||
/*
|
||||
* 'SetCommonOptions()' - Set common filter options for media size, etc.
|
||||
*/
|
||||
|
||||
ppd_file_t * /* O - PPD file */
|
||||
SetCommonOptions(int num_options, /* I - Number of options */
|
||||
cups_option_t *options, /* I - Options */
|
||||
int change_size) /* I - Change page size? */
|
||||
{
|
||||
float temp; /* Swapping variable */
|
||||
ppd_file_t *ppd; /* PPD file */
|
||||
ppd_size_t *pagesize; /* Current page size */
|
||||
const char *val; /* Option value */
|
||||
|
||||
|
||||
ppd = ppdOpenFile(getenv("PPD"));
|
||||
|
||||
ppdMarkDefaults(ppd);
|
||||
cupsMarkOptions(ppd, num_options, options);
|
||||
|
||||
if ((pagesize = ppdPageSize(ppd, NULL)) != NULL)
|
||||
{
|
||||
PageWidth = pagesize->width;
|
||||
PageLength = pagesize->length;
|
||||
PageTop = pagesize->top;
|
||||
PageBottom = pagesize->bottom;
|
||||
PageLeft = pagesize->left;
|
||||
PageRight = pagesize->right;
|
||||
}
|
||||
|
||||
if (ppd != NULL)
|
||||
{
|
||||
ColorDevice = ppd->color_device;
|
||||
LanguageLevel = ppd->language_level;
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("landscape", num_options, options)) != NULL)
|
||||
Orientation = 1;
|
||||
|
||||
if ((val = cupsGetOption("orientation-requested", num_options, options)) != NULL)
|
||||
{
|
||||
/*
|
||||
* Map IPP orientation values to 0 to 3:
|
||||
*
|
||||
* 3 = 0 degrees = 0
|
||||
* 4 = 90 degrees = 1
|
||||
* 5 = -90 degrees = 3
|
||||
* 6 = 180 degrees = 2
|
||||
*/
|
||||
|
||||
Orientation = atoi(val) - 3;
|
||||
if (Orientation >= 2)
|
||||
Orientation ^= 1;
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("page-left", num_options, options)) != NULL)
|
||||
{
|
||||
switch (Orientation)
|
||||
{
|
||||
case 0 :
|
||||
PageLeft = (float)atof(val);
|
||||
break;
|
||||
case 1 :
|
||||
PageBottom = (float)atof(val);
|
||||
break;
|
||||
case 2 :
|
||||
PageRight = PageWidth - (float)atof(val);
|
||||
break;
|
||||
case 3 :
|
||||
PageTop = PageLength - (float)atof(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("page-right", num_options, options)) != NULL)
|
||||
{
|
||||
switch (Orientation)
|
||||
{
|
||||
case 0 :
|
||||
PageRight = PageWidth - (float)atof(val);
|
||||
break;
|
||||
case 1 :
|
||||
PageTop = PageLength - (float)atof(val);
|
||||
break;
|
||||
case 2 :
|
||||
PageLeft = (float)atof(val);
|
||||
break;
|
||||
case 3 :
|
||||
PageBottom = (float)atof(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("page-bottom", num_options, options)) != NULL)
|
||||
{
|
||||
switch (Orientation)
|
||||
{
|
||||
case 0 :
|
||||
PageBottom = (float)atof(val);
|
||||
break;
|
||||
case 1 :
|
||||
PageRight = PageWidth - (float)atof(val);
|
||||
break;
|
||||
case 2 :
|
||||
PageTop = PageLength - (float)atof(val);
|
||||
break;
|
||||
case 3 :
|
||||
PageLeft = (float)atof(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("page-top", num_options, options)) != NULL)
|
||||
{
|
||||
switch (Orientation)
|
||||
{
|
||||
case 0 :
|
||||
PageTop = PageLength - (float)atof(val);
|
||||
break;
|
||||
case 1 :
|
||||
PageLeft = (float)atof(val);
|
||||
break;
|
||||
case 2 :
|
||||
PageBottom = (float)atof(val);
|
||||
break;
|
||||
case 3 :
|
||||
PageRight = PageWidth - (float)atof(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (change_size)
|
||||
switch (Orientation)
|
||||
{
|
||||
case 0 : /* Portait */
|
||||
break;
|
||||
|
||||
case 1 : /* Landscape */
|
||||
temp = PageLeft;
|
||||
PageLeft = PageBottom;
|
||||
PageBottom = temp;
|
||||
|
||||
temp = PageRight;
|
||||
PageRight = PageTop;
|
||||
PageTop = temp;
|
||||
|
||||
temp = PageWidth;
|
||||
PageWidth = PageLength;
|
||||
PageLength = temp;
|
||||
break;
|
||||
|
||||
case 2 : /* Reverse Portrait */
|
||||
temp = PageWidth - PageLeft;
|
||||
PageLeft = PageWidth - PageRight;
|
||||
PageRight = temp;
|
||||
|
||||
temp = PageLength - PageBottom;
|
||||
PageBottom = PageLength - PageTop;
|
||||
PageTop = temp;
|
||||
break;
|
||||
|
||||
case 3 : /* Reverse Landscape */
|
||||
temp = PageWidth - PageLeft;
|
||||
PageLeft = PageWidth - PageRight;
|
||||
PageRight = temp;
|
||||
|
||||
temp = PageLength - PageBottom;
|
||||
PageBottom = PageLength - PageTop;
|
||||
PageTop = temp;
|
||||
|
||||
temp = PageLeft;
|
||||
PageLeft = PageBottom;
|
||||
PageBottom = temp;
|
||||
|
||||
temp = PageRight;
|
||||
PageRight = PageTop;
|
||||
PageTop = temp;
|
||||
|
||||
temp = PageWidth;
|
||||
PageWidth = PageLength;
|
||||
PageLength = temp;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("sides", num_options, options)) != NULL &&
|
||||
strncmp(val, "two-", 4) == 0)
|
||||
Duplex = 1;
|
||||
else if ((val = cupsGetOption("Duplex", num_options, options)) != NULL &&
|
||||
strcmp(val, "DuplexNoTumble") == 0)
|
||||
Duplex = 1;
|
||||
else if (ppdIsMarked(ppd, "Duplex", "DuplexNoTumble") ||
|
||||
ppdIsMarked(ppd, "Duplex", "DuplexTumble"))
|
||||
Duplex = 1;
|
||||
|
||||
return (ppd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Common filter definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <cups/cups.h>
|
||||
#include <cups/language.h>
|
||||
#include <cups/string.h>
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
extern int Orientation, /* 0 = portrait, 1 = landscape, etc. */
|
||||
Duplex, /* Duplexed? */
|
||||
LanguageLevel, /* Language level of printer */
|
||||
ColorDevice; /* Do color text? */
|
||||
extern float PageLeft, /* Left margin */
|
||||
PageRight, /* Right margin */
|
||||
PageBottom, /* Bottom margin */
|
||||
PageTop, /* Top margin */
|
||||
PageWidth, /* Total page width */
|
||||
PageLength; /* Total page length */
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
extern ppd_file_t *SetCommonOptions(int num_options, cups_option_t *options,
|
||||
int change_size);
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,405 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 attribute processing for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* CR_color_range() - Set the range for color values.
|
||||
* AC_anchor_corner() - Set the anchor corner.
|
||||
* FT_fill_type() - Set the fill type or pattern.
|
||||
* LA_line_attributes() - Set the line drawing attributes.
|
||||
* LT_line_type() - Set the line type (style)...
|
||||
* NP_number_pens() - Set the number of pens to be used.
|
||||
* PC_pen_color() - Set the pen color...
|
||||
* PW_pen_width() - Set the pen width.
|
||||
* RF_raster_fill() - Set the raster fill pattern.
|
||||
* SM_symbol_mode() - Set where symbols are drawn.
|
||||
* SP_select_pen() - Select a pen for drawing.
|
||||
* UL_user_line_type() - Set a user-defined line type.
|
||||
* WU_width_units() - Set the units used for pen widths.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'CR_color_range()' - Set the range for color values.
|
||||
*/
|
||||
|
||||
void
|
||||
CR_color_range(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
{
|
||||
/*
|
||||
* Default to 0 to 255 for all color values.
|
||||
*/
|
||||
|
||||
ColorRange[0][0] = 0.0;
|
||||
ColorRange[0][1] = 255.0;
|
||||
ColorRange[1][0] = 0.0;
|
||||
ColorRange[1][1] = 255.0;
|
||||
ColorRange[2][0] = 0.0;
|
||||
ColorRange[2][1] = 255.0;
|
||||
}
|
||||
else if (num_params == 6)
|
||||
{
|
||||
/*
|
||||
* Set the range based on the parameters...
|
||||
*/
|
||||
ColorRange[0][0] = params[0].value.number;
|
||||
ColorRange[0][1] = params[1].value.number - params[0].value.number;
|
||||
ColorRange[1][0] = params[2].value.number;
|
||||
ColorRange[1][1] = params[3].value.number - params[2].value.number;
|
||||
ColorRange[2][0] = params[4].value.number;
|
||||
ColorRange[2][1] = params[5].value.number - params[4].value.number;
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'CR\' command with invalid number of parameters (%d)!\n",
|
||||
num_params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'AC_anchor_corner()' - Set the anchor corner.
|
||||
*/
|
||||
|
||||
void
|
||||
AC_anchor_corner(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'FT_fill_type()' - Set the fill type or pattern.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* This needs to be updated to support non-solid fill.
|
||||
*/
|
||||
|
||||
void
|
||||
FT_fill_type(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0 ||
|
||||
params[0].value.number == 1 ||
|
||||
params[0].value.number == 2)
|
||||
{
|
||||
/**** SOLID PATTERN ****/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'LA_line_attributes()' - Set the line drawing attributes.
|
||||
*/
|
||||
|
||||
void
|
||||
LA_line_attributes(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
if (num_params == 0)
|
||||
{
|
||||
Outputf("3.0 setmiterlimit\n");
|
||||
Outputf("0 setlinecap\n");
|
||||
Outputf("0 setlinejoin\n");
|
||||
}
|
||||
else for (i = 0; i < (num_params - 1); i += 2)
|
||||
switch ((int)params[i].value.number)
|
||||
{
|
||||
case 1 :
|
||||
Outputf("%d setlinecap\n",
|
||||
params[i + 1].value.number == 1 ? 0 :
|
||||
params[i + 1].value.number == 4 ? 1 : 2);
|
||||
break;
|
||||
case 2 :
|
||||
switch ((int)params[i + 1].value.number)
|
||||
{
|
||||
case 1 :
|
||||
case 2 :
|
||||
case 3 :
|
||||
Outputf("0 setlinejoin\n");
|
||||
break;
|
||||
case 5 :
|
||||
Outputf("2 setlinejoin\n");
|
||||
break;
|
||||
default :
|
||||
Outputf("1 setlinejoin\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 3 :
|
||||
Outputf("%f setmiterlimit\n",
|
||||
1.0 + 0.5 * (params[i + 1].value.number - 1.0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'LT_line_type()' - Set the line type (style)...
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* This needs to be updated to support line types.
|
||||
*/
|
||||
|
||||
void
|
||||
LT_line_type(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'NP_number_pens()' - Set the number of pens to be used.
|
||||
*/
|
||||
|
||||
void
|
||||
NP_number_pens(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
if (num_params == 0)
|
||||
PenCount = 8;
|
||||
else if (num_params == 1)
|
||||
PenCount = (int)params[0].value.number;
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'NP\' command with invalid number of parameters (%d)!\n",
|
||||
num_params);
|
||||
|
||||
PC_pen_color(0, NULL);
|
||||
|
||||
for (i = 0; i <= PenCount; i ++)
|
||||
Outputf("/W%d { DefaultPenWidth PenScaling mul setlinewidth } bind def\n", i);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PC_pen_color()' - Set the pen color...
|
||||
*/
|
||||
|
||||
void
|
||||
PC_pen_color(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
static float standard_colors[8][3] = /* Standard colors for first 8 pens */
|
||||
{
|
||||
{ 1.0, 1.0, 1.0 }, /* White */
|
||||
{ 0.0, 0.0, 0.0 }, /* Black */
|
||||
{ 1.0, 0.0, 0.0 }, /* Red */
|
||||
{ 0.0, 1.0, 0.0 }, /* Green */
|
||||
{ 1.0, 1.0, 0.0 }, /* Yellow */
|
||||
{ 0.0, 0.0, 1.0 }, /* Blue */
|
||||
{ 1.0, 0.0, 1.0 }, /* Magenta */
|
||||
{ 0.0, 1.0, 1.0 } /* Cyan */
|
||||
};
|
||||
|
||||
if (num_params == 0)
|
||||
{
|
||||
for (i = 0; i <= PenCount; i ++)
|
||||
if (i < 8)
|
||||
Outputf("/P%d { %.3f %.3f %.3f setrgbcolor } bind def\n",
|
||||
i, standard_colors[i][0],
|
||||
standard_colors[i][1], standard_colors[i][2]);
|
||||
else
|
||||
Outputf("/P%d { 0.0 0.0 0.0 setrgbcolor } bind def\n", i);
|
||||
}
|
||||
else if (num_params == 1)
|
||||
{
|
||||
i = (int)params[0].value.number;
|
||||
|
||||
Outputf("/P%d { %.3f %.3f %.3f setrgbcolor } bind def\n",
|
||||
i, standard_colors[i & 7][0], standard_colors[i & 7][1],
|
||||
standard_colors[i & 7][2]);
|
||||
}
|
||||
else if (num_params == 4)
|
||||
Outputf("/P%d { %.3f %.3f %.3f setrgbcolor } bind def\n",
|
||||
(int)params[0].value.number,
|
||||
(params[1].value.number - ColorRange[0][0]) / ColorRange[0][1],
|
||||
(params[2].value.number - ColorRange[1][0]) / ColorRange[1][1],
|
||||
(params[3].value.number - ColorRange[2][0]) / ColorRange[2][1]);
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'PC\' command with invalid number of parameters (%d)!\n",
|
||||
num_params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PW_pen_width()' - Set the pen width.
|
||||
*/
|
||||
|
||||
void
|
||||
PW_pen_width(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int pen; /* Pen number */
|
||||
float w; /* Width value */
|
||||
|
||||
|
||||
if (WidthUnits == 0)
|
||||
{
|
||||
/*
|
||||
* Metric...
|
||||
*/
|
||||
|
||||
if (num_params == 0)
|
||||
w = 0.35f / 25.4f * 72.0f;
|
||||
else
|
||||
w = params[0].value.number / 25.4f * 72.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Relative...
|
||||
*/
|
||||
|
||||
w = (float)hypot(PlotSize[0], PlotSize[1]) / 1016.0f * 72.0f;
|
||||
|
||||
if (num_params == 0)
|
||||
w *= 0.01f;
|
||||
else
|
||||
w *= params[0].value.number;
|
||||
}
|
||||
|
||||
if (num_params == 2)
|
||||
Outputf("/W%d { %.1f PenScaling mul setlinewidth } bind def W%d\n",
|
||||
(int)params[1].value.number, w, (int)params[1].value.number);
|
||||
else if (num_params < 2)
|
||||
{
|
||||
/*
|
||||
* Set width for all pens...
|
||||
*/
|
||||
|
||||
for (pen = 0; pen <= PenCount; pen ++)
|
||||
Outputf("/W%d { %.1f PenScaling mul setlinewidth } bind def\n",
|
||||
pen, w);
|
||||
|
||||
Outputf("W%d\n", PenNumber);
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'PW\' command with invalid number of parameters (%d)!\n",
|
||||
num_params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RF_raster_fill()' - Set the raster fill pattern.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* This needs to be implemented.
|
||||
*/
|
||||
|
||||
void
|
||||
RF_raster_fill(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SM_symbol_mode()' - Set where symbols are drawn.
|
||||
*/
|
||||
|
||||
void
|
||||
SM_symbol_mode(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SP_select_pen()' - Select a pen for drawing.
|
||||
*/
|
||||
|
||||
void
|
||||
SP_select_pen(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
PenNumber = 1;
|
||||
else if (params[0].value.number <= PenCount)
|
||||
PenNumber = (int)params[0].value.number;
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'SP\' command with invalid number or value of parameters (%d, %d)!\n",
|
||||
num_params, (int)params[0].value.number);
|
||||
|
||||
Outputf("P%d W%d\n", PenNumber, PenNumber);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'UL_user_line_type()' - Set a user-defined line type.
|
||||
*/
|
||||
|
||||
void
|
||||
UL_user_line_type(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'WU_width_units()' - Set the units used for pen widths.
|
||||
*/
|
||||
|
||||
void
|
||||
WU_width_units(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
WidthUnits = 0;
|
||||
else if (num_params == 1)
|
||||
WidthUnits = (int)params[0].value.number;
|
||||
else
|
||||
fprintf(stderr, "WARNING: HP-GL/2 \'WU\' command with invalid number of parameters (%d)!\n",
|
||||
num_params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,433 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 character processing for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* AD_define_alternate() - Define the alternate font.
|
||||
* CF_character_fill() - Set whether or not to fill or outline
|
||||
* characters.
|
||||
* CP_character_plot() - Move the current pen position for the given
|
||||
* number of columns and rows.
|
||||
* DI_absolute_direction() - Set the direction vector for text.
|
||||
* DR_relative_direction() - Set the relative direction vector for text.
|
||||
* DT_define_label_term() - Set the label string terminator.
|
||||
* DV_define_variable_path() - Define a path for text.
|
||||
* ES_extra_space() - Set extra spacing (kerning) between characters.
|
||||
* LB_label() - Display a label string.
|
||||
* LO_label_origin() - Set the label origin.
|
||||
* SA_select_alternate() - Select the alternate font.
|
||||
* SD_define_standard() - Define the standard font...
|
||||
* SI_absolute_size() - Set the absolute size of text.
|
||||
* SL_character_slant() - Set the slant of text.
|
||||
* SR_relative_size() - Set the relative size of text.
|
||||
* SS_select_standard() - Select the standard font for text.
|
||||
* TD_transparent_data() - Send transparent print data.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'AD_define_alternate()' - Define the alternate font.
|
||||
*/
|
||||
|
||||
void
|
||||
AD_define_alternate(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
int typeface, /* Typeface number */
|
||||
posture, /* Posture number */
|
||||
weight; /* Weight number */
|
||||
float height; /* Height/size of font */
|
||||
|
||||
|
||||
/*
|
||||
* Set default font attributes...
|
||||
*/
|
||||
|
||||
typeface = 48;
|
||||
posture = 0;
|
||||
weight = 0;
|
||||
height = 11.5;
|
||||
|
||||
/*
|
||||
* Loop through parameter value pairs...
|
||||
*/
|
||||
|
||||
for (i = 0; i < (num_params - 1); i += 2)
|
||||
switch ((int)params[i].value.number)
|
||||
{
|
||||
case 4 :
|
||||
height = params[i + 1].value.number;
|
||||
break;
|
||||
case 5 :
|
||||
posture = (int)params[i + 1].value.number;
|
||||
break;
|
||||
case 6 :
|
||||
weight = (int)params[i + 1].value.number;
|
||||
break;
|
||||
case 7 :
|
||||
typeface = (int)params[i + 1].value.number;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the font...
|
||||
*/
|
||||
|
||||
Outputf("/SA { /%s%s%s%s findfont %.1f scalefont setfont } def\n",
|
||||
typeface == 48 ? "Courier" : "Helvetica",
|
||||
(weight != 0 || posture != 0) ? "-" : "",
|
||||
weight != 0 ? "Bold" : "",
|
||||
posture != 0 ? "Oblique" : "",
|
||||
height);
|
||||
|
||||
CharHeight[1] = height;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'CF_character_fill()' - Set whether or not to fill or outline characters.
|
||||
*/
|
||||
|
||||
void
|
||||
CF_character_fill(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
CharFillMode = 0;
|
||||
else
|
||||
CharFillMode = (int)params[0].value.number;
|
||||
|
||||
if (num_params == 2)
|
||||
CharPen = (int)params[1].value.number;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'CP_character_plot()' - Move the current pen position for the given number
|
||||
* of columns and rows.
|
||||
*/
|
||||
|
||||
void
|
||||
CP_character_plot(int num_params,
|
||||
param_t *params)
|
||||
{
|
||||
if (num_params < 2)
|
||||
return;
|
||||
|
||||
switch (Rotation)
|
||||
{
|
||||
case 0:
|
||||
PenPosition[0] += params[0].value.number * 1.2f / CharHeight[CharFont];
|
||||
PenPosition[1] += params[1].value.number * CharHeight[CharFont];
|
||||
break;
|
||||
case 90:
|
||||
PenPosition[0] -= params[1].value.number * 1.2f / CharHeight[CharFont];
|
||||
PenPosition[1] += params[0].value.number * CharHeight[CharFont];
|
||||
break;
|
||||
case 180:
|
||||
PenPosition[0] -= params[0].value.number * 1.2f / CharHeight[CharFont];
|
||||
PenPosition[1] -= params[1].value.number * CharHeight[CharFont];
|
||||
break;
|
||||
case 270:
|
||||
PenPosition[0] += params[1].value.number * 1.2f / CharHeight[CharFont];
|
||||
PenPosition[1] -= params[0].value.number * CharHeight[CharFont];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'DI_absolute_direction()' - Set the direction vector for text.
|
||||
*/
|
||||
|
||||
void
|
||||
DI_absolute_direction(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
Outputf(CharFont == 0 ? "SS\n" : "SA\n");
|
||||
|
||||
if (num_params == 2)
|
||||
Outputf("currentfont [ %f %f %f %f 0.0 0.0 ] makefont setfont\n",
|
||||
params[0].value.number, -params[1].value.number,
|
||||
params[1].value.number, params[0].value.number);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'DR_relative_direction()' - Set the relative direction vector for text.
|
||||
*/
|
||||
|
||||
void
|
||||
DR_relative_direction(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'DT_define_label_term()' - Set the label string terminator.
|
||||
*/
|
||||
|
||||
void
|
||||
DT_define_label_term(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
StringTerminator = '\003';
|
||||
else
|
||||
StringTerminator = params[0].value.string[0];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'DV_define_variable_path()' - Define a path for text.
|
||||
*/
|
||||
|
||||
void
|
||||
DV_define_variable_path(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ES_extra_space()' - Set extra spacing (kerning) between characters.
|
||||
*/
|
||||
|
||||
void
|
||||
ES_extra_space(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'LB_label()' - Display a label string.
|
||||
*/
|
||||
|
||||
void
|
||||
LB_label(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
char *s; /* Pointer into string */
|
||||
|
||||
|
||||
if (num_params == 0)
|
||||
return;
|
||||
|
||||
Outputf("gsave\n");
|
||||
Outputf("currentmiterlimit 1.0 setmiterlimit\n");
|
||||
Outputf("MP\n");
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
Outputf("(");
|
||||
for (s = params[0].value.string; *s != '\0'; s ++)
|
||||
if (strchr("()\\", *s) != NULL)
|
||||
Outputf("\\%c", *s);
|
||||
else
|
||||
Outputf("%c", *s);
|
||||
Outputf(") true charpath\n");
|
||||
|
||||
if (CharFillMode != 1)
|
||||
Outputf("FI\n");
|
||||
if (CharFillMode == 1 || CharFillMode == 3)
|
||||
Outputf("P%d ST\n", CharPen);
|
||||
|
||||
Outputf("setmiterlimit\n");
|
||||
Outputf("grestore\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'LO_label_origin()' - Set the label origin.
|
||||
*/
|
||||
|
||||
void
|
||||
LO_label_origin(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SA_select_alternate()' - Select the alternate font.
|
||||
*/
|
||||
|
||||
void
|
||||
SA_select_alternate(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
Outputf("SA\n");
|
||||
CharFont = 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SD_define_standard()' - Define the standard font...
|
||||
*/
|
||||
|
||||
void
|
||||
SD_define_standard(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
int typeface, /* Typeface number */
|
||||
posture, /* Posture number */
|
||||
weight; /* Weight number */
|
||||
float height; /* Height/size of font */
|
||||
|
||||
|
||||
/*
|
||||
* Set default font attributes...
|
||||
*/
|
||||
|
||||
typeface = 48;
|
||||
posture = 0;
|
||||
weight = 0;
|
||||
height = 11.5;
|
||||
|
||||
/*
|
||||
* Loop through parameter value pairs...
|
||||
*/
|
||||
|
||||
for (i = 0; i < (num_params - 1); i += 2)
|
||||
switch ((int)params[i].value.number)
|
||||
{
|
||||
case 4 :
|
||||
height = params[i + 1].value.number;
|
||||
break;
|
||||
case 5 :
|
||||
posture = (int)params[i + 1].value.number;
|
||||
break;
|
||||
case 6 :
|
||||
weight = (int)params[i + 1].value.number;
|
||||
break;
|
||||
case 7 :
|
||||
typeface = (int)params[i + 1].value.number;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the font...
|
||||
*/
|
||||
|
||||
Outputf("/SS { /%s%s%s%s findfont %.1f scalefont setfont } def\n",
|
||||
typeface == 48 ? "Courier" : "Helvetica",
|
||||
(weight != 0 || posture != 0) ? "-" : "",
|
||||
weight != 0 ? "Bold" : "",
|
||||
posture != 0 ? "Oblique" : "",
|
||||
height);
|
||||
|
||||
CharHeight[0] = height;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SI_absolute_size()' - Set the absolute size of text.
|
||||
*/
|
||||
|
||||
void
|
||||
SI_absolute_size(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SL_character_slant()' - Set the slant of text.
|
||||
*/
|
||||
|
||||
void
|
||||
SL_character_slant(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SR_relative_size()' - Set the relative size of text.
|
||||
*/
|
||||
|
||||
void
|
||||
SR_relative_size(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SS_select_standard()' - Select the standard font for text.
|
||||
*/
|
||||
|
||||
void
|
||||
SS_select_standard(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
Outputf("SS\n");
|
||||
CharFont = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'TD_transparent_data()' - Send transparent print data.
|
||||
*/
|
||||
|
||||
void
|
||||
TD_transparent_data(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,473 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 configuration routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* update_transform() - Update the page transformation matrix as needed.
|
||||
* BP_begin_plot() - Start a plot...
|
||||
* DF_default_values() - Set all state info to the default values.
|
||||
* IN_initialize() - Initialize the plotter.
|
||||
* IP_input_absolute() - Set P1 and P2 values for the plot.
|
||||
* IR_input_relative() - Update P1 and P2.
|
||||
* IW_input_window() - Setup an input window.
|
||||
* PG_advance_page() - Eject the current page.
|
||||
* PS_plot_size() - Set the plot size.
|
||||
* RO_rotate() - Rotate the plot.
|
||||
* RP_replot() - Replot the current page.
|
||||
* SC_scale() - Set user-defined scaling.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'update_transform()' - Update the page transformation matrix as needed.
|
||||
*/
|
||||
|
||||
void
|
||||
update_transform(void)
|
||||
{
|
||||
float width, /* Plot width */
|
||||
height; /* Plot height */
|
||||
float page_width, /* Actual page width in points */
|
||||
page_length; /* Actual page length in points */
|
||||
float scaling; /* Scaling factor */
|
||||
|
||||
|
||||
/*
|
||||
* Get the page and input window sizes...
|
||||
*/
|
||||
|
||||
width = IW2[0] - IW1[0];
|
||||
height = IW2[1] - IW1[1];
|
||||
|
||||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Scale the plot as needed...
|
||||
*/
|
||||
|
||||
if (FitPlot)
|
||||
{
|
||||
page_width = PageRight - PageLeft;
|
||||
page_length = PageTop - PageBottom;
|
||||
|
||||
if (Rotation == 0 || Rotation == 180)
|
||||
{
|
||||
scaling = page_width / width;
|
||||
if (scaling > (page_length / width))
|
||||
scaling = page_length / width;
|
||||
}
|
||||
else
|
||||
{
|
||||
scaling = page_width / height;
|
||||
if (scaling > (page_length / height))
|
||||
scaling = page_length / height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
page_width = PlotSize[0];
|
||||
page_length = PlotSize[1];
|
||||
|
||||
if (Rotation == 0 || Rotation == 180)
|
||||
scaling = page_width / width;
|
||||
else
|
||||
scaling = page_width / height;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate a new transformation matrix...
|
||||
*/
|
||||
|
||||
switch (Rotation)
|
||||
{
|
||||
case 0 :
|
||||
Transform[0][0] = scaling;
|
||||
Transform[0][1] = 0.0;
|
||||
Transform[0][2] = -IW1[0] * scaling;
|
||||
Transform[1][0] = 0.0;
|
||||
Transform[1][1] = scaling;
|
||||
Transform[1][2] = -IW1[1] * scaling;
|
||||
break;
|
||||
|
||||
case 90 :
|
||||
Transform[0][0] = 0.0;
|
||||
Transform[0][1] = -scaling;
|
||||
Transform[0][2] = (height - IW1[0]) * scaling;
|
||||
Transform[1][0] = scaling;
|
||||
Transform[1][1] = 0.0;
|
||||
Transform[1][2] = -IW1[1] * scaling;
|
||||
break;
|
||||
|
||||
case 180 :
|
||||
Transform[0][0] = -scaling;
|
||||
Transform[0][1] = 0.0;
|
||||
Transform[0][2] = (height - IW1[0]) * scaling;
|
||||
Transform[1][0] = 0.0;
|
||||
Transform[1][1] = -scaling;
|
||||
Transform[1][2] = (width - IW1[1]) * scaling;
|
||||
break;
|
||||
|
||||
case 270 :
|
||||
Transform[0][0] = 0.0;
|
||||
Transform[0][1] = scaling;
|
||||
Transform[0][2] = -IW1[0] * scaling;
|
||||
Transform[1][0] = -scaling;
|
||||
Transform[1][1] = 0.0;
|
||||
Transform[1][2] = (width - IW1[1]) * scaling;
|
||||
break;
|
||||
}
|
||||
|
||||
PenScaling = Transform[0][0] + Transform[0][1];
|
||||
|
||||
if (PenScaling < 0.0)
|
||||
PenScaling = -PenScaling;
|
||||
|
||||
if (PageDirty)
|
||||
printf("/PenScaling %.3f def W%d\n", PenScaling, PenNumber);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'BP_begin_plot()' - Start a plot...
|
||||
*/
|
||||
|
||||
void
|
||||
BP_begin_plot(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'DF_default_values()' - Set all state info to the default values.
|
||||
*/
|
||||
|
||||
void
|
||||
DF_default_values(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
AC_anchor_corner(0, NULL);
|
||||
AD_define_alternate(0, NULL);
|
||||
SD_define_standard(0, NULL);
|
||||
CF_character_fill(0, NULL);
|
||||
DI_absolute_direction(0, NULL);
|
||||
DT_define_label_term(0, NULL);
|
||||
DV_define_variable_path(0, NULL);
|
||||
ES_extra_space(0, NULL);
|
||||
FT_fill_type(0, NULL);
|
||||
IW_input_window(0, NULL);
|
||||
LA_line_attributes(0, NULL);
|
||||
LO_label_origin(0, NULL);
|
||||
LT_line_type(0, NULL);
|
||||
PA_plot_absolute(0, NULL);
|
||||
PolygonMode = 0;
|
||||
RF_raster_fill(0, NULL);
|
||||
SC_scale(0, NULL);
|
||||
SM_symbol_mode(0, NULL);
|
||||
SS_select_standard(0, NULL);
|
||||
TD_transparent_data(0, NULL);
|
||||
UL_user_line_type(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'IN_initialize()' - Initialize the plotter.
|
||||
*/
|
||||
|
||||
void
|
||||
IN_initialize(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
DF_default_values(0, NULL);
|
||||
PU_pen_up(0, NULL);
|
||||
RO_rotate(0, NULL);
|
||||
PS_plot_size(0, NULL);
|
||||
WU_width_units(0, NULL);
|
||||
PW_pen_width(0, NULL);
|
||||
SP_select_pen(0, NULL);
|
||||
|
||||
PenPosition[0] = PenPosition[1] = 0.0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'IP_input_absolute()' - Set P1 and P2 values for the plot.
|
||||
*/
|
||||
|
||||
void
|
||||
IP_input_absolute(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
{
|
||||
P1[0] = 0.0;
|
||||
P1[1] = 0.0;
|
||||
P2[0] = PlotSize[0] / 72.0f * 1016.0f;
|
||||
P2[1] = PlotSize[1] / 72.0f * 1016.0f;
|
||||
}
|
||||
else if (num_params == 2)
|
||||
{
|
||||
P2[0] -= P1[0];
|
||||
P2[1] -= P1[1];
|
||||
P1[0] = params[0].value.number;
|
||||
P1[1] = params[1].value.number;
|
||||
P2[0] += P1[0];
|
||||
P2[1] += P1[1];
|
||||
}
|
||||
else if (num_params == 4)
|
||||
{
|
||||
P1[0] = params[0].value.number;
|
||||
P1[1] = params[1].value.number;
|
||||
P2[0] = params[2].value.number;
|
||||
P2[1] = params[3].value.number;
|
||||
}
|
||||
|
||||
IW1[0] = P1[0];
|
||||
IW1[1] = P1[1];
|
||||
IW2[0] = P2[0];
|
||||
IW2[1] = P2[1];
|
||||
|
||||
update_transform();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'IR_input_relative()' - Update P1 and P2.
|
||||
*/
|
||||
|
||||
void
|
||||
IR_input_relative(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
{
|
||||
P1[0] = PageLeft / 72.0f * 1016.0f;
|
||||
P1[1] = PageBottom / 72.0f * 1016.0f;
|
||||
P2[0] = PageRight / 72.0f * 1016.0f;
|
||||
P2[1] = PageTop / 72.0f * 1016.0f;
|
||||
}
|
||||
else if (num_params == 2)
|
||||
{
|
||||
P2[0] -= P1[0];
|
||||
P2[1] -= P1[1];
|
||||
P1[0] = params[0].value.number * PlotSize[0] / 72.0f * 1016.0f / 100.0f;
|
||||
P1[1] = params[1].value.number * PlotSize[1] / 72.0f * 1016.0f / 100.0f;
|
||||
P2[0] += P1[0];
|
||||
P2[1] += P1[1];
|
||||
}
|
||||
else if (num_params == 4)
|
||||
{
|
||||
P1[0] = params[0].value.number * PlotSize[0] / 72.0f * 1016.0f / 100.0f;
|
||||
P1[1] = params[1].value.number * PlotSize[1] / 72.0f * 1016.0f / 100.0f;
|
||||
P2[0] = params[2].value.number * PlotSize[0] / 72.0f * 1016.0f / 100.0f;
|
||||
P2[1] = params[3].value.number * PlotSize[1] / 72.0f * 1016.0f / 100.0f;
|
||||
}
|
||||
|
||||
IW1[0] = P1[0];
|
||||
IW1[1] = P1[1];
|
||||
IW2[0] = P2[0];
|
||||
IW2[1] = P2[1];
|
||||
|
||||
update_transform();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'IW_input_window()' - Setup an input window.
|
||||
*/
|
||||
|
||||
void
|
||||
IW_input_window(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
{
|
||||
IW1[0] = P1[0];
|
||||
IW1[1] = P1[1];
|
||||
IW2[0] = P2[0];
|
||||
IW2[1] = P2[1];
|
||||
}
|
||||
else if (num_params == 4)
|
||||
{
|
||||
IW1[0] = params[0].value.number;
|
||||
IW1[1] = params[1].value.number;
|
||||
IW2[0] = params[2].value.number;
|
||||
IW2[1] = params[3].value.number;
|
||||
}
|
||||
|
||||
update_transform();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PG_advance_page()' - Eject the current page.
|
||||
*/
|
||||
|
||||
void
|
||||
PG_advance_page(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
if (PageDirty)
|
||||
{
|
||||
puts("grestore");
|
||||
puts("showpage");
|
||||
|
||||
PageDirty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PS_plot_size()' - Set the plot size.
|
||||
*/
|
||||
|
||||
void
|
||||
PS_plot_size(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
switch (num_params)
|
||||
{
|
||||
case 0 :
|
||||
if (Rotation == 0 || Rotation == 180)
|
||||
{
|
||||
PlotSize[0] = PageRight - PageLeft;
|
||||
PlotSize[1] = PageTop - PageBottom;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlotSize[0] = PageTop - PageBottom;
|
||||
PlotSize[1] = PageRight - PageLeft;
|
||||
}
|
||||
break;
|
||||
case 1 :
|
||||
if (Rotation == 0 || Rotation == 180)
|
||||
{
|
||||
PlotSize[1] = 72.0f * params[0].value.number / 1016.0f;
|
||||
PlotSize[0] = 0.75f * PlotSize[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
PlotSize[0] = 72.0f * params[0].value.number / 1016.0f;
|
||||
PlotSize[1] = 0.75f * PlotSize[0];
|
||||
}
|
||||
break;
|
||||
case 2 :
|
||||
if (Rotation == 0 || Rotation == 180)
|
||||
{
|
||||
PlotSize[0] = 72.0f * params[1].value.number / 1016.0f;
|
||||
PlotSize[1] = 72.0f * params[0].value.number / 1016.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlotSize[0] = 72.0f * params[0].value.number / 1016.0f;
|
||||
PlotSize[1] = 72.0f * params[1].value.number / 1016.0f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is required for buggy files that don't set the input window.
|
||||
*/
|
||||
|
||||
IP_input_absolute(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RO_rotate()' - Rotate the plot.
|
||||
*/
|
||||
|
||||
void
|
||||
RO_rotate(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
Rotation = 0;
|
||||
else
|
||||
Rotation = (int)params[0].value.number;
|
||||
|
||||
update_transform();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RP_replot()' - Replot the current page.
|
||||
*/
|
||||
|
||||
void
|
||||
RP_replot(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'SC_scale()' - Set user-defined scaling.
|
||||
*/
|
||||
|
||||
void
|
||||
SC_scale(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0)
|
||||
ScalingType = -1;
|
||||
else if (num_params > 3)
|
||||
{
|
||||
Scaling1[0] = params[0].value.number;
|
||||
Scaling2[0] = params[1].value.number;
|
||||
Scaling1[1] = params[2].value.number;
|
||||
Scaling2[1] = params[3].value.number;
|
||||
|
||||
if (num_params > 4)
|
||||
ScalingType = (int)params[4].value.number;
|
||||
else
|
||||
ScalingType = 0;
|
||||
}
|
||||
|
||||
update_transform();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,232 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 input processing for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ParseCommand() - Parse an HPGL/2 command.
|
||||
* FreeParameters() - Free all string parameter values.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#define MAX_PARAMS 16384
|
||||
|
||||
|
||||
/*
|
||||
* 'ParseCommand()' - Parse an HPGL/2 command.
|
||||
*
|
||||
* Returns the number of parameters seen or -1 on EOF.
|
||||
*/
|
||||
|
||||
int /* O - -1 on EOF, # params otherwise */
|
||||
ParseCommand(FILE *fp, /* I - File to read from */
|
||||
char *name, /* O - Name of command */
|
||||
param_t **params) /* O - Parameter list */
|
||||
{
|
||||
int num_params, /* Number of parameters seen */
|
||||
ch, /* Current char */
|
||||
done, /* Non-zero when the current command is read */
|
||||
i; /* Looping var */
|
||||
char buf[262144]; /* String buffer */
|
||||
static param_t p[MAX_PARAMS]; /* Parameter buffer */
|
||||
|
||||
|
||||
num_params = 0;
|
||||
done = 0;
|
||||
|
||||
do
|
||||
{
|
||||
while ((ch = getc(fp)) != EOF)
|
||||
if (strchr(" \t\r\n,;", ch) == NULL)
|
||||
break;
|
||||
|
||||
if (ch == EOF)
|
||||
return (-1);
|
||||
|
||||
if (ch == 0x1b)
|
||||
switch (getc(fp))
|
||||
{
|
||||
case '.' : /* HP-GL/2 job control */
|
||||
i = getc(fp);
|
||||
|
||||
if (strchr(")Z", i) != NULL)
|
||||
{
|
||||
/*
|
||||
* 'Printer Off' command - look for next 'Printer On' command...
|
||||
*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while ((i = getc(fp)) != EOF && i != 0x1b);
|
||||
|
||||
if (i == EOF)
|
||||
return (-1);
|
||||
|
||||
if (getc(fp) != '.')
|
||||
continue;
|
||||
|
||||
if ((i = getc(fp)) == '(' ||
|
||||
i == 'Y')
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strchr("@HIMNTI\003", i) != NULL)
|
||||
{
|
||||
while ((i = getc(fp)) != EOF && i != ':');
|
||||
}
|
||||
break;
|
||||
|
||||
default : /* HP RTL/PCL control */
|
||||
while ((i = getc(fp)) != EOF && !isupper(i));
|
||||
break;
|
||||
}
|
||||
} while (ch == 0x1b);
|
||||
|
||||
name[0] = ch;
|
||||
name[1] = getc(fp);
|
||||
name[2] = '\0';
|
||||
|
||||
if (strcasecmp(name, "LB") == 0)
|
||||
{
|
||||
for (i = 0; (ch = getc(fp)) != StringTerminator; i ++)
|
||||
buf[i] = ch;
|
||||
buf[i] = '\0';
|
||||
p[num_params].type = PARAM_STRING;
|
||||
p[num_params].value.string = strdup(buf);
|
||||
num_params ++;
|
||||
}
|
||||
else if (strcasecmp(name, "SM") == 0)
|
||||
{
|
||||
buf[0] = getc(fp);
|
||||
buf[1] = '\0';
|
||||
p[num_params].type = PARAM_STRING;
|
||||
p[num_params].value.string = strdup(buf);
|
||||
num_params ++;
|
||||
}
|
||||
else if (strcasecmp(name, "DT") == 0)
|
||||
{
|
||||
if ((buf[0] = getc(fp)) != ';')
|
||||
{
|
||||
buf[1] = '\0';
|
||||
p[num_params].type = PARAM_STRING;
|
||||
p[num_params].value.string = strdup(buf);
|
||||
num_params ++;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(name, "PE") == 0)
|
||||
{
|
||||
for (i = 0; i < (sizeof(buf) - 1); i ++)
|
||||
if ((buf[i] = getc(fp)) == ';')
|
||||
break;
|
||||
|
||||
buf[i] = '\0';
|
||||
p[num_params].type = PARAM_STRING;
|
||||
p[num_params].value.string = strdup(buf);
|
||||
num_params ++;
|
||||
}
|
||||
|
||||
while (!done)
|
||||
switch (ch = getc(fp))
|
||||
{
|
||||
case ',' :
|
||||
case ' ' :
|
||||
case '\n' :
|
||||
case '\r' :
|
||||
case '\t' :
|
||||
break;
|
||||
|
||||
case '\"' :
|
||||
fscanf(fp, "%[^\"]\"", buf);
|
||||
if (num_params < MAX_PARAMS)
|
||||
{
|
||||
p[num_params].type = PARAM_STRING;
|
||||
p[num_params].value.string = strdup(buf);
|
||||
num_params ++;
|
||||
};
|
||||
break;
|
||||
|
||||
case '-' :
|
||||
case '+' :
|
||||
ungetc(ch, fp);
|
||||
fscanf(fp, "%f", &(p[num_params].value.number));
|
||||
if (num_params < MAX_PARAMS)
|
||||
{
|
||||
p[num_params].type = PARAM_RELATIVE;
|
||||
num_params ++;
|
||||
}
|
||||
break;
|
||||
case '0' :
|
||||
case '1' :
|
||||
case '2' :
|
||||
case '3' :
|
||||
case '4' :
|
||||
case '5' :
|
||||
case '6' :
|
||||
case '7' :
|
||||
case '8' :
|
||||
case '9' :
|
||||
case '.' :
|
||||
ungetc(ch, fp);
|
||||
fscanf(fp, "%f", &(p[num_params].value.number));
|
||||
if (num_params < MAX_PARAMS)
|
||||
{
|
||||
p[num_params].type = PARAM_ABSOLUTE;
|
||||
num_params ++;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
ungetc(ch, fp);
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
*params = p;
|
||||
return (num_params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'FreeParameters()' - Free all string parameter values.
|
||||
*/
|
||||
|
||||
void
|
||||
FreeParameters(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameter values */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
for (i = 0; i < num_params; i ++)
|
||||
if (params[i].type == PARAM_STRING)
|
||||
free(params[i].value.string);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 filter main entry for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry for HP-GL/2 filter.
|
||||
* compare_names() - Compare two command names.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
/*#define DEBUG*/
|
||||
#define _HPGL_MAIN_C_
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* HP-GL/2 command table...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[4]; /* Name of command */
|
||||
void (*func)(int, param_t *); /* Function to call */
|
||||
} name_t;
|
||||
|
||||
static name_t commands[] =
|
||||
{
|
||||
{ "BP", BP_begin_plot },
|
||||
{ "DF", DF_default_values },
|
||||
{ "IN", IN_initialize },
|
||||
{ "IP", IP_input_absolute },
|
||||
{ "IR", IR_input_relative },
|
||||
{ "IW", IW_input_window },
|
||||
{ "PG", PG_advance_page },
|
||||
{ "RO", RO_rotate },
|
||||
{ "RP", RP_replot },
|
||||
{ "SC", SC_scale },
|
||||
{ "AA", AA_arc_absolute },
|
||||
{ "AR", AR_arc_relative },
|
||||
{ "AT", AT_arc_absolute3 },
|
||||
{ "CI", CI_circle },
|
||||
{ "PA", PA_plot_absolute },
|
||||
{ "PD", PD_pen_down },
|
||||
{ "PE", PE_polyline_encoded },
|
||||
{ "PR", PR_plot_relative },
|
||||
{ "PS", PS_plot_size },
|
||||
{ "PU", PU_pen_up },
|
||||
{ "RT", RT_arc_relative3 },
|
||||
{ "EA", EA_edge_rect_absolute },
|
||||
{ "EP", EP_edge_polygon },
|
||||
{ "ER", ER_edge_rect_relative },
|
||||
{ "EW", EW_edge_wedge },
|
||||
{ "FP", FP_fill_polygon },
|
||||
{ "PM", PM_polygon_mode },
|
||||
{ "RA", RA_fill_rect_absolute },
|
||||
{ "RR", RR_fill_rect_relative },
|
||||
{ "WG", WG_fill_wedge },
|
||||
{ "AD", AD_define_alternate },
|
||||
{ "CF", CF_character_fill },
|
||||
{ "CP", CP_character_plot },
|
||||
{ "DI", DI_absolute_direction },
|
||||
{ "DR", DR_relative_direction },
|
||||
{ "DT", DT_define_label_term },
|
||||
{ "DV", DV_define_variable_path },
|
||||
{ "ES", ES_extra_space },
|
||||
{ "LB", LB_label },
|
||||
{ "LO", LO_label_origin },
|
||||
{ "SA", SA_select_alternate },
|
||||
{ "SD", SD_define_standard },
|
||||
{ "SI", SI_absolute_size },
|
||||
{ "SL", SL_character_slant },
|
||||
{ "SR", SR_relative_size },
|
||||
{ "SS", SS_select_standard },
|
||||
{ "TD", TD_transparent_data },
|
||||
{ "AC", AC_anchor_corner },
|
||||
{ "FT", FT_fill_type },
|
||||
{ "LA", LA_line_attributes },
|
||||
{ "LT", LT_line_type },
|
||||
{ "NP", NP_number_pens },
|
||||
{ "PC", PC_pen_color },
|
||||
{ "CR", CR_color_range },
|
||||
{ "PW", PW_pen_width },
|
||||
{ "RF", RF_raster_fill },
|
||||
{ "SM", SM_symbol_mode },
|
||||
{ "SP", SP_select_pen },
|
||||
{ "UL", UL_user_line_type },
|
||||
{ "WU", WU_width_units }
|
||||
};
|
||||
#define NUM_COMMANDS (sizeof(commands) / sizeof(name_t))
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int compare_names(const void *p1, const void *p2);
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry for HP-GL/2 filter.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
FILE *fp; /* Input file */
|
||||
ppd_file_t *ppd; /* PPD file */
|
||||
int num_params; /* Number of parameters */
|
||||
param_t *params; /* Command parameters */
|
||||
name_t *command, /* Command */
|
||||
name; /* Name of command */
|
||||
int num_options; /* Number of print options */
|
||||
cups_option_t *options; /* Print options */
|
||||
const char *val; /* Option value */
|
||||
int shading; /* -1 = black, 0 = grey, 1 = color */
|
||||
float penwidth; /* Default pen width */
|
||||
|
||||
|
||||
if (argc < 6 || argc > 7)
|
||||
{
|
||||
fputs("ERROR: hpgltops job-id user title copies options [file]\n", stderr);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have 7 arguments, print the file named on the command-line.
|
||||
* Otherwise, send stdin instead...
|
||||
*/
|
||||
|
||||
if (argc == 6)
|
||||
fp = stdin;
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Try to open the print file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(argv[6], "rb")) == NULL)
|
||||
{
|
||||
perror("ERROR: unable to open print file - ");
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process command-line options and write the prolog...
|
||||
*/
|
||||
|
||||
options = NULL;
|
||||
num_options = cupsParseOptions(argv[5], 0, &options);
|
||||
|
||||
if ((ppd = SetCommonOptions(num_options, options, 1)) != NULL)
|
||||
ppdClose(ppd);
|
||||
|
||||
shading = 1;
|
||||
penwidth = 1.0;
|
||||
|
||||
if ((val = cupsGetOption("blackplot", num_options, options)) != NULL)
|
||||
shading = 0;
|
||||
|
||||
if ((val = cupsGetOption("fitplot", num_options, options)) != NULL)
|
||||
FitPlot = 1;
|
||||
|
||||
if ((val = cupsGetOption("penwidth", num_options, options)) != NULL)
|
||||
penwidth = (float)atof(val);
|
||||
|
||||
/*
|
||||
* Write the PostScript prolog and initialize the plotting "engine"...
|
||||
*/
|
||||
|
||||
OutputProlog(argv[3], argv[2], shading, penwidth);
|
||||
|
||||
IP_input_absolute(0, NULL);
|
||||
|
||||
/*
|
||||
* Sort the command array...
|
||||
*/
|
||||
|
||||
qsort(commands, NUM_COMMANDS, sizeof(name_t),
|
||||
(int (*)(const void *, const void *))compare_names);
|
||||
|
||||
/*
|
||||
* Read commands until we reach the end of file.
|
||||
*/
|
||||
|
||||
while ((num_params = ParseCommand(fp, name.name, ¶ms)) >= 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int i;
|
||||
fprintf(stderr, "DEBUG: %s(%d)", name.name, num_params);
|
||||
for (i = 0; i < num_params; i ++)
|
||||
if (params[i].type == PARAM_STRING)
|
||||
fprintf(stderr, " \'%s\'", params[i].value.string);
|
||||
else
|
||||
fprintf(stderr, " %f", params[i].value.number);
|
||||
fputs("\n", stderr);
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
if ((command = bsearch(&name, commands, NUM_COMMANDS, sizeof(name_t),
|
||||
(int (*)(const void *, const void *))compare_names)) != NULL)
|
||||
(*command->func)(num_params, params);
|
||||
|
||||
FreeParameters(num_params, params);
|
||||
}
|
||||
|
||||
OutputTrailer();
|
||||
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'compare_names()' - Compare two command names.
|
||||
*/
|
||||
|
||||
static int /* O - Result of strcasecmp() on names */
|
||||
compare_names(const void *p1, /* I - First name */
|
||||
const void *p2) /* I - Second name */
|
||||
{
|
||||
return (strcasecmp(((name_t *)p1)->name, ((name_t *)p2)->name));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,380 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 polygon routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* EA_edge_rect_absolute() - Draw a rectangle.
|
||||
* EP_edge_polygon() - Stroke the edges of a polygon.
|
||||
* ER_edge_rect_relative() - Draw a rectangle relative to the current
|
||||
* EW_edge_wedge() - Draw a pie wedge.
|
||||
* FP_fill_polygon() - Fill a polygon.
|
||||
* PM_polygon_mode() - Set the polygon drawing mode.
|
||||
* RA_fill_rect_absolute() - Fill a rectangle.
|
||||
* RR_fill_rect_relative() - Fill a rectangle relative to the current
|
||||
* WG_fill_wedge() - Fill a pie wedge.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'EA_edge_rect_absolute()' - Draw a rectangle.
|
||||
*/
|
||||
|
||||
void
|
||||
EA_edge_rect_absolute(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
|
||||
|
||||
if (num_params < 2)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
Transform[0][2];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
Transform[1][2];
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], y);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'EP_edge_polygon()' - Stroke the edges of a polygon.
|
||||
*/
|
||||
|
||||
void
|
||||
EP_edge_polygon(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ER_edge_rect_relative()' - Draw a rectangle relative to the current
|
||||
* pen position.
|
||||
*/
|
||||
|
||||
void
|
||||
ER_edge_rect_relative(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
|
||||
|
||||
if (num_params < 2)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
PenPosition[0];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
PenPosition[1];
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], y);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'EW_edge_wedge()' - Draw a pie wedge.
|
||||
*/
|
||||
|
||||
void
|
||||
EW_edge_wedge(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
float start, end, /* Start and end of arc */
|
||||
theta, /* Current angle */
|
||||
dt, /* Step between points */
|
||||
radius; /* Radius of arc */
|
||||
|
||||
|
||||
if (num_params < 3)
|
||||
return;
|
||||
|
||||
radius = params[0].value.number;
|
||||
start = params[1].value.number;
|
||||
end = start + params[2].value.number;
|
||||
|
||||
if (num_params > 3)
|
||||
dt = (float)fabs(params[3].value.number);
|
||||
else
|
||||
dt = 5.0f;
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (start < end)
|
||||
for (theta = start + dt; theta < end; theta += dt)
|
||||
{
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
|
||||
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
}
|
||||
else
|
||||
for (theta = start - dt; theta > end; theta -= dt)
|
||||
{
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
|
||||
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
}
|
||||
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * end / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * end / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * end / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * end / 180.0) * Transform[1][1]);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'FP_fill_polygon()' - Fill a polygon.
|
||||
*/
|
||||
|
||||
void
|
||||
FP_fill_polygon(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
(void)num_params;
|
||||
(void)params;
|
||||
|
||||
Outputf("FI\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PM_polygon_mode()' - Set the polygon drawing mode.
|
||||
*/
|
||||
|
||||
void
|
||||
PM_polygon_mode(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params == 0 ||
|
||||
params[0].value.number == 0)
|
||||
{
|
||||
Outputf("MP\n");
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
PolygonMode = 1;
|
||||
}
|
||||
else if (params[0].value.number == 2)
|
||||
PolygonMode = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RA_fill_rect_absolute()' - Fill a rectangle.
|
||||
*/
|
||||
|
||||
void
|
||||
RA_fill_rect_absolute(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
|
||||
|
||||
if (num_params < 2)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
Transform[0][2];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
Transform[1][2];
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], y);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("FI\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RR_fill_rect_relative()' - Fill a rectangle relative to the current
|
||||
* pen position.
|
||||
*/
|
||||
|
||||
void
|
||||
RR_fill_rect_relative(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
|
||||
|
||||
if (num_params < 2)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
PenPosition[0];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
PenPosition[1];
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], y);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
Outputf("%.3f %.3f LI\n", x, PenPosition[1]);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("FI\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'WG_fill_wedge()' - Fill a pie wedge.
|
||||
*/
|
||||
|
||||
void
|
||||
WG_fill_wedge(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
float start, end, /* Start and end angles */
|
||||
theta, /* Current angle */
|
||||
dt, /* Step between points */
|
||||
radius; /* Radius of arc */
|
||||
|
||||
|
||||
if (num_params < 3)
|
||||
return;
|
||||
|
||||
radius = params[0].value.number;
|
||||
start = params[1].value.number;
|
||||
end = start + params[2].value.number;
|
||||
|
||||
if (num_params > 3)
|
||||
dt = (float)fabs(params[3].value.number);
|
||||
else
|
||||
dt = 5.0;
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (start < end)
|
||||
for (theta = start + dt; theta < end; theta += dt)
|
||||
{
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
|
||||
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
}
|
||||
else
|
||||
for (theta = start - dt; theta > end; theta -= dt)
|
||||
{
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
|
||||
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
}
|
||||
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * end / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * end / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * end / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * end / 180.0) * Transform[1][1]);
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("FI\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 prolog routines for for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* OutputProlog() - Output the PostScript prolog...
|
||||
* OutputTrailer() - Output the PostScript trailer...
|
||||
* Outputf() - Write a formatted string to the output file, creating the
|
||||
* page header as needed...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/*
|
||||
* 'OutputProlog()' - Output the PostScript prolog...
|
||||
*/
|
||||
|
||||
void
|
||||
OutputProlog(char *title, /* I - Job title */
|
||||
char *user, /* I - Username */
|
||||
int shading, /* I - Type of shading */
|
||||
float penwidth) /* I - Default pen width */
|
||||
{
|
||||
FILE *prolog; /* Prolog file */
|
||||
char line[255]; /* Line from prolog file */
|
||||
time_t curtime; /* Current time */
|
||||
struct tm *curtm; /* Current date */
|
||||
|
||||
|
||||
curtime = time(NULL);
|
||||
curtm = localtime(&curtime);
|
||||
|
||||
puts("%!PS-Adobe-3.0");
|
||||
printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n",
|
||||
PageLeft, PageBottom, PageRight, PageTop);
|
||||
puts("%%Pages: (atend)");
|
||||
printf("%%%%LanguageLevel: %d\n", LanguageLevel);
|
||||
puts("%%DocumentData: Clean7Bit");
|
||||
puts("%%DocumentSuppliedResources: procset hpgltops 1.0 0");
|
||||
puts("%%DocumentNeededResources: font Courier Helvetica");
|
||||
puts("%%Creator: hpgltops/" CUPS_SVERSION);
|
||||
strftime(line, sizeof(line), "%%%%CreationDate: %c", curtm);
|
||||
puts(line);
|
||||
printf("%%%%Title: %s\n", title);
|
||||
printf("%%%%For: %s\n", user);
|
||||
if (Orientation & 1)
|
||||
puts("%%Orientation: Landscape");
|
||||
puts("%%EndComments");
|
||||
puts("%%BeginProlog");
|
||||
printf("/DefaultPenWidth %.2f def\n", penwidth * 72.0 / 25.4);
|
||||
puts("3.0 setmiterlimit");
|
||||
if (!shading) /* Black only */
|
||||
puts("/setrgbcolor { pop pop pop } bind def");
|
||||
else if (!ColorDevice) /* Greyscale */
|
||||
puts("/setrgbcolor { 0.08 mul exch 0.61 mul add exch 0.31 mul add setgray } bind def\n");
|
||||
|
||||
if ((prolog = fopen(CUPS_DATADIR "/data/HPGLprolog", "r")) == NULL)
|
||||
{
|
||||
perror("ERROR: Unable to open HPGL prolog \"" CUPS_DATADIR "/data/HPGLprolog\" for reading");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof(line), prolog) != NULL)
|
||||
fputs(line, stdout);
|
||||
|
||||
fclose(prolog);
|
||||
|
||||
puts("%%EndProlog");
|
||||
|
||||
IN_initialize(0, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'OutputTrailer()' - Output the PostScript trailer...
|
||||
*/
|
||||
|
||||
void
|
||||
OutputTrailer(void)
|
||||
{
|
||||
if (PageDirty)
|
||||
PG_advance_page(0, NULL);
|
||||
|
||||
puts("%%BeginTrailer");
|
||||
printf("%%%%Pages: %d\n", PageCount);
|
||||
puts("%%EOF");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'Outputf()' - Write a formatted string to the output file, creating the
|
||||
* page header as needed...
|
||||
*/
|
||||
|
||||
int /* O - Number of bytes written */
|
||||
Outputf(const char *format, /* I - Printf-style string */
|
||||
...) /* I - Additional args as needed */
|
||||
{
|
||||
va_list ap; /* Argument pointer */
|
||||
int bytes; /* Number of bytes written */
|
||||
|
||||
|
||||
/*
|
||||
* Write the page header as needed...
|
||||
*/
|
||||
|
||||
if (!PageDirty)
|
||||
{
|
||||
PageDirty = 1;
|
||||
PageCount ++;
|
||||
|
||||
printf("%%%%Page: %d %d\n", PageCount, PageCount);
|
||||
printf("/PenScaling %.3f def\n", PenScaling);
|
||||
puts("gsave");
|
||||
|
||||
if (Duplex && (PageCount & 1) == 0)
|
||||
switch ((PageRotation / 90) & 3)
|
||||
{
|
||||
case 0 :
|
||||
printf("%.1f %.1f translate\n", PageWidth - PageRight, PageBottom);
|
||||
break;
|
||||
case 1 :
|
||||
printf("%.1f %.1f translate\n", PageLength - PageTop,
|
||||
PageWidth - PageRight);
|
||||
break;
|
||||
case 2 :
|
||||
printf("%.1f %.1f translate\n", PageLeft, PageLength - PageTop);
|
||||
break;
|
||||
case 3 :
|
||||
printf("%.1f %.1f translate\n", PageBottom, PageLeft);
|
||||
break;
|
||||
}
|
||||
else
|
||||
switch ((PageRotation / 90) & 3)
|
||||
{
|
||||
case 0 :
|
||||
printf("%.1f %.1f translate\n", PageLeft, PageBottom);
|
||||
break;
|
||||
case 1 :
|
||||
printf("%.1f %.1f translate\n", PageBottom, PageWidth - PageRight);
|
||||
break;
|
||||
case 2 :
|
||||
printf("%.1f %.1f translate\n", PageWidth - PageRight,
|
||||
PageLength - PageTop);
|
||||
break;
|
||||
case 3 :
|
||||
printf("%.1f %.1f translate\n", PageLength - PageTop, PageLeft);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the string to the output file...
|
||||
*/
|
||||
|
||||
va_start(ap, format);
|
||||
bytes = vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return (bytes);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,704 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 vector routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* AA_arc_absolute() - Draw an arc.
|
||||
* AR_arc_relative() - Draw an arc relative to the current pen
|
||||
* AT_arc_absolute3() - Draw an arc using 3 points.
|
||||
* CI_circle() - Draw a circle.
|
||||
* PA_plot_absolute() - Plot a line using absolute coordinates.
|
||||
* PD_pen_down() - Start drawing.
|
||||
* PE_polygon_encoded() - Draw an encoded polyline.
|
||||
* PR_plot_relative() - Plot a line using relative coordinates.
|
||||
* PU_pen_up() - Stop drawing.
|
||||
* RT_arc_relative3() - Draw an arc through 3 points relative to the
|
||||
* decode_number() - Decode an encoded number.
|
||||
* plot_points() - Plot the specified points.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "hpgltops.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static double decode_number(unsigned char **, int, double);
|
||||
static void plot_points(int, param_t *);
|
||||
|
||||
|
||||
/*
|
||||
* 'AA_arc_absolute()' - Draw an arc.
|
||||
*/
|
||||
|
||||
void
|
||||
AA_arc_absolute(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y, /* Transformed coordinates */
|
||||
dx, dy; /* Distance from current pen */
|
||||
float start, end, /* Start and end angles */
|
||||
theta, /* Current angle */
|
||||
dt, /* Step between points */
|
||||
radius; /* Radius of arc */
|
||||
|
||||
|
||||
if (num_params < 3)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
Transform[0][2];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
Transform[1][2];
|
||||
|
||||
dx = PenPosition[0] - x;
|
||||
dy = PenPosition[1] - y;
|
||||
|
||||
start = (float)(180.0 * atan2(dy, dx) / M_PI);
|
||||
if (start < 0.0)
|
||||
start += 360.0f;
|
||||
|
||||
end = start + params[2].value.number;
|
||||
radius = (float)hypot(dx, dy);
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (num_params > 3 && params[3].value.number > 0.0)
|
||||
dt = (float)fabs(params[3].value.number);
|
||||
else
|
||||
dt = 5.0;
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (start < end)
|
||||
for (theta = start + dt; theta < end; theta += dt)
|
||||
{
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * theta / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * theta / 180.0));
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
else
|
||||
for (theta = start - dt; theta > end; theta -= dt)
|
||||
{
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * theta / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * theta / 180.0));
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
}
|
||||
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * end / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * end / 180.0));
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'AR_arc_relative()' - Draw an arc relative to the current pen
|
||||
* position.
|
||||
*/
|
||||
|
||||
void
|
||||
AR_arc_relative(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y, /* Transformed coordinates */
|
||||
dx, dy; /* Distance from current pen */
|
||||
float start, end, /* Start and end angles */
|
||||
theta, /* Current angle */
|
||||
dt, /* Step between points */
|
||||
radius; /* Radius of arc */
|
||||
|
||||
|
||||
if (num_params < 3)
|
||||
return;
|
||||
|
||||
x = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
PenPosition[0];
|
||||
y = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
PenPosition[1];
|
||||
|
||||
dx = PenPosition[0] - x;
|
||||
dy = PenPosition[1] - y;
|
||||
|
||||
start = (float)(180.0 * atan2(dy, dx) / M_PI);
|
||||
if (start < 0.0)
|
||||
start += 360.0f;
|
||||
|
||||
end = start + params[2].value.number;
|
||||
radius = (float)hypot(dx, dy);
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (num_params > 3 && params[3].value.number > 0.0)
|
||||
dt = (float)fabs(params[3].value.number);
|
||||
else
|
||||
dt = 5.0;
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (start < end)
|
||||
for (theta = start + dt; theta < end; theta += dt)
|
||||
{
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * theta / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * theta / 180.0));
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
else
|
||||
for (theta = start - dt; theta > end; theta -= dt)
|
||||
{
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * theta / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * theta / 180.0));
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
}
|
||||
|
||||
PenPosition[0] = (float)(x + radius * cos(M_PI * end / 180.0));
|
||||
PenPosition[1] = (float)(y + radius * sin(M_PI * end / 180.0));
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'AT_arc_absolute3()' - Draw an arc using 3 points.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* Currently this only draws two line segments through the
|
||||
* specified points.
|
||||
*/
|
||||
|
||||
void
|
||||
AT_arc_absolute3(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params < 4)
|
||||
return;
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
PenPosition[0] = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
Transform[0][2];
|
||||
PenPosition[1] = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
Transform[1][2];
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
|
||||
PenPosition[0] = Transform[0][0] * params[2].value.number +
|
||||
Transform[0][1] * params[3].value.number +
|
||||
Transform[0][2];
|
||||
PenPosition[1] = Transform[1][0] * params[2].value.number +
|
||||
Transform[1][1] * params[3].value.number +
|
||||
Transform[1][2];
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'CI_circle()' - Draw a circle.
|
||||
*/
|
||||
|
||||
void
|
||||
CI_circle(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
float x, y; /* Transformed coordinates */
|
||||
float theta, /* Current angle */
|
||||
dt, /* Step between points */
|
||||
radius; /* Radius of circle */
|
||||
|
||||
|
||||
if (num_params < 1)
|
||||
return;
|
||||
|
||||
if (!PenDown)
|
||||
return;
|
||||
|
||||
radius = params[0].value.number;
|
||||
|
||||
if (num_params > 1)
|
||||
dt = (float)fabs(params[1].value.number);
|
||||
else
|
||||
dt = 5.0;
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
for (theta = 0.0; theta < 360.0; theta += dt)
|
||||
{
|
||||
x = (float)(PenPosition[0] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[0][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[0][1]);
|
||||
y = (float)(PenPosition[1] +
|
||||
radius * cos(M_PI * theta / 180.0) * Transform[1][0] +
|
||||
radius * sin(M_PI * theta / 180.0) * Transform[1][1]);
|
||||
|
||||
Outputf("%.3f %.3f %s\n", x, y, theta == 0.0 ? "MO" : "LI");
|
||||
}
|
||||
|
||||
Outputf("CP\n");
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PA_plot_absolute()' - Plot a line using absolute coordinates.
|
||||
*/
|
||||
|
||||
void
|
||||
PA_plot_absolute(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
PenMotion = 0;
|
||||
|
||||
if (num_params > 1)
|
||||
plot_points(num_params, params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PD_pen_down()' - Start drawing.
|
||||
*/
|
||||
|
||||
void
|
||||
PD_pen_down(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
PenDown = 1;
|
||||
|
||||
if (num_params > 1)
|
||||
plot_points(num_params, params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PE_polygon_encoded()' - Draw an encoded polyline.
|
||||
*/
|
||||
|
||||
void
|
||||
PE_polyline_encoded(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
unsigned char *s; /* Pointer into string */
|
||||
int temp, /* Temporary value */
|
||||
base_bits, /* Data bits per byte */
|
||||
draw, /* Draw or move */
|
||||
abscoords; /* Use absolute coordinates */
|
||||
double tx, ty, /* Transformed coordinates */
|
||||
x, y, /* Raw coordinates */
|
||||
frac_bits; /* Multiplier for encoded number */
|
||||
|
||||
|
||||
base_bits = 6;
|
||||
frac_bits = 1.0;
|
||||
draw = 1;
|
||||
abscoords = 0;
|
||||
|
||||
if (num_params == 0)
|
||||
return;
|
||||
|
||||
if (!PolygonMode)
|
||||
{
|
||||
Outputf("MP\n");
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
|
||||
for (s = (unsigned char *)params[0].value.string; *s != '\0';)
|
||||
switch (*s)
|
||||
{
|
||||
case '7' :
|
||||
s ++;
|
||||
base_bits = 5;
|
||||
break;
|
||||
case ':' : /* Select pen */
|
||||
s ++;
|
||||
temp = (int)decode_number(&s, base_bits, 1.0);
|
||||
Outputf("P%d W%d\n", temp, temp);
|
||||
break;
|
||||
case '<' : /* Next coords are a move-to */
|
||||
draw = 0;
|
||||
s ++;
|
||||
break;
|
||||
case '>' : /* Set fractional bits */
|
||||
s ++;
|
||||
temp = (int)decode_number(&s, base_bits, 1.0);
|
||||
frac_bits = 1.0 / (1 << temp);
|
||||
break;
|
||||
case '=' : /* Next coords are absolute */
|
||||
s ++;
|
||||
abscoords = 1;
|
||||
break;
|
||||
default :
|
||||
if (*s >= 63)
|
||||
{
|
||||
/*
|
||||
* Coordinate...
|
||||
*/
|
||||
|
||||
x = decode_number(&s, base_bits, frac_bits);
|
||||
y = decode_number(&s, base_bits, frac_bits);
|
||||
|
||||
if (abscoords)
|
||||
{
|
||||
tx = Transform[0][0] * x + Transform[0][1] * y +
|
||||
Transform[0][2];
|
||||
ty = Transform[1][0] * x + Transform[1][1] * y +
|
||||
Transform[1][2];
|
||||
}
|
||||
else if (x == 0.0 && y == 0.0)
|
||||
{
|
||||
draw = 1;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
tx = Transform[0][0] * x + Transform[0][1] * y +
|
||||
PenPosition[0];
|
||||
ty = Transform[1][0] * x + Transform[1][1] * y +
|
||||
PenPosition[1];
|
||||
}
|
||||
|
||||
if (draw)
|
||||
Outputf("%.3f %.3f LI\n", tx, ty);
|
||||
else
|
||||
Outputf("%.3f %.3f MO\n", tx, ty);
|
||||
|
||||
PenPosition[0] = (float)tx;
|
||||
PenPosition[1] = (float)ty;
|
||||
|
||||
draw = 1;
|
||||
abscoords = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Junk - ignore...
|
||||
*/
|
||||
|
||||
if (*s != '\n' && *s != '\r')
|
||||
fprintf(stderr, "WARNING: ignoring illegal PE char \'%c\'...\n", *s);
|
||||
s ++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PR_plot_relative()' - Plot a line using relative coordinates.
|
||||
*/
|
||||
|
||||
void
|
||||
PR_plot_relative(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
PenMotion = 1;
|
||||
|
||||
if (num_params > 1)
|
||||
plot_points(num_params, params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'PU_pen_up()' - Stop drawing.
|
||||
*/
|
||||
|
||||
void
|
||||
PU_pen_up(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
PenDown = 0;
|
||||
|
||||
if (num_params > 1)
|
||||
plot_points(num_params, params);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'RT_arc_relative3()' - Draw an arc through 3 points relative to the
|
||||
* current pen position.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* This currently only draws two line segments through the specified
|
||||
* points.
|
||||
*/
|
||||
|
||||
void
|
||||
RT_arc_relative3(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
if (num_params < 4)
|
||||
return;
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
PenPosition[0] = Transform[0][0] * params[0].value.number +
|
||||
Transform[0][1] * params[1].value.number +
|
||||
PenPosition[0];
|
||||
PenPosition[1] = Transform[1][0] * params[0].value.number +
|
||||
Transform[1][1] * params[1].value.number +
|
||||
PenPosition[1];
|
||||
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
|
||||
PenPosition[0] = Transform[0][0] * params[2].value.number +
|
||||
Transform[0][1] * params[3].value.number +
|
||||
PenPosition[0];
|
||||
PenPosition[1] = Transform[1][0] * params[2].value.number +
|
||||
Transform[1][1] * params[3].value.number +
|
||||
PenPosition[1];
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
Outputf("%.3f %.3f LI\n", PenPosition[0], PenPosition[1]);
|
||||
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'decode_number()' - Decode an encoded number.
|
||||
*/
|
||||
|
||||
static double /* O - Value */
|
||||
decode_number(unsigned char **s, /* IO - String to decode */
|
||||
int base_bits, /* I - Number of data bits per byte */
|
||||
double frac_bits) /* I - Multiplier for fractional data */
|
||||
{
|
||||
double temp, /* Current value */
|
||||
shift; /* Multiplier */
|
||||
int sign; /* Sign of result */
|
||||
|
||||
|
||||
sign = 0;
|
||||
|
||||
if (base_bits == 5)
|
||||
{
|
||||
for (temp = 0.0, shift = frac_bits * 0.5; **s != '\0'; (*s) ++)
|
||||
if (**s >= 95 && **s < 127)
|
||||
{
|
||||
if (sign == 0)
|
||||
{
|
||||
if ((**s - 95) & 1)
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
temp += ((**s - 95) & ~1) * shift;
|
||||
}
|
||||
else
|
||||
temp += (**s - 95) * shift;
|
||||
break;
|
||||
}
|
||||
else if (**s < 63)
|
||||
{
|
||||
if (**s != '\r' && **s != '\n')
|
||||
fprintf(stderr, "hpgl2ps: Bad PE character \'%c\'!\n", **s);
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sign == 0)
|
||||
{
|
||||
if ((**s - 63) & 1)
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
temp += ((**s - 63) & ~1) * shift;
|
||||
}
|
||||
else
|
||||
temp += (**s - 63) * shift;
|
||||
|
||||
shift *= 32.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (temp = 0.0, shift = frac_bits * 0.5; **s != '\0'; (*s) ++)
|
||||
if (**s >= 191 && **s < 255)
|
||||
{
|
||||
if (sign == 0)
|
||||
{
|
||||
if ((**s - 191) & 1)
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
temp += ((**s - 191) & ~1) * shift;
|
||||
}
|
||||
else
|
||||
temp += (**s - 191) * shift;
|
||||
break;
|
||||
}
|
||||
else if (**s < 63)
|
||||
{
|
||||
if (**s != '\r' && **s != '\n')
|
||||
fprintf(stderr, "hpgl2ps: Bad PE character \'%c\'!\n", **s);
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sign == 0)
|
||||
{
|
||||
if ((**s - 63) & 1)
|
||||
sign = -1;
|
||||
else
|
||||
sign = 1;
|
||||
|
||||
temp += ((**s - 63) & ~1) * shift;
|
||||
}
|
||||
else
|
||||
temp += (**s - 63) * shift;
|
||||
|
||||
shift *= 64.0;
|
||||
}
|
||||
}
|
||||
|
||||
(*s) ++;
|
||||
|
||||
return (temp * sign);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'plot_points()' - Plot the specified points.
|
||||
*/
|
||||
|
||||
static void
|
||||
plot_points(int num_params, /* I - Number of parameters */
|
||||
param_t *params) /* I - Parameters */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
float x, y; /* Transformed coordinates */
|
||||
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (!PolygonMode)
|
||||
Outputf("MP\n");
|
||||
|
||||
Outputf("%.3f %.3f MO\n", PenPosition[0], PenPosition[1]);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_params; i += 2)
|
||||
{
|
||||
if (PenMotion == 0)
|
||||
{
|
||||
x = Transform[0][0] * params[i + 0].value.number +
|
||||
Transform[0][1] * params[i + 1].value.number +
|
||||
Transform[0][2];
|
||||
y = Transform[1][0] * params[i + 0].value.number +
|
||||
Transform[1][1] * params[i + 1].value.number +
|
||||
Transform[1][2];
|
||||
}
|
||||
else
|
||||
{
|
||||
x = Transform[0][0] * params[i + 0].value.number +
|
||||
Transform[0][1] * params[i + 1].value.number +
|
||||
PenPosition[0];
|
||||
y = Transform[1][0] * params[i + 0].value.number +
|
||||
Transform[1][1] * params[i + 1].value.number +
|
||||
PenPosition[1];
|
||||
}
|
||||
|
||||
if (PenDown)
|
||||
Outputf("%.3f %.3f LI\n", x, y);
|
||||
|
||||
PenPosition[0] = x;
|
||||
PenPosition[1] = y;
|
||||
}
|
||||
|
||||
if (PenDown)
|
||||
{
|
||||
if (!PolygonMode)
|
||||
Outputf("ST\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* HP-GL/2 to PostScript filter for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif /* M_PI */
|
||||
|
||||
/*
|
||||
* Parameter value structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
union
|
||||
{
|
||||
float number;
|
||||
char *string;
|
||||
} value;
|
||||
} param_t;
|
||||
|
||||
#define PARAM_ABSOLUTE 0
|
||||
#define PARAM_RELATIVE 1
|
||||
#define PARAM_STRING 2
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
#ifdef _HPGL_MAIN_C_
|
||||
# define VAR
|
||||
# define VALUE(x) =x
|
||||
# define VALUE2(x,y) ={x,y}
|
||||
#else
|
||||
# define VAR extern
|
||||
# define VALUE(x)
|
||||
# define VALUE2(x,y)
|
||||
#endif /* _HPGL_MAIN_C_ */
|
||||
|
||||
VAR float P1[2], /* Lower-lefthand physical limit */
|
||||
P2[2], /* Upper-righthand physical limit */
|
||||
IW1[2], /* Window lower-lefthand limit */
|
||||
IW2[2]; /* Window upper-righthand limit */
|
||||
VAR int Rotation VALUE(0); /* Page rotation */
|
||||
VAR int ScalingType VALUE(-1); /* Type of scaling (-1 for none) */
|
||||
VAR float Scaling1[2], /* Lower-lefthand user limit */
|
||||
Scaling2[2]; /* Upper-righthand user limit */
|
||||
VAR float Transform[2][3]; /* Transform matrix */
|
||||
VAR int PageRotation VALUE(0); /* Page/plot rotation */
|
||||
|
||||
VAR char StringTerminator VALUE('\003'); /* Terminator for labels */
|
||||
VAR float PenPosition[2] VALUE2(0.0f, 0.0f),
|
||||
/* Current pen position */
|
||||
PenScaling VALUE(1.0f); /* Pen width scaling factor */
|
||||
VAR int PenMotion VALUE(0), /* 0 = absolute, 1 = relative */
|
||||
PenNumber VALUE(1), /* Current pen number */
|
||||
PenCount VALUE(8), /* Number of pens */
|
||||
PenDown VALUE(0), /* 0 = pen up, 1 = pen down */
|
||||
PolygonMode VALUE(0), /* Drawing polygons? */
|
||||
PageCount VALUE(1), /* Number of pages in plot */
|
||||
PageDirty VALUE(0), /* Current page written on? */
|
||||
WidthUnits VALUE(0); /* 0 = mm, 1 = proportionate */
|
||||
VAR float PlotSize[2] VALUE2(2592.0f, 3456.0f);
|
||||
/* Plot size */
|
||||
VAR int CharFillMode VALUE(0), /* Where to draw labels */
|
||||
CharPen VALUE(0), /* Pen to use for labels */
|
||||
CharFont VALUE(0); /* Font to use for labels */
|
||||
VAR float CharHeight[2] VALUE2(11.5f,11.5f);
|
||||
/* Size of font for labels */
|
||||
VAR int FitPlot VALUE(0); /* 1 = fit to page */
|
||||
VAR float ColorRange[3][2] /* Range of color values */
|
||||
#ifdef _HPGL_MAIN_C_
|
||||
= {
|
||||
{ 0.0, 255.0 },
|
||||
{ 0.0, 255.0 },
|
||||
{ 0.0, 255.0 }
|
||||
}
|
||||
#endif /* _HPGL_MAIN_C_ */
|
||||
;
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
/* hpgl-input.c */
|
||||
extern int ParseCommand(FILE *fp, char *name, param_t **params);
|
||||
extern void FreeParameters(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-config.c */
|
||||
extern void update_transform(void);
|
||||
extern void BP_begin_plot(int num_params, param_t *params);
|
||||
extern void DF_default_values(int num_params, param_t *params);
|
||||
extern void IN_initialize(int num_params, param_t *params);
|
||||
extern void IP_input_absolute(int num_params, param_t *params);
|
||||
extern void IR_input_relative(int num_params, param_t *params);
|
||||
extern void IW_input_window(int num_params, param_t *params);
|
||||
extern void PG_advance_page(int num_params, param_t *params);
|
||||
extern void PS_plot_size(int num_params, param_t *params);
|
||||
extern void RO_rotate(int num_params, param_t *params);
|
||||
extern void RP_replot(int num_params, param_t *params);
|
||||
extern void SC_scale(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-vector.c */
|
||||
extern void AA_arc_absolute(int num_params, param_t *params);
|
||||
extern void AR_arc_relative(int num_params, param_t *params);
|
||||
extern void AT_arc_absolute3(int num_params, param_t *params);
|
||||
extern void CI_circle(int num_params, param_t *params);
|
||||
extern void PA_plot_absolute(int num_params, param_t *params);
|
||||
extern void PD_pen_down(int num_params, param_t *params);
|
||||
extern void PE_polyline_encoded(int num_params, param_t *params);
|
||||
extern void PR_plot_relative(int num_params, param_t *params);
|
||||
extern void PU_pen_up(int num_params, param_t *params);
|
||||
extern void RT_arc_relative3(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-polygon.c */
|
||||
extern void EA_edge_rect_absolute(int num_params, param_t *params);
|
||||
extern void EP_edge_polygon(int num_params, param_t *params);
|
||||
extern void ER_edge_rect_relative(int num_params, param_t *params);
|
||||
extern void EW_edge_wedge(int num_params, param_t *params);
|
||||
extern void FP_fill_polygon(int num_params, param_t *params);
|
||||
extern void PM_polygon_mode(int num_params, param_t *params);
|
||||
extern void RA_fill_rect_absolute(int num_params, param_t *params);
|
||||
extern void RR_fill_rect_relative(int num_params, param_t *params);
|
||||
extern void WG_fill_wedge(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-char.c */
|
||||
extern void AD_define_alternate(int num_params, param_t *params);
|
||||
extern void CF_character_fill(int num_params, param_t *params);
|
||||
extern void CP_character_plot(int num_params, param_t *params);
|
||||
extern void DI_absolute_direction(int num_params, param_t *params);
|
||||
extern void DR_relative_direction(int num_params, param_t *params);
|
||||
extern void DT_define_label_term(int num_params, param_t *params);
|
||||
extern void DV_define_variable_path(int num_params, param_t *params);
|
||||
extern void ES_extra_space(int num_params, param_t *params);
|
||||
extern void LB_label(int num_params, param_t *params);
|
||||
extern void LO_label_origin(int num_params, param_t *params);
|
||||
extern void SA_select_alternate(int num_params, param_t *params);
|
||||
extern void SD_define_standard(int num_params, param_t *params);
|
||||
extern void SI_absolute_size(int num_params, param_t *params);
|
||||
extern void SL_character_slant(int num_params, param_t *params);
|
||||
extern void SR_relative_size(int num_params, param_t *params);
|
||||
extern void SS_select_standard(int num_params, param_t *params);
|
||||
extern void TD_transparent_data(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-attr.c */
|
||||
extern void AC_anchor_corner(int num_params, param_t *params);
|
||||
extern void CR_color_range(int num_params, param_t *params);
|
||||
extern void FT_fill_type(int num_params, param_t *params);
|
||||
extern void LA_line_attributes(int num_params, param_t *params);
|
||||
extern void LT_line_type(int num_params, param_t *params);
|
||||
extern void NP_number_pens(int num_params, param_t *params);
|
||||
extern void PC_pen_color(int num_params, param_t *params);
|
||||
extern void PW_pen_width(int num_params, param_t *params);
|
||||
extern void RF_raster_fill(int num_params, param_t *params);
|
||||
extern void SM_symbol_mode(int num_params, param_t *params);
|
||||
extern void SP_select_pen(int num_params, param_t *params);
|
||||
extern void UL_user_line_type(int num_params, param_t *params);
|
||||
extern void WU_width_units(int num_params, param_t *params);
|
||||
|
||||
/* hpgl-prolog.c */
|
||||
extern void OutputProlog(char *title, char *user, int shading, float penwidth);
|
||||
extern void OutputTrailer(void);
|
||||
extern int Outputf(const char *format, ...);
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,910 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Colorspace conversions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageWhiteToWhite() - Convert luminance colors to device-dependent
|
||||
* ImageWhiteToRGB() - Convert luminance data to RGB.
|
||||
* ImageWhiteToBlack() - Convert luminance colors to black.
|
||||
* ImageWhiteToCMY() - Convert luminance colors to CMY.
|
||||
* ImageWhiteToCMYK() - Convert luminance colors to CMYK.
|
||||
* ImageRGBToBlack() - Convert RGB data to black.
|
||||
* ImageRGBToCMY() - Convert RGB colors to CMY.
|
||||
* ImageRGBToCMYK() - Convert RGB colors to CMYK.
|
||||
* ImageRGBToWhite() - Convert RGB colors to luminance.
|
||||
* ImageRGBToRGB() - Convert RGB colors to device-dependent RGB.
|
||||
* ImageLut() - Adjust all pixel values with the given LUT.
|
||||
* ImageRGBAdjust() - Adjust the hue and saturation of the given RGB
|
||||
* colors.
|
||||
* huerotate() - Rotate the hue, maintaining luminance.
|
||||
* ident() - Make an identity matrix.
|
||||
* mult() - Multiply two matrices.
|
||||
* saturate() - Make a saturation matrix.
|
||||
* xform() - Transform a 3D point using a matrix...
|
||||
* xrotate() - Rotate about the x (red) axis...
|
||||
* yrotate() - Rotate about the y (green) axis...
|
||||
* zrotate() - Rotate about the z (blue) axis...
|
||||
* zshear() - Shear z using x and y...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
extern int ImageHaveProfile;
|
||||
extern int ImageDensity[256];
|
||||
extern int ImageMatrix[3][3][256];
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void huerotate(float [3][3], float);
|
||||
static void ident(float [3][3]);
|
||||
static void mult(float [3][3], float [3][3], float [3][3]);
|
||||
static void saturate(float [3][3], float);
|
||||
static void xform(float [3][3], float, float, float, float *, float *, float *);
|
||||
static void xrotate(float [3][3], float, float);
|
||||
static void yrotate(float [3][3], float, float);
|
||||
static void zrotate(float [3][3], float, float);
|
||||
static void zshear(float [3][3], float, float);
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageWhiteToWhite()' - Convert luminance colors to device-dependent
|
||||
* luminance.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageWhiteToWhite(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 255 - ImageDensity[255 - *in++];
|
||||
count --;
|
||||
}
|
||||
else if (in != out)
|
||||
memcpy(out, in, count);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageWhiteToRGB()' - Convert luminance data to RGB.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageWhiteToRGB(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
out[0] = 255 - ImageDensity[255 - *in++];
|
||||
out[1] = out[0];
|
||||
out[2] = out[0];
|
||||
out += 3;
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = *in;
|
||||
*out++ = *in;
|
||||
*out++ = *in++;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageWhiteToBlack()' - Convert luminance colors to black.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageWhiteToBlack(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = ImageDensity[255 - *in++];
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 255 - *in++;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageWhiteToCMY()' - Convert luminance colors to CMY.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageWhiteToCMY(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
out[0] = ImageDensity[255 - *in++];
|
||||
out[1] = out[0];
|
||||
out[2] = out[0];
|
||||
out += 3;
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 255 - *in;
|
||||
*out++ = 255 - *in;
|
||||
*out++ = 255 - *in++;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageWhiteToCMYK()' - Convert luminance colors to CMYK.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageWhiteToCMYK(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 0;
|
||||
*out++ = 0;
|
||||
*out++ = 0;
|
||||
*out++ = ImageDensity[255 - *in++];
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 0;
|
||||
*out++ = 0;
|
||||
*out++ = 0;
|
||||
*out++ = 255 - *in++;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBToBlack()' - Convert RGB data to black.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBToBlack(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = ImageDensity[255 - (31 * in[0] + 61 * in[1] + 8 * in[2]) / 100];
|
||||
in += 3;
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 255 - (31 * in[0] + 61 * in[1] + 8 * in[2]) / 100;
|
||||
in += 3;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBToCMY()' - Convert RGB colors to CMY.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBToCMY(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
int c, m, y, k; /* CMYK values */
|
||||
int cc, cm, cy; /* Calibrated CMY values */
|
||||
|
||||
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
c = 255 - *in++;
|
||||
m = 255 - *in++;
|
||||
y = 255 - *in++;
|
||||
k = min(c, min(m, y));
|
||||
c -= k;
|
||||
m -= k;
|
||||
y -= k;
|
||||
|
||||
cc = ImageMatrix[0][0][c] +
|
||||
ImageMatrix[0][1][m] +
|
||||
ImageMatrix[0][2][y] + k;
|
||||
cm = ImageMatrix[1][0][c] +
|
||||
ImageMatrix[1][1][m] +
|
||||
ImageMatrix[1][2][y] + k;
|
||||
cy = ImageMatrix[2][0][c] +
|
||||
ImageMatrix[2][1][m] +
|
||||
ImageMatrix[2][2][y] + k;
|
||||
|
||||
if (cc < 0)
|
||||
*out++ = 0;
|
||||
else if (cc > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cc];
|
||||
|
||||
if (cm < 0)
|
||||
*out++ = 0;
|
||||
else if (cm > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cm];
|
||||
|
||||
if (cy < 0)
|
||||
*out++ = 0;
|
||||
else if (cy > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cy];
|
||||
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
c = 255 - in[0];
|
||||
m = 255 - in[1];
|
||||
y = 255 - in[2];
|
||||
k = min(c, min(m, y));
|
||||
|
||||
*out++ = (255 - in[1] / 4) * (c - k) / 255 + k;
|
||||
*out++ = (255 - in[2] / 4) * (m - k) / 255 + k;
|
||||
*out++ = (255 - in[0] / 4) * (y - k) / 255 + k;
|
||||
in += 3;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBToCMYK()' - Convert RGB colors to CMYK.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBToCMYK(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count)/* I - Number of pixels */
|
||||
{
|
||||
int c, m, y, k, /* CMYK values */
|
||||
diff, /* Color differences */
|
||||
divk; /* Color divisor */
|
||||
int cc, cm, cy; /* Calibrated CMY values */
|
||||
|
||||
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
c = 255 - *in++;
|
||||
m = 255 - *in++;
|
||||
y = 255 - *in++;
|
||||
k = min(c, min(m, y));
|
||||
|
||||
diff = 255 - (max(c, max(m, y)) - k);
|
||||
k = k * diff / 255;
|
||||
|
||||
if (k == 255)
|
||||
c = m = y = 0;
|
||||
else if (k > 0)
|
||||
{
|
||||
divk = 255 - k;
|
||||
c = 255 * (c - k) / divk;
|
||||
m = 255 * (m - k) / divk;
|
||||
y = 255 * (y - k) / divk;
|
||||
|
||||
if (c > 255)
|
||||
c = 255;
|
||||
|
||||
if (m > 255)
|
||||
m = 255;
|
||||
|
||||
if (y > 255)
|
||||
y = 255;
|
||||
}
|
||||
|
||||
cc = (ImageMatrix[0][0][c] +
|
||||
ImageMatrix[0][1][m] +
|
||||
ImageMatrix[0][2][y]);
|
||||
cm = (ImageMatrix[1][0][c] +
|
||||
ImageMatrix[1][1][m] +
|
||||
ImageMatrix[1][2][y]);
|
||||
cy = (ImageMatrix[2][0][c] +
|
||||
ImageMatrix[2][1][m] +
|
||||
ImageMatrix[2][2][y]);
|
||||
|
||||
if (cc < 0)
|
||||
*out++ = 0;
|
||||
else if (cc > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cc];
|
||||
|
||||
if (cm < 0)
|
||||
*out++ = 0;
|
||||
else if (cm > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cm];
|
||||
|
||||
if (cy < 0)
|
||||
*out++ = 0;
|
||||
else if (cy > 255)
|
||||
*out++ = ImageDensity[255];
|
||||
else
|
||||
*out++ = ImageDensity[cy];
|
||||
|
||||
*out++ = ImageDensity[k];
|
||||
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
c = 255 - *in++;
|
||||
m = 255 - *in++;
|
||||
y = 255 - *in++;
|
||||
k = min(c, min(m, y));
|
||||
|
||||
if (k == 255)
|
||||
c = m = y = 0;
|
||||
else if (k > 0)
|
||||
{
|
||||
divk = 255 - k;
|
||||
c = 255 * (c - k) / divk;
|
||||
m = 255 * (m - k) / divk;
|
||||
y = 255 * (y - k) / divk;
|
||||
|
||||
if (c > 255)
|
||||
c = 255;
|
||||
|
||||
if (m > 255)
|
||||
m = 255;
|
||||
|
||||
if (y > 255)
|
||||
y = 255;
|
||||
}
|
||||
|
||||
*out++ = c;
|
||||
*out++ = m;
|
||||
*out++ = y;
|
||||
*out++ = k;
|
||||
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBToWhite()' - Convert RGB colors to luminance.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBToWhite(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = 255 - ImageDensity[255 - (31 * in[0] + 61 * in[1] + 8 * in[2]) / 100];
|
||||
in += 3;
|
||||
count --;
|
||||
}
|
||||
else
|
||||
while (count > 0)
|
||||
{
|
||||
*out++ = (31 * in[0] + 61 * in[1] + 8 * in[2]) / 100;
|
||||
in += 3;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBToRGB()' - Convert RGB colors to device-dependent RGB.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBToRGB(const ib_t *in, /* I - Input pixels */
|
||||
ib_t *out, /* I - Output pixels */
|
||||
int count) /* I - Number of pixels */
|
||||
{
|
||||
int c, m, y, k; /* CMYK values */
|
||||
int cr, cg, cb; /* Calibrated RGB values */
|
||||
|
||||
|
||||
if (ImageHaveProfile)
|
||||
while (count > 0)
|
||||
{
|
||||
c = 255 - *in++;
|
||||
m = 255 - *in++;
|
||||
y = 255 - *in++;
|
||||
k = min(c, min(m, y));
|
||||
c -= k;
|
||||
m -= k;
|
||||
y -= k;
|
||||
|
||||
cr = ImageMatrix[0][0][c] +
|
||||
ImageMatrix[0][1][m] +
|
||||
ImageMatrix[0][2][y] + k;
|
||||
cg = ImageMatrix[1][0][c] +
|
||||
ImageMatrix[1][1][m] +
|
||||
ImageMatrix[1][2][y] + k;
|
||||
cb = ImageMatrix[2][0][c] +
|
||||
ImageMatrix[2][1][m] +
|
||||
ImageMatrix[2][2][y] + k;
|
||||
|
||||
if (cr < 0)
|
||||
*out++ = 255;
|
||||
else if (cr > 255)
|
||||
*out++ = 255 - ImageDensity[255];
|
||||
else
|
||||
*out++ = 255 - ImageDensity[cr];
|
||||
|
||||
if (cg < 0)
|
||||
*out++ = 255;
|
||||
else if (cg > 255)
|
||||
*out++ = 255 - ImageDensity[255];
|
||||
else
|
||||
*out++ = 255 - ImageDensity[cg];
|
||||
|
||||
if (cb < 0)
|
||||
*out++ = 255;
|
||||
else if (cb > 255)
|
||||
*out++ = 255 - ImageDensity[255];
|
||||
else
|
||||
*out++ = 255 - ImageDensity[cb];
|
||||
|
||||
count --;
|
||||
}
|
||||
else if (in != out)
|
||||
memcpy(out, in, count * 3);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageLut()' - Adjust all pixel values with the given LUT.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageLut(ib_t *pixels, /* IO - Input/output pixels */
|
||||
int count, /* I - Number of pixels/bytes to adjust */
|
||||
const ib_t *lut) /* I - Lookup table */
|
||||
{
|
||||
while (count > 0)
|
||||
{
|
||||
*pixels = lut[*pixels];
|
||||
pixels ++;
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageRGBAdjust()' - Adjust the hue and saturation of the given RGB colors.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageRGBAdjust(ib_t *pixels, /* IO - Input/output pixels */
|
||||
int count, /* I - Number of pixels to adjust */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue) /* I - Color hue (degrees) */
|
||||
{
|
||||
int i, j, k; /* Looping vars */
|
||||
float mat[3][3]; /* Color adjustment matrix */
|
||||
static int last_sat = 100, /* Last saturation used */
|
||||
last_hue = 0; /* Last hue used */
|
||||
static int lut[3][3][256]; /* Lookup table for matrix */
|
||||
|
||||
|
||||
if (saturation != last_sat ||
|
||||
hue != last_hue)
|
||||
{
|
||||
/*
|
||||
* Build the color adjustment matrix...
|
||||
*/
|
||||
|
||||
ident(mat);
|
||||
saturate(mat, saturation * 0.01);
|
||||
huerotate(mat, (float)hue);
|
||||
|
||||
/*
|
||||
* Convert the matrix into a 3x3 array of lookup tables...
|
||||
*/
|
||||
|
||||
for (i = 0; i < 3; i ++)
|
||||
for (j = 0; j < 3; j ++)
|
||||
for (k = 0; k < 256; k ++)
|
||||
lut[i][j][k] = mat[i][j] * k + 0.5;
|
||||
|
||||
/*
|
||||
* Save the saturation and hue to compare later...
|
||||
*/
|
||||
|
||||
last_sat = saturation;
|
||||
last_hue = hue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adjust each pixel in the given buffer.
|
||||
*/
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
i = lut[0][0][pixels[0]] +
|
||||
lut[1][0][pixels[1]] +
|
||||
lut[2][0][pixels[2]];
|
||||
if (i < 0)
|
||||
pixels[0] = 0;
|
||||
else if (i > 255)
|
||||
pixels[0] = 255;
|
||||
else
|
||||
pixels[0] = i;
|
||||
|
||||
i = lut[0][1][pixels[0]] +
|
||||
lut[1][1][pixels[1]] +
|
||||
lut[2][1][pixels[2]];
|
||||
if (i < 0)
|
||||
pixels[1] = 0;
|
||||
else if (i > 255)
|
||||
pixels[1] = 255;
|
||||
else
|
||||
pixels[1] = i;
|
||||
|
||||
i = lut[0][2][pixels[0]] +
|
||||
lut[1][2][pixels[1]] +
|
||||
lut[2][2][pixels[2]];
|
||||
if (i < 0)
|
||||
pixels[2] = 0;
|
||||
else if (i > 255)
|
||||
pixels[2] = 255;
|
||||
else
|
||||
pixels[2] = i;
|
||||
|
||||
count --;
|
||||
pixels += 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The color saturation/hue matrix stuff is provided thanks to Mr. Paul
|
||||
* Haeberli at "http://www.sgi.com/grafica/matrix/index.html".
|
||||
*/
|
||||
|
||||
/*
|
||||
* 'huerotate()' - Rotate the hue, maintaining luminance.
|
||||
*/
|
||||
|
||||
static void
|
||||
huerotate(float mat[3][3], /* I - Matrix to append to */
|
||||
float rot) /* I - Hue rotation in degrees */
|
||||
{
|
||||
float hmat[3][3]; /* Hue matrix */
|
||||
float lx, ly, lz; /* Luminance vector */
|
||||
float xrs, xrc; /* X rotation sine/cosine */
|
||||
float yrs, yrc; /* Y rotation sine/cosine */
|
||||
float zrs, zrc; /* Z rotation sine/cosine */
|
||||
float zsx, zsy; /* Z shear x/y */
|
||||
|
||||
|
||||
/*
|
||||
* Load the identity matrix...
|
||||
*/
|
||||
|
||||
ident(hmat);
|
||||
|
||||
/*
|
||||
* Rotate the grey vector into positive Z...
|
||||
*/
|
||||
|
||||
xrs = M_SQRT1_2;
|
||||
xrc = M_SQRT1_2;
|
||||
xrotate(hmat,xrs,xrc);
|
||||
|
||||
yrs = -1.0 / sqrt(3.0);
|
||||
yrc = -M_SQRT2 * yrs;
|
||||
yrotate(hmat,yrs,yrc);
|
||||
|
||||
/*
|
||||
* Shear the space to make the luminance plane horizontal...
|
||||
*/
|
||||
|
||||
xform(hmat, 0.3086, 0.6094, 0.0820, &lx, &ly, &lz);
|
||||
zsx = lx / lz;
|
||||
zsy = ly / lz;
|
||||
zshear(hmat, zsx, zsy);
|
||||
|
||||
/*
|
||||
* Rotate the hue...
|
||||
*/
|
||||
|
||||
zrs = sin(rot * M_PI / 180.0);
|
||||
zrc = cos(rot * M_PI / 180.0);
|
||||
|
||||
zrotate(hmat, zrs, zrc);
|
||||
|
||||
/*
|
||||
* Unshear the space to put the luminance plane back...
|
||||
*/
|
||||
|
||||
zshear(hmat, -zsx, -zsy);
|
||||
|
||||
/*
|
||||
* Rotate the grey vector back into place...
|
||||
*/
|
||||
|
||||
yrotate(hmat, -yrs, yrc);
|
||||
xrotate(hmat, -xrs, xrc);
|
||||
|
||||
/*
|
||||
* Append it to the current matrix...
|
||||
*/
|
||||
|
||||
mult(hmat, mat, mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ident()' - Make an identity matrix.
|
||||
*/
|
||||
|
||||
static void
|
||||
ident(float mat[3][3]) /* I - Matrix to identify */
|
||||
{
|
||||
mat[0][0] = 1.0;
|
||||
mat[0][1] = 0.0;
|
||||
mat[0][2] = 0.0;
|
||||
mat[1][0] = 0.0;
|
||||
mat[1][1] = 1.0;
|
||||
mat[1][2] = 0.0;
|
||||
mat[2][0] = 0.0;
|
||||
mat[2][1] = 0.0;
|
||||
mat[2][2] = 1.0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'mult()' - Multiply two matrices.
|
||||
*/
|
||||
|
||||
static void
|
||||
mult(float a[3][3], /* I - First matrix */
|
||||
float b[3][3], /* I - Second matrix */
|
||||
float c[3][3]) /* I - Destination matrix */
|
||||
{
|
||||
int x, y; /* Looping vars */
|
||||
float temp[3][3]; /* Temporary matrix */
|
||||
|
||||
|
||||
/*
|
||||
* Multiply a and b, putting the result in temp...
|
||||
*/
|
||||
|
||||
for (y = 0; y < 3; y ++)
|
||||
for (x = 0; x < 3; x ++)
|
||||
temp[y][x] = b[y][0] * a[0][x] +
|
||||
b[y][1] * a[1][x] +
|
||||
b[y][2] * a[2][x];
|
||||
|
||||
/*
|
||||
* Copy temp to c (that way c can be a pointer to a or b).
|
||||
*/
|
||||
|
||||
memcpy(c, temp, sizeof(temp));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'saturate()' - Make a saturation matrix.
|
||||
*/
|
||||
|
||||
static void
|
||||
saturate(float mat[3][3], /* I - Matrix to append to */
|
||||
float sat) /* I - Desired color saturation */
|
||||
{
|
||||
float smat[3][3]; /* Saturation matrix */
|
||||
|
||||
|
||||
smat[0][0] = (1.0 - sat) * 0.3086 + sat;
|
||||
smat[0][1] = (1.0 - sat) * 0.3086;
|
||||
smat[0][2] = (1.0 - sat) * 0.3086;
|
||||
smat[1][0] = (1.0 - sat) * 0.6094;
|
||||
smat[1][1] = (1.0 - sat) * 0.6094 + sat;
|
||||
smat[1][2] = (1.0 - sat) * 0.6094;
|
||||
smat[2][0] = (1.0 - sat) * 0.0820;
|
||||
smat[2][1] = (1.0 - sat) * 0.0820;
|
||||
smat[2][2] = (1.0 - sat) * 0.0820 + sat;
|
||||
|
||||
mult(smat, mat, mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'xform()' - Transform a 3D point using a matrix...
|
||||
*/
|
||||
|
||||
static void
|
||||
xform(float mat[3][3], /* I - Matrix */
|
||||
float x, /* I - Input X coordinate */
|
||||
float y, /* I - Input Y coordinate */
|
||||
float z, /* I - Input Z coordinate */
|
||||
float *tx, /* O - Output X coordinate */
|
||||
float *ty, /* O - Output Y coordinate */
|
||||
float *tz) /* O - Output Z coordinate */
|
||||
{
|
||||
*tx = x * mat[0][0] + y * mat[1][0] + z * mat[2][0];
|
||||
*ty = x * mat[0][1] + y * mat[1][1] + z * mat[2][1];
|
||||
*tz = x * mat[0][2] + y * mat[1][2] + z * mat[2][2];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'xrotate()' - Rotate about the x (red) axis...
|
||||
*/
|
||||
|
||||
static void
|
||||
xrotate(float mat[3][3], /* I - Matrix */
|
||||
float rs, /* I - Rotation angle sine */
|
||||
float rc) /* I - Rotation angle cosine */
|
||||
{
|
||||
float rmat[3][3]; /* I - Rotation matrix */
|
||||
|
||||
|
||||
rmat[0][0] = 1.0;
|
||||
rmat[0][1] = 0.0;
|
||||
rmat[0][2] = 0.0;
|
||||
|
||||
rmat[1][0] = 0.0;
|
||||
rmat[1][1] = rc;
|
||||
rmat[1][2] = rs;
|
||||
|
||||
rmat[2][0] = 0.0;
|
||||
rmat[2][1] = -rs;
|
||||
rmat[2][2] = rc;
|
||||
|
||||
mult(rmat, mat, mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'yrotate()' - Rotate about the y (green) axis...
|
||||
*/
|
||||
|
||||
static void
|
||||
yrotate(float mat[3][3], /* I - Matrix */
|
||||
float rs, /* I - Rotation angle sine */
|
||||
float rc) /* I - Rotation angle cosine */
|
||||
{
|
||||
float rmat[3][3]; /* I - Rotation matrix */
|
||||
|
||||
|
||||
rmat[0][0] = rc;
|
||||
rmat[0][1] = 0.0;
|
||||
rmat[0][2] = -rs;
|
||||
|
||||
rmat[1][0] = 0.0;
|
||||
rmat[1][1] = 1.0;
|
||||
rmat[1][2] = 0.0;
|
||||
|
||||
rmat[2][0] = rs;
|
||||
rmat[2][1] = 0.0;
|
||||
rmat[2][2] = rc;
|
||||
|
||||
mult(rmat,mat,mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'zrotate()' - Rotate about the z (blue) axis...
|
||||
*/
|
||||
|
||||
static void
|
||||
zrotate(float mat[3][3], /* I - Matrix */
|
||||
float rs, /* I - Rotation angle sine */
|
||||
float rc) /* I - Rotation angle cosine */
|
||||
{
|
||||
float rmat[3][3]; /* I - Rotation matrix */
|
||||
|
||||
|
||||
rmat[0][0] = rc;
|
||||
rmat[0][1] = rs;
|
||||
rmat[0][2] = 0.0;
|
||||
|
||||
rmat[1][0] = -rs;
|
||||
rmat[1][1] = rc;
|
||||
rmat[1][2] = 0.0;
|
||||
|
||||
rmat[2][0] = 0.0;
|
||||
rmat[2][1] = 0.0;
|
||||
rmat[2][2] = 1.0;
|
||||
|
||||
mult(rmat,mat,mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'zshear()' - Shear z using x and y...
|
||||
*/
|
||||
|
||||
static void
|
||||
zshear(float mat[3][3], /* I - Matrix */
|
||||
float dx, /* I - X shear */
|
||||
float dy) /* I - Y shear */
|
||||
{
|
||||
float smat[3][3]; /* Shear matrix */
|
||||
|
||||
|
||||
smat[0][0] = 1.0;
|
||||
smat[0][1] = 0.0;
|
||||
smat[0][2] = dx;
|
||||
|
||||
smat[1][0] = 0.0;
|
||||
smat[1][1] = 1.0;
|
||||
smat[1][2] = dy;
|
||||
|
||||
smat[2][0] = 0.0;
|
||||
smat[2][1] = 0.0;
|
||||
smat[2][2] = 1.0;
|
||||
|
||||
mult(smat, mat, mat);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,644 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* GIF image routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadGIF() - Read a GIF image file.
|
||||
* gif_read_cmap() - Read the colormap from a GIF file...
|
||||
* gif_get_block() - Read a GIF data block...
|
||||
* gif_get_code() - Get a LZW code from the file...
|
||||
* gif_read_lzw() - Read a byte from the LZW stream...
|
||||
* gif_read_image() - Read a GIF image stream...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
|
||||
/*
|
||||
* GIF definitions...
|
||||
*/
|
||||
|
||||
#define GIF_INTERLACE 0x40
|
||||
#define GIF_COLORMAP 0x80
|
||||
|
||||
typedef ib_t gif_cmap_t[256][4];
|
||||
|
||||
|
||||
/*
|
||||
* Local globals...
|
||||
*/
|
||||
|
||||
static int gif_eof = 0; /* Did we hit EOF? */
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int gif_read_cmap(FILE *fp, int ncolors, gif_cmap_t cmap,
|
||||
int *gray);
|
||||
static int gif_get_block(FILE *fp, unsigned char *buffer);
|
||||
static int gif_get_code (FILE *fp, int code_size, int first_time);
|
||||
static int gif_read_lzw(FILE *fp, int first_time, int input_code_size);
|
||||
static int gif_read_image(FILE *fp, image_t *img, gif_cmap_t cmap,
|
||||
int interlace);
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadGIF()' - Read a GIF image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadGIF(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
unsigned char buf[1024]; /* Input buffer */
|
||||
gif_cmap_t cmap; /* Colormap */
|
||||
int i, /* Looping var */
|
||||
bpp, /* Bytes per pixel */
|
||||
gray, /* Grayscale image? */
|
||||
ncolors, /* Bits per pixel */
|
||||
transparent; /* Transparent color index */
|
||||
|
||||
|
||||
/*
|
||||
* Read the header; we already know it is a GIF file...
|
||||
*/
|
||||
|
||||
fread(buf, 13, 1, fp);
|
||||
|
||||
img->xsize = (buf[7] << 8) | buf[6];
|
||||
img->ysize = (buf[9] << 8) | buf[8];
|
||||
ncolors = 2 << (buf[10] & 0x07);
|
||||
gray = primary == IMAGE_BLACK || primary == IMAGE_WHITE;
|
||||
|
||||
if (buf[10] & GIF_COLORMAP)
|
||||
if (gif_read_cmap(fp, ncolors, cmap, &gray))
|
||||
{
|
||||
fclose(fp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
transparent = -1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
switch (getc(fp))
|
||||
{
|
||||
case ';' : /* End of image */
|
||||
fclose(fp);
|
||||
return (-1); /* Early end of file */
|
||||
|
||||
case '!' : /* Extension record */
|
||||
buf[0] = getc(fp);
|
||||
if (buf[0] == 0xf9) /* Graphic Control Extension */
|
||||
{
|
||||
gif_get_block(fp, buf);
|
||||
if (buf[0] & 1) /* Get transparent color index */
|
||||
transparent = buf[3];
|
||||
}
|
||||
|
||||
while (gif_get_block(fp, buf) != 0);
|
||||
break;
|
||||
|
||||
case ',' : /* Image data */
|
||||
fread(buf, 9, 1, fp);
|
||||
|
||||
if (buf[8] & GIF_COLORMAP)
|
||||
{
|
||||
ncolors = 2 << (buf[8] & 0x07);
|
||||
gray = primary == IMAGE_BLACK || primary == IMAGE_WHITE;
|
||||
|
||||
if (gif_read_cmap(fp, ncolors, cmap, &gray))
|
||||
{
|
||||
fclose(fp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (transparent >= 0)
|
||||
{
|
||||
/*
|
||||
* Make transparent color white...
|
||||
*/
|
||||
|
||||
cmap[transparent][0] = 255;
|
||||
cmap[transparent][1] = 255;
|
||||
cmap[transparent][2] = 255;
|
||||
}
|
||||
|
||||
if (gray)
|
||||
{
|
||||
switch (secondary)
|
||||
{
|
||||
case IMAGE_CMYK :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageWhiteToCMYK(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageWhiteToCMY(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageWhiteToBlack(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_WHITE :
|
||||
break;
|
||||
case IMAGE_RGB :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageWhiteToRGB(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
}
|
||||
|
||||
img->colorspace = secondary;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hue != 0 || saturation != 100)
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageRGBAdjust(cmap[i], 1, saturation, hue);
|
||||
|
||||
switch (primary)
|
||||
{
|
||||
case IMAGE_CMYK :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageRGBToCMYK(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageRGBToCMY(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageRGBToBlack(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_WHITE :
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageRGBToWhite(cmap[i], cmap[i], 1);
|
||||
break;
|
||||
case IMAGE_RGB :
|
||||
break;
|
||||
}
|
||||
|
||||
img->colorspace = primary;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
{
|
||||
bpp = ImageGetDepth(img);
|
||||
|
||||
for (i = ncolors - 1; i >= 0; i --)
|
||||
ImageLut(cmap[i], bpp, lut);
|
||||
}
|
||||
|
||||
img->xsize = (buf[5] << 8) | buf[4];
|
||||
img->ysize = (buf[7] << 8) | buf[6];
|
||||
|
||||
i = gif_read_image(fp, img, cmap, buf[8] & GIF_INTERLACE);
|
||||
fclose(fp);
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'gif_read_cmap()' - Read the colormap from a GIF file...
|
||||
*/
|
||||
|
||||
static int /* O - -1 on error, 0 on success */
|
||||
gif_read_cmap(FILE *fp, /* I - File to read from */
|
||||
int ncolors, /* I - Number of colors in file */
|
||||
gif_cmap_t cmap, /* O - Colormap information */
|
||||
int *gray) /* IO - Is the image grayscale? */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
|
||||
|
||||
/*
|
||||
* Read the colormap...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ncolors; i ++)
|
||||
if (fread(cmap[i], 3, 1, fp) < 1)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Check to see if the colormap is a grayscale ramp...
|
||||
*/
|
||||
|
||||
for (i = 0; i < ncolors; i ++)
|
||||
if (cmap[i][0] != cmap[i][1] || cmap[i][1] != cmap[i][2])
|
||||
break;
|
||||
|
||||
if (i == ncolors)
|
||||
{
|
||||
*gray = 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If this needs to be a grayscale image, convert the RGB values to
|
||||
* luminance values...
|
||||
*/
|
||||
|
||||
if (*gray)
|
||||
for (i = 0; i < ncolors; i ++)
|
||||
cmap[i][0] = (cmap[i][0] * 31 + cmap[i][1] * 61 + cmap[i][2] * 8) / 100;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'gif_get_block()' - Read a GIF data block...
|
||||
*/
|
||||
|
||||
static int /* O - Number characters read */
|
||||
gif_get_block(FILE *fp, /* I - File to read from */
|
||||
unsigned char *buf) /* I - Input buffer */
|
||||
{
|
||||
int count; /* Number of character to read */
|
||||
|
||||
|
||||
/*
|
||||
* Read the count byte followed by the data from the file...
|
||||
*/
|
||||
|
||||
if ((count = getc(fp)) == EOF)
|
||||
{
|
||||
gif_eof = 1;
|
||||
return (-1);
|
||||
}
|
||||
else if (count == 0)
|
||||
gif_eof = 1;
|
||||
else if (fread(buf, 1, count, fp) < count)
|
||||
{
|
||||
gif_eof = 1;
|
||||
return (-1);
|
||||
}
|
||||
else
|
||||
gif_eof = 0;
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'gif_get_code()' - Get a LZW code from the file...
|
||||
*/
|
||||
|
||||
static int /* O - LZW code */
|
||||
gif_get_code(FILE *fp, /* I - File to read from */
|
||||
int code_size, /* I - Size of code in bits */
|
||||
int first_time) /* I - 1 = first time, 0 = not first time */
|
||||
{
|
||||
unsigned i, j, /* Looping vars */
|
||||
ret; /* Return value */
|
||||
int count; /* Number of bytes read */
|
||||
static unsigned char buf[280]; /* Input buffer */
|
||||
static unsigned curbit, /* Current bit */
|
||||
lastbit, /* Last bit in buffer */
|
||||
done, /* Done with this buffer? */
|
||||
last_byte; /* Last byte in buffer */
|
||||
static unsigned char bits[8] = /* Bit masks for codes */
|
||||
{
|
||||
0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x80
|
||||
};
|
||||
|
||||
|
||||
if (first_time)
|
||||
{
|
||||
/*
|
||||
* Just initialize the input buffer...
|
||||
*/
|
||||
|
||||
curbit = 0;
|
||||
lastbit = 0;
|
||||
done = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
if ((curbit + code_size) >= lastbit)
|
||||
{
|
||||
/*
|
||||
* Don't have enough bits to hold the code...
|
||||
*/
|
||||
|
||||
if (done)
|
||||
return (-1); /* Sorry, no more... */
|
||||
|
||||
/*
|
||||
* Move last two bytes to front of buffer...
|
||||
*/
|
||||
|
||||
buf[0] = buf[last_byte - 2];
|
||||
buf[1] = buf[last_byte - 1];
|
||||
|
||||
/*
|
||||
* Read in another buffer...
|
||||
*/
|
||||
|
||||
if ((count = gif_get_block (fp, buf + 2)) <= 0)
|
||||
{
|
||||
/*
|
||||
* Whoops, no more data!
|
||||
*/
|
||||
|
||||
done = 1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update buffer state...
|
||||
*/
|
||||
|
||||
last_byte = 2 + count;
|
||||
curbit = (curbit - lastbit) + 16;
|
||||
lastbit = last_byte * 8;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
for (ret = 0, i = curbit + code_size - 1, j = code_size;
|
||||
j > 0;
|
||||
i --, j --)
|
||||
ret = (ret << 1) | ((buf[i / 8] & bits[i & 7]) != 0);
|
||||
|
||||
curbit += code_size;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'gif_read_lzw()' - Read a byte from the LZW stream...
|
||||
*/
|
||||
|
||||
static int /* I - Byte from stream */
|
||||
gif_read_lzw(FILE *fp, /* I - File to read from */
|
||||
int first_time, /* I - 1 = first time, 0 = not first time */
|
||||
int input_code_size) /* I - Code size in bits */
|
||||
{
|
||||
int i, /* Looping var */
|
||||
code, /* Current code */
|
||||
incode; /* Input code */
|
||||
static short fresh = 0, /* 1 = empty buffers */
|
||||
code_size, /* Current code size */
|
||||
set_code_size, /* Initial code size set */
|
||||
max_code, /* Maximum code used */
|
||||
max_code_size, /* Maximum code size */
|
||||
firstcode, /* First code read */
|
||||
oldcode, /* Last code read */
|
||||
clear_code, /* Clear code for LZW input */
|
||||
end_code, /* End code for LZW input */
|
||||
table[2][4096], /* String table */
|
||||
stack[8192], /* Output stack */
|
||||
*sp; /* Current stack pointer */
|
||||
|
||||
|
||||
if (first_time)
|
||||
{
|
||||
/*
|
||||
* Setup LZW state...
|
||||
*/
|
||||
|
||||
set_code_size = input_code_size;
|
||||
code_size = set_code_size + 1;
|
||||
clear_code = 1 << set_code_size;
|
||||
end_code = clear_code + 1;
|
||||
max_code_size = 2 * clear_code;
|
||||
max_code = clear_code + 2;
|
||||
|
||||
/*
|
||||
* Initialize input buffers...
|
||||
*/
|
||||
|
||||
gif_get_code(fp, 0, 1);
|
||||
|
||||
/*
|
||||
* Wipe the decompressor table...
|
||||
*/
|
||||
|
||||
fresh = 1;
|
||||
|
||||
for (i = 0; i < clear_code; i ++)
|
||||
{
|
||||
table[0][i] = 0;
|
||||
table[1][i] = i;
|
||||
}
|
||||
|
||||
for (; i < 4096; i ++)
|
||||
table[0][i] = table[1][0] = 0;
|
||||
|
||||
sp = stack;
|
||||
|
||||
return (0);
|
||||
}
|
||||
else if (fresh)
|
||||
{
|
||||
fresh = 0;
|
||||
|
||||
do
|
||||
firstcode = oldcode = gif_get_code(fp, code_size, 0);
|
||||
while (firstcode == clear_code);
|
||||
|
||||
return (firstcode);
|
||||
}
|
||||
|
||||
if (sp > stack)
|
||||
return (*--sp);
|
||||
|
||||
while ((code = gif_get_code (fp, code_size, 0)) >= 0)
|
||||
{
|
||||
if (code == clear_code)
|
||||
{
|
||||
for (i = 0; i < clear_code; i ++)
|
||||
{
|
||||
table[0][i] = 0;
|
||||
table[1][i] = i;
|
||||
}
|
||||
|
||||
for (; i < 4096; i ++)
|
||||
table[0][i] = table[1][i] = 0;
|
||||
|
||||
code_size = set_code_size + 1;
|
||||
max_code_size = 2 * clear_code;
|
||||
max_code = clear_code + 2;
|
||||
|
||||
sp = stack;
|
||||
|
||||
firstcode = oldcode = gif_get_code(fp, code_size, 0);
|
||||
|
||||
return (firstcode);
|
||||
}
|
||||
else if (code == end_code)
|
||||
{
|
||||
unsigned char buf[260];
|
||||
|
||||
|
||||
if (!gif_eof)
|
||||
while (gif_get_block(fp, buf) > 0);
|
||||
|
||||
return (-2);
|
||||
}
|
||||
|
||||
incode = code;
|
||||
|
||||
if (code >= max_code)
|
||||
{
|
||||
*sp++ = firstcode;
|
||||
code = oldcode;
|
||||
}
|
||||
|
||||
while (code >= clear_code)
|
||||
{
|
||||
*sp++ = table[1][code];
|
||||
if (code == table[0][code])
|
||||
return (255);
|
||||
|
||||
code = table[0][code];
|
||||
}
|
||||
|
||||
*sp++ = firstcode = table[1][code];
|
||||
code = max_code;
|
||||
|
||||
if (code < 4096)
|
||||
{
|
||||
table[0][code] = oldcode;
|
||||
table[1][code] = firstcode;
|
||||
max_code ++;
|
||||
|
||||
if (max_code >= max_code_size && max_code_size < 4096)
|
||||
{
|
||||
max_code_size *= 2;
|
||||
code_size ++;
|
||||
}
|
||||
}
|
||||
|
||||
oldcode = incode;
|
||||
|
||||
if (sp > stack)
|
||||
return (*--sp);
|
||||
}
|
||||
|
||||
return (code);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'gif_read_image()' - Read a GIF image stream...
|
||||
*/
|
||||
|
||||
static int /* I - 0 = success, -1 = failure */
|
||||
gif_read_image(FILE *fp, /* I - Input file */
|
||||
image_t *img, /* I - Image pointer */
|
||||
gif_cmap_t cmap, /* I - Colormap */
|
||||
int interlace) /* I - Non-zero = interlaced image */
|
||||
{
|
||||
unsigned char code_size; /* Code size */
|
||||
ib_t *pixels, /* Pixel buffer */
|
||||
*temp; /* Current pixel */
|
||||
int xpos, /* Current X position */
|
||||
ypos, /* Current Y position */
|
||||
pass; /* Current pass */
|
||||
int pixel; /* Current pixel */
|
||||
int bpp; /* Bytes per pixel */
|
||||
static int xpasses[4] = { 8, 8, 4, 2 },
|
||||
ypasses[5] = { 0, 4, 2, 1, 999999 };
|
||||
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
pixels = calloc(bpp, img->xsize);
|
||||
xpos = 0;
|
||||
ypos = 0;
|
||||
pass = 0;
|
||||
code_size = getc(fp);
|
||||
|
||||
if (gif_read_lzw(fp, 1, code_size) < 0)
|
||||
return (-1);
|
||||
|
||||
temp = pixels;
|
||||
while ((pixel = gif_read_lzw(fp, 0, code_size)) >= 0)
|
||||
{
|
||||
switch (bpp)
|
||||
{
|
||||
case 4 :
|
||||
temp[3] = cmap[pixel][3];
|
||||
case 3 :
|
||||
temp[2] = cmap[pixel][2];
|
||||
case 2 :
|
||||
temp[1] = cmap[pixel][1];
|
||||
default :
|
||||
temp[0] = cmap[pixel][0];
|
||||
}
|
||||
|
||||
xpos ++;
|
||||
temp += bpp;
|
||||
if (xpos == img->xsize)
|
||||
{
|
||||
ImagePutRow(img, 0, ypos, img->xsize, pixels);
|
||||
|
||||
xpos = 0;
|
||||
temp = pixels;
|
||||
|
||||
if (interlace)
|
||||
{
|
||||
ypos += xpasses[pass];
|
||||
|
||||
if (ypos >= img->ysize)
|
||||
{
|
||||
pass ++;
|
||||
|
||||
ypos = ypasses[pass];
|
||||
}
|
||||
}
|
||||
else
|
||||
ypos ++;
|
||||
}
|
||||
|
||||
if (ypos >= img->ysize)
|
||||
break;
|
||||
}
|
||||
|
||||
free(pixels);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* JPEG image routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadJPEG() - Read a JPEG image file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
#ifdef HAVE_LIBJPEG
|
||||
# include <jpeglib.h> /* JPEG/JFIF image definitions */
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadJPEG()' - Read a JPEG image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadJPEG(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo; /* Decompressor info */
|
||||
struct jpeg_error_mgr jerr; /* Error handler info */
|
||||
ib_t *in, /* Input pixels */
|
||||
*out; /* Output pixels */
|
||||
|
||||
|
||||
(void)secondary;
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr);
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, fp);
|
||||
jpeg_read_header(&cinfo, 1);
|
||||
|
||||
cinfo.quantize_colors = 0;
|
||||
|
||||
if (cinfo.num_components == 1)
|
||||
{
|
||||
cinfo.out_color_space = JCS_GRAYSCALE;
|
||||
cinfo.out_color_components = 1;
|
||||
cinfo.output_components = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
cinfo.out_color_components = 3;
|
||||
cinfo.output_components = 3;
|
||||
}
|
||||
|
||||
jpeg_calc_output_dimensions(&cinfo);
|
||||
|
||||
img->xsize = cinfo.output_width;
|
||||
img->ysize = cinfo.output_height;
|
||||
img->colorspace = primary;
|
||||
|
||||
if (cinfo.X_density > 0 && cinfo.Y_density > 0 && cinfo.density_unit > 0)
|
||||
{
|
||||
if (cinfo.density_unit == 1)
|
||||
{
|
||||
img->xppi = cinfo.X_density;
|
||||
img->yppi = cinfo.Y_density;
|
||||
}
|
||||
else
|
||||
{
|
||||
img->xppi = (int)((float)cinfo.X_density * 2.54);
|
||||
img->yppi = (int)((float)cinfo.Y_density * 2.54);
|
||||
}
|
||||
}
|
||||
|
||||
ImageSetMaxTiles(img, 0);
|
||||
|
||||
in = malloc(img->xsize * cinfo.output_components);
|
||||
if (primary < 0)
|
||||
out = malloc(-img->xsize * primary);
|
||||
else
|
||||
out = malloc(img->xsize * primary);
|
||||
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
while (cinfo.output_scanline < cinfo.output_height)
|
||||
{
|
||||
jpeg_read_scanlines(&cinfo, (JSAMPROW *)&in, (JDIMENSION)1);
|
||||
|
||||
if ((saturation != 100 || hue != 0) && cinfo.output_components > 1)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
if ((primary == IMAGE_WHITE && cinfo.out_color_space == JCS_GRAYSCALE) ||
|
||||
(primary == IMAGE_RGB && cinfo.out_color_space == JCS_RGB))
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize * ImageGetDepth(img), lut);
|
||||
|
||||
ImagePutRow(img, 0, cinfo.output_scanline - 1, img->xsize, in);
|
||||
}
|
||||
else if (cinfo.out_color_space == JCS_GRAYSCALE)
|
||||
{
|
||||
switch (primary)
|
||||
{
|
||||
case IMAGE_BLACK :
|
||||
ImageWhiteToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_RGB :
|
||||
ImageWhiteToRGB(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageWhiteToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageWhiteToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * ImageGetDepth(img), lut);
|
||||
|
||||
ImagePutRow(img, 0, cinfo.output_scanline - 1, img->xsize, out);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (primary)
|
||||
{
|
||||
case IMAGE_WHITE :
|
||||
ImageRGBToWhite(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageRGBToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * ImageGetDepth(img), lut);
|
||||
|
||||
ImagePutRow(img, 0, cinfo.output_scanline - 1, img->xsize, out);
|
||||
}
|
||||
}
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBJPEG */
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PhotoCD routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadPhotoCD() - Read a PhotoCD image file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
|
||||
/*
|
||||
* PhotoCD support is currently limited to the 768x512 base image, which
|
||||
* is only YCC encoded. Support for the higher resolution images will
|
||||
* require a lot of extra code...
|
||||
*/
|
||||
|
||||
/*
|
||||
* 'ImageReadPhotoCD()' - Read a PhotoCD image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadPhotoCD(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
int x, y; /* Looping vars */
|
||||
int xdir, /* X direction */
|
||||
xstart; /* X starting point */
|
||||
int bpp; /* Bytes per pixel */
|
||||
int pass; /* Pass number */
|
||||
int rotation; /* 0 for 768x512, 1 for 512x768 */
|
||||
int temp, /* Adjusted luminance */
|
||||
temp2, /* Red, green, and blue values */
|
||||
cb, cr; /* Adjusted chroma values */
|
||||
ib_t *in, /* Input (YCC) pixels */
|
||||
*iy, /* Luminance */
|
||||
*icb, /* Blue chroma */
|
||||
*icr, /* Red chroma */
|
||||
*rgb, /* RGB */
|
||||
*rgbptr, /* Pointer into RGB data */
|
||||
*out; /* Output pixels */
|
||||
|
||||
|
||||
(void)secondary;
|
||||
|
||||
/*
|
||||
* Get the image orientation...
|
||||
*/
|
||||
|
||||
fseek(fp, 72, SEEK_SET);
|
||||
rotation = (getc(fp) & 63) != 8;
|
||||
|
||||
/*
|
||||
* Seek to the start of the base image...
|
||||
*/
|
||||
|
||||
fseek(fp, 0x30000, SEEK_SET);
|
||||
|
||||
/*
|
||||
* Allocate and initialize...
|
||||
*/
|
||||
|
||||
img->colorspace = primary;
|
||||
img->xppi = 128;
|
||||
img->yppi = 128;
|
||||
|
||||
if (rotation)
|
||||
{
|
||||
img->xsize = 512;
|
||||
img->ysize = 768;
|
||||
}
|
||||
else
|
||||
{
|
||||
img->xsize = 768;
|
||||
img->ysize = 512;
|
||||
}
|
||||
|
||||
ImageSetMaxTiles(img, 0);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
in = malloc(768 * 3);
|
||||
out = malloc(768 * bpp);
|
||||
|
||||
if (bpp > 1)
|
||||
rgb = malloc(768 * 3);
|
||||
|
||||
if (rotation)
|
||||
{
|
||||
xstart = 767 * bpp;
|
||||
xdir = -2 * bpp;
|
||||
}
|
||||
else
|
||||
{
|
||||
xstart = 0;
|
||||
xdir = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the image file...
|
||||
*/
|
||||
|
||||
for (y = 0; y < 512; y += 2)
|
||||
{
|
||||
/*
|
||||
* Grab the next two scanlines:
|
||||
*
|
||||
* YYYYYYYYYYYYYYY...
|
||||
* YYYYYYYYYYYYYYY...
|
||||
* CbCbCb...CrCrCr...
|
||||
*/
|
||||
|
||||
if (fread(in, 1, 768 * 3, fp) < (768 * 3))
|
||||
{
|
||||
/*
|
||||
* Couldn't read a row of data - return an error!
|
||||
*/
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process the two scanlines...
|
||||
*/
|
||||
|
||||
for (pass = 0, iy = in; pass < 2; pass ++)
|
||||
{
|
||||
if (bpp == 1)
|
||||
{
|
||||
/*
|
||||
* Just extract the luminance channel from the line and put it
|
||||
* in the image...
|
||||
*/
|
||||
|
||||
if (primary == IMAGE_BLACK)
|
||||
{
|
||||
if (rotation)
|
||||
{
|
||||
for (rgbptr = out + xstart, x = 0; x < 768; x ++)
|
||||
*rgbptr-- = 255 - *iy++;
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, 768, lut);
|
||||
|
||||
ImagePutCol(img, 511 - y - pass, 0, 768, out);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImageWhiteToBlack(iy, out, 768);
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, 768, lut);
|
||||
|
||||
ImagePutRow(img, 0, y + pass, 768, out);
|
||||
iy += 768;
|
||||
}
|
||||
}
|
||||
else if (rotation)
|
||||
{
|
||||
for (rgbptr = out + xstart, x = 0; x < 768; x ++)
|
||||
*rgbptr-- = 255 - *iy++;
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, 768, lut);
|
||||
|
||||
ImagePutCol(img, 511 - y - pass, 0, 768, out);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(iy, 768, lut);
|
||||
|
||||
ImagePutRow(img, 0, y + pass, 768, iy);
|
||||
iy += 768;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Convert YCbCr to RGB... While every pixel gets a luminance
|
||||
* value, adjacent pixels share chroma information.
|
||||
*/
|
||||
|
||||
for (x = 0, rgbptr = rgb + xstart, icb = in + 1536, icr = in + 1920;
|
||||
x < 768;
|
||||
x ++, iy ++, rgbptr += xdir)
|
||||
{
|
||||
if (!(x & 1))
|
||||
{
|
||||
cb = (float)(*icb - 156);
|
||||
cr = (float)(*icr - 137);
|
||||
}
|
||||
|
||||
temp = 92241 * (*iy);
|
||||
|
||||
temp2 = (temp + 86706 * cr) / 65536;
|
||||
if (temp2 < 0)
|
||||
*rgbptr++ = 0;
|
||||
else if (temp2 > 255)
|
||||
*rgbptr++ = 255;
|
||||
else
|
||||
*rgbptr++ = temp2;
|
||||
|
||||
temp2 = (temp - 25914 * cb - 44166 * cr) / 65536;
|
||||
if (temp2 < 0)
|
||||
*rgbptr++ = 0;
|
||||
else if (temp2 > 255)
|
||||
*rgbptr++ = 255;
|
||||
else
|
||||
*rgbptr++ = temp2;
|
||||
|
||||
temp2 = (temp + 133434 * cb) / 65536;
|
||||
if (temp2 < 0)
|
||||
*rgbptr++ = 0;
|
||||
else if (temp2 > 255)
|
||||
*rgbptr++ = 255;
|
||||
else
|
||||
*rgbptr++ = temp2;
|
||||
|
||||
if (x & 1)
|
||||
{
|
||||
icb ++;
|
||||
icr ++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Adjust the hue and saturation if needed...
|
||||
*/
|
||||
|
||||
if (saturation != 100 || hue != 0)
|
||||
ImageRGBAdjust(rgb, 768, saturation, hue);
|
||||
|
||||
/*
|
||||
* Then convert the RGB data to the appropriate colorspace and
|
||||
* put it in the image...
|
||||
*/
|
||||
|
||||
if (img->colorspace == IMAGE_RGB)
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(rgb, 768 * 3, lut);
|
||||
|
||||
if (rotation)
|
||||
ImagePutCol(img, 511 - y - pass, 0, 768, rgb);
|
||||
else
|
||||
ImagePutRow(img, 0, y + pass, 768, rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(rgb, out, 768);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(rgb, out, 768);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, 768 * bpp, lut);
|
||||
|
||||
if (rotation)
|
||||
ImagePutCol(img, 511 - y - pass, 0, 768, out);
|
||||
else
|
||||
ImagePutRow(img, 0, y + pass, 768, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free memory and return...
|
||||
*/
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
if (bpp > 1)
|
||||
free(rgb);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PNG image routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadPNG() - Read a PNG image file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
||||
#include <png.h> /* Portable Network Graphics (PNG) definitions */
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadPNG()' - Read a PNG image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadPNG(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
int y; /* Looping var */
|
||||
png_structp pp; /* PNG read pointer */
|
||||
png_infop info; /* PNG info pointers */
|
||||
int bpp; /* Bytes per pixel */
|
||||
ib_t *in, /* Input pixels */
|
||||
*out; /* Output pixels */
|
||||
|
||||
|
||||
/*
|
||||
* Setup the PNG data structures...
|
||||
*/
|
||||
|
||||
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
info = png_create_info_struct(pp);
|
||||
|
||||
/*
|
||||
* Initialize the PNG read "engine"...
|
||||
*/
|
||||
|
||||
png_init_io(pp, fp);
|
||||
|
||||
/*
|
||||
* Get the image dimensions and load the output image...
|
||||
*/
|
||||
|
||||
png_read_info(pp, info);
|
||||
|
||||
if (info->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(pp);
|
||||
|
||||
if (info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
img->colorspace = secondary;
|
||||
else
|
||||
img->colorspace = primary;
|
||||
|
||||
img->xsize = info->width;
|
||||
img->ysize = info->height;
|
||||
|
||||
if (info->valid & PNG_INFO_pHYs &&
|
||||
info->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
{
|
||||
img->xppi = (int)((float)info->x_pixels_per_unit * 0.0254);
|
||||
img->yppi = (int)((float)info->y_pixels_per_unit * 0.0254);
|
||||
}
|
||||
|
||||
ImageSetMaxTiles(img, 0);
|
||||
|
||||
if (info->bit_depth < 8)
|
||||
{
|
||||
png_set_packing(pp);
|
||||
|
||||
if (info->valid & PNG_INFO_sBIT)
|
||||
png_set_shift(pp, &(info->sig_bit));
|
||||
}
|
||||
else if (info->bit_depth == 16)
|
||||
png_set_strip_16(pp);
|
||||
|
||||
if (info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
in = malloc(img->xsize);
|
||||
else
|
||||
in = malloc(img->xsize * 3);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
out = malloc(img->xsize * bpp);
|
||||
|
||||
/*
|
||||
* This doesn't work for interlaced PNG files... :(
|
||||
*/
|
||||
|
||||
for (y = 0; y < img->ysize; y ++)
|
||||
{
|
||||
if (info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
if (img->colorspace == IMAGE_WHITE)
|
||||
png_read_row(pp, (png_bytep)out, NULL);
|
||||
else
|
||||
{
|
||||
png_read_row(pp, (png_bytep)in, NULL);
|
||||
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_RGB :
|
||||
ImageWhiteToRGB(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageWhiteToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageWhiteToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageWhiteToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (img->colorspace == IMAGE_RGB)
|
||||
{
|
||||
png_read_row(pp, (png_bytep)out, NULL);
|
||||
|
||||
if (saturation != 100 || hue != 0)
|
||||
ImageRGBAdjust(out, img->xsize, saturation, hue);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_read_row(pp, (png_bytep)in, NULL);
|
||||
|
||||
if ((saturation != 100 || hue != 0) && bpp > 1)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_WHITE :
|
||||
ImageRGBToWhite(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageRGBToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
|
||||
png_read_end(pp, info);
|
||||
png_read_destroy(pp, info, NULL);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_LIBPNG && HAVE_LIBZ */
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Portable Any Map file routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadPNM() - Read a PNM image file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadPNM()' - Read a PNM image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadPNM(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
int x, y; /* Looping vars */
|
||||
int bpp; /* Bytes per pixel */
|
||||
ib_t *in, /* Input pixels */
|
||||
*inptr, /* Current input pixel */
|
||||
*out, /* Output pixels */
|
||||
*outptr, /* Current output pixel */
|
||||
bit; /* Bit in input line */
|
||||
char line[255], /* Input line */
|
||||
*lineptr; /* Pointer in line */
|
||||
int format, /* Format of PNM file */
|
||||
val, /* Pixel value */
|
||||
maxval; /* Maximum pixel value */
|
||||
|
||||
|
||||
/*
|
||||
* Read the file header in the format:
|
||||
*
|
||||
* Pformat
|
||||
* # comment1
|
||||
* # comment2
|
||||
* ...
|
||||
* # commentN
|
||||
* width
|
||||
* height
|
||||
* max sample
|
||||
*/
|
||||
|
||||
lineptr = fgets(line, sizeof(line), fp);
|
||||
lineptr ++;
|
||||
|
||||
format = atoi(lineptr);
|
||||
while (isdigit(*lineptr))
|
||||
lineptr ++;
|
||||
|
||||
while (lineptr != NULL && img->xsize == 0)
|
||||
{
|
||||
if (*lineptr == '\0' || *lineptr == '#')
|
||||
lineptr = fgets(line, sizeof(line), fp);
|
||||
else if (isdigit(*lineptr))
|
||||
{
|
||||
img->xsize = atoi(lineptr);
|
||||
while (isdigit(*lineptr))
|
||||
lineptr ++;
|
||||
}
|
||||
else
|
||||
lineptr ++;
|
||||
}
|
||||
|
||||
while (lineptr != NULL && img->ysize == 0)
|
||||
{
|
||||
if (*lineptr == '\0' || *lineptr == '#')
|
||||
lineptr = fgets(line, sizeof(line), fp);
|
||||
else if (isdigit(*lineptr))
|
||||
{
|
||||
img->ysize = atoi(lineptr);
|
||||
while (isdigit(*lineptr))
|
||||
lineptr ++;
|
||||
}
|
||||
else
|
||||
lineptr ++;
|
||||
}
|
||||
|
||||
if (format != 1 && format != 4)
|
||||
{
|
||||
maxval = 0;
|
||||
|
||||
while (lineptr != NULL && maxval == 0)
|
||||
{
|
||||
if (*lineptr == '\0' || *lineptr == '#')
|
||||
lineptr = fgets(line, sizeof(line), fp);
|
||||
else if (isdigit(*lineptr))
|
||||
{
|
||||
maxval = atoi(lineptr);
|
||||
while (isdigit(*lineptr))
|
||||
lineptr ++;
|
||||
}
|
||||
else
|
||||
lineptr ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
maxval = 1;
|
||||
|
||||
if (format == 1 || format == 2 || format == 4 || format == 5)
|
||||
img->colorspace = secondary;
|
||||
else
|
||||
img->colorspace = primary;
|
||||
|
||||
ImageSetMaxTiles(img, 0);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
in = malloc(img->xsize * 3);
|
||||
out = malloc(img->xsize * bpp);
|
||||
|
||||
/*
|
||||
* Read the image file...
|
||||
*/
|
||||
|
||||
for (y = 0; y < img->ysize; y ++)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case 1 :
|
||||
case 2 :
|
||||
for (x = img->xsize, inptr = in; x > 0; x --, inptr ++)
|
||||
if (fscanf(fp, "%d", &val) == 1)
|
||||
*inptr = 255 * val / maxval;
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
for (x = img->xsize, inptr = in; x > 0; x --, inptr += 3)
|
||||
{
|
||||
if (fscanf(fp, "%d", &val) == 1)
|
||||
inptr[0] = 255 * val / maxval;
|
||||
if (fscanf(fp, "%d", &val) == 1)
|
||||
inptr[1] = 255 * val / maxval;
|
||||
if (fscanf(fp, "%d", &val) == 1)
|
||||
inptr[2] = 255 * val / maxval;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
fread(out, (img->xsize + 7) / 8, 1, fp);
|
||||
for (x = img->xsize, inptr = in, outptr = out, bit = 128;
|
||||
x > 0;
|
||||
x --, inptr ++)
|
||||
{
|
||||
if (*outptr & bit)
|
||||
*inptr = 255;
|
||||
else
|
||||
*inptr = 0;
|
||||
|
||||
if (bit > 1)
|
||||
bit >>= 1;
|
||||
else
|
||||
{
|
||||
bit = 128;
|
||||
inptr ++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 5 :
|
||||
fread(in, img->xsize, 1, fp);
|
||||
break;
|
||||
|
||||
case 6 :
|
||||
fread(in, img->xsize, 3, fp);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case 1 :
|
||||
case 2 :
|
||||
case 4 :
|
||||
case 5 :
|
||||
if (img->colorspace == IMAGE_WHITE)
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_RGB :
|
||||
ImageWhiteToRGB(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageWhiteToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageWhiteToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageWhiteToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
if ((saturation != 100 || hue != 0) && bpp > 1)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
if (img->colorspace == IMAGE_RGB)
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize * 3, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_WHITE :
|
||||
ImageRGBToWhite(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageRGBToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,267 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* SGI image file routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadSGI() - Read a SGI image file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
#include "image-sgi.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadSGI()' - Read a SGI image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadSGI(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary, /* I - Secondary choice for colorspace */
|
||||
int saturation, /* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
int i, y; /* Looping vars */
|
||||
int bpp; /* Bytes per pixel */
|
||||
sgi_t *sgip; /* SGI image file */
|
||||
ib_t *in, /* Input pixels */
|
||||
*inptr, /* Current input pixel */
|
||||
*out; /* Output pixels */
|
||||
unsigned short *rows[4], /* Row pointers for image data */
|
||||
*red,
|
||||
*green,
|
||||
*blue,
|
||||
*gray,
|
||||
*alpha;
|
||||
|
||||
|
||||
/*
|
||||
* Setup the SGI file...
|
||||
*/
|
||||
|
||||
sgip = sgiOpenFile(fp, SGI_READ, 0, 0, 0, 0, 0);
|
||||
|
||||
/*
|
||||
* Get the image dimensions and load the output image...
|
||||
*/
|
||||
|
||||
if (sgip->zsize < 3)
|
||||
img->colorspace = secondary;
|
||||
else
|
||||
img->colorspace = primary;
|
||||
|
||||
img->xsize = sgip->xsize;
|
||||
img->ysize = sgip->ysize;
|
||||
|
||||
ImageSetMaxTiles(img, 0);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
in = malloc(img->xsize * sgip->zsize);
|
||||
out = malloc(img->xsize * bpp);
|
||||
|
||||
rows[0] = calloc(img->xsize * sgip->zsize, sizeof(unsigned short));
|
||||
for (i = 1; i < sgip->zsize; i ++)
|
||||
rows[i] = rows[0] + i * img->xsize;
|
||||
|
||||
/*
|
||||
* Read the SGI image file...
|
||||
*/
|
||||
|
||||
for (y = 0; y < img->ysize; y ++)
|
||||
{
|
||||
for (i = 0; i < sgip->zsize; i ++)
|
||||
sgiGetRow(sgip, rows[i], img->ysize - 1 - y, i);
|
||||
|
||||
switch (sgip->zsize)
|
||||
{
|
||||
case 1 :
|
||||
if (sgip->bpp == 1)
|
||||
for (i = img->xsize - 1, gray = rows[0], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = *gray++;
|
||||
}
|
||||
else
|
||||
for (i = img->xsize - 1, gray = rows[0], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = (*gray++) / 256 + 128;
|
||||
}
|
||||
break;
|
||||
case 2 :
|
||||
if (sgip->bpp == 1)
|
||||
for (i = img->xsize - 1, gray = rows[0], alpha = rows[1], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = (*gray++) * (*alpha++) / 255;
|
||||
}
|
||||
else
|
||||
for (i = img->xsize - 1, gray = rows[0], alpha = rows[1], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = ((*gray++) / 256 + 128) * (*alpha++) / 32767;
|
||||
}
|
||||
break;
|
||||
case 3 :
|
||||
if (sgip->bpp == 1)
|
||||
for (i = img->xsize - 1, red = rows[0], green = rows[1],
|
||||
blue = rows[2], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = *red++;
|
||||
*inptr++ = *green++;
|
||||
*inptr++ = *blue++;
|
||||
}
|
||||
else
|
||||
for (i = img->xsize - 1, red = rows[0], green = rows[1],
|
||||
blue = rows[2], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = (*red++) / 256 + 128;
|
||||
*inptr++ = (*green++) / 256 + 128;
|
||||
*inptr++ = (*blue++) / 256 + 128;
|
||||
}
|
||||
break;
|
||||
case 4 :
|
||||
if (sgip->bpp == 1)
|
||||
for (i = img->xsize - 1, red = rows[0], green = rows[1],
|
||||
blue = rows[2], alpha = rows[3], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = (*red++) * (*alpha) / 255;
|
||||
*inptr++ = (*green++) * (*alpha) / 255;
|
||||
*inptr++ = (*blue++) * (*alpha++) / 255;
|
||||
}
|
||||
else
|
||||
for (i = img->xsize - 1, red = rows[0], green = rows[1],
|
||||
blue = rows[2], inptr = in;
|
||||
i >= 0;
|
||||
i --)
|
||||
{
|
||||
*inptr++ = ((*red++) / 256 + 128) * (*alpha) / 32767;
|
||||
*inptr++ = ((*green++) / 256 + 128) * (*alpha) / 32767;
|
||||
*inptr++ = ((*blue++) / 256 + 128) * (*alpha++) / 32767;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (sgip->zsize < 3)
|
||||
{
|
||||
if (img->colorspace == IMAGE_WHITE)
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_RGB :
|
||||
ImageWhiteToRGB(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageWhiteToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageWhiteToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageWhiteToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (img->colorspace == IMAGE_RGB)
|
||||
{
|
||||
if (saturation != 100 || hue != 0)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize * 3, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((saturation != 100 || hue != 0) && bpp > 1)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_WHITE :
|
||||
ImageRGBToWhite(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageRGBToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(in);
|
||||
free(out);
|
||||
free(rows[0]);
|
||||
|
||||
sgiClose(sgip);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* SGI image file format library definitions for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _SGI_H_
|
||||
# define _SGI_H_
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
# define SGI_MAGIC 474 /* Magic number in image file */
|
||||
|
||||
# define SGI_READ 0 /* Read from an SGI image file */
|
||||
# define SGI_WRITE 1 /* Write to an SGI image file */
|
||||
|
||||
# define SGI_COMP_NONE 0 /* No compression */
|
||||
# define SGI_COMP_RLE 1 /* Run-length encoding */
|
||||
# define SGI_COMP_ARLE 2 /* Agressive run-length encoding */
|
||||
|
||||
|
||||
/*
|
||||
* Image structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *file; /* Image file */
|
||||
int mode, /* File open mode */
|
||||
bpp, /* Bytes per pixel/channel */
|
||||
comp; /* Compression */
|
||||
unsigned short xsize, /* Width in pixels */
|
||||
ysize, /* Height in pixels */
|
||||
zsize; /* Number of channels */
|
||||
long firstrow, /* File offset for first row */
|
||||
nextrow, /* File offset for next row */
|
||||
**table, /* Offset table for compression */
|
||||
**length; /* Length table for compression */
|
||||
unsigned short *arle_row; /* Advanced RLE compression buffer */
|
||||
long arle_offset, /* Advanced RLE buffer offset */
|
||||
arle_length; /* Advanced RLE buffer length */
|
||||
} sgi_t;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
extern int sgiClose(sgi_t *sgip);
|
||||
extern int sgiGetRow(sgi_t *sgip, unsigned short *row, int y, int z);
|
||||
extern sgi_t *sgiOpen(char *filename, int mode, int comp, int bpp,
|
||||
int xsize, int ysize, int zsize);
|
||||
extern sgi_t *sgiOpenFile(FILE *file, int mode, int comp, int bpp,
|
||||
int xsize, int ysize, int zsize);
|
||||
extern int sgiPutRow(sgi_t *sgip, unsigned short *row, int y, int z);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
#endif /* !_SGI_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,857 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* SGI image file format library routines for the Common UNIX Printing
|
||||
* System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* sgiClose() - Close an SGI image file.
|
||||
* sgiGetRow() - Get a row of image data from a file.
|
||||
* sgiOpen() - Open an SGI image file for reading or writing.
|
||||
* sgiOpenFile() - Open an SGI image file for reading or writing.
|
||||
* sgiPutRow() - Put a row of image data to a file.
|
||||
* getlong() - Get a 32-bit big-endian integer.
|
||||
* getshort() - Get a 16-bit big-endian integer.
|
||||
* putlong() - Put a 32-bit big-endian integer.
|
||||
* putshort() - Put a 16-bit big-endian integer.
|
||||
* read_rle8() - Read 8-bit RLE data.
|
||||
* read_rle16() - Read 16-bit RLE data.
|
||||
* write_rle8() - Write 8-bit RLE data.
|
||||
* write_rle16() - Write 16-bit RLE data.
|
||||
*/
|
||||
|
||||
#include "image-sgi.h"
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int getlong(FILE *);
|
||||
static int getshort(FILE *);
|
||||
static int putlong(long, FILE *);
|
||||
static int putshort(unsigned short, FILE *);
|
||||
static int read_rle8(FILE *, unsigned short *, int);
|
||||
static int read_rle16(FILE *, unsigned short *, int);
|
||||
static int write_rle8(FILE *, unsigned short *, int);
|
||||
static int write_rle16(FILE *, unsigned short *, int);
|
||||
|
||||
|
||||
/*
|
||||
* 'sgiClose()' - Close an SGI image file.
|
||||
*/
|
||||
|
||||
int
|
||||
sgiClose(sgi_t *sgip) /* I - SGI image */
|
||||
{
|
||||
int i; /* Return status */
|
||||
long *offset; /* Looping var for offset table */
|
||||
|
||||
|
||||
if (sgip == NULL)
|
||||
return (-1);
|
||||
|
||||
if (sgip->mode == SGI_WRITE && sgip->comp != SGI_COMP_NONE)
|
||||
{
|
||||
/*
|
||||
* Write the scanline offset table to the file...
|
||||
*/
|
||||
|
||||
fseek(sgip->file, 512, SEEK_SET);
|
||||
|
||||
for (i = sgip->ysize * sgip->zsize, offset = sgip->table[0];
|
||||
i > 0;
|
||||
i --, offset ++)
|
||||
if (putlong(offset[0], sgip->file) < 0)
|
||||
return (-1);
|
||||
|
||||
for (i = sgip->ysize * sgip->zsize, offset = sgip->length[0];
|
||||
i > 0;
|
||||
i --, offset ++)
|
||||
if (putlong(offset[0], sgip->file) < 0)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (sgip->table != NULL)
|
||||
{
|
||||
free(sgip->table[0]);
|
||||
free(sgip->table);
|
||||
}
|
||||
|
||||
if (sgip->length != NULL)
|
||||
{
|
||||
free(sgip->length[0]);
|
||||
free(sgip->length);
|
||||
}
|
||||
|
||||
if (sgip->comp == SGI_COMP_ARLE)
|
||||
free(sgip->arle_row);
|
||||
|
||||
i = fclose(sgip->file);
|
||||
free(sgip);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'sgiGetRow()' - Get a row of image data from a file.
|
||||
*/
|
||||
|
||||
int
|
||||
sgiGetRow(sgi_t *sgip, /* I - SGI image */
|
||||
unsigned short *row, /* O - Row to read */
|
||||
int y, /* I - Line to read */
|
||||
int z) /* I - Channel to read */
|
||||
{
|
||||
int x; /* X coordinate */
|
||||
long offset; /* File offset */
|
||||
|
||||
|
||||
if (sgip == NULL ||
|
||||
row == NULL ||
|
||||
y < 0 || y >= sgip->ysize ||
|
||||
z < 0 || z >= sgip->zsize)
|
||||
return (-1);
|
||||
|
||||
switch (sgip->comp)
|
||||
{
|
||||
case SGI_COMP_NONE :
|
||||
/*
|
||||
* Seek to the image row - optimize buffering by only seeking if
|
||||
* necessary...
|
||||
*/
|
||||
|
||||
offset = 512 + (y + z * sgip->ysize) * sgip->xsize * sgip->bpp;
|
||||
if (offset != ftell(sgip->file))
|
||||
fseek(sgip->file, offset, SEEK_SET);
|
||||
|
||||
if (sgip->bpp == 1)
|
||||
{
|
||||
for (x = sgip->xsize; x > 0; x --, row ++)
|
||||
*row = getc(sgip->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x = sgip->xsize; x > 0; x --, row ++)
|
||||
*row = getshort(sgip->file);
|
||||
}
|
||||
break;
|
||||
|
||||
case SGI_COMP_RLE :
|
||||
offset = sgip->table[z][y];
|
||||
if (offset != ftell(sgip->file))
|
||||
fseek(sgip->file, offset, SEEK_SET);
|
||||
|
||||
if (sgip->bpp == 1)
|
||||
return (read_rle8(sgip->file, row, sgip->xsize));
|
||||
else
|
||||
return (read_rle16(sgip->file, row, sgip->xsize));
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'sgiOpen()' - Open an SGI image file for reading or writing.
|
||||
*/
|
||||
|
||||
sgi_t *
|
||||
sgiOpen(char *filename, /* I - File to open */
|
||||
int mode, /* I - Open mode (SGI_READ or SGI_WRITE) */
|
||||
int comp, /* I - Type of compression */
|
||||
int bpp, /* I - Bytes per pixel */
|
||||
int xsize, /* I - Width of image in pixels */
|
||||
int ysize, /* I - Height of image in pixels */
|
||||
int zsize) /* I - Number of channels */
|
||||
{
|
||||
sgi_t *sgip; /* New SGI image file */
|
||||
FILE *file; /* Image file pointer */
|
||||
|
||||
|
||||
if (mode == SGI_READ)
|
||||
file = fopen(filename, "rb");
|
||||
else
|
||||
file = fopen(filename, "wb+");
|
||||
|
||||
if (file == NULL)
|
||||
return (NULL);
|
||||
|
||||
if ((sgip = sgiOpenFile(file, mode, comp, bpp, xsize, ysize, zsize)) == NULL)
|
||||
fclose(file);
|
||||
|
||||
return (sgip);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'sgiOpenFile()' - Open an SGI image file for reading or writing.
|
||||
*/
|
||||
|
||||
sgi_t *
|
||||
sgiOpenFile(FILE *file, /* I - File to open */
|
||||
int mode, /* I - Open mode (SGI_READ or SGI_WRITE) */
|
||||
int comp, /* I - Type of compression */
|
||||
int bpp, /* I - Bytes per pixel */
|
||||
int xsize, /* I - Width of image in pixels */
|
||||
int ysize, /* I - Height of image in pixels */
|
||||
int zsize) /* I - Number of channels */
|
||||
{
|
||||
int i, j; /* Looping var */
|
||||
char name[80]; /* Name of file in image header */
|
||||
short magic; /* Magic number */
|
||||
sgi_t *sgip; /* New image pointer */
|
||||
|
||||
|
||||
if ((sgip = calloc(sizeof(sgi_t), 1)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
sgip->file = file;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case SGI_READ :
|
||||
sgip->mode = SGI_READ;
|
||||
|
||||
magic = getshort(sgip->file);
|
||||
if (magic != SGI_MAGIC)
|
||||
{
|
||||
free(sgip);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
sgip->comp = getc(sgip->file);
|
||||
sgip->bpp = getc(sgip->file);
|
||||
getshort(sgip->file); /* Dimensions */
|
||||
sgip->xsize = getshort(sgip->file);
|
||||
sgip->ysize = getshort(sgip->file);
|
||||
sgip->zsize = getshort(sgip->file);
|
||||
getlong(sgip->file); /* Minimum pixel */
|
||||
getlong(sgip->file); /* Maximum pixel */
|
||||
|
||||
if (sgip->comp)
|
||||
{
|
||||
/*
|
||||
* This file is compressed; read the scanline tables...
|
||||
*/
|
||||
|
||||
fseek(sgip->file, 512, SEEK_SET);
|
||||
|
||||
sgip->table = calloc(sgip->zsize, sizeof(long *));
|
||||
sgip->table[0] = calloc(sgip->ysize * sgip->zsize, sizeof(long));
|
||||
for (i = 1; i < sgip->zsize; i ++)
|
||||
sgip->table[i] = sgip->table[0] + i * sgip->ysize;
|
||||
|
||||
for (i = 0; i < sgip->zsize; i ++)
|
||||
for (j = 0; j < sgip->ysize; j ++)
|
||||
sgip->table[i][j] = getlong(sgip->file);
|
||||
}
|
||||
break;
|
||||
|
||||
case SGI_WRITE :
|
||||
if (xsize < 1 ||
|
||||
ysize < 1 ||
|
||||
zsize < 1 ||
|
||||
bpp < 1 || bpp > 2 ||
|
||||
comp < SGI_COMP_NONE || comp > SGI_COMP_ARLE)
|
||||
{
|
||||
free(sgip);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
sgip->mode = SGI_WRITE;
|
||||
|
||||
putshort(SGI_MAGIC, sgip->file);
|
||||
putc((sgip->comp = comp) != 0, sgip->file);
|
||||
putc(sgip->bpp = bpp, sgip->file);
|
||||
putshort(3, sgip->file); /* Dimensions */
|
||||
putshort(sgip->xsize = xsize, sgip->file);
|
||||
putshort(sgip->ysize = ysize, sgip->file);
|
||||
putshort(sgip->zsize = zsize, sgip->file);
|
||||
if (bpp == 1)
|
||||
{
|
||||
putlong(0, sgip->file); /* Minimum pixel */
|
||||
putlong(255, sgip->file); /* Maximum pixel */
|
||||
}
|
||||
else
|
||||
{
|
||||
putlong(-32768, sgip->file); /* Minimum pixel */
|
||||
putlong(32767, sgip->file); /* Maximum pixel */
|
||||
}
|
||||
putlong(0, sgip->file); /* Reserved */
|
||||
|
||||
memset(name, 0, sizeof(name));
|
||||
fwrite(name, sizeof(name), 1, sgip->file);
|
||||
|
||||
for (i = 0; i < 102; i ++)
|
||||
putlong(0, sgip->file);
|
||||
|
||||
switch (comp)
|
||||
{
|
||||
case SGI_COMP_NONE : /* No compression */
|
||||
/*
|
||||
* This file is uncompressed. To avoid problems with sparse files,
|
||||
* we need to write blank pixels for the entire image...
|
||||
*/
|
||||
|
||||
if (bpp == 1)
|
||||
{
|
||||
for (i = xsize * ysize * zsize; i > 0; i --)
|
||||
putc(0, sgip->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = xsize * ysize * zsize; i > 0; i --)
|
||||
putshort(0, sgip->file);
|
||||
}
|
||||
break;
|
||||
|
||||
case SGI_COMP_ARLE : /* Aggressive RLE */
|
||||
sgip->arle_row = calloc(xsize, sizeof(unsigned short));
|
||||
sgip->arle_offset = 0;
|
||||
|
||||
case SGI_COMP_RLE : /* Run-Length Encoding */
|
||||
/*
|
||||
* This file is compressed; write the (blank) scanline tables...
|
||||
*/
|
||||
|
||||
for (i = 2 * ysize * zsize; i > 0; i --)
|
||||
putlong(0, sgip->file);
|
||||
|
||||
sgip->firstrow = ftell(sgip->file);
|
||||
sgip->nextrow = ftell(sgip->file);
|
||||
sgip->table = calloc(sgip->zsize, sizeof(long *));
|
||||
sgip->table[0] = calloc(sgip->ysize * sgip->zsize, sizeof(long));
|
||||
for (i = 1; i < sgip->zsize; i ++)
|
||||
sgip->table[i] = sgip->table[0] + i * sgip->ysize;
|
||||
sgip->length = calloc(sgip->zsize, sizeof(long *));
|
||||
sgip->length[0] = calloc(sgip->ysize * sgip->zsize, sizeof(long));
|
||||
for (i = 1; i < sgip->zsize; i ++)
|
||||
sgip->length[i] = sgip->length[0] + i * sgip->ysize;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
free(sgip);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (sgip);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'sgiPutRow()' - Put a row of image data to a file.
|
||||
*/
|
||||
|
||||
int
|
||||
sgiPutRow(sgi_t *sgip, /* I - SGI image */
|
||||
unsigned short *row, /* I - Row to write */
|
||||
int y, /* I - Line to write */
|
||||
int z) /* I - Channel to write */
|
||||
{
|
||||
int x; /* X coordinate */
|
||||
long offset; /* File offset */
|
||||
|
||||
|
||||
if (sgip == NULL ||
|
||||
row == NULL ||
|
||||
y < 0 || y >= sgip->ysize ||
|
||||
z < 0 || z >= sgip->zsize)
|
||||
return (-1);
|
||||
|
||||
switch (sgip->comp)
|
||||
{
|
||||
case SGI_COMP_NONE :
|
||||
/*
|
||||
* Seek to the image row - optimize buffering by only seeking if
|
||||
* necessary...
|
||||
*/
|
||||
|
||||
offset = 512 + (y + z * sgip->ysize) * sgip->xsize * sgip->bpp;
|
||||
if (offset != ftell(sgip->file))
|
||||
fseek(sgip->file, offset, SEEK_SET);
|
||||
|
||||
if (sgip->bpp == 1)
|
||||
{
|
||||
for (x = sgip->xsize; x > 0; x --, row ++)
|
||||
putc(*row, sgip->file);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x = sgip->xsize; x > 0; x --, row ++)
|
||||
putshort(*row, sgip->file);
|
||||
}
|
||||
break;
|
||||
|
||||
case SGI_COMP_ARLE :
|
||||
if (sgip->table[z][y] != 0)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* First check the last row written...
|
||||
*/
|
||||
|
||||
if (sgip->arle_offset > 0)
|
||||
{
|
||||
for (x = 0; x < sgip->xsize; x ++)
|
||||
if (row[x] != sgip->arle_row[x])
|
||||
break;
|
||||
|
||||
if (x == sgip->xsize)
|
||||
{
|
||||
sgip->table[z][y] = sgip->arle_offset;
|
||||
sgip->length[z][y] = sgip->arle_length;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If that didn't match, search all the previous rows...
|
||||
*/
|
||||
|
||||
fseek(sgip->file, sgip->firstrow, SEEK_SET);
|
||||
|
||||
if (sgip->bpp == 1)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
sgip->arle_offset = ftell(sgip->file);
|
||||
if ((sgip->arle_length = read_rle8(sgip->file, sgip->arle_row, sgip->xsize)) < 0)
|
||||
{
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (memcmp(row, sgip->arle_row, sgip->xsize * sizeof(unsigned short)) == 0)
|
||||
{
|
||||
x = sgip->xsize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
sgip->arle_offset = ftell(sgip->file);
|
||||
if ((sgip->arle_length = read_rle16(sgip->file, sgip->arle_row, sgip->xsize)) < 0)
|
||||
{
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (memcmp(row, sgip->arle_row, sgip->xsize * sizeof(unsigned short)) == 0)
|
||||
{
|
||||
x = sgip->xsize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x == sgip->xsize)
|
||||
{
|
||||
sgip->table[z][y] = sgip->arle_offset;
|
||||
sgip->length[z][y] = sgip->arle_length;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
fseek(sgip->file, 0, SEEK_END); /* Clear EOF */
|
||||
|
||||
case SGI_COMP_RLE :
|
||||
if (sgip->table[z][y] != 0)
|
||||
return (-1);
|
||||
|
||||
offset = sgip->table[z][y] = sgip->nextrow;
|
||||
|
||||
if (offset != ftell(sgip->file))
|
||||
fseek(sgip->file, offset, SEEK_SET);
|
||||
|
||||
if (sgip->bpp == 1)
|
||||
x = write_rle8(sgip->file, row, sgip->xsize);
|
||||
else
|
||||
x = write_rle16(sgip->file, row, sgip->xsize);
|
||||
|
||||
if (sgip->comp == SGI_COMP_ARLE)
|
||||
{
|
||||
sgip->arle_offset = offset;
|
||||
sgip->arle_length = x;
|
||||
memcpy(sgip->arle_row, row, sgip->xsize * sizeof(unsigned short));
|
||||
}
|
||||
|
||||
sgip->nextrow = ftell(sgip->file);
|
||||
sgip->length[z][y] = x;
|
||||
|
||||
return (x);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'getlong()' - Get a 32-bit big-endian integer.
|
||||
*/
|
||||
|
||||
static int
|
||||
getlong(FILE *fp) /* I - File to read from */
|
||||
{
|
||||
unsigned char b[4];
|
||||
|
||||
|
||||
fread(b, 4, 1, fp);
|
||||
return ((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'getshort()' - Get a 16-bit big-endian integer.
|
||||
*/
|
||||
|
||||
static int
|
||||
getshort(FILE *fp) /* I - File to read from */
|
||||
{
|
||||
unsigned char b[2];
|
||||
|
||||
|
||||
fread(b, 2, 1, fp);
|
||||
return ((b[0] << 8) | b[1]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'putlong()' - Put a 32-bit big-endian integer.
|
||||
*/
|
||||
|
||||
static int
|
||||
putlong(long n, /* I - Long to write */
|
||||
FILE *fp) /* I - File to write to */
|
||||
{
|
||||
if (putc(n >> 24, fp) == EOF)
|
||||
return (EOF);
|
||||
if (putc(n >> 16, fp) == EOF)
|
||||
return (EOF);
|
||||
if (putc(n >> 8, fp) == EOF)
|
||||
return (EOF);
|
||||
if (putc(n, fp) == EOF)
|
||||
return (EOF);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'putshort()' - Put a 16-bit big-endian integer.
|
||||
*/
|
||||
|
||||
static int
|
||||
putshort(unsigned short n, /* I - Short to write */
|
||||
FILE *fp) /* I - File to write to */
|
||||
{
|
||||
if (putc(n >> 8, fp) == EOF)
|
||||
return (EOF);
|
||||
if (putc(n, fp) == EOF)
|
||||
return (EOF);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'read_rle8()' - Read 8-bit RLE data.
|
||||
*/
|
||||
|
||||
static int
|
||||
read_rle8(FILE *fp, /* I - File to read from */
|
||||
unsigned short *row, /* O - Data */
|
||||
int xsize) /* I - Width of data in pixels */
|
||||
{
|
||||
int i, /* Looping var */
|
||||
ch, /* Current character */
|
||||
count, /* RLE count */
|
||||
length; /* Number of bytes read... */
|
||||
|
||||
|
||||
length = 0;
|
||||
|
||||
while (xsize > 0)
|
||||
{
|
||||
if ((ch = getc(fp)) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
count = ch & 127;
|
||||
if (count == 0)
|
||||
break;
|
||||
|
||||
if (ch & 128)
|
||||
{
|
||||
for (i = 0; i < count; i ++, row ++, xsize --, length ++)
|
||||
*row = getc(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = getc(fp);
|
||||
length ++;
|
||||
for (i = 0; i < count; i ++, row ++, xsize --)
|
||||
*row = ch;
|
||||
}
|
||||
}
|
||||
|
||||
return (xsize > 0 ? -1 : length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'read_rle16()' - Read 16-bit RLE data.
|
||||
*/
|
||||
|
||||
static int
|
||||
read_rle16(FILE *fp, /* I - File to read from */
|
||||
unsigned short *row, /* O - Data */
|
||||
int xsize)/* I - Width of data in pixels */
|
||||
{
|
||||
int i, /* Looping var */
|
||||
ch, /* Current character */
|
||||
count, /* RLE count */
|
||||
length; /* Number of bytes read... */
|
||||
|
||||
|
||||
length = 0;
|
||||
|
||||
while (xsize > 0)
|
||||
{
|
||||
if ((ch = getshort(fp)) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
count = ch & 127;
|
||||
if (count == 0)
|
||||
break;
|
||||
|
||||
if (ch & 128)
|
||||
{
|
||||
for (i = 0; i < count; i ++, row ++, xsize --, length ++)
|
||||
*row = getshort(fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = getshort(fp);
|
||||
length ++;
|
||||
for (i = 0; i < count; i ++, row ++, xsize --)
|
||||
*row = ch;
|
||||
}
|
||||
}
|
||||
|
||||
return (xsize > 0 ? -1 : length * 2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'write_rle8()' - Write 8-bit RLE data.
|
||||
*/
|
||||
|
||||
static int
|
||||
write_rle8(FILE *fp, /* I - File to write to */
|
||||
unsigned short *row, /* I - Data */
|
||||
int xsize)/* I - Width of data in pixels */
|
||||
{
|
||||
int length,
|
||||
count,
|
||||
i,
|
||||
x;
|
||||
unsigned short *start,
|
||||
repeat;
|
||||
|
||||
|
||||
for (x = xsize, length = 0; x > 0;)
|
||||
{
|
||||
start = row;
|
||||
row += 2;
|
||||
x -= 2;
|
||||
|
||||
while (x > 0 && (row[-2] != row[-1] || row[-1] != row[0]))
|
||||
{
|
||||
row ++;
|
||||
x --;
|
||||
}
|
||||
|
||||
row -= 2;
|
||||
x += 2;
|
||||
|
||||
count = row - start;
|
||||
while (count > 0)
|
||||
{
|
||||
i = count > 126 ? 126 : count;
|
||||
count -= i;
|
||||
|
||||
if (putc(128 | i, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
if (putc(*start, fp) == EOF)
|
||||
return (-1);
|
||||
start ++;
|
||||
i --;
|
||||
length ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (x <= 0)
|
||||
break;
|
||||
|
||||
start = row;
|
||||
repeat = row[0];
|
||||
|
||||
row ++;
|
||||
x --;
|
||||
|
||||
while (x > 0 && *row == repeat)
|
||||
{
|
||||
row ++;
|
||||
x --;
|
||||
}
|
||||
|
||||
count = row - start;
|
||||
while (count > 0)
|
||||
{
|
||||
i = count > 126 ? 126 : count;
|
||||
count -= i;
|
||||
|
||||
if (putc(i, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
if (putc(repeat, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
}
|
||||
}
|
||||
|
||||
length ++;
|
||||
|
||||
if (putc(0, fp) == EOF)
|
||||
return (-1);
|
||||
else
|
||||
return (length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'write_rle16()' - Write 16-bit RLE data.
|
||||
*/
|
||||
|
||||
static int
|
||||
write_rle16(FILE *fp, /* I - File to write to */
|
||||
unsigned short *row, /* I - Data */
|
||||
int xsize)/* I - Width of data in pixels */
|
||||
{
|
||||
int length,
|
||||
count,
|
||||
i,
|
||||
x;
|
||||
unsigned short *start,
|
||||
repeat;
|
||||
|
||||
|
||||
for (x = xsize, length = 0; x > 0;)
|
||||
{
|
||||
start = row;
|
||||
row += 2;
|
||||
x -= 2;
|
||||
|
||||
while (x > 0 && (row[-2] != row[-1] || row[-1] != row[0]))
|
||||
{
|
||||
row ++;
|
||||
x --;
|
||||
}
|
||||
|
||||
row -= 2;
|
||||
x += 2;
|
||||
|
||||
count = row - start;
|
||||
while (count > 0)
|
||||
{
|
||||
i = count > 126 ? 126 : count;
|
||||
count -= i;
|
||||
|
||||
if (putshort(128 | i, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
if (putshort(*start, fp) == EOF)
|
||||
return (-1);
|
||||
start ++;
|
||||
i --;
|
||||
length ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (x <= 0)
|
||||
break;
|
||||
|
||||
start = row;
|
||||
repeat = row[0];
|
||||
|
||||
row ++;
|
||||
x --;
|
||||
|
||||
while (x > 0 && *row == repeat)
|
||||
{
|
||||
row ++;
|
||||
x --;
|
||||
}
|
||||
|
||||
count = row - start;
|
||||
while (count > 0)
|
||||
{
|
||||
i = count > 126 ? 126 : count;
|
||||
count -= i;
|
||||
|
||||
if (putshort(i, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
|
||||
if (putshort(repeat, fp) == EOF)
|
||||
return (-1);
|
||||
length ++;
|
||||
}
|
||||
}
|
||||
|
||||
length ++;
|
||||
|
||||
if (putshort(0, fp) == EOF)
|
||||
return (-1);
|
||||
else
|
||||
return (2 * length);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,376 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Sun Raster image file routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageReadSunRaster() - Read a SunRaster image file.
|
||||
* read_unsigned() - Read a 32-bit unsigned integer.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
|
||||
#define RAS_MAGIC 0x59a66a95
|
||||
|
||||
/* Sun supported ras_type's */
|
||||
#define RT_OLD 0 /* Raw pixrect image in 68000 byte order */
|
||||
#define RT_STANDARD 1 /* Raw pixrect image in 68000 byte order */
|
||||
#define RT_BYTE_ENCODED 2 /* Run-length compression of bytes */
|
||||
#define RT_FORMAT_RGB 3 /* XRGB or RGB instead of XBGR or BGR */
|
||||
#define RT_EXPERIMENTAL 0xffff /* Reserved for testing */
|
||||
|
||||
/* Sun registered ras_maptype's */
|
||||
#define RMT_RAW 2
|
||||
/* Sun supported ras_maptype's */
|
||||
#define RMT_NONE 0 /* ras_maplength is expected to be 0 */
|
||||
#define RMT_EQUAL_RGB 1 /* red[ras_maplength/3],green[],blue[] */
|
||||
|
||||
#define RAS_RLE 0x80
|
||||
|
||||
/*
|
||||
* NOTES:
|
||||
* Each line of the image is rounded out to a multiple of 16 bits.
|
||||
* This corresponds to the rounding convention used by the memory pixrect
|
||||
* package (/usr/include/pixrect/memvar.h) of the SunWindows system.
|
||||
* The ras_encoding field (always set to 0 by Sun's supported software)
|
||||
* was renamed to ras_length in release 2.0. As a result, rasterfiles
|
||||
* of type 0 generated by the old software claim to have 0 length; for
|
||||
* compatibility, code reading rasterfiles must be prepared to compute the
|
||||
* true length from the width, height, and depth fields.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static unsigned read_unsigned(FILE *fp);
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageReadSunRaster()' - Read a SunRaster image file.
|
||||
*/
|
||||
|
||||
int /* O - Read status */
|
||||
ImageReadSunRaster(image_t *img, /* IO - Image */
|
||||
FILE *fp, /* I - Image file */
|
||||
int primary, /* I - Primary choice for colorspace */
|
||||
int secondary,/* I - Secondary choice for colorspace */
|
||||
int saturation,/* I - Color saturation (%) */
|
||||
int hue, /* I - Color hue (degrees) */
|
||||
const ib_t *lut) /* I - Lookup table for gamma/brightness */
|
||||
{
|
||||
int i, x, y,
|
||||
bpp, /* Bytes per pixel */
|
||||
scanwidth,
|
||||
run_count,
|
||||
run_value;
|
||||
ib_t *in,
|
||||
*out,
|
||||
*scanline,
|
||||
*scanptr,
|
||||
*p,
|
||||
bit;
|
||||
unsigned ras_depth, /* depth (1, 8, or 24 bits) of pixel */
|
||||
ras_type, /* type of file; see RT_* below */
|
||||
ras_maplength; /* length (bytes) of following map */
|
||||
unsigned char cmap[3][256]; /* colormap */
|
||||
|
||||
|
||||
/*
|
||||
* Read the header; we already know that this is a raster file (ImageOpen
|
||||
* checks this) so we don't need to check the magic number again.
|
||||
*/
|
||||
|
||||
read_unsigned(fp); /* Skip magic */
|
||||
img->xsize = read_unsigned(fp);
|
||||
img->ysize = read_unsigned(fp);
|
||||
ras_depth = read_unsigned(fp);
|
||||
/* ras_length */read_unsigned(fp);
|
||||
ras_type = read_unsigned(fp);
|
||||
/* ras_maptype*/read_unsigned(fp);
|
||||
ras_maplength = read_unsigned(fp);
|
||||
|
||||
if (ras_maplength > 0)
|
||||
{
|
||||
fread(cmap[0], 1, ras_maplength / 3, fp);
|
||||
fread(cmap[1], 1, ras_maplength / 3, fp);
|
||||
fread(cmap[2], 1, ras_maplength / 3, fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the width of each line and allocate memory as needed...
|
||||
*/
|
||||
|
||||
scanwidth = (img->xsize * ras_depth + 7) / 8;
|
||||
if (scanwidth & 1)
|
||||
scanwidth ++;
|
||||
|
||||
if (ras_depth < 24 && ras_maplength == 0)
|
||||
{
|
||||
img->colorspace = secondary;
|
||||
in = malloc(img->xsize + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
img->colorspace = primary;
|
||||
in = malloc(img->xsize * 3 + 1);
|
||||
}
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
out = malloc(img->xsize * bpp);
|
||||
scanline = malloc(scanwidth);
|
||||
run_count = 0;
|
||||
|
||||
for (y = 0; y < img->ysize; y ++)
|
||||
{
|
||||
if (ras_depth != 8 || ras_maplength > 0)
|
||||
p = scanline;
|
||||
else
|
||||
p = in;
|
||||
|
||||
if (ras_type != RT_BYTE_ENCODED)
|
||||
fread(p, scanwidth, 1, fp);
|
||||
else
|
||||
{
|
||||
for (i = scanwidth; i > 0; i --, p ++)
|
||||
{
|
||||
if (run_count > 0)
|
||||
{
|
||||
*p = run_value;
|
||||
run_count --;
|
||||
}
|
||||
else
|
||||
{
|
||||
run_value = getc(fp);
|
||||
|
||||
if (run_value == RAS_RLE)
|
||||
{
|
||||
run_count = getc(fp);
|
||||
if (run_count == 0)
|
||||
*p = RAS_RLE;
|
||||
else
|
||||
run_value = *p = getc(fp);
|
||||
}
|
||||
else
|
||||
*p = run_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ras_depth == 1 && ras_maplength == 0)
|
||||
{
|
||||
/*
|
||||
* 1-bit B&W image...
|
||||
*/
|
||||
|
||||
for (x = img->xsize, bit = 128, scanptr = scanline, p = in;
|
||||
x > 0;
|
||||
x --, p ++)
|
||||
{
|
||||
if (*scanptr & bit)
|
||||
*p = 255;
|
||||
else
|
||||
*p = 0;
|
||||
|
||||
if (bit > 1)
|
||||
{
|
||||
bit = 128;
|
||||
scanptr ++;
|
||||
}
|
||||
else
|
||||
bit >>= 1;
|
||||
}
|
||||
}
|
||||
else if (ras_depth == 1)
|
||||
{
|
||||
/*
|
||||
* 1-bit colormapped image...
|
||||
*/
|
||||
|
||||
for (x = img->xsize, bit = 128, scanptr = scanline, p = in;
|
||||
x > 0;
|
||||
x --)
|
||||
{
|
||||
if (*scanptr & bit)
|
||||
{
|
||||
*p++ = cmap[0][1];
|
||||
*p++ = cmap[1][1];
|
||||
*p++ = cmap[2][1];
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = cmap[0][0];
|
||||
*p++ = cmap[1][0];
|
||||
*p++ = cmap[2][0];
|
||||
}
|
||||
|
||||
if (bit > 1)
|
||||
{
|
||||
bit = 128;
|
||||
scanptr ++;
|
||||
}
|
||||
else
|
||||
bit >>= 1;
|
||||
}
|
||||
}
|
||||
else if (ras_depth == 8 && ras_maplength > 0)
|
||||
{
|
||||
/*
|
||||
* 8-bit colormapped image.
|
||||
*/
|
||||
|
||||
for (x = img->xsize, scanptr = scanline, p = in;
|
||||
x > 0;
|
||||
x --)
|
||||
{
|
||||
*p++ = cmap[0][*scanptr];
|
||||
*p++ = cmap[1][*scanptr];
|
||||
*p++ = cmap[2][*scanptr++];
|
||||
}
|
||||
}
|
||||
else if (ras_depth == 24 && ras_type != RT_FORMAT_RGB)
|
||||
{
|
||||
/*
|
||||
* Convert BGR to RGB...
|
||||
*/
|
||||
|
||||
for (x = img->xsize, scanptr = scanline, p = in;
|
||||
x > 0;
|
||||
x --, scanptr += 3)
|
||||
{
|
||||
*p++ = scanptr[2];
|
||||
*p++ = scanptr[1];
|
||||
*p++ = scanptr[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (bpp == 1)
|
||||
{
|
||||
if (img->colorspace == IMAGE_WHITE)
|
||||
{
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_RGB :
|
||||
ImageWhiteToRGB(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageWhiteToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageWhiteToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageWhiteToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (img->colorspace == IMAGE_RGB)
|
||||
{
|
||||
if (saturation != 100 || hue != 0)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
if (lut)
|
||||
ImageLut(in, img->xsize * 3, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, in);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((saturation != 100 || hue != 0) && bpp > 1)
|
||||
ImageRGBAdjust(in, img->xsize, saturation, hue);
|
||||
|
||||
switch (img->colorspace)
|
||||
{
|
||||
case IMAGE_WHITE :
|
||||
ImageRGBToWhite(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_BLACK :
|
||||
ImageRGBToBlack(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMY :
|
||||
ImageRGBToCMY(in, out, img->xsize);
|
||||
break;
|
||||
case IMAGE_CMYK :
|
||||
ImageRGBToCMYK(in, out, img->xsize);
|
||||
break;
|
||||
}
|
||||
|
||||
if (lut)
|
||||
ImageLut(out, img->xsize * bpp, lut);
|
||||
|
||||
ImagePutRow(img, 0, y, img->xsize, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(scanline);
|
||||
free(in);
|
||||
free(out);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'read_unsigned()' - Read a 32-bit unsigned integer.
|
||||
*/
|
||||
|
||||
static unsigned /* O - Integer from file */
|
||||
read_unsigned(FILE *fp) /* I - File to read from */
|
||||
{
|
||||
unsigned v; /* Integer from file */
|
||||
|
||||
|
||||
v = getc(fp);
|
||||
v = (v << 8) | getc(fp);
|
||||
v = (v << 8) | getc(fp);
|
||||
v = (v << 8) | getc(fp);
|
||||
|
||||
return (v);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,310 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Image zoom routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageZoomAlloc() - Allocate a pixel zoom record...
|
||||
* ImageZoomFill() - Fill a zoom record with image data utilizing bilinear
|
||||
* interpolation.
|
||||
* ImageZoomQFill() - Fill a zoom record quickly using nearest-neighbor
|
||||
* sampling.
|
||||
* ImageZoomFree() - Free a zoom record...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
|
||||
|
||||
/*
|
||||
* 'ZoomAlloc()' - Allocate a pixel zoom record...
|
||||
*/
|
||||
|
||||
izoom_t *
|
||||
ImageZoomAlloc(image_t *img, /* I - Image to zoom */
|
||||
int x0, /* I - Upper-lefthand corner */
|
||||
int y0, /* I - ... */
|
||||
int x1, /* I - Lower-righthand corner */
|
||||
int y1, /* I - ... */
|
||||
int xsize, /* I - Final width of image */
|
||||
int ysize, /* I - Final height of image */
|
||||
int rotated) /* I - Non-zero if image is rotated 90 degs */
|
||||
{
|
||||
izoom_t *z; /* New zoom record */
|
||||
|
||||
|
||||
if ((z = (izoom_t *)calloc(1, sizeof(izoom_t))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
z->img = img;
|
||||
z->row = 0;
|
||||
z->depth = ImageGetDepth(img);
|
||||
z->rotated = rotated;
|
||||
|
||||
if (rotated)
|
||||
{
|
||||
z->xorig = x1;
|
||||
z->yorig = y0;
|
||||
z->width = y1 - y0 + 1;
|
||||
z->height = x1 - x0 + 1;
|
||||
z->xsize = xsize;
|
||||
z->ysize = ysize;
|
||||
z->xmod = z->width % z->xsize;
|
||||
z->xstep = z->width / z->xsize;
|
||||
z->xincr = 1;
|
||||
z->ymod = z->height % z->ysize;
|
||||
z->ystep = z->height / z->ysize;
|
||||
z->yincr = 1;
|
||||
z->instep = z->xstep * z->depth;
|
||||
z->inincr = z->xincr * z->depth;
|
||||
|
||||
if (z->width < img->ysize)
|
||||
z->xmax = z->width;
|
||||
else
|
||||
z->xmax = z->width - 1;
|
||||
|
||||
if (z->height < img->xsize)
|
||||
z->ymax = z->height;
|
||||
else
|
||||
z->ymax = z->height - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
z->xorig = x0;
|
||||
z->yorig = y0;
|
||||
z->width = x1 - x0 + 1;
|
||||
z->height = y1 - y0 + 1;
|
||||
z->xsize = xsize;
|
||||
z->ysize = ysize;
|
||||
z->xmod = z->width % z->xsize;
|
||||
z->xstep = z->width / z->xsize;
|
||||
z->xincr = 1;
|
||||
z->ymod = z->height % z->ysize;
|
||||
z->ystep = z->height / z->ysize;
|
||||
z->yincr = 1;
|
||||
z->instep = z->xstep * z->depth;
|
||||
z->inincr = z->xincr * z->depth;
|
||||
|
||||
if (z->width < img->xsize)
|
||||
z->xmax = z->width;
|
||||
else
|
||||
z->xmax = z->width - 1;
|
||||
|
||||
if (z->height < img->ysize)
|
||||
z->ymax = z->height;
|
||||
else
|
||||
z->ymax = z->height - 1;
|
||||
}
|
||||
|
||||
if ((z->rows[0] = (ib_t *)malloc(z->xsize * z->depth)) == NULL)
|
||||
{
|
||||
free(z);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((z->rows[1] = (ib_t *)malloc(z->xsize * z->depth)) == NULL)
|
||||
{
|
||||
free(z->rows[0]);
|
||||
free(z);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if ((z->in = (ib_t *)malloc(z->width * z->depth)) == NULL)
|
||||
{
|
||||
free(z->rows[0]);
|
||||
free(z->rows[1]);
|
||||
free(z);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (z);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageZoomFill()' - Fill a zoom record with image data utilizing bilinear
|
||||
* interpolation.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageZoomFill(izoom_t *z, /* I - Zoom record to fill */
|
||||
int iy) /* I - Zoom image row */
|
||||
{
|
||||
ib_t *r, /* Row pointer */
|
||||
*inptr; /* Pixel pointer */
|
||||
int xerr0, /* X error counter */
|
||||
xerr1; /* ... */
|
||||
int ix,
|
||||
x,
|
||||
count,
|
||||
z_depth,
|
||||
z_xstep,
|
||||
z_xincr,
|
||||
z_instep,
|
||||
z_inincr,
|
||||
z_xmax,
|
||||
z_xmod,
|
||||
z_xsize;
|
||||
|
||||
|
||||
if (iy > z->ymax)
|
||||
iy = z->ymax;
|
||||
|
||||
z->row ^= 1;
|
||||
|
||||
z_depth = z->depth;
|
||||
z_xsize = z->xsize;
|
||||
z_xmax = z->xmax;
|
||||
z_xmod = z->xmod;
|
||||
z_xstep = z->xstep;
|
||||
z_xincr = z->xincr;
|
||||
z_instep = z->instep;
|
||||
z_inincr = z->inincr;
|
||||
|
||||
if (z->rotated)
|
||||
ImageGetCol(z->img, z->xorig - iy, z->yorig, z->width, z->in);
|
||||
else
|
||||
ImageGetRow(z->img, z->xorig, z->yorig + iy, z->width, z->in);
|
||||
|
||||
if (z_inincr < 0)
|
||||
inptr = z->in + (z->width - 1) * z_depth;
|
||||
else
|
||||
inptr = z->in;
|
||||
|
||||
for (x = z_xsize, xerr0 = z_xsize, xerr1 = 0, ix = 0, r = z->rows[z->row];
|
||||
x > 0;
|
||||
x --)
|
||||
{
|
||||
if (ix < z_xmax)
|
||||
{
|
||||
for (count = 0; count < z_depth; count ++)
|
||||
*r++ = (inptr[count] * xerr0 + inptr[z_depth + count] * xerr1) / z_xsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (count = 0; count < z_depth; count ++)
|
||||
*r++ = inptr[count];
|
||||
}
|
||||
|
||||
ix += z_xstep;
|
||||
inptr += z_instep;
|
||||
xerr0 -= z_xmod;
|
||||
xerr1 += z_xmod;
|
||||
|
||||
if (xerr0 <= 0)
|
||||
{
|
||||
xerr0 += z_xsize;
|
||||
xerr1 -= z_xsize;
|
||||
ix += z_xincr;
|
||||
inptr += z_inincr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageZoomQFill()' - Fill a zoom record quickly using nearest-neighbor sampling.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageZoomQFill(izoom_t *z, /* I - Zoom record to fill */
|
||||
int iy) /* I - Zoom image row */
|
||||
{
|
||||
ib_t *r, /* Row pointer */
|
||||
*inptr; /* Pixel pointer */
|
||||
int xerr0; /* X error counter */
|
||||
int ix,
|
||||
x,
|
||||
count,
|
||||
z_depth,
|
||||
z_xstep,
|
||||
z_xincr,
|
||||
z_instep,
|
||||
z_inincr,
|
||||
z_xmod,
|
||||
z_xsize;
|
||||
|
||||
|
||||
if (iy > z->ymax)
|
||||
iy = z->ymax;
|
||||
|
||||
z->row ^= 1;
|
||||
|
||||
z_depth = z->depth;
|
||||
z_xsize = z->xsize;
|
||||
z_xmod = z->xmod;
|
||||
z_xstep = z->xstep;
|
||||
z_xincr = z->xincr;
|
||||
z_instep = z->instep;
|
||||
z_inincr = z->inincr;
|
||||
|
||||
if (z->rotated)
|
||||
ImageGetCol(z->img, z->xorig - iy, z->yorig, z->width, z->in);
|
||||
else
|
||||
ImageGetRow(z->img, z->xorig, z->yorig + iy, z->width, z->in);
|
||||
|
||||
if (z_inincr < 0)
|
||||
inptr = z->in + (z->width - 1) * z_depth;
|
||||
else
|
||||
inptr = z->in;
|
||||
|
||||
for (x = z_xsize, xerr0 = z_xsize, ix = 0, r = z->rows[z->row];
|
||||
x > 0;
|
||||
x --)
|
||||
{
|
||||
for (count = 0; count < z_depth; count ++)
|
||||
*r++ = inptr[count];
|
||||
|
||||
ix += z_xstep;
|
||||
inptr += z_instep;
|
||||
xerr0 -= z_xmod;
|
||||
|
||||
if (xerr0 <= 0)
|
||||
{
|
||||
xerr0 += z_xsize;
|
||||
ix += z_xincr;
|
||||
inptr += z_inincr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageZoomFree()' - Free a zoom record...
|
||||
*/
|
||||
|
||||
void
|
||||
ImageZoomFree(izoom_t *z) /* I - Zoom record to free */
|
||||
{
|
||||
free(z->rows[0]);
|
||||
free(z->rows[1]);
|
||||
free(z->in);
|
||||
free(z);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,760 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Base image support for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* ImageOpen() - Open an image file and read it into memory.
|
||||
* ImageClose() - Close an image file.
|
||||
* ImageSetMaxTiles() - Set the maximum number of tiles to cache.
|
||||
* ImageSetProfile() - Set the device color profile.
|
||||
* ImageGetCol() - Get a column of pixels from an image.
|
||||
* ImageGetRow() - Get a row of pixels from an image.
|
||||
* ImagePutCol() - Put a column of pixels to an image.
|
||||
* ImagePutRow() - Put a row of pixels to an image.
|
||||
* get_tile() - Get a cached tile.
|
||||
* flush_tile() - Flush the least-recently-used tile in the cache.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "image.h"
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
int ImageHaveProfile = 0; /* Do we have a color profile? */
|
||||
int ImageDensity[256]; /* Ink/marker density LUT */
|
||||
int ImageMatrix[3][3][256]; /* Color transform matrix LUT */
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static ib_t *get_tile(image_t *img, int x, int y);
|
||||
static void flush_tile(image_t *img);
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageOpen()' - Open an image file and read it into memory.
|
||||
*/
|
||||
|
||||
image_t * /* O - New image */
|
||||
ImageOpen(char *filename, /* I - Filename of image */
|
||||
int primary, /* I - Primary colorspace needed */
|
||||
int secondary, /* I - Secondary colorspace if primary no good */
|
||||
int saturation,/* I - Color saturation level */
|
||||
int hue, /* I - Color hue adjustment */
|
||||
const ib_t *lut) /* I - RGB gamma/brightness LUT */
|
||||
{
|
||||
FILE *fp; /* File pointer */
|
||||
unsigned char header[16], /* First 16 bytes of file */
|
||||
header2[16]; /* Bytes 2048-2064 (PhotoCD) */
|
||||
image_t *img; /* New image buffer */
|
||||
int status; /* Status of load... */
|
||||
|
||||
|
||||
/*
|
||||
* Range check...
|
||||
*/
|
||||
|
||||
if (filename == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Figure out the file type...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(filename, "r")) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (fread(header, 1, sizeof(header), fp) == 0)
|
||||
{
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
fseek(fp, 2048, SEEK_SET);
|
||||
memset(header2, 0, sizeof(header2));
|
||||
fread(header2, 1, sizeof(header2), fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
lseek(fileno(fp), 0, SEEK_SET); /* Avoid standard C library bugs */
|
||||
|
||||
/*
|
||||
* Allocate memory...
|
||||
*/
|
||||
|
||||
img = calloc(sizeof(image_t), 1);
|
||||
|
||||
if (img == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the image as appropriate...
|
||||
*/
|
||||
|
||||
img->max_ics = TILE_MINIMUM;
|
||||
img->xppi = 128;
|
||||
img->yppi = 128;
|
||||
|
||||
if (memcmp(header, "GIF87a", 6) == 0 ||
|
||||
memcmp(header, "GIF89a", 6) == 0)
|
||||
status = ImageReadGIF(img, fp, primary, secondary, saturation, hue, lut);
|
||||
else if (header[0] == 0x01 && header[1] == 0xda)
|
||||
status = ImageReadSGI(img, fp, primary, secondary, saturation, hue, lut);
|
||||
else if (header[0] == 0x59 && header[1] == 0xa6 &&
|
||||
header[2] == 0x6a && header[3] == 0x95)
|
||||
status = ImageReadSunRaster(img, fp, primary, secondary, saturation, hue, lut);
|
||||
else if (header[0] == 'P' && header[1] >= '1' && header[1] <= '6')
|
||||
status = ImageReadPNM(img, fp, primary, secondary, saturation, hue, lut);
|
||||
else if (memcmp(header2, "PCD_IPI", 7) == 0)
|
||||
status = ImageReadPhotoCD(img, fp, primary, secondary, saturation, hue, lut);
|
||||
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
||||
else if (memcmp(header, "\211PNG", 4) == 0)
|
||||
status = ImageReadPNG(img, fp, primary, secondary, saturation, hue, lut);
|
||||
#endif /* HAVE_LIBPNG && HAVE_LIBZ */
|
||||
#ifdef HAVE_LIBJPEG
|
||||
else if (memcmp(header + 6, "JFIF", 4) == 0)
|
||||
status = ImageReadJPEG(img, fp, primary, secondary, saturation, hue, lut);
|
||||
#endif /* HAVE_LIBJPEG */
|
||||
#ifdef HAVE_LIBTIFF
|
||||
else if (memcmp(header, "MM", 2) == 0 ||
|
||||
memcmp(header, "II", 2) == 0)
|
||||
status = ImageReadTIFF(img, fp, primary, secondary, saturation, hue, lut);
|
||||
#endif /* HAVE_LIBTIFF */
|
||||
else
|
||||
{
|
||||
fclose(fp);
|
||||
status = -1;
|
||||
}
|
||||
|
||||
if (status)
|
||||
{
|
||||
free(img);
|
||||
return (NULL);
|
||||
}
|
||||
else
|
||||
return (img);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageClose()' - Close an image file.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageClose(image_t *img) /* I - Image to close */
|
||||
{
|
||||
ic_t *current, /* Current cached tile */
|
||||
*next; /* Next cached tile */
|
||||
|
||||
|
||||
/*
|
||||
* Wipe the tile cache file (if any)...
|
||||
*/
|
||||
|
||||
if (img->cachefile != NULL)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: Closing and removing swap file \"%s\"...\n",
|
||||
img->cachename);
|
||||
|
||||
fclose(img->cachefile);
|
||||
unlink(img->cachename);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the image cache...
|
||||
*/
|
||||
|
||||
fputs("DEBUG: Freeing memory...\n", stderr);
|
||||
|
||||
for (current = img->first; current != NULL; current = next)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: Freeing cache (%08lx, next = %08lx)...\n",
|
||||
current, next);
|
||||
|
||||
next = current->next;
|
||||
free(current);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the rest of memory...
|
||||
*/
|
||||
|
||||
if (img->tiles != NULL)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: Freeing tiles (%08lx)...\n", img->tiles[0]);
|
||||
|
||||
free(img->tiles[0]);
|
||||
|
||||
fprintf(stderr, "DEBUG: Freeing tile pointers (%08lx)...\n", img->tiles);
|
||||
|
||||
free(img->tiles);
|
||||
}
|
||||
|
||||
free(img);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageSetMaxTiles()' - Set the maximum number of tiles to cache.
|
||||
*
|
||||
* If the "max_tiles" argument is 0 then the maximum number of tiles is
|
||||
* computed from the image size or the RIP_CACHE environment variable.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageSetMaxTiles(image_t *img, /* I - Image to set */
|
||||
int max_tiles) /* I - Number of tiles to cache */
|
||||
{
|
||||
int cache_size, /* Size of tile cache in bytes */
|
||||
min_tiles, /* Minimum number of tiles to cache */
|
||||
max_size; /* Maximum cache size in bytes */
|
||||
char *cache_env, /* Cache size environment variable */
|
||||
cache_units[255]; /* Cache size units */
|
||||
|
||||
|
||||
min_tiles = max(TILE_MINIMUM,
|
||||
1 + max((img->xsize + TILE_SIZE - 1) / TILE_SIZE,
|
||||
(img->ysize + TILE_SIZE - 1) / TILE_SIZE));
|
||||
|
||||
if (max_tiles == 0)
|
||||
max_tiles = ((img->xsize + TILE_SIZE - 1) / TILE_SIZE) *
|
||||
((img->ysize + TILE_SIZE - 1) / TILE_SIZE);
|
||||
|
||||
cache_size = max_tiles * TILE_SIZE * TILE_SIZE * ImageGetDepth(img);
|
||||
|
||||
if ((cache_env = getenv("RIP_MAX_CACHE")) != NULL)
|
||||
{
|
||||
switch (sscanf(cache_env, "%d%s", &max_size, cache_units))
|
||||
{
|
||||
case 0 :
|
||||
max_size = 32 * 1024 * 1024;
|
||||
break;
|
||||
case 1 :
|
||||
max_size *= 4 * TILE_SIZE * TILE_SIZE;
|
||||
break;
|
||||
case 2 :
|
||||
if (tolower(cache_units[0]) == 'g')
|
||||
max_size *= 1024 * 1024 * 1024;
|
||||
else if (tolower(cache_units[0]) == 'm')
|
||||
max_size *= 1024 * 1024;
|
||||
else if (tolower(cache_units[0]) == 'k')
|
||||
max_size *= 1024;
|
||||
else if (tolower(cache_units[0]) == 't')
|
||||
max_size *= 4 * TILE_SIZE * TILE_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
max_size = 32 * 1024 * 1024;
|
||||
|
||||
if (cache_size > max_size)
|
||||
max_tiles = max_size / TILE_SIZE / TILE_SIZE / ImageGetDepth(img);
|
||||
|
||||
if (max_tiles < min_tiles)
|
||||
max_tiles = min_tiles;
|
||||
|
||||
img->max_ics = max_tiles;
|
||||
|
||||
fprintf(stderr, "DEBUG: max_ics=%d...\n", img->max_ics);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageSetProfile()' - Set the device color profile.
|
||||
*/
|
||||
|
||||
void
|
||||
ImageSetProfile(float d, /* I - Ink/marker density */
|
||||
float g, /* I - Ink/marker gamma */
|
||||
float matrix[3][3]) /* I - Color transform matrix */
|
||||
{
|
||||
int i, j, k; /* Looping vars */
|
||||
float m; /* Current matrix value */
|
||||
int *im; /* Pointer into ImageMatrix */
|
||||
|
||||
ImageHaveProfile = 1;
|
||||
|
||||
for (i = 0, im = ImageMatrix[0][0]; i < 3; i ++)
|
||||
for (j = 0; j < 3; j ++)
|
||||
for (k = 0, m = matrix[i][j]; k < 256; k ++)
|
||||
*im++ = (int)(k * m + 0.5);
|
||||
|
||||
for (k = 0, im = ImageDensity; k < 256; k ++)
|
||||
*im++ = 255.0 * d * pow((float)k / 255.0, g) + 0.5;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageGetCol()' - Get a column of pixels from an image.
|
||||
*/
|
||||
|
||||
int /* O - -1 on error, 0 on success */
|
||||
ImageGetCol(image_t *img, /* I - Image */
|
||||
int x, /* I - Column */
|
||||
int y, /* I - Start row */
|
||||
int height, /* I - Column height */
|
||||
ib_t *pixels) /* O - Pixel data */
|
||||
{
|
||||
int bpp, /* Bytes per pixel */
|
||||
twidth, /* Tile width */
|
||||
count; /* Number of pixels to get */
|
||||
const ib_t *ib; /* Pointer into tile */
|
||||
|
||||
|
||||
if (img == NULL || x < 0 || x >= img->xsize || y >= img->ysize)
|
||||
return (-1);
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if ((y + height) > img->ysize)
|
||||
height = img->ysize - y;
|
||||
|
||||
if (height < 1)
|
||||
return (-1);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
twidth = bpp * (TILE_SIZE - 1);
|
||||
|
||||
while (height > 0)
|
||||
{
|
||||
ib = get_tile(img, x, y);
|
||||
|
||||
if (ib == NULL)
|
||||
return (-1);
|
||||
|
||||
count = TILE_SIZE - (y & (TILE_SIZE - 1));
|
||||
if (count > height)
|
||||
count = height;
|
||||
|
||||
y += count;
|
||||
height -= count;
|
||||
|
||||
for (; count > 0; count --, ib += twidth)
|
||||
switch (bpp)
|
||||
{
|
||||
case 4 :
|
||||
*pixels++ = *ib++;
|
||||
case 3 :
|
||||
*pixels++ = *ib++;
|
||||
*pixels++ = *ib++;
|
||||
case 1 :
|
||||
*pixels++ = *ib++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImageGetRow()' - Get a row of pixels from an image.
|
||||
*/
|
||||
|
||||
int /* O - -1 on error, 0 on success */
|
||||
ImageGetRow(image_t *img, /* I - Image */
|
||||
int x, /* I - Start column */
|
||||
int y, /* I - Row */
|
||||
int width, /* I - Width of row */
|
||||
ib_t *pixels) /* O - Pixel data */
|
||||
{
|
||||
int bpp, /* Bytes per pixel */
|
||||
count; /* Number of pixels to get */
|
||||
const ib_t *ib; /* Pointer to pixels */
|
||||
|
||||
|
||||
if (img == NULL || y < 0 || y >= img->ysize || x >= img->xsize)
|
||||
return (-1);
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if ((x + width) > img->xsize)
|
||||
width = img->xsize - x;
|
||||
|
||||
if (width < 1)
|
||||
return (-1);
|
||||
|
||||
bpp = img->colorspace < 0 ? -img->colorspace : img->colorspace;
|
||||
|
||||
while (width > 0)
|
||||
{
|
||||
ib = get_tile(img, x, y);
|
||||
|
||||
if (ib == NULL)
|
||||
return (-1);
|
||||
|
||||
count = TILE_SIZE - (x & (TILE_SIZE - 1));
|
||||
if (count > width)
|
||||
count = width;
|
||||
memcpy(pixels, ib, count * bpp);
|
||||
pixels += count * bpp;
|
||||
x += count;
|
||||
width -= count;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImagePutCol()' - Put a column of pixels to an image.
|
||||
*/
|
||||
|
||||
int /* O - -1 on error, 0 on success */
|
||||
ImagePutCol(image_t *img, /* I - Image */
|
||||
int x, /* I - Column */
|
||||
int y, /* I - Start row */
|
||||
int height, /* I - Column height */
|
||||
const ib_t *pixels) /* I - Pixels to put */
|
||||
{
|
||||
int bpp, /* Bytes per pixel */
|
||||
twidth, /* Width of tile */
|
||||
count; /* Number of pixels to put */
|
||||
int tilex, /* Column within tile */
|
||||
tiley; /* Row within tile */
|
||||
ib_t *ib; /* Pointer to pixels in tile */
|
||||
|
||||
|
||||
if (img == NULL || x < 0 || x >= img->xsize || y >= img->ysize)
|
||||
return (-1);
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if ((y + height) > img->ysize)
|
||||
height = img->ysize - y;
|
||||
|
||||
if (height < 1)
|
||||
return (-1);
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
twidth = bpp * (TILE_SIZE - 1);
|
||||
tilex = x / TILE_SIZE;
|
||||
tiley = y / TILE_SIZE;
|
||||
|
||||
while (height > 0)
|
||||
{
|
||||
ib = get_tile(img, x, y);
|
||||
|
||||
if (ib == NULL)
|
||||
return (-1);
|
||||
|
||||
img->tiles[tiley][tilex].dirty = 1;
|
||||
tiley ++;
|
||||
|
||||
count = TILE_SIZE - (y & (TILE_SIZE - 1));
|
||||
if (count > height)
|
||||
count = height;
|
||||
|
||||
y += count;
|
||||
height -= count;
|
||||
|
||||
for (; count > 0; count --, ib += twidth)
|
||||
switch (bpp)
|
||||
{
|
||||
case 4 :
|
||||
*ib++ = *pixels++;
|
||||
case 3 :
|
||||
*ib++ = *pixels++;
|
||||
*ib++ = *pixels++;
|
||||
case 1 :
|
||||
*ib++ = *pixels++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ImagePutRow()' - Put a row of pixels to an image.
|
||||
*/
|
||||
|
||||
int /* O - -1 on error, 0 on success */
|
||||
ImagePutRow(image_t *img, /* I - Image */
|
||||
int x, /* I - Start column */
|
||||
int y, /* I - Row */
|
||||
int width, /* I - Row width */
|
||||
const ib_t *pixels) /* I - Pixel data */
|
||||
{
|
||||
int bpp, /* Bytes per pixel */
|
||||
count; /* Number of pixels to put */
|
||||
int tilex, /* Column within tile */
|
||||
tiley; /* Row within tile */
|
||||
ib_t *ib; /* Pointer to pixels in tile */
|
||||
|
||||
|
||||
if (img == NULL || y < 0 || y >= img->ysize || x >= img->xsize)
|
||||
return (-1);
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if ((x + width) > img->xsize)
|
||||
width = img->xsize - x;
|
||||
|
||||
if (width < 1)
|
||||
return (-1);
|
||||
|
||||
bpp = img->colorspace < 0 ? -img->colorspace : img->colorspace;
|
||||
tilex = x / TILE_SIZE;
|
||||
tiley = y / TILE_SIZE;
|
||||
|
||||
while (width > 0)
|
||||
{
|
||||
ib = get_tile(img, x, y);
|
||||
|
||||
if (ib == NULL)
|
||||
return (-1);
|
||||
|
||||
img->tiles[tiley][tilex].dirty = 1;
|
||||
|
||||
count = TILE_SIZE - (x & (TILE_SIZE - 1));
|
||||
if (count > width)
|
||||
count = width;
|
||||
memcpy(ib, pixels, count * bpp);
|
||||
pixels += count * bpp;
|
||||
x += count;
|
||||
width -= count;
|
||||
tilex ++;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'get_tile()' - Get a cached tile.
|
||||
*/
|
||||
|
||||
static ib_t * /* O - Pointer to tile or NULL */
|
||||
get_tile(image_t *img, /* I - Image */
|
||||
int x, /* I - Column in image */
|
||||
int y) /* I - Row in image */
|
||||
{
|
||||
int bpp, /* Bytes per pixel */
|
||||
tilex, /* Column within tile */
|
||||
tiley, /* Row within tile */
|
||||
xtiles, /* Number of tiles horizontally */
|
||||
ytiles; /* Number of tiles vertically */
|
||||
ic_t *ic; /* Cache pointer */
|
||||
itile_t *tile; /* Tile pointer */
|
||||
|
||||
|
||||
if (x >= img->xsize || y >= img->ysize)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Internal image RIP error - %d,%d is outside of %dx%d\n",
|
||||
x, y, img->xsize, img->ysize);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (img->tiles == NULL)
|
||||
{
|
||||
xtiles = (img->xsize + TILE_SIZE - 1) / TILE_SIZE;
|
||||
ytiles = (img->ysize + TILE_SIZE - 1) / TILE_SIZE;
|
||||
|
||||
fprintf(stderr, "DEBUG: Creating tile array (%dx%d)\n", xtiles, ytiles);
|
||||
|
||||
img->tiles = calloc(sizeof(itile_t *), ytiles);
|
||||
tile = calloc(sizeof(itile_t), xtiles * ytiles);
|
||||
|
||||
for (tiley = 0; tiley < ytiles; tiley ++)
|
||||
{
|
||||
img->tiles[tiley] = tile;
|
||||
for (tilex = xtiles; tilex > 0; tilex --, tile ++)
|
||||
tile->pos = -1;
|
||||
}
|
||||
}
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
tilex = x / TILE_SIZE;
|
||||
tiley = y / TILE_SIZE;
|
||||
x &= (TILE_SIZE - 1);
|
||||
y &= (TILE_SIZE - 1);
|
||||
|
||||
tile = img->tiles[tiley] + tilex;
|
||||
|
||||
if ((ic = tile->ic) == NULL)
|
||||
{
|
||||
if (img->num_ics < img->max_ics)
|
||||
{
|
||||
ic = calloc(sizeof(ic_t) + bpp * TILE_SIZE * TILE_SIZE, 1);
|
||||
ic->pixels = ((ib_t *)ic) + sizeof(ic_t);
|
||||
|
||||
img->num_ics ++;
|
||||
|
||||
fprintf(stderr, "DEBUG: Allocated cache tile %d (%08lx)...\n",
|
||||
img->num_ics, ic);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "DEBUG: Flushing old cache tile (%08lx)...\n",
|
||||
img->first);
|
||||
|
||||
flush_tile(img);
|
||||
ic = img->first;
|
||||
}
|
||||
|
||||
ic->tile = tile;
|
||||
tile->ic = ic;
|
||||
|
||||
if (tile->pos >= 0)
|
||||
{
|
||||
fprintf(stderr, "DEBUG: Loading cache tile from file position %d...\n",
|
||||
tile->pos);
|
||||
|
||||
if (ftell(img->cachefile) != tile->pos)
|
||||
if (fseek(img->cachefile, tile->pos, SEEK_SET))
|
||||
perror("get_tile:");
|
||||
|
||||
fread(ic->pixels, bpp, TILE_SIZE * TILE_SIZE, img->cachefile);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs("DEBUG: Clearing cache tile...\n", stderr);
|
||||
|
||||
memset(ic->pixels, 0, bpp * TILE_SIZE * TILE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
if (ic == img->first)
|
||||
img->first = ic->next;
|
||||
else if (img->first == NULL)
|
||||
img->first = ic;
|
||||
|
||||
if (ic != img->last)
|
||||
{
|
||||
if (img->last != NULL)
|
||||
img->last->next = ic;
|
||||
|
||||
ic->prev = img->last;
|
||||
img->last = ic;
|
||||
}
|
||||
|
||||
ic->next = NULL;
|
||||
|
||||
return (ic->pixels + bpp * (y * TILE_SIZE + x));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'flush_tile()' - Flush the least-recently-used tile in the cache.
|
||||
*/
|
||||
|
||||
static void
|
||||
flush_tile(image_t *img) /* I - Image */
|
||||
{
|
||||
int bpp; /* Bytes per pixel */
|
||||
itile_t *tile; /* Pointer to tile */
|
||||
|
||||
|
||||
|
||||
bpp = ImageGetDepth(img);
|
||||
tile = img->first->tile;
|
||||
|
||||
if (!tile->dirty)
|
||||
{
|
||||
tile->ic = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (img->cachefile == NULL)
|
||||
{
|
||||
cupsTempFile(img->cachename, sizeof(img->cachename));
|
||||
|
||||
fprintf(stderr, "DEBUG: Creating swap file \"%s\"...\n", img->cachename);
|
||||
|
||||
if ((img->cachefile = fopen(img->cachename, "wb+")) == NULL)
|
||||
{
|
||||
perror("ERROR: Unable to create image swap file");
|
||||
tile->ic = NULL;
|
||||
tile->dirty = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (tile->pos >= 0)
|
||||
{
|
||||
if (ftell(img->cachefile) != tile->pos)
|
||||
if (fseek(img->cachefile, tile->pos, SEEK_SET))
|
||||
{
|
||||
perror("ERROR: Unable to seek in swap file");
|
||||
tile->ic = NULL;
|
||||
tile->dirty = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fseek(img->cachefile, 0, SEEK_END))
|
||||
{
|
||||
perror("ERROR: Unable to append to swap file");
|
||||
tile->ic = NULL;
|
||||
tile->dirty = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
tile->pos = ftell(img->cachefile);
|
||||
}
|
||||
|
||||
|
||||
if (fwrite(tile->ic->pixels, bpp, TILE_SIZE * TILE_SIZE, img->cachefile) < 1)
|
||||
perror("ERROR: Unable to write tile to swap file");
|
||||
else
|
||||
fprintf(stderr, "DEBUG: Wrote tile at position %d...\n", tile->pos);
|
||||
|
||||
tile->ic = NULL;
|
||||
tile->dirty = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Image library definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
#ifndef _IMAGE_H_
|
||||
# define _IMAGE_H_
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <errno.h>
|
||||
# include <config.h>
|
||||
|
||||
|
||||
/*
|
||||
* Colorspaces...
|
||||
*/
|
||||
|
||||
# define IMAGE_CMYK -4 /* Cyan, magenta, yellow, and black */
|
||||
# define IMAGE_CMY -3 /* Cyan, magenta, and yellow */
|
||||
# define IMAGE_BLACK -1 /* Black */
|
||||
# define IMAGE_WHITE 1 /* White (luminance) */
|
||||
# define IMAGE_RGB 3 /* Red, green, and blue */
|
||||
|
||||
/*
|
||||
* Tile definitions...
|
||||
*/
|
||||
|
||||
# define TILE_SIZE 256 /* 256x256 pixel tiles */
|
||||
# define TILE_MINIMUM 10 /* Minimum number of tiles */
|
||||
|
||||
/*
|
||||
* min/max/abs macros...
|
||||
*/
|
||||
|
||||
#ifndef max
|
||||
# define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif /* !max */
|
||||
#ifndef min
|
||||
# define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif /* !min */
|
||||
#ifndef abs
|
||||
# define abs(a) ((a) < 0 ? -(a) : (a))
|
||||
#endif /* !abs */
|
||||
|
||||
|
||||
/*
|
||||
* Image byte type...
|
||||
*/
|
||||
|
||||
typedef unsigned char ib_t;
|
||||
|
||||
/*
|
||||
* Tile cache structure...
|
||||
*/
|
||||
|
||||
typedef struct ic_str
|
||||
{
|
||||
struct ic_str *prev, /* Previous tile in cache */
|
||||
*next; /* Next tile in cache */
|
||||
void *tile; /* Tile this is attached to */
|
||||
ib_t *pixels; /* Pixel data */
|
||||
} ic_t;
|
||||
|
||||
/*
|
||||
* Tile structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int dirty; /* True if tile is dirty */
|
||||
long pos; /* Position of tile on disk (-1 if not written) */
|
||||
ic_t *ic; /* Pixel data */
|
||||
} itile_t;
|
||||
|
||||
/*
|
||||
* Image structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int colorspace; /* Colorspace of image */
|
||||
unsigned xsize, /* Width of image in pixels */
|
||||
ysize, /* Height of image in pixels */
|
||||
xppi, /* X resolution in pixels-per-inch */
|
||||
yppi, /* Y resolution in pixels-per-inch */
|
||||
num_ics, /* Number of cached tiles */
|
||||
max_ics; /* Maximum number of cached tiles */
|
||||
itile_t **tiles; /* Tiles in image */
|
||||
ic_t *first, /* First cached tile in image */
|
||||
*last; /* Last cached tile in image */
|
||||
FILE *cachefile; /* Tile cache file */
|
||||
char cachename[256]; /* Tile cache filename */
|
||||
} image_t;
|
||||
|
||||
/*
|
||||
* Image row zooming structure...
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
image_t *img; /* Image to zoom */
|
||||
unsigned xorig,
|
||||
yorig,
|
||||
width, /* Width of input area */
|
||||
height, /* Height of input area */
|
||||
depth, /* Number of bytes per pixel */
|
||||
rotated, /* Non-zero if image needs to be rotated */
|
||||
xsize, /* Width of output image */
|
||||
ysize, /* Height of output image */
|
||||
xmax, /* Maximum input image X position */
|
||||
ymax, /* Maximum input image Y position */
|
||||
xmod, /* Threshold for Bresenheim rounding */
|
||||
ymod; /* ... */
|
||||
int xstep, /* Amount to step for each pixel along X */
|
||||
xincr,
|
||||
instep, /* Amount to step pixel pointer along X */
|
||||
inincr,
|
||||
ystep, /* Amount to step for each pixel along Y */
|
||||
yincr,
|
||||
row; /* Current row */
|
||||
ib_t *rows[2], /* Horizontally scaled pixel data */
|
||||
*in; /* Unscaled input pixel data */
|
||||
} izoom_t;
|
||||
|
||||
|
||||
/*
|
||||
* Basic image functions...
|
||||
*/
|
||||
|
||||
extern image_t *ImageOpen(char *filename, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern void ImageClose(image_t *img);
|
||||
extern void ImageSetMaxTiles(image_t *img, int max_tiles);
|
||||
extern void ImageSetProfile(float d, float g, float matrix[3][3]);
|
||||
|
||||
#define ImageGetDepth(img) ((img)->colorspace < 0 ? -(img)->colorspace : (img)->colorspace)
|
||||
extern int ImageGetCol(image_t *img, int x, int y, int height, ib_t *pixels);
|
||||
extern int ImageGetRow(image_t *img, int x, int y, int width, ib_t *pixels);
|
||||
extern int ImagePutCol(image_t *img, int x, int y, int height, const ib_t *pixels);
|
||||
extern int ImagePutRow(image_t *img, int x, int y, int width, const ib_t *pixels);
|
||||
|
||||
/*
|
||||
* File formats...
|
||||
*/
|
||||
|
||||
extern int ImageReadGIF(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern int ImageReadJPEG(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern int ImageReadPNG(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern int ImageReadPNM(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern int ImageReadPhotoCD(image_t *img, FILE *fp, int primary,
|
||||
int secondary, int saturation, int hue,
|
||||
const ib_t *lut);
|
||||
extern int ImageReadSGI(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
extern int ImageReadSunRaster(image_t *img, FILE *fp, int primary,
|
||||
int secondary, int saturation, int hue,
|
||||
const ib_t *lut);
|
||||
extern int ImageReadTIFF(image_t *img, FILE *fp, int primary, int secondary,
|
||||
int saturation, int hue, const ib_t *lut);
|
||||
|
||||
/*
|
||||
* Colorspace conversions...
|
||||
*/
|
||||
|
||||
extern void ImageWhiteToWhite(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageWhiteToRGB(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageWhiteToBlack(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageWhiteToCMY(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageWhiteToCMYK(const ib_t *in, ib_t *out, int count);
|
||||
|
||||
extern void ImageRGBToWhite(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageRGBToRGB(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageRGBToBlack(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageRGBToCMY(const ib_t *in, ib_t *out, int count);
|
||||
extern void ImageRGBToCMYK(const ib_t *in, ib_t *out, int count);
|
||||
|
||||
extern void ImageRGBAdjust(ib_t *pixels, int count, int saturation, int hue);
|
||||
|
||||
extern void ImageLut(ib_t *pixels, int count, const ib_t *lut);
|
||||
|
||||
/*
|
||||
* Image scaling operations...
|
||||
*/
|
||||
|
||||
extern izoom_t *ImageZoomAlloc(image_t *img, int x0, int y0, int x1, int y1,
|
||||
int xsize, int ysize, int rotated);
|
||||
extern void ImageZoomFill(izoom_t *z, int iy);
|
||||
extern void ImageZoomQFill(izoom_t *z, int iy);
|
||||
extern void ImageZoomFree(izoom_t *z);
|
||||
|
||||
|
||||
#endif /* !_IMAGE_H_ */
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,494 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Image file to PostScript filter for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry...
|
||||
* ps_hex() - Print binary data as a series of hexadecimal numbers.
|
||||
* ps_ascii85() - Print binary data as a series of base-85 numbers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "image.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
int Flip = 0, /* Flip/mirror pages */
|
||||
Collate = 0, /* Collate copies? */
|
||||
Copies = 1; /* Number of copies */
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void ps_hex(ib_t *, int);
|
||||
static void ps_ascii85(ib_t *, int, int);
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry...
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
image_t *img; /* Image to print */
|
||||
float xprint, /* Printable area */
|
||||
yprint,
|
||||
xinches, /* Total size in inches */
|
||||
yinches;
|
||||
float xsize, /* Total size in points */
|
||||
ysize;
|
||||
int xpages, /* # x pages */
|
||||
ypages, /* # y pages */
|
||||
xpage, /* Current x page */
|
||||
ypage, /* Current y page */
|
||||
page; /* Current page number */
|
||||
int x0, y0, /* Corners of the page in image coords */
|
||||
x1, y1;
|
||||
ib_t *row; /* Current row */
|
||||
int y; /* Current Y coordinate in image */
|
||||
int colorspace; /* Output colorspace */
|
||||
int out_offset, /* Offset into output buffer */
|
||||
out_length; /* Length of output buffer */
|
||||
ppd_file_t *ppd; /* PPD file */
|
||||
int num_options; /* Number of print options */
|
||||
cups_option_t *options; /* Print options */
|
||||
const char *val; /* Option value */
|
||||
int slowcollate; /* Collate copies the slow way */
|
||||
float g; /* Gamma correction value */
|
||||
float b; /* Brightness factor */
|
||||
float zoom; /* Zoom facter */
|
||||
int ppi; /* Pixels-per-inch */
|
||||
int hue, sat; /* Hue and saturation adjustment */
|
||||
int realcopies; /* Real copies being printed */
|
||||
|
||||
|
||||
if (argc != 7)
|
||||
{
|
||||
fputs("ERROR: imagetops job-id user title copies options file\n", stderr);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process command-line options and write the prolog...
|
||||
*/
|
||||
|
||||
zoom = 0.0;
|
||||
ppi = 0;
|
||||
hue = 0;
|
||||
sat = 100;
|
||||
g = 1.0;
|
||||
b = 1.0;
|
||||
|
||||
Copies = atoi(argv[4]);
|
||||
|
||||
options = NULL;
|
||||
num_options = cupsParseOptions(argv[5], 0, &options);
|
||||
|
||||
ppd = SetCommonOptions(num_options, options, 1);
|
||||
|
||||
ppdMarkDefaults(ppd);
|
||||
cupsMarkOptions(ppd, num_options, options);
|
||||
|
||||
if ((val = cupsGetOption("multiple-document-handling", num_options, options)) != NULL)
|
||||
{
|
||||
/*
|
||||
* This IPP attribute is unnecessarily complicated...
|
||||
*
|
||||
* single-document, separate-documents-collated-copies, and
|
||||
* single-document-new-sheet all require collated copies.
|
||||
*
|
||||
* separate-documents-collated-copies allows for uncollated copies.
|
||||
*/
|
||||
|
||||
Collate = strcmp(val, "separate-documents-collated-copies") != 0;
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("Collate", num_options, options)) != NULL &&
|
||||
strcmp(val, "True") == 0)
|
||||
Collate = 1;
|
||||
|
||||
if ((val = cupsGetOption("gamma", num_options, options)) != NULL)
|
||||
g = atoi(val) * 0.001f;
|
||||
|
||||
if ((val = cupsGetOption("brightness", num_options, options)) != NULL)
|
||||
b = atoi(val) * 0.01f;
|
||||
|
||||
if ((val = cupsGetOption("scaling", num_options, options)) != NULL)
|
||||
zoom = atoi(val) * 0.01;
|
||||
|
||||
if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
|
||||
ppi = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("saturation", num_options, options)) != NULL)
|
||||
sat = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("hue", num_options, options)) != NULL)
|
||||
hue = atoi(val);
|
||||
|
||||
/*
|
||||
* Open the input image to print...
|
||||
*/
|
||||
|
||||
colorspace = ColorDevice ? IMAGE_RGB : IMAGE_WHITE;
|
||||
|
||||
if ((img = ImageOpen(argv[6], colorspace, IMAGE_WHITE, sat, hue, NULL)) == NULL)
|
||||
{
|
||||
fputs("ERROR: Unable to open image file for printing!\n", stderr);
|
||||
ppdClose(ppd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
colorspace = img->colorspace;
|
||||
|
||||
/*
|
||||
* Scale as necessary...
|
||||
*/
|
||||
|
||||
xprint = (PageRight - PageLeft) / 72.0;
|
||||
yprint = (PageTop - PageBottom) / 72.0;
|
||||
|
||||
if (zoom == 0.0 && ppi == 0)
|
||||
ppi = img->xppi;
|
||||
|
||||
if (ppi > 0)
|
||||
{
|
||||
/*
|
||||
* Scale the image as neccesary to match the desired pixels-per-inch.
|
||||
*/
|
||||
|
||||
xinches = (float)img->xsize / (float)ppi;
|
||||
yinches = (float)img->ysize / (float)ppi;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Scale percentage of page size...
|
||||
*/
|
||||
|
||||
xsize = xprint * zoom;
|
||||
ysize = xsize * img->ysize / img->xsize;
|
||||
|
||||
if (ysize > (yprint * zoom))
|
||||
{
|
||||
ysize = yprint * zoom;
|
||||
xsize = ysize * img->xsize / img->ysize;
|
||||
}
|
||||
|
||||
xinches = xsize;
|
||||
yinches = ysize;
|
||||
}
|
||||
|
||||
xpages = ceil(xinches / xprint);
|
||||
ypages = ceil(yinches / yprint);
|
||||
|
||||
/*
|
||||
* See if we need to collate, and if so how we need to do it...
|
||||
*/
|
||||
|
||||
if (xpages == 1 && ypages == 1)
|
||||
Collate = 0;
|
||||
|
||||
slowcollate = Collate && ppdFindOption(ppd, "Collate") == NULL;
|
||||
|
||||
/*
|
||||
* Write any "exit server" options that have been selected...
|
||||
*/
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_EXIT);
|
||||
|
||||
/*
|
||||
* Write any JCL commands that are needed to print PostScript code...
|
||||
*/
|
||||
|
||||
if (ppd != NULL && ppd->jcl_begin && ppd->jcl_ps)
|
||||
{
|
||||
fputs(ppd->jcl_begin, stdout);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_JCL);
|
||||
fputs(ppd->jcl_ps, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start sending the document with any commands needed...
|
||||
*/
|
||||
|
||||
puts("%!");
|
||||
|
||||
if (ppd != NULL && ppd->patches != NULL)
|
||||
puts(ppd->patches);
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_DOCUMENT);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_ANY);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PROLOG);
|
||||
|
||||
if (g != 1.0 || b != 1.0)
|
||||
printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
|
||||
"ifelse %.3f mul } bind settransfer\n", g, b);
|
||||
|
||||
if (Copies > 1 && !slowcollate)
|
||||
{
|
||||
printf("/#copies %d def\n", Copies);
|
||||
realcopies = Copies;
|
||||
Copies = 1;
|
||||
}
|
||||
else
|
||||
realcopies = 1;
|
||||
|
||||
/*
|
||||
* Output the pages...
|
||||
*/
|
||||
|
||||
xprint = xinches / xpages;
|
||||
yprint = yinches / ypages;
|
||||
row = malloc(img->xsize * abs(colorspace) + 3);
|
||||
|
||||
for (page = 1; Copies > 0; Copies --)
|
||||
for (xpage = 0; xpage < xpages; xpage ++)
|
||||
for (ypage = 0; ypage < ypages; ypage ++, page ++)
|
||||
{
|
||||
fprintf(stderr, "PAGE: %d %d\n", page, realcopies);
|
||||
fprintf(stderr, "INFO: Printing page %d...\n", page);
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
|
||||
puts("gsave");
|
||||
|
||||
if (Flip)
|
||||
printf("%.0f 0 translate -1 1 scale\n", PageWidth);
|
||||
|
||||
switch (Orientation)
|
||||
{
|
||||
case 1 : /* Landscape */
|
||||
printf("%.0f 0 translate 90 rotate\n", PageLength);
|
||||
break;
|
||||
case 2 : /* Reverse Portrait */
|
||||
printf("%.0f %.0f translate 180 rotate\n", PageWidth, PageLength);
|
||||
break;
|
||||
case 3 : /* Reverse Landscape */
|
||||
printf("0 %.0f translate -90 rotate\n", PageWidth);
|
||||
break;
|
||||
}
|
||||
|
||||
x0 = img->xsize * xpage / xpages;
|
||||
x1 = img->xsize * (xpage + 1) / xpages - 1;
|
||||
y0 = img->ysize * ypage / ypages;
|
||||
y1 = img->ysize * (ypage + 1) / ypages - 1;
|
||||
|
||||
printf("%.1f %.1f translate\n", PageLeft, PageBottom + 72.0 * yprint);
|
||||
printf("%.3f %.3f scale\n\n",
|
||||
xprint * 72.0 / (x1 - x0 + 1),
|
||||
yprint * 72.0 / (y1 - y0 + 1));
|
||||
|
||||
if (LanguageLevel == 1)
|
||||
{
|
||||
printf("/picture %d string def\n", (x1 - x0 + 1) * abs(colorspace));
|
||||
printf("%d %d 8[1 0 0 -1 0 1]", (x1 - x0 + 1), (y1 - y0 + 1));
|
||||
|
||||
if (colorspace == IMAGE_WHITE)
|
||||
puts("{currentfile picture readhexstring pop} image");
|
||||
else
|
||||
puts("{currentfile picture readhexstring pop} false 3 colorimage");
|
||||
|
||||
for (y = y0; y <= y1; y ++)
|
||||
{
|
||||
ImageGetRow(img, x0, y, x1 - x0 + 1, row);
|
||||
ps_hex(row, (x1 - x0 + 1) * abs(colorspace));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (colorspace == IMAGE_WHITE)
|
||||
puts("/DeviceGray setcolorspace");
|
||||
else
|
||||
puts("/DeviceRGB setcolorspace");
|
||||
|
||||
printf("<<"
|
||||
"/ImageType 1"
|
||||
"/Width %d"
|
||||
"/Height %d"
|
||||
"/BitsPerComponent 8",
|
||||
x1 - x0 + 1, y1 - y0 + 1);
|
||||
|
||||
if (colorspace == IMAGE_WHITE)
|
||||
fputs("/Decode[0 1]", stdout);
|
||||
else
|
||||
fputs("/Decode[0 1 0 1 0 1]", stdout);
|
||||
|
||||
fputs("/DataSource currentfile /ASCII85Decode filter", stdout);
|
||||
|
||||
if (((x1 - x0 + 1) / xprint) < 100.0)
|
||||
fputs("/Interpolate true", stdout);
|
||||
|
||||
puts("/ImageMatrix[1 0 0 -1 0 1]>>image");
|
||||
|
||||
for (y = y0, out_offset = 0; y <= y1; y ++)
|
||||
{
|
||||
ImageGetRow(img, x0, y, x1 - x0 + 1, row + out_offset);
|
||||
|
||||
out_length = (x1 - x0 + 1) * abs(colorspace) + out_offset;
|
||||
out_offset = out_length & 3;
|
||||
|
||||
ps_ascii85(row, out_length, y == y1);
|
||||
|
||||
if (out_offset > 0)
|
||||
memcpy(row, row + out_length - out_offset, out_offset);
|
||||
}
|
||||
}
|
||||
|
||||
puts("grestore");
|
||||
puts("showpage");
|
||||
}
|
||||
|
||||
/*
|
||||
* End the job with the appropriate JCL command or CTRL-D otherwise.
|
||||
*/
|
||||
|
||||
if (ppd != NULL && ppd->jcl_end)
|
||||
fputs(ppd->jcl_end, stdout);
|
||||
else
|
||||
putchar(0x04);
|
||||
|
||||
/*
|
||||
* Close files...
|
||||
*/
|
||||
|
||||
ImageClose(img);
|
||||
ppdClose(ppd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ps_hex()' - Print binary data as a series of hexadecimal numbers.
|
||||
*/
|
||||
|
||||
static void
|
||||
ps_hex(ib_t *data, /* I - Data to print */
|
||||
int length) /* I - Number of bytes to print */
|
||||
{
|
||||
int col;
|
||||
static char *hex = "0123456789ABCDEF";
|
||||
|
||||
|
||||
col = 0;
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
/*
|
||||
* Put the hex chars out to the file; note that we don't use printf()
|
||||
* for speed reasons...
|
||||
*/
|
||||
|
||||
putchar(hex[*data >> 4]);
|
||||
putchar(hex[*data & 15]);
|
||||
|
||||
data ++;
|
||||
length --;
|
||||
|
||||
col = (col + 1) & 31;
|
||||
if (col == 0 && length > 0)
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'ps_ascii85()' - Print binary data as a series of base-85 numbers.
|
||||
*/
|
||||
|
||||
static void
|
||||
ps_ascii85(ib_t *data, /* I - Data to print */
|
||||
int length, /* I - Number of bytes to print */
|
||||
int last_line) /* I - Last line of raster data? */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
unsigned b; /* Binary data word */
|
||||
unsigned char c[5]; /* ASCII85 encoded chars */
|
||||
|
||||
|
||||
while (length > 3)
|
||||
{
|
||||
b = (((((data[0] << 8) | data[1]) << 8) | data[2]) << 8) | data[3];
|
||||
|
||||
if (b == 0)
|
||||
putchar('z');
|
||||
else
|
||||
{
|
||||
c[4] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[3] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[2] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[1] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[0] = b + '!';
|
||||
|
||||
fwrite(c, 5, 1, stdout);
|
||||
}
|
||||
|
||||
data += 4;
|
||||
length -= 4;
|
||||
}
|
||||
|
||||
if (last_line)
|
||||
{
|
||||
if (length > 0)
|
||||
{
|
||||
for (b = 0, i = length; i > 0; b = (b << 8) | data[0], data ++, i --);
|
||||
|
||||
c[4] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[3] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[2] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[1] = (b % 85) + '!';
|
||||
b /= 85;
|
||||
c[0] = b + '!';
|
||||
|
||||
fwrite(c, length + 1, 1, stdout);
|
||||
}
|
||||
|
||||
puts("~>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,804 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* PostScript filter for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry...
|
||||
* check_range() - Check to see if the current page is selected for
|
||||
* copy_bytes() - Copy bytes from the input file to stdout...
|
||||
* end_nup() - End processing for N-up printing...
|
||||
* psgets() - Get a line from a file.
|
||||
* start_nup() - Start processing for N-up printing...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
#define MAX_PAGES 10000
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
int NumPages = 0; /* Number of pages in file */
|
||||
long Pages[MAX_PAGES]; /* Offsets to each page */
|
||||
char PageLabels[MAX_PAGES][64];
|
||||
/* Page labels */
|
||||
const char *PageRanges = NULL; /* Range of pages selected */
|
||||
const char *PageSet = NULL; /* All, Even, Odd pages */
|
||||
int Order = 0, /* 0 = normal, 1 = reverse pages */
|
||||
Flip = 0, /* Flip/mirror pages */
|
||||
NUp = 1, /* Number of pages on each sheet (1, 2, 4) */
|
||||
Collate = 0, /* Collate copies? */
|
||||
Copies = 1; /* Number of copies */
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int check_range(int page);
|
||||
static void copy_bytes(FILE *fp, size_t length);
|
||||
static void end_nup(int number);
|
||||
static char *psgets(char *buf, size_t len, FILE *fp);
|
||||
static void start_nup(int number);
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry...
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
FILE *fp; /* Print file */
|
||||
ppd_file_t *ppd; /* PPD file */
|
||||
int num_options; /* Number of print options */
|
||||
cups_option_t *options; /* Print options */
|
||||
const char *val; /* Option value */
|
||||
char tempfile[255]; /* Temporary file name */
|
||||
FILE *temp; /* Temporary file */
|
||||
int number; /* Page number */
|
||||
int slowcollate; /* 1 if we need to collate manually */
|
||||
int sloworder; /* 1 if we need to order manually */
|
||||
char line[8192]; /* Line buffer */
|
||||
float g; /* Gamma correction value */
|
||||
float b; /* Brightness factor */
|
||||
int level; /* Nesting level for embedded files */
|
||||
int nbytes, /* Number of bytes read */
|
||||
tbytes; /* Total bytes to read for binary data */
|
||||
int page; /* Current page sequence number */
|
||||
|
||||
|
||||
if (argc < 6 || argc > 7)
|
||||
{
|
||||
fputs("ERROR: pstops job-id user title copies options [file]\n", stderr);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have 7 arguments, print the file named on the command-line.
|
||||
* Otherwise, send stdin instead...
|
||||
*/
|
||||
|
||||
if (argc == 6)
|
||||
fp = stdin;
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Try to open the print file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(argv[6], "rb")) == NULL)
|
||||
{
|
||||
perror("ERROR: unable to open print file - ");
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process command-line options and write the prolog...
|
||||
*/
|
||||
|
||||
g = 1.0;
|
||||
b = 1.0;
|
||||
|
||||
Copies = atoi(argv[4]);
|
||||
|
||||
ppd = ppdOpenFile(getenv("PPD"));
|
||||
|
||||
options = NULL;
|
||||
num_options = cupsParseOptions(argv[5], 0, &options);
|
||||
|
||||
ppd = SetCommonOptions(num_options, options, 1);
|
||||
|
||||
ppdMarkDefaults(ppd);
|
||||
cupsMarkOptions(ppd, num_options, options);
|
||||
|
||||
if ((val = cupsGetOption("page-ranges", num_options, options)) != NULL)
|
||||
PageRanges = val;
|
||||
|
||||
if ((val = cupsGetOption("page-set", num_options, options)) != NULL)
|
||||
PageSet = val;
|
||||
|
||||
if ((val = cupsGetOption("multiple-document-handling", num_options, options)) != NULL)
|
||||
{
|
||||
/*
|
||||
* This IPP attribute is unnecessarily complicated...
|
||||
*
|
||||
* single-document, separate-documents-collated-copies, and
|
||||
* single-document-new-sheet all require collated copies.
|
||||
*
|
||||
* separate-documents-collated-copies allows for uncollated copies.
|
||||
*/
|
||||
|
||||
Collate = strcmp(val, "separate-documents-collated-copies") != 0;
|
||||
}
|
||||
|
||||
if ((val = cupsGetOption("Collate", num_options, options)) != NULL &&
|
||||
strcmp(val, "True") == 0)
|
||||
Collate = 1;
|
||||
|
||||
if ((val = cupsGetOption("OutputOrder", num_options, options)) != NULL &&
|
||||
strcmp(val, "Reverse") == 0)
|
||||
Order = 1;
|
||||
|
||||
if ((val = cupsGetOption("number-up", num_options, options)) != NULL)
|
||||
NUp = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("gamma", num_options, options)) != NULL)
|
||||
g = atoi(val) * 0.001f;
|
||||
|
||||
if ((val = cupsGetOption("brightness", num_options, options)) != NULL)
|
||||
b = atoi(val) * 0.01f;
|
||||
|
||||
/*
|
||||
* See if we have to filter the fast or slow way...
|
||||
*/
|
||||
|
||||
if (ppdFindOption(ppd, "Collate") == NULL && Collate && Copies > 1)
|
||||
slowcollate = 1;
|
||||
else
|
||||
slowcollate = 0;
|
||||
|
||||
if (ppdFindOption(ppd, "OutputOrder") == NULL && Order)
|
||||
sloworder = 1;
|
||||
else
|
||||
sloworder = 0;
|
||||
|
||||
/*
|
||||
* If we need to filter slowly, then create a temporary file for page data...
|
||||
*
|
||||
* If the temp file can't be created, then we'll ignore the collating/output
|
||||
* order options...
|
||||
*/
|
||||
|
||||
if (sloworder || slowcollate)
|
||||
{
|
||||
temp = fopen(cupsTempFile(tempfile, sizeof(tempfile)), "wb+");
|
||||
|
||||
if (temp == NULL)
|
||||
slowcollate = sloworder = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write any "exit server" options that have been selected...
|
||||
*/
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_EXIT);
|
||||
|
||||
/*
|
||||
* Write any JCL commands that are needed to print PostScript code...
|
||||
*/
|
||||
|
||||
if (ppd != NULL && ppd->jcl_begin && ppd->jcl_ps)
|
||||
{
|
||||
fputs(ppd->jcl_begin, stdout);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_JCL);
|
||||
fputs(ppd->jcl_ps, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the first line to see if we have DSC comments...
|
||||
*/
|
||||
|
||||
if (psgets(line, sizeof(line), fp) == NULL)
|
||||
{
|
||||
fputs("ERROR: Empty print file!\n", stderr);
|
||||
ppdClose(ppd);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start sending the document with any commands needed...
|
||||
*/
|
||||
|
||||
puts(line);
|
||||
|
||||
if (ppd != NULL && ppd->patches != NULL)
|
||||
puts(ppd->patches);
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_DOCUMENT);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_ANY);
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PROLOG);
|
||||
|
||||
if (NUp > 1)
|
||||
puts("userdict begin\n"
|
||||
"/ESPshowpage /showpage load def\n"
|
||||
"/showpage { } def\n"
|
||||
"end");
|
||||
|
||||
if (g != 1.0 || b != 1.0)
|
||||
printf("{ neg 1 add dup 0 lt { pop 1 } { %.3f exp neg 1 add } "
|
||||
"ifelse %.3f mul } bind settransfer\n", g, b);
|
||||
|
||||
if (Copies > 1 && (!Collate || !slowcollate))
|
||||
printf("/#copies %d def\n", Copies);
|
||||
|
||||
if (strncmp(line, "%!PS-Adobe-", 11) == 0)
|
||||
{
|
||||
/*
|
||||
* OK, we have DSC comments; read until we find a %%Page comment...
|
||||
*/
|
||||
|
||||
level = 0;
|
||||
|
||||
while (psgets(line, sizeof(line), fp) != NULL)
|
||||
if (strncmp(line, "%%BeginDocument:", 16) == 0 ||
|
||||
strncmp(line, "%%BeginDocument ", 16) == 0) /* Adobe Acrobat BUG */
|
||||
level ++;
|
||||
else if (strcmp(line, "%%EndDocument") == 0 && level > 0)
|
||||
level --;
|
||||
else if (strncmp(line, "%%Page:", 7) == 0 && level == 0)
|
||||
break;
|
||||
else if (strncmp(line, "%%BeginBinary:", 14) == 0 ||
|
||||
(strncmp(line, "%%BeginData:", 12) == 0 &&
|
||||
strstr(line, "Binary") != NULL))
|
||||
{
|
||||
/*
|
||||
* Copy binary data...
|
||||
*/
|
||||
|
||||
tbytes = atoi(strchr(line, ':') + 1);
|
||||
while (tbytes > 0)
|
||||
{
|
||||
nbytes = fread(line, 1, sizeof(line), fp);
|
||||
fwrite(line, 1, nbytes, stdout);
|
||||
tbytes -= nbytes;
|
||||
}
|
||||
}
|
||||
else
|
||||
puts(line);
|
||||
|
||||
/*
|
||||
* Then read all of the pages, filtering as needed...
|
||||
*/
|
||||
|
||||
for (page = 1;;)
|
||||
{
|
||||
if (strncmp(line, "%%BeginDocument:", 16) == 0 ||
|
||||
strncmp(line, "%%BeginDocument ", 16) == 0) /* Adobe Acrobat BUG */
|
||||
level ++;
|
||||
else if (strcmp(line, "%%EndDocument") == 0 && level > 0)
|
||||
level --;
|
||||
else if (strncmp(line, "%%Page:", 7) == 0 && level == 0)
|
||||
{
|
||||
if (sscanf(line, "%*s%*s%d", &number) == 1)
|
||||
{
|
||||
if (!check_range(number))
|
||||
{
|
||||
while (psgets(line, sizeof(line), fp) != NULL)
|
||||
if (strncmp(line, "%%BeginDocument:", 16) == 0 ||
|
||||
strncmp(line, "%%BeginDocument ", 16) == 0) /* Adobe Acrobat BUG */
|
||||
level ++;
|
||||
else if (strcmp(line, "%%EndDocument") == 0 && level > 0)
|
||||
level --;
|
||||
else if (strncmp(line, "%%Page:", 7) == 0 && level == 0)
|
||||
break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!sloworder && NumPages > 0)
|
||||
end_nup(NumPages - 1);
|
||||
|
||||
if (slowcollate || sloworder)
|
||||
Pages[NumPages] = ftell(temp);
|
||||
|
||||
if (!sloworder)
|
||||
{
|
||||
if ((NumPages % NUp) == 0)
|
||||
{
|
||||
if (ppd == NULL || ppd->num_filters == 0)
|
||||
fprintf(stderr, "PAGE: %d %d\n", page, Copies);
|
||||
|
||||
printf("%%%%Page: %d %d\n", page, page);
|
||||
page ++;
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
}
|
||||
|
||||
start_nup(NumPages);
|
||||
}
|
||||
|
||||
NumPages ++;
|
||||
}
|
||||
}
|
||||
else if (strncmp(line, "%%BeginBinary:", 14) == 0 ||
|
||||
(strncmp(line, "%%BeginData:", 12) == 0 &&
|
||||
strstr(line, "Binary") != NULL))
|
||||
{
|
||||
/*
|
||||
* Copy binary data...
|
||||
*/
|
||||
|
||||
tbytes = atoi(strchr(line, ':') + 1);
|
||||
while (tbytes > 0)
|
||||
{
|
||||
nbytes = fread(line, 1, sizeof(line), fp);
|
||||
|
||||
if (!sloworder)
|
||||
fwrite(line, 1, nbytes, stdout);
|
||||
|
||||
if (slowcollate || sloworder)
|
||||
fwrite(line, 1, nbytes, stdout);
|
||||
|
||||
tbytes -= nbytes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!sloworder)
|
||||
puts(line);
|
||||
|
||||
if (slowcollate || sloworder)
|
||||
{
|
||||
fputs(line, temp);
|
||||
putc('\n', temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (psgets(line, sizeof(line), fp) == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!sloworder)
|
||||
end_nup((NumPages + NUp - 1) & (NUp - 1));
|
||||
|
||||
if (slowcollate || sloworder)
|
||||
{
|
||||
Pages[NumPages] = ftell(temp);
|
||||
page = 1;
|
||||
|
||||
if (!sloworder)
|
||||
{
|
||||
while (Copies > 0)
|
||||
{
|
||||
rewind(temp);
|
||||
|
||||
for (number = 0; number < NumPages; number ++)
|
||||
{
|
||||
if ((number % NUp) == 0)
|
||||
{
|
||||
if (ppd == NULL || ppd->num_filters == 0)
|
||||
fprintf(stderr, "PAGE: %d 1\n", page);
|
||||
|
||||
printf("%%%%Page: %d %d\n", page, page);
|
||||
page ++;
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
}
|
||||
|
||||
start_nup(number);
|
||||
copy_bytes(temp, Pages[number + 1] - Pages[number]);
|
||||
end_nup(number);
|
||||
}
|
||||
|
||||
Copies --;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
for (number = NumPages - 1; number >= 0; number --)
|
||||
{
|
||||
if ((number % NUp) == 0)
|
||||
{
|
||||
if (ppd == NULL || ppd->num_filters == 0)
|
||||
fprintf(stderr, "PAGE: %d %d\n", page,
|
||||
slowcollate ? 1 : Copies);
|
||||
|
||||
printf("%%%%Page: %d %d\n", page, page);
|
||||
page ++;
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
}
|
||||
|
||||
start_nup(NumPages - 1 - number);
|
||||
fseek(temp, Pages[number], SEEK_SET);
|
||||
copy_bytes(temp, Pages[number + 1] - Pages[number]);
|
||||
end_nup(NumPages - 1 - number);
|
||||
}
|
||||
|
||||
Copies --;
|
||||
}
|
||||
while (Copies > 0 || !slowcollate);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* No DSC comments - write any page commands and then the rest of the file...
|
||||
*/
|
||||
|
||||
if (ppd == NULL || ppd->num_filters == 0)
|
||||
fprintf(stderr, "PAGE: 1 %d\n", slowcollate ? 1 : Copies);
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
|
||||
while (psgets(line, sizeof(line), fp) != NULL)
|
||||
{
|
||||
puts(line);
|
||||
|
||||
if (slowcollate)
|
||||
{
|
||||
fputs(line, temp);
|
||||
putc('\n', temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (slowcollate)
|
||||
{
|
||||
while (Copies > 1)
|
||||
{
|
||||
if (ppd == NULL || ppd->num_filters == 0)
|
||||
fputs("PAGE: 1 1\n", stderr);
|
||||
|
||||
ppdEmit(ppd, stdout, PPD_ORDER_PAGE);
|
||||
rewind(temp);
|
||||
copy_bytes(temp, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* End the job with the appropriate JCL command or CTRL-D otherwise.
|
||||
*/
|
||||
|
||||
if (ppd != NULL && ppd->jcl_end)
|
||||
fputs(ppd->jcl_end, stdout);
|
||||
else
|
||||
putchar(0x04);
|
||||
|
||||
/*
|
||||
* Close files and remove the temporary file if needed...
|
||||
*/
|
||||
|
||||
if (slowcollate || sloworder)
|
||||
{
|
||||
fclose(temp);
|
||||
unlink(tempfile);
|
||||
}
|
||||
|
||||
ppdClose(ppd);
|
||||
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'check_range()' - Check to see if the current page is selected for
|
||||
* printing.
|
||||
*/
|
||||
|
||||
static int /* O - 1 if selected, 0 otherwise */
|
||||
check_range(int page) /* I - Page number */
|
||||
{
|
||||
const char *range; /* Pointer into range string */
|
||||
int lower, upper; /* Lower and upper page numbers */
|
||||
|
||||
|
||||
if (PageSet != NULL)
|
||||
{
|
||||
/*
|
||||
* See if we only print even or odd pages...
|
||||
*/
|
||||
|
||||
if (strcmp(PageSet, "even") == 0 && (page & 1))
|
||||
return (0);
|
||||
if (strcmp(PageSet, "odd") == 0 && !(page & 1))
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (PageRanges == NULL)
|
||||
return (1); /* No range, print all pages... */
|
||||
|
||||
for (range = PageRanges; *range != '\0';)
|
||||
{
|
||||
if (*range == '-')
|
||||
{
|
||||
lower = 1;
|
||||
range ++;
|
||||
upper = strtol(range, (char **)&range, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
lower = strtol(range, (char **)&range, 10);
|
||||
|
||||
if (*range == '-')
|
||||
{
|
||||
range ++;
|
||||
if (!isdigit(*range))
|
||||
upper = 65535;
|
||||
else
|
||||
upper = strtol(range, (char **)&range, 10);
|
||||
}
|
||||
else
|
||||
upper = lower;
|
||||
}
|
||||
|
||||
if (page >= lower && page <= upper)
|
||||
return (1);
|
||||
|
||||
if (*range == ',')
|
||||
range ++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'copy_bytes()' - Copy bytes from the input file to stdout...
|
||||
*/
|
||||
|
||||
static void
|
||||
copy_bytes(FILE *fp, /* I - File to read from */
|
||||
size_t length) /* I - Length of page data */
|
||||
{
|
||||
char buffer[8192]; /* Data buffer */
|
||||
size_t nbytes, /* Number of bytes read */
|
||||
nleft; /* Number of bytes left/remaining */
|
||||
|
||||
|
||||
nleft = length;
|
||||
|
||||
while (nleft > 0 || length == 0)
|
||||
{
|
||||
if ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) < 1)
|
||||
return;
|
||||
|
||||
nleft -= nbytes;
|
||||
|
||||
fwrite(buffer, 1, nbytes, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'end_nup()' - End processing for N-up printing...
|
||||
*/
|
||||
|
||||
static void
|
||||
end_nup(int number) /* I - Page number */
|
||||
{
|
||||
if (Flip || Orientation || NUp > 1)
|
||||
puts("grestoreall");
|
||||
|
||||
switch (NUp)
|
||||
{
|
||||
case 2 :
|
||||
if ((number & 1) == 1)
|
||||
puts("ESPshowpage");
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
if ((number & 3) == 3)
|
||||
puts("ESPshowpage");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'psgets()' - Get a line from a file.
|
||||
*
|
||||
* Note:
|
||||
*
|
||||
* This function differs from the gets() function in that it
|
||||
* handles any combination of CR, LF, or CR LF to end input
|
||||
* lines.
|
||||
*/
|
||||
|
||||
static char * /* O - String or NULL if EOF */
|
||||
psgets(char *buf, /* I - Buffer to read into */
|
||||
size_t len, /* I - Length of buffer */
|
||||
FILE *fp) /* I - File to read from */
|
||||
{
|
||||
char *bufptr; /* Pointer into buffer */
|
||||
int ch; /* Character from file */
|
||||
|
||||
|
||||
len --;
|
||||
bufptr = buf;
|
||||
|
||||
while ((bufptr - buf) < len)
|
||||
{
|
||||
if ((ch = getc(fp)) == EOF)
|
||||
break;
|
||||
|
||||
if (ch == 0x0d)
|
||||
{
|
||||
/*
|
||||
* Got a CR; see if there is a LF as well...
|
||||
*/
|
||||
|
||||
ch = getc(fp);
|
||||
if (ch != EOF && ch != 0x0a)
|
||||
ungetc(ch, fp); /* Nope, save it for later... */
|
||||
|
||||
break;
|
||||
}
|
||||
else if (ch == 0x0a)
|
||||
break;
|
||||
else
|
||||
*bufptr++ = ch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Nul-terminate the string and return it (or NULL for EOF).
|
||||
*/
|
||||
|
||||
*bufptr = '\0';
|
||||
|
||||
if (ch == EOF && bufptr == buf)
|
||||
return (NULL);
|
||||
else
|
||||
return (buf);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'start_nup()' - Start processing for N-up printing...
|
||||
*/
|
||||
|
||||
static void
|
||||
start_nup(int number) /* I - Page number */
|
||||
{
|
||||
int x, y; /* Relative position of subpage */
|
||||
float w, l, /* Width and length of subpage */
|
||||
tx, ty; /* Translation values for subpage */
|
||||
|
||||
|
||||
if (Flip || Orientation || NUp > 1)
|
||||
puts("gsave");
|
||||
|
||||
if (Flip)
|
||||
printf("%.0f 0 translate -1 1 scale\n", PageWidth);
|
||||
|
||||
switch (Orientation)
|
||||
{
|
||||
case 1 : /* Landscape */
|
||||
printf("%.0f 0 translate 90 rotate\n", PageLength);
|
||||
break;
|
||||
case 2 : /* Reverse Portrait */
|
||||
printf("%.0f %.0f translate 180 rotate\n", PageWidth, PageLength);
|
||||
break;
|
||||
case 3 : /* Reverse Landscape */
|
||||
printf("0 %.0f translate -90 rotate\n", PageWidth);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (NUp)
|
||||
{
|
||||
case 2 :
|
||||
x = number & 1;
|
||||
|
||||
if (Orientation & 1)
|
||||
{
|
||||
x = 1 - x;
|
||||
w = PageLength;
|
||||
l = w * PageLength / PageWidth;
|
||||
|
||||
if (l > (PageWidth * 0.5))
|
||||
{
|
||||
l = PageWidth * 0.5;
|
||||
w = l * PageWidth / PageLength;
|
||||
}
|
||||
|
||||
tx = PageWidth * 0.5 - l;
|
||||
ty = (PageLength - w) * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
l = PageWidth;
|
||||
w = l * PageWidth / PageLength;
|
||||
|
||||
if (w > (PageLength * 0.5))
|
||||
{
|
||||
w = PageLength * 0.5;
|
||||
l = w * PageLength / PageWidth;
|
||||
}
|
||||
|
||||
tx = PageLength * 0.5 - w;
|
||||
ty = (PageWidth - l) * 0.5;
|
||||
}
|
||||
|
||||
if (Orientation & 1)
|
||||
{
|
||||
printf("0 %.0f translate -90 rotate\n", PageLength);
|
||||
printf("%.0f %.0f translate %.3f %.3f scale\n",
|
||||
ty, tx + l * x, w / PageWidth, l / PageLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%.0f 0 translate 90 rotate\n", PageWidth);
|
||||
printf("%.0f %.0f translate %.3f %.3f scale\n",
|
||||
tx + w * x, ty, w / PageWidth, l / PageLength);
|
||||
}
|
||||
|
||||
printf("newpath\n"
|
||||
"0 0 moveto\n"
|
||||
"%.0f 0 lineto\n"
|
||||
"%.0f %.0f lineto\n"
|
||||
"0 %.0f lineto\n"
|
||||
"closepath clip newpath\n",
|
||||
PageWidth, PageWidth, PageLength, PageLength);
|
||||
break;
|
||||
|
||||
case 4 :
|
||||
x = number & 1;
|
||||
y = 1 - ((number & 2) != 0);
|
||||
w = PageWidth * 0.5;
|
||||
l = PageLength * 0.5;
|
||||
|
||||
printf("%.0f %.0f translate 0.5 0.5 scale\n", x * w, y * l);
|
||||
printf("newpath\n"
|
||||
"0 0 moveto\n"
|
||||
"%.0f 0 lineto\n"
|
||||
"%.0f %.0f lineto\n"
|
||||
"0 %.0f lineto\n"
|
||||
"closepath clip newpath\n",
|
||||
PageWidth, PageWidth, PageLength, PageLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,493 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Hewlett-Packard Page Control Language and Raster Transfer Language
|
||||
* filter for ESP Print.
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products
|
||||
*
|
||||
* These coded instructions, statements, and computer programs contain
|
||||
* unpublished proprietary information of Easy Software Products, and
|
||||
* are protected by Federal copyright law. They may not be disclosed
|
||||
* to third parties or copied or duplicated in any form, in whole or
|
||||
* in part, without the prior written consent of Easy Software Products.
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include <cups/cups.h>
|
||||
#include <cups/raster.h>
|
||||
#include <cups/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
unsigned char *Planes[4], /* Output buffers */
|
||||
*CompBuffer; /* Compression buffer */
|
||||
int NumPlanes, /* Number of color planes */
|
||||
Feed; /* Number of lines to skip */
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes...
|
||||
*/
|
||||
|
||||
void Setup(void);
|
||||
void StartPage(cups_page_header_t *header);
|
||||
void EndPage(cups_page_header_t *header);
|
||||
void Shutdown(void);
|
||||
|
||||
void CompressData(unsigned char *line, int length, int plane, int type);
|
||||
void OutputLine(cups_page_header_t *header);
|
||||
|
||||
|
||||
/*
|
||||
* 'Setup()' - Prepare the printer for printing.
|
||||
*/
|
||||
|
||||
void
|
||||
Setup(void)
|
||||
{
|
||||
/*
|
||||
* Send a PCL reset sequence.
|
||||
*/
|
||||
|
||||
putchar(0x1b);
|
||||
putchar('E');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'StartPage()' - Start a page of graphics.
|
||||
*/
|
||||
|
||||
void
|
||||
StartPage(cups_page_header_t *header) /* I - Page header */
|
||||
{
|
||||
int plane; /* Looping var */
|
||||
|
||||
|
||||
/*
|
||||
* Set the media type, position, and size...
|
||||
*/
|
||||
|
||||
printf("\033&l6D\033&k12H"); /* Set 6 LPI, 10 CPI */
|
||||
printf("\033&l%.2fP", /* Set page length */
|
||||
header->PageSize[1] / 12.0);
|
||||
printf("\033&l%dX", header->NumCopies); /* Set number copies */
|
||||
if (header->MediaPosition)
|
||||
printf("\033&l%dH", header->MediaPosition); /* Set media position */
|
||||
if (header->cupsMediaType)
|
||||
printf("\033&l%dM", /* Set media type */
|
||||
header->cupsMediaType);
|
||||
|
||||
/*
|
||||
* Set graphics mode...
|
||||
*/
|
||||
|
||||
if (header->cupsColorSpace == CUPS_CSPACE_KCMY)
|
||||
{
|
||||
NumPlanes = 4;
|
||||
printf("\033*r-4U"); /* Set KCMY graphics */
|
||||
}
|
||||
else
|
||||
NumPlanes = 1;
|
||||
|
||||
printf("\033*t%dR", header->HWResolution[0]); /* Set resolution */
|
||||
printf("\033*r%dS", header->cupsWidth); /* Set width */
|
||||
printf("\033*r%dT", header->cupsHeight); /* Set height */
|
||||
printf("\033&a0H\033&a0V"); /* Set top-of-page */
|
||||
printf("\033*r1A"); /* Start graphics */
|
||||
|
||||
if (header->cupsCompression)
|
||||
printf("\033*b%dM", /* Set compression */
|
||||
header->cupsCompression);
|
||||
|
||||
Feed = 0; /* No blank lines yet */
|
||||
|
||||
/*
|
||||
* Allocate memory for a line of graphics...
|
||||
*/
|
||||
|
||||
Planes[0] = malloc(header->cupsBytesPerLine);
|
||||
for (plane = 1; plane < NumPlanes; plane ++)
|
||||
Planes[plane] = Planes[0] + plane * header->cupsBytesPerLine / NumPlanes;
|
||||
|
||||
if (header->cupsCompression)
|
||||
CompBuffer = malloc(header->cupsBytesPerLine * 2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'EndPage()' - Finish a page of graphics.
|
||||
*/
|
||||
|
||||
void
|
||||
EndPage(cups_page_header_t *header) /* I - Page header */
|
||||
{
|
||||
/*
|
||||
* Eject the current page...
|
||||
*/
|
||||
|
||||
if (NumPlanes > 1)
|
||||
{
|
||||
printf("\033*rC"); /* End color GFX */
|
||||
printf("\033&l0H"); /* Eject current page */
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\033*r0B"); /* End GFX */
|
||||
printf("\014"); /* Eject currnet page */
|
||||
}
|
||||
|
||||
/*
|
||||
* Free memory...
|
||||
*/
|
||||
|
||||
free(Planes[0]);
|
||||
|
||||
if (header->cupsCompression)
|
||||
free(CompBuffer);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'Shutdown()' - Shutdown the printer.
|
||||
*/
|
||||
|
||||
void
|
||||
Shutdown(void)
|
||||
{
|
||||
/*
|
||||
* Send a PCL reset sequence.
|
||||
*/
|
||||
|
||||
putchar(0x1b);
|
||||
putchar('E');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'CompressData()' - Compress a line of graphics.
|
||||
*/
|
||||
|
||||
void
|
||||
CompressData(unsigned char *line, /* I - Data to compress */
|
||||
int length, /* I - Number of bytes */
|
||||
int plane, /* I - Color plane */
|
||||
int type) /* I - Type of compression */
|
||||
{
|
||||
unsigned char *line_ptr, /* Current byte pointer */
|
||||
*line_end, /* End-of-line byte pointer */
|
||||
*comp_ptr, /* Pointer into compression buffer */
|
||||
*start; /* Start of compression sequence */
|
||||
int count; /* Count of bytes for output */
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0 :
|
||||
/*
|
||||
* Do no compression...
|
||||
*/
|
||||
|
||||
line_ptr = line;
|
||||
line_end = line + length;
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
/*
|
||||
* Do run-length encoding...
|
||||
*/
|
||||
|
||||
line_end = line + length;
|
||||
for (line_ptr = line, comp_ptr = CompBuffer;
|
||||
line_ptr < line_end;
|
||||
comp_ptr += 2, line_ptr += count)
|
||||
{
|
||||
for (count = 1;
|
||||
(line_ptr + count) < line_end &&
|
||||
line_ptr[0] == line_ptr[count] &&
|
||||
count < 256;
|
||||
count ++);
|
||||
|
||||
comp_ptr[0] = count - 1;
|
||||
comp_ptr[1] = line_ptr[0];
|
||||
}
|
||||
|
||||
line_ptr = CompBuffer;
|
||||
line_end = comp_ptr;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
/*
|
||||
* Do TIFF pack-bits encoding...
|
||||
*/
|
||||
|
||||
line_ptr = line;
|
||||
line_end = line + length;
|
||||
comp_ptr = CompBuffer;
|
||||
|
||||
while (line_ptr < line_end)
|
||||
{
|
||||
if ((line_ptr + 1) >= line_end)
|
||||
{
|
||||
/*
|
||||
* Single byte on the end...
|
||||
*/
|
||||
|
||||
*comp_ptr++ = 0x00;
|
||||
*comp_ptr++ = *line_ptr++;
|
||||
}
|
||||
else if (line_ptr[0] == line_ptr[1])
|
||||
{
|
||||
/*
|
||||
* Repeated sequence...
|
||||
*/
|
||||
|
||||
line_ptr ++;
|
||||
count = 2;
|
||||
|
||||
while (line_ptr < (line_end - 1) &&
|
||||
line_ptr[0] == line_ptr[1] &&
|
||||
count < 127)
|
||||
{
|
||||
line_ptr ++;
|
||||
count ++;
|
||||
}
|
||||
|
||||
*comp_ptr++ = 257 - count;
|
||||
*comp_ptr++ = *line_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Non-repeated sequence...
|
||||
*/
|
||||
|
||||
start = line_ptr;
|
||||
line_ptr ++;
|
||||
count = 1;
|
||||
|
||||
while (line_ptr < (line_end - 1) &&
|
||||
line_ptr[0] != line_ptr[1] &&
|
||||
count < 127)
|
||||
{
|
||||
line_ptr ++;
|
||||
count ++;
|
||||
}
|
||||
|
||||
*comp_ptr++ = count - 1;
|
||||
|
||||
memcpy(comp_ptr, start, count);
|
||||
comp_ptr += count;
|
||||
}
|
||||
}
|
||||
|
||||
line_ptr = CompBuffer;
|
||||
line_end = comp_ptr;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the length of the data and write a raster plane...
|
||||
*/
|
||||
|
||||
printf("\033*b%d%c", line_end - line_ptr, plane);
|
||||
fwrite(line_ptr, line_end - line_ptr, 1, stdout);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'OutputLine()' - Output a line of graphics.
|
||||
*/
|
||||
|
||||
void
|
||||
OutputLine(cups_page_header_t *header) /* I - Page header */
|
||||
{
|
||||
int plane; /* Current plane */
|
||||
|
||||
|
||||
/*
|
||||
* Output whitespace as needed...
|
||||
*/
|
||||
|
||||
if (Feed > 0)
|
||||
{
|
||||
printf("\033*b%dY", Feed);
|
||||
Feed = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write bitmap data as needed...
|
||||
*/
|
||||
|
||||
for (plane = 0; plane < NumPlanes; plane ++)
|
||||
CompressData(Planes[plane], header->cupsBytesPerLine / NumPlanes,
|
||||
plane < (NumPlanes - 1) ? 'V' : 'W',
|
||||
header->cupsCompression);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry and processing of driver.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
int fd; /* File descriptor */
|
||||
cups_raster_t *ras; /* Raster stream for printing */
|
||||
cups_page_header_t header; /* Page header from file */
|
||||
int page; /* Current page */
|
||||
int y; /* Current line */
|
||||
|
||||
|
||||
/*
|
||||
* Check for valid arguments...
|
||||
*/
|
||||
|
||||
if (argc < 6 || argc > 7)
|
||||
{
|
||||
/*
|
||||
* We don't have the correct number of arguments; write an error message
|
||||
* and then sleep for 1 second to give the scheduler a chance to read
|
||||
* the message.
|
||||
*/
|
||||
|
||||
fputs("ERROR: rastertopcl job-id user title copies options [file]\n", stderr);
|
||||
sleep(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the page stream...
|
||||
*/
|
||||
|
||||
if (argc == 7)
|
||||
{
|
||||
if ((fd = open(argv[6], O_RDONLY)) == -1)
|
||||
{
|
||||
perror("ERROR: Unable to open raster file - ");
|
||||
sleep(1);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
fd = 0;
|
||||
|
||||
ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
|
||||
|
||||
/*
|
||||
* Initialize the print device...
|
||||
*/
|
||||
|
||||
Setup();
|
||||
|
||||
/*
|
||||
* Process pages as needed...
|
||||
*/
|
||||
|
||||
page = 0;
|
||||
|
||||
while (cupsRasterReadHeader(ras, &header))
|
||||
{
|
||||
/*
|
||||
* Write a status message with the page number and number of copies.
|
||||
*/
|
||||
|
||||
page ++;
|
||||
|
||||
fprintf(stderr, "PAGE: %d %d\n", page, header.NumCopies);
|
||||
|
||||
/*
|
||||
* Start the page...
|
||||
*/
|
||||
|
||||
StartPage(&header);
|
||||
|
||||
/*
|
||||
* Loop for each line on the page...
|
||||
*/
|
||||
|
||||
for (y = 0; y < header.cupsHeight; y ++)
|
||||
{
|
||||
/*
|
||||
* Let the user know how far we have progressed...
|
||||
*/
|
||||
|
||||
if ((y & 127) == 0)
|
||||
fprintf(stderr, "INFO: Printing page %d, %d%% complete...\n", page,
|
||||
100 * y / header.cupsHeight);
|
||||
|
||||
/*
|
||||
* Read a line of graphics...
|
||||
*/
|
||||
|
||||
if (cupsRasterReadPixels(ras, Planes[0], header.cupsBytesPerLine) < 1)
|
||||
break;
|
||||
|
||||
/*
|
||||
* See if the line is blank; if not, write it to the printer...
|
||||
*/
|
||||
|
||||
if (Planes[0][0] ||
|
||||
memcmp(Planes[0], Planes[0] + 1, header.cupsBytesPerLine - 1))
|
||||
OutputLine(&header);
|
||||
else
|
||||
Feed ++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Eject the page...
|
||||
*/
|
||||
|
||||
EndPage(&header);
|
||||
}
|
||||
|
||||
/*
|
||||
* Shutdown the printer...
|
||||
*/
|
||||
|
||||
Shutdown();
|
||||
|
||||
/*
|
||||
* Close the raster stream...
|
||||
*/
|
||||
|
||||
cupsRasterClose(ras);
|
||||
if (fd != 0)
|
||||
close(fd);
|
||||
|
||||
/*
|
||||
* If no pages were printed, send an error message...
|
||||
*/
|
||||
|
||||
if (page == 0)
|
||||
fputs("ERROR: No pages found!\n", stderr);
|
||||
else
|
||||
fputs("INFO: Ready to print.\n", stderr);
|
||||
|
||||
/*
|
||||
* Sleep for 1 second and return...
|
||||
*/
|
||||
|
||||
sleep(1);
|
||||
return (page == 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,745 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Common text filter routines for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* TextMain() - Standard main entry for text filters.
|
||||
* compare_keywords() - Compare two C/C++ keywords.
|
||||
* getutf8() - Get a UTF-8 encoded wide character...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "textcommon.h"
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
int WrapLines = 1, /* Wrap text in lines */
|
||||
SizeLines = 60, /* Number of lines on a page */
|
||||
SizeColumns = 80, /* Number of columns on a line */
|
||||
PageColumns = 1, /* Number of columns on a page */
|
||||
ColumnGutter = 0, /* Number of characters between text columns */
|
||||
ColumnWidth = 80, /* Width of each column */
|
||||
PrettyPrint = 0, /* Do pretty code formatting */
|
||||
Copies = 1; /* Number of copies */
|
||||
lchar_t **Page = NULL; /* Page characters */
|
||||
int NumPages = 0; /* Number of pages in document */
|
||||
int CharsPerInch = 10; /* Number of character columns per inch */
|
||||
int LinesPerInch = 6; /* Number of lines per inch */
|
||||
int UTF8 = 0; /* Use UTF-8 encoding? */
|
||||
char *Keywords[] = /* List of known keywords... */
|
||||
{
|
||||
"and",
|
||||
"and_eq",
|
||||
"asm",
|
||||
"auto",
|
||||
"bitand",
|
||||
"bitor",
|
||||
"bool",
|
||||
"break",
|
||||
"case",
|
||||
"catch",
|
||||
"char",
|
||||
"class",
|
||||
"compl",
|
||||
"const",
|
||||
"continue",
|
||||
"default",
|
||||
"delete",
|
||||
"do",
|
||||
"double",
|
||||
"else",
|
||||
"enum",
|
||||
"explicit",
|
||||
"extern",
|
||||
"false",
|
||||
"float",
|
||||
"for",
|
||||
"friend",
|
||||
"goto",
|
||||
"if",
|
||||
"inline",
|
||||
"int",
|
||||
"long",
|
||||
"mutable",
|
||||
"namespace",
|
||||
"new",
|
||||
"not",
|
||||
"not_eq",
|
||||
"operator",
|
||||
"or",
|
||||
"or_eq",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
"register",
|
||||
"return",
|
||||
"short",
|
||||
"signed",
|
||||
"sizeof",
|
||||
"static",
|
||||
"struct",
|
||||
"switch",
|
||||
"template",
|
||||
"this",
|
||||
"throw",
|
||||
"true",
|
||||
"try",
|
||||
"typedef",
|
||||
"typename",
|
||||
"union",
|
||||
"unsigned",
|
||||
"virtual",
|
||||
"void",
|
||||
"volatile",
|
||||
"while",
|
||||
"xor",
|
||||
"xor_eq"
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static int compare_keywords(const void *, const void *);
|
||||
static int getutf8(FILE *fp);
|
||||
|
||||
|
||||
/*
|
||||
* 'TextMain()' - Standard main entry for text filters.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
TextMain(char *name, /* I - Name of filter */
|
||||
int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
FILE *fp; /* Print file */
|
||||
ppd_file_t *ppd; /* PPD file */
|
||||
int i, /* Looping var */
|
||||
ch, /* Current char from file */
|
||||
lastch, /* Previous char from file */
|
||||
attr, /* Current attribute */
|
||||
line, /* Current line */
|
||||
column, /* Current column */
|
||||
page_column; /* Current page column */
|
||||
int num_options; /* Number of print options */
|
||||
cups_option_t *options; /* Print options */
|
||||
const char *val; /* Option value */
|
||||
char keyword[64], /* Keyword string */
|
||||
*keyptr; /* Pointer into string */
|
||||
int keycol; /* Column where keyword starts */
|
||||
int ccomment; /* Inside a C-style comment? */
|
||||
int cstring; /* Inside a C string */
|
||||
|
||||
|
||||
if (argc < 6 || argc > 7)
|
||||
{
|
||||
fprintf(stderr, "ERROR: %s job-id user title copies options [file]\n",
|
||||
name);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have 7 arguments, print the file named on the command-line.
|
||||
* Otherwise, send stdin instead...
|
||||
*/
|
||||
|
||||
if (argc == 6)
|
||||
fp = stdin;
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Try to open the print file...
|
||||
*/
|
||||
|
||||
if ((fp = fopen(argv[6], "rb")) == NULL)
|
||||
{
|
||||
perror("ERROR: unable to open print file - ");
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process command-line options and write the prolog...
|
||||
*/
|
||||
|
||||
options = NULL;
|
||||
num_options = cupsParseOptions(argv[5], 0, &options);
|
||||
|
||||
if ((val = cupsGetOption("prettyprint", num_options, options)) != NULL)
|
||||
{
|
||||
PrettyPrint = 1;
|
||||
PageLeft = 72.0f;
|
||||
PageRight = PageWidth - 36.0f;
|
||||
PageBottom = PageBottom > 36.0f ? PageBottom : 36.0f;
|
||||
PageTop = PageLength - 36.0f;
|
||||
CharsPerInch = 12;
|
||||
LinesPerInch = 8;
|
||||
}
|
||||
|
||||
if ((ppd = SetCommonOptions(num_options, options, 1)) != NULL)
|
||||
ppdClose(ppd);
|
||||
|
||||
WrapLines = cupsGetOption("nowrap", num_options, options) == NULL;
|
||||
|
||||
if ((val = cupsGetOption("columns", num_options, options)) != NULL)
|
||||
PageColumns = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("cpi", num_options, options)) != NULL)
|
||||
CharsPerInch = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("lpi", num_options, options)) != NULL)
|
||||
LinesPerInch = atoi(val);
|
||||
|
||||
if ((val = cupsGetOption("prettyprint", num_options, options)) != NULL)
|
||||
PageTop -= 216.0f / LinesPerInch;
|
||||
|
||||
Copies = atoi(argv[4]);
|
||||
|
||||
WriteProlog(argv[3], argv[2], ppd);
|
||||
|
||||
/*
|
||||
* Read text from the specified source and print it...
|
||||
*/
|
||||
|
||||
column = 0;
|
||||
line = 0;
|
||||
page_column = 0;
|
||||
attr = 0;
|
||||
keyptr = keyword;
|
||||
keycol = 0;
|
||||
ccomment = 0;
|
||||
cstring = 0;
|
||||
|
||||
while ((ch = getutf8(fp)) >= 0)
|
||||
{
|
||||
/*
|
||||
* Control codes:
|
||||
*
|
||||
* BS Backspace (0x08)
|
||||
* HT Horizontal tab; next 8th column (0x09)
|
||||
* LF Line feed; forward full line (0x0a)
|
||||
* VT Vertical tab; reverse full line (0x0b)
|
||||
* FF Form feed (0x0c)
|
||||
* CR Carriage return (0x0d)
|
||||
* ESC 7 Reverse full line (0x1b 0x37)
|
||||
* ESC 8 Reverse half line (0x1b 0x38)
|
||||
* ESC 9 Forward half line (0x1b 0x39)
|
||||
*/
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case 0x08 : /* BS - backspace for boldface & underline */
|
||||
if (column > 0)
|
||||
column --;
|
||||
|
||||
keyptr = keyword;
|
||||
keycol = column;
|
||||
break;
|
||||
|
||||
case 0x09 : /* HT - tab to next 8th column */
|
||||
if (PrettyPrint && keyptr > keyword)
|
||||
{
|
||||
*keyptr = '\0';
|
||||
keyptr = keyword;
|
||||
|
||||
if (bsearch(&keyptr, Keywords, sizeof(Keywords) / sizeof(Keywords[0]),
|
||||
sizeof(Keywords[0]), compare_keywords))
|
||||
{
|
||||
/*
|
||||
* Put keywords in boldface...
|
||||
*/
|
||||
|
||||
i = page_column * (ColumnWidth + ColumnGutter);
|
||||
|
||||
while (keycol < column)
|
||||
{
|
||||
Page[line][keycol + i].attr |= ATTR_BOLD;
|
||||
keycol ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
column = (column + 8) & ~7;
|
||||
|
||||
if (column >= ColumnWidth && WrapLines)
|
||||
{ /* Wrap text to margins */
|
||||
line ++;
|
||||
column = 0;
|
||||
|
||||
if (line >= SizeLines)
|
||||
{
|
||||
page_column ++;
|
||||
line = 0;
|
||||
|
||||
if (page_column >= PageColumns)
|
||||
{
|
||||
WritePage();
|
||||
page_column = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
keycol = column;
|
||||
break;
|
||||
|
||||
case 0x0a : /* LF - output current line */
|
||||
if (PrettyPrint && keyptr > keyword)
|
||||
{
|
||||
*keyptr = '\0';
|
||||
keyptr = keyword;
|
||||
|
||||
if (bsearch(&keyptr, Keywords, sizeof(Keywords) / sizeof(Keywords[0]),
|
||||
sizeof(Keywords[0]), compare_keywords))
|
||||
{
|
||||
/*
|
||||
* Put keywords in boldface...
|
||||
*/
|
||||
|
||||
i = page_column * (ColumnWidth + ColumnGutter);
|
||||
|
||||
while (keycol < column)
|
||||
{
|
||||
Page[line][keycol + i].attr |= ATTR_BOLD;
|
||||
keycol ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
line ++;
|
||||
column = 0;
|
||||
keycol = 0;
|
||||
|
||||
if (!ccomment && !cstring)
|
||||
attr &= ~(ATTR_ITALIC | ATTR_BOLD | ATTR_RED | ATTR_GREEN | ATTR_BLUE);
|
||||
|
||||
if (line >= SizeLines)
|
||||
{
|
||||
page_column ++;
|
||||
line = 0;
|
||||
|
||||
if (page_column >= PageColumns)
|
||||
{
|
||||
WritePage();
|
||||
page_column = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0b : /* VT - move up 1 line */
|
||||
if (line > 0)
|
||||
line --;
|
||||
|
||||
keyptr = keyword;
|
||||
keycol = column;
|
||||
|
||||
if (!ccomment && !cstring)
|
||||
attr &= ~(ATTR_ITALIC | ATTR_BOLD | ATTR_RED | ATTR_GREEN | ATTR_BLUE);
|
||||
break;
|
||||
|
||||
case 0x0c : /* FF - eject current page... */
|
||||
if (PrettyPrint && keyptr > keyword)
|
||||
{
|
||||
*keyptr = '\0';
|
||||
keyptr = keyword;
|
||||
|
||||
if (bsearch(&keyptr, Keywords, sizeof(Keywords) / sizeof(Keywords[0]),
|
||||
sizeof(Keywords[0]), compare_keywords))
|
||||
{
|
||||
/*
|
||||
* Put keywords in boldface...
|
||||
*/
|
||||
|
||||
i = page_column * (ColumnWidth + ColumnGutter);
|
||||
|
||||
while (keycol < column)
|
||||
{
|
||||
Page[line][keycol + i].attr |= ATTR_BOLD;
|
||||
keycol ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
page_column ++;
|
||||
column = 0;
|
||||
keycol = 0;
|
||||
line = 0;
|
||||
|
||||
if (!ccomment && !cstring)
|
||||
attr &= ~(ATTR_ITALIC | ATTR_BOLD | ATTR_RED | ATTR_GREEN | ATTR_BLUE);
|
||||
|
||||
if (page_column >= PageColumns)
|
||||
{
|
||||
WritePage();
|
||||
page_column = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0d : /* CR */
|
||||
column = 0;
|
||||
break;
|
||||
|
||||
case 0x1b : /* Escape sequence */
|
||||
ch = getutf8(fp);
|
||||
if (ch == '7')
|
||||
{
|
||||
/*
|
||||
* ESC 7 Reverse full line (0x1b 0x37)
|
||||
*/
|
||||
|
||||
if (line > 0)
|
||||
line --;
|
||||
}
|
||||
else if (ch == '8')
|
||||
{
|
||||
/*
|
||||
* ESC 8 Reverse half line (0x1b 0x38)
|
||||
*/
|
||||
|
||||
if ((attr & ATTR_RAISED) && line > 0)
|
||||
{
|
||||
attr &= ~ATTR_RAISED;
|
||||
line --;
|
||||
}
|
||||
else if (attr & ATTR_LOWERED)
|
||||
attr &= ~ATTR_LOWERED;
|
||||
else
|
||||
attr |= ATTR_RAISED;
|
||||
}
|
||||
else if (ch == '9')
|
||||
{
|
||||
/*
|
||||
* ESC 9 Forward half line (0x1b 0x39)
|
||||
*/
|
||||
|
||||
if ((attr & ATTR_LOWERED) && line < (SizeLines - 1))
|
||||
{
|
||||
attr &= ~ATTR_LOWERED;
|
||||
line ++;
|
||||
}
|
||||
else if (attr & ATTR_RAISED)
|
||||
attr &= ~ATTR_RAISED;
|
||||
else
|
||||
attr |= ATTR_LOWERED;
|
||||
}
|
||||
break;
|
||||
|
||||
default : /* All others... */
|
||||
if (ch < ' ')
|
||||
break; /* Ignore other control chars */
|
||||
|
||||
if (PrettyPrint)
|
||||
{
|
||||
/*
|
||||
* Do highlighting of C/C++ keywords, preprocessor commands,
|
||||
* and comments...
|
||||
*/
|
||||
|
||||
if ((ch == ' ' || ch == '\t') && (attr & ATTR_BOLD))
|
||||
{
|
||||
/*
|
||||
* Stop bolding preprocessor command...
|
||||
*/
|
||||
|
||||
attr &= ~ATTR_BOLD;
|
||||
}
|
||||
else if (!(isalnum(ch) || ch == '_') && keyptr > keyword)
|
||||
{
|
||||
/*
|
||||
* Look for a keyword...
|
||||
*/
|
||||
|
||||
*keyptr = '\0';
|
||||
keyptr = keyword;
|
||||
|
||||
if (!(attr & ATTR_ITALIC) &&
|
||||
bsearch(&keyptr, Keywords, sizeof(Keywords) / sizeof(Keywords[0]),
|
||||
sizeof(Keywords[0]), compare_keywords))
|
||||
{
|
||||
/*
|
||||
* Put keywords in boldface...
|
||||
*/
|
||||
|
||||
i = page_column * (ColumnWidth + ColumnGutter);
|
||||
|
||||
while (keycol < column)
|
||||
{
|
||||
Page[line][keycol + i].attr |= ATTR_BOLD;
|
||||
keycol ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((isalnum(ch) || ch == '_') && !ccomment && !cstring)
|
||||
{
|
||||
/*
|
||||
* Add characters to the current keyword (if they'll fit).
|
||||
*/
|
||||
|
||||
if (keyptr == keyword)
|
||||
keycol = column;
|
||||
|
||||
if (keyptr < (keyword + sizeof(keyword) - 1))
|
||||
*keyptr++ = ch;
|
||||
}
|
||||
else if (ch == '\"' && lastch != '\\' && !ccomment && !cstring)
|
||||
{
|
||||
/*
|
||||
* Start a C string constant...
|
||||
*/
|
||||
|
||||
cstring = -1;
|
||||
attr |= ATTR_BLUE;
|
||||
}
|
||||
else if (ch == '*' && lastch == '/' && !cstring)
|
||||
{
|
||||
/*
|
||||
* Start a C-style comment...
|
||||
*/
|
||||
|
||||
ccomment = 1;
|
||||
attr |= ATTR_ITALIC | ATTR_GREEN;
|
||||
}
|
||||
else if (ch == '/' && lastch == '/' && !cstring)
|
||||
{
|
||||
/*
|
||||
* Start a C++-style comment...
|
||||
*/
|
||||
|
||||
attr |= ATTR_ITALIC | ATTR_GREEN;
|
||||
}
|
||||
else if (ch == '#' && column == 0 && !ccomment && !cstring)
|
||||
{
|
||||
/*
|
||||
* Start a preprocessor command...
|
||||
*/
|
||||
|
||||
attr |= ATTR_BOLD | ATTR_RED;
|
||||
}
|
||||
}
|
||||
|
||||
if (column >= ColumnWidth && WrapLines)
|
||||
{ /* Wrap text to margins */
|
||||
column = 0;
|
||||
line ++;
|
||||
|
||||
if (line >= SizeLines)
|
||||
{
|
||||
page_column ++;
|
||||
line = 0;
|
||||
|
||||
if (page_column >= PageColumns)
|
||||
{
|
||||
WritePage();
|
||||
page_column = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add text to the current column & line...
|
||||
*/
|
||||
|
||||
if (column < ColumnWidth)
|
||||
{
|
||||
i = column + page_column * (ColumnWidth + ColumnGutter);
|
||||
|
||||
if (PrettyPrint)
|
||||
Page[line][i].attr = attr;
|
||||
else if (ch == Page[line][i].ch)
|
||||
Page[line][i].attr |= ATTR_BOLD;
|
||||
else if (Page[line][i].ch == '_')
|
||||
Page[line][i].attr |= ATTR_UNDERLINE;
|
||||
else
|
||||
Page[line][i].attr = attr;
|
||||
|
||||
Page[line][i].ch = ch;
|
||||
}
|
||||
|
||||
if (PrettyPrint)
|
||||
{
|
||||
if ((ch == '{' || ch == '}') && !ccomment && !cstring &&
|
||||
column < ColumnWidth)
|
||||
{
|
||||
/*
|
||||
* Highlight curley braces...
|
||||
*/
|
||||
|
||||
Page[line][i].attr |= ATTR_BOLD;
|
||||
}
|
||||
else if ((ch == '/' || ch == '*') && lastch == '/' &&
|
||||
column < ColumnWidth)
|
||||
{
|
||||
/*
|
||||
* Highlight first comment character...
|
||||
*/
|
||||
|
||||
Page[line][i - 1].attr = attr;
|
||||
}
|
||||
else if (ch == '\"' && lastch != '\\' && !ccomment && cstring > 0)
|
||||
{
|
||||
/*
|
||||
* End a C string constant...
|
||||
*/
|
||||
|
||||
cstring = 0;
|
||||
attr &= ~ATTR_BLUE;
|
||||
}
|
||||
else if (ch == '/' && lastch == '*' && ccomment)
|
||||
{
|
||||
/*
|
||||
* End a C-style comment...
|
||||
*/
|
||||
|
||||
ccomment = 0;
|
||||
attr &= ~(ATTR_ITALIC | ATTR_GREEN);
|
||||
}
|
||||
|
||||
if (cstring < 0)
|
||||
cstring = 1;
|
||||
}
|
||||
|
||||
column ++;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save this character for the next cycle.
|
||||
*/
|
||||
|
||||
lastch = ch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write any remaining page data...
|
||||
*/
|
||||
|
||||
if (line > 0 || page_column > 0 || column > 0)
|
||||
WritePage();
|
||||
|
||||
/*
|
||||
* Write the epilog and return...
|
||||
*/
|
||||
|
||||
WriteEpilogue();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'compare_keywords()' - Compare two C/C++ keywords.
|
||||
*/
|
||||
|
||||
static int /* O - Result of strcmp */
|
||||
compare_keywords(const void *k1, /* I - First keyword */
|
||||
const void *k2) /* I - Second keyword */
|
||||
{
|
||||
return (strcmp(*((const char **)k1), *((const char **)k2)));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'getutf8()' - Get a UTF-8 encoded wide character...
|
||||
*/
|
||||
|
||||
static int /* O - Character or -1 on error */
|
||||
getutf8(FILE *fp) /* I - File to read from */
|
||||
{
|
||||
int ch; /* Current character value */
|
||||
int next; /* Next character from file */
|
||||
|
||||
|
||||
/*
|
||||
* Read the first character and process things accordingly...
|
||||
*
|
||||
* UTF-8 maps 16-bit characters to:
|
||||
*
|
||||
* 0 to 127 = 0xxxxxxx
|
||||
* 128 to 2047 = 110xxxxx 10yyyyyy (xxxxxyyyyyy)
|
||||
* 2048 to 65535 = 1110xxxx 10yyyyyy 10zzzzzz (xxxxyyyyyyzzzzzz)
|
||||
*
|
||||
* We also accept:
|
||||
*
|
||||
* 128 to 191 = 10xxxxxx
|
||||
*
|
||||
* since this range of values is otherwise undefined unless you are
|
||||
* in the middle of a multi-byte character...
|
||||
*
|
||||
* This code currently does not support anything beyond 16-bit
|
||||
* characters, in part because PostScript doesn't support more than
|
||||
* 16-bit characters...
|
||||
*/
|
||||
|
||||
if ((ch = getc(fp)) == EOF)
|
||||
return (EOF);
|
||||
|
||||
if (ch < 0xc0 || !UTF8) /* One byte character? */
|
||||
return (ch);
|
||||
else if ((ch & 0xe0) == 0xc0)
|
||||
{
|
||||
/*
|
||||
* Two byte character...
|
||||
*/
|
||||
|
||||
if ((next = getc(fp)) == EOF)
|
||||
return (EOF);
|
||||
else
|
||||
return (((ch & 0x1f) << 6) | (next & 0x3f));
|
||||
}
|
||||
else if ((ch & 0xf0) == 0xe0)
|
||||
{
|
||||
/*
|
||||
* Three byte character...
|
||||
*/
|
||||
|
||||
if ((next = getc(fp)) == EOF)
|
||||
return (EOF);
|
||||
|
||||
ch = ((ch & 0x0f) << 6) | (next & 0x3f);
|
||||
|
||||
if ((next = getc(fp)) == EOF)
|
||||
return (EOF);
|
||||
else
|
||||
return ((ch << 6) | (next & 0x3f));
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* More than three bytes... We don't support that...
|
||||
*/
|
||||
|
||||
return (EOF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Common text filter definitions for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1997-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/*
|
||||
* Constants...
|
||||
*/
|
||||
|
||||
#define ATTR_BOLD 0x01
|
||||
#define ATTR_UNDERLINE 0x02
|
||||
#define ATTR_RAISED 0x04
|
||||
#define ATTR_LOWERED 0x08
|
||||
#define ATTR_ITALIC 0x10
|
||||
#define ATTR_RED 0x20
|
||||
#define ATTR_GREEN 0x40
|
||||
#define ATTR_BLUE 0x80
|
||||
|
||||
|
||||
/*
|
||||
* Structures...
|
||||
*/
|
||||
|
||||
typedef struct /**** Character/attribute structure... ****/
|
||||
{
|
||||
unsigned short ch, /* Character */
|
||||
attr; /* Any attributes */
|
||||
} lchar_t;
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
extern int WrapLines, /* Wrap text in lines */
|
||||
SizeLines, /* Number of lines on a page */
|
||||
SizeColumns, /* Number of columns on a line */
|
||||
PageColumns, /* Number of columns on a page */
|
||||
ColumnGutter, /* Number of characters between text columns */
|
||||
ColumnWidth, /* Width of each column */
|
||||
PrettyPrint, /* Do pretty code formatting */
|
||||
Copies; /* Number of copies to produce */
|
||||
extern lchar_t **Page; /* Page characters */
|
||||
extern int NumPages; /* Number of pages in document */
|
||||
extern int CharsPerInch, /* Number of character columns per inch */
|
||||
LinesPerInch, /* Number of lines per inch */
|
||||
UTF8; /* Use UTF-8 encoding? */
|
||||
extern char *Keywords[]; /* List of known keywords... */
|
||||
|
||||
|
||||
/*
|
||||
* Required functions...
|
||||
*/
|
||||
|
||||
extern int TextMain(char *name, int argc, char *argv[]);
|
||||
extern void WriteEpilogue(void);
|
||||
extern void WritePage(void);
|
||||
extern void WriteProlog(char *title, char *user, ppd_file_t *ppd);
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,568 +0,0 @@
|
||||
/*
|
||||
* "$Id$"
|
||||
*
|
||||
* Text to PostScript filter for the Common UNIX Printing System (CUPS).
|
||||
*
|
||||
* Copyright 1993-1999 by Easy Software Products.
|
||||
*
|
||||
* These coded instructions, statements, and computer programs are the
|
||||
* property of Easy Software Products and are protected by Federal
|
||||
* copyright law. Distribution and use rights are outlined in the file
|
||||
* "LICENSE.txt" which should have been included with this file. If this
|
||||
* file is missing or damaged please contact Easy Software Products
|
||||
* at:
|
||||
*
|
||||
* Attn: CUPS Licensing Information
|
||||
* Easy Software Products
|
||||
* 44141 Airport View Drive, Suite 204
|
||||
* Hollywood, Maryland 20636-3111 USA
|
||||
*
|
||||
* Voice: (301) 373-9603
|
||||
* EMail: cups-info@cups.org
|
||||
* WWW: http://www.cups.org
|
||||
*
|
||||
* Contents:
|
||||
*
|
||||
* main() - Main entry for text to PostScript filter.
|
||||
* WriteEpilogue() - Write the PostScript file epilogue.
|
||||
* WritePage() - Write a page of text.
|
||||
* WriteProlog() - Write the PostScript file prolog with options.
|
||||
* write_line() - Write a row of text.
|
||||
* write_string() - Write a string of text.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include necessary headers...
|
||||
*/
|
||||
|
||||
#include "textcommon.h"
|
||||
|
||||
|
||||
/*
|
||||
* Globals...
|
||||
*/
|
||||
|
||||
char *Glyphs[65536]; /* PostScript glyphs for Unicode */
|
||||
|
||||
/*
|
||||
* Local functions...
|
||||
*/
|
||||
|
||||
static void write_line(int row, lchar_t *line);
|
||||
static void write_string(int col, int row, int len, lchar_t *s);
|
||||
|
||||
|
||||
/*
|
||||
* 'main()' - Main entry for text to PostScript filter.
|
||||
*/
|
||||
|
||||
int /* O - Exit status */
|
||||
main(int argc, /* I - Number of command-line arguments */
|
||||
char *argv[]) /* I - Command-line arguments */
|
||||
{
|
||||
return (TextMain("texttops", argc, argv));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'WriteEpilogue()' - Write the PostScript file epilogue.
|
||||
*/
|
||||
|
||||
void
|
||||
WriteEpilogue(void)
|
||||
{
|
||||
puts("%%BeginTrailer");
|
||||
printf("%%%%Pages: %d\n", NumPages);
|
||||
puts("%%EOF");
|
||||
|
||||
free(Page[0]);
|
||||
free(Page);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'WritePage()' - Write a page of text.
|
||||
*/
|
||||
|
||||
void
|
||||
WritePage(void)
|
||||
{
|
||||
int line; /* Current line */
|
||||
|
||||
|
||||
NumPages ++;
|
||||
printf("%%%%Page: %d %d\n", NumPages, NumPages);
|
||||
|
||||
puts("gsave");
|
||||
|
||||
if (PrettyPrint)
|
||||
printf("%d H\n", NumPages);
|
||||
|
||||
for (line = 0; line < SizeLines; line ++)
|
||||
write_line(line, Page[line]);
|
||||
|
||||
puts("grestore");
|
||||
puts("showpage");
|
||||
|
||||
memset(Page[0], 0, sizeof(lchar_t) * SizeColumns * SizeLines);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'WriteProlog()' - Write the PostScript file prolog with options.
|
||||
*/
|
||||
|
||||
void
|
||||
WriteProlog(char *title, /* I - Title of job */
|
||||
char *user, /* I - Username */
|
||||
ppd_file_t *ppd) /* I - PPD file info */
|
||||
{
|
||||
int line; /* Current output line */
|
||||
char *charset; /* Character set string */
|
||||
char filename[1024]; /* Glyph filenames */
|
||||
FILE *fp; /* Glyph files */
|
||||
int ch, unicode; /* Character values */
|
||||
char glyph[64]; /* Glyph name */
|
||||
int chars[256]; /* Character encoding array */
|
||||
time_t curtime; /* Current time */
|
||||
struct tm *curtm; /* Current date */
|
||||
char curdate[255]; /* Current date (text format) */
|
||||
|
||||
|
||||
curtime = time(NULL);
|
||||
curtm = localtime(&curtime);
|
||||
strftime(curdate, sizeof(curdate), "%c", curtm);
|
||||
|
||||
puts("%!PS-Adobe-3.0");
|
||||
printf("%%%%BoundingBox: %.0f %.0f %.0f %.0f\n", PageLeft, PageBottom,
|
||||
PageRight, PageTop);
|
||||
if (Orientation & 1)
|
||||
puts("%%Orientation: Landscape");
|
||||
puts("%%Creator: texttops/" CUPS_SVERSION);
|
||||
printf("%%%%CreationDate: %s\n", curdate);
|
||||
printf("%%%%Title: %s\n", title);
|
||||
printf("%%%%For: %s\n", user);
|
||||
if (PrettyPrint)
|
||||
puts("%%DocumentNeededResources: font Courier Courier-Bold Courier-Oblique");
|
||||
else
|
||||
puts("%%DocumentNeededResources: font Courier Courier-Bold");
|
||||
puts("%%DocumentSuppliedResources: procset texttops 1.0 0");
|
||||
puts("%%Pages: (atend)");
|
||||
|
||||
puts("%%EndComments");
|
||||
|
||||
SizeColumns = (PageRight - PageLeft) / 72.0 * CharsPerInch;
|
||||
SizeLines = (PageTop - PageBottom) / 72.0 * LinesPerInch;
|
||||
|
||||
Page = calloc(sizeof(lchar_t *), SizeLines);
|
||||
Page[0] = calloc(sizeof(lchar_t), SizeColumns * SizeLines);
|
||||
for (line = 1; line < SizeLines; line ++)
|
||||
Page[line] = Page[0] + line * SizeColumns;
|
||||
|
||||
if (PageColumns > 1)
|
||||
{
|
||||
ColumnGutter = CharsPerInch / 2;
|
||||
ColumnWidth = (SizeColumns - ColumnGutter * (PageColumns - 1)) /
|
||||
PageColumns;
|
||||
}
|
||||
else
|
||||
ColumnWidth = SizeColumns;
|
||||
|
||||
/*
|
||||
* Get the output character set; if it is undefined or "us-ascii", do
|
||||
* nothing because we can use the default encoding...
|
||||
*/
|
||||
|
||||
puts("%%BeginProlog");
|
||||
puts("%%BeginResource: procset texttops 1.0 0");
|
||||
|
||||
charset = getenv("CHARSET");
|
||||
if (charset != NULL && strcmp(charset, "us-ascii") != 0)
|
||||
{
|
||||
/*
|
||||
* Load the PostScript glyph names and the corresponding character
|
||||
* set definition...
|
||||
*/
|
||||
|
||||
memset(Glyphs, 0, sizeof(Glyphs));
|
||||
|
||||
if ((fp = fopen(CUPS_DATADIR "/data/psglyphs", "r")) != NULL)
|
||||
{
|
||||
while (fscanf(fp, "%x%s", &unicode, glyph) == 2)
|
||||
Glyphs[unicode] = strdup(glyph);
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
if (strncmp(charset, "iso-", 4) == 0)
|
||||
{
|
||||
memset(chars, 0, sizeof(chars));
|
||||
|
||||
sprintf(filename, CUPS_DATADIR "/%s", charset + 4);
|
||||
|
||||
if ((fp = fopen(filename, "r")) != NULL)
|
||||
{
|
||||
while (fscanf(fp, "%x%x", &ch, &unicode) == 2)
|
||||
chars[ch] = unicode;
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* UTF-8 encoding - just pass the first 256 characters for now...
|
||||
*/
|
||||
|
||||
UTF8 = 1;
|
||||
|
||||
for (unicode = 0; unicode < 256; unicode ++)
|
||||
chars[unicode] = unicode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the encoding array...
|
||||
*/
|
||||
|
||||
printf("%% %s encoding\n", charset);
|
||||
puts("/textEncoding [");
|
||||
|
||||
for (ch = 0; ch < 256; ch ++)
|
||||
{
|
||||
if (Glyphs[chars[ch]])
|
||||
printf("/%s", Glyphs[chars[ch]]);
|
||||
else
|
||||
printf("/.notdef");
|
||||
|
||||
if ((ch & 7) == 7)
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
puts("] def");
|
||||
|
||||
puts("% Reencode fonts");
|
||||
puts("/Courier findfont");
|
||||
puts("dup length dict begin\n"
|
||||
" { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
|
||||
" /Encoding textEncoding def\n"
|
||||
" currentdict\n"
|
||||
"end");
|
||||
puts("/Courier exch definefont pop");
|
||||
|
||||
puts("/Courier-Bold findfont");
|
||||
puts("dup length dict begin\n"
|
||||
" { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
|
||||
" /Encoding textEncoding def\n"
|
||||
" currentdict\n"
|
||||
"end");
|
||||
puts("/Courier-Bold exch definefont pop");
|
||||
|
||||
if (PrettyPrint)
|
||||
{
|
||||
puts("/Courier-Oblique findfont");
|
||||
puts("dup length dict begin\n"
|
||||
" { 1 index /FID ne { def } { pop pop } ifelse } forall\n"
|
||||
" /Encoding textEncoding def\n"
|
||||
" currentdict\n"
|
||||
"end");
|
||||
puts("/Courier-Oblique exch definefont pop");
|
||||
}
|
||||
}
|
||||
|
||||
puts("% Define fonts");
|
||||
|
||||
printf("/FN /Courier findfont [%.1f 0 0 %.1f 0 0] makefont def\n",
|
||||
120.0 / CharsPerInch, 68.0 / LinesPerInch);
|
||||
printf("/FB /Courier-Bold findfont [%.1f 0 0 %.1f 0 0] makefont def\n",
|
||||
120.0 / CharsPerInch, 68.0 / LinesPerInch);
|
||||
if (PrettyPrint)
|
||||
printf("/FI /Courier-Oblique findfont [%.1f 0 0 %.1f 0 0] makefont def\n",
|
||||
120.0 / CharsPerInch, 68.0 / LinesPerInch);
|
||||
|
||||
puts("% Common procedures");
|
||||
|
||||
puts("/N { FN setfont moveto } bind def");
|
||||
puts("/B { FB setfont moveto } bind def");
|
||||
puts("/U { gsave 0 rlineto stroke grestore } bind def");
|
||||
|
||||
if (PrettyPrint)
|
||||
{
|
||||
if (ColorDevice)
|
||||
{
|
||||
puts("/S { 0.0 setgray show } bind def");
|
||||
puts("/r { 0.5 0.0 0.0 setrgbcolor show } bind def");
|
||||
puts("/g { 0.0 0.5 0.0 setrgbcolor show } bind def");
|
||||
puts("/b { 0.0 0.0 0.5 setrgbcolor show } bind def");
|
||||
}
|
||||
else
|
||||
{
|
||||
puts("/S { 0.0 setgray show } bind def");
|
||||
puts("/r { 0.2 setgray show } bind def");
|
||||
puts("/g { 0.2 setgray show } bind def");
|
||||
puts("/b { 0.2 setgray show } bind def");
|
||||
}
|
||||
|
||||
puts("/I { FI setfont moveto } bind def");
|
||||
|
||||
puts("/P 20 string def");
|
||||
printf("/T(");
|
||||
|
||||
while (*title != '\0')
|
||||
{
|
||||
if (*title == '(' || *title == ')' || *title == '\\')
|
||||
putchar('\\');
|
||||
|
||||
putchar(*title++);
|
||||
}
|
||||
|
||||
puts(")def");
|
||||
|
||||
puts("/H {");
|
||||
puts("gsave");
|
||||
puts("\t0.9 setgray");
|
||||
|
||||
if (Duplex)
|
||||
{
|
||||
puts("\tdup 2 mod 0 eq {");
|
||||
printf("\t\t%.1f %.1f translate } {\n",
|
||||
PageWidth - PageRight, PageTop + 72.0f / LinesPerInch);
|
||||
printf("\t\t%.1f %.1f translate } ifelse\n",
|
||||
PageLeft, PageTop + 72.0f / LinesPerInch);
|
||||
}
|
||||
else
|
||||
printf("\t%.1f %.1f translate\n",
|
||||
PageLeft, PageTop + 72.0f / LinesPerInch);
|
||||
|
||||
printf("\t0 0 %.1f %.1f rectfill\n", PageRight - PageLeft,
|
||||
144.0f / LinesPerInch);
|
||||
|
||||
puts("\tFB setfont");
|
||||
puts("\t0 setgray");
|
||||
|
||||
if (Duplex)
|
||||
{
|
||||
puts("\tdup 2 mod 0 eq {");
|
||||
printf("\t\tT stringwidth pop neg %.1f add %.1f } {\n",
|
||||
PageRight - PageLeft - 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
printf("\t\t%.1f %.1f } ifelse\n", 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
}
|
||||
else
|
||||
printf("\t%.1f %.1f\n", 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
|
||||
puts("\tmoveto T show");
|
||||
|
||||
printf("\t(%s)\n", curdate);
|
||||
printf("\tdup stringwidth pop neg 2 div %.1f add %.1f\n",
|
||||
(PageRight - PageLeft) * 0.5,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
puts("\tmoveto show");
|
||||
|
||||
if (Duplex)
|
||||
{
|
||||
puts("\tdup P cvs exch 2 mod 0 eq {");
|
||||
printf("\t\t%.1f %.1f } {\n", 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
printf("\t\tdup stringwidth pop neg %.1f add %.1f } ifelse\n",
|
||||
PageRight - PageLeft - 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
}
|
||||
else
|
||||
printf("\tP cvs dup stringwidth pop neg %.1f add %.1f\n",
|
||||
PageRight - PageLeft - 36.0f / LinesPerInch,
|
||||
(0.5f + 0.157f) * 72.0f / LinesPerInch);
|
||||
|
||||
puts("\tmoveto show");
|
||||
puts("\tgrestore");
|
||||
puts("} bind def");
|
||||
}
|
||||
else
|
||||
puts("/S { show } bind def");
|
||||
|
||||
puts("%%EndResource");
|
||||
|
||||
puts("%%EndProlog");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'write_line()' - Write a row of text.
|
||||
*/
|
||||
|
||||
static void
|
||||
write_line(int row, /* I - Row number (0 to N) */
|
||||
lchar_t *line) /* I - Line to print */
|
||||
{
|
||||
int col; /* Current column */
|
||||
int attr; /* Current attribute */
|
||||
lchar_t *start; /* First character in sequence */
|
||||
|
||||
|
||||
for (col = 0, start = line; col < SizeColumns;)
|
||||
{
|
||||
while (col < SizeColumns && (line->ch == ' ' || line->ch == 0))
|
||||
{
|
||||
col ++;
|
||||
line ++;
|
||||
}
|
||||
|
||||
if (col >= SizeColumns)
|
||||
break;
|
||||
|
||||
attr = line->attr;
|
||||
start = line;
|
||||
|
||||
while (col < SizeColumns && line->ch != 0 && attr == line->attr)
|
||||
{
|
||||
col ++;
|
||||
line ++;
|
||||
}
|
||||
|
||||
write_string(col - (line - start), row, line - start, start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 'write_string()' - Write a string of text.
|
||||
*/
|
||||
|
||||
static void
|
||||
write_string(int col, /* I - Start column */
|
||||
int row, /* I - Row */
|
||||
int len, /* I - Number of characters */
|
||||
lchar_t *s) /* I - String to print */
|
||||
{
|
||||
int i; /* Looping var */
|
||||
float x, y; /* Position of text */
|
||||
unsigned attr; /* Character attributes */
|
||||
|
||||
|
||||
/*
|
||||
* Position the text and set the font...
|
||||
*/
|
||||
|
||||
if (Duplex && (NumPages & 1) == 0)
|
||||
{
|
||||
x = PageWidth - PageRight;
|
||||
y = PageTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = PageLeft;
|
||||
y = PageTop;
|
||||
}
|
||||
|
||||
x += (float)col * 72.0f / (float)CharsPerInch;
|
||||
y -= (float)(row + 0.843) * 72.0f / (float)LinesPerInch;
|
||||
|
||||
attr = s->attr;
|
||||
|
||||
if (attr & ATTR_RAISED)
|
||||
y += 36.0 / (float)LinesPerInch;
|
||||
else if (attr & ATTR_LOWERED)
|
||||
y -= 36.0 / (float)LinesPerInch;
|
||||
|
||||
if (x == (int)x)
|
||||
printf("%.0f ", x);
|
||||
else
|
||||
printf("%.1f ", x);
|
||||
|
||||
if (y == (int)y)
|
||||
printf("%.0f ", y);
|
||||
else
|
||||
printf("%.1f ", y);
|
||||
|
||||
if (attr & ATTR_BOLD)
|
||||
putchar('B');
|
||||
else if (attr & ATTR_ITALIC)
|
||||
putchar('I');
|
||||
else
|
||||
putchar('N');
|
||||
|
||||
if (attr & ATTR_UNDERLINE)
|
||||
printf(" %.1f U", (float)len * 72.0 / (float)CharsPerInch);
|
||||
|
||||
/*
|
||||
* See if the string contains 16-bit characters...
|
||||
*/
|
||||
|
||||
for (i = 0; i < len; i ++)
|
||||
if (s[i].ch > 255)
|
||||
break;
|
||||
|
||||
if (i < len)
|
||||
{
|
||||
/*
|
||||
* Write a hex Unicode string...
|
||||
*/
|
||||
|
||||
fputs("<feff", stdout);
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
printf("%04x", s->ch);
|
||||
len --;
|
||||
s ++;
|
||||
}
|
||||
|
||||
putchar('>');
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Write a quoted string...
|
||||
*/
|
||||
|
||||
putchar('(');
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
if (s->ch > 126)
|
||||
{
|
||||
/*
|
||||
* Quote 8-bit characters...
|
||||
*/
|
||||
|
||||
printf("\\%03o", s->ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Quote the parenthesis and backslash as needed...
|
||||
*/
|
||||
|
||||
if (s->ch == '(' || s->ch == ')' || s->ch == '\\')
|
||||
putchar('\\');
|
||||
|
||||
putchar(s->ch);
|
||||
}
|
||||
|
||||
len --;
|
||||
s ++;
|
||||
}
|
||||
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
if (PrettyPrint)
|
||||
{
|
||||
if (attr & ATTR_RED)
|
||||
puts("r");
|
||||
else if (attr & ATTR_GREEN)
|
||||
puts("g");
|
||||
else if (attr & ATTR_BLUE)
|
||||
puts("b");
|
||||
else
|
||||
puts("S");
|
||||
}
|
||||
else
|
||||
puts("S");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* End of "$Id$".
|
||||
*/
|
||||
@@ -1,57 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: accept.8 380 1999-06-10 16:15:04Z mike $"
|
||||
.\"
|
||||
.\" accept/reject man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH accept 8 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
accept/reject \- accept/reject jobs sent to a destination
|
||||
.SH SYNOPSIS
|
||||
.B accept
|
||||
destination(s)
|
||||
.br
|
||||
.B reject
|
||||
[ -h
|
||||
.I server
|
||||
] [ -r [
|
||||
.I reason
|
||||
] ]
|
||||
destination(s)
|
||||
.SH DESCRIPTION
|
||||
\fBaccept\fR instructs the printing system to accept print jobs to the
|
||||
specified destinations.
|
||||
.LP
|
||||
\fBreject\fR instructs the printing system to reject print jobs to the
|
||||
specified destinations. The \fI-r\fR option sets the reason for rejecting
|
||||
print jobs. If not specified the reason defaults to "Reason Unknown".
|
||||
.SH COMPATIBILITY
|
||||
The CUPS versions of \fBaccept\fR and \fBreject\fR may ask the user for an
|
||||
access password depending on the printing system configuration. This differs
|
||||
from the System V versions which require the root user to execute these
|
||||
commands.
|
||||
.SH SEE ALSO
|
||||
cancel(1), disable(8), enable(8), lp(1), lpadmin(8), lpstat(1),
|
||||
CUPS Software Administrator's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: accept.8 380 1999-06-10 16:15:04Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
@@ -1,88 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: backend.1 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" backend man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH backend 1 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
backend \- backend transmission interfaces
|
||||
.SH SYNOPSIS
|
||||
.B backend
|
||||
job user title num-copies options
|
||||
.I [ filename ]
|
||||
.SH DESCRIPTION
|
||||
The CUPS backend interface provides a standard method for sending document
|
||||
files to different physical interfaces.
|
||||
.LP
|
||||
Backends must be capable of reading from a filename on the command-line
|
||||
or from the standard input, copying stdin to a temporary if required by
|
||||
the physical interface.
|
||||
.LP
|
||||
The command name (argv[0]) is set to the device URI of the destination printer.
|
||||
.SH ENVIRONMENT VARIABLES
|
||||
The following environment variables are defined by the CUPS server when
|
||||
executing the backend:
|
||||
.TP 5
|
||||
CHARSET
|
||||
.br
|
||||
The default text character set (typically us-ascii or iso-8859-1).
|
||||
.TP 5
|
||||
LANG
|
||||
.br
|
||||
The default language locale (typically C or en).
|
||||
.TP 5
|
||||
PATH
|
||||
.br
|
||||
The standard execution path for external programs that may be run by the backend.
|
||||
.TP 5
|
||||
PPD
|
||||
.br
|
||||
The full pathname of the PostScript Printer Description (PPD) file for
|
||||
this printer.
|
||||
.TP 5
|
||||
RIP_CACHE
|
||||
.br
|
||||
The recommended amount of memory to use for Raster Image Processors (RIPs).
|
||||
.TP 5
|
||||
SERVER_ROOT
|
||||
.br
|
||||
The root directory of the server.
|
||||
.TP 5
|
||||
SOFTWARE
|
||||
.br
|
||||
The name and version number of the server (typically CUPS/1.0).
|
||||
.TP 5
|
||||
TZ
|
||||
.br
|
||||
The timezone of the server (typically GMT).
|
||||
.TP 5
|
||||
USER
|
||||
.br
|
||||
The user executing the backend (typically root).
|
||||
.SH SEE ALSO
|
||||
cupsd(8), filter(1)
|
||||
CUPS Software Administrator's Manual,
|
||||
CUPS Interface Design Description
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: backend.1 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
@@ -1,36 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: classes.conf.5 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" classes.conf man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH classes.conf 5 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
classes.conf \- class configuration file for cups
|
||||
.SH DESCRIPTION
|
||||
.SH SEE ALSO
|
||||
cupsd(8), cupsd.conf(5), mime.convs(5), mime.types(5), printers.conf(5),
|
||||
CUPS Software Administrator's Manual,
|
||||
CUPS Interface Design Description
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: classes.conf.5 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
@@ -1,47 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: cupsd.8 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" cupsd man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH cupsd 8 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
cupsd \- common unix printing system daemon
|
||||
.SH SYNOPSIS
|
||||
.B cups
|
||||
.I [ \-c config-file ]
|
||||
.SH DESCRIPTION
|
||||
\fBcupsd\fR is the scheduler for the Common UNIX Printing System. It implements
|
||||
a printing system based upon the Internet Printing Protocol, version 1.0. If
|
||||
no options are specified on the command-line then the default configuration file
|
||||
(usually \fI/var/cups/conf/cupsf.conf\fR) will be used.
|
||||
.SH COMPATIBILITY
|
||||
\fBcupsd\fR implements all of the required IPP/1.0 attributes and operations.
|
||||
It also implements optional operation set 1 and several CUPS-specific
|
||||
administation operations.
|
||||
.SH SEE ALSO
|
||||
classes.conf(5), cupsd.conf(5), mime.convs(5), mime.types(5), printers.conf(5),
|
||||
CUPS Software Administrator's Manual,
|
||||
CUPS Interface Design Description
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: cupsd.8 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
@@ -1,36 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: cupsd.conf.5 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" cupsd.conf man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH cupsd.conf 5 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
cupsd.conf \- server configuration file for cups
|
||||
.SH DESCRIPTION
|
||||
.SH SEE ALSO
|
||||
classes.conf(5), cupsd(8), mime.convs(5), mime.types(5), printers.conf(5),
|
||||
CUPS Software Administrator's Manual,
|
||||
CUPS Interface Design Description
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: cupsd.conf.5 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
Arquivo binário não exibido.
@@ -1,64 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: enable.8 380 1999-06-10 16:15:04Z mike $"
|
||||
.\"
|
||||
.\" enable/disable man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH enable 8 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
disable, disable \- stop/start printers and classes
|
||||
.SH SYNOPSIS
|
||||
.B enable
|
||||
destination(s)
|
||||
.br
|
||||
.B disable
|
||||
[ \-c ] [ -h
|
||||
.I server
|
||||
] [ \-r [
|
||||
.I reason
|
||||
] ] destination(s)
|
||||
.SH DESCRIPTION
|
||||
\fBenable\fR starts the named printers or classes.
|
||||
.LP
|
||||
\fBdisable\fR stops the named printers or classes. The following options may
|
||||
be used:
|
||||
.TP 5
|
||||
\-c
|
||||
.br
|
||||
Cancels all jobs on the named destination.
|
||||
.TP 5
|
||||
\-r [ \fIreason\fR ]
|
||||
.br
|
||||
Sets the message associated with the stopped state. If no reason is specified
|
||||
then the message is set to "Reason Unknown".
|
||||
.SH COMPATIBILITY
|
||||
The CUPS versions of \fBdisable\fR and \fBenable\fR may ask the user for an
|
||||
access password depending on the printing system configuration. This differs
|
||||
from the System V versions which require the root user to execute these
|
||||
commands.
|
||||
.SH SEE ALSO
|
||||
accept(8), cancel(1), lp(1), lpadmin(8), lpstat(1), reject(8),
|
||||
CUPS Software Administrator's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
|
||||
.\"
|
||||
.\" End of "$Id: enable.8 380 1999-06-10 16:15:04Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
@@ -1,95 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: filter.1 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" filter man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH filter 1 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
filter \- file conversion filter interfaces
|
||||
.SH SYNOPSIS
|
||||
.B filter
|
||||
job user title num-copies options
|
||||
.I [ filename ]
|
||||
.SH DESCRIPTION
|
||||
The CUPS filter interface provides a standard method for adding support for
|
||||
new document types to CUPS. Each filter is capable of converting from one
|
||||
or more input formats to another format that can either be printed directly
|
||||
or piped into another filter to get it to a printable format.
|
||||
.LP
|
||||
Filters must be capable of reading from a filename on the command-line or from
|
||||
the standard input, copying stdin to a temporary if required by the file
|
||||
format.
|
||||
.LP
|
||||
The command name (argv[0]) is set to the name of the destination printer.
|
||||
.SH ENVIRONMENT VARIABLES
|
||||
The following environment variables are defined by the CUPS server when
|
||||
executing each filter:
|
||||
.TP 5
|
||||
CHARSET
|
||||
.br
|
||||
The default text character set (typically us-ascii or iso-8859-1).
|
||||
.TP 5
|
||||
LANG
|
||||
.br
|
||||
The default language locale (typically C or en).
|
||||
.TP 5
|
||||
PATH
|
||||
.br
|
||||
The standard execution path for external programs that may be run by the filter.
|
||||
.TP 5
|
||||
PPD
|
||||
.br
|
||||
The full pathname of the PostScript Printer Description (PPD) file for
|
||||
this printer.
|
||||
.TP 5
|
||||
RIP_CACHE
|
||||
.br
|
||||
The recommended amount of memory to use for Raster Image Processors (RIPs).
|
||||
.TP 5
|
||||
SERVER_ROOT
|
||||
.br
|
||||
The root directory of the server.
|
||||
.TP 5
|
||||
SOFTWARE
|
||||
.br
|
||||
The name and version number of the server (typically CUPS/1.0).
|
||||
.TP 5
|
||||
TZ
|
||||
.br
|
||||
The timezone of the server (typically GMT).
|
||||
.TP 5
|
||||
USER
|
||||
.br
|
||||
The user executing the filter (typically root).
|
||||
.SH COMPATIBILITY
|
||||
While the filter interface is compatible with System V interface
|
||||
scripts, it will only work with the System V interface script as the
|
||||
only filter. Typically the interface script will be provided via the
|
||||
\fBlpadmin(8)\fR command using the \fI-i\fR option.
|
||||
.SH SEE ALSO
|
||||
backend(1), cupsd(8),
|
||||
CUPS Software Administrator's Manual,
|
||||
CUPS Interface Design Description
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: filter.1 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
-71
@@ -1,71 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lp.1 491 1999-07-07 14:03:48Z mike $"
|
||||
.\"
|
||||
.\" lp/cancel man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lp 1 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lp \- print files
|
||||
.br
|
||||
cancel \- cancel jobs
|
||||
.SH SYNOPSIS
|
||||
.B lp
|
||||
[ \-c ] [ \-d
|
||||
.I destination
|
||||
] [ \-m ] [ \-n
|
||||
.I num-copies
|
||||
[ \-o
|
||||
.I option
|
||||
] [ \-p/q
|
||||
.I priority
|
||||
] [ \-s ] [ \-t
|
||||
.I title
|
||||
] [
|
||||
.I file(s)
|
||||
]
|
||||
.br
|
||||
.B cancel
|
||||
[ \-a ] [ -h
|
||||
.I server
|
||||
] [
|
||||
.I id
|
||||
] [
|
||||
.I destination
|
||||
] [
|
||||
.I destination-id
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
\fBlp\fR submits files for printing.
|
||||
.LP
|
||||
\fBcancel\fR cancels existing print jobs. The \fI-a\fR option will remove
|
||||
all jobs from the specified destination.
|
||||
.SH COMPATIBILITY
|
||||
Unlike the System V printing system, CUPS allows printer names to contain
|
||||
any printable character except SPACE and TAB. Also, printer and class names are
|
||||
\fBnot\fR case-sensitive.
|
||||
.SH SEE ALSO
|
||||
lpstat(1),
|
||||
CUPS Software User's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lp.1 491 1999-07-07 14:03:48Z mike $".
|
||||
.\"
|
||||
BIN
Arquivo binário não exibido.
-124
@@ -1,124 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lpadmin.8 461 1999-06-24 17:44:19Z mike $"
|
||||
.\"
|
||||
.\" lpadmin man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lpadmin 8 "Common UNIX Printing System" "22 June 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lpadmin \- configure cups printers and classes
|
||||
.SH SYNOPSIS
|
||||
.B lpadmin
|
||||
[ -h
|
||||
.I server
|
||||
] \-d
|
||||
.I destination
|
||||
.br
|
||||
.B lpadmin
|
||||
[ -h
|
||||
.I server
|
||||
] \-p
|
||||
.I printer
|
||||
.I option(s)
|
||||
.br
|
||||
.B lpadmin
|
||||
[ -h
|
||||
.I server
|
||||
] \-x
|
||||
.I destination
|
||||
.SH DESCRIPTION
|
||||
\fBlpadmin\fR configures printer and class queues provided by CUPS. It can also
|
||||
be used to set the system default printer or class.
|
||||
.LP
|
||||
The first form of the command sets the default printer or class to
|
||||
\fIdestination\fR. Subsequent print jobs submitted via the \fIlp(1)\fR or
|
||||
\fIlpr(1)\fR commands will use this destination unless the user specifies
|
||||
otherwise.
|
||||
.LP
|
||||
The second form of the command configures the named printer. The additional
|
||||
options are described below.
|
||||
.LP
|
||||
The third form of the command deletes the printer or class \fIdestination\fR.
|
||||
Any jobs that are pending for the destination will be removed and any job that
|
||||
is currently printed will be aborted.
|
||||
.SH CONFIGURATION OPTIONS
|
||||
The following options are recognized when configuring a printer queue:
|
||||
.TP 5
|
||||
\-c \fIclass\fR
|
||||
.br
|
||||
Adds the named \fIprinter\fR to \fIclass\fR. If \fIclass\fR does not
|
||||
exist it is created automatically.
|
||||
.TP 5
|
||||
\-i \fIinterface\fR
|
||||
.br
|
||||
Sets a System V style interface script for the printer. This option cannot
|
||||
be specified with the \fI\-P\fR option (PPD file) and is intended for
|
||||
providing support for legacy printer drivers.
|
||||
.TP 5
|
||||
\-m \fImodel\fR
|
||||
.br
|
||||
Sets a standard System V interface script or PPD file from the model
|
||||
directory.
|
||||
.TP 5
|
||||
\-r \fIclass\fR
|
||||
.br
|
||||
Removes the named \fIprinter\fR from \fIclass\fR. If the resulting class
|
||||
becomes empty it is removed.
|
||||
.TP 5
|
||||
\-v \fIdevice-uri\fR
|
||||
.br
|
||||
Sets the \fIdevice-uri\fR attribute of the printer queue. If \fIdevice-uri\fR
|
||||
is a filename it is automatically converted to the form \fBfile:/file/name\fR.
|
||||
.TP 5
|
||||
\-D \fIinfo\fR
|
||||
.br
|
||||
Provides a textual description of the printer.
|
||||
.TP 5
|
||||
\-E
|
||||
.br
|
||||
Enables the printer; this is the same as running the \fIaccept(8)\fR and
|
||||
\fIenable(8)\fR programs on the printer.
|
||||
.TP 5
|
||||
\-L \fIlocation\fR
|
||||
.br
|
||||
Provides a textual location of the printer.
|
||||
.TP 5
|
||||
\-P \fIppd-file\fR
|
||||
.br
|
||||
Specifies a PostScript Printer Description file to use with the printer. If
|
||||
specified, this option overrides the \fI-i\fR option (interface script).
|
||||
.SH COMPATIBILITY
|
||||
Unlike the System V printing system, CUPS allows printer names to contain
|
||||
any printable character except SPACE and TAB. Also, printer and class names are
|
||||
\fBnot\fR case-sensitive. Finally, the CUPS version of \fBlpadmin\fR may ask the
|
||||
user for an access password depending on the printing system configuration.
|
||||
This differs from the System V version which requires the root user to execute
|
||||
this command.
|
||||
.SH LIMITATIONS
|
||||
The CUPS version of \fBlpadmin\fR does not support all of the System V or
|
||||
Solaris printing system configuration options.
|
||||
.SH SEE ALSO
|
||||
accept(8), cancel(1), disable(8), enable(8), lp(1), lpstat(1), reject(8),
|
||||
CUPS Software Administrator's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lpadmin.8 461 1999-06-24 17:44:19Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
-79
@@ -1,79 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lpc.8 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" lpc man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lpc 8 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lpc \- line printer control program
|
||||
.SH SYNOPSIS
|
||||
.B lpc
|
||||
[
|
||||
.I command
|
||||
[
|
||||
.I parameter(s)
|
||||
] ]
|
||||
.SH DESCRIPTION
|
||||
\fBlpc\fR provides limited control over printer and class queues provided by
|
||||
CUPS. It can also be used to query the state of queues.
|
||||
.LP
|
||||
If no command is specified on the command-line, \fRlpc\fR will display a
|
||||
prompt and accept commands from the standard input.
|
||||
.SH COMMANDS
|
||||
The \fBlpc\fR program accepts a subset of commands accepted by the Berkeley
|
||||
\fBlpc\fR program of the same name:
|
||||
.TP 5
|
||||
\fIexit
|
||||
.br
|
||||
Exits the command interpreter.
|
||||
.TP 5
|
||||
help \fI[command]\fR
|
||||
.br
|
||||
Displays a short help message.
|
||||
.TP 5
|
||||
quit
|
||||
.br
|
||||
Exits the command interpreter.
|
||||
.TP 5
|
||||
status \fI[queue]\fR
|
||||
.br
|
||||
Displays the status of one or more printer or class queues.
|
||||
.TP 5
|
||||
? \fI[command]\fR
|
||||
.br
|
||||
Display a short help message.
|
||||
.SH LIMITATIONS
|
||||
Since \fBlpc\fR is geared towards the Berkeley printing system, it is impossible
|
||||
to use \fBlpc\fR to configure printer or class queues provided by CUPS. To
|
||||
configure printer or class queues you must use the \fBlpadmin(8)\fR command
|
||||
or another CUPS-compatible client with that functionality.
|
||||
.SH COMPATIBILITY
|
||||
The CUPS version of \fBlpc\fR does not implement all of the standard Berkeley
|
||||
commands.
|
||||
.SH SEE ALSO
|
||||
accept(8), cancel(1), disable(8), enable(8), lp(1), lpr(1), lprm(1),
|
||||
lpstat(1), reject(8),
|
||||
CUPS Software Administrator's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lpc.8 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
BIN
Arquivo binário não exibido.
-96
@@ -1,96 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lpr.1 491 1999-07-07 14:03:48Z mike $"
|
||||
.\"
|
||||
.\" lpr man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lpr 1 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lpr \- print files
|
||||
.SH SYNOPSIS
|
||||
.B lpr
|
||||
[ \-P
|
||||
.I destination
|
||||
] [ \-#
|
||||
.I num-copies
|
||||
[ \-l ] [ \-o
|
||||
.I option
|
||||
] [ \-p] [ \-r ] [ \-C/J/T
|
||||
.I title
|
||||
] [
|
||||
.I file(s)
|
||||
]
|
||||
.SH DESCRIPTION
|
||||
\fBlpr\fR submits files for printing. Files named on the command line are sent
|
||||
to the named printer (or the system default destination if no destination is
|
||||
specified). If no files are listed on the command-line \fBlpr\fR reads the
|
||||
print file from the standard input.
|
||||
.SH OPTIONS
|
||||
The following options are recognized by \fBlpr\fR:
|
||||
.TP 5
|
||||
\-P \fIdestination\fR
|
||||
.br
|
||||
Prints files to the named printer.
|
||||
.TP 5
|
||||
\-# \fIcopies\fR
|
||||
.br
|
||||
Sets the number of copies to print from 1 to 100.
|
||||
.TP 5
|
||||
\-C \fIname\fR
|
||||
.br
|
||||
Sets the job name.
|
||||
.TP 5
|
||||
\-J \fIname\fR
|
||||
.br
|
||||
Sets the job name.
|
||||
.TP 5
|
||||
\-T \fIname\fR
|
||||
.br
|
||||
Sets the job name.
|
||||
.TP 5
|
||||
\-l
|
||||
.br
|
||||
Specifies that the print file is already formatted for the destination and
|
||||
should be sent without filtering. This option is equivalent to "-oraw".
|
||||
.TP 5
|
||||
\-o \fIoption\fR
|
||||
.br
|
||||
Sets the job name.
|
||||
.TP 5
|
||||
\-p
|
||||
.br
|
||||
Specifies that the print file should be formatted with a shaded header with
|
||||
the date, time, job name, and page number. This option is equivalent to
|
||||
"-oprettyprint" and is only useful when printing text files.
|
||||
.TP 5
|
||||
\-r
|
||||
.br
|
||||
Specifies that the named print files should be deleted after printing them.
|
||||
.SH COMPATIBILITY
|
||||
The "c", "d", "f", "g", "i", "m", "n", "t", "v", and "w" options are not
|
||||
supported by CUPS and will produce a warning message if used.
|
||||
.SH SEE ALSO
|
||||
cancel(1), lp(1), lpstat(1),
|
||||
CUPS Software User's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lpr.1 491 1999-07-07 14:03:48Z mike $".
|
||||
.\"
|
||||
BIN
Arquivo binário não exibido.
@@ -1,40 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lprm.1 327 1999-05-14 17:03:06Z mike $"
|
||||
.\"
|
||||
.\" lprm man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lprm 1 "Common UNIX Printing System" "14 May 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lprm \- cancel print jobs
|
||||
.SH SYNOPSIS
|
||||
.B lprm
|
||||
.SH DESCRIPTION
|
||||
\fBlpstat\fR
|
||||
.SH COMPATIBILITY
|
||||
SOMETHING
|
||||
.SH SEE ALSO
|
||||
cancel(1), lp(1), lpstat(1),
|
||||
CUPS Software User's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lprm.1 327 1999-05-14 17:03:06Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
-115
@@ -1,115 +0,0 @@
|
||||
.\"
|
||||
.\" "$Id: lpstat.1 461 1999-06-24 17:44:19Z mike $"
|
||||
.\"
|
||||
.\" lpstat man page for the Common UNIX Printing System (CUPS).
|
||||
.\"
|
||||
.\" Copyright 1997-1999 by Easy Software Products.
|
||||
.\"
|
||||
.\" These coded instructions, statements, and computer programs are the
|
||||
.\" property of Easy Software Products and are protected by Federal
|
||||
.\" copyright law. Distribution and use rights are outlined in the file
|
||||
.\" "LICENSE.txt" which should have been included with this file. If this
|
||||
.\" file is missing or damaged please contact Easy Software Products
|
||||
.\" at:
|
||||
.\"
|
||||
.\" Attn: CUPS Licensing Information
|
||||
.\" Easy Software Products
|
||||
.\" 44141 Airport View Drive, Suite 204
|
||||
.\" Hollywood, Maryland 20636-3111 USA
|
||||
.\"
|
||||
.\" Voice: (301) 373-9603
|
||||
.\" EMail: cups-info@cups.org
|
||||
.\" WWW: http://www.cups.org
|
||||
.\"
|
||||
.TH lpstat 1 "Common UNIX Printing System" "24 June 1999" "Easy Software Products"
|
||||
.SH NAME
|
||||
lpstat \- print cups status information
|
||||
.SH SYNOPSIS
|
||||
.B lpstat
|
||||
[ -a [
|
||||
.I destination(s)
|
||||
] ] [ -c [
|
||||
.I class(es)
|
||||
] ] [ -d ] [ -h
|
||||
.I server
|
||||
] [ -o [
|
||||
.I destination(s)
|
||||
] ] [ -p [
|
||||
.I printer(s)
|
||||
] ] [ -r ] [ -s ] [ -t ] [ -u [
|
||||
.I user(s)
|
||||
] ] [ -v [
|
||||
.I printer(s)
|
||||
] ]
|
||||
.SH DESCRIPTION
|
||||
\fBlpstat\fR displays status information about the current classes, jobs, and
|
||||
printers. When run with no arguments, \fBlpstat\fR will list jobs queued by
|
||||
the user. Other options include:
|
||||
.TP 5
|
||||
\-a [\fIprinter(s)\fR]
|
||||
.br
|
||||
Shows the accepting state of printer queues. If no printers are
|
||||
specified then all printers are listed.
|
||||
.TP 5
|
||||
\-c [\fIclass(es)\fR]
|
||||
.br
|
||||
Shows the printer classes and the printers that belong to them. If no
|
||||
classes are specified then all classes are listed.
|
||||
.TP 5
|
||||
\-d
|
||||
.br
|
||||
Shows the current default destination.
|
||||
.TP 5
|
||||
\-h \fIserver\fR
|
||||
.br
|
||||
Specifies the CUPS server to communicate with.
|
||||
.TP 5
|
||||
\-o [\fIdestination(s)\fR]
|
||||
.br
|
||||
Shows the jobs queue on the specified destinations. If no destinations are
|
||||
specified all jobs are shown.
|
||||
.TP 5
|
||||
\-p [\fIprinter(s)\fR]
|
||||
.br
|
||||
Shows the printers and whether or not they are enabled for printing. If
|
||||
no printers are specified then all printers are listed.
|
||||
.TP 5
|
||||
\-r
|
||||
.br
|
||||
Shows whether or not the CUPS server is running.
|
||||
.TP 5
|
||||
\-s
|
||||
.br
|
||||
Shows a status summary, including the system default destination, a
|
||||
list of classes and their member printers, and a list of printers and
|
||||
their associated devices. This is equivalent to using the "-d", "-c",
|
||||
and "-p" options.
|
||||
.TP 5
|
||||
\-t
|
||||
.br
|
||||
Shows all status information. This is equivalent to using the "-r",
|
||||
"-d", "-c", "-d", "-v", "-a", "-p", and "-o" options.
|
||||
.TP 5
|
||||
\-u [\fIuser(s)\fR]
|
||||
.br
|
||||
Shows a list of print jobs queued by the specified users. If no users
|
||||
are specified, lists the jobs queued by the current user.
|
||||
.TP 5
|
||||
\-v [\fIprinter(s)\fR]
|
||||
.br
|
||||
Shows the printers and what device they are attached to. If no printers
|
||||
are specified then all printers are listed.
|
||||
.SH COMPATIBILITY
|
||||
Unlike the System V printing system, CUPS allows printer names to contain
|
||||
any printable character except SPACE and TAB. Also, printer and class names are
|
||||
\fBnot\fR case-sensitive.
|
||||
.LP
|
||||
The "-h" option is not a standard System V option.
|
||||
.SH SEE ALSO
|
||||
cancel(1), lp(1),
|
||||
CUPS Software User's Manual
|
||||
.SH COPYRIGHT
|
||||
Copyright 1993-1999 by Easy Software Products, All Rights Reserved.
|
||||
.\"
|
||||
.\" End of "$Id: lpstat.1 461 1999-06-24 17:44:19Z mike $".
|
||||
.\"
|
||||
Arquivo binário não exibido.
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário