Compare commits

...

9 Commits

Author SHA1 Message Date
7bef98a33a update zstd-jnilib to latest
and provide in fetch_dependencies information of latest

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 20:21:31 +01:00
fcda589742 cleanup remove samples 2025-11-02 18:30:07 +01:00
bce0e160d8 don't build build.xml, maintain it manualy
remove antify.sh and related builx.xml target makefile

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 18:10:21 +01:00
36e58808d5 don't depend on sharedrawweb
use directly sharedrawweb java code here

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 18:04:02 +01:00
e78da6ec76 cleanup continued missing files
toolbox related makefiles
remove bootstrapbuild.sh since was for c code not in that project

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 08:46:16 +01:00
3c4b44e837 add missing script coming from unlinked artlog toolbox project
not mandatory but consistent to have all code

Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-02 08:41:53 +01:00
1b0be89766 fix dependencies and BUILD.md for public build
Signed-off-by: philippe lhardy <philippe.lhardy@astrolabe.coop>
2025-11-01 23:35:33 +01:00
180718c36f Merge branch 'pi'
# Conflicts:
#	BUILD.md
#	fetch_dependencies.sh
2025-11-01 23:02:15 +01:00
philippe lhardy
2b050cccda better dependencies fetching
- provide git url for sharedrawweb
2025-11-01 22:57:33 +01:00
46 changed files with 2401 additions and 2428183 deletions

0
.resources.var Normal file
View File

47
4create.makefile Normal file
View File

@@ -0,0 +1,47 @@
PACKAGE?=org.artisanlogiciel.games
MAIN_CLASS?=Main
PACKAGE_DIR=$(subst .,/,$(PACKAGE))
OUT=out
EDITOR=emacs
$(OUT):
mkdir -p $(OUT)
clean:
@find $(PACKAGE_DIR) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null && echo "cleaned classes in source"
@find $(OUT) -name "*.class" -type f -print0|xargs -0 rm 2>/dev/null || echo "nothing to clean"
test:
javac -d $(OUT) $(PACKAGE_DIR)/$(MAIN_CLASS).java
java -cp $(OUT) $(PACKAGE).$(MAIN_CLASS)
run/%: $(OUT)
javac -d $(OUT) $(PACKAGE_DIR)/$(subst run/,,$@).java
java -cp $(OUT) $(PACKAGE)/$(subst run/,,$@)
compile/%:
javac -d $(OUT) $(PACKAGE_DIR)/$(subst compile/,,$@).java
$(PACKAGE_DIR)/%.java:
./generate_new.sh class $(subst .java,,$(subst $(PACKAGE_DIR)/,,$@))
interface/%:
./generate_new.sh interface package_dir=$(PACKAGE_DIR) $(subst interface/,,$@)
$(EDITOR) $(PACKAGE_DIR)/$(subst interface/,,$@).java
work/%: $(PACKAGE_DIR)/$(subst work/,,%).java
$(EDITOR) $<
work: work/$(MAIN_CLASS)
save:
git citool
.PHONY: clean test work work/% run/% save compile/% interface/%
# tried to avoid intermediate file removal : does not work
# .SECONDARY: $(PACKAGE_DIR)/%.java
# this does work : once precious intermediate file is not removed.
.PRECIOUS: $(PACKAGE_DIR)/%.java

55
4java.makefile Normal file
View File

@@ -0,0 +1,55 @@
PROJECT_VERSION=`./debianize.sh getversion`
DISTPREFIX=`./debianize.sh getproject`
DISTJAR=$(DISTPREFIX)-$(PROJECT_VERSION).jar
JAVAC=javac
JAR=jar
all: dist/lib/$(DISTJAR)
getname:
@echo dist/lib/$(DISTJAR)
getjavalibs:
@if [ -d libs ] ; then find libs/ -type f -o -type l -name "*.jar"; fi
dist:
mkdir -p dist
dist/lib/$(DISTJAR): dist
ant dist
clean:
cd java; make clean
rm -f dist/lib/$(DISTPREFIX)*.jar
rm -rf build
cleanall: clean
rm -rf debian
rm -rf deb
rm -rf download
debian:
mkdir debian
deb/%:
mkdir -p deb
touch $@
./debianize.sh create $@
debian/compat:
echo "10" >$@
debian/%:
./debianize.sh create $@ >$@
deb: debian debian/rules debian/control debian/compat debian/changelog deb/javadoc deb/jlibs
dpkg-buildpackage -uc -us
/usr/bin/emacs:
sudo apt-get install emacs
emacsdevenv:
.PHONY: clean all cleanall getname deb emacsdevenv work/% interface/%

View File

@@ -10,7 +10,7 @@ within same directory as this BUILD.md :
``` ```
# ./doit.sh # ./doit.sh
# depends on sharedrawweb for stl export # depends on sharedrawweb for stl export
./fetch_dependencies.sh ./fetch_dependencies.sh use_zstd
ant dist ant dist
``` ```

68
Makefile.4.java Normal file
View File

@@ -0,0 +1,68 @@
PROJECT_VERSION=`./debianize.sh getversion`
DISTPREFIX=`./debianize.sh getproject`
DISTJAR=$(DISTPREFIX)-$(PROJECT_VERSION).jar
JDEE_VERSION=2.4.1
JAVAC=javac
JAR=jar
RHINO_VER=1_7R5
all: dist/lib/$(DISTJAR)
getname:
@echo dist/lib/$(DISTJAR)
dist:
mkdir -p dist
dist/lib/$(DISTJAR): dist
ant dist
clean:
rm -f dist/lib/$(DISTPREFIX)*.jar
rm -rf build
cd java; make clean
cleanall: clean
rm -rf debian
rm -rf deb
rm -rf download
@( [ -d ~/.emacs.d/jdee-$(JDEE_VERSION) ] && echo "DON'T remove installed ~/.emacs.d/jdee-$(JDEE_VERSION). To remove jdee do 'make removejdee'" ) || true
debian:
mkdir debian
deb/%:
mkdir -p deb
touch $@
./debianize.sh create $@
debian/compat:
echo "10" >$@
debian/%:
./debianize.sh create $@ >$@
deb: debian debian/rules debian/control debian/compat debian/changelog deb/javadoc deb/jlibs deb/format
./buildsourcetree.sh
/usr/bin/emacs:
sudo apt-get install emacs
download/jdee-bin-$(JDEE_VERSION).tar.bz2:
mkdir -p download; cd download; wget http://sourceforge.net/projects/jdee/files/jdee/$(JDEE_VERSION)/jdee-bin-$(JDEE_VERSION).tar.bz2
~/.emacs.d/jdee-$(JDEE_VERSION): /usr/bin/emacs download/jdee-bin-$(JDEE_VERSION).tar.bz2
mkdir -p ~/.emacs.d; tar -xjf download/jdee-bin-$(JDEE_VERSION).tar.bz2 -C ~/.emacs.d
echo "(add-to-list 'load-path \"~/.emacs.d/jdee-$(JDEE_VERSION)/lisp\")\n(load \"jde\")" >>~/.emacs.d/init.el
emacsdevenv: ~/.emacs.d/jdee-$(JDEE_VERSION)
removejdee:
rm -rf ~/.emacs.d/jdee-$(JDEE_VERSION)
sed -i -n -e "/^(add-to-list 'load-path \"~\/\.emacs\.d\/jdee-$(JDEE_VERSION)\/lisp\")$$/d" -e "/^(load \"jde\")$$/d" -e"/^.*$$/p" ~/.emacs.d/init.el
download/rhino$(RHINO_VER).zip:
mkdir -p download
cd download; wget https://github.com/mozilla/rhino/releases/download/Rhino$(RHINO_VER)_RELEASE/rhino$(RHINO_VER).zip
.PHONY: clean all cleanall getname deb emacsdevenv removejdee

View File

@@ -34,11 +34,11 @@ and output
* txt labyrinth as text * txt labyrinth as text
* we minetest/luanti world edit format * we minetest/luanti world edit format
===== BUILD ===== ## BUILD
See BUILD.md See BUILD.md
===== INSTALL ===== ## INSTALL
obtain laby.zip directly build or from you own build ( see BUILD above ). obtain laby.zip directly build or from you own build ( see BUILD above ).
@@ -48,11 +48,10 @@ unzip laby.zip
it will create a artloglaby directory. it will create a artloglaby directory.
===== RUN ===== ## RUN
run it on a Linux distribution with : run it on a Linux distribution with :
``` ```
cd artloglaby ; ./laby.sh cd artloglaby ; ./laby.sh
``` ```

View File

@@ -1,12 +0,0 @@
java/
java sources
java/org/artisanlogiciel/games
java sources for package org.artisanlogiciel.games respect of java directory naming convention of files
java/org/artisanlogiciel/games/Main.java
Main Java entry point for this program

View File

@@ -1,23 +0,0 @@
#!/bin/bash
if [[ ! -f configure.ac ]]
then
echo "[ERROR] Missing configure.ac . Please create one " >&2
exit 1
fi
if which autoreconf
then
echo "bootstrap using automake tools"
echo "from configure.ac will generate configure"
autoreconf --install
echo "lauch ./configure && make"
else
echo "[ERROR] Missing autoreconf script from autotools. Please install autotools ( package autotools-dev and autoreconf" >&2
fi

View File

@@ -13,8 +13,7 @@
<!-- Fill me please / todo <!-- Fill me please / todo
see fetch_dependencies see fetch_dependencies
--> -->
<property name="artgraphicslib" value="artgaphics-0.2.0"/> <property name="zstd-jnilib" value="zstd-jni-1.5.7-6"/>
<property name="zstd-jnilib" value="zstd-jni-1.5.2-2"/>
<target name="gather_project_params"> <target name="gather_project_params">
<!-- original source parameter is in project_params project_version --> <!-- original source parameter is in project_params project_version -->
<loadfile property="distversion" srcfile="${basedir}/project_params"> <loadfile property="distversion" srcfile="${basedir}/project_params">
@@ -41,7 +40,7 @@
<target name="compile" depends="init" <target name="compile" depends="init"
description="compile the source " > description="compile the source " >
<!-- Compile the java code from ${src} into ${build} --> <!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${artgraphicslib}.jar:libs/${zstd-jnilib}.jar"> <javac srcdir="${src}" destdir="${build}" includeantruntime="false" classpath="libs/${zstd-jnilib}.jar">
<exclude name="org/artisanlogiciel/games/javafx/*"/> <exclude name="org/artisanlogiciel/games/javafx/*"/>
<compilerarg value="-Xlint:deprecation,unchecked" /> <compilerarg value="-Xlint:deprecation,unchecked" />
</javac> </javac>

76
debianize.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
action=$1
file=$2
maintainer="Artlog <pl@artisanlogiciel.net>"
if [[ $action == getversion ]]
then
source ./project_params
echo $project_version
elif [[ $action == getproject ]]
then
source ./project_params
echo $project_name
elif [[ $action =~ get([_a-z]*)$ ]]
then
getvar=${BASH_REMATCH[1]}
source ./project_params
eval "echo \$$getvar"
elif [[ $action == create ]]
then
source ./project_params
if [[ $file == debian/control ]]
then
cat <<EOF
Source: ${project_name}-java
Priority: extra
Maintainer: $maintainer
Build-Depends: debhelper (>= 7.0.50~), javahelper (>=0.25)
Build-Depends-Indep: default-jdk, default-jdk-doc, libtrove-java, libtrove-java-doc, ant
Standards-Version: ${project_version}
Section: java
Package: ${project_name}-java
Architecture: all
Depends: \${java:Depends}, \${misc:Depends}
Recommends: \${java:Recommends}
Description: Labyrinth generator
Labyrinth generator
Package: ${project_name}-java-doc
Architecture: all
Depends: \${java:Depends}, \${misc:Depends}
Recommends: \${java:Recommends}
Description: Labyrinth generator (documentation)
Labyrinth generator
EOF
elif [[ $file = debian/changelog ]]
then
cat <<EOF
${project_name}-java (${project_version}) unstable; urgency=low
* Initial debian package
-- ${maintainer} $(LANG=C date -R)
EOF
elif [[ $file = debian/rules ]]
then
cat <<EOF
#!/usr/bin/make -f
JAVA_HOME=/usr/lib/jvm/default-java
%:
dh \$@ --with javahelper
EOF
elif [[ $file = deb/javadoc ]]
then
echo "api /usr/share/doc/${project_name}-java/api" >debian/${project_name}-java-doc.javadoc
elif [[ $file = deb/jlibs ]]
then
echo "dist/lib/${project_name}-${project_version}.jar" >debian/${project_name}-java.jlibs
fi
fi

393
doit.sh Executable file
View File

@@ -0,0 +1,393 @@
#!/bin/bash
# entry point for project building / editing / running
# this specific_run is intended to be overriden by specific_doit.sh script if any.
function specific_run()
{
echo "[ERROR] '$1' command is not supported in a generic manner" >&2
}
# within a list of files $1 $2 ... find the first that exists and set variable found_best to it.
find_best()
{
while [[ $# > 0 ]]
do
if [[ -f $1 ]]
then
found_best=$1
return
fi
shift
done
}
# $1 variable $2 value
save_parameter()
{
echo "$1=\"$2\"" >> .params
}
info()
{
if [[ -z $NOJAVA ]]
then
echo "DEV_ENV=$DEV_ENV"
echo "JDK_PATH=$JDK_PATH"
echo "ECLIPSE_PATH=$ECLIPSE_PATH"
echo "PATH=$PATH"
java -version
else
echo "NOJAVA is set to $NOJAVA"
fi
}
setup()
{
if [[ -z $NOJAVA ]]
then
if [[ ! -d java ]]
then
echo "[INFO] Missing java directory." >&2
fi
fi
}
do_code()
{
if [[ -z $NOJAVA ]]
then
background=$1
local jd=()
local id=()
local menu=()
index=0
# find all java source file within current directory and populate jd array with. even if java is a link ( -H option ).
for java_dir in $(find -H java -name '*.java' -exec dirname {} \; | sort -u)
do
index=$((index+1))
id+=($index)
jd+=("$java_dir")
menu+=($index "$java_dir")
done
echo "found ${#jd[@]} java source directories"
if [[ ${#jd[@]} -gt 1 ]]
then
echo "${jd[@]}"
# menu <text> <height> <width> <listheight> <tag[1]> <name[1]> ... <tag[n]> <name[n]>
index_dir=$($DIALOG --menu "Select dir" 20 100 10 ${menu[@]} 3>&1 1>&2 2>&3)
if [[ ! $? ]]
then
echo "[ERROR] $DIALOG --menu did fail when requesting choice over java directories" >&2
exit 1
fi
fi
java_dir=${jd[$((index_dir-1))]}
if [[ ! -d $java_dir ]]
then
echo "$java_dir is not a directory" >&2
return
fi
echo "chose dir $java_dir"
find $java_dir -maxdepth 1 -name '*.java' |
{
local s=()
while read codeline
do
javafile=$(basename "$codeline")
javaclass=${javafile/.java/}
echo "$javafile $javaclass"
s+=("$javaclass" "$codeline")
done
javaclass=$($DIALOG --menu "Edit it" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ -n $javaclass ]]
then
if [[ $background == codebg ]]
then
${EDITOR} $java_dir/$javaclass.java &
else
${EDITOR} $java_dir/$javaclass.java
fi
fi
}
else
echo "NOJAVA set"
fi
}
edit_properties()
{
local property_file=$1
if [[ -f $property_file ]]
then
modified=0
s=()
properties=()
values=()
{
while read codeline
do
if [[ $codeline =~ (^[a-zA-Z_]*)=(.*) ]]
then
property=${BASH_REMATCH[1]}
value=${BASH_REMATCH[2]}
s+=("$property" "$value")
properties+=("$property")
values+=("$value")
fi
done
s+=(exit "Exit")
} < $property_file
while true
do
property=$($DIALOG --menu "Edit '$property_file'" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $property ]]
then
if [[ $property == exit ]]
then
return 1
elif [[ $property == save ]]
then
for (( i=0; i<${prop_len}; i++ ));
do
echo "${properties[$i]}=${values[$i]}"
done >$property_file
return 0
fi
prop_len="${#properties[@]}"
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
init_value=${values[$i]}
fi
done
value=$($DIALOG --inputbox "Enter $property value" 10 80 "$init_value" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
prop_len="${#properties[@]}"
s=()
if [[ "$value" != "$init_value" ]]
then
modified=$(( modified + 1 ))
fi
for (( i=0; i<${prop_len}; i++ ));
do
if [[ ${properties[$i]} == $property ]]
then
values[$i]=$value
fi
s+=("${properties[$i]}" "${values[$i]}")
echo "${properties[$i]}=${values[$i]}"
done
s+=(exit "Exit")
if [[ $modified != 0 ]]
then
s+=(save "Save")
fi
fi
fi
else
return 2
fi
done
else
echo "[ERROR] property_file '$propertyfile' not found" >&2
fi
}
specific_menus=()
if [[ -f ./specificdoit.sh ]]
then
source ./specificdoit.sh
fi
if [[ -f .params ]]
then
source .params
if [[ -n $DIALOG ]]
then
if [[ ! -x $DIALOG ]]
then
echo "[ERROR] DIALOG=$DIALOG dialog tool not executable" >&2
exit 1
fi
fi
fi
LOG_OUTFILE=.log
if [[ -z $DIALOG ]]
then
echo "[INFO] detecting dialog program"
possible_console_gui="whiptail dialog"
for DIALOG in $possible_console_gui
do
DIALOG=$(which $DIALOG)
if [[ -x $DIALOG ]]
then
$DIALOG --menu "Ultra Light IDE" 20 80 2 "select me to validate $DIALOG " justfortest
rc=$?
if [[ $rc != 0 ]]
then
echo "[ERROR] $DIALOG return code $rc : can't use it" >&2
else
break
fi
fi
done
if [[ -z $DIALOG ]]
then
echo "[ERROR] no console gui support (no dialog tool found within $possible_console_gui) => no menus " >&2
echo "[INFO] this can happen under emacs within shell or eshell, please use term then"
exit 1
fi
save_parameter DIALOG "$DIALOG"
fi
possible_editor="emacs vi nano"
for EDITOR in $possible_editor
do
EDITOR=$(which $EDITOR)
if [[ -x $EDITOR ]]
then
break
fi
done
if [[ -z $EDITOR ]]
then
echo "[ERROR] no editor found (within $possible_editor) => no editing " >&2
fi
setup
action=initial
# count successives failures.
failed_commands_count=0
while [[ $action != quit ]]
do
# should detect that dialog failed
if [[ -z $NOJAVA ]]
then
# should be cleaned up from specific laby project targets.
action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" ant "Ant build" run "Run it" ${specific_menus[@]} test "Test it" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" create "Create a new class" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3)
else
action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 readme "Read me" clean "Clean All" run "Run it" test "Test it" ${specific_menus[@]} code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" info "Info" logs "Logs" quit "Quit" 3>&1 1>&2 2>&3)
fi
rc=$?
if [[ $rc == 0 ]]
then
failed_commands_count=0
else
failed_commands_count=$(( failed_commands_count + 1 ))
fi
if (( $failed_commands_count > 10 ))
then
echo "[ERROR] more than 10 successive failures ( $failed_commands_count > 10 )" >&2
echo "[INFO] Check if your environment supports $DIALOG"
action=quit
fi
if [[ $action == run ]]
then
if [[ -z $NOJAVA ]]
then
echo "run it"
{
source ./project_params
javalibs=$(make -f ${JAVA_MAKEFILE} getjavalibs|awk '{ printf "%s:",$1 }')
mainlib=$(make -f ${JAVA_MAKEFILE} getname)
javarun="java -cp $mainlib:$javalibs $project_mainclass"
echo $javarun
$javarun
}
else
make
fi
elif [[ $action == ant ]]
then
make -f ${JAVA_MAKEFILE} clean
make -f ${JAVA_MAKEFILE}
ant compile >>.log 2>&1
elif [[ $action == clean ]]
then
if [[ -z $NOJAVA ]]
then
make -f ${JAVA_MAKEFILE} clean
pushd java
make clean
popd
else
make clean
fi
elif [[ $action == test ]]
then
if [[ -z $NOJAVA ]]
then
echo "test it"
pushd java
make display
popd
else
make test
fi
elif [[ $action == deb ]]
then
make -f ${JAVA_MAKEFILE} deb
elif [[ $action =~ code ]]
then
do_code $action
elif [[ $action == readme ]]
then
found_best=
find_best README README.md
if [[ -n $found_best ]]
then
$DIALOG --textbox $found_best 40 80 --scrolltext
else
echo "no README or README.md found" >&2
fi
elif [[ $action == properties ]]
then
edit_properties project_params
elif [[ $action == create ]]
then
newclass=$($DIALOG --inputbox "Enter new class name" 10 80 "NewClass" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]]
then
if [[ -n $newclass ]]
then
MAIN_CLASS=Main PACKAGE=$(./debianize.sh getproject_mainpackage) make -f 4create.makefile work/$newclass
fi
fi
elif [[ $action == info ]]
then
infos=$(mktemp)
info >$infos
$DIALOG --textbox $infos 40 80 --scrolltext
rm $infos
elif [[ $action == logs ]]
then
if [[ -f .log ]]
then
$DIALOG --textbox .log 40 80 --scrolltext
fi
elif [[ $action == quit ]]
then
echo "[INFO] quit requested"
else
specific_run $action
fi
done

137
eclipse_env.sh Executable file
View File

@@ -0,0 +1,137 @@
#!/bin/bash
# for the story this comes from a JavaFX training i attended
usage()
{
cat <<EOF
Usage $0:
setup_dev_env: create file devenv_params with reference over jdk and eclipse path
any other argument is an error
no argument => launch eclipse
EOF
}
create_dev_params()
{
if [[ -e devenv_params ]]
then
echo " devenv_params already exists"
exit 1
# could update this way
# source devenv_params
else
if [[ -z $DEV_ENV ]]
then
echo "[ERROR] DEV_ENV $DEV_ENV not set, call setup_eclipse_dir from this '$0' script"
exit 1
fi
cat >devenv_params <<EOF
DEV_ENV=$DEV_ENV
JDK_PATH=$JDK_PATH
ECLIPSE_PATH=$ECLIPSE_PATH
EOF
fi
}
setup_eclipse_dir()
{
if [[ -e devenv_params ]]
then
source devenv_params
else
echo "[WARNING] Use some defaults for devenv_params"
echo "[INFO] please adapt them. Current setup should be compatible with 'sudo snap install eclipse --classic' setup"
DEV_ENV=~$(pwd)/devel_tools
JDK_PATH=/usr/lib/jvm/java-11-openjdk-amd64
ECLIPSE_PATH=$(dirname $(which eclipse))
fi
}
# Not tested written after install ...
setup_eclipse()
{
# current list of TGZ got from oracle (tm)
TGZ_LIST="eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz javafx_scenebuilder-2_0-linux-x64.tar.gz jdk-8u74-linux-x64.tar.gz"
}
check_eclipse()
{
if [[ -z $JDK_PATH ]]
then
echo "[ERROR] Missing JDK_PATH, either devenv_params is wrong or missing" >&2
exit 1
fi
if [[ -z $ECLIPSE_PATH ]]
then
echo "[ERROR] Missing ECLIPSE_PATH, either devenv_params is wrong or missing" >&2
exit 1
fi
if [[ ! -d $JDK_PATH ]]
then
echo "[ERROR] Missing JDK_PATH '$JDK_PATH'" >&2
fi
if [[ ! -d $ECLIPSE_PATH ]]
then
ls -la ${DEV_ENV}
echo "[ERROR] Missing ECLIPSE_PATH '$ECLIPSE_PATH'" >&2
exit 1
fi
}
# not yet used ...
create_sandbox()
{
mkdir sandbox
}
check_java_version() {
local expected_version='1.8.0'
if java -version 2>&1 | grep "$expected_version"
then
if javac -version 2>&1 | grep "$expected_version"
then
$*
else
echo "[ERROR] Wrong javac version expected $expected_version" >&2
fi
else
echo "[ERROR] Wrong java version expected $expected_version" >&2
fi
}
# overrides PATH with JDK_PATH ECLIPSE_PATH
# and check java is the right one to launch eclipse
run_in_sandbox()
{
PATH=$JDK_PATH/bin/:$JDK_PATH/jre/bin/:$ECLIPSE_PATH:$PATH
export PATH
[[ -n $check_version ]] && check_java_version
}
while [[ $# > 0 ]]
do
case $1 in
setup_dev_env)
setup_eclipse_dir
create_dev_params
exit 0
;;
*)
echo "[ERROR] Unrecognized argument '$1'" >&2
usage
exit 1
;;
esac
shift 1
done
setup_eclipse_dir
check_eclipse
run_in_sandbox eclipse -data $(pwd)/workspace

View File

@@ -10,6 +10,12 @@ toolsdir=$(pwd)
source metascript.sh source metascript.sh
popd >/dev/null popd >/dev/null
usage() {
cat <<EOF
$0 use_jackson|use_zstd|use_artgraphic
EOF
}
fetch_jackson_databind() fetch_jackson_databind()
{ {
lib_jackson_databind=jackson-databind-${libversion_jackson_databind}.jar lib_jackson_databind=jackson-databind-${libversion_jackson_databind}.jar
@@ -24,19 +30,29 @@ fetch_jackson_databind()
fetch_zstd-jni() fetch_zstd-jni()
{ {
# echo "compiled from https://github.com/luben/zstd-jni commit 54d3d50c16d96bd8a30e2d4c0a9648001a52d6f9" # echo "compiled from https://github.com/luben/zstd-jni commit 54d3d50c16d96bd8a30e2d4c0a9648001a52d6f9"
# had to hack through jar generation ... # had to hack through jar generation ...
# cp ~/artisanlogiciel/ext_projects/java/zstd-jni/target/zstd-jni-1.5.2-2.jar . # cp ~/artisanlogiciel/ext_projects/java/zstd-jni/target/zstd-jni-1.5.2-2.jar .
maven_repo=https://repo1.maven.org/maven2/
package_path=com/github/luben/zstd-jni/
# https://repo1.maven.org/maven2/maven-metadata.xml
latest=$(curl -s ${maven_repo}${package_path}maven-metadata.xml | xmllint --xpath 'string(metadata/versioning/latest)' -)
log_info "latest version : $latest"
zstdjni=$(xmllint --xpath 'string(/project/property[@name="zstd-jnilib"]/@value)' build.xml)
if [[ -n $zstdjni ]]
then
$defer pushd libs $defer pushd libs
$metarun wget https://repo1.maven.org/maven2/com/github/luben/zstd-jni/${libversion_zstdjni}/zstd-jni-${libversion_zstdjni}.jar libversion_zstdjni=${zstdjni/zstd-jni-}
$metarun curl ${maven_repo}${package_path}${libversion_zstdjni}/${zstdjni}.jar -o ${zstdjni}.jar
$defer popd $defer popd
else
log_error 'no /project/property[@name="zstd-jnilib"]/@value) found in build.xml'
fi
} }
# HARDCODED START # HARDCODED START
libversion_zstdjni=1.5.2-2
libversion_jackson_databind=2.12.0 libversion_jackson_databind=2.12.0
sharedrawweb_git_url="ssh://git@www4.artisanlogiciel.net:2023/home/git/artisanlogiciel/code/sharedrawweb" sharedrawweb_git_url="https://framagit.org/artlog/sharedrawweb.git"
libversion_artgaphic=0.2.0 libversion_artgaphic=0.2.0
# HARDCODED END # HARDCODED END
lib_artgaphic=artgaphics-${libversion_artgaphic}.jar lib_artgaphic=artgaphics-${libversion_artgaphic}.jar
@@ -52,7 +68,10 @@ do
use_jackson=$1 use_jackson=$1
;; ;;
use_zstd) use_zstd)
use_zstd=1 use_zstd=$1
;;
use_artgraphic)
use_artgraphic=$1
;; ;;
*) *)
parsemetaarg "$1" parsemetaarg "$1"
@@ -62,26 +81,29 @@ do
done done
if [[ ! -d sharedrawweb ]]
then
log_error "expected a sharedrawweb project parent ( for exports ). Please clone related project."
log_info "git clone $sharedrawweb_git_url sharedrawweb"
fi
if [[ ! -d libs ]] if [[ ! -d libs ]]
then then
$metarun mkdir libs $metarun mkdir libs
fi fi
if [[ ! -e libs/$lib_artgaphic ]] if [[ -n $user_artgraphic ]]
then then
lib_artgaphic_source_file=../sharedrawweb/dist/lib/$lib_artgaphic if [[ ! -d sharedrawweb ]]
then
log_error "expected a sharedrawweb project parent ( for exports ). Please clone related project."
log_info "git clone $sharedrawweb_git_url sharedrawweb"
fi
if [[ ! -e libs/$lib_artgaphic ]]
then
lib_artgaphic_source_file=sharedrawweb/dist/lib/$lib_artgaphic
if [[ -f $lib_artgaphic_source_file ]] if [[ -f $lib_artgaphic_source_file ]]
then then
# ../ since libs is one level below current project # ../ since libs is one level below current project
$metarun ln -s ../$lib_artgaphic_source_file libs/ $metarun ln -s ../$lib_artgaphic_source_file libs/
else else
log_error "Missing $lib_artgaphic_source_file. It is require to build it sharedrawweb project first" log_error "Missing $lib_artgaphic_source_file"
log_info "It is required to build sharedrawweb project first"
fi
fi fi
fi fi

209
generate_new.sh Executable file
View File

@@ -0,0 +1,209 @@
#!/bin/bash
# generate empty templates or add functions given a defined language
usage()
{
head -n 2
}
generate_java_class()
{
cat <<EOF >$JAVA_FILE
package $PACKAGE;
/**
$CLASS was autogenerated by $TOOLP
**/
public $ctype $CLASS
{
Object param;
$CLASS(Object param)
{
this.param=param;
}
void method()
{
System.out.println("Method of $PACKAGE.$CLASS");
}
public static void main(String args[]) {
if ( args.length > 1 )
{
$CLASS instance=new $CLASS(args[1]);
instance.method();
}
else
{
System.err.println("Missing argument for $CLASS");
}
}
}
EOF
}
generate_java_interface()
{
cat <<EOF >$JAVA_FILE
package $PACKAGE;
/**
$CLASS was autogenerated by $TOOLP
**/
public $ctype $CLASS
{
/**
@return X
*/
int getX();
/**
@return Y
*/
int getY();
}
EOF
}
add_new_c_main()
{
cat <<EOF >>$C_FILE
# autogenerated by $TOOLP
int main(int argc, char **argv)
{
todo(\"Code this\");
return 0;
}
EOF
}
add_new_c_function()
{
echo "[INFO] add new c function $FUNCTION in h_file=$H_FILE and c_file=$C_FILE"
if [[ $FUNCTION == main ]]
then
add_new_c_main
else
cat <<EOF >>$H_FILE
# autogenerated by $TOOLP
int $FUNCTION();
EOF
cat <<EOF >>$C_FILE
# autogenerated by $TOOLP
int $FUNCTION(){
todo(\"Code this $FUNCTION\");
return -2;
}
EOF
fi
}
#TODO : support "like=" to copy/renaming an existing class
TOOLP="$0 $*"
ctype=class
genlang=java
while [[ $# > 0 ]]
do
case $1 in
class|interface)
ctype=$1
;;
package=*)
PACKAGE=${1/package=/}
;;
package_dir=*)
PACKAGE_DIR=${1/package=/}
PACKAGE=${PACKAGE//\//\.}
;;
genlang=*)
genlang=${1/genlang=/}
;;
class=*)
CLASS=${1/class=/}
;;
function=*)
FUNCTION=${1/function=/}
;;
c_file=*)
C_FILE=${1/c_file=}
;;
h_file=*)
H_FILE=${1/h_file=}
;;
*)
if [[ -z $CLASS ]]
then
CLASS=${1}
echo "[INFO] setting class=$CLASS" >&2
else
echo "[ERROR] unrecognized parameter $1" >&2
fi
;;
esac
shift 1
done
if [[ $genlang == java ]]
then
if [[ -z $PACKAGE ]]
then
echo "[INFO] obtain package name from project settings"
PACKAGE=$(./debianize.sh getproject_mainpackage)
if [[ -z $PACKAGE ]]
then
echo "[ERROR] can't find project_mainpackage" >&2
exit 1
fi
fi
if [[ -z $CLASS ]]
then
echo "[ERROR] Missing class" >&2
exit 1
fi
PACKAGE_DIR=${PACKAGE//\./\/}
if [[ ! -d $PACKAGE_DIR ]]
then
echo "Missing $PACKAGE_DIR" >&2
exit 1
fi
JAVA_FILE=$PACKAGE_DIR/$CLASS.java
if [[ -e $JAVA_FILE ]]
then
echo "[ERROR] $JAVA_FILE already exists" >&2
exit 1
else
if [[ $ctype == class ]]
then
generate_java_class
else
generate_java_interface
fi
fi
echo "$JAVA_FILE generated"
elif [[ $genlang == c ]]
then
if [[ -z $H_FILE ]]
then
H_FILE=c/genauto.h
fi
if [[ -z $C_FILE ]]
then
C_FILE=c/genauto.c
fi
add_new_c_function
else
echo "[ERROR] language genlang=$genlang NOT supported" >&2
usage
fi

View File

@@ -0,0 +1,92 @@
package org.artisanlogiciel.compression;
import java.io.DataInputStream;
import java.io.OutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.artisanlogiciel.graphics.SvgWriter;
import org.artisanlogiciel.graphics.Drawing;
/**
* Very simple utility to convert from .imc to svg.
*
* TODO : could be more clever and not load full image into memory to save it afterwards ( for very small embedded systems ).
*/
public class Main
{
Drawing mLocalImage;
public static void main(String[] args) {
Main m = new Main();
if ( args.length > 1 )
{
m.loadExpanded(args[0]);
try {
File out = new File(args[1]);
if (out.exists())
{
System.err.println("File already exists" + out + " Not overriding it");
}
else
{
//m.saveSvg(new DataOutputStream(new FileOutputStream(out)));
FileOutputStream fout = new FileOutputStream(out);
m.saveSvg(fout);
fout.flush();
fout.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
System.out.println("Very simple utility to convert from .imc to svg.");
System.out.println("first argument is compressed file, second is svg output file (should not already exist)");
}
}
public void saveSvg(OutputStream s)
throws IOException
{
SvgWriter writer = new SvgWriter(mLocalImage.getLines());
writer.writeTo(s);
}
public void saveKompressed( String ref) {
try {
FileOutputStream fi = new FileOutputStream( ref);
mLocalImage.saveLinesKompressed( new DataOutputStream( fi));
}
catch( java.io.FileNotFoundException fnfe)
{
fnfe.printStackTrace(System.err);
}
catch ( java.io.IOException ioe) {
ioe.printStackTrace(System.err);
}
}
public void loadExpanded( String ref) {
try {
FileInputStream fi = new FileInputStream( ref);
mLocalImage = new Drawing();
mLocalImage.loadLinesExpanded( new DataInputStream( fi));
}
catch( java.io.FileNotFoundException fnfe) {
fnfe.printStackTrace(System.err);
}
catch ( java.io.IOException ioe) {
ioe.printStackTrace(System.err);
}
}
}

View File

@@ -0,0 +1,146 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.compression.graphics;
/*
simple class to read bitfields
@see BitFieldWriter
@author Philippe Lhardy
*/
import java.io.*;
class BitFieldReader {
// size of nextWord
final int dataSize = 32;
/* offset of next bit to be read in current word
should ensure bitOffset < dataSize
*/
private int bitOffset = 0;
/* word used waiting to be fully read
dataSize is bit size of currentWord
currentWord is part of word read that begins at bitOffset.
*/
private int currentWord = 0;
private DataInputStream inputStream;
/* value returned is an int between 0 and 2^bits-1 */
public int read( int bits) throws java.io.IOException {
int field = 0;
int head = 0;
// a new word is needed
if ( bitOffset == 0 ) {
nextWord();
}
// if more bits needed that word currently used.
if ( bits + bitOffset > dataSize) {
// warning recursive call ( not terminal )
int bitsize = dataSize - bitOffset;
head = read( dataSize - bitOffset);
// current word had entirely been read, need a new one
// don't do that... nextWord() will be done by next read...
field = read( bits - bitsize);
// reconstruct all
// more significant bits in first word, least in last
field = field | ( head << (bits - bitsize));
}
else {
// terminal part do the job
if ( bits == dataSize) {
// special case to keep sign
field = currentWord;
currentWord = 0;
bitOffset = 0;
}
else {
field = ( currentWord >> ( dataSize - bits) )
& ( 0x7fffffff >> ( dataSize - 1 - bits) );
// bits are read then remove them from currentWord
currentWord <<= bits;
bitOffset = ( bitOffset + bits ) % dataSize;
/*
System.out.println( "size " + Integer.toString(bits)
+ " value " + Integer.toString(field)
+ " offset " + Integer.toString(bitOffset)
+ " currentWord " + Integer.toString( currentWord)
);
*/
}
}
return field;
}
private int getInt( byte[] pBytes)
{
long field = 0;
field = pBytes[0]<<24 | pBytes[1]<<16 | pBytes[2]<<8 | pBytes[3];
return (int) field;
}
/**
* doesn't work correctly as readInt
*/
private int readInt()
throws IOException
{
byte bytes[]=new byte[4];
int nr=0;
int index = 0;
/* read at least 4 bytes */
while ( ( nr != -1) && ( index < 4 ) )
{
nr = inputStream.read( bytes, index, 4 - index);
index +=nr;
}
return getInt( bytes);
}
private void nextWord() throws java.io.IOException {
// read next word
// currentWord = readInt();
currentWord= inputStream.readInt();
bitOffset = 0;
}
/*
go to next entire word.
*/
public void padToWord() throws java.io.IOException {
if ( bitOffset != 0) {
nextWord();
}
}
/* set InputStream */
public void setInputStream( InputStream input) {
inputStream = new DataInputStream(input);
}
}

View File

@@ -0,0 +1,125 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.compression.graphics;
/*
simple class to write bitfields
@see BitFieldReader
@author Philippe Lhardy
*/
import java.io.*;
class BitFieldWriter {
// size of nextWord
final int dataSize = 32;
/* bitOffset is number of bits already used in word
should ensure bitOffset < dataSize
*/
private int bitOffset;
/* word used waiting to be filled to be written
dataSize is bit size of nextWord
*/
private int nextWord;
private DataOutputStream outputStream;
public void write( int field, int bits) throws java.io.IOException {
// if more bits needed that word currently used.
if ( bits + bitOffset > dataSize) {
// warning recursive call ( not terminal )
// fill and write current word
int bitsize = dataSize - bitOffset;
int head;
// most significant bits first
// suppress at left least significant bits
head = field >> (bits - bitsize);
write( head, dataSize - bitOffset);
// no need of newWord() previous write already done it
// least significant bits last
field = field & ( 0x7FFFFFFF >> ( bitsize - 1));
write( field, bits - bitsize);
}
else {
if ( bits == dataSize ) {
// special case to keep sign
nextWord = field;
bitOffset = 0;
}
else {
// keep only meaning part of field
field = field & ( 0x7FFFFFFF >> ( dataSize - 1 - bits));
nextWord = nextWord | ( field << ( dataSize - bits - bitOffset));
bitOffset = ( bitOffset + bits ) % dataSize;
}
// a new word is needed
if ( bitOffset == 0 ) {
newWord();
}
}
/*
System.out.println( "nextWord " + Integer.toString( nextWord) + " size "
+ Integer.toString( bits) + " field " + Integer.toString( field));
*/
}
/**
* seems to works correctly as DataOutputStream.writeInt()
*/
private void writeInt( int i)
throws IOException
{
long j = i;
byte bytes[]=new byte[4];
bytes[0] = (byte) ((j & 0xFF000000) >> 24);
bytes[1] = (byte) ((j & 0x00FF0000) >> 16);
bytes[2] = (byte) ((j & 0x0000FF00) >> 8);
bytes[3] = (byte) (j & 0x000000FF);
outputStream.write( bytes, 0, 4);
}
private void newWord() throws java.io.IOException {
// do really write current word;
//writeInt( nextWord);
outputStream.writeInt(nextWord);
// reset nextWord
bitOffset = 0;
nextWord = 0;
}
/*
write all current datas if any
to have a clean word ready.
*/
public void padToWord() throws java.io.IOException {
if ( bitOffset != 0) {
newWord();
}
}
/* set OutputStream */
public void setOutputStream( OutputStream output) {
outputStream = new DataOutputStream(output);
}
}

View File

@@ -0,0 +1,149 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
DrawingLineExpander
decompress a draw line from a stream
main algorithm is to code only delta displacement in littlest possible size.
*/
package org.artisanlogiciel.compression.graphics;
import java.awt.Point;
import java.io.InputStream;
import java.util.ArrayList;
public class DrawLineExpander {
ArrayList<Point> expandedLines;
int currentSize;
int scode[] = {3,6,14,30,64};
final static int SCODE_MAX = 4;
private BitFieldReader fieldReader = null;
public DrawLineExpander() {
expandedLines = new ArrayList<>();
fieldReader = new BitFieldReader();
}
/* create a List of points */
public ArrayList<Point> expand( InputStream input ) throws java.io.IOException {
fieldReader.setInputStream( input);
int point_count = fieldReader.read( 32);
// System.out.println( point_count);
expandedLines.add( readAbs( 64));
for ( int i = 1; i < point_count; i ++ ) {
Point point = readRel();
if ( currentSize == 64 ) {
// absolute
expandedLines.add( point);
}
else {
// relative
Point previous = (Point) expandedLines.get(expandedLines.size()-1);
point.x = point.x + previous.x;
point.y = point.y + previous.y;
expandedLines.add( point);
}
}
return expandedLines;
}
/*
read point with size encoding depending on first bits
*/
private Point readRel() throws java.io.IOException {
int index;
/* 11 : next, 10 : previous ; 0* : same
6 -> 14->30
^ |
| v
3 <- 64
*/
// find index of current size
for ( index = 0; index < SCODE_MAX; index ++) {
if ( scode[index] == currentSize ) break;
}
// read size modifier until it is good one
while ( fieldReader.read(1) != 0 ) {
index = index + ( ( fieldReader.read(1) == 0 ) ? -1 : 1);
// handle circularity
if ( index > SCODE_MAX ) {
index = 0;
}
if ( index < 0 ) {
index = SCODE_MAX;
}
}
return readAbs( scode[index]);
}
/* write given Point with size */
Point readAbs( int size) throws java.io.IOException {
int codeval;
int center, max;
currentSize = size;
Point point = new Point();
if ( size > 32 ) {
point.x = fieldReader.read(32);
point.y = fieldReader.read(32);
}
else {
boolean nocenter=false;
codeval = fieldReader.read( size);
// System.out.println( codeval);
/*
for coding/decoding scheme see
org.artisanlogiciel.graphics.DrawLineKompressor.java
*/
if ( size == 3 ) {
max = 3;
center = 1;
nocenter=true;
}
else {
max = ( 1 << ( size / 2 ) );
center = (max / 2) - 1;
}
// central hole impossible but we don't really care
if ( nocenter )
{
if ( codeval > ( center * max ) ) {
codeval ++;
}
if ( codeval >= ( max * max )) {
System.out.println(
"!!! reserved value for decompression should not occur !!!");
}
}
point.x = ( codeval % max) - center;
point.y = ( codeval / max) - center;
// System.out.println( point.toString());
}
return point;
}
}

View File

@@ -0,0 +1,256 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
DrawingLineKompressor
compress a draw line over a stream
main algorithm is to code only delta displacement in littlest possible size.
*/
package org.artisanlogiciel.compression.graphics;
import java.awt.Point;
import java.io.OutputStream;
import java.util.ArrayList;
public class DrawLineKompressor {
ArrayList<Point> fromLines;
int previousSize;
int scode[] = {3,6,14,30,64};
final static int SCODE_MAX = 4;
private BitFieldWriter fieldWriter = null;
public DrawLineKompressor( ArrayList<Point> lines) {
fromLines = lines;
fieldWriter = new BitFieldWriter();
}
public void kompress( OutputStream output ) throws java.io.IOException {
fieldWriter.setOutputStream( output);
int skipsame=0;
if ( ( fromLines != null) && ( fromLines.size() > 0)) {
Point topoint = null;
for ( int i = 1; i < fromLines.size(); i++) {
Point frompoint = (Point) fromLines.get( i);
if ( ( topoint != null ) && ( topoint.x == frompoint.x ) && ( topoint.y == frompoint.y ) )
{
skipsame ++;
}
topoint=frompoint;
}
if ( skipsame > 0 )
{
System.out.println("[WARNING] lines contains " + skipsame + " duplicates points");
}
}
if ( ( fromLines != null) && ( fromLines.size() > 0)) {
Point frompoint = (Point) fromLines.get(0);
Point point, topoint;
topoint = new Point();
int center, size;
fieldWriter.write( fromLines.size() - skipsame, 32);
writeAbs( frompoint, 64);
for ( int i = 1; i < fromLines.size(); i++) {
point = (Point) fromLines.get( i);
topoint.x = point.x - frompoint.x;
topoint.y = point.y - frompoint.y;
// find wich size to use...
if (( topoint.x == 0 ) && ( topoint.y == 0 ))
{
// ARGH THIS IS INVALID !
System.out.println("[ERROR] (0,0) point is invalid for compression !!!");
continue;
}
if ( (Math.abs( topoint.x) < 2) && (Math.abs(topoint.y) < 2)) {
writeRel( topoint, 3);
}
else {
size = 64;
for ( int index = 1; index < ( SCODE_MAX - 1 ); index ++) {
/* center = ( ( 1 << ( scode[index] / 2 ) ) - 1 ) / 2;
if ( (Math.abs(topoint.x) <= center)
&& (Math.abs(topoint.y) <= center))
{
size = scode[index];
}
*/
// center is biased there are more + than - , ex for 6bits :(x,y) within ( -3,4 ) x (-3,4)
center = 1 << ( ( scode[index] / 2 ) - 1 );
if ( ( topoint.x <= center ) && ( topoint.x > -center )
&& ( topoint.y <= center ) && ( topoint.y > -center ) )
{
size = scode[index];
// always take the smaller size.
break;
}
}
if ( size < 32 ) {
writeRel( topoint, size);
}
else {
// warning absolute
writeRel( point, 64);
}
}
// new frompoint is previous point
frompoint = point;
}
fieldWriter.padToWord();
}
}
/*
compute bits of size
*/
void writeRel( Point point, int size) throws java.io.IOException {
/*
System.out.println( "point " + point.toString());
System.out.println( "size " + Integer.toString( size));
*/
/* 11 : next, 10 : previous ; 0* : same
6 -> 14
^ |
| v
3 <- 64
*/
if ( size != previousSize) {
int cindex, pindex;
// find index of size
for ( cindex = 0; cindex < SCODE_MAX; cindex ++) {
if ( scode[cindex] == size ) break;
}
// find index of previous size
for ( pindex = 0; pindex < SCODE_MAX; pindex ++) {
if ( scode[pindex] == previousSize ) break;
}
if ( pindex < cindex ) {
/*
if way with = is better than - then use = next
else use - previous
0--<--pindex===>==cindex---<---SCODE_MAX
*/
if ( ((SCODE_MAX - cindex) + pindex ) > ( pindex - cindex ) ) {
// ( pindex - cindex ) times next
for ( ; pindex < cindex; pindex ++) {
fieldWriter.write( 3,2);
}
}
else {
// ((SCODE_MAX -cindex) + pindex ) fois previous
for ( pindex = SCODE_MAX - cindex + pindex; pindex > 0; pindex --) {
fieldWriter.write( 2,2);
}
}
}
else {
/*
if way with = is better than - then use = previous
else use - next
0-->--cindex===<==pindex--->---SCODE_MAX
*/
if ( ((SCODE_MAX - pindex) + cindex ) > cindex - pindex ) {
// ( cindex - pindex ) fois previous
for ( ; cindex < pindex; pindex --) {
fieldWriter.write( 2,2);
}
}
else {
// ((SCODE_MAX - pindex) + cindex ) fois next
for ( pindex = SCODE_MAX - pindex + cindex; pindex > 0; pindex --)
{
fieldWriter.write( 3,2);
}
}
}
}
// this is good size.
fieldWriter.write( 0,1);
writeAbs( point, size);
}
/* write given Point with size */
void writeAbs( Point point, int size) throws java.io.IOException {
int codeval;
int center, max;
previousSize = size;
if ( size > 32 ) {
fieldWriter.write( point.x, 32);
fieldWriter.write( point.y, 32);
}
else {
boolean nocenter = false;
/* size == 3 example :
X - >
Y 0 1 2
| 3 . 4-
v 5 6 7
specific application of general case bellow.
*/
/* X ->
Y 0
| 0 center max
v max
0 1 2 ...center.... (max - 1)
max 2 * max - 1
. (0,0) center * ( max + 1)
(max-1)*max -1 (max ^ 2) - 1
2 */
if ( size == 3 ) {
max = 3;
center = 1;
nocenter = true;
}
else {
max = ( 1 << ( size / 2 ) );
// biased center ( -center +1, center )
center = (max / 2) - 1;
}
/*
System.out.println( "size" + Integer.toString( size));
System.out.println( "max, center " + Integer.toString( max) + " " + Integer.toString( center));
System.out.println( "x, y " + Integer.toString( point.x) + " " + Integer.toString( point.y));
*/
codeval = point.x + center + (( point.y + center ) * max );
// central hole impossible BUT we should not really care ( in fact whole center square is impossible since covered by encoding with lower number of bits ) , avoid it only for size 3.
if (nocenter) {
if ( codeval == ( center * max ) + 1 ) {
System.out.println("!!! warning (0,0) point is invalid for compression !!!");
}
if ( codeval > (center * max) ){
codeval --;
}
}
// System.out.println( "code " + Integer.toString( codeval));
fieldWriter.write( codeval, size);
}
}
}

View File

@@ -0,0 +1,28 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
import java.io.Serializable;
public class DrawException extends Exception implements Serializable {
public DrawException() {
super();
}
}

View File

@@ -0,0 +1,106 @@
/**
Drawing
contains a set of DrawingLine to create a Drawing
- feature of load / save
*/
package org.artisanlogiciel.graphics;
import java.awt.Graphics;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import org.artisanlogiciel.graphics.Importer;
import org.artisanlogiciel.graphics.ResetException;
import org.artisanlogiciel.graphics.NoMoreLineException;
public class Drawing
{
private ArrayList<DrawingLine> lines;
public Drawing()
{
reset();
}
public void reset() {
lines = new ArrayList<DrawingLine>(10);
}
public void addLine( DrawingLine line) {
lines.add( line);
}
public void saveLines( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for ( DrawingLine line : lines )
{
line.save( destination);
}
}
public void loadLines( DataInputStream source) throws
java.io.IOException {
int nb_lines = source.readInt();
DrawingLine line;
for ( int i = 0; i < nb_lines; i++ ) {
line = new DrawingLine();
line.load( source);
lines.add( line);
}
}
public void importImage( Importer importer) throws
java.io.IOException
{
importer.importInto(this);
}
public void saveLinesKompressed( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for ( DrawingLine line : lines )
{
line.saveKompressed( destination);
}
}
public void loadLinesExpanded( DataInputStream source) throws
java.io.IOException {
// DrawLineExpander expander = new DrawLineExpander();
int nb_lines = source.readInt();
DrawingLine line;
for ( int i = 0; i < nb_lines; i++ ) {
line = new DrawingLine();
line.loadExpanded( source);
lines.add( line);
}
}
public int length() {
return lines.size();
}
public DrawingLine getLine( int line) throws ResetException, NoMoreLineException {
if ( line == lines.size() ) {
throw new NoMoreLineException();
}
if ( line > lines.size() ) {
throw new ResetException();
}
return lines.get( line);
}
public ArrayList<DrawingLine> getLines() {
return new ArrayList<DrawingLine>(lines);
}
/** Not a copy, use with care */
public ArrayList<DrawingLine> getInternLines() {
return lines;
}
}

View File

@@ -0,0 +1,96 @@
/**
DrawingLine
keep track of list of Points constituting a line
*/
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import org.artisanlogiciel.compression.graphics.DrawLineExpander;
import org.artisanlogiciel.compression.graphics.DrawLineKompressor;
public class DrawingLine implements Cloneable, Serializable
{
ArrayList<Point> lines;
public DrawingLine() {
lines = new ArrayList<>();
}
public void addPoint( Point point) {
lines.add( point);
}
public void setPoints( ArrayList<Point> points) {
lines = points;
}
public Object clone() throws java.lang.CloneNotSupportedException {
return super.clone();
}
private void writePoint( Point p, DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( p.x);
destination.writeInt( p.y);
}
private void readPoint( DataInputStream source) throws java.io.IOException {
Point point = new Point( source.readInt(), source.readInt());
lines.add( point);
}
public void save( DataOutputStream destination) throws
java.io.IOException {
destination.writeInt( lines.size());
for (int i=0; i < lines.size(); i++) {
writePoint( (Point) lines.get(i), destination);
}
}
public void load( DataInputStream source) throws
java.io.IOException {
int point_number = source.readInt();
for (int i=0; i < point_number; i++) {
readPoint( source);
}
}
/**
* send over the stream a compressed version of this line
*/
public void saveKompressed( OutputStream destination) throws
java.io.IOException {
DrawLineKompressor kompressor = new DrawLineKompressor( lines);
kompressor.kompress( destination);
}
/**
* load form the stream a compressed version of this line
*/
public void loadExpanded( InputStream source) throws
java.io.IOException {
DrawLineExpander expander = new DrawLineExpander();
lines = expander.expand( source);
}
public ArrayList<Point> getPoints() {
return new ArrayList<Point>(lines);
}
public ArrayList<Point> internalGetPoints() {
return lines;
}
}

View File

@@ -0,0 +1,94 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataInputStream;
/**
.IMA format is an old proprietary format for laser show program
it contain a list of point the laser beam should goe through,
x=255 has a special meaning to hide (255,254) ( send beam into the box) or show it (255,255): let is flow outside.
*/
public class IMAImporter implements Importer
{
final DataInputStream mStream;
boolean mBeanOn = false;
int mIndex =0;
boolean mDebug = false;
public IMAImporter(DataInputStream inputStream)
{
mStream=inputStream;
}
public void setDebug(boolean pDebug)
{
mDebug=pDebug;
}
@Override
public void importInto(Drawing drawing)
{
int x,y;
DrawingLine line = null;
mBeanOn = false;
try {
// little endian unsigned short
int pointCount = mStream.readUnsignedByte();
pointCount = ( 256 * mStream.readUnsignedByte() ) + pointCount;
if ( mDebug )
{
System.out.println("point count :" + pointCount);
}
for (int j = 0 ; j < pointCount; j+=2)
{
mIndex=j;
x = mStream.readUnsignedByte();
y = mStream.readUnsignedByte();
// special beam on/off
if ( ( x == 0xff ) && ( y >= 0xfe ) )
{
mBeanOn = ( y == 0xff);
if ( mDebug )
{
System.out.println("beam change at " + mIndex + " " + mBeanOn);
}
}
else
{
y = 255-y;
if ( mDebug )
{
System.out.println("point at " + mIndex + " " + mBeanOn + " x " + x + " y " + y);
}
if ( mBeanOn )
{
if (line == null )
{
line = new DrawingLine();
}
line.addPoint(new Point(x,y));
}
else
{
if ( line != null )
{
drawing.addLine(line);
line = null;
}
}
}
}
if ( line != null )
{
drawing.addLine(line);
line = null;
}
}
catch( Exception any)
{
System.err.println(" error at index " + mIndex);
any.printStackTrace(System.err);
}
}
}

View File

@@ -0,0 +1,143 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* Write a DrawLine (using its internal Vector representation) into IMA format
* this is with loss ( ima is a 255x255 point resolution )
*
* @author philippe
*
*/
public class IMAWriter {
private final ArrayList<DrawingLine> mLines;
private int mByteCount = 0;
// need to compute bounding box and normalize to 255x255
private Point mOrig = new Point(100000,100000);
private Point mMax = new Point(-100000,-100000);
double ratioX = .1;
double ratioY = .1;
public IMAWriter(ArrayList<DrawingLine> pLines)
{
mLines = pLines;
setup();
}
private void updateOrigMax(Point p)
{
double ox = mOrig.getX(), oy = mOrig.getY(), mx = mMax.getX(), my = mMax.getY();
if (p.getX() < ox )
{
ox = p.getX();
}
if (p.getX() > mx)
{
mx = p.getX();
}
if (p.getY() < oy )
{
oy = p.getY();
}
if (p.getY() > my)
{
my = p.getY();
}
mOrig.setLocation(ox,oy);
mMax.setLocation(mx,my);
}
private void setup()
{
int count = 0;
for (DrawingLine line : mLines)
{
for (Point p : line.getPoints())
{
updateOrigMax(p);
count+=2;
}
// beam on + off
count+=4;
}
mByteCount=count;
if ( mMax.getX() != mOrig.getX())
{
ratioX = 255 / (mMax.getX() - mOrig.getX());
}
else
{
ratioX = 1.;
}
if ( mMax.getY() != mOrig.getY())
{
ratioY = 255 / (mMax.getY() - mOrig.getY());
}
else
{
ratioY = 1.;
}
}
public void writeTo(DataOutputStream pData)
throws IOException
{
int wrote = 0;
// writeheader : number of points ...
// little endian unsigned short.
pData.writeByte(mByteCount%256);
pData.writeByte(mByteCount/256);
for (DrawingLine line : mLines)
{
// write ima line
wrote += writeLine(pData, line.getPoints());
}
}
void writeBeamOnOff(DataOutputStream pData,boolean pOn)
throws IOException
{
pData.writeByte(0xff);
pData.writeByte(pOn ? 0xff : 0xfe);
}
void writePoint(DataOutputStream pData,Point pPoint)
throws IOException
{
int x = (int) ((pPoint.getX()-mOrig.getX()) * ratioX);
int y = 255 - ((int) ((pPoint.getY()-mOrig.getY()) * ratioY));
if ( x == 0xff )
{
x=0xfe;
}
pData.writeByte(x);
pData.writeByte(y);
}
int writeLine(DataOutputStream pData,ArrayList<Point> pPoints)
throws IOException
{
int count = 0;
for (Point p : pPoints)
{
writePoint(pData,p);
if ( count == 0 )
{
writeBeamOnOff(pData,true);
}
count++;
}
writeBeamOnOff(pData,false);
return 2*(count +2);
}
}

View File

@@ -0,0 +1,8 @@
package org.artisanlogiciel.graphics;
public interface Importer {
void importInto(Drawing drawing);
void setDebug(boolean pDebug);
}

View File

@@ -0,0 +1,31 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
import java.io.Serializable;
public class NoMoreLineException
extends DrawException
implements Serializable
{
public NoMoreLineException() {
super();
}
}

View File

@@ -0,0 +1,28 @@
/*
This file is part of ShareDrawWeb.
ShareDrawWeb is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ShareDrawWeb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ShareDrawWeb; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.artisanlogiciel.graphics;
public class ResetException
extends DrawException
{
public ResetException() {
super();
}
}

View File

@@ -0,0 +1,65 @@
package org.artisanlogiciel.graphics;
import java.awt.Point;
//import java.io.DataOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
/**
* Write a DrawLine (using its internal Vector representation) into svg
*
* @author philippe
*
*/
public class SvgWriter {
private final ArrayList<DrawingLine> mLines;
public SvgWriter(ArrayList<DrawingLine> pLines)
{
mLines = pLines;
}
public void writeTo(OutputStream pData)
throws IOException
{
pData.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>".getBytes("UTF8"));
pData.write("<svg>".getBytes("UTF8"));
for (DrawingLine line : mLines)
{
pData.write("<g><path ".getBytes("UTF8"));
pData.write("style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\" d=\"".getBytes("UTF8"));
pData.write( getSvgPathString(line.getPoints()).getBytes("UTF8"));
pData.write(" \" /></g>".getBytes("UTF8"));
}
pData.write("</svg>".getBytes("UTF8"));
}
String getSvgPathString(ArrayList<Point> pPoints)
{
StringBuilder sb = new StringBuilder(pPoints.size() * 10);
Point second = null;
Point previous = null;
for ( Point p : pPoints)
{
if ( previous != null )
{
if ( second == null )
{
second = p;
// 'l' a line ( 'c' woudl be a curve )
sb.append(" l ");
}
sb.append( "" + (p.getX() - previous.getX()) + "," + (p.getY() - previous.getY()) );
previous = p;
}
else
{
sb.append("m " + p.getX() + "," + p.getY());
previous = p;
}
}
return sb.toString();
}
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff