diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/editparts/ReportElementEditPart.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/editparts/ReportElementEditPart.java index 234b96432df..57fc1b44347 100644 --- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/editparts/ReportElementEditPart.java +++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/editparts/ReportElementEditPart.java @@ -35,6 +35,7 @@ import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editpolicies.ReportElementResizablePolicy; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.figures.IReportElementFigure; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.figures.ReportElementFigure; +import org.eclipse.birt.report.designer.internal.ui.editors.schematic.figures.TableFigure; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.handles.AbstractGuideHandle; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.handles.IGuideFeedBackHost; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.tools.ReportElementDragTracker; @@ -45,6 +46,7 @@ import org.eclipse.birt.report.designer.util.ColorManager; import org.eclipse.birt.report.designer.util.DEUtil; import org.eclipse.birt.report.designer.util.ImageManager; +import org.eclipse.birt.report.designer.util.MetricUtility; import org.eclipse.birt.report.engine.css.engine.value.css.CSSValueConstants; import org.eclipse.birt.report.model.api.DesignElementHandle; import org.eclipse.birt.report.model.api.MasterPageHandle; @@ -55,6 +57,7 @@ import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants; import org.eclipse.birt.report.model.api.metadata.DimensionValue; import org.eclipse.birt.report.model.api.util.ColorUtil; +import org.eclipse.birt.report.model.api.util.DimensionUtil; import org.eclipse.birt.report.model.api.util.URIUtil; import org.eclipse.birt.report.model.elements.interfaces.IStyleModel; import org.eclipse.draw2d.IFigure; @@ -690,17 +693,67 @@ protected void refreshBackgroundImage(DesignElementHandle handle) { // Should not be ExceptionHandler.handle(e), see SCR#73730 image = null; } - if (image == null) { figure.setImage(null); return; } - int dpi = getImageDPI(backGroundImage); + int dpi = getImageDPI(backGroundImage); if (figure instanceof ReportElementFigure) { ((ReportElementFigure) figure).setBackgroundImageDPI(dpi); + } else if (figure instanceof TableFigure) { + ((TableFigure) figure).setBackgroundImageDPI(dpi); + } + + int pxBackgroundHeight = 0; + int pxBackgroundWidth = 0; + double percentageHeight = 1d; + double percentageWidth = 1d; + + // calculate the background image height dimension + String propertyValue = handle.getStringProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT); + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + + if (propertyValue.endsWith("%")) { + percentageHeight = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundHeight = (DimensionValue) handle + .getProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT); + + if (propertyBackgroundHeight.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundHeight = (int) propertyBackgroundHeight.getMeasure(); + } else { + DimensionValue backgroundHeight = DimensionUtil.convertTo(propertyBackgroundHeight.getMeasure(), + propertyBackgroundHeight.getUnits(), DesignChoiceConstants.UNITS_IN); + pxBackgroundHeight = (int) MetricUtility.inchToPixel(backgroundHeight.getMeasure()); + } + } } - figure.setImage(image); + + // calculate the background image width dimension + propertyValue = handle.getStringProperty(IStyleModel.BACKGROUND_SIZE_WIDTH); + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + + if (propertyValue.endsWith("%")) { + percentageWidth = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundWidth = (DimensionValue) handle + .getProperty(IStyleModel.BACKGROUND_SIZE_WIDTH); + + if (propertyBackgroundWidth.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundWidth = (int) propertyBackgroundWidth.getMeasure(); + } else { + DimensionValue backgroundWidth = DimensionUtil.convertTo(propertyBackgroundWidth.getMeasure(), + propertyBackgroundWidth.getUnits(), DesignChoiceConstants.UNITS_IN); + pxBackgroundWidth = (int) MetricUtility.inchToPixel(backgroundWidth.getMeasure()); + } + } + } + figure.setImage(image, pxBackgroundHeight, pxBackgroundWidth, percentageHeight, percentageWidth); Object[] backGroundPosition = getBackgroundPosition(handle); int backGroundRepeat = getBackgroundRepeat(handle); @@ -954,6 +1007,11 @@ protected int getBackgroundRepeat(DesignElementHandle handle) { return getModelAdapter().getBackgroundRepeat(handle); } + protected int getBackgroundHeight(DesignElementHandle handle) { + return 0; +// return getModelAdapter().getBackgroundImageHeight(handle, getPreferredSize(), null); + } + protected boolean isFigureLeft(Request request) { if (!(request instanceof SelectionRequest)) { return true; diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/IReportElementFigure.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/IReportElementFigure.java index 9e7d8225934..866f62c8ff3 100644 --- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/IReportElementFigure.java +++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/IReportElementFigure.java @@ -72,6 +72,29 @@ public interface IReportElementFigure { */ void setImage(Image image); + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + */ + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth); + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + * @param percentageHeight percentage of height of the image to base 1.0 + * @param percentageWidth percentage of width of the image to base 1.0 + */ + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth, double percentageHeight, + double percentageWidth); + /** * Sets the margin of current figure. * diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/ReportElementFigure.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/ReportElementFigure.java index b7393eb3cbc..f6fb4afe589 100644 --- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/ReportElementFigure.java +++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/ReportElementFigure.java @@ -46,16 +46,32 @@ public class ReportElementFigure extends Figure implements IReportElementFigure, private Dimension size = new Dimension(); + private Dimension propertySize = new Dimension(); + + private double percentageHeight = 1; + + private double percentageWidth = 1; + private Rectangle clip; private static final Rectangle OLD_CLIP = new Rectangle(); private int backgroundImageDPI = 0; + /** + * Get the background image dpi + * + * @return get the background image dpi + */ public int getBackgroundImageDPI() { return backgroundImageDPI; } + /** + * Set the background image dpi + * + * @param backgroundImageDPI background image dpi + */ public void setBackgroundImageDPI(int backgroundImageDPI) { this.backgroundImageDPI = backgroundImageDPI; } @@ -100,6 +116,11 @@ public Image getImage() { return img; } + /** + * Set page clip + * + * @param clip rectangle to clip page + */ public void setPageClip(Rectangle clip) { this.clip = clip; } @@ -181,9 +202,9 @@ protected void paintFigure(Graphics graphics) { } } - ArrayList xyList = createImageList(x, y); + ArrayList xyList = createImageList(x, y); - Iterator iter = xyList.iterator(); + Iterator iter = xyList.iterator(); Dimension imageSize = new Rectangle(image.getBounds()).getSize(); while (iter.hasNext()) { Point point = (Point) iter.next(); @@ -202,10 +223,10 @@ protected void paintFigure(Graphics graphics) { * @param y the y-cordinator of the base image. * @return the list of all the images to be displayed. */ - private ArrayList createImageList(int x, int y) { + private ArrayList createImageList(int x, int y) { Rectangle area = getBounds(); - ArrayList yList = new ArrayList(); + ArrayList yList = new ArrayList(); if ((repeat & ImageConstants.REPEAT_Y) == 0) { yList.add(new Point(x, y)); @@ -223,11 +244,11 @@ private ArrayList createImageList(int x, int y) { } } - ArrayList xyList = new ArrayList(); + ArrayList xyList = new ArrayList(); - Iterator iter = yList.iterator(); + Iterator iter = yList.iterator(); while (iter.hasNext()) { - Point point = (Point) iter.next(); + Point point = iter.next(); if ((repeat & ImageConstants.REPEAT_X) == 0) { xyList.add(point); @@ -308,23 +329,99 @@ public void setRepeat(int flag) { */ @Override public void setImage(Image image) { - if (img == image) { + this.setImage(image, 0, 0); + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + */ + @Override + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth) { + this.setImage(image, 0, 0, 1, 1); + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + * @param percentageHeight percentage of height of the image to base 1.0 + * @param percentageWidth percentage of width of the image to base 1.0 + */ + @Override + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth, double percentageHeight, + double percentageWidth) { + if (img == image && propertySize.height == backGroundImageHeight && propertySize.width == backGroundImageWidth + && this.percentageHeight == percentageHeight && this.percentageWidth == percentageWidth) { return; } img = image; if (img != null) { - if (backgroundImageDPI > 0) { + propertySize.height = backGroundImageHeight; + propertySize.width = backGroundImageWidth; + this.percentageHeight = percentageHeight; + this.percentageWidth = percentageWidth; + + if (backgroundImageDPI > 0 && backGroundImageHeight <= 0 && backGroundImageWidth > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image width + inch = ((double) image.getBounds().width) / backgroundImageDPI; + int originalWidth = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageWidth / originalWidth; + + inch = ((double) image.getBounds().height) / backgroundImageDPI; + size.height = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.width = backGroundImageWidth; + + } else if (backgroundImageDPI > 0 && backGroundImageWidth <= 0 && backGroundImageHeight > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image height + inch = ((double) image.getBounds().height) / backgroundImageDPI; + int originalHeight = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageHeight / originalHeight; + + inch = ((double) image.getBounds().width) / backgroundImageDPI; + size.width = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.height = backGroundImageHeight; + + } else if (backgroundImageDPI > 0 && (backGroundImageHeight <= 0 && backGroundImageWidth <= 0)) { + double inch = ((double) image.getBounds().width) / backgroundImageDPI; size.width = (int) MetricUtility.inchToPixel(inch); inch = ((double) image.getBounds().height) / backgroundImageDPI; size.height = (int) MetricUtility.inchToPixel(inch); + + } else if (backGroundImageHeight > 0 && backGroundImageWidth > 0) { + + size.height = backGroundImageHeight; + size.width = backGroundImageWidth; + } else { size = new Rectangle(image.getBounds()).getSize(); } } else { size = new Dimension(); } + // auto scaling of percentage if one percentage is set and the image size is unset + if (percentageHeight != 1.0 && percentageWidth == 1.0 && backGroundImageWidth == 0) { + percentageWidth = percentageHeight; + } else if (percentageWidth != 1.0 && percentageHeight == 1.0 && backGroundImageHeight == 0) { + percentageHeight = percentageWidth; + } + size.height = (int) (size.height * percentageHeight); + size.width = (int) (size.width * percentageWidth); revalidate(); repaint(); } @@ -359,7 +456,7 @@ public void setMargin(Insets newMargin) { /** * Returns the margin of current figure. * - * @return + * @return margin of the element */ @Override public Insets getMargin() { @@ -399,7 +496,10 @@ public Dimension getFixMinimumSize(int w, int h) { } /** - * @param backGroundImageWidth + * Set the Background image size + * + * @param backGroundImageWidth width of the background image + * @param backGroundImageHeight height of background image */ public void setBackGroundImageSize(int backGroundImageWidth, int backGroundImageHeight) { diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/TableFigure.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/TableFigure.java index 98e3d162766..390d5676fdd 100644 --- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/TableFigure.java +++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/figures/TableFigure.java @@ -23,6 +23,7 @@ import org.eclipse.birt.report.designer.nls.Messages; import org.eclipse.birt.report.designer.ui.IReportGraphicConstants; import org.eclipse.birt.report.designer.ui.ReportPlatformUIImages; +import org.eclipse.birt.report.designer.util.MetricUtility; import org.eclipse.draw2d.FreeformFigure; import org.eclipse.draw2d.FreeformViewport; import org.eclipse.draw2d.Graphics; @@ -56,6 +57,14 @@ public class TableFigure extends FreeformViewport implements IReportElementFigur private Dimension size = new Dimension(); + private Dimension propertySize = new Dimension(); + + private double percentageHeight = 1; + + private double percentageWidth = 1; + + private int backgroundImageDPI = 0; + class TableViewportLayout extends ViewportLayout { @Override @@ -101,6 +110,24 @@ public void layout(IFigure figure) { } } + /** + * Get the background image dpi + * + * @return get the background image dpi + */ + public int getBackgroundImageDPI() { + return backgroundImageDPI; + } + + /** + * Set the background image dpi + * + * @param backgroundImageDPI background image dpi + */ + public void setBackgroundImageDPI(int backgroundImageDPI) { + this.backgroundImageDPI = backgroundImageDPI; + } + /** * Constructor */ @@ -192,12 +219,14 @@ protected void paintFigure(Graphics graphics) { } } - ArrayList xyList = createImageList(x, y); + ArrayList xyList = createImageList(x, y); - Iterator iter = xyList.iterator(); + Iterator iter = xyList.iterator(); + Dimension imageSize = new Rectangle(image.getBounds()).getSize(); while (iter.hasNext()) { - Point point = (Point) iter.next(); - graphics.drawImage(image, point); + Point point = iter.next(); + graphics.drawImage(image, 0, 0, imageSize.width, imageSize.height, point.x, point.y, size.width, + size.height); } xyList.clear(); } @@ -209,11 +238,11 @@ protected void paintFigure(Graphics graphics) { * @param y the y-cordinator of the base image. * @return the list of all the images to be displayed. */ - private ArrayList createImageList(int x, int y) { + private ArrayList createImageList(int x, int y) { // Rectangle area = getOriginalClientArea( ); Rectangle area = getBounds(); - ArrayList yList = new ArrayList(); + ArrayList yList = new ArrayList(); if ((repeat & ImageConstants.REPEAT_Y) == 0) { yList.add(new Point(x, y)); @@ -231,11 +260,11 @@ private ArrayList createImageList(int x, int y) { } } - ArrayList xyList = new ArrayList(); + ArrayList xyList = new ArrayList(); - Iterator iter = yList.iterator(); + Iterator iter = yList.iterator(); while (iter.hasNext()) { - Point point = (Point) iter.next(); + Point point = iter.next(); if ((repeat & ImageConstants.REPEAT_X) == 0) { xyList.add(point); @@ -363,16 +392,101 @@ public void setMargin(Insets newMargin) { */ @Override public void setImage(Image image) { - if (img == image) { + setImage(image, 0, 0); + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + */ + @Override + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth) { + this.setImage(image, 0, 0, 1, 1); + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be + * null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + * @param percentageHeight percentage of height of the image to base 1.0 + * @param percentageWidth percentage of width of the image to base 1.0 + */ + @Override + public void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth, double percentageHeight, + double percentageWidth) { + if (img == image && propertySize.height == backGroundImageHeight && propertySize.width == backGroundImageWidth + && this.percentageHeight == percentageHeight && this.percentageWidth == percentageWidth) { return; } img = image; if (img != null) { - size = new Rectangle(image.getBounds()).getSize(); + propertySize.height = backGroundImageHeight; + propertySize.width = backGroundImageWidth; + this.percentageHeight = percentageHeight; + this.percentageWidth = percentageWidth; + + if (backgroundImageDPI > 0 && backGroundImageHeight <= 0 && backGroundImageWidth > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image width + inch = ((double) image.getBounds().width) / backgroundImageDPI; + int originalWidth = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageWidth / originalWidth; + + inch = ((double) image.getBounds().height) / backgroundImageDPI; + size.height = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.width = backGroundImageWidth; + + } else if (backgroundImageDPI > 0 && backGroundImageWidth <= 0 && backGroundImageHeight > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image height + inch = ((double) image.getBounds().height) / backgroundImageDPI; + int originalHeight = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageHeight / originalHeight; + + inch = ((double) image.getBounds().width) / backgroundImageDPI; + size.width = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.height = backGroundImageHeight; + + } else if (backgroundImageDPI > 0 && (backGroundImageHeight <= 0 && backGroundImageWidth <= 0)) { + + double inch = ((double) image.getBounds().width) / backgroundImageDPI; + size.width = (int) MetricUtility.inchToPixel(inch); + + inch = ((double) image.getBounds().height) / backgroundImageDPI; + size.height = (int) MetricUtility.inchToPixel(inch); + + } else if (backGroundImageHeight > 0 && backGroundImageWidth > 0) { + + size.height = backGroundImageHeight; + size.width = backGroundImageWidth; + + } else { + size = new Rectangle(image.getBounds()).getSize(); + } } else { size = new Dimension(); } + // auto scaling of percentage if one percentage is set and the image size is unset + if (percentageHeight != 1.0 && percentageWidth == 1.0 && backGroundImageWidth == 0) { + percentageWidth = percentageHeight; + } else if (percentageWidth != 1.0 && percentageHeight == 1.0 && backGroundImageHeight == 0) { + percentageHeight = percentageWidth; + } + size.height = (int) (size.height * percentageHeight); + size.width = (int) (size.width * percentageWidth); revalidate(); repaint(); } + } diff --git a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/layer/TableGridLayer.java b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/layer/TableGridLayer.java index beef475ca9b..9a9fb876a4a 100644 --- a/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/layer/TableGridLayer.java +++ b/UI/org.eclipse.birt.report.designer.ui/src/org/eclipse/birt/report/designer/internal/ui/editors/schematic/layer/TableGridLayer.java @@ -14,6 +14,9 @@ package org.eclipse.birt.report.designer.internal.ui.editors.schematic.layer; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -26,13 +29,18 @@ import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.TableEditPart; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.editparts.TableUtil; import org.eclipse.birt.report.designer.internal.ui.editors.schematic.figures.ImageConstants; +import org.eclipse.birt.report.designer.internal.ui.util.ExceptionHandler; +import org.eclipse.birt.report.designer.internal.ui.util.UIUtil; import org.eclipse.birt.report.designer.util.ColorManager; import org.eclipse.birt.report.designer.util.ImageManager; +import org.eclipse.birt.report.designer.util.MetricUtility; import org.eclipse.birt.report.model.api.ColumnHandle; import org.eclipse.birt.report.model.api.DesignElementHandle; import org.eclipse.birt.report.model.api.RowHandle; import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants; import org.eclipse.birt.report.model.api.metadata.DimensionValue; +import org.eclipse.birt.report.model.api.util.DimensionUtil; +import org.eclipse.birt.report.model.api.util.URIUtil; import org.eclipse.birt.report.model.elements.interfaces.IStyleModel; import org.eclipse.draw2d.Graphics; import org.eclipse.draw2d.PositionConstants; @@ -51,6 +59,18 @@ public class TableGridLayer extends GridLayer { private TableEditPart source; + private Image img; + + private Dimension size = new Dimension(); + + private Dimension propertySize = new Dimension(); + + private double percentageHeight = 1; + + private double percentageWidth = 1; + + private int backgroundImageDPI = 0; + /** * Constructor * @@ -151,6 +171,61 @@ private void drawBackgroudImage(DesignElementHandle handle, Graphics g, int x, i } if (image != null) { + + this.backgroundImageDPI = getImageDpi(backGroundImage); + + int pxBackgroundHeight = 0; + int pxBackgroundWidth = 0; + double percentageHeight = 1d; + double percentageWidth = 1d; + + // calculate the background image height dimension + String propertyValue = handle.getStringProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT); + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + + if (propertyValue.endsWith("%")) { + percentageHeight = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundHeight = (DimensionValue) handle + .getProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT); + + if (propertyBackgroundHeight.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundHeight = (int) propertyBackgroundHeight.getMeasure(); + } else { + DimensionValue backgroundHeight = DimensionUtil.convertTo( + propertyBackgroundHeight.getMeasure(), propertyBackgroundHeight.getUnits(), + DesignChoiceConstants.UNITS_IN); + pxBackgroundHeight = (int) MetricUtility.inchToPixel(backgroundHeight.getMeasure()); + } + } + } + + // calculate the background image width dimension + propertyValue = handle.getStringProperty(IStyleModel.BACKGROUND_SIZE_WIDTH); + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + + if (propertyValue.endsWith("%")) { + percentageWidth = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundWidth = (DimensionValue) handle + .getProperty(IStyleModel.BACKGROUND_SIZE_WIDTH); + + if (propertyBackgroundWidth.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundWidth = (int) propertyBackgroundWidth.getMeasure(); + } else { + DimensionValue backgroundWidth = DimensionUtil.convertTo( + propertyBackgroundWidth.getMeasure(), propertyBackgroundWidth.getUnits(), + DesignChoiceConstants.UNITS_IN); + pxBackgroundWidth = (int) MetricUtility.inchToPixel(backgroundWidth.getMeasure()); + } + } + } + this.setImage(image, pxBackgroundHeight, pxBackgroundWidth, percentageHeight, percentageWidth); + Rectangle rectangle = new Rectangle(x, y, width, height); Object[] backGroundPosition = getBackgroundPosition(handle); @@ -185,7 +260,7 @@ private void drawBackgroudImage(DesignElementHandle handle, Graphics g, int x, i } int tx, ty; - Dimension size = new Rectangle(image.getBounds()).getSize(); + Dimension size = this.size; // new Rectangle(image.getBounds()).getSize(); // Calculates X if (position != null && position.x != -1) { @@ -227,9 +302,12 @@ private void drawBackgroudImage(DesignElementHandle handle, Graphics g, int x, i Rectangle rect = new Rectangle(); g.getClip(rect); g.setClip(rectangle); + + Dimension imageSize = new Rectangle(image.getBounds()).getSize(); while (iter.hasNext()) { Point point = iter.next(); - g.drawImage(image, point); + g.drawImage(image, 0, 0, imageSize.width, imageSize.height, point.x, point.y, size.width, + size.height); } g.setClip(rect); xyList.clear(); @@ -237,6 +315,119 @@ private void drawBackgroudImage(DesignElementHandle handle, Graphics g, int x, i } } + private int getImageDpi(String backGroundImage) { + if (!(this.source.getTableAdapter().getModuleHandle() != null)) { + return 0; + } + int dpi = 96; + DesignElementHandle model = this.source.getTableAdapter().getModuleHandle(); + + InputStream in = null; + URL temp = null; + try { + if (URIUtil.isValidResourcePath(backGroundImage)) { + temp = ImageManager.getInstance().generateURL(model.getModuleHandle(), + URIUtil.getLocalPath(backGroundImage)); + + } else { + temp = ImageManager.getInstance().generateURL(model.getModuleHandle(), backGroundImage); + } + if (temp != null) { + in = temp.openStream(); + } + + } catch (IOException e) { + in = null; + } + + dpi = UIUtil.getImageResolution(in)[0]; + if (in != null) { + try { + in.close(); + } catch (IOException e) { + ExceptionHandler.handle(e); + } + } + return dpi; + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param image The Image to be displayed. It can be null. + * @param backGroundImageHeight height of the image + * @param backGroundImageWidth width of the image + */ + private void setImage(Image image, int backGroundImageHeight, int backGroundImageWidth, double percentageHeight, + double percentageWidth) { + if (img == image && propertySize.height == backGroundImageHeight && propertySize.width == backGroundImageWidth + && this.percentageHeight == percentageHeight && this.percentageWidth == percentageWidth) { + return; + } + img = image; + if (img != null) { + propertySize.height = backGroundImageHeight; + propertySize.width = backGroundImageWidth; + this.percentageHeight = percentageHeight; + this.percentageWidth = percentageWidth; + + if (backgroundImageDPI > 0 && backGroundImageHeight <= 0 && backGroundImageWidth > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image width + inch = ((double) image.getBounds().width) / backgroundImageDPI; + int originalWidth = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageWidth / originalWidth; + + inch = ((double) image.getBounds().height) / backgroundImageDPI; + size.height = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.width = backGroundImageWidth; + + } else if (backgroundImageDPI > 0 && backGroundImageWidth <= 0 && backGroundImageHeight > 0) { + + double inch = 1d; + + // scaling factor of correct image relation based on original image height + inch = ((double) image.getBounds().height) / backgroundImageDPI; + int originalHeight = (int) MetricUtility.inchToPixel(inch); + double scaleFactor = (double) backGroundImageHeight / originalHeight; + + inch = ((double) image.getBounds().width) / backgroundImageDPI; + size.width = (int) (MetricUtility.inchToPixel(inch) * scaleFactor); + size.height = backGroundImageHeight; + + } else if (backgroundImageDPI > 0 && (backGroundImageHeight <= 0 && backGroundImageWidth <= 0)) { + + double inch = ((double) image.getBounds().width) / backgroundImageDPI; + size.width = (int) MetricUtility.inchToPixel(inch); + + inch = ((double) image.getBounds().height) / backgroundImageDPI; + size.height = (int) MetricUtility.inchToPixel(inch); + + } else if (backGroundImageHeight > 0 && backGroundImageWidth > 0) { + + size.height = backGroundImageHeight; + size.width = backGroundImageWidth; + + } else { + size = new Rectangle(image.getBounds()).getSize(); + } + } else { + size = new Dimension(); + } + // auto scaling of percentage if one percentage is set and the image size is unset + if (percentageHeight != 1.0 && percentageWidth == 1.0 && backGroundImageWidth == 0) { + percentageWidth = percentageHeight; + } else if (percentageWidth != 1.0 && percentageHeight == 1.0 && backGroundImageHeight == 0) { + percentageHeight = percentageWidth; + } + size.height = (int) (size.height * percentageHeight); + size.width = (int) (size.width * percentageWidth); + revalidate(); + repaint(); + } + /** * Create the list of all the images to be displayed. * diff --git a/build/org.eclipse.birt.target/BIRT Engine Test.launch b/build/org.eclipse.birt.target/BIRT Engine Test.launch new file mode 100644 index 00000000000..f71c4030c28 --- /dev/null +++ b/build/org.eclipse.birt.target/BIRT Engine Test.launch @@ -0,0 +1,953 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.birt.target/BIRT Model Test (Engine).launch b/build/org.eclipse.birt.target/BIRT Model Test (Engine).launch new file mode 100644 index 00000000000..e99aed74553 --- /dev/null +++ b/build/org.eclipse.birt.target/BIRT Model Test (Engine).launch @@ -0,0 +1,953 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/org.eclipse.birt.target/BIRT Model Test.launch b/build/org.eclipse.birt.target/BIRT Model Test.launch index 6a638915ec6..66d3ea483f4 100644 --- a/build/org.eclipse.birt.target/BIRT Model Test.launch +++ b/build/org.eclipse.birt.target/BIRT Model Test.launch @@ -693,6 +693,7 @@ + diff --git a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/AttributeBuilder.java b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/AttributeBuilder.java index 27b2007a9f0..2f93899eae4 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/AttributeBuilder.java +++ b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/AttributeBuilder.java @@ -20,6 +20,8 @@ import org.eclipse.birt.report.engine.css.engine.value.css.CSSValueConstants; import org.eclipse.birt.report.engine.emitter.HTMLTags; import org.eclipse.birt.report.engine.ir.DimensionType; +import org.eclipse.birt.report.engine.nLayout.area.style.BackgroundImageInfo; +import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants; import org.w3c.dom.css.CSSValue; //FIXME: code review: We should list all the properties according the CSS. @@ -100,22 +102,76 @@ public static void buildVisual(StringBuffer styleBuffer, IStyle style) { * @param style The style object. * @param emitter The HTMLReportEmitter object which provides * resource manager and hyperlink builder objects. + * @param parentSize The size of the parent container */ - public static void buildBackground(StringBuffer styleBuffer, IStyle style, HTMLReportEmitter emitter) { + public static void buildBackground(StringBuffer styleBuffer, IStyle style, HTMLReportEmitter emitter, + DimensionType[] parentSize) { buildProperty(styleBuffer, HTMLTags.ATTR_BACKGROUND_COLOR, style.getBackgroundColor()); String image = style.getBackgroundImage(); if (image == null || "none".equalsIgnoreCase(image)) //$NON-NLS-1$ { + if (style.getBackgroundHeight() != null || style.getBackgroundWidth() != null) { + addPropName(styleBuffer, HTMLTags.ATTR_BACKGROUND_SIZE); + + if (style.getBackgroundWidth() != null && style.getBackgroundHeight() != null) { + addPropValue(styleBuffer, "100%"); + addPropValue(styleBuffer, "auto"); + addPropValue(styleBuffer, "auto"); + } else { + if (style.getBackgroundWidth() != null) { + addPropValue(styleBuffer, style.getBackgroundWidth()); + } else { + addPropValue(styleBuffer, "auto"); + } + if (style.getBackgroundHeight() != null) { + addPropValue(styleBuffer, style.getBackgroundHeight()); + } else { + addPropValue(styleBuffer, "auto"); + } + } + styleBuffer.append(';'); + } return; } + BackgroundImageInfo backgroundImage = emitter.handleStyleImage(image, true, style); - image = emitter.handleStyleImage(image, true, style); + image = backgroundImage.getUri(); if (image != null && image.length() > 0) { buildURLProperty(styleBuffer, HTMLTags.ATTR_BACKGROUND_IMAGE, image); buildProperty(styleBuffer, HTMLTags.ATTR_BACKGROUND_REPEAT, style.getBackgroundRepeat()); buildProperty(styleBuffer, HTMLTags.ATTR_BACKGROUND_ATTACHEMNT, style.getBackgroundAttachment()); + DimensionType height = null; + DimensionType width = null; + if (parentSize != null && parentSize.length == 2) { + height = parentSize[0]; + width = parentSize[1]; + } + addPropName(styleBuffer, HTMLTags.ATTR_BACKGROUND_SIZE); + + String h = backgroundImage.getHeight() + "px"; + String w = backgroundImage.getWidth() + "px"; + String propertyValue = style.getPropertyValue(CSSConstants.CSS_BACKGROUND_HEIGHT_PROPERTY); + String propertyValue2 = style.getPropertyValue(CSSConstants.CSS_BACKGROUND_WIDTH_PROPERTY); + if (propertyValue != null && (DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + || DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue))) { + if (DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + h = "auto"; + if (width != null) { + w = width.toString(); + } + } else if (DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue)) { + if (height != null) { + h = height.toString(); + } + w = "auto"; + } + } + addPropValue(styleBuffer, w); + addPropValue(styleBuffer, h); + styleBuffer.append(';'); + String x = style.getBackgroundPositionX(); String y = style.getBackgroundPositionY(); if (x != null || y != null) { diff --git a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLEmitter.java b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLEmitter.java index 41f00a61d78..a5afaa8b3da 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLEmitter.java +++ b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLEmitter.java @@ -1,12 +1,11 @@ /******************************************************************************* * Copyright (c) 2004, 2007 Actuate Corporation. - * + * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0/. - * + * * SPDX-License-Identifier: EPL-2.0 - * * * Contributors: * Actuate Corporation - initial API and implementation @@ -124,7 +123,8 @@ public void buildPageStyle(IPageContent page, StringBuffer styleBuffer, boolean // The method getStyle( ) will nevel return a null value; IStyle style = page.getStyle(); if (!needOutputBackgroundSize) { - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + DimensionType[] pageSize = { page.getPageHeight(), page.getPageWidth() }; + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, pageSize); } else { AttributeBuilder.buildBackgroundColor(styleBuffer, style, reportEmitter); } diff --git a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLPerformanceOptimize.java b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLPerformanceOptimize.java index a5233be6c69..0f8e4a9f629 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLPerformanceOptimize.java +++ b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLPerformanceOptimize.java @@ -23,6 +23,8 @@ import org.eclipse.birt.report.engine.content.IStyle; import org.eclipse.birt.report.engine.content.ITableContent; import org.eclipse.birt.report.engine.content.ITextContent; +import org.eclipse.birt.report.engine.css.engine.StyleConstants; +import org.eclipse.birt.report.engine.css.engine.value.css.CSSValueConstants; import org.eclipse.birt.report.engine.emitter.HTMLTags; import org.eclipse.birt.report.engine.emitter.HTMLWriter; import org.eclipse.birt.report.engine.emitter.html.util.HTMLEmitterUtil; @@ -79,7 +81,7 @@ public void buildStyle(StringBuffer styleBuffer, IStyle style) { AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, null); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -226,9 +228,10 @@ public void buildTableStyle(ITableContent table, StringBuffer styleBuffer) { return; } + DimensionType[] tableSize = { table.getHeight(), table.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, tableSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -267,9 +270,10 @@ public void buildColumnStyle(IColumn column, StringBuffer styleBuffer) { return; } + DimensionType[] columnSize = { null, column.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, columnSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -290,12 +294,12 @@ public void handleColumnAlign(IColumn column) { public void buildRowStyle(IRowContent row, StringBuffer styleBuffer) { buildSize(styleBuffer, HTMLTags.ATTR_HEIGHT, row.getHeight()); // $NON-NLS-1$ - // The method getStyle( ) will nevel return a null value; + // The method getStyle( ) will never return a null value; IStyle style = row.getStyle(); // output the none value of the display - CSSValue display = style.getProperty(IStyle.STYLE_DISPLAY); - if (IStyle.NONE_VALUE == display) { + CSSValue display = style.getProperty(StyleConstants.STYLE_DISPLAY); + if (CSSValueConstants.NONE_VALUE == display) { styleBuffer.append(" display: none;"); } @@ -304,9 +308,10 @@ public void buildRowStyle(IRowContent row, StringBuffer styleBuffer) { return; } + DimensionType[] rowSize = { row.getHeight(), row.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, rowSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -367,6 +372,7 @@ public void buildCellStyle(ICellContent cell, StringBuffer styleBuffer, boolean return; } + DimensionType[] cellSize = { cell.getHeight(), cell.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildMargins(styleBuffer, style); if (fixedCellHeight) { @@ -376,7 +382,7 @@ public void buildCellStyle(ICellContent cell, StringBuffer styleBuffer, boolean AttributeBuilder.buildPaddings(styleBuffer, style); } AttributeBuilder.buildBorders(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, cellSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -422,9 +428,10 @@ public void buildContainerStyle(IContainerContent container, StringBuffer styleB return; } + DimensionType[] containerSize = { container.getHeight(), container.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, containerSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -474,9 +481,10 @@ public void buildTextStyle(ITextContent text, StringBuffer styleBuffer, int disp return; } + DimensionType[] textSize = { text.getHeight(), text.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, textSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -511,9 +519,10 @@ public void buildForeignStyle(IForeignContent foreign, StringBuffer styleBuffer, return; } + DimensionType[] foreignSize = { foreign.getHeight(), foreign.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, foreignSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); @@ -547,9 +556,10 @@ public void buildImageStyle(IImageContent image, StringBuffer styleBuffer, int d return; } + DimensionType[] imageSize = { image.getHeight(), image.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, imageSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildTextDecoration(styleBuffer, style); diff --git a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLReportEmitter.java b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLReportEmitter.java index eff08648f71..f1a5b84a33c 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLReportEmitter.java +++ b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLReportEmitter.java @@ -1528,7 +1528,7 @@ private void startBackgroundContainer(IStyle style, DimensionType pageWidth, Dim StringBuffer sb = new StringBuffer(); sb.append("width:").append(pageWidth).append(";"); sb.append("height:").append(pageHeight).append(";"); - AttributeBuilder.buildBackground(sb, style, this); + AttributeBuilder.buildBackground(sb, style, this, null); sb.append("background-size:").append(backgroundWidth).append(" ").append(backgroundHeight).append(";"); writer.attribute(HTMLTags.ATTR_STYLE, sb.toString()); } @@ -2651,7 +2651,7 @@ public void startNode(Node node, HashMap cssStyles) { if (attrValue != null) { if ("img".equalsIgnoreCase(nodeName) && "src".equalsIgnoreCase(attrName)) { - String attrValueTrue = handleStyleImage(attrValue); + String attrValueTrue = handleStyleImage(attrValue).getUri(); if (attrValueTrue != null) { attrValue = attrValueTrue; } @@ -2675,7 +2675,7 @@ public void startNode(Node node, HashMap cssStyles) { buffer.append(key); buffer.append(":"); if ("background-image".equalsIgnoreCase(key)) { - String valueTrue = handleStyleImage(value, true); + String valueTrue = handleStyleImage(value, true).getUri(); if (valueTrue != null) { value = valueTrue; } @@ -3228,7 +3228,7 @@ protected String validate(IHyperlinkAction action) { * @param uri uri in style image * @return Return the image URI */ - public String handleStyleImage(String uri) { + public BackgroundImageInfo handleStyleImage(String uri) { return handleStyleImage(uri, false, null); } @@ -3239,7 +3239,7 @@ public String handleStyleImage(String uri) { * @param isBackground Is this image a used for a background? * @return Return the image URI */ - public String handleStyleImage(String uri, boolean isBackground) { + public BackgroundImageInfo handleStyleImage(String uri, boolean isBackground) { return handleStyleImage(uri, isBackground, null); } @@ -3250,7 +3250,7 @@ public String handleStyleImage(String uri, boolean isBackground) { * @param isBackground Is this image a used for a background? * @return Return the image URI */ - public String handleStyleImage(IStyle style, boolean isBackground) { + public BackgroundImageInfo handleStyleImage(IStyle style, boolean isBackground) { return handleStyleImage(null, isBackground, style); } @@ -3261,34 +3261,35 @@ public String handleStyleImage(IStyle style, boolean isBackground) { /** * Handle the style of image * - * @param uri uri in style image + * @param uri URI in style image * @param isBackground Is this image a used for a background? * @param imageStyle Style of the image * @return Return the image URI */ - public String handleStyleImage(String uri, boolean isBackground, IStyle imageStyle) { + public BackgroundImageInfo handleStyleImage(String uri, boolean isBackground, IStyle imageStyle) { ReportDesignHandle design = (ReportDesignHandle) runnable.getDesignHandle(); URL url = design.findResource(uri, IResourceLocator.IMAGE, reportContext.getAppContext()); String fileExtension = null; - Module module = null; + Module module = design.getModule(); BackgroundImageInfo backgroundImage = null; if (isBackground && imageStyle != null) { - module = design.getModule(); ResourceLocatorWrapper rl = null; ExecutionContext exeContext = ((ReportContent) this.report).getExecutionContext(); if (exeContext != null) { rl = exeContext.getResourceLocator(); } - String uriString = EmitterUtil.getBackgroundImageUrl(imageStyle, design, this.report.getReportContext() == null ? null : this.report.getReportContext().getAppContext()); backgroundImage = new BackgroundImageInfo(uriString, - imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl, module, - imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, module, imageStyle.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(imageStyle); if (backgroundImage.getSourceType().equalsIgnoreCase(CSSConstants.CSS_EMBED_VALUE)) { uri = backgroundImage.getDataUrl(); @@ -3300,7 +3301,7 @@ public String handleStyleImage(String uri, boolean isBackground, IStyle imageSty fileExtension = uri.substring(uri.lastIndexOf(".") + 1); } if (url == null) { - return uri; + return backgroundImage; } uri = url.toExternalForm(); Image image = null; @@ -3343,8 +3344,9 @@ public String handleStyleImage(String uri, boolean isBackground, IStyle imageSty default: assert (false); } + backgroundImage.setUri(imgUri); } - return imgUri; + return backgroundImage; } /** diff --git a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLVisionOptimize.java b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLVisionOptimize.java index 879b0504ddd..995fb29e2dc 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLVisionOptimize.java +++ b/engine/org.eclipse.birt.report.engine.emitter.html/src/org/eclipse/birt/report/engine/emitter/html/HTMLVisionOptimize.java @@ -95,7 +95,7 @@ public void buildStyle(StringBuffer styleBuffer, IStyle style) { AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, null); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); AttributeBuilder.buildSize(styleBuffer, style); @@ -220,9 +220,10 @@ public void buildTableStyle(ITableContent table, StringBuffer styleBuffer) { return; } + DimensionType[] tableSize = { table.getHeight(), table.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, tableSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); } @@ -275,8 +276,9 @@ public void buildRowStyle(IRowContent row, StringBuffer styleBuffer) { return; } + DimensionType[] rowSize = { row.getHeight(), row.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, rowSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); } @@ -382,13 +384,14 @@ public void buildCellStyle(ICellContent cell, StringBuffer styleBuffer, boolean // build the cell's border buildCellBorder(cell, styleBuffer); + DimensionType[] cellSize = { cell.getHeight(), cell.getWidth() }; if (null != style) { - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, cellSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); } - AttributeBuilder.buildBackground(styleBuffer, cellMergedStyle, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, cellMergedStyle, reportEmitter, cellSize); AttributeBuilder.buildText(styleBuffer, cellMergedStyle); AttributeBuilder.buildVisual(styleBuffer, cellMergedStyle); } @@ -437,9 +440,10 @@ public void buildContainerStyle(IContainerContent container, StringBuffer styleB return; } + DimensionType[] containerSize = { container.getHeight(), container.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, containerSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); } @@ -493,9 +497,10 @@ public void buildTextStyle(ITextContent text, StringBuffer styleBuffer, int disp return; } + DimensionType[] textSize = { text.getHeight(), text.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, textSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); } @@ -527,9 +532,10 @@ public void buildForeignStyle(IForeignContent foreign, StringBuffer styleBuffer, return; } + DimensionType[] foreignSize = { foreign.getHeight(), foreign.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, foreignSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); @@ -574,9 +580,10 @@ public void buildImageStyle(IImageContent image, StringBuffer styleBuffer, int d return; } + DimensionType[] imageSize = { image.getHeight(), image.getWidth() }; AttributeBuilder.buildFont(styleBuffer, style); AttributeBuilder.buildBox(styleBuffer, style); - AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter); + AttributeBuilder.buildBackground(styleBuffer, style, reportEmitter, imageSize); AttributeBuilder.buildText(styleBuffer, style); AttributeBuilder.buildVisual(styleBuffer, style); diff --git a/engine/org.eclipse.birt.report.engine.emitter.pdf/src/org/eclipse/birt/report/engine/emitter/pdf/PDFPage.java b/engine/org.eclipse.birt.report.engine.emitter.pdf/src/org/eclipse/birt/report/engine/emitter/pdf/PDFPage.java index f60b8167408..24a65f60d62 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.pdf/src/org/eclipse/birt/report/engine/emitter/pdf/PDFPage.java +++ b/engine/org.eclipse.birt.report.engine.emitter.pdf/src/org/eclipse/birt/report/engine/emitter/pdf/PDFPage.java @@ -184,8 +184,6 @@ protected void drawBackgroundImage(float x, float y, float width, float height, boolean xExtended = (repeat & AreaConstants.REPEAT_X) == AreaConstants.REPEAT_X; boolean yExtended = (repeat & AreaConstants.REPEAT_Y) == AreaConstants.REPEAT_Y; - imageWidth = image.getWidth(); - imageHeight = image.getHeight(); float originalX = offsetX; float originalY = offsetY; diff --git a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java index f893b652e6a..1853fc0a409 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java +++ b/engine/org.eclipse.birt.report.engine.emitter.pptx/src/org/eclipse/birt/report/engine/emitter/pptx/TableWriter.java @@ -600,6 +600,7 @@ protected void drawCellBox(CellArea cell) { drawCellAntidiagonal(cell); BoxStyle style = cell.getBoxStyle(); + IStyle contentStyle = cell.getContent().getStyle(); Color backgroundcolor = style.getBackgroundColor(); BackgroundImageInfo bgimginfo = style.getBackgroundImage(); @@ -615,17 +616,19 @@ protected void drawCellBox(CellArea cell) { } } String imageRelationship = canvas.getImageRelationship(bgimginfo); - + if (bgimginfo != null) { + bgimginfo.setImageSize(contentStyle); + } if (imageRelationship != null) { float offsetY = 0; float offsetX = 0; int repeatmode = bgimginfo.getRepeatedMode(); if (repeatmode == BackgroundImageInfo.NO_REPEAT) { - int imgheight = PPTXUtil.pixelToEmu((int) bgimginfo.getImageInstance().getHeight(), - bgimginfo.getImageInstance().getDpiY()); - int imgwidth = PPTXUtil.pixelToEmu((int) bgimginfo.getImageInstance().getWidth(), - bgimginfo.getImageInstance().getDpiX()); + + int imgheight = PPTXUtil.convertToEnums(bgimginfo.getHeightMetricPt()); + int imgwidth = PPTXUtil.convertToEnums(bgimginfo.getWidthMetricPt()); + int cellheight = PPTXUtil.convertToEnums(canvas.getScaledValue(cell.getHeight())); int cellwidth = PPTXUtil.convertToEnums(canvas.getScaledValue(cell.getWidth())); offsetY = PPTXUtil.parsePercentageOffset(cellheight, imgheight); diff --git a/engine/org.eclipse.birt.report.engine/META-INF/MANIFEST.MF b/engine/org.eclipse.birt.report.engine/META-INF/MANIFEST.MF index bf8c0ccf6eb..b936795acbe 100644 --- a/engine/org.eclipse.birt.report.engine/META-INF/MANIFEST.MF +++ b/engine/org.eclipse.birt.report.engine/META-INF/MANIFEST.MF @@ -92,4 +92,6 @@ Import-Package: org.apache.batik.css.engine;version="1.14.0", org.apache.batik.css.parser;version="1.14.0", org.apache.batik.i18n;version="1.14.0", org.apache.batik.transcoder;version="1.14.0", - org.apache.batik.transcoder.image;version="1.14.0" + org.apache.batik.transcoder.image;version="1.14.0", + org.eclipse.birt.report.designer.util, + org.eclipse.draw2d.geometry diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/TOCStyle.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/TOCStyle.java index 9cd055821c5..985e61be7ed 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/TOCStyle.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/TOCStyle.java @@ -50,6 +50,14 @@ public class TOCStyle implements IScriptStyle, Serializable { * Style property: background-image-type */ public static final String BACKGROUND_IMAGE_TYPE = "background-image-type"; + /** + * Style property: background image height + */ + public static final String BACKGROUND_SIZE_HEIGHT = "background-size-height"; + /** + * Style property: background image width + */ + public static final String BACKGROUND_SIZE_WIDTH = "background-size-width"; /** * Style property: background-position-x */ @@ -378,6 +386,22 @@ public String getBackgroundRepeat() { return properties.get(BACKGROUND_REPEAT); } + /** + * Get the background image height + */ + @Override + public String getBackgroundHeight() { + return properties.get(BACKGROUND_SIZE_HEIGHT); + } + + /** + * Get the background image height + */ + @Override + public String getBackgroundWidth() { + return properties.get(BACKGROUND_SIZE_WIDTH); + } + /** * Get the bottom border color */ @@ -864,6 +888,22 @@ public void setBackgroundRepeat(String repeat) { setProperty(BACKGROUND_REPEAT, repeat); } + /** + * Set the background image height + */ + @Override + public void setBackgroundHeight(String height) { + setProperty(BACKGROUND_SIZE_HEIGHT, height); + } + + /** + * Set the background image height + */ + @Override + public void setBackgroundWidth(String width) { + setProperty(BACKGROUND_SIZE_WIDTH, width); + } + /** * Set the bottom border color */ diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/element/IScriptStyleDesign.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/element/IScriptStyleDesign.java index c5e65792e14..73502ee5cc0 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/element/IScriptStyleDesign.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/element/IScriptStyleDesign.java @@ -80,6 +80,36 @@ public interface IScriptStyleDesign { String getBackgroundRepeat(); + /** + * Set the background height of the background image. + * + * @param value the new background image height + * @throws ScriptException if the property is locked + */ + void setBackgroundHeight(String value) throws ScriptException; + + /** + * Returns the height of the background image. + * + * @return the background image height + */ + String getBackgroundHeight(); + + /** + * Set the background width of the background image. + * + * @param value the new background image width + * @throws ScriptException if the property is locked + */ + void setBackgroundWidth(String value) throws ScriptException; + + /** + * Returns the width of the background image. + * + * @return the background image width + */ + String getBackgroundWidth(); + /** * Sets the repeat pattern for a background image. The input value is defined in * DesignChoiceConstants and can be one of: diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/IScriptStyle.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/IScriptStyle.java index 87432a451b1..978090ff447 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/IScriptStyle.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/api/script/instance/IScriptStyle.java @@ -282,6 +282,36 @@ public interface IScriptStyle { */ void setBackgroundRepeat(String repeat); + /** + * Set the background height of the background image. + * + * @param value the new background image height + * @throws ScriptException if the property is locked + */ + void setBackgroundHeight(String value) throws ScriptException; + + /** + * Returns the height of the background image. + * + * @return the background image height + */ + String getBackgroundHeight(); + + /** + * Set the background width of the background image. + * + * @param value the new background image width + * @throws ScriptException if the property is locked + */ + void setBackgroundWidth(String value) throws ScriptException; + + /** + * Returns the width of the background image. + * + * @return the background image width + */ + String getBackgroundWidth(); + /** * Get the bottom border color * diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/IStyle.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/IStyle.java index 5e9ca2f5783..50736155fdf 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/IStyle.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/IStyle.java @@ -353,6 +353,20 @@ public interface IStyle extends CSSStyleDeclaration, StyleConstants, CSS2Propert void setBackgroundImageType(String imageType); /** + * Set the image background height + * + * @param background image height + */ + void setBackgroundHeight(String height); + + /** + * Set the image background width + * + * @param background image width + */ + void setBackgroundWidth(String width); + + /** * Get the diagonal line number * * @return Return the diagonal line number diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/css/dom/AbstractStyle.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/css/dom/AbstractStyle.java index eab43252e1f..f7be93b8739 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/css/dom/AbstractStyle.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/css/dom/AbstractStyle.java @@ -547,6 +547,16 @@ public void setBackgroundRepeat(String backgroundRepeat) { setCssText(STYLE_BACKGROUND_REPEAT, backgroundRepeat); } + @Override + public void setBackgroundHeight(String height) { + setCssText(STYLE_BACKGROUND_HEIGHT, height); + } + + @Override + public void setBackgroundWidth(String width) { + setCssText(STYLE_BACKGROUND_WIDTH, width); + } + /** * @param borderBottomColor The borderBottomColor to set. */ diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/HTMLTags.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/HTMLTags.java index 339725d849a..800d7e82536 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/HTMLTags.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/HTMLTags.java @@ -49,6 +49,7 @@ public class HTMLTags { public static final String ATTR_BACKGROUND_REPEAT = "background-repeat"; //$NON-NLS-1$ public static final String ATTR_BACKGROUND_ATTACHEMNT = "background-attachment"; //$NON-NLS-1$ public static final String ATTR_BACKGROUND_POSITION = "background-position"; //$NON-NLS-1$ + public static final String ATTR_BACKGROUND_SIZE = "background-size"; //$NON-NLS-1$ public static final String ATTR_PADDING = "padding"; //$NON-NLS-1$ public static final String ATTR_PADDING_TOP = "padding-top"; //$NON-NLS-1$ diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/emitter/PageDeviceRender.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/emitter/PageDeviceRender.java index 1682ffed5f8..add17b808a9 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/emitter/PageDeviceRender.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/emitter/PageDeviceRender.java @@ -595,7 +595,7 @@ private void endClip() { */ public void drawBackgroundImage(BackgroundImageInfo bi, int startX, int startY, int width, int height) { try { - pageGraphic.drawBackgroundImage(startX, startY, width, height, bi.getWidth(), bi.getHeight(), + pageGraphic.drawBackgroundImage(startX, startY, width, height, bi.getWidthMetricPt(), bi.getHeightMetricPt(), bi.getRepeatedMode(), bi.getUrl(), bi.getImageData(), getScaledValue(bi.getXOffset()), getScaledValue(bi.getYOffset())); } catch (Exception e) { diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/CellArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/CellArea.java index 7456abb6bc9..f5ff394980e 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/CellArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/CellArea.java @@ -266,8 +266,12 @@ protected void buildProperties(IContent content, LayoutContext context) { rl = exeContext.getResourceLocator(); } BackgroundImageInfo backgroundImage = new BackgroundImageInfo(getImageUrl(url), - style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl, this.getCurrentModule(), - style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, this.getCurrentModule(), style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(style); + boxStyle.setBackgroundImage(backgroundImage); } localProperties = new LocalProperties(); diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java index eb9389eb4d8..10c1d617796 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/ContainerArea.java @@ -1151,8 +1151,11 @@ protected void buildProperties(IContent content, LayoutContext context) { rl = exeContext.getResourceLocator(); } BackgroundImageInfo backgroundImage = new BackgroundImageInfo(getImageUrl(url.getCssText()), - style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl, this.getCurrentModule(), - style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, this.getCurrentModule(), style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(style); boxStyle.setBackgroundImage(backgroundImage); } @@ -1179,8 +1182,12 @@ protected void buildLogicContainerProperties(IContent content) { rl = exeContext.getResourceLocator(); } BackgroundImageInfo backgroundImage = new BackgroundImageInfo(getImageUrl(url), - cs.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl, this.getCurrentModule(), - cs.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + cs.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(cs.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(cs.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, this.getCurrentModule(), cs.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(cs); + boxStyle.setBackgroundImage(backgroundImage); } if (!isInlineStacking) { diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/PageArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/PageArea.java index 71fafa87b3a..60c6a8a4c5c 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/PageArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/PageArea.java @@ -316,8 +316,12 @@ protected BackgroundImageInfo createBackgroundImage(String url, Module module) { IStyle cs = pageContent.getComputedStyle(); BackgroundImageInfo backgroundImage = null; - backgroundImage = new BackgroundImageInfo(url, cs.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, - 0, rl, module, cs.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage = new BackgroundImageInfo(url, cs.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(cs.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(cs.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, module, cs.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(cs); + Image img = backgroundImage.getImageInstance(); IStyle style = pageContent.getStyle(); @@ -359,27 +363,12 @@ protected BackgroundImageInfo createBackgroundImage(String url, Module module) { actualWidth = (int) (imageWidth * height / imageHeight); } } else { - DimensionType widthDim = DimensionType.parserUnit(widthStr); - DimensionType heightDim = DimensionType.parserUnit(heightStr); - if (widthDim != null) { - actualWidth = PropertyUtil.getDimensionValue(content, widthDim); - if (heightDim == null) { - actualHeight = (int) (imageHeight * actualWidth / imageWidth); - } else { - actualHeight = PropertyUtil.getDimensionValue(content, heightDim); - } - } else if (heightDim != null) { - actualHeight = PropertyUtil.getDimensionValue(content, heightDim); - if (widthDim == null) { - actualWidth = (int) (imageWidth * actualHeight / imageHeight); - } else { - actualWidth = PropertyUtil.getDimensionValue(content, widthDim); - } - } else { - actualHeight = (int) imageHeight; - actualWidth = (int) imageWidth; - } + actualHeight = backgroundImage.getHeightMetricPt(); + actualWidth = backgroundImage.getWidthMetricPt(); } + } else { + actualHeight = backgroundImage.getHeightMetricPt(); + actualWidth = backgroundImage.getWidthMetricPt(); } backgroundImage.setXOffset( @@ -387,8 +376,9 @@ protected BackgroundImageInfo createBackgroundImage(String url, Module module) { backgroundImage.setYOffset( getDimensionValue(cs.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y), height - actualHeight)); - backgroundImage.setHeight(actualHeight); - backgroundImage.setWidth(actualWidth); + backgroundImage.setHeightMetricPt(actualHeight); + backgroundImage.setWidthMetricPt(actualWidth); + return backgroundImage; } return null; diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TableArea.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TableArea.java index aae6b9656aa..98ab4d9f0b3 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TableArea.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/impl/TableArea.java @@ -175,8 +175,12 @@ protected void buildProperties(IContent content, LayoutContext context) { rl = exeContext.getResourceLocator(); } BackgroundImageInfo backgroundImage = new BackgroundImageInfo(getImageUrl(url), - style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl, - this.getCurrentModule(), style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + style.getProperty(StyleConstants.STYLE_BACKGROUND_REPEAT), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_X)), + PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_BACKGROUND_POSITION_Y)), + 0, 0, rl, this.getCurrentModule(), + style.getProperty(StyleConstants.STYLE_BACKGROUND_IMAGE_TYPE)); + backgroundImage.setImageSize(style); boxStyle.setBackgroundImage(backgroundImage); } localProperties = new LocalProperties(); diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/style/BackgroundImageInfo.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/style/BackgroundImageInfo.java index 5a5b68c37b4..4dedb0e9fd7 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/style/BackgroundImageInfo.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/nLayout/area/style/BackgroundImageInfo.java @@ -19,18 +19,38 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Base64.Decoder; import java.util.Base64.Encoder; +import java.util.Iterator; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.stream.ImageInputStream; + +import org.eclipse.birt.report.engine.content.IStyle; +import org.eclipse.birt.report.engine.css.engine.value.css.CSSConstants; +import org.eclipse.birt.report.engine.layout.pdf.util.PropertyUtil; import org.eclipse.birt.report.engine.util.ResourceLocatorWrapper; import org.eclipse.birt.report.engine.util.SvgFile; +import org.eclipse.birt.report.model.api.DesignElementHandle; +import org.eclipse.birt.report.model.api.IResourceLocator; +import org.eclipse.birt.report.model.api.ModuleHandle; +import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants; import org.eclipse.birt.report.model.api.elements.structures.EmbeddedImage; +import org.eclipse.birt.report.model.api.metadata.DimensionValue; +import org.eclipse.birt.report.model.api.util.DimensionUtil; +import org.eclipse.birt.report.model.api.util.StringUtil; +import org.eclipse.birt.report.model.api.util.URIUtil; import org.eclipse.birt.report.model.core.Module; import org.eclipse.birt.report.model.metadata.MetaDataDictionary; import org.eclipse.birt.report.model.metadata.StructureDefn; import org.eclipse.birt.report.model.util.StructureRefUtil; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import org.w3c.dom.css.CSSValue; import com.lowagie.text.Image; @@ -43,52 +63,101 @@ * */ public class BackgroundImageInfo extends AreaConstants { + + /** + * the horizontal and vertical DPI + */ + private final static int graphicDpi = 96; + protected int xOffset = 0; protected int yOffset = 0; protected int repeatedMode; - protected int width = 0; - protected int height = 0; protected String url; + protected String uri; protected String dataUrl; protected byte[] imageData; protected String sourceType; protected String mimeType; protected String fileExtension; + protected int[] dpi = { 96, 96 }; + + // width & height in pixel + protected int width = 0; + protected int height = 0; + + // width & height in Metric unit + protected int widthMetricPt = 0; + protected int heightMetricPt = 0; + // width & height based on designer properties + protected String propertyWidth = "auto"; + protected String propertyHeight = "auto"; + + /** + * URL type of data protocol + */ private final static String DATA_PROTOCOL = "data:"; + /** + * Base64 key string of the URL data protocol + */ private final static String DATA_URL_BASE64 = ";base64,"; - // mapping based on image extension: to MIME-type to default extension + /** + * default DPI resolution of the background image + */ + private final static int BGI_DPI_DEFAULT = 96; + + /** + * default metric DPI converting due to different pixel converters + */ + private final static int BGI_DPI_METRIC_PT = 72000; // (720 + 28); + + /** + * Mapping based on image extension: to MIME-type to default extension + */ private final static String[][] SUPPORTED_MIME_TYPES = { { ".jpg", "image/jpeg", "jpg" }, { ".jpe", "image/jpeg", "jpg" }, { ".jpeg", "image/jpeg", "jpg" }, { ".tiff", "image/tiff", "tiff" }, { ".svg", "image/svg+xml", "svg" }, { ".png", "image/png", "png" }, { ".gif", "image/gif", "gif" } }; + /** + * Default source type URL + */ protected final static String BGI_SRC_TYPE_DEFAULT = BGI_SRC_TYPE_URL; + /** + * Module handle of the background image + */ private Module module = null; + /** + * Image object of the background image himself + */ private Image image = null; + /** + * Resource locator of the background + */ private ResourceLocatorWrapper rl = null; /** * constructor 01 of background image * - * @param url - * @param repeatedMode - * @param xOffset - * @param yOffset - * @param height - * @param width - * @param rl - * @param module - * @param sourceType + * @param url URL of the background image + * @param repeatedMode repeat mode of the background image + * @param xOffset offset position x of the background image + * @param yOffset offset position y of the background image + * @param height height of the background image + * @param width width of the background image + * @param rl resource locator + * @param module module handle of the background image + * @param sourceType source type of the background image + * @param dpi resolution of the background image * * @since 4.13 */ public BackgroundImageInfo(String url, int repeatedMode, int xOffset, int yOffset, int height, int width, - ResourceLocatorWrapper rl, Module module, String sourceType) { + ResourceLocatorWrapper rl, Module module, String sourceType, int dpi) { this.xOffset = xOffset; this.yOffset = yOffset; this.repeatedMode = repeatedMode; @@ -103,12 +172,19 @@ public BackgroundImageInfo(String url, int repeatedMode, int xOffset, int yOffse this.sourceType = BGI_SRC_TYPE_DEFAULT; } prepareImageByteArray(); + + if (dpi <= 0) { + this.dpi = this.getImageDpi(); + } else { + this.dpi[0] = dpi; + this.dpi[1] = dpi; + } } /** * constructor 02 of background image * - * @param bgi + * @param bgi object of background image */ public BackgroundImageInfo(BackgroundImageInfo bgi) { this.xOffset = bgi.xOffset; @@ -120,6 +196,7 @@ public BackgroundImageInfo(BackgroundImageInfo bgi) { this.imageData = bgi.imageData; this.image = bgi.image; this.rl = bgi.rl; + this.dpi = bgi.dpi; if (bgi.sourceType != null) { this.sourceType = bgi.sourceType; } else { @@ -130,39 +207,39 @@ public BackgroundImageInfo(BackgroundImageInfo bgi) { /** * constructor 03 of background image * - * @param url - * @param mode - * @param xOffset - * @param yOffset - * @param height - * @param width - * @param rl - * @param module + * @param url URL of the background image + * @param mode repeat mode of the background image + * @param xOffset offset position x of the background image + * @param yOffset offset position y of the background image + * @param height height of the background image + * @param width width of the background image + * @param rl resource locator + * @param module module handle of the background image */ public BackgroundImageInfo(String url, CSSValue mode, int xOffset, int yOffset, int height, int width, ResourceLocatorWrapper rl, Module module) { this(url, mode != null ? repeatMap.get(mode) : REPEAT, xOffset, yOffset, height, width, rl, module, - BGI_SRC_TYPE_DEFAULT); + BGI_SRC_TYPE_DEFAULT, 0); } /** * constructor 04 of background image * - * @param url - * @param mode - * @param xOffset - * @param yOffset - * @param height - * @param width - * @param rl - * @param module - * @param sourceType + * @param url URL of the background image + * @param mode repeat mode of the background image + * @param xOffset offset position x of the background image + * @param yOffset offset position y of the background image + * @param height height of the background image + * @param width width of the background image + * @param rl resource locator + * @param module module handle of the background image + * @param sourceType source type of the background image */ public BackgroundImageInfo(String url, CSSValue mode, int xOffset, int yOffset, int height, int width, ResourceLocatorWrapper rl, Module module, CSSValue sourceType) { this(url, mode != null ? repeatMap.get(mode) : REPEAT, xOffset, yOffset, height, width, rl, module, sourceType != null ? bgiSourceTypeMap.get(sourceType) - : BGI_SRC_TYPE_URL); + : BGI_SRC_TYPE_URL, 0); } /** @@ -384,7 +461,7 @@ public void setYOffset(int y) { * @return Return the background image height */ public int getHeight() { - return height; + return this.height; } /** @@ -402,7 +479,7 @@ public void setHeight(int height) { * @return Return the background image width */ public int getWidth() { - return width; + return this.width; } /** @@ -481,4 +558,361 @@ public byte[] getImageData() { return this.imageData; } + /** + * Set the URI string + * + * @param uri representation of the image URI + * @since 4.14 + */ + public void setUri(String uri) { + this.uri = uri; + } + + /** + * Get the URI string + * + * @return Return the URI string + * @since 4.14 + */ + public String getUri() { + if (this.uri == null) { + return this.getDataUrl(); + } + return this.uri; + } + + /** + * Get property width of background image based on set designer property size + * + * @return Return the property height of background image based on designer + * property + * @since 4.14 + */ + public String getPropertyHeight() { + return this.propertyHeight; + } + + /** + * Get property width of background image based on set designer property size + * + * @return Return the property width of background image based on designer + * property + * @since 4.14 + */ + public String getPropertyWidth() { + return this.propertyWidth; + } + + /** + * Get height metric of background image (used e.g. PDF emitter) + * + * @return Return the height metric of background image + * @since 4.14 + */ + public int getHeightMetricPt() { + return this.heightMetricPt; + } + + /** + * Set the height metric of background image + * + * @param height height metric of background image + * @since 4.14 + */ + public void setHeightMetricPt(int height) { + this.heightMetricPt = height; + } + + /** + * Get width metric of background image (used e.g. PDF emitter) + * + * @return Return the width metric of background image + * @since 4.14 + */ + public int getWidthMetricPt() { + return this.widthMetricPt; + } + + /** + * Set the width metric of background image + * + * @param width width metric of background image + * @since 4.14 + */ + public void setWidthMetricPt(int width) { + this.widthMetricPt = width; + } + + /** + * Set image dpi with horizontal and vertical resolution + * + * + * @param dpi set the resolution of the image (horizontal & vertical resolution + * in dpi) resolution + * @since 4.14 + */ + public void setDpi(int[] dpi) { + if (dpi.length != 2) { + dpi = new int[2]; + dpi[0] = BGI_DPI_DEFAULT; + dpi[1] = BGI_DPI_DEFAULT; + } + this.dpi = dpi; + } + + /** + * Get image dpi with horizontal and vertical resolution + * + * + * @return Return an array of the image dpi for the horizontal and vertical + * resolution + * @since 4.14 + */ + public int[] getDpi() { + return this.dpi; + } + + /** + * Get image dpi with horizontal and vertical resolution + * + * @return Return an array of the image dpi for the horizontal and vertical + * resolution + */ + private int[] getImageDpi() { + InputStream in = null; + URL temp = null; + DesignElementHandle model = this.module.getModuleHandle(); + + try { + if (org.eclipse.birt.report.model.api.util.URIUtil.isValidResourcePath(this.url)) { + temp = this.generateURL(model.getModuleHandle(), + org.eclipse.birt.report.model.api.util.URIUtil.getLocalPath(this.url)); + } else { + temp = this.generateURL(model.getModuleHandle(), this.url); + } + if (temp != null) { + in = temp.openStream(); + } + } catch (IOException e) { + in = null; + } + + int[] dpi = getImageResolution(in); + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + if (dpi == null || dpi.length != 2) { + dpi = new int[2]; + dpi[0] = BGI_DPI_DEFAULT; + dpi[1] = BGI_DPI_DEFAULT; + } else { + if (dpi[0] <= 0) { + dpi[0] = BGI_DPI_DEFAULT; + } + if (dpi[1] <= 0) { + dpi[1] = BGI_DPI_DEFAULT; + } + } + return dpi; + } + + /** + * Returns the DPI info of given image if applicable. + * + * @param imageStream + * + * @return the DPI values in format of {hdpi/widthdpi, vdpi/heightdpi} + */ + private int[] getImageResolution(InputStream imageStream) { + int[] dpi = { BGI_DPI_DEFAULT, BGI_DPI_DEFAULT }; + + if (imageStream != null) { + try { + ImageInputStream iis = ImageIO.createImageInputStream(imageStream); + Iterator i = ImageIO.getImageReaders(iis); + ImageReader r = i.next(); + r.setInput(iis); + r.read(0); + + IIOMetadata meta = r.getImageMetadata(0); + + if (meta != null) { + double mm2inch = 25.4; + + NodeList lst; + Element node = (Element) meta.getAsTree("javax_imageio_1.0"); //$NON-NLS-1$ + lst = node.getElementsByTagName("HorizontalPixelSize"); //$NON-NLS-1$ + if (lst != null && lst.getLength() == 1) { + dpi[0] = (int) (mm2inch / Float.parseFloat(((Element) lst.item(0)).getAttribute("value"))); //$NON-NLS-1$ + } + + lst = node.getElementsByTagName("VerticalPixelSize"); //$NON-NLS-1$ + if (lst != null && lst.getLength() == 1) { + dpi[1] = (int) (mm2inch / Float.parseFloat(((Element) lst.item(0)).getAttribute("value"))); //$NON-NLS-1$ + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + return dpi; + } + + /** + * Sets the Image that this ImageFigure displays. + * + * @param style style of the background image + * @since 4.14 + */ + public void setImageSize(IStyle style) { + String propertyValue = null; + int pxBackgroundHeight = 0; + int pxBackgroundWidth = 0; + double percentageHeight = 1d; + double percentageWidth = 1d; + + if (style != null) { + + // calculate the background image height + propertyValue = style.getPropertyValue(CSSConstants.CSS_BACKGROUND_HEIGHT_PROPERTY); + CSSValue dimensionValueHeight = style.getPropertyCSSValue(CSSConstants.CSS_BACKGROUND_HEIGHT_PROPERTY); + this.heightMetricPt = PropertyUtil.getDimensionValue(dimensionValueHeight); + this.propertyHeight = propertyValue; + + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + try { + if (propertyValue.endsWith("%")) { + percentageHeight = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundHeight = StringUtil.parse(propertyValue); + + if (propertyBackgroundHeight.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundHeight = (int) propertyBackgroundHeight.getMeasure(); + } else { + DimensionValue backgroundHeight = DimensionUtil.convertTo( + propertyBackgroundHeight.getMeasure(), propertyBackgroundHeight.getUnits(), + DesignChoiceConstants.UNITS_IN); + pxBackgroundHeight = (int) BackgroundImageInfo.inchToPixel(backgroundHeight.getMeasure()); + } + } + } catch (Exception e) { + } + } + + // calculate the background image width + propertyValue = style.getPropertyValue(CSSConstants.CSS_BACKGROUND_WIDTH_PROPERTY); + CSSValue dimensionValueWidth = style.getPropertyCSSValue(CSSConstants.CSS_BACKGROUND_WIDTH_PROPERTY); + this.widthMetricPt = PropertyUtil.getDimensionValue(dimensionValueWidth); + this.propertyWidth = propertyValue; + + if (propertyValue != null && !DesignChoiceConstants.BACKGROUND_SIZE_AUTO.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_COVER.equals(propertyValue) + && !DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN.equals(propertyValue)) { + try { + if (propertyValue.endsWith("%")) { + percentageWidth = Double.parseDouble(propertyValue.replace("%", "")) / 100; + } else { + DimensionValue propertyBackgroundWidth = StringUtil.parse(propertyValue); + + if (propertyBackgroundWidth.getUnits().equals(DesignChoiceConstants.UNITS_PX)) { + pxBackgroundWidth = (int) propertyBackgroundWidth.getMeasure(); + } else { + DimensionValue backgroundWidth = DimensionUtil.convertTo( + propertyBackgroundWidth.getMeasure(), propertyBackgroundWidth.getUnits(), + DesignChoiceConstants.UNITS_IN); + pxBackgroundWidth = (int) BackgroundImageInfo.inchToPixel(backgroundWidth.getMeasure()); + } + } + } catch (Exception e) { + } + } + } + this.height = pxBackgroundHeight; + this.width = pxBackgroundWidth; + double scaleFactorHeight = 1d; + double scaleFactorWidth = 1d; + + if (this.image != null) { + int dpi = this.dpi[0]; + double imageHeight = this.image.getHeight(); + double imageWidth = this.image.getWidth(); + + if (dpi > 0) { + if (this.height <= 0) { + double inch = imageHeight / dpi; + this.height = (int) BackgroundImageInfo.inchToPixel(inch); + this.heightMetricPt = (int) (inch * BGI_DPI_METRIC_PT); + } else if (pxBackgroundHeight > 0 && pxBackgroundWidth <= 0) { + double inch = imageHeight / dpi; + scaleFactorWidth = this.height / (BackgroundImageInfo.inchToPixel(inch)); + } + } + + if (dpi > 0) { + if (this.width <= 0) { + double inch = imageWidth / dpi; + this.width = (int) BackgroundImageInfo.inchToPixel(inch); + this.widthMetricPt = (int) (inch * BGI_DPI_METRIC_PT); + } else if (pxBackgroundHeight <= 0 && pxBackgroundWidth > 0) { + double inch = imageWidth / dpi; + scaleFactorHeight = this.width / (BackgroundImageInfo.inchToPixel(inch)); + } + } + + if (dpi <= 0 && this.height <= 0 && this.width <= 0) { + this.heightMetricPt = (int) (this.image.getHeight() * BGI_DPI_METRIC_PT / 100); + this.heightMetricPt = (int) (this.image.getWidth() * BGI_DPI_METRIC_PT / 100); + + this.height = this.heightMetricPt; + this.width = this.widthMetricPt; + } + } + // auto scaling of percentage if one percentage is set and the image size is unset + if (percentageHeight != 1.0 && percentageWidth == 1.0 && pxBackgroundWidth == 0) { + percentageWidth = percentageHeight; + } else if (percentageWidth != 1.0 && percentageHeight == 1.0 && pxBackgroundHeight == 0) { + percentageHeight = percentageWidth; + } + this.height = (int) (this.height * percentageHeight * scaleFactorHeight); + this.width = (int) (this.width * percentageWidth * scaleFactorWidth); + this.heightMetricPt = (int) (this.heightMetricPt * percentageHeight * scaleFactorHeight); + this.widthMetricPt = (int) (this.widthMetricPt * percentageWidth * scaleFactorWidth); + + } + + /** + * Generate the image URL (based on method ImageManager.getInstance().generateURL) + * + * @param designHandle handle of the report + * @param uri of the image + * @return Return the URL of the image + * @throws MalformedURLException + */ + private URL generateURL(ModuleHandle designHandle, String uri) throws MalformedURLException { + try { + return new URL(uri); + } catch (MalformedURLException e) { + String path = URIUtil.getLocalPath(uri); + if (path != null && designHandle != null) { + return designHandle.findResource(path, IResourceLocator.IMAGE); + } + return URI.create(uri).toURL(); + } + } + + /** + * Transforms the inch to pixel (based on method MetricUtility.inchToPixel) + * + * @param inch size of inch + * @return pixel value + */ + private static double inchToPixel(double inch) { + return (inch * graphicDpi); + } } diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/element/StyleDesign.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/element/StyleDesign.java index 7092b7ff17a..65c940917e7 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/element/StyleDesign.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/element/StyleDesign.java @@ -117,6 +117,58 @@ public void setBackgroundRepeat(String value) throws ScriptException { } } + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.report.engine.script.element.IStyleDesign# + * getBackgroundHeight() + */ + @Override + public String getBackgroundHeight() { + return styleImpl.getBackgroundHeight(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.report.engine.script.element.IStyleDesign# + * setBackgroundHeight(java.lang.String) + */ + @Override + public void setBackgroundHeight(String value) throws ScriptException { + try { + styleImpl.setBackgroundHeight(value); + } catch (SemanticException e) { + throw new ScriptException(e.getLocalizedMessage()); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.report.engine.script.element.IStyleDesign# + * getBackgroundWidth() + */ + @Override + public String getBackgroundWidth() { + return styleImpl.getBackgroundWidth(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.report.engine.script.element.IStyleDesign# + * setBackgroundWidth(java.lang.String) + */ + @Override + public void setBackgroundWidth(String value) throws ScriptException { + try { + styleImpl.setBackgroundWidth(value); + } catch (SemanticException e) { + throw new ScriptException(e.getLocalizedMessage()); + } + } + /* * (non-Javadoc) * diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/StyleInstance.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/StyleInstance.java index 66c456a28ba..2421a06d692 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/StyleInstance.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/script/internal/instance/StyleInstance.java @@ -319,6 +319,40 @@ public void setBackgroundRepeat(String repeat) { style.setBackgroundRepeat(repeat); } + /** + * Get the background image height + */ + @Override + public String getBackgroundHeight() { + return style.getBackgroundHeight(); + } + + /** + * Set the background image height + */ + @Override + public void setBackgroundHeight(String height) { + checkWritable(); + style.setBackgroundHeight(height); + } + + /** + * Get the background image width + */ + @Override + public String getBackgroundWidth() { + return style.getBackgroundWidth(); + } + + /** + * Set the background image width + */ + @Override + public void setBackgroundWidth(String width) { + checkWritable(); + style.setBackgroundWidth(width); + } + /** * Get the bottom border color */ diff --git a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/api/StyleHandleTest.java b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/api/StyleHandleTest.java index 773bbd3af76..58097717c9c 100644 --- a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/api/StyleHandleTest.java +++ b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/api/StyleHandleTest.java @@ -782,8 +782,8 @@ public void testBackgroundSize() throws Exception { */ private void comparedBackgroundSize(StyleHandle styleHandle, String propName, String value, String expectedWidth, String expectedHeight) throws Exception { - DimensionHandle width = styleHandle.getBackgroundSizeWidth(); - DimensionHandle height = styleHandle.getBackgroundSizeHeight(); + DimensionHandle width = styleHandle.getBackgroundWidth(); + DimensionHandle height = styleHandle.getBackgroundHeight(); String oldWidth = width.getStringValue(); String oldHeight = height.getStringValue(); diff --git a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/css/StyleSheetLoaderTest.java b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/css/StyleSheetLoaderTest.java index 5262c71d6a7..a977ed7026d 100644 --- a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/css/StyleSheetLoaderTest.java +++ b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/css/StyleSheetLoaderTest.java @@ -159,9 +159,9 @@ public void testParserForAllProperties() throws Exception { assertEquals("10px", style1.getBorderBottomWidth().getDisplayValue());//$NON-NLS-1$ assertEquals("test", style3.getName()); //$NON-NLS-1$ - assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN, style3.getBackgroundSizeWidth().getStringValue()); + assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN, style3.getBackgroundWidth().getStringValue()); - assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_AUTO, style3.getBackgroundSizeHeight().getStringValue()); + assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_AUTO, style3.getBackgroundHeight().getStringValue()); } diff --git a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/parser/StyleParseTest.java b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/parser/StyleParseTest.java index ace35e4c5cd..a72f5a3d423 100644 --- a/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/parser/StyleParseTest.java +++ b/model/org.eclipse.birt.report.model.tests/test/org/eclipse/birt/report/model/parser/StyleParseTest.java @@ -381,10 +381,10 @@ public void testParser() throws Exception { assertNotNull(iter.next()); assertNotNull(iter.next()); - DimensionHandle handle = sh.getBackgroundSizeWidth(); + DimensionHandle handle = sh.getBackgroundWidth(); assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_CONTAIN, handle.getStringValue()); - handle = sh.getBackgroundSizeHeight(); + handle = sh.getBackgroundHeight(); assertEquals(DesignChoiceConstants.BACKGROUND_SIZE_COVER, handle.getStringValue()); style = design.findStyle("test"); //$NON-NLS-1$ @@ -600,9 +600,9 @@ public void testWriter() throws Exception { style.setTextDirection(DesignChoiceConstants.BIDI_DIRECTION_LTR); style.setBackgroundImageType(DesignChoiceConstants.IMAGE_REF_TYPE_URL); - DimensionHandle handle = style.getBackgroundSizeHeight(); + DimensionHandle handle = style.getBackgroundHeight(); handle.setStringValue("19pt"); //$NON-NLS-1$ - handle = style.getBackgroundSizeWidth(); + handle = style.getBackgroundWidth(); handle.setStringValue("0.5in"); //$NON-NLS-1$ // Overflow diff --git a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/StyleHandle.java b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/StyleHandle.java index 5d515615497..1cce97c3243 100644 --- a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/StyleHandle.java +++ b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/StyleHandle.java @@ -1851,37 +1851,45 @@ public void setTextDirection(String value) throws SemanticException { } /** - * Gets a dimension handle to deal with the size height for the background. - * Besides the dimension value, the dimension handle may return one of constants - * defined in DesignChoiceConstants: - *
    - *
  • BACKGROUND_SIZE_AUTO - *
  • BACKGROUND_SIZE_CONTAIN - *
  • BACKGROUND_SIZE_COVER - *
+ * Get the height of the background image. * * @return a DimensionHandle for the background size height. */ - public DimensionHandle getBackgroundSizeHeight() { + public DimensionHandle getBackgroundHeight() { return getDimensionProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT); } /** - * Gets a dimension handle to deal with the size width for the background. - * Besides the dimension value, the dimension handle may return one of constants - * defined in DesignChoiceConstants: - *
    - *
  • BACKGROUND_SIZE_AUTO - *
  • BACKGROUND_SIZE_CONTAIN - *
  • BACKGROUND_SIZE_COVER - *
+ * Sets the height of the background image. + * + * @param height the new width of the background image + * @throws SemanticException if the given type is not defined + */ + + public void setBackgroundHeight(String height) throws SemanticException { + setStringProperty(IStyleModel.BACKGROUND_SIZE_HEIGHT, height); + } + + /** + * Get the width of the background image. * * @return a DimensionHandle for the background size width. */ - public DimensionHandle getBackgroundSizeWidth() { + public DimensionHandle getBackgroundWidth() { return getDimensionProperty(IStyleModel.BACKGROUND_SIZE_WIDTH); } + /** + * Sets the width of the background image. + * + * @param width the new width of the background image + * @throws SemanticException if the given type is not defined + */ + + public void setBackgroundWidth(String width) throws SemanticException { + setStringProperty(IStyleModel.BACKGROUND_SIZE_WIDTH, width); + } + /** * Returns the type of the background image. The method may return one of * constants defined in DesignChoiceConstants: diff --git a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/simpleapi/IStyle.java b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/simpleapi/IStyle.java index 4d1bc9df2cc..c333aa64bfb 100644 --- a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/simpleapi/IStyle.java +++ b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/api/simpleapi/IStyle.java @@ -111,6 +111,36 @@ public interface IStyle { void setBackgroundRepeat(String value) throws SemanticException; + /** + * Set the background height of the background image. + * + * @param value the new background image height + * @throws SemanticException + */ + void setBackgroundHeight(String value) throws SemanticException; + + /** + * Returns the height of the background image. + * + * @return the background image height + */ + String getBackgroundHeight(); + + /** + * Set the background width of the background image. + * + * @param value the new background image width + * @throws SemanticException + */ + void setBackgroundWidth(String value) throws SemanticException; + + /** + * Returns the width of the background image. + * + * @return the background image width + */ + String getBackgroundWidth(); + /** * Returns the style of the bottom line of the border. The return value is * defined in DesignChoiceConstants and can be one of: diff --git a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/simpleapi/Style.java b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/simpleapi/Style.java index e215cd09070..0eb421a348a 100644 --- a/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/simpleapi/Style.java +++ b/model/org.eclipse.birt.report.model/src/org/eclipse/birt/report/model/simpleapi/Style.java @@ -164,6 +164,74 @@ public void setBackgroundRepeat(String value) throws SemanticException { cmdStack.commit(); } + /* + * (non-Javadoc) + * + * @seeorg.eclipse.birt.report.engine.script.element.IStyleDesign# + * getBackgroundHeight() + */ + + @Override + public String getBackgroundHeight() { + return style.getBackgroundHeight().getStringValue(); + } + + /* + * (non-Javadoc) + * + * @seeorg.eclipse.birt.report.engine.script.element.IStyleDesign# + * setBackgroundHeight(java.lang.String) + */ + + @Override + public void setBackgroundHeight(String value) throws SemanticException { + ActivityStack cmdStack = style.getModule().getActivityStack(); + + cmdStack.startNonUndoableTrans(null); + try { + style.setBackgroundHeight(value); + } catch (SemanticException e) { + cmdStack.rollback(); + throw e; + } + + cmdStack.commit(); + } + + /* + * (non-Javadoc) + * + * @seeorg.eclipse.birt.report.engine.script.element.IStyleDesign# + * getBackgroundHeight() + */ + + @Override + public String getBackgroundWidth() { + return style.getBackgroundWidth().getStringValue(); + } + + /* + * (non-Javadoc) + * + * @seeorg.eclipse.birt.report.engine.script.element.IStyleDesign# + * setBackgroundHeight(java.lang.String) + */ + + @Override + public void setBackgroundWidth(String value) throws SemanticException { + ActivityStack cmdStack = style.getModule().getActivityStack(); + + cmdStack.startNonUndoableTrans(null); + try { + style.setBackgroundWidth(value); + } catch (SemanticException e) { + cmdStack.rollback(); + throw e; + } + + cmdStack.commit(); + } + /* * (non-Javadoc) * diff --git a/xtab/org.eclipse.birt.report.item.crosstab.core/src/org/eclipse/birt/report/item/crosstab/core/script/internal/StyleInstance.java b/xtab/org.eclipse.birt.report.item.crosstab.core/src/org/eclipse/birt/report/item/crosstab/core/script/internal/StyleInstance.java index 85f07207e91..4345804694b 100644 --- a/xtab/org.eclipse.birt.report.item.crosstab.core/src/org/eclipse/birt/report/item/crosstab/core/script/internal/StyleInstance.java +++ b/xtab/org.eclipse.birt.report.item.crosstab.core/src/org/eclipse/birt/report/item/crosstab/core/script/internal/StyleInstance.java @@ -301,6 +301,38 @@ public void setBackgroundRepeat(String repeat) { style.setBackgroundRepeat(repeat); } + /** + * Get the background image height + */ + @Override + public String getBackgroundHeight() { + return style.getBackgroundHeight(); + } + + /** + * Set the background image height + */ + @Override + public void setBackgroundHeight(String height) { + style.setBackgroundHeight(height); + } + + /** + * Get the background image width + */ + @Override + public String getBackgroundWidth() { + return style.getBackgroundWidth(); + } + + /** + * Set the background image height + */ + @Override + public void setBackgroundWidth(String width) { + style.setBackgroundWidth(width); + } + /** * Get the bottom border color */