Search in sources :

Example 6 with TextStyleTag

use of eu.transkribus.core.model.beans.customtags.TextStyleTag in project TranskribusCore by Transkribus.

the class CustomTagListTest method testMultipleRandomIndexedAddOrMergeTag.

// @Ignore
@Test
public void testMultipleRandomIndexedAddOrMergeTag() {
    TrpTextLineType line = new TrpTextLineType(new TrpTextRegionType(new TrpPageType()));
    line.setUnicodeText("Hello world!", null);
    CustomTagList tl = new CustomTagList(line);
    int textLength = tl.getTextLength();
    CustomTag wholeRangeTag = new CustomTag("test", 0, textLength);
    String[] nonIndexedTags = new String[] { "a_non_indexed", "b_ni", "c_balbla_non_indexed" };
    // + overlap to test exceptions when index out of bounds!
    int rangeOfTags = textLength + 5;
    final int N = (int) 1e3;
    for (int i = 0; i < N; ++i) {
        // int sizeBefore = tl.getIndexedTags("test").size();
        int o = rand.nextInt(rangeOfTags);
        int l = rand.nextInt(rangeOfTags - o) + 1;
        CustomTag ct = null;
        int d = rand.nextInt(3);
        if (d == 0) {
            // structure tag
            ct = new CustomTag("a_test_indexed", o, l);
        } else if (d == 1) {
            // text style tag
            ct = new TextStyleTag(o, l);
            ((TextStyleTag) ct).setBold(rand.nextBoolean());
            ((TextStyleTag) ct).setItalic(rand.nextBoolean());
            ((TextStyleTag) ct).setMonospace(rand.nextBoolean());
        } else {
            ct = new CustomTag(nonIndexedTags[rand.nextInt(3)]);
        // ct = new CustomTag("non-indexed");
        }
        // logger.info("range: "+o+","+l);
        // CustomTag ct = new CustomTag("test", o, l);
        logger.trace("i=" + i + "/" + N);
        logger.trace("adding custom tag: " + ct);
        logger.trace("list before = " + tl);
        try {
            tl.addOrMergeTag(ct, null);
            Assert.assertTrue("Indexed CustomTag was not inside but no exception thrown: " + ct, !ct.isIndexed() || wholeRangeTag.getOverlapType(ct) == OverlapType.INSIDE);
        } catch (IndexOutOfBoundsException ie) {
            Assert.assertTrue("CustomTag was inside but exception thrown: " + ct, wholeRangeTag.getOverlapType(ct) != OverlapType.INSIDE);
            logger.trace("Exception for tag not inside: " + ct);
        }
        logger.trace("list after = " + tl);
        checkIntegrity(tl);
    // int sizeAfter = tl.getIndexedTags("test").size();
    // logger.debug("sizeAfter = "+sizeAfter);
    }
    logger.info("list = " + tl);
}
Also used : TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType) Test(org.junit.Test)

Example 7 with TextStyleTag

use of eu.transkribus.core.model.beans.customtags.TextStyleTag in project TranskribusCore by Transkribus.

the class CustomTagListTest method testAddBothOverlap.

// @Ignore
@Test
public void testAddBothOverlap() {
    TrpTextLineType line = new TrpTextLineType(new TrpTextRegionType(new TrpPageType()));
    line.setUnicodeText("Hello world and all parallel worlds!", null);
    // line.setUnicodeText("hello", who);
    CustomTagList tl = new CustomTagList(line);
    // int l=10;
    TextStyleTag ts1 = new TextStyleTag(2, 3);
    ts1.setBold(true);
    ts1.setItalic(true);
    tl.addOrMergeTag(ts1, null);
    logger.debug("tl1 = " + tl);
    TextStyleTag ts2 = new TextStyleTag(6, 2);
    ts2.setBold(true);
    ts2.setSuperscript(true);
    tl.addOrMergeTag(ts2, null);
    logger.debug("tl2 = " + tl);
    TextStyleTag ts3 = new TextStyleTag(9, 11);
    tl.addOrMergeTag(ts3, null);
    logger.debug("tl3 = " + tl);
    Assert.assertEquals("Nr. of merged elements must be 2 --> empty tags shall be removed!", 2, tl.getTags().size());
}
Also used : TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType) Test(org.junit.Test)

Example 8 with TextStyleTag

use of eu.transkribus.core.model.beans.customtags.TextStyleTag in project TranskribusCore by Transkribus.

the class TextStyleTagTest method testEqualsObject.

@Test
public void testEqualsObject() {
    TextStyleTag t1 = new TextStyleTag();
    TextStyleTag t2 = new TextStyleTag();
    TextStyleTag t3 = new TextStyleTag();
    t1.setFontFamily("hello");
    t1.setBold(true);
    t1.setItalic(true);
    t2 = t1.copy();
    t3 = t1.copy();
    t3.setFontFamily("hello1");
    Assert.assertTrue("Should be equal!", t1.equalsEffectiveValues(t2, true));
    Assert.assertFalse("Should not be equal!", t3.equalsEffectiveValues(t1, true));
}
Also used : TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) Test(org.junit.Test)

Example 9 with TextStyleTag

use of eu.transkribus.core.model.beans.customtags.TextStyleTag in project TranskribusCore by Transkribus.

the class TextStyleTagTest method testAddFields.

@Test
public void testAddFields() {
    TextStyleTag t1 = new TextStyleTag();
    TextStyleTag t2 = new TextStyleTag();
    TextStyleTag t3 = new TextStyleTag();
    TextStyleTag t4 = new TextStyleTag();
    t1.setFontFamily("hello1");
    t1.setKerning(1);
    t1.setBold(true);
    t1.setItalic(true);
    t1.setStrikethrough(true);
    t1.setSuperscript(true);
    t2.setFontFamily("hello");
    t2.setKerning(0);
    t2.setFontSize(10.0f);
    t2.setMonospace(true);
    t2.setBold(true);
    t2.setItalic(true);
    logger.info("t1 before = " + t1);
    logger.info("t2 = " + t2);
    t3.setFontFamily("hello");
    t3.setKerning(0);
    t3.setFontSize(10.0f);
    t3.setBold(true);
    t3.setItalic(true);
    t3.setMonospace(true);
    t4.setOffset(2);
    t4.setLength(2);
    t4.setFontFamily("hello");
    t4.setKerning(1);
    t4.setFontSize(10.0f);
    t4.setBold(true);
    t4.setItalic(true);
    t4.setMonospace(true);
    t4.setStrikethrough(false);
    t1.setAttributes(t2, false);
    // Assert.assertTrue("Merged objects do not agree with test object 1", t3.equals(t1));
    logger.info("t1 after merge = " + t1);
    logger.info("t3 = " + t3);
    logger.info("t4 = " + t4);
    Assert.assertTrue("Merged objects should equal", t3.equalsEffectiveValues(t1, true));
    Assert.assertTrue("Merged objects should equal in effective values", t3.equalsEffectiveValues(t1, false));
    Assert.assertFalse("Merged objects should equal", t4.equalsEffectiveValues(t1, true));
    t3.setOffset(0);
    t3.setLength(4);
    logger.info("t3 = " + t3);
    Assert.assertTrue("Merged objects should not agree", t3.equalsEffectiveValues(t1, false));
    Assert.assertFalse("Merged objects should not agree", t3.equalsEffectiveValues(t1, true));
// logger.info("t3 = "+t3);
}
Also used : TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) Test(org.junit.Test)

Example 10 with TextStyleTag

use of eu.transkribus.core.model.beans.customtags.TextStyleTag in project TranskribusCore by Transkribus.

the class TextStyleTypeUtils method applyTextStyleToCustomTag.

/**
 * If a global TextStyleType is set, apply it to the custom tag, if not leave custom tag as it is!
 */
public static void applyTextStyleToCustomTag(ITrpShapeType shape) {
    TextStyleTag tst = getTextStyleAsCustomTag(shape);
    if (tst != null) {
        // there is a "global" text style type --> remove current text style tags and add new "global" text style tag
        shape.getCustomTagList().removeTags(TextStyleTag.TAG_NAME);
        logger.trace("global text style tst = " + tst);
        shape.getCustomTagList().addOrMergeTag(tst, null);
        logger.trace("synced custom tag: " + shape.getCustom());
    }
}
Also used : TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag)

Aggregations

TextStyleTag (eu.transkribus.core.model.beans.customtags.TextStyleTag)13 CustomTagList (eu.transkribus.core.model.beans.customtags.CustomTagList)6 Test (org.junit.Test)6 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)5 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)5 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)5 TrpPageType (eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType)4 Chunk (com.itextpdf.text.Chunk)2 AbbrevTag (eu.transkribus.core.model.beans.customtags.AbbrevTag)2 CommentTag (eu.transkribus.core.model.beans.customtags.CommentTag)2 GapTag (eu.transkribus.core.model.beans.customtags.GapTag)2 Point (java.awt.Point)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BaseColor (com.itextpdf.text.BaseColor)1 Phrase (com.itextpdf.text.Phrase)1 RtfText (com.tutego.jrtf.RtfText)1 OrganizationTag (eu.transkribus.core.model.beans.customtags.OrganizationTag)1 PersonTag (eu.transkribus.core.model.beans.customtags.PersonTag)1 PlaceTag (eu.transkribus.core.model.beans.customtags.PlaceTag)1