Compare commits

...

10 commits

Author SHA1 Message Date
4d039a3765
IDEA update 2025-03-13 23:08:01 +01:00
7b2f626049
IDEA update 2025-03-13 23:01:41 +01:00
9f9597b5fb
Read-me added
Histoire de comprendre l’outil.
2025-03-13 23:00:03 +01:00
59443bf51a
Can clean temporary POM 2025-03-13 22:35:05 +01:00
500c19ed9f
IDEA update. 2025-03-13 22:34:31 +01:00
e3a86668c6
IDEA update. 2025-03-13 22:11:26 +01:00
7f6bbaaabd
Can minimize QRCode.
Ça peut être plus carré via `-m`.
2025-03-13 22:10:50 +01:00
c305d24713
Can return QRCode
Une entrée en argument ou via le descripteur entrant retourne un QRCode.
2025-03-13 18:40:53 +01:00
d71983460b
IDEA's update 2025-03-13 17:31:17 +01:00
31ec7f7cdc
Options added
J’ai des options pour… plein de trucs.
Encore des essais.
2025-03-13 17:27:52 +01:00
6 changed files with 257 additions and 23 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@ target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
dependency-reduced-pom.xml
### IntelliJ IDEA ###
.idea/modules.xml

90
.idea/workspace.xml generated
View file

@ -4,12 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="5081cfcb-f2e4-4632-9166-012ebe74b972" name="Changes" comment="Initialization&#10;&#10;Mon mini-projet commence. :-)">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/fr/alnotz/jqrcode/App.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/fr/alnotz/jqrcode/App.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/module-info.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/module-info.java" afterDir="false" />
</list>
<list default="true" id="5081cfcb-f2e4-4632-9166-012ebe74b972" name="Changes" comment="IDEA update" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -19,6 +14,7 @@
<option name="RECENT_TEMPLATES">
<list>
<option value="module-info" />
<option value="Enum" />
</list>
</option>
</component>
@ -29,7 +25,8 @@
<setting file="file://$PROJECT_DIR$/src/main/java/fr/alnotz/jqrcode/App.java" root0="SKIP_INSPECTION" />
</component>
<component name="MavenImportPreferences">
<option name="explicitlyEnabledProfiles" value="dev" />
<option name="explicitlyEnabledProfiles" value="prod" />
<option name="explicitlyDisabledProfiles" value="dev" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 5
@ -73,7 +70,7 @@
<configuration name="App" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="fr.alnotz.jqrcode.App" />
<module name="jqrcode" />
<option name="PROGRAM_PARAMETERS" value="Toto" />
<option name="PROGRAM_PARAMETERS" value="--say Toto" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="fr.alnotz.jqrcode.*" />
@ -107,11 +104,84 @@
<option name="project" value="LOCAL" />
<updated>1741870167870</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="IDEA's update">
<option name="closed" value="true" />
<created>1741883477644</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1741883477644</updated>
</task>
<task id="LOCAL-00003" summary="Can return QRCode&#10;&#10;Une entrée en argument ou via le descripteur entrant retourne un QRCode.">
<option name="closed" value="true" />
<created>1741887660005</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1741887660005</updated>
</task>
<task id="LOCAL-00004" summary="Can minimize QRCode.&#10;&#10;Ça peut être plus carré via `-m`.">
<option name="closed" value="true" />
<created>1741900270392</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1741900270392</updated>
</task>
<task id="LOCAL-00005" summary="IDEA update.">
<option name="closed" value="true" />
<created>1741900287008</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1741900287008</updated>
</task>
<task id="LOCAL-00006" summary="IDEA update.">
<option name="closed" value="true" />
<created>1741901679694</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1741901679694</updated>
</task>
<task id="LOCAL-00007" summary="Can clean temporary POM">
<option name="closed" value="true" />
<created>1741901706222</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1741901706222</updated>
</task>
<task id="LOCAL-00008" summary="IDEA update">
<option name="closed" value="true" />
<created>1741903302257</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1741903302257</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="Initialization&#10;&#10;Mon mini-projet commence. :-)" />
<option name="LAST_COMMIT_MESSAGE" value="Initialization&#10;&#10;Mon mini-projet commence. :-)" />
<MESSAGE value="IDEA's update" />
<MESSAGE value="Can return QRCode&#10;&#10;Une entrée en argument ou via le descripteur entrant retourne un QRCode." />
<MESSAGE value="Can minimize QRCode.&#10;&#10;Ça peut être plus carré via `-m`." />
<MESSAGE value="IDEA update." />
<MESSAGE value="Can clean temporary POM" />
<MESSAGE value="IDEA update" />
<option name="LAST_COMMIT_MESSAGE" value="IDEA update" />
</component>
</project>

24
README.md Normal file
View file

@ -0,0 +1,24 @@
# JQRCode
Petite implémentation de la bibliothèque QRCode Generator développée par Nayuki.
Voir le site du projet : https://www.nayuki.io/page/qr-code-generator-library.
Lapplication est, après paquetage, une archive JAR nommée `jqrcode` et
exécutable comme suit :
```bash
java -jar target/jqrcode --help
```
Elle peut encoder un texte `TEXT` comme argument.
```bash
java -jar target/jqrcode -s $TEXT
```
Si cet argument est `-`, `jqrcode` lit lentrée standard.
```bash
echo $TEXT | java -jar target/jqrcode -s -
```
Pour prendre peu despace mémoire, opter pour le profil Maven `prod`.

30
pom.xml
View file

@ -87,6 +87,36 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>.</directory>
<includes>
<include>dependency-reduced-pom.xml</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -1,10 +1,13 @@
package fr.alnotz.jqrcode;
import io.nayuki.qrcodegen.DataTooLongException;
import io.nayuki.qrcodegen.QrCode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Iterator;
/**
* Hello world!
@ -12,22 +15,123 @@ import java.io.InputStreamReader;
*/
public class App
{
public static void main( String[] args ) throws IOException {
System.out.printf("QRCode version %s.%s\n",
QrCode.MAX_VERSION,
QrCode.MIN_VERSION);
System.out.printf("Size : %s\n", args.length);
if (args.length > 0 ) {
for (String arg: args) {
System.out.printf("Arg1 : %s\n", arg);
}
}
private static final String LICENCE = "jqrcode Copyright© 2025 Alnotz\n" +
"This program comes with ABSOLUTELY NO WARRANTY.\n" +
"This is free software, and you are welcome to redistribute it" +
" under certain\n conditions.\n";
private static final String VERSION = String.format("JQRCode v. 1.0\n" +
"QRCode v. %s.%s\n",
QrCode.MAX_VERSION,
QrCode.MIN_VERSION);
private static final String HELP = """
Usages:
jqrcode (-h | --help)
jqrcode (-V | --version)
jqrcode (-l | --licence)
jqrcode [-m | --minified] (-s | --say)
""";
private static String readInput() throws IOException {
BufferedReader input =
new BufferedReader(new InputStreamReader(System.in));
String text = "";
if (input.ready()) {
System.out.println("Pipe entry :");
for (Object line:input.lines().toArray()){
System.out.printf("%s\n", line);
for (String line: input.lines().toList()){
text += String.format("%s\n", line);
}
}
return text;
}
private static String encode(String input, QRStyle qrstyle) {
String output = "";
QrCode qr = QrCode.encodeText(input, QrCode.Ecc.MEDIUM);
if (qrstyle.equals(QRStyle.NORMAL)) {
for(int x = 0; x < qr.size; x++) {
for(int y = 0; y < qr.size; y++) {
/* █ ▀ ▄ */
output += qr.getModule(x, y) ? "" : " ";
}
output += "\n";
}
} else {
for(int x = 0; x < qr.size-1; x += 2) {
for (int y = 0; y < qr.size; y++) {
if (qr.getModule(x, y) && qr.getModule(x+1, y)) {
output += "";
} else if (qr.getModule(x, y) && !qr.getModule(x+1, y)) {
output += "";
} else if (!qr.getModule(x, y) && qr.getModule(x+1, y)) {
output += "";
} else {
output += " ";
}
}
output += "\n";
}
if (qr.size %2 == 1) {
for (int y = 0; y < qr.size; y++) {
output += qr.getModule(qr.size-1, y) ? "" : " ";
}
output += "\n";
}
}
return output;
}
public static void main( String[] args ) throws IOException {
if (args.length > 0 ) {
final Iterator<String> argsIterator =
Arrays.stream(args).iterator();
QRStyle qrStyle = QRStyle.NORMAL;
while (argsIterator.hasNext()){
String arg = argsIterator.next();
switch (arg) {
case "-h":
case "--help":
System.out.println(HELP);
break;
case "-m":
case "--minified":
qrStyle = QRStyle.MINIFIED;
continue;
case "-s":
case "--say":
if(argsIterator.hasNext()) {
final String TEXT = argsIterator.next();
String output;
try {
if (TEXT.equals("-")) {
output = encode(
readInput(),
qrStyle
);
} else {
output = encode(
TEXT,
qrStyle
);
}
} catch (Exception exception) {
output = "ERROR: Input too long!\n";
}
System.out.print(output);
} else {
System.out.println("'--say' hasn't entry!");
System.exit(1);
}
break;
case "-V":
case "--version":
System.out.print(VERSION);
break;
case "-l":
case "--licence":
System.out.print(LICENCE);
break;
}
System.exit(0);
}
}
}

View file

@ -0,0 +1,5 @@
package fr.alnotz.jqrcode;
public enum QRStyle {
NORMAL, MINIFIED
}