mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@859 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
6df63fb609
commit
fb4784fbac
10 changed files with 148 additions and 34 deletions
|
@ -36,6 +36,7 @@ public final class BookModel {
|
|||
|
||||
private final HashMap myFootnotes = new HashMap();
|
||||
private final HashMap myInternalHyperlinks = new HashMap();
|
||||
private final ArrayList myBookTextModels;
|
||||
|
||||
private final ZLImageMap myImageMap = new ZLImageMap();
|
||||
|
||||
|
@ -43,13 +44,18 @@ public final class BookModel {
|
|||
public final int ParagraphNumber;
|
||||
public final ZLTextModel Model;
|
||||
|
||||
public final int ModelNumber;
|
||||
|
||||
Label(ZLTextModel model, int paragraphNumber) {
|
||||
ParagraphNumber = paragraphNumber;
|
||||
Model = model;
|
||||
ModelNumber = myBookTextModels.indexOf(model);
|
||||
}
|
||||
}
|
||||
|
||||
public BookModel(final BookDescription description) {
|
||||
myBookTextModels = new ArrayList();
|
||||
myBookTextModels.add(BookTextModel);
|
||||
Description = description;
|
||||
ZLFile file = new ZLFile(description.FileName);
|
||||
FormatPlugin plugin = PluginCollection.instance().getPlugin(file, false);
|
||||
|
@ -92,4 +98,15 @@ public final class BookModel {
|
|||
void addImage(String id, ZLImage image) {
|
||||
myImageMap.put(id, image);
|
||||
}
|
||||
|
||||
//
|
||||
public ZLTextPlainModel addBookTextModel() {
|
||||
ZLTextPlainModel bookTextModel = new ZLTextPlainModel(65536);
|
||||
myBookTextModels.add(bookTextModel);
|
||||
return bookTextModel;
|
||||
}
|
||||
|
||||
public ArrayList getBookTextModels() {
|
||||
return myBookTextModels;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,10 +145,10 @@ public class BookReader {
|
|||
insertEndParagraph(ZLTextParagraph.Kind.END_OF_SECTION_PARAGRAPH);
|
||||
}
|
||||
|
||||
public final void insertEndOfTextParagraph() {
|
||||
/* public final void insertEndOfTextParagraph() {
|
||||
insertEndParagraph(ZLTextParagraph.Kind.END_OF_TEXT_PARAGRAPH);
|
||||
}
|
||||
|
||||
*/
|
||||
public final void unsetCurrentTextModel() {
|
||||
myCurrentTextModel = null;
|
||||
}
|
||||
|
@ -326,4 +326,9 @@ public class BookReader {
|
|||
myCurrentTextModel.addFixedHSpace(length);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public final void setNewTextModel() {
|
||||
myCurrentTextModel = Model.addBookTextModel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public class BookTextView extends FBView {
|
|||
private static final String PARAGRAPH_PREFIX = "Paragraph_";
|
||||
private static final String WORD_PREFIX = "Word_";
|
||||
private static final String CHAR_PREFIX = "Char_";
|
||||
private static final String MODEL_PREFIX = "Model_";
|
||||
|
||||
private static final int MAX_UNDO_STACK_SIZE = 20;
|
||||
|
||||
|
@ -62,8 +63,7 @@ public class BookTextView extends FBView {
|
|||
myContentsModel = contentsModel;
|
||||
}
|
||||
|
||||
public void setModel(ZLTextModel model, String fileName) {
|
||||
super.setModel(model);
|
||||
public void setModels(ArrayList/*<ZLTextModel>*/ models, String fileName) {
|
||||
myFileName = fileName;
|
||||
|
||||
myPositionStack.clear();
|
||||
|
@ -75,11 +75,18 @@ public class BookTextView extends FBView {
|
|||
myPositionStack.add(new Position(
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, PARAGRAPH_PREFIX + i, 0).getValue(),
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, WORD_PREFIX + i, 0).getValue(),
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, CHAR_PREFIX + i, 0).getValue()
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, CHAR_PREFIX + i, 0).getValue(),
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, fileName, MODEL_PREFIX + i, 0).getValue()
|
||||
));
|
||||
}
|
||||
|
||||
if ((model != null) && (!myPositionStack.isEmpty())) {
|
||||
if (!myPositionStack.isEmpty()) {
|
||||
System.out.println("stack is not empty");
|
||||
super.setModels(models, ((Position)myPositionStack.get(myCurrentPointInStack)).ModelIndex);
|
||||
} else {
|
||||
super.setModels(models, 0);
|
||||
}
|
||||
if ((getModel() != null) && (!myPositionStack.isEmpty())) {
|
||||
gotoPosition((Position)myPositionStack.get(myCurrentPointInStack));
|
||||
}
|
||||
}
|
||||
|
@ -90,21 +97,27 @@ public class BookTextView extends FBView {
|
|||
myPositionStack.add(new Position(StartCursor));
|
||||
} else {
|
||||
((Position)myPositionStack.get(myCurrentPointInStack)).set(StartCursor);
|
||||
Position position = (Position)myPositionStack.get(myCurrentPointInStack);
|
||||
System.out.println("current position " + position.ModelIndex + " , " + position.ParagraphIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void scrollToHome() {
|
||||
final ZLTextWordCursor cursor = StartCursor;
|
||||
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0) {
|
||||
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0
|
||||
&& myCurrentModelIndex == 0) {
|
||||
return;
|
||||
}
|
||||
setModel(0);
|
||||
final Position position = new Position(cursor);
|
||||
gotoParagraph(0, false);
|
||||
gotoPosition(0, 0, 0);
|
||||
preparePaintInfo();
|
||||
if (!position.equalsToCursor(StartCursor)) {
|
||||
/* if (!position.equalsToCursor(StartCursor)) {
|
||||
savePosition(position);
|
||||
}
|
||||
*/
|
||||
savePosition(position, StartCursor);
|
||||
Application.refreshWindow();
|
||||
}
|
||||
|
||||
|
@ -115,9 +128,11 @@ public class BookTextView extends FBView {
|
|||
final Position position = new Position(cursor);
|
||||
gotoParagraph(paragraphIndex, false);
|
||||
preparePaintInfo();
|
||||
if (!position.equalsToCursor(StartCursor)) {
|
||||
/* if (!position.equalsToCursor(StartCursor)) {
|
||||
savePosition(position);
|
||||
}
|
||||
*/
|
||||
savePosition(position, StartCursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +219,8 @@ public class BookTextView extends FBView {
|
|||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, PARAGRAPH_PREFIX + i, 0).setValue(position.ParagraphIndex);
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, WORD_PREFIX + i, 0).setValue(position.WordIndex);
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, CHAR_PREFIX + i, 0).setValue(position.CharIndex);
|
||||
new ZLIntegerOption(ZLOption.STATE_CATEGORY, group, MODEL_PREFIX + i, 0).setValue(position.ModelIndex);
|
||||
System.out.println("saving model index " + position.ModelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,4 +241,5 @@ public class BookTextView extends FBView {
|
|||
gotoPosition((Position)myPositionStack.get(++myCurrentPointInStack));
|
||||
((FBReader)Application).refreshWindow();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -267,7 +267,9 @@ public final class FBReader extends ZLApplication {
|
|||
if (myBookModel != null) {
|
||||
BookModel.Label label = myBookModel.getLabel(id);
|
||||
if ((label != null) && (label.Model != null)) {
|
||||
if (label.Model == myBookModel.BookTextModel) {
|
||||
// if (label.Model == myBookModel.BookTextModel) {
|
||||
if (label.ModelNumber != -1) {
|
||||
BookTextView.setModel(label.ModelNumber);
|
||||
BookTextView.gotoParagraphSafe(label.ParagraphNumber);
|
||||
} else {
|
||||
FootnoteView.setModel(label.Model);
|
||||
|
@ -291,7 +293,7 @@ public final class FBReader extends ZLApplication {
|
|||
void openBookInternal(BookDescription description) {
|
||||
if (description != null) {
|
||||
BookTextView.saveState();
|
||||
BookTextView.setModel(null, "");
|
||||
BookTextView.setModels(null, "");
|
||||
BookTextView.setContentsModel(null);
|
||||
ContentsView.setModel(null);
|
||||
|
||||
|
@ -299,7 +301,8 @@ public final class FBReader extends ZLApplication {
|
|||
final String fileName = description.FileName;
|
||||
myBookNameOption.setValue(fileName);
|
||||
ZLTextHyphenator.getInstance().load(description.getLanguage());
|
||||
BookTextView.setModel(myBookModel.BookTextModel, fileName);
|
||||
// BookTextView.setModel(myBookModel.BookTextModel, fileName);
|
||||
BookTextView.setModels(myBookModel.getBookTextModels(), fileName);
|
||||
BookTextView.setCaption(description.getTitle());
|
||||
BookTextView.setContentsModel(myBookModel.ContentsModel);
|
||||
FootnoteView.setModel(null);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class PluginCollection {
|
|||
if (ourInstance == null) {
|
||||
ourInstance = new PluginCollection();
|
||||
ourInstance.myPlugins.add(new FB2Plugin());
|
||||
//ourInstance.myPlugins.add(new PluckerPlugin());
|
||||
ourInstance.myPlugins.add(new PluckerPlugin());
|
||||
//ourInstance->myPlugins.push_back(new DocBookPlugin());
|
||||
//ourInstance.myPlugins.add(new HtmlPlugin());
|
||||
/*ourInstance.myPlugins.add(new TxtPlugin());
|
||||
|
|
|
@ -190,8 +190,9 @@ public class PluckerBookReader extends BookReader {
|
|||
myParagraphVector = (ArrayList)myParagraphMap.get(uid);
|
||||
processTextRecord(size, pars);
|
||||
if ((flags & 0x1) == 0) {
|
||||
// System.out.println("insert endoftext");
|
||||
insertEndOfTextParagraph();
|
||||
System.out.println("setting new text model");
|
||||
// insertEndOfTextParagraph();
|
||||
setNewTextModel();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -202,8 +203,8 @@ public class PluckerBookReader extends BookReader {
|
|||
final String mime = "image/palm";
|
||||
ZLImage image = null;
|
||||
if (type == 2) {
|
||||
System.out.println("type2");
|
||||
image = new ZLFileImage(mime, myFilePath, myStream.offset());
|
||||
// System.out.println("type2");
|
||||
// image = new PluckerFileImage(mime, myFilePath, myStream.offset(), recordSize - 8);
|
||||
} else if (myCompressionVersion == 1) {
|
||||
//image = new DocCompressedFileImage(mime, myFilePath, myStream->offset(), recordSize - 8);
|
||||
} else if (myCompressionVersion == 2) {
|
||||
|
@ -341,7 +342,7 @@ public class PluckerBookReader extends BookReader {
|
|||
break;
|
||||
case 0x1A:
|
||||
safeBeginParagraph();
|
||||
System.out.println("image ref");
|
||||
// System.out.println("image ref");
|
||||
addImageReference(fromNumber(twoBytes(ptr, cur + 1)), (short) 0);
|
||||
break;
|
||||
case 0x22:
|
||||
|
@ -381,7 +382,7 @@ public class PluckerBookReader extends BookReader {
|
|||
case 0x53: // color setting is ignored
|
||||
break;
|
||||
case 0x5C:
|
||||
System.out.println("image ref");
|
||||
// System.out.println("image ref");
|
||||
addImageReference(fromNumber(twoBytes(ptr, cur + 3)), (short) 0);
|
||||
break;
|
||||
case 0x60: // underlined text is ignored
|
||||
|
|
|
@ -25,6 +25,9 @@ import org.geometerplus.zlibrary.core.util.*;
|
|||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||
|
||||
public class ZLFileImage implements ZLImage {
|
||||
private final String myPath;
|
||||
private final int myOffset;
|
||||
|
||||
public ZLFileImage(String mimeType, String path, int offset) {
|
||||
myPath = path;
|
||||
myOffset = offset;
|
||||
|
@ -53,9 +56,7 @@ public class ZLFileImage implements ZLImage {
|
|||
return buffer;
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
private final String myPath;
|
||||
private final int myOffset;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package org.geometerplus.zlibrary.text.view;
|
||||
|
||||
import java.util.*;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.view.*;
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
|
||||
|
@ -36,7 +39,15 @@ public abstract class ZLTextView extends ZLView {
|
|||
super(application, context);
|
||||
}
|
||||
|
||||
public abstract void setModel(ZLTextModel model);
|
||||
public final void setModel(ZLTextModel model) {
|
||||
final ArrayList list = new ArrayList(1);
|
||||
list.add(model);
|
||||
setModels(list, 0);
|
||||
}
|
||||
|
||||
public abstract void setModel(int modelNumber);
|
||||
|
||||
public abstract void setModels(ArrayList/*<ZLTextModel>*/ model, int current);
|
||||
|
||||
public abstract void scrollPage(boolean forward, int scrollingMode, int value);
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.geometerplus.zlibrary.text.view.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.geometerplus.zlibrary.core.application.ZLApplication;
|
||||
import org.geometerplus.zlibrary.core.view.ZLPaintContext;
|
||||
import org.geometerplus.zlibrary.text.model.*;
|
||||
|
@ -28,17 +30,21 @@ import org.geometerplus.zlibrary.text.view.style.*;
|
|||
|
||||
public abstract class ZLTextViewImpl extends ZLTextView {
|
||||
private ZLTextModel myModel;
|
||||
protected int myCurrentModelIndex; //?
|
||||
private ArrayList/*<ZLTextModel>*/ myModels;
|
||||
private final ZLTextSelectionModel mySelectionModel;
|
||||
|
||||
protected class Position {
|
||||
public int ParagraphIndex;
|
||||
public int WordIndex;
|
||||
public int CharIndex;
|
||||
public int ModelIndex;
|
||||
|
||||
public Position(int paragraphIndex, int wordIndex, int charIndex) {
|
||||
public Position(int paragraphIndex, int wordIndex, int charIndex, int modelIndex) {
|
||||
ParagraphIndex = paragraphIndex;
|
||||
WordIndex = wordIndex;
|
||||
CharIndex = charIndex;
|
||||
ModelIndex = modelIndex;
|
||||
}
|
||||
|
||||
public Position(ZLTextWordCursor cursor) {
|
||||
|
@ -51,6 +57,8 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
WordIndex = cursor.getWordIndex();
|
||||
CharIndex = cursor.getCharIndex();
|
||||
}
|
||||
ModelIndex = myCurrentModelIndex;
|
||||
// System.out.println("creating position " + myCurrentModelIndex);
|
||||
}
|
||||
|
||||
public boolean equalsToCursor(ZLTextWordCursor cursor) {
|
||||
|
@ -58,7 +66,9 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
(ParagraphIndex == cursor.getParagraphCursor().Index) &&
|
||||
(WordIndex == cursor.getWordIndex()) &&
|
||||
(CharIndex == cursor.getCharIndex());
|
||||
// (ModelIndex == cursor.getModelIndex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private interface SizeUnit {
|
||||
|
@ -104,23 +114,43 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
mySelectionModel = new ZLTextSelectionModel(this, application);
|
||||
}
|
||||
|
||||
public void setModel(ZLTextModel model) {
|
||||
myModel = model;
|
||||
if (model != null) {
|
||||
final int paragraphsNumber = model.getParagraphsNumber();
|
||||
public void setModels(ArrayList models, int current) {
|
||||
System.out.println(current);
|
||||
myModels = (models != null) ? models : new ArrayList();
|
||||
myModel = (current >= 0 && current < myModels.size()) ?
|
||||
(ZLTextModel) myModels.get(current) : null;
|
||||
myCurrentModelIndex = current;
|
||||
setModelInternal();
|
||||
}
|
||||
|
||||
private void setModelInternal() {
|
||||
if (myModel != null) {
|
||||
final int paragraphsNumber = myModel.getParagraphsNumber();
|
||||
if (paragraphsNumber > 0) {
|
||||
myTextSize = new int[paragraphsNumber + 1];
|
||||
myTextSize[0] = 0;
|
||||
for (int i = 0; i < paragraphsNumber; ++i) {
|
||||
myTextSize[i + 1] = myTextSize[i] + model.getParagraphTextLength(i);
|
||||
myTextSize[i + 1] = myTextSize[i] + myModel.getParagraphTextLength(i);
|
||||
}
|
||||
StartCursor.setCursor(ZLTextParagraphCursor.cursor(model, 0));
|
||||
StartCursor.setCursor(ZLTextParagraphCursor.cursor(myModel, 0));
|
||||
EndCursor.reset();
|
||||
myPaintState = PaintState.START_IS_KNOWN;
|
||||
|
||||
// StartCursor.setModelIndex(myCurrentModelIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setModel(int modelNumber) {
|
||||
if ((modelNumber != myCurrentModelIndex) && (modelNumber >= 0) &&
|
||||
(modelNumber < myModels.size())) {
|
||||
myModel = (ZLTextModel) myModels.get(modelNumber);
|
||||
myCurrentModelIndex = modelNumber;
|
||||
System.out.println("setting model number " + modelNumber);
|
||||
setModelInternal();
|
||||
}
|
||||
}
|
||||
|
||||
protected ZLTextModel getModel() {
|
||||
return myModel;
|
||||
}
|
||||
|
@ -310,9 +340,11 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
if (StartCursor.isNull()) {
|
||||
preparePaintInfo();
|
||||
}
|
||||
if (!position.equalsToCursor(StartCursor)) {
|
||||
/* if (!position.equalsToCursor(StartCursor)) {
|
||||
savePosition(position);
|
||||
}
|
||||
*/
|
||||
savePosition(position, StartCursor);
|
||||
Application.refreshWindow();
|
||||
}
|
||||
}
|
||||
|
@ -320,6 +352,13 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
protected void savePosition(Position position) {
|
||||
}
|
||||
|
||||
//?
|
||||
protected final void savePosition(Position position, ZLTextWordCursor cursor) {
|
||||
if (!position.equalsToCursor(cursor)) {
|
||||
savePosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
public void search(final String text, boolean ignoreCase, boolean wholeText, boolean backward, boolean thisSectionOnly) {
|
||||
if (text.length() == 0) {
|
||||
return;
|
||||
|
@ -1021,7 +1060,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
}
|
||||
|
||||
public final void gotoPosition(Position position) {
|
||||
gotoPosition(position.ParagraphIndex, position.WordIndex, position.CharIndex);
|
||||
gotoPosition(position.ParagraphIndex, position.WordIndex, position.CharIndex, position.ModelIndex);
|
||||
}
|
||||
|
||||
public final void gotoPosition(int paragraphIndex, int wordIndex, int charIndex) {
|
||||
|
@ -1037,6 +1076,11 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
EndCursor.reset();
|
||||
myPaintState = PaintState.START_IS_KNOWN;
|
||||
}
|
||||
|
||||
public final void gotoPosition(int paragraphIndex, int wordIndex, int charIndex, int modelIndex) {
|
||||
setModel(modelIndex);
|
||||
gotoPosition(paragraphIndex, wordIndex, charIndex);
|
||||
}
|
||||
|
||||
public void gotoParagraph(int num, boolean last) {
|
||||
if (myModel == null) {
|
||||
|
@ -1441,9 +1485,11 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
if (StartCursor.isNull()) {
|
||||
preparePaintInfo();
|
||||
}
|
||||
if (!position.equalsToCursor(StartCursor)) {
|
||||
/* if (!position.equalsToCursor(StartCursor)) {
|
||||
savePosition(position);
|
||||
}
|
||||
*/
|
||||
savePosition(position, StartCursor);
|
||||
Application.refreshWindow();
|
||||
myTreeStateIsFrozen = false;
|
||||
return true;
|
||||
|
@ -1510,4 +1556,5 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
Application.refreshWindow();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ public final class ZLTextWordCursor {
|
|||
private ZLTextParagraphCursor myParagraphCursor;
|
||||
private int myWordIndex;
|
||||
private int myCharIndex;
|
||||
|
||||
// private int myModelIndex;
|
||||
|
||||
public ZLTextWordCursor() {
|
||||
}
|
||||
|
@ -197,4 +199,13 @@ public final class ZLTextWordCursor {
|
|||
moveTo(myWordIndex, myCharIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/* public int getModelIndex() {
|
||||
return myModelIndex;
|
||||
}
|
||||
|
||||
public void setModelIndex(int modelIndex) {
|
||||
myModelIndex = modelIndex;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue