Commit 2a36efcf authored by Jason Rumney's avatar Jason Rumney

(w32font_text_extents): Avoid getting HDC and selecting

a font into it unless we have to.
parent a2bc5bdd
2008-02-24 Jason Rumney <jasonr@gnu.org>
* w32font.c (w32font_text_extents): Avoid getting HDC and selecting
a font into it unless we have to.
2008-02-19 Stefan Monnier <monnier@iro.umontreal.ca>
* intervals.h (INT_LISPLIKE): Remove. It may misfire.
......
......@@ -290,8 +290,8 @@ w32font_text_extents (font, code, nglyphs, metrics)
struct font_metrics *metrics;
{
int i;
HFONT old_font;
HDC dc;
HFONT old_font = NULL;
HDC dc = NULL;
struct frame * f;
int total_width = 0;
WORD *wcode = alloca(nglyphs * sizeof (WORD));
......@@ -302,9 +302,6 @@ w32font_text_extents (font, code, nglyphs, metrics)
until the API is updated to pass in a frame. */
f = XFRAME (selected_frame);
dc = get_frame_dc (f);
old_font = SelectObject (dc, ((W32FontStruct *)(font->font.font))->hfont);
if (metrics)
{
GLYPHMETRICS gm;
......@@ -339,33 +336,45 @@ w32font_text_extents (font, code, nglyphs, metrics)
metrics->ascent = max (metrics->ascent, char_metric->ascent);
metrics->descent = max (metrics->descent, char_metric->descent);
}
else if (GetGlyphOutlineW (dc, *(code + i), GGO_METRICS, &gm, 0,
NULL, &transform) != GDI_ERROR)
{
int new_val = metrics->width + gm.gmBlackBoxX
+ gm.gmptGlyphOrigin.x;
metrics->rbearing = max (metrics->rbearing, new_val);
new_val = -gm.gmptGlyphOrigin.x - metrics->width;
metrics->lbearing = max (metrics->lbearing, new_val);
metrics->width += gm.gmCellIncX;
new_val = -gm.gmptGlyphOrigin.y;
metrics->ascent = max (metrics->ascent, new_val);
new_val = gm.gmBlackBoxY + gm.gmptGlyphOrigin.y;
metrics->descent = max (metrics->descent, new_val);
}
else
{
/* Rely on an estimate based on the overall font metrics. */
break;
if (dc == NULL)
{
dc = get_frame_dc (f);
old_font = SelectObject (dc, ((W32FontStruct *)
(font->font.font))->hfont);
}
if (GetGlyphOutlineW (dc, *(code + i), GGO_METRICS, &gm, 0,
NULL, &transform) != GDI_ERROR)
{
int new_val = metrics->width + gm.gmBlackBoxX
+ gm.gmptGlyphOrigin.x;
metrics->rbearing = max (metrics->rbearing, new_val);
new_val = -gm.gmptGlyphOrigin.x - metrics->width;
metrics->lbearing = max (metrics->lbearing, new_val);
metrics->width += gm.gmCellIncX;
new_val = -gm.gmptGlyphOrigin.y;
metrics->ascent = max (metrics->ascent, new_val);
new_val = gm.gmBlackBoxY + gm.gmptGlyphOrigin.y;
metrics->descent = max (metrics->descent, new_val);
}
else
{
/* Rely on an estimate based on the overall font metrics. */
break;
}
}
}
/* If we got through everything, return. */
if (i == nglyphs)
{
/* Restore state and release DC. */
SelectObject (dc, old_font);
release_frame_dc (f, dc);
if (dc != NULL)
{
/* Restore state and release DC. */
SelectObject (dc, old_font);
release_frame_dc (f, dc);
}
return metrics->width;
}
......@@ -382,6 +391,13 @@ w32font_text_extents (font, code, nglyphs, metrics)
}
}
if (dc == NULL)
{
dc = get_frame_dc (f);
old_font = SelectObject (dc, ((W32FontStruct *)
(font->font.font))->hfont);
}
if (GetTextExtentPoint32W (dc, wcode, nglyphs, &size))
{
total_width = size.cx;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment