]> git.saurik.com Git - wxWidgets.git/commitdiff
Use extraFontFlag to specify if anti-aliased fonts should be used.
authorRobin Dunn <robin@alldunn.com>
Wed, 11 Feb 2004 22:42:01 +0000 (22:42 +0000)
committerRobin Dunn <robin@alldunn.com>
Wed, 11 Feb 2004 22:42:01 +0000 (22:42 +0000)
Use GetPartialTextExtents.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
contrib/include/wx/stc/stc.h
contrib/src/stc/PlatWX.cpp
contrib/src/stc/ScintillaWX.cpp
contrib/src/stc/ScintillaWX.h
contrib/src/stc/stc.cpp
contrib/src/stc/stc.cpp.in
contrib/src/stc/stc.h.in
include/wx/stc/stc.h
src/stc/PlatWX.cpp
src/stc/ScintillaWX.cpp
src/stc/ScintillaWX.h
src/stc/stc.cpp
src/stc/stc.cpp.in
src/stc/stc.h.in

index a9dcb71234e214e97e8d7e315e0ee0d8062bae75..fa819fb6890abc8f0aace633a5cce93313141dfc 100644 (file)
@@ -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();
+    
 
 //----------------------------------------------------------------------
 
index 39569116f9d6938171f98bd4c51d8145b5fcbb7f..50ffa9ac8fe73f285cb55f7acc808a382da56a7b 100644 (file)
@@ -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);
-    SetFont(font);
+    wxString   str = stc2wx(s, len);
+    wxArrayInt tpos;
 
-#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
+    SetFont(font);
 
+    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;
 }
 
 
index d382203bfda76af086c4ee089697854a9bc588c7..f1ebd651172fc32612edf5cf1010a9ea1d8ad2ec 100644 (file)
@@ -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;
+}
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
index 1316c6661d3b965b176a8ccd46557def063ff9c8..06b6fec31068053993c4c54cb812b32bc54a9525 100644 (file)
@@ -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;
index 2f5ea9eae121410647eb7289f10a9b6b8af080cf..f84f0acfc1e1b5cdd214c7ac19bddf1553eb74f9 100644 (file)
@@ -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
 
index f8fb2d1cc612284a74551aa901a0f9843d9ba98b..d23c6dbdbd5073f765db1e0b29d1fe384ec53b70 100644 (file)
@@ -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
 
index 34b5c6c0671e0c67210ff6a24a6d2c509f4e9f2c..f28b7fd7acb68be670448699ee6f2b4ff2031080 100644 (file)
@@ -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();
+    
 
 //----------------------------------------------------------------------
 
index a9dcb71234e214e97e8d7e315e0ee0d8062bae75..fa819fb6890abc8f0aace633a5cce93313141dfc 100644 (file)
@@ -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();
+    
 
 //----------------------------------------------------------------------
 
index 39569116f9d6938171f98bd4c51d8145b5fcbb7f..50ffa9ac8fe73f285cb55f7acc808a382da56a7b 100644 (file)
@@ -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);
-    SetFont(font);
+    wxString   str = stc2wx(s, len);
+    wxArrayInt tpos;
 
-#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
+    SetFont(font);
 
+    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;
 }
 
 
index d382203bfda76af086c4ee089697854a9bc588c7..f1ebd651172fc32612edf5cf1010a9ea1d8ad2ec 100644 (file)
@@ -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;
+}
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
index 1316c6661d3b965b176a8ccd46557def063ff9c8..06b6fec31068053993c4c54cb812b32bc54a9525 100644 (file)
@@ -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;
index 2f5ea9eae121410647eb7289f10a9b6b8af080cf..f84f0acfc1e1b5cdd214c7ac19bddf1553eb74f9 100644 (file)
@@ -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
 
index f8fb2d1cc612284a74551aa901a0f9843d9ba98b..d23c6dbdbd5073f765db1e0b29d1fe384ec53b70 100644 (file)
@@ -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
 
index 34b5c6c0671e0c67210ff6a24a6d2c509f4e9f2c..f28b7fd7acb68be670448699ee6f2b4ff2031080 100644 (file)
@@ -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();
+    
 
 //----------------------------------------------------------------------