Enable barcode scaling on reports
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2236487
This commit is contained in:
parent
020e2b0b9d
commit
40493823be
|
@ -17,7 +17,9 @@
|
|||
package org.compiere.print.layout;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Properties;
|
||||
|
||||
import net.sourceforge.barbecue.Barcode;
|
||||
|
@ -64,6 +66,7 @@ public class BarcodeElement extends PrintElement
|
|||
private Barcode m_barcode = null;
|
||||
/** Allow this field to overflow over next fields */// teo_sarca, [ 1673590 ]
|
||||
private boolean m_allowOverflow = true;
|
||||
private float m_scaleFactor = 1;
|
||||
|
||||
/**
|
||||
* Create Barcode
|
||||
|
@ -147,15 +150,6 @@ public class BarcodeElement extends PrintElement
|
|||
if (mFont != null)
|
||||
m_barcode.setFont(mFont.getFont());
|
||||
}
|
||||
if (item.getMaxWidth() > 0)
|
||||
m_barcode.setBarWidth(item.getMaxWidth());
|
||||
if (item.getMaxHeight() > 0)
|
||||
m_barcode.setBarHeight(item.getMaxHeight());
|
||||
// m_barcode.setResolution(72);
|
||||
//
|
||||
p_width = m_barcode.getWidth();
|
||||
p_height = m_barcode.getHeight();
|
||||
log.fine(type + " height=" + p_height + ", width=" + p_width);
|
||||
}
|
||||
} // createBarcode
|
||||
|
||||
|
@ -184,9 +178,35 @@ public class BarcodeElement extends PrintElement
|
|||
*/
|
||||
protected boolean calculateSize ()
|
||||
{
|
||||
p_width = 0;
|
||||
p_height = 0;
|
||||
if (m_barcode == null)
|
||||
return true;
|
||||
|
||||
p_width = m_barcode.getWidth();
|
||||
p_height = m_barcode.getHeight();
|
||||
|
||||
if (p_width * p_height == 0)
|
||||
return true; // don't bother scaling and prevent div by 0
|
||||
|
||||
m_scaleFactor = 1f;
|
||||
if (p_maxWidth != 0 && p_width > p_maxWidth)
|
||||
m_scaleFactor = p_maxWidth / p_width;
|
||||
if (p_maxHeight != 0 && p_height > p_maxHeight && p_maxHeight/p_height < m_scaleFactor)
|
||||
m_scaleFactor = p_maxHeight / p_height;
|
||||
|
||||
p_width = (float) m_scaleFactor * p_width;
|
||||
p_height = (float) m_scaleFactor * p_height;
|
||||
|
||||
return true;
|
||||
} // calculateSize
|
||||
|
||||
public float getScaleFactor() {
|
||||
if (!p_sizeCalculated)
|
||||
p_sizeCalculated = calculateSize();
|
||||
return m_scaleFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author teo_sarca - [ 1673590 ] report table - barcode overflows over next fields
|
||||
* @return can this element overflow over the next fields
|
||||
|
@ -219,9 +239,23 @@ public class BarcodeElement extends PrintElement
|
|||
int y = (int)location.y;
|
||||
|
||||
try {
|
||||
m_barcode.draw(g2D, x, y);
|
||||
|
||||
int w = m_barcode.getWidth();
|
||||
int h = m_barcode.getHeight();
|
||||
|
||||
// draw barcode to buffer
|
||||
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D temp = (Graphics2D) image.getGraphics();
|
||||
m_barcode.draw(temp, 0, 0);
|
||||
|
||||
// scale barcode and paint
|
||||
AffineTransform transform = new AffineTransform();
|
||||
transform.translate(x,y);
|
||||
transform.scale(m_scaleFactor, m_scaleFactor);
|
||||
g2D.drawImage(image, transform, this);
|
||||
|
||||
} catch (OutputException e) {
|
||||
}
|
||||
}
|
||||
} // paint
|
||||
|
||||
/**
|
||||
|
|
|
@ -1729,10 +1729,14 @@ public class LayoutEngine implements Pageable, Printable, Doc
|
|||
else
|
||||
value = o.toString();
|
||||
BarcodeElement element = new BarcodeElement (value, item);
|
||||
|
||||
|
||||
if (element.isValid())
|
||||
data[row][col] = element;
|
||||
}
|
||||
|
||||
if (data[row][col] != null)
|
||||
((BarcodeElement)data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
|
||||
|
||||
}
|
||||
else if (item.isTypeText() )
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.awt.font.TextAttribute;
|
|||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.util.ArrayList;
|
||||
|
@ -38,6 +39,7 @@ import java.util.Properties;
|
|||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.barbecue.Barcode;
|
||||
import net.sourceforge.barbecue.output.OutputException;
|
||||
|
||||
import org.compiere.model.MQuery;
|
||||
|
@ -1413,7 +1415,31 @@ public class TableElement extends PrintElement
|
|||
else if (printItems[index] instanceof BarcodeElement)
|
||||
{
|
||||
try {
|
||||
((BarcodeElement)printItems[index]).getBarcode().draw(g2D, curX, (int)penY);
|
||||
Barcode barcode = ((BarcodeElement)printItems[index]).getBarcode();
|
||||
if ( barcode != null )
|
||||
{
|
||||
double scale = ((BarcodeElement)printItems[index]).getScaleFactor();
|
||||
if ( scale != 1.0 )
|
||||
{
|
||||
int w = barcode.getWidth();
|
||||
int h = barcode.getHeight();
|
||||
|
||||
// draw barcode to buffer
|
||||
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D temp = (Graphics2D) image.getGraphics();
|
||||
barcode.draw(temp, 0, 0);
|
||||
|
||||
// scale barcode and paint
|
||||
AffineTransform transform = new AffineTransform();
|
||||
transform.translate(curX,penY);
|
||||
transform.scale(scale, scale);
|
||||
g2D.drawImage(image, transform, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
barcode.draw(g2D, curX, (int)penY);
|
||||
}
|
||||
}
|
||||
} catch (OutputException e) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue