diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index a9dcb71234..fa819fb689 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -2482,7 +2482,14 @@ public: bool DoDropText(long x, long y, const wxString& data); #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(); + //---------------------------------------------------------------------- diff --git a/contrib/src/stc/PlatWX.cpp b/contrib/src/stc/PlatWX.cpp index 39569116f9..50ffa9ac8f 100644 --- a/contrib/src/stc/PlatWX.cpp +++ b/contrib/src/stc/PlatWX.cpp @@ -100,7 +100,7 @@ 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; Release(); @@ -185,13 +185,15 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b if (ea.GetCount()) encoding = ea[0]; - id = new wxFont(size, + wxFont* font = new wxFont(size, wxDEFAULT, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, stc2wx(faceName), 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) { - wxString str = stc2wx(s, len); + wxString str = stc2wx(s, len); + wxArrayInt tpos; + SetFont(font); -#ifndef __WXMAC__ - // 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; iGetTextExtent(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; iGetTextExtent(str.Left(i+1), &w, &h); - tpos[i] = w; - } -#endif - + hdc->GetPartialTextExtents(str, tpos); #if wxUSE_UNICODE // 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 // so figure it out and fix it! - i = 0; + size_t i = 0; size_t ui = 0; while ((int)i < len) { unsigned char uch = (unsigned char)s[i]; @@ -498,10 +476,8 @@ void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positio #else // If not unicode then just use the widths we have - memcpy(positions, tpos, len * sizeof(*tpos)); + memcpy(positions, tpos.begin(), len * sizeof(int)); #endif - - delete [] tpos; } diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index d382203bfd..f1ebd65117 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -160,6 +160,7 @@ void ScintillaWX::Initialise() { dropTarget->SetScintilla(this); stc->SetDropTarget(dropTarget); #endif + vs.extraFontFlag = true; } @@ -907,5 +908,15 @@ void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) { } #endif + +void ScintillaWX::SetUseAntiAliasing(bool useAA) { + vs.extraFontFlag = useAA; + InvalidateStyleRedraw(); +} + +bool ScintillaWX::GetUseAntiAliasing() { + return vs.extraFontFlag; +} + //---------------------------------------------------------------------- //---------------------------------------------------------------------- diff --git a/contrib/src/stc/ScintillaWX.h b/contrib/src/stc/ScintillaWX.h index 1316c6661d..06b6fec310 100644 --- a/contrib/src/stc/ScintillaWX.h +++ b/contrib/src/stc/ScintillaWX.h @@ -164,6 +164,8 @@ public: void DoScrollToLine(int line); void DoScrollToColumn(int column); void ClipChildren(wxDC& dc, PRectangle rect); + void SetUseAntiAliasing(bool useAA); + bool GetUseAntiAliasing(); private: bool capturedMouse; diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 2f5ea9eae1..f84f0acfc1 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -2230,6 +2230,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { #endif +void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { + m_swx->SetUseAntiAliasing(useAA); +} + +bool wxStyledTextCtrl::GetUseAntiAliasing() { + return m_swx->GetUseAntiAliasing(); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index f8fb2d1cc6..d23c6dbdbd 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -392,6 +392,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { #endif +void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { + m_swx->SetUseAntiAliasing(useAA); +} + +bool wxStyledTextCtrl::GetUseAntiAliasing() { + return m_swx->GetUseAntiAliasing(); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in index 34b5c6c067..f28b7fd7ac 100644 --- a/contrib/src/stc/stc.h.in +++ b/contrib/src/stc/stc.h.in @@ -210,7 +210,14 @@ public: bool DoDropText(long x, long y, const wxString& data); #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(); + //---------------------------------------------------------------------- diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index a9dcb71234..fa819fb689 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -2482,7 +2482,14 @@ public: bool DoDropText(long x, long y, const wxString& data); #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(); + //---------------------------------------------------------------------- diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 39569116f9..50ffa9ac8f 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -100,7 +100,7 @@ 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; Release(); @@ -185,13 +185,15 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b if (ea.GetCount()) encoding = ea[0]; - id = new wxFont(size, + wxFont* font = new wxFont(size, wxDEFAULT, italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, stc2wx(faceName), 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) { - wxString str = stc2wx(s, len); + wxString str = stc2wx(s, len); + wxArrayInt tpos; + SetFont(font); -#ifndef __WXMAC__ - // 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; iGetTextExtent(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; iGetTextExtent(str.Left(i+1), &w, &h); - tpos[i] = w; - } -#endif - + hdc->GetPartialTextExtents(str, tpos); #if wxUSE_UNICODE // 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 // so figure it out and fix it! - i = 0; + size_t i = 0; size_t ui = 0; while ((int)i < len) { unsigned char uch = (unsigned char)s[i]; @@ -498,10 +476,8 @@ void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positio #else // If not unicode then just use the widths we have - memcpy(positions, tpos, len * sizeof(*tpos)); + memcpy(positions, tpos.begin(), len * sizeof(int)); #endif - - delete [] tpos; } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index d382203bfd..f1ebd65117 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -160,6 +160,7 @@ void ScintillaWX::Initialise() { dropTarget->SetScintilla(this); stc->SetDropTarget(dropTarget); #endif + vs.extraFontFlag = true; } @@ -907,5 +908,15 @@ void ScintillaWX::ClipChildren(wxDC& WXUNUSED(dc), PRectangle WXUNUSED(rect)) { } #endif + +void ScintillaWX::SetUseAntiAliasing(bool useAA) { + vs.extraFontFlag = useAA; + InvalidateStyleRedraw(); +} + +bool ScintillaWX::GetUseAntiAliasing() { + return vs.extraFontFlag; +} + //---------------------------------------------------------------------- //---------------------------------------------------------------------- diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index 1316c6661d..06b6fec310 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -164,6 +164,8 @@ public: void DoScrollToLine(int line); void DoScrollToColumn(int column); void ClipChildren(wxDC& dc, PRectangle rect); + void SetUseAntiAliasing(bool useAA); + bool GetUseAntiAliasing(); private: bool capturedMouse; diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 2f5ea9eae1..f84f0acfc1 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -2230,6 +2230,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { #endif +void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { + m_swx->SetUseAntiAliasing(useAA); +} + +bool wxStyledTextCtrl::GetUseAntiAliasing() { + return m_swx->GetUseAntiAliasing(); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index f8fb2d1cc6..d23c6dbdbd 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -392,6 +392,14 @@ bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { #endif +void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { + m_swx->SetUseAntiAliasing(useAA); +} + +bool wxStyledTextCtrl::GetUseAntiAliasing() { + return m_swx->GetUseAntiAliasing(); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 34b5c6c067..f28b7fd7ac 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -210,7 +210,14 @@ public: bool DoDropText(long x, long y, const wxString& data); #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(); + //----------------------------------------------------------------------