Ejemplo n.º 1
0
  @Override
  protected void loadSizes(boolean update) {
    bounds = new Rectangle(0, 0, 0, 0);
    min_size = new Dimension();
    max_size = new Dimension();
    margin = new LengthSet();
    emargin = margin;
    padding = new LengthSet();
    border = new LengthSet();
    isempty = true;
    displayed = false;
    visible = false;
    coords = new LengthSet();

    if (colwidth.equals("")) // no width set - try to get from style
    {
      int contw = cblock.getContentWidth();
      CSSDecoder dec = new CSSDecoder(ctx);
      CSSProperty.Width wprop = style.getProperty("width");
      if (wprop != null && wprop != CSSProperty.Width.AUTO) {
        TermLengthOrPercent width = getLengthValue("width");
        abswidth = dec.getLength(width, false, 0, 0, contw);
        content.width = abswidth;
        wset = true;
        if (width.isPercentage()) {
          wrelative = true;
          percent = Math.round(width.getValue());
          if (percent == 0) wrelative = false; // consider 0% as absolute 0
        }
      }
    }

    bounds.width = content.width;
  }
Ejemplo n.º 2
0
  /**
   * Converts a length from a CSS length or percentage to 'pt'.
   *
   * @param spec the CSS length specification
   * @param whole the value that corresponds to 100%. It is used only when spec is a percentage.
   * @return the length in 'pt'
   */
  public double ptLength(TermLengthOrPercent spec, double whole) {
    float nval = spec.getValue();
    if (spec.isPercentage()) return (whole * nval) / 100;
    else {
      TermLength.Unit unit = spec.getUnit();

      double ret = 0;
      if (unit == TermLength.Unit.pt) {
        ret = nval;
      } else if (unit == TermLength.Unit.in) {
        ret = nval * 72;
      } else if (unit == TermLength.Unit.cm) {
        ret = (nval * 72) / 2.54;
      } else if (unit == TermLength.Unit.mm) {
        ret = (nval * 72) / 25.4;
      } else if (unit == TermLength.Unit.pc) {
        ret = nval * 12;
      } else if (unit == TermLength.Unit.px) {
        ret = (nval * 72) / dpi;
      } else if (unit == TermLength.Unit.em) {
        ret = (em * nval * 72) / dpi; // em is in pixels
      } else if (unit == TermLength.Unit.rem) {
        ret = (rem * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.ex) {
        ret = (ex * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.ch) {
        ret = (ch * nval * 72) / dpi;
      } else if (unit == TermLength.Unit.vw) {
        return (viewport.getVisibleRect().getWidth() * nval * 72) / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vh) {
        return (viewport.getVisibleRect().getHeight() * nval * 72) / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vmin) {
        return (Math.min(
                    viewport.getVisibleRect().getWidth(), viewport.getVisibleRect().getHeight())
                * nval
                * 72)
            / (100.0 * dpi);
      } else if (unit == TermLength.Unit.vmax) {
        return (Math.max(
                    viewport.getVisibleRect().getWidth(), viewport.getVisibleRect().getHeight())
                * nval
                * 72)
            / (100.0 * dpi);
      }
      return ret;
    }
  }
Ejemplo n.º 3
0
  /**
   * Updates the context according to the given element style. The properties that are not defined
   * in the style are left unchanged.
   *
   * @param style the style data
   */
  public void update(NodeData style) {
    // setup the font
    String family = null;
    CSSProperty.FontFamily ff = style.getProperty("font-family");
    if (ff == null) family = font.getFamily(); // use current
    else if (ff == FontFamily.list_values) {
      TermList fmlspec = style.getValue(TermList.class, "font-family");
      if (fmlspec == null) family = font.getFamily();
      else family = getFontName(fmlspec);
    } else {
      if (factory != null)
        family =
            factory
                .getConfig()
                .getDefaultFont(ff.getAWTValue()); // try to translate to physical font
      if (family == null) family = ff.getAWTValue(); // could not translate - use as is
    }

    double size;
    double psize = (parent == null) ? CSSUnits.medium_font : parent.getEm();
    CSSProperty.FontSize fsize = style.getProperty("font-size");
    if (fsize == null) size = em;
    else if (fsize == CSSProperty.FontSize.length || fsize == CSSProperty.FontSize.percentage) {
      TermLengthOrPercent lenspec = style.getValue(TermLengthOrPercent.class, "font-size");
      if (lenspec != null) {
        em = psize;
        size =
            pxLength(lenspec, psize); // pixels are ok here (java is fixed to 72 dpi for font sizes)
      } else size = em;
    } else size = CSSUnits.convertFontSize(psize, fsize);
    fontSize = CSSUnits.points(size);

    if (rootContext != null) rem = rootContext.getEm();
    else rem = em; // we don't have a root context?

    CSSProperty.FontWeight weight = style.getProperty("font-weight");
    if (weight != null) fontWeight = weight;
    CSSProperty.FontStyle fstyle = style.getProperty("font-style");
    if (fstyle != null) fontStyle = fstyle;
    int fs = Font.PLAIN;
    if (representsBold(fontWeight)) fs = Font.BOLD;
    if (fontStyle == CSSProperty.FontStyle.ITALIC || fontStyle == CSSProperty.FontStyle.OBLIQUE)
      fs = fs | Font.ITALIC;

    font = new Font(family, fs, (int) Math.round(size));
    em = size;

    CSSProperty.FontVariant variant = style.getProperty("font-variant");
    if (variant != null) fontVariant = variant;
    CSSProperty.TextDecoration decor = style.getProperty("text-decoration");
    textDecoration.clear();
    if (decor != null) {
      if (decor == TextDecoration.list_values) {
        TermList list = style.getValue(TermList.class, "text-decoration");
        for (Term<?> t : list) {
          if (t.getValue() instanceof CSSProperty.TextDecoration)
            textDecoration.add((CSSProperty.TextDecoration) t.getValue());
        }
      } else if (decor != TextDecoration.NONE) textDecoration.add(decor);
    }

    // color
    TermColor clr = style.getValue(TermColor.class, "color");
    if (clr != null) color = clr.getValue();
  }