UPCEWriter.java (zxing-zxing-3.4.0) | : | UPCEWriter.java (zxing-zxing-3.4.1) | ||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
* | * | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* 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 java.util.Map; | import java.util.Collection; | |||
import java.util.Collections; | ||||
import com.google.zxing.BarcodeFormat; | import com.google.zxing.BarcodeFormat; | |||
import com.google.zxing.EncodeHintType; | ||||
import com.google.zxing.FormatException; | import com.google.zxing.FormatException; | |||
import com.google.zxing.WriterException; | ||||
import com.google.zxing.common.BitMatrix; | import com.google.zxing.common.BitMatrix; | |||
/** | /** | |||
* This object renders an UPC-E code as a {@link BitMatrix}. | * This object renders an UPC-E code as a {@link BitMatrix}. | |||
* | * | |||
* @author 0979097955s@gmail.com (RX) | * @author 0979097955s@gmail.com (RX) | |||
*/ | */ | |||
public final class UPCEWriter extends UPCEANWriter { | public final class UPCEWriter extends UPCEANWriter { | |||
private static final int CODE_WIDTH = 3 + // start guard | private static final int CODE_WIDTH = 3 + // start guard | |||
(7 * 6) + // bars | (7 * 6) + // bars | |||
6; // end guard | 6; // end guard | |||
@Override | @Override | |||
public BitMatrix encode(String contents, | protected Collection<BarcodeFormat> getSupportedWriteFormats() { | |||
BarcodeFormat format, | return Collections.singleton(BarcodeFormat.UPC_E); | |||
int width, | ||||
int height, | ||||
Map<EncodeHintType, ?> hints) throws WriterException { | ||||
if (format != BarcodeFormat.UPC_E) { | ||||
throw new IllegalArgumentException("Can only encode UPC_E, but got " + for | ||||
mat); | ||||
} | ||||
return super.encode(contents, format, width, height, hints); | ||||
} | } | |||
@Override | @Override | |||
public boolean[] encode(String contents) { | public boolean[] encode(String contents) { | |||
int length = contents.length(); | int length = contents.length(); | |||
switch (length) { | switch (length) { | |||
case 7: | case 7: | |||
// No check digit present, calculate it and add it | // No check digit present, calculate it and add it | |||
int check; | int check; | |||
try { | try { | |||
skipping to change at line 89 | skipping to change at line 80 | |||
checkNumeric(contents); | checkNumeric(contents); | |||
int firstDigit = Character.digit(contents.charAt(0), 10); | int firstDigit = Character.digit(contents.charAt(0), 10); | |||
if (firstDigit != 0 && firstDigit != 1) { | if (firstDigit != 0 && firstDigit != 1) { | |||
throw new IllegalArgumentException("Number system must be 0 or 1"); | throw new IllegalArgumentException("Number system must be 0 or 1"); | |||
} | } | |||
int checkDigit = Character.digit(contents.charAt(7), 10); | int checkDigit = Character.digit(contents.charAt(7), 10); | |||
int parities = UPCEReader.NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkD igit]; | int parities = UPCEReader.NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkD igit]; | |||
boolean[] result = new boolean[CODE_WIDTH]; | boolean[] result = new boolean[CODE_WIDTH]; | |||
int pos = 0; | ||||
pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, true); | int pos = appendPattern(result, 0, UPCEANReader.START_END_PATTERN, true); | |||
for (int i = 1; i <= 6; i++) { | for (int i = 1; i <= 6; i++) { | |||
int digit = Character.digit(contents.charAt(i), 10); | int digit = Character.digit(contents.charAt(i), 10); | |||
if ((parities >> (6 - i) & 1) == 1) { | if ((parities >> (6 - i) & 1) == 1) { | |||
digit += 10; | digit += 10; | |||
} | } | |||
pos += appendPattern(result, pos, UPCEANReader.L_AND_G_PATTERNS[digit], fa lse); | pos += appendPattern(result, pos, UPCEANReader.L_AND_G_PATTERNS[digit], fa lse); | |||
} | } | |||
appendPattern(result, pos, UPCEANReader.END_PATTERN, false); | appendPattern(result, pos, UPCEANReader.END_PATTERN, false); | |||
End of changes. 6 change blocks. | ||||
16 lines changed or deleted | 5 lines changed or added |