diff --git a/jni/Android.mk b/jni/Android.mk index f4d5358bc..b0a4580b3 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -32,11 +32,20 @@ include $(CLEAR_VARS) LOCAL_MODULE := NativeFormats-v1 LOCAL_LDLIBS := -lz LOCAL_STATIC_LIBRARIES := expat + LOCAL_SRC_FILES := \ NativeFormats/JavaNativeFormatPlugin.cpp \ NativeFormats/JavaPluginCollection.cpp \ - NativeFormats/util/AndroidUtil.cpp + NativeFormats/util/AndroidUtil.cpp \ + NativeFormats/fbreader/src/formats/FormatPlugin.cpp \ + NativeFormats/fbreader/src/formats/PluginCollection.cpp + LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/NativeFormats/util + $(LOCAL_PATH)/NativeFormats/util \ + $(LOCAL_PATH)/NativeFormats/zlibrary/core/src/util \ + $(LOCAL_PATH)/NativeFormats/zlibrary/core/src/image \ + $(LOCAL_PATH)/NativeFormats/zlibrary/core/src/language \ + $(LOCAL_PATH)/NativeFormats/zlibrary/core/src/library \ + $(LOCAL_PATH)/NativeFormats/zlibrary/core/src/filesystem include $(BUILD_SHARED_LIBRARY) diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp new file mode 100644 index 000000000..753946249 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include +#include +#include + +#include "FormatPlugin.h" + +#include "../library/Book.h" + +void FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream) { + std::string language = book.language(); + std::string encoding = book.encoding(); + + if (!encoding.empty() && !language.empty()) { + return; + } + + PluginCollection &collection = PluginCollection::Instance(); + if (language.empty()) { + language = collection.defaultLanguage(); + } + if (encoding.empty()) { + encoding = collection.defaultEncoding(); + } + if (collection.isLanguageAutoDetectEnabled() && stream.open()) { + static const int BUFSIZE = 65536; + char *buffer = new char[BUFSIZE]; + const size_t size = stream.read(buffer, BUFSIZE); + stream.close(); + shared_ptr info = + ZLLanguageDetector().findInfo(buffer, size); + delete[] buffer; + if (!info.isNull()) { + if (!info->Language.empty()) { + language = info->Language; + } + encoding = info->Encoding; + if ((encoding == "US-ASCII") || (encoding == "ISO-8859-1")) { + encoding = "windows-1252"; + } + } + } + book.setEncoding(encoding); + book.setLanguage(language); +} + +void FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream) { + std::string language = book.language(); + if (!language.empty()) { + return; + } + + PluginCollection &collection = PluginCollection::Instance(); + if (language.empty()) { + language = collection.defaultLanguage(); + } + if (collection.isLanguageAutoDetectEnabled() && stream.open()) { + static const int BUFSIZE = 65536; + char *buffer = new char[BUFSIZE]; + const size_t size = stream.read(buffer, BUFSIZE); + stream.close(); + shared_ptr info = + ZLLanguageDetector().findInfo(buffer, size); + delete[] buffer; + if (!info.isNull()) { + if (!info->Language.empty()) { + language = info->Language; + } + } + } + book.setLanguage(language); +} + +const std::string &FormatPlugin::tryOpen(const ZLFile&) const { + static const std::string EMPTY = ""; + return EMPTY; +} + +shared_ptr FormatPlugin::coverImage(const ZLFile &file) const { + return 0; +} diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h new file mode 100644 index 000000000..2dbc45e92 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __FORMATPLUGIN_H__ +#define __FORMATPLUGIN_H__ + +#include + +#include +#include + +#include + +class Book; +class BookModel; +//class ZLOptionsDialog; +//class ZLOptionsDialogTab; +class ZLFile; +class ZLInputStream; +class ZLImage; + +/*class FormatInfoPage { + +protected: + FormatInfoPage(); + +public: + virtual ~FormatInfoPage(); +};*/ + +class FormatPlugin { + +protected: + FormatPlugin(); + +public: + virtual ~FormatPlugin(); + + virtual bool providesMetaInfo() const = 0; + virtual const std::string supportedFileType() const = 0; + //virtual FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file); + + virtual const std::string &tryOpen(const ZLFile &file) const; + virtual bool readMetaInfo(Book &book) const = 0; + virtual bool readLanguageAndEncoding(Book &book) const = 0; + virtual bool readModel(BookModel &model) const = 0; + virtual shared_ptr coverImage(const ZLFile &file) const; + +protected: + static void detectEncodingAndLanguage(Book &book, ZLInputStream &stream); + static void detectLanguage(Book &book, ZLInputStream &stream); +}; + +class PluginCollection { + +public: + static PluginCollection &Instance(); + static void deleteInstance(); + +private: + PluginCollection(); + +public: + ~PluginCollection(); + +public: + std::vector > plugins() const; + shared_ptr pluginByType(const std::string &fileType) const; + + bool isLanguageAutoDetectEnabled(); + std::string defaultLanguage(); + std::string defaultEncoding(); + +private: + static PluginCollection *ourInstance; + + jobject myJavaInstance; + + std::vector > myPlugins; +}; + +//inline FormatInfoPage::FormatInfoPage() {} +//inline FormatInfoPage::~FormatInfoPage() {} +inline FormatPlugin::FormatPlugin() {} +inline FormatPlugin::~FormatPlugin() {} +//inline FormatInfoPage *FormatPlugin::createInfoPage(ZLOptionsDialog&, const ZLFile&) { return 0; } + +inline std::vector > PluginCollection::plugins() const { + return myPlugins; +} + +#endif /* __FORMATPLUGIN_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/PluginCollection.cpp b/jni/NativeFormats/fbreader/src/formats/PluginCollection.cpp new file mode 100644 index 000000000..dcddcd7b4 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/formats/PluginCollection.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include + +#include +#include + +#include "FormatPlugin.h" + +#include "../library/Book.h" + +//#include "fb2/FB2Plugin.h" +////#include "docbook/DocBookPlugin.h" +//#include "html/HtmlPlugin.h" +//#include "txt/TxtPlugin.h" +//#include "pdb/PdbPlugin.h" +//#include "tcr/TcrPlugin.h" +//#include "oeb/OEBPlugin.h" +//#include "chm/CHMPlugin.h" +//#include "rtf/RtfPlugin.h" +//#include "openreader/OpenReaderPlugin.h" +////#include "pdf/PdfPlugin.h" + +PluginCollection *PluginCollection::ourInstance = 0; + +PluginCollection &PluginCollection::Instance() { + if (ourInstance == 0) { + ourInstance = new PluginCollection(); + //ourInstance->myPlugins.push_back(new FB2Plugin()); +// //ourInstance->myPlugins.push_back(new DocBookPlugin()); + //ourInstance->myPlugins.push_back(new HtmlPlugin()); + //ourInstance->myPlugins.push_back(new TxtPlugin()); +// ourInstance->myPlugins.push_back(new PluckerPlugin()); +// ourInstance->myPlugins.push_back(new PalmDocPlugin()); +// ourInstance->myPlugins.push_back(new MobipocketPlugin()); +// ourInstance->myPlugins.push_back(new EReaderPlugin()); +// ourInstance->myPlugins.push_back(new ZTXTPlugin()); +// ourInstance->myPlugins.push_back(new TcrPlugin()); +// ourInstance->myPlugins.push_back(new CHMPlugin()); + //ourInstance->myPlugins.push_back(new OEBPlugin()); + //ourInstance->myPlugins.push_back(new RtfPlugin()); +// ourInstance->myPlugins.push_back(new OpenReaderPlugin()); +// //ourInstance->myPlugins.push_back(new PdfPlugin()); + } + return *ourInstance; +} + +void PluginCollection::deleteInstance() { + if (ourInstance != 0) { + delete ourInstance; + ourInstance = 0; + } +} + +PluginCollection::PluginCollection() { + JNIEnv *env = AndroidUtil::getEnv(); + jclass cls = env->FindClass(AndroidUtil::Class_PluginCollection); + jobject instance = env->CallStaticObjectMethod(cls, AndroidUtil::SMID_PluginCollection_Instance); + myJavaInstance = env->NewGlobalRef(instance); + env->DeleteLocalRef(instance); + env->DeleteLocalRef(cls); +} + +PluginCollection::~PluginCollection() { + JNIEnv *env = AndroidUtil::getEnv(); + env->DeleteGlobalRef(myJavaInstance); +} + +shared_ptr PluginCollection::pluginByType(const std::string &fileType) const { + for (std::vector >::const_iterator it = myPlugins.begin(); it != myPlugins.end(); ++it) { + if (fileType == (*it)->supportedFileType()) { + return *it; + } + } + return 0; +} + +bool PluginCollection::isLanguageAutoDetectEnabled() { + JNIEnv *env = AndroidUtil::getEnv(); + jboolean res = env->CallBooleanMethod(myJavaInstance, AndroidUtil::MID_PluginCollection_isLanguageAutoDetectEnabled); + return res != 0; +} + +std::string PluginCollection::defaultLanguage() { + JNIEnv *env = AndroidUtil::getEnv(); + jstring res = (jstring)env->CallObjectMethod(myJavaInstance, AndroidUtil::MID_PluginCollection_getDefaultLanguage); + const char *data = env->GetStringUTFChars(res, 0); + std::string str(data); + env->ReleaseStringUTFChars(res, data); + env->DeleteLocalRef(res); + return str; +} + +std::string PluginCollection::defaultEncoding() { + JNIEnv *env = AndroidUtil::getEnv(); + jstring res = (jstring)env->CallObjectMethod(myJavaInstance, AndroidUtil::MID_PluginCollection_getDefaultEncoding); + const char *data = env->GetStringUTFChars(res, 0); + std::string str(data); + env->ReleaseStringUTFChars(res, data); + env->DeleteLocalRef(res); + return str; +} diff --git a/jni/NativeFormats/fbreader/src/library/Book.h b/jni/NativeFormats/fbreader/src/library/Book.h new file mode 100644 index 000000000..5793a3cb0 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/library/Book.h @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __BOOK_H__ +#define __BOOK_H__ + +#include + +#include + +#include + +#include + +#include "Lists.h" + +class Author; +class Tag; + +class Book { + +public: + static const std::string AutoEncoding; + +public: + static shared_ptr createBook( + const ZLFile &file, + int id, + const std::string &encoding, + const std::string &language, + const std::string &title + ); + + static shared_ptr loadFromFile(const ZLFile &file); + + // this method is used in Migration only + //static shared_ptr loadFromBookInfo(const ZLFile &file); + + static shared_ptr loadFromJavaBook(JNIEnv *env, jobject javaBook); + +public: + Book(const ZLFile &file, int id); + +public: + ~Book(); + +public: // unmodifiable book methods + const std::string &title() const; + const ZLFile &file() const; + const std::string &language() const; + const std::string &encoding() const; + const std::string &seriesTitle() const; + int indexInSeries() const; + + const TagList &tags() const; + const AuthorList &authors() const; + +public: // modifiable book methods + void setTitle(const std::string &title); + void setLanguage(const std::string &language); + void setEncoding(const std::string &encoding); + void setSeries(const std::string &title, int index); + +public: + bool addTag(shared_ptr tag); + bool addTag(const std::string &fullName); + bool removeTag(shared_ptr tag, bool includeSubTags); + bool renameTag(shared_ptr from, shared_ptr to, bool includeSubTags); + bool cloneTag(shared_ptr from, shared_ptr to, bool includeSubTags); + void removeAllTags(); + + void addAuthor(shared_ptr author); + void addAuthor(const std::string &displayName, const std::string &sortKey = std::string()); + bool replaceAuthor(shared_ptr from, shared_ptr to); + void removeAllAuthors(); + +public: + int bookId() const; + void setBookId(int bookId); + +private: + int myBookId; + + const ZLFile myFile; + std::string myTitle; + std::string myLanguage; + std::string myEncoding; + std::string mySeriesTitle; + int myIndexInSeries; + TagList myTags; + AuthorList myAuthors; + +private: // disable copying + Book(const Book &); + const Book &operator = (const Book &); +}; + +class BookComparator { + +public: + bool operator () ( + const shared_ptr book0, + const shared_ptr book1 + ) const; +}; + +class BookByFileNameComparator { + +public: + bool operator () ( + const shared_ptr book0, + const shared_ptr book1 + ) const; +}; + +inline const std::string &Book::title() const { return myTitle; } +inline const ZLFile &Book::file() const { return myFile; } +inline const std::string &Book::language() const { return myLanguage; } +inline const std::string &Book::encoding() const { return myEncoding; } +inline const std::string &Book::seriesTitle() const { return mySeriesTitle; } +inline int Book::indexInSeries() const { return myIndexInSeries; } + +inline const TagList &Book::tags() const { return myTags; } +inline const AuthorList &Book::authors() const { return myAuthors; } + +inline int Book::bookId() const { return myBookId; } +inline void Book::setBookId(int bookId) { myBookId = bookId; } + +#endif /* __BOOK_H__ */ diff --git a/jni/NativeFormats/fbreader/src/library/Lists.h b/jni/NativeFormats/fbreader/src/library/Lists.h new file mode 100644 index 000000000..9768841e8 --- /dev/null +++ b/jni/NativeFormats/fbreader/src/library/Lists.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __LISTS_H__ +#define __LISTS_H__ + +#include +#include + +#include + +class Book; +class Author; +class Tag; +class BookByFileNameComparator; + +typedef std::vector > BookList; +typedef std::set,BookByFileNameComparator> BookSet; +typedef std::vector > AuthorList; +typedef std::vector > TagList; +typedef std::set > TagSet; + +#endif /* __LISTS_H__ */ diff --git a/jni/NativeFormats/util/AndroidUtil.h b/jni/NativeFormats/util/AndroidUtil.h index baff9264c..f452980ac 100644 --- a/jni/NativeFormats/util/AndroidUtil.h +++ b/jni/NativeFormats/util/AndroidUtil.h @@ -20,10 +20,15 @@ #ifndef __ANDROIDUTIL_H__ #define __ANDROIDUTIL_H__ +#include + class AndroidUtil { public: static const char * const Class_NativeFormatPlugin; + +public: + static JNIEnv *getEnv(); }; #endif /* __ANDROIDUTIL_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h new file mode 100644 index 000000000..e0ff44f07 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLFILE_H__ +#define __ZLFILE_H__ + +#include +#include + +#include +#include + +class ZLDir; +class ZLInputStream; +class ZLOutputStream; + +class ZLFile { + +public: + static const ZLFile NO_FILE; + +private: + static std::map > ourPlainStreamCache; + +public: + static std::string fileNameToUtf8(const std::string &fileName); + static std::string replaceIllegalCharacters(const std::string &fileName, char replaceWith); + +public: + enum ArchiveType { + NONE = 0, + GZIP = 0x0001, + //BZIP2 = 0x0002, + COMPRESSED = 0x00ff, + ZIP = 0x0100, + //TAR = 0x0200, + ARCHIVE = 0xff00, + }; + +private: + ZLFile(); + +public: + explicit ZLFile(const std::string &path, const std::string &mimeType = std::string()); + ~ZLFile(); + + bool exists() const; + size_t size() const; + + void forceArchiveType(ArchiveType type) const; + + bool isCompressed() const; + bool isDirectory() const; + bool isArchive() const; + + bool remove() const; + bool canRemove() const; + + const std::string &path() const; + const std::string &name(bool hideExtension) const; + const std::string &extension() const; + + const std::string &mimeType() const; + + std::string physicalFilePath() const; + std::string resolvedPath() const; + + shared_ptr inputStream() const; + shared_ptr outputStream(bool writeThrough = false) const; + shared_ptr directory(bool createUnexisting = false) const; + + bool operator == (const ZLFile &other) const; + bool operator != (const ZLFile &other) const; + bool operator < (const ZLFile &other) const; + +private: + void fillInfo() const; + shared_ptr envelopeCompressedStream(shared_ptr &base) const; + +private: + std::string myPath; + std::string myNameWithExtension; + std::string myNameWithoutExtension; + std::string myExtension; + mutable std::string myMimeType; + mutable bool myMimeTypeIsUpToDate; + mutable ArchiveType myArchiveType; + mutable ZLFileInfo myInfo; + mutable bool myInfoIsFilled; +}; + +inline ZLFile::~ZLFile() {} + +inline bool ZLFile::isCompressed() const { return (myArchiveType & COMPRESSED) != 0; } +inline bool ZLFile::isArchive() const { return (myArchiveType & ARCHIVE) != 0; } + +inline const std::string &ZLFile::path() const { return myPath; } +inline const std::string &ZLFile::name(bool hideExtension) const { return hideExtension ? myNameWithoutExtension : myNameWithExtension; } +inline const std::string &ZLFile::extension() const { return myExtension; } + +inline bool ZLFile::operator == (const ZLFile &other) const { return myPath == other.myPath; } +inline bool ZLFile::operator != (const ZLFile &other) const { return myPath != other.myPath; } +inline bool ZLFile::operator < (const ZLFile &other) const { return myPath < other.myPath; } + +#endif /* __ZLFILE_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h new file mode 100644 index 000000000..5ba9e0235 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLFILEINFO_H__ +#define __ZLFILEINFO_H__ + +struct ZLFileInfo { + bool Exists; + bool IsDirectory; + size_t Size; + + ZLFileInfo(); +}; + +inline ZLFileInfo::ZLFileInfo() : Exists(false), IsDirectory(false), Size(0) { +} + +#endif /* __ZLFILEINFO_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h new file mode 100644 index 000000000..8df26f2b7 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLINPUTSTREAM_H__ +#define __ZLINPUTSTREAM_H__ + +#include + +#include +#include + +class ZLInputStream : public ZLUserDataHolder { + +protected: + ZLInputStream(); + +public: + virtual ~ZLInputStream(); + virtual bool open() = 0; + virtual size_t read(char *buffer, size_t maxSize) = 0; + virtual void close() = 0; + + virtual void seek(int offset, bool absoluteOffset) = 0; + virtual size_t offset() const = 0; + virtual size_t sizeOfOpened() = 0; + +private: + // disable copying + ZLInputStream(const ZLInputStream&); + const ZLInputStream &operator = (const ZLInputStream&); +}; + +class ZLInputStreamDecorator : public ZLInputStream { + +public: + ZLInputStreamDecorator(shared_ptr decoratee); + +private: + bool open(); + size_t read(char *buffer, size_t maxSize); + void close(); + + void seek(int offset, bool absoluteOffset); + size_t offset() const; + size_t sizeOfOpened(); + +private: + shared_ptr myBaseStream; + size_t myBaseOffset; +}; + +inline ZLInputStream::ZLInputStream() {} +inline ZLInputStream::~ZLInputStream() {} + +#endif /* __ZLINPUTSTREAM_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/image/ZLImage.h b/jni/NativeFormats/zlibrary/core/src/image/ZLImage.h new file mode 100644 index 000000000..541d42652 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/image/ZLImage.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLIMAGE_H__ +#define __ZLIMAGE_H__ + +#include + +#include + +class ZLImage { + +protected: + ZLImage(); + +public: + virtual ~ZLImage(); + virtual bool isSingle() const = 0; +}; + +class ZLSingleImage : public ZLImage { + +public: + enum Kind { + REGULAR_IMAGE = 1, + FILE_IMAGE = 2, + BASE64_ENCODED_IMAGE = 3, + }; + +protected: + ZLSingleImage(const std::string &mimeType); + virtual ~ZLSingleImage(); + +public: + bool isSingle() const { return true; } + const std::string &mimeType() const; + virtual const shared_ptr stringData() const = 0; + + virtual Kind kind() const; + +private: + std::string myMimeType; +}; + +class ZLMultiImage : public ZLImage { + +protected: + ZLMultiImage(); + virtual ~ZLMultiImage(); + +public: + bool isSingle() const { return false; } + virtual unsigned int rows() const = 0; + virtual unsigned int columns() const = 0; + virtual shared_ptr subImage(unsigned int row, unsigned int column) const = 0; +}; + +inline ZLImage::ZLImage() {} +inline ZLImage::~ZLImage() {} + +inline ZLSingleImage::ZLSingleImage(const std::string &mimeType) : myMimeType(mimeType) {} +inline ZLSingleImage::~ZLSingleImage() {} +inline const std::string &ZLSingleImage::mimeType() const { return myMimeType; } +inline ZLSingleImage::Kind ZLSingleImage::kind() const { return REGULAR_IMAGE; } + +inline ZLMultiImage::ZLMultiImage() : ZLImage() {} +inline ZLMultiImage::~ZLMultiImage() {} + +#endif /* __ZLIMAGE_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h new file mode 100644 index 000000000..f70798be3 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLLANGUAGEDETECTOR_H__ +#define __ZLLANGUAGEDETECTOR_H__ + +#include +#include + +//#include + +class ZLStatisticsBasedMatcher; + +class ZLLanguageDetector { + +public: + struct LanguageInfo { + LanguageInfo(const std::string &language, const std::string &encoding); + const std::string Language; + const std::string Encoding; + }; + +public: + ZLLanguageDetector(); + ~ZLLanguageDetector(); + + shared_ptr findInfo(const char *buffer, size_t length, int matchingCriterion = 0); + +private: + typedef std::vector > SBVector; + SBVector myMatchers; +}; + +#endif /* __ZLLANGUAGEDETECTOR_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.h b/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.h new file mode 100644 index 000000000..2b4bccca6 --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLIBRARY_H__ +#define __ZLIBRARY_H__ + +#include + +//class ZLApplication; +//class ZLPaintContext; + +class ZLibrary { + +public: + static const std::string FileNameDelimiter; + static const std::string PathDelimiter; + static const std::string EndOfLine; + static std::string Language(); +// static std::string Country(); + + static std::string Version(); + + static const std::string BaseDirectory; + static const std::string &ZLibraryDirectory(); + +// static const std::string &ImageDirectory(); +// static const std::string &ApplicationName(); +// static const std::string &ApplicationImageDirectory(); + static const std::string &ApplicationDirectory(); +// static const std::string &DefaultFilesPathPrefix(); + +// static const std::string &ApplicationWritableDirectory(); + +public: + static bool init(int &argc, char **&argv); + static void parseArguments(int &argc, char **&argv); +// static ZLPaintContext *createContext(); +// static void run(ZLApplication *application); + static void shutdown(); + +private: +// static void initLocale(); + +private: +// static bool ourLocaleIsInitialized; +// static std::string ourLanguage; +// static std::string ourCountry; + static std::string ourZLibraryDirectory; + +// static std::string ourImageDirectory; +// static std::string ourApplicationImageDirectory; + static std::string ourApplicationName; + static std::string ourApplicationDirectory; +// static std::string ourApplicationWritableDirectory; +// static std::string ourDefaultFilesPathPrefix; + +private: +// static std::string replaceRegExps(const std::string &pattern); + +public: + static void initApplication(const std::string &name); + +private: + ZLibrary(); + +friend class ZLApplicationBase; +}; + +inline const std::string &ZLibrary::ZLibraryDirectory() { return ourZLibraryDirectory; } +//inline const std::string &ZLibrary::ApplicationName() { return ourApplicationName; } +//inline const std::string &ZLibrary::ImageDirectory() { return ourImageDirectory; } +//inline const std::string &ZLibrary::ApplicationImageDirectory() { return ourApplicationImageDirectory; } +inline const std::string &ZLibrary::ApplicationDirectory() { return ourApplicationDirectory; } +//inline const std::string &ZLibrary::ApplicationWritableDirectory() { return ourApplicationWritableDirectory; } +//inline const std::string &ZLibrary::DefaultFilesPathPrefix() { return ourDefaultFilesPathPrefix; } + +#endif /* __ZLIBRARY_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLUserData.h b/jni/NativeFormats/zlibrary/core/src/util/ZLUserData.h new file mode 100644 index 000000000..528adf7db --- /dev/null +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLUserData.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ZLUSERDATA_H__ +#define __ZLUSERDATA_H__ + +#include +#include + +#include + +class ZLUserData { + +public: + virtual ~ZLUserData(); +}; + +class ZLUserDataHolder { + +protected: + virtual ~ZLUserDataHolder(); + +public: + void addUserData(const std::string &key, shared_ptr data); + void removeUserData(const std::string &key); + shared_ptr getUserData(const std::string &key) const; + +private: + std::map > myDataMap; +}; + +#endif /* __ZLUSERDATA_H__ */