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:
@@ -61,8 +61,6 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
|||||||
void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes);
|
void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes);
|
||||||
// sets fonts to be used when displaying HTML page.
|
// sets fonts to be used when displaying HTML page.
|
||||||
|
|
||||||
virtual wxList* GetTempData();
|
|
||||||
|
|
||||||
static void AddModule(wxHtmlTagsModule *module);
|
static void AddModule(wxHtmlTagsModule *module);
|
||||||
// Adds tags module. see wxHtmlTagsModule for details.
|
// Adds tags module. see wxHtmlTagsModule for details.
|
||||||
|
|
||||||
@@ -91,6 +89,8 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
|||||||
void SetFontUnderlined(int x) {m_FontUnderlined = x;}
|
void SetFontUnderlined(int x) {m_FontUnderlined = x;}
|
||||||
int GetFontFixed() const {return m_FontFixed;}
|
int GetFontFixed() const {return m_FontFixed;}
|
||||||
void SetFontFixed(int x) {m_FontFixed = x;}
|
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;}
|
int GetAlign() const {return m_Align;}
|
||||||
void SetAlign(int a) {m_Align = a;}
|
void SetAlign(int a) {m_Align = a;}
|
||||||
@@ -135,8 +135,9 @@ class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser
|
|||||||
// average height of normal-sized text
|
// average height of normal-sized text
|
||||||
int m_Align;
|
int m_Align;
|
||||||
// actual alignment
|
// 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
|
// table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off
|
||||||
// state of these flags (from left to right):
|
// state of these flags (from left to right):
|
||||||
// [bold][italic][underlined][fixed_size]
|
// [bold][italic][underlined][fixed_size]
|
||||||
|
@@ -26,16 +26,22 @@
|
|||||||
|
|
||||||
#include "wx/html/forcelnk.h"
|
#include "wx/html/forcelnk.h"
|
||||||
#include "wx/html/m_templ.h"
|
#include "wx/html/m_templ.h"
|
||||||
|
#include "wx/fontenum.h"
|
||||||
|
#include "wx/tokenzr.h"
|
||||||
|
|
||||||
FORCE_LINK_ME(m_fonts)
|
FORCE_LINK_ME(m_fonts)
|
||||||
|
|
||||||
|
|
||||||
TAG_HANDLER_BEGIN(FONT, "FONT")
|
TAG_HANDLER_BEGIN(FONT, "FONT")
|
||||||
|
|
||||||
|
TAG_HANDLER_VARS
|
||||||
|
wxSortedArrayString m_Faces;
|
||||||
|
|
||||||
TAG_HANDLER_PROC(tag)
|
TAG_HANDLER_PROC(tag)
|
||||||
{
|
{
|
||||||
wxColour oldclr = m_WParser -> GetActualColor();
|
wxColour oldclr = m_WParser -> GetActualColor();
|
||||||
int oldsize = m_WParser -> GetFontSize();
|
int oldsize = m_WParser -> GetFontSize();
|
||||||
|
wxString oldface = m_WParser -> GetFontFace();
|
||||||
|
|
||||||
if (tag.HasParam(wxT("COLOR"))) {
|
if (tag.HasParam(wxT("COLOR"))) {
|
||||||
unsigned long tmp = 0;
|
unsigned long tmp = 0;
|
||||||
@@ -58,16 +64,37 @@ TAG_HANDLER_BEGIN(FONT, "FONT")
|
|||||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
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);
|
ParseInner(tag);
|
||||||
|
|
||||||
if (oldclr != m_WParser -> GetActualColor()) {
|
if (oldface != m_WParser -> GetFontFace()) {
|
||||||
m_WParser -> SetActualColor(oldclr);
|
m_WParser -> SetFontFace(oldface);
|
||||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlColourCell(oldclr));
|
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
||||||
}
|
}
|
||||||
if (oldsize != m_WParser -> GetFontSize()) {
|
if (oldsize != m_WParser -> GetFontSize()) {
|
||||||
m_WParser -> SetFontSize(oldsize);
|
m_WParser -> SetFontSize(oldsize);
|
||||||
m_WParser -> GetContainer() -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -51,8 +51,10 @@ wxHtmlWinParser::wxHtmlWinParser(wxWindow *wnd) : wxHtmlParser()
|
|||||||
for (j = 0; j < 2; j++)
|
for (j = 0; j < 2; j++)
|
||||||
for (k = 0; k < 2; k++)
|
for (k = 0; k < 2; k++)
|
||||||
for (l = 0; l < 2; l++)
|
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_FontsTable[i][j][k][l][m] = NULL;
|
||||||
|
m_FontsFacesTable[i][j][k][l][m] = wxEmptyString;
|
||||||
|
}
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
|
static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
|
||||||
#else
|
#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)
|
void wxHtmlWinParser::AddText(const char* txt)
|
||||||
{
|
{
|
||||||
wxHtmlCell *c;
|
wxHtmlCell *c;
|
||||||
@@ -260,17 +240,26 @@ wxFont* wxHtmlWinParser::CreateCurrentFont()
|
|||||||
ff = GetFontFixed(),
|
ff = GetFontFixed(),
|
||||||
fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
|
fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
|
||||||
|
|
||||||
if (m_FontsTable[fb][fi][fu][ff][fs] == NULL) {
|
wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal;
|
||||||
m_FontsTable[fb][fi][fu][ff][fs] =
|
wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]);
|
||||||
new wxFont(
|
wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]);
|
||||||
m_FontsSizes[fs] * m_PixelScale,
|
|
||||||
ff ? wxMODERN : wxSWISS,
|
if (*fontptr != NULL && *faceptr != face) {
|
||||||
fi ? wxITALIC : wxNORMAL,
|
delete *fontptr;
|
||||||
fb ? wxBOLD : wxNORMAL,
|
*fontptr = NULL;
|
||||||
fu ? TRUE : FALSE, ff ? m_FontFaceFixed : m_FontFaceNormal);
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user