[wxMSW][wx3.0.3] wxRichTextCtrl: Getting buffer as HTML does not add width and height of embedded image

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

[wxMSW][wx3.0.3] wxRichTextCtrl: Getting buffer as HTML does not add width and height of embedded image

Post by Rudra »

Hi

I am trying to get the wxRichTextCtrl's buffer as HTML string using wxRichTextHTMLHandler. I set handler's flag to wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64. If I resize the embedded image using Picture Properties Dialog that comes on right clicking the image, It does not add any width or height property in corresponding img html tag. I get original size of image when I load the html in browser.

However this is not the case with xml handler, it does add both properties. I also tried getting wxRichTextBuffer from xml string then read the buffer using html handler but I get same result. It doesn't add height and width properties.

// HTML string from wxRichTextCtrl's buffer

Code: Select all

<html><head></head><body>
<font face="Arial" size="3" color="#000000" ><p align="left"><font face="Arial" size="3" color="#000000" ><font  style="color: #0000FF" >this is test</font></font></p>

<p align="left"><font face="Arial" size="3" color="#0000FF" ><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfgBA0LFx9ZpKm9AAAAT0lEQVQoz2P4z4AfMgwOBQwyDJMZpmKBkxkkIAoYGJIY/mJo/csQw8AAU4CpBCyNrABVCVQaVQEDQwpUCVwaXQFECZI0pgKQkhhk7uAIagABfsbXPDlYlAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNi0wNC0xM1QxMToyMzozMiswMjowMA9Vk2wAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTYtMDQtMTNUMTE6MjM6MzErMDI6MDBP4DFNAAAAAElFTkSuQmCC" /></font></p>

</font></body></html>
// XML string from wxRichTextCtrl's buffer

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org">
  <paragraphlayout textcolor="#000000" fontpointsize="11" fontfamily="74" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Arial" alignment="1" parspacingafter="10" parspacingbefore="0" linespacing="10" margin-left="5,4098" margin-right="5,4098" margin-top="5,4098" margin-bottom="5,4098">
    <paragraph>
      <text textcolor="#0000FF" fontpointsize="11" fontfamily="74" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Arial">this is test</text>
    </paragraph>
    <paragraph textcolor="#0000FF" fontpointsize="11" fontfamily="74" fontstyle="90" fontweight="90" fontunderlined="0" fontface="Arial">
    [b]  <image imagetype="15" width="24,4098">[/b]
        <data>89504E470D0A1A0A0000000D4948445200000010000000100804000000B5FA37EA0000000467414D410000B18F0BFC6105000000206348524D00007A26000080840000FA00000080E8000075300000EA6000003A98000017709CBA513C00000002624B474400FF878FCCBF0000000774494D4507E0040D0B171F59A4A9BD0000004F4944415428CF63F8CF801F320C0E050C320C9319A66281931924200A18189218FE6268FDCB10C3C0005380A9042C8DAC005509541A550103430A54095C1A5D0144099234A60290921864EEE0086A00017EC6D73C3958940000002574455874646174653A63726561746500323031362D30342D31335431313A32333A33322B30323A30300F55936C0000002574455874646174653A6D6F6469667900323031362D30342D31335431313A32333A33312B30323A30304FE0314D0000000049454E44AE426082</data>

      </image>
    </paragraph>
  </paragraphlayout>
</richtext>

Let me know if there is way to get height and width of image in HTML.

Please suggest.

Thanks,
R
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.3] wxRichTextCtrl: Getting buffer as HTML does not add width and height of embedded image

Post by doublemax »

You'd have to modify the HTML output handler for that. wxRichTextHTMLHandler::WriteImage in richtexthtml.cpp
Use the source, Luke!
Rudra
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Sep 13, 2013 2:59 pm

Re: [wxMSW][wx3.0.3] wxRichTextCtrl: Getting buffer as HTML does not add width and height of embedded image

Post by Rudra »

Thanks for the reply

I use the output html string to insert in a web page. Even if I don't set the wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 flag, I get same html data. Hence always get image in original size rather than modified size on web page.

Code: Select all

// Get as html data
	wxString text;
	wxStringOutputStream strStream(&text);
	wxRichTextHTMLHandler htmlHandler;
	htmlHandler.SaveFile(&m_bodyText->GetBuffer(), strStream);
I want if image size is modified in RTC then show image in modified size when web browser loads the html.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][wx3.0.3] wxRichTextCtrl: Getting buffer as HTML does not add width and height of embedded image

Post by doublemax »

I want if image size is modified in RTC then show image in modified size when web browser loads the html.
Yes, i understood that. But the current code doesn't do it, so there is no way to make it magically happen.

The size you set through the image property dialog is the printable size in physical dimensions, e.g. for when you wanted to print it. But in HTML this size has no meaning, so the size isn't added (at least i guess that's the reason).
Use the source, Luke!
Post Reply