From 0919e93e5299eb10571120cfb98a3cf8a487dc69 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 11 Feb 2004 23:49:43 +0000 Subject: [PATCH] Added wxDC:GetPartialTextExtents git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25753 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 10 ++++++- include/wx/mac/dc.h | 1 + src/common/dcbase.cpp | 30 +++++++++++++++++++++ src/mac/carbon/dc.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ src/mac/dc.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index cb7d80bd14..a01bb775ca 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -29,6 +29,7 @@ #include "wx/pen.h" #include "wx/palette.h" #include "wx/list.h" // we use wxList in inline functions +#include "wx/dynarray.h" class WXDLLEXPORT wxDC; class WXDLLEXPORT wxDCBase; @@ -427,6 +428,11 @@ public: wxCoord *heightLine = NULL, wxFont *font = NULL); + // Measure cumulative width of text after each character + bool GetPartialTextExtents(const wxString& text, wxArrayInt& widths) const + { return DoGetPartialTextExtents(text, widths); } + + // size and resolution // ------------------- @@ -734,7 +740,9 @@ protected: wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *theFont = NULL) const = 0; - + + virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; + #if wxUSE_SPLINES virtual void DoDrawSpline(wxList *points); #endif diff --git a/include/wx/mac/dc.h b/include/wx/mac/dc.h index 6411ccaf56..5fc2601e55 100644 --- a/include/wx/mac/dc.h +++ b/include/wx/mac/dc.h @@ -86,6 +86,7 @@ class WXDLLEXPORT wxDC: public wxDCBase wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *theFont = NULL) const; + virtual bool DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const; virtual bool CanDrawBitmap() const; virtual bool CanGetTextExtent() const; diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 75b4c6ac79..7f1b5170ec 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -365,6 +365,36 @@ void wxDCBase::DoDrawSpline( wxList *points ) #endif // wxUSE_SPLINES +// ---------------------------------------------------------------------------- +// Partial Text Extents +// ---------------------------------------------------------------------------- + + +// Each element of the array will be the width of the string up to and +// including the coresoponding character in text. This is the generic +// implementation, the port-specific classes should do this with native APIs +// if available. + +bool wxDCBase::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) const +{ + int totalWidth = 0; + size_t i; + + widths.Empty(); + widths.Add(0, text.Length()); + + // Calculate the position of each character based on the widths of + // the previous characters + for (i=0; iGetNoAntiAliasing() ) + useGetThemeText = false ; + + if ( useGetThemeText ) + { + // If anybody knows how to do this more efficiently yet still handle + // the fractional glyph widths that may be present when using AA + // fonts, please change it. Currently it is measuring from the + // begining of the string for each succeding substring, which is much + // slower than this should be. + for (size_t i=0; iGetNoAntiAliasing() ) + useGetThemeText = false ; + + if ( useGetThemeText ) + { + // If anybody knows how to do this more efficiently yet still handle + // the fractional glyph widths that may be present when using AA + // fonts, please change it. Currently it is measuring from the + // begining of the string for each succeding substring, which is much + // slower than this should be. + for (size_t i=0; i