use of eu.transkribus.core.model.beans.pagecontent.BaselineType in project TranskribusCore by Transkribus.
the class TrpPdfDocument method highlightTagsForShape.
private void highlightTagsForShape(ITrpShapeType shape, boolean rtl, ExportCache cache) throws IOException {
int tagId = 0;
int k = 1;
Set<Entry<CustomTag, String>> entrySet = ExportUtils.getAllTagsForShapeElement(shape).entrySet();
// Set<String> wantedTags = ExportUtils.getOnlyWantedTagnames(CustomTagFactory.getRegisteredTagNames());
Set<String> wantedTags = cache.getOnlySelectedTagnames(CustomTagFactory.getRegisteredTagNames());
// logger.debug("wanted tags in TRPPDFDOC " + wantedTags.size());
int[] prevLength = new int[entrySet.size()];
int[] prevOffset = new int[entrySet.size()];
boolean falling = true;
BaselineType baseline = null;
if (shape instanceof TrpTextLineType) {
TrpTextLineType l = (TrpTextLineType) shape;
baseline = l.getBaseline();
} else if (shape instanceof TrpWordType) {
TrpWordType w = (TrpWordType) shape;
TrpTextLineType l = (TrpTextLineType) w.getParentShape();
baseline = l.getBaseline();
}
try {
List<Point> ptsList = null;
if (baseline != null) {
ptsList = PointStrUtils.parsePoints(baseline.getPoints());
}
if (ptsList != null) {
int size = ptsList.size();
// logger.debug("l.getBaseline().getPoints() " + l.getBaseline().getPoints());
if (size >= 2 && ptsList.get(0).y < ptsList.get(size - 1).y) {
// logger.debug("falling is false ");
falling = false;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Map.Entry<CustomTag, String> currEntry : entrySet) {
if (wantedTags.contains(currEntry.getKey().getTagName())) {
String color = CustomTagFactory.getTagColor(currEntry.getKey().getTagName());
int currLength = currEntry.getKey().getLength();
int currOffset = currEntry.getKey().getOffset();
/**
* if the current tag overlaps one of the previous tags
* -> increase the distance of the line under the textline
*/
// if (isOverlaped(prevOffset, prevLength, currOffset, currLength)){
// k++;
// }
// else{
// k=1;
// }
k = getAmountOfOverlaps(prevOffset, prevLength, currOffset, currLength);
// logger.debug("current tag name "+ currEntry.getKey().getTagName() + " k is " + k);
// logger.debug("current tag text "+ currEntry.getKey().getContainedText());
prevOffset[tagId] = currOffset;
prevLength[tagId] = currLength;
tagId++;
float yShift = (lineMeanHeight / 6) * k;
/*
* remember where to draw line with help of a list
*/
if (baseline != null) {
// use lowest point in baseline and move up one half of the distance to the topmost point
// java.awt.Rectangle baseLineRect = PageXmlUtils.buildPolygon(baseline.getPoints()).getBounds();
java.awt.Rectangle baseLineRect = ((TrpBaselineType) baseline).getBoundingBox();
calculateTagLines(baseLineRect, shape, currEntry.getKey().getContainedText(), currOffset, currLength, color, yShift, falling, rtl);
}
}
}
}
Aggregations