Esempio n. 1
0
 private float getScaleFactor() {
   if (Float.isNaN(scaleFactor)) {
     // try to get it from the page
     Page page = getBox().getPage();
     if (page != null) {
       scaleFactor = (float) page.getSize().width / (float) page.getPaperSize().height;
     }
   }
   return scaleFactor;
 }
  /**
   * Populates the templates two boxes with a title and map
   *
   * @param page the parent(owner) page
   * @param map the Map to be drawn
   */
  public void init(Page page, Map map) {
    this.page = page;
    com.lowagie.text.Rectangle paperRectangle = getPaperSize();
    Dimension paperSize =
        new Dimension((int) paperRectangle.getWidth(), (int) paperRectangle.getHeight());
    // set the requested papersize
    page.setPaperSize(paperSize);
    // then apply the ratio of the papersize also to the page size.
    setPageSizeFromPaperSize(page, paperSize);

    float scaleFactor = (float) page.getSize().width / (float) page.getPaperSize().height;

    int height = page.getSize().height;
    int width = page.getSize().width;

    int xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT);
    int yPos = getPercentagePieceOf(height, UPPER_MARGIN_PERCENT);
    int w = getPercentagePieceOf(width, TITLE_WIDTH_PERCENT);
    int h = getPercentagePieceOf(height, TITLE_HEIGHT_PERCENT);
    // the base font size is good for the A4 size, scale every other proportional
    float scaledSize = (float) BASEFONT_SIZE * (float) paperSize.height / PageSize.A4.getHeight();
    // float scaledFontSize = scaleValue(page, paperSize, scaledSize);
    addLabelBox(formatName(map.getName()), xPos, yPos, w, h, (int) scaledSize, scaleFactor);

    xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT);
    yPos = getPercentagePieceOf(height, UPPER_MARGIN_PERCENT + TITLE_HEIGHT_PERCENT);
    w = getPercentagePieceOf(width, MAP_WIDTH_PERCENT);
    h = getPercentagePieceOf(height, MAP_HEIGHT_PERCENT);
    addMapBox(map, xPos, yPos, w, h, paperSize);

    // xPos = getPercentagePieceOf(width, 100f - RIGHT_MARGIN_PERCENT - SPACING_PERCENT * 3f
    // - LEGEND_WIDTH_PERCENT);
    // yPos = getPercentagePieceOf(height, 100f - BOTTOM_MARGIN_PERCENT - SPACING_PERCENT * 3f
    // - LEGEND_HEIGHT_PERCENT);
    // w = getPercentagePieceOf(width, LEGEND_WIDTH_PERCENT);
    // h = getPercentagePieceOf(height, LEGEND_HEIGHT_PERCENT);
    // addLegendBox(xPos, yPos, w, h);

    xPos = getPercentagePieceOf(width, LEFT_MARGIN_PERCENT + SPACING_PERCENT * 2f);
    yPos =
        getPercentagePieceOf(
            height, 100f - BOTTOM_MARGIN_PERCENT - SPACING_PERCENT * 3f - SCALE_HEIGHT_PERCENT);
    w = getPercentagePieceOf(width, SCALE_WIDTH_PERCENT);
    h = getPercentagePieceOf(height, SCALE_HEIGHT_PERCENT);
    addScale(xPos, yPos, w, h);
  }