Skip to content
Snippets Groups Projects
Commit 37e68062 authored by Georg Graßnick's avatar Georg Graßnick :thinking:
Browse files

Add static initializer for liblouis

parent 92cbcb7e
No related branches found
No related tags found
1 merge request!35Feat/libluis bin
...@@ -191,6 +191,7 @@ public final class App { ...@@ -191,6 +191,7 @@ public final class App {
barChart.setYAxisName("Länge in m"); barChart.setYAxisName("Länge in m");
// Render diagram // Render diagram
LiblouisBrailleTextRasterizer.initModule();
MasterRenderer renderer = new MasterRenderer(indexV4Printer, a4Format); MasterRenderer renderer = new MasterRenderer(indexV4Printer, a4Format);
RasterCanvas canvas = renderer.rasterize(barChart); RasterCanvas canvas = renderer.rasterize(barChart);
// SVG exporting // SVG exporting
......
...@@ -11,6 +11,7 @@ import de.tudresden.inf.mci.brailleplot.util.NativeLibraryHelper; ...@@ -11,6 +11,7 @@ import de.tudresden.inf.mci.brailleplot.util.NativeLibraryHelper;
import de.tudresden.inf.mci.brailleplot.util.NoSuchNativeLibraryException; import de.tudresden.inf.mci.brailleplot.util.NoSuchNativeLibraryException;
import org.liblouis.DisplayException; import org.liblouis.DisplayException;
import org.liblouis.DisplayTable; import org.liblouis.DisplayTable;
import org.liblouis.Louis;
import org.liblouis.TranslationException; import org.liblouis.TranslationException;
import org.liblouis.TranslationResult; import org.liblouis.TranslationResult;
import org.liblouis.Translator; import org.liblouis.Translator;
...@@ -27,6 +28,8 @@ import static java.lang.Math.ceil; ...@@ -27,6 +28,8 @@ import static java.lang.Math.ceil;
public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
private static boolean mNativeLibInitialized = false;
private AbstractBrailleTableParser mParser; private AbstractBrailleTableParser mParser;
// Parameters for rasterizing // Parameters for rasterizing
private int x; private int x;
...@@ -44,13 +47,6 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -44,13 +47,6 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
* @param printer Needed to get the semantictable according to the printer config. * @param printer Needed to get the semantictable according to the printer config.
*/ */
public LiblouisBrailleTextRasterizer(final Printer printer) { public LiblouisBrailleTextRasterizer(final Printer printer) {
try {
NativeLibraryHelper.loadNativeLibrary("liblouis");
} catch (NoSuchNativeLibraryException e) {
// Even if the library is not distributed within the jar file, it might be installed on the system.
}
Objects.requireNonNull(printer, "The given printer for the LiblouisBrailleTextRasterizer was null!"); Objects.requireNonNull(printer, "The given printer for the LiblouisBrailleTextRasterizer was null!");
try { try {
mParser = AbstractBrailleTableParser.getParser(printer, "semantictable"); mParser = AbstractBrailleTableParser.getParser(printer, "semantictable");
...@@ -191,4 +187,30 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -191,4 +187,30 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
} }
return result.getBraille().length(); return result.getBraille().length();
} }
/**
* Initializes the Module.
* @throws LibLouisLibraryMissingException If liblouis could not be loaded from neither the jar or the default JNI include path.
*/
public static void initModule() throws LibLouisLibraryMissingException {
if (!mNativeLibInitialized) {
try {
NativeLibraryHelper.loadNativeLibrary("liblouis");
} catch (NoSuchNativeLibraryException e) {
// Even if the library is not distributed within the jar file, it might be installed on the system.
}
try {
Louis.getVersion();
} catch (java.lang.UnsatisfiedLinkError e) {
throw new LibLouisLibraryMissingException(e);
}
mNativeLibInitialized = true;
}
}
public static class LibLouisLibraryMissingException extends NoSuchNativeLibraryException {
LibLouisLibraryMissingException(Throwable cause) {
super(cause);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment