use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.
the class TrpShapeTypeUtils method setUnicodeText.
public static void setUnicodeText(ITrpShapeType shape, String unicode, Object who) {
logger.trace("setting unicode text in " + shape.getName() + ", id: " + shape.getId() + ", text: " + unicode);
int lBefore = shape.getUnicodeText().length();
TextEquivType te = new TextEquivType();
te.setUnicode(unicode);
shape.setTextEquiv(te);
shape.getCustomTagList().onTextEdited(0, lBefore, unicode);
shape.getObservable().setChangedAndNotifyObservers(new TrpTextChangedEvent(who, 0, lBefore, unicode));
}
use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.
the class TrpShapeTypeUtils method editUnicodeText.
public static void editUnicodeText(ITrpShapeType shape, int start, int end, String replacement, Object who) {
logger.trace("editing unicode text in " + shape.getName() + ", id: " + shape.getId() + ", start/end: " + start + "/" + end + ", text: " + replacement);
StringBuilder sb = new StringBuilder(shape.getUnicodeText());
sb.replace(start, end, replacement);
String unicode = sb.toString();
if (shape instanceof TrpWordType && unicode.equals(TrpWordType.EMPTY_WORD_FILL)) {
unicode = "";
replacement = "";
}
TextEquivType te = new TextEquivType();
te.setUnicode(unicode);
shape.setTextEquiv(te);
SebisStopWatch.SW.start();
shape.getCustomTagList().onTextEdited(start, end, replacement);
SebisStopWatch.SW.stop(true, "onTextEdited: ", logger);
shape.getObservable().setChangedAndNotifyObservers(new TrpTextChangedEvent(who, start, end, replacement));
}
use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.
the class KlosterTeiToPageParser method parsePage.
static void parsePage(Node pbNode, boolean save) throws IOException, JAXBException {
Element pb = (Element) pbNode;
String imgFn = pb.getAttribute("facs");
int pageN = Integer.parseInt(pb.getAttribute("n"));
int pageHeight = Integer.parseInt(pb.getAttribute("xmlns:h"));
int pageWidth = Integer.parseInt(pb.getAttribute("xmlns:w"));
PcGtsType page = PageXmlUtils.createEmptyPcGtsType("imgfn", pageWidth, pageHeight);
TrpTextRegionType region = new TrpTextRegionType();
region.setId("region_1");
System.out.println("page data: imgFn = " + imgFn + " n = " + pageN + " pageWidth = " + pageWidth + " pageHeight = " + pageHeight);
int minX = 999999, minY = 999999, maxX = -1, maxY = -1;
Node sibling = pbNode.getNextSibling();
int lineCount = 0;
while (sibling != null) {
if (sibling.getNodeName().equals("pb")) {
break;
}
// System.out.println("sibling type: "+sibling.getTextContent());
if (sibling.getNodeType() == Node.ELEMENT_NODE && sibling.getNodeName().equals("lb")) {
Element lb = (Element) sibling;
int n = Integer.parseInt(lb.getAttribute("n"));
int x = Integer.parseInt(lb.getAttribute("xmlns:x"));
int y = Integer.parseInt(lb.getAttribute("xmlns:y"));
int w = Integer.parseInt(lb.getAttribute("xmlns:w"));
int h = Integer.parseInt(lb.getAttribute("xmlns:h"));
if (x < minX)
minX = x;
if (y < minY)
minY = y;
if (x + w > maxX)
maxX = x + w;
if (y + h > maxY)
maxY = y + h;
String txt = sibling.getNextSibling().getTextContent();
txt = StringUtils.stripEnd(txt, " \r\n");
// System.out.println("line: txt = "+txt+" [x,y,w,h] = ["+x+","+y+","+w+","+h+"]");
System.out.format("line: n = %d, txt = %s, coords = [%d,%d,%d,%d]\n", n, txt, x, y, w, h);
TrpTextLineType line = new TrpTextLineType();
line.setCoords(bbToCoords(x, y, w, h));
TextEquivType te = new TextEquivType();
te.setUnicode(txt);
line.setTextEquiv(te);
line.setId("line_" + (++lineCount));
// create baseline:
TrpBaselineType bl = new TrpBaselineType();
int yBl = (int) (y + 0.7 * h);
bl.setPoints(x + "," + yBl + " " + (x + w) + "," + yBl);
line.setBaseline(bl);
region.getTextLine().add(line);
}
sibling = sibling.getNextSibling();
// System.out.println("sibling node name: "+sibling.getNodeName());
// if (!sibling.getNodeName().equals("lb"))
// break;
}
if (!region.getTextLine().isEmpty()) {
region.setCoords(bbToCoords(minX, minY, maxX - minX, maxY - minY));
} else {
region.setCoords(bbToCoords(0, 0, pageWidth, pageHeight));
}
page.getPage().getTextRegionOrImageRegionOrLineDrawingRegion().add(region);
if (save && !region.getTextLine().isEmpty()) {
File xmlFile = new File(PAGE_DIR + FilenameUtils.getBaseName(imgFn) + ".xml");
PageXmlUtils.marshalToFile(page, xmlFile);
FileUtils.copyFile(new File(DIR + imgFn), new File(DST_DIR + imgFn));
System.out.println("written page to: " + xmlFile.getAbsolutePath());
}
}
use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.
the class PageXmlUtils method setTextToLine.
public static void setTextToLine(String text, PcGtsType pc, String lineId) {
TextLineType tl = findLineById(pc, lineId);
if (tl == null) {
logger.info("Line does not exist: " + lineId);
return;
}
logger.debug("Setting text in line=" + lineId + ": " + text);
if (tl.getTextEquiv() == null) {
logger.debug("Creating new TextEquiv element.");
TextEquivType textEquiv = new TextEquivType();
textEquiv.setUnicode(text);
tl.setTextEquiv(textEquiv);
} else {
logger.debug("Setting text in existing TextEquiv element.");
tl.getTextEquiv().setUnicode(text);
}
}
use of eu.transkribus.core.model.beans.pagecontent.TextEquivType in project TranskribusCore by Transkribus.
the class BeanCopyUtils method copyTextEquivType.
// public static CellCoordsType copyCellCoordsType(CellCoordsType coords) {
// if (coords == null)
// return null;
//
// CellCoordsType copy = new CellCoordsType();
// copy.setPoints(coords.getPoints());
// copy.setCornerPts(coords.getCornerPts());
//
// return copy;
// }
public static TextEquivType copyTextEquivType(TextEquivType text) {
if (text == null)
return null;
TextEquivType copy = new TextEquivType();
copy.setConf(text.getConf());
copy.setPlainText(text.getPlainText());
copy.setUnicode(text.getUnicode());
return copy;
}
Aggregations