Search in sources :

Example 1 with BaselineType

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);
            }
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) Point(java.awt.Point) TrpWordType(eu.transkribus.core.model.beans.pagecontent_trp.TrpWordType) Point(java.awt.Point) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DocumentException(com.itextpdf.text.DocumentException) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpBaselineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpBaselineType) Entry(java.util.Map.Entry) BaselineType(eu.transkribus.core.model.beans.pagecontent.BaselineType) TrpBaselineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpBaselineType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DocumentException (com.itextpdf.text.DocumentException)1 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)1 BaselineType (eu.transkribus.core.model.beans.pagecontent.BaselineType)1 TrpBaselineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpBaselineType)1 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)1 TrpWordType (eu.transkribus.core.model.beans.pagecontent_trp.TrpWordType)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 JAXBException (javax.xml.bind.JAXBException)1