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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user