From c44ad973b9bcc2a32833284b1010889a56bbc76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 7 Apr 2003 22:19:19 +0000 Subject: [PATCH] partially backported wxHTML SetFonts improvements git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20070 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/htdcrend.tex | 11 ++++++++ docs/latex/wx/htprint.tex | 10 +++++++ docs/latex/wx/htwindow.tex | 53 ++++++++++++++++++++++++++------------ docs/latex/wx/htwinprs.tex | 5 ++-- include/wx/html/htmldefs.h | 30 ++++++++++++++++++--- include/wx/html/htmlwin.h | 7 ++++- include/wx/html/htmprint.h | 6 +++++ include/wx/html/winpars.h | 4 +-- src/html/htmprint.cpp | 18 +++++++++++-- src/html/winpars.cpp | 26 ++++++++++++------- 10 files changed, 133 insertions(+), 37 deletions(-) diff --git a/docs/latex/wx/htdcrend.tex b/docs/latex/wx/htdcrend.tex index 2ecfad889a..605b344ac2 100644 --- a/docs/latex/wx/htdcrend.tex +++ b/docs/latex/wx/htdcrend.tex @@ -44,8 +44,19 @@ in pixels (you should set it to page width minus margins). the screen width is always 800 pixels: it gives best results and ensures (almost) same printed outputs across platforms and differently configured desktops.} +\membersection{wxHtmlDCRenderer::SetFonts}\label{wxhtmldcrenderersetfonts} + +\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes = NULL}} + +Sets fonts. See \helpref{wxHtmlWindow::SetFonts}{wxhtmlwindowsetfonts} for +detailed description. + See also \helpref{SetSize}{wxhtmldcrenderersetsize}. +\wxheading{Note} + +This method was added in wxWindows 2.4.1. + \membersection{wxHtmlDCRenderer::SetSize}\label{wxhtmldcrenderersetsize} \func{void}{SetSize}{\param{int }{width}, \param{int }{height}} diff --git a/docs/latex/wx/htprint.tex b/docs/latex/wx/htprint.tex index b7693ca40e..542f4618be 100644 --- a/docs/latex/wx/htprint.tex +++ b/docs/latex/wx/htprint.tex @@ -27,6 +27,16 @@ This class serves as printout class for HTML documents. Constructor. +\membersection{wxHtmlPrintout::SetFonts}\label{wxhtmlprintoutsetfonts} + +\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes = NULL}} + +Sets fonts. See \helpref{wxHtmlWindow::SetFonts}{wxhtmlwindowsetfonts} for +detailed description. + +\wxheading{Note} + +This method was added in wxWindows 2.4.1. \membersection{wxHtmlPrintout::SetFooter}\label{wxhtmlprintoutsetfooter} diff --git a/docs/latex/wx/htwindow.tex b/docs/latex/wx/htwindow.tex index cbedbca677..9095564858 100644 --- a/docs/latex/wx/htwindow.tex +++ b/docs/latex/wx/htwindow.tex @@ -14,8 +14,9 @@ file or downloaded via HTTP protocol) in a window. The width of the window is constant - given in the constructor - and virtual height is changed dynamically depending on page size. Once the window is created you can set its content by calling -\helpref{SetPage(text)}{wxhtmlwindowsetpage} or -\helpref{LoadPage(filename)}{wxhtmlwindowloadpage}. +\helpref{SetPage(text)}{wxhtmlwindowsetpage}, +\helpref{LoadPage(filename)}{wxhtmlwindowloadpage} or +\helpref{LoadFile}{wxhtmlwindowloadfile}. \wxheading{Note} @@ -146,6 +147,24 @@ Clears history. Moves to next page in history. +\membersection{wxHtmlWindow::LoadFile}\label{wxhtmlwindowloadfile} + +\func{virtual bool}{LoadFile}{\param{const wxFileName\& }{filename}} + +Loads HTML page from file and displays it. + +\wxheading{Return value} + +FALSE if an error occurred, TRUE otherwise + +\wxheading{Note} + +This method was added in wxWindows 2.4.1. + +\wxheading{See also} + +\helpref{LoadPage}{wxhtmlwindowloadpage} + \membersection{wxHtmlWindow::LoadPage}\label{wxhtmlwindowloadpage} \func{virtual bool}{LoadPage}{\param{const wxString\& }{location}} @@ -154,7 +173,7 @@ Unlike SetPage this function first loads HTML page from {\it location} and then displays it. See example: \begin{verbatim} -htmlwin -> SetPage("help/myproject/index.htm"); +htmlwin->LoadPage("help/myproject/index.htm"); \end{verbatim} \wxheading{Parameters} @@ -165,6 +184,10 @@ htmlwin -> SetPage("help/myproject/index.htm"); FALSE if an error occurred, TRUE otherwise +\wxheading{See also} + +\helpref{LoadFile}{wxhtmlwindowloadfile} + \membersection{wxHtmlWindow::OnCellClicked}\label{wxhtmlwindowoncellclicked} \func{virtual void}{OnCellClicked}{\param{wxHtmlCell }{*cell}, \param{wxCoord }{x}, \param{wxCoord }{y}, \param{const wxMouseEvent\& }{event}} @@ -278,7 +301,7 @@ This function sets the space between border of window and HTML contents. See ima \membersection{wxHtmlWindow::SetFonts}\label{wxhtmlwindowsetfonts} -\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes}} +\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes = NULL}} This function sets font sizes and faces. @@ -293,24 +316,20 @@ platform-specific face name. Examples are "helvetica" under Unix or \docparam{sizes}{This is an array of 7 items of {\it int} type. The values represent size of font with HTML size from -2 to +4 -( to )} +( to ). Default sizes are used if {\it sizes} +is NULL.} \wxheading{Defaults} -Under wxGTK: +Default font sizes are defined by constants wxHTML\_FONT\_SIZE\_1, +wxHTML\_FONT\_SIZE\_2, ..., wxHTML\_FONT\_SIZE\_7. Note that they differ among +platforms. Default face names are empty strings. -\begin{verbatim} - SetFonts("", "", {10, 12, 14, 16, 19, 24, 32}); -\end{verbatim} +\wxheading{Note} -Under Windows: - -\begin{verbatim} - SetFonts("", "", {7, 8, 10, 12, 16, 22, 30}); -\end{verbatim} - -Although it seems different the fact is that the fonts are of approximately -same size under both platforms (due to wxMSW / wxGTK inconsistency) +{\tt NULL} is valid value of {\it sizes} since wxWindows 2.4.1. Older +versions did not accept {\tt NULL} value. wxHTML\_FONT\_SIZE\_n constants +were added in wxWindows 2.4.1. \membersection{wxHtmlWindow::SetPage}\label{wxhtmlwindowsetpage} diff --git a/docs/latex/wx/htwinprs.tex b/docs/latex/wx/htwinprs.tex index 9e2424ff7b..f098127d30 100644 --- a/docs/latex/wx/htwinprs.tex +++ b/docs/latex/wx/htwinprs.tex @@ -269,9 +269,10 @@ Sets underlined flag of actualfont. {\it x} is either TRUE of FALSE. \membersection{wxHtmlWinParser::SetFonts}\label{wxhtmlwinparsersetfonts} -\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes}} +\func{void}{SetFonts}{\param{wxString }{normal\_face}, \param{wxString }{fixed\_face}, \param{const int }{*sizes = NULL}} -Sets fonts. This method is identical to \helpref{wxHtmlWindow::SetFonts}{wxhtmlwindowsetfonts} +Sets fonts. See \helpref{wxHtmlWindow::SetFonts}{wxhtmlwindowsetfonts} for +detailed description. \membersection{wxHtmlWinParser::SetInputEncoding}\label{wxhtmlwinparsersetinputencoding} diff --git a/include/wx/html/htmldefs.h b/include/wx/html/htmldefs.h index f0c758d433..75ff26175a 100644 --- a/include/wx/html/htmldefs.h +++ b/include/wx/html/htmldefs.h @@ -99,10 +99,32 @@ /* maximum number of pages printable via html printing */ - - - - + /* default font sizes */ +#ifdef __WXMSW__ + #define wxHTML_FONT_SIZE_1 7 + #define wxHTML_FONT_SIZE_2 8 + #define wxHTML_FONT_SIZE_3 10 + #define wxHTML_FONT_SIZE_4 12 + #define wxHTML_FONT_SIZE_5 16 + #define wxHTML_FONT_SIZE_6 22 + #define wxHTML_FONT_SIZE_7 30 +#elif defined(__WXMAC__) + #define wxHTML_FONT_SIZE_1 9 + #define wxHTML_FONT_SIZE_2 12 + #define wxHTML_FONT_SIZE_3 14 + #define wxHTML_FONT_SIZE_4 18 + #define wxHTML_FONT_SIZE_5 24 + #define wxHTML_FONT_SIZE_6 30 + #define wxHTML_FONT_SIZE_7 36 +#else + #define wxHTML_FONT_SIZE_1 10 + #define wxHTML_FONT_SIZE_2 12 + #define wxHTML_FONT_SIZE_3 14 + #define wxHTML_FONT_SIZE_4 16 + #define wxHTML_FONT_SIZE_5 19 + #define wxHTML_FONT_SIZE_6 24 + #define wxHTML_FONT_SIZE_7 32 +#endif #if WXWIN_COMPATIBILITY_2 diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h index 14ed7b410b..7314b23ea7 100644 --- a/include/wx/html/htmlwin.h +++ b/include/wx/html/htmlwin.h @@ -26,6 +26,7 @@ #include "wx/html/htmlcell.h" #include "wx/filesys.h" #include "wx/html/htmlfilt.h" +#include "wx/filename.h" class wxHtmlProcessor; class wxHtmlWinModule; @@ -100,6 +101,9 @@ public: // Return value : same as SetPage virtual bool LoadPage(const wxString& location); + // Loads HTML page from file + bool LoadFile(const wxFileName& filename); + // Returns full location of opened page wxString GetOpenedPage() const {return m_OpenedPage;} // Returns anchor within opened page @@ -117,7 +121,8 @@ public: void SetRelatedStatusBar(int bar); // Sets fonts to be used when displaying HTML page. - void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes); + void SetFonts(wxString normal_face, wxString fixed_face, + const int *sizes = NULL); // Sets space between text and window borders. void SetBorders(int b) {m_Borders = b;} diff --git a/include/wx/html/htmprint.h b/include/wx/html/htmprint.h index 713d1ef895..843fe299c9 100644 --- a/include/wx/html/htmprint.h +++ b/include/wx/html/htmprint.h @@ -53,6 +53,9 @@ public: // (see wxFileSystem for detailed explanation) void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = TRUE); + // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). + void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); + // [x,y] is position of upper-left corner of printing rectangle (see SetSize) // from is y-coordinate of the very first visible cell // Returned value is y coordinate of first cell than didn't fit onto page. @@ -123,6 +126,9 @@ public: // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants. // You can set different header/footer for odd and even pages + // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). + void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); + void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2, float spaces = 5); // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 23905552f7..83500c5ad9 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -68,8 +68,8 @@ public: // returns associated wxWindow wxHtmlWindow *GetWindow() {return m_Window;} - // sets fonts to be used when displaying HTML page. - void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes); + // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). + void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); // Adds tags module. see wxHtmlTagsModule for details. static void AddModule(wxHtmlTagsModule *module); diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index a2dfa82097..54d66d3a8b 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -93,6 +93,13 @@ void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepat } +void wxHtmlDCRenderer::SetFonts(wxString normal_face, wxString fixed_face, + const int *sizes) +{ + m_Parser->SetFonts(normal_face, fixed_face, sizes); + if (m_DC == NULL && m_Cells != NULL) m_Cells->Layout(m_Width); +} + int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render) { @@ -408,11 +415,18 @@ void wxHtmlPrintout::SetMargins(float top, float bottom, float left, float right +void wxHtmlPrintout::SetFonts(wxString normal_face, wxString fixed_face, + const int *sizes) +{ + m_Renderer->SetFonts(normal_face, fixed_face, sizes); + m_RendererHdr->SetFonts(normal_face, fixed_face, sizes); +} -//-------------------------------------------------------------------------------- + +//---------------------------------------------------------------------------- // wxHtmlEasyPrinting -//-------------------------------------------------------------------------------- +//---------------------------------------------------------------------------- wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxFrame *parent_frame) diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index 1d4af2c3fc..4a5de2de4d 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -69,14 +69,8 @@ wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindow *wnd) : wxHtmlParser() m_FontsEncTable[i][j][k][l][m] = wxFONTENCODING_DEFAULT; #endif } -#ifdef __WXMSW__ - static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30}; -#elif defined(__WXMAC__) - static int default_sizes[7] = {9, 12, 14, 18, 24, 30, 36}; -#else - static int default_sizes[7] = {10, 12, 14, 16, 19, 24, 32}; -#endif - SetFonts(wxT(""), wxT(""), default_sizes); + + SetFonts(wxEmptyString, wxEmptyString, NULL); } // fill in wxHtmlParser's tables: @@ -118,8 +112,22 @@ void wxHtmlWinParser::RemoveModule(wxHtmlTagsModule *module) m_Modules.DeleteObject(module); } -void wxHtmlWinParser::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes) +void wxHtmlWinParser::SetFonts(wxString normal_face, wxString fixed_face, + const int *sizes) { + static int default_sizes[7] = + { + wxHTML_FONT_SIZE_1, + wxHTML_FONT_SIZE_2, + wxHTML_FONT_SIZE_3, + wxHTML_FONT_SIZE_4, + wxHTML_FONT_SIZE_5, + wxHTML_FONT_SIZE_6, + wxHTML_FONT_SIZE_7 + }; + + if (sizes == NULL) sizes = default_sizes; + int i, j, k, l, m; for (i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];