Add readRtf feature with appropriate spec test. Docs updated as well.

This commit is contained in:
Vjekoslav Ratkajec 2016-02-05 09:06:21 +01:00
parent acd5d40ab0
commit 252b12be13
3 changed files with 28 additions and 2 deletions

View file

@ -93,6 +93,13 @@ void WriteText(const base::string16& text, mate::Arguments* args) {
writer.WriteText(text); writer.WriteText(text);
} }
base::string16 ReadRtf(mate::Arguments* args) {
std::string data;
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
clipboard->ReadRTF(GetClipboardType(args), &data);
return base::UTF8ToUTF16(data);
}
void WriteRtf(const std::string& text, mate::Arguments* args) { void WriteRtf(const std::string& text, mate::Arguments* args) {
ui::ScopedClipboardWriter writer(GetClipboardType(args)); ui::ScopedClipboardWriter writer(GetClipboardType(args));
writer.WriteRTF(text); writer.WriteRTF(text);
@ -139,6 +146,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
dict.SetMethod("write", &Write); dict.SetMethod("write", &Write);
dict.SetMethod("readText", &ReadText); dict.SetMethod("readText", &ReadText);
dict.SetMethod("writeText", &WriteText); dict.SetMethod("writeText", &WriteText);
dict.SetMethod("readRtf", &ReadRtf);
dict.SetMethod("writeRtf", &WriteRtf); dict.SetMethod("writeRtf", &WriteRtf);
dict.SetMethod("readHtml", &ReadHtml); dict.SetMethod("readHtml", &ReadHtml);
dict.SetMethod("writeHtml", &WriteHtml); dict.SetMethod("writeHtml", &WriteHtml);

View file

@ -61,9 +61,17 @@ Returns the content in the clipboard as a [NativeImage](native-image.md).
Writes `image` to the clipboard. Writes `image` to the clipboard.
### `clipboard.writeRtf(text)` ### `clipboard.readRtf([type])`
* `type` String (optional)
Returns the content in the clipboard as RTF.
### `clipboard.writeRtf(text[, type])`
* `text` String * `text` String
* `type` String (optional)
Writes the `text` into the clipboard in RTF. Writes the `text` into the clipboard in RTF.

View file

@ -35,20 +35,30 @@ describe('clipboard module', function() {
return assert.equal(clipboard.readHtml(), markup); return assert.equal(clipboard.readHtml(), markup);
}); });
}); });
describe('clipboard.readRtf', function() {
return it('returns rtf text correctly', function() {
var rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}";
clipboard.writeRtf(rtf);
return assert.equal(clipboard.readRtf(), rtf);
});
});
return describe('clipboard.write()', function() { return describe('clipboard.write()', function() {
return it('returns data correctly', function() { return it('returns data correctly', function() {
var i, markup, p, text; var i, markup, p, text, rtf;
text = 'test'; text = 'test';
rtf = '{\\rtf1\\utf8 text}';
p = path.join(fixtures, 'assets', 'logo.png'); p = path.join(fixtures, 'assets', 'logo.png');
i = nativeImage.createFromPath(p); i = nativeImage.createFromPath(p);
markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>'; markup = process.platform === 'darwin' ? '<meta charset=\'utf-8\'><b>Hi</b>' : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>';
clipboard.write({ clipboard.write({
text: "test", text: "test",
html: '<b>Hi</b>', html: '<b>Hi</b>',
rtf: '{\\rtf1\\utf8 text}',
image: p image: p
}); });
assert.equal(clipboard.readText(), text); assert.equal(clipboard.readText(), text);
assert.equal(clipboard.readHtml(), markup); assert.equal(clipboard.readHtml(), markup);
assert.equal(clipboard.readRtf(), rtf);
return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL()); return assert.equal(clipboard.readImage().toDataURL(), i.toDataURL());
}); });
}); });