/** * Initializes properties that are specific to text elements. Common properties are initialized by its * parent constructor. * @param textElement an element whose properties are copied to this element. Usually it is a * {@link net.sf.jasperreports.engine.design.JRDesignTextElement} that must be transformed into an * <tt>JRBaseTextElement</tt> at compile time. * @param factory a factory used in the compile process */ protected JRBaseTextElement(JRTextElement textElement, JRBaseObjectFactory factory) { super(textElement, factory); horizontalTextAlign = textElement.getOwnHorizontalTextAlign(); verticalTextAlign = textElement.getOwnVerticalTextAlign(); rotationValue = textElement.getOwnRotationValue(); markup = textElement.getOwnMarkup(); lineBox = textElement.getLineBox().clone(this); paragraph = textElement.getParagraph().clone(this); fontName = textElement.getOwnFontName(); isBold = textElement.isOwnBold(); isItalic = textElement.isOwnItalic(); isUnderline = textElement.isOwnUnderline(); isStrikeThrough = textElement.isOwnStrikeThrough(); fontsize = textElement.getOwnFontsize(); pdfFontName = textElement.getOwnPdfFontName(); pdfEncoding = textElement.getOwnPdfEncoding(); isPdfEmbedded = textElement.isOwnPdfEmbedded(); }
/** * */ protected void copyTextElement(ReportConverter reportConverter, JRTextElement textElement, JRBasePrintText printText) { copyElement(reportConverter, textElement, printText); printText.copyBox(textElement.getLineBox()); printText.copyParagraph(textElement.getParagraph()); printText.setBold(textElement.isOwnBold()); printText.setFontName(textElement.getOwnFontName()); printText.setFontSize(textElement.getOwnFontsize()); printText.setHorizontalTextAlign(textElement.getOwnHorizontalTextAlign()); printText.setItalic(textElement.isOwnItalic()); printText.setPdfEmbedded(textElement.isOwnPdfEmbedded()); printText.setPdfEncoding(textElement.getOwnPdfEncoding()); printText.setPdfFontName(textElement.getOwnPdfFontName()); printText.setRotation(textElement.getOwnRotationValue()); printText.setStrikeThrough(textElement.isOwnStrikeThrough()); printText.setMarkup(textElement.getOwnMarkup()); printText.setUnderline(textElement.isOwnUnderline()); printText.setVerticalTextAlign(textElement.getOwnVerticalTextAlign()); }
/** * */ private void writeTextElement(JRTextElement textElement) throws IOException { writer.startElement(JRXmlConstants.ELEMENT_textElement); writer.addAttribute(JRXmlConstants.ATTRIBUTE_textAlignment, textElement.getOwnHorizontalTextAlign()); VerticalTextAlignEnum vTextAlign = textElement.getOwnVerticalTextAlign(); if (isOlderVersionThan(JRConstants.VERSION_6_2_1)) { vTextAlign = vTextAlign == VerticalTextAlignEnum.JUSTIFIED ? VerticalTextAlignEnum.TOP : vTextAlign; } writer.addAttribute(JRXmlConstants.ATTRIBUTE_verticalAlignment, vTextAlign); writer.addAttribute(JRXmlConstants.ATTRIBUTE_rotation, textElement.getOwnRotationValue()); if (isOlderVersionThan(JRConstants.VERSION_4_0_2)) { writer.addAttribute(JRXmlConstants.ATTRIBUTE_lineSpacing, textElement.getParagraph().getLineSpacing()); } writer.addAttribute(JRXmlConstants.ATTRIBUTE_markup, textElement.getOwnMarkup()); writeFont(textElement); writeParagraph(textElement.getParagraph()); writer.closeElement(true); }
private int findRowGroupColumHeaderElementIndex(int rowGroupIndex, List<JRChild> cellElements) { String rowGropIndexStr = Integer.toString(rowGroupIndex); int colHeaderTextIndex = -1; for (ListIterator<JRChild> elemIt = cellElements.listIterator(cellElements.size()); elemIt.hasPrevious();) { JRChild child = elemIt.previous(); if (child instanceof JRTextElement) { JRFillTextElement textElement = (JRFillTextElement) child; JRElement parentElement = textElement.getParent(); String prop = parentElement.hasProperties() ? parentElement.getPropertiesMap().getProperty(PROPERTY_ROW_GROUP_COLUMN_HEADER) : null; if (prop != null && prop.equals(rowGropIndexStr)) { // found it colHeaderTextIndex = elemIt.nextIndex(); break; } } } return colHeaderTextIndex; }
/** * */ protected void setTextElement(JRTextElement textElement) { super.setElement(textElement); fontName = textElement.getOwnFontName(); isBold = textElement.isOwnBold(); isItalic = textElement.isOwnItalic(); isUnderline = textElement.isOwnUnderline(); isStrikeThrough = textElement.isOwnStrikeThrough(); fontsize = textElement.getOwnFontsize(); pdfFontName = textElement.getOwnPdfFontName(); pdfEncoding = textElement.getOwnPdfEncoding(); isPdfEmbedded = textElement.isOwnPdfEmbedded(); horizontalTextAlign = textElement.getOwnHorizontalTextAlign(); verticalTextAlign = textElement.getOwnVerticalTextAlign(); rotationValue = textElement.getOwnRotationValue(); markup = textElement.getOwnMarkup(); }
/** * */ private void writeTextElement( JRTextElement textElement, String textElementName) { if(textElement != null) { write( textElementName + ".setHorizontalTextAlign({0});\n", textElement.getOwnHorizontalTextAlign()); write( textElementName + ".setVerticalTextAlign({0});\n", textElement.getOwnVerticalTextAlign()); write( textElementName + ".setRotation({0});\n", textElement.getOwnRotationValue()); write( textElementName + ".setMarkup(\"{0}\");\n", JRStringUtil.escapeJavaStringLiteral(textElement.getOwnMarkup())); writeFont( textElement, textElementName); writeParagraph( textElement.getParagraph(), textElementName); flush(); } }
protected JRDesignComponentElement createIconLabelElement(SortOrderEnum order, JRFillTextElement textElement, BuiltinExpressionEvaluatorFactory builtinExpressions) { JRTextElement parentElement = (JRTextElement) textElement.getParent(); JRDesignComponentElement designIconLabelElement = IconLabelComponentUtil.getInstance(filler.getJasperReportsContext()).createIconLabelComponentElement(parentElement, textElement); IconLabelComponent iconLabelComponent = (IconLabelComponent)designIconLabelElement.getComponent(); JRDesignTextField labelTextField = (JRDesignTextField)iconLabelComponent.getLabelTextField(); JRDesignTextField iconTextField = (JRDesignTextField)iconLabelComponent.getIconTextField(); designIconLabelElement.setStyle(textElement.getInitStyle()); labelTextField.setStyle(textElement.getInitStyle()); iconTextField.setStyle(textElement.getInitStyle()); if (textElement instanceof JRTextField) { labelTextField.setExpression(((JRTextField) textElement).getExpression()); } else if (textElement instanceof JRStaticText) { String text = ((JRStaticText) textElement).getText(); labelTextField.setExpression(builtinExpressions.createConstantExpression(text)); } String iconText = order == SortOrderEnum.ASCENDING ? filler.getPropertiesUtil().getProperty(TableReport.PROPERTY_UP_ARROW_CHAR) : (order == SortOrderEnum.DESCENDING ? filler.getPropertiesUtil().getProperty(TableReport.PROPERTY_DOWN_ARROW_CHAR) : ""); iconTextField.setExpression(builtinExpressions.createConstantExpression(" " + iconText)); designIconLabelElement.getPropertiesMap().setProperty( MatcherExporterFilter.PROPERTY_MATCHER_EXPORT_FILTER_KEY, TableReport.TABLE_HEADER_ICON_LABEL_MATCHER_EXPORT_KEY ); return designIconLabelElement; }
/** * */ protected JRFillTextElement( JRBaseFiller filler, JRTextElement textElement, JRFillObjectFactory factory ) { super(filler, textElement, factory); initLineBox = textElement.getLineBox().clone(this); initParagraph = textElement.getParagraph().clone(this); // not supporting property expressions for this this.consumeSpaceOnOverflow = filler.getPropertiesUtil().getBooleanProperty( PROPERTY_CONSUME_SPACE_ON_OVERFLOW, true, // manually falling back to report properties as getParentProperties() is null for textElement textElement, filler.getMainDataset() ); this.defaultKeepFullText = filler.getPropertiesUtil().getBooleanProperty( JRTextElement.PROPERTY_PRINT_KEEP_FULL_TEXT, false, // manually falling back to report properties as getParentProperties() is null for textElement textElement, filler.getMainDataset()); this.dynamicKeepFullText = hasDynamicProperty(JRTextElement.PROPERTY_PRINT_KEEP_FULL_TEXT); this.fillStyleObjectsMap = new HashMap<JRStyle, JRFillTextElement.FillStyleObjects>(); }
/** * */ public TextMeasurer(JasperReportsContext jasperReportsContext, JRCommonText textElement) { this.jasperReportsContext = jasperReportsContext; this.textElement = textElement; this.propertiesHolder = textElement instanceof JRPropertiesHolder ? (JRPropertiesHolder) textElement : null;//FIXMENOW all elements are now properties holders, so interfaces might be rearranged if (textElement.getDefaultStyleProvider() instanceof JRPropertiesHolder) { this.propertiesHolder = new DelegatePropertiesHolder( propertiesHolder, (JRPropertiesHolder)textElement.getDefaultStyleProvider() ); } if (textElement instanceof DynamicPropertiesHolder) { this.dynamicPropertiesHolder = (DynamicPropertiesHolder) textElement; // we can check this from the beginning this.hasDynamicIgnoreMissingFontProp = this.dynamicPropertiesHolder.hasDynamicProperty( JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT); this.hasDynamicSaveLineBreakOffsetsProp = this.dynamicPropertiesHolder.hasDynamicProperty( JRTextElement.PROPERTY_SAVE_LINE_BREAKS); } // read static property values JRPropertiesUtil propertiesUtil = JRPropertiesUtil.getInstance(jasperReportsContext); defaultIgnoreMissingFont = propertiesUtil.getBooleanProperty(propertiesHolder, JRStyledText.PROPERTY_AWT_IGNORE_MISSING_FONT, false); defaultSaveLineBreakOffsets = propertiesUtil.getBooleanProperty(propertiesHolder, JRTextElement.PROPERTY_SAVE_LINE_BREAKS, false); Context measureContext = new Context(); simpleLineWrapper = new SimpleTextLineWrapper(); simpleLineWrapper.init(measureContext); complextLineWrapper = new ComplexTextLineWrapper(); complextLineWrapper.init(measureContext); }
protected String getTruncateSuffix() { //FIXME do not read each time String truncateSuffx = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(propertiesHolder, JRTextElement.PROPERTY_TRUNCATE_SUFFIX); if (truncateSuffx != null) { truncateSuffx = truncateSuffx.trim(); if (truncateSuffx.length() == 0) { truncateSuffx = null; } } return truncateSuffx; }
protected JRFont getFontClone(JRFont sourceFont){ if (sourceFont == null) return null; if (sourceFont instanceof JRBaseFont){ return (JRBaseFont)((JRBaseFont)sourceFont).clone(); } if (sourceFont instanceof JRTextElement){ return (JRTextElement)((JRTextElement)sourceFont).clone(); } return null; }
private JRFillCellContents decorateWithSortIcon(JRFillCellContents cell, SortOrderEnum order) { // check whether the contents contain a single text element JRElement[] elements = cell.getElements(); if (elements.length != 1) { if (log.isDebugEnabled()) { log.debug("order by column header has " + elements.length + " elements"); } return cell; } if (!(elements[0] instanceof JRTextElement)) { if (log.isDebugEnabled()) { log.debug("order by column header has element " + elements[0].getClass().getName()); } return cell; } // TODO lucianc cache JRFillTextElement textElement = (JRFillTextElement) elements[0]; if (log.isDebugEnabled()) { log.debug("wrapping column header element " + textElement.getUUID() + " in iconLabel"); } BuiltinExpressionEvaluatorFactory builtinExpressions = new BuiltinExpressionEvaluatorFactory(); JRDesignComponentElement iconLabelElement = createIconLabelElement(order, textElement, builtinExpressions); JRFillExpressionEvaluator decoratedEvaluator = builtinExpressions.decorate(cell.expressionEvaluator); IconLabelFillObjectFactory factory = new IconLabelFillObjectFactory(fillFactory, decoratedEvaluator); JRFillComponentElement fillIconLabelElement = new JRFillComponentElement(filler, iconLabelElement, factory); JRFillCellContents clonedCell = (JRFillCellContents) cell.createClone(); clonedCell.addElement(1, fillIconLabelElement); JRFillElement clonedTextElement = (JRFillElement) clonedCell.getElements()[0]; clonedTextElement.setExpressionEvaluator(decoratedEvaluator); clonedTextElement.addDynamicProperty(MatcherExporterFilter.PROPERTY_MATCHER_EXPORT_FILTER_KEY, builtinExpressions.createConstantExpression(TableReport.TABLE_HEADER_LABEL_MATCHER_EXPORT_KEY)); return clonedCell; }
@Override public HorizontalTextAlignEnum getOwnHorizontalTextAlign() { return providerStyle == null || providerStyle.getOwnHorizontalTextAlign() == null ? ((JRTextElement)this.parent).getOwnHorizontalTextAlign() : providerStyle.getOwnHorizontalTextAlign(); }
@Override public VerticalTextAlignEnum getOwnVerticalTextAlign() { return providerStyle == null || providerStyle.getOwnVerticalTextAlign() == null ? ((JRTextElement)this.parent).getOwnVerticalTextAlign() : providerStyle.getOwnVerticalTextAlign(); }
@Override public RotationEnum getOwnRotationValue() { return providerStyle == null || providerStyle.getOwnRotationValue() == null ? ((JRTextElement)this.parent).getOwnRotationValue() : providerStyle.getOwnRotationValue(); }
@Override public String getOwnMarkup() { return providerStyle == null || providerStyle.getOwnMarkup() == null ? ((JRTextElement)parent).getOwnMarkup() : providerStyle.getOwnMarkup(); }
protected boolean isToTruncateAtChar() { //FIXME do not read each time return JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(propertiesHolder, JRTextElement.PROPERTY_TRUNCATE_AT_CHAR, false); }
protected boolean inScope(PropertyMetadata property, JRElement element) { List<PropertyScope> scopes = property.getScopes(); if (scopes.contains(PropertyScope.ELEMENT)) { return true; } if (element instanceof JRTextElement && scopes.contains(PropertyScope.TEXT_ELEMENT)) { return true; } if (element instanceof JRImage && scopes.contains(PropertyScope.IMAGE_ELEMENT)) { return true; } if (element instanceof JRChart && scopes.contains(PropertyScope.CHART_ELEMENT)) { return true; } if (element instanceof JRCrosstab && scopes.contains(PropertyScope.CROSSTAB)) { return true; } if (element instanceof JRFrame && scopes.contains(PropertyScope.FRAME)) { return true; } if (element instanceof JRSubreport && scopes.contains(PropertyScope.SUBREPORT)) { return true; } //TODO lucianc generic element if (element instanceof JRComponentElement && scopes.contains(PropertyScope.COMPONENT)) { List<String> qualifications = property.getScopeQualifications(); if (qualifications == null || qualifications.isEmpty()) { //assuming all components return true; } JRComponentElement componentElement = (JRComponentElement) element; String qualification; if (componentElement.getComponent() instanceof Designated) { qualification = ((Designated) componentElement.getComponent()).getDesignation(); } else { ComponentKey key = componentElement.getComponentKey(); if (key == null || key.getNamespace() == null || key.getName() == null) { //key is missing qualification = null; } else { qualification = key.getNamespace() + PropertyConstants.COMPONENT_KEY_QUALIFICATION_SEPARATOR + key.getName(); } } return qualification != null && qualifications.contains(qualification); } return false; }
/** * */ public JRDesignComponentElement createIconLabelComponentElement(JRTextElement textElement) { return createIconLabelComponentElement(textElement, textElement); }