BF [ 2830146 ] Custom print paper is not using dimension units specified

https://sourceforge.net/tracker/?func=detail&aid=2830146&group_id=176962&atid=879332
This commit is contained in:
teo_sarca 2009-07-31 06:43:45 +00:00
parent a8b44e2565
commit 323e667a45
2 changed files with 29 additions and 12 deletions

View File

@ -25,6 +25,7 @@ import java.util.Properties;
import javax.print.attribute.Attribute;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.MediaPrintableArea;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
@ -148,19 +149,28 @@ public class CPaper extends Paper
} // setMediaSize
/**
* Get Media Size
* @return media size
* Get Media Size
* @return media size
*/
//AA Goodwill : Custom Paper Support
public CPaper (double x, double y, boolean landscape,
public CPaper (double x, double y, int units,
boolean landscape,
double left, double top, double right, double bottom)
{
super();
setMediaSize (x,y, landscape);
setMediaSize (x, y, units, landscape);
setImageableArea(left, top, getWidth()-left-right, getHeight()-top-bottom);
}
public void setMediaSize (double x, double y, boolean landscape)
/**
* Set Media Size
* @param x the value to which to set this <code>Paper</code> object's width
* @param y the value to which to set this <code>Paper</code> object's height
* @param units number of microns (see Size2DSyntax.INCH, Size2DSyntax.MM)
* @param landscape true if it's landscape format
* @see Paper#setSize(double, double)
*/
public void setMediaSize (double x, double y, int units, boolean landscape)
{
if (x == 0 || y == 0)
throw new IllegalArgumentException("MediaSize is null");
@ -168,11 +178,12 @@ public class CPaper extends Paper
m_landscape = landscape;
// Get Sise in Inch * 72
double width = x * 72;
double height = y * 72;
final double mult = (double)units / (double)Size2DSyntax.INCH * (double)72;
final double width = x * mult;
final double height = y * mult;
// Set Size
setSize (width, height);
log.fine("Width & Height" + ": " + String.valueOf(x) + "/" + String.valueOf(y) + " - Landscape=" + m_landscape);
log.fine("Width & Height" + ": " + x + "/" + y + " - Landscape=" + m_landscape);
} // setMediaSize
//End Of AA Goodwill

View File

@ -24,6 +24,7 @@ import javax.print.attribute.Size2DSyntax;
import javax.print.attribute.standard.MediaSize;
import javax.print.attribute.standard.MediaSizeName;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.PO;
import org.compiere.model.X_AD_PrintPaper;
import org.compiere.util.CCache;
@ -203,8 +204,10 @@ public class MPrintPaper extends X_AD_PrintPaper
String du = getDimensionUnits();
if (du == null || DIMENSIONUNITS_MM.equals(du))
return Size2DSyntax.MM;
else
else if (DIMENSIONUNITS_Inch.equals(du))
return Size2DSyntax.INCH;
else
throw new AdempiereException("@NotSupported@ @DimensionUnit@ : "+du);
} // getUnits
/**
@ -215,11 +218,14 @@ public class MPrintPaper extends X_AD_PrintPaper
{
//Modify Lines By AA Goodwill : Custom Paper Support
CPaper retValue;
if (getCode().toLowerCase().startsWith("custom")){
retValue = new CPaper (getSizeX().doubleValue(), getSizeY().doubleValue(), isLandscape(),
if (getCode().toLowerCase().startsWith("custom"))
{
retValue = new CPaper (getSizeX().doubleValue(), getSizeY().doubleValue(), getUnitsInt(),
isLandscape(),
getMarginLeft(), getMarginTop(), getMarginRight(), getMarginBottom());
}
else{
else
{
retValue = new CPaper (getMediaSize(), isLandscape(),
getMarginLeft(), getMarginTop(), getMarginRight(), getMarginBottom());
}