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:
parent
e0e5663fe4
commit
d1558f3d53
@ -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();
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -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; 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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -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; 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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user