From 7acd36259b464d7139128f2e53acf04b3110eb71 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 5 Aug 2004 23:59:44 +0000 Subject: [PATCH] Added NormalizeFontSizes which will set the html font sizes based on the size of a system font. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28649 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/html/htmlwin.h | 3 +++ include/wx/html/htmprint.h | 9 +++++++ include/wx/html/winpars.h | 3 +++ src/html/htmlwin.cpp | 18 ++++++++++++- src/html/htmprint.cpp | 54 ++++++++++++++++++++++++++++++++++++++ src/html/winpars.cpp | 17 ++++++++++++ wxPython/src/html.i | 17 ++++++++++++ 7 files changed, 120 insertions(+), 1 deletion(-) diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h index adefe1fce2..62f0446573 100644 --- a/include/wx/html/htmlwin.h +++ b/include/wx/html/htmlwin.h @@ -130,6 +130,9 @@ public: void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL); + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + // 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 c80acd6655..e2a27bc59b 100644 --- a/include/wx/html/htmprint.h +++ b/include/wx/html/htmprint.h @@ -59,6 +59,9 @@ public: // 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); + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + // [x,y] is position of upper-left corner of printing rectangle (see SetSize) // from is y-coordinate of the very first visible cell // to is y-coordinate of the next following page break, if any @@ -142,6 +145,9 @@ public: // 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); + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + 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 @@ -237,6 +243,9 @@ public: void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = 0); // Sets fonts to be used when displaying HTML page. (if size null then default sizes used) + void NormalizeFontSizes(int size=-1); + // Sets font sizes to be relative to the given size or the system default size + wxPrintData *GetPrintData(); wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} // return page setting data objects. diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 24ed74b270..67217628f8 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -72,6 +72,9 @@ public: // 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); + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + // Adds tags module. see wxHtmlTagsModule for details. static void AddModule(wxHtmlTagsModule *module); diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index eb97f6d3d9..0068fec835 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -36,12 +36,12 @@ #include "wx/dataobj.h" #include "wx/timer.h" #include "wx/dcmemory.h" +#include "wx/settings.h" #include "wx/arrimpl.cpp" #include "wx/listimpl.cpp" - #if wxUSE_CLIPBOARD // ---------------------------------------------------------------------------- // wxHtmlWinAutoScrollTimer: the timer used to generate a stream of scroll @@ -249,6 +249,22 @@ void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int if (!op.IsEmpty()) LoadPage(op); } +void wxHtmlWindow::NormalizeFontSizes(int size) +{ + int f_sizes[7]; + if (size == -1) + size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); + + f_sizes[0] = int(size * 0.6); + f_sizes[1] = int(size * 0.8); + f_sizes[2] = size; + f_sizes[3] = int(size * 1.2); + f_sizes[4] = int(size * 1.4); + f_sizes[5] = int(size * 1.6); + f_sizes[6] = int(size * 1.8); + + SetFonts(wxEmptyString, wxEmptyString, f_sizes); +} bool wxHtmlWindow::SetPage(const wxString& source) diff --git a/src/html/htmprint.cpp b/src/html/htmprint.cpp index 720bde4849..800ca10d66 100644 --- a/src/html/htmprint.cpp +++ b/src/html/htmprint.cpp @@ -37,6 +37,7 @@ #include "wx/wxhtml.h" #include "wx/wfstream.h" #include "wx/module.h" +#include "wx/settings.h" //-------------------------------------------------------------------------------- @@ -101,6 +102,24 @@ void wxHtmlDCRenderer::SetFonts(wxString normal_face, wxString fixed_face, } +void wxHtmlDCRenderer::NormalizeFontSizes(int size) +{ + int f_sizes[7]; + if (size == -1) + size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); + + f_sizes[0] = int(size * 0.6); + f_sizes[1] = int(size * 0.8); + f_sizes[2] = size; + f_sizes[3] = int(size * 1.2); + f_sizes[4] = int(size * 1.4); + f_sizes[5] = int(size * 1.6); + f_sizes[6] = int(size * 1.8); + + SetFonts(wxEmptyString, wxEmptyString, f_sizes); +} + + int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render, int to, int *known_pagebreaks, int number_of_pages) { int pbreak, hght; @@ -447,6 +466,24 @@ void wxHtmlPrintout::SetFonts(wxString normal_face, wxString fixed_face, } +void wxHtmlPrintout::NormalizeFontSizes(int size) +{ + int f_sizes[7]; + if (size == -1) + size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); + + f_sizes[0] = int(size * 0.6); + f_sizes[1] = int(size * 0.8); + f_sizes[2] = size; + f_sizes[3] = int(size * 1.2); + f_sizes[4] = int(size * 1.4); + f_sizes[5] = int(size * 1.6); + f_sizes[6] = int(size * 1.8); + + SetFonts(wxEmptyString, wxEmptyString, f_sizes); +} + + //---------------------------------------------------------------------------- // wxHtmlEasyPrinting @@ -634,6 +671,23 @@ void wxHtmlEasyPrinting::SetFonts(wxString normal_face, wxString fixed_face, m_FontsSizes = NULL; } +void wxHtmlEasyPrinting::NormalizeFontSizes(int size) +{ + int f_sizes[7]; + if (size == -1) + size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); + + f_sizes[0] = int(size * 0.6); + f_sizes[1] = int(size * 0.8); + f_sizes[2] = size; + f_sizes[3] = int(size * 1.2); + f_sizes[4] = int(size * 1.4); + f_sizes[5] = int(size * 1.6); + f_sizes[6] = int(size * 1.8); + + SetFonts(wxEmptyString, wxEmptyString, f_sizes); +} + wxHtmlPrintout *wxHtmlEasyPrinting::CreatePrintout() { diff --git a/src/html/winpars.cpp b/src/html/winpars.cpp index e994399b8b..77769c411f 100644 --- a/src/html/winpars.cpp +++ b/src/html/winpars.cpp @@ -154,6 +154,23 @@ void wxHtmlWinParser::SetFonts(wxString normal_face, wxString fixed_face, } } +void wxHtmlWinParser::NormalizeFontSizes(int size) +{ + int f_sizes[7]; + if (size == -1) + size = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize(); + + f_sizes[0] = int(size * 0.6); + f_sizes[1] = int(size * 0.8); + f_sizes[2] = size; + f_sizes[3] = int(size * 1.2); + f_sizes[4] = int(size * 1.4); + f_sizes[5] = int(size * 1.6); + f_sizes[6] = int(size * 1.8); + + SetFonts(wxEmptyString, wxEmptyString, f_sizes); +} + void wxHtmlWinParser::InitParser(const wxString& source) { wxHtmlParser::InitParser(source); diff --git a/wxPython/src/html.i b/wxPython/src/html.i index 403878e34d..42fdb2f0bd 100644 --- a/wxPython/src/html.i +++ b/wxPython/src/html.i @@ -199,6 +199,9 @@ public: } } + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + wxHtmlContainerCell* GetContainer(); wxHtmlContainerCell* OpenContainer(); wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); @@ -865,6 +868,9 @@ public: } } + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + DocDeclStr( void, SetTitle(const wxString& title), "", ""); @@ -952,6 +958,10 @@ public: delete [] temp; } } + + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + int Render(int x, int y, int from = 0, int dont_render = False, int to = INT_MAX, //int *known_pagebreaks = NULL, int number_of_pages = 0 int* choices=NULL, int LCOUNT = 0 @@ -993,6 +1003,10 @@ public: delete [] temp; } } + + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2, float spaces = 5); @@ -1033,6 +1047,9 @@ public: } } + // Sets font sizes to be relative to the given size or the system default size + void NormalizeFontSizes(int size=-1); + wxPrintData *GetPrintData() {return m_PrintData;} wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;} -- 2.45.2