Tag: cws_src680_oj14 User: oj Date: 2007-06-06 07:00:04+0000 Modified: dba/reportdesign/java/com/sun/star/report/pentaho/output/ImageProducer.java dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java dba/reportdesign/java/com/sun/star/report/pentaho/output/spreadsheet/SpreadsheetRawReportProcessor.java dba/reportdesign/java/com/sun/star/report/pentaho/output/spreadsheet/SpreadsheetRawReportTarget.java dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportProcessor.java dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java
Log: #i77610# changes to images as well File Changes: Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/ ===================================================================== File [changed]: ImageProducer.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/ImageProducer.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +43 -48 --------------------- --- ImageProducer.java 2007-05-09 12:29:54+0000 1.1.2.1 +++ ImageProducer.java 2007-06-06 07:00:01+0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: ImageProducer.java,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: oj $ $Date: 2007/05/09 12:29:54 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -38,6 +38,7 @@ package com.sun.star.report.pentaho.output; import java.awt.Image; +import java.awt.Dimension; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -54,6 +55,8 @@ import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; +import com.sun.star.report.ImageService; +import com.sun.star.report.ReportExecutionException; import com.sun.star.report.pentaho.DefaultNameGenerator; import com.keypoint.PngEncoder; import org.jfree.io.IOUtils; @@ -160,16 +163,36 @@ private HashMap imageCache; private InputRepository inputRepository; private OutputRepository outputRepository; + private ImageService imageService; private ResourceManager resourceManager; private DefaultNameGenerator nameGenerator; public ImageProducer(final ResourceManager resourceManager, final InputRepository inputRepository, - final OutputRepository outputRepository) + final OutputRepository outputRepository, + final ImageService imageService) { + if (resourceManager == null) + { + throw new NullPointerException(); + } + if (inputRepository == null) + { + throw new NullPointerException(); + } + if (outputRepository == null) + { + throw new NullPointerException(); + } + if (imageService == null) + { + throw new NullPointerException(); + } + this.resourceManager = resourceManager; this.inputRepository = inputRepository; this.outputRepository = outputRepository; + this.imageService = imageService; this.imageCache = new HashMap(); this.nameGenerator = new DefaultNameGenerator(outputRepository); } @@ -217,13 +240,10 @@ // quick caching ... use a weak list ... final WaitingImageObserver obs = new WaitingImageObserver(image); obs.waitImageLoaded(); - final int width = image.getWidth(null); - final int height = image.getHeight(null); - final PngEncoder encoder = new PngEncoder(image, - PngEncoder.ENCODE_ALPHA, PngEncoder.FILTER_NONE, 5); + final PngEncoder encoder = new PngEncoder(image, PngEncoder.ENCODE_ALPHA, PngEncoder.FILTER_NONE, 5); final byte[] data = encoder.pngEncode(); - return produceFromByteArray(data, width, height); + return produceFromByteArray(data); } private OfficeImage produceFromBlob(final Blob blob) @@ -246,23 +266,17 @@ } catch (IOException e) { - e.printStackTrace(); + Log.warn ("Failed to produce image from Blob", e); } catch (SQLException e) { - e.printStackTrace(); + Log.warn ("Failed to produce image from Blob", e); } return null; } private OfficeImage produceFromByteArray(final byte[] data) { - return produceFromByteArray(data, -1, -1); - } - - - private OfficeImage produceFromByteArray(final byte[] data, final int imageWidth, final int imageHeight) - { final ByteDataImageKey imageKey = new ByteDataImageKey(data); final OfficeImage o = (OfficeImage) imageCache.get(imageKey); if (o != null) @@ -272,28 +286,12 @@ try { - int width = imageWidth; - int height = imageHeight; - if (width == -1 || height == -1) - { - // this might be a little bit inefficient .. - // implementing some proper finger-printing might be faster .. - final Resource resource = resourceManager.createDirectly(data, Image.class); - final Image image = (Image) resource.getResource(); - - final WaitingImageObserver wobs = new WaitingImageObserver(image); - wobs.waitImageLoaded(); - - width = image.getWidth(wobs); - height = image.getHeight(wobs); - } - - final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.PX, width); - final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.PX, height); + final String mimeType = imageService.getMimeType(data); + final Dimension dims = imageService.getImageSize(data); // copy the image into the local output-storage // todo: Implement data-fingerprinting so that we can detect the mime-type - final String name = nameGenerator.generateName("Pictures/image", "application/octet-stream"); + final String name = nameGenerator.generateName("Pictures/image", mimeType); final OutputStream outputStream = outputRepository.createOutputStream(name); final ByteArrayInputStream bin = new ByteArrayInputStream(data); @@ -306,6 +304,8 @@ outputStream.close(); } + final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); + final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); final OfficeImage officeImage = new OfficeImage(name, widthVal, heightVal); imageCache.put (imageKey, officeImage); return officeImage; @@ -314,7 +314,7 @@ { Log.warn("Failed to load image from local input-repository", e); } - catch (ResourceException e) + catch (ReportExecutionException e) { Log.warn("Failed to create image from local input-repository", e); } @@ -358,17 +358,10 @@ inputStream.close(); } final byte[] data = bout.toByteArray(); - final Resource resource = resourceManager.createDirectly(data, Image.class); - final Image image = (Image) resource.getResource(); + final Dimension dims = imageService.getImageSize(data); - // this might be a little bit inefficient .. - final WaitingImageObserver wobs = new WaitingImageObserver(image); - wobs.waitImageLoaded(); - - final int width = image.getWidth(wobs); - final int height = image.getHeight(wobs); - final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.PX, width); - final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.PX, height); + final CSSNumericValue widthVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getWidth() / 100.0); + final CSSNumericValue heightVal = CSSNumericValue.createValue(CSSNumericType.MM, dims.getHeight() / 100.0); final OfficeImage officeImage = new OfficeImage(source, widthVal, heightVal); imageCache.put(source, officeImage); @@ -378,11 +371,13 @@ { Log.warn("Failed to load image from local input-repository", e); } - catch (ResourceException e) + catch (ReportExecutionException e) { Log.warn("Failed to create image from local input-repository", e); } } + + // Return the image as broken image instead .. final OfficeImage officeImage = new OfficeImage(source, null, null); imageCache.put(source, officeImage); return officeImage; File [changed]: OfficeDocumentReportTarget.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/OfficeDocumentReportTarget.java?r1=1.1.2.3&r2=1.1.2.4 Delta lines: +35 -9 -------------------- --- OfficeDocumentReportTarget.java 2007-05-15 06:50:25+0000 1.1.2.3 +++ OfficeDocumentReportTarget.java 2007-06-06 07:00:01+0000 1.1.2.4 @@ -4,9 +4,9 @@ * * $RCSfile: OfficeDocumentReportTarget.java,v $ * - * $Revision: 1.1.2.3 $ + * $Revision: 1.1.2.4 $ * - * last change: $Author: oj $ $Date: 2007/05/15 06:50:25 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -55,6 +55,7 @@ import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; +import com.sun.star.report.ImageService; import com.sun.star.report.pentaho.OfficeNamespaces; import com.sun.star.report.pentaho.layoutprocessor.ImageElementContext; import com.sun.star.report.pentaho.model.OfficeDocument; @@ -252,10 +253,22 @@ final ResourceKey baseResource, final InputRepository inputRepository, final OutputRepository outputRepository, - final String target) + final String target, + final ImageService imageService) throws ReportProcessingException { super(reportJob, resourceManager, baseResource); + if (imageService == null) + { + throw new NullPointerException("ImageService must not be null"); + } + if (target == null) + { + throw new NullPointerException("Target-Name must not be null"); + } + + final ResourceManager realResourceManager = getResourceManager(); + this.target = target; this.tableNameGenerator = new AttributeNameGenerator(); @@ -264,11 +277,12 @@ this.states = new FastStack(); this.xmlWriters = new FastStack(); this.imageNames = new AttributeNameGenerator(); - this.imageProducer = new ImageProducer(resourceManager, inputRepository, outputRepository); + + this.imageProducer = new ImageProducer(realResourceManager, inputRepository, outputRepository, imageService); try { - styleMapper = StyleMapper.loadInstance(resourceManager); + styleMapper = StyleMapper.loadInstance(realResourceManager); } catch (ResourceException e) { @@ -299,8 +313,7 @@ final DefaultTagDescription tagDescription = createTagDescription(); try { - final OutputStream outputStream = - outputRepository.createOutputStream(target); + final OutputStream outputStream = outputRepository.createOutputStream(target); final Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); this.rootXmlWriter = new XmlWriter(writer, tagDescription); @@ -1100,6 +1113,7 @@ { final Object imageData = attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "image-data"); final boolean preserveIRI = "true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "preserve-IRI")); + String styleName = null; // for the first shot, do nothing fancy .. final ImageProducer.OfficeImage image = imageProducer.produceImage(imageData, preserveIRI); @@ -1126,7 +1140,7 @@ CSSValueResolverUtility.convertLength(height, imageAreaHeightVal.getType()); final boolean scale = "true".equals(attrs.getAttribute(OfficeNamespaces.INTERNAL_NS, "scale")); - if (scale) + if (scale == false) { final double clipWidth = normalizedImageWidth.getValue() - imageAreaWidthVal.getValue(); final double clipHeight = normalizedImageHeight.getValue() - imageAreaHeightVal.getValue(); @@ -1149,6 +1163,9 @@ buffer.append(imageAreaHeightVal.getType().getType()); buffer.append(")"); graphProperties.setAttribute(OfficeNamespaces.FO_NS, "clip", buffer.toString()); + + styleName = imageStyle.getStyleName(); + getStylesCollection().getAutomaticStyles().addStyle(imageStyle); } else if (clipWidth > 0) { @@ -1168,6 +1185,8 @@ buffer.append(")"); graphProperties.setAttribute(OfficeNamespaces.FO_NS, "clip", buffer.toString()); + styleName = imageStyle.getStyleName(); + getStylesCollection().getAutomaticStyles().addStyle(imageStyle); imageAreaHeightVal = normalizedImageHeight; } else if (clipHeight > 0) @@ -1188,6 +1207,8 @@ buffer.append(")"); graphProperties.setAttribute(OfficeNamespaces.FO_NS, "clip", buffer.toString()); + styleName = imageStyle.getStyleName(); + getStylesCollection().getAutomaticStyles().addStyle(imageStyle); imageAreaWidthVal = normalizedImageWidth; } else @@ -1216,6 +1237,10 @@ final AttributeList frameList = new AttributeList(); frameList.setAttribute(OfficeNamespaces.DRAWING_NS, "name", imageNames.generateName("Image")); + if (styleName != null) + { + frameList.setAttribute(OfficeNamespaces.DRAWING_NS, "style-name", styleName); + } frameList.setAttribute(OfficeNamespaces.TEXT_NS, "anchor-type", "paragraph"); frameList.setAttribute(OfficeNamespaces.SVG_NS, "z-index", "0"); frameList.setAttribute(OfficeNamespaces.SVG_NS, "x", "0cm"); @@ -1239,6 +1264,7 @@ imageList.setAttribute(OfficeNamespaces.XLINK_NS, "show", "embed"); imageList.setAttribute(OfficeNamespaces.XLINK_NS, "actuate", "onLoad"); + try { getXmlWriter().writeTag(OfficeNamespaces.DRAWING_NS, "frame", frameList, XmlWriterSupport.OPEN); Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/spreadsheet/ ================================================================================= File [changed]: SpreadsheetRawReportProcessor.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/spreadsheet/SpreadsheetRawReportProcessor.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +21 -8 -------------------- --- SpreadsheetRawReportProcessor.java 2007-05-09 12:37:19+0000 1.1.2.1 +++ SpreadsheetRawReportProcessor.java 2007-06-06 07:00:01+0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: SpreadsheetRawReportProcessor.java,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: oj $ $Date: 2007/05/09 12:37:19 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -46,6 +46,7 @@ import org.jfree.resourceloader.ResourceManager; import com.sun.star.report.OutputRepository; import com.sun.star.report.InputRepository; +import com.sun.star.report.ImageService; /** * @author Michael D'Amour @@ -56,10 +57,12 @@ private String targetName; private InputRepository inputRepository; + private ImageService imageService; public SpreadsheetRawReportProcessor(final InputRepository inputRepository, final OutputRepository outputRepository, - final String targetName) + final String targetName, + final ImageService imageService) { if (outputRepository == null) { @@ -69,22 +72,32 @@ { throw new NullPointerException(); } + if (imageService == null) + { + throw new NullPointerException(); + } + if (inputRepository == null) + { + throw new NullPointerException(); + } this.targetName = targetName; this.inputRepository = inputRepository; this.outputRepository = outputRepository; + this.imageService = imageService; } - protected ReportTarget createReportTarget(ReportJob job) throws ReportProcessingException + protected ReportTarget createReportTarget(final ReportJob job) throws ReportProcessingException { final ReportStructureRoot report = job.getReportStructureRoot(); final ResourceManager resourceManager = report.getResourceManager(); - return new SpreadsheetRawReportTarget(job, resourceManager, report.getBaseResource(), inputRepository, outputRepository, targetName); + return new SpreadsheetRawReportTarget + (job, resourceManager, report.getBaseResource(), inputRepository, outputRepository, targetName, imageService); } - public void processReport(ReportJob job) throws ReportDataFactoryException, DataSourceException, + public void processReport(final ReportJob job) throws ReportDataFactoryException, DataSourceException, ReportProcessingException { - ReportTarget reportTarget = createReportTarget(job); + final ReportTarget reportTarget = createReportTarget(job); // first run: collect table cell sizes for all tables processReportRun(job, reportTarget); // second run: uses table cell data to output a single uniform table File [changed]: SpreadsheetRawReportTarget.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/spreadsheet/SpreadsheetRawReportTarget.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +7 -5 ------------------- --- SpreadsheetRawReportTarget.java 2007-05-09 12:37:30+0000 1.1.2.1 +++ SpreadsheetRawReportTarget.java 2007-06-06 07:00:01+0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: SpreadsheetRawReportTarget.java,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: oj $ $Date: 2007/05/09 12:37:30 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -44,6 +44,7 @@ import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; +import com.sun.star.report.ImageService; import com.sun.star.report.pentaho.OfficeNamespaces; import com.sun.star.report.pentaho.PentahoReportEngineMetaData; import com.sun.star.report.pentaho.model.OfficeStyle; @@ -97,10 +98,11 @@ final ResourceKey baseResource, final InputRepository inputRepository, final OutputRepository outputRepository, - final String target) + final String target, + final ImageService imageService) throws ReportProcessingException { - super(reportJob, resourceManager, baseResource, inputRepository, outputRepository, target); + super(reportJob, resourceManager, baseResource, inputRepository, outputRepository, target, imageService); columnBoundaryList = new ArrayList(); elementBoundaryCollectionPass = true; } Directory: /dba/reportdesign/java/com/sun/star/report/pentaho/output/text/ ========================================================================== File [changed]: TextRawReportProcessor.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportProcessor.java?r1=1.1.2.1&r2=1.1.2.2 Delta lines: +13 -5 -------------------- --- TextRawReportProcessor.java 2007-05-09 12:31:41+0000 1.1.2.1 +++ TextRawReportProcessor.java 2007-06-06 07:00:01+0000 1.1.2.2 @@ -4,9 +4,9 @@ * * $RCSfile: TextRawReportProcessor.java,v $ * - * $Revision: 1.1.2.1 $ + * $Revision: 1.1.2.2 $ * - * last change: $Author: oj $ $Date: 2007/05/09 12:31:41 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -38,6 +38,7 @@ import com.sun.star.report.OutputRepository; import com.sun.star.report.InputRepository; +import com.sun.star.report.ImageService; import org.jfree.report.ReportProcessingException; import org.jfree.report.flow.ReportJob; import org.jfree.report.flow.ReportStructureRoot; @@ -55,10 +56,12 @@ private OutputRepository outputRepository; private String targetName; private InputRepository inputRepository; + private ImageService imageService; public TextRawReportProcessor(final InputRepository inputRepository, final OutputRepository outputRepository, - final String targetName) + final String targetName, + final ImageService imageService) { if (inputRepository == null) { @@ -72,9 +75,14 @@ { throw new NullPointerException(); } + if (imageService == null) + { + throw new NullPointerException(); + } this.targetName = targetName; this.inputRepository = inputRepository; this.outputRepository = outputRepository; + this.imageService = imageService; } protected ReportTarget createReportTarget(final ReportJob job) @@ -84,6 +92,6 @@ final ResourceManager resourceManager = report.getResourceManager(); return new TextRawReportTarget (job, resourceManager, report.getBaseResource(), - inputRepository, outputRepository, targetName); + inputRepository, outputRepository, targetName, imageService); } } File [changed]: TextRawReportTarget.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/pentaho/output/text/TextRawReportTarget.java?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +10 -7 -------------------- --- TextRawReportTarget.java 2007-05-15 06:50:25+0000 1.1.2.2 +++ TextRawReportTarget.java 2007-06-06 07:00:01+0000 1.1.2.3 @@ -4,9 +4,9 @@ * * $RCSfile: TextRawReportTarget.java,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: oj $ $Date: 2007/05/15 06:50:25 $ + * last change: $Author: oj $ $Date: 2007/06/06 07:00:01 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -44,6 +44,7 @@ import com.sun.star.report.InputRepository; import com.sun.star.report.OutputRepository; +import com.sun.star.report.ImageService; import com.sun.star.report.pentaho.OfficeNamespaces; import com.sun.star.report.pentaho.PentahoReportEngineMetaData; import com.sun.star.report.pentaho.model.OfficeMasterPage; @@ -123,10 +124,11 @@ final ResourceKey baseResource, final InputRepository inputRepository, final OutputRepository outputRepository, - final String target) + final String target, + final ImageService imageService) throws ReportProcessingException { - super(reportJob, resourceManager, baseResource, inputRepository, outputRepository, target); + super(reportJob, resourceManager, baseResource, inputRepository, outputRepository, target, imageService); activePageContext = new FastStack(); this.sectionNames = new AttributeNameGenerator(); @@ -818,8 +820,8 @@ } if (keepWithNext) { - final Element paragraphProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "paragraph-properties"); - paragraphProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always"); + final Element tableProps = produceFirstChild(style, OfficeNamespaces.STYLE_NS, "table-properties"); + tableProps.setAttribute(OfficeNamespaces.FO_NS, "keep-with-next", "always"); } attrs.setAttribute(OfficeNamespaces.TABLE_NS, "style-name", style.getStyleName()); // no need to copy the styles, this was done while deriving the @@ -1207,6 +1209,7 @@ { final XmlWriter xmlWriter = getXmlWriter(); xmlWriter.writeCloseTag(); + firstDetailState = DETAIL_SECTION_WAIT; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
