added <font face> support
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5104 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
194fa2aca0
commit
f1ad10f373
@ -61,8 +61,6 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
||||
void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes);
|
||||
// sets fonts to be used when displaying HTML page.
|
||||
|
||||
virtual wxList* GetTempData();
|
||||
|
||||
static void AddModule(wxHtmlTagsModule *module);
|
||||
// Adds tags module. see wxHtmlTagsModule for details.
|
||||
|
||||
@ -91,6 +89,8 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
||||
void SetFontUnderlined(int x) {m_FontUnderlined = x;}
|
||||
int GetFontFixed() const {return m_FontFixed;}
|
||||
void SetFontFixed(int x) {m_FontFixed = x;}
|
||||
wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;}
|
||||
void SetFontFace(const wxString& face) {if (GetFontFixed()) m_FontFaceFixed = face; else m_FontFaceNormal = face;}
|
||||
|
||||
int GetAlign() const {return m_Align;}
|
||||
void SetAlign(int a) {m_Align = a;}
|
||||
@ -135,8 +135,9 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
||||
// average height of normal-sized text
|
||||
int m_Align;
|
||||
// actual alignment
|
||||
|
||||
wxFont *m_FontsTable[2][2][2][2][7];
|
||||
|
||||
wxFont* m_FontsTable[2][2][2][2][7];
|
||||
wxString m_FontsFacesTable[2][2][2][2][7];
|
||||
// table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
|
||||
// state of these flags (from left to right):
|
||||
// [bold][italic][underlined][fixed_size]
|
||||
|
@ -26,16 +26,22 @@
|
||||
|
||||
#include "wx/html/forcelnk.h"
|
||||
#include "wx/html/m_templ.h"
|
||||
#include "wx/fontenum.h"
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
FORCE_LINK_ME(m_fonts)
|
||||
|
||||
|
||||
TAG_HANDLER_BEGIN(FONT, "FONT")
|
||||
|
||||
TAG_HANDLER_VARS
|
||||
wxSortedArrayString m_Faces;
|
||||
|
||||
TAG_HANDLER_PROC(tag)
|
||||
{
|
||||
wxColour oldclr = m_WParser -> GetActualColor();
|
||||
int oldsize = m_WParser -> GetFontSize();
|
||||
wxString oldface = m_WParser -> GetFontFace();
|
||||
|
||||
if (tag.HasParam(wxT("COLOR"))) {
|
||||
unsigned long tmp = 0;
|
||||
@ -58,16 +64,37 @@ TAG_HANDLER_BEGIN(FONT, "FONT")
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
}
|
||||
}
|
||||
|
||||
if (tag.HasParam(wxT("FACE"))) {
|
||||
if (m_Faces.GetCount() == 0) {
|
||||
wxFontEnumerator enu;
|
||||
enu.EnumerateFacenames();
|
||||
m_Faces = *enu.GetFacenames();
|
||||
}
|
||||
wxStringTokenizer tk(tag.GetParam(wxT("FACE")), ",");
|
||||
int index;
|
||||
|
||||
while (tk.HasMoreTokens())
|
||||
if ((index = m_Faces.Index(tk.GetNextToken())) != wxNOT_FOUND) {
|
||||
m_WParser -> SetFontFace(m_Faces[index]);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ParseInner(tag);
|
||||
|
||||
if (oldclr != m_WParser -> GetActualColor()) {
|
||||
m_WParser -> SetActualColor(oldclr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
|
||||
}
|
||||
if (oldface != m_WParser -> GetFontFace()) {
|
||||
m_WParser -> SetFontFace(oldface);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
}
|
||||
if (oldsize != m_WParser -> GetFontSize()) {
|
||||
m_WParser -> SetFontSize(oldsize);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||
}
|
||||
if (oldclr != m_WParser -> GetActualColor()) {
|
||||
m_WParser -> SetActualColor(oldclr);
|
||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -51,8 +51,10 @@ wxHtmlWinParser::wxHtmlWinParser(wxWindow *wnd) : wxHtmlParser()
|
||||
for (j = 0; j < 2; j++)
|
||||
for (k = 0; k < 2; k++)
|
||||
for (l = 0; l < 2; l++)
|
||||
for (m = 0; m < 7; m++)
|
||||
for (m = 0; m < 7; m++) {
|
||||
m_FontsTable[i][j][k][l][m] = NULL;
|
||||
m_FontsFacesTable[i][j][k][l][m] = wxEmptyString;
|
||||
}
|
||||
#ifdef __WXMSW__
|
||||
static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
|
||||
#else
|
||||
@ -152,28 +154,6 @@ wxObject* wxHtmlWinParser::GetProduct()
|
||||
|
||||
|
||||
|
||||
wxList* wxHtmlWinParser::GetTempData()
|
||||
{
|
||||
int i, j, k, l, m;
|
||||
wxFont *f;
|
||||
wxList *lst = wxHtmlParser::GetTempData();
|
||||
|
||||
if (lst == NULL) lst = new wxList;
|
||||
lst -> DeleteContents(TRUE);
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
for (j = 0; j < 2; j++)
|
||||
for (k = 0; k < 2; k++)
|
||||
for (l = 0; l < 2; l++)
|
||||
for (m = 0; m < 7; m++) {
|
||||
f = m_FontsTable[i][j][k][l][m];
|
||||
if (f) lst -> Append(f);
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void wxHtmlWinParser::AddText(const char* txt)
|
||||
{
|
||||
wxHtmlCell *c;
|
||||
@ -260,17 +240,26 @@ wxFont* wxHtmlWinParser::CreateCurrentFont()
|
||||
ff = GetFontFixed(),
|
||||
fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
|
||||
|
||||
if (m_FontsTable[fb][fi][fu][ff][fs] == NULL) {
|
||||
m_FontsTable[fb][fi][fu][ff][fs] =
|
||||
new wxFont(
|
||||
m_FontsSizes[fs] * m_PixelScale,
|
||||
ff ? wxMODERN : wxSWISS,
|
||||
fi ? wxITALIC : wxNORMAL,
|
||||
fb ? wxBOLD : wxNORMAL,
|
||||
fu ? TRUE : FALSE, ff ? m_FontFaceFixed : m_FontFaceNormal);
|
||||
wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal;
|
||||
wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]);
|
||||
wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]);
|
||||
|
||||
if (*fontptr != NULL && *faceptr != face) {
|
||||
delete *fontptr;
|
||||
*fontptr = NULL;
|
||||
}
|
||||
m_DC -> SetFont(*(m_FontsTable[fb][fi][fu][ff][fs]));
|
||||
return (m_FontsTable[fb][fi][fu][ff][fs]);
|
||||
|
||||
if (*fontptr == NULL) {
|
||||
*faceptr = face;
|
||||
*fontptr = new wxFont(
|
||||
m_FontsSizes[fs] * m_PixelScale,
|
||||
ff ? wxMODERN : wxSWISS,
|
||||
fi ? wxITALIC : wxNORMAL,
|
||||
fb ? wxBOLD : wxNORMAL,
|
||||
fu ? TRUE : FALSE, face);
|
||||
}
|
||||
m_DC -> SetFont(**fontptr);
|
||||
return (*fontptr);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user