Index: imagetops.c
===================================================================
--- imagetops.c	(revision 5996)
+++ imagetops.c	(working copy)
@@ -609,8 +609,8 @@
   puts("%%Creator: imagetops/" CUPS_SVERSION);
   strftime(curdate, sizeof(curdate), "%c", curtm);
   printf("%%%%CreationDate: %s\n", curdate);
-  printf("%%%%Title: %s\n", argv[3]);
-  printf("%%%%For: %s\n", argv[2]);
+  WriteTextComment("Title", argv[3]);
+  WriteTextComment("For", argv[2]);
   if (Orientation & 1)
     puts("%%Orientation: Landscape");
   else
Index: texttops.c
===================================================================
--- texttops.c	(revision 5996)
+++ texttops.c	(working copy)
@@ -208,8 +208,8 @@
   printf("%%cupsRotation: %d\n", (Orientation & 3) * 90);
   puts("%%Creator: texttops/" CUPS_SVERSION);
   printf("%%%%CreationDate: %s\n", curdate);
-  printf("%%%%Title: %s\n", title);
-  printf("%%%%For: %s\n", user);
+  WriteTextComment("Title", title);
+  WriteTextComment("For", user);
   puts("%%Pages: (atend)");
 
  /*
Index: common.c
===================================================================
--- common.c	(revision 5996)
+++ common.c	(working copy)
@@ -3,7 +3,7 @@
  *
  *   Common filter routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -28,6 +28,7 @@
  *   SetCommonOptions() - Set common filter options for media size,
  *                        etc.
  *   UpdatePageVars()   - Update the page variables for the orientation.
+ *   WriteComment()     - Write a DSC comment.
  *   WriteCommon()      - Write common procedures...
  *   WriteLabelProlog() - Write the prolog with the classification
  *                        and page label.
@@ -46,30 +47,31 @@
  * 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
@@ -227,7 +229,7 @@
 void
 UpdatePageVars(void)
 {
-  float		temp;		/* Swapping variable */
+  float		temp;			/* Swapping variable */
 
 
   switch (Orientation & 3)
@@ -467,5 +469,76 @@
 
 
 /*
+ * '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 + 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(")");
+}
+
+
+/*
  * End of "$Id$".
  */
Index: pstops.c
===================================================================
--- pstops.c	(revision 5996)
+++ pstops.c	(working copy)
@@ -666,10 +666,10 @@
     fputs("ERROR: No %%Pages: comment in header!\n", stderr);
 
   if (!saw_for)
-    printf("%%%%For: %s\n", doc->user);
+    WriteTextComment("For", doc->user);
 
   if (!saw_title)
-    printf("%%%%Title: %s\n", doc->title);
+    WriteTextComment("Title", doc->title);
 
   if (doc->copies != 1 && (!doc->collate || !doc->slow_collate))
   {
@@ -946,8 +946,8 @@
   else
     puts("%%Pages: 1");
 
-  printf("%%%%For: %s\n", doc->user);
-  printf("%%%%Title: %s\n", doc->title);
+  WriteTextComment("For", doc->user);
+  WriteTextComment("Title", doc->title);
 
   if (doc->copies != 1 && (!doc->collate || !doc->slow_collate))
   {
Index: hpgl-prolog.c
===================================================================
--- hpgl-prolog.c	(revision 5996)
+++ hpgl-prolog.c	(working copy)
@@ -70,8 +70,8 @@
   puts("%%Creator: hpgltops/" CUPS_SVERSION);
   strftime(line, sizeof(line), "%c", curtm);
   printf("%%%%CreationDate: %s\n", line);
-  printf("%%%%Title: %s\n", title);
-  printf("%%%%For: %s\n", user);
+  WriteTextComment("Title", title);
+  WriteTextComment("For", user);
   printf("%%cupsRotation: %d\n", (Orientation & 3) * 90);
   puts("%%EndComments");
   puts("%%BeginProlog");
Index: common.h
===================================================================
--- common.h	(revision 5996)
+++ common.h	(working copy)
@@ -3,7 +3,7 @@
  *
  *   Common filter definitions for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -76,6 +76,7 @@
 extern void	WriteLabelProlog(const char *label, float bottom,
 		                 float top, float width);
 extern void	WriteLabels(int orient);
+extern void	WriteTextComment(const char *name, const char *value);
 
 
 /*
