diff --git a/build.gradle.kts b/build.gradle.kts index 72ad77e..d50e7ad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { - extra["gradle"] = "8.3" + extra["gradle"] = "8.4" extra["javaVersion"] = JavaVersion.VERSION_11 } @@ -27,7 +27,7 @@ dependencies { testImplementation(libs.junit) } -val dokkaOutputDir = buildDir.resolve("docs") +val dokkaOutputDir = layout.buildDirectory.asFile.get().resolve("docs") tasks { wrapper { gradleVersion = gradle diff --git a/gradle.properties b/gradle.properties index b247afb..451b888 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.pnuema.java -VERSION_NAME=2.3 +VERSION_NAME=2.4 POM_ARTIFACT_ID=barcode POM_NAME=Barcode-Java diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ac72c34..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/local.properties b/local.properties index 97d17a1..ac2ef9c 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Thu Jul 13 11:22:30 CDT 2023 -sdk.dir=/Users/b359923/Library/Android/sdk +#Tue Oct 17 23:18:39 CDT 2023 +sdk.dir=C\:\\Users\\bradb\\AppData\\Local\\Android\\Sdk diff --git a/src/main/java/com/pnuema/java/barcode/Barcode.java b/src/main/java/com/pnuema/java/barcode/Barcode.java index 493710b..5152e06 100644 --- a/src/main/java/com/pnuema/java/barcode/Barcode.java +++ b/src/main/java/com/pnuema/java/barcode/Barcode.java @@ -897,7 +897,7 @@ private Image generateImage() { if (getEncodedType() == EncodingType.PostNet) { //draw half bars in postnet if (getEncodedValue().charAt(pos) == '0') { - g.fillRect(pos * iBarWidth + shiftAdjustment, (ILHeight / 2) + topLabelAdjustment, iBarWidth / 2, (ILHeight / 2) + topLabelAdjustment); + g.fillRect(pos * iBarWidth + shiftAdjustment, (int) (ILHeight - ILHeight * 0.4f) + topLabelAdjustment, iBarWidth / 2, (int) (ILHeight - ILHeight * 0.4f) + topLabelAdjustment); } else { g.fillRect(pos * iBarWidth + shiftAdjustment, topLabelAdjustment, iBarWidth / 2, ILHeight + topLabelAdjustment); } diff --git a/src/main/java/com/pnuema/java/barcode/symbologies/MSI.java b/src/main/java/com/pnuema/java/barcode/symbologies/MSI.java index a8dc274..93c4018 100644 --- a/src/main/java/com/pnuema/java/barcode/symbologies/MSI.java +++ b/src/main/java/com/pnuema/java/barcode/symbologies/MSI.java @@ -27,77 +27,27 @@ private String encodeMSI() { error("EMSI-1: Numeric Data Only"); } - String PreEncoded = getRawData(); - - //get checksum - if (encodedType == EncodingType.MSI_Mod10 || encodedType == EncodingType.MSI_2Mod10) { - String odds = ""; - String evens = ""; - for (int i = PreEncoded.length() - 1; i >= 0; i -= 2) { - odds = PreEncoded.toCharArray()[i] + odds; - if (i - 1 >= 0) - evens = PreEncoded.toCharArray()[i - 1] + evens; - } - - //multiply odds by 2 - odds = String.valueOf(Integer.parseInt(odds) * 2); - - int evensum = 0; - int oddsum = 0; - for (Character c : evens.toCharArray()) { - evensum += Integer.parseInt(c.toString()); - } - for (Character c : odds.toCharArray()) { - oddsum += Integer.parseInt(c.toString()); - } - int mod = (oddsum + evensum) % 10; - int checksum = mod == 0 ? 0 : 10 - mod; - PreEncoded += String.valueOf(checksum); + //Add Checksum + String withChecksum = ""; + + if (encodedType == EncodingType.MSI_Mod10) { + withChecksum = Mod10(getRawData()); + } else if (encodedType == EncodingType.MSI_Mod11) { + withChecksum = Mod11(getRawData()); + } else if (encodedType == EncodingType.MSI_2Mod10) { + withChecksum = Mod10(Mod10(getRawData())); + } else if (encodedType == EncodingType.MSI_Mod11_Mod10) { + withChecksum = Mod10(Mod11(getRawData())); } - if (encodedType == EncodingType.MSI_Mod11 || encodedType == EncodingType.MSI_Mod11_Mod10) { - int sum = 0; - int weight = 2; - for (int i = PreEncoded.length() - 1; i >= 0; i--) { - if (weight > 7) { - weight = 2; - } - sum += Integer.parseInt(String.valueOf(PreEncoded.toCharArray()[i])) * weight++; - } - int mod = sum % 11; - int checksum = mod == 0 ? 0 : 11 - mod; - - PreEncoded += String.valueOf(checksum); - } - - if (encodedType == EncodingType.MSI_2Mod10 || encodedType == EncodingType.MSI_Mod11_Mod10) { - //get second check digit if 2 mod 10 was selected or Mod11/Mod10 - String odds = ""; - String evens = ""; - for (int i = PreEncoded.length() - 1; i >= 0; i -= 2) { - odds = String.valueOf(PreEncoded.toCharArray()[i]) + odds; - if (i - 1 >= 0) { - evens = String.valueOf(PreEncoded.toCharArray()[i - 1]) + evens; - } - } - - //multiply odds by 2 - odds = String.valueOf(Integer.parseInt(odds) * 2); - - int evensum = 0; - int oddsum = 0; - for (Character c : evens.toCharArray()) { - evensum += Integer.parseInt(c.toString()); - } - for (Character c : odds.toCharArray()) { - oddsum += Integer.parseInt(c.toString()); - } - int checksum = 10 - ((oddsum + evensum) % 10); - PreEncoded += String.valueOf(checksum); - } + if (withChecksum.isEmpty()) + error("EMSI-2: Invalid MSI encoding type"); + //add start character String result = "110"; - for (Character c : PreEncoded.toCharArray()) { + + //add encoding + for (Character c : withChecksum.toCharArray()) { result += MSI_Code[Integer.parseInt(c.toString())]; } @@ -107,6 +57,48 @@ private String encodeMSI() { return result; } + private String Mod10(String code) + { + var odds = ""; + var evens = ""; + var chars = code.toCharArray(); + for (var i = code.length() - 1; i >= 0; i -= 2) + { + odds = chars[i] + odds; + if (i - 1 >= 0) + evens = chars[i - 1] + evens; + }//for + + //multiply odds by 2 + odds = String.valueOf(Integer.parseInt(odds) * 2); + + var evensum = 0; + var oddsum = 0; + for (Character c : evens.toCharArray()) + evensum += Integer.parseInt(c.toString()); + for (Character c : odds.toCharArray()) + oddsum += Integer.parseInt(c.toString()); + var mod = (oddsum + evensum) % 10; + var checksum = mod == 0 ? 0 : 10 - mod; + return code + checksum; + } + + private String Mod11(String code) + { + var sum = 0; + var weight = 2; + var chars = code.toCharArray(); + for (var i = code.length() - 1; i >= 0; i--) + { + if (weight > 7) weight = 2; + sum += Integer.parseInt(String.valueOf(chars[i])) * weight++; + }//foreach + var mod = sum % 11; + var checksum = mod == 0 ? 0 : 11 - mod; + + return code + checksum; + } + public String getEncodedValue() { return encodeMSI(); }