Search in sources :

Example 1 with RtfPara

use of com.tutego.jrtf.RtfPara in project TranskribusCore by Transkribus.

the class TrpRtfBuilder method writeRtfForDoc.

public static void writeRtfForDoc(TrpDoc doc, boolean wordBased, boolean writeTags, boolean doBlackening, File file, Set<Integer> pageIndices, IProgressMonitor monitor, ExportCache cache) throws JAXBException, IOException {
    exportTags = writeTags;
    tagnames = cache.getSelectedTags();
    TrpRtfBuilder.doBlackening = doBlackening;
    /*
		 * get all names of tags
		 */
    // tagnames = CustomTagFactory.getRegisteredTagNames();
    Rtf rtf = Rtf.rtf();
    List<TrpPage> pages = doc.getPages();
    int totalPages = pageIndices == null ? pages.size() : pageIndices.size();
    if (monitor != null) {
        monitor.beginTask("Exporting to RTF", totalPages);
    }
    int c = 0;
    for (int i = 0; i < pages.size(); ++i) {
        if (pageIndices != null && !pageIndices.contains(i))
            continue;
        if (monitor != null) {
            if (monitor.isCanceled()) {
                logger.debug("RTF export cancelled!");
                return;
            }
            monitor.subTask("Processing page " + (c + 1));
        }
        TrpPage page = pages.get(i);
        TrpTranscriptMetadata md = page.getCurrentTranscript();
        JAXBPageTranscript tr = new JAXBPageTranscript(md);
        tr.build();
        TrpPageType trpPage = tr.getPage();
        logger.debug("writing rtf for page " + (i + 1) + "/" + doc.getNPages());
        // rtf().header(color( 204, 0, 0 ).at( 0 ),
        // color( 0, 0xff, 0 ).at( 1 ),
        // color( 0, 0, 0xff ).at( 2 ),
        // font( "Calibri" ).at( 0 ) );
        // RtfHeaderColor color = RtfHeaderColor.color(0xff, 0, 0);
        rtf.header(color(204, 0, 0).at(0), color(0, 0xff, 0).at(1)).section(getRtfParagraphsForTranscript(trpPage, wordBased));
        ++c;
        if (monitor != null) {
            monitor.worked(c);
        }
    }
    // write tags at end of last page
    if (exportTags) {
        // RtfText headline = RtfText.text("Person names in this document (amount of found persons: " + persons.size() + ")", "\n");
        /*
			 * for all different tagnames:
			 * find all custom tags in doc
			 * create list and 
			 */
        ArrayList<RtfPara> tagParas = new ArrayList<RtfPara>();
        // tagnames = all user choosen tags via export dialog
        for (String currTagname : tagnames) {
            // logger.debug("curr tagname " + currTagname);
            // get all custom tags with currTagname and text
            HashMap<CustomTag, String> allTagsOfThisTagname = cache.getTags(currTagname);
            if (allTagsOfThisTagname.size() > 0) {
                tagParas.add(RtfPara.p(RtfText.text(RtfText.underline(currTagname + " tags in this document: " + allTagsOfThisTagname.size()))));
                // ArrayList<RtfText> tagTexts = new ArrayList<RtfText>();
                Collection<String> valueSet = allTagsOfThisTagname.values();
                RtfText[] tagTexts = new RtfText[valueSet.size()];
                int l = 0;
                for (String currEntry : valueSet) {
                    tagTexts[l++] = RtfText.text(currEntry.concat("\n"));
                // logger.debug("tag value is " + currEntry);
                }
                tagParas.add(RtfPara.p(tagTexts));
            }
        }
        // int parSize = getParsNumber();
        // int k = 0;
        // 
        // if (persons.size() > 0){
        // logger.debug("k is " + k);
        // List<String> newPersonList = new ArrayList<String>(new HashSet<String>(persons));
        // tagParas[k++]=RtfPara.p(RtfText.text("Person names in this document (amount of found persons: " + newPersonList.size() + ")", "\n"));
        // logger.debug("k is " + k);
        // //rtf.p("Person names in this document (amount of found persons: " + persons.size() + ")", "\n");
        // //to make the list contain only unique values
        // 
        // RtfText[] personTexts = new RtfText[newPersonList.size()];
        // for (int j=0; j<newPersonList.size(); ++j) {
        // personTexts[j] = RtfText.text(newPersonList.get(j), "\n");
        // logger.debug("person is " + newPersonList.get(j));
        // }
        // tagParas[k++] = RtfPara.p(personTexts);
        // }
        // 
        // if (places.size() > 0){
        // List<String> newPlaceList = new ArrayList<String>(new HashSet<String>(places));
        // tagParas[k++]=RtfPara.p(RtfText.text("Places in this document (amount of found places " + newPlaceList.size() + ")", "\n"));
        // 
        // RtfText[] placeTexts = new RtfText[newPlaceList.size()];
        // for (int j=0; j<newPlaceList.size(); ++j) {
        // //RtfText.color(0, "red");
        // placeTexts[j] = RtfText.color(0, newPlaceList.get(j).concat("\n"));
        // logger.debug("place is " + newPlaceList.get(j));
        // }
        // RtfPara par2 = RtfPara.p(placeTexts);
        // tagParas[k++] = par2;
        // }
        // 
        // if(addresses.size() > 0){
        // List<String> newAddressList = new ArrayList<String>(new HashSet<String>(addresses));
        // tagParas[k++]=RtfPara.p(RtfText.text("Addresses in this document (amount of found addresses " + newAddressList.size() + ")", "\n"));
        // 
        // RtfText[] addresseTexts = new RtfText[newAddressList.size()];
        // for (int j=0; j<newAddressList.size(); ++j) {
        // addresseTexts[j] = RtfText.text(newAddressList.get(j), "\n");
        // logger.debug("addresse is " + newAddressList.get(j));
        // }
        // RtfPara par3 = RtfPara.p(addresseTexts);
        // tagParas[k++] = par3;
        // }
        // rtf.section(par3);
        rtf.header(color(204, 0, 0).at(0)).section(tagParas);
    }
    rtf.out(new FileWriter(file));
    logger.info("wrote rtf to: " + file.getAbsolutePath());
}
Also used : JAXBPageTranscript(eu.transkribus.core.model.beans.JAXBPageTranscript) Rtf(com.tutego.jrtf.Rtf) TrpPage(eu.transkribus.core.model.beans.TrpPage) RtfText(com.tutego.jrtf.RtfText) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) TrpTranscriptMetadata(eu.transkribus.core.model.beans.TrpTranscriptMetadata) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) RtfPara(com.tutego.jrtf.RtfPara) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType)

Example 2 with RtfPara

use of com.tutego.jrtf.RtfPara in project TranskribusCore by Transkribus.

the class TrpRtfBuilder method getRtfParagraphsForTranscript.

// public static void writeRtfForElement(Rtf rtf, ITrpShapeType element, boolean wordBased, File file, boolean append) throws IOException, JAXBException {
// element.getUnicodeText();
// CustomTagList cl = element.getCustomTagList();
// 
// RtfText text = RtfText.text(element.getUnicodeText());
// text = formatRtfText(text, element.getTextStyle());
// 
// 
// 
// if (element instanceof TextLineType || element instanceof TextRegionType) {// TODO words vs lines and regions
// rtf.p(text);
// } else if (element instanceof TrpWordType) {
// //			rtf.p(texts);
// }
// 
// 
// //		cl.getCustomTagAndContinuations(tag)
// 
// 
// 
// }
public static RtfPara[] getRtfParagraphsForTranscript(TrpPageType trpPage, boolean wordBased) throws IOException, JAXBException {
    boolean rtl = false;
    List<TrpTextRegionType> textRegions = trpPage.getTextRegions(true);
    // List<TrpTextRegionType> textRegions = trpPage.getTextRegionsAndTextRegionsFromTableRegions(true);
    RtfPara[] paras = new RtfPara[textRegions.size()];
    for (int j = 0; j < textRegions.size(); ++j) {
        TrpTextRegionType r = textRegions.get(j);
        // if (exportTags){
        // getTagsForShapeElement(r);
        // }
        List<TextLineType> lines = r.getTextLine();
        RtfText[] linesTexts = new RtfText[lines.size()];
        for (int i = 0; i < lines.size(); ++i) {
            TrpTextLineType trpL = (TrpTextLineType) lines.get(i);
            linesTexts[i] = (wordBased && trpL.getWord().size() > 0) ? getRtfTextForLineFromWords(trpL) : getRtfTextForShapeElement(trpL);
            linesTexts[i] = RtfText.text(linesTexts[i], "\n");
        }
        // read from right to left -> alignment is right
        if (rtl) {
        // paras[j] = RtfPara.p(linesTexts).footnote("Test").alignRight();
        } else {
            String test = "test";
            paras[j] = RtfPara.p(linesTexts);
        // paras[j] = RtfPara.p(linesTexts, RtfText.footnote("Test")).alignLeft();
        }
    }
    return paras;
// Rtf rtf = Rtf.rtf().section(paras);
// return rtf;
// for (RegionType r : trpPage.getTextRegionOrImageRegionOrLineDrawingRegion()) {
// if (r instanceof GraphicRegionType) {
// GraphicRegionType gr = (GraphicRegionType) r;
// // TODO: how to export images in pdf??
// r.getTextRegions(recursive);
// }
// }
// tr.getPage().getTextRegions(recursive);
// Rtf.rtf();
// RtfWriter;
}
Also used : RtfPara(com.tutego.jrtf.RtfPara) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TextLineType(eu.transkribus.core.model.beans.pagecontent.TextLineType) TrpTextLineType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType) TrpTextRegionType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType) RtfText(com.tutego.jrtf.RtfText)

Aggregations

RtfPara (com.tutego.jrtf.RtfPara)2 RtfText (com.tutego.jrtf.RtfText)2 Rtf (com.tutego.jrtf.Rtf)1 JAXBPageTranscript (eu.transkribus.core.model.beans.JAXBPageTranscript)1 TrpPage (eu.transkribus.core.model.beans.TrpPage)1 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)1 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)1 TextLineType (eu.transkribus.core.model.beans.pagecontent.TextLineType)1 TrpPageType (eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType)1 TrpTextLineType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextLineType)1 TrpTextRegionType (eu.transkribus.core.model.beans.pagecontent_trp.TrpTextRegionType)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1