Example #1
0
  public CellStyle(Writer styleWriter, JRExporterGridCell gridCell) {
    super(styleWriter);

    JRPrintElement element = gridCell.getElement();

    if (element != null && element.getModeValue() == ModeEnum.OPAQUE) {
      // fill = "solid";
      backcolor = JRColorUtil.getColorHexa(element.getBackcolor());
    } else {
      // fill = "none";
      if (gridCell.getBackcolor() != null) {
        backcolor = JRColorUtil.getColorHexa(gridCell.getBackcolor());
      }
    }

    RotationEnum rotation =
        element instanceof JRPrintText
            ? ((JRPrintText) element).getRotationValue()
            : RotationEnum.NONE;
    VerticalAlignEnum vAlign = VerticalAlignEnum.TOP;
    HorizontalAlignEnum hAlign = HorizontalAlignEnum.LEFT;

    JRAlignment alignment = element instanceof JRAlignment ? (JRAlignment) element : null;
    if (alignment != null) {
      vAlign = alignment.getVerticalAlignmentValue();
      hAlign = alignment.getHorizontalAlignmentValue();
    }

    horizontalAlignment = ParagraphStyle.getHorizontalAlignment(hAlign, vAlign, rotation);
    verticalAlignment = ParagraphStyle.getVerticalAlignment(hAlign, vAlign, rotation);

    setBox(gridCell.getBox());
  }
    public Object createObject(Attributes atts) throws JRException {
      // Grab the chart from the object stack.
      StandardChartSettings chartSettings = (StandardChartSettings) digester.peek();

      // Set the text color
      String attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_textColor);
      if (attrValue != null && attrValue.length() > 0) {
        Color color = JRColorUtil.getColor(attrValue, null);
        chartSettings.setLegendColor(color);
      }

      // Set the background color
      attrValue = atts.getValue(JRXmlConstants.ATTRIBUTE_backgroundColor);
      if (attrValue != null && attrValue.length() > 0) {
        Color color = JRColorUtil.getColor(attrValue, null);
        chartSettings.setLegendBackgroundColor(color);
      }

      EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
      if (position != null) {
        chartSettings.setLegendPosition(position);
      }

      return chartSettings;
    }
  public Object createObject(Attributes atts) {
    StandardChartSettings chartSettings = new StandardChartSettings();

    String isShowLegend = atts.getValue(JRXmlConstants.ATTRIBUTE_isShowLegend);
    if (isShowLegend != null && isShowLegend.length() > 0) {
      chartSettings.setShowLegend(Boolean.valueOf(isShowLegend));
    }

    Color backcolor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor), null);
    if (backcolor != null) {
      chartSettings.setBackcolor(backcolor);
    }

    chartSettings.setLinkType(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkType));
    chartSettings.setLinkTarget(atts.getValue(JRXmlConstants.ATTRIBUTE_hyperlinkTarget));

    String bookmarkLevelAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_bookmarkLevel);
    if (bookmarkLevelAttr != null) {
      chartSettings.setBookmarkLevel(Integer.parseInt(bookmarkLevelAttr));
    }

    chartSettings.setCustomizerClass(atts.getValue(JRXmlConstants.ATTRIBUTE_customizerClass));
    chartSettings.setRenderType(atts.getValue(JRXmlConstants.ATTRIBUTE_renderType));

    return chartSettings;
  }
    public Object createObject(Attributes atts) {
      StandardChartSettings chartSettings = (StandardChartSettings) digester.peek();

      Color color =
          JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
      if (color != null) {
        chartSettings.setSubtitleColor(color);
      }

      return chartSettings;
    }
    public Object createObject(Attributes atts) {
      StandardChartSettings chartSettings = (StandardChartSettings) digester.peek();

      EdgeEnum position = EdgeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_position));
      if (position != null) {
        chartSettings.setTitlePosition(position);
      }

      Color color =
          JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_color), Color.black);
      if (color != null) {
        chartSettings.setTitleColor(color);
      }

      return chartSettings;
    }
 private void exportBorder(DocxBorderInfo info, int side) {
   if (info.borderWidth[side] != null) {
     write(
         "<w:"
             + DocxBorderInfo.BORDER[side]
             + " w:val=\""
             + info.borderStyle[side]
             + "\" w:sz=\""
             + info.borderWidth[side]
             + "\" w:space=\"0\"");
     if (info.borderColor[side] != null) // FIXMEDOCX check this; use default color?
     {
       write(" w:color=\"" + JRColorUtil.getColorHexa(info.borderColor[side]) + "\"");
     }
     write(" />\n");
   }
 }
  public Renderable createImage(
      JasperReportsContext jasperReportsContext,
      JRComponentElement componentElement,
      QRCodeBean qrCodeBean,
      String message) {
    Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
    hints.put(EncodeHintType.CHARACTER_SET, QRCodeComponent.PROPERTY_DEFAULT_ENCODING);
    ErrorCorrectionLevel errorCorrectionLevel =
        qrCodeBean.getErrorCorrectionLevel().getErrorCorrectionLevel();
    hints.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);

    ByteMatrix matrix = null;
    SVGCanvasProvider provider = null;
    try {
      QRCode qrCode = Encoder.encode(message, errorCorrectionLevel, hints);
      matrix = qrCode.getMatrix();

      provider = new SVGCanvasProvider(false, OrientationEnum.UP.getValue());
    } catch (WriterException e) {
      throw new JRRuntimeException(e);
    } catch (BarcodeCanvasSetupException e) {
      throw new JRRuntimeException(e);
    }

    Document svgDoc = provider.getDOM();
    Element svg = svgDoc.getDocumentElement();
    int codeWidth = matrix.getWidth();
    int codeHeight = matrix.getHeight();

    JRStyle elementStyle = componentElement.getStyle();
    int elementWidth =
        componentElement.getWidth()
            - (elementStyle == null
                ? 0
                : (elementStyle.getLineBox().getLeftPadding()
                    + elementStyle.getLineBox().getRightPadding()));
    int elementHeight =
        componentElement.getHeight()
            - (elementStyle == null
                ? 0
                : (elementStyle.getLineBox().getTopPadding()
                    + elementStyle.getLineBox().getBottomPadding()));

    int margin = qrCodeBean.getMargin() == null ? DEFAULT_MARGIN : qrCodeBean.getMargin();
    int matrixWidth = codeWidth + 2 * margin;
    int matrixHeight = codeHeight + 2 * margin;

    // scaling to match the image size as closely as possible so that it looks good in html.
    // the resolution is taken into account because the html exporter rasterizes to a png
    // that has the same size as the svg.
    int resolution =
        JRPropertiesUtil.getInstance(jasperReportsContext)
            .getIntegerProperty(
                componentElement, BarcodeRasterizedImageProducer.PROPERTY_RESOLUTION, 300);
    int imageWidth = (int) Math.ceil(elementWidth * (resolution / 72d));
    int imageHeight = (int) Math.ceil(elementHeight * (resolution / 72d));

    double horizontalScale = ((double) imageWidth) / matrixWidth;
    double verticalScale = ((double) imageHeight) / matrixHeight;

    // we are scaling with integer units, not considering fractional coordinates for now
    int scale = Math.max(1, (int) Math.min(Math.ceil(horizontalScale), Math.ceil(verticalScale)));
    int qrWidth = scale * matrixWidth;
    int qrHeight = scale * matrixHeight;

    // scaling again because of the integer units
    double qrScale =
        Math.max(1d, Math.max(((double) qrWidth) / imageWidth, ((double) qrHeight) / imageHeight));
    int svgWidth = (int) Math.ceil(qrScale * imageWidth);
    int svgHeight = (int) Math.ceil(qrScale * imageHeight);
    svg.setAttribute("width", String.valueOf(svgWidth));
    svg.setAttribute("height", String.valueOf(svgHeight));
    svg.setAttribute("viewBox", "0 0 " + svgWidth + " " + svgHeight);

    int xOffset = Math.max(0, (svgWidth - qrWidth) / 2);
    int yOffset = Math.max(0, (svgHeight - qrHeight) / 2);

    Color color = componentElement.getForecolor();
    String fill = "#" + JRColorUtil.getColorHexa(color);
    String fillOpacity =
        color.getAlpha() < 255 ? Float.toString(((float) color.getAlpha()) / 255) : null;
    String rectangleSize = Integer.toString(scale);
    for (int x = 0; x < codeWidth; x++) {
      for (int y = 0; y < codeHeight; y++) {
        if (matrix.get(x, y) == 1) {
          Element element = svgDoc.createElementNS(svg.getNamespaceURI(), "rect");
          element.setAttribute("x", String.valueOf(xOffset + scale * (x + margin)));
          element.setAttribute("y", String.valueOf(yOffset + scale * (y + margin)));
          element.setAttribute("width", rectangleSize);
          element.setAttribute("height", rectangleSize);
          element.setAttribute("fill", fill);
          if (fillOpacity != null) {
            element.setAttribute("fill-opacity", fillOpacity);
          }
          svgDoc.getFirstChild().appendChild(element);
        }
      }
    }

    Source source = new DOMSource(svgDoc);
    StringWriter outWriter = new StringWriter();
    Result output = new StreamResult(outWriter);

    try {
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.transform(source, output);

    } catch (TransformerException e) {
      throw new JRRuntimeException(e);
    }

    String svgString = outWriter.toString();
    return new BatikRenderer(svgString, null);
  }
  protected void setCommonStyle(JRStyle style, Attributes atts) {
    // get JRElement attributes
    ModeEnum mode = ModeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_mode));
    if (mode != null) {
      style.setMode(mode);
    }

    String forecolor = atts.getValue(JRXmlConstants.ATTRIBUTE_forecolor);
    style.setForecolor(JRColorUtil.getColor(forecolor, null));

    String backcolor = atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor);
    style.setBackcolor(JRColorUtil.getColor(backcolor, null));

    // get graphic element attributes
    PenEnum pen = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_pen));
    if (pen != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'pen' attribute is deprecated. Use the <pen> tag instead.");
      }

      JRPenUtil.setLinePenFromPen(pen, style.getLinePen());
    }

    FillEnum fill = FillEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_fill));
    if (fill != null) {
      style.setFill(fill);
    }

    // get rectangle attributes
    String radius = atts.getValue(JRXmlConstants.ATTRIBUTE_radius);
    if (radius != null && radius.length() > 0) {
      style.setRadius(Integer.parseInt(radius));
    }

    // get image attributes
    ScaleImageEnum scaleImage =
        ScaleImageEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage));
    if (scaleImage != null) {
      style.setScaleImage(scaleImage);
    }

    HorizontalAlignEnum horizontalAlignment =
        HorizontalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign));
    if (horizontalAlignment != null) {
      style.setHorizontalAlignment(horizontalAlignment);
    }

    VerticalAlignEnum verticalAlignment =
        VerticalAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign));
    if (verticalAlignment != null) {
      style.setVerticalAlignment(verticalAlignment);
    }

    // get box attributes
    PenEnum border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_border));
    if (border != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'border' attribute is deprecated. Use the <pen> tag instead.");
      }
      JRPenUtil.setLinePenFromPen(border, style.getLineBox().getPen());
    }

    Color borderColor =
        JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_borderColor), null);
    if (borderColor != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'borderColor' attribute is deprecated. Use the <pen> tag instead.");
      }
      style.getLineBox().getPen().setLineColor(borderColor);
    }

    String padding = atts.getValue(JRXmlConstants.ATTRIBUTE_padding);
    if (padding != null && padding.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'padding' attribute is deprecated. Use the <box> tag instead.");
      }
      style.getLineBox().setPadding(Integer.parseInt(padding));
    }

    border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_topBorder));
    if (border != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'topBorder' attribute is deprecated. Use the <pen> tag instead.");
      }
      JRPenUtil.setLinePenFromPen(border, style.getLineBox().getTopPen());
    }

    borderColor =
        JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_topBorderColor), Color.black);
    if (borderColor != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'topBorderColor' attribute is deprecated. Use the <pen> tag instead.");
      }
      style.getLineBox().getTopPen().setLineColor(borderColor);
    }

    padding = atts.getValue(JRXmlConstants.ATTRIBUTE_topPadding);
    if (padding != null && padding.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'topPadding' attribute is deprecated. Use the <box> tag instead.");
      }
      style.getLineBox().setTopPadding(Integer.parseInt(padding));
    }

    border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorder));
    if (border != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'leftBorder' attribute is deprecated. Use the <pen> tag instead.");
      }
      JRPenUtil.setLinePenFromPen(border, style.getLineBox().getLeftPen());
    }

    borderColor =
        JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorderColor), Color.black);
    if (borderColor != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'leftBorderColor' attribute is deprecated. Use the <pen> tag instead.");
      }
      style.getLineBox().getLeftPen().setLineColor(borderColor);
    }

    padding = atts.getValue(JRXmlConstants.ATTRIBUTE_leftPadding);
    if (padding != null && padding.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'leftPadding' attribute is deprecated. Use the <box> tag instead.");
      }
      style.getLineBox().setLeftPadding(Integer.parseInt(padding));
    }

    border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorder));
    if (border != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'bottomBorder' attribute is deprecated. Use the <pen> tag instead.");
      }
      JRPenUtil.setLinePenFromPen(border, style.getLineBox().getBottomPen());
    }

    borderColor =
        JRColorUtil.getColor(
            atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorderColor), Color.black);
    if (borderColor != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'bottomBorderColor' attribute is deprecated. Use the <pen> tag instead.");
      }
      style.getLineBox().getBottomPen().setLineColor(borderColor);
    }

    padding = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomPadding);
    if (padding != null && padding.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'bottomPadding' attribute is deprecated. Use the <box> tag instead.");
      }
      style.getLineBox().setBottomPadding(Integer.parseInt(padding));
    }

    border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorder));
    if (border != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'rightBorder' attribute is deprecated. Use the <pen> tag instead.");
      }
      JRPenUtil.setLinePenFromPen(border, style.getLineBox().getRightPen());
    }

    borderColor =
        JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorderColor), Color.black);
    if (borderColor != null) {
      if (log.isWarnEnabled()) {
        log.warn("The 'rightBorderColor' attribute is deprecated. Use the <pen> tag instead.");
      }
      style.getLineBox().getRightPen().setLineColor(borderColor);
    }

    padding = atts.getValue(JRXmlConstants.ATTRIBUTE_rightPadding);
    if (padding != null && padding.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'rightPadding' attribute is deprecated. Use the <box> tag instead.");
      }
      style.getLineBox().setRightPadding(Integer.parseInt(padding));
    }

    RotationEnum rotation =
        RotationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rotation));
    if (rotation != null) {
      style.setRotation(rotation);
    }

    LineSpacingEnum lineSpacing =
        LineSpacingEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing));
    if (lineSpacing != null) {
      style.setLineSpacing(lineSpacing);
    }

    style.setMarkup(atts.getValue(JRXmlConstants.ATTRIBUTE_markup));

    String isStyledText = atts.getValue(JRXmlConstants.ATTRIBUTE_isStyledText);
    if (isStyledText != null && isStyledText.length() > 0) {
      if (log.isWarnEnabled()) {
        log.warn("The 'isStyledText' attribute is deprecated. Use the 'markup' attribute instead.");
      }
      style.setMarkup(
          Boolean.valueOf(isStyledText)
              ? JRCommonText.MARKUP_STYLED_TEXT
              : JRCommonText.MARKUP_NONE);
    }

    style.setPattern(atts.getValue(JRXmlConstants.ATTRIBUTE_pattern));

    String isBlankWhenNull = atts.getValue(JRXmlConstants.ATTRIBUTE_isBlankWhenNull);
    if (isBlankWhenNull != null && isBlankWhenNull.length() > 0) {
      style.setBlankWhenNull(Boolean.valueOf(isBlankWhenNull));
    }

    if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null) {
      style.setFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_fontName));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null) {
      style.setBold(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isBold)));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null) {
      style.setItalic(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic)));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null) {
      style.setUnderline(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline)));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null) {
      style.setStrikeThrough(
          Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough)));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize) != null) {
      style.setFontSize(Integer.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize)));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null) {
      style.setPdfFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null) {
      style.setPdfEncoding(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding));
    }
    if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null) {
      style.setPdfEmbedded(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded)));
    }
  }