Examples of TextPosition


Examples of org.apache.pdfbox.util.TextPosition

     * {@link #setListItemPatterns(List)}.
     * @param pw
     * @return
     */
    protected Pattern matchListItemPattern(PositionWrapper pw) {
        TextPosition tp = pw.getTextPosition();
        String txt = tp.getCharacter();
        Pattern p = matchPattern(txt,getListItemPatterns());
        return p;
    }
View Full Code Here

Examples of org.apache.pdfbox.util.TextPosition

    prevLineY = lineY;

    float start = getFirstTrimmed(line).getX();
    //    leftMargin += start;
    incrementOrAdd(leftMargin, start);
    TextPosition lastTrimmed = getLastTrimmed(line);
    float end = lastTrimmed.getX() + lastTrimmed.getWidth();
    //    rightMargin += end;
    incrementOrAdd(rightMargin, end);

    Float fontSize;
    for (TextPosition t : line) {
View Full Code Here

Examples of org.apache.pdfbox.util.TextPosition

  private String lastStyle = null;
  private float prevLineY = -1f;
  private boolean pageBreak = false;

  protected void printImage(List<TextPosition> line) throws IOException {
    TextPosition start = getFirstTrimmed(line);
    float y = start.getY();
    for (Entry<Float, Image> entry : pageImages.entrySet()) {
      if (entry.getKey() < y) {
        Image image = entry.getValue();
        String name = imageStripper.printImage(image);
        pageImages.remove(entry.getKey());
View Full Code Here

Examples of org.apache.pdfbox.util.TextPosition

    if (line.size() < 1) {
      return;
    }

    float start = -1;
    TextPosition firstText = getFirstTrimmed(line);
    start = firstText.getX();
    if (start == -1 || firstText.getCharacter().trim().isEmpty()) {
      return;
    }

    float end = -1;
    TextPosition lastText = getLastTrimmed(line);
    end = lastText.getX() + lastText.getWidth();
    if (end == -1 || lastText.getCharacter().trim().isEmpty()) {
      return;
    }

    if (start > maxLeftMargin /*&& end < minRightMargin*/) {
      // too much lineSpacing
View Full Code Here

Examples of org.apache.pdfbox.util.TextPosition

       * if so, is it dominant. */
      int ltrCnt = 0;
      int rtlCnt = 0;

      while (textIter.hasNext()) {
        TextPosition position = textIter.next();
        String stringValue = position.getCharacter();
        for (int a = 0; a < stringValue.length(); a++) {
          byte dir = Character.getDirectionality(stringValue.charAt(a));
          if ((dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT)
            || (dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING)
            || (dir == Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE)) {
            ltrCnt++;
          } else if ((dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT)
            || (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC)
            || (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING)
            || (dir == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE)) {
            rtlCnt++;
          }
        }
      }

      // choose the dominant direction
      boolean isRtlDominant = rtlCnt > ltrCnt;

      startArticle(!isRtlDominant);
      startOfArticle = true;
      // we will later use this to skip reordering
      boolean hasRtl = rtlCnt > 0;

      /* Now cycle through to print the text.
       * We queue up a line at a time before we print so that we can convert
       * the line from presentation form to logical form (if needed).
       */
      List<TextPosition> line = new ArrayList<TextPosition>();

      textIter = textList.iterator(); // start from the beginning again
      /* PDF files don't always store spaces. We will need to guess where we should add
       * spaces based on the distances between TextPositions. Historically, this was done
       * based on the size of the space character provided by the font. In general, this worked
       * but there were cases where it did not work. Calculating the average character width
       * and using that as a metric works better in some cases but fails in some cases where the
       * spacing worked. So we use both. NOTE: Adobe reader also fails on some of these examples.
       */
      //Keeps track of the previous average character width
      float previousAveCharWidth = -1;
      while (textIter.hasNext()) {
        TextPosition position = textIter.next();
        PositionWrapper current = new PositionWrapper(position);
        String characterValue = position.getCharacter();

        //Resets the average character width when we see a change in font
        // or a change in the font size
        if (lastPosition != null
          && ((position.getFont() != lastPosition.getTextPosition().getFont()) || (position.getFontSize() != lastPosition
            .getTextPosition().getFontSize()))) {
          previousAveCharWidth = -1;
        }

        float positionX;
        float positionY;
        float positionWidth;
        float positionHeight;

        /* If we are sorting, then we need to use the text direction
         * adjusted coordinates, because they were used in the sorting. */
        if (getSortByPosition()) {
          positionX = position.getXDirAdj();
          positionY = position.getYDirAdj();
          positionWidth = position.getWidthDirAdj();
          positionHeight = position.getHeightDir();
        } else {
          positionX = position.getX();
          positionY = position.getY();
          positionWidth = position.getWidth();
          positionHeight = position.getHeight();
        }

        //The current amount of characters in a word
        int wordCharCount = position.getIndividualWidths().length;

        /* Estimate the expected width of the space based on the
         * space character with some margin. */
        float wordSpacing = position.getWidthOfSpace();
        float deltaSpace = 0;
        if ((wordSpacing == 0) || (wordSpacing == Float.NaN)) {
          deltaSpace = Float.MAX_VALUE;
        } else {
          if (lastWordSpacing < 0) {
View Full Code Here

Examples of org.pdfbox.util.TextPosition

    }

    private Map coalesceLine(Map input) {
      final Map output = new TreeMap();
      final Iterator kit = input.keySet().iterator();
      TextPosition lastFragment = null;
        String lastString = null;
        Integer lastKey = null;
        while (kit.hasNext())
        {
          final Integer key = (Integer) kit.next();
          final TextPosition thisFragment = (TextPosition) input.get(key);
            if (lastFragment != null && adjacent(lastFragment, thisFragment))
            {
                lastFragment = thisFragment;
                lastString += thisFragment.getCharacter();
            }
            else
            {
                if (lastFragment != null)
                {
                    output.put(lastKey, lastString);
                }
                lastFragment = thisFragment;
                lastString = thisFragment.getCharacter();
                lastKey = key;
            }
            if (lastFragment != null)
            {
                output.put(lastKey, lastString);
View Full Code Here

Examples of org.pdfbox.util.TextPosition

    }

    private void regroup(final List fragments, final Map lines)
    {
        for (int i = 0; i < fragments.size(); i++) {
          final TextPosition textPosition = (TextPosition) fragments.get(i);
          final Integer y = new Integer((int)textPosition.getY());
          final Integer x = new Integer((int)textPosition.getX());
          final Map pieces;
            if (lines.containsKey(y)) {
                pieces = (TreeMap) lines.get(y);
            } else {
                pieces = new TreeMap();
View Full Code Here

Examples of org.spockframework.runtime.model.TextPosition

  // startColumns.get(i) is the first non-empty column of lines.get(i)
  private final List<Integer> startColumns = new ArrayList<Integer>();

  private ExpressionInfoRenderer(ExpressionInfo expr) {
    TextPosition start = expr.getRegion().getStart();
    if (start.getLine() != 1 || start.getColumn() != 1)
      throw new IllegalArgumentException("can only print expressions starting at 1,1");
    if (expr.getRegion().getEnd().getLine() != 1)
      throw new IllegalArgumentException("can only print expressions ending on line 1");
    this.expr = expr;
  }
View Full Code Here

Examples of spatschorke.da.ooconnector.TextPosition

    ISearchResult searchResult = textDocument.getSearchService().findAll(
        searchDescriptor);

    List<IArtefactPosition> positions = new ArrayList<IArtefactPosition>();
    for (ITextRange textRange : searchResult.getTextRanges()) {
      OOArtefactPosition position = new TextPosition(ooDocument,
          textRange);
      positions.add(position);
    }
    return positions;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.