Developing new fonts....

git-svn-id: svn://ultimatepp.org/upp/trunk@1363 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-07-06 08:40:03 +00:00
parent d1c50c8278
commit 782abba616
8 changed files with 38 additions and 34 deletions

View file

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

View file

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

View file

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

View file

@ -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();

View file

@ -53,9 +53,6 @@ private:
friend void StaticExitDraw_();
Font lastFont;
int lastAngle;
Point actual_offset_bak;
struct Cloff : Moveable<Cloff> {
@ -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;

View file

@ -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())

View file

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

View file

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