mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 12:00:17 +02:00
cleanup
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@831 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
186daba22e
commit
b850b035ca
3 changed files with 130 additions and 132 deletions
|
@ -79,7 +79,7 @@ loop:
|
||||||
if (sourceIndex + 1 > compressedSize) {
|
if (sourceIndex + 1 > compressedSize) {
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
int N = 256 * token + sourceBuffer[sourceIndex++];
|
int N = 256 * (token & 0xFF) + (sourceBuffer[sourceIndex++] & 0xFF);
|
||||||
int copyLength = (N & 7) + 3;
|
int copyLength = (N & 7) + 3;
|
||||||
if (targetIndex + copyLength > maxUncompressedSize) {
|
if (targetIndex + copyLength > maxUncompressedSize) {
|
||||||
break loop;
|
break loop;
|
||||||
|
|
|
@ -58,17 +58,16 @@ public class PluckerBookReader extends BookReader {
|
||||||
private final ZLEncodingConverter myConverter;
|
private final ZLEncodingConverter myConverter;
|
||||||
|
|
||||||
public PluckerBookReader(String filePath, BookModel model, String encoding){
|
public PluckerBookReader(String filePath, BookModel model, String encoding){
|
||||||
super(model);
|
super(model);
|
||||||
myConverter = new EncodedTextReader(encoding).getConverter();
|
myConverter = new EncodedTextReader(encoding).getConverter();
|
||||||
myFilePath = filePath;
|
myFilePath = filePath;
|
||||||
System.out.println(filePath + " " + encoding);
|
System.out.println(filePath + " " + encoding);
|
||||||
myFont = FontType.FT_REGULAR;
|
myFont = FontType.FT_REGULAR;
|
||||||
myCharBuffer = new char[65535];
|
myCharBuffer = new char[65535];
|
||||||
myForcedEntry = null;
|
myForcedEntry = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDocument() throws IOException {
|
public boolean readDocument() throws IOException {
|
||||||
System.out.println("reading document");
|
System.out.println("reading document");
|
||||||
myStream = new PdbInputStream(new ZLFile(myFilePath));
|
myStream = new PdbInputStream(new ZLFile(myFilePath));
|
||||||
|
|
||||||
|
@ -334,130 +333,129 @@ public class PluckerBookReader extends BookReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processTextFunction(char[] ptr, int cur) {
|
private void processTextFunction(char[] ptr, int cur) {
|
||||||
switch (ptr[cur]) {
|
switch (ptr[cur]) {
|
||||||
case 0x08:
|
case 0x08:
|
||||||
safeAddControl(FBTextKind.INTERNAL_HYPERLINK, false);
|
safeAddControl(FBTextKind.INTERNAL_HYPERLINK, false);
|
||||||
break;
|
break;
|
||||||
case 0x0A:
|
case 0x0A:
|
||||||
safeAddHyperlinkControl(fromNumber(twoBytes(ptr, cur+ 1)));
|
safeAddHyperlinkControl(fromNumber(twoBytes(ptr, cur+ 1)));
|
||||||
break;
|
break;
|
||||||
case 0x0C:
|
case 0x0C:
|
||||||
{
|
{
|
||||||
int sectionNum = twoBytes(ptr, cur + 1);
|
int sectionNum = twoBytes(ptr, cur + 1);
|
||||||
int paragraphNum = twoBytes(ptr, cur + 3);
|
int paragraphNum = twoBytes(ptr, cur + 3);
|
||||||
safeAddHyperlinkControl(fromNumber(sectionNum) + '#' + fromNumber(paragraphNum));
|
safeAddHyperlinkControl(fromNumber(sectionNum) + '#' + fromNumber(paragraphNum));
|
||||||
myReferencedParagraphs.add(new Pair(sectionNum, paragraphNum));
|
myReferencedParagraphs.add(new Pair(sectionNum, paragraphNum));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case 0x11:
|
|
||||||
changeFont((ptr[cur + 1]));
|
|
||||||
break;
|
|
||||||
case 0x1A:
|
|
||||||
safeBeginParagraph();
|
|
||||||
//addImageReference(fromNumber(twoBytes(ptr, cur + 1)));
|
|
||||||
break;
|
|
||||||
case 0x22:
|
|
||||||
if (!myParagraphStarted) {
|
|
||||||
if (myForcedEntry == null) {
|
|
||||||
myForcedEntry = ZLModelFactory.createForcedControlEntry();
|
|
||||||
}
|
}
|
||||||
myForcedEntry.setLeftIndent((short)ptr[cur + 1]);
|
case 0x11:
|
||||||
myForcedEntry.setRightIndent((short)ptr[cur + 2]);
|
changeFont((ptr[cur + 1]));
|
||||||
}
|
break;
|
||||||
break;
|
case 0x1A:
|
||||||
case 0x29:
|
safeBeginParagraph();
|
||||||
if (!myParagraphStarted) {
|
//addImageReference(fromNumber(twoBytes(ptr, cur + 1)));
|
||||||
if (myForcedEntry == null) {
|
break;
|
||||||
myForcedEntry = ZLModelFactory.createForcedControlEntry();
|
case 0x22:
|
||||||
|
if (!myParagraphStarted) {
|
||||||
|
if (myForcedEntry == null) {
|
||||||
|
myForcedEntry = ZLModelFactory.createForcedControlEntry();
|
||||||
|
}
|
||||||
|
myForcedEntry.setLeftIndent((short)ptr[cur + 1]);
|
||||||
|
myForcedEntry.setRightIndent((short)ptr[cur + 2]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x29:
|
||||||
|
if (!myParagraphStarted) {
|
||||||
|
if (myForcedEntry == null) {
|
||||||
|
myForcedEntry = ZLModelFactory.createForcedControlEntry();
|
||||||
|
}
|
||||||
|
switch (ptr[cur + 1]) {
|
||||||
|
case 0: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_LEFT); break;
|
||||||
|
case 1: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_RIGHT); break;
|
||||||
|
case 2: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_CENTER); break;
|
||||||
|
case 3: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_JUSTIFY); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x33: // just break line instead of horizontal rule (TODO: draw horizontal rule?)
|
||||||
|
safeEndParagraph();
|
||||||
|
break;
|
||||||
|
case 0x38:
|
||||||
|
safeEndParagraph();
|
||||||
|
break;
|
||||||
|
case 0x40:
|
||||||
|
safeAddControl(FBTextKind.EMPHASIS, true);
|
||||||
|
break;
|
||||||
|
case 0x48:
|
||||||
|
safeAddControl(FBTextKind.EMPHASIS, false);
|
||||||
|
break;
|
||||||
|
case 0x53: // color setting is ignored
|
||||||
|
break;
|
||||||
|
case 0x5C:
|
||||||
|
//addImageReference(fromNumber(twoBytes(ptr, cur + 3)));
|
||||||
|
break;
|
||||||
|
case 0x60: // underlined text is ignored
|
||||||
|
break;
|
||||||
|
case 0x68: // underlined text is ignored
|
||||||
|
break;
|
||||||
|
case 0x70: // strike-through text is ignored
|
||||||
|
break;
|
||||||
|
case 0x78: // strike-through text is ignored
|
||||||
|
break;
|
||||||
|
case 0x83:
|
||||||
|
{
|
||||||
|
safeBeginParagraph();
|
||||||
|
addData(new char[] { (char)twoBytes(ptr, cur + 2) });
|
||||||
|
myBufferIsEmpty = false;
|
||||||
|
myBytesToSkip = ptr[cur+1];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch (ptr[cur + 1]) {
|
case 0x85: // TODO: process 4-byte unicode character
|
||||||
case 0: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_LEFT); break;
|
break;
|
||||||
case 1: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_RIGHT); break;
|
case 0x8E: // custom font operations are ignored
|
||||||
case 2: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_CENTER); break;
|
case 0x8C:
|
||||||
case 3: myForcedEntry.setAlignmentType(ZLTextAlignmentType.ALIGN_JUSTIFY); break;
|
case 0x8A:
|
||||||
}
|
case 0x88:
|
||||||
}
|
break;
|
||||||
break;
|
case 0x90: // TODO: add table processing
|
||||||
case 0x33: // just break line instead of horizontal rule (TODO: draw horizontal rule?)
|
case 0x92: // TODO: process table
|
||||||
safeEndParagraph();
|
case 0x97: // TODO: process table
|
||||||
break;
|
break;
|
||||||
case 0x38:
|
default: // this should be impossible
|
||||||
safeEndParagraph();
|
//std::cerr << "Oops... function #" << (int)(unsigned char)*ptr << "\n";
|
||||||
break;
|
break;
|
||||||
case 0x40:
|
|
||||||
safeAddControl(FBTextKind.EMPHASIS, true);
|
|
||||||
break;
|
|
||||||
case 0x48:
|
|
||||||
safeAddControl(FBTextKind.EMPHASIS, false);
|
|
||||||
break;
|
|
||||||
case 0x53: // color setting is ignored
|
|
||||||
break;
|
|
||||||
case 0x5C:
|
|
||||||
//addImageReference(fromNumber(twoBytes(ptr, cur + 3)));
|
|
||||||
break;
|
|
||||||
case 0x60: // underlined text is ignored
|
|
||||||
break;
|
|
||||||
case 0x68: // underlined text is ignored
|
|
||||||
break;
|
|
||||||
case 0x70: // strike-through text is ignored
|
|
||||||
break;
|
|
||||||
case 0x78: // strike-through text is ignored
|
|
||||||
break;
|
|
||||||
case 0x83:
|
|
||||||
{
|
|
||||||
char[] utf8 = new char[4];
|
|
||||||
int len = 0;//ZLUnicodeUtil.ucs2ToUtf8(utf8, twoBytes(ptr, cur + 2));
|
|
||||||
safeBeginParagraph();
|
|
||||||
addData(new String(utf8).substring(len).toCharArray());
|
|
||||||
myBufferIsEmpty = false;
|
|
||||||
myBytesToSkip = ptr[cur+1];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 0x85: // TODO: process 4-byte unicode character
|
|
||||||
break;
|
|
||||||
case 0x8E: // custom font operations are ignored
|
|
||||||
case 0x8C:
|
|
||||||
case 0x8A:
|
|
||||||
case 0x88:
|
|
||||||
break;
|
|
||||||
case 0x90: // TODO: add table processing
|
|
||||||
case 0x92: // TODO: process table
|
|
||||||
case 0x97: // TODO: process table
|
|
||||||
break;
|
|
||||||
default: // this should be impossible
|
|
||||||
//std::cerr << "Oops... function #" << (int)(unsigned char)*ptr << "\n";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFont(int font, boolean start) {
|
private void setFont(int font, boolean start) {
|
||||||
switch (font) {
|
switch (font) {
|
||||||
case FontType.FT_REGULAR:
|
case FontType.FT_REGULAR:
|
||||||
break;
|
break;
|
||||||
case FontType.FT_H1:
|
case FontType.FT_H1:
|
||||||
case FontType.FT_H2:
|
case FontType.FT_H2:
|
||||||
case FontType.FT_H3:
|
case FontType.FT_H3:
|
||||||
case FontType.FT_H4:
|
case FontType.FT_H4:
|
||||||
case FontType.FT_H5:
|
case FontType.FT_H5:
|
||||||
case FontType.FT_H6:
|
case FontType.FT_H6:
|
||||||
processHeader(font, start);
|
processHeader(font, start);
|
||||||
break;
|
break;
|
||||||
case FontType.FT_BOLD:
|
case FontType.FT_BOLD:
|
||||||
safeAddControl(FBTextKind.BOLD, start);
|
safeAddControl(FBTextKind.BOLD, start);
|
||||||
break;
|
break;
|
||||||
case FontType.FT_TT:
|
case FontType.FT_TT:
|
||||||
safeAddControl(FBTextKind.CODE, start);
|
safeAddControl(FBTextKind.CODE, start);
|
||||||
break;
|
break;
|
||||||
case FontType.FT_SMALL:
|
case FontType.FT_SMALL:
|
||||||
break;
|
break;
|
||||||
case FontType.FT_SUB:
|
case FontType.FT_SUB:
|
||||||
safeAddControl(FBTextKind.SUB, start);
|
safeAddControl(FBTextKind.SUB, start);
|
||||||
break;
|
break;
|
||||||
case FontType.FT_SUP:
|
case FontType.FT_SUP:
|
||||||
safeAddControl(FBTextKind.SUP, start);
|
safeAddControl(FBTextKind.SUP, start);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFont(int font) {
|
private void changeFont(int font) {
|
||||||
if (myFont == font) {
|
if (myFont == font) {
|
||||||
return;
|
return;
|
||||||
|
@ -561,7 +559,7 @@ public class PluckerBookReader extends BookReader {
|
||||||
this.mySecond = second;
|
this.mySecond = second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO
|
|
||||||
static private int twoBytes(char[] ptr, int offset) {
|
static private int twoBytes(char[] ptr, int offset) {
|
||||||
return 256 * ptr[offset] + ptr[offset+1];
|
return 256 * ptr[offset] + ptr[offset+1];
|
||||||
}
|
}
|
||||||
|
@ -572,4 +570,4 @@ public class PluckerBookReader extends BookReader {
|
||||||
//ZLStringUtil.appendNumber(str, num);
|
//ZLStringUtil.appendNumber(str, num);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
|
@ -42,15 +42,15 @@ public class PluckerPlugin extends PdbPlugin {
|
||||||
try {
|
try {
|
||||||
PdbStream stream = new PluckerTextStream(file);
|
PdbStream stream = new PluckerTextStream(file);
|
||||||
if (stream.open()) {
|
if (stream.open()) {
|
||||||
//detectEncodingAndLanguage(description, stream);
|
detectEncodingAndLanguage(description, stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (description.getEncoding().length() == 0) {
|
if (description.getEncoding().length() == 0) {
|
||||||
// return false;
|
return false;
|
||||||
//}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue