protected void drawHyperlink( final RenderNode box, final String target, final String window, final String title) { if (box.isNodeVisible(getDrawArea()) == false) { return; } final PdfAction action = createActionForLink(target); final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float leftX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX())); final float rightX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX() + box.getWidth())); final float lowerY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY() + box.getHeight())); final float upperY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY())); if (action != null) { final PdfAnnotation annotation = new PdfAnnotation(writer, leftX, lowerY, rightX, upperY, action); writer.addAnnotation(annotation); } else if (StringUtils.isEmpty(title) == false) { final Rectangle rect = new Rectangle(leftX, lowerY, rightX, upperY); final PdfAnnotation commentAnnotation = PdfAnnotation.createText(writer, rect, "Tooltip", title, false, null); commentAnnotation.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, writer.getDirectContent().createAppearance(rect.getWidth(), rect.getHeight())); writer.addAnnotation(commentAnnotation); } }
public void resizeProportional() { final float originalPageWidth = originalPageDefinition.getWidth(); final float currentPageWidth = currentPageDefinition.getWidth(); final float scaleFactor = currentPageWidth / originalPageWidth; for (int i = 0; i < visualElements.length; i++) { // Resize the element. final CachedLayoutData cachedLayoutData = ModelUtility.getCachedLayoutData(visualElements[i]); final double elementWidth = StrictGeomUtility.toExternalValue(cachedLayoutData.getWidth()); final Element theElement = visualElements[i]; final ElementStyleSheet styleSheet = theElement.getStyle(); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(elementWidth * scaleFactor)); // Reposition the element. final double origin = StrictGeomUtility.toExternalValue(cachedLayoutData.getX()); final double destination = scaleFactor * origin; final int theShift = (int) (destination - origin); final Element[] theElements = new Element[1]; theElements[0] = theElement; align(theShift, theElements); } registerChanges(); }
public void processLogicalPage(final LogicalPageKey key, final LogicalPageBox logicalPage) throws DocumentException { final float width = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageWidth()); final float height = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageHeight()); final Rectangle pageSize = new Rectangle(width, height); final Document document = getDocument(); document.setPageSize(pageSize); document.setMargins(0, 0, 0, 0); if (awaitOpenDocument) { document.open(); awaitOpenDocument = false; } final Graphics2D graphics = new PdfGraphics2D(writer.getDirectContent(), width, height, metaData); // and now process the box .. final PdfLogicalPageDrawable logicalPageDrawable = new PdfLogicalPageDrawable( logicalPage, metaData, writer, null, resourceManager, imageCache, version); logicalPageDrawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); graphics.dispose(); document.newPage(); }
protected void drawImageMap(final RenderableReplacedContentBox content) { if (version < '6') { return; } final ImageMap imageMap = RenderUtility.extractImageMap(content); // only generate a image map, if the user does not specify their own onw via the override. // Of course, they would have to provide the map by other means as well. if (imageMap == null) { return; } final ImageMapEntry[] imageMapEntries = imageMap.getMapEntries(); for (int i = 0; i < imageMapEntries.length; i++) { final ImageMapEntry imageMapEntry = imageMapEntries[i]; final String link = imageMapEntry.getAttribute(LibXmlInfo.XHTML_NAMESPACE, "href"); final String tooltip = imageMapEntry.getAttribute(LibXmlInfo.XHTML_NAMESPACE, "title"); if (StringUtils.isEmpty(tooltip)) { continue; } final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final int x = (int) (translateX + StrictGeomUtility.toExternalValue(content.getX())); final int y = (int) StrictGeomUtility.toExternalValue(content.getY()); final float[] translatedCoords = translateCoordinates(imageMapEntry.getAreaCoordinates(), x, y); final PolygonAnnotation polygonAnnotation = new PolygonAnnotation(writer, translatedCoords); polygonAnnotation.put(PdfName.CONTENTS, new PdfString(tooltip, PdfObject.TEXT_UNICODE)); writer.addAnnotation(polygonAnnotation); } }
protected boolean drawPdfScript(final RenderNode box) { final Object attribute = box.getAttributes() .getAttribute(AttributeNames.Pdf.NAMESPACE, AttributeNames.Pdf.SCRIPT_ACTION); if (attribute == null) { return false; } final String attributeText = String.valueOf(attribute); final PdfAction action = PdfAction.javaScript(attributeText, writer, false); final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float leftX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX())); final float rightX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX() + box.getWidth())); final float lowerY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY() + box.getHeight())); final float upperY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY())); final PdfAnnotation annotation = new PdfAnnotation(writer, leftX, lowerY, rightX, upperY, action); writer.addAnnotation(annotation); return true; }
private void updateCellStyle(final Cell cell, final CellBackground background) { final Color backgroundColor = background.getBackgroundColor(); if (backgroundColor != null) { cell.setBackgroundColor(backgroundColor); } final BorderEdge top = background.getTop(); if (BorderEdge.EMPTY.equals(top) == false) { cell.setBorderColorTop(top.getColor()); cell.setBorderWidthTop((float) StrictGeomUtility.toExternalValue(top.getWidth())); } final BorderEdge left = background.getLeft(); if (BorderEdge.EMPTY.equals(left) == false) { cell.setBorderColorLeft(left.getColor()); cell.setBorderWidthLeft((float) StrictGeomUtility.toExternalValue(left.getWidth())); } final BorderEdge bottom = background.getBottom(); if (BorderEdge.EMPTY.equals(bottom) == false) { cell.setBorderColorBottom(bottom.getColor()); cell.setBorderWidthBottom((float) StrictGeomUtility.toExternalValue(bottom.getWidth())); } final BorderEdge right = background.getRight(); if (BorderEdge.EMPTY.equals(right) == false) { cell.setBorderColorRight(right.getColor()); cell.setBorderWidthRight((float) StrictGeomUtility.toExternalValue(right.getWidth())); } }
public void alignRight() { final double theCurrentPageWidth = currentPageDefinition.getWidth(); final int theShiftRight = (int) (theCurrentPageWidth - StrictGeomUtility.toExternalValue(computeFarRightPostion())); align(theShiftRight, visualElements); registerChanges(); }
protected void drawBookmark(final RenderNode box, final String bookmark) { if (box.isNodeVisible(getDrawArea()) == false) { return; } final PdfOutline root = writer.getDirectContent().getRootOutline(); final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float upperY = translateX + (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY())); final float leftX = (float) (StrictGeomUtility.toExternalValue(box.getX())); final PdfDestination dest = new PdfDestination(PdfDestination.FIT, leftX, upperY, 0); new PdfOutline(root, dest, bookmark); // destination will always point to the 'current' page // todo: Make this a hierarchy .. }
protected void drawAnchor(final RenderNode content) { if (content.isNodeVisible(getDrawArea()) == false) { return; } final String anchorName = (String) content.getStyleSheet().getStyleProperty(ElementStyleKeys.ANCHOR_NAME); if (anchorName == null) { return; } final AffineTransform affineTransform = getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final float upperY = translateX + (float) (globalHeight - StrictGeomUtility.toExternalValue(content.getY())); final float leftX = (float) (StrictGeomUtility.toExternalValue(content.getX())); final PdfDestination dest = new PdfDestination(PdfDestination.FIT, leftX, upperY, 0); writer.getDirectContent().localDestination(anchorName, dest); }
/** Invoked when an action occurs. */ public void actionPerformed(final ActionEvent e) { final ReportSelectionModel model = getSelectionModel(); if (model == null) { return; } final Element[] visualElements = model.getSelectedVisualElements(); if (visualElements.length <= 1) { return; } final Element[] carrier = new Element[1]; final Element[] objects = ModelUtility.filterParents(visualElements); final MassElementStyleUndoEntryBuilder builder = new MassElementStyleUndoEntryBuilder(objects); long minY = Long.MAX_VALUE; long maxY = Long.MIN_VALUE; for (int j = 0; j < objects.length; j++) { final Element object = objects[j]; final CachedLayoutData data = ModelUtility.getCachedLayoutData(object); final long y1 = data.getY(); final long y2 = y1 + data.getHeight(); if (y2 > maxY) { maxY = y2; } if (y1 < minY) { minY = y1; } } final long centerPoint = minY + (maxY - minY) / 2; for (int j = 0; j < objects.length; j++) { final Element object = objects[j]; final CachedLayoutData data = ModelUtility.getCachedLayoutData(object); final long elementCenter = data.getY() + data.getHeight() / 2; final long delta = centerPoint - elementCenter; if (delta == 0) { continue; } carrier[0] = object; final MoveDragOperation mop = new MoveDragOperation( carrier, ORIGIN_POINT, EmptySnapModel.INSTANCE, EmptySnapModel.INSTANCE); mop.update(new Point2D.Double(0, StrictGeomUtility.toExternalValue(delta)), 1); mop.finish(); } final MassElementStyleUndoEntry massElementStyleUndoEntry = builder.finish(); getActiveContext() .getUndo() .addChange( ActionMessages.getString("AlignMiddleAction.UndoName"), massElementStyleUndoEntry); }
public void init( final LogicalPageBox rootBox, final PdfOutputProcessorMetaData metaData, final ResourceManager resourceManager, final PhysicalPageBox page) { super.init(rootBox, metaData, resourceManager); if (page != null) { this.globalHeight = (float) StrictGeomUtility.toExternalValue( page.getHeight() - page.getImageableY() + page.getGlobalY()); } else { this.globalHeight = rootBox.getPageHeight(); } this.globalEmbed = getMetaData().isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS); }
public void processPhysicalPage( final PageGrid pageGrid, final LogicalPageBox logicalPage, final int row, final int col, final PhysicalPageKey pageKey) throws DocumentException { final PhysicalPageBox page = pageGrid.getPage(row, col); if (page == null) { return; } final float width = (float) StrictGeomUtility.toExternalValue(page.getWidth()); final float height = (float) StrictGeomUtility.toExternalValue(page.getHeight()); final Rectangle pageSize = new Rectangle(width, height); final float marginLeft = (float) StrictGeomUtility.toExternalValue(page.getImageableX()); final float marginRight = (float) StrictGeomUtility.toExternalValue( page.getWidth() - page.getImageableWidth() - page.getImageableX()); final float marginTop = (float) StrictGeomUtility.toExternalValue(page.getImageableY()); final float marginBottom = (float) StrictGeomUtility.toExternalValue( page.getHeight() - page.getImageableHeight() - page.getImageableY()); final Document document = getDocument(); document.setPageSize(pageSize); document.setMargins(marginLeft, marginRight, marginTop, marginBottom); if (awaitOpenDocument) { document.open(); awaitOpenDocument = false; } final PdfContentByte directContent = writer.getDirectContent(); final Graphics2D graphics = new PdfGraphics2D(directContent, width, height, metaData); final PdfLogicalPageDrawable logicalPageDrawable = new PdfLogicalPageDrawable( logicalPage, metaData, writer, page, resourceManager, imageCache, version); final PhysicalPageDrawable drawable = new PhysicalPageDrawable(logicalPageDrawable, page); drawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); graphics.dispose(); document.newPage(); }
public void alignCenter() { final long farLeftPostion = computeFarLeftPosition(); final long farRightPostion = computeFarRightPostion(); final long currentPageWidth = StrictGeomUtility.toInternalValue(currentPageDefinition.getWidth()); final long remainingRightSpace = currentPageWidth - farRightPostion; final long normalizedSpace = (farLeftPostion + remainingRightSpace) / 2; long requiredShift = normalizedSpace - farLeftPostion; if (remainingRightSpace > farLeftPostion) { // move to the Right requiredShift = Math.abs(requiredShift); } else { // move to the Left requiredShift = 0 - Math.abs(requiredShift); } final int shiftInPoints = (int) StrictGeomUtility.toExternalValue(requiredShift); align(shiftInPoints, visualElements); registerChanges(); }
protected boolean drawImage( final RenderableReplacedContentBox content, final Image image, final com.lowagie.text.Image itextImage) { final StyleSheet layoutContext = content.getStyleSheet(); final boolean shouldScale = layoutContext.getBooleanStyleProperty(ElementStyleKeys.SCALE); final int x = (int) StrictGeomUtility.toExternalValue(content.getX()); final int y = (int) StrictGeomUtility.toExternalValue(content.getY()); final int width = (int) StrictGeomUtility.toExternalValue(content.getWidth()); final int height = (int) StrictGeomUtility.toExternalValue(content.getHeight()); if (width == 0 || height == 0) { PdfLogicalPageDrawable.logger.debug("Error: Image area is empty: " + content); return false; } final WaitingImageObserver obs = new WaitingImageObserver(image); obs.waitImageLoaded(); final int imageWidth = image.getWidth(obs); final int imageHeight = image.getHeight(obs); if (imageWidth < 1 || imageHeight < 1) { return false; } final Rectangle2D.Double drawAreaBounds = new Rectangle2D.Double(x, y, width, height); final AffineTransform scaleTransform; final Graphics2D g2; if (shouldScale == false) { double deviceScaleFactor = 1; final double devResolution = getMetaData().getNumericFeatureValue(OutputProcessorFeature.DEVICE_RESOLUTION); if (getMetaData().isFeatureSupported(OutputProcessorFeature.IMAGE_RESOLUTION_MAPPING)) { if (devResolution != 72.0 && devResolution > 0) { // Need to scale the device to its native resolution before attempting to draw the image.. deviceScaleFactor = (72.0 / devResolution); } } final int clipWidth = Math.min(width, (int) Math.ceil(deviceScaleFactor * imageWidth)); final int clipHeight = Math.min(height, (int) Math.ceil(deviceScaleFactor * imageHeight)); final ElementAlignment horizontalAlignment = (ElementAlignment) layoutContext.getStyleProperty(ElementStyleKeys.ALIGNMENT); final ElementAlignment verticalAlignment = (ElementAlignment) layoutContext.getStyleProperty(ElementStyleKeys.VALIGNMENT); final int alignmentX = (int) RenderUtility.computeHorizontalAlignment(horizontalAlignment, width, clipWidth); final int alignmentY = (int) RenderUtility.computeVerticalAlignment(verticalAlignment, height, clipHeight); g2 = (Graphics2D) getGraphics().create(); g2.clip(drawAreaBounds); g2.translate(x, y); g2.translate(alignmentX, alignmentY); g2.clip(new Rectangle2D.Float(0, 0, clipWidth, clipHeight)); g2.scale(deviceScaleFactor, deviceScaleFactor); scaleTransform = null; } else { g2 = (Graphics2D) getGraphics().create(); g2.clip(drawAreaBounds); g2.translate(x, y); g2.clip(new Rectangle2D.Float(0, 0, width, height)); final double scaleX; final double scaleY; final boolean keepAspectRatio = layoutContext.getBooleanStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO); if (keepAspectRatio) { final double scaleFactor = Math.min(width / (double) imageWidth, height / (double) imageHeight); scaleX = scaleFactor; scaleY = scaleFactor; } else { scaleX = width / (double) imageWidth; scaleY = height / (double) imageHeight; } final int clipWidth = (int) (scaleX * imageWidth); final int clipHeight = (int) (scaleY * imageHeight); final ElementAlignment horizontalAlignment = (ElementAlignment) layoutContext.getStyleProperty(ElementStyleKeys.ALIGNMENT); final ElementAlignment verticalAlignment = (ElementAlignment) layoutContext.getStyleProperty(ElementStyleKeys.VALIGNMENT); final int alignmentX = (int) RenderUtility.computeHorizontalAlignment(horizontalAlignment, width, clipWidth); final int alignmentY = (int) RenderUtility.computeVerticalAlignment(verticalAlignment, height, clipHeight); g2.translate(alignmentX, alignmentY); scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); } final PdfGraphics2D pdfGraphics2D = (PdfGraphics2D) g2; pdfGraphics2D.drawPdfImage(itextImage, image, scaleTransform, null); g2.dispose(); return true; }
protected void drawText(final RenderableText renderableText, final long contentX2) { if (renderableText.getLength() == 0) { return; } final long posX = renderableText.getX(); final long posY = renderableText.getY(); final float x1 = (float) (StrictGeomUtility.toExternalValue(posX)); final PdfContentByte cb; PdfTextSpec textSpec = (PdfTextSpec) getTextSpec(); if (textSpec == null) { final StyleSheet layoutContext = renderableText.getStyleSheet(); // The code below may be weird, but at least it is predictable weird. final String fontName = getMetaData() .getNormalizedFontFamilyName( (String) layoutContext.getStyleProperty(TextStyleKeys.FONT)); final String encoding = (String) layoutContext.getStyleProperty(TextStyleKeys.FONTENCODING); final float fontSize = (float) layoutContext.getDoubleStyleProperty(TextStyleKeys.FONTSIZE, 10); final boolean embed = globalEmbed || layoutContext.getBooleanStyleProperty(TextStyleKeys.EMBEDDED_FONT); final boolean bold = layoutContext.getBooleanStyleProperty(TextStyleKeys.BOLD); final boolean italics = layoutContext.getBooleanStyleProperty(TextStyleKeys.ITALIC); final BaseFontFontMetrics fontMetrics = getMetaData() .getBaseFontFontMetrics(fontName, fontSize, bold, italics, encoding, embed, false); final PdfGraphics2D g2 = (PdfGraphics2D) getGraphics(); final Color cssColor = (Color) layoutContext.getStyleProperty(ElementStyleKeys.PAINT); g2.setPaint(cssColor); g2.setFillPaint(); g2.setStrokePaint(); // final float translateY = (float) affineTransform.getTranslateY(); cb = g2.getRawContentByte(); textSpec = new PdfTextSpec(layoutContext, getMetaData(), g2, fontMetrics, cb); setTextSpec(textSpec); cb.beginText(); cb.setFontAndSize(fontMetrics.getBaseFont(), fontSize); } else { cb = textSpec.getContentByte(); } final BaseFontFontMetrics baseFontRecord = textSpec.getFontMetrics(); final BaseFont baseFont = baseFontRecord.getBaseFont(); final float ascent = baseFont.getFontDescriptor(BaseFont.BBOXURY, textSpec.getFontSize()); final float y2 = (float) (StrictGeomUtility.toExternalValue(posY) + ascent); final float y = globalHeight - y2; final AffineTransform affineTransform = textSpec.getGraphics().getTransform(); final float translateX = (float) affineTransform.getTranslateX(); final FontNativeContext nativeContext = baseFontRecord.getNativeContext(); if (baseFontRecord.isTrueTypeFont() && textSpec.isBold() && nativeContext.isNativeBold() == false) { final float strokeWidth = textSpec.getFontSize() / 30.0f; // right from iText ... if (strokeWidth == 1) { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE); cb.setLineWidth(strokeWidth); } } else { cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); } // if the font does not declare to be italics already, emulate it .. if (baseFontRecord.isTrueTypeFont() && textSpec.isItalics() && nativeContext.isNativeItalics() == false) { final float italicAngle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, textSpec.getFontSize()); if (italicAngle == 0) { // italics requested, but the font itself does not supply italics gylphs. cb.setTextMatrix(1, 0, PdfLogicalPageDrawable.ITALIC_ANGLE, 1, x1 + translateX, y); } else { cb.setTextMatrix(x1 + translateX, y); } } else { cb.setTextMatrix(x1 + translateX, y); } final OutputProcessorMetaData metaData = getMetaData(); final GlyphList gs = renderableText.getGlyphs(); final int offset = renderableText.getOffset(); final CodePointBuffer codePointBuffer = getCodePointBuffer(); if (metaData.isFeatureSupported(OutputProcessorFeature.FAST_FONTRENDERING) && isNormalTextSpacing(renderableText)) { final int maxLength = renderableText.computeMaximumTextSize(contentX2); final String text = gs.getText(renderableText.getOffset(), maxLength, codePointBuffer); cb.showText(text); } else { final PdfTextArray textArray = new PdfTextArray(); final StringBuilder buffer = new StringBuilder(gs.getSize()); final int maxPos = offset + renderableText.computeMaximumTextSize(contentX2); for (int i = offset; i < maxPos; i++) { final Glyph g = gs.getGlyph(i); final Spacing spacing = g.getSpacing(); if (i != offset) { final float optimum = (float) StrictGeomUtility.toFontMetricsValue(spacing.getMinimum()); if (optimum != 0) { textArray.add(buffer.toString()); textArray.add(-optimum / textSpec.getFontSize()); buffer.setLength(0); } } final String text = gs.getGlyphAsString(i, codePointBuffer); buffer.append(text); } if (buffer.length() > 0) { textArray.add(buffer.toString()); } cb.showText(textArray); } }
public void update(final Point2D normalizedPoint, final double zoomFactor) { final SnapPositionsModel horizontalSnapModel = getHorizontalSnapModel(); final Element[] selectedVisualElements = getSelectedVisualElements(); final long originPointX = getOriginPointX(); final long[] elementWidth = getElementWidth(); final long px = StrictGeomUtility.toInternalValue(normalizedPoint.getX()); final long dx = px - originPointX; for (int i = 0; i < selectedVisualElements.length; i++) { final Element element = selectedVisualElements[i]; if (element instanceof RootLevelBand) { continue; } final ElementStyleSheet styleSheet = element.getStyle(); final double elementMinWidth = styleSheet.getDoubleStyleProperty(ElementStyleKeys.MIN_WIDTH, 0); // this is where I want the element on a global scale... final long targetWidth = elementWidth[i] + dx; final CachedLayoutData data = ModelUtility.getCachedLayoutData(element); final long elementX = data.getX(); final long targetX2 = elementX + targetWidth; if (elementMinWidth >= 0) { // absolute position; resolving is easy here final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetX2, element.getObjectID()); if (Math.abs(snapPosition - targetX2) > snapThreshold) { final long localWidth = Math.max(0, targetX2 - elementX); final float position = (float) StrictGeomUtility.toExternalValue(localWidth); styleSheet.setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(position)); } else { final long localWidth = Math.max(0, snapPosition - elementX); final float position = (float) StrictGeomUtility.toExternalValue(localWidth); styleSheet.setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(position)); } } else { final Element parent = element.getParentSection(); final CachedLayoutData parentData = ModelUtility.getCachedLayoutData(parent); final long parentBase = parentData.getWidth(); if (parentBase > 0) { // relative position; resolve the percentage against the height of the parent. final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetX2, element.getObjectID()); if (Math.abs(snapPosition - targetX2) > snapThreshold) { final long localWidth = Math.max(0, targetX2 - elementX); // strict geometry: all values are multiplied by 1000 // percentages in the engine are represented by floats betwen 0 and 100. final long percentage = StrictGeomUtility.toInternalValue(localWidth * 100 / parentBase); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(StrictGeomUtility.toExternalValue(-percentage))); } else { final long localWidth = Math.max(0, snapPosition - elementX); // strict geometry: all values are multiplied by 1000 // percentages in the engine are represented by floats betwen 0 and 100. final long percentage = StrictGeomUtility.toInternalValue(localWidth * 100 / parentBase); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(StrictGeomUtility.toExternalValue(-percentage))); } } } element.notifyNodePropertiesChanged(); } }
public void alignLeft() { final int theShiftLeft = (int) (0 - StrictGeomUtility.toExternalValue(computeFarLeftPosition())); align(theShiftLeft, visualElements); registerChanges(); }
/** @noinspection IOResourceOpenedButNotSafelyClosed */ public void print( final LogicalPageKey logicalPageKey, final LogicalPageBox logicalPage, final TableContentProducer contentProducer, final RTFOutputProcessorMetaData metaData, final boolean incremental) throws ContentProcessingException { final int startRow = contentProducer.getFinishedRows(); final int finishRow = contentProducer.getFilledRows(); if (incremental && startRow == finishRow) { return; } if (document == null) { this.cellBackgroundProducer = new CellBackgroundProducer( metaData.isFeatureSupported(AbstractTableOutputProcessor.TREAT_ELLIPSE_AS_RECTANGLE), metaData.isFeatureSupported(OutputProcessorFeature.UNALIGNED_PAGEBANDS)); final PhysicalPageBox pageFormat = logicalPage.getPageGrid().getPage(0, 0); final float urx = (float) StrictGeomUtility.toExternalValue(pageFormat.getWidth()); final float ury = (float) StrictGeomUtility.toExternalValue(pageFormat.getHeight()); final float marginLeft = (float) StrictGeomUtility.toExternalValue(pageFormat.getImageableX()); final float marginRight = (float) StrictGeomUtility.toExternalValue( pageFormat.getWidth() - pageFormat.getImageableWidth() - pageFormat.getImageableX()); final float marginTop = (float) StrictGeomUtility.toExternalValue(pageFormat.getImageableY()); final float marginBottom = (float) StrictGeomUtility.toExternalValue( pageFormat.getHeight() - pageFormat.getImageableHeight() - pageFormat.getImageableY()); final Rectangle pageSize = new Rectangle(urx, ury); document = new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom); imageCache = new RTFImageCache(resourceManager); // rtf does not support PageFormats or other meta data... final PatchRtfWriter2 instance = PatchRtfWriter2.getInstance(document, new NoCloseOutputStream(outputStream)); instance.getDocumentSettings().setAlwaysUseUnicode(true); final String author = config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.Author"); if (author != null) { document.addAuthor(author); } final String title = config.getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.Title"); if (title != null) { document.addTitle(title); } document.addProducer(); document.addCreator(RTFPrinter.CREATOR); try { document.addCreationDate(); } catch (Exception e) { RTFPrinter.logger.debug("Unable to add creation date. It will have to work without it.", e); } document.open(); } // Start a new page. try { final SheetLayout sheetLayout = contentProducer.getSheetLayout(); final int columnCount = contentProducer.getColumnCount(); if (table == null) { final int rowCount = contentProducer.getRowCount(); table = new Table(columnCount, rowCount); table.setAutoFillEmptyCells(false); table.setWidth(100); // span the full page.. // and finally the content .. final float[] cellWidths = new float[columnCount]; for (int i = 0; i < columnCount; i++) { cellWidths[i] = (float) StrictGeomUtility.toExternalValue(sheetLayout.getCellWidth(i, i + 1)); } table.setWidths(cellWidths); } // logger.debug ("Processing: " + startRow + " " + finishRow + " " + incremental); for (int row = startRow; row < finishRow; row++) { for (short col = 0; col < columnCount; col++) { final RenderBox content = contentProducer.getContent(row, col); final CellMarker.SectionType sectionType = contentProducer.getSectionType(row, col); if (content == null) { final RenderBox backgroundBox = contentProducer.getBackground(row, col); final CellBackground background; if (backgroundBox != null) { background = cellBackgroundProducer.getBackgroundForBox( logicalPage, sheetLayout, col, row, 1, 1, true, sectionType, backgroundBox); } else { background = cellBackgroundProducer.getBackgroundAt( logicalPage, sheetLayout, col, row, true, sectionType); } if (background == null) { // An empty cell .. ignore final PatchRtfCell cell = new PatchRtfCell(); cell.setBorderWidth(0); cell.setMinimumHeight( (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row))); table.addCell(cell, row, col); continue; } // A empty cell with a defined background .. final PatchRtfCell cell = new PatchRtfCell(); cell.setBorderWidth(0); cell.setMinimumHeight( (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row))); updateCellStyle(cell, background); table.addCell(cell, row, col); continue; } if (content.isCommited() == false) { throw new InvalidReportStateException("Uncommited content encountered"); } final long contentOffset = contentProducer.getContentOffset(row, col); final long colPos = sheetLayout.getXPosition(col); final long rowPos = sheetLayout.getYPosition(row); if (content.getX() != colPos || (content.getY() + contentOffset) != rowPos) { // A spanned cell .. continue; } final int colSpan = sheetLayout.getColSpan(col, content.getX() + content.getWidth()); final int rowSpan = sheetLayout.getRowSpan(row, content.getY() + content.getHeight() + contentOffset); final CellBackground realBackground = cellBackgroundProducer.getBackgroundForBox( logicalPage, sheetLayout, col, row, colSpan, rowSpan, false, sectionType, content); final PatchRtfCell cell = new PatchRtfCell(); cell.setRowspan(rowSpan); cell.setColspan(colSpan); cell.setBorderWidth(0); cell.setMinimumHeight( (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row))); if (realBackground != null) { updateCellStyle(cell, realBackground); } computeCellStyle(content, cell); // export the cell and all content .. final RTFTextExtractor etx = new RTFTextExtractor(metaData); etx.compute(content, cell, imageCache); table.addCell(cell, row, col); content.setFinishedTable(true); // logger.debug("set Finished to cell (" + col + ", " + row + "," + content.getName() + // ")"); } } if (incremental == false) { document.add(table); table = null; } } catch (DocumentException e) { throw new ContentProcessingException("Failed to generate RTF-Document", e); } }