Package org.jfree.layouting.layouter.context

Examples of org.jfree.layouting.layouter.context.LayoutContext


   */
  public void resolve (final LayoutProcess process,
                       final LayoutElement currentNode,
                       final StyleKey key)
  {
    final LayoutContext layoutContext = currentNode.getLayoutContext();
    final CSSValue value = layoutContext.getValue(ContentStyleKeys.MOVE_TO);

    // Maybe this is a 'normal'.
    if (MoveToValues.NORMAL.equals(value))
    {
      if ("alternate".equals(layoutContext.getPseudoElement()))
      {
        // For '::alternate' pseudo-elements, if the superior parent uses
        // the 'footnote' counter in its 'content' property then the computed
        // value of 'move-to' is 'footnotes'.
        if (isCounterUsed(currentNode.getParent(), "footnote"))
        {
          layoutContext.setValue(ContentStyleKeys.MOVE_TO,
              new CSSStringValue(CSSStringType.STRING, "footnotes"));
          return;
        }

        // For '::alternate' pseudo-elements, if the superior parent uses
        // the 'endnote' counter in its 'content' property then the computed
        // value of 'move-to' is 'endnotes'.
        if (isCounterUsed(currentNode.getParent(), "endnote"))
        {
          layoutContext.setValue(ContentStyleKeys.MOVE_TO,
              new CSSStringValue(CSSStringType.STRING, "endnotes"));
          return;
        }

        // For '::alternate' pseudo-elements, if the superior parent uses
        // the 'section-note' counter in its 'content' property then the
        // computed value of 'move-to' is 'section-notes'.
        if (isCounterUsed(currentNode.getParent(), "section-note"))
        {
          layoutContext.setValue(ContentStyleKeys.MOVE_TO,
              new CSSStringValue(CSSStringType.STRING, "section-notes"));
          return;
        }
      }
      layoutContext.setValue(ContentStyleKeys.MOVE_TO, MoveToValues.HERE);
    }
  }
View Full Code Here


  public void resolve(final LayoutProcess process,
                      final LayoutElement currentNode,
                      final StyleKey key)
  {
    final LayoutContext layoutContext = currentNode.getLayoutContext();
    final CSSValue value = layoutContext.getValue(key);
    final LayoutElement parent = currentNode.getParent();
    final FontSpecification fontSpecification =
        currentNode.getLayoutContext().getFontSpecification();

    if (value instanceof CSSNumericValue == false)
    {
      if (parent == null)
      {
        fontSpecification.setFontSize(this.baseFontSize);
        layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, baseFontSize));
      }
      else
      {
        final LayoutContext parentContext = parent.getLayoutContext();
        final FontSpecification parentFont = parentContext.getFontSpecification();
        final double fontSize = parentFont.getFontSize();
        fontSpecification.setFontSize(fontSize);
        layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, fontSize));
      }
      return;
    }

    final CSSNumericValue nval = (CSSNumericValue) value;
    if (CSSValueResolverUtility.isAbsoluteValue(nval))
    {
      final CSSNumericValue fsize = CSSValueResolverUtility.convertLength
          (nval, currentNode.getLayoutContext(), process.getOutputMetaData());
      final double fontSize = fsize.getValue();
      fontSpecification.setFontSize(fontSize);
      layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, fontSize));
    }
    // we encountered one of the relative values.
    else if (CSSNumericType.EM.equals(nval.getType()))
    {
      final double parentSize;
      if (parent == null)
      {
        parentSize = this.baseFontSize;
      }
      else
      {
        final LayoutContext parentContext = parent.getLayoutContext();
        final FontSpecification parentFont = parentContext.getFontSpecification();
        parentSize = parentFont.getFontSize();
      }
      final double fontSize = parentSize * nval.getValue();
      fontSpecification.setFontSize(fontSize);
      layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, fontSize));
    }
    else if (CSSNumericType.EX.equals(nval.getType()))
    {
      final double parentSize;
      if (parent == null)
      {
        // if we have no parent, we create a fixed default value.
        parentSize = this.baseFontSize * LibFontsDefaults.DEFAULT_XHEIGHT_SIZE / LibFontsDefaults.DEFAULT_ASCENT_SIZE;
      }
      else
      {
        final LayoutContext parentContext = parent.getLayoutContext();
        final FontSpecification parentFont = parentContext.getFontSpecification();
        parentSize = parentFont.getFontSize();
      }
      final double fontSize = parentSize * nval.getValue();
      layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, fontSize));
      fontSpecification.setFontSize(fontSize);
    }
    else if (CSSNumericType.PERCENTAGE.equals(nval.getType()))
    {
      final double parentSize;
      if (parent == null)
      {
        // if we have no parent, we create a fixed default value.
        parentSize = this.baseFontSize;
      }
      else
      {
        final LayoutContext parentContext = parent.getLayoutContext();
        final FontSpecification parentFont = parentContext.getFontSpecification();
        parentSize = parentFont.getFontSize();
      }
      final double fontSize = parentSize * nval.getValue() / 100.0d;
      fontSpecification.setFontSize(fontSize);
      layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, fontSize));
View Full Code Here

            (OutputProcessorFeature.BACKGROUND_IMAGE) == false)
    {
      return;
    }

    final LayoutContext layoutContext = currentNode.getLayoutContext();
    final CSSValue value = layoutContext.getValue(key);
    if (value == null)
    {
      return;
    }
    if (value instanceof CSSValueList == false)
    {
      return;
    }

    final CSSValueList list = (CSSValueList) value;
    final int length = list.getLength();
    if (length == 0)
    {
      return;
    }
    final BackgroundSpecification backgroundSpecification =
            layoutContext.getBackgroundSpecification();
    final ResourceKey baseURL = DocumentContextUtility.getBaseResource
        (process.getDocumentContext());

    for (int i = 0; i < length; i++)
    {
View Full Code Here

    }
  }

  private void buildStyle(final RenderBox box, final StyleBuilder builder)
  {
    final LayoutContext layoutContext = box.getLayoutContext();
    if (layoutContext == null)
    {
      // this is either the logical page box or one of the direct anchestors
      // of said box.
      return;
    }

    final FontSpecification fs = layoutContext.getFontSpecification();
    final double fontSize = fs.getFontSize();
    builder.append(FontStyleKeys.FONT_SIZE, toPointString(fontSize), "pt");
    builder.append(FontStyleKeys.FONT_FAMILY, fs.getFontFamily());
    builder.append(FontStyleKeys.FONT_WEIGHT,
        layoutContext.getValue(FontStyleKeys.FONT_WEIGHT));
    builder.append(FontStyleKeys.FONT_STYLE,
        layoutContext.getValue(FontStyleKeys.FONT_STYLE));
    builder.append(TextStyleKeys.TEXT_ALIGN, layoutContext.getValue(TextStyleKeys.TEXT_ALIGN));
    builder.append(TextStyleKeys.TEXT_ALIGN_LAST, layoutContext.getValue(TextStyleKeys.TEXT_ALIGN_LAST));

    final NodeLayoutProperties nlp = box.getNodeLayoutProperties();
    //final BoxLayoutProperties blp = box.getBoxLayoutProperties();
    final ComputedLayoutProperties sblp = box.getComputedLayoutProperties();
    builder.append(LineStyleKeys.VERTICAL_ALIGN, nlp.getVerticalAlignment());

    if (sblp.getPaddingTop() > 0 ||
        sblp.getPaddingLeft() > 0 ||
        sblp.getPaddingBottom() > 0 ||
        sblp.getPaddingRight() > 0)
    {
      if (sblp.getPaddingTop() > 0 || assumeZeroPaddings == false)
      {
        builder.append(BoxStyleKeys.PADDING_TOP,
            toPointString(sblp.getPaddingTop()), "pt");
      }
      if (sblp.getPaddingLeft() > 0 || assumeZeroPaddings == false)
      {
        builder.append(BoxStyleKeys.PADDING_LEFT,
            toPointString(sblp.getPaddingLeft()), "pt");
      }
      if (sblp.getPaddingBottom() > 0 || assumeZeroPaddings == false)
      {
        builder.append(BoxStyleKeys.PADDING_BOTTOM,
            toPointString(sblp.getPaddingBottom()), "pt");
      }
      if (sblp.getPaddingRight() > 0 || assumeZeroPaddings == false)
      {
        builder.append(BoxStyleKeys.PADDING_RIGHT,
            toPointString(sblp.getPaddingRight()), "pt");
      }
    }
    else if (assumeZeroPaddings == false)
    {
      builder.append("padding", false, "0");
    }

    if (sblp.getMarginLeft() != 0 ||
        sblp.getMarginRight() != 0 ||
        sblp.getMarginTop() != 0 ||
        sblp.getMarginBottom() != 0)
    {
      if (sblp.getMarginLeft() > 0 || assumeZeroMargins == false)
      {
        builder.append(BoxStyleKeys.MARGIN_LEFT,
            toPointString(sblp.getMarginLeft()), "pt");
      }
      if (sblp.getMarginRight() > 0 || assumeZeroMargins == false)
      {
        builder.append(BoxStyleKeys.MARGIN_RIGHT,
            toPointString(sblp.getMarginRight()), "pt");
      }
      if (sblp.getMarginTop() > 0 || assumeZeroMargins == false)
      {
        builder.append(BoxStyleKeys.MARGIN_TOP,
            toPointString(sblp.getMarginTop()), "pt");
      }
      if (sblp.getMarginBottom() > 0 || assumeZeroMargins == false)
      {
        builder.append(BoxStyleKeys.MARGIN_BOTTOM,
            toPointString(sblp.getMarginBottom()), "pt");
      }
    }
    else if (assumeZeroMargins == false)
    {
      builder.append("margin", false, "0");
    }

    final String bgColor = toColorString(layoutContext.getValue
        (BorderStyleKeys.BACKGROUND_COLOR));
    if (bgColor != null)
    {
      builder.append(BorderStyleKeys.BACKGROUND_COLOR, bgColor);
    }
    final String fgColor = toColorString(layoutContext.getValue(ColorStyleKeys.COLOR));
    if (fgColor != null)
    {
      builder.append(ColorStyleKeys.COLOR, fgColor);
    }

    if (sblp.getBorderTop() > 0 || sblp.getBorderLeft() > 0 ||
        sblp.getBorderBottom() > 0 || sblp.getBorderRight() > 0)
    {
      if (sblp.getBorderTop() > 0)
      {
        builder.append(BorderStyleKeys.BORDER_TOP_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_TOP_COLOR));
        builder.append(BorderStyleKeys.BORDER_TOP_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_TOP_STYLE));
        builder.append(BorderStyleKeys.BORDER_TOP_WIDTH, toPointString(sblp.getBorderTop()), "pt");
      }
      else if (assumeZeroBorders == false)
      {
        builder.append(BorderStyleKeys.BORDER_TOP_STYLE, BorderStyle.NONE);
      }

      if (sblp.getBorderLeft() > 0)
      {
        builder.append(BorderStyleKeys.BORDER_LEFT_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_LEFT_COLOR));
        builder.append(BorderStyleKeys.BORDER_LEFT_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_LEFT_STYLE));
        builder.append(BorderStyleKeys.BORDER_LEFT_WIDTH, toPointString(sblp.getBorderLeft()), "pt");
      }
      else if (assumeZeroBorders == false)
      {
        builder.append(BorderStyleKeys.BORDER_LEFT_STYLE, BorderStyle.NONE);
      }

      if (sblp.getBorderBottom() > 0)
      {
        builder.append(BorderStyleKeys.BORDER_BOTTOM_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_BOTTOM_COLOR));
        builder.append(BorderStyleKeys.BORDER_BOTTOM_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_BOTTOM_STYLE));
        builder.append(BorderStyleKeys.BORDER_BOTTOM_WIDTH, toPointString(sblp.getBorderBottom()), "pt");
      }
      else if (assumeZeroBorders == false)
      {
        builder.append(BorderStyleKeys.BORDER_BOTTOM_STYLE, BorderStyle.NONE);
      }

      if (sblp.getBorderRight() > 0)
      {
        builder.append(BorderStyleKeys.BORDER_RIGHT_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_RIGHT_COLOR));
        builder.append(BorderStyleKeys.BORDER_RIGHT_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_RIGHT_STYLE));
        builder.append(BorderStyleKeys.BORDER_RIGHT_WIDTH, toPointString(sblp.getBorderRight()), "pt");
      }
      else if (assumeZeroBorders == false)
      {
        builder.append(BorderStyleKeys.BORDER_RIGHT_STYLE, BorderStyle.NONE);
View Full Code Here

    final ContextId ctxId = new ContextId
        (ContextId.SOURCE_NORMALIZER, NO_PARENT, nextId);
    nextId += 1;

    final LayoutContext layoutContext = new DefaultLayoutContext
        (ctxId, namespace, tag, pseudo, attributes);
    final LayoutElement element =
        new LayoutElement(currentElement, currentSilbling, layoutContext);
    currentElement = element;
    currentSilbling = null;
View Full Code Here

   * @throws IOException
   */
  private void startCurrentElement()
      throws NormalizationException, IOException
  {
    final LayoutContext layoutContext = currentElement.getLayoutContext();
    final CSSValue displayRole = layoutContext.getValue(BoxStyleKeys.DISPLAY_ROLE);
    if (DisplayRole.NONE.equals(displayRole))
    {
      // ignore that element ..
      ignoreContext += 1;
      Log.debug("Ignoring element (and all childs) of " +
          layoutContext.getPseudoElement() +
          " as it has Display:NONE");
    }
    else if (ignoreContext > 0)
    {
      // keep track of our distance to the first hidden element
      ignoreContext += 1;
    }

//    Log.debug ("Element " + layoutContext.getTagName() + " " + displayRole);

    // update counters and strings ...
    if (DisplayRole.LIST_ITEM.equals(displayRole))
    {
      currentElement.incrementCounter("list-item", 1);
    }

    if (ignoreContext > 0)
    {
      return;
    }

    // check, whether the element allows content at all..
    // isAllowContentProcessing is false, if the 'content' property
    // had been set to 'none' or 'inhibit'.
    final ContentSpecification contentSpec =
        currentElement.getLayoutContext().getContentSpecification();
    if (contentSpec.isAllowContentProcessing() == false)
    {
      // Quote-the-standard:
      // -------------------
      // On elements, this inhibits the children of the element from
      // being rendered as children of this element, as if the element
      // was empty.
      //
      // On pseudo-elements, this inhibits the creation of the pseudo-element,
      // as if 'display' computed to 'none'.
      //
      // In both cases, this further inhibits the creation of any
      // pseudo-elements which have this pseudo-element as a superior.
      if (contentSpec.isInhibitContent() &&
          layoutContext.isPseudoElement())
      {
//          Log.debug("Starting to ignore childs of psuedo element " +
//                  layoutContext.getTagName() + ":" +
//                  layoutContext.getPseudoElement() +
//                  " as it inhibits content creation.");
View Full Code Here

  }

  protected boolean generateBeforePseudoElements(final LayoutElement element)
      throws IOException, NormalizationException
  {
    final LayoutContext layoutContext = element.getLayoutContext();

    final CSSValue displayRole = layoutContext.getValue(BoxStyleKeys.DISPLAY_ROLE);
    if (DisplayRole.LIST_ITEM.equals(displayRole))
    {
      if (styleResolver.isPseudoElementStyleResolvable(element, "marker"))
      {
        startElementInternal(layoutContext.getNamespace(),
            layoutContext.getTagName(), "marker",
            layoutContext.getAttributes());
        endElement();
      }
    }

    // it might be against the standard, but we do not accept the
    // contents-token here.
    if (styleResolver.isPseudoElementStyleResolvable(element, "before"))
    {
      startElementInternal(layoutContext.getNamespace(),
          layoutContext.getTagName(), "before",
          layoutContext.getAttributes());
      endElement();
    }

    return false;
  }
View Full Code Here

      return false;
    }
    // we do not generate an alternate element, if there is no need to do so.
    if (styleResolver.isPseudoElementStyleResolvable(element, "alternate"))
    {
      final LayoutContext layoutContext = element.getLayoutContext();
      startElementInternal(layoutContext.getNamespace(),
          layoutContext.getTagName(), "alternate",
          layoutContext.getAttributes());
      if (element.isContentsConsumed())
      {
        // if the alternate element consumes the content, fine. We have
        // to close the element later ..
        element.openAlternate();
View Full Code Here

  }

  private boolean generateOutsidePseudoElements(final LayoutElement element)
      throws IOException, NormalizationException
  {
    final LayoutContext layoutContext = element.getLayoutContext();

    final CSSValue value = layoutContext.getValue(ContentStyleKeys.MOVE_TO);
    if (MoveToValues.HERE.equals(value) == false)
    {
      // Some moved content.
      final String target;
      if (value == null)
      {
        target = null;
      }
      else if (value instanceof CSSStringValue)
      {
        final CSSStringValue sval = (CSSStringValue) value;
        target = sval.getValue();
      }
      else
      {
        target = value.getCSSText();
      }

      layoutContext.getContentSpecification().setMoveTarget(target);

      // we do not generate an alternate element, if there is no need to do so.
      if (styleResolver.isPseudoElementStyleResolvable(element, "alternate"))
      {
        startElementInternal(layoutContext.getNamespace(),
            layoutContext.getTagName(), "alternate",
            layoutContext.getAttributes());
        if (element.isContentsConsumed())
        {
          // if the alternate element consumes the content, fine. We have
          // to close the element later ..
          element.openAlternate();
View Full Code Here

        element.getLayoutContext().getContentSpecification();
    final ContentToken[] strings = contentSpecification.getStrings();

    // todo: This might be invalid.

    final LayoutContext layoutContext = element.getLayoutContext();
    final CSSValue value = layoutContext.getValue(ContentStyleKeys.STRING_DEFINE);
    if (value == null)
    {
      return false;
    }
    if (value instanceof CSSValueList)
View Full Code Here

TOP

Related Classes of org.jfree.layouting.layouter.context.LayoutContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.