diff --git a/newdraw/Draw/Draw.h b/newdraw/Draw/Draw.h index 5f397e9fb..6b90ddb5e 100644 --- a/newdraw/Draw/Draw.h +++ b/newdraw/Draw/Draw.h @@ -223,9 +223,9 @@ public: int GetAscent() const { return Fi().ascent; } int GetDescent() const { return Fi().descent; } + int GetCy() const { return Fi().height; } int GetExternal() const { return Fi().external; } int GetInternal() const { return Fi().internal; } - int GetGlyphsHeight() const { return Fi().height; } int GetLineHeight() const { return Fi().lineheight; } int GetOverhang() const { return Fi().overhang; } int GetAveWidth() const { return Fi().avewidth; } @@ -270,7 +270,7 @@ public: int GetDescent() const { return font.GetDescent(); } int GetExternal() const { return font.GetExternal(); } int GetInternal() const { return font.GetInternal(); } - int GetHeight() const { return font.GetGlyphsHeight(); } + int GetHeight() const { return font.GetCy(); } int GetLineHeight() const { return font.GetLineHeight(); } int GetOverhang() const { return font.GetOverhang(); } int GetAveWidth() const { return font.GetAveWidth(); } diff --git a/newdraw/Draw/DrawText.cpp b/newdraw/Draw/DrawText.cpp index f55fd9217..8894cee93 100644 --- a/newdraw/Draw/DrawText.cpp +++ b/newdraw/Draw/DrawText.cpp @@ -59,15 +59,14 @@ void Draw::DrawText(int x, int y, int angle, const wchar *text, Font font, } else if(gi.IsReplaced()) { - FontInfo fi = font.Info(); Font fnt = font; fnt.Face(gi.lspc); - FontInfo fi2 = fnt.Info(); + fnt.Height(gi.rspc); if(angle) - DrawTextOp(int(x + cosa * d), int(y - sina * (fi.GetAscent() - fi2.GetAscent() + d)), + DrawTextOp(int(x + cosa * d), int(y - sina * (font.GetAscent() - fnt.GetAscent() + d)), angle, &chr, fnt, ink, 1, NULL); else - DrawTextOp(x + d, y + fi.GetAscent() - fi2.GetAscent(), 0, &chr, fnt, ink, 1, NULL); + DrawTextOp(x + d, y + font.GetAscent() - fnt.GetAscent(), 0, &chr, fnt, ink, 1, NULL); GlyphMetrics(gi, font, chr); } else diff --git a/newdraw/Draw/DrawTextWin32.cpp b/newdraw/Draw/DrawTextWin32.cpp index 80cdf12f8..390f6ec2f 100644 --- a/newdraw/Draw/DrawTextWin32.cpp +++ b/newdraw/Draw/DrawTextWin32.cpp @@ -8,17 +8,6 @@ NAMESPACE_UPP HFONT GetWin32Font(Font fnt, int angle); -void SystemDraw::SetFont(Font font, int angle) { - DrawLock __; - LLOG("Set font: " << font << " face: " << font.GetFaceName()); - if(lastFont == font && lastAngle == angle) - return; - lastFont = font; - lastAngle = angle; - HFONT h = (HFONT) SelectObject(handle, GetWin32Font(font, angle)); - if(!orgFont) orgFont = h; -} - void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font font, Color ink, int n, const int *dx) { Std(font); @@ -39,7 +28,7 @@ void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font fon LLOG("Setting text color: " << ink); ::SetTextColor(handle, lastTextColor = cr); } - SetFont(font, angle); + HGDIOBJ orgfont = ::SelectObject(handle, GetWin32Font(font, angle)); int ascent = font.Info().GetAscent(); if(angle) { double sina, cosa; @@ -50,6 +39,7 @@ void SystemDraw::DrawTextOp(int x, int y, int angle, const wchar *text, Font fon else ::ExtTextOutW(handle, x, y + ascent, 0, NULL, (const WCHAR *)text, n, dx); + ::SelectObject(handle, orgfont); } #endif diff --git a/newdraw/Draw/DrawWin32.cpp b/newdraw/Draw/DrawWin32.cpp index 06ecb1c4f..9b9b695e4 100644 --- a/newdraw/Draw/DrawWin32.cpp +++ b/newdraw/Draw/DrawWin32.cpp @@ -250,8 +250,6 @@ void SystemDraw::Cinit() { lastPen = Null; actBrush = orgBrush = NULL; actPen = orgPen = NULL; - orgFont = NULL; - lastAngle = INT_MIN; } void SystemDraw::Init() { @@ -293,7 +291,6 @@ void SystemDraw::Unselect0() { DrawLock __; if(orgPen) SelectObject(handle, orgPen); if(orgBrush) SelectObject(handle, orgBrush); - if(orgFont) SelectObject(handle, orgFont); if(actPen) DeleteObject(actPen); if(actBrush) DeleteObject(actBrush); Cinit(); diff --git a/newdraw/Draw/DrawWin32.h b/newdraw/Draw/DrawWin32.h index acdec65af..e225c6ed2 100644 --- a/newdraw/Draw/DrawWin32.h +++ b/newdraw/Draw/DrawWin32.h @@ -53,9 +53,6 @@ private: friend void StaticExitDraw_(); - Font lastFont; - int lastAngle; - Point actual_offset_bak; struct Cloff : Moveable { @@ -71,7 +68,6 @@ private: Color lastColor; HBRUSH orgBrush; HBRUSH actBrush; - HFONT orgFont; HPEN orgPen; HPEN actPen; int lastPen; @@ -120,7 +116,6 @@ public: #endif void SetColor(Color color); - void SetFont(Font font, int angle = 0); void SetDrawPen(int width, Color color); Size GetSizeCaps(int i, int j) const; diff --git a/newdraw/Draw/Font.cpp b/newdraw/Draw/Font.cpp index 9bf361961..f8da55569 100644 --- a/newdraw/Draw/Font.cpp +++ b/newdraw/Draw/Font.cpp @@ -90,7 +90,7 @@ int Font::FindFaceNameIndex(const String& name) { void Font::SyncStdFont() { DrawLock __; - StdFontSize = Size(AStdFont.GetAveWidth(), AStdFont().Bold().GetGlyphsHeight()); + StdFontSize = Size(AStdFont.GetAveWidth(), AStdFont().Bold().GetCy()); } void Font::SetStdFont(Font font) @@ -229,8 +229,10 @@ CharEntry GetGlyphEntry(Font font, int chr, unsigned hash) e.info.rspc = cg.basic_char; } else - if(Replace(font, chr, rfnt)) + if(Replace(font, chr, rfnt)) { e.info.lspc = rfnt.GetFace(); + e.info.rspc = rfnt.GetHeight(); + } else e.info.lspc = -2; } @@ -253,7 +255,7 @@ GlyphInfo GetGlyphInfo(Font font, int chr) void GlyphMetrics(GlyphInfo& f, Font font, int chr) { if(f.IsReplaced()) - f = GetGlyphInfo(font().Face(f.lspc), chr); + f = GetGlyphInfo(font().Face(f.lspc).Height(f.rspc), chr); if(f.IsComposed()) { f = GetGlyphInfo(font, f.rspc); if(f.IsComposedLM()) diff --git a/newdraw/Draw/FontCR.cpp b/newdraw/Draw/FontCR.cpp index c33ee85ba..bea0b7e68 100644 --- a/newdraw/Draw/FontCR.cpp +++ b/newdraw/Draw/FontCR.cpp @@ -245,6 +245,14 @@ static const char *sFontReplacements[] = { "PMingLiU", }; +//!!! Add ascent replacement cache!!! + +struct FontMetricsReplacement { + Font src; + Font dst; + Font mdst; +}; + bool Replace(Font fnt, int chr, Font& rfnt) { static Vector rface; @@ -259,6 +267,22 @@ bool Replace(Font fnt, int chr, Font& rfnt) Font f = fnt; for(int i = 0; i < rface.GetCount(); i++) if(IsNormal(f.Face(rface[i]), chr)) { + int a = fnt.GetAscent(); + int d = fnt.GetDescent(); + if(f.GetAscent() > a || f.GetDescent() > d) { + static FontMetricsReplacement cache[256]; + int q = CombineHash(fnt, f) & 255; + if(cache[q].src != fnt || cache[q].dst != f) { + cache[q].src = fnt; + cache[q].dst = f; + while((f.GetAscent() > a || f.GetDescent() > d) && f.GetHeight() > 1) { + f.Height(max(1, min(f.GetHeight() - 1, f.GetHeight() * 9 / 10))); + } + cache[q].mdst = f; + } + else + f = cache[q].mdst; + } rfnt = f; return true; } diff --git a/newdraw/Draw/FontWin32.cpp b/newdraw/Draw/FontWin32.cpp index cf2e53159..7338596c9 100644 --- a/newdraw/Draw/FontWin32.cpp +++ b/newdraw/Draw/FontWin32.cpp @@ -30,8 +30,7 @@ struct HFontEntry { HFONT GetWin32Font(Font fnt, int angle) { - RTIMING("FTFace"); - DDUMP(fnt); + LTIMING("GetWin32Font"); static HFontEntry cache[FONTCACHE]; ONCELOCK { for(int i = 0; i < FONTCACHE; i++) @@ -50,7 +49,7 @@ HFONT GetWin32Font(Font fnt, int angle) } be = e; } - RTIMING("FTFace2"); + LTIMING("GetWin32Font2"); if(be.hfont) DeleteObject(be.hfont); @@ -247,8 +246,6 @@ GlyphInfo GetGlyphInfoSys(Font font, int chr) int q = CombineHash(font, page) % GLYPHINFOCACHE; if(fnt[q] != font || pg[q] != page) { - DDUMP(font); - DDUMP(q); fnt[q] = font; pg[q] = page; HFONT hfont = GetWin32Font(font, 0);