Index: platform/cups/rpdl/trunk/rpdl.ppd
===================================================================
--- platform/cups/rpdl/trunk/rpdl.ppd (revision 36567)
+++ platform/cups/rpdl/trunk/rpdl.ppd (revision 36567)
@@ -0,0 +1,191 @@
+*PPD-Adobe: "4.3"
+*%%%% PPD file for RPDL Generic with CUPS.
+*%%%% Created by the CUPS PPD Compiler CUPS v1.4.1.
+*FormatVersion: "4.3"
+*FileVersion: "1.0"
+*LanguageVersion: English
+*LanguageEncoding: ISOLatin1
+*PCFileName: "rpdl.ppd"
+*Product: "(RPDL Generic)"
+*Manufacturer: "Ricoh"
+*ModelName: "Ricoh RPDL Generic"
+*ShortNickName: "Ricoh RPDL Generic"
+*NickName: "Ricoh RPDL Generic, 1.0"
+*PSVersion: "(3010.000) 0"
+*LanguageLevel: "3"
+*ColorDevice: False
+*DefaultColorSpace: Gray
+*FileSystem: False
+*Throughput: "1"
+*LandscapeOrientation: Plus90
+*TTRasterizer: Type42
+*cupsVersion: 1.4
+*cupsModelNumber: 0
+*cupsManualCopies: False
+*cupsFilter: "application/vnd.cups-raster 100 /usr/lib/cups/filter/rastertorpdl"
+*cupsLanguages: "en"
+*UIConstraints: *TonerSave *Smoothing True
+*UIConstraints: *Smoothing True *TonerSave
+*UIConstraints: *Duplex *OptionDuplexer False
+*UIConstraints: *OptionDuplexer False *Duplex
+*UIConstraints: *OptionLowerTray False *InputSlot Lower
+*UIConstraints: *InputSlot Lower *OptionLowerTray False
+*OpenUI *PageSize/Media Size: PickOne
+*OrderDependency: 10 AnySetup *PageSize
+*DefaultPageSize: A4
+*PageSize A1/A1: "<</PageSize[1684 2384]/ImagingBBox null>>setpagedevice"
+*PageSize A2/A2: "<</PageSize[1191 1684]/ImagingBBox null>>setpagedevice"
+*PageSize A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
+*PageSize A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
+*PageSize A5/A5: "<</PageSize[420 595]/ImagingBBox null>>setpagedevice"
+*PageSize A6/A6: "<</PageSize[297 420]/ImagingBBox null>>setpagedevice"
+*PageSize B4/B4: "<</PageSize[729 1032]/ImagingBBox null>>setpagedevice"
+*PageSize B5/B5: "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
+*PageSize B6/B6: "<</PageSize[363 516]/ImagingBBox null>>setpagedevice"
+*PageSize Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
+*PageSize Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
+*PageSize Statement/Statement: "<</PageSize[396 612]/ImagingBBox null>>setpagedevice"
+*PageSize Ledger/US Ledger: "<</PageSize[1224 792]/ImagingBBox null>>setpagedevice"
+*CloseUI: *PageSize
+*OpenUI *PageRegion/Media Size: PickOne
+*OrderDependency: 10 AnySetup *PageRegion
+*DefaultPageRegion: A4
+*PageRegion A1/A1: "<</PageSize[1684 2384]/ImagingBBox null>>setpagedevice"
+*PageRegion A2/A2: "<</PageSize[1191 1684]/ImagingBBox null>>setpagedevice"
+*PageRegion A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
+*PageRegion A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
+*PageRegion A5/A5: "<</PageSize[420 595]/ImagingBBox null>>setpagedevice"
+*PageRegion A6/A6: "<</PageSize[297 420]/ImagingBBox null>>setpagedevice"
+*PageRegion B4/B4: "<</PageSize[729 1032]/ImagingBBox null>>setpagedevice"
+*PageRegion B5/B5: "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
+*PageRegion B6/B6: "<</PageSize[363 516]/ImagingBBox null>>setpagedevice"
+*PageRegion Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
+*PageRegion Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
+*PageRegion Statement/Statement: "<</PageSize[396 612]/ImagingBBox null>>setpagedevice"
+*PageRegion Ledger/US Ledger: "<</PageSize[1224 792]/ImagingBBox null>>setpagedevice"
+*CloseUI: *PageRegion
+*DefaultImageableArea: A4
+*ImageableArea A1/A1: "0 0 1684 2384"
+*ImageableArea A2/A2: "0 0 1191 1684"
+*ImageableArea A3/A3: "0 0 842 1191"
+*ImageableArea A4/A4: "0 0 595 842"
+*ImageableArea A5/A5: "0 0 420 595"
+*ImageableArea A6/A6: "0 0 297 420"
+*ImageableArea B4/B4: "0 0 729 1032"
+*ImageableArea B5/B5: "0 0 516 729"
+*ImageableArea B6/B6: "0 0 363 516"
+*ImageableArea Letter/US Letter: "0 0 612 792"
+*ImageableArea Legal/US Legal: "0 0 612 1008"
+*ImageableArea Statement/Statement: "0 0 396 612"
+*ImageableArea Ledger/US Ledger: "0 0 1224 792"
+*DefaultPaperDimension: A4
+*PaperDimension A1/A1: "1684 2384"
+*PaperDimension A2/A2: "1191 1684"
+*PaperDimension A3/A3: "842 1191"
+*PaperDimension A4/A4: "595 842"
+*PaperDimension A5/A5: "420 595"
+*PaperDimension A6/A6: "297 420"
+*PaperDimension B4/B4: "729 1032"
+*PaperDimension B5/B5: "516 729"
+*PaperDimension B6/B6: "363 516"
+*PaperDimension Letter/US Letter: "612 792"
+*PaperDimension Legal/US Legal: "612 1008"
+*PaperDimension Statement/Statement: "396 612"
+*PaperDimension Ledger/US Ledger: "1224 792"
+*MaxMediaWidth: "0"
+*MaxMediaHeight: "0"
+*HWMargins: 0 0 0 0
+*CustomPageSize True: "pop pop pop <</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice"
+*ParamCustomPageSize Width: 1 points 0 0
+*ParamCustomPageSize Height: 2 points 0 0
+*ParamCustomPageSize WidthOffset: 3 points 0 0
+*ParamCustomPageSize HeightOffset: 4 points 0 0
+*ParamCustomPageSize Orientation: 5 int 0 0
+*OpenUI *Resolution/Resolution: PickOne
+*OrderDependency: 10 AnySetup *Resolution
+*DefaultResolution: 600dpi
+*Resolution 600dpi/600 DPI: "<</HWResolution[600 600]/cupsBitsPerColor 1/cupsRowCount 0/cupsRowFeed 0/cupsRowStep 0/cupsColorSpace 3>>setpagedevice"
+*Resolution 400dpi/400 DPI: "<</HWResolution[400 400]/cupsBitsPerColor 1/cupsRowCount 0/cupsRowFeed 0/cupsRowStep 0/cupsColorSpace 3>>setpagedevice"
+*Resolution 1200dpi/1200 DPI: "<</HWResolution[1200 1200]/cupsBitsPerColor 1/cupsRowCount 0/cupsRowFeed 0/cupsRowStep 0/cupsColorSpace 3>>setpagedevice"
+*CloseUI: *Resolution
+*OpenUI *InputSlot/Media Source: PickOne
+*OrderDependency: 10 AnySetup *InputSlot
+*DefaultInputSlot: Auto
+*InputSlot Auto/Automatic Selection: "<</MediaPosition 0>>setpagedevice"
+*InputSlot Manual/Manual Tray: "<</MediaPosition 1>>setpagedevice"
+*InputSlot Upper/Tray 1: "<</MediaPosition 2>>setpagedevice"
+*InputSlot Lower/Tray 2: "<</MediaPosition 3>>setpagedevice"
+*CloseUI: *InputSlot
+*OpenUI *Duplex/Two-Sided Printing: PickOne
+*OrderDependency: 10 AnySetup *Duplex
+*DefaultDuplex: None
+*Duplex None/No: "<</Duplex false>>setpagedevice"
+*Duplex DuplexNoTumble/Long Edge Binding: "<</Duplex true/Tumble false>>setpagedevice"
+*Duplex DuplexTumble/Short Edge Binding: "<</Duplex true/Tumble true>>setpagedevice"
+*CloseUI: *Duplex
+*OpenGroup: InstallableOptions/Installable Options
+*OpenUI *OptionDuplexer/Duplexing Unit: Boolean
+*OrderDependency: 10 AnySetup *OptionDuplexer
+*DefaultOptionDuplexer: False
+*OptionDuplexer True/Installed: ""
+*OptionDuplexer False/Not Installed: ""
+*CloseUI: *OptionDuplexer
+*OpenUI *OptionLowerTray/Tray 2: Boolean
+*OrderDependency: 10 AnySetup *OptionLowerTray
+*DefaultOptionLowerTray: False
+*OptionLowerTray True/Installed: ""
+*OptionLowerTray False/Not Installed: ""
+*CloseUI: *OptionLowerTray
+*CloseGroup: InstallableOptions
+*OpenGroup: Special/Special
+*OpenUI *Smoothing/Smoothing: Boolean
+*OrderDependency: 100 DocumentSetup *Smoothing
+*DefaultSmoothing: True
+*Smoothing True/On: "<</cupsInteger0 1>>setpagedevice"
+*Smoothing False/Off: "<</cupsInteger0 0>>setpagedevice"
+*CloseUI: *Smoothing
+*OpenUI *TonerSave/Toner Saving: PickOne
+*OrderDependency: 110 DocumentSetup *TonerSave
+*DefaultTonerSave: None
+*TonerSave None/Disabled: "<</cupsInteger1 0>>setpagedevice"
+*TonerSave Light/Intermediate Save: "<</cupsInteger1 1>>setpagedevice"
+*TonerSave Strong/Strong Save: "<</cupsInteger1 2>>setpagedevice"
+*CloseUI: *TonerSave
+*CloseGroup: Special
+*DefaultFont: Courier
+*Font AvantGarde-Book: Standard "(1.05)" Standard ROM
+*Font AvantGarde-BookOblique: Standard "(1.05)" Standard ROM
+*Font AvantGarde-Demi: Standard "(1.05)" Standard ROM
+*Font AvantGarde-DemiOblique: Standard "(1.05)" Standard ROM
+*Font Bookman-Demi: Standard "(1.05)" Standard ROM
+*Font Bookman-DemiItalic: Standard "(1.05)" Standard ROM
+*Font Bookman-Light: Standard "(1.05)" Standard ROM
+*Font Bookman-LightItalic: Standard "(1.05)" Standard ROM
+*Font Courier: Standard "(1.05)" Standard ROM
+*Font Courier-Bold: Standard "(1.05)" Standard ROM
+*Font Courier-BoldOblique: Standard "(1.05)" Standard ROM
+*Font Courier-Oblique: Standard "(1.05)" Standard ROM
+*Font Helvetica: Standard "(1.05)" Standard ROM
+*Font Helvetica-Bold: Standard "(1.05)" Standard ROM
+*Font Helvetica-BoldOblique: Standard "(1.05)" Standard ROM
+*Font Helvetica-Narrow: Standard "(1.05)" Standard ROM
+*Font Helvetica-Narrow-Bold: Standard "(1.05)" Standard ROM
+*Font Helvetica-Narrow-BoldOblique: Standard "(1.05)" Standard ROM
+*Font Helvetica-Narrow-Oblique: Standard "(1.05)" Standard ROM
+*Font Helvetica-Oblique: Standard "(1.05)" Standard ROM
+*Font NewCenturySchlbk-Bold: Standard "(1.05)" Standard ROM
+*Font NewCenturySchlbk-BoldItalic: Standard "(1.05)" Standard ROM
+*Font NewCenturySchlbk-Italic: Standard "(1.05)" Standard ROM
+*Font NewCenturySchlbk-Roman: Standard "(1.05)" Standard ROM
+*Font Palatino-Bold: Standard "(1.05)" Standard ROM
+*Font Palatino-BoldItalic: Standard "(1.05)" Standard ROM
+*Font Palatino-Italic: Standard "(1.05)" Standard ROM
+*Font Palatino-Roman: Standard "(1.05)" Standard ROM
+*Font Symbol: Special "(001.005)" Special ROM
+*Font Times-Bold: Standard "(1.05)" Standard ROM
+*Font Times-BoldItalic: Standard "(1.05)" Standard ROM
+*Font Times-Italic: Standard "(1.05)" Standard ROM
+*Font Times-Roman: Standard "(1.05)" Standard ROM
+*Font ZapfChancery-MediumItalic: Standard "(1.05)" Standard ROM
+*Font ZapfDingbats: Special "(001.005)" Special ROM
+*% End of rpdl.ppd, 09180 bytes.
Index: platform/cups/rpdl/trunk/rastertorpdl.c
===================================================================
--- platform/cups/rpdl/trunk/rastertorpdl.c (revision 36567)
+++ platform/cups/rpdl/trunk/rastertorpdl.c (revision 36567)
@@ -0,0 +1,662 @@
+/*
+   This software is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
+   to anyone for the consequences of using it or for whether it serves any
+   particular purpose or works at all, unless he says so in writing.  Refer
+   to the GNU General Public License for full details.
+
+   Everyone is granted permission to copy, modify and redistribute
+   this software, but only under the conditions described in the GNU
+   General Public License.  A copy of this license is supposed to have been
+   given to you along with this software so you can know your rights and
+   responsibilities.  It should be in a file named COPYING.  Among other
+   things, the copyright notice and this notice must be preserved on all
+   copies.
+ */
+/* 
+   ESC sequences in RPDL are copied from Ricoh RPDL driver for Ghostscript.
+   That implementation was released under GPL, and covered with
+   copyright (C) 1999, 2000 Norihito Ohmori.
+ */
+#include <cups/cups.h>
+#include <cups/i18n.h>
+#include <cups/raster.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+
+int g_canceled = 0;
+
+static void
+cancel_job(int sig)
+{
+    g_canceled = 1;
+}
+
+static void
+rpdl_init(FILE *out, ppd_file_t *ppd)
+{
+    fputs(
+        "\033\022!@R00\033 "        /* enter RPDL mode */
+        "\0334"                     /* leave graphic mode */
+        "\033\032I"                 /* printer reset */
+        "\033\022YP,2 "             /* select RPDL mode */
+        , out);
+}
+
+static int
+rpdl_set_custom_paper_size(FILE *out, int width, int height /* in pt */)
+{
+    int w, h;
+
+    if (width < height) {
+        w = width;
+        h = height;
+    }
+    else {
+        w = height;
+        h = width;
+    }
+
+    fprintf(out, "\033\022?5%d,%d\033 ",
+            (int) (w * 25.4 / 72.0),
+            (int) (h * 25.4 / 72.0));
+
+    return 1;
+}
+
+struct paper_name_map_t {
+    const char *name;
+    const char *code[2];
+};
+
+static int
+rpdl_set_paper_size_by_name(FILE *out, const char *name)
+{
+    struct paper_name_map_t *pmap;
+    static struct paper_name_map_t paper_name_map[] = {
+        { "A1", { "A1R", "A1" } },
+        { "A2", { "A2R", "A2" } },
+        { "A3", { "A3R", "A3" } },
+        { "A4", { "A4R", "A4" } },
+        { "A5", { "A5R", "A5" } },
+        { "A6", { "A6R", "A6" } },
+
+        { "B4", { "B4R", "B4" } },
+        { "B5", { "B5R", "B5" } },
+        { "B6", { "B6R", "B6" } },
+
+        { "Letter",    { "LTR", "LT" } },    /* Letter */
+        { "Legal",     { "LGR", "LG" } },    /* Legal */
+        { "Statement", { "HLR", "HLT" } },   /* Half Letter / Statement */
+        { "Ledger",    { "DLR", "DLT" } },   /* Ledger / Double Letter */
+
+        { NULL, { NULL, NULL } },
+    };
+
+    for (pmap = paper_name_map; pmap->name; pmap ++) {
+        if (! strcasecmp(pmap->name, name)) {
+            int i;
+
+            for (i = 0; i < 2; i ++) {
+                if (pmap->code[i])
+                    fprintf(out, "\033\02251@%s\033 ", pmap->code[i]);
+            }
+
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+struct paper_size_map_t {
+    short int width;
+    short int height;
+    const char *name;
+};
+
+static int
+rpdl_set_paper_size_by_size(FILE *out, int width, int height /* in pt */)
+{
+    int w, h;
+    struct paper_size_map_t *pmap;
+    static struct paper_size_map_t paper_size_map[] = {
+        { 1684, 2384, "A1" },
+        { 1191, 1684, "A2" },
+        {  842, 1191, "A3" },
+        {  595,  842, "A4" },
+        {  420,  595, "A5" },
+        {  297,  420, "A6" },
+
+        {  729, 1032, "B4" },
+        {  516,  729, "B5" },
+        {  363,  516, "B6" },
+
+        {  612,  792, "Letter"    },
+        {  612, 1008, "Legal"     },
+        {  396,  612, "Statement" },
+        {  792, 1224, "Ledger"    },
+
+        { -1, -1, NULL },
+    };
+
+    if (width < height) {
+        w = width;
+        h = height;
+    }
+    else {
+        w = height;
+        h = width;
+    }
+
+    for (pmap = paper_size_map; pmap->width > 0; pmap ++) {
+        if (w == pmap->width && h == pmap->height) {
+            return rpdl_set_paper_size_by_name(out, pmap->name);
+        }
+    }
+
+    return 0;
+}
+
+static int
+rpdl_set_paper_size(FILE *out, ppd_file_t *ppd, cups_page_header2_t *header)
+{
+    int r;
+
+    r = 0;
+    if (*(header->cupsPageSizeName)) {
+        r = rpdl_set_paper_size_by_name(out, header->cupsPageSizeName);
+        if (r)
+            return r;
+    }
+
+    r = rpdl_set_paper_size_by_size(out, header->PageSize[0],
+                                          header->PageSize[1]);
+    if (r)
+        return r;
+
+    return rpdl_set_custom_paper_size(out, header->PageSize[0],
+                                           header->PageSize[1]);
+}
+
+static void
+rpdl_set_paper_type(FILE *out, int paper_type)
+{
+    fprintf(out, "\033\022?6T,%d\033 ", paper_type);
+}
+
+static int
+rpdl_set_tray(FILE *out, ppd_file_t *ppd, cups_page_header2_t *header)
+{
+    switch (header->MediaPosition) {
+    case 0:     /* auto */
+        fputs("\033\022Z2 ", out);
+        break;
+    case 1:     /* manual tray */
+        fputs("\033\022Z1 "
+              "\033\031M", out);
+        break;
+    default:    /* tray N */
+        fputs("\033\022Z1 ", out);
+        fprintf(out, "\033\031%d", header->MediaPosition);
+    }
+
+    return 0;
+}
+
+static int
+rpdl_set_paper_tray(FILE *out, ppd_file_t *ppd, cups_page_header2_t *header)
+{
+    int r;
+
+    switch (header->MediaPosition) {
+    case 0:     /* auto */
+        /* paper type can not be specified */
+        break;
+    case 1:     /* manual tray */
+        rpdl_set_paper_type(out, 0);
+        break;
+    default:    /* tray N */
+        /* always 15 */
+        rpdl_set_paper_type(out, 15);
+    }
+
+    r = rpdl_set_tray(out, ppd, header);
+
+    if (header->MediaPosition == 0 /* auto */) {
+        r = rpdl_set_paper_size(out, ppd, header);
+    }
+
+    return 0;
+}
+
+static int
+rpdl_setup_page(FILE *out, ppd_file_t *ppd, cups_page_header2_t *header)
+{
+    if (header->cupsBitsPerColor != 1) {
+        fputs("ERROR: BPC is not 1!\n", stderr);
+        return -1;
+    }
+
+    if (header->cupsColorSpace != CUPS_CSPACE_K) {
+        fputs("ERROR: Color Space is not K!\n", stderr);
+        return -1;
+    }
+
+    if (header->Duplex) {
+        fputs("\033\022YA06,2 ", out);      /* duplex: on */
+
+        if (header->Tumble) {
+            fputs("\033\022YA03,1 ", out);  /* top binding */
+        }
+        else {
+            fputs("\033\022YA03,2 ", out);  /* left binding */
+        }
+            /* right binding is 3 */
+    }
+    else {
+        fputs("\033\022YA06,1 ", out);      /* duplex: off */
+    }
+
+    switch (header->HWResolution[0] /* dpi */) {
+    case 1200:
+        fputs(
+            "\033\022YA04,4 "               /* engine           */
+            "\033\022YW,4 "                 /* graphics unit    */
+            "\033\022YI,9 "                 /* unknown unit     */
+            "\033\022#5 "                   /* cartecian unit   */
+            "\033\022Q6 "                   /* spacing unit     */
+            , out);
+        break;
+    case 600:
+        fputs(
+            "\033\022YA04,3 "               /* engine           */
+            "\033\022YW,3 "                 /* graphics unit    */
+            "\033\022YI,8 "                 /* unknown unit     */
+            "\033\022#4 "                   /* cartecian unit   */
+            "\033\022Q5 "                   /* spacing unit     */
+            , out);
+        break;
+    case 400:
+    default:
+        fputs(
+            "\033\022YA04,1 "               /* engine           */
+            "\033\022YW,1 "                 /* graphics unit    */
+            "\033\022YI,7 "                 /* unknown unit     */
+            "\033\022#2 "                   /* cartecian unit   */
+            "\033\022Q4 "                   /* spacing unit     */
+            , out);
+    }
+
+    switch (header->cupsInteger[1]) {
+    case 2:
+        fputs("\033\022YA02,1 ", out);      /* strong toner save */
+        break;
+    case 1:
+        fputs("\033\022YA02,3 ", out);      /* light toner save */
+        break;
+    default:
+        if (header->cupsInteger[0]) {
+            fputs("\033\022YA02,2 ", out);  /* smoothing on */
+        }
+        else {
+            fputs("\033\022YA02,4 ", out);  /* smoothing off */
+        }
+    }
+
+    fputs(
+        "\033\022YQ,2 "                     /* page length - maximum */
+        "\033\022YB,2 "                     /* printable area - maximum */
+        "\033\022YK,1 "                     /* left margin - 0 mm */
+        "\033\022YL,1 "                     /* top margin  - 0 mm */
+        "\033\022YM,1 "                     /* zoom - 100% */
+        , out);        
+
+    rpdl_set_paper_tray(out, ppd, header);
+
+    if (header->PageSize[0] > header->PageSize[1]) {
+        fputs("\033\022D2 ", out);          /* landscape */
+    }
+    else {
+        fputs("\033\022D1 ", out);          /* portrait */
+    }
+
+    /* number of copies */
+    fprintf(out, "\033\022N%d ", header->NumCopies);
+
+    return 0;
+}
+
+static int
+rpdl_finish(FILE *out, ppd_file_t *ppd, cups_page_header2_t *header)
+{
+    if (header->Duplex) {
+        if (header->Tumble) {   /* in case of top binding */
+            fputs("\033\022YA03,2 ", out);  /* reset to left binding */
+        }
+
+        fputs("\033\022YA06,1 ", out);      /* duplex: off */
+    }
+
+    if (header->MediaPosition != 0 /* auto */) {
+        fputs("\033\022Z2 ", out);          /* tray auto */
+        rpdl_set_paper_size_by_name(out, "A4");
+    }
+
+    return 0;
+}
+
+static int
+runlength_line2(const unsigned char *source, int cb_source,
+                unsigned char *buffer, size_t cb_buffer)
+{
+    const unsigned char *ps, *es;
+    unsigned char *pb, *eb;
+    int c = -1;
+
+    ps = source;
+    es = source + cb_source;
+    pb = buffer;
+    eb = buffer + cb_buffer;
+    while (ps < es) {
+        unsigned char nc;
+        int run;
+
+        if (pb >= eb)
+            return -1;
+
+        nc = *pb ++ = *ps ++;
+
+        if (nc != c) {
+            c = nc;
+            continue;
+        }
+
+        /* begin run */
+        run = 0;
+        while (ps < es && run < 255) {
+            if (*ps != c)
+                break;
+
+            ps ++;
+            run ++;
+        }
+
+        if (pb >= eb)
+            return -1;
+
+        *pb ++ = run;
+        c = -1;
+    }
+
+    return pb - buffer;
+}
+
+static void
+trim_line(const unsigned char *source, int cb_source,
+          int *offset, int *length)
+{
+    const unsigned char *sp, *ep;
+
+    ep = source + cb_source;
+    for (sp = source; sp < ep; sp ++)
+        if (*sp != 0)
+            break;
+
+    for (           ; ep > sp; ep --)
+        if (*(ep - 1) != 0)
+            break;
+
+    *offset = sp - source;
+    *length = ep - sp;
+}
+
+static int
+rpdl_render_line(FILE *out, const unsigned char *line_buf, int cb_line,
+                 int x, int y, int use_compression, int use_trim,
+                 unsigned char *comp_buf, int cb_cbuf)
+{
+    int cb_cdat;
+    int of_trim, cb_trim;
+
+    if (use_trim) {
+        trim_line(line_buf, cb_line, &of_trim, &cb_trim);
+    }
+    else {
+        cb_trim = cb_line;
+        of_trim = 0;
+    }
+
+    if (cb_trim == 0)
+        return 0;
+
+    if (use_compression) {
+        cb_cdat = runlength_line2(line_buf + of_trim, cb_trim, comp_buf,
+                                  cb_cbuf);
+        if (cb_cdat < 0)
+            return -1;
+
+        if (cb_cdat == 0)
+            return 0;
+    }
+
+    if (! use_compression || cb_cdat >= cb_trim) {
+        /* non-effective compression => raw */
+        fprintf(out, "\033\022G3,%d,%d,,,%d,%d@",
+                cb_trim * 8, 1, (x + of_trim * 8) * 1, y * 1);
+
+        fwrite(line_buf + of_trim, 1, cb_trim, out);
+    }
+    else {
+        /* effective compression */
+        fprintf(out, "\033\022G3,%d,%d,,4,%d,%d,%d@",
+                cb_trim * 8, 1, (x + of_trim * 8) * 1, y * 1,
+                cb_cdat);
+
+        fwrite(comp_buf, 1, cb_cdat, out);
+    }
+
+    return 1;
+}
+
+#if 0   /* example */
+static int
+rpdl_render_image(FILE *out, const unsigned char *ptr, int width, int height,
+                  int ox, int oy, int use_compression, int use_trim)
+{
+    int cb_line, cb_cbuf;
+    unsigned char *comp_buf;
+    int y;
+
+    cb_line = (width + 7) / 8;
+
+    cb_cbuf = (cb_line * 3 + 1) / 2;
+    comp_buf = malloc(cb_cbuf);
+    if (! comp_buf)
+        return -1;
+
+    for (y = 0; y < height; y ++) {
+        int r;
+
+        r = rpdl_render_line(out, ptr, cb_line, ox, oy + y, use_compression,
+                             use_trim, comp_buf, cb_cbuf);
+
+        if (r < 0) {
+            fputs("ERROR: buffer is small.\n", stderr);
+            return -1;
+        }
+
+        ptr += cb_line;
+    }
+
+    free(comp_buf);
+
+    return 0;
+}
+#endif
+
+int
+main(int argc, char *argv[])
+{
+    int num_options;
+    cups_option_t *options;
+    FILE *out;
+    int fd;
+    cups_raster_t *ras;
+    ppd_file_t *ppd;
+    cups_page_header2_t header;
+    int page, y;
+    int inited;
+#if ! defined(HAVE_SIGSET) && defined(HAVE_SIGACTION)
+    struct sigaction action;
+#endif
+
+    setbuf(stderr, NULL);
+
+    if (argc < 6 || argc > 7) {
+        _cupsLangPrintf(stderr,
+                        _("Usage: %s job-id user title copies options\n"),
+                        argv[0]);
+
+        return 1;
+    }
+
+    num_options = cupsParseOptions(argv[5], 0, &options);
+
+    ppd = ppdOpenFile(getenv("PPD"));
+
+    if (! ppd) {
+        _cupsLangPuts(stderr, _("ERROR: Unable to open PPD file!\n"));
+        return 1;
+    }
+
+    ppdMarkDefaults(ppd);
+    cupsMarkOptions(ppd, num_options, options);
+
+    if (argc >= 7) {
+        fd = open(argv[6], O_RDONLY);
+        if (fd < 0) {
+            _cupsLangPrintf(stderr,
+                            _("ERROR: Unable to open raster file - %s\n"),
+                            strerror(errno));
+
+            return 1;
+        }
+    }
+    else
+        fd = 0;
+
+    ras = cupsRasterOpen(fd, CUPS_RASTER_READ);
+
+    out = stdout;
+
+    g_canceled = 0;
+
+#if defined(HAVE_SIGSET)
+    sigset(SIGTERM, cancel_job);
+#elif defined(HAVE_SIGACTION)
+    memset(&action, 0, sizeof(action));
+    sigemptyset(&action.sa_mask);
+    action.sa_handler = cancel_job;
+    sigaction(SIGTERM, &action, NULL);
+#else
+    signal(SIGTERM, cancel_job);
+#endif
+
+    rpdl_init(out, ppd);
+
+    inited = 0;
+    page   = 0;
+    while (cupsRasterReadHeader2(ras, &header)) {
+        unsigned char *plane;
+        unsigned char *comp_buf;
+        int cb_cbuf;
+
+        if (g_canceled) break;
+
+        page ++;
+        fprintf(stderr, "PAGE: %d %d\n", page, header.NumCopies);
+        _cupsLangPrintf(stderr, _("INFO: Starting page %d...\n"), page);
+
+        if (! inited) {
+            rpdl_setup_page(out, ppd, &header);
+
+            inited = 1;
+        }
+
+        plane = malloc(header.cupsBytesPerLine);
+        if (! plane) {
+            g_canceled = 1;
+            break;
+        }
+
+        cb_cbuf = (header.cupsBytesPerLine * 3 + 1) / 2;
+        comp_buf = malloc(cb_cbuf);
+        if (! comp_buf) {
+            if (plane)
+                free(plane);
+
+            g_canceled = 1;
+            break;
+        }
+
+        for (y = 0; y < header.cupsHeight; y ++) {
+            if (g_canceled) break;
+
+            if (cupsRasterReadPixels(ras, plane,
+                                     header.cupsBytesPerLine) < 1) {
+                break;
+            }
+
+            rpdl_render_line(out, plane, header.cupsBytesPerLine, 0, y,
+                             1, 1, comp_buf, cb_cbuf);
+        }
+
+        if (comp_buf)
+            free(comp_buf);
+
+        if (plane)
+            free(plane);
+
+        _cupsLangPrintf(stderr, _("INFO: Finished page %d...\n"), page);
+
+        fputs("\014", out);     /* Form Feed */
+    }
+
+    if (! g_canceled && header.Duplex && page % 2 == 1) {
+        fputs("\014", out);     /* Form Feed */
+    }
+
+    if (inited)
+        rpdl_finish(out, ppd, &header);
+
+    if (ppd)
+        ppdClose(ppd);
+
+    cupsRasterClose(ras);
+
+    if (fd)
+        close(fd);
+
+    if (out != stdout)
+        fclose(out);
+
+    cupsFreeOptions(num_options, options);
+
+    if (page == 0) {
+        _cupsLangPuts(stderr, _("ERROR: No pages found!\n"));
+
+        return 1;
+    }
+    else {
+        _cupsLangPuts(stderr, _("INFO: Ready to print.\n"));
+
+        return 0;
+    }
+}
+
+/* vi: set expandtab ts=4 sw=4 sts=0 : */
Index: platform/cups/rpdl/trunk/COPYING
===================================================================
--- platform/cups/rpdl/trunk/COPYING (revision 36567)
+++ platform/cups/rpdl/trunk/COPYING (revision 36567)
@@ -0,0 +1,339 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
Index: platform/cups/rpdl/trunk/rpdl.drv
===================================================================
--- platform/cups/rpdl/trunk/rpdl.drv (revision 36567)
+++ platform/cups/rpdl/trunk/rpdl.drv (revision 36567)
@@ -0,0 +1,77 @@
+#include <font.defs>
+#include <media.defs>
+
+DriverType custom
+Filter application/vnd.cups-raster 100 /usr/lib/cups/filter/rastertorpdl
+
+Manufacturer "Ricoh"
+Version 1.0
+ModelName "RPDL Generic"
+
+Font *
+
+MediaSize A1
+MediaSize A2
+MediaSize A3
+*MediaSize A4
+MediaSize A5
+MediaSize A6
+MediaSize B4
+MediaSize B5
+MediaSize B6
+MediaSize Letter
+MediaSize Legal
+MediaSize Statement
+MediaSize Ledger
+
+VariablePaperSize yes
+
+#if 0
+ColorDevice false
+ColorModel Gray/Grayscale w chunky 0
+#endif
+
+*Resolution k 1 0 0 0 "600dpi/600 DPI"
+Resolution k 1 0 0 0 "400dpi/400 DPI"
+Resolution k 1 0 0 0 "1200dpi/1200 DPI"
+
+*InputSlot 0 "Auto/Automatic Selection"
+InputSlot 1 "Manual/Manual Tray"
+InputSlot 2 "Upper/Tray 1"
+InputSlot 3 "Lower/Tray 2"
+
+Group "Special"
+  Option "Smoothing/Smoothing" Boolean DocumentSetup 100
+    *Choice "True/On" "<</cupsInteger0 1>>setpagedevice"
+    Choice "False/Off" "<</cupsInteger0 0>>setpagedevice"
+  Option "TonerSave/Toner Saving" PickOne DocumentSetup 110
+    *Choice "None/Disabled" "<</cupsInteger1 0>>setpagedevice"
+    Choice "Light/Intermediate Save" "<</cupsInteger1 1>>setpagedevice"
+    Choice "Strong/Strong Save" "<</cupsInteger1 2>>setpagedevice"
+
+UIConstraints "*TonerSave *Smoothing True"
+
+Group General
+#if 0
+  Duplex normal
+#else
+  Option "Duplex/Two-Sided Printing" PickOne AnySetup 10
+    *Choice "None/No" "<</Duplex false>>setpagedevice"
+    Choice "DuplexNoTumble/Long Edge Binding"
+           "<</Duplex true/Tumble false>>setpagedevice"
+    Choice "DuplexTumble/Short Edge Binding"
+           "<</Duplex true/Tumble true>>setpagedevice"
+#endif
+
+Group "InstallableOptions/Options Installed"
+  Option "OptionDuplexer/Duplexing Unit" Boolean AnySetup 10
+    Choice "True/Installed" ""
+    *Choice "False/Not Installed" ""
+  Option "OptionLowerTray/Tray 2" Boolean AnySetup 10
+    Choice "True/Installed" ""
+    *Choice "False/Not Installed" ""
+
+UIConstraints "*Duplex *OptionDuplexer False"
+UIConstraints "*OptionLowerTray False *InputSlot Lower"
+
+PCFileName "rpdl.ppd"
Index: platform/cups/rpdl/trunk/Makefile
===================================================================
--- platform/cups/rpdl/trunk/Makefile (revision 36567)
+++ platform/cups/rpdl/trunk/Makefile (revision 36567)
@@ -0,0 +1,31 @@
+
+CUPS_FILTER_DIR=	/usr/lib/cups/filter/
+PPD_DIR=		/usr/share/ppd/custom/
+
+CFLAGS+=		-Wall -O2
+CUPS_CFLAGS=		$(shell cups-config --cflags)
+CUPS_LIBS=		$(shell cups-config --libs) -lcupsimage
+
+all:		build
+
+build:		rastertorpdl rpdl.ppd
+
+clean:
+	rm -f rastertorpdl rpdl.ppd
+	rm -f *.o
+
+install:	install-driver install-ppd
+
+install-driver:	rastertorpdl
+	install -c -t $(CUPS_FILTER_DIR) $<
+
+install-ppd:	rpdl.ppd
+	install -c -t $(PPD_DIR) $<
+
+rastertorpdl:	rastertorpdl.c
+	$(CC) -o $@ $(CFLAGS) $(CUPS_CFLAGS) $< $(CUPS_LIBS)
+
+rpdl.ppd:	rpdl.drv
+	ppdc -d . $<
+
+.PHONY:		all build clean install install-driver install-ppd
Index: platform/cups/rpdl/trunk/TODO.ja
===================================================================
--- platform/cups/rpdl/trunk/TODO.ja (revision 36567)
+++ platform/cups/rpdl/trunk/TODO.ja (revision 36567)
@@ -0,0 +1,7 @@
+
+* Autotool化
+* ページごとにサイズなどのセッティングが異なる場合の対応（必要？）
+* マージン？
+* PJLシーケンスの追加
+* より具体的な機種名をもりこんだPPDの作成
+
