[printing-discuss] capabilities

Ben Woodard ben at zork.net
Wed Nov 7 09:22:06 PST 2001


I was sort of waiting for drew to create and announce a mailing list
for capabilities discussion before I launched this volley. However,
I'm impatient and I figured it would take people a couple of days to
migrate over to the new print-cap mailing list. so I thought that I
would begin the discussion here with a submission of a header file to
start with regards to capabilities.  Please think of this as a place
to begin discussion not a pre-defined interface. It is basically a cut
down, flattened out, simplified version of libppd's header file. So
tell me what you think.

#include <stdio.h>
#include <unistd.h>
#include <glib.h>

typedef enum {                // *** UI types ***
    CAP_UI_BOOLEAN,             // True or False option 
    CAP_UI_PICKONE,             // Pick one from a list 
    CAP_UI_PICKMANY             // Pick zero or more from a list
} CapUIType;                  /* used to be cap_ui_t */

typedef enum {                // *** Order dependency sections ***
    CAP_ORDER_ANY,              // Option code can be anywhere in the file 
    CAP_ORDER_DOCUMENT,         // ... must be in the DocumentSetup section 
    CAP_ORDER_EXIT,             // ... must be sent prior to the document 
    CAP_ORDER_JCL,              // ... must be sent as a JCL command 
    CAP_ORDER_PAGE,             // ... must be in the PageSetup section 
    CAP_ORDER_PROLOG            // ... must be in the Prolog section
} CapSectionOrder;            /* used to be cap_section_t */

typedef enum {                // *** Colorspaces ***
    CAP_CS_CMYK = -4,           // CMYK colorspace 
    CAP_CS_CMY,                 // CMY colorspace 
    CAP_CS_GRAY = 1,            // Grayscale colorspace 
    CAP_CS_RGB = 3,             // RGB colorspace 
    CAP_CS_RGBK,                // RGBK (K = gray) colorspace 
    CAP_CS_N                    // DeviceN colorspace
} CapCSType;                  /* used to be cap_cs_t */

#define CAP_TYPE_CHOICE 0x08
#define CAP_TYPE_OPTION 0x07
#define CAP_TYPE_GROUP 0x06
#define CAP_TYPE_CONSTRAINT 0x05
#define CAP_TYPE_SIZE 0x04
#define CAP_TYPE_EMULATOR 0x03
#define CAP_TYPE_PROFILE 0x02
#define CAP_TYPE_FILE 0x01
#define CAP_CHECK_TYPE(obj, otype) (((CapObject *) obj)->id == otype ? TRUE : \
	                            FALSE)
#define CAP_CAST_FAILED(otype)           ((g_log (G_LOG_DOMAIN,      \
                G_LOG_LEVEL_CRITICAL,                                \
                "file %s: line %d (%s): cast to %s failed.",         \
                __FILE__,                                            \
                __LINE__,                                            \
                __PRETTY_FUNCTION__,                                 \
                otype)))
  /* Macros to test an objects type */
#define CAP_IS_CHOICE(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_CHOICE)))
#define CAP_IS_OPTION(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_OPTION)))
#define CAP_IS_GROUP(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_GROUP)))
#define CAP_IS_CONSTRAINT(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_CONSTRAINT)))
#define CAP_IS_SIZE(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_SIZE)))
#define CAP_IS_EMULATOR(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_EMULATOR)))
#define CAP_IS_PROFILE(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_PROFILE)))
#define CAP_IS_FILE(obj) ((CAP_CHECK_TYPE(obj, CAP_TYPE_FILE)))
  /* Macros to cast an object */
#define CAP_CHOICE(obj) ((CAP_IS_CHOICE(obj) ? ((CapChoice *) obj) :   \
                                      (CAP_CAST_FAILED("CapChoice"),   \
                                      NULL)))
#define CAP_OPTION(obj) ((CAP_IS_OPTION(obj) ? ((CapOption *) obj) :   \
                                      (CAP_CAST_FAILED("CapOption"),   \
                                      NULL)))
#define CAP_GROUP(obj) ((CAP_IS_GROUP(obj) ? ((CapGroup *) obj) :     \
                                      (CAP_CAST_FAILED("CapGroup"),   \
                                      NULL)))
#define CAP_CONSTRAINT(obj) ((CAP_IS_CONSTRAINT(obj) ? ((CapConstraint*) obj):\
                                      (CAP_CAST_FAILED("CapConstraint"),\
                                      NULL)))
#define CAP_SIZE(obj) ((CAP_IS_SIZE(obj) ? ((CapSize *) obj) :         \
                                      (CAP_CAST_FAILED("CapSize"),     \
                                      NULL)))
#define CAP_EMULATOR(obj) ((CAP_IS_EMULATOR(obj) ? ((CapEmulator *)    \
                                      obj) :                           \
                                      (CAP_CAST_FAILED("CapEmulator"), \
                                      NULL)))
#define CAP_PROFILE(obj) ((CAP_IS_PROFILE(obj) ? ((CapProfile *)       \
                                      obj) :                           \
                                      (CAP_CAST_FAILED("CapProfile"),  \
                                      NULL)))
#define CAP_FILE(obj) ((CAP_IS_FILE(obj) ? ((CapFile *) obj) :       \
                                      (CAP_CAST_FAILED("CapFile"),   \
                                      NULL)))
/* This is a virtual class.  It should never be instantiated. */ 
typedef struct {
  guint8 id;
} CapObject;

  // Types and structures... version numbererivatives) is governed
typedef struct {		// *** Options ***
    guint8 id;			// Object id

    gboolean conflicted;	// 0 if no conflicts exist, 1 otherwise 
    gboolean emitted;		// 1 already emitted 0 otherwise

    GString *keyword;		// Option keyword name ("PageSize", etc.) 
    GString *defchoice;		// Default option choice 
    GString *text;		// Human-readable text

    CapUIType ui;		// Type of UI option 
    CapSectionOrder section;	// Section for command 
    float order;		// Order number
    GSList *choices;		// should be a GSList of CapChoice objects
} CapOption;			/* was cap_option_t */

typedef struct {		// *** Option choices ***
    guint8 id;			// Object id

    gboolean marked;		// 0 if not selected, 1 otherwise
    GString *choice;		// Computer-readable option name: 41 chars 
    GString *text;		// Human-readable option name: 81 chars
    char *code;			// Code to send for this option 
    CapOption *option;		// Pointer to parent option structure 
} CapChoice;			/* was cap_choice_t */


  /* hrm..  this whole struct should be a GSList... */
typedef struct {		// *** Groups ***
    guint8 id;			// Object id

    GString *text;		// Human-readable group name
    GSList *options;		/* should be a GSList of CapOption objects */
    GSList *subgroups;		// GSList of CapGroups (subgroups)
} CapGroup;			/* was cap_group_t */

typedef struct {		// *** Constraints ***
    guint8 id;			// Object id

    GString *option1;		// First keyword 
    GString *choice1;		// First option/choice (blank for all) 
    GString *option2;		// Second keyword 
    GString *choice2;		// Second option/choice (blank for all) 
} CapConstraint;		/* was cap_const_t */

typedef struct {		// *** Page Sizes ***
    guint8 id;			// Object id

    gboolean marked;		// Page size selected?
    GString *name;		// Media size option 
    float width;		// Width of media in points 
    float length;		// Length of media in points 
    float left;			// Left printable margin in points 
    float bottom;		// Bottom printable margin in points 
    float right;		// Right printable margin in points 
    float top;			// Top printable margin in points 
} CapSize;			/* cap_size_t; */

typedef struct {		// *** Emulators ***
    guint8 id;			// Object id

    GString *name;		// Emulator name 
    char *start;		// Code to switch to this emulation 
    char *stop;			// Code to stop this emulation 
} CapEmulator;		/* was cap_emul_t */

typedef struct {		// *** sRGB Color Profiles ***
    guint8 id;			// Object id

    GString *resolution;	// Resolution or "-" 
    GString *media_type;	// Media type of "-"
    float density;		// Ink density to use 
    float gamma;		// Gamma correction to use 
    float matrix[3][3];		// Transform matrix 
} CapProfile;			/* was cap_profile_t */

typedef struct {		// *** Files ***
    guint8 id;			// Object id

    int language_level;		// Language level of device 
    gboolean color_device;	// 1 = color device, 0 = grayscale 
    gboolean variable_sizes;	// 1 = supports variable sizes,0 = doesn't 
    gboolean accurate_screens;	// 1 = supports accurate screens, 0 = not 
    gboolean contone_only;	// 1 = continuous tone only, 0 = not 
    int landscape;		// -90 or 90 
    int model_number;		// Device-specific model number 
    gboolean manual_copies;	// 1 = Copies done manually, 0 = hardware 
    CapCSType colorspace;	// Default colorspace 
    GSList *patches;		// GSList of char*'s Patch commands to be sent
    // to printer 
    GSList *emulations;		// GSList of CapEmulator's; Emulations and the
    // code to invoke them 
    GString *jcl_begin;		// Start JCL commands 
    GString *jcl_ps;		// Enter PostScript interpreter 
    GString *jcl_end;		// End JCL commands 
    GString *lang_encoding;	// Language encoding 
    GString *lang_version;	// Language version (English, Spanish, etc.) 
    GString *modelname;		// Model name (general) 
    GString *ttrasterizer;	// Truetype rasterizer 
    GString *manufacturer;	// Manufacturer name 
    GString *product;		// Product name (from PS RIP/interpreter) 
    GString *nickname;		// Nickname (specific) 
    GString *shortnickname;	// Short version of nickname

    GSList *groups;		// GSList of CapGroup objects
    GSList *sizes;		// GSList of CapSize objects      

    float custom_min[2];	// Minimum variable page size 
    float custom_max[2];	// Maximum variable page size 
    float custom_margins[4];	// Margins around page

    GSList *consts;		// GSList of CapConstraints
    GSList *fonts;		// GSList of char* 's      
    GSList *profiles;		// GSList of CapProfiles
    GSList *filters;		// GSList of char*'s
} CapFile;			/* used to be: cap_file_t */

CapFile *cap_init(wchar_t *printername);
void cap_end(CapFile* cap);

/* files to use if you just want to read ppd files */
CapFile *ppd_file_new(const char *filename);
CapFile *ppd_file_new_from_filep(FILE * fp);
CapFile *ppd_file_new_from_fd(int fd);

gboolean cap_emit_to_file(CapFile * cap, FILE * fp, CapSectionOrder section);
gboolean cap_emit_to_fd(CapFile * cap, int fd, CapSectionOrder section);

int cap_get_num_conflicts(CapFile * cap);

gboolean cap_check_option_is_marked(CapFile * cap, const char *keyword,
				      const char *option);
void cap_mark_defaults(CapFile * cap);
gint cap_mark_option(CapFile * cap, const char *keyword, const char *option);

CapChoice *cap_find_choice(CapOption * o, const char *option);
CapChoice *cap_find_marked_choice(CapFile * cap, const char *keyword);

CapOption *cap_find_option_by_keyword(CapFile * cap, const char *keyword);

float cap_get_page_length(CapFile * cap, const char *name);
CapSize *cap_get_page_size(CapFile * cap, const char *name);
float cap_get_page_width(CapFile * cap, const char *name);

void cap_debug_dump_cap(CapFile * cap);

/* Constructors for the various classes */
CapChoice *cap_choice_new(CapOption * option, const char *choice,
		    const char *text);
CapOption *cap_option_new(CapGroup * group, const char *name);
CapGroup *cap_group_new(void);
CapConstraint *cap_constraint_new(void);
CapSize *cap_size_new(const char *name);
CapEmulator *cap_emulator_new(void);
CapProfile *cap_profile_new(void);







More information about the printing-discuss mailing list