/** * */ public JRStyle getBaseStyle(JRParagraph paragraph) { if (paragraph != null) { JRParagraphContainer paragraphContainer = paragraph.getParagraphContainer(); if (paragraphContainer instanceof JRStyle) { return getBaseStyle((JRStyle)paragraphContainer); } return getBaseStyle(paragraphContainer); } return null; }
/** * */ public Float getLineSpacingSize(JRParagraph paragraph) { Float ownLineSpacingSize = paragraph.getOwnLineSpacingSize(); if (ownLineSpacingSize != null) { return ownLineSpacingSize; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Float lineSpacingSize = style.getParagraph().getLineSpacingSize(); if (lineSpacingSize != null) { return lineSpacingSize; } } return propertiesUtil.getFloatProperty(JRParagraph.DEFAULT_LINE_SPACING_SIZE); }
/** * */ public Integer getFirstLineIndent(JRParagraph paragraph) { Integer ownFirstLineIndent = paragraph.getOwnFirstLineIndent(); if (ownFirstLineIndent != null) { return ownFirstLineIndent; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer firstLineIndent = style.getParagraph().getFirstLineIndent(); if (firstLineIndent != null) { return firstLineIndent; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_FIRST_LINE_INDENT); }
/** * */ public Integer getLeftIndent(JRParagraph paragraph) { Integer ownLeftIndent = paragraph.getOwnLeftIndent(); if (ownLeftIndent != null) { return ownLeftIndent; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer leftIndent = style.getParagraph().getLeftIndent(); if (leftIndent != null) { return leftIndent; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_LEFT_INDENT); }
/** * */ public Integer getRightIndent(JRParagraph paragraph) { Integer ownRightIndent = paragraph.getOwnRightIndent(); if (ownRightIndent != null) { return ownRightIndent; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer rightIndent = style.getParagraph().getRightIndent(); if (rightIndent != null) { return rightIndent; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_RIGHT_INDENT); }
/** * */ public Integer getSpacingBefore(JRParagraph paragraph) { Integer ownSpacingBefore = paragraph.getOwnSpacingBefore(); if (ownSpacingBefore != null) { return ownSpacingBefore; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer spacingBefore = style.getParagraph().getSpacingBefore(); if (spacingBefore != null) { return spacingBefore; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_SPACING_BEFORE); }
/** * */ public Integer getSpacingAfter(JRParagraph paragraph) { Integer ownSpacingAfter = paragraph.getOwnSpacingAfter(); if (ownSpacingAfter != null) { return ownSpacingAfter; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer spacingAfter = style.getParagraph().getSpacingAfter(); if (spacingAfter != null) { return spacingAfter; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_SPACING_AFTER); }
/** * */ public Integer getTabStopWidth(JRParagraph paragraph) { Integer ownTabStopWidth = paragraph.getOwnTabStopWidth(); if (ownTabStopWidth != null) { return ownTabStopWidth; } JRStyle style = getBaseStyle(paragraph); if (style != null) { Integer tabStopWidth = style.getParagraph().getTabStopWidth(); if (tabStopWidth != null) { return tabStopWidth; } } return propertiesUtil.getIntegerProperty(JRParagraph.DEFAULT_TAB_STOP_WIDTH); }
/** * */ public TabStop[] getTabStops(JRParagraph paragraph) { TabStop[] ownTabStops = paragraph.getOwnTabStops(); if (ownTabStops != null) { return ownTabStops; } JRStyle style = getBaseStyle(paragraph); if (style != null) { TabStop[] tabStops = style.getParagraph().getTabStops(); if (tabStops != null) { return tabStops; } } return null; }
/** * */ public LineSpacingEnum getLineSpacing(JRParagraph paragraph) { LineSpacingEnum ownLineSpacing = paragraph.getOwnLineSpacing(); if (ownLineSpacing != null) { return ownLineSpacing; } JRStyle baseStyle = getBaseStyle(paragraph); if (baseStyle != null) { LineSpacingEnum lineSpacing = baseStyle.getParagraph().getLineSpacing(); if (lineSpacing != null) { return lineSpacing; } } return LineSpacingEnum.SINGLE;//FIXMENOW could we make all enums in default props? }
@Override public Object createObject(Attributes atts) { JRParagraphContainer paragraphContainer = (JRParagraphContainer) digester.peek(); JRParagraph paragraph = paragraphContainer.getParagraph(); setParagraphAttributes(atts, paragraph); return paragraph; }
/** * */ public void writeParagraph(JRParagraph paragraph, XmlNamespace namespace) throws IOException { if (paragraph != null && isNewerVersionOrEqual(JRConstants.VERSION_4_0_2)) { writer.startElement(JRXmlConstants.ELEMENT_paragraph, namespace); writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacing, paragraph.getOwnLineSpacing()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacingSize, paragraph.getOwnLineSpacingSize()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_firstLineIndent, paragraph.getOwnFirstLineIndent()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_leftIndent, paragraph.getOwnLeftIndent()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_rightIndent, paragraph.getOwnRightIndent()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_spacingBefore, paragraph.getOwnSpacingBefore()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_spacingAfter, paragraph.getOwnSpacingAfter()); writer.addAttribute(JRXmlConstants.ATTRIBUTE_tabStopWidth, paragraph.getOwnTabStopWidth()); /* */ TabStop[] tabStops = paragraph.getTabStops(); if (tabStops != null && tabStops.length > 0) { for(int i = 0; i < tabStops.length; i++) { writeTabStop(tabStops[i]); } } writer.closeElement(true); } }
/** * Merges two paragraphs, by appending the properties of the source paragraph to the ones of the destination paragraph. */ public static void appendParagraph(JRParagraph destParagraph, JRParagraph srcParagraph) { if (srcParagraph.getOwnLineSpacing() != null) { destParagraph.setLineSpacing(srcParagraph.getOwnLineSpacing()); } if (srcParagraph.getOwnLeftIndent() != null) { destParagraph.setLeftIndent(srcParagraph.getOwnLeftIndent()); } if (srcParagraph.getOwnRightIndent() != null) { destParagraph.setRightIndent(srcParagraph.getOwnRightIndent()); } if (srcParagraph.getOwnSpacingBefore() != null) { destParagraph.setSpacingBefore(srcParagraph.getOwnSpacingBefore()); } if (srcParagraph.getOwnSpacingAfter() != null) { destParagraph.setSpacingAfter(srcParagraph.getOwnSpacingAfter()); } if (srcParagraph.getOwnTabStopWidth() != null) { destParagraph.setTabStopWidth(srcParagraph.getOwnTabStopWidth()); } }
/** * */ protected void writeParagraph(JRParagraph paragraph, String paragraphHolder) { if (paragraph != null) { String paragraphName = paragraphHolder + "Paragraph"; write( "JRParagraph " + paragraphName + " = " + paragraphHolder + ".getParagraph();\n"); write( paragraphName + ".setLineSpacing({0});\n", paragraph.getOwnLineSpacing()); write( paragraphName + ".setLineSpacingSize({0});\n", paragraph.getOwnLineSpacingSize()); write( paragraphName + ".setFirstLineIndent({0});\n", paragraph.getOwnFirstLineIndent()); write( paragraphName + ".setLeftIndent({0});\n", paragraph.getOwnLeftIndent()); write( paragraphName + ".setRightIndent({0});\n", paragraph.getOwnRightIndent()); write( paragraphName + ".setSpacingBefore({0});\n", paragraph.getOwnSpacingBefore()); write( paragraphName + ".setSpacingAfter({0});\n", paragraph.getOwnSpacingAfter()); write( paragraphName + ".setTabStopWidth(Integer.valueOf({0, number, #}));\n", paragraph.getOwnTabStopWidth());//FIXMENOW is this pattern needed? TabStop[] tabStops = paragraph.getTabStops(); if (tabStops != null && tabStops.length > 0) { for(int i = 0; i < tabStops.length; i++) { writeTabStop( tabStops[i], paragraphName + "TabStop" + i); write( paragraphName +".addTabStop(" + paragraphName + "TabStop" + i + ");\n"); } } flush(); } }
/** * */ private void exportPropsHeader(String styleNameReference, JRParagraph paragraph) { write(" <w:pPr>\n"); if (styleNameReference != null) { write(" <w:pStyle w:val=\"" + styleNameReference + "\"/>\n"); } if(paragraph != null) { write(" <w:ind"); if (paragraph.getOwnFirstLineIndent() != null) { write(" w:firstLine=\"" + LengthUtil.twip(paragraph.getOwnFirstLineIndent().intValue()) + "\""); } if (paragraph.getOwnLeftIndent() != null) { write(" w:left=\"" + LengthUtil.twip(paragraph.getOwnLeftIndent().intValue()) + "\""); } if (paragraph.getOwnRightIndent() != null) { write(" w:right=\"" + LengthUtil.twip(paragraph.getOwnRightIndent().intValue()) + "\""); } write("/>\n"); } if (pageBreak) { write(" <w:pageBreakBefore/>\n"); pageBreak = false; } }
/** * */ private void exportTabStops(JRParagraph paragraph) { TabStop[] tabStops = paragraph.getTabStops(); if (tabStops != null && tabStops.length > 0) { write(" <w:tabs>\n"); for (int i = 0; i < tabStops.length; i++) { TabStop tabStop = tabStops[i]; write(" <w:tab w:pos=\"" + LengthUtil.twip(tabStop.getPosition()) + "\" w:val=\"" + getTabStopAlignment(tabStop.getAlignment()) + "\"/>\n"); } write(" </w:tabs>\n"); } }
/** * @throws IOException * */ private void exportParagraph(JRParagraph paragraph) throws IOException { if (paragraph != null) { xmlWriter.startElement(JRXmlConstants.ELEMENT_paragraph); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacing, paragraph.getOwnLineSpacing()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacingSize, paragraph.getOwnLineSpacingSize()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_firstLineIndent, paragraph.getOwnFirstLineIndent()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_leftIndent, paragraph.getOwnLeftIndent()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_rightIndent, paragraph.getOwnRightIndent()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_spacingBefore, paragraph.getOwnSpacingBefore()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_spacingAfter, paragraph.getOwnSpacingAfter()); xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_tabStopWidth, paragraph.getOwnTabStopWidth()); /* */ TabStop[] tabStops = paragraph.getTabStops(); if (tabStops != null && tabStops.length > 0) { for(int i = 0; i < tabStops.length; i++) { exportTabStop(tabStops[i]); } } xmlWriter.closeElement(true); } }
@Override public JRParagraph getParagraph() { return paragraph == null ? (fillStyleObjects == null ? initParagraph : fillStyleObjects.paragraph) : paragraph; }
public CachingParagraph(JRParagraph base) { this.base = base; this.lineSpacing = base.getLineSpacing(); this.lineSpacingSize = base.getLineSpacingSize(); this.firstLineIndent = base.getFirstLineIndent(); this.leftIndent = base.getLeftIndent(); this.rightIndent = base.getRightIndent(); this.spacingBefore = base.getSpacingBefore(); this.spacingAfter = base.getSpacingAfter(); }
private void cloneParagraph(JRParagraph fieldBox, JRParagraph staticBox){ if (fieldBox == null || staticBox == null) return; fieldBox.setFirstLineIndent(staticBox.getFirstLineIndent()); fieldBox.setLeftIndent(staticBox.getLeftIndent()); fieldBox.setLineSpacing(staticBox.getLineSpacing()); fieldBox.setLineSpacingSize(staticBox.getLineSpacingSize()); fieldBox.setRightIndent(staticBox.getRightIndent()); fieldBox.setSpacingAfter(staticBox.getSpacingAfter()); fieldBox.setSpacingBefore(staticBox.getSpacingBefore()); fieldBox.setTabStopWidth(staticBox.getTabStopWidth()); }
@Override public JRParagraph getParagraph() { return paragraph; }
/** * */ public void copyParagraph(JRParagraph paragraph) { this.paragraph = paragraph.clone(this); }
public static void setParagraphAttributes(Attributes atts, JRParagraph paragraph) { LineSpacingEnum lineSpacing = LineSpacingEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing)); if (lineSpacing != null) { paragraph.setLineSpacing(lineSpacing); } String lineSpacingSize = atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacingSize); if (lineSpacingSize != null && lineSpacingSize.length() > 0) { paragraph.setLineSpacingSize(Float.parseFloat(lineSpacingSize)); } String firstLineIndent = atts.getValue(JRXmlConstants.ATTRIBUTE_firstLineIndent); if (firstLineIndent != null && firstLineIndent.length() > 0) { paragraph.setFirstLineIndent(Integer.parseInt(firstLineIndent)); } String leftIndent = atts.getValue(JRXmlConstants.ATTRIBUTE_leftIndent); if (leftIndent != null && leftIndent.length() > 0) { paragraph.setLeftIndent(Integer.parseInt(leftIndent)); } String rightIndent = atts.getValue(JRXmlConstants.ATTRIBUTE_rightIndent); if (rightIndent != null && rightIndent.length() > 0) { paragraph.setRightIndent(Integer.parseInt(rightIndent)); } String spacingBefore = atts.getValue(JRXmlConstants.ATTRIBUTE_spacingBefore); if (spacingBefore != null && spacingBefore.length() > 0) { paragraph.setSpacingBefore(Integer.parseInt(spacingBefore)); } String spacingAfter = atts.getValue(JRXmlConstants.ATTRIBUTE_spacingAfter); if (spacingAfter != null && spacingAfter.length() > 0) { paragraph.setSpacingAfter(Integer.parseInt(spacingAfter)); } String tabStopWidth = atts.getValue(JRXmlConstants.ATTRIBUTE_tabStopWidth); if (tabStopWidth != null && tabStopWidth.length() > 0) { paragraph.setTabStopWidth(Integer.parseInt(tabStopWidth)); } }
public void writeParagraph(JRParagraph paragraph) throws IOException { writeParagraph(paragraph, null); }
/** * */ public static Float getLineSpacingSize(JRParagraph paragraph) { return styleResolver.getLineSpacingSize(paragraph); }
/** * */ public static Integer getFirstLineIndent(JRParagraph paragraph) { return styleResolver.getFirstLineIndent(paragraph); }
/** * */ public static Integer getLeftIndent(JRParagraph paragraph) { return styleResolver.getLeftIndent(paragraph); }
/** * */ public static Integer getRightIndent(JRParagraph paragraph) { return styleResolver.getRightIndent(paragraph); }
/** * */ public static Integer getSpacingBefore(JRParagraph paragraph) { return styleResolver.getSpacingBefore(paragraph); }
/** * */ public static Integer getSpacingAfter(JRParagraph paragraph) { return styleResolver.getSpacingAfter(paragraph); }
/** * */ public static Integer getTabStopWidth(JRParagraph paragraph) { return styleResolver.getTabStopWidth(paragraph); }
/** * */ public static TabStop[] getTabStops(JRParagraph paragraph) { return styleResolver.getTabStops(paragraph); }
/** * */ public static LineSpacingEnum getLineSpacing(JRParagraph paragraph) { return styleResolver.getLineSpacing(paragraph); }
/** * @deprecated Replaced by {@link StyleUtil#appendParagraph(JRParagraph, JRParagraph)}. */ public static void appendParagraph(JRParagraph destParagraph, JRParagraph srcParagraph) { StyleUtil.appendParagraph(destParagraph, srcParagraph); }
/** * */ public static float getLineHeight(boolean isFirstLine, JRParagraph paragraph, float maxLeading, float maxAscent) { float lineHeight = 0; switch(paragraph.getLineSpacing()) { case SINGLE: default : { lineHeight = maxLeading + 1f * maxAscent; break; } case ONE_AND_HALF: { if (isFirstLine) { lineHeight = maxLeading + 1f * maxAscent; } else { lineHeight = maxLeading + 1.5f * maxAscent; } break; } case DOUBLE: { if (isFirstLine) { lineHeight = maxLeading + 1f * maxAscent; } else { lineHeight = maxLeading + 2f * maxAscent; } break; } case PROPORTIONAL: { if (isFirstLine) { lineHeight = maxLeading + 1f * maxAscent; } else { lineHeight = maxLeading + paragraph.getLineSpacingSize().floatValue() * maxAscent; } break; } case AT_LEAST: { if (isFirstLine) { lineHeight = maxLeading + 1f * maxAscent; } else { lineHeight = Math.max(maxLeading + 1f * maxAscent, paragraph.getLineSpacingSize().floatValue()); } break; } case FIXED: { if (isFirstLine) { lineHeight = maxLeading + 1f * maxAscent; } else { lineHeight = paragraph.getLineSpacingSize().floatValue(); } break; } } return lineHeight; }
/** * */ private void exportLineSpacing(JRParagraph paragraph) { if ( paragraph.getOwnLineSpacing() != null || paragraph.getOwnLineSpacingSize() != null || paragraph.getOwnSpacingBefore() != null || paragraph.getOwnSpacingAfter() != null ) { String lineRule; String lineSpacing; switch (paragraph.getLineSpacing()) { case AT_LEAST : { lineRule = "atLeast"; lineSpacing = String.valueOf(LengthUtil.twip(paragraph.getLineSpacingSize().floatValue())); break; } case FIXED : { lineRule = "exact"; lineSpacing = String.valueOf(LengthUtil.twip(paragraph.getLineSpacingSize().floatValue())); break; } case PROPORTIONAL : { lineRule = "auto"; lineSpacing = String.valueOf((int)(paragraph.getLineSpacingSize().floatValue() * LINE_SPACING_FACTOR)); break; } case DOUBLE : { lineRule = "auto"; lineSpacing = String.valueOf((int)(2f * LINE_SPACING_FACTOR)); break; } case ONE_AND_HALF : { lineRule = "auto"; lineSpacing = String.valueOf((int)(1.5f * LINE_SPACING_FACTOR)); break; } case SINGLE : default : { lineRule = "auto"; lineSpacing = String.valueOf((int)(1f * LINE_SPACING_FACTOR)); } } write(" <w:spacing w:lineRule=\"" + lineRule + "\" w:line=\"" + lineSpacing + "\""); write(" w:after=\"" + LengthUtil.twip(paragraph.getSpacingAfter().intValue()) + "\""); write(" w:before=\"" + LengthUtil.twip(paragraph.getSpacingBefore().intValue()) + "\"/>\n"); } }