aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney <[email protected]>2008-06-26 22:11:25 +0000
committerJason Rumney <[email protected]>2008-06-26 22:11:25 +0000
commitc35f9821de5ec0cf127185890191ad0154600d0d (patch)
tree18fc6dbe64578d453a0004a8d7b7c4dc3a94e13c /src
parentec06f5c9a0d4fc01c3af9e14add64bb09f977fb6 (diff)
* w32font.h (FONT_HANDLE, FONT_TEXTMETRIC): New macros.
* w32term.c (x_draw_glyph_string_foreground): (x_draw_composite_glyph_string_foreground): Sync with xterm.c. Use FONT_HANDLE macro. (x_draw_glyph_string): Use FONT_TEXTMETRIC macro. * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape): (uniscribe_encode_char): Use FONT_HANDLE macro. * w32font.c (Fx_select_font): Use FONT_HANDLE macro. (w32font_text_extents): Use precast w32_font. (w32font_close): Free cached metrics. (w32font_open_internal): Allocate space for name on stack.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog17
-rw-r--r--src/w32font.c29
-rw-r--r--src/w32font.h4
-rw-r--r--src/w32term.c53
-rw-r--r--src/w32uniscribe.c6
5 files changed, 62 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ac2aa66f32..83b6881b42 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
+2008-06-26 Jason Rumney <[email protected]>
+
+ * w32font.h (FONT_HANDLE, FONT_TEXTMETRIC): New macros.
+
+ * w32term.c (x_draw_glyph_string_foreground):
+ (x_draw_composite_glyph_string_foreground): Sync with xterm.c.
+ Use FONT_HANDLE macro.
+ (x_draw_glyph_string): Use FONT_TEXTMETRIC macro.
+
+ * w32uniscribe.c (uniscribe_otf_capability, uniscribe_shape):
+ (uniscribe_encode_char): Use FONT_HANDLE macro.
+
+ * w32font.c (Fx_select_font): Use FONT_HANDLE macro.
+ (w32font_text_extents): Use precast w32_font.
+ (w32font_close): Free cached metrics.
+ (w32font_open_internal): Allocate space for name on stack.
+
2008-06-26 Chong Yidong <[email protected]>
* xdisp.c (extend_face_to_end_of_line): Fix last change.
diff --git a/src/w32font.c b/src/w32font.c
index 9b261a9da3..bc3340c191 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -233,8 +233,23 @@ w32font_close (f, font)
FRAME_PTR f;
struct font *font;
{
+ int i;
struct w32font_info *w32_font = (struct w32font_info *) font;
+
+ /* Delete the GDI font object. */
DeleteObject (w32_font->hfont);
+
+ /* Free all the cached metrics. */
+ if (w32_font->cached_metrics)
+ {
+ for (i = 0; i < w32_font->n_cache_blocks; i++)
+ {
+ if (w32_font->cached_metrics[i])
+ xfree (w32_font->cached_metrics[i]);
+ }
+ xfree (w32_font->cached_metrics);
+ w32_font->cached_metrics = NULL;
+ }
}
/* w32 implementation of has_char for font backend.
@@ -493,8 +508,7 @@ w32font_text_extents (font, code, nglyphs, metrics)
{
metrics->width = total_width;
metrics->lbearing = 0;
- metrics->rbearing = total_width
- + ((struct w32font_info *) font)->metrics.tmOverhang;
+ metrics->rbearing = total_width + w32_font->metrics.tmOverhang;
}
/* Restore state and release DC. */
@@ -831,15 +845,12 @@ w32font_open_internal (f, font_entity, pixel_size, font_object)
/* We don't know how much space we need for the full name, so start with
96 bytes and go up in steps of 32. */
len = 96;
- name = xmalloc (len);
+ name = alloca (len);
while (name && w32font_full_name (&logfont, font_entity, pixel_size,
name, len) < 0)
{
- char *new = xrealloc (name, len += 32);
-
- if (! new)
- xfree (name);
- name = new;
+ len += 32;
+ name = alloca (len);
}
if (name)
font->props[FONT_FULLNAME_INDEX]
@@ -2048,7 +2059,7 @@ in the font selection dialog. */)
/* Initialize as much of the font details as we can from the current
default font. */
hdc = GetDC (FRAME_W32_WINDOW (f));
- oldobj = SelectObject (hdc, ((struct w32font_info *) FRAME_FONT (f))->hfont);
+ oldobj = SelectObject (hdc, FONT_HANDLE (FRAME_FONT (f)));
GetTextFace (hdc, LF_FACESIZE, lf.lfFaceName);
if (GetTextMetrics (hdc, &tm))
{
diff --git a/src/w32font.h b/src/w32font.h
index 30b6ed3427..25cf4ece56 100644
--- a/src/w32font.h
+++ b/src/w32font.h
@@ -56,6 +56,10 @@ struct w32font_info
HFONT hfont;
};
+/* Macros for getting OS specific information from a font struct. */
+#define FONT_HANDLE(f) (((struct w32font_info *)(f))->hfont)
+#define FONT_TEXTMETRIC(f) (((struct w32font_info *)(f))->metrics)
+
#define CACHE_BLOCKSIZE 128
Lisp_Object w32font_get_cache P_ ((FRAME_PTR fe));
diff --git a/src/w32term.c b/src/w32term.c
index 5766205130..28861eea90 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1237,8 +1237,6 @@ x_draw_glyph_string_foreground (s)
struct glyph_string *s;
{
int i, x;
- struct w32font_info * w32_font;
- HFONT old_font;
/* If first glyph of S has a left box line, start drawing the text
of S to the right of that box line. */
@@ -1248,21 +1246,10 @@ x_draw_glyph_string_foreground (s)
else
x = s->x;
- if (s->for_overlaps || (s->background_filled_p && s->hl != DRAW_CURSOR)
- || cleartype_active)
- SetBkMode (s->hdc, TRANSPARENT);
- else
- SetBkMode (s->hdc, OPAQUE);
-
SetTextColor (s->hdc, s->gc->foreground);
SetBkColor (s->hdc, s->gc->background);
SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
- w32_font = (struct w32font_info *) s->font;
-
- if (w32_font && w32_font->hfont)
- old_font = SelectObject (s->hdc, w32_font->hfont);
-
/* Draw characters of S as rectangles if S's font could not be
loaded. */
if (s->font_not_found_p)
@@ -1278,24 +1265,27 @@ x_draw_glyph_string_foreground (s)
}
else
{
- int boff = s->font->baseline_offset;
+ struct font *font = s->font;
+ int boff = font->baseline_offset;
int y;
+ HFONT old_font;
+
+ old_font = SelectObject (s->hdc, FONT_HANDLE (font));
- if (s->font->vertical_centering)
- boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
+ if (font->vertical_centering)
+ boff = VCENTER_BASELINE_OFFSET (font, s->f) - boff;
y = s->ybase - boff;
if (s->for_overlaps
|| (s->background_filled_p && s->hl != DRAW_CURSOR))
- s->font->driver->draw (s, 0, s->nchars, x, y, 0);
+ font->driver->draw (s, 0, s->nchars, x, y, 0);
else
- s->font->driver->draw (s, 0, s->nchars, x, y, 1);
+ font->driver->draw (s, 0, s->nchars, x, y, 1);
if (s->face->overstrike)
- s->font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
- }
+ font->driver->draw (s, 0, s->nchars, x + 1, y, 0);
- if (w32_font && w32_font->hfont)
- SelectObject (s->hdc, old_font);
+ SelectObject (s->hdc, old_font);
+ }
}
/* Draw the foreground of composite glyph string S. */
@@ -1305,8 +1295,6 @@ x_draw_composite_glyph_string_foreground (s)
struct glyph_string *s;
{
int i, j, x;
- HFONT old_font;
- struct w32font_info * w32_font;
/* If first glyph of S has a left box line, start drawing the text
of S to the right of that box line. */
@@ -1323,14 +1311,8 @@ x_draw_composite_glyph_string_foreground (s)
SetTextColor (s->hdc, s->gc->foreground);
SetBkColor (s->hdc, s->gc->background);
- SetBkMode (s->hdc, TRANSPARENT);
SetTextAlign (s->hdc, TA_BASELINE | TA_LEFT);
- w32_font = (struct w32font_info *) s->font;
-
- if (w32_font && w32_font->hfont)
- old_font = SelectObject (s->hdc, w32_font->hfont);
-
/* Draw a rectangle for the composition if the font for the very
first character of the composition could not be loaded. */
if (s->font_not_found_p)
@@ -1339,11 +1321,14 @@ x_draw_composite_glyph_string_foreground (s)
w32_draw_rectangle (s->hdc, s->gc, x, s->y, s->width - 1,
s->height - 1);
}
-
+ else
{
struct font *font = s->font;
int y = s->ybase;
int width = 0;
+ HFONT old_font;
+
+ old_font = SelectObject (s->hdc, FONT_HANDLE (font));
if (s->cmp->method == COMPOSITION_WITH_GLYPH_STRING)
{
@@ -1393,10 +1378,8 @@ x_draw_composite_glyph_string_foreground (s)
font->driver->draw (s, j, j + 1, xx + 1, yy, 0);
}
}
+ SelectObject (s->hdc, old_font);
}
-
- if (w32_font && w32_font->hfont)
- SelectObject (s->hdc, old_font);
}
@@ -2345,7 +2328,7 @@ x_draw_glyph_string (s)
/* Draw strike-through. */
if (s->face->strike_through_p
- && !((struct w32font_info *) s->font)->metrics.tmStruckOut)
+ && !FONT_TEXTMETRIC(s->font).tmStruckOut)
{
unsigned long h = 1;
unsigned long dy = (s->height - h) / 2;
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c
index 494abef74d..366287e8de 100644
--- a/src/w32uniscribe.c
+++ b/src/w32uniscribe.c
@@ -166,7 +166,7 @@ uniscribe_otf_capability (font)
f = XFRAME (selected_frame);
context = get_frame_dc (f);
- old_font = SelectObject (context, ((struct w32font_info *) font)->hfont);
+ old_font = SelectObject (context, FONT_HANDLE(font));
features = otf_features (context, "GSUB");
XSETCAR (capability, features);
@@ -259,7 +259,7 @@ uniscribe_shape (lgstring)
f = XFRAME (selected_frame);
context = get_frame_dc (f);
- old_font = SelectObject (context, uniscribe_font->w32_font.hfont);
+ old_font = SelectObject (context, FONT_HANDLE(font));
glyphs = alloca (max_glyphs * sizeof (WORD));
clusters = alloca (nchars * sizeof (WORD));
@@ -424,7 +424,7 @@ uniscribe_encode_char (font, c)
/* Use selected frame until API is updated to pass the frame. */
f = XFRAME (selected_frame);
context = get_frame_dc (f);
- old_font = SelectObject (context, ((struct w32font_info *) font)->hfont);
+ old_font = SelectObject (context, FONT_HANDLE(font));
retval = GetGlyphIndicesW (context, chars, 1, indices,
GGI_MARK_NONEXISTING_GLYPHS);