mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
ZLEncodingConverter has a name; Rtf plugin as compilable again
Conflicts: jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp
This commit is contained in:
parent
50d6d2c00f
commit
5f6eb8a469
12 changed files with 42 additions and 16 deletions
|
@ -51,7 +51,7 @@ void FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream)
|
|||
language = info->Language;
|
||||
}
|
||||
encoding = info->Encoding;
|
||||
if ((encoding == "US-ASCII") || (encoding == "ISO-8859-1")) {
|
||||
if ((encoding == "us-ascii") || (encoding == "iso-8859-1")) {
|
||||
encoding = "windows-1252";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ jmethodID AndroidUtil::SMID_PluginCollection_Instance;
|
|||
|
||||
jmethodID AndroidUtil::MID_Encoding_createConverter;
|
||||
|
||||
jfieldID AndroidUtil::FID_EncodingConverter_Name;
|
||||
jmethodID AndroidUtil::MID_EncodingConverter_convert;
|
||||
jmethodID AndroidUtil::MID_EncodingConverter_reset;
|
||||
|
||||
|
@ -161,6 +162,7 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
env->DeleteLocalRef(cls);
|
||||
|
||||
CHECK_NULL( cls = env->FindClass(Class_EncodingConverter) );
|
||||
CHECK_NULL( FID_EncodingConverter_Name = env->GetFieldID(cls, "Name", "Ljava/lang/String;") );
|
||||
CHECK_NULL( MID_EncodingConverter_convert = env->GetMethodID(cls, "convert", "([BII[BI)I") );
|
||||
CHECK_NULL( MID_EncodingConverter_reset = env->GetMethodID(cls, "reset", "()V") );
|
||||
env->DeleteLocalRef(cls);
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
|
||||
static jmethodID MID_Encoding_createConverter;
|
||||
|
||||
static jfieldID FID_EncodingConverter_Name;
|
||||
static jmethodID MID_EncodingConverter_convert;
|
||||
static jmethodID MID_EncodingConverter_reset;
|
||||
|
||||
|
|
|
@ -24,14 +24,18 @@
|
|||
class DummyEncodingConverter : public ZLEncodingConverter {
|
||||
|
||||
private:
|
||||
DummyEncodingConverter();
|
||||
DummyEncodingConverter(const std::string &name);
|
||||
|
||||
public:
|
||||
~DummyEncodingConverter();
|
||||
std::string name() const;
|
||||
void convert(std::string &dst, const char *srcStart, const char *srcEnd);
|
||||
void reset();
|
||||
bool fillTable(int *map);
|
||||
|
||||
private:
|
||||
const std::string myName;
|
||||
|
||||
friend class DummyEncodingConverterProvider;
|
||||
};
|
||||
|
||||
|
@ -40,20 +44,20 @@ bool DummyEncodingConverterProvider::providesConverter(const std::string &encodi
|
|||
return (lowerCasedEncoding == "utf-8") || (lowerCasedEncoding == "us-ascii");
|
||||
}
|
||||
|
||||
shared_ptr<ZLEncodingConverter> DummyEncodingConverterProvider::createConverter() {
|
||||
return new DummyEncodingConverter();
|
||||
shared_ptr<ZLEncodingConverter> DummyEncodingConverterProvider::createConverter(const std::string &name) {
|
||||
return new DummyEncodingConverter(name);
|
||||
}
|
||||
|
||||
shared_ptr<ZLEncodingConverter> DummyEncodingConverterProvider::createConverter(const std::string&) {
|
||||
return createConverter();
|
||||
}
|
||||
|
||||
DummyEncodingConverter::DummyEncodingConverter() {
|
||||
DummyEncodingConverter::DummyEncodingConverter(const std::string &name) : myName(name) {
|
||||
}
|
||||
|
||||
DummyEncodingConverter::~DummyEncodingConverter() {
|
||||
}
|
||||
|
||||
std::string DummyEncodingConverter::name() const {
|
||||
return myName;
|
||||
}
|
||||
|
||||
void DummyEncodingConverter::convert(std::string &dst, const char *srcStart, const char *srcEnd) {
|
||||
dst.append(srcStart, srcEnd - srcStart);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ class DummyEncodingConverterProvider : public ZLEncodingConverterProvider {
|
|||
|
||||
public:
|
||||
bool providesConverter(const std::string &encoding);
|
||||
shared_ptr<ZLEncodingConverter> createConverter();
|
||||
shared_ptr<ZLEncodingConverter> createConverter(const std::string &encoding);
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ private:
|
|||
|
||||
public:
|
||||
~JavaEncodingConverter();
|
||||
std::string name() const;
|
||||
void convert(std::string &dst, const char *srcStart, const char *srcEnd);
|
||||
void reset();
|
||||
bool fillTable(int *map);
|
||||
|
@ -85,6 +86,14 @@ JavaEncodingConverter::~JavaEncodingConverter() {
|
|||
env->DeleteLocalRef(myJavaConverter);
|
||||
}
|
||||
|
||||
std::string JavaEncodingConverter::name() const {
|
||||
JNIEnv *env = AndroidUtil::getEnv();
|
||||
jstring javaName = (jstring)env->GetObjectField(myJavaConverter, AndroidUtil::FID_EncodingConverter_Name);
|
||||
const std::string result = AndroidUtil::fromJavaString(env, javaName);
|
||||
env->DeleteLocalRef(javaName);
|
||||
return result;
|
||||
}
|
||||
|
||||
void JavaEncodingConverter::convert(std::string &dst, const char *srcStart, const char *srcEnd) {
|
||||
JNIEnv *env = AndroidUtil::getEnv();
|
||||
const int srcLen = srcEnd - srcStart;
|
||||
|
|
|
@ -61,6 +61,12 @@ shared_ptr<ZLEncodingConverter> ZLEncodingCollection::converter(const std::strin
|
|||
return 0;
|
||||
}
|
||||
|
||||
shared_ptr<ZLEncodingConverter> ZLEncodingCollection::defaultConverter() const {
|
||||
return DummyEncodingConverterProvider().createConverter();
|
||||
shared_ptr<ZLEncodingConverter> ZLEncodingCollection::converter(int code) const {
|
||||
std::string name;
|
||||
ZLStringUtil::appendNumber(name, code);
|
||||
return converter(name);
|
||||
}
|
||||
|
||||
shared_ptr<ZLEncodingConverter> ZLEncodingCollection::defaultConverter() const {
|
||||
return DummyEncodingConverterProvider().createConverter("utf-8");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ protected:
|
|||
|
||||
public:
|
||||
virtual ~ZLEncodingConverter();
|
||||
virtual std::string name() const = 0;
|
||||
virtual void convert(std::string &dst, const char *srcStart, const char *srcEnd) = 0;
|
||||
void convert(std::string &dst, const std::string &src);
|
||||
virtual void reset() = 0;
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
|
||||
public:
|
||||
shared_ptr<ZLEncodingConverter> converter(const std::string &name) const;
|
||||
shared_ptr<ZLEncodingConverter> converter(int code) const;
|
||||
shared_ptr<ZLEncodingConverter> defaultConverter() const;
|
||||
void registerProvider(shared_ptr<ZLEncodingConverterProvider> provider);
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ static std::string naiveEncodingDetection(const unsigned char *buffer, size_t le
|
|||
return std::string();
|
||||
}
|
||||
}
|
||||
return ascii ? "ascii" : "utf-8";
|
||||
return ascii ? "us-ascii" : "utf-8";
|
||||
}
|
||||
|
||||
shared_ptr<ZLLanguageDetector::LanguageInfo> ZLLanguageDetector::findInfo(const char *buffer, size_t length, int matchingCriterion) {
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
}
|
||||
-keep class org.geometerplus.fbreader.formats.EncodingConverter
|
||||
-keepclassmembers class org.geometerplus.fbreader.formats.EncodingConverter {
|
||||
public ** Name;
|
||||
public int convert(byte[],int,int,byte[],int);
|
||||
public void reset();
|
||||
}
|
||||
|
|
|
@ -23,10 +23,12 @@ import java.nio.*;
|
|||
import java.nio.charset.*;
|
||||
|
||||
public class EncodingConverter {
|
||||
public final String Name;
|
||||
private CharsetDecoder myDecoder;
|
||||
private CharsetEncoder myEncoder;
|
||||
|
||||
EncodingConverter(String encoding) {
|
||||
Name = encoding;
|
||||
myDecoder = Charset.forName(encoding).newDecoder()
|
||||
.onMalformedInput(CodingErrorAction.REPLACE)
|
||||
.onUnmappableCharacter(CodingErrorAction.REPLACE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue