]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/common.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / filter / common.c
index b097d5749fa33c38127ad48726675e5e3bc83f47..bed4a53afe073c713c2d01c36ce0ad1538c40cf3 100644 (file)
@@ -1,37 +1,16 @@
 /*
- * "$Id$"
+ * Common filter routines for CUPS.
  *
- *   Common filter routines for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. 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
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  *
- *   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 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   SetCommonOptions() - Set common filter options for media size,
- *                        etc.
- *   UpdatePageVars()   - Update the page variables for the orientation.
- *   WriteCommon()      - Write common procedures...
- *   WriteLabelProlog() - Write the prolog with the classification
- *                        and page label.
- *   WriteLabels()      - Write the actual page labels.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
  * 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 */
+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? */
+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? */
 {
-  ppd_file_t   *ppd;           /* PPD file */
-  ppd_size_t   *pagesize;      /* Current page size */
-  const char   *val;           /* Option value */
+  ppd_file_t   *ppd;                   /* PPD file */
+  ppd_size_t   *pagesize;              /* Current page size */
+  const char   *val;                   /* Option value */
 
 
 #ifdef LC_TIME
@@ -102,8 +82,8 @@ SetCommonOptions(int           num_options,  /* I - Number of options */
 
   if ((val = cupsGetOption("landscape", num_options, options)) != NULL)
   {
-    if (strcasecmp(val, "no") != 0 && strcasecmp(val, "off") != 0 &&
-        strcasecmp(val, "false") != 0)
+    if (_cups_strcasecmp(val, "no") != 0 && _cups_strcasecmp(val, "off") != 0 &&
+        _cups_strcasecmp(val, "false") != 0)
     {
       if (ppd && ppd->landscape > 0)
         Orientation = 1;
@@ -227,7 +207,7 @@ SetCommonOptions(int           num_options, /* I - Number of options */
 void
 UpdatePageVars(void)
 {
-  float                temp;           /* Swapping variable */
+  float                temp;                   /* Swapping variable */
 
 
   switch (Orientation & 3)
@@ -467,5 +447,71 @@ WriteLabels(int orient)    /* I - Orientation of the page */
 
 
 /*
- * End of "$Id$".
+ * 'WriteTextComment()' - Write a DSC text comment.
  */
+
+void
+WriteTextComment(const char *name,     /* I - Comment name ("Title", etc.) */
+                 const char *value)    /* I - Comment value */
+{
+  int  len;                            /* Current line length */
+
+
+ /*
+  * DSC comments are of the form:
+  *
+  *   %%name: value
+  *
+  * The name and value must be limited to 7-bit ASCII for most printers,
+  * so we escape all non-ASCII and ASCII control characters as described
+  * in the Adobe Document Structuring Conventions specification.
+  */
+
+  printf("%%%%%s: (", name);
+  len = 5 + (int)strlen(name);
+
+  while (*value)
+  {
+    if (*value < ' ' || *value >= 127)
+    {
+     /*
+      * Escape this character value...
+      */
+
+      if (len >= 251)                  /* Keep line < 254 chars */
+        break;
+
+      printf("\\%03o", *value & 255);
+      len += 4;
+    }
+    else if (*value == '\\')
+    {
+     /*
+      * Escape the backslash...
+      */
+
+      if (len >= 253)                  /* Keep line < 254 chars */
+        break;
+
+      putchar('\\');
+      putchar('\\');
+      len += 2;
+    }
+    else
+    {
+     /*
+      * Put this character literally...
+      */
+
+      if (len >= 254)                  /* Keep line < 254 chars */
+        break;
+
+      putchar(*value);
+      len ++;
+    }
+
+    value ++;
+  }
+
+  puts(")");
+}