1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 12:00:17 +02:00

CSS stream

This commit is contained in:
Nikolay Pultsin 2014-09-08 21:26:16 +01:00
parent 5b95c153b8
commit b21e516d6a
7 changed files with 91 additions and 12 deletions

View file

@ -24,12 +24,15 @@
#include <ZLLanguageUtil.h>
#include <ZLImage.h>
#include <ZLFileImage.h>
#include <ZLLogger.h>
#include "PdbPlugin.h"
#include "PalmDocStream.h"
#include "MobipocketHtmlBookReader.h"
#include "../txt/PlainTextFormat.h"
#include "../../library/Book.h"
#include "../../bookmodel/BookModel.h"
const std::string MobipocketPlugin::supportedFileType() const {
return "Mobipocket";
@ -42,6 +45,32 @@ void MobipocketPlugin::readDocumentInternal(const ZLFile &file, BookModel &model
MobipocketHtmlBookReader(file, model, format, encoding).readDocument(stream);
}
bool MobipocketPlugin::readModel(BookModel &model) const {
const Book &book = *model.book();
const ZLFile &file = book.file();
ZLLogger::Instance().registerClass("MobiCSS");
shared_ptr<ZLInputStream> cssStream = new PalmDocCssStream(file);
if (cssStream->open()) {
char *buffer = new char[1024];
while (true) {
const int len = cssStream->read(buffer, 1024);
if (len <= 0) {
break;
}
ZLLogger::Instance().println("MobiCSS", std::string(buffer, len));
}
delete[] buffer;
cssStream->close();
}
shared_ptr<ZLInputStream> stream = createStream(file);
PlainTextFormat format(file);
readDocumentInternal(file, model, format, book.encoding(), *stream);
return true;
}
bool MobipocketPlugin::readMetainfo(Book &book) const {
shared_ptr<ZLInputStream> stream = book.file().inputStream();
if (stream.isNull() || ! stream->open()) {
@ -204,7 +233,7 @@ shared_ptr<const ZLImage> MobipocketPlugin::coverImage(const ZLFile &file) const
coverIndex = thumbIndex;
}
PalmDocStream pbStream(file);
PalmDocContentStream pbStream(file);
if (!pbStream.open()) {
return 0;
}

View file

@ -30,7 +30,7 @@ bool PalmDocLikePlugin::providesMetainfo() const {
}
shared_ptr<ZLInputStream> PalmDocLikePlugin::createStream(const ZLFile &file) const {
return new PalmDocStream(file);
return new PalmDocContentStream(file);
}
/*

View file

@ -173,6 +173,33 @@ std::pair<int,int> PalmDocStream::imageLocation(const PdbHeader &header, int ind
}
}
size_t PalmDocStream::sizeOfOpened() {
PalmDocContentStream::PalmDocContentStream(const ZLFile &file) : PalmDocStream(file) {
}
size_t PalmDocContentStream::sizeOfOpened() {
return myTextLength;
}
PalmDocCssStream::PalmDocCssStream(const ZLFile &file) : PalmDocStream(file) {
}
bool PalmDocCssStream::open() {
if (!PalmDocStream::open()) {
return false;
}
seek(myTextLength, false);
if (PalmDocStream::offset() < myTextLength) {
close();
return false;
}
return true;
}
size_t PalmDocCssStream::offset() const {
const size_t o = PalmDocStream::offset();
return o <= myTextLength ? 0 : o - myTextLength;
}
size_t PalmDocCssStream::sizeOfOpened() {
return (size_t)((1 << 31) - 1);
}

View file

@ -27,8 +27,10 @@ class HuffDecompressor;
class PalmDocStream : public PalmDocLikeStream {
public:
protected:
PalmDocStream(const ZLFile &file);
public:
~PalmDocStream();
std::pair<int,int> imageLocation(const PdbHeader &header, int index) const;
@ -37,15 +39,36 @@ public:
private:
bool processRecord();
bool processZeroRecord();
size_t sizeOfOpened();
protected:
unsigned long myTextLength;
private:
unsigned short myCompressionVersion;
unsigned long myTextLength; //TODO: Warning: isn't used
unsigned short myTextRecordNumber;
unsigned short myImageStartIndex;
shared_ptr<HuffDecompressor> myHuffDecompressorPtr;
};
class PalmDocContentStream : public PalmDocStream {
public:
PalmDocContentStream(const ZLFile &file);
private:
size_t sizeOfOpened();
};
class PalmDocCssStream : public PalmDocStream {
public:
PalmDocCssStream(const ZLFile &file);
private:
bool open();
size_t sizeOfOpened();
size_t offset() const;
};
#endif /* __PALMDOCSTREAM_H__ */

View file

@ -51,7 +51,7 @@ class SimplePdbPlugin : public PdbPlugin {
public:
bool readMetainfo(Book &book) const;
bool readModel(BookModel &model) const;
//bool readModel(BookModel &model) const;
protected:
virtual shared_ptr<ZLInputStream> createStream(const ZLFile &file) const = 0;
@ -90,6 +90,7 @@ private:
bool readUids(Book &book) const;
bool readLanguageAndEncoding(Book &book) const;
bool readMetainfo(Book &book) const;
bool readModel(BookModel &model) const;
void readDocumentInternal(const ZLFile &file, BookModel &model, const class PlainTextFormat &format, const std::string &encoding, ZLInputStream &stream) const;
shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;

View file

@ -35,13 +35,12 @@ public:
protected:
virtual bool open();
virtual void close();
void seek(int offset, bool absoluteOffset);
size_t offset() const;
private:
size_t read(char *buffer, size_t maxSize);
void seek(int offset, bool absoluteOffset);
size_t offset() const;
protected:
virtual bool fillBuffer() = 0;

View file

@ -53,21 +53,21 @@ bool SimplePdbPlugin::readMetainfo(Book &book) const {
return true;
}
/*
bool SimplePdbPlugin::readModel(BookModel &model) const {
const Book &book = *model.book();
const ZLFile &file = book.file();
shared_ptr<ZLInputStream> stream = createStream(file);
PlainTextFormat format(file);
/*
if (!format.initialized()) {
PlainTextFormatDetector detector;
detector.detect(*stream, format);
}
*/
readDocumentInternal(file, model, format, book.encoding(), *stream);
return true;
}
*/
void SimplePdbPlugin::readDocumentInternal(const ZLFile&, BookModel &model, const PlainTextFormat &format, const std::string &encoding, ZLInputStream &stream) const {
//if (TextFormatDetector().isHtml(stream)) {