Java Code Examples for org.apache.poi.xwpf.usermodel.XWPFRun#setFontSize()
The following examples show how to use
org.apache.poi.xwpf.usermodel.XWPFRun#setFontSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleUtils.java From poi-tl with Apache License 2.0 | 6 votes |
/** * 重复样式 * * @param destRun * 新建的run * @param srcRun * 原始run */ public static void styleRun(XWPFRun destRun, XWPFRun srcRun) { if (null == destRun || null == srcRun) return; CTR ctr = srcRun.getCTR(); if (ctr.isSetRPr() && ctr.getRPr().isSetRStyle()) { String val = ctr.getRPr().getRStyle().getVal(); if (StringUtils.isNotBlank(val)) { CTRPr pr = destRun.getCTR().isSetRPr() ? destRun.getCTR().getRPr() : destRun.getCTR().addNewRPr(); CTString rStyle = pr.isSetRStyle() ? pr.getRStyle() : pr.addNewRStyle(); rStyle.setVal(val); } } if (Boolean.TRUE.equals(srcRun.isBold())) destRun.setBold(srcRun.isBold()); destRun.setColor(srcRun.getColor()); // destRun.setCharacterSpacing(srcRun.getCharacterSpacing()); if (StringUtils.isNotBlank(srcRun.getFontFamily())) destRun.setFontFamily(srcRun.getFontFamily()); int fontSize = srcRun.getFontSize(); if (-1 != fontSize) destRun.setFontSize(fontSize); if (Boolean.TRUE.equals(srcRun.isItalic())) destRun.setItalic(srcRun.isItalic()); if (Boolean.TRUE.equals(srcRun.isStrikeThrough())) destRun.setStrikeThrough(srcRun.isStrikeThrough()); destRun.setUnderline(srcRun.getUnderline()); }
Example 2
Source File: ETLWordDocumentGenerator.java From WhiteRabbit with Apache License 2.0 | 6 votes |
private static void addTableLevelSection(CustomXWPFDocument document, ETL etl) throws InvalidFormatException, FileNotFoundException { XWPFParagraph tmpParagraph = document.createParagraph(); XWPFRun tmpRun = tmpParagraph.createRun(); MappingPanel mappingPanel = new MappingPanel(etl.getTableToTableMapping()); mappingPanel.setShowOnlyConnectedItems(true); int height = mappingPanel.getMinimumSize().height; mappingPanel.setSize(800, height); tmpRun.setText(mappingPanel.getSourceDbName() + " Data Mapping Approach to " + mappingPanel.getTargetDbName()); tmpRun.setFontSize(18); BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB); im.getGraphics().setColor(Color.WHITE); im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight()); mappingPanel.paint(im.getGraphics()); document.addPicture(im, 600, height * 6 / 8); }
Example 3
Source File: TemplateValidationGenerator.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Inserts the given {@link TemplateValidationMessage} in a run next to the one of the given construct subject to the message. * * @param message * the {@link TemplateValidationMessage} to insert * the error message to insert in a run * @param offset * the offset in number of {@link XWPFRun} to insert after {@link TemplateValidationMessage#getLocation() message location} * @return the number of inserted {@link XWPFRun} */ private int addRunError(TemplateValidationMessage message, int offset) { int res = 0; if (message.getLocation().getParent() instanceof XWPFParagraph) { XWPFParagraph paragraph = (XWPFParagraph) message.getLocation().getParent(); final int basePosition = paragraph.getRuns().indexOf(message.getLocation()) + offset; // separation run. res++; final String color = M2DocUtils.getColor(message.getLevel()); XWPFRun newBlankRun = paragraph.insertNewRun(basePosition + res); newBlankRun.setText(BLANK_SEPARATOR); res++; final XWPFRun separationRun = paragraph.insertNewRun(basePosition + res); separationRun.setText(LOCATION_SEPARATOR); separationRun.setColor(color); separationRun.setFontSize(ERROR_MESSAGE_FONT_SIZE); final CTHighlight separationHighlight = separationRun.getCTR().getRPr().addNewHighlight(); separationHighlight.setVal(STHighlightColor.LIGHT_GRAY); res++; final XWPFRun messageRun = paragraph.insertNewRun(basePosition + res); messageRun.setText(message.getMessage()); messageRun.setColor(color); messageRun.setFontSize(ERROR_MESSAGE_FONT_SIZE); final CTHighlight messageHighlight = messageRun.getCTR().getRPr().addNewHighlight(); messageHighlight.setVal(STHighlightColor.LIGHT_GRAY); } return res; }
Example 4
Source File: M2DocEvaluator.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Apply the given style to the given run. Background color is not taken into account here since it does not apply to runs. * * @param run * The run to style * @param style * The style to apply, can be <code>null</code> */ private void applyMStyle(XWPFRun run, MStyle style) { if (style.getFontSize() != -1) { run.setFontSize(style.getFontSize()); } if (style.getFontName() != null) { run.setFontFamily(style.getFontName()); } if (style.getFontModifiers() != -1) { run.setBold((style.getFontModifiers() & MStyle.FONT_BOLD) != 0); run.setItalic((style.getFontModifiers() & MStyle.FONT_ITALIC) != 0); if ((style.getFontModifiers() & MStyle.FONT_UNDERLINE) != 0) { run.setUnderline(UnderlinePatterns.SINGLE); } run.setStrikeThrough((style.getFontModifiers() & MStyle.FONT_STRIKE_THROUGH) != 0); } if (style.getForegroundColor() != null) { run.setColor(hexColor(style.getForegroundColor())); } if (style.getBackgroundColor() != null) { final CTRPr ctrpr; if (run.getCTR().getRPr() != null) { ctrpr = run.getCTR().getRPr(); } else { ctrpr = run.getCTR().addNewRPr(); } final CTShd ctshd; if (ctrpr.getShd() != null) { ctshd = ctrpr.getShd(); } else { ctshd = ctrpr.addNewShd(); } ctshd.setVal(STShd.CLEAR); ctshd.setColor("auto"); ctshd.setFill(hexColor(style.getBackgroundColor())); } }
Example 5
Source File: ETLWordDocumentGenerator.java From WhiteRabbit with Apache License 2.0 | 5 votes |
private static void addSourceTablesAppendix(CustomXWPFDocument document, ETL etl) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.PAGE); run.setText("Appendix: source tables"); run.setFontSize(18); for (Table sourceTable : etl.getSourceDatabase().getTables()) { paragraph = document.createParagraph(); run = paragraph.createRun(); run.setText("Table: " + sourceTable.getName()); run.setFontSize(14); createDocumentParagraph(document, sourceTable.getComment()); XWPFTable table = document.createTable(sourceTable.getFields().size() + 1, 4); // table.setWidth(2000); XWPFTableRow header = table.getRow(0); setTextAndHeaderShading(header.getCell(0), "Field"); setTextAndHeaderShading(header.getCell(1), "Type"); setTextAndHeaderShading(header.getCell(2), "Most freq. value"); setTextAndHeaderShading(header.getCell(3), "Comment"); int rowNr = 1; for (Field sourceField : sourceTable.getFields()) { XWPFTableRow row = table.getRow(rowNr++); row.getCell(0).setText(sourceField.getName()); row.getCell(1).setText(sourceField.getType()); row.getCell(2).setText(sourceField.getValueCounts().getMostFrequentValue()); createCellParagraph(row.getCell(3), sourceField.getComment().trim()); } } run.setFontSize(18); }
Example 6
Source File: StyleUtils.java From poi-tl with Apache License 2.0 | 4 votes |
/** * 设置run的样式 * * @param run * @param style */ public static void styleRun(XWPFRun run, Style style) { if (null == run || null == style) return; String color = style.getColor(); String fontFamily = style.getFontFamily(); int fontSize = style.getFontSize(); Boolean bold = style.isBold(); Boolean italic = style.isItalic(); Boolean strike = style.isStrike(); Boolean underLine = style.isUnderLine(); Enum highlightColor = style.getHighlightColor(); int twips = style.getCharacterSpacing(); String vertAlign = style.getVertAlign(); CTRPr pr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr(); if (StringUtils.isNotBlank(color)) { // run.setColor(color); // issue 326 CTColor ctColor = pr.isSetColor() ? pr.getColor() : pr.addNewColor(); ctColor.setVal(color); if (ctColor.isSetThemeColor()) ctColor.unsetThemeColor(); } if (0 != fontSize) run.setFontSize(fontSize); if (StringUtils.isNotBlank(fontFamily)) { run.setFontFamily(fontFamily); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); fonts.setAscii(fontFamily); fonts.setHAnsi(fontFamily); fonts.setCs(fontFamily); fonts.setEastAsia(fontFamily); } if (null != highlightColor) { CTHighlight highlight = pr.isSetHighlight() ? pr.getHighlight() : pr.addNewHighlight(); STHighlightColor hColor = highlight.xgetVal(); if (hColor == null) { hColor = STHighlightColor.Factory.newInstance(); } STHighlightColor.Enum val = STHighlightColor.Enum.forString(highlightColor.toString()); if (val != null) { hColor.setStringValue(val.toString()); highlight.xsetVal(hColor); } } if (null != bold) run.setBold(bold); if (null != italic) run.setItalic(italic); if (null != strike) run.setStrikeThrough(strike); if (Boolean.TRUE.equals(underLine)) { run.setUnderline(UnderlinePatterns.SINGLE); } // in twentieths of a point if (0 != twips) run.setCharacterSpacing(20*twips); if (StringUtils.isNotBlank(vertAlign)) { run.setVerticalAlignment(vertAlign); } }
Example 7
Source File: ETLWordDocumentGenerator.java From WhiteRabbit with Apache License 2.0 | 4 votes |
private static void addTargetTableSection(CustomXWPFDocument document, ETL etl, Table targetTable) throws InvalidFormatException, FileNotFoundException { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.addBreak(BreakType.PAGE); run.setText("Table name: " + targetTable.getName()); run.setFontSize(18); createDocumentParagraph(document, targetTable.getComment()); for (ItemToItemMap tableToTableMap : etl.getTableToTableMapping().getSourceToTargetMaps()) if (tableToTableMap.getTargetItem() == targetTable) { Table sourceTable = (Table) tableToTableMap.getSourceItem(); Mapping<Field> fieldtoFieldMapping = etl.getFieldToFieldMapping(sourceTable, targetTable); paragraph = document.createParagraph(); run = paragraph.createRun(); run.setText("Reading from " + tableToTableMap.getSourceItem()); run.setFontSize(14); createDocumentParagraph(document, tableToTableMap.getLogic()); createDocumentParagraph(document, tableToTableMap.getComment()); // Add picture of field to field mapping MappingPanel mappingPanel = new MappingPanel(fieldtoFieldMapping); mappingPanel.setShowOnlyConnectedItems(true); int height = mappingPanel.getMinimumSize().height; mappingPanel.setSize(800, height); BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB); im.getGraphics().setColor(Color.WHITE); im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight()); mappingPanel.paint(im.getGraphics()); document.addPicture(im, 600, height * 6 / 8); // Add table of field to field mapping XWPFTable table = document.createTable(fieldtoFieldMapping.getTargetItems().size() + 1, 4); // table.setWidth(2000); XWPFTableRow header = table.getRow(0); setTextAndHeaderShading(header.getCell(0), "Destination Field"); setTextAndHeaderShading(header.getCell(1), "Source Field"); setTextAndHeaderShading(header.getCell(2), "Logic"); setTextAndHeaderShading(header.getCell(3), "Comment"); int rowNr = 1; for (MappableItem targetField : fieldtoFieldMapping.getTargetItems()) { XWPFTableRow row = table.getRow(rowNr++); row.getCell(0).setText(targetField.getName()); StringBuilder source = new StringBuilder(); StringBuilder logic = new StringBuilder(); StringBuilder comment = new StringBuilder(); for (ItemToItemMap fieldToFieldMap : fieldtoFieldMapping.getSourceToTargetMaps()) { if (fieldToFieldMap.getTargetItem() == targetField) { if (source.length() != 0) source.append("\n"); source.append(fieldToFieldMap.getSourceItem().getName().trim()); if (logic.length() != 0) logic.append("\n"); logic.append(fieldToFieldMap.getLogic().trim()); if (comment.length() != 0) comment.append("\n"); comment.append(fieldToFieldMap.getComment().trim()); } } for (Field field : targetTable.getFields()) { if (field.getName().equals(targetField.getName())) { if (comment.length() != 0) comment.append("\n"); comment.append(field.getComment().trim()); } } createCellParagraph(row.getCell(1), source.toString()); createCellParagraph(row.getCell(2), logic.toString()); createCellParagraph(row.getCell(3), comment.toString()); } } }