wxArrayInt& widths,
double scaleX) = 0;
+ // Call either DoGetTextExtent() or wxDC::GetTextExtent() depending on the
+ // value of m_useDCImpl.
+ //
+ // This must be always used instead of calling DoGetTextExtent() directly!
+ void CallGetTextExtent(const wxString& string,
+ wxCoord *width,
+ wxCoord *height,
+ wxCoord *descent = NULL,
+ wxCoord *externalLeading = NULL);
+
// Exactly one of m_dc and m_win is non-NULL for any given object of this
// class.
const wxDC* const m_dc;
const wxWindow* const m_win;
+ // If this is true, simply forward to wxDC::GetTextExtent() from our
+ // CallGetTextExtent() instead of calling our own DoGetTextExtent().
+ //
+ // We need this because our DoGetTextExtent() typically only works with
+ // native DCs, i.e. those having an HDC under Windows or using Pango under
+ // GTK+. However wxTextMeasure object can be constructed for any wxDC, not
+ // necessarily a native one and in this case we must call back into the DC
+ // implementation of text measuring itself.
+ bool m_useDCImpl;
+
// This one can be NULL or not.
const wxFont* const m_font;
m_font(theFont)
{
wxASSERT_MSG( dc, wxS("wxTextMeasure needs a valid wxDC") );
+
+ // By default, use wxDC version, we'll explicitly reset this to false in
+ // the derived classes if the DC is of native variety.
+ m_useDCImpl = true;
}
wxTextMeasureBase::wxTextMeasureBase(const wxWindow *win, const wxFont *theFont)
m_font(theFont)
{
wxASSERT_MSG( win, wxS("wxTextMeasure needs a valid wxWindow") );
+
+ // We don't have any wxDC so we can't forward to it.
+ m_useDCImpl = false;
+}
+
+void wxTextMeasureBase::CallGetTextExtent(const wxString& string,
+ wxCoord *width,
+ wxCoord *height,
+ wxCoord *descent,
+ wxCoord *externalLeading)
+{
+ if ( m_useDCImpl )
+ m_dc->GetTextExtent(string, width, height, descent, externalLeading);
+ else
+ DoGetTextExtent(string, width, height, descent, externalLeading);
}
void wxTextMeasureBase::GetTextExtent(const wxString& string,
MeasuringGuard guard(*this);
- DoGetTextExtent(string, width, height, descent, externalLeading);
+ CallGetTextExtent(string, width, height, descent, externalLeading);
}
void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text,
{
// but we don't know it yet - choose something reasonable
int dummy;
- DoGetTextExtent(wxS("W"), &dummy, &heightLineDefault);
+ CallGetTextExtent(wxS("W"), &dummy, &heightLineDefault);
}
heightTextTotal += heightLineDefault;
}
else
{
- DoGetTextExtent(curLine, &widthLine, &heightLine);
+ CallGetTextExtent(curLine, &widthLine, &heightLine);
if ( widthLine > widthTextMax )
widthTextMax = widthLine;
heightTextTotal += heightLine;
i != strings.end();
++i )
{
- DoGetTextExtent(*i, &w, &h);
+ CallGetTextExtent(*i, &w, &h);
if ( w > widthMax )
widthMax = w;
#include "wx/fontutil.h"
#include "wx/gtk/private.h"
+#include "wx/gtk/dc.h"
#ifndef __WXGTK3__
#include "wx/gtk/dcclient.h"
{
wxASSERT_MSG( m_font, wxT("wxTextMeasure needs a valid wxFont") );
+ m_context = NULL;
+ m_layout = NULL;
+
#ifndef __WXGTK3__
m_wdc = NULL;
+
+ if ( m_dc )
+ {
+ wxClassInfo* const ci = m_dc->GetImpl()->GetClassInfo();
+
+ // Currently the code here only works with wxWindowDCImpl and only in
+ // wxGTK2 as wxGTK3 uses Cairo and not Pango for all its DCs.
+ if ( ci->IsKindOf(wxCLASSINFO(wxWindowDCImpl)))
+ {
+ m_useDCImpl = false;
+ }
+ }
#endif // GTK+ < 3
- m_context = NULL;
- m_layout = NULL;
}
// Get Gtk needed elements, if we have not them yet.
#endif
#include "wx/msw/private.h"
-#include "wx/msw/dc.h"
#ifndef WX_PRECOMP
#include "wx/window.h"
#include "wx/private/textmeasure.h"
+#include "wx/msw/dc.h"
+
// ============================================================================
// wxTextMeasure implementation
// ============================================================================
{
m_hdc = NULL;
m_hfontOld = NULL;
+
+ if ( m_dc )
+ {
+ wxClassInfo* const ci = m_dc->GetImpl()->GetClassInfo();
+
+ if ( ci->IsKindOf(wxCLASSINFO(wxMSWDCImpl)))
+ {
+ m_useDCImpl = false;
+ }
+ }
}
void wxTextMeasure::BeginMeasuring()
#endif
#include "wx/dcclient.h"
+#include "wx/dcps.h"
+#include "wx/metafile.h"
// ----------------------------------------------------------------------------
// test class
CPPUNIT_ASSERT_EQUAL( sz.x, w );
CPPUNIT_ASSERT( dc.GetMultiLineTextExtent("Good\nbye").y >= 2*sz.y );
+
+ // Test the functions with some other DC kinds also.
+#if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT
+ wxPostScriptDC psdc;
+ // wxPostScriptDC doesn't have any font set by default but its
+ // GetTextExtent() requires one to be set. This is probably a bug and we
+ // should set the default font in it implicitly but for now just work
+ // around it.
+ psdc.SetFont(*wxNORMAL_FONT);
+ DoTestGetTextExtent(psdc);
+#endif
+
+#if wxUSE_ENH_METAFILE
+ wxEnhMetaFileDC metadc;
+ DoTestGetTextExtent(metadc);
+#endif
}
void MeasuringTextTestCase::WindowGetTextExtent()