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()); }
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); }