summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Gramiak <agrambot@gmail.com>2019-05-10 09:45:57 -0600
committerAlexander Gramiak <agrambot@gmail.com>2019-05-19 19:50:32 -0600
commita4fe9c70af7a60117480d3361541550341da801a (patch)
treef9c082b94c2af6df79f7aa66dbcce4a97eabbbbd /src
parentb3d3c0daa49f5cbed7c58c7508d4d36dba3757e5 (diff)
downloademacs-a4fe9c70af7a60117480d3361541550341da801a.tar.gz
Replace XChar2b with unsigned in all font backends
The xfont backend using XChar2b in its API doesn't mean that we should use it everywhere else. * src/dispextern.h (glyph_string): * src/ftcrfont.c (ftcrfont_draw): * src/ftxfont.c (ftxfont_draw): * src/w32term.c (w32_draw_glyphless_glyph_string_foreground): * src/xdisp.c (init_glyph_string, get_char_face_and_encoding) (get_glyph_face_and_encoding, get_char_glyph_code) (fill_gstring_glyph_string, fill_stretch_glyph_string) (normal_char_ascent_descent, gui_get_glyph_overhangs) (compute_overhangs_and_x, gui_produce_glyphs): * src/xfont.c (xfont_get_pcm, xfont_chars_supported, xfont_open) (xfont_encode_char, xfont_text_extents, xfont_draw) * src/xftfont.c (xftfont_draw): * src/xterm.c (x_compute_glyph_string_overhangs) (x_draw_glyphless_glyph_string_foreground): Use unsigned over XChar2b. * src/nsgui.h: * src/w32gui.h: * src/xterm.h: Remove XChar2b, STORE_XCHAR2B, XCHAR2B_BYTE1, and XCHAR2B_BYTE2 typedefs and macros. * src/font.h (font_driver): (ftfont_text_extents) * src/ftcrfont.c (ftcrfont_text_extents): * src/ftfont.c (ftfont_text_extents): * src/macfont.m (macfont_text_extents): * src/nsfont.m (nsfont_text_extents): * src/w32font.h (w32_font_text_extents): * src/font.c (xfont_text_extents): * src/xftfont.c (xftfont_text_extents): Make code parameter const.
Diffstat (limited to 'src')
-rw-r--r--src/dispextern.h2
-rw-r--r--src/font.h4
-rw-r--r--src/ftcrfont.c11
-rw-r--r--src/ftfont.c2
-rw-r--r--src/ftxfont.c8
-rw-r--r--src/macfont.m4
-rw-r--r--src/nsfont.m2
-rw-r--r--src/nsgui.h15
-rw-r--r--src/w32font.c2
-rw-r--r--src/w32font.h2
-rw-r--r--src/w32gui.h13
-rw-r--r--src/w32term.c14
-rw-r--r--src/xdisp.c46
-rw-r--r--src/xfont.c101
-rw-r--r--src/xftfont.c5
-rw-r--r--src/xterm.c15
-rw-r--r--src/xterm.h9
17 files changed, 103 insertions, 152 deletions
diff --git a/src/dispextern.h b/src/dispextern.h
index 05e09301b06..eee515f2d24 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1317,7 +1317,7 @@ struct glyph_string
enum glyph_row_area area;
/* Characters to be drawn, and number of characters. */
- XChar2b *char2b;
+ unsigned *char2b;
int nchars;
/* A face-override for drawing cursors, mouse face and similar. */
diff --git a/src/font.h b/src/font.h
index 3720650a2e1..9ca0c97dc52 100644
--- a/src/font.h
+++ b/src/font.h
@@ -647,7 +647,7 @@ struct font_driver
the font FONT and the sequence of glyph codes CODE, and store the
result in METRICS. */
void (*text_extents) (struct font *font,
- unsigned *code, int nglyphs,
+ const unsigned *code, int nglyphs,
struct font_metrics *metrics);
#ifdef HAVE_WINDOW_SYSTEM
@@ -894,7 +894,7 @@ extern Lisp_Object ftfont_shape (Lisp_Object);
extern unsigned ftfont_encode_char (struct font *, int);
extern void ftfont_close (struct font *);
extern void ftfont_filter_properties (Lisp_Object, Lisp_Object);
-extern void ftfont_text_extents (struct font *, unsigned *, int,
+extern void ftfont_text_extents (struct font *, const unsigned *, int,
struct font_metrics *);
extern void syms_of_ftfont (void);
#endif /* HAVE_FREETYPE */
diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index e7c73eac4d3..606db0b949b 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -242,7 +242,7 @@ ftcrfont_close (struct font *font)
static void
ftcrfont_text_extents (struct font *font,
- unsigned *code,
+ const unsigned *code,
int nglyphs,
struct font_metrics *metrics)
{
@@ -341,13 +341,12 @@ ftcrfont_draw (struct glyph_string *s,
glyphs = alloca (sizeof (cairo_glyph_t) * len);
for (i = 0; i < len; i++)
{
- unsigned code = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8)
- | XCHAR2B_BYTE2 (s->char2b + from + i));
-
- glyphs[i].index = code;
+ glyphs[i].index = s->char2b[from + i];
glyphs[i].x = x;
glyphs[i].y = y;
- x += (s->padding_p ? 1 : ftcrfont_glyph_extents (s->font, code, NULL));
+ x += (s->padding_p ? 1 : ftcrfont_glyph_extents (s->font,
+ glyphs[i].index,
+ NULL));
}
x_set_cr_source_with_gc_foreground (f, s->gc);
diff --git a/src/ftfont.c b/src/ftfont.c
index 4770c3c40b3..f17bd9ab3f7 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -1353,7 +1353,7 @@ ftfont_encode_char (struct font *font, int c)
}
void
-ftfont_text_extents (struct font *font, unsigned int *code,
+ftfont_text_extents (struct font *font, const unsigned int *code,
int nglyphs, struct font_metrics *metrics)
{
struct font_info *ftfont_info = (struct font_info *) font;
diff --git a/src/ftxfont.c b/src/ftxfont.c
index f9a69c35151..8bce7f10f1e 100644
--- a/src/ftxfont.c
+++ b/src/ftxfont.c
@@ -252,7 +252,7 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
struct font *font = s->font;
XPoint p[0x700];
int n[7];
- unsigned *code;
+ unsigned *code = s->char2b + from;
int len = to - from;
int i;
GC *gcs;
@@ -260,14 +260,9 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
n[0] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = 0;
- USE_SAFE_ALLOCA;
- SAFE_NALLOCA (code, 1, len);
block_input ();
if (with_background)
ftxfont_draw_background (f, font, s->gc, x, y, s->width);
- for (i = 0; i < len; i++)
- code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8)
- | XCHAR2B_BYTE2 (s->char2b + from + i));
if (face->gc == s->gc)
{
@@ -312,7 +307,6 @@ ftxfont_draw (struct glyph_string *s, int from, int to, int x, int y,
}
unblock_input ();
- SAFE_FREE ();
return len;
}
diff --git a/src/macfont.m b/src/macfont.m
index 0ade77e7337..d69af679813 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -1639,7 +1639,7 @@ static Lisp_Object macfont_open (struct frame *, Lisp_Object, int);
static void macfont_close (struct font *);
static int macfont_has_char (Lisp_Object, int);
static unsigned macfont_encode_char (struct font *, int);
-static void macfont_text_extents (struct font *, unsigned int *, int,
+static void macfont_text_extents (struct font *, const unsigned int *, int,
struct font_metrics *);
static int macfont_draw (struct glyph_string *, int, int, int, int, bool);
static Lisp_Object macfont_shape (Lisp_Object);
@@ -2735,7 +2735,7 @@ macfont_encode_char (struct font *font, int c)
}
static void
-macfont_text_extents (struct font *font, unsigned int *code, int nglyphs,
+macfont_text_extents (struct font *font, const unsigned int *code, int nglyphs,
struct font_metrics *metrics)
{
int width, i;
diff --git a/src/nsfont.m b/src/nsfont.m
index 9721e489357..eca97ab86cc 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -945,7 +945,7 @@ nsfont_encode_char (struct font *font, int c)
of METRICS. The glyphs are specified by their glyph codes in
CODE (length NGLYPHS). */
static void
-nsfont_text_extents (struct font *font, unsigned int *code,
+nsfont_text_extents (struct font *font, const unsigned int *code,
int nglyphs, struct font_metrics *metrics)
{
struct nsfont_info *font_info = (struct nsfont_info *)font;
diff --git a/src/nsgui.h b/src/nsgui.h
index 87c06e68a22..c21953593ad 100644
--- a/src/nsgui.h
+++ b/src/nsgui.h
@@ -58,21 +58,6 @@ typedef struct _XCharStruct
int descent;
} XCharStruct;
-/* Fake structure from Xlib.h to represent two-byte characters. */
-#ifndef __OBJC__
-typedef unsigned short unichar;
-#endif
-typedef unichar XChar2b;
-
-#define STORE_XCHAR2B(chp, b1, b2) \
- (*(chp) = ((XChar2b)((((b1) & 0x00ff) << 8) | ((b2) & 0x00ff))))
-
-#define XCHAR2B_BYTE1(chp) \
- ((*(chp) & 0xff00) >> 8)
-
-#define XCHAR2B_BYTE2(chp) \
- (*(chp) & 0x00ff)
-
/* Used in xdisp.c when comparing faces and frame colors. */
extern unsigned long ns_color_index_to_rgba(int idx, struct frame *f);
diff --git a/src/w32font.c b/src/w32font.c
index 848016da1ca..bd68e22cc90 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -433,7 +433,7 @@ w32font_encode_char (struct font *font, int c)
CODE (length NGLYPHS). Apparently metrics can be NULL, in this
case just return the overall width. */
void
-w32font_text_extents (struct font *font, unsigned *code,
+w32font_text_extents (struct font *font, const unsigned *code,
int nglyphs, struct font_metrics *metrics)
{
int i;
diff --git a/src/w32font.h b/src/w32font.h
index 65f42a3178d..c7bb7f30570 100644
--- a/src/w32font.h
+++ b/src/w32font.h
@@ -74,7 +74,7 @@ int w32font_open_internal (struct frame *f, Lisp_Object font_entity,
int pixel_size, Lisp_Object font_object);
void w32font_close (struct font *font);
int w32font_has_char (Lisp_Object entity, int c);
-void w32font_text_extents (struct font *font, unsigned *code, int nglyphs,
+void w32font_text_extents (struct font *font, const unsigned *code, int nglyphs,
struct font_metrics *metrics);
int w32font_draw (struct glyph_string *s, int from, int to,
int x, int y, bool with_background);
diff --git a/src/w32gui.h b/src/w32gui.h
index 5e1730b92c7..62bad33c19b 100644
--- a/src/w32gui.h
+++ b/src/w32gui.h
@@ -33,19 +33,6 @@ typedef HWND Window;
typedef HDC Display; /* HDC so it doesn't conflict with xpm lib. */
typedef HCURSOR Emacs_Cursor;
-#define XChar2b wchar_t
-
-/* Dealing with bits of wchar_t as if they were an XChar2b. */
-#define STORE_XCHAR2B(chp, byte1, byte2) \
- ((*(chp)) = ((XChar2b)((((byte1) & 0x00ff) << 8) | ((byte2) & 0x00ff))))
-
-#define XCHAR2B_BYTE1(chp) \
- (((*(chp)) & 0xff00) >> 8)
-
-#define XCHAR2B_BYTE2(chp) \
- ((*(chp)) & 0x00ff)
-
-
/* Windows equivalent of XImage. */
typedef struct _XImage
{
diff --git a/src/w32term.c b/src/w32term.c
index 4a93b2a4043..5726124b0ed 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -1097,14 +1097,10 @@ w32_compute_glyph_string_overhangs (struct glyph_string *s)
&& s->first_glyph->type == CHAR_GLYPH
&& !s->font_not_found_p)
{
- unsigned *code = alloca (sizeof (unsigned) * s->nchars);
struct font *font = s->font;
struct font_metrics metrics;
- int i;
- for (i = 0; i < s->nchars; i++)
- code[i] = s->char2b[i];
- font->driver->text_extents (font, code, s->nchars, &metrics);
+ font->driver->text_extents (font, s->char2b, s->nchars, &metrics);
s->right_overhang = (metrics.rbearing > metrics.width
? metrics.rbearing - metrics.width : 0);
s->left_overhang = metrics.lbearing < 0 ? -metrics.lbearing : 0;
@@ -1349,7 +1345,7 @@ static void
w32_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
{
struct glyph *glyph = s->first_glyph;
- XChar2b char2b[8];
+ unsigned char2b[8];
int x, i, j;
bool with_background;
@@ -1406,16 +1402,12 @@ w32_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
{
struct font *font = s->font;
int upper_len = (len + 1) / 2;
- unsigned code;
HFONT old_font;
old_font = SelectObject (s->hdc, FONT_HANDLE (font));
/* It is certain that all LEN characters in STR are ASCII. */
for (j = 0; j < len; j++)
- {
- code = font->driver->encode_char (font, str[j]);
- STORE_XCHAR2B (char2b + j, code >> 8, code & 0xFF);
- }
+ char2b[j] = font->driver->encode_char (font, str[j]) & 0xFFFF;
font->driver->draw (s, 0, upper_len,
x + glyph->slice.glyphless.upper_xoff,
s->ybase + glyph->slice.glyphless.upper_yoff,
diff --git a/src/xdisp.c b/src/xdisp.c
index 6929ca4b4bf..c561ea9e36c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -25914,7 +25914,7 @@ dump_glyph_string (struct glyph_string *s)
#endif /* GLYPH_DEBUG */
/* Initialize glyph string S. CHAR2B is a suitably allocated vector
- of XChar2b structures for S; it can't be allocated in
+ of 2-byte unsigned integers for S; it can't be allocated in
init_glyph_string because it must be allocated via `alloca'. W
is the window on which S is drawn. ROW and AREA are the glyph row
and area within the row from which S is constructed. START is the
@@ -25944,7 +25944,7 @@ init_glyph_string (struct glyph_string *s,
#ifdef HAVE_NTGUI
HDC hdc,
#endif
- XChar2b *char2b, struct window *w, struct glyph_row *row,
+ unsigned *char2b, struct window *w, struct glyph_row *row,
enum glyph_row_area area, int start, enum draw_glyphs_face hl)
{
memset (s, 0, sizeof *s);
@@ -26023,7 +26023,7 @@ append_glyph_string (struct glyph_string **head, struct glyph_string **tail,
static struct face *
get_char_face_and_encoding (struct frame *f, int c, int face_id,
- XChar2b *char2b, bool display_p)
+ unsigned *char2b, bool display_p)
{
struct face *face = FACE_FROM_ID (f, face_id);
unsigned code = 0;
@@ -26035,7 +26035,8 @@ get_char_face_and_encoding (struct frame *f, int c, int face_id,
if (code == FONT_INVALID_CODE)
code = 0;
}
- STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
+ /* Ensure that the code is only 2 bytes wide. */
+ *char2b = code & 0xFFFF;
/* Make sure X resources of the face are allocated. */
#ifdef HAVE_X_WINDOWS
@@ -26056,7 +26057,7 @@ get_char_face_and_encoding (struct frame *f, int c, int face_id,
static struct face *
get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
- XChar2b *char2b)
+ unsigned *char2b)
{
struct face *face;
unsigned code = 0;
@@ -26078,7 +26079,8 @@ get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
code = 0;
}
- STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
+ /* Ensure that the code is only 2 bytes wide. */
+ *char2b = code & 0xFFFF;
return face;
}
@@ -26087,7 +26089,7 @@ get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
Return true iff FONT has a glyph for C. */
static bool
-get_char_glyph_code (int c, struct font *font, XChar2b *char2b)
+get_char_glyph_code (int c, struct font *font, unsigned *char2b)
{
unsigned code;
@@ -26098,7 +26100,9 @@ get_char_glyph_code (int c, struct font *font, XChar2b *char2b)
if (code == FONT_INVALID_CODE)
return false;
- STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
+
+ /* Ensure that the code is only 2 bytes wide. */
+ *char2b = code & 0xFFFF;
return true;
}
@@ -26211,7 +26215,8 @@ fill_gstring_glyph_string (struct glyph_string *s, int face_id,
Lisp_Object lglyph = LGSTRING_GLYPH (lgstring, i);
unsigned code = LGLYPH_CODE (lglyph);
- STORE_XCHAR2B ((s->char2b + i), code >> 8, code & 0xFF);
+ /* Ensure that the code is only 2 bytes wide. */
+ s->char2b[i] = code & 0xFFFF;
}
s->width = composition_gstring_width (lgstring, s->cmp_from, s->cmp_to, NULL);
return glyph - s->row->glyphs[s->area];
@@ -26390,17 +26395,16 @@ fill_stretch_glyph_string (struct glyph_string *s, int start, int end)
}
static struct font_metrics *
-get_per_char_metric (struct font *font, XChar2b *char2b)
+get_per_char_metric (struct font *font, const unsigned *char2b)
{
static struct font_metrics metrics;
- unsigned code;
if (! font)
return NULL;
- code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b);
- if (code == FONT_INVALID_CODE)
+ if (*char2b == FONT_INVALID_CODE)
return NULL;
- font->driver->text_extents (font, &code, 1, &metrics);
+
+ font->driver->text_extents (font, char2b, 1, &metrics);
return &metrics;
}
@@ -26418,7 +26422,7 @@ normal_char_ascent_descent (struct font *font, int c, int *ascent, int *descent)
if (FONT_TOO_HIGH (font))
{
- XChar2b char2b;
+ unsigned char2b;
/* Get metrics of C, defaulting to a reasonably sized ASCII
character. */
@@ -26465,7 +26469,7 @@ gui_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *r
if (glyph->type == CHAR_GLYPH)
{
- XChar2b char2b;
+ unsigned char2b;
struct face *face = get_glyph_face_and_encoding (f, glyph, &char2b);
if (face->font)
{
@@ -26779,7 +26783,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
do \
{ \
int face_id; \
- XChar2b *char2b; \
+ unsigned *char2b; \
\
face_id = (row)->glyphs[area][START].face_id; \
\
@@ -26808,7 +26812,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
struct face *base_face = FACE_FROM_ID (f, face_id); \
ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
struct composition *cmp = composition_table[cmp_id]; \
- XChar2b *char2b; \
+ unsigned *char2b; \
struct glyph_string *first_s = NULL; \
int n; \
\
@@ -26840,7 +26844,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
#define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
do { \
int face_id; \
- XChar2b *char2b; \
+ unsigned *char2b; \
Lisp_Object gstring; \
\
face_id = (row)->glyphs[area][START].face_id; \
@@ -28433,7 +28437,7 @@ gui_produce_glyphs (struct it *it)
if (it->what == IT_CHARACTER)
{
- XChar2b char2b;
+ unsigned char2b;
struct face *face = FACE_FROM_ID (it->f, it->face_id);
struct font *font = face->font;
struct font_metrics *pcm = NULL;
@@ -28832,7 +28836,7 @@ gui_produce_glyphs (struct it *it)
int lbearing, rbearing;
int i, width, ascent, descent;
int c;
- XChar2b char2b;
+ unsigned char2b;
struct font_metrics *pcm;
ptrdiff_t pos;
diff --git a/src/xfont.c b/src/xfont.c
index ff80df407d7..a402f770630 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -46,18 +46,20 @@ struct xfont_info
/* Prototypes of support functions. */
-static XCharStruct *xfont_get_pcm (XFontStruct *, XChar2b *);
+static XCharStruct *xfont_get_pcm (XFontStruct *, unsigned char2b);
/* Get metrics of character CHAR2B in XFONT. Value is null if CHAR2B
is not contained in the font. */
static XCharStruct *
-xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b)
+xfont_get_pcm (XFontStruct *xfont, unsigned char2b)
{
/* The result metric information. */
XCharStruct *pcm = NULL;
+ const unsigned char byte1 = char2b >> 8;
+ const unsigned char byte2 = char2b & 0xFF;
- eassert (xfont && char2b);
+ eassert (xfont);
if (xfont->per_char != NULL)
{
@@ -66,13 +68,13 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b)
/* min_char_or_byte2 specifies the linear character index
corresponding to the first element of the per_char array,
max_char_or_byte2 is the index of the last character. A
- character with non-zero CHAR2B->byte1 is not in the font.
+ character with non-zero byte1 is not in the font.
A character with byte2 less than min_char_or_byte2 or
greater max_char_or_byte2 is not in the font. */
- if (char2b->byte1 == 0
- && char2b->byte2 >= xfont->min_char_or_byte2
- && char2b->byte2 <= xfont->max_char_or_byte2)
- pcm = xfont->per_char + char2b->byte2 - xfont->min_char_or_byte2;
+ if (byte1 == 0
+ && byte2 >= xfont->min_char_or_byte2
+ && byte2 <= xfont->max_char_or_byte2)
+ pcm = xfont->per_char + byte2 - xfont->min_char_or_byte2;
}
else
{
@@ -89,14 +91,14 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b)
D = max_char_or_byte2 - min_char_or_byte2 + 1
/ = integer division
\ = integer modulus */
- if (char2b->byte1 >= xfont->min_byte1
- && char2b->byte1 <= xfont->max_byte1
- && char2b->byte2 >= xfont->min_char_or_byte2
- && char2b->byte2 <= xfont->max_char_or_byte2)
+ if (byte1 >= xfont->min_byte1
+ && byte1 <= xfont->max_byte1
+ && byte2 >= xfont->min_char_or_byte2
+ && byte2 <= xfont->max_char_or_byte2)
pcm = (xfont->per_char
+ ((xfont->max_char_or_byte2 - xfont->min_char_or_byte2 + 1)
- * (char2b->byte1 - xfont->min_byte1))
- + (char2b->byte2 - xfont->min_char_or_byte2));
+ * (byte1 - xfont->min_byte1))
+ + (byte2 - xfont->min_char_or_byte2));
}
}
else
@@ -104,8 +106,8 @@ xfont_get_pcm (XFontStruct *xfont, XChar2b *char2b)
/* If the per_char pointer is null, all glyphs between the first
and last character indexes inclusive have the same
information, as given by both min_bounds and max_bounds. */
- if (char2b->byte2 >= xfont->min_char_or_byte2
- && char2b->byte2 <= xfont->max_char_or_byte2)
+ if (byte2 >= xfont->min_char_or_byte2
+ && byte2 <= xfont->max_char_or_byte2)
pcm = &xfont->max_bounds;
}
@@ -193,7 +195,6 @@ xfont_chars_supported (Lisp_Object chars, XFontStruct *xfont,
{
int c = XFIXNUM (XCAR (chars));
unsigned code = ENCODE_CHAR (charset, c);
- XChar2b char2b;
if (code == CHARSET_INVALID_CODE (charset))
break;
@@ -201,9 +202,7 @@ xfont_chars_supported (Lisp_Object chars, XFontStruct *xfont,
continue;
if (code >= 0x10000)
break;
- char2b.byte1 = code >> 8;
- char2b.byte2 = code & 0xFF;
- if (! xfont_get_pcm (xfont, &char2b))
+ if (! xfont_get_pcm (xfont, code))
break;
}
return (NILP (chars));
@@ -216,7 +215,6 @@ xfont_chars_supported (Lisp_Object chars, XFontStruct *xfont,
{
int c = XFIXNUM (AREF (chars, i));
unsigned code = ENCODE_CHAR (charset, c);
- XChar2b char2b;
if (code == CHARSET_INVALID_CODE (charset))
continue;
@@ -224,9 +222,7 @@ xfont_chars_supported (Lisp_Object chars, XFontStruct *xfont,
break;
if (code >= 0x10000)
continue;
- char2b.byte1 = code >> 8;
- char2b.byte2 = code & 0xFF;
- if (xfont_get_pcm (xfont, &char2b))
+ if (xfont_get_pcm (xfont, code))
break;
}
return (i >= 0);
@@ -801,11 +797,9 @@ xfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
else
{
XCharStruct *pcm;
- XChar2b char2b;
Lisp_Object val;
- char2b.byte1 = 0x00, char2b.byte2 = 0x20;
- pcm = xfont_get_pcm (xfont, &char2b);
+ pcm = xfont_get_pcm (xfont, 0x20);
if (pcm)
font->space_width = pcm->width;
else
@@ -823,8 +817,8 @@ xfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
{
int width = font->space_width, n = pcm != NULL;
- for (char2b.byte2 = 33; char2b.byte2 <= 126; char2b.byte2++)
- if ((pcm = xfont_get_pcm (xfont, &char2b)) != NULL)
+ for (unsigned char2b = 33; char2b <= 126; ++char2b)
+ if ((pcm = xfont_get_pcm (xfont, char2b)) != NULL)
width += pcm->width, n++;
if (n > 0)
font->average_width = width / n;
@@ -934,7 +928,6 @@ xfont_encode_char (struct font *font, int c)
XFontStruct *xfont = ((struct xfont_info *) font)->xfont;
struct charset *charset;
unsigned code;
- XChar2b char2b;
charset = CHARSET_FROM_ID (font->encoding_charset);
code = ENCODE_CHAR (charset, c);
@@ -946,13 +939,11 @@ xfont_encode_char (struct font *font, int c)
return (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset)
? code : FONT_INVALID_CODE);
}
- char2b.byte1 = code >> 8;
- char2b.byte2 = code & 0xFF;
- return (xfont_get_pcm (xfont, &char2b) ? code : FONT_INVALID_CODE);
+ return (xfont_get_pcm (xfont, code) ? code : FONT_INVALID_CODE);
}
static void
-xfont_text_extents (struct font *font, unsigned int *code,
+xfont_text_extents (struct font *font, const unsigned int *code,
int nglyphs, struct font_metrics *metrics)
{
XFontStruct *xfont = ((struct xfont_info *) font)->xfont;
@@ -961,13 +952,11 @@ xfont_text_extents (struct font *font, unsigned int *code,
for (i = 0, first = true; i < nglyphs; i++)
{
- XChar2b char2b;
static XCharStruct *pcm;
if (code[i] >= 0x10000)
continue;
- char2b.byte1 = code[i] >> 8, char2b.byte2 = code[i] & 0xFF;
- pcm = xfont_get_pcm (xfont, &char2b);
+ pcm = xfont_get_pcm (xfont, code[i]);
if (! pcm)
continue;
if (first)
@@ -1017,7 +1006,7 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
USE_SAFE_ALLOCA;
char *str = SAFE_ALLOCA (len);
for (i = 0; i < len ; i++)
- str[i] = XCHAR2B_BYTE2 (s->char2b + from + i);
+ str[i] = s->char2b[from + i] & 0xFF;
block_input ();
if (with_background)
{
@@ -1049,21 +1038,41 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y,
{
if (s->padding_p)
for (i = 0; i < len; i++)
- XDrawImageString16 (display, FRAME_X_DRAWABLE (s->f),
- gc, x + i, y, s->char2b + from + i, 1);
+ {
+ const unsigned code = s->char2b[from + i];
+ const XChar2b char2b = { .byte1 = code >> 8,
+ .byte2 = code & 0xFF };
+ XDrawImageString16 (display, FRAME_X_DRAWABLE (s->f),
+ gc, x + i, y, &char2b, 1);
+ }
else
- XDrawImageString16 (display, FRAME_X_DRAWABLE (s->f),
- gc, x, y, s->char2b + from, len);
+ {
+ const unsigned code = s->char2b[from];
+ const XChar2b char2b = { .byte1 = code >> 8,
+ .byte2 = code & 0xFF };
+ XDrawImageString16 (display, FRAME_X_DRAWABLE (s->f),
+ gc, x, y, &char2b, len);
+ }
}
else
{
if (s->padding_p)
for (i = 0; i < len; i++)
- XDrawString16 (display, FRAME_X_DRAWABLE (s->f),
- gc, x + i, y, s->char2b + from + i, 1);
+ {
+ const unsigned code = s->char2b[from + i];
+ const XChar2b char2b = { .byte1 = code >> 8,
+ .byte2 = code & 0xFF };
+ XDrawString16 (display, FRAME_X_DRAWABLE (s->f),
+ gc, x + i, y, &char2b, 1);
+ }
else
- XDrawString16 (display, FRAME_X_DRAWABLE (s->f),
- gc, x, y, s->char2b + from, len);
+ {
+ const unsigned code = s->char2b[from];
+ const XChar2b char2b = { .byte1 = code >> 8,
+ .byte2 = code & 0xFF };
+ XDrawString16 (display, FRAME_X_DRAWABLE (s->f),
+ gc, x, y, &char2b, len);
+ }
}
unblock_input ();
diff --git a/src/xftfont.c b/src/xftfont.c
index 8a4516f7f91..2edc51fe356 100644
--- a/src/xftfont.c
+++ b/src/xftfont.c
@@ -536,7 +536,7 @@ xftfont_encode_char (struct font *font, int c)
}
static void
-xftfont_text_extents (struct font *font, unsigned int *code,
+xftfont_text_extents (struct font *font, const unsigned int *code,
int nglyphs, struct font_metrics *metrics)
{
struct font_info *xftfont_info = (struct font_info *) font;
@@ -621,8 +621,7 @@ xftfont_draw (struct glyph_string *s, int from, int to, int x, int y,
}
code = alloca (sizeof (FT_UInt) * len);
for (i = 0; i < len; i++)
- code[i] = ((XCHAR2B_BYTE1 (s->char2b + from + i) << 8)
- | XCHAR2B_BYTE2 (s->char2b + from + i));
+ code[i] = s->char2b[from + i];
if (s->padding_p)
for (i = 0; i < len; i++)
diff --git a/src/xterm.c b/src/xterm.c
index 2de6198359c..bff9f74a17b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1599,13 +1599,8 @@ x_compute_glyph_string_overhangs (struct glyph_string *s)
if (s->first_glyph->type == CHAR_GLYPH)
{
- unsigned *code = alloca (sizeof (unsigned) * s->nchars);
struct font *font = s->font;
- int i;
-
- for (i = 0; i < s->nchars; i++)
- code[i] = (s->char2b[i].byte1 << 8) | s->char2b[i].byte2;
- font->driver->text_extents (font, code, s->nchars, &metrics);
+ font->driver->text_extents (font, s->char2b, s->nchars, &metrics);
}
else
{
@@ -1831,7 +1826,7 @@ static void
x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
{
struct glyph *glyph = s->first_glyph;
- XChar2b char2b[8];
+ unsigned char2b[8];
int x, i, j;
/* If first glyph of S has a left box line, start drawing the text
@@ -1882,14 +1877,10 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
if (str)
{
int upper_len = (len + 1) / 2;
- unsigned code;
/* It is assured that all LEN characters in STR is ASCII. */
for (j = 0; j < len; j++)
- {
- code = s->font->driver->encode_char (s->font, str[j]);
- STORE_XCHAR2B (char2b + j, code >> 8, code & 0xFF);
- }
+ char2b[j] = s->font->driver->encode_char (s->font, str[j]) & 0xFFFF;
s->font->driver->draw (s, 0, upper_len,
x + glyph->slice.glyphless.upper_xoff,
s->ybase + glyph->slice.glyphless.upper_yoff,
diff --git a/src/xterm.h b/src/xterm.h
index 54473045787..ce1443c381c 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1262,15 +1262,6 @@ extern void x_session_close (void);
#define FRAME_X_EMBEDDED_P(f) (FRAME_X_OUTPUT(f)->explicit_parent != 0)
-#define STORE_XCHAR2B(chp, b1, b2) \
- ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
-
-#define XCHAR2B_BYTE1(chp) \
- ((chp)->byte1)
-
-#define XCHAR2B_BYTE2(chp) \
- ((chp)->byte2)
-
#define STORE_NATIVE_RECT(nr,rx,ry,rwidth,rheight) \
((nr).x = (rx), \
(nr).y = (ry), \