Search in sources :

Example 6 with U

use of org.docx4j.wml.U in project TranskribusCore by Transkribus.

the class DocxBuilder method createIt.

public static P createIt() {
    org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
    P p = wmlObjectFactory.createP();
    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    p.setPPr(ppr);
    // Create object for rPr
    ParaRPr pararpr = wmlObjectFactory.createParaRPr();
    ppr.setRPr(pararpr);
    // Create object for u
    U u = wmlObjectFactory.createU();
    pararpr.setU(u);
    u.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
    // Create object for lang
    CTLanguage language = wmlObjectFactory.createCTLanguage();
    pararpr.setLang(language);
    language.setVal("en-AU");
    // Create object for jc
    Jc jc = wmlObjectFactory.createJc();
    ppr.setJc(jc);
    jc.setVal(org.docx4j.wml.JcEnumeration.CENTER);
    // Create object for r
    R r = wmlObjectFactory.createR();
    p.getContent().add(r);
    // Create object for rPr
    RPr rpr = wmlObjectFactory.createRPr();
    r.setRPr(rpr);
    // Create object for u
    U u2 = wmlObjectFactory.createU();
    rpr.setU(u2);
    u2.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
    // Create object for lang
    CTLanguage language2 = wmlObjectFactory.createCTLanguage();
    rpr.setLang(language2);
    language2.setVal("en-AU");
    // Create object for t (wrapped in JAXBElement)
    Text text = wmlObjectFactory.createText();
    JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
    r.getContent().add(textWrapped);
    text.setValue("Underlined and centred");
    return p;
}
Also used : Text(org.docx4j.wml.Text) P(org.docx4j.wml.P) CTLanguage(org.docx4j.wml.CTLanguage) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) U(org.docx4j.wml.U) RPr(org.docx4j.wml.RPr) ParaRPr(org.docx4j.wml.ParaRPr) ParaRPr(org.docx4j.wml.ParaRPr) Jc(org.docx4j.wml.Jc)

Example 7 with U

use of org.docx4j.wml.U in project TranskribusCore by Transkribus.

the class DocxBuilder method getFormattedTextForShapeElement.

private static void getFormattedTextForShapeElement(ITrpShapeType element, P p, MainDocumentPart mdp) throws Exception {
    ArrayList<R> listOfallRuns = new ArrayList<R>();
    String textStr = element.getUnicodeText();
    CustomTagList cl = element.getCustomTagList();
    if (textStr == null || cl == null)
        throw new IOException("Element has no text or custom tag list: " + element + ", class: " + element.getClass().getName());
    if (textStr.isEmpty()) {
        return;
    }
    boolean rtl = false;
    // from right to left
    if (Character.getDirectionality(textStr.charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT || Character.getDirectionality(textStr.charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC || Character.getDirectionality(textStr.charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING || Character.getDirectionality(textStr.charAt(0)) == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE) {
        logger.debug("&&&&&&&& STRING IS RTL : ");
        deleteCharAtIndex(0, textStr);
        rtl = true;
    }
    // format according to tags:CustomTagList
    for (CustomTag nonIndexedTag : cl.getNonIndexedTags()) {
        // exchange chars with * if wished to be blackened
        if (doBlackening && nonIndexedTag.getTagName().equals(RegionTypeUtil.BLACKENING_REGION.toLowerCase())) {
            // logger.debug("nonindexed tag found ");
            textStr = ExportUtils.blackenString(nonIndexedTag, textStr);
        }
        /*
			 * for gap and comment: remember their position to find and add them to their corresponding 'run' later on 
			 * 
			 */
        if (nonIndexedTag.getTagName().equals("gap")) {
            GapTag gap = (GapTag) nonIndexedTag;
            gapList.put(nonIndexedTag.getOffset(), gap);
        }
    // unclear and comments can not be non-indexed
    // if (nonIndexedTag.getTagName().equals("comment")){
    // logger.debug("nonindexed comment tag found ");
    // CommentTag ct = (CommentTag) nonIndexedTag;
    // commentList.put(nonIndexedTag.getEnd()-1, ct.getComment());
    // }
    // if(nonIndexedTag.getTagName().equals("unclear")){
    // logger.debug("unclear tag found ");
    // unclearList.put(nonIndexedTag.getOffset(), nonIndexedTag.getOffset()+nonIndexedTag.getLength());
    // }
    }
    for (CustomTag indexedTag : cl.getIndexedTags()) {
        if (doBlackening && indexedTag.getTagName().equals(RegionTypeUtil.BLACKENING_REGION.toLowerCase())) {
            textStr = ExportUtils.blackenString(indexedTag, textStr);
        }
        /*
			 * find all gaps and store the offset
			 */
        if (indexedTag.getTagName().equals("gap")) {
            GapTag gap = (GapTag) indexedTag;
            gapList.put(indexedTag.getOffset(), gap);
        }
        if (indexedTag.getTagName().equals("comment")) {
            // logger.debug("indexed comment tag found at pos " + (indexedTag.getEnd()-1));
            CommentTag ct = (CommentTag) indexedTag;
            commentList.put(indexedTag.getEnd() - 1, ct.getComment());
        }
        // if(exportTags){
        if (markUnclearWords && indexedTag.getTagName().equals("unclear")) {
            // logger.debug("unclear tag found ");
            // logger.debug("unclear start is: " + indexedTag.getOffset());
            // logger.debug("unclear end is: " + (indexedTag.getEnd()-1));
            unclearList.put(indexedTag.getOffset(), indexedTag.getEnd() - 1);
        }
        if (expandAbbrevs && indexedTag.getTagName().equals("abbrev")) {
            logger.debug("abbrev tag found ");
            AbbrevTag at = (AbbrevTag) indexedTag;
            String expansion = at.getExpansion();
            // only add if an expansion was typed
            if (!expansion.equals("")) {
                expandAbbrevList.put(indexedTag.getEnd(), at.getExpansion());
            }
        }
        if (substituteAbbrevs && indexedTag.getTagName().equals("abbrev")) {
            // logger.debug("abbrev tag found ");
            AbbrevTag at = (AbbrevTag) indexedTag;
            String expansion = at.getExpansion();
            // key is the start of the abbrev
            if (!expansion.equals("")) {
                substituteAbbrevList.put(indexedTag.getOffset(), at);
            }
        }
        if (showSuppliedWithBrackets && indexedTag.getTagName().equals("supplied")) {
            // logger.debug("supplied tag found ");
            SuppliedTag at = (SuppliedTag) indexedTag;
            String text = at.getContainedText();
            // only add if an expansion was typed
            if (!text.equals("")) {
                showSuppliedList.put(indexedTag.getOffset(), text);
            }
        }
        if (ignoreSupplied && indexedTag.getTagName().equals("supplied")) {
            // logger.debug("supplied tag found ");
            SuppliedTag at = (SuppliedTag) indexedTag;
            String text = at.getContainedText();
            // only add if an expansion was typed
            if (!text.equals("")) {
                ignoreSuppliedList.put(indexedTag.getOffset(), text);
            }
        }
        // create index for all choosen tagnames
        if (exportTags && tagnames.contains(indexedTag.getTagName()) && !indexedTag.getTagName().equals("gap")) {
            // logger.debug("export tag as idx entry " + indexedTag.getOffset());
            addValuesToIdxList(idxList, indexedTag.getEnd(), indexedTag);
        }
    // }
    }
    List<TextStyleTag> textStylesTags = element.getTextStyleTags();
    // ArrayList<R> runs = new ArrayList<R>();
    boolean shapeEnded = false;
    for (int i = 0; i <= textStr.length(); ++i) {
        // use of abbrevIdx: this is necessary for the appearance at the end of a textline
        // otherwise the abbrev expansion would not appear at the end of a line because then the index i would be too small
        shapeEnded = (i + 1 >= textStr.length() ? true : false);
        /*
			 * is this case the abbrev gets totally replaced by its expansion
			 * so if the start of the abbrev was found the expansion is written and we can break the writing of the abbrev
			 */
        if (substituteAbbrevList.containsKey(i)) {
            String exp = substituteAbbrevList.get(i).getExpansion();
            if (rtl) {
                exp = reverseString(exp);
            }
            org.docx4j.wml.Text abbrevText = factory.createText();
            abbrevText.setValue(exp);
            org.docx4j.wml.R abbrevRun = factory.createR();
            // p.getContent().add(abbrevRun);
            abbrevRun.getContent().add(abbrevText);
            listOfallRuns.add(abbrevRun);
            // go to end of the abbreviation and proceed with remaining text
            i += substituteAbbrevList.get(i).getLength();
            shapeEnded = (i == textStr.length() ? true : false);
        }
        /*
			 * add expansion in brackets behind the abbrev		
			 * the abbrev list contains as key the end index of the abbrev	
			 */
        if (expandAbbrevList.containsKey(i)) {
            String exp = expandAbbrevList.get(i);
            if (rtl) {
                exp = reverseString(exp);
            }
            org.docx4j.wml.Text abbrevText = factory.createText();
            abbrevText.setValue("[" + exp + "]");
            org.docx4j.wml.R abbrevRun = factory.createR();
            // p.getContent().add(abbrevRun);
            abbrevRun.getContent().add(abbrevText);
            listOfallRuns.add(abbrevRun);
        }
        /*
			 * in this case the supplied tag is expanded either with or without brackets
			 * 
			 */
        if (showSuppliedList.containsKey(i)) {
            String exp = showSuppliedList.get(i);
            if (rtl) {
                exp = reverseString(exp);
            }
            org.docx4j.wml.Text suppliedText = factory.createText();
            suppliedText.setValue("[" + exp + "]");
            org.docx4j.wml.R suppliedRun = factory.createR();
            suppliedRun.getContent().add(suppliedText);
            listOfallRuns.add(suppliedRun);
            // supplied is handled now - so set i to the end of supplied
            i += showSuppliedList.get(i).length();
            shapeEnded = (i == textStr.length() ? true : false);
        }
        /*
			 * in this case the supplied tag gets ignored
			 * this means that index i must be incremented by the length of this supplied tag text
			 */
        if (ignoreSuppliedList.containsKey(i)) {
            i += ignoreSuppliedList.get(i).length();
            shapeEnded = (i == textStr.length() ? true : false);
        }
        /*
			 * gap is at this position
			 * hence create extra run with [...] as value and then go on
			 * of if suppied attribute is set handle supplied as set in the export settings
			 */
        if (gapList.containsKey(i)) {
            org.docx4j.wml.Text t = factory.createText();
            // if (!rtl)
            // t.setValue("[...] ");
            // else
            // t.setValue(" [...]");
            GapTag gt = gapList.get(i);
            String cta = (String) gt.getAttributeValue("supplied");
            // attribute supplied is set in the gap tag -> handle supplied as wanted
            if (cta != null && !cta.equals("")) {
                // may the gap with supplied attribute gets ignored
                if (!ignoreSupplied) {
                    if (showSuppliedWithBrackets) {
                        t.setValue("[" + cta + "]");
                    }
                // do not show supplied attribute by default!?
                // else{
                // t.setValue(cta);
                // }
                }
            } else // nothing supplied, so show [...] for the gap tag
            {
                t.setValue("[...]");
                t.setSpace("preserve");
            }
            org.docx4j.wml.R run = factory.createR();
            // p.getContent().add(run);
            run.getContent().add(t);
            listOfallRuns.add(run);
        }
        // begin of unclear word should be marked with [ and end with ]
        if (unclearList.containsKey(i)) {
            org.docx4j.wml.Text t = factory.createText();
            if (!rtl)
                t.setValue("[");
            else
                t.setValue("]");
            org.docx4j.wml.R run = factory.createR();
            // p.getContent().add(run);
            run.getContent().add(t);
            listOfallRuns.add(run);
        }
        /*
			 * if so we create an index entry for this text string in the docx
			 */
        if (idxList.containsKey(i)) {
            addIndexEntry(i, p, textStr, rtl);
        }
        String currText = "";
        if (i + 1 <= textStr.length()) {
            currText = textStr.substring(i, i + 1);
        // logger.debug("&&&&&&&& current single char : " + currText);
        }
        /*
			 * 2nd is (should be) soft hyphen with Unicode U+00AD
			 * First arg is not sign and was initially used for soft hyphen by Diggitexx
			 * need to be at the line end - otherwise 
			 * 
			 */
        if ((currText.equals("¬") || currText.equals("­") || currText.equals("-")) && !preserveLineBreaks && shapeEnded) {
            break;
        }
        org.docx4j.wml.Text t = factory.createText();
        t.setValue(currText);
        t.setSpace("preserve");
        org.docx4j.wml.R run = factory.createR();
        // p.getContent().add(run);
        run.getContent().add(t);
        listOfallRuns.add(run);
        // end of unclear tag
        if (unclearList.containsValue(i)) {
            org.docx4j.wml.Text unclearEnd = factory.createText();
            if (!rtl)
                unclearEnd.setValue("]");
            else
                unclearEnd.setValue("[");
            org.docx4j.wml.R unclearRun = factory.createR();
            // p.getContent().add(unclearRun);
            unclearRun.getContent().add(unclearEnd);
            listOfallRuns.add(unclearRun);
        }
        // the properties of this text section
        org.docx4j.wml.RPr rpr = factory.createRPr();
        /*
			 * format according to custom style tag - check for each char in the text if a special style should be set
			 */
        for (TextStyleTag styleTag : textStylesTags) {
            if (i >= styleTag.getOffset() && i < (styleTag.getOffset() + styleTag.getLength())) {
                org.docx4j.wml.BooleanDefaultTrue b = new org.docx4j.wml.BooleanDefaultTrue();
                b.setVal(true);
                TextStyleType ts = styleTag.getTextStyle();
                if (ts == null)
                    continue;
                if (CoreUtils.val(ts.isBold())) {
                    rpr.setB(b);
                }
                if (CoreUtils.val(ts.isItalic())) {
                    rpr.setI(b);
                }
                if (CoreUtils.val(ts.isLetterSpaced())) {
                // ????
                }
                if (CoreUtils.val(ts.isMonospace())) {
                // ????
                }
                if (CoreUtils.val(ts.isReverseVideo())) {
                // ????
                }
                if (CoreUtils.val(ts.isSerif())) {
                // ????
                }
                if (CoreUtils.val(ts.isSmallCaps())) {
                    rpr.setSmallCaps(b);
                }
                if (CoreUtils.val(ts.isStrikethrough())) {
                    rpr.setStrike(b);
                }
                if (CoreUtils.val(ts.isSubscript())) {
                    org.docx4j.wml.CTVerticalAlignRun al = factory.createCTVerticalAlignRun();
                    al.setVal(STVerticalAlignRun.SUBSCRIPT);
                    rpr.setVertAlign(al);
                }
                if (CoreUtils.val(ts.isSuperscript())) {
                    org.docx4j.wml.CTVerticalAlignRun al = factory.createCTVerticalAlignRun();
                    al.setVal(STVerticalAlignRun.SUPERSCRIPT);
                    rpr.setVertAlign(al);
                }
                if (CoreUtils.val(ts.isUnderlined())) {
                    U u = factory.createU();
                    u.setVal(UnderlineEnumeration.SINGLE);
                    rpr.setU(u);
                }
            // BooleanDefaultTrue bdt = Context.getWmlObjectFactory().createBooleanDefaultTrue();
            // bdt.setVal(Boolean.TRUE);
            // rpr.setRtl(bdt);
            // rpr.setHighlight(new Highlight());
            }
        }
        // at the run properties (= text styles) to the run
        run.setRPr(rpr);
        // find position of footnote/comment
        if (commentList.containsKey(i)) {
            // logger.debug("position of comment: " + i);
            // logger.debug("value of comment: " + commentList.get(i));
            // creates the footnote at the end of the wished text - this position was found at the beginning of this method
            org.docx4j.wml.R fnRun = factory.createR();
            // p.getContent().add(fnRun);
            createFootnote(commentList.get(i), fnRun, mdp);
            listOfallRuns.add(fnRun);
        }
        /*
			 * add space at end of line if line breaks are not preserved
			 */
        if (!preserveLineBreaks && shapeEnded) {
            org.docx4j.wml.Text space = factory.createText();
            space.setValue(" ");
            space.setSpace("preserve");
            org.docx4j.wml.R runSpace = factory.createR();
            // p.getContent().add(runSpace);
            runSpace.getContent().add(space);
            listOfallRuns.add(runSpace);
        }
    // runs.add(run);
    }
    if (rtl) {
        PPr paragraphProperties = factory.createPPr();
        Jc justification = factory.createJc();
        justification.setVal(JcEnumeration.RIGHT);
        paragraphProperties.setJc(justification);
        p.setPPr(paragraphProperties);
    }
    for (int i = listOfallRuns.size() - 1; i >= 0; i--) {
        if (rtl) {
            p.getContent().add(listOfallRuns.get(i));
        } else {
            p.getContent().addAll(listOfallRuns);
            break;
        }
    }
    clearAllLists();
}
Also used : ArrayList(java.util.ArrayList) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) RPr(org.docx4j.wml.RPr) R(org.docx4j.wml.R) U(org.docx4j.wml.U) R(org.docx4j.wml.R) Jc(org.docx4j.wml.Jc) Text(org.docx4j.wml.Text) TextStyleType(eu.transkribus.core.model.beans.pagecontent.TextStyleType) SuppliedTag(eu.transkribus.core.model.beans.customtags.SuppliedTag) CustomTagList(eu.transkribus.core.model.beans.customtags.CustomTagList) IOException(java.io.IOException) CommentTag(eu.transkribus.core.model.beans.customtags.CommentTag) TextStyleTag(eu.transkribus.core.model.beans.customtags.TextStyleTag) PPr(org.docx4j.wml.PPr) GapTag(eu.transkribus.core.model.beans.customtags.GapTag) AbbrevTag(eu.transkribus.core.model.beans.customtags.AbbrevTag)

Example 8 with U

use of org.docx4j.wml.U in project TranskribusCore by Transkribus.

the class DocxBuilder method writeDocxForDoc.

public static void writeDocxForDoc(TrpDoc doc, boolean wordBased, boolean writeTags, boolean doBlackeningSensibleData, File file, Set<Integer> pageIndices, IProgressMonitor monitor, boolean createTitle, boolean markUnclear, boolean expandAbbreviations, boolean replaceAbbrevs, boolean keepLineBreaks, boolean showSuppliedInBrackets, boolean ignoreSuppliedTags, ExportCache cache) throws JAXBException, IOException, Docx4JException, InterruptedException {
    // ch.qos.logback.classic.Logger root = logger.getClass().get(ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    ((ch.qos.logback.classic.Logger) logger).setLevel(ch.qos.logback.classic.Level.DEBUG);
    exportTags = writeTags;
    doBlackening = doBlackeningSensibleData;
    tagnames = cache.getOnlySelectedTagnames(ExportUtils.getOnlyWantedTagnames(CustomTagFactory.getRegisteredTagNames()));
    markUnclearWords = markUnclear;
    expandAbbrevs = expandAbbreviations;
    preserveLineBreaks = keepLineBreaks;
    substituteAbbrevs = replaceAbbrevs;
    showSuppliedWithBrackets = showSuppliedInBrackets;
    ignoreSupplied = ignoreSuppliedTags;
    /*
		 * get all names of tags
		 */
    // tagnames = CustomTagFactory.getRegisteredTagNames();
    // main document part
    wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    org.docx4j.wml.ObjectFactory factory = Context.getWmlObjectFactory();
    List<TrpPage> pages = doc.getPages();
    int totalPages = pageIndices == null ? pages.size() : pageIndices.size();
    if (monitor != null) {
        monitor.beginTask("Exporting to docx", totalPages);
    }
    int c = 0;
    boolean atLeastOnePageWritten = false;
    // can be used as page break every time we need one
    Br objBr = new Br();
    objBr.setType(STBrType.PAGE);
    P pageBreakP = factory.createP();
    pageBreakP.getContent().add(objBr);
    for (int i = 0; i < pages.size(); ++i) {
        if (pageIndices != null && !pageIndices.contains(i))
            continue;
        if (!atLeastOnePageWritten && createTitle) {
            addTitlePage(doc, mdp);
            // add page break
            mdp.addObject(pageBreakP);
        }
        if (monitor != null) {
            if (monitor.isCanceled()) {
                throw new InterruptedException("Export canceled by the user");
            // logger.debug("docx 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();
        JAXBPageTranscript tr = null;
        if (cache != null) {
            tr = cache.getPageTranscriptAtIndex(i);
        }
        if (tr == null) {
            TrpPage page = pages.get(i);
            TrpTranscriptMetadata md = page.getCurrentTranscript();
            // md.getStatus().equals("Done");
            tr = new JAXBPageTranscript(md);
            tr.build();
        }
        TrpPageType trpPage = tr.getPage();
        logger.debug("writing docx for the page " + (i + 1) + "/" + doc.getNPages());
        writeDocxForTranscriptWithTables(mdp, trpPage, wordBased, preserveLineBreaks);
        atLeastOnePageWritten = true;
        ++c;
        if (monitor != null) {
            monitor.worked(c);
        }
    }
    P p = factory.createP();
    mdp.getContent().add(p);
    addComplexField(p, " INDEX \\e \"", "\" \\c \"1\" \\z \"1031\"");
    FieldUpdater updater = new FieldUpdater(wordMLPackage);
    updater.update(true);
    // write tags at end of last page
    if (false) {
        // RtfText headline = RtfText.text("Person names in this document (amount of found persons: " + persons.size() + ")", "\n");
        logger.debug("export tags ");
        boolean firstExport = true;
        // 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);
            // one paragraph for each tagname
            org.docx4j.wml.P p4Tag = factory.createP();
            if (allTagsOfThisTagname.size() > 0 && !currTagname.equals("textStyle") && !currTagname.equals("gap") && !currTagname.equals("comment")) {
                // new page if tag export starts
                if (firstExport) {
                    // Br objBr = new Br();
                    // objBr.setType(STBrType.PAGE);
                    p4Tag.getContent().add(objBr);
                    firstExport = false;
                }
                // logger.debug("allTagsOfThisTagname " + allTagsOfThisTagname.size());
                // one run for headline and thanfor each entry
                org.docx4j.wml.Text t = factory.createText();
                t.setValue(currTagname + " tags in this document: " + allTagsOfThisTagname.size());
                t.setSpace("preserve");
                org.docx4j.wml.R run = factory.createR();
                run.getContent().add(t);
                org.docx4j.wml.RPr rpr = factory.createRPr();
                org.docx4j.wml.BooleanDefaultTrue b = new org.docx4j.wml.BooleanDefaultTrue();
                b.setVal(true);
                U u = factory.createU();
                u.setVal(UnderlineEnumeration.SINGLE);
                rpr.setB(b);
                rpr.setU(u);
                run.setRPr(rpr);
                // this Br element is used break the current and go for next line
                Br br = factory.createBr();
                run.getContent().add(br);
                p4Tag.getContent().add(run);
                // ArrayList<RtfText> tagTexts = new ArrayList<RtfText>();
                Collection<String> valueSet = allTagsOfThisTagname.values();
                int l = 0;
                for (String currEntry : valueSet) {
                    org.docx4j.wml.R currRun = factory.createR();
                    org.docx4j.wml.Text currText = factory.createText();
                    currText.setValue(currEntry);
                    currText.setSpace("preserve");
                    currRun.getContent().add(currText);
                    // reuse linebreak
                    currRun.getContent().add(br);
                    p4Tag.getContent().add(currRun);
                }
            }
            mdp.getContent().add(p4Tag);
        }
    }
    // finally save the file
    wordMLPackage.save(file);
    logger.info("Saved " + file.getAbsolutePath());
}
Also used : JAXBPageTranscript(eu.transkribus.core.model.beans.JAXBPageTranscript) TrpTranscriptMetadata(eu.transkribus.core.model.beans.TrpTranscriptMetadata) CustomTag(eu.transkribus.core.model.beans.customtags.CustomTag) Logger(org.slf4j.Logger) RPr(org.docx4j.wml.RPr) P(org.docx4j.wml.P) U(org.docx4j.wml.U) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text) TrpPageType(eu.transkribus.core.model.beans.pagecontent_trp.TrpPageType) P(org.docx4j.wml.P) FieldUpdater(org.docx4j.model.fields.FieldUpdater) TrpPage(eu.transkribus.core.model.beans.TrpPage) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Br(org.docx4j.wml.Br)

Example 9 with U

use of org.docx4j.wml.U in project Java-Tutorial by gpcodervn.

the class Docx4jUtils method addUnderlineStyle.

private void addUnderlineStyle(RPr runProperties) {
    U val = new U();
    val.setVal(UnderlineEnumeration.SINGLE);
    runProperties.setU(val);
}
Also used : U(org.docx4j.wml.U)

Example 10 with U

use of org.docx4j.wml.U in project docx4j-template by vindell.

the class Docx4J_简单例子 method getRPr.

/**
 * 创建字体
 *
 * @param isBlod
 *            粗体
 * @param isUnderLine
 *            下划线
 * @param isItalic
 *            斜体
 * @param isStrike
 *            删除线
 */
public RPr getRPr(ObjectFactory factory, String fontFamily, String colorVal, String fontSize, STHint sTHint, boolean isBlod, boolean isUnderLine, boolean isItalic, boolean isStrike) {
    RPr rPr = factory.createRPr();
    RFonts rf = new RFonts();
    rf.setHint(sTHint);
    rf.setAscii(fontFamily);
    rf.setHAnsi(fontFamily);
    rPr.setRFonts(rf);
    BooleanDefaultTrue bdt = factory.createBooleanDefaultTrue();
    rPr.setBCs(bdt);
    if (isBlod) {
        rPr.setB(bdt);
    }
    if (isItalic) {
        rPr.setI(bdt);
    }
    if (isStrike) {
        rPr.setStrike(bdt);
    }
    if (isUnderLine) {
        U underline = new U();
        underline.setVal(UnderlineEnumeration.SINGLE);
        rPr.setU(underline);
    }
    Color color = new Color();
    color.setVal(colorVal);
    rPr.setColor(color);
    HpsMeasure sz = new HpsMeasure();
    sz.setVal(new BigInteger(fontSize));
    rPr.setSz(sz);
    rPr.setSzCs(sz);
    return rPr;
}
Also used : RPr(org.docx4j.wml.RPr) U(org.docx4j.wml.U) HpsMeasure(org.docx4j.wml.HpsMeasure) Color(org.docx4j.wml.Color) RFonts(org.docx4j.wml.RFonts) BigInteger(java.math.BigInteger) BooleanDefaultTrue(org.docx4j.wml.BooleanDefaultTrue)

Aggregations

U (org.docx4j.wml.U)11 RPr (org.docx4j.wml.RPr)7 BigInteger (java.math.BigInteger)4 BooleanDefaultTrue (org.docx4j.wml.BooleanDefaultTrue)4 Color (org.docx4j.wml.Color)4 HpsMeasure (org.docx4j.wml.HpsMeasure)4 RFonts (org.docx4j.wml.RFonts)4 R (org.docx4j.wml.R)3 Text (org.docx4j.wml.Text)3 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)2 Jc (org.docx4j.wml.Jc)2 P (org.docx4j.wml.P)2 PPr (org.docx4j.wml.PPr)2 ParaRPr (org.docx4j.wml.ParaRPr)2 JAXBPageTranscript (eu.transkribus.core.model.beans.JAXBPageTranscript)1 TrpPage (eu.transkribus.core.model.beans.TrpPage)1 TrpTranscriptMetadata (eu.transkribus.core.model.beans.TrpTranscriptMetadata)1 AbbrevTag (eu.transkribus.core.model.beans.customtags.AbbrevTag)1 CommentTag (eu.transkribus.core.model.beans.customtags.CommentTag)1 CustomTagList (eu.transkribus.core.model.beans.customtags.CustomTagList)1