mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
MiniHelp: fixed mistyping
added 'open external links in browser' feature git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@464 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
70fa3f6820
commit
a7cc9a9bec
17 changed files with 98 additions and 18 deletions
2
TODO
2
TODO
|
@ -5,6 +5,8 @@ ZLTextView:
|
|||
переход по ссылкам
|
||||
внутренним
|
||||
внешним (вызов браузера)
|
||||
swing
|
||||
DONE android
|
||||
переносы
|
||||
position indicator
|
||||
обработка неразрывных пробелов
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<p>FBReader распространяется свободно, включая исходные тексты, под лицензией <a l:href="http://www.gnu.org/licenses/gpl.html">GNU GPL</a>.</p>
|
||||
<empty-line/>
|
||||
<subtitle><p>С чего начать</p></subtitle>
|
||||
<p>FBReader автоматически собирает в библиотеку файлы форматов <code>fb2</code>, <code>oeb</code> и <code>OpenReader</code>, лежащие в каталогах, заданных параметром <code>“Каталоги с книгами”</code>. Поэтому прежде всего нужно определить этот параметр. Откройте диалог настроек (нажмите на кнопку <image l:href="#settings.png" voffset="-6"/>) и отредактруйте <code>“каталоги с книгами”</code> в разделе <code>“Общие настройки”</code>. Каталоги перечисляются через двоеточие, в этих каталогах должны лижать файлы с расширениями <code>fb2</code>, <code>oebzip</code> или <code>orb</code>, или содержащие их архивы.</p>
|
||||
<p>FBReader автоматически собирает в библиотеку файлы форматов <code>fb2</code>, <code>oeb</code> и <code>OpenReader</code>, лежащие в каталогах, заданных параметром <code>“Каталоги с книгами”</code>. Поэтому прежде всего нужно определить этот параметр. Откройте диалог настроек (нажмите на кнопку <image l:href="#settings.png" voffset="-6"/>) и отредактруйте <code>“каталоги с книгами”</code> в разделе <code>“Общие настройки”</code>. Каталоги перечисляются через двоеточие, в этих каталогах должны лежать файлы с расширениями <code>fb2</code>, <code>oebzip</code> или <code>orb</code>, или содержащие их архивы.</p>
|
||||
<p>Теперь откройте <code>библиотеку</code> (нажмите на <image l:href="#books.png" voffset="-6"/>), выберите книгу, и приступайте к чтению.</p>
|
||||
<p>Чтобы читать книгу в другом формате, ее нужно вручную добавить в библиотеку. Запустите <code>диалог добавления книги</code> (<image l:href="#addbook.png"/>), выберите файл и отредактируйте информацию о книге. В следующий раз вы сможете открыть эту книгу уже с помощью <code>библиотеки</code> (<image l:href="#books.png" voffset="-6"/>).</p>
|
||||
<empty-line/>
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package org.fbreader.fbreader;
|
||||
|
||||
import org.zlibrary.core.library.ZLibrary;
|
||||
import org.zlibrary.core.options.*;
|
||||
import org.zlibrary.core.view.ZLPaintContext;
|
||||
import org.zlibrary.text.model.ZLTextModel;
|
||||
import org.zlibrary.text.view.impl.ZLTextWordCursor;
|
||||
import org.zlibrary.text.view.impl.ZLTextParagraphCursor;
|
||||
import org.zlibrary.text.view.impl.*;
|
||||
import org.fbreader.bookmodel.FBTextKind;
|
||||
|
||||
class BookTextView extends FBView {
|
||||
private ZLIntegerOption myParagraphNumberOption;
|
||||
|
@ -46,6 +47,47 @@ class BookTextView extends FBView {
|
|||
if (super.onStylusPress(x, y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ZLTextElementArea area = getElementByCoordinates(x, y);
|
||||
if (area != null) {
|
||||
ZLTextElement element = area.Element;
|
||||
if ((element instanceof ZLTextImageElement) ||
|
||||
(element instanceof ZLTextWord)) {
|
||||
final ZLTextWordCursor cursor = new ZLTextWordCursor(getStartCursor());
|
||||
cursor.moveToParagraph(area.ParagraphNumber);
|
||||
cursor.moveToParagraphStart();
|
||||
final int elementNumber = area.TextElementNumber;
|
||||
byte hyperlinkKind = FBTextKind.REGULAR;
|
||||
String id = null;
|
||||
for (int i = 0; i < elementNumber; ++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:
|
||||
ZLibrary.getInstance().openInBrowser(id);
|
||||
return true;
|
||||
case FBTextKind.FOOTNOTE:
|
||||
case FBTextKind.INTERNAL_HYPERLINK:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class ContentsView extends FBView {
|
|||
return true;
|
||||
}
|
||||
|
||||
final int index = paragraphIndexByCoordinate(y);
|
||||
final int index = getParagraphIndexByCoordinate(y);
|
||||
if (index == -1) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public abstract class ZLibrary {
|
|||
|
||||
abstract public ZLPaintContext createPaintContext();
|
||||
abstract public InputStream getResourceInputStream(String fileName);
|
||||
abstract public void openInBrowser(String reference);
|
||||
|
||||
protected final void loadProperties() {
|
||||
new ZLXMLReaderAdapter() {
|
||||
|
|
|
@ -20,6 +20,8 @@ public interface ZLTextParagraph {
|
|||
|
||||
byte getControlKind();
|
||||
boolean getControlIsStart();
|
||||
boolean getControlIsHyperlink();
|
||||
String getHyperlinkControlLabel();
|
||||
|
||||
ZLImageEntry getImageEntry();
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
private byte myControlKind;
|
||||
private boolean myControlIsStart;
|
||||
private boolean myControlIsHyperlink;
|
||||
private String myHyperlinkControlLabel;
|
||||
|
||||
private ZLImageEntry myImageEntry;
|
||||
|
||||
|
@ -68,6 +69,9 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
public boolean getControlIsHyperlink() {
|
||||
return myControlIsHyperlink;
|
||||
}
|
||||
public String getHyperlinkControlLabel() {
|
||||
return myHyperlinkControlLabel;
|
||||
}
|
||||
|
||||
public ZLImageEntry getImageEntry() {
|
||||
return myImageEntry;
|
||||
|
@ -109,6 +113,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
if ((kind & 0x0200) == 0x0200) {
|
||||
myControlIsHyperlink = true;
|
||||
short labelLength = (short)data[dataOffset++];
|
||||
myHyperlinkControlLabel = new String(data, dataOffset, labelLength);
|
||||
dataOffset += labelLength;
|
||||
} else {
|
||||
myControlIsHyperlink = false;
|
||||
|
@ -219,8 +224,6 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
|||
block[blockOffset++] = (char)labelLength;
|
||||
label.getChars(0, labelLength, block, blockOffset);
|
||||
myBlockOffset = blockOffset + labelLength;
|
||||
//addEntry(code + myEntries.size());
|
||||
//myEntries.add(new ZLTextHyperlinkControlEntry(textKind, label));
|
||||
}
|
||||
|
||||
public final void addImage(String id, ZLImageMap imageMap, short vOffset) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
final class ZLTextControlElement extends ZLTextElement {
|
||||
public class ZLTextControlElement extends ZLTextElement {
|
||||
private final static ZLTextControlElement[] myStartElements = new ZLTextControlElement[256];
|
||||
private final static ZLTextControlElement[] myEndElements = new ZLTextControlElement[256];
|
||||
|
||||
|
@ -17,7 +17,7 @@ final class ZLTextControlElement extends ZLTextElement {
|
|||
public final byte Kind;
|
||||
public final boolean IsStart;
|
||||
|
||||
private ZLTextControlElement(byte kind, boolean isStart) {
|
||||
protected ZLTextControlElement(byte kind, boolean isStart) {
|
||||
Kind = kind;
|
||||
IsStart = isStart;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
class ZLTextElement {
|
||||
public class ZLTextElement {
|
||||
final static ZLTextElement HSpace = new ZLTextElement();
|
||||
final static ZLTextElement AfterParagraph = new ZLTextElement();
|
||||
final static ZLTextElement IndentElement = new ZLTextElement();
|
||||
|
|
|
@ -2,15 +2,15 @@ package org.zlibrary.text.view.impl;
|
|||
|
||||
import org.zlibrary.text.view.ZLTextStyle;
|
||||
|
||||
class ZLTextElementArea extends ZLTextRectangularArea {
|
||||
final int ParagraphNumber;
|
||||
final int TextElementNumber;
|
||||
public class ZLTextElementArea extends ZLTextRectangularArea {
|
||||
public final int ParagraphNumber;
|
||||
public final int TextElementNumber;
|
||||
final int StartCharNumber;
|
||||
final int Length;
|
||||
final boolean AddHyphenationSign;
|
||||
final boolean ChangeStyle;
|
||||
final ZLTextStyle Style;
|
||||
final ZLTextElement Element;
|
||||
public final ZLTextElement Element;
|
||||
|
||||
ZLTextElementArea(int paragraphNumber, int textElementNumber, int startCharNumber, int length, boolean addHyphenationSign, boolean changeStyle, ZLTextStyle style, ZLTextElement element, int xStart, int xEnd, int yStart, int yEnd) {
|
||||
super(xStart, xEnd, yStart, yEnd);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.zlibrary.text.view.impl;
|
||||
|
||||
public final class ZLTextHyperlinkControlElement extends ZLTextControlElement {
|
||||
public final String Label;
|
||||
|
||||
ZLTextHyperlinkControlElement(byte kind, String label) {
|
||||
super(kind, true);
|
||||
Label = label;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package org.zlibrary.text.view.impl;
|
|||
|
||||
import org.zlibrary.core.image.ZLImageData;
|
||||
|
||||
class ZLTextImageElement extends ZLTextElement {
|
||||
public final class ZLTextImageElement extends ZLTextElement {
|
||||
private ZLImageData myImageData;
|
||||
|
||||
ZLTextImageElement(ZLImageData imageData) {
|
||||
|
|
|
@ -26,7 +26,11 @@ public abstract class ZLTextParagraphCursor {
|
|||
processTextEntry(it.getTextData(), it.getTextOffset(), it.getTextLength());
|
||||
break;
|
||||
case ZLTextParagraph.Entry.CONTROL:
|
||||
myElements.add(ZLTextControlElement.get(it.getControlKind(), it.getControlIsStart()));
|
||||
if (it.getControlIsStart() && it.getControlIsHyperlink()) {
|
||||
myElements.add(new ZLTextHyperlinkControlElement(it.getControlKind(), it.getHyperlinkControlLabel()));
|
||||
} else {
|
||||
myElements.add(ZLTextControlElement.get(it.getControlKind(), it.getControlIsStart()));
|
||||
}
|
||||
break;
|
||||
case ZLTextParagraph.Entry.IMAGE:
|
||||
ZLImage image = it.getImageEntry().getImage();
|
||||
|
|
|
@ -339,7 +339,6 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharNumber, myTextStyle);
|
||||
final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info);
|
||||
if (cachedInfo != null) {
|
||||
//System.err.println("cached!!!!");
|
||||
return cachedInfo;
|
||||
}
|
||||
|
||||
|
@ -898,7 +897,11 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
return start;
|
||||
}
|
||||
|
||||
protected int paragraphIndexByCoordinate(int y) {
|
||||
protected ZLTextElementArea getElementByCoordinates(int x, int y) {
|
||||
return ZLTextRectangularArea.binarySearch(myTextElementMap, x, y);
|
||||
}
|
||||
|
||||
protected int getParagraphIndexByCoordinate(int y) {
|
||||
ZLTextElementArea area = ZLTextRectangularArea.binarySearch(myTextElementMap, y);
|
||||
return (area != null) ? area.ParagraphNumber : -1;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.zlibrary.text.view.impl;
|
|||
|
||||
import org.zlibrary.core.view.ZLPaintContext;
|
||||
|
||||
final class ZLTextWord extends ZLTextElement {
|
||||
public final class ZLTextWord extends ZLTextElement {
|
||||
public final char[] Data;
|
||||
public final int Offset;
|
||||
public final int Length;
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.zlibrary.ui.android.library;
|
|||
import java.io.InputStream;
|
||||
|
||||
import android.content.Resources;
|
||||
import android.content.Intent;
|
||||
import android.net.ContentURI;
|
||||
|
||||
import org.zlibrary.core.library.ZLibrary;
|
||||
import org.zlibrary.core.application.ZLApplication;
|
||||
|
@ -60,6 +62,12 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
public void openInBrowser(String reference) {
|
||||
Intent intent = new Intent(Intent.VIEW_ACTION);
|
||||
intent.setData(ContentURI.create(reference));
|
||||
myActivity.startActivity(intent);
|
||||
}
|
||||
|
||||
void run(ZLAndroidActivity activity) {
|
||||
myActivity = activity;
|
||||
|
||||
|
|
|
@ -54,4 +54,9 @@ public class ZLSwingLibrary extends ZLibrary {
|
|||
|
||||
// ZLDialogManager.getInstance().errorBox(new "noHelpBox");
|
||||
}
|
||||
|
||||
public void openInBrowser(String reference) {
|
||||
// TODO: implement
|
||||
System.out.println("to open in browser: " + reference);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue