BOM unicode files support, fixed problem with scroll in frame area

git-svn-id: svn://ultimatepp.org/upp/trunk@859 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-02-13 11:41:52 +00:00
parent 1b8d06832a
commit 67a5b4db82
6 changed files with 124 additions and 6 deletions

105
uppsrc/Core/Bom.cpp Normal file
View file

@ -0,0 +1,105 @@
#include "Core.h"
NAMESPACE_UPP
static void sLoadBom(Stream& in, String *t, WString *wt)
{
if(in.IsOpen()) {
String s;
if(in.GetLeft() > 3) {
word header = in.Get16();
if(header == 0xfffe || header == 0xfeff) {
int n = (int)in.GetLeft() / 2;
WStringBuffer ws(n);
ws.SetLength(in.Get(~ws, 2 * n) / 2);
if(header == 0xfffe)
EndianSwap((word *)~ws, ws.GetCount());
if(wt)
*wt = ws;
else
*t = FromUnicode(ws);
return;
}
int c = in.Get();
if(c < 0)
return;
byte *h = (byte *)&header;
if(h[0] == 0xef && h[1] == 0xbb && c == 0xbf) {
if(wt)
*wt = FromUtf8(LoadStream(in));
else
*t = ToCharset(CHARSET_DEFAULT, LoadStream(in), CHARSET_UTF8);
return;
}
s.Cat(h, 2);
s.Cat(c);
}
s.Cat(LoadStream(in));
if(wt)
*wt = ToUnicode(s, GetLNGCharset(GetSystemLNG()));
else
*t = ToCharset(CHARSET_DEFAULT, s, GetLNGCharset(GetSystemLNG()));
return;
}
return;
}
WString LoadStreamBOMW(Stream& in)
{
WString s = WString::GetVoid();
sLoadBom(in, NULL, &s);
return s;
}
String LoadStreamBOM(Stream& in)
{
String s = String::GetVoid();
sLoadBom(in, &s, NULL);
return s;
}
WString LoadFileBOMW(const char *path)
{
FileIn in(path);
return LoadStreamBOMW(in);
}
String LoadFileBOM(const char *path)
{
FileIn in(path);
return LoadStreamBOM(in);
}
bool SaveStreamBOM(Stream& out, const WString& data) {
if(!out.IsOpen() || out.IsError())
return false;
word w = 0xfeff;
out.Put(&w, 2);
out.Put(~data, 2 * data.GetLength());
out.Close();
return out.IsOK();
}
bool SaveFileBOM(const char *path, const WString& data)
{
FileOut out(path);
return SaveStreamBOM(out, data);
}
bool SaveStreamBOMUtf8(Stream& out, const String& data) {
if(!out.IsOpen() || out.IsError())
return false;
unsigned char bom[] = {0xEF, 0xBB, 0xBF};
out.Put(bom, 3);
out.Put(ToCharset(CHARSET_UTF8, data));
out.Close();
return out.IsOK();
}
bool SaveFileBOMUtf8(const char *path, const String& data)
{
FileOut out(path);
return SaveStreamBOMUtf8(out, data);
}
END_UPP_NAMESPACE

View file

@ -205,3 +205,12 @@ String ToAscii(const String& s, byte charset = CHARSET_DEFAULT);
String ToUpper(const char *s, byte charset = CHARSET_DEFAULT);
String ToLower(const char *s, byte charset = CHARSET_DEFAULT);
String ToAscii(const char *s, byte charset = CHARSET_DEFAULT);
WString LoadStreamBOMW(Stream& in);
String LoadStreamBOM(Stream& in);
WString LoadFileBOMW(const char *path);
String LoadFileBOM(const char *path);
bool SaveStreamBOM(Stream& out, const WString& data);
bool SaveFileBOM(const char *path, const WString& data);
bool SaveStreamBOMUtf8(Stream& out, const String& data);
bool SaveFileBOMUtf8(const char *path, const String& data);

View file

@ -50,6 +50,7 @@ file
StrUtil.cpp optimize_speed,
CharSet.h,
CharSet.cpp optimize_speed,
Bom.cpp,
Kernel32W.dli,
Mpr32W.dli,
Path.h,

View file

@ -119,7 +119,12 @@ void Ctrl::ScrollView(const Rect& _r, int dx, int dy)
dx = sgn(dx) * min(abs(dx), vsz.cx);
dy = sgn(dy) * min(abs(dy), vsz.cy);
Rect r = _r & vsz;
Ctrl *w = GetTopCtrl();
Ctrl *w;
for(w = this; w->parent; w = w->parent)
if(w->InFrame()) {
Refresh();
return;
}
if(!w || !w->top) return;
Rect view = InFrame() ? GetView() : GetClippedView();
Rect sr = (r + view.TopLeft()) & view;
@ -178,11 +183,7 @@ void Ctrl::ScrollView(int dx, int dy) {
void Ctrl::SyncScroll()
{
// 01/12/2007 - mdelfede
// added support for windowed controls
// if(parent || !top)
if(!top)
// 01/12/2007 - END
return;
Vector<Scroll> scroll = top->scroll;
top->scroll.Clear();

View file

@ -1,3 +1,5 @@
description "2D software rendering with PDF/SVG strength";
uses
Core,
CtrlLib;

View file

@ -2,7 +2,7 @@
#define _Painter_icpp_init_stub
#include "Core/init"
#include "CtrlLib/init"
#define BLITZ_INDEX__ F8939D4A0BC2FDAEDB6EE5CF1693AFE34
#define BLITZ_INDEX__ FB97560702FE0F85B954F5A6632CEB2DB
#include "PaintPainting.icpp"
#undef BLITZ_INDEX__
#endif