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));
}
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";
}
}
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));
}
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);
}
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);
}
Aggregations