Search in sources :

Example 1 with ITrpShapeType

use of eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType in project TranskribusCore by Transkribus.

the class TextStyleTypeUtils method setTextStyleTag.

/**
 * Sets the <em>global</em> text style for the given shape.
 */
public static void setTextStyleTag(ITrpShapeType shape, TextStyleType s, boolean recursive, Object who) {
    shape.setTextStyle(TextStyleTypeUtils.addTextStyleTypeFields(s, shape.getTextStyle(), true));
    TextStyleTypeUtils.applyTextStyleToCustomTag(shape);
    if (recursive) {
        for (ITrpShapeType c : shape.getChildren(recursive)) {
            c.getObservable().setActive(false);
            c.setTextStyle(s, recursive, who);
            c.getObservable().setActive(true);
        }
    }
    shape.getObservable().setChangedAndNotifyObservers(new TrpTextStyleChangedEvent(who));
}
Also used : TrpTextStyleChangedEvent(eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpTextStyleChangedEvent) ITrpShapeType(eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)

Example 2 with ITrpShapeType

use of eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType in project TranskribusCore by Transkribus.

the class CustomTag method getNeighborText.

public String getNeighborText(boolean before, int N) {
    if (customTagList == null)
        return "";
    String txtOfShape = customTagList.getShape().getUnicodeText();
    // first get neighboring text of same shape
    String txt = "";
    try {
        if (before) {
            txt = txtOfShape.substring(0, getOffset());
        } else {
            txt = txtOfShape.substring(getEnd());
        }
    } catch (IndexOutOfBoundsException e) {
        txt = "";
    }
    // if this is not enough (i.e. length < N), try to get some text from neighboring shapes
    ITrpShapeType n = customTagList.getShape().getSiblingShape(before);
    String del = " ";
    while (n != null && txt.length() < N) {
        if (before) {
            txt = n.getUnicodeText() + del + txt;
        } else {
            txt += del + n.getUnicodeText();
        }
        n = n.getSiblingShape(before);
    }
    // cut text if too long, respecting word boundaries
    try {
        if (txt.length() > N) {
            int startIndex = before ? txt.length() - 1 : 0;
            txt = CoreUtils.neighborString(txt, startIndex, N, before, true);
        // txt = before ? txt.substring(txt.length()-N) : txt.substring(0, N);
        }
        return txt;
    } catch (IndexOutOfBoundsException ex) {
        // should not happen...
        return "i am error";
    }
}
Also used : ITrpShapeType(eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)

Example 3 with ITrpShapeType

use of eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType in project TranskribusCore by Transkribus.

the class CustomTagUtil method setStructure.

public static void setStructure(ITrpShapeType shape, String structureType, boolean recursive, Object who) {
    if (shape == null)
        return;
    logger.trace("setting structure: " + structureType + " id: " + shape.getId() + " type: " + shape.getClass().getSimpleName() + " recursive: " + recursive);
    if (!isTextregionOrLineOrWord(shape))
        return;
    if (shape instanceof TrpTextRegionType) {
        // if this is a text region, also set PAGE structure field if possible
        TextTypeSimpleType s = StructureTag.parseTextType(structureType);
        ((TrpTextRegionType) shape).setType(s);
    }
    // set custom tag:
    if (structureType == null || structureType.equals(""))
        shape.getCustomTagList().removeTags(StructureTag.TAG_NAME);
    else {
        shape.getCustomTagList().addOrMergeTag(new StructureTag(structureType), null);
    }
    if (recursive) {
        for (ITrpShapeType c : shape.getChildren(recursive)) {
            c.setStructure(structureType, recursive, who);
        }
    }
    shape.getObservable().setChangedAndNotifyObservers(new TrpStructureChangedEvent(who));
}
Also used : TextTypeSimpleType(eu.transkribus.core.model.beans.pagecontent.TextTypeSimpleType) TrpStructureChangedEvent(eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpStructureChangedEvent) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) ITrpShapeType(eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)

Example 4 with ITrpShapeType

use of eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType in project TranskribusCore by Transkribus.

the class CustomTagList method getPreviousContinuedCustomTag.

public Pair<CustomTagList, CustomTag> getPreviousContinuedCustomTag(CustomTag ct) {
    if (// tag is not in the list
    !hasTag(ct) || !ct.isContinued())
        return null;
    if (// tag does not start at beginning
    ct.getOffset() != 0)
        return null;
    // get previous shape:
    ITrpShapeType prevShape = shape.getSiblingShape(true);
    if (prevShape == null)
        return null;
    int lastIndex = Math.max(0, prevShape.getCustomTagList().getTextLength() - 1);
    CustomTag prevTag = prevShape.getCustomTagList().getOverlappingTag(ct.getTagName(), lastIndex);
    logger.trace("prevTag = " + prevTag);
    if (prevTag == null || !prevTag.isContinued())
        return null;
    return Pair.of(prevShape.getCustomTagList(), prevTag);
}
Also used : ITrpShapeType(eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)

Example 5 with ITrpShapeType

use of eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType in project TranskribusCore by Transkribus.

the class CustomTagList method getNextContinuedCustomTag.

public Pair<CustomTagList, CustomTag> getNextContinuedCustomTag(CustomTag ct) {
    if (// tag is not in the list
    !hasTag(ct) || !ct.isContinued())
        return null;
    if (// tag does not reach the end
    ct.getEnd() != getTextLength())
        return null;
    // get next shape:
    ITrpShapeType nextShape = shape.getSiblingShape(false);
    if (nextShape == null)
        return null;
    CustomTag nextTag = nextShape.getCustomTagList().getOverlappingTag(ct.getTagName(), 0);
    if (nextTag == null || !nextTag.isContinued())
        return null;
    return Pair.of(nextShape.getCustomTagList(), nextTag);
}
Also used : ITrpShapeType(eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)

Aggregations

ITrpShapeType (eu.transkribus.core.model.beans.pagecontent_trp.ITrpShapeType)9 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)3 RegionType (eu.transkribus.core.model.beans.pagecontent.RegionType)2 TrpRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpRegionType)2 TrpTableRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTableRegionType)2 Image (com.itextpdf.text.Image)1 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)1 OrderedGroupType (eu.transkribus.core.model.beans.pagecontent.OrderedGroupType)1 RegionRefIndexedType (eu.transkribus.core.model.beans.pagecontent.RegionRefIndexedType)1 TextRegionType (eu.transkribus.core.model.beans.pagecontent.TextRegionType)1 TextTypeSimpleType (eu.transkribus.core.model.beans.pagecontent.TextTypeSimpleType)1 UnknownRegionType (eu.transkribus.core.model.beans.pagecontent.UnknownRegionType)1 WordType (eu.transkribus.core.model.beans.pagecontent.WordType)1 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)1 TrpStructureChangedEvent (eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpStructureChangedEvent)1 TrpTextStyleChangedEvent (eu.transkribus.core.model.beans.pagecontent_trp.observable.TrpObserveEvent.TrpTextStyleChangedEvent)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1