Ejemplo n.º 1
0
  private static void renderText(List<DisplayCommand> displayList, InlineBox layoutBox) {
    // there needs to be some major refactoring before this is less ugly.
    // TODO eliminate the current wonky lookup for extracting a node
    // TODO include the parent box when rendering text without using this
    // check
    // FIXME text rendering is not contained because inline layout and
    // cascading(?) do not exist yet.
    Node sourceNode = layoutBox.getStyledNode().getNode();

    if (sourceNode.getType() == NodeType.TEXT) {
      Optional<Color> colorVal = getColor(layoutBox, "color");
      Color fontColor = colorVal.orElse(Color.BLACK);

      Dimensions dims = layoutBox.getDimensions();
      Rect paddingBox = dims.paddingBox();
      String text = ((TextNode) sourceNode).getText();
      Deque<LineBox> lines = layoutBox.getLines();

      // displayList.add(new RenderText(text, lines, paddingBox,
      // fontColor));
    }
  }
Ejemplo n.º 2
0
  private static void renderBorders(List<DisplayCommand> displayList, LayoutBox layoutBox) {
    Optional<Color> colorVal = getColor(layoutBox, "border-color");

    if (colorVal.isPresent()) {
      Color color = colorVal.get();
      Dimensions dims = layoutBox.getDimensions();
      Rect borderBox = dims.borderBox();

      // left border
      displayList.add(
          new SolidColor(
              color, new Rect(borderBox.x, borderBox.y, dims.border.left, borderBox.height)));
      // right border
      displayList.add(
          new SolidColor(
              color,
              new Rect(
                  borderBox.x + borderBox.width - dims.border.right,
                  borderBox.y,
                  dims.border.right,
                  borderBox.height)));
      // top border
      displayList.add(
          new SolidColor(
              color, new Rect(borderBox.x, borderBox.y, borderBox.width, dims.border.top)));
      // bottom border
      displayList.add(
          new SolidColor(
              color,
              new Rect(
                  borderBox.x,
                  borderBox.y + borderBox.height - dims.border.bottom,
                  borderBox.width,
                  dims.border.bottom)));
    }
  }
Ejemplo n.º 3
0
  private static void renderLayoutBox(List<DisplayCommand> displayList, LayoutBox layoutBox) {
    System.out.println(layoutBox);
    switch (layoutBox.getType()) {
      case BLOCK_NODE:
        renderBackground(displayList, layoutBox);
        renderBorders(displayList, layoutBox);
        for (LayoutBox child : layoutBox.getChildren()) {
          renderLayoutBox(displayList, child);
        }
        break;
      case INLINE_NODE:
        InlineBox box = (InlineBox) layoutBox;
        Optional<Color> colorVal = getColor(layoutBox, "border-color");
        Dimensions dims = layoutBox.getDimensions();
        Rect borderBox = dims.borderBox();
        Deque<LineBox> lines = box.getLines();

        if (colorVal.isPresent()) {
          Color color = colorVal.get();
          LineBox firstLine = lines.getFirst();
          float boxHeight = firstLine.getBoxHeight();
          float lineHeight = firstLine.getLineHeight();
          float borderHeight = lineHeight + dims.border.top + dims.border.bottom;

          // left border
          displayList.add(
              new SolidColor(
                  color,
                  new Rect(
                      borderBox.x,
                      borderBox.y + boxHeight - lineHeight,
                      dims.border.left,
                      borderHeight)));

          LineBox lastLine = lines.getLast();
          // right border
          displayList.add(
              new SolidColor(
                  color,
                  new Rect(
                      borderBox.x
                          + lastLine.getFilledWidth()
                          + dims.border.left
                          + dims.border.right,
                      borderBox.y + borderHeight * (lines.size() - 1),
                      dims.border.right,
                      borderHeight)));

          float lineX = dims.content.x - dims.border.left;
          float lineY = dims.content.y;

          for (LineBox line : box.getLines()) {
            // TODO proper line-height calculations
            float lineWidth = line.getFilledWidth() + dims.border.left + dims.border.right;

            // top border
            displayList.add(
                new SolidColor(
                    color, new Rect(lineX, lineY - dims.border.top, lineWidth, dims.border.top)));
            // bottom border
            displayList.add(
                new SolidColor(
                    color, new Rect(lineX, lineY + lineHeight, lineWidth, dims.border.bottom)));

            lineY += borderHeight;
          }
        }
        break;
      default:
        break;
    }
  }