Tell me how the formatting and rich text are transferred when copying between completely different editors, for example Google Docs in the browser and Word on the PC. What kind of technology? More specifically: there is html in the clipboard, you need to convert it so that when you paste into the editor, there is already text.
1 answer
In the clipboard, data can be stored in multiple views (mime-type) at the same time. The source application (copy) buffers a separate copy of the data for each of the supported views, and the consumer (paste) selects the most convenient format for itself, one of those that it understands. In some applications, there is a choice of views that will be used (see Paste Special in Word). An example on Qt:
QByteArray svg=BOOST_PP_STRINGIZE( <svg height="100" width="100"> <circle cx="50" cy="50" r="45" stroke="black" stroke-width="3" fill="red" /> <text style="font-size:50px" x="20" y="75">Foo</text> </svg> ); QImage image; image.loadFromData( svg ); auto*mime=new QMimeData(); mime->setText("Foo"); // Как текст (будет понимать notepad). mime->setData( "text/html" , "<i>F</i><b>o</b><u>o</u>" ); // Поймет ворд mime->setData( "image/svg+xml" ,svg ); mime->setImageData( image ); // заполняет сразу несколько графических форматов auto*clip=QApplication::clipboard(); clip->clear(); clip->setMimeData(mime); - Already independently found the answer, but there was no time to unsubscribe. You answered quite right, thanks :) The only thing is that in Qt you can immediately setHtml, it is not necessary to set types manually. - UndeadDragon
|