richtexthtml.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: richtext/richtexthtml.h
  3. // Purpose: interface of wxRichTextHTMLHandler
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxRichTextHTMLHandler
  9. Handles HTML output (only) for wxRichTextCtrl content.
  10. The most flexible way to use this class is to create a temporary object and call
  11. its functions directly, rather than use wxRichTextBuffer::SaveFile or
  12. wxRichTextCtrl::SaveFile.
  13. Image handling requires a little extra work from the application, to choose an
  14. appropriate image format for the target HTML viewer and to clean up the temporary
  15. images later.
  16. If you are planning to load the HTML into a standard web browser, you can
  17. specify the handler flag wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64 (the default)
  18. and no extra work is required: the images will be written with the HTML.
  19. However, if you want wxHTML compatibility, you will need to use
  20. @c wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY or
  21. @c wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES.
  22. In this case, you must either call wxRichTextHTMLHandler::DeleteTemporaryImages
  23. before the next load operation, or you must store the image locations and
  24. delete them yourself when appropriate.
  25. You can call wxRichTextHTMLHandler::GetTemporaryImageLocations to
  26. get the array of temporary image names.
  27. @section richtexthtmlhandler_flags Handler flags
  28. The following flags can be used with this handler, via the handler's SetFlags()
  29. function or the buffer or control's SetHandlerFlags() function:
  30. - wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY
  31. Images are saved to the memory filesystem: suitable for showing wxHTML windows.
  32. - wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_FILES
  33. Images are saved to temporary files: suitable for showing in wxHTML windows.
  34. - wxRICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64
  35. Images are written with the HTML files in Base 64 format: suitable for showing
  36. in web browsers.
  37. - wxRICHTEXT_HANDLER_NO_HEADER_FOOTER
  38. Don't include header and footer tags (HTML, HEAD, BODY), so that the HTML
  39. can be used as part of a larger document.
  40. - wxRICHTEXT_HANDLER_USE_CSS
  41. Use CSS where possible, otherwise use workarounds that will show in wxHtmlWindow.
  42. @library{wxrichtext}
  43. @category{richtext}
  44. */
  45. class wxRichTextHTMLHandler : public wxRichTextFileHandler
  46. {
  47. public:
  48. /**
  49. Constructor.
  50. */
  51. wxRichTextHTMLHandler(const wxString& name = "HTML",
  52. const wxString& ext = "html",
  53. int type = wxRICHTEXT_TYPE_HTML);
  54. /**
  55. Clears the image locations generated by the last operation.
  56. */
  57. void ClearTemporaryImageLocations();
  58. /**
  59. Deletes the in-memory or temporary files generated by the last operation.
  60. */
  61. bool DeleteTemporaryImages();
  62. /**
  63. Delete the in-memory or temporary files generated by the last operation.
  64. This is a static function that can be used to delete the saved locations
  65. from an earlier operation, for example after the user has viewed the HTML file.
  66. */
  67. static bool DeleteTemporaryImages(int flags,
  68. const wxArrayString& imageLocations);
  69. /**
  70. Returns the mapping for converting point sizes to HTML font sizes.
  71. */
  72. wxArrayInt GetFontSizeMapping() const;
  73. /**
  74. Returns the directory used to store temporary image files.
  75. */
  76. const wxString& GetTempDir() const;
  77. /**
  78. Returns the image locations for the last operation.
  79. */
  80. const wxArrayString& GetTemporaryImageLocations() const;
  81. /**
  82. Reset the file counter, in case, for example, the same names are required each
  83. time.
  84. */
  85. static void SetFileCounter(int counter);
  86. /**
  87. Sets the mapping for converting point sizes to HTML font sizes.
  88. There should be 7 elements, one for each HTML font size, each element
  89. specifying the maximum point size for that HTML font size.
  90. For example:
  91. @code
  92. wxArrayInt fontSizeMapping;
  93. fontSizeMapping.Add(7);
  94. fontSizeMapping.Add(9);
  95. fontSizeMapping.Add(11);
  96. fontSizeMapping.Add(12);
  97. fontSizeMapping.Add(14);
  98. fontSizeMapping.Add(22);
  99. fontSizeMapping.Add(100);
  100. htmlHandler.SetFontSizeMapping(fontSizeMapping);
  101. @endcode
  102. */
  103. void SetFontSizeMapping(const wxArrayInt& fontSizeMapping);
  104. /**
  105. Sets the directory for storing temporary files.
  106. If empty, the system temporary directory will be used.
  107. */
  108. void SetTempDir(const wxString& tempDir);
  109. /**
  110. Sets the list of image locations generated by the last operation.
  111. */
  112. void SetTemporaryImageLocations(const wxArrayString& locations);
  113. protected:
  114. /**
  115. Saves the buffer content to the HTML stream.
  116. */
  117. virtual bool DoSaveFile(wxRichTextBuffer* buffer, wxOutputStream& stream);
  118. };