Example #1
0
  protected Format outputCellStart(Field field) {
    Format format = field.getFormat();
    Rectangle bounds = field.getBounds();

    String align = null;
    switch (format.getAlign()) {
      case Format.ALIGN_LEFT:
        align = "left";
        break;
      case Format.ALIGN_CENTER:
        align = "center";
        break;
      case Format.ALIGN_RIGHT:
        align = "right";
        break;
    }

    out.print("<div style=\"position:absolute;width:" + (int) bounds.width + "pt;");
    out.print("height:" + (int) field.getOutputHeight() + "pt;text-align:" + align + ";");
    out.print("left:" + (int) bounds.x + "pt;top:" + (int) bounds.y + "pt;");
    if (!format.isWrap()) out.print("white-space:nowrap;");
    out.println("\">");

    return format;
  }
Example #2
0
  protected void doOutputField(Field field) {
    Format format = outputCellStart(field);
    // Style attribute courtesy of Brendon Price <*****@*****.**>
    out.print("<span style=\"");
    if (format.getFontFamilyName() != null)
      out.print("font-family: " + format.getFontFamilyName() + "; ");
    out.print("font-size: " + format.getSize() + "pt; ");
    outputColor(format.getColor());

    // Border code courtesy of Khadiyd Idris <*****@*****.**>
    Border b = field.getBorderOrDefault();
    String bcolor = "black";
    if (b.getColor() != null) {
      bcolor =
          "#"
              + Integer.toHexString(b.getColor().getRed())
              + Integer.toHexString(b.getColor().getGreen())
              + Integer.toHexString(b.getColor().getBlue());
    }

    if (b.getTop() != null)
      out.print("border-top: solid " + bcolor + " " + b.getTop().getThickness() + "pt; ");
    if (b.getLeft() != null)
      out.print("border-left: solid " + bcolor + " " + b.getLeft().getThickness() + "pt; ");
    if (b.getBottom() != null)
      out.print("border-bottom: solid " + bcolor + " " + b.getBottom().getThickness() + "pt; ");
    if (b.getRight() != null)
      out.print("border-right: solid " + bcolor + " " + b.getRight().getThickness() + "pt; ");

    out.print("\">");

    if (format.isBold()) out.print("<b>");
    if (format.isItalic()) out.print("<i>");
    if (format.isUnderline()) out.print("<u>");

    String str = field.toString();
    if (str == null || str.length() == 0) str = "&nbsp;";

    // Fix courtesy of Brendon Price <*****@*****.**>
    if ("&nbsp;".equals(str)) out.print(str);
    else out.print(StringUtils.newlinesToXHTMLBreaks(StringUtils.escapeHTML(str)));

    if (format.isUnderline()) out.print("</u>");
    if (format.isItalic()) out.print("</i>");
    if (format.isBold()) out.print("</b>");
    out.print("</span>");

    outputCellEnd();
  }