Use a libev prepare watcher for calling awesome_refresh()
[awesome.git] / draw.c
blob686bcfeb6fdea43bb95a159a6f5859b626d38f96
1 /*
2 * draw.c - draw functions
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <cairo-xcb.h>
24 #include "config.h"
26 #include <langinfo.h>
27 #include <iconv.h>
28 #include <errno.h>
29 #include <ctype.h>
30 #include <math.h>
32 #include "structs.h"
34 #include "common/tokenize.h"
35 #include "common/xutil.h"
37 /** Convert text from any charset to UTF-8 using iconv.
38 * \param iso The ISO string to convert.
39 * \param len The string size.
40 * \param dest The destination pointer. Memory will be allocated, up to you to
41 * free, like any char *.
42 * \param dlen The destination length, can be NULL.
43 * \return True if conversion was done.
45 bool
46 draw_iso2utf8(const char *iso, size_t len, char **dest, ssize_t *dlen)
48 static iconv_t iso2utf8 = (iconv_t) -1;
49 static int8_t dont_need_convert = -1;
51 if(dont_need_convert == -1)
52 dont_need_convert = !a_strcmp(nl_langinfo(CODESET), "UTF-8");
54 if(!len || dont_need_convert)
55 return false;
57 if(iso2utf8 == (iconv_t) -1)
59 iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET));
60 if(iso2utf8 == (iconv_t) -1)
62 if(errno == EINVAL)
63 warn("unable to convert text from %s to UTF-8, not available",
64 nl_langinfo(CODESET));
65 else
66 warn("unable to convert text: %s", strerror(errno));
68 return false;
72 size_t orig_utf8len, utf8len;
73 char *utf8;
75 orig_utf8len = utf8len = 2 * len + 1;
76 utf8 = *dest = p_new(char, utf8len);
78 if(iconv(iso2utf8, (char **) &iso, &len, &utf8, &utf8len) == (size_t) -1)
80 warn("text conversion failed: %s", strerror(errno));
81 p_delete(dest);
82 return false;
85 if(dlen)
86 *dlen = orig_utf8len - utf8len;
88 return true;
91 static xcb_visualtype_t *
92 draw_screen_default_visual(xcb_screen_t *s)
94 if(!s)
95 return NULL;
97 xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s);
99 if(depth_iter.data)
100 for(; depth_iter.rem; xcb_depth_next (&depth_iter))
101 for(xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
102 visual_iter.rem; xcb_visualtype_next (&visual_iter))
103 if(s->root_visual == visual_iter.data->visual_id)
104 return visual_iter.data;
106 return NULL;
109 /** Create a new Pango font.
110 * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]).
111 * \return A new font.
113 font_t *
114 draw_font_new(const char *fontname)
116 cairo_surface_t *surface;
117 xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
118 cairo_t *cr;
119 PangoLayout *layout;
120 font_t *font = p_new(font_t, 1);
122 xcb_visualtype_t *visual = draw_screen_default_visual(s);
124 if(!visual)
125 fatal("cannot get visual");
127 /* Create a dummy cairo surface, cairo context and pango layout in
128 * order to get font informations */
129 surface = cairo_xcb_surface_create(globalconf.connection,
130 globalconf.default_screen,
131 visual,
132 s->width_in_pixels,
133 s->height_in_pixels);
135 cr = cairo_create(surface);
136 layout = pango_cairo_create_layout(cr);
138 /* Get the font description used to set text on a PangoLayout */
139 font->desc = pango_font_description_from_string(fontname);
140 pango_layout_set_font_description(layout, font->desc);
142 /* Get height */
143 pango_layout_get_pixel_size(layout, NULL, &font->height);
145 g_object_unref(layout);
146 cairo_destroy(cr);
147 cairo_surface_destroy(surface);
149 return font;
152 /** Delete a font.
153 * \param font Font to delete.
155 void
156 draw_font_delete(font_t **font)
158 if(*font)
160 pango_font_description_free((*font)->desc);
161 p_delete(font);
165 /** Initialize a draw_text_context_t with text data.
166 * \param data The draw text context to init.
167 * \param str The text string to render.
168 * \param slen The text string length.
169 * \return True if everything is ok, false otherwise.
171 bool
172 draw_text_context_init(draw_text_context_t *data, const char *str, ssize_t slen)
174 GError *error = NULL;
176 if(!str)
177 return false;
179 if(!pango_parse_markup(str, slen, 0, &data->attr_list, &data->text, NULL, &error))
181 warn("cannot parse pango markup: %s", error ? error->message : "unknown error");
182 if(error)
183 g_error_free(error);
184 return false;
187 data->len = a_strlen(data->text);
189 return true;
192 /** Initialize a new draw context.
193 * \param d The draw context to initialize.
194 * \param phys_screen Physical screen id.
195 * \param width Width.
196 * \param height Height.
197 * \param px Pixmap object to store.
198 * \param fg Foreground color.
199 * \param bg Background color.
201 void
202 draw_context_init(draw_context_t *d, int phys_screen,
203 int width, int height, xcb_pixmap_t px,
204 const xcolor_t *fg, const xcolor_t *bg)
206 xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
208 d->phys_screen = phys_screen;
209 d->width = width;
210 d->height = height;
211 d->visual = draw_screen_default_visual(s);
212 d->pixmap = px;
213 d->surface = cairo_xcb_surface_create(globalconf.connection, px, d->visual, width, height);
214 d->cr = cairo_create(d->surface);
215 d->layout = pango_cairo_create_layout(d->cr);
216 d->fg = *fg;
217 d->bg = *bg;
220 /** Draw text into a draw context.
221 * \param ctx Draw context to draw to.
222 * \param data Draw text context data.
223 * \param elip Ellipsize mode.
224 * \param wrap Wrap mode.
225 * \param align Text alignment.
226 * \param margin Margin to respect when drawing text.
227 * \param area Area to draw to.
228 * \param ext Text extents.
230 void
231 draw_text(draw_context_t *ctx, draw_text_context_t *data,
232 PangoEllipsizeMode ellip, PangoWrapMode wrap,
233 alignment_t align, padding_t *margin, area_t area, area_t *ext)
235 int x, y;
237 pango_layout_set_text(ctx->layout, data->text, data->len);
238 pango_layout_set_width(ctx->layout,
239 pango_units_from_double(area.width
240 - (margin->left
241 + margin->right)));
242 pango_layout_set_height(ctx->layout, pango_units_from_double(area.height)
243 - (margin->top + margin->bottom));
244 pango_layout_set_ellipsize(ctx->layout, ellip);
245 pango_layout_set_wrap(ctx->layout, wrap);
246 pango_layout_set_attributes(ctx->layout, data->attr_list);
247 pango_layout_set_font_description(ctx->layout, globalconf.font->desc);
249 x = area.x + margin->left;
250 /* + 1 is added for rounding, so that in any case of doubt we rather draw
251 * the text 1px lower than too high which usually results in a better type
252 * face */
253 y = area.y + (ctx->height - ext->height + 1) / 2 + margin->top;
255 /* only honors alignment if enough space */
256 if(ext->width < area.width)
257 switch(align)
259 case AlignCenter:
260 x += (area.width - ext->width) / 2;
261 break;
262 case AlignRight:
263 x += area.width - ext->width;
264 break;
265 default:
266 break;
269 cairo_move_to(ctx->cr, x, y);
271 cairo_set_source_rgba(ctx->cr,
272 ctx->fg.red / 65535.0,
273 ctx->fg.green / 65535.0,
274 ctx->fg.blue / 65535.0,
275 ctx->fg.alpha / 65535.0);
276 pango_cairo_update_layout(ctx->cr, ctx->layout);
277 pango_cairo_show_layout(ctx->cr, ctx->layout);
280 /** Setup color-source for cairo (gradient or mono).
281 * \param ctx Draw context.
282 * \param gradient_vector x, y to x + x_offset, y + y_offset.
283 * \param pcolor Color to use at start of gradient_vector.
284 * \param pcolor_center Color at center of gradient_vector.
285 * \param pcolor_end Color at end of gradient_vector.
286 * \return pat Pattern or NULL, needs to get cairo_pattern_destroy()'ed.
288 static cairo_pattern_t *
289 draw_setup_cairo_color_source(draw_context_t *ctx, vector_t gradient_vector,
290 const color_t *pcolor, const color_t *pcolor_center,
291 const color_t *pcolor_end)
293 cairo_pattern_t *pat = NULL;
294 bool has_center = pcolor_center->initialized;
295 bool has_end = pcolor_end->initialized;
297 /* no need for a real pattern: */
298 if(!has_end && !has_center)
299 cairo_set_source_rgba(ctx->cr,
300 pcolor->red / 255.0,
301 pcolor->green / 255.0,
302 pcolor->blue / 255.0,
303 pcolor->alpha / 255.0);
304 else
306 pat = cairo_pattern_create_linear(gradient_vector.x,
307 gradient_vector.y,
308 gradient_vector.x + gradient_vector.x_offset,
309 gradient_vector.y + gradient_vector.y_offset);
311 /* pcolor is always set (so far in awesome) */
312 cairo_pattern_add_color_stop_rgba(pat, 0.0,
313 pcolor->red / 255.0,
314 pcolor->green / 255.0,
315 pcolor->blue / 255.0,
316 pcolor->alpha / 255.0);
318 if(has_center)
319 cairo_pattern_add_color_stop_rgba(pat, 0.5,
320 pcolor_center->red / 255.0,
321 pcolor_center->green / 255.0,
322 pcolor_center->blue / 255.0,
323 pcolor_center->alpha / 255.0);
325 if(has_end)
326 cairo_pattern_add_color_stop_rgba(pat, 1.0,
327 pcolor_end->red / 255.0,
328 pcolor_end->green / 255.0,
329 pcolor_end->blue / 255.0,
330 pcolor_end->alpha / 255.0);
331 else
332 cairo_pattern_add_color_stop_rgba(pat, 1.0,
333 pcolor->red / 255.0,
334 pcolor->green / 255.0,
335 pcolor->blue / 255.0,
336 pcolor->alpha / 255.0);
337 cairo_set_source(ctx->cr, pat);
339 return pat;
342 /** Draw rectangle inside the coordinates
343 * \param ctx Draw context
344 * \param geometry geometry
345 * \param line_width line width
346 * \param filled fill rectangle?
347 * \param color color to use
349 void
350 draw_rectangle(draw_context_t *ctx, area_t geometry,
351 float line_width, bool filled, const color_t *color)
353 cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
354 cairo_set_line_width(ctx->cr, line_width);
355 cairo_set_miter_limit(ctx->cr, 10.0);
356 cairo_set_line_join(ctx->cr, CAIRO_LINE_JOIN_MITER);
357 cairo_set_source_rgba(ctx->cr,
358 color->red / 255.0,
359 color->green / 255.0,
360 color->blue / 255.0,
361 color->alpha / 255.0);
362 if(filled)
364 cairo_rectangle(ctx->cr, geometry.x, geometry.y,
365 geometry.width, geometry.height);
366 cairo_fill(ctx->cr);
368 else
370 cairo_rectangle(ctx->cr, geometry.x + line_width / 2.0, geometry.y + line_width / 2.0,
371 geometry.width - line_width, geometry.height - line_width);
372 cairo_stroke(ctx->cr);
376 /** Draw rectangle with gradient colors
377 * \param ctx Draw context.
378 * \param geometry Geometry.
379 * \param line_width Line width.
380 * \param filled Filled rectangle?
381 * \param gradient_vector Color-gradient course.
382 * \param pcolor Color at start of gradient_vector.
383 * \param pcolor_center Color in the center.
384 * \param pcolor_end Color at end of gradient_vector.
386 void
387 draw_rectangle_gradient(draw_context_t *ctx, area_t geometry, float line_width, bool filled,
388 vector_t gradient_vector, const color_t *pcolor,
389 const color_t *pcolor_center, const color_t *pcolor_end)
391 cairo_pattern_t *pat;
393 cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
394 cairo_set_line_width(ctx->cr, line_width);
395 cairo_set_miter_limit(ctx->cr, 10.0);
396 cairo_set_line_join(ctx->cr, CAIRO_LINE_JOIN_MITER);
398 pat = draw_setup_cairo_color_source(ctx, gradient_vector, pcolor, pcolor_center, pcolor_end);
400 if(filled)
402 cairo_rectangle(ctx->cr, geometry.x, geometry.y, geometry.width, geometry.height);
403 cairo_fill(ctx->cr);
405 else
407 cairo_rectangle(ctx->cr, geometry.x + 1, geometry.y, geometry.width - 1, geometry.height - 1);
408 cairo_stroke(ctx->cr);
411 if(pat)
412 cairo_pattern_destroy(pat);
415 /** Setup some cairo-things for drawing a graph
416 * \param ctx Draw context
418 void
419 draw_graph_setup(draw_context_t *ctx)
421 cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_NONE);
422 cairo_set_line_width(ctx->cr, 1.0);
423 /* without it, it can draw over the path on sharp angles
424 * ...too long lines * (...graph_line) */
425 cairo_set_miter_limit(ctx->cr, 0.0);
426 cairo_set_line_join(ctx->cr, CAIRO_LINE_JOIN_MITER);
429 /** Draw a graph.
430 * \param ctx Draw context.
431 * \param rect The area to draw into.
432 * \param from Array of starting-point offsets to draw a graph lines.
433 * \param to Array of end-point offsets to draw a graph lines.
434 * \param cur_index Current position in data-array (cycles around).
435 * \param grow Put new values to the left or to the right.
436 * \param gradient_vector Color-Gradient course.
437 * \param pcolor Color at start of gradient_vector.
438 * \param pcolor_center Color in the center.
439 * \param pcolor_end Color at end of gradient_vector.
441 void
442 draw_graph(draw_context_t *ctx, area_t rect, int *from, int *to, int cur_index,
443 position_t grow, vector_t gradient_vector, const color_t *pcolor,
444 const color_t *pcolor_center, const color_t *pcolor_end)
446 int i = -1;
447 float x = rect.x + 0.5; /* middle of a pixel */
448 cairo_pattern_t *pat;
450 pat = draw_setup_cairo_color_source(ctx, gradient_vector,
451 pcolor, pcolor_center, pcolor_end);
453 if(grow == Right) /* draw from right to left */
455 x += rect.width - 1;
456 while(++i < rect.width)
458 cairo_move_to(ctx->cr, x, rect.y - from[cur_index]);
459 cairo_line_to(ctx->cr, x, rect.y - to[cur_index]);
460 x -= 1.0;
462 if(--cur_index < 0)
463 cur_index = rect.width - 1;
466 else /* draw from left to right */
467 while(++i < rect.width)
469 cairo_move_to(ctx->cr, x, rect.y - from[cur_index]);
470 cairo_line_to(ctx->cr, x, rect.y - to[cur_index]);
471 x += 1.0;
473 if(--cur_index < 0)
474 cur_index = rect.width - 1;
477 cairo_stroke(ctx->cr);
479 if(pat)
480 cairo_pattern_destroy(pat);
483 /** Draw a line into a graph-widget.
484 * \param ctx Draw context.
485 * \param rect The area to draw into.
486 * \param to array of offsets to draw the line through...
487 * \param cur_index current position in data-array (cycles around)
488 * \param grow put new values to the left or to the right
489 * \param gradient_vector Color-gradient course.
490 * \param pcolor Color at start of gradient_vector.
491 * \param pcolor_center Color in the center.
492 * \param pcolor_end Color at end of gradient_vector.
494 void
495 draw_graph_line(draw_context_t *ctx, area_t rect, int *to, int cur_index,
496 position_t grow, vector_t gradient_vector, const color_t *pcolor,
497 const color_t *pcolor_center, const color_t *pcolor_end)
499 int i, w;
500 float x, y;
501 cairo_pattern_t *pat;
503 /* NOTE: without, it sometimes won't draw to some path (centered in a pixel)
504 * ... it won't fill some pixels! It also looks much nicer so.
505 * (since line-drawing is the last on the graph, no need to reset to _NONE) */
506 /* Not much difference to CAIRO_ANTIALIAS_DEFAULT, but recommend for LCD */
507 cairo_set_antialias(ctx->cr, CAIRO_ANTIALIAS_SUBPIXEL);
508 /* a nicer, better visible line compared to 1.0 */
509 cairo_set_line_width(ctx->cr, 1.25);
511 pat = draw_setup_cairo_color_source(ctx, gradient_vector, pcolor, pcolor_center, pcolor_end);
513 /* path through the centers of pixels */
514 x = rect.x + 0.5;
515 y = rect.y + 0.5;
516 w = rect.width;
518 if(grow == Right)
520 /* go through the values from old to new. Begin with the oldest. */
521 if(++cur_index > w - 1)
522 cur_index = 0;
524 cairo_move_to(ctx->cr, x, y - to[cur_index]);
526 else
527 /* on the left border: fills a pixel also when there's only one value */
528 cairo_move_to(ctx->cr, x - 1.0, y - to[cur_index]);
530 for(i = 0; i < w; i++)
532 cairo_line_to(ctx->cr, x, y - to[cur_index]);
533 x += 1.0;
535 /* cycles around the index */
536 if(grow == Right)
538 if(++cur_index > w - 1)
539 cur_index = 0;
541 else
543 if(--cur_index < 0)
544 cur_index = w - 1;
548 /* onto the right border: fills a pixel also when there's only one value */
549 if(grow == Right)
550 cairo_line_to(ctx->cr, x, y - to[(cur_index + (w - 1)) % w]);
552 cairo_stroke(ctx->cr);
554 if(pat)
555 cairo_pattern_destroy(pat);
556 /* reset line-width */
557 cairo_set_line_width(ctx->cr, 1.0);
560 /** Draw an image from ARGB data to a draw context.
561 * Data should be stored as an array of alpha, red, blue, green for each pixel
562 * and the array size should be w * h elements long.
563 * \param ctx Draw context to draw to.
564 * \param x X coordinate.
565 * \param y Y coordinate.
566 * \param w Width.
567 * \param h Height.
568 * \param ratio The ratio to apply to the image.
569 * \param data The image pixels array.
571 static void
572 draw_image_from_argb_data(draw_context_t *ctx, int x, int y, int w, int h,
573 double ratio, unsigned char *data)
575 cairo_t *cr;
576 cairo_surface_t *source;
578 source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h,
579 #if CAIRO_VERSION_MAJOR < 1 || (CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR < 5) || (CAIRO_VERSION_MAJOR == 1 && CAIRO_VERSION_MINOR == 5 && CAIRO_VERSION_MICRO < 8)
580 sizeof(unsigned char) * 4 * w);
581 #else
582 cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, w));
583 #endif
584 cr = cairo_create(ctx->surface);
585 cairo_scale(cr, ratio, ratio);
586 cairo_set_source_surface(cr, source, x / ratio, y / ratio);
588 cairo_paint(cr);
590 cairo_destroy(cr);
591 cairo_surface_destroy(source);
594 /** Draw an image to a draw context.
595 * \param ctx Draw context to draw to.
596 * \param x X coordinate.
597 * \param y Y coordinate.
598 * \param ratio The ratio to apply to the image.
599 * \param image The image to draw.
601 void
602 draw_image(draw_context_t *ctx, int x, int y, double ratio, image_t *image)
604 draw_image_from_argb_data(ctx, x, y, image_getwidth(image), image_getheight(image), ratio, image_getdata(image));
607 /** Rotate a pixmap.
608 * \param ctx Draw context to draw with.
609 * \param src Drawable to draw from.
610 * \param dest Drawable to draw to.
611 * \param src_w Drawable width.
612 * \param src_h Drawable height.
613 * \param dest_w Drawable width.
614 * \param dest_h Drawable height.
615 * \param angle angle to rotate.
616 * \param tx Translate to this x coordinate.
617 * \param ty Translate to this y coordinate.
619 void
620 draw_rotate(draw_context_t *ctx,
621 xcb_pixmap_t src, xcb_pixmap_t dest,
622 int src_w, int src_h,
623 int dest_w, int dest_h,
624 double angle, int tx, int ty)
626 cairo_surface_t *surface, *source;
627 cairo_t *cr;
629 surface = cairo_xcb_surface_create(globalconf.connection, dest,
630 ctx->visual, dest_w, dest_h);
631 source = cairo_xcb_surface_create(globalconf.connection, src,
632 ctx->visual, src_w, src_h);
633 cr = cairo_create (surface);
635 cairo_translate(cr, tx, ty);
636 cairo_rotate(cr, angle);
638 cairo_set_source_surface(cr, source, 0.0, 0.0);
639 cairo_paint(cr);
641 cairo_destroy(cr);
642 cairo_surface_destroy(source);
643 cairo_surface_destroy(surface);
646 /** Return the width and height of a text in pixel.
647 * \param data The draw context text data.
648 * \return Text height and width.
650 area_t
651 draw_text_extents(draw_text_context_t *data)
653 cairo_surface_t *surface;
654 cairo_t *cr;
655 PangoLayout *layout;
656 PangoRectangle ext;
657 xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen);
658 area_t geom = { 0, 0, 0, 0 };
660 if(data->len <= 0)
661 return geom;
663 xcb_visualtype_t *visual = draw_screen_default_visual(s);
665 if(!visual)
666 fatal("no visual found");
668 surface = cairo_xcb_surface_create(globalconf.connection,
669 globalconf.default_screen,
670 visual,
671 s->width_in_pixels,
672 s->height_in_pixels);
674 cr = cairo_create(surface);
675 layout = pango_cairo_create_layout(cr);
676 pango_layout_set_text(layout, data->text, data->len);
677 pango_layout_set_attributes(layout, data->attr_list);
678 pango_layout_set_font_description(layout, globalconf.font->desc);
679 pango_layout_get_pixel_extents(layout, NULL, &ext);
680 g_object_unref(layout);
681 cairo_destroy(cr);
682 cairo_surface_destroy(surface);
684 geom.width = ext.width;
685 geom.height = ext.height;
687 return geom;
690 /** Transform a string to a alignment_t type.
691 * Recognized string are flex, fixed, left, center, middle or right.
692 * Everything else will be recognized as AlignLeft.
693 * \param align Atring with align text.
694 * \param len The string length.
695 * \return An alignment_t type.
697 alignment_t
698 draw_align_fromstr(const char *align, ssize_t len)
700 switch(a_tokenize(align, len))
702 case A_TK_CENTER: return AlignCenter;
703 case A_TK_RIGHT: return AlignRight;
704 case A_TK_FLEX: return AlignFlex;
705 case A_TK_FIXED: return AlignFixed;
706 case A_TK_TOP: return AlignTop;
707 case A_TK_BOTTOM: return AlignBottom;
708 case A_TK_MIDDLE: return AlignMiddle;
709 default: return AlignLeft;
713 /** Transform an alignment to a string.
714 * \param a The alignment.
715 * \return A string which must not be freed.
717 const char *
718 draw_align_tostr(alignment_t a)
720 switch(a)
722 case AlignLeft: return "left";
723 case AlignCenter: return "center";
724 case AlignRight: return "right";
725 case AlignFlex: return "flex";
726 case AlignFixed: return "fixed";
727 case AlignBottom: return "bottom";
728 case AlignTop: return "top";
729 case AlignMiddle: return "middle";
730 default: return NULL;
734 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80