本文整理了Java中com.koolearn.klibrary.text.view.ZLTextWordCursor
类的一些代码示例,展示了ZLTextWordCursor
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZLTextWordCursor
类的具体详情如下:
包路径:com.koolearn.klibrary.text.view.ZLTextWordCursor
类名称:ZLTextWordCursor
[英]第几段 This is KooReader. 第几个单词 KooReader 第几个字母 R
[中]第几段 我是库雷德。第几个单词 库雷德第几个字母 R
代码示例来源:origin: Jiangzqts/EpubRead
if (cursor.isNull()) {
cursor = view.getEndCursor();
if (cursor.isNull()) {
return;
cursor = new ZLTextWordCursor(cursor);
cursor.moveTo(bookmark);
for (int count = bookmark.getLength(); count > 0; cursor.nextWord()) {
while (cursor.isEndOfParagraph()) {
if (!cursor.nextParagraph()) {
break mainLoop;
final ZLTextElement element = cursor.getElement();
if (element instanceof ZLTextWord) {
if (word != null) {
bookmark.setEnd(cursor.getParagraphIndex(), cursor.getElementIndex(), word.Length);
代码示例来源:origin: Jiangzqts/EpubRead
boolean intersects(ZLTextPage page) {
return
!isEmpty() &&
!page.StartCursor.isNull() && !page.EndCursor.isNull() &&
page.StartCursor.compareTo(getEndPosition()) < 0 &&
page.EndCursor.compareTo(getStartPosition()) > 0;
}
代码示例来源:origin: ydcx/KooReader
private void skip(ZLTextPage page, ZLTextWordCursor cursor, int unit, int size) {
final ZLTextParagraphCursor paragraphCursor = cursor.getParagraphCursor();
if (paragraphCursor == null) {
return;
}
final int endElementIndex = paragraphCursor.getParagraphLength();
resetTextStyle();
applyStyleChanges(paragraphCursor, 0, cursor.getElementIndex());
ZLTextLineInfo info = null;
while (!cursor.isEndOfParagraph() && size > 0) {
info = processTextLine(page, paragraphCursor, cursor.getElementIndex(), cursor.getCharIndex(), endElementIndex, info);
cursor.moveTo(info.EndElementIndex, info.EndCharIndex);
size -= infoSize(info, unit);
}
}
代码示例来源:origin: Jiangzqts/EpubRead
public boolean canFindNext() {
final ZLTextWordCursor end = myCurrentPage.EndCursor;
return !end.isNull() && (myModel != null) && (myModel.getNextMark(end.getMark()) != null);
}
代码示例来源:origin: ydcx/KooReader
public void gotoHome() {
final ZLTextWordCursor cursor = getStartCursor();
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphIndex() == 0) {
return;
}
gotoPosition(0, 0, 0);
preparePaintInfo();
}
代码示例来源:origin: ydcx/KooReader
private ZLTextWordCursor findStart(ZLTextPage page, ZLTextWordCursor end, int unit, int height) {
final ZLTextWordCursor start = new ZLTextWordCursor(end);
ParagraphSize size = paragraphSize(page, start, true, unit);
height -= size.Height;
boolean positionChanged = !start.isStartOfParagraph();
start.moveToParagraphStart();
while (height > 0) {
final ParagraphSize previousSize = size;
if (positionChanged && start.getParagraphCursor().isEndOfSection()) {
break;
if (!start.previousParagraph()) {
break;
if (!start.getParagraphCursor().isEndOfSection()) {
positionChanged = true;
boolean sameStart = start.samePositionAs(end);
if (!sameStart && start.isEndOfParagraph() && end.isStartOfParagraph()) {
ZLTextWordCursor startCopy = new ZLTextWordCursor(start);
startCopy.nextParagraph();
sameStart = startCopy.samePositionAs(end);
start.setCursor(findStart(page, end, SizeUnit.LINE_UNIT, 1));
代码示例来源:origin: ydcx/KooReader
public AutoTextSnippet(ZLTextWordCursor start, int maxChars) {
System.err.println("AutoTextSnippet " + maxChars);
final ZLTextWordCursor cursor = new ZLTextWordCursor(start);
mainLoop:
while (buffer.Builder.length() + sentenceBuffer.Builder.length() + phraseBuffer.Builder.length() < maxChars && sentenceCounter < maxChars / 20) {
while (cursor.isEndOfParagraph()) {
if (!cursor.nextParagraph()) {
break mainLoop;
if (!buffer.isEmpty() && cursor.getParagraphCursor().isLikeEndOfSection()) {
break mainLoop;
final ZLTextElement element = cursor.getElement();
if (element == ZLTextElement.HSpace) {
if (lineIsNonEmpty) {
final ZLTextWord word = (ZLTextWord)element;
phraseBuffer.Builder.append(word.Data, word.Offset, word.Length);
phraseBuffer.Cursor.setCursor(cursor);
phraseBuffer.Cursor.setCharIndex(word.Length);
++wordCounter;
lineIsNonEmpty = true;
cursor.nextWord();
cursor.isEndOfText() || cursor.getParagraphCursor().isLikeEndOfSection();
代码示例来源:origin: Jiangzqts/EpubRead
break;
case PaintStateEnum.TO_SCROLL_FORWARD:
if (!page.EndCursor.isEndOfText()) {
final ZLTextWordCursor startCursor = new ZLTextWordCursor();
switch (myScrollingMode) {
case ScrollingMode.NO_OVERLAPPING:
case ScrollingMode.SCROLL_LINES:
page.findLineFromStart(startCursor, myOverlappingValue);
if (startCursor.isEndOfParagraph()) {
startCursor.nextParagraph();
if (!startCursor.isNull() && startCursor.samePositionAs(page.StartCursor)) {
page.findLineFromStart(startCursor, 1);
if (!startCursor.isNull()) {
final ZLTextWordCursor endCursor = new ZLTextWordCursor();
buildInfos(page, startCursor, endCursor);
if (!page.isEmptyPage() && (myScrollingMode != ScrollingMode.KEEP_LINES || !endCursor.samePositionAs(page.EndCursor))) {
page.StartCursor.setCursor(startCursor);
page.EndCursor.setCursor(endCursor);
break;
page.StartCursor.setCursor(page.EndCursor);
buildInfos(page, page.StartCursor, page.EndCursor);
if (!page.StartCursor.isStartOfText()) {
switch (myScrollingMode) {
case ScrollingMode.NO_OVERLAPPING:
代码示例来源:origin: ydcx/KooReader
private void buildInfos(ZLTextPage page, ZLTextWordCursor start, ZLTextWordCursor result) {
result.setCursor(start);
int textAreaHeight = page.getTextHeight();
page.LineInfos.clear();
final ZLTextLineInfo previousInfo = info;
resetTextStyle();
final ZLTextParagraphCursor paragraphCursor = result.getParagraphCursor();
final int wordIndex = result.getElementIndex();
applyStyleChanges(paragraphCursor, 0, wordIndex);
info = new ZLTextLineInfo(paragraphCursor, wordIndex, result.getCharIndex(), getTextStyle());
final int endIndex = info.ParagraphCursorLength;
while (info.EndElementIndex != endIndex) {
result.moveTo(info.EndElementIndex, info.EndCharIndex);
page.LineInfos.add(info);
if (textAreaHeight < 0) {
nextParagraph = result.isEndOfParagraph() && result.nextParagraph();
if (nextParagraph && result.getParagraphCursor().isEndOfSection()) {
if (page.Column0Height == 0 && page.twoColumnView() && !page.LineInfos.isEmpty()) {
textAreaHeight = page.getTextHeight();
(!result.getParagraphCursor().isEndOfSection() ||
page.LineInfos.size() == page.Column0Height)
);
代码示例来源:origin: Jiangzqts/EpubRead
public final synchronized void gotoPage(int page) {
if (myModel == null || myModel.getParagraphsNumber() == 0) {
return;
}
final float factor = computeCharsPerPage();
final float textSize = page * factor;
int intTextSize = (int) textSize;
int paragraphIndex = myModel.findParagraphByTextLength(intTextSize);
if (paragraphIndex > 0 && myModel.getTextLength(paragraphIndex) > intTextSize) {
--paragraphIndex;
}
intTextSize = myModel.getTextLength(paragraphIndex);
int sizeOfTextBefore = myModel.getTextLength(paragraphIndex - 1);
while (paragraphIndex > 0 && intTextSize == sizeOfTextBefore) {
--paragraphIndex;
intTextSize = sizeOfTextBefore;
sizeOfTextBefore = myModel.getTextLength(paragraphIndex - 1);
}
final int paragraphLength = intTextSize - sizeOfTextBefore;
final int wordIndex;
if (paragraphLength == 0) {
wordIndex = 0;
} else {
preparePaintInfo(myCurrentPage);
final ZLTextWordCursor cursor = new ZLTextWordCursor(myCurrentPage.EndCursor);
cursor.moveToParagraph(paragraphIndex);
wordIndex = cursor.getParagraphCursor().getParagraphLength();
}
gotoPositionByEnd(paragraphIndex, wordIndex, 0);
}
代码示例来源:origin: ydcx/KooReader
myNextPage.reset();
boolean doRepaint = false;
if (myCurrentPage.StartCursor.isNull()) {
doRepaint = true;
preparePaintInfo(myCurrentPage);
if (myCurrentPage.StartCursor.isNull()) {
return;
if (myCurrentPage.StartCursor.getParagraphIndex() != mark.ParagraphIndex ||
myCurrentPage.StartCursor.getMark().compareTo(mark) > 0) {
doRepaint = true;
gotoPosition(mark.ParagraphIndex, 0, 0);
preparePaintInfo(myCurrentPage);
if (myCurrentPage.EndCursor.isNull()) {
preparePaintInfo(myCurrentPage);
while (mark.compareTo(myCurrentPage.EndCursor.getMark()) > 0) {
doRepaint = true;
turnPage(true, ScrollingMode.NO_OVERLAPPING, 0);
if (myCurrentPage.StartCursor.isNull()) {
preparePaintInfo(myCurrentPage);
代码示例来源:origin: ydcx/KooReader
private int sizeOfTextBeforeCursor(ZLTextWordCursor wordCursor) {
final ZLTextParagraphCursor paragraphCursor = wordCursor.getParagraphCursor();
if (paragraphCursor == null) {
return -1;
}
final int paragraphIndex = paragraphCursor.Index;
int sizeOfText = myModel.getTextLength(paragraphIndex - 1);
final int paragraphLength = paragraphCursor.getParagraphLength();
if (paragraphLength > 0) {
sizeOfText +=
(myModel.getTextLength(paragraphIndex) - sizeOfText)
* wordCursor.getElementIndex()
/ paragraphLength;
}
return sizeOfText;
}
代码示例来源:origin: ydcx/KooReader
public TOCTree getCurrentTOCElement() {
final ZLTextWordCursor cursor = BookTextView.getStartCursor();
if (Model == null || cursor == null) {
return null;
}
int index = cursor.getParagraphIndex();
if (cursor.isEndOfParagraph()) {
++index;
}
TOCTree treeToSelect = null;
for (TOCTree tree : Model.TOCTree) {
final TOCTree.Reference reference = tree.getReference();
if (reference == null) {
continue;
}
if (reference.ParagraphIndex > index) {
break;
}
treeToSelect = tree;
}
return treeToSelect;
}
代码示例来源:origin: ydcx/KooReader
public void addInvisibleBookmark(ZLTextWordCursor cursor) {
if (cursor == null) {
return;
}
cursor = new ZLTextWordCursor(cursor);
if (cursor.isNull()) {
return;
}
final ZLTextView textView = getTextView();
final ZLTextModel textModel;
final Book book;
final AutoTextSnippet snippet;
// textView.model will not be changed inside synchronised block
synchronized (textView) {
textModel = textView.getModel();
final BookModel model = Model;
book = model != null ? model.Book : null;
if (book == null || textView != BookTextView || textModel == null) {
return;
}
snippet = new AutoTextSnippet(cursor, 30);
}
updateInvisibleBookmarksList(new Bookmark(
Collection, book, textModel.getId(), snippet, false
));
}
代码示例来源:origin: Jiangzqts/EpubRead
Buffer(ZLTextWordCursor cursor) {
Cursor = new ZLTextWordCursor(cursor);
}
代码示例来源:origin: ydcx/KooReader
public final synchronized int pagePosition1() {
return myCurrentPage == null ? 0 : myCurrentPage.EndCursor.getParagraphIndex();
}
代码示例来源:origin: ydcx/KooReader
public final void storePosition() {
if (StartPosition == null) {
return;
}
final KooReaderApp reader = getReader();
if (!StartPosition.equals(reader.getTextView().getStartCursor())) {
reader.addInvisibleBookmark(StartPosition);
reader.storePosition();
}
}
代码示例来源:origin: ydcx/KooReader
public boolean isEndOfText() {
return isEndOfParagraph() && myParagraphCursor.isLast();
}
代码示例来源:origin: Jiangzqts/EpubRead
private ZLTextWordCursor findStart(ZLTextPage page, ZLTextWordCursor end, int unit, int height) {
final ZLTextWordCursor start = new ZLTextWordCursor(end);
ParagraphSize size = paragraphSize(page, start, true, unit);
height -= size.Height;
boolean positionChanged = !start.isStartOfParagraph();
start.moveToParagraphStart();
while (height > 0) {
final ParagraphSize previousSize = size;
if (positionChanged && start.getParagraphCursor().isEndOfSection()) {
break;
if (!start.previousParagraph()) {
break;
if (!start.getParagraphCursor().isEndOfSection()) {
positionChanged = true;
boolean sameStart = start.samePositionAs(end);
if (!sameStart && start.isEndOfParagraph() && end.isStartOfParagraph()) {
ZLTextWordCursor startCopy = new ZLTextWordCursor(start);
startCopy.nextParagraph();
sameStart = startCopy.samePositionAs(end);
start.setCursor(findStart(page, end, SizeUnit.LINE_UNIT, 1));
代码示例来源:origin: Jiangzqts/EpubRead
public AutoTextSnippet(ZLTextWordCursor start, int maxChars) {
System.err.println("AutoTextSnippet " + maxChars);
final ZLTextWordCursor cursor = new ZLTextWordCursor(start);
mainLoop:
while (buffer.Builder.length() + sentenceBuffer.Builder.length() + phraseBuffer.Builder.length() < maxChars && sentenceCounter < maxChars / 20) {
while (cursor.isEndOfParagraph()) {
if (!cursor.nextParagraph()) {
break mainLoop;
if (!buffer.isEmpty() && cursor.getParagraphCursor().isLikeEndOfSection()) {
break mainLoop;
final ZLTextElement element = cursor.getElement();
if (element == ZLTextElement.HSpace) {
if (lineIsNonEmpty) {
final ZLTextWord word = (ZLTextWord)element;
phraseBuffer.Builder.append(word.Data, word.Offset, word.Length);
phraseBuffer.Cursor.setCursor(cursor);
phraseBuffer.Cursor.setCharIndex(word.Length);
++wordCounter;
lineIsNonEmpty = true;
cursor.nextWord();
cursor.isEndOfText() || cursor.getParagraphCursor().isLikeEndOfSection();
内容来源于网络,如有侵权,请联系作者删除!