Skip to content

Commit

Permalink
adding min/max size attributes for DataMatrix component
Browse files Browse the repository at this point in the history
  • Loading branch information
shertage committed Nov 21, 2019
1 parent aad6be0 commit 2d56734
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package net.sf.jasperreports.components.barcode4j;

import java.awt.Dimension;

import org.krysalis.barcode4j.BaselineAlignment;
import org.krysalis.barcode4j.ChecksumMode;
import org.krysalis.barcode4j.HumanReadablePlacement;
Expand Down Expand Up @@ -232,6 +234,49 @@ public void visitDataMatrix(DataMatrixComponent dataMatrix)
{
dataMatrixBean.setShape(SymbolShapeHint.byName(dataMatrix.getShape()));
}

Dimension minSymbolDimension = null;
if(dataMatrix.getMinSymbolWidth() != null)
{
if(dataMatrix.getMinSymbolHeight() != null)
{
minSymbolDimension = new Dimension(dataMatrix.getMinSymbolWidth(), dataMatrix.getMinSymbolHeight());
}
else
{
minSymbolDimension = new Dimension(dataMatrix.getMinSymbolWidth(), dataMatrix.getMinSymbolWidth());
}
}
else if(dataMatrix.getMinSymbolHeight() != null)
{
minSymbolDimension = new Dimension(dataMatrix.getMinSymbolHeight(), dataMatrix.getMinSymbolHeight());
}
if(minSymbolDimension != null)
{
dataMatrixBean.setMinSize(minSymbolDimension);
}

Dimension maxSymbolDimension = null;
if(dataMatrix.getMaxSymbolWidth() != null)
{
if(dataMatrix.getMaxSymbolHeight() != null)
{
maxSymbolDimension = new Dimension(dataMatrix.getMaxSymbolWidth(), dataMatrix.getMaxSymbolHeight());
}
else
{
maxSymbolDimension = new Dimension(dataMatrix.getMaxSymbolWidth(), dataMatrix.getMaxSymbolWidth());
}
}
else if(dataMatrix.getMaxSymbolHeight() != null)
{
maxSymbolDimension = new Dimension(dataMatrix.getMaxSymbolHeight(), dataMatrix.getMaxSymbolHeight());
}
if(maxSymbolDimension != null)
{
dataMatrixBean.setMaxSize(maxSymbolDimension);
}

evaluateBarcodeRenderable(dataMatrix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ public void visitDataMatrix(DataMatrixComponent dataMatrix)
{
startBarcode(dataMatrix);
writeBaseAttributes(dataMatrix);
xmlWriteHelper.addAttribute("shape", dataMatrix.getShape());
xmlWriteHelper.addAttribute(DataMatrixComponent.PROPERTY_SHAPE, dataMatrix.getShape());
xmlWriteHelper.addAttribute(DataMatrixComponent.PROPERTY_MIN_SYMBOL_WIDTH, dataMatrix.getMinSymbolWidth());
xmlWriteHelper.addAttribute(DataMatrixComponent.PROPERTY_MAX_SYMBOL_WIDTH, dataMatrix.getMaxSymbolWidth());
xmlWriteHelper.addAttribute(DataMatrixComponent.PROPERTY_MIN_SYMBOL_HEIGHT, dataMatrix.getMinSymbolHeight());
xmlWriteHelper.addAttribute(DataMatrixComponent.PROPERTY_MAX_SYMBOL_HEIGHT, dataMatrix.getMaxSymbolHeight());
writeBaseContents(dataMatrix);
endBarcode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ public class DataMatrixComponent extends Barcode4jComponent
private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;

public static final String PROPERTY_SHAPE = "shape";
public static final String PROPERTY_MIN_SYMBOL_WIDTH = "minSymbolWidth";
public static final String PROPERTY_MAX_SYMBOL_WIDTH = "maxSymbolWidth";
public static final String PROPERTY_MIN_SYMBOL_HEIGHT = "minSymbolHeight";
public static final String PROPERTY_MAX_SYMBOL_HEIGHT = "maxSymbolHeight";

private String shape;
private Integer minSymbolWidth;
private Integer maxSymbolWidth;
private Integer minSymbolHeight;
private Integer maxSymbolHeight;

@Override
public void receive(BarcodeVisitor visitor)
Expand All @@ -55,13 +63,60 @@ public void setShape(String shape)
{
Object old = this.shape;
this.shape = shape;
getEventSupport().firePropertyChange(PROPERTY_SHAPE,
old, this.shape);
getEventSupport().firePropertyChange(PROPERTY_SHAPE, old, this.shape);
}

public void setShape(SymbolShapeHint shape)
{
setShape(shape == null ? null : shape.getName());
}

public Integer getMinSymbolWidth()
{
return minSymbolWidth;
}

public void setMinSymbolWidth(Integer minSymbolWidth)
{
Object old = this.minSymbolWidth;
this.minSymbolWidth = minSymbolWidth;
getEventSupport().firePropertyChange(PROPERTY_MIN_SYMBOL_WIDTH, old, this.minSymbolWidth);
}

public Integer getMaxSymbolWidth()
{
return maxSymbolWidth;
}

public void setMaxSymbolWidth(Integer maxSymbolWidth)
{
Object old = this.maxSymbolWidth;
this.maxSymbolWidth = maxSymbolWidth;
getEventSupport().firePropertyChange(PROPERTY_MAX_SYMBOL_WIDTH, old, this.maxSymbolWidth);
}

public Integer getMinSymbolHeight()
{
return minSymbolHeight;
}

public void setMinSymbolHeight(Integer minSymbolHeight)
{
Object old = this.minSymbolHeight;
this.minSymbolHeight = minSymbolHeight;
getEventSupport().firePropertyChange(PROPERTY_MIN_SYMBOL_HEIGHT, old, this.minSymbolHeight);
}

public Integer getMaxSymbolHeight()
{
return maxSymbolHeight;
}

public void setMaxSymbolHeight(Integer maxSymbolHeight)
{
Object old = this.maxSymbolHeight;
this.maxSymbolHeight = maxSymbolHeight;
getEventSupport().firePropertyChange(PROPERTY_MAX_SYMBOL_HEIGHT, old, this.maxSymbolHeight);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@
</restriction>
</simpleType>
</attribute>
<attribute name="minSymbolWidth" use="optional" type="integer"/>
<attribute name="maxSymbolWidth" use="optional" type="integer"/>
<attribute name="minSymbolHeight" use="optional" type="integer"/>
<attribute name="maxSymbolHeight" use="optional" type="integer"/>
</extension>
</complexContent>
</complexType>
Expand Down

0 comments on commit 2d56734

Please sign in to comment.