mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2024-12-29 03:19:44 +00:00
to_utf8, Utf8Encoder: pass encoding as constructor parameter
Edit other files accordingly.
This commit is contained in:
parent
cc792da858
commit
63f09462fd
@ -165,23 +165,12 @@ bool parseOptions (int argc, char** argv, Arguments &info)
|
||||
|
||||
// Font encoding settings
|
||||
info.encoding = variables["encoding"].as<std::string>();
|
||||
if (info.encoding == "win1250")
|
||||
if(info.encoding != "win1250" && info.encoding != "win1251" && info.encoding != "win1252")
|
||||
{
|
||||
std::cout << "Using Central and Eastern European font encoding." << std::endl;
|
||||
}
|
||||
else if (info.encoding == "win1251")
|
||||
{
|
||||
std::cout << "Using Cyrillic font encoding." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(info.encoding != "win1252")
|
||||
{
|
||||
std::cout << info.encoding << " is not a valid encoding option." << std::endl;
|
||||
info.encoding = "win1252";
|
||||
}
|
||||
std::cout << "Using default (English) font encoding." << std::endl;
|
||||
std::cout << info.encoding << " is not a valid encoding option." << std::endl;
|
||||
info.encoding = "win1252";
|
||||
}
|
||||
std::cout << ToUTF8::encodingUsingMessage(info.encoding) << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -262,7 +251,8 @@ void printRaw(ESM::ESMReader &esm)
|
||||
int load(Arguments& info)
|
||||
{
|
||||
ESM::ESMReader& esm = info.reader;
|
||||
esm.setEncoding(ToUTF8::calculateEncoding(info.encoding));
|
||||
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(info.encoding));
|
||||
esm.setEncoder(&encoder);
|
||||
|
||||
std::string filename = info.filename;
|
||||
std::cout << "Loading file: " << filename << std::endl;
|
||||
@ -432,7 +422,8 @@ int clone(Arguments& info)
|
||||
std::cout << std::endl << "Saving records to: " << info.outname << "..." << std::endl;
|
||||
|
||||
ESM::ESMWriter& esm = info.writer;
|
||||
esm.setEncoding(info.encoding);
|
||||
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(info.encoding));
|
||||
esm.setEncoder(&encoder);
|
||||
esm.setAuthor(info.data.author);
|
||||
esm.setDescription(info.data.description);
|
||||
esm.setVersion(info.data.version);
|
||||
|
@ -272,7 +272,8 @@ void DataFilesModel::addMasters(const QString &path)
|
||||
foreach (const QString &path, dir.entryList()) {
|
||||
try {
|
||||
ESM::ESMReader fileReader;
|
||||
fileReader.setEncoding(ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
||||
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
||||
fileReader.setEncoder(&encoder);
|
||||
fileReader.open(dir.absoluteFilePath(path).toStdString());
|
||||
|
||||
ESM::ESMReader::MasterList mlist = fileReader.getMasters();
|
||||
@ -335,7 +336,8 @@ void DataFilesModel::addPlugins(const QString &path)
|
||||
|
||||
try {
|
||||
ESM::ESMReader fileReader;
|
||||
fileReader.setEncoding(ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
||||
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding(mEncoding.toStdString()));
|
||||
fileReader.setEncoder(&encoder);
|
||||
fileReader.open(dir.absoluteFilePath(path).toStdString());
|
||||
|
||||
ESM::ESMReader::MasterList mlist = fileReader.getMasters();
|
||||
|
@ -649,8 +649,7 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) {
|
||||
std::string section("");
|
||||
MwIniImporter::multistrmap map;
|
||||
boost::iostreams::stream<boost::iostreams::file_source>file(filename.c_str());
|
||||
ToUTF8::Utf8Encoder encoder;
|
||||
encoder.setEncoding(mEncoding);
|
||||
ToUTF8::Utf8Encoder encoder(mEncoding);
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
|
@ -331,11 +331,15 @@ void OMW::Engine::go()
|
||||
// cursor replacer (converts the cursor from the bsa so they can be used by mygui)
|
||||
MWGui::CursorReplace replacer;
|
||||
|
||||
// Create encoder
|
||||
ToUTF8::Utf8Encoder encoder (mEncoding);
|
||||
|
||||
// Create the world
|
||||
mEnvironment.setWorld (new MWWorld::World (*mOgre, mFileCollections, mMaster,
|
||||
mResDir, mCfgMgr.getCachePath(), mNewGame, mEncoding, mFallbackMap));
|
||||
mResDir, mCfgMgr.getCachePath(), mNewGame, &encoder, mFallbackMap));
|
||||
|
||||
//Load translation data
|
||||
mTranslationDataStorage.setEncoder(&encoder);
|
||||
mTranslationDataStorage.loadTranslationData(mFileCollections, mMaster);
|
||||
|
||||
// Create window manager - this manages all the MW-specific GUI windows
|
||||
@ -494,7 +498,6 @@ void OMW::Engine::showFPS(int level)
|
||||
void OMW::Engine::setEncoding(const ToUTF8::FromType& encoding)
|
||||
{
|
||||
mEncoding = encoding;
|
||||
mTranslationDataStorage.setEncoding (encoding);
|
||||
}
|
||||
|
||||
void OMW::Engine::setFallbackValues(std::map<std::string,std::string> fallbackMap)
|
||||
|
@ -170,7 +170,7 @@ namespace MWWorld
|
||||
World::World (OEngine::Render::OgreRenderer& renderer,
|
||||
const Files::Collections& fileCollections,
|
||||
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
||||
const ToUTF8::FromType& encoding, std::map<std::string,std::string> fallbackMap)
|
||||
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap)
|
||||
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
||||
mSky (true), mCells (mStore, mEsm),
|
||||
mNumFacing(0)
|
||||
@ -187,7 +187,7 @@ namespace MWWorld
|
||||
std::cout << "Loading ESM " << masterPath.string() << "\n";
|
||||
|
||||
// This parses the ESM file and loads a sample cell
|
||||
mEsm.setEncoding(encoding);
|
||||
mEsm.setEncoder(encoder);
|
||||
mEsm.open (masterPath.string());
|
||||
mStore.load (mEsm);
|
||||
|
||||
|
@ -95,7 +95,7 @@ namespace MWWorld
|
||||
World (OEngine::Render::OgreRenderer& renderer,
|
||||
const Files::Collections& fileCollections,
|
||||
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
||||
const ToUTF8::FromType& encoding, std::map<std::string,std::string> fallbackMap);
|
||||
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
|
@ -344,7 +344,7 @@ std::string ESMReader::getString(int size)
|
||||
getExact(ptr, size);
|
||||
|
||||
// Convert to UTF8 and return
|
||||
return mEncoder.getUtf8(ptr, size);
|
||||
return mEncoder->getUtf8(ptr, size);
|
||||
}
|
||||
|
||||
void ESMReader::fail(const std::string &msg)
|
||||
@ -362,10 +362,9 @@ void ESMReader::fail(const std::string &msg)
|
||||
throw std::runtime_error(ss.str());
|
||||
}
|
||||
|
||||
void ESMReader::setEncoding(const ToUTF8::FromType& encoding)
|
||||
void ESMReader::setEncoder(ToUTF8::Utf8Encoder* encoder)
|
||||
{
|
||||
mEncoding = encoding;
|
||||
mEncoder.setEncoding(encoding);
|
||||
mEncoder = encoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -235,8 +235,8 @@ public:
|
||||
/// Used for error handling
|
||||
void fail(const std::string &msg);
|
||||
|
||||
/// Sets font encoding for ESM strings
|
||||
void setEncoding(const ToUTF8::FromType& encoding);
|
||||
/// Sets font encoder for ESM strings
|
||||
void setEncoder(ToUTF8::Utf8Encoder* encoder);
|
||||
|
||||
private:
|
||||
Ogre::DataStreamPtr mEsm;
|
||||
@ -251,8 +251,7 @@ private:
|
||||
|
||||
SaveData mSaveData;
|
||||
MasterList mMasters;
|
||||
ToUTF8::FromType mEncoding;
|
||||
ToUTF8::Utf8Encoder mEncoder;
|
||||
ToUTF8::Utf8Encoder* mEncoder;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
@ -158,7 +158,7 @@ void ESMWriter::writeHString(const std::string& data)
|
||||
else
|
||||
{
|
||||
// Convert to UTF8 and return
|
||||
std::string ascii = m_encoder.getLegacyEnc(data);
|
||||
std::string ascii = m_encoder->getLegacyEnc(data);
|
||||
|
||||
write(ascii.c_str(), ascii.size());
|
||||
}
|
||||
@ -188,23 +188,9 @@ void ESMWriter::write(const char* data, int size)
|
||||
m_stream->write(data, size);
|
||||
}
|
||||
|
||||
void ESMWriter::setEncoding(const std::string& encoding)
|
||||
void ESMWriter::setEncoder(ToUTF8::Utf8Encoder* encoder)
|
||||
{
|
||||
if (encoding == "win1250")
|
||||
{
|
||||
m_encoding = ToUTF8::WINDOWS_1250;
|
||||
}
|
||||
else if (encoding == "win1251")
|
||||
{
|
||||
m_encoding = ToUTF8::WINDOWS_1251;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default Latin encoding
|
||||
m_encoding = ToUTF8::WINDOWS_1252;
|
||||
}
|
||||
|
||||
m_encoder.setEncoding(m_encoding);
|
||||
m_encoder = encoder;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "esmcommon.hpp"
|
||||
#include "../to_utf8/to_utf8.hpp"
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
namespace ESM {
|
||||
|
||||
@ -24,7 +24,7 @@ public:
|
||||
void setVersion(int ver);
|
||||
int getType();
|
||||
void setType(int type);
|
||||
void setEncoding(const std::string& encoding); // Write strings as UTF-8?
|
||||
void setEncoder(ToUTF8::Utf8Encoder *encoding); // Write strings as UTF-8?
|
||||
void setAuthor(const std::string& author);
|
||||
void setDescription(const std::string& desc);
|
||||
|
||||
@ -94,12 +94,10 @@ private:
|
||||
std::list<RecordData> m_records;
|
||||
std::ostream* m_stream;
|
||||
std::streampos m_headerPos;
|
||||
ToUTF8::FromType m_encoding;
|
||||
ToUTF8::Utf8Encoder m_encoder;
|
||||
ToUTF8::Utf8Encoder* m_encoder;
|
||||
int m_recordCount;
|
||||
|
||||
HEDRstruct m_header;
|
||||
SaveData m_saveData;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -43,16 +43,10 @@
|
||||
|
||||
using namespace ToUTF8;
|
||||
|
||||
Utf8Encoder::Utf8Encoder(void):
|
||||
Utf8Encoder::Utf8Encoder(const FromType sourceEncoding):
|
||||
mOutput(50*1024)
|
||||
{
|
||||
}
|
||||
|
||||
void Utf8Encoder::setEncoding(const FromType sourceEncoding)
|
||||
{
|
||||
mEncoding = sourceEncoding;
|
||||
|
||||
switch (mEncoding)
|
||||
switch (sourceEncoding)
|
||||
{
|
||||
case ToUTF8::WINDOWS_1252:
|
||||
{
|
||||
|
@ -24,9 +24,7 @@ namespace ToUTF8
|
||||
class Utf8Encoder
|
||||
{
|
||||
public:
|
||||
Utf8Encoder(void);
|
||||
|
||||
void setEncoding(const FromType sourceEncoding);
|
||||
Utf8Encoder(FromType sourceEncoding);
|
||||
|
||||
// Convert to UTF8 from the previously given code page.
|
||||
std::string getUtf8(const char *input, int size);
|
||||
@ -48,9 +46,7 @@ namespace ToUTF8
|
||||
size_t getLength2(const char* input, bool &ascii);
|
||||
void copyFromArray2(const char*& chp, char* &out);
|
||||
|
||||
FromType mEncoding;
|
||||
std::vector<char> mOutput;
|
||||
int mSize;
|
||||
char* translationArray;
|
||||
};
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ namespace Translation
|
||||
|
||||
if (!line.empty())
|
||||
{
|
||||
line = mEncoder.getUtf8(line);
|
||||
line = mEncoder->getUtf8(line);
|
||||
|
||||
size_t tab_pos = line.find('\t');
|
||||
if (tab_pos != std::string::npos && tab_pos > 0 && tab_pos < line.size() - 1)
|
||||
@ -101,10 +101,9 @@ namespace Translation
|
||||
return phrase;
|
||||
}
|
||||
|
||||
void Storage::setEncoding (const ToUTF8::FromType& encoding)
|
||||
void Storage::setEncoder(ToUTF8::Utf8Encoder* encoder)
|
||||
{
|
||||
mEncoding = encoding;
|
||||
mEncoder.setEncoding(encoding);
|
||||
mEncoder = encoder;
|
||||
}
|
||||
|
||||
bool Storage::hasTranslation() const
|
||||
|
@ -19,7 +19,7 @@ namespace Translation
|
||||
// Standard form usually means nominative case
|
||||
std::string topicStandardForm(const std::string& phrase) const;
|
||||
|
||||
void setEncoding (const ToUTF8::FromType& encoding);
|
||||
void setEncoder(ToUTF8::Utf8Encoder* encoder);
|
||||
|
||||
bool hasTranslation() const;
|
||||
|
||||
@ -34,8 +34,7 @@ namespace Translation
|
||||
void loadDataFromStream(ContainerType& container, std::istream& stream);
|
||||
|
||||
|
||||
ToUTF8::FromType mEncoding;
|
||||
ToUTF8::Utf8Encoder mEncoder;
|
||||
ToUTF8::Utf8Encoder* mEncoder;
|
||||
ContainerType mCellNamesTranslations, mTopicIDs, mPhraseForms;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user