From 8ef14b52c35fd35122c94f92dd1fafab189d6e79 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 29 Mar 2015 03:11:17 +0200 Subject: [PATCH] Don't use "ascent" field of Scintilla Font class any more. This field will be removed in Scintilla 3.5.5. See #16776. --- src/stc/PlatWX.cpp | 67 +++++++++++++++++++++------- src/stc/scintilla/include/Platform.h | 8 +--- src/stc/scintilla/src/Style.cxx | 3 -- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 953047059f..81711665cf 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -75,9 +75,45 @@ wxColour wxColourFromCDandAlpha(ColourDesired& cd, int alpha) { //---------------------------------------------------------------------- +namespace +{ + +// wxFont with ascent cached, a pointer to this type is stored in Font::fid. +class wxFontWithAscent : public wxFont +{ +public: + explicit wxFontWithAscent(const wxFont &font) + : wxFont(font), + m_ascent(0) + { + } + + static wxFontWithAscent* FromFID(FontID fid) + { + return static_cast(fid); + } + + void SetAscent(int ascent) { m_ascent = ascent; } + int GetAscent() const { return m_ascent; } + +private: + int m_ascent; +}; + +void SetAscent(Font& f, int ascent) +{ + wxFontWithAscent::FromFID(f.GetID())->SetAscent(ascent); +} + +int GetAscent(Font& f) +{ + return wxFontWithAscent::FromFID(f.GetID())->GetAscent(); +} + +} // anonymous namespace + Font::Font() { fid = 0; - ascent = 0; } Font::~Font() { @@ -104,20 +140,20 @@ void Font::Create(const FontParameters &fp) { else weight = wxFONTWEIGHT_NORMAL; - wxFont* font = new wxFont(fp.size, - wxFONTFAMILY_DEFAULT, - fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, - weight, - false, - stc2wx(fp.faceName), - encoding); - fid = font; + wxFont font(fp.size, + wxFONTFAMILY_DEFAULT, + fp.italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL, + weight, + false, + stc2wx(fp.faceName), + encoding); + fid = new wxFontWithAscent(font); } void Font::Release() { if (fid) - delete (wxFont*)fid; + delete wxFontWithAscent::FromFID(fid); fid = 0; } @@ -478,7 +514,7 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, XYPOSITION ybase, // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, @@ -491,7 +527,7 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, XYPOSITION ybase, hdc->SetClippingRegion(wxRectFromPRectangle(rc)); // see comments above - hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); hdc->DestroyClippingRegion(); } @@ -506,7 +542,7 @@ void SurfaceImpl::DrawTextTransparent(PRectangle rc, Font &font, XYPOSITION ybas // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - GetAscent(font)); hdc->SetBackgroundMode(wxBRUSHSTYLE_SOLID); } @@ -583,8 +619,9 @@ XYPOSITION SurfaceImpl::Ascent(Font &font) { SetFont(font); int w, h, d, e; hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e); - font.ascent = h - d; - return font.ascent; + const int ascent = h - d; + SetAscent(font, ascent); + return ascent; } XYPOSITION SurfaceImpl::Descent(Font &font) { diff --git a/src/stc/scintilla/include/Platform.h b/src/stc/scintilla/include/Platform.h index d83e7f26c0..f8150b992d 100644 --- a/src/stc/scintilla/include/Platform.h +++ b/src/stc/scintilla/include/Platform.h @@ -255,9 +255,7 @@ struct FontParameters { class Font { protected: FontID fid; -#if PLAT_WX - int ascent; -#endif + // Private so Font objects can not be copied Font(const Font &); Font &operator=(const Font &); @@ -271,9 +269,7 @@ public: FontID GetID() { return fid; } // Alias another font - caller guarantees not to Release void SetID(FontID fid_) { fid = fid_; } -#if PLAT_WX - void SetAscent(int ascent_) { ascent = ascent_; } -#endif + friend class Surface; friend class SurfaceImpl; }; diff --git a/src/stc/scintilla/src/Style.cxx b/src/stc/scintilla/src/Style.cxx index 8b5b42dbf7..4f1143914c 100644 --- a/src/stc/scintilla/src/Style.cxx +++ b/src/stc/scintilla/src/Style.cxx @@ -159,8 +159,5 @@ void Style::ClearTo(const Style &source) { void Style::Copy(Font &font_, const FontMeasurements &fm_) { font.MakeAlias(font_); -#if PLAT_WX - font.SetAscent(fm_.ascent); -#endif (FontMeasurements &)(*this) = fm_; }