1 /* 2 * Copyright 2008 ZXing authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.zxing; 18 19 import com.google.zxing.aztec.AztecWriter; 20 import com.google.zxing.common.BitMatrix; 21 import com.google.zxing.datamatrix.DataMatrixWriter; 22 import com.google.zxing.oned.CodaBarWriter; 23 import com.google.zxing.oned.Code128Writer; 24 import com.google.zxing.oned.Code39Writer; 25 import com.google.zxing.oned.Code93Writer; 26 import com.google.zxing.oned.EAN13Writer; 27 import com.google.zxing.oned.EAN8Writer; 28 import com.google.zxing.oned.ITFWriter; 29 import com.google.zxing.oned.UPCAWriter; 30 import com.google.zxing.oned.UPCEWriter; 31 import com.google.zxing.pdf417.PDF417Writer; 32 import com.google.zxing.qrcode.QRCodeWriter; 33 34 import java.util.Map; 35 36 /** 37 * This is a factory class which finds the appropriate Writer subclass for the BarcodeFormat 38 * requested and encodes the barcode with the supplied contents. 39 * 40 * @author dswitkin@google.com (Daniel Switkin) 41 */ 42 public final class MultiFormatWriter implements Writer { 43 44 @Override encode(String contents, BarcodeFormat format, int width, int height)45 public BitMatrix encode(String contents, 46 BarcodeFormat format, 47 int width, 48 int height) throws WriterException { 49 return encode(contents, format, width, height, null); 50 } 51 52 @Override encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType,?> hints)53 public BitMatrix encode(String contents, 54 BarcodeFormat format, 55 int width, int height, 56 Map<EncodeHintType,?> hints) throws WriterException { 57 58 Writer writer; 59 switch (format) { 60 case EAN_8: 61 writer = new EAN8Writer(); 62 break; 63 case UPC_E: 64 writer = new UPCEWriter(); 65 break; 66 case EAN_13: 67 writer = new EAN13Writer(); 68 break; 69 case UPC_A: 70 writer = new UPCAWriter(); 71 break; 72 case QR_CODE: 73 writer = new QRCodeWriter(); 74 break; 75 case CODE_39: 76 writer = new Code39Writer(); 77 break; 78 case CODE_93: 79 writer = new Code93Writer(); 80 break; 81 case CODE_128: 82 writer = new Code128Writer(); 83 break; 84 case ITF: 85 writer = new ITFWriter(); 86 break; 87 case PDF_417: 88 writer = new PDF417Writer(); 89 break; 90 case CODABAR: 91 writer = new CodaBarWriter(); 92 break; 93 case DATA_MATRIX: 94 writer = new DataMatrixWriter(); 95 break; 96 case AZTEC: 97 writer = new AztecWriter(); 98 break; 99 default: 100 throw new IllegalArgumentException("No encoder available for format " + format); 101 } 102 return writer.encode(contents, format, width, height, hints); 103 } 104 105 } 106