"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/main/java/com/google/zxing/oned/OneDimensionalCodeWriter.java" between
zxing-zxing-3.4.0.tar.gz and zxing-zxing-3.4.1.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.

OneDimensionalCodeWriter.java  (zxing-zxing-3.4.0):OneDimensionalCodeWriter.java  (zxing-zxing-3.4.1)
skipping to change at line 22 skipping to change at line 22
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.zxing.oned; package com.google.zxing.oned;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType; import com.google.zxing.EncodeHintType;
import com.google.zxing.Writer; import com.google.zxing.Writer;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* <p>Encapsulates functionality and implementation that is common to one-dimens ional barcodes.</p> * <p>Encapsulates functionality and implementation that is common to one-dimens ional barcodes.</p>
* *
* @author dsbnatut@gmail.com (Kazuki Nishiura) * @author dsbnatut@gmail.com (Kazuki Nishiura)
*/ */
public abstract class OneDimensionalCodeWriter implements Writer { public abstract class OneDimensionalCodeWriter implements Writer {
private static final Pattern NUMERIC = Pattern.compile("[0-9]+"); private static final Pattern NUMERIC = Pattern.compile("[0-9]+");
@Override @Override
public final BitMatrix encode(String contents, BarcodeFormat format, int width public final BitMatrix encode(String contents, BarcodeFormat format, int width
, int height) , int height) {
throws WriterException {
return encode(contents, format, width, height, null); return encode(contents, format, width, height, null);
} }
/** /**
* Encode the contents following specified format. * Encode the contents following specified format.
* {@code width} and {@code height} are required size. This method may return bigger size * {@code width} and {@code height} are required size. This method may return bigger size
* {@code BitMatrix} when specified size is too small. The user can set both { @code width} and * {@code BitMatrix} when specified size is too small. The user can set both { @code width} and
* {@code height} to zero to get minimum size barcode. If negative value is se t to {@code width} * {@code height} to zero to get minimum size barcode. If negative value is se t to {@code width}
* or {@code height}, {@code IllegalArgumentException} is thrown. * or {@code height}, {@code IllegalArgumentException} is thrown.
*/ */
@Override @Override
public BitMatrix encode(String contents, public BitMatrix encode(String contents,
BarcodeFormat format, BarcodeFormat format,
int width, int width,
int height, int height,
Map<EncodeHintType,?> hints) throws WriterException { Map<EncodeHintType,?> hints) {
if (contents.isEmpty()) { if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents"); throw new IllegalArgumentException("Found empty contents");
} }
if (width < 0 || height < 0) { if (width < 0 || height < 0) {
throw new IllegalArgumentException("Negative size is not allowed. Input: " throw new IllegalArgumentException("Negative size is not allowed. Input: "
+ width + 'x' + height); + width + 'x' + height);
} }
Collection<BarcodeFormat> supportedFormats = getSupportedWriteFormats();
if (supportedFormats != null && !supportedFormats.contains(format)) {
throw new IllegalArgumentException("Can only encode " + supportedFormats +
", but got " + format);
}
int sidesMargin = getDefaultMargin(); int sidesMargin = getDefaultMargin();
if (hints != null && hints.containsKey(EncodeHintType.MARGIN)) { if (hints != null && hints.containsKey(EncodeHintType.MARGIN)) {
sidesMargin = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString() ); sidesMargin = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString() );
} }
boolean[] code = encode(contents); boolean[] code = encode(contents);
return renderResult(code, width, height, sidesMargin); return renderResult(code, width, height, sidesMargin);
} }
protected Collection<BarcodeFormat> getSupportedWriteFormats() {
return null;
}
/** /**
* @return a byte array of horizontal pixels (0 = white, 1 = black) * @return a byte array of horizontal pixels (0 = white, 1 = black)
*/ */
private static BitMatrix renderResult(boolean[] code, int width, int height, i nt sidesMargin) { private static BitMatrix renderResult(boolean[] code, int width, int height, i nt sidesMargin) {
int inputWidth = code.length; int inputWidth = code.length;
// Add quiet zone on both sides. // Add quiet zone on both sides.
int fullWidth = inputWidth + sidesMargin; int fullWidth = inputWidth + sidesMargin;
int outputWidth = Math.max(width, fullWidth); int outputWidth = Math.max(width, fullWidth);
int outputHeight = Math.max(1, height); int outputHeight = Math.max(1, height);
 End of changes. 6 change blocks. 
5 lines changed or deleted 13 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)