Use extraFontFlag to specify if anti-aliased fonts should be used.
Use GetPartialTextExtents. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2482,7 +2482,14 @@ public:
|
|||||||
bool DoDropText(long x, long y, const wxString& data);
|
bool DoDropText(long x, long y, const wxString& data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Specify whether anti-aliased fonts should be used. Will have no effect
|
||||||
|
// on some platforms, but on some (wxMac for example) can greatly improve
|
||||||
|
// performance.
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
|
||||||
|
// Returns the current UseAntiAliasing setting.
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ Font::Font() {
|
|||||||
Font::~Font() {
|
Font::~Font() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic) {
|
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic, bool extraFontFlag) {
|
||||||
wxFontEncoding encoding;
|
wxFontEncoding encoding;
|
||||||
|
|
||||||
Release();
|
Release();
|
||||||
@@ -185,13 +185,15 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b
|
|||||||
if (ea.GetCount())
|
if (ea.GetCount())
|
||||||
encoding = ea[0];
|
encoding = ea[0];
|
||||||
|
|
||||||
id = new wxFont(size,
|
wxFont* font = new wxFont(size,
|
||||||
wxDEFAULT,
|
wxDEFAULT,
|
||||||
italic ? wxITALIC : wxNORMAL,
|
italic ? wxITALIC : wxNORMAL,
|
||||||
bold ? wxBOLD : wxNORMAL,
|
bold ? wxBOLD : wxNORMAL,
|
||||||
false,
|
false,
|
||||||
stc2wx(faceName),
|
stc2wx(faceName),
|
||||||
encoding);
|
encoding);
|
||||||
|
font->SetNoAntiAliasing(!extraFontFlag);
|
||||||
|
id = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -445,42 +447,18 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, int ybase,
|
|||||||
|
|
||||||
void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
|
void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
|
||||||
|
|
||||||
wxString str = stc2wx(s, len);
|
wxString str = stc2wx(s, len);
|
||||||
|
wxArrayInt tpos;
|
||||||
|
|
||||||
SetFont(font);
|
SetFont(font);
|
||||||
|
|
||||||
#ifndef __WXMAC__
|
hdc->GetPartialTextExtents(str, tpos);
|
||||||
// Calculate the position of each character based on the widths of
|
|
||||||
// the previous characters
|
|
||||||
int* tpos = new int[len+1];
|
|
||||||
int totalWidth = 0;
|
|
||||||
size_t i;
|
|
||||||
for (i=0; i<str.Length(); i++) {
|
|
||||||
int w, h;
|
|
||||||
hdc->GetTextExtent(str[i], &w, &h);
|
|
||||||
totalWidth += w;
|
|
||||||
tpos[i] = totalWidth;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Instead of a running total, remeasure from the begining of the
|
|
||||||
// text for each character's position. This is because with AA fonts
|
|
||||||
// on OS X widths can be fractions of pixels wide when more than one
|
|
||||||
// are drawn together, so the sum of all character widths is not necessarily
|
|
||||||
// (and probably not) the same as the whole string width.
|
|
||||||
int* tpos = new int[len+1];
|
|
||||||
size_t i;
|
|
||||||
for (i=0; i<str.Length(); i++) {
|
|
||||||
int w, h;
|
|
||||||
hdc->GetTextExtent(str.Left(i+1), &w, &h);
|
|
||||||
tpos[i] = w;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
// Map the widths for UCS-2 characters back to the UTF-8 input string
|
// Map the widths for UCS-2 characters back to the UTF-8 input string
|
||||||
// NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
|
// NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
|
||||||
// so figure it out and fix it!
|
// so figure it out and fix it!
|
||||||
i = 0;
|
size_t i = 0;
|
||||||
size_t ui = 0;
|
size_t ui = 0;
|
||||||
while ((int)i < len) {
|
while ((int)i < len) {
|
||||||
unsigned char uch = (unsigned char)s[i];
|
unsigned char uch = (unsigned char)s[i];
|
||||||
@@ -498,10 +476,8 @@ void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positio
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// If not unicode then just use the widths we have
|
// If not unicode then just use the widths we have
|
||||||
memcpy(positions, tpos, len * sizeof(*tpos));
|
memcpy(positions, tpos.begin(), len * sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete [] tpos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -160,6 +160,7 @@ void ScintillaWX::Initialise() {
|
|||||||
dropTarget->SetScintilla(this);
|
dropTarget->SetScintilla(this);
|
||||||
stc->SetDropTarget(dropTarget);
|
stc->SetDropTarget(dropTarget);
|
||||||
#endif
|
#endif
|
||||||
|
vs.extraFontFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -907,5 +908,15 @@ void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void ScintillaWX::SetUseAntiAliasing(bool useAA) {
|
||||||
|
vs.extraFontFlag = useAA;
|
||||||
|
InvalidateStyleRedraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScintillaWX::GetUseAntiAliasing() {
|
||||||
|
return vs.extraFontFlag;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@@ -164,6 +164,8 @@ public:
|
|||||||
void DoScrollToLine(int line);
|
void DoScrollToLine(int line);
|
||||||
void DoScrollToColumn(int column);
|
void DoScrollToColumn(int column);
|
||||||
void ClipChildren(wxDC& dc, PRectangle rect);
|
void ClipChildren(wxDC& dc, PRectangle rect);
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool capturedMouse;
|
bool capturedMouse;
|
||||||
|
@@ -2230,6 +2230,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) {
|
||||||
|
m_swx->SetUseAntiAliasing(useAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxStyledTextCtrl::GetUseAntiAliasing() {
|
||||||
|
return m_swx->GetUseAntiAliasing();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
|
||||||
|
@@ -392,6 +392,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) {
|
||||||
|
m_swx->SetUseAntiAliasing(useAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxStyledTextCtrl::GetUseAntiAliasing() {
|
||||||
|
return m_swx->GetUseAntiAliasing();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
|
||||||
|
@@ -210,7 +210,14 @@ public:
|
|||||||
bool DoDropText(long x, long y, const wxString& data);
|
bool DoDropText(long x, long y, const wxString& data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Specify whether anti-aliased fonts should be used. Will have no effect
|
||||||
|
// on some platforms, but on some (wxMac for example) can greatly improve
|
||||||
|
// performance.
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
|
||||||
|
// Returns the current UseAntiAliasing setting.
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -2482,7 +2482,14 @@ public:
|
|||||||
bool DoDropText(long x, long y, const wxString& data);
|
bool DoDropText(long x, long y, const wxString& data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Specify whether anti-aliased fonts should be used. Will have no effect
|
||||||
|
// on some platforms, but on some (wxMac for example) can greatly improve
|
||||||
|
// performance.
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
|
||||||
|
// Returns the current UseAntiAliasing setting.
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -100,7 +100,7 @@ Font::Font() {
|
|||||||
Font::~Font() {
|
Font::~Font() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic) {
|
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic, bool extraFontFlag) {
|
||||||
wxFontEncoding encoding;
|
wxFontEncoding encoding;
|
||||||
|
|
||||||
Release();
|
Release();
|
||||||
@@ -185,13 +185,15 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b
|
|||||||
if (ea.GetCount())
|
if (ea.GetCount())
|
||||||
encoding = ea[0];
|
encoding = ea[0];
|
||||||
|
|
||||||
id = new wxFont(size,
|
wxFont* font = new wxFont(size,
|
||||||
wxDEFAULT,
|
wxDEFAULT,
|
||||||
italic ? wxITALIC : wxNORMAL,
|
italic ? wxITALIC : wxNORMAL,
|
||||||
bold ? wxBOLD : wxNORMAL,
|
bold ? wxBOLD : wxNORMAL,
|
||||||
false,
|
false,
|
||||||
stc2wx(faceName),
|
stc2wx(faceName),
|
||||||
encoding);
|
encoding);
|
||||||
|
font->SetNoAntiAliasing(!extraFontFlag);
|
||||||
|
id = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -445,42 +447,18 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, int ybase,
|
|||||||
|
|
||||||
void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
|
void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
|
||||||
|
|
||||||
wxString str = stc2wx(s, len);
|
wxString str = stc2wx(s, len);
|
||||||
|
wxArrayInt tpos;
|
||||||
|
|
||||||
SetFont(font);
|
SetFont(font);
|
||||||
|
|
||||||
#ifndef __WXMAC__
|
hdc->GetPartialTextExtents(str, tpos);
|
||||||
// Calculate the position of each character based on the widths of
|
|
||||||
// the previous characters
|
|
||||||
int* tpos = new int[len+1];
|
|
||||||
int totalWidth = 0;
|
|
||||||
size_t i;
|
|
||||||
for (i=0; i<str.Length(); i++) {
|
|
||||||
int w, h;
|
|
||||||
hdc->GetTextExtent(str[i], &w, &h);
|
|
||||||
totalWidth += w;
|
|
||||||
tpos[i] = totalWidth;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Instead of a running total, remeasure from the begining of the
|
|
||||||
// text for each character's position. This is because with AA fonts
|
|
||||||
// on OS X widths can be fractions of pixels wide when more than one
|
|
||||||
// are drawn together, so the sum of all character widths is not necessarily
|
|
||||||
// (and probably not) the same as the whole string width.
|
|
||||||
int* tpos = new int[len+1];
|
|
||||||
size_t i;
|
|
||||||
for (i=0; i<str.Length(); i++) {
|
|
||||||
int w, h;
|
|
||||||
hdc->GetTextExtent(str.Left(i+1), &w, &h);
|
|
||||||
tpos[i] = w;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
// Map the widths for UCS-2 characters back to the UTF-8 input string
|
// Map the widths for UCS-2 characters back to the UTF-8 input string
|
||||||
// NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
|
// NOTE: I don't think this is right for when sizeof(wxChar) > 2, ie wxGTK2
|
||||||
// so figure it out and fix it!
|
// so figure it out and fix it!
|
||||||
i = 0;
|
size_t i = 0;
|
||||||
size_t ui = 0;
|
size_t ui = 0;
|
||||||
while ((int)i < len) {
|
while ((int)i < len) {
|
||||||
unsigned char uch = (unsigned char)s[i];
|
unsigned char uch = (unsigned char)s[i];
|
||||||
@@ -498,10 +476,8 @@ void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positio
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// If not unicode then just use the widths we have
|
// If not unicode then just use the widths we have
|
||||||
memcpy(positions, tpos, len * sizeof(*tpos));
|
memcpy(positions, tpos.begin(), len * sizeof(int));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete [] tpos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -160,6 +160,7 @@ void ScintillaWX::Initialise() {
|
|||||||
dropTarget->SetScintilla(this);
|
dropTarget->SetScintilla(this);
|
||||||
stc->SetDropTarget(dropTarget);
|
stc->SetDropTarget(dropTarget);
|
||||||
#endif
|
#endif
|
||||||
|
vs.extraFontFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -907,5 +908,15 @@ void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void ScintillaWX::SetUseAntiAliasing(bool useAA) {
|
||||||
|
vs.extraFontFlag = useAA;
|
||||||
|
InvalidateStyleRedraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScintillaWX::GetUseAntiAliasing() {
|
||||||
|
return vs.extraFontFlag;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@@ -164,6 +164,8 @@ public:
|
|||||||
void DoScrollToLine(int line);
|
void DoScrollToLine(int line);
|
||||||
void DoScrollToColumn(int column);
|
void DoScrollToColumn(int column);
|
||||||
void ClipChildren(wxDC& dc, PRectangle rect);
|
void ClipChildren(wxDC& dc, PRectangle rect);
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool capturedMouse;
|
bool capturedMouse;
|
||||||
|
@@ -2230,6 +2230,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) {
|
||||||
|
m_swx->SetUseAntiAliasing(useAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxStyledTextCtrl::GetUseAntiAliasing() {
|
||||||
|
return m_swx->GetUseAntiAliasing();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
|
||||||
|
@@ -392,6 +392,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) {
|
||||||
|
m_swx->SetUseAntiAliasing(useAA);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxStyledTextCtrl::GetUseAntiAliasing() {
|
||||||
|
return m_swx->GetUseAntiAliasing();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Event handlers
|
// Event handlers
|
||||||
|
|
||||||
|
@@ -210,7 +210,14 @@ public:
|
|||||||
bool DoDropText(long x, long y, const wxString& data);
|
bool DoDropText(long x, long y, const wxString& data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Specify whether anti-aliased fonts should be used. Will have no effect
|
||||||
|
// on some platforms, but on some (wxMac for example) can greatly improve
|
||||||
|
// performance.
|
||||||
|
void SetUseAntiAliasing(bool useAA);
|
||||||
|
|
||||||
|
// Returns the current UseAntiAliasing setting.
|
||||||
|
bool GetUseAntiAliasing();
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user