예제 #1
0
void
XpValidatePrinterMediaAttrs(XpContextPtr pContext,
			    const XpOidList* valid_trays,
			    const XpOidList* valid_sizes)
{
    const XpOidMediumSS* msss;
    XpOidMediumSS* pool_msss;
    XpOidTrayMediumList* tm;

    pool_msss = XpGetMediumSSAttr(pContext, XPPrinterAttr,
				  xpoid_att_medium_source_sizes_supported,
				  valid_trays, valid_sizes);
    if(0 == XpOidMediumSSCount(pool_msss))
	msss = XpGetDefaultMediumSS();
    else
	msss = pool_msss;
    XpPutMediumSSAttr(pContext, XPPrinterAttr,
		      xpoid_att_medium_source_sizes_supported, msss);

    tm = XpGetTrayMediumListAttr(pContext, XPPrinterAttr,
				 xpoid_att_input_trays_medium,
				 valid_trays, msss);
    XpPutTrayMediumListAttr(pContext, XPPrinterAttr,
			    xpoid_att_input_trays_medium, tm);
    
    XpOidMediumSSDelete(pool_msss);
    XpOidTrayMediumListDelete(tm);
}
예제 #2
0
/*
 * XpGetMaxWidthHeightRes returns into the supplied width and height
 * unsigned short pointers the dimensions in millimeters of the largest
 * supported media for a specific printer.  It looks at the
 * medium-source-sizes-supported attribute (if it exists) to determine
 * the list of possible media, and calls XpGetMediumMillimeters to get the
 * dimensions for each medium.  If the m-s-s-s attribute is not defined,
 * then the dimensions for the na-letter medium is returned.
 *
 * This function also returns the largest resolution in DPI defined in
 * printer-resolutions-supported. If printer-resolutions-supported is not
 * specified, the default is obtained from the passed XpValidatePoolsRec.
 *
 * The passed XpValidatePoolsRec is also used to determine valid values
 * when parsing attribute values.
 */
void
XpGetMaxWidthHeightRes(
		       const char *printer_name,
		       const XpValidatePoolsRec* vpr,
		       float *width,
		       float *height,
		       int* resolution)
{
    const char* value;
    const char* attr_str;
    XpOidMediumSS* pool_msss;
    const XpOidMediumSS* msss;
    int i_mss, i_ds;
    XpOidMediumDiscreteSizeList* ds_list;
    float w, h;
    XpOidCardList* pool_resolutions_supported;
    const XpOidCardList* resolutions_supported;
    int i;
    int res;
    /*
     * get the max medium width and height
     */
    attr_str = XpOidString(xpoid_att_medium_source_sizes_supported);
    value = XpGetPrinterAttribute(printer_name, attr_str);
    pool_msss = XpOidMediumSSNew(value,
				 vpr->valid_input_trays,
				 vpr->valid_medium_sizes);
    if(0 == XpOidMediumSSCount(pool_msss))
	msss = XpGetDefaultMediumSS();
    else
	msss = pool_msss;
    *width = *height = 0;
    for(i_mss = 0; i_mss < XpOidMediumSSCount(msss); i_mss++)
    {
	if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
	   &&
	   xpoid_none != (msss->mss)[i_mss].input_tray)
	{
	    ds_list = (msss->mss)[i_mss].ms.discrete;
	    for(i_ds = 0; i_ds < ds_list->count; i_ds++)
	    {
		if(xpoid_none != (ds_list->list)[i_ds].page_size)
		{
		    XpGetMediumMillimeters((ds_list->list)[i_ds].page_size,
					   &w, &h);
		    if(w > *width) *width = w;
		    if(h > *height) *height = h;
		}
	    }
	}
    }
    XpOidMediumSSDelete(pool_msss);
    /*
     * get the maximum resolution
     */
    attr_str = XpOidString(xpoid_att_printer_resolutions_supported);
    value = XpGetPrinterAttribute(printer_name, attr_str);
    pool_resolutions_supported =
	XpOidCardListNew(value, vpr->valid_printer_resolutions_supported);
    if(0 == XpOidCardListCount(pool_resolutions_supported))
	resolutions_supported = vpr->default_printer_resolutions_supported;
    else
	resolutions_supported = pool_resolutions_supported;
    *resolution = 0;
    for(i = 0; i < XpOidCardListCount(resolutions_supported); i++)
    {
	res = XpOidCardListGetCard(resolutions_supported, i);
	if(res > *resolution) *resolution = res;
    }
    XpOidCardListDelete(pool_resolutions_supported);
}
예제 #3
0
/*
 * XpGetReproductionArea queries the current pool attribute values in
 * order to determine the reproduction area for the currently selected
 * medium.
 *
 * First the current page size (equivalent to current medium) and tray
 * (if specified) is retrieved via XpGetPageSize. The value of the
 * medium-source-sizes-supported attribute is interrogated until a matching
 * entry for the current page size and tray is found. The reproduction
 * area defined for the current entry is converted into an XRectangle
 * using XRectangleFromXpOidArea and returned to the caller.
 *
 * Note: This routine assumes the values found in the passed context's
 *       attributes pools have been validated.
 */
void
XpGetReproductionArea(XpContextPtr pContext,
		      xRectangle *pRect)
{
    XpOid page_size;
    XpOid tray;
    XpOidMediumSS* msss;
    int i_mss, i_ds;
    XpOidMediumDiscreteSizeList* ds_list;
    XpOidArea* repro;
    BOOL done;
    int resolution;
    XpOid orientation;
    /*
     * find the appropriate assured reproduction area for the current
     * tray and page size in the medium-source-sizes-supported attribute.
     */
    msss = XpGetMediumSSAttr(pContext, XPPrinterAttr,
			     xpoid_att_medium_source_sizes_supported,
			     (const XpOidList*)NULL,
			     (const XpOidList*)NULL);
    page_size = XpGetPageSize(pContext, &tray, msss);
    resolution = XpGetResolution(pContext);
    orientation = XpGetContentOrientation(pContext);
    
    memset(pRect, 0, sizeof(xRectangle));

    if(xpoid_none == tray)
    {
	/*
	 * no tray specified; use 1st matching page size
	 */
	for(i_mss = 0, done = xFalse;
	    i_mss < XpOidMediumSSCount(msss) && !done;
	    i_mss++)
	{
	    if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
	       &&
	       xpoid_none != (msss->mss)[i_mss].input_tray)
	    {
		ds_list =  (msss->mss)[i_mss].ms.discrete;
		for(i_ds = 0; i_ds < ds_list->count; i_ds++)
		{
		    if(page_size == (ds_list->list)[i_ds].page_size)
		    {
			repro =
			    &(ds_list->list)[i_ds].assured_reproduction_area;
			XRectangleFromXpOidArea(pRect, repro,
						resolution, orientation);
			done = xTrue;
			break;
		    }
		}
	    }
	}
    }
    else
    {
	/*
	 * tray && page size specified; find matching entry
	 */
	for(i_mss = 0, done = xFalse;
	    i_mss < XpOidMediumSSCount(msss) && !done;
	    i_mss++)
	{
	    if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
	       &&
	       xpoid_none != (msss->mss)[i_mss].input_tray
	       &&
	       (tray == (msss->mss)[i_mss].input_tray
		||
		xpoid_unspecified == (msss->mss)[i_mss].input_tray)
	       )
	    {
		ds_list =  (msss->mss)[i_mss].ms.discrete;
		for(i_ds = 0; i_ds < ds_list->count; i_ds++)
		{
		    if(page_size == (ds_list->list)[i_ds].page_size)
		    {
			repro =
			    &(ds_list->list)[i_ds].assured_reproduction_area;
			XRectangleFromXpOidArea(pRect, repro,
						resolution, orientation);
			if(xpoid_unspecified != (msss->mss)[i_mss].input_tray)
			{
			    /*
			     * exact match on tray takes precendence over
			     * unspecified tray entry in m-s-s-s
			     */
			    done = xTrue;
			}
			break;
		    }
		}
	    }
	}
    }
    XpOidMediumSSDelete(msss);
}
예제 #4
0
/*
 * XpGetPageSize returns the XpOid of the current page size (medium names
 * are page sizes in this implementation) as indicated by the passed
 * context.
 *
 * The relevant input-tray is returned in pTray. This parm must not be
 * NULL. If the input-tray is not indicated or irrelevant, xpoid_none
 * will be returned.
 *
 * This function optionally takes a XpOidMediumSS representation of the
 * medium-source-sizes-supported attribute in order to avoid parsing the
 * string value twice for calling functions that need to parse m-s-s-s
 * anyway (e.g. XpGetReproductionArea). If the caller has no other reason
 * to parse medium-source-sizes-supported, it is recommended that NULL be
 * passed.  This function will obtain medium-source-sizes-supported if it
 * needs to.
 *
 * Note: This routine assumes the values found in the passed context's
 *       attributes pools have been validated.
 */
XpOid
XpGetPageSize(XpContextPtr pContext,
	    XpOid* pTray,
	    const XpOidMediumSS* msss)
{
    XpOid medium;
    /*
     * check to see if default-medium is specified
     */
    medium = XpGetOidAttr(pContext, XPPageAttr, xpoid_att_default_medium,
			  (const XpOidList*)NULL);
    if(medium == xpoid_none)
    {
	/*
	 * default-medium not in page pool; try the document pool
	 */
	medium = XpGetOidAttr(pContext, XPDocAttr, xpoid_att_default_medium,
			      (const XpOidList*)NULL);
    }
    if(medium == xpoid_none)
    {
	/*
	 * default-medium not specified; try default-input-tray
	 */
	*pTray = XpGetOidAttr(pContext, XPPageAttr,
			      xpoid_att_default_input_tray,
			      (const XpOidList*)NULL);
	if(*pTray == xpoid_none)
	{
	    /*
	     * default-input-tray not in page pool; try the document pool
	     */
	    *pTray = XpGetOidAttr(pContext, XPDocAttr,
				  xpoid_att_default_input_tray,
				  (const XpOidList*)NULL);
	}
	if(*pTray != xpoid_none)
	{
	    /*
	     * default-input-tray found; get corresponding medium from
	     * input-trays-medium
	     */
	    XpOidTrayMediumList* input_trays_medium;
	    int i;
	    
	    input_trays_medium =
		XpGetTrayMediumListAttr(pContext, XPPrinterAttr,
					xpoid_att_input_trays_medium,
					(const XpOidList*)NULL,
					(const XpOidMediumSS*)NULL);
	    for(i = 0; i < XpOidTrayMediumListCount(input_trays_medium); i++)
	    {
		if(*pTray == XpOidTrayMediumListTray(input_trays_medium, i))
		{
		    medium = XpOidTrayMediumListMedium(input_trays_medium, i);
		    break;
		}
	    }
	    XpOidTrayMediumListDelete(input_trays_medium);
	}
    }
    else
	*pTray = xpoid_none;
    
    if(medium == xpoid_none)
    {
	XpOidMediumSS* local_msss = (XpOidMediumSS*)NULL;
	int i_mss, i_ds;
	XpOidMediumDiscreteSizeList* ds_list;
	/*
	 * no medium specified; use 1st page size found in
	 * medium-source-sizes-supported
	 */
	if((XpOidMediumSS*)NULL == msss)
	    msss = local_msss =
		XpGetMediumSSAttr(pContext, XPPrinterAttr,
				  xpoid_att_medium_source_sizes_supported,
				  (const XpOidList*)NULL,
				  (const XpOidList*)NULL);
	for(i_mss = 0;
	    i_mss < XpOidMediumSSCount(msss) && xpoid_none == medium;
	    i_mss++)
	{
	    if(XpOidMediumSS_DISCRETE == (msss->mss)[i_mss].mstag
	       &&
	       xpoid_none != (msss->mss)[i_mss].input_tray)
	    {
		ds_list =  (msss->mss)[i_mss].ms.discrete;
		for(i_ds = 0; i_ds < ds_list->count; i_ds++)
		{
		    if(xpoid_none != (ds_list->list)[i_ds].page_size)
		    {
			medium = (ds_list->list)[i_ds].page_size;
			break;
		    }
		}
	    }
	}
	XpOidMediumSSDelete(local_msss);
    }
    return medium;
}
예제 #5
0
static void
XpValidateDocOrPagePool(XpContextPtr pContext,
			XPAttributes pool, /* XPDocAttr or XPPageAttr */
			const XpOidList* attrs_supported,
			const XpValidatePoolsRec* vpr)
{
    /*
     * content-orientation
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_content_orientation))
    {
	XpOidList* content_orientations_supported;
	content_orientations_supported =
	    XpGetListAttr(pContext, XPPrinterAttr,
			  xpoid_att_content_orientations_supported,
			  vpr->valid_content_orientations_supported);
	XpValidateOidAttr(pContext, pool, xpoid_att_content_orientation,
			  content_orientations_supported, xpoid_none);
	XpOidListDelete(content_orientations_supported);
    }
    /*
     * copy-count
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_copy_count))
	XpValidateCardAttr(pContext, pool, xpoid_att_copy_count,
			   (const XpOidCardList*)NULL, 0);
    /*
     * default-printer-resolution
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_default_printer_resolution))
    {
	XpOidCardList* printer_resolutions_supported;
	printer_resolutions_supported =
	    XpGetCardListAttr(pContext, XPPrinterAttr,
			      xpoid_att_printer_resolutions_supported,
			      vpr->valid_printer_resolutions_supported);
	XpValidateCardAttr(pContext, pool,
			   xpoid_att_default_printer_resolution,
			   printer_resolutions_supported, 0);
	XpOidCardListDelete(printer_resolutions_supported);
    }
    /*
     * default-input-tray
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_default_input_tray))
    {
	XpOidTrayMediumList* input_trays_medium;
	const char* value_in;
	XpOid value_tray;
	
	input_trays_medium =
	    XpGetTrayMediumListAttr(pContext, XPPrinterAttr,
				    xpoid_att_input_trays_medium,
				    (const XpOidList*)NULL,
				    (const XpOidMediumSS*)NULL);
	value_in =
	    XpGetStringAttr(pContext, pool, xpoid_att_default_input_tray);
	value_tray = XpOidFromString(value_in);
	if(!XpOidTrayMediumListHasTray(input_trays_medium, value_tray))
	    value_tray = xpoid_none;
	XpPutOidAttr(pContext, pool, xpoid_att_default_input_tray, value_tray);
	XpOidTrayMediumListDelete(input_trays_medium);
    }
    /*
     * default-medium
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_default_medium))
    {
	XpOidMediumSS* msss;
	const char* value_in;
	XpOid value_size;
	
	msss = XpGetMediumSSAttr(pContext, XPPrinterAttr,
				 xpoid_att_medium_source_sizes_supported,
				 (const XpOidList*)NULL,
				 (const XpOidList*)NULL);
	value_in = XpGetStringAttr(pContext, pool, xpoid_att_default_medium);
	value_size = XpOidFromString(value_in);
	if(!XpOidMediumSSHasSize(msss, value_size))
	    value_size = xpoid_none;
	XpPutOidAttr(pContext, pool, xpoid_att_default_medium, value_size);
	XpOidMediumSSDelete(msss);
    }
    /*
     * document-format
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_document_format))
    {
	XpOidDocFmtList* document_formats_supported;
	const char* value_in;
	XpOidDocFmt* document_format;
	const char* value_out;
	
	document_formats_supported =
	    XpGetDocFmtListAttr(pContext, XPPrinterAttr,
				xpoid_att_document_formats_supported,
				vpr->valid_document_formats_supported);
	value_in = XpGetStringAttr(pContext, pool, xpoid_att_document_format);
	document_format = XpOidDocFmtNew(value_in);
	if(XpOidDocFmtListHasFmt(document_formats_supported, document_format))
	    value_out = XpOidDocFmtString(document_format);
	else
	    value_out = XpOidDocFmtString(vpr->default_document_format);
	XpOidDocFmtListDelete(document_formats_supported);
	XpOidDocFmtDelete(document_format);
	XpPutStringAttr(pContext, pool, xpoid_att_document_format, value_out);
	XpOidFree(value_out);
    }
    /*
     * plex
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_plex))
    {
	XpOidList* plexes_supported;
	plexes_supported =
	    XpGetListAttr(pContext, XPPrinterAttr, xpoid_att_plexes_supported,
			  vpr->valid_plexes_supported);
	XpValidateOidAttr(pContext, pool, xpoid_att_plex,
			  plexes_supported, xpoid_none);
	XpOidListDelete(plexes_supported);
    }
    /*
     * xp-listfonts-modes
     */
    if(XpOidListHasOid(attrs_supported, xpoid_att_xp_listfonts_modes))
    {
	XpOidList* xp_listfonts_modes_supported;
	xp_listfonts_modes_supported =
	    XpGetListAttr(pContext, XPPrinterAttr,
			  xpoid_att_xp_listfonts_modes_supported,
			  vpr->valid_xp_listfonts_modes_supported);
	XpValidateListAttr(pContext, pool, xpoid_att_xp_listfonts_modes,
			   xp_listfonts_modes_supported,
			   (const XpOidList*)NULL);
	XpOidListDelete(xp_listfonts_modes_supported);
    }
}