Ejemplo n.º 1
0
  public static BorderInfo getBorderInfo(
      final CSS2Properties properties, final RenderState renderState) {
    final BorderInfo binfo = new BorderInfo();

    binfo.topStyle = getBorderStyle(properties.getBorderTopStyle());
    binfo.rightStyle = getBorderStyle(properties.getBorderRightStyle());
    binfo.bottomStyle = getBorderStyle(properties.getBorderBottomStyle());
    binfo.leftStyle = getBorderStyle(properties.getBorderLeftStyle());

    final ColorFactory cf = ColorFactory.getInstance();
    final String topColorSpec = properties.getBorderTopColor();
    if (topColorSpec != null) {
      binfo.topColor = cf.getColor(topColorSpec);
    }
    final String rightColorSpec = properties.getBorderRightColor();
    if (rightColorSpec != null) {
      binfo.rightColor = cf.getColor(rightColorSpec);
    }
    final String bottomColorSpec = properties.getBorderBottomColor();
    if (bottomColorSpec != null) {
      binfo.bottomColor = cf.getColor(bottomColorSpec);
    }
    final String leftColorSpec = properties.getBorderLeftColor();
    if (leftColorSpec != null) {
      binfo.leftColor = cf.getColor(leftColorSpec);
    }

    HtmlValues.populateBorderInsets(binfo, properties, renderState);

    return binfo;
  }
Ejemplo n.º 2
0
 private static HtmlInsets updateRightInset(
     HtmlInsets insets, String sizeText, final RenderState renderState) {
   if (sizeText == null) {
     return insets;
   }
   sizeText = sizeText.trim();
   if (sizeText.length() == 0) {
     return insets;
   }
   if (insets == null) {
     insets = new HtmlInsets();
   }
   if ("auto".equalsIgnoreCase(sizeText)) {
     insets.rightType = HtmlInsets.TYPE_AUTO;
   } else if (sizeText.endsWith("%")) {
     insets.rightType = HtmlInsets.TYPE_PERCENT;
     try {
       insets.right = Integer.parseInt(sizeText.substring(0, sizeText.length() - 1));
     } catch (final NumberFormatException nfe) {
       insets.right = 0;
     }
   } else {
     insets.rightType = HtmlInsets.TYPE_PIXELS;
     insets.right = HtmlValues.getPixelSize(sizeText, renderState, 0);
   }
   return insets;
 }
Ejemplo n.º 3
0
 public static ListStyle getListStyle(final String listStyleText) {
   final ListStyle listStyle = new ListStyle();
   final String[] tokens = HtmlValues.splitCssValue(listStyleText);
   for (final String token : tokens) {
     final int listStyleType = HtmlValues.getListStyleType(token);
     if (listStyleType != ListStyle.TYPE_UNSET) {
       listStyle.type = listStyleType;
     } else if (HtmlValues.isUrl(token)) {
       // TODO: listStyle.image
     } else {
       final int listStylePosition = HtmlValues.getListStylePosition(token);
       if (listStylePosition != ListStyle.POSITION_UNSET) {
         listStyle.position = listStylePosition;
       }
     }
   }
   return listStyle;
 }
 protected RenderState createRenderState(RenderState prevRenderState) {
   String face = this.getAttribute("face");
   String size = this.getAttribute("size");
   String color = this.getAttribute("color");
   if (face != null) {
     prevRenderState = new FontNameRenderState(prevRenderState, face);
   }
   if (size != null) {
     int fontNumber = HtmlValues.getFontNumberOldStyle(size, prevRenderState);
     float fontSize = HtmlValues.getFontSize(fontNumber);
     prevRenderState = new FontSizeRenderState(prevRenderState, fontSize);
     prevRenderState = new BaseFontRenderState(prevRenderState, fontNumber);
   }
   if (color != null) {
     prevRenderState =
         new ColorRenderState(prevRenderState, ColorFactory.getInstance().getColor(color));
   }
   return prevRenderState;
 }
Ejemplo n.º 5
0
 public HtmlInsets getMarginInsets() {
   HtmlInsets mi = this.marginInsets;
   if (mi != INVALID_INSETS) {
     return mi;
   }
   AbstractCSS2Properties props = this.getCssProperties();
   if (props == null) {
     mi = null;
   } else {
     mi = HtmlValues.getMarginInsets(props, this);
   }
   if (mi == null) {
     int hspace = 0;
     int vspace = 0;
     boolean createNew = false;
     String hspaceText = this.element.getAttribute("hspace");
     if (hspaceText != null && hspaceText.length() != 0) {
       createNew = true;
       try {
         hspace = Integer.parseInt(hspaceText);
       } catch (NumberFormatException nfe) {
         // TODO: Percentages?
       }
     }
     String vspaceText = this.element.getAttribute("vspace");
     if (vspaceText != null && vspaceText.length() != 0) {
       createNew = true;
       try {
         vspace = Integer.parseInt(vspaceText);
       } catch (NumberFormatException nfe) {
         // TODO: Percentages?
       }
     }
     if (createNew) {
       mi = new HtmlInsets();
       mi.top = vspace;
       mi.topType = HtmlInsets.TYPE_PIXELS;
       mi.bottom = vspace;
       mi.bottomType = HtmlInsets.TYPE_PIXELS;
       mi.left = hspace;
       mi.leftType = HtmlInsets.TYPE_PIXELS;
       mi.right = hspace;
       mi.rightType = HtmlInsets.TYPE_PIXELS;
     }
   }
   this.marginInsets = mi;
   return mi;
 }