*CtrlCore: Fixed charset encoding issues in EncodeRTF, RichEdit: ClipZoom method

git-svn-id: svn://ultimatepp.org/upp/trunk@3323 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-04-05 14:03:51 +00:00
parent 7386be99a3
commit 82fdf80b01
6 changed files with 24 additions and 5 deletions

View file

@ -222,16 +222,14 @@ void RTFEncoder::Command(const char *cmd, int param)
void RTFEncoder::PutText(const wchar *text)
{
for(; *text; text++) {
if((uint16)*text >= 128) {
stream.Put(NFormat("\\u%d\\'%02x", (int16)*text, FromUnicode(*text, CHARSET_DEFAULT)));
}
for(; *text; text++)
if((uint16)*text >= 128)
stream.Put(NFormat("\\u%d?", (int16)*text));
else {
if(*text == '{' || *text == '}' || *text == '\\')
stream.Put('\\');
stream.Put((byte)*text);
}
}
}
void RTFEncoder::PutBinHex(const byte *b, int count)

View file

@ -76,6 +76,7 @@ bool RichEdit::Accept(PasteClip& d, RichText& clip)
void RichEdit::ClipPaste(RichText& clip)
{
clip.ApplyZoom(clipzoom.Reciprocal());
Filter(clip);
NextUndo();
if(clip.GetPartCount() == 1 && clip.IsTable(0)) {
@ -179,6 +180,11 @@ static String sQTF(const Value& data)
return AsQTF(txt);
}
void RichEdit::ZoomClip(RichText& text) const
{
text.ApplyZoom(clipzoom);
}
void RichEdit::Copy()
{
RichText txt;
@ -190,6 +196,7 @@ void RichEdit::Copy()
BeepExclamation();
return;
}
ZoomClip(txt);
ClearClipboard();
AppendClipboardUnicodeText(txt.GetPlainText());
Value clip = RawPickToValue(txt);
@ -208,6 +215,7 @@ String RichEdit::GetSelectionData(const String& fmt) const
String f = fmt;
if(IsSelection()) {
RichText clip = GetSelection();
ZoomClip(clip);
if(f == "text/QTF")
return AsQTF(clip);
if(InScList(f, RTFS))

View file

@ -705,6 +705,8 @@ RichEdit::RichEdit()
imagefs.Type("Images (*.png *.gif *.jpg *.bmp)", "*.png *.gif *.jpg *.bmp");
singleline = false;
clipzoom = Zoom(1, 1);
}
RichEdit::~RichEdit() {}

View file

@ -278,6 +278,8 @@ private:
bool incundoserial;
Vector<int> ffs;
static int fh[];
@ -421,6 +423,8 @@ private:
};
StyleKey stylekey[20];
Zoom clipzoom;
Rect GetTextRect() const;
Size GetZoomedPage() const;
@ -579,6 +583,7 @@ private:
void ClipPaste(RichText& clip);
bool InSelection(int& c) const;
void RefreshDropCaret();
void ZoomClip(RichText& text) const;
void InsertImage();
@ -750,6 +755,9 @@ public:
RichEdit& SetZoom(int z) { zoom = z; Refresh(); return *this; }
RichEdit& SetContext(void *ctx) { context = ctx; Refresh(); return *this; }
void *GetContext() const { return context; }
RichEdit& ClipZoom(Zoom z) { clipzoom = z; return *this; }
RichEdit& ClipZoom(int m, int d) { clipzoom = Zoom(m, d); return *this; }
Zoom GetClipZoom() const { return clipzoom; }
struct UndoInfo {
int undoserial;

View file

@ -18,6 +18,7 @@ struct Zoom {
int operator&(int x) const { int q = d ? iscale(x, m, d) : 0; return x > 0 ? max(q, 1) : q; }
double AsDouble() const { return (double)m / d; }
Zoom Reciprocal() const { return Zoom(d, m); }
Zoom() { m = d = 1; }
Zoom(const Nuller&) { m = d = 0; }

View file

@ -9,6 +9,8 @@ Draw& SimplePageDraw::Page(int)
void RichText::ApplyZoom(Zoom z)
{
if(z.m == z.d)
return;
RichStyles ostyle(style, 1);
for(int i = 0; i < style.GetCount(); i++)
style[i].format *= z;