示例#1
0
  public boolean onStylusRelease(int x, int y) {
    if (super.onStylusRelease(x, y)) {
      return false;
    }

    ZLTextElementArea area = getElementByCoordinates(x, y);
    if (area != null) {
      ZLTextElement element = area.Element;
      if ((element instanceof ZLTextImageElement) || (element instanceof ZLTextWord)) {
        final ZLTextWordCursor cursor = new ZLTextWordCursor(StartCursor);
        cursor.moveToParagraph(area.ParagraphIndex);
        cursor.moveToParagraphStart();
        final int elementIndex = area.TextElementIndex;
        byte hyperlinkKind = FBTextKind.REGULAR;
        String id = null;
        for (int i = 0; i < elementIndex; ++i) {
          ZLTextElement e = cursor.getElement();
          if (e instanceof ZLTextControlElement) {
            if (e instanceof ZLTextHyperlinkControlElement) {
              final ZLTextHyperlinkControlElement control = (ZLTextHyperlinkControlElement) e;
              hyperlinkKind = control.Kind;
              id = control.Label;
            } else {
              final ZLTextControlElement control = (ZLTextControlElement) e;
              if (!control.IsStart && (control.Kind == hyperlinkKind)) {
                hyperlinkKind = FBTextKind.REGULAR;
                id = null;
              }
            }
          }
          cursor.nextWord();
        }
        if (id != null) {
          switch (hyperlinkKind) {
            case FBTextKind.EXTERNAL_HYPERLINK:
              if (OpenInBrowserOption.getValue()) {
                ZLibrary.Instance().openInBrowser(id);
              }
              return true;
            case FBTextKind.FOOTNOTE:
            case FBTextKind.INTERNAL_HYPERLINK:
              ((FBReader) Application).tryOpenFootnote(id);
              return true;
          }
        }
      }
    }
    return false;
  }
 public ArrayList<Integer> getParagraphWordIndices(int paragraphIndex) {
   final ArrayList<Integer> indices = new ArrayList<Integer>();
   final ZLTextWordCursor cursor =
       new ZLTextWordCursor(getReader().getTextView().getStartCursor());
   cursor.moveToParagraph(paragraphIndex);
   cursor.moveToParagraphStart();
   while (!cursor.isEndOfParagraph()) {
     ZLTextElement element = cursor.getElement();
     if (element instanceof ZLTextWord) {
       indices.add(cursor.getElementIndex());
     }
     cursor.nextWord();
   }
   return indices;
 }
 public List<String> getParagraphWords(int paragraphIndex) {
   final ArrayList<String> words = new ArrayList<String>();
   final ZLTextWordCursor cursor =
       new ZLTextWordCursor(getReader().getTextView().getStartCursor());
   cursor.moveToParagraph(paragraphIndex);
   cursor.moveToParagraphStart();
   while (!cursor.isEndOfParagraph()) {
     ZLTextElement element = cursor.getElement();
     if (element instanceof ZLTextWord) {
       words.add(element.toString());
     }
     cursor.nextWord();
   }
   return words;
 }
 public String getParagraphText(int paragraphIndex) {
   final StringBuffer sb = new StringBuffer();
   final ZLTextWordCursor cursor =
       new ZLTextWordCursor(getReader().getTextView().getStartCursor());
   cursor.moveToParagraph(paragraphIndex);
   cursor.moveToParagraphStart();
   while (!cursor.isEndOfParagraph()) {
     ZLTextElement element = cursor.getElement();
     if (element instanceof ZLTextWord) {
       sb.append(element.toString() + " ");
     }
     cursor.nextWord();
   }
   return sb.toString();
 }
示例#5
0
  private String createBookmarkText(ZLTextWordCursor cursor) {
    cursor = new ZLTextWordCursor(cursor);

    final StringBuilder builder = new StringBuilder();
    final StringBuilder sentenceBuilder = new StringBuilder();
    final StringBuilder phraseBuilder = new StringBuilder();

    int wordCounter = 0;
    int sentenceCounter = 0;
    int storedWordCounter = 0;
    boolean lineIsNonEmpty = false;
    boolean appendLineBreak = false;
    mainLoop:
    while ((wordCounter < 20) && (sentenceCounter < 3)) {
      while (cursor.isEndOfParagraph()) {
        if (!cursor.nextParagraph()) {
          break mainLoop;
        }
        if ((builder.length() > 0) && cursor.getParagraphCursor().isEndOfSection()) {
          break mainLoop;
        }
        if (phraseBuilder.length() > 0) {
          sentenceBuilder.append(phraseBuilder);
          phraseBuilder.delete(0, phraseBuilder.length());
        }
        if (sentenceBuilder.length() > 0) {
          if (appendLineBreak) {
            builder.append("\n");
          }
          builder.append(sentenceBuilder);
          sentenceBuilder.delete(0, sentenceBuilder.length());
          ++sentenceCounter;
          storedWordCounter = wordCounter;
        }
        lineIsNonEmpty = false;
        if (builder.length() > 0) {
          appendLineBreak = true;
        }
      }
      final ZLTextElement element = cursor.getElement();
      if (element instanceof ZLTextWord) {
        final ZLTextWord word = (ZLTextWord) element;
        if (lineIsNonEmpty) {
          phraseBuilder.append(" ");
        }
        phraseBuilder.append(word.Data, word.Offset, word.Length);
        ++wordCounter;
        lineIsNonEmpty = true;
        switch (word.Data[word.Offset + word.Length - 1]) {
          case ',':
          case ':':
          case ';':
          case ')':
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            break;
          case '.':
          case '!':
          case '?':
            ++sentenceCounter;
            if (appendLineBreak) {
              builder.append("\n");
              appendLineBreak = false;
            }
            sentenceBuilder.append(phraseBuilder);
            phraseBuilder.delete(0, phraseBuilder.length());
            builder.append(sentenceBuilder);
            sentenceBuilder.delete(0, sentenceBuilder.length());
            storedWordCounter = wordCounter;
            break;
        }
      }
      cursor.nextWord();
    }
    if (storedWordCounter < 4) {
      if (sentenceBuilder.length() == 0) {
        sentenceBuilder.append(phraseBuilder);
      }
      if (appendLineBreak) {
        builder.append("\n");
      }
      builder.append(sentenceBuilder);
    }
    return builder.toString();
  }