[NEW_FEATURE] Add Chinese BIG5 encoding (in progress).
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@564 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
16930873f2
commit
fe4c746cd4
@ -93,11 +93,21 @@ public:
|
||||
static WcharMbcsConvertor * getInstance() {return _pSelf;};
|
||||
static void destroyInstance() {delete _pSelf;};
|
||||
|
||||
const wchar_t * char2wchar(const char* mbStr, UINT codepage);
|
||||
const wchar_t * char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend);
|
||||
const char * wchar2char(const wchar_t* wcStr, UINT codepage);
|
||||
const char * wchar2char(const wchar_t * wcStr, UINT codepage, long *mstart, long *mend);
|
||||
const wchar_t * char2wchar(const char *mbStr, UINT codepage);
|
||||
const wchar_t * char2wchar(const char *mbcs2Convert, UINT codepage, int *mstart, int *mend);
|
||||
const char * wchar2char(const wchar_t *wcStr, UINT codepage);
|
||||
const char * wchar2char(const wchar_t *wcStr, UINT codepage, long *mstart, long *mend);
|
||||
|
||||
const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode) {
|
||||
const wchar_t * strW = char2wchar(txt2Encode, fromCodepage);
|
||||
return wchar2char(strW, toCodepage);
|
||||
};
|
||||
/*
|
||||
const char * encodeFromUtf8To(const char *txt2Encode) const {
|
||||
const wchar_t * strW = wmc->char2wchar(txt2Encode, SC_CP_UTF8);
|
||||
return wchar2char(strW, toCodepage);
|
||||
};
|
||||
*/
|
||||
protected:
|
||||
WcharMbcsConvertor() : _multiByteStr(NULL), _wideCharStr(NULL), _multiByteAllocLen(0), _wideCharAllocLen(0), initSize(1024) {
|
||||
};
|
||||
|
@ -4372,6 +4372,32 @@ void Notepad_plus::command(int id)
|
||||
break;
|
||||
}
|
||||
|
||||
case IDM_FORMAT_BIG5 :
|
||||
{
|
||||
int encoding = -1;
|
||||
switch (id)
|
||||
{
|
||||
case IDM_FORMAT_BIG5:
|
||||
encoding = CP_BIG5;
|
||||
break;
|
||||
|
||||
default : // IDM_FORMAT_ANSI
|
||||
encoding = CP_ACP;
|
||||
}
|
||||
|
||||
int len = _pEditView->getCurrentDocLen();
|
||||
char *content = new char[len+1];
|
||||
_pEditView->execute(SCI_GETTEXT, len+1, (LPARAM)content);
|
||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
||||
const char *newContent = wmc->encode(encoding, SC_CP_UTF8, content);
|
||||
_pEditView->execute(SCI_SETCODEPAGE, SC_CP_UTF8);
|
||||
_pEditView->execute(SCI_SETTEXT, 0, (LPARAM)newContent);
|
||||
_pEditView->getCurrentBuffer()->setEncoding(encoding);
|
||||
delete [] content;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case IDM_FORMAT_CONV2_ANSI:
|
||||
case IDM_FORMAT_CONV2_AS_UTF_8:
|
||||
case IDM_FORMAT_CONV2_UTF_8:
|
||||
|
@ -396,6 +396,10 @@ BEGIN
|
||||
MENUITEM "Encode in UTF-8", IDM_FORMAT_UTF_8
|
||||
MENUITEM "Encode in UCS-2 Big Endian", IDM_FORMAT_UCS_2BE
|
||||
MENUITEM "Encode in UCS-2 Little Endian", IDM_FORMAT_UCS_2LE
|
||||
POPUP "More..."
|
||||
BEGIN
|
||||
MENUITEM "Chinese Traditional (Big5)", IDM_FORMAT_BIG5
|
||||
END
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Convert to ANSI", IDM_FORMAT_CONV2_ANSI
|
||||
MENUITEM "Convert to UTF-8 without BOM", IDM_FORMAT_CONV2_AS_UTF_8
|
||||
|
@ -64,7 +64,7 @@ static bool isInList(const TCHAR *token, const TCHAR *list) {
|
||||
|
||||
Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName) //type must be either DOC_REGULAR or DOC_UNNAMED
|
||||
: _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0),
|
||||
_canNotify(false), _timeStamp(0), _needReloading(false)
|
||||
_canNotify(false), _timeStamp(0), _needReloading(false), _encoding(-1)
|
||||
{
|
||||
NppParameters *pNppParamInst = NppParameters::getInstance();
|
||||
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
|
||||
@ -603,6 +603,8 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) {
|
||||
Utf8_16_Write UnicodeConvertor;
|
||||
UnicodeConvertor.setEncoding(mode);
|
||||
|
||||
int encoding = buffer->getEncoding();
|
||||
|
||||
FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb"));
|
||||
if (fp)
|
||||
{
|
||||
@ -617,8 +619,17 @@ bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) {
|
||||
grabSize = blockSize;
|
||||
|
||||
_pscratchTilla->getText(data, i, i + grabSize);
|
||||
if (encoding != -1)
|
||||
{
|
||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
||||
const char *newData = wmc->encode(SC_CP_UTF8, encoding, data);
|
||||
UnicodeConvertor.fwrite(newData, strlen(newData));
|
||||
}
|
||||
else
|
||||
{
|
||||
UnicodeConvertor.fwrite(data, grabSize);
|
||||
}
|
||||
}
|
||||
UnicodeConvertor.fclose();
|
||||
|
||||
if (isHidden)
|
||||
|
@ -220,6 +220,15 @@ public :
|
||||
_unicodeMode = mode;
|
||||
doNotify(BufferChangeUnicode | BufferChangeDirty);
|
||||
};
|
||||
|
||||
int getEncoding() const {
|
||||
return _encoding;
|
||||
};
|
||||
|
||||
void setEncoding(int encoding) {
|
||||
_encoding = encoding;
|
||||
};
|
||||
|
||||
DocFileStatus getStatus() const {
|
||||
return _currentStatus;
|
||||
};
|
||||
@ -319,6 +328,7 @@ private :
|
||||
bool _isDirty;
|
||||
formatType _format;
|
||||
UniMode _unicodeMode;
|
||||
int _encoding;
|
||||
bool _isUserReadOnly;
|
||||
bool _needLexer; //initially true
|
||||
//these properties have to be duplicated because of multiple references
|
||||
|
@ -238,6 +238,8 @@
|
||||
#define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12)
|
||||
#define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13)
|
||||
|
||||
#define IDM_FORMAT_BIG5 (IDM_FORMAT + 20)
|
||||
|
||||
#define IDM_LANG (IDM + 6000)
|
||||
#define IDM_LANGSTYLE_CONFIG_DLG (IDM_LANG + 1)
|
||||
#define IDM_LANG_C (IDM_LANG + 2)
|
||||
|
Loading…
Reference in New Issue
Block a user