From 67a5b4db82232957f8fd47171b434f033cb33b6a Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 13 Feb 2009 11:41:52 +0000 Subject: [PATCH] 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 --- uppsrc/Core/Bom.cpp | 105 +++++++++++++++++++++++++++++++++++ uppsrc/Core/CharSet.h | 9 +++ uppsrc/Core/Core.upp | 1 + uppsrc/CtrlCore/CtrlDraw.cpp | 11 ++-- uppsrc/Painter/Painter.upp | 2 + uppsrc/Painter/init | 2 +- 6 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 uppsrc/Core/Bom.cpp diff --git a/uppsrc/Core/Bom.cpp b/uppsrc/Core/Bom.cpp new file mode 100644 index 000000000..9af61853d --- /dev/null +++ b/uppsrc/Core/Bom.cpp @@ -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 diff --git a/uppsrc/Core/CharSet.h b/uppsrc/Core/CharSet.h index 3411e480d..69509a869 100644 --- a/uppsrc/Core/CharSet.h +++ b/uppsrc/Core/CharSet.h @@ -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); diff --git a/uppsrc/Core/Core.upp b/uppsrc/Core/Core.upp index 2b389c683..0dff4e618 100644 --- a/uppsrc/Core/Core.upp +++ b/uppsrc/Core/Core.upp @@ -50,6 +50,7 @@ file StrUtil.cpp optimize_speed, CharSet.h, CharSet.cpp optimize_speed, + Bom.cpp, Kernel32W.dli, Mpr32W.dli, Path.h, diff --git a/uppsrc/CtrlCore/CtrlDraw.cpp b/uppsrc/CtrlCore/CtrlDraw.cpp index 2ba359da7..50f5338d9 100644 --- a/uppsrc/CtrlCore/CtrlDraw.cpp +++ b/uppsrc/CtrlCore/CtrlDraw.cpp @@ -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 = top->scroll; top->scroll.Clear(); diff --git a/uppsrc/Painter/Painter.upp b/uppsrc/Painter/Painter.upp index 68ca2a39a..1eca83717 100644 --- a/uppsrc/Painter/Painter.upp +++ b/uppsrc/Painter/Painter.upp @@ -1,3 +1,5 @@ +description "2D software rendering with PDF/SVG strength"; + uses Core, CtrlLib; diff --git a/uppsrc/Painter/init b/uppsrc/Painter/init index c15029df4..a2b52881e 100644 --- a/uppsrc/Painter/init +++ b/uppsrc/Painter/init @@ -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