Ejemplo n.º 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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 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);
}
Ejemplo n.º 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;
}