clip
clip copied to clipboard
question: how to get data like html or svg
Hi, I would like to get the html text and not the raw text. How I can dot that? I also would like to get data from graphic software (like photoshop) which I suppose is svg (but I'm not sure).
I tried to register with the following mime type without success (is_convertible
returns false):
clip::format html_format = clip::register_format("text/html");
clip::format rich_format = clip::register_format("text/richtext");
clip::format svg_format = clip::register_format("image/svg+xml");
Is there a way to get these formats?
Also, is it possible to get the list of the current formats in the clipboard?
Just a little update about html format. I found that the correct format for html should be HTML Format
and not text/html
. But length is 0, so still unusable.
clip::format html_format = clip::register_format("HTML Format");
l.is_convertible(html_format ))//return true when having html in clipboard
size_t len = l.get_data_length(html_format);//return 0
I can get the html using directly windows api:
int cfid = RegisterClipboardFormat("HTML Format");
OpenClipboard(NULL);
HGLOBAL hglb = GetClipboardData(cfid);
if (hglb != NULL)
{
std::cout << "raw " << (char*)hglb << " \n";
}
With the CLIP api, I've made little progress, it seems that the clipboard wasn't opened (or something like that) but now instead of having get_data_length
giving 0, the assertion fails len <= total_size, file ..\clip_win.cpp, line 387
Finally, in Windows I found that it is possible to list the current formats stored in the clipboard (if registered) so I guess it would possible to add this feature in the api (at least for windows):
UINT uFormat;
LPCSTR lpFormatName = NULL;
char szFormatName[80];
uFormat = EnumClipboardFormats(0);
while (uFormat)
{
if (lpFormatName == NULL)
{
if (GetClipboardFormatName(uFormat, szFormatName, sizeof(szFormatName)))
lpFormatName = szFormatName;
else
lpFormatName = "(unknown)";
std::cout << "has format: '" << lpFormatName << "'\n";
}
uFormat = EnumClipboardFormats(uFormat);
}
Hi @loudoweb, actually the API doesn't give the possibility to list all formats, but it's something I needed in the past for debugging purposes and I would like to create a little app to check the clipboard content in detail. So it's something I would like to add.
About the html format. The get_data_length()
function returns 0 because it returns the required data size depending on the format (text or custom). So it's not prepared for a general purposes / any kind of clipboard content, but it could be expanded for that case.
Thanks for your answer @dacap .
So if I can't use get_data_length
to get the length, how could I use get_data
?
At the moment the API is not made for general purpose clipboard content. So it's something to implement.