mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
native => master merging
This commit is contained in:
parent
56ae87e6f2
commit
1fc9eac6e8
14 changed files with 1030 additions and 2 deletions
|
@ -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)
|
||||
|
|
101
jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp
Normal file
101
jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <jni.h>
|
||||
|
||||
#include <ZLInputStream.h>
|
||||
#include <ZLLanguageDetector.h>
|
||||
#include <ZLImage.h>
|
||||
|
||||
#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<ZLLanguageDetector::LanguageInfo> 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<ZLLanguageDetector::LanguageInfo> 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<ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
||||
return 0;
|
||||
}
|
108
jni/NativeFormats/fbreader/src/formats/FormatPlugin.h
Normal file
108
jni/NativeFormats/fbreader/src/formats/FormatPlugin.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <jni.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
|
||||
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<ZLImage> 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<shared_ptr<FormatPlugin> > plugins() const;
|
||||
shared_ptr<FormatPlugin> pluginByType(const std::string &fileType) const;
|
||||
|
||||
bool isLanguageAutoDetectEnabled();
|
||||
std::string defaultLanguage();
|
||||
std::string defaultEncoding();
|
||||
|
||||
private:
|
||||
static PluginCollection *ourInstance;
|
||||
|
||||
jobject myJavaInstance;
|
||||
|
||||
std::vector<shared_ptr<FormatPlugin> > 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<shared_ptr<FormatPlugin> > PluginCollection::plugins() const {
|
||||
return myPlugins;
|
||||
}
|
||||
|
||||
#endif /* __FORMATPLUGIN_H__ */
|
119
jni/NativeFormats/fbreader/src/formats/PluginCollection.cpp
Normal file
119
jni/NativeFormats/fbreader/src/formats/PluginCollection.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <AndroidUtil.h>
|
||||
|
||||
#include <ZLibrary.h>
|
||||
#include <ZLFile.h>
|
||||
|
||||
#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<FormatPlugin> PluginCollection::pluginByType(const std::string &fileType) const {
|
||||
for (std::vector<shared_ptr<FormatPlugin> >::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;
|
||||
}
|
145
jni/NativeFormats/fbreader/src/library/Book.h
Normal file
145
jni/NativeFormats/fbreader/src/library/Book.h
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <jni.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
|
||||
#include <ZLFile.h>
|
||||
|
||||
#include "Lists.h"
|
||||
|
||||
class Author;
|
||||
class Tag;
|
||||
|
||||
class Book {
|
||||
|
||||
public:
|
||||
static const std::string AutoEncoding;
|
||||
|
||||
public:
|
||||
static shared_ptr<Book> createBook(
|
||||
const ZLFile &file,
|
||||
int id,
|
||||
const std::string &encoding,
|
||||
const std::string &language,
|
||||
const std::string &title
|
||||
);
|
||||
|
||||
static shared_ptr<Book> loadFromFile(const ZLFile &file);
|
||||
|
||||
// this method is used in Migration only
|
||||
//static shared_ptr<Book> loadFromBookInfo(const ZLFile &file);
|
||||
|
||||
static shared_ptr<Book> 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> tag);
|
||||
bool addTag(const std::string &fullName);
|
||||
bool removeTag(shared_ptr<Tag> tag, bool includeSubTags);
|
||||
bool renameTag(shared_ptr<Tag> from, shared_ptr<Tag> to, bool includeSubTags);
|
||||
bool cloneTag(shared_ptr<Tag> from, shared_ptr<Tag> to, bool includeSubTags);
|
||||
void removeAllTags();
|
||||
|
||||
void addAuthor(shared_ptr<Author> author);
|
||||
void addAuthor(const std::string &displayName, const std::string &sortKey = std::string());
|
||||
bool replaceAuthor(shared_ptr<Author> from, shared_ptr<Author> 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<Book> book0,
|
||||
const shared_ptr<Book> book1
|
||||
) const;
|
||||
};
|
||||
|
||||
class BookByFileNameComparator {
|
||||
|
||||
public:
|
||||
bool operator () (
|
||||
const shared_ptr<Book> book0,
|
||||
const shared_ptr<Book> 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__ */
|
39
jni/NativeFormats/fbreader/src/library/Lists.h
Normal file
39
jni/NativeFormats/fbreader/src/library/Lists.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <vector>
|
||||
#include <set>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
|
||||
class Book;
|
||||
class Author;
|
||||
class Tag;
|
||||
class BookByFileNameComparator;
|
||||
|
||||
typedef std::vector<shared_ptr<Book> > BookList;
|
||||
typedef std::set<shared_ptr<Book>,BookByFileNameComparator> BookSet;
|
||||
typedef std::vector<shared_ptr<Author> > AuthorList;
|
||||
typedef std::vector<shared_ptr<Tag> > TagList;
|
||||
typedef std::set<shared_ptr<Tag> > TagSet;
|
||||
|
||||
#endif /* __LISTS_H__ */
|
|
@ -20,10 +20,15 @@
|
|||
#ifndef __ANDROIDUTIL_H__
|
||||
#define __ANDROIDUTIL_H__
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
class AndroidUtil {
|
||||
|
||||
public:
|
||||
static const char * const Class_NativeFormatPlugin;
|
||||
|
||||
public:
|
||||
static JNIEnv *getEnv();
|
||||
};
|
||||
|
||||
#endif /* __ANDROIDUTIL_H__ */
|
||||
|
|
121
jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h
Normal file
121
jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <string>
|
||||
#include <map>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
#include <ZLFileInfo.h>
|
||||
|
||||
class ZLDir;
|
||||
class ZLInputStream;
|
||||
class ZLOutputStream;
|
||||
|
||||
class ZLFile {
|
||||
|
||||
public:
|
||||
static const ZLFile NO_FILE;
|
||||
|
||||
private:
|
||||
static std::map<std::string,weak_ptr<ZLInputStream> > 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<ZLInputStream> inputStream() const;
|
||||
shared_ptr<ZLOutputStream> outputStream(bool writeThrough = false) const;
|
||||
shared_ptr<ZLDir> 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<ZLInputStream> envelopeCompressedStream(shared_ptr<ZLInputStream> &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__ */
|
34
jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h
Normal file
34
jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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__ */
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
#include <ZLUserData.h>
|
||||
|
||||
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<ZLInputStream> 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<ZLInputStream> myBaseStream;
|
||||
size_t myBaseOffset;
|
||||
};
|
||||
|
||||
inline ZLInputStream::ZLInputStream() {}
|
||||
inline ZLInputStream::~ZLInputStream() {}
|
||||
|
||||
#endif /* __ZLINPUTSTREAM_H__ */
|
85
jni/NativeFormats/zlibrary/core/src/image/ZLImage.h
Normal file
85
jni/NativeFormats/zlibrary/core/src/image/ZLImage.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
|
||||
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<std::string> 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<const ZLImage> 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__ */
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <vector>
|
||||
#include <string>
|
||||
|
||||
//#include <shared_ptr.h>
|
||||
|
||||
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<LanguageInfo> findInfo(const char *buffer, size_t length, int matchingCriterion = 0);
|
||||
|
||||
private:
|
||||
typedef std::vector<shared_ptr<ZLStatisticsBasedMatcher> > SBVector;
|
||||
SBVector myMatchers;
|
||||
};
|
||||
|
||||
#endif /* __ZLLANGUAGEDETECTOR_H__ */
|
93
jni/NativeFormats/zlibrary/core/src/library/ZLibrary.h
Normal file
93
jni/NativeFormats/zlibrary/core/src/library/ZLibrary.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
//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__ */
|
48
jni/NativeFormats/zlibrary/core/src/util/ZLUserData.h
Normal file
48
jni/NativeFormats/zlibrary/core/src/util/ZLUserData.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2008-2012 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* 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 <map>
|
||||
#include <string>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
|
||||
class ZLUserData {
|
||||
|
||||
public:
|
||||
virtual ~ZLUserData();
|
||||
};
|
||||
|
||||
class ZLUserDataHolder {
|
||||
|
||||
protected:
|
||||
virtual ~ZLUserDataHolder();
|
||||
|
||||
public:
|
||||
void addUserData(const std::string &key, shared_ptr<ZLUserData> data);
|
||||
void removeUserData(const std::string &key);
|
||||
shared_ptr<ZLUserData> getUserData(const std::string &key) const;
|
||||
|
||||
private:
|
||||
std::map<std::string,shared_ptr<ZLUserData> > myDataMap;
|
||||
};
|
||||
|
||||
#endif /* __ZLUSERDATA_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue