Skip to content
Snippets Groups Projects
Commit e5e17df5 authored by Andrey Ruzhanskiy's avatar Andrey Ruzhanskiy
Browse files

Added new method for length of braille

parent 3ccb1048
No related branches found
No related tags found
1 merge request!24Feat/brailletextrasterizer 38
...@@ -45,7 +45,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -45,7 +45,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
try { try {
mTranslator = new Translator("src\\main\\resources\\mapping\\liblouis\\de-g0.utb"); mTranslator = new Translator("src\\main\\resources\\mapping\\liblouis\\de-g1.ctb");
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getCause()); throw new RuntimeException(e.getCause());
} }
...@@ -56,6 +56,9 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -56,6 +56,9 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
public void rasterize(final BrailleText data, final RasterCanvas canvas) throws InsufficientRenderingAreaException { public void rasterize(final BrailleText data, final RasterCanvas canvas) throws InsufficientRenderingAreaException {
Objects.requireNonNull(data, "The data given to the brailletextrasterizer was null!"); Objects.requireNonNull(data, "The data given to the brailletextrasterizer was null!");
Objects.requireNonNull(canvas, "The canvas given to the brailletextrasterizer was null!"); Objects.requireNonNull(canvas, "The canvas given to the brailletextrasterizer was null!");
if (data.getText() == "") {
throw new RuntimeException("The string in the Brailletext must not be empty!");
}
Rectangle rect = data.getArea().intersectedWith(canvas.getDotRectangle()); Rectangle rect = data.getArea().intersectedWith(canvas.getDotRectangle());
mCanvas = canvas; mCanvas = canvas;
TranslationResult result = null; TranslationResult result = null;
...@@ -149,4 +152,18 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -149,4 +152,18 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
} }
return (int) ceil((double) widthOfText / (double) tempMaxWidth); return (int) ceil((double) widthOfText / (double) tempMaxWidth);
} }
public int getBrailleStringLength(String text) {
Objects.requireNonNull(text, "The given string for getBrailleStringLength was null!");
if (text == "") return 0;
TranslationResult result = null;
try {
result = mTranslator.translate(text, null, null, null, DisplayTable.StandardDisplayTables.DEFAULT);
} catch (TranslationException e) {
e.printStackTrace();
} catch (DisplayException e) {
e.printStackTrace();
}
return result.getBraille().length();
}
} }
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