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

Merge branch 'feat/brailletext_update-54' into 'master'

Feat/brailletext update 54

See merge request !34
parents b15fb375 0a49cb61
No related branches found
No related tags found
1 merge request!34Feat/brailletext update 54
...@@ -8,6 +8,7 @@ import de.tudresden.inf.mci.brailleplot.layout.RasterCanvas; ...@@ -8,6 +8,7 @@ import de.tudresden.inf.mci.brailleplot.layout.RasterCanvas;
import de.tudresden.inf.mci.brailleplot.layout.Rectangle; import de.tudresden.inf.mci.brailleplot.layout.Rectangle;
import de.tudresden.inf.mci.brailleplot.point.Point2DDouble; import de.tudresden.inf.mci.brailleplot.point.Point2DDouble;
import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData; import de.tudresden.inf.mci.brailleplot.printabledata.MatrixData;
import de.tudresden.inf.mci.brailleplot.rendering.language.BrailleLanguage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
......
package de.tudresden.inf.mci.brailleplot.rendering; package de.tudresden.inf.mci.brailleplot.rendering;
import de.tudresden.inf.mci.brailleplot.layout.Rectangle; import de.tudresden.inf.mci.brailleplot.layout.Rectangle;
import de.tudresden.inf.mci.brailleplot.rendering.language.BrailleLanguage;
import java.util.Objects; import java.util.Objects;
...@@ -14,6 +15,12 @@ public class BrailleText implements Renderable { ...@@ -14,6 +15,12 @@ public class BrailleText implements Renderable {
private String mContent; private String mContent;
private Rectangle mArea; private Rectangle mArea;
public String getLanguage() {
return mLanguage;
}
private String mLanguage;
/** /**
* Constructor. Creates a braille text field. * Constructor. Creates a braille text field.
* @param content The actual text of the text field. * @param content The actual text of the text field.
...@@ -22,8 +29,16 @@ public class BrailleText implements Renderable { ...@@ -22,8 +29,16 @@ public class BrailleText implements Renderable {
public BrailleText(final String content, final Rectangle area) { public BrailleText(final String content, final Rectangle area) {
setText(content); setText(content);
setArea(area); setArea(area);
mLanguage = "de-g0.utb";
}
public BrailleText(final String content, final Rectangle area, BrailleLanguage.Language language) {
setText(content);
setArea(area);
mLanguage = BrailleLanguage.getCorrectLanguage(language);
} }
/** /**
* Sets a new text content. * Sets a new text content.
* @param content The new content for the text field. * @param content The new content for the text field.
......
package de.tudresden.inf.mci.brailleplot.rendering; package de.tudresden.inf.mci.brailleplot.rendering;
import de.tudresden.inf.mci.brailleplot.rendering.language.BrailleLanguage;
import de.tudresden.inf.mci.brailleplot.util.GeneralResource; import de.tudresden.inf.mci.brailleplot.util.GeneralResource;
import de.tudresden.inf.mci.brailleplot.brailleparser.AbstractBrailleTableParser; import de.tudresden.inf.mci.brailleplot.brailleparser.AbstractBrailleTableParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer; import de.tudresden.inf.mci.brailleplot.configparser.Printer;
...@@ -17,10 +18,11 @@ import java.io.File; ...@@ -17,10 +18,11 @@ import java.io.File;
import java.util.Objects; import java.util.Objects;
import static java.lang.Math.ceil; import static java.lang.Math.ceil;
/** /**
* Class representing a brailletextrasterizing approach using the liblouis library. * Class representing a brailletextrasterizing approach using the liblouis library.
* @author Andrey Ruzhanskiy * @author Andrey Ruzhanskiy
* @version 30.08.2019 * @version 27.09.2019
*/ */
public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
...@@ -39,6 +41,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -39,6 +41,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
/** /**
* Constructor for liblouistextrasterizer. * Constructor for liblouistextrasterizer.
*
* @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) {
...@@ -53,7 +56,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -53,7 +56,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
String tableFilePath = tableFile.getAbsolutePath(); String tableFilePath = tableFile.getAbsolutePath();
mTranslator = new Translator(tableFilePath); mTranslator = new Translator(tableFilePath);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error while creating liblouis translator:", e); throw new RuntimeException("Error while creating liblouis translator", e);
} }
} }
...@@ -65,6 +68,13 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -65,6 +68,13 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
if (data.getText() == "") { if (data.getText() == "") {
return; return;
} }
try {
File tableFile = mLibLouisTableDirectory.toPath().resolve(data.getLanguage()).toFile(); // reference to specific table file in exported directory
String tableFilePath = tableFile.getAbsolutePath();
mTranslator = new Translator(tableFilePath);
} catch (Exception e) {
throw new RuntimeException("Error while creating liblouis translator", e);
}
Rectangle rect = data.getArea().intersectedWith(canvas.getDotRectangle()); Rectangle rect = data.getArea().intersectedWith(canvas.getDotRectangle());
mCanvas = canvas; mCanvas = canvas;
TranslationResult result = null; TranslationResult result = null;
...@@ -75,8 +85,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -75,8 +85,7 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
} catch (DisplayException e) { } catch (DisplayException e) {
e.printStackTrace(); e.printStackTrace();
} }
String[]resultAsArray = result.getBraille().split(""); String[] resultAsArray = result.getBraille().split("");
// We need to know where to start // We need to know where to start
...@@ -129,14 +138,13 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -129,14 +138,13 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
/** /**
* Calculates the required height for the text. * Calculates the required height for the text.
* @param text Text to be analyzed. *
* @param xPos X position where to start. * @param text Text to be analyzed.
* @param yPos Y position where to start. * @param maxWidth the maximum width of the area where the text has to be. In dots.
* @param maxWidth the maximum width of the area where the text has to be * @param canvas Canvas on which the text should later appear
* @param canvas Canvas on which the text should later appear
* @return Height in braillecells. * @return Height in braillecells.
*/ */
public int calculateRequiredHeight(final String text, final int xPos, final int yPos, final int maxWidth, public int calculateRequiredHeight(final String text, final int maxWidth,
final RasterCanvas canvas) { final RasterCanvas canvas) {
Objects.requireNonNull(text, "The given string for calculateRequiredHeight was null!"); Objects.requireNonNull(text, "The given string for calculateRequiredHeight was null!");
Objects.requireNonNull(canvas, "The given canvas for calculateRequiredHeight was null!"); Objects.requireNonNull(canvas, "The given canvas for calculateRequiredHeight was null!");
...@@ -162,6 +170,33 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -162,6 +170,33 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
} }
/**
* Calculates the required height for the text with the given language.
*
* @param text Text to be analyzed.
* @param maxWidth the maximum width of the area where the text has to be. In dots.
* @param canvas Canvas on which the text should later appear
* @param language {@link BrailleLanguage.Language} The language which is to be used.
* @return Height in braillecells.
*/
public int calculateRequiredHeight(final String text, final int maxWidth,
final RasterCanvas canvas, final BrailleLanguage.Language language) {
Objects.requireNonNull(text, "The given string for calculateRequiredHeight was null!");
Objects.requireNonNull(canvas, "The given canvas for calculateRequiredHeight was null!");
Translator temp = mTranslator;
try {
File tableFile = mLibLouisTableDirectory.toPath().resolve(BrailleLanguage.getCorrectLanguage(language)).toFile(); // reference to specific table file in exported directory
String tableFilePath = tableFile.getAbsolutePath();
mTranslator = new Translator(tableFilePath);
} catch (Exception e) {
throw new RuntimeException("Error while creating liblouis translator", e);
}
int length = calculateRequiredHeight(text, maxWidth, canvas);
mTranslator = temp;
return length;
}
/** /**
* Method for getting the braillelength for a given string. * Method for getting the braillelength for a given string.
* @param text String to analyze * @param text String to analyze
...@@ -182,4 +217,28 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> { ...@@ -182,4 +217,28 @@ public class LiblouisBrailleTextRasterizer implements Rasterizer<BrailleText> {
} }
return result.getBraille().length(); return result.getBraille().length();
} }
/**
* Method for getting the braillelength for a given string with the given {@link BrailleLanguage.Language}.
* @param text String to analyze
* @param language {@link BrailleLanguage.Language} The language which is to be used.
* @return length of the braille
*/
public int getBrailleStringLength(final String text, final BrailleLanguage.Language language) {
Objects.requireNonNull(text, "The given string for getBrailleStringLength was null!");
if (text == "") {
return 0;
}
Translator temp = mTranslator;
try {
File tableFile = mLibLouisTableDirectory.toPath().resolve(BrailleLanguage.getCorrectLanguage(language)).toFile(); // reference to specific table file in exported directory
String tableFilePath = tableFile.getAbsolutePath();
mTranslator = new Translator(tableFilePath);
} catch (Exception e) {
throw new RuntimeException("Error while creating liblouis translator", e);
}
int length = getBrailleStringLength(text);
mTranslator = temp;
return length;
}
} }
...@@ -86,7 +86,7 @@ final class UniformTextureBarChartRasterizer implements Rasterizer<BarChart> { ...@@ -86,7 +86,7 @@ final class UniformTextureBarChartRasterizer implements Rasterizer<BarChart> {
try { try {
// 1. Reserve space for the diagram title on the top // 1. Reserve space for the diagram title on the top
titleBarHeight = mTextRasterizer.calculateRequiredHeight(strDiagramTitle, 0, 0, titleBarHeight = mTextRasterizer.calculateRequiredHeight(strDiagramTitle,
barArea.intWrapper().getWidth() * mCanvas.getCellWidth(), mCanvas); barArea.intWrapper().getWidth() * mCanvas.getCellWidth(), mCanvas);
titleArea = barArea.removeFromTop(mCanvas.getCellYFromDotY(titleBarHeight)); titleArea = barArea.removeFromTop(mCanvas.getCellYFromDotY(titleBarHeight));
......
package de.tudresden.inf.mci.brailleplot.rendering.language;
/**
* Helper class for braillelanguage
* @author Andrey Ruzhanskiy
* @version 27.09.2019
*/
public class BrailleLanguage {
public static String getCorrectLanguage(Language language){
switch (language) {
case GERMAN_VOLLSCHRIFT:
case DE_VOLLSCHRIFT:
return "de-g1.ctb";
case GERMAN_BASISSCHRIFT:
case DE_BASISSCHRIFT:
return "de-g0.utb";
case GERMAN_KURZSCHRIFT:
case DE_KURZSCHRIFT:
return "de-g2.ctb";
}
throw new RuntimeException("Unsupported language given as braillelanguage! \"" + language.toString() + "\"");
}
public enum Language {
DE_KURZSCHRIFT,
DE_BASISSCHRIFT,
DE_VOLLSCHRIFT,
GERMAN_KURZSCHRIFT,
GERMAN_BASISSCHRIFT,
GERMAN_VOLLSCHRIFT
}
}
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