Don't use "ascent" field of Scintilla Font class any more.

This field will be removed in Scintilla 3.5.5.

See #16776.
This commit is contained in:
Vadim Zeitlin 2015-03-29 03:11:17 +02:00
parent eb7979d25e
commit 8ef14b52c3
3 changed files with 54 additions and 24 deletions

View File

@ -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<wxFontWithAscent*>(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) {

View File

@ -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;
};

View File

@ -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_;
}