Exemple #1
0
  public void initialize() throws BirtException {
    createRoot();
    Color backgroundColor =
        PropertyUtil.getColor(
            pageContent.getComputedStyle().getProperty(StyleConstants.STYLE_BACKGROUND_COLOR));
    ReportDesignHandle designHandle = pageContent.getReportContent().getDesign().getReportDesign();
    IStyle style = pageContent.getStyle();

    String imageUrl =
        EmitterUtil.getBackgroundImageUrl(
            style,
            designHandle,
            pageContent.getReportContent().getReportContext() == null
                ? null
                : pageContent.getReportContent().getReportContext().getAppContext());
    if (backgroundColor != null || imageUrl != null) {
      boxStyle = new BoxStyle();
      boxStyle.setBackgroundColor(backgroundColor);
      if (imageUrl != null) {
        boxStyle.setBackgroundImage(createBackgroundImage(imageUrl));
      }
    }
    context.setMaxHeight(root.getHeight());
    context.setMaxWidth(root.getWidth());
    context.setMaxBP(root.getHeight());
    layoutHeader();
    layoutFooter();
    updateBodySize();
    context.setMaxHeight(body.getHeight());
    context.setMaxWidth(body.getWidth());
    context.setMaxBP(body.getHeight());
    maxAvaWidth = context.getMaxWidth();
    context.resetUnresolvedRowHints();
  }
Exemple #2
0
  // support page border on root area
  protected BoxStyle buildRootStyle() {
    IStyle style = pageContent.getStyle();
    if ((style != null) && !style.isEmpty()) {
      BoxStyle boxStyle = new BoxStyle();
      IStyle cs = pageContent.getComputedStyle();
      int borderWidth = getDimensionValue(cs.getProperty(IStyle.STYLE_BORDER_LEFT_WIDTH), width);
      if (borderWidth > 0) {
        boxStyle.setLeftBorder(
            new BorderInfo(
                cs.getProperty(IStyle.STYLE_BORDER_LEFT_COLOR),
                cs.getProperty(IStyle.STYLE_BORDER_LEFT_STYLE),
                borderWidth));
      }

      borderWidth = getDimensionValue(cs.getProperty(IStyle.STYLE_BORDER_RIGHT_WIDTH), width);
      if (borderWidth > 0) {
        boxStyle.setRightBorder(
            new BorderInfo(
                cs.getProperty(IStyle.STYLE_BORDER_RIGHT_COLOR),
                cs.getProperty(IStyle.STYLE_BORDER_RIGHT_STYLE),
                borderWidth));
      }
      borderWidth = getDimensionValue(cs.getProperty(IStyle.STYLE_BORDER_TOP_WIDTH), width);
      if (borderWidth > 0) {
        boxStyle.setTopBorder(
            new BorderInfo(
                cs.getProperty(IStyle.STYLE_BORDER_TOP_COLOR),
                cs.getProperty(IStyle.STYLE_BORDER_TOP_STYLE),
                borderWidth));
      }

      borderWidth = getDimensionValue(cs.getProperty(IStyle.STYLE_BORDER_BOTTOM_WIDTH), width);
      if (borderWidth > 0) {
        boxStyle.setBottomBorder(
            new BorderInfo(
                cs.getProperty(IStyle.STYLE_BORDER_BOTTOM_COLOR),
                cs.getProperty(IStyle.STYLE_BORDER_BOTTOM_STYLE),
                borderWidth));
      }
      return boxStyle;
    }
    return boxStyle.DEFAULT;
  }
Exemple #3
0
  protected BackgroundImageInfo createBackgroundImage(String url) {
    ResourceLocatorWrapper rl = null;
    ExecutionContext exeContext =
        ((ReportContent) content.getReportContent()).getExecutionContext();
    if (exeContext != null) {
      rl = exeContext.getResourceLocator();
    }
    IStyle cs = pageContent.getComputedStyle();
    BackgroundImageInfo backgroundImage =
        new BackgroundImageInfo(
            url, cs.getProperty(IStyle.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl);
    Image img = backgroundImage.getImageInstance();

    IStyle style = pageContent.getStyle();
    String widthStr = style.getBackgroundWidth();
    String heightStr = style.getBackgroundHeight();

    if (img != null) {
      int resolutionX = img.getDpiX();
      int resolutionY = img.getDpiY();
      if (0 == resolutionX || 0 == resolutionY) {
        resolutionX = 96;
        resolutionY = 96;
      }
      float imageWidth = img.getPlainWidth() / resolutionX * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO;
      float imageHeight =
          img.getPlainHeight() / resolutionY * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO;
      int actualWidth = (int) imageWidth;
      int actualHeight = (int) imageHeight;

      if (widthStr != null && widthStr.length() > 0
          || heightStr != null && heightStr.length() > 0) {
        if ("contain".equals(widthStr) || "contain".equals(heightStr)) {
          float rh = imageHeight / height;
          float rw = imageWidth / width;
          if (rh > rw) {
            actualHeight = height;
            actualWidth = (int) (imageWidth * height / imageHeight);
          } else {
            actualWidth = width;
            actualHeight = (int) (imageHeight * width / imageWidth);
          }

        } else if ("cover".equals(widthStr) || "cover".equals(heightStr)) {
          float rh = imageHeight / height;
          float rw = imageWidth / width;
          if (rh > rw) {
            actualWidth = width;
            actualHeight = (int) (imageHeight * width / imageWidth);
          } else {
            actualHeight = height;
            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;
          }
        }
      }

      backgroundImage.setXOffset(
          getDimensionValue(
              cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_X), width - actualWidth));
      backgroundImage.setYOffset(
          getDimensionValue(
              cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_Y), height - actualHeight));
      backgroundImage.setHeight(actualHeight);
      backgroundImage.setWidth(actualWidth);
      return backgroundImage;
    }
    return null;
  }