1 /* 
    2  * ctx.h is free software; you can redistribute it and/or
    3  * modify it under the terms of the GNU Lesser General Public
    4  * License as published by the Free Software Foundation; either
    5  * version 3 of the License, or (at your option) any later version.
    6  *
    7  * ctx.h is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10  * Lesser General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Lesser General Public
   13  * License along with ctx; if not, see <https://www.gnu.org/licenses/>.
   14  *
   15  * 2012, 2015, 2019, 2020 Øyvind Kolås <pippin@gimp.org>
   16  *
   17  * ctx is a single header 2d vector graphics processing framework.
   18  *
   19  * To use ctx in a project, do the following:
   20  *
   21  * #define CTX_IMPLEMENTATION
   22  * #include "ctx.h"
   23  *
   24  * Ctx contains a minimal default fallback font with only ascii, so
   25  * you probably want to also include a font, and perhaps enable
   26  * the cairo or SDL2 optional renderers, a more complete example
   27  * could be:
   28  *
   29  * #include <cairo.h>
   30  * #include <SDL.h>
   31  * #include "ctx-font-regular.h"
   32  * #define CTX_IMPLEMENTATION
   33  * #include "ctx.h"
   34  *
   35  * The behavior of ctx can be tweaked, and features can be configured, 
   36  enabled
   37  * or disabled with other #defines, see further down in the start of this 
   38  file
   39  * for details.
   40  */
   41 
   42 #ifndef CTX_H
   43 #define CTX_H
   44 
   45 #ifdef __cplusplus
   46 extern "C" {
   47 #endif
   48 
   49 #include <stdint.h>
   50 #include <string.h>
   51 #include <stdio.h>
   52 
   53 typedef struct _Ctx            Ctx;
   54 
   55 /* The pixel formats supported as render targets
   56  */
   57 enum _CtxPixelFormat
   58 {
   59   CTX_FORMAT_NONE=0,
   60   CTX_FORMAT_GRAY8,  // 1  - these enum values are not coincidence
   61   CTX_FORMAT_GRAYA8, // 2  -
   62   CTX_FORMAT_RGB8,   // 3  -
   63   CTX_FORMAT_RGBA8,  // 4  -
   64   CTX_FORMAT_BGRA8,  // 5
   65   CTX_FORMAT_RGB565, // 6
   66   CTX_FORMAT_RGB565_BYTESWAPPED, // 7
   67   CTX_FORMAT_RGB332, // 8
   68   CTX_FORMAT_RGBAF,  // 9
   69   CTX_FORMAT_GRAYF,  // 10
   70   CTX_FORMAT_GRAYAF, // 11
   71   CTX_FORMAT_GRAY1,  //12 MONO
   72   CTX_FORMAT_GRAY2,  //13 DUO
   73   CTX_FORMAT_GRAY4,  //14
   74   CTX_FORMAT_CMYK8,  //15
   75   CTX_FORMAT_CMYKA8, //16 
   76   CTX_FORMAT_CMYKAF, //17
   77 };
   78 typedef enum   _CtxPixelFormat CtxPixelFormat;
   79 
   80 typedef struct _CtxGlyph       CtxGlyph;
   81 
   82 /**
   83  * ctx_new:
   84  *
   85  * Create a new drawing context, this context has no pixels but
   86  * accumulates commands and can be played back on other ctx
   87  * render contexts.
   88  */
   89 Ctx *ctx_new (void);
   90 
   91 /**
   92  * ctx_new_for_framebuffer:
   93  *
   94  * Create a new drawing context for a framebuffer, rendering happens
   95  * immediately.
   96  */
   97 Ctx *ctx_new_for_framebuffer (void *data,
   98                               int   width,
   99                               int   height,
  100                               int   stride,
  101                               CtxPixelFormat pixel_format);
  102 /**
  103  * ctx_new_ui:
  104  *
  105  * Create a new interactive ctx context, might depend on additional
  106  * integration.
  107  */
  108 Ctx *ctx_new_ui (int width, int height);
  109 
  110 /**
  111  * ctx_new_for_drawlist:
  112  *
  113  * Create a new drawing context for a pre-existing drawlist.
  114  */
  115 Ctx *ctx_new_for_drawlist (void *data, size_t length);
  116 
  117 
  118 /**
  119  * ctx_dirty_rect:
  120  *
  121  * Query the dirtied bounding box of drawing commands thus far.
  122  */
  123 void  ctx_dirty_rect      (Ctx *ctx, int *x, int *y, int *width, int 
  124                            *height);
  125 
  126 /**
  127  * ctx_free:
  128  * @ctx: a ctx context
  129  */
  130 void ctx_free (Ctx *ctx);
  131 
  132 /* clears and resets a context */
  133 void ctx_reset          (Ctx *ctx);
  134 void ctx_begin_path     (Ctx *ctx);
  135 void ctx_save           (Ctx *ctx);
  136 void ctx_restore        (Ctx *ctx);
  137 void ctx_start_group    (Ctx *ctx);
  138 void ctx_end_group      (Ctx *ctx);
  139 void ctx_clip           (Ctx *ctx);
  140 void ctx_identity       (Ctx *ctx);
  141 void ctx_rotate         (Ctx *ctx, float x);
  142 
  143 void ctx_image_smoothing     (Ctx *ctx, int enabled);
  144 int  ctx_get_image_smoothing (Ctx *ctx);
  145 
  146 #define CTX_LINE_WIDTH_HAIRLINE -1000.0
  147 #define CTX_LINE_WIDTH_ALIASED  -1.0
  148 #define CTX_LINE_WIDTH_FAST     -1.0  /* aliased 1px wide line */
  149 void ctx_miter_limit (Ctx *ctx, float limit);
  150 float ctx_get_miter_limit (Ctx *ctx);
  151 void ctx_line_width       (Ctx *ctx, float x);
  152 void ctx_line_dash_offset (Ctx *ctx, float line_dash);
  153 float ctx_get_line_dash_offset (Ctx *ctx);
  154 void ctx_apply_transform  (Ctx *ctx, float a,  float b,  // hscale, hskew
  155                                      float c,  float d,  // vskew,  vscale
  156                                      float e,  float f); // htran,  vtran
  157 void ctx_set_transform    (Ctx *ctx, float a, float b, float c, float d, 
  158                            float e, float f);
  159 void  ctx_line_dash       (Ctx *ctx, float *dashes, int count);
  160 void  ctx_font_size       (Ctx *ctx, float x);
  161 void  ctx_font            (Ctx *ctx, const char *font);
  162 void  ctx_font_family     (Ctx *ctx, const char *font_family);
  163 void  ctx_scale           (Ctx *ctx, float x, float y);
  164 void  ctx_translate       (Ctx *ctx, float x, float y);
  165 void  ctx_line_to         (Ctx *ctx, float x, float y);
  166 void  ctx_move_to         (Ctx *ctx, float x, float y);
  167 void  ctx_curve_to        (Ctx *ctx, float cx0, float cy0,
  168                            float cx1, float cy1,
  169                            float x, float y);
  170 void  ctx_quad_to         (Ctx *ctx, float cx, float cy,
  171                            float x, float y);
  172 void  ctx_arc             (Ctx  *ctx,
  173                            float x, float y,
  174                            float radius,
  175                            float angle1, float angle2,
  176                            int   direction);
  177 void  ctx_arc_to          (Ctx *ctx, float x1, float y1,
  178                            float x2, float y2, float radius);
  179 void  ctx_rel_arc_to      (Ctx *ctx, float x1, float y1,
  180                            float x2, float y2, float radius);
  181 void  ctx_rectangle       (Ctx *ctx,
  182                            float x0, float y0,
  183                            float w, float h);
  184 void  ctx_round_rectangle (Ctx *ctx,
  185                            float x0, float y0,
  186                            float w, float h,
  187                            float radius);
  188 void  ctx_rel_line_to     (Ctx *ctx,
  189                            float x, float y);
  190 void  ctx_rel_move_to     (Ctx *ctx,
  191                            float x, float y);
  192 void  ctx_rel_curve_to    (Ctx *ctx,
  193                            float x0, float y0,
  194                            float x1, float y1,
  195                            float x2, float y2);
  196 void  ctx_rel_quad_to     (Ctx *ctx,
  197                            float cx, float cy,
  198                            float x, float y);
  199 void  ctx_close_path      (Ctx *ctx);
  200 float ctx_get_font_size   (Ctx *ctx);
  201 const char *ctx_get_font  (Ctx *ctx);
  202 float ctx_get_line_width  (Ctx *ctx);
  203 int   ctx_width           (Ctx *ctx);
  204 int   ctx_height          (Ctx *ctx);
  205 int   ctx_rev             (Ctx *ctx);
  206 float ctx_x               (Ctx *ctx);
  207 float ctx_y               (Ctx *ctx);
  208 void  ctx_current_point   (Ctx *ctx, float *x, float *y);
  209 void  ctx_get_transform   (Ctx *ctx, float *a, float *b,
  210                            float *c, float *d,
  211                            float *e, float *f);
  212 
  213 CtxGlyph *ctx_glyph_allocate (int n_glyphs);
  214 
  215 void gtx_glyph_free       (CtxGlyph *glyphs);
  216 
  217 int  ctx_glyph            (Ctx *ctx, uint32_t unichar, int stroke);
  218 
  219 void ctx_quad_to          (Ctx *ctx, float cx, float cy,
  220                            float x, float y);
  221 
  222 void ctx_arc              (Ctx  *ctx,
  223                            float x, float y,
  224                            float radius,
  225                            float angle1, float angle2,
  226                            int   direction);
  227 
  228 void ctx_arc_to           (Ctx *ctx, float x1, float y1,
  229                            float x2, float y2, float radius);
  230 
  231 void ctx_preserve         (Ctx *ctx);
  232 void ctx_fill             (Ctx *ctx);
  233 void ctx_stroke           (Ctx *ctx);
  234 
  235 void ctx_parse            (Ctx *ctx, const char *string);
  236 
  237 void ctx_shadow_rgba      (Ctx *ctx, float r, float g, float b, float a);
  238 void ctx_shadow_blur      (Ctx *ctx, float x);
  239 void ctx_shadow_offset_x  (Ctx *ctx, float x);
  240 void ctx_shadow_offset_y  (Ctx *ctx, float y);
  241 void ctx_view_box         (Ctx *ctx,
  242                            float x0, float y0,
  243                            float w, float h);
  244 void
  245 ctx_set_pixel_u8          (Ctx *ctx, uint16_t x, uint16_t y, uint8_t r, 
  246                            uint8_t g, uint8_t b, uint8_t a);
  247 
  248 void  ctx_global_alpha     (Ctx *ctx, float global_alpha);
  249 float ctx_get_global_alpha (Ctx *ctx);
  250 
  251 void ctx_named_source (Ctx *ctx, const char *name);
  252 // followed by a color, gradient or pattern definition
  253 
  254 void ctx_rgba_stroke   (Ctx *ctx, float r, float g, float b, float a);
  255 void ctx_rgb_stroke    (Ctx *ctx, float r, float g, float b);
  256 void ctx_gray_stroke   (Ctx *ctx, float gray);
  257 void ctx_drgba_stroke  (Ctx *ctx, float r, float g, float b, float a);
  258 void ctx_cmyka_stroke  (Ctx *ctx, float c, float m, float y, float k, float 
  259                         a);
  260 void ctx_cmyk_stroke   (Ctx *ctx, float c, float m, float y, float k);
  261 void ctx_dcmyka_stroke (Ctx *ctx, float c, float m, float y, float k, float 
  262                         a);
  263 void ctx_dcmyk_stroke  (Ctx *ctx, float c, float m, float y, float k);
  264 
  265 
  266 
  267 void ctx_rgba   (Ctx *ctx, float r, float g, float b, float a);
  268 void ctx_rgb    (Ctx *ctx, float r, float g, float b);
  269 void ctx_rgba8  (Ctx *ctx, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
  270 
  271 void ctx_gray   (Ctx *ctx, float gray);
  272 void ctx_drgba  (Ctx *ctx, float r, float g, float b, float a);
  273 void ctx_cmyka  (Ctx *ctx, float c, float m, float y, float k, float a);
  274 void ctx_cmyk   (Ctx *ctx, float c, float m, float y, float k);
  275 void ctx_dcmyka (Ctx *ctx, float c, float m, float y, float k, float a);
  276 void ctx_dcmyk  (Ctx *ctx, float c, float m, float y, float k);
  277 
  278 /* there is also getters for colors, by first setting a color in one format 
  279 and getting
  280  * it with another color conversions can be done
  281  */
  282 
  283 void ctx_get_rgba   (Ctx *ctx, float *rgba);
  284 void ctx_get_graya  (Ctx *ctx, float *ya);
  285 void ctx_get_drgba  (Ctx *ctx, float *drgba);
  286 void ctx_get_cmyka  (Ctx *ctx, float *cmyka);
  287 void ctx_get_dcmyka (Ctx *ctx, float *dcmyka);
  288 int  ctx_in_fill    (Ctx *ctx, float x, float y);
  289 int  ctx_in_stroke  (Ctx *ctx, float x, float y);
  290 
  291 void ctx_linear_gradient (Ctx *ctx, float x0, float y0, float x1, float y1);
  292 void ctx_radial_gradient (Ctx *ctx, float x0, float y0, float r0,
  293                           float x1, float y1, float r1);
  294 /* XXX should be ctx_gradient_add_stop_rgba */
  295 void ctx_gradient_add_stop (Ctx *ctx, float pos, float r, float g, float b, 
  296                             float a);
  297 
  298 void ctx_gradient_add_stop_u8 (Ctx *ctx, float pos, uint8_t r, uint8_t g, 
  299                                uint8_t b, uint8_t a);
  300 
  301 
  302 /*
  303  *
  304  */
  305 void ctx_define_texture (Ctx *ctx,
  306                          const char *eid,
  307                          int         width,
  308                          int         height,
  309                          int         stride,
  310                          int         format,
  311                          void       *data,
  312                          char       *ret_eid);
  313 
  314 void
  315 ctx_get_image_data (Ctx *ctx, int sx, int sy, int sw, int sh,
  316                     CtxPixelFormat format, int dst_stride,
  317                     uint8_t *dst_data);
  318 
  319 void
  320 ctx_put_image_data (Ctx *ctx, int w, int h, int stride, int format,
  321                     uint8_t *data,
  322                     int ox, int oy,
  323                     int dirtyX, int dirtyY,
  324                     int dirtyWidth, int dirtyHeight);
  325 
  326 
  327 /* loads an image file from disk into texture, returning pixel width, 
  328 height
  329  * and eid, the eid is based on the path; not the contents - avoiding doing
  330  * sha1 checksum of contents. The width and height of the image is returned
  331  * along with the used eid, width height or eid can be NULL if we
  332  * do not care about their values.
  333  */
  334 void ctx_texture_load (Ctx        *ctx,
  335                        const char *path,
  336                        int        *width,
  337                        int        *height,
  338                        char       *eid);
  339 
  340 /* sets the paint source to be a texture by eid
  341  */
  342 void ctx_texture              (Ctx *ctx, const char *eid, float x, float y);
  343 
  344 void ctx_draw_texture         (Ctx *ctx, const char *eid, float x, float y, 
  345                                float w, float h);
  346 
  347 void ctx_draw_texture_clipped (Ctx *ctx, const char *eid, float x, float y, 
  348                                float w, float h, float sx, float sy, float 
  349                                swidth, float sheight);
  350 
  351 void ctx_draw_image           (Ctx *ctx, const char *path, float x, float y,
  352                                float w, float h);
  353 
  354 void ctx_draw_image_clipped   (Ctx *ctx, const char *path, float x, float y,
  355                                float w, float h, float sx, float sy, float 
  356                                swidth, float sheight);
  357 
  358 /* used by the render threads of fb and sdl backends.
  359  */
  360 void ctx_set_texture_source (Ctx *ctx, Ctx *texture_source);
  361 /* used when sharing cache state of eids between clients
  362  */
  363 void ctx_set_texture_cache (Ctx *ctx, Ctx *texture_cache);
  364 
  365 typedef struct _CtxDrawlist CtxDrawlist;
  366 typedef void (*CtxFullCb) (CtxDrawlist *drawlist, void *data);
  367 
  368 int ctx_pixel_format_bits_per_pixel (CtxPixelFormat format); // bits per 
  369                                      pixel
  370 int ctx_pixel_format_get_stride (CtxPixelFormat format, int width);
  371 int ctx_pixel_format_components (CtxPixelFormat format);
  372 
  373 void _ctx_set_store_clear (Ctx *ctx);
  374 void _ctx_set_transformation (Ctx *ctx, int transformation);
  375 
  376 Ctx *ctx_hasher_new (int width, int height, int cols, int rows);
  377 uint8_t *ctx_hasher_get_hash (Ctx *ctx, int col, int row);
  378 
  379 int ctx_utf8_strlen (const char *s);
  380 
  381 #ifdef _BABL_H
  382 #define CTX_BABL 1
  383 #else
  384 #define CTX_BABL 0
  385 #endif
  386 
  387 /* If cairo.h is included before ctx.h add cairo integration code
  388  */
  389 #ifdef CAIRO_H
  390 #define CTX_CAIRO 1
  391 #else
  392 #define CTX_CAIRO 0
  393 #endif
  394 
  395 #ifdef SDL_h_
  396 #define CTX_SDL 1
  397 #else
  398 #define CTX_SDL 0
  399 #endif
  400 
  401 #ifndef CTX_FB
  402 #if CTX_SDL
  403 #define CTX_FB 1
  404 #else
  405 #define CTX_FB 0
  406 #endif
  407 #endif
  408 
  409 #if CTX_SDL
  410 #define ctx_mutex_t            SDL_mutex
  411 #define ctx_create_mutex()     SDL_CreateMutex()
  412 #define ctx_lock_mutex(a)      SDL_LockMutex(a)
  413 #define ctx_unlock_mutex(a)    SDL_UnlockMutex(a)
  414 #else
  415 #define ctx_mutex_t           int
  416 #define ctx_create_mutex()    NULL
  417 #define ctx_lock_mutex(a)   
  418 #define ctx_unlock_mutex(a)  
  419 #endif
  420 
  421 #if CTX_CAIRO
  422 
  423 /* render the deferred commands of a ctx context to a cairo
  424  * context
  425  */
  426 void  ctx_render_cairo  (Ctx *ctx, cairo_t *cr);
  427 
  428 /* create a ctx context that directly renders to the specified
  429  * cairo context
  430  */
  431 Ctx * ctx_new_for_cairo (cairo_t *cr);
  432 #endif
  433 
  434 /* free with free() */
  435 char *ctx_render_string (Ctx *ctx, int longform, int *retlen);
  436 
  437 void ctx_render_stream  (Ctx *ctx, FILE *stream, int formatter);
  438 
  439 void ctx_render_ctx     (Ctx *ctx, Ctx *d_ctx);
  440 
  441 void ctx_start_move     (Ctx *ctx);
  442 
  443 
  444 int ctx_add_single      (Ctx *ctx, void *entry);
  445 
  446 uint32_t ctx_utf8_to_unichar (const char *input);
  447 int      ctx_unichar_to_utf8 (uint32_t  ch, uint8_t  *dest);
  448 
  449 
  450 typedef enum
  451 {
  452   CTX_FILL_RULE_EVEN_ODD,
  453   CTX_FILL_RULE_WINDING
  454 } CtxFillRule;
  455 
  456 typedef enum
  457 {
  458   CTX_COMPOSITE_SOURCE_OVER,
  459   CTX_COMPOSITE_COPY,
  460   CTX_COMPOSITE_SOURCE_IN,
  461   CTX_COMPOSITE_SOURCE_OUT,
  462   CTX_COMPOSITE_SOURCE_ATOP,
  463   CTX_COMPOSITE_CLEAR,
  464 
  465   CTX_COMPOSITE_DESTINATION_OVER,
  466   CTX_COMPOSITE_DESTINATION,
  467   CTX_COMPOSITE_DESTINATION_IN,
  468   CTX_COMPOSITE_DESTINATION_OUT,
  469   CTX_COMPOSITE_DESTINATION_ATOP,
  470   CTX_COMPOSITE_XOR,
  471 } CtxCompositingMode;
  472 
  473 typedef enum
  474 {
  475   CTX_BLEND_NORMAL,
  476   CTX_BLEND_MULTIPLY,
  477   CTX_BLEND_SCREEN,
  478   CTX_BLEND_OVERLAY,
  479   CTX_BLEND_DARKEN,
  480   CTX_BLEND_LIGHTEN,
  481   CTX_BLEND_COLOR_DODGE,
  482   CTX_BLEND_COLOR_BURN,
  483   CTX_BLEND_HARD_LIGHT,
  484   CTX_BLEND_SOFT_LIGHT,
  485   CTX_BLEND_DIFFERENCE,
  486   CTX_BLEND_EXCLUSION,
  487   CTX_BLEND_HUE, 
  488   CTX_BLEND_SATURATION, 
  489   CTX_BLEND_COLOR, 
  490   CTX_BLEND_LUMINOSITY,  // 15
  491   CTX_BLEND_DIVIDE,
  492   CTX_BLEND_ADDITION,
  493   CTX_BLEND_SUBTRACT,    // 18
  494 } CtxBlend;
  495 
  496 void ctx_blend_mode (Ctx *ctx, CtxBlend mode);
  497 
  498 typedef enum
  499 {
  500   CTX_JOIN_BEVEL = 0,
  501   CTX_JOIN_ROUND = 1,
  502   CTX_JOIN_MITER = 2
  503 } CtxLineJoin;
  504 
  505 typedef enum
  506 {
  507   CTX_CAP_NONE   = 0,
  508   CTX_CAP_ROUND  = 1,
  509   CTX_CAP_SQUARE = 2
  510 } CtxLineCap;
  511 
  512 typedef enum
  513 {
  514   CTX_TEXT_BASELINE_ALPHABETIC = 0,
  515   CTX_TEXT_BASELINE_TOP,
  516   CTX_TEXT_BASELINE_HANGING,
  517   CTX_TEXT_BASELINE_MIDDLE,
  518   CTX_TEXT_BASELINE_IDEOGRAPHIC,
  519   CTX_TEXT_BASELINE_BOTTOM
  520 } CtxTextBaseline;
  521 
  522 typedef enum
  523 {
  524   CTX_TEXT_ALIGN_START = 0,
  525   CTX_TEXT_ALIGN_END,
  526   CTX_TEXT_ALIGN_CENTER,
  527   CTX_TEXT_ALIGN_LEFT,
  528   CTX_TEXT_ALIGN_RIGHT
  529 } CtxTextAlign;
  530 
  531 typedef enum
  532 {
  533   CTX_TEXT_DIRECTION_INHERIT = 0,
  534   CTX_TEXT_DIRECTION_LTR,
  535   CTX_TEXT_DIRECTION_RTL
  536 } CtxTextDirection;
  537 
  538 struct
  539 _CtxGlyph
  540 {
  541   uint32_t index;
  542   float    x;
  543   float    y;
  544 };
  545 
  546 CtxTextAlign ctx_get_text_align (Ctx *ctx);
  547 CtxTextBaseline ctx_get_text_baseline (Ctx *ctx);
  548 CtxTextDirection ctx_get_text_direction (Ctx *ctx);
  549 CtxFillRule ctx_get_fill_rule (Ctx *ctx);
  550 CtxLineCap ctx_get_line_cap (Ctx *ctx);
  551 CtxLineJoin ctx_get_line_join (Ctx *ctx);
  552 CtxCompositingMode ctx_get_compositing_mode (Ctx *ctx);
  553 CtxBlend ctx_get_blend_mode (Ctx *ctx);
  554 
  555 void ctx_gradient_add_stop_string (Ctx *ctx, float pos, const char *color);
  556 
  557 void ctx_text_align           (Ctx *ctx, CtxTextAlign      align);
  558 void ctx_text_baseline        (Ctx *ctx, CtxTextBaseline   baseline);
  559 void ctx_text_direction       (Ctx *ctx, CtxTextDirection  direction);
  560 void ctx_fill_rule            (Ctx *ctx, CtxFillRule       fill_rule);
  561 void ctx_line_cap             (Ctx *ctx, CtxLineCap        cap);
  562 void ctx_line_join            (Ctx *ctx, CtxLineJoin       join);
  563 void ctx_compositing_mode     (Ctx *ctx, CtxCompositingMode mode);
  564 int  ctx_set_drawlist     (Ctx *ctx, void *data, int length);
  565 typedef struct _CtxEntry CtxEntry;
  566 /* we only care about the tight packing for this specific
  567  * struct as we do indexing across members in arrays of it,
  568  * to make sure its size becomes 9bytes -
  569  * the pack pragma is also sufficient on recent gcc versions
  570  */
  571 #pragma pack(push,1)
  572 struct
  573   _CtxEntry
  574 {
  575   uint8_t code;
  576   union
  577   {
  578     float    f[2];
  579     uint8_t  u8[8];
  580     int8_t   s8[8];
  581     uint16_t u16[4];
  582     int16_t  s16[4];
  583     uint32_t u32[2];
  584     int32_t  s32[2];
  585     uint64_t u64[1]; // unused
  586   } data; // 9bytes long, we're favoring compactness and correctness
  587   // over performance. By sacrificing float precision, zeroing
  588   // first 8bit of f[0] would permit 8bytes long and better
  589   // aglinment and cacheline behavior.
  590 };
  591 #pragma pack(pop)
  592 const CtxEntry *ctx_get_drawlist (Ctx *ctx);
  593 int  ctx_append_drawlist  (Ctx *ctx, void *data, int length);
  594 
  595 /* these are only needed for clients rendering text, as all text gets
  596  * converted to paths.
  597  */
  598 void  ctx_glyphs        (Ctx        *ctx,
  599                          CtxGlyph   *glyphs,
  600                          int         n_glyphs);
  601 
  602 void  ctx_glyphs_stroke (Ctx       *ctx,
  603                          CtxGlyph   *glyphs,
  604                          int         n_glyphs);
  605 
  606 void  ctx_text          (Ctx        *ctx,
  607                          const char *string);
  608 void  ctx_text_stroke   (Ctx        *ctx,
  609                          const char *string);
  610 
  611 void  ctx_fill_text     (Ctx        *ctx,
  612                          const char *string,
  613                          float       x,
  614                          float       y);
  615 
  616 void  ctx_stroke_text   (Ctx        *ctx,
  617                          const char *string,
  618                          float       x,
  619                          float       y);
  620 
  621 /* returns the total horizontal advance if string had been rendered */
  622 float ctx_text_width    (Ctx        *ctx,
  623                          const char *string);
  624 
  625 float ctx_glyph_width   (Ctx *ctx, int unichar);
  626 
  627 int   ctx_load_font_ttf (const char *name, const void *ttf_contents, int 
  628                          length);
  629 
  630 
  631 
  632 enum _CtxModifierState
  633 {
  634   CTX_MODIFIER_STATE_SHIFT   = (1<<0),
  635   CTX_MODIFIER_STATE_CONTROL = (1<<1),
  636   CTX_MODIFIER_STATE_ALT     = (1<<2),
  637   CTX_MODIFIER_STATE_BUTTON1 = (1<<3),
  638   CTX_MODIFIER_STATE_BUTTON2 = (1<<4),
  639   CTX_MODIFIER_STATE_BUTTON3 = (1<<5),
  640   CTX_MODIFIER_STATE_DRAG    = (1<<6), // pointer button is down (0 or any)
  641 };
  642 typedef enum _CtxModifierState CtxModifierState;
  643 
  644 enum _CtxScrollDirection
  645 {
  646   CTX_SCROLL_DIRECTION_UP,
  647   CTX_SCROLL_DIRECTION_DOWN,
  648   CTX_SCROLL_DIRECTION_LEFT,
  649   CTX_SCROLL_DIRECTION_RIGHT
  650 };
  651 typedef enum _CtxScrollDirection CtxScrollDirection;
  652 
  653 typedef struct _CtxEvent CtxEvent;
  654 
  655 void ctx_set_renderer (Ctx *ctx,
  656                        void *renderer);
  657 void *ctx_get_renderer (Ctx *ctx);
  658 
  659 int ctx_renderer_is_sdl (Ctx *ctx);
  660 int ctx_renderer_is_fb (Ctx *ctx);
  661 int ctx_renderer_is_ctx (Ctx *ctx);
  662 int ctx_renderer_is_braille (Ctx *ctx);
  663 
  664 /* the following API is only available when CTX_EVENTS is defined to 1
  665  *
  666  * it provides the ability to register callbacks with the current path
  667  * that get delivered with transformed coordinates.
  668  */
  669 unsigned long ctx_ticks (void);
  670 int ctx_is_dirty (Ctx *ctx);
  671 void ctx_set_dirty (Ctx *ctx, int dirty);
  672 float ctx_get_float (Ctx *ctx, uint64_t hash);
  673 void ctx_set_float (Ctx *ctx, uint64_t hash, float value);
  674 
  675 unsigned long ctx_ticks (void);
  676 void ctx_flush (Ctx *ctx);
  677 
  678 void ctx_set_clipboard (Ctx *ctx, const char *text);
  679 char *ctx_get_clipboard (Ctx *ctx);
  680 
  681 void _ctx_events_init     (Ctx *ctx);
  682 typedef struct _CtxIntRectangle CtxIntRectangle;
  683 struct _CtxIntRectangle {
  684   int x;
  685   int y;
  686   int width;
  687   int height;
  688 };
  689 
  690 void ctx_quit (Ctx *ctx);
  691 int  ctx_has_quit (Ctx *ctx);
  692 
  693 typedef void (*CtxCb) (CtxEvent *event,
  694                        void     *data,
  695                        void     *data2);
  696 typedef void (*CtxDestroyNotify) (void *data);
  697 
  698 enum _CtxEventType {
  699   CTX_PRESS        = 1 << 0,
  700   CTX_MOTION       = 1 << 1,
  701   CTX_RELEASE      = 1 << 2,
  702   CTX_ENTER        = 1 << 3,
  703   CTX_LEAVE        = 1 << 4,
  704   CTX_TAP          = 1 << 5,
  705   CTX_TAP_AND_HOLD = 1 << 6,
  706 
  707   /* NYI: SWIPE, ZOOM ROT_ZOOM, */
  708 
  709   CTX_DRAG_PRESS   = 1 << 7,
  710   CTX_DRAG_MOTION  = 1 << 8,
  711   CTX_DRAG_RELEASE = 1 << 9,
  712   CTX_KEY_PRESS    = 1 << 10,
  713   CTX_KEY_DOWN     = 1 << 11,
  714   CTX_KEY_UP       = 1 << 12,
  715   CTX_SCROLL       = 1 << 13,
  716   CTX_MESSAGE      = 1 << 14,
  717   CTX_DROP         = 1 << 15,
  718 
  719   CTX_SET_CURSOR   = 1 << 16, // used internally
  720 
  721   /* client should store state - preparing
  722                                  * for restart
  723                                  */
  724   CTX_POINTER  = (CTX_PRESS | CTX_MOTION | CTX_RELEASE | CTX_DROP),
  725   CTX_TAPS     = (CTX_TAP | CTX_TAP_AND_HOLD),
  726   CTX_CROSSING = (CTX_ENTER | CTX_LEAVE),
  727   CTX_DRAG     = (CTX_DRAG_PRESS | CTX_DRAG_MOTION | CTX_DRAG_RELEASE),
  728   CTX_KEY      = (CTX_KEY_DOWN | CTX_KEY_UP | CTX_KEY_PRESS),
  729   CTX_MISC     = (CTX_MESSAGE),
  730   CTX_ANY      = (CTX_POINTER | CTX_DRAG | CTX_CROSSING | CTX_KEY | 
  731                  CTX_MISC | CTX_TAPS),
  732 };
  733 typedef enum _CtxEventType CtxEventType;
  734 
  735 #define CTX_CLICK   CTX_PRESS   // SHOULD HAVE MORE LOGIC
  736 
  737 struct _CtxEvent {
  738   CtxEventType  type;
  739   uint32_t time;
  740   Ctx     *ctx;
  741   int stop_propagate; /* when set - propagation is stopped */
  742 
  743   CtxModifierState state;
  744 
  745   int     device_no; /* 0 = left mouse button / virtual focus */
  746                      /* 1 = middle mouse button */
  747                      /* 2 = right mouse button */
  748                      /* 3 = first multi-touch .. (NYI) */
  749 
  750   float   device_x; /* untransformed (device) coordinates  */
  751   float   device_y;
  752 
  753   /* coordinates; and deltas for motion/drag events in user-coordinates: */
  754   float   x;
  755   float   y;
  756   float   start_x; /* start-coordinates (press) event for drag, */
  757   float   start_y; /*    untransformed coordinates */
  758   float   prev_x;  /* previous events coordinates */
  759   float   prev_y;
  760   float   delta_x; /* x - prev_x, redundant - but often useful */
  761   float   delta_y; /* y - prev_y, redundant - ..  */
  762 
  763 
  764   unsigned int unicode; /* only valid for key-events, re-use as keycode? */
  765   const char *string;   /* as key can be "up" "down" "space" "backspace" 
  766   "a" "b" "ø" etc .. */
  767                         /* this is also where the message is delivered for
  768                          * MESSAGE events
  769                          *
  770                          * and the data for drop events are delivered
  771                          */
  772   CtxScrollDirection scroll_direction;
  773 
  774 
  775   // would be nice to add the bounding box of the hit-area causing
  776   // the event, making for instance scissored enter/leave repaint easier.
  777 };
  778 
  779 // layer-event "layer"  motion x y device_no 
  780 
  781 void ctx_add_key_binding_full (Ctx *ctx,
  782                                const char *key,
  783                                const char *action,
  784                                const char *label,
  785                                CtxCb       cb,
  786                                void       *cb_data,
  787                                CtxDestroyNotify destroy_notify,
  788                                void       *destroy_data);
  789 void ctx_add_key_binding (Ctx *ctx,
  790                           const char *key,
  791                           const char *action,
  792                           const char *label,
  793                           CtxCb cb,
  794                           void  *cb_data);
  795 typedef struct CtxBinding {
  796   char *nick;
  797   char *command;
  798   char *label;
  799   CtxCb cb;
  800   void *cb_data;
  801   CtxDestroyNotify destroy_notify;
  802   void  *destroy_data;
  803 } CtxBinding;
  804 CtxBinding *ctx_get_bindings (Ctx *ctx);
  805 void  ctx_clear_bindings     (Ctx *ctx);
  806 void  ctx_remove_idle        (Ctx *ctx, int handle);
  807 int   ctx_add_timeout_full   (Ctx *ctx, int ms, int (*idle_cb)(Ctx *ctx, 
  808                               void *idle_data), void *idle_data,
  809                               void (*destroy_notify)(void *destroy_data), 
  810                                     void *destroy_data);
  811 int   ctx_add_timeout        (Ctx *ctx, int ms, int (*idle_cb)(Ctx *ctx, 
  812                               void *idle_data), void *idle_data);
  813 int   ctx_add_idle_full      (Ctx *ctx, int (*idle_cb)(Ctx *ctx, void 
  814                               *idle_data), void *idle_data,
  815                               void (*destroy_notify)(void *destroy_data), 
  816                                     void *destroy_data);
  817 int   ctx_add_idle           (Ctx *ctx, int (*idle_cb)(Ctx *ctx, void 
  818                               *idle_data), void *idle_data);
  819 
  820 
  821 void ctx_add_hit_region (Ctx *ctx, const char *id);
  822 
  823 void ctx_set_title (Ctx *ctx, const char *title);
  824 
  825 void ctx_listen_full (Ctx     *ctx,
  826                       float    x,
  827                       float    y,
  828                       float    width,
  829                       float    height,
  830                       CtxEventType  types,
  831                       CtxCb    cb,
  832                       void    *data1,
  833                       void    *data2,
  834                       void   (*finalize)(void *listen_data, void 
  835                               *listen_data2,
  836                                          void *finalize_data),
  837                       void    *finalize_data);
  838 void  ctx_event_stop_propagate (CtxEvent *event);
  839 void  ctx_listen               (Ctx          *ctx,
  840                                 CtxEventType  types,
  841                                 CtxCb         cb,
  842                                 void*         data1,
  843                                 void*         data2);
  844 void  ctx_listen_with_finalize (Ctx          *ctx,
  845                                 CtxEventType  types,
  846                                 CtxCb         cb,
  847                                 void*         data1,
  848                                 void*         data2,
  849                       void   (*finalize)(void *listen_data, void 
  850                               *listen_data2,
  851                                          void *finalize_data),
  852                       void    *finalize_data);
  853 
  854 void ctx_init (int *argc, char ***argv); // is a no-op but could launch
  855                                          // terminal
  856 CtxEvent *ctx_get_event (Ctx *ctx);
  857 
  858 int   ctx_pointer_is_down (Ctx *ctx, int no);
  859 float ctx_pointer_x (Ctx *ctx);
  860 float ctx_pointer_y (Ctx *ctx);
  861 void  ctx_freeze (Ctx *ctx);
  862 void  ctx_thaw   (Ctx *ctx);
  863 int   ctx_events_frozen (Ctx *ctx);
  864 void  ctx_events_clear_items (Ctx *ctx);
  865 int   ctx_events_width (Ctx *ctx);
  866 int   ctx_events_height (Ctx *ctx);
  867 
  868 /* The following functions drive the event delivery, registered callbacks
  869  * are called in response to these being called.
  870  */
  871 
  872 int ctx_key_down  (Ctx *ctx, unsigned int keyval,
  873                    const char *string, uint32_t time);
  874 int ctx_key_up    (Ctx *ctx, unsigned int keyval,
  875                    const char *string, uint32_t time);
  876 int ctx_key_press (Ctx *ctx, unsigned int keyval,
  877                    const char *string, uint32_t time);
  878 
  879 
  880 int ctx_scrolled  (Ctx *ctx, float x, float y, CtxScrollDirection 
  881                    scroll_direction, uint32_t time);
  882 void ctx_incoming_message (Ctx *ctx, const char *message, long time);
  883 int ctx_pointer_motion    (Ctx *ctx, float x, float y, int device_no, 
  884                            uint32_t time);
  885 int ctx_pointer_release   (Ctx *ctx, float x, float y, int device_no, 
  886                            uint32_t time);
  887 int ctx_pointer_press     (Ctx *ctx, float x, float y, int device_no, 
  888                            uint32_t time);
  889 int ctx_pointer_drop      (Ctx *ctx, float x, float y, int device_no, 
  890                            uint32_t time,
  891                            char *string);
  892 
  893 typedef enum
  894 {
  895   CTX_CONT             = '\0', // - contains args from preceding entry
  896   CTX_NOP              = ' ', //
  897   CTX_DATA             = '(', // size size-in-entries - u32
  898   CTX_DATA_REV         = ')', // reverse traversal data marker
  899   CTX_SET_RGBA_U8      = '*', // r g b a - u8
  900   CTX_NEW_EDGE         = '+', // x0 y0 x1 y1 - s16
  901   // set pixel might want a shorter ascii form? or keep it an embedded
  902   // only option?
  903   CTX_SET_PIXEL        = '-', // 8bit "fast-path" r g b a x y - u8 for rgba,
  904                          and u16 for x,y
  905   /* optimizations that reduce the number of entries used,
  906    * not visible outside the drawlist compression, thus
  907    * using entries that cannot be used directly as commands
  908    * since they would be interpreted as numbers - if values>127
  909    * then the embedded font data is harder to escape.
  910    */
  911   CTX_REL_LINE_TO_X4            = '0', // x1 y1 x2 y2 x3 y3 x4 y4   -- s8
  912   CTX_REL_LINE_TO_REL_CURVE_TO  = '1', // x1 y1 cx1 cy1 cx2 cy2 x y -- s8
  913   CTX_REL_CURVE_TO_REL_LINE_TO  = '2', // cx1 cy1 cx2 cy2 x y x1 y1 -- s8
  914   CTX_REL_CURVE_TO_REL_MOVE_TO  = '3', // cx1 cy1 cx2 cy2 x y x1 y1 -- s8
  915   CTX_REL_LINE_TO_X2            = '4', // x1 y1 x2 y2 -- s16
  916   CTX_MOVE_TO_REL_LINE_TO       = '5', // x1 y1 x2 y2 -- s16
  917   CTX_REL_LINE_TO_REL_MOVE_TO   = '6', // x1 y1 x2 y2 -- s16
  918   CTX_FILL_MOVE_TO              = '7', // x y
  919   CTX_REL_QUAD_TO_REL_QUAD_TO   = '8', // cx1 x1 cy1 y1 cx1 x2 cy1 y1 -- s8
  920   CTX_REL_QUAD_TO_S16           = '9', // cx1 cy1 x y                 - s16
  921   // expand with: . : 
  922   CTX_FLUSH            = ';',
  923 
  924   CTX_DEFINE_GLYPH     = '@', // unichar width - u32
  925   CTX_ARC_TO           = 'A', // x1 y1 x2 y2 radius
  926   CTX_ARC              = 'B', // x y radius angle1 angle2 direction
  927   CTX_CURVE_TO         = 'C', // cx1 cy1 cx2 cy2 x y
  928   CTX_STROKE           = 'E', //
  929   CTX_FILL             = 'F', //
  930   CTX_RESTORE          = 'G', //
  931   CTX_HOR_LINE_TO      = 'H', // x
  932   CTX_DEFINE_TEXTURE   = 'I', // "eid" width height format "data"
  933   CTX_ROTATE           = 'J', // radians
  934   CTX_COLOR            = 'K', // model, c1 c2 c3 ca - has a variable set of
  935   // arguments.
  936   CTX_LINE_TO          = 'L', // x y
  937   CTX_MOVE_TO          = 'M', // x y
  938   CTX_BEGIN_PATH       = 'N', //
  939   CTX_SCALE            = 'O', // xscale yscale
  940   CTX_NEW_PAGE         = 'P', // - NYI - optional page-size
  941   CTX_QUAD_TO          = 'Q', // cx cy x y
  942   CTX_VIEW_BOX         = 'R', // x y width height
  943   CTX_SMOOTH_TO        = 'S', // cx cy x y
  944   CTX_SMOOTHQ_TO       = 'T', // x y
  945   CTX_RESET            = 'U', //
  946   CTX_VER_LINE_TO      = 'V', // y
  947   CTX_APPLY_TRANSFORM  = 'W', // a b c d e f - for set_transform combine 
  948                          with identity
  949   CTX_EXIT             = 'X', //
  950   CTX_ROUND_RECTANGLE  = 'Y', // x y width height radius
  951 
  952   CTX_CLOSE_PATH2      = 'Z', //
  953   CTX_KERNING_PAIR     = '[', // glA glB kerning, glA and glB in u16 
  954                          kerning in s32
  955   CTX_COLOR_SPACE      = ']', // IccSlot  data  data_len,
  956                          //    data can be a string with a name,
  957                          //    icc data or perhaps our own serialization
  958                          //    of profile data
  959   CTX_EDGE_FLIPPED     = '`', // x0 y0 x1 y1 - s16
  960   CTX_REL_ARC_TO       = 'a', // x1 y1 x2 y2 radius
  961   CTX_CLIP             = 'b',
  962   CTX_REL_CURVE_TO     = 'c', // cx1 cy1 cx2 cy2 x y
  963   CTX_LINE_DASH        = 'd', // dashlen0 [dashlen1 ...]
  964   CTX_TRANSLATE        = 'e', // x y
  965   CTX_LINEAR_GRADIENT  = 'f', // x1 y1 x2 y2
  966   CTX_SAVE             = 'g',
  967   CTX_REL_HOR_LINE_TO  = 'h', // x
  968   CTX_TEXTURE          = 'i',
  969   CTX_PRESERVE         = 'j', // 
  970   CTX_SET_KEY          = 'k', // - used together with another char to 
  971                          identify
  972                               //   a key to set
  973   CTX_REL_LINE_TO      = 'l', // x y
  974   CTX_REL_MOVE_TO      = 'm', // x y
  975   CTX_FONT             = 'n', // as used by text parser
  976   CTX_RADIAL_GRADIENT  = 'o', // x1 y1 radius1 x2 y2 radius2
  977   CTX_GRADIENT_STOP    = 'p', // argument count depends on current color 
  978                          model
  979   CTX_REL_QUAD_TO      = 'q', // cx cy x y
  980   CTX_RECTANGLE        = 'r', // x y width height
  981   CTX_REL_SMOOTH_TO    = 's', // cx cy x y
  982   CTX_REL_SMOOTHQ_TO   = 't', // x y
  983   CTX_STROKE_TEXT      = 'u', // string - utf8 string
  984   CTX_REL_VER_LINE_TO  = 'v', // y
  985   CTX_GLYPH            = 'w', // unichar fontsize
  986   CTX_TEXT             = 'x', // string | kern - utf8 data to shape or 
  987                          horizontal kerning amount
  988   CTX_IDENTITY         = 'y', //
  989   CTX_CLOSE_PATH       = 'z', //
  990   CTX_START_GROUP      = '{',
  991   CTX_END_GROUP        = '}',
  992   CTX_EDGE             = ',',
  993 
  994   /* though expressed as two chars in serialization we have
  995    * dedicated byte commands for the setters to keep the dispatch
  996    * simpler. There is no need for these to be human readable thus we go >
  997    128
  998    *
  999    * unused/reserved: D!&<=>?#:.^_=/~%\'"
 1000    *
 1001    */
 1002   CTX_FILL_RULE        = 128, // kr rule - u8, default = 
 1003                          CTX_FILLE_RULE_EVEN_ODD
 1004   CTX_BLEND_MODE       = 129, // kB mode - u8 , default=0
 1005 
 1006   CTX_MITER_LIMIT      = 130, // km limit - float, default = 0.0
 1007 
 1008   CTX_LINE_JOIN        = 131, // kj join - u8 , default=0
 1009   CTX_LINE_CAP         = 132, // kc cap - u8, default = 0
 1010   CTX_LINE_WIDTH       = 133, // kw width, default = 2.0
 1011   CTX_GLOBAL_ALPHA     = 134, // ka alpha - default=1.0
 1012   CTX_COMPOSITING_MODE = 135, // kc mode - u8 , default=0
 1013 
 1014   CTX_FONT_SIZE        = 136, // kf size - float, default=?
 1015   CTX_TEXT_ALIGN       = 137, // kt align - u8, default = 
 1016                          CTX_TEXT_ALIGN_START
 1017   CTX_TEXT_BASELINE    = 138, // kb baseline - u8, default = 
 1018                          CTX_TEXT_ALIGN_ALPHABETIC
 1019   CTX_TEXT_DIRECTION   = 139, // kd
 1020 
 1021   CTX_SHADOW_BLUR      = 140, // ks
 1022   CTX_SHADOW_COLOR     = 141, // kC
 1023   CTX_SHADOW_OFFSET_X  = 142, // kx
 1024   CTX_SHADOW_OFFSET_Y  = 143, // ky
 1025   CTX_IMAGE_SMOOTHING  = 144, // kS
 1026   CTX_LINE_DASH_OFFSET = 145, // kD lineDashOffset
 1027   // items marked with % are currently only for the parser
 1028   // for instance for svg compatibility or simulated/converted color spaces
 1029   // not the serialization/internal render stream
 1030   //
 1031   CTX_STROKE_RECT      = 200, // strokeRect - only exist in long form
 1032   CTX_FILL_RECT        = 201, // fillRect   - only exist in long form
 1033 } CtxCode;
 1034 
 1035 
 1036 #pragma pack(push,1)
 1037 
 1038 typedef struct _CtxCommand CtxCommand;
 1039 typedef struct _CtxIterator CtxIterator;
 1040 
 1041 CtxIterator *
 1042 ctx_current_path (Ctx *ctx);
 1043 void
 1044 ctx_path_extents (Ctx *ctx, float *ex1, float *ey1, float *ex2, float *ey2);
 1045 
 1046 #define CTX_ASSERT               0
 1047 
 1048 #if CTX_ASSERT==1
 1049 #define ctx_assert(a)  if(!(a)){fprintf(stderr,"%s:%i assertion failed\n", 
 1050                    __FUNCTION__, __LINE__);  }
 1051 #else
 1052 #define ctx_assert(a)
 1053 #endif
 1054 
 1055 int ctx_get_drawlist_count (Ctx *ctx);
 1056 
 1057 struct
 1058   _CtxCommand
 1059 {
 1060   union
 1061   {
 1062     uint8_t  code;
 1063     CtxEntry entry;
 1064     struct
 1065     {
 1066       uint8_t code;
 1067       float scalex;
 1068       float scaley;
 1069     } scale;
 1070     struct
 1071     {
 1072       uint8_t code;
 1073       uint32_t stringlen;
 1074       uint32_t blocklen;
 1075       uint8_t cont;
 1076       uint8_t data[8]; /* ... and continues */
 1077     } data;
 1078     struct
 1079     {
 1080       uint8_t code;
 1081       uint32_t stringlen;
 1082       uint32_t blocklen;
 1083     } data_rev;
 1084     struct
 1085     {
 1086       uint8_t code;
 1087       float pad;
 1088       float pad2;
 1089       uint8_t code_data;
 1090       uint32_t stringlen;
 1091       uint32_t blocklen;
 1092       uint8_t code_cont;
 1093       uint8_t utf8[8]; /* .. and continues */
 1094     } text;
 1095     struct
 1096     {
 1097       uint8_t  code;
 1098       uint32_t key_hash;
 1099       float    pad;
 1100       uint8_t  code_data;
 1101       uint32_t stringlen;
 1102       uint32_t blocklen;
 1103       uint8_t  code_cont;
 1104       uint8_t  utf8[8]; /* .. and continues */
 1105     } set;
 1106     struct
 1107     {
 1108       uint8_t  code;
 1109       uint32_t pad0;
 1110       float    pad1;
 1111       uint8_t  code_data;
 1112       uint32_t stringlen;
 1113       uint32_t blocklen;
 1114       uint8_t  code_cont;
 1115       uint8_t  utf8[8]; /* .. and continues */
 1116     } get;
 1117     struct {
 1118       uint8_t  code;
 1119       uint32_t count; /* better than byte_len in code, but needs to then be 
 1120       set   */
 1121       float    pad1;
 1122       uint8_t  code_data;
 1123       uint32_t byte_len;
 1124       uint32_t blocklen;
 1125       uint8_t  code_cont;
 1126       float    data[2]; /* .. and - possibly continues */
 1127     } line_dash;
 1128     struct {
 1129       uint8_t  code;
 1130       uint32_t space_slot;
 1131       float    pad1;
 1132       uint8_t  code_data;
 1133       uint32_t data_len;
 1134       uint32_t blocklen;
 1135       uint8_t  code_cont;
 1136       uint8_t  data[8]; /* .. and continues */
 1137     } colorspace;
 1138     struct
 1139     {
 1140       uint8_t  code;
 1141       float    x;
 1142       float    y;
 1143       uint8_t  code_data;
 1144       uint32_t stringlen;
 1145       uint32_t blocklen;
 1146       uint8_t  code_cont;
 1147       char     eid[8]; /* .. and continues */
 1148     } texture;
 1149     struct
 1150     {
 1151       uint8_t  code;
 1152       uint32_t width;
 1153       uint32_t height;
 1154       uint8_t  code_cont0;
 1155       uint16_t format;
 1156       uint16_t pad0;
 1157       uint32_t pad1;
 1158       uint8_t  code_data;
 1159       uint32_t stringlen;
 1160       uint32_t blocklen;
 1161       uint8_t  code_cont1;
 1162       char     eid[8]; /* .. and continues */
 1163       // followed by - in variable offset code_Data, data_len, 
 1164       datablock_len, cont, pixeldata
 1165     } define_texture;
 1166     struct
 1167     {
 1168       uint8_t  code;
 1169       float    pad;
 1170       float    pad2;
 1171       uint8_t  code_data;
 1172       uint32_t stringlen;
 1173       uint32_t blocklen;
 1174       uint8_t  code_cont;
 1175       uint8_t  utf8[8]; /* .. and continues */
 1176     } text_stroke;
 1177     struct
 1178     {
 1179       uint8_t  code;
 1180       float    pad;
 1181       float    pad2;
 1182       uint8_t  code_data;
 1183       uint32_t stringlen;
 1184       uint32_t blocklen;
 1185       uint8_t  code_cont;
 1186       uint8_t  utf8[8]; /* .. and continues */
 1187     } set_font;
 1188     struct
 1189     {
 1190       uint8_t code;
 1191       float model;
 1192       float r;
 1193       uint8_t pad1;
 1194       float g;
 1195       float b;
 1196       uint8_t pad2;
 1197       float a;
 1198     } rgba;
 1199     struct
 1200     {
 1201       uint8_t code;
 1202       float model;
 1203       float c;
 1204       uint8_t pad1;
 1205       float m;
 1206       float y;
 1207       uint8_t pad2;
 1208       float k;
 1209       float a;
 1210     } cmyka;
 1211     struct
 1212     {
 1213       uint8_t code;
 1214       float model;
 1215       float g;
 1216       uint8_t pad1;
 1217       float a;
 1218     } graya;
 1219     struct
 1220     {
 1221       uint8_t code;
 1222       float model;
 1223       float c0;
 1224       uint8_t pad1;
 1225       float c1;
 1226       float c2;
 1227       uint8_t pad2;
 1228       float c3;
 1229       float c4;
 1230       uint8_t pad3;
 1231       float c5;
 1232       float c6;
 1233       uint8_t pad4;
 1234       float c7;
 1235       float c8;
 1236       uint8_t pad5;
 1237       float c9;
 1238       float c10;
 1239     } set_color;
 1240     struct
 1241     {
 1242       uint8_t code;
 1243       float x;
 1244       float y;
 1245     } rel_move_to;
 1246     struct
 1247     {
 1248       uint8_t code;
 1249       float x;
 1250       float y;
 1251     } rel_line_to;
 1252     struct
 1253     {
 1254       uint8_t code;
 1255       float x;
 1256       float y;
 1257     } line_to;
 1258     struct
 1259     {
 1260       uint8_t code;
 1261       float cx1;
 1262       float cy1;
 1263       uint8_t pad0;
 1264       float cx2;
 1265       float cy2;
 1266       uint8_t pad1;
 1267       float x;
 1268       float y;
 1269     } rel_curve_to;
 1270     struct
 1271     {
 1272       uint8_t code;
 1273       float x;
 1274       float y;
 1275     } move_to;
 1276     struct
 1277     {
 1278       uint8_t code;
 1279       float cx1;
 1280       float cy1;
 1281       uint8_t pad0;
 1282       float cx2;
 1283       float cy2;
 1284       uint8_t pad1;
 1285       float x;
 1286       float y;
 1287     } curve_to;
 1288     struct
 1289     {
 1290       uint8_t code;
 1291       float x1;
 1292       float y1;
 1293       uint8_t pad0;
 1294       float r1;
 1295       float x2;
 1296       uint8_t pad1;
 1297       float y2;
 1298       float r2;
 1299     } radial_gradient;
 1300     struct
 1301     {
 1302       uint8_t code;
 1303       float x1;
 1304       float y1;
 1305       uint8_t pad0;
 1306       float x2;
 1307       float y2;
 1308     } linear_gradient;
 1309     struct
 1310     {
 1311       uint8_t code;
 1312       float x;
 1313       float y;
 1314       uint8_t pad0;
 1315       float width;
 1316       float height;
 1317       uint8_t pad1;
 1318       float radius;
 1319     } rectangle;
 1320     struct {
 1321       uint8_t code;
 1322       float x;
 1323       float y;
 1324       uint8_t pad0;
 1325       float width;
 1326       float height;
 1327     } view_box;
 1328 
 1329     struct
 1330     {
 1331       uint8_t code;
 1332       uint16_t glyph_before;
 1333       uint16_t glyph_after;
 1334        int32_t amount;
 1335     } kern;
 1336 
 1337     struct
 1338     {
 1339       uint8_t code;
 1340       uint32_t glyph;
 1341       uint32_t advance; // * 256
 1342     } define_glyph;
 1343 
 1344     struct
 1345     {
 1346       uint8_t code;
 1347       uint8_t rgba[4];
 1348       uint16_t x;
 1349       uint16_t y;
 1350     } set_pixel;
 1351     struct
 1352     {
 1353       uint8_t code;
 1354       float cx;
 1355       float cy;
 1356       uint8_t pad0;
 1357       float x;
 1358       float y;
 1359     } quad_to;
 1360     struct
 1361     {
 1362       uint8_t code;
 1363       float cx;
 1364       float cy;
 1365       uint8_t pad0;
 1366       float x;
 1367       float y;
 1368     } rel_quad_to;
 1369     struct
 1370     {
 1371       uint8_t code;
 1372       float x;
 1373       float y;
 1374       uint8_t pad0;
 1375       float radius;
 1376       float angle1;
 1377       uint8_t pad1;
 1378       float angle2;
 1379       float direction;
 1380     }
 1381     arc;
 1382     struct
 1383     {
 1384       uint8_t code;
 1385       float x1;
 1386       float y1;
 1387       uint8_t pad0;
 1388       float x2;
 1389       float y2;
 1390       uint8_t pad1;
 1391       float radius;
 1392     }
 1393     arc_to;
 1394     /* some format specific generic accesors:  */
 1395     struct
 1396     {
 1397       uint8_t code;
 1398       float   x0;
 1399       float   y0;
 1400       uint8_t pad0;
 1401       float   x1;
 1402       float   y1;
 1403       uint8_t pad1;
 1404       float   x2;
 1405       float   y2;
 1406       uint8_t pad2;
 1407       float   x3;
 1408       float   y3;
 1409       uint8_t pad3;
 1410       float   x4;
 1411       float   y4;
 1412     } c;
 1413     struct
 1414     {
 1415       uint8_t code;
 1416       float   a0;
 1417       float   a1;
 1418       uint8_t pad0;
 1419       float   a2;
 1420       float   a3;
 1421       uint8_t pad1;
 1422       float   a4;
 1423       float   a5;
 1424       uint8_t pad2;
 1425       float   a6;
 1426       float   a7;
 1427       uint8_t pad3;
 1428       float   a8;
 1429       float   a9;
 1430     } f;
 1431     struct
 1432     {
 1433       uint8_t  code;
 1434       uint32_t a0;
 1435       uint32_t a1;
 1436       uint8_t  pad0;
 1437       uint32_t a2;
 1438       uint32_t a3;
 1439       uint8_t  pad1;
 1440       uint32_t a4;
 1441       uint32_t a5;
 1442       uint8_t  pad2;
 1443       uint32_t a6;
 1444       uint32_t a7;
 1445       uint8_t  pad3;
 1446       uint32_t a8;
 1447       uint32_t a9;
 1448     } u32;
 1449     struct
 1450     {
 1451       uint8_t  code;
 1452       uint64_t a0;
 1453       uint8_t  pad0;
 1454       uint64_t a1;
 1455       uint8_t  pad1;
 1456       uint64_t a2;
 1457       uint8_t  pad2;
 1458       uint64_t a3;
 1459       uint8_t  pad3;
 1460       uint64_t a4;
 1461     } u64;
 1462     struct
 1463     {
 1464       uint8_t code;
 1465       int32_t a0;
 1466       int32_t a1;
 1467       uint8_t pad0;
 1468       int32_t a2;
 1469       int32_t a3;
 1470       uint8_t pad1;
 1471       int32_t a4;
 1472       int32_t a5;
 1473       uint8_t pad2;
 1474       int32_t a6;
 1475       int32_t a7;
 1476       uint8_t pad3;
 1477       int32_t a8;
 1478       int32_t a9;
 1479     } s32;
 1480     struct
 1481     {
 1482       uint8_t code;
 1483       int16_t a0;
 1484       int16_t a1;
 1485       int16_t a2;
 1486       int16_t a3;
 1487       uint8_t pad0;
 1488       int16_t a4;
 1489       int16_t a5;
 1490       int16_t a6;
 1491       int16_t a7;
 1492       uint8_t pad1;
 1493       int16_t a8;
 1494       int16_t a9;
 1495       int16_t a10;
 1496       int16_t a11;
 1497       uint8_t pad2;
 1498       int16_t a12;
 1499       int16_t a13;
 1500       int16_t a14;
 1501       int16_t a15;
 1502       uint8_t pad3;
 1503       int16_t a16;
 1504       int16_t a17;
 1505       int16_t a18;
 1506       int16_t a19;
 1507     } s16;
 1508     struct
 1509     {
 1510       uint8_t code;
 1511       uint16_t a0;
 1512       uint16_t a1;
 1513       uint16_t a2;
 1514       uint16_t a3;
 1515       uint8_t pad0;
 1516       uint16_t a4;
 1517       uint16_t a5;
 1518       uint16_t a6;
 1519       uint16_t a7;
 1520       uint8_t pad1;
 1521       uint16_t a8;
 1522       uint16_t a9;
 1523       uint16_t a10;
 1524       uint16_t a11;
 1525       uint8_t pad2;
 1526       uint16_t a12;
 1527       uint16_t a13;
 1528       uint16_t a14;
 1529       uint16_t a15;
 1530       uint8_t pad3;
 1531       uint16_t a16;
 1532       uint16_t a17;
 1533       uint16_t a18;
 1534       uint16_t a19;
 1535     } u16;
 1536     struct
 1537     {
 1538       uint8_t code;
 1539       uint8_t a0;
 1540       uint8_t a1;
 1541       uint8_t a2;
 1542       uint8_t a3;
 1543       uint8_t a4;
 1544       uint8_t a5;
 1545       uint8_t a6;
 1546       uint8_t a7;
 1547       uint8_t pad0;
 1548       uint8_t a8;
 1549       uint8_t a9;
 1550       uint8_t a10;
 1551       uint8_t a11;
 1552       uint8_t a12;
 1553       uint8_t a13;
 1554       uint8_t a14;
 1555       uint8_t a15;
 1556       uint8_t pad1;
 1557       uint8_t a16;
 1558       uint8_t a17;
 1559       uint8_t a18;
 1560       uint8_t a19;
 1561       uint8_t a20;
 1562       uint8_t a21;
 1563       uint8_t a22;
 1564       uint8_t a23;
 1565     } u8;
 1566     struct
 1567     {
 1568       uint8_t code;
 1569       int8_t a0;
 1570       int8_t a1;
 1571       int8_t a2;
 1572       int8_t a3;
 1573       int8_t a4;
 1574       int8_t a5;
 1575       int8_t a6;
 1576       int8_t a7;
 1577       uint8_t pad0;
 1578       int8_t a8;
 1579       int8_t a9;
 1580       int8_t a10;
 1581       int8_t a11;
 1582       int8_t a12;
 1583       int8_t a13;
 1584       int8_t a14;
 1585       int8_t a15;
 1586       uint8_t pad1;
 1587       int8_t a16;
 1588       int8_t a17;
 1589       int8_t a18;
 1590       int8_t a19;
 1591       int8_t a20;
 1592       int8_t a21;
 1593       int8_t a22;
 1594       int8_t a23;
 1595     } s8;
 1596   };
 1597   CtxEntry next_entry; // also pads size of CtxCommand slightly.
 1598 };
 1599 
 1600 typedef struct _CtxImplementation CtxImplementation;
 1601 struct _CtxImplementation
 1602 {
 1603   void (*process)        (void *renderer, CtxCommand *entry);
 1604   void (*reset)          (void *renderer);
 1605   void (*flush)          (void *renderer);
 1606   char *(*get_clipboard) (void *ctxctx);
 1607   void (*set_clipboard)  (void *ctxctx, const char *text);
 1608   void (*free)           (void *renderer);
 1609 };
 1610 
 1611 CtxCommand *ctx_iterator_next (CtxIterator *iterator);
 1612 
 1613 #define ctx_arg_string()  ((char*)&entry[2].data.u8[0])
 1614 
 1615 
 1616 /* The above should be public API
 1617  */
 1618 
 1619 #pragma pack(pop)
 1620 
 1621 /* access macros for nth argument of a given type when packed into
 1622  * an CtxEntry pointer in current code context
 1623  */
 1624 #define ctx_arg_float(no) entry[(no)>>1].data.f[(no)&1]
 1625 #define ctx_arg_u64(no)   entry[(no)].data.u64[0]
 1626 #define ctx_arg_u32(no)   entry[(no)>>1].data.u32[(no)&1]
 1627 #define ctx_arg_s32(no)   entry[(no)>>1].data.s32[(no)&1]
 1628 #define ctx_arg_u16(no)   entry[(no)>>2].data.u16[(no)&3]
 1629 #define ctx_arg_s16(no)   entry[(no)>>2].data.s16[(no)&3]
 1630 #define ctx_arg_u8(no)    entry[(no)>>3].data.u8[(no)&7]
 1631 #define ctx_arg_s8(no)    entry[(no)>>3].data.s8[(no)&7]
 1632 #define ctx_arg_string()  ((char*)&entry[2].data.u8[0])
 1633 
 1634 typedef enum
 1635 {
 1636   CTX_GRAY           = 1,
 1637   CTX_RGB            = 3,
 1638   CTX_DRGB           = 4,
 1639   CTX_CMYK           = 5,
 1640   CTX_DCMYK          = 6,
 1641   CTX_LAB            = 7,
 1642   CTX_LCH            = 8,
 1643   CTX_GRAYA          = 101,
 1644   CTX_RGBA           = 103,
 1645   CTX_DRGBA          = 104,
 1646   CTX_CMYKA          = 105,
 1647   CTX_DCMYKA         = 106,
 1648   CTX_LABA           = 107,
 1649   CTX_LCHA           = 108,
 1650   CTX_GRAYA_A        = 201,
 1651   CTX_RGBA_A         = 203,
 1652   CTX_RGBA_A_DEVICE  = 204,
 1653   CTX_CMYKA_A        = 205,
 1654   CTX_DCMYKA_A       = 206,
 1655   // RGB  device and  RGB  ?
 1656 } CtxColorModel;
 1657 
 1658 enum _CtxAntialias
 1659 {
 1660   CTX_ANTIALIAS_DEFAULT,
 1661   CTX_ANTIALIAS_NONE, // non-antialiased
 1662   CTX_ANTIALIAS_FAST, // aa 3
 1663   CTX_ANTIALIAS_GOOD, // aa 5
 1664   CTX_ANTIALIAS_BEST  // aa 17
 1665 };
 1666 typedef enum _CtxAntialias CtxAntialias;
 1667 
 1668 enum _CtxCursor
 1669 {
 1670   CTX_CURSOR_UNSET,
 1671   CTX_CURSOR_NONE,
 1672   CTX_CURSOR_ARROW,
 1673   CTX_CURSOR_IBEAM,
 1674   CTX_CURSOR_WAIT,
 1675   CTX_CURSOR_HAND,
 1676   CTX_CURSOR_CROSSHAIR,
 1677   CTX_CURSOR_RESIZE_ALL,
 1678   CTX_CURSOR_RESIZE_N,
 1679   CTX_CURSOR_RESIZE_S,
 1680   CTX_CURSOR_RESIZE_E,
 1681   CTX_CURSOR_RESIZE_NE,
 1682   CTX_CURSOR_RESIZE_SE,
 1683   CTX_CURSOR_RESIZE_W,
 1684   CTX_CURSOR_RESIZE_NW,
 1685   CTX_CURSOR_RESIZE_SW,
 1686   CTX_CURSOR_MOVE
 1687 };
 1688 typedef enum _CtxCursor CtxCursor;
 1689 
 1690 /* to be used immediately after a ctx_listen or ctx_listen_full causing the
 1691  * cursor to change when hovering the listen area.
 1692  */
 1693 void ctx_listen_set_cursor (Ctx      *ctx,
 1694                             CtxCursor cursor);
 1695 
 1696 /* lower level cursor setting that is independent of ctx event handling
 1697  */
 1698 void         ctx_set_cursor (Ctx *ctx, CtxCursor cursor);
 1699 CtxCursor    ctx_get_cursor (Ctx *ctx);
 1700 void         ctx_set_antialias (Ctx *ctx, CtxAntialias antialias);
 1701 CtxAntialias ctx_get_antialias (Ctx *ctx);
 1702 void         ctx_set_render_threads   (Ctx *ctx, int n_threads);
 1703 int          ctx_get_render_threads   (Ctx *ctx);
 1704 
 1705 void         ctx_set_hash_cache (Ctx *ctx, int enable_hash_cache);
 1706 int          ctx_get_hash_cache (Ctx *ctx);
 1707 
 1708 
 1709 typedef struct _CtxParser CtxParser;
 1710   CtxParser *ctx_parser_new (
 1711   Ctx       *ctx,
 1712   int        width,
 1713   int        height,
 1714   float      cell_width,
 1715   float      cell_height,
 1716   int        cursor_x,
 1717   int        cursor_y,
 1718   int   (*set_prop)(void *prop_data, uint64_t key, const char *data,  int 
 1719          len),
 1720   int   (*get_prop)(void *prop_Data, const char *key, char **data, int *len)
 1721          ,
 1722   void  *prop_data,
 1723   void (*exit) (void *exit_data),
 1724   void *exit_data);
 1725 
 1726 
 1727 enum _CtxColorSpace
 1728 {
 1729   CTX_COLOR_SPACE_DEVICE_RGB,
 1730   CTX_COLOR_SPACE_DEVICE_CMYK,
 1731   CTX_COLOR_SPACE_USER_RGB,
 1732   CTX_COLOR_SPACE_USER_CMYK,
 1733   CTX_COLOR_SPACE_TEXTURE
 1734 };
 1735 typedef enum _CtxColorSpace CtxColorSpace;
 1736 
 1737 /* sets the color space for a slot, the space is either a string of
 1738  * "sRGB" "rec2020" .. etc or an icc profile.
 1739  *
 1740  * The slots device_rgb and device_cmyk is mostly to be handled outside 
 1741  drawing 
 1742  * code, and user_rgb and user_cmyk is to be used. With no user_cmyk set
 1743  * user_cmyk == device_cmyk.
 1744  *
 1745  * The set profiles follows the graphics state.
 1746  */
 1747 void ctx_color_space (Ctx           *ctx,
 1748                       CtxColorSpace  space_slot,
 1749                       unsigned char *data,
 1750                       int            data_length);
 1751 
 1752 void
 1753 ctx_parser_set_size (CtxParser *parser,
 1754                      int        width,
 1755                      int        height,
 1756                      float      cell_width,
 1757                      float      cell_height);
 1758 
 1759 void ctx_parser_feed_byte (CtxParser *parser, int byte);
 1760 
 1761 int
 1762 ctx_get_contents (const char     *path,
 1763                    unsigned char **contents,
 1764                    long           *length);
 1765 
 1766 void ctx_parser_free (CtxParser *parser);
 1767 typedef struct _CtxSHA1 CtxSHA1;
 1768 
 1769 #ifndef CTX_CODEC_CHAR
 1770 //#define CTX_CODEC_CHAR '\035'
 1771 //#define CTX_CODEC_CHAR 'a'
 1772 #define CTX_CODEC_CHAR '\020' // datalink escape
 1773 //#define CTX_CODEC_CHAR '^'
 1774 #endif
 1775 
 1776 #ifndef assert
 1777 #define assert(a)
 1778 #endif
 1779 
 1780 #ifdef __cplusplus
 1781 }
 1782 #endif
 1783 #endif
 1784 #ifndef __CTX_H__
 1785 #define __CTX_H__
 1786 #ifndef CTX_STRING_H
 1787 #define CTX_STRING_H
 1788 
 1789 typedef struct _CtxString CtxString;
 1790 struct _CtxString
 1791 {
 1792   char *str;
 1793   int   length;
 1794   int   utf8_length;
 1795   int   allocated_length;
 1796   int   is_line;
 1797 };
 1798 
 1799 CtxString   *ctx_string_new_with_size  (const char *initial, int 
 1800                                         initial_size);
 1801 CtxString   *ctx_string_new            (const char *initial);
 1802 void        ctx_string_free           (CtxString *string, int freealloc);
 1803 const char *ctx_string_get            (CtxString *string);
 1804 uint32_t    ctx_string_get_unichar    (CtxString *string, int pos);
 1805 int         ctx_string_get_length     (CtxString *string);
 1806 void        ctx_string_set            (CtxString *string, const char 
 1807                                        *new_string);
 1808 void        ctx_string_clear          (CtxString *string);
 1809 void        ctx_string_append_str     (CtxString *string, const char *str);
 1810 void        ctx_string_append_byte    (CtxString *string, char  val);
 1811 void        ctx_string_append_string  (CtxString *string, CtxString 
 1812                                        *string2);
 1813 void        ctx_string_append_unichar (CtxString *string, unsigned int 
 1814                                        unichar);
 1815 void        ctx_string_append_data    (CtxString *string, const char *data, 
 1816                                        int len);
 1817 
 1818 void        ctx_string_append_utf8char (CtxString *string, const char *str);
 1819 void        ctx_string_append_printf  (CtxString *string, const char 
 1820                                        *format, ...);
 1821 void        ctx_string_replace_utf8   (CtxString *string, int pos, const 
 1822                                        char *new_glyph);
 1823 void        ctx_string_insert_utf8    (CtxString *string, int pos, const 
 1824                                        char *new_glyph);
 1825 void        ctx_string_replace_unichar (CtxString *string, int pos, 
 1826                                         uint32_t unichar);
 1827 void        ctx_string_remove         (CtxString *string, int pos);
 1828 char       *ctx_strdup_printf         (const char *format, ...);
 1829 
 1830 #ifndef TRUE
 1831 #define TRUE 1
 1832 #endif
 1833 #ifndef FALSE
 1834 #define FALSE 0
 1835 #endif
 1836 
 1837 #endif
 1838 #ifndef _CTX_INTERNAL_FONT_
 1839 #define _CTX_INTERNAL_FONT_
 1840 
 1841 #ifndef CTX_FONT_ascii
 1842 /* this is a ctx encoded font based on DejaVuSans.ttf */
 1843 /* CTX_SUBDIV:4  CTX_BAKE_FONT_SIZE:160 */
 1844 /* glyphs covered: 
 1845 
 1846  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghi
 1847   jklmnopqrstuvwxyz{|}~  */
 1848 static const struct __attribute__ ((packed)) {uint8_t code; uint32_t a; 
 1849                                    uint32_t b;}
 1850 ctx_font_ascii[]={
 1851 {'@', 0x00000020, 0x00002bb0},/*                 x-advance: 43.687500 */
 1852 {'@', 0x00000021, 0x00003719},/*        !        x-advance: 55.097656 */
 1853 {'M', 0x41a5e7f2, 0xc1886037},
 1854 {'0', 0x44000036, 0xbc0000ca},
 1855 {'m', 0x00000000, 0xc2a64f08},
 1856 {'l', 0x4159fc90, 0x00000000},
 1857 {'l', 0x00000000, 0x422fd6c4},
 1858 {'l', 0xbfabcfe0, 0x41bfad86},
 1859 {'l', 0xc12df5b2, 0x00000000},
 1860 {'l', 0xbfb46710, 0xc1bfad86},
 1861 {'l', 0x00000000, 0xc22fd6c4},
 1862 {'@', 0x00000022, 0x00003f38},/*        "        x-advance: 63.218750 */
 1863 {'M', 0x41c50c07, 0xc2c86716},
 1864 {'l', 0x00000000, 0x4214fe48},
 1865 {'4', 0x0000ffd3, 0xff6c0000},
 1866 {'6', 0x0000002d, 0x00000065},
 1867 {'l', 0x00000000, 0x4214fe48},
 1868 {'l', 0xc1368ce4, 0x00000000},
 1869 {'l', 0x00000000, 0xc214fe48},
 1870 {'l', 0x41368ce4, 0x00000000},
 1871 {'@', 0x00000023, 0x0000732a},/*        #        x-advance: 115.164062 */
 1872 {'M', 0x428c8973, 0xc271e113},
 1873 {'0', 0x59ea00b2, 0xa716004e},
 1874 {'m', 0xc12112e8, 0xc218c06d},
 1875 {'0', 0x004e6fe5, 0x002a911c},
 1876 {'0', 0x00536fe5, 0x00a22900},
 1877 {'0', 0x005559ea, 0x00a12900},
 1878 {'0', 0x00d66fe5, 0x00b2911b},
 1879 {'0', 0x00d56fe5, 0x00ac911b},
 1880 {'0', 0x005ed700, 0x00aaa716},
 1881 {'0', 0x0060d700, 0x002b911b},
 1882 {'@', 0x00000024, 0x00005773},/*        $        x-advance: 87.449219 */
 1883 {'M', 0x4239c595, 0x41a19c59},
 1884 {'4', 0x0000ffe6, 0xffb00000},
 1885 {'8', 0xfac800e4, 0xeec8fae4},
 1886 {'l', 0x00000000, 0xc14149e1},
 1887 {'8', 0x1a37111b, 0x0839081c},
 1888 {'l', 0x00000000, 0xc1f4d50c},
 1889 {'8', 0xe0aaf7c5, 0xc1e6e9e6},
 1890 {'8', 0xbc1dd500, 0xe454e71d},
 1891 {'4', 0xffc10000, 0x0000001a},
 1892 {'l', 0x00000000, 0x417920a8},
 1893 {'8', 0x05300118, 0x0b2d0417},
 1894 {'l', 0x00000000, 0x413beb60},
 1895 {'8', 0xefd3f5ea, 0xf9d0fae9},
 1896 {'l', 0x00000000, 0x41e54302},
 1897 {'8', 0x2159093c, 0x421c181c},
 1898 {'8', 0x47e22d00, 0x1ea91ae2},
 1899 {'6', 0x00510000, 0xfee1ffe6},
 1900 {'l', 0x00000000, 0xc1dc2258},
 1901 {'8', 0x11d103e1, 0x25f00ef0},
 1902 {'8', 0x230f1700, 0x12300c0f},
 1903 {'m', 0x40d6c3d8, 0x414e2cac},
 1904 {'l', 0x00000000, 0x41e87bb4},
 1905 {'8', 0xed33fc22, 0xda11f211},
 1906 {'8', 0xdbf0e900, 0xecccf3f0},
 1907 {'@', 0x00000025, 0x0000829a},/*        %        x-advance: 130.601562 */
 1908 {'M', 0x42c7dda3, 0xc2306037},
 1909 {'8', 0x13dc00e9, 0x37f313f3},
 1910 {'8', 0x370d2200, 0x1324130d},
 1911 {'8', 0xed230016, 0xc90dec0d},
 1912 {'8', 0xc9f3dd00, 0xecddecf3},
 1913 {'m', 0x00000000, 0xc1086034},
 1914 {'8', 0x1d43002a, 0x4f181d18},
 1915 {'8', 0x4fe73200, 0x1dbd1de8},
 1916 {'8', 0xe3bd00d6, 0xb1e8e3e8},
 1917 {'8', 0xb118ce00, 0xe343e319},
 1918 {'m', 0xc28a8603, 0xc2237d6c},
 1919 {'8', 0x14dc00e9, 0x36f313f3},
 1920 {'8', 0x370d2300, 0x1324130d},
 1921 {'8', 0xed240017, 0xc90ded0d},
 1922 {'8', 0xcaf3de00, 0xecdcecf3},
 1923 {'m', 0x42726a86, 0xc1086038},
 1924 {'l', 0x412bcfe0, 0x00000000},
 1925 {'4', 0x019fff06, 0x0000ffd6},
 1926 {'6', 0xfe6100fa, 0x0000ff0e},
 1927 {'8', 0x1d43002a, 0x4f191d19},
 1928 {'8', 0x50e73200, 0x1dbd1de8},
 1929 {'8', 0xe3bd00d6, 0xb0e8e3e8},
 1930 {'8', 0xb118cf00, 0xe343e318},
 1931 {'@', 0x00000026, 0x00006b2e},/*        &        x-advance: 107.179688 */
 1932 {'M', 0x4205b0f7, 0xc257920a},
 1933 {'8', 0x2bdd15e8, 0x2df515f5},
 1934 {'8', 0x411c2700, 0x1a471a1c},
 1935 {'8', 0xf82f0019, 0xe729f816},
 1936 {'6', 0xff6fff72, 0xffe20025},
 1937 {'l', 0x42086037, 0x420b98e9},
 1938 {'8', 0xcd18e90f, 0xc70ae508},
 1939 {'l', 0x4147bb40, 0x00000000},
 1940 {'8', 0x46ef23fd, 0x44da22f3},
 1941 {'4', 0x004c004a, 0x0000ffbd},
 1942 {'l', 0xc1198e98, 0xc11dda33},
 1943 {'8', 0x23c617e5, 0x0bbf0be2},
 1944 {'8', 0xdc9700c0, 0xa2d7dbd7},
 1945 {'8', 0xc011de00, 0xc835e211},
 1946 {'8', 0xdfedf0f4, 0xdffaf0fa},
 1947 {'8', 0xbb1dd500, 0xe64fe61d},
 1948 {'8', 0x042c0016, 0x0e2d0416},
 1949 {'l', 0x00000000, 0x41436fb0},
 1950 {'8', 0xedd4f4e9, 0xfad9faeb},
 1951 {'8', 0x0fd300e4, 0x26ef0eef},
 1952 {'8', 0x1b070d00, 0x26200d08},
 1953 {'@', 0x00000027, 0x000025c9},/*        '        x-advance: 37.785156 */
 1954 {'M', 0x41c50c07, 0xc2c86716},
 1955 {'l', 0x00000000, 0x4214fe48},
 1956 {'l', 0xc1368ce3, 0x00000000},
 1957 {'l', 0x00000000, 0xc214fe48},
 1958 {'l', 0x41368ce3, 0x00000000},
 1959 {'@', 0x00000028, 0x0000359f},/*        (        x-advance: 53.621094 */
 1960 {'M', 0x422a7844, 0xc2d09732},
 1961 {'q', 0xc10fe480, 0x4176fae0},
 1962 {0, 0xc155b0f6, 0x41f44b9c},
 1963 {'q', 0xc08b98e8, 0x41719c54},
 1964 {0, 0xc08b98e8, 0x41f4d50a},
 1965 {'q', 0x00000000, 0x41780dbe},
 1966 {0, 0x408b98e8, 0x41f5e7f2},
 1967 {'9', 0x003c0011, 0x007a0035},
 1968 {'l', 0xc12bcfe2, 0x00000000},
 1969 {'q', 0xc12112e6, 0xc17c5958},
 1970 {0, 0xc1719c5a, 0xc1f80dbf},
 1971 {'q', 0xc09eed18, 0xc173c224},
 1972 {0, 0xc09eed18, 0xc1f225cc},
 1973 {'q', 0x00000000, 0xc16f768c},
 1974 {0, 0x409eed18, 0xc1f112e6},
 1975 {'q', 0x409eed1c, 0xc172af40},
 1976 {0, 0x41719c5a, 0xc1f80dc0},
 1977 {'l', 0x412bcfe2, 0x00000000},
 1978 {'@', 0x00000029, 0x0000359f},/*        )        x-advance: 53.621094 */
 1979 {'M', 0x41301b7d, 0xc2d09732},
 1980 {'l', 0x412bcfe5, 0x00000000},
 1981 {'q', 0x412112e6, 0x417d6c40},
 1982 {0, 0x41708972, 0x41f80dc0},
 1983 {'q', 0x40a112e8, 0x4172af40},
 1984 {0, 0x40a112e8, 0x41f112e6},
 1985 {'q', 0x00000000, 0x41708974},
 1986 {0, 0xc0a112e8, 0x41f225cc},
 1987 {'9', 0x003cffed, 0x007cffc4},
 1988 {'l', 0xc12bcfe5, 0x00000000},
 1989 {'q', 0x410ed19d, 0xc175e7f3},
 1990 {0, 0x41549e11, 0xc1f44b99},
 1991 {'q', 0x408dbeb4, 0xc173c226},
 1992 {0, 0x408dbeb4, 0xc1f5e7f2},
 1993 {'q', 0x00000000, 0xc1780dc0},
 1994 {0, 0xc08dbeb4, 0xc1f4d50a},
 1995 {'q', 0xc08b98e8, 0xc1719c58},
 1996 {0, 0xc1549e11, 0xc1f44b9c},
 1997 {'@', 0x0000002a, 0x000044b9},/*        *        x-advance: 68.722656 */
 1998 {'M', 0x42814302, 0xc2a761ef},
 1999 {'0', 0x346034a0, 0xcaa61af1},
 2000 {'0', 0x00e26500, 0x36a69b00},
 2001 {'0', 0xcc60e6f1, 0xe60fcca0},
 2002 {'0', 0x9b00365a, 0x6500001e},
 2003 {'l', 0x41b46716, 0xc159fc90},
 2004 {'l', 0x407920b0, 0x40d49e10},
 2005 {'@', 0x0000002b, 0x0000732a},/*        +        x-advance: 115.164062 */
 2006 {'M', 0x427ce2ca, 0xc2ac5957},
 2007 {'l', 0x00000000, 0x421587ba},
 2008 {'l', 0x421587bc, 0x00000000},
 2009 {'l', 0x00000000, 0x41368ce4},
 2010 {'l', 0xc21587bc, 0x00000000},
 2011 {'l', 0x00000000, 0x421587bb},
 2012 {'l', 0xc1346714, 0x00000000},
 2013 {'l', 0x00000000, 0xc21587bb},
 2014 {'l', 0xc21587bb, 0x00000000},
 2015 {'l', 0xb5800000, 0xc1368ce4},
 2016 {'l', 0x421587bb, 0x00000000},
 2017 {'l', 0x00000000, 0xc21587ba},
 2018 {'l', 0x41346714, 0x00000000},
 2019 {'@', 0x0000002c, 0x00002bb0},/*        ,        x-advance: 43.687500 */
 2020 {'M', 0x4180dbeb, 0xc1886037},
 2021 {'0', 0x2e000038, 0x00de55d4},
 2022 {'l', 0x40b01b7c, 0xc1abcfe4},
 2023 {'l', 0x00000000, 0xc138b2b0},
 2024 {'@', 0x0000002d, 0x00003198},/*        -        x-advance: 49.593750 */
 2025 {'M', 0x40d6c3dd, 0xc22c9e11},
 2026 {'l', 0x4210b2af, 0x00000000},
 2027 {'l', 0x00000000, 0x41301b7c},
 2028 {'l', 0xc210b2af, 0x00000000},
 2029 {'l', 0xb5c00000, 0xc1301b7c},
 2030 {'[', 0x0047002d, 0x00000508},
 2031 {'[', 0x004a002d, 0x000007a6},
 2032 {'[', 0x004f002d, 0x000003d3},
 2033 {'[', 0x0051002d, 0x00000508},
 2034 {'[', 0x006f002d, 0x0000028c},
 2035 {'@', 0x0000002e, 0x00002bb0},/*        .        x-advance: 43.687500 */
 2036 {'M', 0x416b2af4, 0xc1886037},
 2037 {'0', 0x44000038, 0xbc0000c8},
 2038 {'@', 0x0000002f, 0x00002e4f},/*        /        x-advance: 46.308594 */
 2039 {'M', 0x420b98e9, 0xc2c86716},
 2040 {'l', 0x41368ce4, 0x00000000},
 2041 {'l', 0xc20b98e9, 0x42e1e7f2},
 2042 {'l', 0xc1368ce4, 0xb5800000},
 2043 {'l', 0x420b98e9, 0xc2e1e7f2},
 2044 {'@', 0x00000030, 0x00005773},/*        0        x-advance: 87.449219 */
 2045 {'M', 0x422ec3dd, 0xc2b68ce3},
 2046 {'q', 0xc1278448, 0x00000000},
 2047 {0, 0xc17c5956, 0x41255e80},
 2048 {'q', 0xc0a7844c, 0x41244b98},
 2049 {0, 0xc0a7844c, 0x41f7844c},
 2050 {'q', 0x00000000, 0x41a4d50c},
 2051 {0, 0x40a7844c, 0x41f7844c},
 2052 {'8', 0x293f2915, 0xd73f002a},
 2053 {'q', 0x40a9aa18, 0xc1255e80},
 2054 {0, 0x40a9aa18, 0xc1f7844c},
 2055 {'q', 0x00000000, 0xc1a55e80},
 2056 {0, 0xc0a9aa18, 0xc1f7844c},
 2057 {'9', 0xffd7ffec, 0xffd7ffc1},
 2058 {'m', 0x00000000, 0xc12bcfe0},
 2059 {'q', 0x4186c3de, 0x00000000},
 2060 {0, 0x41cda33a, 0x4155b0f8},
 2061 {'q', 0x410ed198, 0x41549e10},
 2062 {0, 0x410ed198, 0x421aa180},
 2063 {'q', 0x00000000, 0x41ca6a86},
 2064 {0, 0xc10ed198, 0x421aa181},
 2065 {'8', 0x359a35dd, 0xcb9900bd},
 2066 {'q', 0xc10dbeb5, 0xc155b0f8},
 2067 {0, 0xc10dbeb5, 0xc21aa181},
 2068 {'q', 0x00000000, 0xc1caf3f8},
 2069 {0, 0x410dbeb5, 0xc21aa180},
 2070 {'q', 0x410ed19c, 0xc155b0f8},
 2071 {0, 0x41ce2cab, 0xc155b0f8},
 2072 {'@', 0x00000031, 0x00005773},/*        1        x-advance: 87.449219 */
 2073 {'M', 0x41886037, 0xc1368ce3},
 2074 {'l', 0x41b12e63, 0x00000000},
 2075 {'l', 0x00000000, 0xc298e2cb},
 2076 {'0', 0xcf0013a0, 0x0036ed5f},
 2077 {'l', 0x00000000, 0x42b1957a},
 2078 {'l', 0x41b12e64, 0xb6400000},
 2079 {'l', 0x00000000, 0x41368ce3},
 2080 {'l', 0xc266df5a, 0x00000000},
 2081 {'l', 0xb6000000, 0xc1368ce3},
 2082 {'@', 0x00000032, 0x00005773},/*        2        x-advance: 87.449219 */
 2083 {'M', 0x41d301b8, 0xc1368ce3},
 2084 {'l', 0x423d4302, 0x00000000},
 2085 {'4', 0x002d0000, 0x0000ff02},
 2086 {'l', 0xb6000000, 0xc1368ce3},
 2087 {'8', 0xab54e11e, 0xbb43cb35},
 2088 {'8', 0xcf24e31a, 0xd90aec0a},
 2089 {'8', 0xcceae100, 0xecc6ecea},
 2090 {'8', 0x08cb00e7, 0x1ac408e4},
 2091 {'l', 0x00000000, 0xc15b0f78},
 2092 {'8', 0xed3df320, 0xfa34fa1c},
 2093 {'8', 0x1f63003e, 0x53251f25},
 2094 {'8', 0x2ef71800, 0x34df16f7},
 2095 {'8', 0x2dd607fa, 0x679b25dd},
 2096 {'@', 0x00000033, 0x00005773},/*        3        x-advance: 87.449219 */
 2097 {'M', 0x425f1656, 0xc2581b7d},
 2098 {'8', 0x223c0826, 0x40161a16},
 2099 {'q', 0x00000000, 0x416d50c0},
 2100 {0, 0xc12338b8, 0x41b79fc8},
 2101 {'q', 0xc12338b0, 0x4101eed3},
 2102 {0, 0xc1e7f240, 0x4101eed3},
 2103 {'8', 0xfccc00e7, 0xf1c9fbe6},
 2104 {'l', 0x00000000, 0xc151655e},
 2105 {'8', 0x13310d16, 0x0638061a},
 2106 {'8', 0xec4d0033, 0xc61aec1a},
 2107 {'8', 0xc9e8dd00, 0xecbcece8},
 2108 {'4', 0x0000ffd2, 0xffd40000},
 2109 {'l', 0x41436fae, 0x00000000},
 2110 {'8', 0xf13d0028, 0xd215f015},
 2111 {'8', 0xd1eae200, 0xf0c2f0eb},
 2112 {'8', 0x04d100ea, 0x0fc804e7},
 2113 {'l', 0x00000000, 0xc14149e0},
 2114 {'8', 0xf439f81e, 0xfc33fc1b},
 2115 {'8', 0x1c61003d, 0x4b231b23},
 2116 {'8', 0x38ed2100, 0x1fca16ed},
 2117 {'@', 0x00000034, 0x00005773},/*        4        x-advance: 87.449219 */
 2118 {'M', 0x424fc905, 0xc2b0c74d},
 2119 {'4', 0x00d5ff78, 0x00000088},
 2120 {'6', 0xff2b0000, 0xffd1fff2},
 2121 {'l', 0x41886038, 0x00000000},
 2122 {'l', 0x00000000, 0x42829aa2},
 2123 {'0', 0x2d000039, 0x5e0000c7},
 2124 {'l', 0xc157d6c4, 0x00000000},
 2125 {'l', 0x00000000, 0xc1bcfe48},
 2126 {'l', 0xc234f089, 0x00000000},
 2127 {'l', 0xb5c00000, 0xc151655c},
 2128 {'l', 0x4226b61e, 0xc27df5b1},
 2129 {'@', 0x00000035, 0x00005773},/*        5        x-advance: 87.449219 */
 2130 {'M', 0x416d50c0, 0xc2c86716},
 2131 {'l', 0x4254e2ca, 0x00000000},
 2132 {'4', 0x002d0000, 0x0000ff5d},
 2133 {'l', 0x00000000, 0x41c48294},
 2134 {'8', 0xfb17fc0b, 0xfe17fe0b},
 2135 {'8', 0x246a0043, 0x63272427},
 2136 {'q', 0x00000000, 0x4181655f},
 2137 {0, 0xc12112e8, 0x41c957a0},
 2138 {'q', 0xc12112e4, 0x410ed19d},
 2139 {0, 0xc1e31d34, 0x410ed19d},
 2140 {'8', 0xfccd00e7, 0xf4cbfce6},
 2141 {'l', 0x00000000, 0xc159fc90},
 2142 {'8', 0x13310d18, 0x06360619},
 2143 {'8', 0xe849002e, 0xbe1be81b},
 2144 {'8', 0xbee5d700, 0xe8b7e8e5},
 2145 {'8', 0x04d500eb, 0x0fd404eb},
 2146 {'l', 0x00000000, 0xc249579f},
 2147 {'@', 0x00000036, 0x00005773},/*        6        x-advance: 87.449219 */
 2148 {'M', 0x423579fc, 0xc25e036f},
 2149 {'8', 0x18c700dc, 0x44eb18eb},
 2150 {'8', 0x44152b00, 0x18391815},
 2151 {'8', 0xe8390024, 0xbc15e715},
 2152 {'8', 0xbcebd500, 0xe8c7e8eb},
 2153 {'m', 0x41d74d50, 0xc229eed1},
 2154 {'l', 0x00000000, 0x41459578},
 2155 {'8', 0xf2d7f7ec, 0xfbd7fbec},
 2156 {'8', 0x24ae00cb, 0x6de024e4},
 2157 {'8', 0xdd27e90f, 0xf434f417},
 2158 {'8', 0x245f003c, 0x63232423},
 2159 {'8', 0x63dc3d00, 0x259f25dc},
 2160 {'q', 0xc18b0f76, 0xb4c00000},
 2161 {0, 0xc1d49e10, 0xc1549e11},
 2162 {'q', 0xc1131d36, 0xc155b0f8},
 2163 {0, 0xc1131d36, 0xc21aa181},
 2164 {'q', 0x00000000, 0xc1be112c},
 2165 {0, 0x41346716, 0xc21768ce},
 2166 {'q', 0x41346718, 0xc16293c0},
 2167 {0, 0x41f225cc, 0xc16293c0},
 2168 {'8', 0x04290014, 0x0c2b0414},
 2169 {'@', 0x00000037, 0x00005773},/*        7        x-advance: 87.449219 */
 2170 {'M', 0x41346716, 0xc2c86716},
 2171 {'l', 0x4280dbeb, 0x00000000},
 2172 {'l', 0x00000000, 0x40b8b2b0},
 2173 {'l', 0xc21180dc, 0x42bcdbeb},
 2174 {'l', 0xc16293c2, 0x00000000},
 2175 {'l', 0x4208e9aa, 0xc2b1957a},
 2176 {'l', 0xc2407bb4, 0x00000000},
 2177 {'l', 0xb6000000, 0xc1368ce0},
 2178 {'@', 0x00000038, 0x00005773},/*        8        x-advance: 87.449219 */
 2179 {'M', 0x422ec3dd, 0xc23e55e8},
 2180 {'8', 0x14c400da, 0x38ea14ea},
 2181 {'8', 0x38162400, 0x143c1416},
 2182 {'8', 0xec3c0026, 0xc816ec16},
 2183 {'8', 0xc8eadc00, 0xecc4ecea},
 2184 {'m', 0xc158e9a8, 0xc0b8b2b0},
 2185 {'8', 0xe0caf8de, 0xc6ede9ed},
 2186 {'8', 0xb522d000, 0xe55de522},
 2187 {'8', 0x1b5d003b, 0x4b221b22},
 2188 {'8', 0x3aed2200, 0x20cb17ed},
 2189 {'8', 0x233c0927, 0x40161a16},
 2190 {'8', 0x59dd3a00, 0x1f9b1fdd},
 2191 {'8', 0xe19a00be, 0xa7dde1dd},
 2192 {'8', 0xc016da00, 0xdd3de616},
 2193 {'m', 0xc09eed1c, 0xc1ab4670},
 2194 {'8', 0x30131f00, 0x11361113},
 2195 {'8', 0xef360022, 0xd013ef13},
 2196 {'8', 0xd0ede100, 0xefcaefed},
 2197 {'8', 0x11ca00dd, 0x30ed11ed},
 2198 {'@', 0x00000039, 0x00005773},/*        9        x-advance: 87.449219 */
 2199 {'M', 0x41719c59, 0xc0052784},
 2200 {'l', 0x00000000, 0xc145957a},
 2201 {'8', 0x0e290914, 0x05290514},
 2202 {'8', 0xdd510035, 0x9320dc1c},
 2203 {'8', 0x23d917f1, 0x0ccc0ce9},
 2204 {'8', 0xdca100c4, 0x9ddedcde},
 2205 {'8', 0x9d24c300, 0xdb61db24},
 2206 {'q', 0x418b0f76, 0x00000000},
 2207 {0, 0x41d4149c, 0x4155b0f8},
 2208 {'q', 0x41131d38, 0x41549e10},
 2209 {0, 0x41131d38, 0x421aa180},
 2210 {'q', 0x00000000, 0x41bd87bc},
 2211 {0, 0xc1346718, 0x421768ce},
 2212 {'q', 0xc133542c, 0x416180dd},
 2213 {0, 0xc1f19c58, 0x416180dd},
 2214 {'8', 0xfcd700ec, 0xf4d5fcec},
 2215 {'m', 0x41d7d6c4, 0xc229eed2},
 2216 {'8', 0xe8390024, 0xbc15e815},
 2217 {'8', 0xbcebd500, 0xe7c7e7eb},
 2218 {'8', 0x19c700dc, 0x44eb18eb},
 2219 {'8', 0x44152b00, 0x18391815},
 2220 {'@', 0x0000003a, 0x00002e4f},/*        :        x-advance: 46.308594 */
 2221 {'M', 0x4180dbeb, 0xc1886037},
 2222 {'0', 0x44000038, 0xbc0000c8},
 2223 {'m', 0x00000000, 0xc2581b7c},
 2224 {'0', 0x44000038, 0xbc0000c8},
 2225 {'@', 0x0000003b, 0x00002e4f},/*        ;        x-advance: 46.308594 */
 2226 {'M', 0x4180dbeb, 0xc28e25cc},
 2227 {'0', 0x44000038, 0xbc0000c8},
 2228 {'m', 0x00000000, 0x42581b7c},
 2229 {'0', 0x2e000038, 0x00de55d4},
 2230 {'l', 0x40b01b7c, 0xc1abcfe4},
 2231 {'l', 0x00000000, 0xc138b2b0},
 2232 {'@', 0x0000003c, 0x0000732a},/*        <        x-advance: 115.164062 */
 2233 {'M', 0x42c93543, 0xc2874d51},
 2234 {'l', 0xc28a8604, 0x41c50c08},
 2235 {'l', 0x428a8604, 0x41c3f921},
 2236 {'l', 0x00000000, 0x41436fac},
 2237 {'l', 0xc2ac149e, 0xc1f9aa17},
 2238 {'l', 0xb5800000, 0xc132414c},
 2239 {'l', 0x42ac149e, 0xc1f9aa16},
 2240 {'l', 0x00000000, 0x41436fa8},
 2241 {'@', 0x0000003d, 0x0000732a},/*        =        x-advance: 115.164062 */
 2242 {'M', 0x41690527, 0xc279aa18},
 2243 {'l', 0x42ac149e, 0x00000000},
 2244 {'4', 0x002d0000, 0x0000fea8},
 2245 {'6', 0xffd30000, 0x006d0000},
 2246 {'l', 0x42ac149e, 0x00000000},
 2247 {'l', 0x00000000, 0x41368ce4},
 2248 {'l', 0xc2ac149e, 0x00000000},
 2249 {'l', 0xb5800000, 0xc1368ce4},
 2250 {'@', 0x0000003e, 0x0000732a},/*        >        x-advance: 115.164062 */
 2251 {'M', 0x41690527, 0xc2874d51},
 2252 {'l', 0x00000000, 0xc1436fa8},
 2253 {'l', 0x42ac149e, 0x41f9aa16},
 2254 {'l', 0x00000000, 0x4132414c},
 2255 {'l', 0xc2ac149e, 0x41f9aa17},
 2256 {'l', 0xb5800000, 0xc1436fac},
 2257 {'l', 0x428a414a, 0xc1c3f921},
 2258 {'l', 0xc28a414a, 0xc1c50c08},
 2259 {'@', 0x0000003f, 0x000048f3},/*        ?        x-advance: 72.949219 */
 2260 {'M', 0x41d1eed1, 0xc1886037},
 2261 {'0', 0x44000036, 0xbc0000ca},
 2262 {'m', 0x41538b2a, 0xc11dda32},
 2263 {'4', 0x0000ffcd, 0xffd70000},
 2264 {'8', 0xd407e500, 0xd81fef07},
 2265 {'l', 0x40c149e0, 0xc0bf2418},
 2266 {'8', 0xe616f20f, 0xe706f406},
 2267 {'8', 0xdaefe900, 0xf2d2f2ef},
 2268 {'8', 0x09d300eb, 0x1bcf09e9},
 2269 {'l', 0x00000000, 0xc149e110},
 2270 {'8', 0xea33f119, 0xf935f91a},
 2271 {'8', 0x1a4f0031, 0x441e1a1e},
 2272 {'8', 0x26f71400, 0x29df12f7},
 2273 {'l', 0xc0bcfe48, 0x40b8b2b0},
 2274 {'8', 0x13ef0cf4, 0x0df906fb},
 2275 {'8', 0x0dfe05ff, 0x16000800},
 2276 {'l', 0x00000000, 0x410414a0},
 2277 {'@', 0x00000040, 0x00008973},/*        @        x-advance: 137.449219 */
 2278 {'M', 0x424c9052, 0xc210293c},
 2279 {'8', 0x3c132600, 0x15341513},
 2280 {'8', 0xea330021, 0xc413ea13},
 2281 {'8', 0xc5eddb00, 0xeacceaed},
 2282 {'8', 0x16cd00e0, 0x3bed16ed},
 2283 {'m', 0x42124f08, 0x41a08973},
 2284 {'8', 0x1edb14f0, 0x09d009ec},
 2285 {'8', 0xdfb500d2, 0xa9e4dfe4},
 2286 {'8', 0xa91ccb00, 0xdf4adf1c},
 2287 {'8', 0x0a30001b, 0x1e240914},
 2288 {'4', 0xffdd0000, 0x00000026},
 2289 {'l', 0x00000000, 0x4245957a},
 2290 {'8', 0xdd3dfb27, 0xb316e216},
 2291 {'8', 0xcbf8e400, 0xd2e7e7f8},
 2292 {'8', 0xcbbcdde5, 0xeea9eed8},
 2293 {'8', 0x08c100df, 0x19c808e2},
 2294 {'8', 0x47be1bd6, 0x60e92ce9},
 2295 {'8', 0x4f0f2a00, 0x412c250f},
 2296 {'8', 0x2a411b1c, 0x0e4f0e25},
 2297 {'8', 0xf5430022, 0xdf3df521},
 2298 {'l', 0x40c149e0, 0x40ee63a6},
 2299 {'8', 0x28b71adf, 0x0db00dd9},
 2300 {'8', 0xefa300cf, 0xcdb2efd4},
 2301 {'8', 0xb3ccdfde, 0xa1efd4ef},
 2302 {'8', 0xa312d000, 0xb334d412},
 2303 {'8', 0xcc50de22, 0xee60ee2d},
 2304 {'8', 0x17690038, 0x42511730},
 2305 {'8', 0x391e1a14, 0x3f0a1e0a},
 2306 {'q', 0x00000000, 0x418d3543},
 2307 {0, 0xc12abd00, 0x41ded19d},
 2308 {'q', 0xc12abd00, 0x412338b2},
 2309 {0, 0xc1ebb468, 0x4129aa17},
 2310 {'l', 0x00000000, 0xc1255e7f},
 2311 {'@', 0x00000041, 0x00005e06},/*        A        x-advance: 94.023438 */
 2312 {'M', 0x423beb62, 0xc2adb0f7},
 2313 {'4', 0x00c7ffb7, 0x00000093},
 2314 {'6', 0xff39ffb7, 0xffcbffe2},
 2315 {'l', 0x4175e7f4, 0x00000000},
 2316 {'l', 0x4218c06d, 0x42c86716},
 2317 {'l', 0xc16180d8, 0x00000000},
 2318 {'l', 0xc1120a50, 0xc1cda338},
 2319 {'l', 0xc234abd0, 0x00000000},
 2320 {'l', 0xc1120a4e, 0x41cda338},
 2321 {'l', 0xc164b98e, 0x00000000},
 2322 {'l', 0x42190527, 0xc2c86716},
 2323 {'[', 0x00410041, 0x000003d3},
 2324 {'@', 0x00000042, 0x00005e4b},/*        B        x-advance: 94.292969 */
 2325 {'M', 0x41d86037, 0xc23f68ce},
 2326 {'4', 0x00920000, 0x00000056},
 2327 {'8', 0xef40002b, 0xc915ee15},
 2328 {'8', 0xc9ebdb00, 0xefc0efec},
 2329 {'6', 0x0000ffaa, 0xff5c0000},
 2330 {'4', 0x00780000, 0x00000050},
 2331 {'8', 0xf23b0027, 0xd313f113},
 2332 {'8', 0xd3ede200, 0xf1c5f1ed},
 2333 {'6', 0x0000ffb0, 0xffd4ffca},
 2334 {'l', 0x420a8603, 0x00000000},
 2335 {'8', 0x195f003e, 0x49211921},
 2336 {'8', 0x3aef2400, 0x1bce15ef},
 2337 {'8', 0x233e0827, 0x43161b16},
 2338 {'8', 0x52dc3500, 0x1d991ddc},
 2339 {'l', 0xc20fe482, 0x00000000},
 2340 {'l', 0x00000000, 0xc2c86716},
 2341 {'@', 0x00000043, 0x00005ff9},/*        C        x-advance: 95.972656 */
 2342 {'M', 0x42b10c07, 0xc2b8f769},
 2343 {'l', 0x00000000, 0x4164b990},
 2344 {'8', 0xdac6e7e5, 0xf4bff4e2},
 2345 {'q', 0xc189731c, 0x00000000},
 2346 {0, 0xc1d27843, 0x41289730},
 2347 {'q', 0xc1120a50, 0x41278450},
 2348 {0, 0xc1120a50, 0x41f2af40},
 2349 {'q', 0x00000000, 0x419e63a7},
 2350 {0, 0x41120a50, 0x41f2af40},
 2351 {'8', 0x29692924, 0xf4410022},
 2352 {'9', 0xfff4001f, 0xffda003a},
 2353 {'l', 0x00000000, 0x416293c2},
 2354 {'8', 0x1cc413e4, 0x09bd09e1},
 2355 {'q', 0xc1b60370, 0x34000000},
 2356 {0, 0xc20f5b10, 0xc15e4828},
 2357 {'q', 0xc151655c, 0xc15f5b10},
 2358 {0, 0xc151655c, 0xc21836fb},
 2359 {'q', 0x00000000, 0xc1c149e0},
 2360 {0, 0x4151655e, 0xc21836fa},
 2361 {'q', 0x4151655e, 0xc15f5b10},
 2362 {0, 0x420f5b10, 0xc15f5b10},
 2363 {'8', 0x09430023, 0x1c3b091f},
 2364 {'@', 0x00000044, 0x000069d6},/*        D        x-advance: 105.835938 */
 2365 {'M', 0x41d86037, 0xc2b21eed},
 2366 {'4', 0x01370000, 0x00000041},
 2367 {'q', 0x41a5e7f2, 0x00000000},
 2368 {0, 0x41f2af3e, 0xc11655e8},
 2369 {'q', 0x411aa180, 0xc11655e8},
 2370 {0, 0x411aa180, 0xc1ed50bf},
 2371 {'q', 0x00000000, 0xc1a112e8},
 2372 {0, 0xc11aa180, 0xc1ebb468},
 2373 {'9', 0xffdbffda, 0xffdbff87},
 2374 {'6', 0x0000ffbf, 0xffd4ffca},
 2375 {'l', 0x41ded19c, 0x00000000},
 2376 {'q', 0x41e90526, 0x00000000},
 2377 {0, 0x422b01b7, 0x41425cc8},
 2378 {'q', 0x4159fc90, 0x414149e0},
 2379 {0, 0x4159fc90, 0x421768ce},
 2380 {'q', 0x00000000, 0x41cf3f91},
 2381 {0, 0xc15b0f78, 0x421836fa},
 2382 {'9', 0x0030ffca, 0x0030ff56},
 2383 {'l', 0xc1ded19c, 0x00000000},
 2384 {'l', 0x00000000, 0xc2c86716},
 2385 {'@', 0x00000045, 0x000056d8},/*        E        x-advance: 86.843750 */
 2386 {'M', 0x4157d6c4, 0xc2c86716},
 2387 {'l', 0x427d6c3d, 0x00000000},
 2388 {'l', 0x00000000, 0x41368ce0},
 2389 {'l', 0xc24731d2, 0x00000000},
 2390 {'l', 0xb6000000, 0x41ed50c2},
 2391 {'l', 0x423edf5a, 0x00000000},
 2392 {'l', 0x00000000, 0x41368ce0},
 2393 {'l', 0xc23edf5a, 0x00000000},
 2394 {'l', 0xb6000000, 0x42113c22},
 2395 {'l', 0x424c06de, 0x35800000},
 2396 {'l', 0x00000000, 0x41368ce3},
 2397 {'l', 0xc28120a4, 0x00000000},
 2398 {'l', 0xb6800000, 0xc2c86716},
 2399 {'@', 0x00000046, 0x00004f0f},/*        F        x-advance: 79.058594 */
 2400 {'M', 0x4157d6c4, 0xc2c86716},
 2401 {'l', 0x426655e7, 0x00000000},
 2402 {'l', 0x00000000, 0x41368ce0},
 2403 {'l', 0xc2301b7c, 0x00000000},
 2404 {'l', 0xb6000000, 0x41ec3dda},
 2405 {'l', 0x421eed18, 0x00000000},
 2406 {'l', 0x00000000, 0x41368ce4},
 2407 {'l', 0xc21eed18, 0x00000000},
 2408 {'l', 0xb6000000, 0x423f68ce},
 2409 {'l', 0xc158e9aa, 0x00000000},
 2410 {'l', 0x00000000, 0xc2c86716},
 2411 {'@', 0x00000047, 0x00006a82},/*        G        x-advance: 106.507812 */
 2412 {'M', 0x42a39fc9, 0xc164b98e},
 2413 {'l', 0x00000000, 0xc1d74d51},
 2414 {'l', 0xc1b12e64, 0x00000000},
 2415 {'4', 0xffd40000, 0x0000008e},
 2416 {'l', 0x00000000, 0x422c149e},
 2417 {'8', 0x21bb16e1, 0x0bb00bdb},
 2418 {'q', 0xc1bbeb62, 0x34000000},
 2419 {0, 0xc2131d36, 0xc15b0f76},
 2420 {'q', 0xc1538b28, 0xc15c225c},
 2421 {0, 0xc1538b28, 0xc2190528},
 2422 {'q', 0x00000000, 0xc1c48294},
 2423 {0, 0x41538b2a, 0xc2190526},
 2424 {'q', 0x41549e12, 0xc15c2260},
 2425 {0, 0x42131d36, 0xc15c2260},
 2426 {'8', 0x094a0027, 0x1c410923},
 2427 {'l', 0x00000000, 0x4166df60},
 2428 {'8', 0xdac1e7e2, 0xf4b9f4df},
 2429 {'q', 0xc1931d34, 0x00000000},
 2430 {0, 0xc1dd3542, 0x41244b98},
 2431 {'q', 0xc1131d36, 0x41244b98},
 2432 {0, 0xc1131d36, 0x41f4d50c},
 2433 {'q', 0x00000000, 0x41a225cd},
 2434 {0, 0x41131d36, 0x41f44b99},
 2435 {'8', 0x296e2925, 0xfc33001c},
 2436 {'q', 0x40b46720, 0xbfa338b0},
 2437 {0, 0x412225d0, 0xc07920a4},
 2438 {'@', 0x00000048, 0x0000675b},/*        H        x-advance: 103.355469 */
 2439 {'M', 0x4157d6c4, 0xc2c86716},
 2440 {'l', 0x4158e9aa, 0x00000000},
 2441 {'l', 0x00000000, 0x42244b99},
 2442 {'l', 0x42450c06, 0x00000000},
 2443 {'l', 0x00000000, 0xc2244b99},
 2444 {'l', 0x4158e9a8, 0x00000000},
 2445 {'l', 0x00000000, 0x42c86716},
 2446 {'l', 0xc158e9a8, 0x00000000},
 2447 {'l', 0x00000000, 0xc23edf5b},
 2448 {'l', 0xc2450c06, 0x00000000},
 2449 {'l', 0xb6000000, 0x423edf5b},
 2450 {'l', 0xc158e9aa, 0x00000000},
 2451 {'l', 0x00000000, 0xc2c86716},
 2452 {'@', 0x00000049, 0x00002889},/*        I        x-advance: 40.535156 */
 2453 {'M', 0x4157d6c4, 0xc2c86716},
 2454 {'l', 0x4158e9aa, 0x00000000},
 2455 {'l', 0x00000000, 0x42c86716},
 2456 {'l', 0xc158e9aa, 0x00000000},
 2457 {'l', 0x00000000, 0xc2c86716},
 2458 {'@', 0x0000004a, 0x00002889},/*        J        x-advance: 40.535156 */
 2459 {'M', 0x4157d6c4, 0xc2c86716},
 2460 {'4', 0x00000036, 0x01740000},
 2461 {'8', 0x69e54800, 0x20a820e5},
 2462 {'4', 0x0000ffec, 0xffd30000},
 2463 {'l', 0x40874d50, 0x00000000},
 2464 {'8', 0xec320023, 0xb80eec0e},
 2465 {'l', 0x00000000, 0xc2ba7165},
 2466 {'@', 0x0000004b, 0x00005a22},/*        K        x-advance: 90.132812 */
 2467 {'M', 0x4157d6c4, 0xc2c86716},
 2468 {'l', 0x4158e9aa, 0x00000000},
 2469 {'l', 0x00000000, 0x4229655e},
 2470 {'l', 0x4233dda2, 0xc229655e},
 2471 {'l', 0x418b98ec, 0x00000000},
 2472 {'l', 0xc246ed1a, 0x423ad87b},
 2473 {'l', 0x42552784, 0x4255f5b1},
 2474 {'l', 0xc18ed19c, 0x00000000},
 2475 {'l', 0xc2407bb4, 0xc2410527},
 2476 {'l', 0xb6000000, 0x42410527},
 2477 {'l', 0xc158e9aa, 0x00000000},
 2478 {'l', 0x00000000, 0xc2c86716},
 2479 {'@', 0x0000004c, 0x00004c93},/*        L        x-advance: 76.574219 */
 2480 {'M', 0x4157d6c4, 0xc2c86716},
 2481 {'l', 0x4158e9aa, 0x00000000},
 2482 {'l', 0x00000000, 0x42b1957a},
 2483 {'l', 0x42432af4, 0xb6400000},
 2484 {'l', 0x00000000, 0x41368ce3},
 2485 {'l', 0xc279655f, 0x00000000},
 2486 {'l', 0x00000000, 0xc2c86716},
 2487 {'[', 0x0041004c, 0x00000327},
 2488 {'@', 0x0000004d, 0x00007697},/*        M        x-advance: 118.589844 */
 2489 {'M', 0x4157d6c4, 0xc2c86716},
 2490 {'l', 0x41a19c58, 0x00000000},
 2491 {'l', 0x41cc9054, 0x42886036},
 2492 {'l', 0x41cda336, 0xc2886036},
 2493 {'l', 0x41a19c5c, 0x00000000},
 2494 {'l', 0x00000000, 0x42c86716},
 2495 {'l', 0xc1538b30, 0x00000000},
 2496 {'l', 0x00000000, 0xc2aff920},
 2497 {'l', 0xc1ceb61c, 0x4289731c},
 2498 {'l', 0xc159fc94, 0x36800000},
 2499 {'l', 0xc1ceb61e, 0xc289731c},
 2500 {'l', 0x00000000, 0x42aff920},
 2501 {'l', 0xc1527844, 0x00000000},
 2502 {'l', 0x00000000, 0xc2c86716},
 2503 {'@', 0x0000004e, 0x000066d1},/*        N        x-advance: 102.816406 */
 2504 {'M', 0x4157d6c4, 0xc2c86716},
 2505 {'l', 0x41920a4f, 0x00000000},
 2506 {'l', 0x4231b7d6, 0x42a7a6a8},
 2507 {'l', 0x00000000, 0xc2a7a6a8},
 2508 {'l', 0x41527848, 0x00000000},
 2509 {'l', 0x00000000, 0x42c86716},
 2510 {'l', 0xc1920a50, 0x00000000},
 2511 {'l', 0xc231b7d6, 0xc2a7a6a8},
 2512 {'l', 0x00000000, 0x42a7a6a8},
 2513 {'l', 0xc1527844, 0x00000000},
 2514 {'l', 0x00000000, 0xc2c86716},
 2515 {'@', 0x0000004f, 0x00006c30},/*        O        x-advance: 108.187500 */
 2516 {'M', 0x4258a4f0, 0xc2b6036f},
 2517 {'q', 0xc16c3dd8, 0x00000000},
 2518 {0, 0xc1bbeb61, 0x41301b78},
 2519 {'q', 0xc10a8604, 0x41301b80},
 2520 {0, 0xc10a8604, 0x41f00000},
 2521 {'q', 0x00000000, 0x419768cf},
 2522 {0, 0x410a8604, 0x41ef768d},
 2523 {'8', 0x2c5d2c22, 0xd45d003b},
 2524 {'q', 0x410a8600, 0xc1301b7c},
 2525 {0, 0x410a8600, 0xc1ef768d},
 2526 {'q', 0x00000000, 0xc197f240},
 2527 {0, 0xc10a8600, 0xc1f00000},
 2528 {'9', 0xffd4ffde, 0xffd4ffa3},
 2529 {'m', 0x00000000, 0xc1301b80},
 2530 {'q', 0x41a89730, 0x00000000},
 2531 {0, 0x4206c3de, 0x416293c0},
 2532 {'q', 0x4149e110, 0x416180e0},
 2533 {0, 0x4149e110, 0x421768ce},
 2534 {'q', 0x00000000, 0x41bd87bc},
 2535 {0, 0xc149e110, 0x421768ce},
 2536 {'q', 0xc149e118, 0x416180dd},
 2537 {0, 0xc206c3de, 0x416180dd},
 2538 {'q', 0xc1a920a4, 0xb4c00000},
 2539 {0, 0xc2074d50, 0xc16180dc},
 2540 {'q', 0xc149e114, 0xc16180db},
 2541 {0, 0xc149e114, 0xc21768ce},
 2542 {'q', 0x00000000, 0xc1be112c},
 2543 {0, 0x4149e112, 0xc21768ce},
 2544 {'q', 0x414af3fa, 0xc16293c0},
 2545 {0, 0x42074d50, 0xc16293c0},
 2546 {'[', 0x002d004f, 0x000003d3},
 2547 {'@', 0x00000050, 0x000052e2},/*        P        x-advance: 82.882812 */
 2548 {'M', 0x41d86037, 0xc2b21eed},
 2549 {'4', 0x00960000, 0x00000044},
 2550 {'8', 0xed3a0025, 0xc914ed14},
 2551 {'8', 0xc9ecdd00, 0xedc6edec},
 2552 {'6', 0x0000ffbc, 0xffd4ffca},
 2553 {'l', 0x41f4d50c, 0x00000000},
 2554 {'8', 0x1e650043, 0x59221e22},
 2555 {'8', 0x59de3b00, 0x1e9b1ede},
 2556 {'l', 0xc1886037, 0x00000000},
 2557 {'l', 0x00000000, 0x422112e6},
 2558 {'l', 0xc158e9aa, 0x00000000},
 2559 {'l', 0x00000000, 0xc2c86716},
 2560 {'@', 0x00000051, 0x00006c30},/*        Q        x-advance: 108.187500 */
 2561 {'M', 0x4258a4f0, 0xc2b6036f},
 2562 {'q', 0xc16c3dd8, 0x00000000},
 2563 {0, 0xc1bbeb61, 0x41301b78},
 2564 {'q', 0xc10a8604, 0x41301b80},
 2565 {0, 0xc10a8604, 0x41f00000},
 2566 {'q', 0x00000000, 0x419768cf},
 2567 {0, 0x410a8604, 0x41ef768d},
 2568 {'8', 0x2c5d2c22, 0xd45d003b},
 2569 {'q', 0x410a8600, 0xc1301b7c},
 2570 {0, 0x410a8600, 0xc1ef768d},
 2571 {'q', 0x00000000, 0xc197f240},
 2572 {0, 0xc10a8600, 0xc1f00000},
 2573 {'9', 0xffd4ffde, 0xffd4ffa3},
 2574 {'m', 0x4197f240, 0x42b263a6},
 2575 {'4', 0x004e0047, 0x0000ffbf},
 2576 {'l', 0xc16d50bc, 0xc1805278},
 2577 {'8', 0x00f300f8, 0x00f800fc},
 2578 {'q', 0xc1a920a4, 0x00000000},
 2579 {0, 0xc2074d50, 0xc16180dc},
 2580 {'q', 0xc149e114, 0xc16293c1},
 2581 {0, 0xc149e114, 0xc21768ce},
 2582 {'q', 0x00000000, 0xc1be112c},
 2583 {0, 0x4149e112, 0xc21768ce},
 2584 {'q', 0x414af3fa, 0xc16293c0},
 2585 {0, 0x42074d50, 0xc16293c0},
 2586 {'q', 0x41a89730, 0x00000000},
 2587 {0, 0x4206c3de, 0x416293c0},
 2588 {'q', 0x4149e110, 0x416180e0},
 2589 {0, 0x4149e110, 0x421768ce},
 2590 {'q', 0x00000000, 0x418b98ea},
 2591 {0, 0xc0e180e0, 0x41eeed1a},
 2592 {'q', 0xc0df5b10, 0x4146a860},
 2593 {0, 0xc1a225cc, 0x419293c2},
 2594 {'[', 0x002d0051, 0x000003d3},
 2595 {'@', 0x00000052, 0x00005f80},/*        R        x-advance: 95.500000 */
 2596 {'M', 0x427406df, 0xc23beb62},
 2597 {'8', 0x19210511, 0x35211310},
 2598 {'4', 0x006d0037, 0x0000ffc6},
 2599 {'l', 0xc14d19c8, 0xc1cda338},
 2600 {'8', 0xcbdad8ed, 0xf3cef3ee},
 2601 {'l', 0xc16c3dda, 0x00000000},
 2602 {'l', 0x00000000, 0x4229655e},
 2603 {'4', 0x0000ffca, 0xfe700000},
 2604 {'l', 0x41f4d50c, 0x00000000},
 2605 {'8', 0x1c660044, 0x56211c21},
 2606 {'8', 0x3eef2500, 0x22cd18ef},
 2607 {'m', 0xc207d6c4, 0xc2285278},
 2608 {'4', 0x008e0000, 0x00000044},
 2609 {'8', 0xef3b0027, 0xcb14ee14},
 2610 {'8', 0xccecdd00, 0xefc5efed},
 2611 {'l', 0xc1886037, 0x00000000},
 2612 {'@', 0x00000053, 0x0000573f},/*        S        x-advance: 87.246094 */
 2613 {'M', 0x42931d35, 0xc2c1d354},
 2614 {'l', 0x00000000, 0x41538b28},
 2615 {'8', 0xeac6f2e2, 0xf9ccf9e5},
 2616 {'8', 0x11bc00d4, 0x30e911e9},
 2617 {'8', 0x280f1a00, 0x153c0d10},
 2618 {'l', 0x410301b8, 0x3fd6c3e0},
 2619 {'8', 0x28590b3c, 0x4d1c1c1c},
 2620 {'q', 0x00000000, 0x41690528},
 2621 {0, 0xc11cc750, 0x41b0a4f0},
 2622 {'q', 0xc11bb464, 0x40f08975},
 2623 {0, 0xc1e4b98c, 0x40f08975},
 2624 {'8', 0xfac400e4, 0xedbefae1},
 2625 {'l', 0x00000000, 0xc15f5b0f},
 2626 {'8', 0x1b401221, 0x093e091f},
 2627 {'8', 0xee47002e, 0xcc19ee19},
 2628 {'8', 0xd2eee300, 0xe8c5f0ef},
 2629 {'l', 0xc10414a0, 0xbfce2cc0},
 2630 {'8', 0xdba9f4c4, 0xb9e5e7e5},
 2631 {'8', 0xad25cb00, 0xe267e225},
 2632 {'8', 0x0539001c, 0x0f3b051d},
 2633 {'[', 0x00410053, 0x0000028c},
 2634 {'@', 0x00000054, 0x000053f5},/*        T        x-advance: 83.957031 */
 2635 {'M', 0xbece2cac, 0xc2c86716},
 2636 {'l', 0x42a987bb, 0x00000000},
 2637 {'l', 0x00000000, 0x41368ce0},
 2638 {'l', 0xc20e4828, 0x00000000},
 2639 {'l', 0x00000000, 0x42b1957a},
 2640 {'l', 0xc159fc90, 0x00000000},
 2641 {'l', 0x00000000, 0xc2b1957a},
 2642 {'l', 0xc20e4829, 0x00000000},
 2643 {'l', 0xb5b00000, 0xc1368ce0},
 2644 {'@', 0x00000055, 0x0000649a},/*        U        x-advance: 100.601562 */
 2645 {'M', 0x413f2414, 0xc2c86716},
 2646 {'4', 0x00000036, 0x00f30000},
 2647 {'8', 0x5c174000, 0x1c4b1c17},
 2648 {'8', 0xe44b0034, 0xa417e417},
 2649 {'4', 0xff0d0000, 0x00000036},
 2650 {'l', 0x00000000, 0x427a338b},
 2651 {'q', 0x00000000, 0x419cc74d},
 2652 {0, 0xc11bb468, 0x41ecc74c},
 2653 {'q', 0xc11aa180, 0x41200001},
 2654 {0, 0xc1e4b98e, 0x41200001},
 2655 {'q', 0xc197f240, 0xb4c00000},
 2656 {0, 0xc1e5cc74, 0xc1200000},
 2657 {'q', 0xc11aa180, 0xc11fffff},
 2658 {0, 0xc11aa180, 0xc1ecc74c},
 2659 {'l', 0x00000000, 0xc27a338b},
 2660 {'@', 0x00000056, 0x00005e06},/*        V        x-advance: 94.023438 */
 2661 {'M', 0x421d50c0, 0x00000000},
 2662 {'l', 0xc2190527, 0xc2c86716},
 2663 {'l', 0x416293c1, 0x00000000},
 2664 {'l', 0x41fdf5b2, 0x42a8b98e},
 2665 {'l', 0x41fe7f24, 0xc2a8b98e},
 2666 {'l', 0x416180d8, 0x00000000},
 2667 {'l', 0xc218c06d, 0x42c86716},
 2668 {'l', 0xc175e7f4, 0x00000000},
 2669 {'@', 0x00000057, 0x000087e7},/*        W        x-advance: 135.902344 */
 2670 {'M', 0x40920a4f, 0xc2c86716},
 2671 {'l', 0x415b0f76, 0x00000000},
 2672 {'l', 0x41a89731, 0x42a9655e},
 2673 {'l', 0x41a80dbe, 0xc2a9655e},
 2674 {'l', 0x4173c224, 0x00000000},
 2675 {'l', 0x41a89734, 0x42a9655e},
 2676 {'l', 0x41a80dbc, 0xc2a9655e},
 2677 {'l', 0x415c2260, 0x00000000},
 2678 {'l', 0xc1c957a0, 0x42c86716},
 2679 {'l', 0xc1886038, 0x00000000},
 2680 {'l', 0xc1a920a4, 0xc2adf5b1},
 2681 {'l', 0xc1aabcfe, 0x42adf5b1},
 2682 {'l', 0xc1886036, 0x00000000},
 2683 {'l', 0xc1c8ce2c, 0xc2c86716},
 2684 {'@', 0x00000058, 0x00005e29},/*        X        x-advance: 94.160156 */
 2685 {'M', 0x410a8603, 0xc2c86716},
 2686 {'l', 0x41690527, 0x00000000},
 2687 {'l', 0x41c731d3, 0x4214fe48},
 2688 {'l', 0x41c844b8, 0xc214fe48},
 2689 {'l', 0x41690528, 0x00000000},
 2690 {'l', 0xc200dbeb, 0x42407bb4},
 2691 {'l', 0x4209731d, 0x42505278},
 2692 {'l', 0xc1690528, 0x00000000},
 2693 {'l', 0xc1e180da, 0xc22a7844},
 2694 {'l', 0xc1e31d35, 0x422a7844},
 2695 {'l', 0xc16a180e, 0x00000000},
 2696 {'l', 0x420f1656, 0xc255f5b1},
 2697 {'l', 0xc1f9aa18, 0xc23ad87b},
 2698 {'@', 0x00000059, 0x000053f5},/*        Y        x-advance: 83.957031 */
 2699 {'M', 0xbe89731d, 0xc2c86716},
 2700 {'l', 0x41690527, 0x00000000},
 2701 {'l', 0x41de4829, 0x4224d50c},
 2702 {'l', 0x41dcabd0, 0xc224d50c},
 2703 {'l', 0x41690528, 0x00000000},
 2704 {'l', 0xc20dbeb6, 0x4251eed1},
 2705 {'l', 0x00000000, 0x423edf5b},
 2706 {'l', 0xc159fc90, 0x00000000},
 2707 {'l', 0x00000000, 0xc23edf5b},
 2708 {'l', 0xc20dbeb6, 0xc251eed1},
 2709 {'@', 0x0000005a, 0x00005e29},/*        Z        x-advance: 94.160156 */
 2710 {'M', 0x40f6fad8, 0xc2c86716},
 2711 {'l', 0x429d731c, 0x00000000},
 2712 {'l', 0x00000000, 0x41255e80},
 2713 {'l', 0xc27d6c3c, 0x429ce9aa},
 2714 {'l', 0x4281cc74, 0xb6400000},
 2715 {'l', 0x00000000, 0x41368ce3},
 2716 {'l', 0xc2a39fc8, 0x00000000},
 2717 {'l', 0xb6400000, 0xc1255e7f},
 2718 {'l', 0x427d6c3d, 0xc29ce9aa},
 2719 {'l', 0xc2773f91, 0x00000000},
 2720 {'l', 0x00000000, 0xc1368ce0},
 2721 {'@', 0x0000005b, 0x0000359f},/*        [        x-advance: 53.621094 */
 2722 {'M', 0x413cfe48, 0xc2d0dbeb},
 2723 {'l', 0x41e3a6a8, 0x00000000},
 2724 {'l', 0x00000000, 0x41198e98},
 2725 {'l', 0xc180dbeb, 0x00000000},
 2726 {'l', 0x00000000, 0x42ceb61f},
 2727 {'l', 0x4180dbeb, 0xb5800000},
 2728 {'l', 0x00000000, 0x41198e9b},
 2729 {'l', 0xc1e3a6a8, 0x00000000},
 2730 {'l', 0x00000000, 0xc2f519c5},
 2731 {'@', 0x0000005c, 0x00002e4f},/*       \         x-advance: 46.308594 */
 2732 {'M', 0x41368ce3, 0xc2c86716},
 2733 {'l', 0x420b98e9, 0x42e1e7f2},
 2734 {'l', 0xc1368ce4, 0xb5800000},
 2735 {'l', 0xc20b98e9, 0xc2e1e7f2},
 2736 {'l', 0x41368ce3, 0x00000000},
 2737 {'@', 0x0000005d, 0x0000359f},/*        ]        x-advance: 53.621094 */
 2738 {'M', 0x42273f92, 0xc2d0dbeb},
 2739 {'l', 0x00000000, 0x42f519c5},
 2740 {'l', 0xc1e3a6a8, 0x36000000},
 2741 {'l', 0xb5800000, 0xc1198e9b},
 2742 {'l', 0x41805278, 0x00000000},
 2743 {'l', 0x00000000, 0xc2ceb61f},
 2744 {'l', 0xc1805278, 0x00000000},
 2745 {'l', 0xb5800000, 0xc1198e98},
 2746 {'l', 0x41e3a6a8, 0x00000000},
 2747 {'@', 0x0000005e, 0x0000732a},/*        ^        x-advance: 115.164062 */
 2748 {'M', 0x42805278, 0xc2c86716},
 2749 {'l', 0x4211c596, 0x421587bb},
 2750 {'l', 0xc157d6c8, 0x00000000},
 2751 {'l', 0xc1ec3dd8, 0xc1d4149e},
 2752 {'l', 0xc1ec3ddb, 0x41d4149e},
 2753 {'l', 0xc157d6c3, 0x00000000},
 2754 {'l', 0x4211c595, 0xc21587bb},
 2755 {'l', 0x41527844, 0x00000000},
 2756 {'@', 0x0000005f, 0x000044b9},/*        _        x-advance: 68.722656 */
 2757 {'M', 0x428c225d, 0x41b68ce3},
 2758 {'l', 0x00000000, 0x41198e9a},
 2759 {'l', 0xc28ed19d, 0x00000000},
 2760 {'l', 0x36600000, 0xc1198e9a},
 2761 {'l', 0x428ed19d, 0x00000000},
 2762 {'@', 0x00000060, 0x000044b9},/*        `        x-advance: 68.722656 */
 2763 {'M', 0x41c50c07, 0xc2dbdda3},
 2764 {'0', 0x00d7644b, 0x00349ca9},
 2765 {'@', 0x00000061, 0x0000543a},/*        a        x-advance: 84.226562 */
 2766 {'M', 0x423c74d5, 0xc2172414},
 2767 {'8', 0x0dae00c5, 0x2ee90de9},
 2768 {'8', 0x29111a00, 0x0f2f0f11},
 2769 {'8', 0xe4410029, 0xb318e318},
 2770 {'4', 0xfff50000, 0x0000ffcf},
 2771 {'m', 0x41c50c06, 0xc0a338b8},
 2772 {'4', 0x00ab0000, 0x0000ffcf},
 2773 {'l', 0x00000000, 0xc1368ce3},
 2774 {'8', 0x28d61bf0, 0x0cc30ce7},
 2775 {'8', 0xe7b700d2, 0xbbe5e6e5},
 2776 {'8', 0xb421ce00, 0xe765e722},
 2777 {'4', 0x00000045, 0xfffc0000},
 2778 {'8', 0xcceade00, 0xeec2eeea},
 2779 {'8', 0x06ce00e7, 0x12d206e8},
 2780 {'l', 0x00000000, 0xc1368ce4},
 2781 {'8', 0xf134f61b, 0xfb31fb19},
 2782 {'8', 0x21610041, 0x66202120},
 2783 {'@', 0x00000062, 0x0000573f},/*        b        x-advance: 87.246094 */
 2784 {'M', 0x4285d354, 0xc216112e},
 2785 {'8', 0xabeaca00, 0xe1c3e1ea},
 2786 {'8', 0x1fc300d9, 0x55ea1eea},
 2787 {'8', 0x55163600, 0x1e3d1e16},
 2788 {'8', 0xe23d0027, 0xab16e116},
 2789 {'m', 0xc2280dbe, 0xc1d1eed2},
 2790 {'8', 0xd927e60f, 0xf338f317},
 2791 {'q', 0x415b0f74, 0x00000000},
 2792 {0, 0x41b1b7d6, 0x412df5b0},
 2793 {'q', 0x41097320, 0x412df5b4},
 2794 {0, 0x41097320, 0x41e4b990},
 2795 {'q', 0x00000000, 0x418dbeb6},
 2796 {0, 0xc1097320, 0x41e4b98e},
 2797 {'8', 0x2ba82bde, 0xf4c800df},
 2798 {'9', 0xfff3ffe9, 0xffd8ffd9},
 2799 {'l', 0x00000000, 0x41346716},
 2800 {'l', 0xc146a860, 0x00000000},
 2801 {'l', 0x00000000, 0xc2d0dbeb},
 2802 {'l', 0x4146a860, 0x00000000},
 2803 {'l', 0x00000000, 0x4222af3f},
 2804 {'@', 0x00000063, 0x00004b92},/*        c        x-advance: 75.570312 */
 2805 {'M', 0x4286180e, 0xc2909052},
 2806 {'l', 0x00000000, 0x4138b2ac},
 2807 {'8', 0xefd6f5ec, 0xfbd6fbec},
 2808 {'8', 0x1eb600d0, 0x55e61ee6},
 2809 {'8', 0x551a3700, 0x1e4a1e1a},
 2810 {'8', 0xfb2a0015, 0xef2afb15},
 2811 {'l', 0x00000000, 0x41368ce2},
 2812 {'8', 0x0ed609ec, 0x04d204ea},
 2813 {'q', 0xc187d6c4, 0x00000000},
 2814 {0, 0xc1d7d6c4, 0xc12abcfe},
 2815 {'q', 0xc1200000, 0xc12abcff},
 2816 {0, 0xc1200000, 0xc1e655e8},
 2817 {'q', 0xb5000000, 0xc1931d36},
 2818 {0, 0x412112e6, 0xc1e768d0},
 2819 {'8', 0xd66ed628, 0x042c0016},
 2820 {'q', 0x40adf5b0, 0x3f920a80},
 2821 {0, 0x41289734, 0x405f5b20},
 2822 {'@', 0x00000064, 0x0000573f},/*        d        x-advance: 87.246094 */
 2823 {'M', 0x4279aa18, 0xc27f0897},
 2824 {'l', 0x00000000, 0xc222af3f},
 2825 {'l', 0x41459578, 0x00000000},
 2826 {'4', 0x01a10000, 0x0000ffcf},
 2827 {'l', 0x00000000, 0xc1346716},
 2828 {'8', 0x28d91af1, 0x0cc80ce9},
 2829 {'q', 0xc159fc90, 0x34000000},
 2830 {0, 0xc1b1b7d7, 0xc12df5b0},
 2831 {'q', 0xc1086036, 0xc12df5b0},
 2832 {0, 0xc1086036, 0xc1e4b98e},
 2833 {'q', 0xb5000000, 0xc18dbeb6},
 2834 {0, 0x41086036, 0xc1e4b990},
 2835 {'8', 0xd558d522, 0x0d380021},
 2836 {'9', 0x000c0017, 0x00270027},
 2837 {'m', 0xc2285278, 0x41d1eed2},
 2838 {'8', 0x55163600, 0x1e3d1e16},
 2839 {'8', 0xe23d0027, 0xab16e116},
 2840 {'8', 0xabeaca00, 0xe1c3e1ea},
 2841 {'8', 0x1fc300d9, 0x55ea1eea},
 2842 {'@', 0x00000065, 0x00005490},/*        e        x-advance: 84.562500 */
 2843 {'M', 0x429a7f24, 0xc222af3f},
 2844 {'4', 0x00180000, 0x0000ff1d},
 2845 {'8', 0x4d1e3303, 0x1a4c1a1b},
 2846 {'8', 0xfa37001c, 0xec35fa1a},
 2847 {'l', 0x00000000, 0x413ad87b},
 2848 {'8', 0x11ca0be6, 0x05c805e5},
 2849 {'q', 0xc18fe482, 0x00000000},
 2850 {0, 0xc1e4301b, 0xc127844c},
 2851 {'q', 0xc127844a, 0xc127844b},
 2852 {0, 0xc127844a, 0xc1e293c2},
 2853 {'q', 0xb5000000, 0xc193a6a8},
 2854 {0, 0x411eed1a, 0xc1ea180e},
 2855 {'8', 0xd56bd527, 0x275f003c},
 2856 {'9', 0x00260023, 0x006a0023},
 2857 {'m', 0xc1459578, 0xc067f240},
 2858 {'8', 0xc0ead800, 0xe8c6e8ea},
 2859 {'8', 0x17be00d7, 0x41e417e8},
 2860 {'l', 0x42301b7e, 0xbd897200},
 2861 {'@', 0x00000066, 0x00003063},/*        f        x-advance: 48.386719 */
 2862 {'M', 0x424c06df, 0xc2d0dbeb},
 2863 {'4', 0x00290000, 0x0000ffd1},
 2864 {'8', 0x0adb00e6, 0x26f60af6},
 2865 {'0', 0x00511a00, 0x00af2600},
 2866 {'l', 0x00000000, 0x42832414},
 2867 {'l', 0xc146a85f, 0x00000000},
 2868 {'l', 0x00000000, 0xc2832414},
 2869 {'0', 0xda0000d1, 0xec00002f},
 2870 {'8', 0xb717ce00, 0xe94ae917},
 2871 {'l', 0x413ad87c, 0x00000000},
 2872 {'@', 0x00000067, 0x0000573f},/*        g        x-advance: 87.246094 */
 2873 {'M', 0x4279aa18, 0xc219d354},
 2874 {'8', 0xadeacb00, 0xe3c2e3ea},
 2875 {'8', 0x1dc200d9, 0x53ea1dea},
 2876 {'8', 0x52163500, 0x1d3e1d16},
 2877 {'8', 0xe33e0028, 0xae16e316},
 2878 {'m', 0x41459578, 0x41e90528},
 2879 {'q', 0x00000000, 0x41998e9a},
 2880 {0, 0xc1086038, 0x41e4b98e},
 2881 {'8', 0x259825de, 0xfdcf00e6},
 2882 {'9', 0xfffcffe9, 0xfff4ffd4},
 2883 {'l', 0x00000000, 0xc14036fb},
 2884 {'8', 0x112a0b15, 0x052b0515},
 2885 {'8', 0xe7480030, 0xb418e718},
 2886 {'l', 0x00000000, 0xc0c36fb0},
 2887 {'8', 0x27d91af1, 0x0dc70de9},
 2888 {'8', 0xd6a700c9, 0x91dfd6df},
 2889 {'8', 0x9121bb00, 0xd659d621},
 2890 {'8', 0x0d390021, 0x27270d17},
 2891 {'l', 0x00000000, 0xc1368ce4},
 2892 {'l', 0x41459578, 0x00000000},
 2893 {'l', 0x00000000, 0x4283ad88},
 2894 {'@', 0x00000068, 0x0000571d},/*        h        x-advance: 87.113281 */
 2895 {'M', 0x4296df5b, 0xc23579fc},
 2896 {'4', 0x00b50000, 0x0000ffcf},
 2897 {'l', 0x00000000, 0xc233dda3},
 2898 {'8', 0xc1f0d600, 0xebcfebf0},
 2899 {'8', 0x19c100d8, 0x45e919e9},
 2900 {'l', 0x00000000, 0x4229eed1},
 2901 {'l', 0xc146a860, 0x00000000},
 2902 {'4', 0xfe5f0000, 0x00000031},
 2903 {'l', 0x00000000, 0x4223c225},
 2904 {'8', 0xd829e511, 0xf337f318},
 2905 {'8', 0x204e0033, 0x5e1a1f1a},
 2906 {'@', 0x00000069, 0x00002630},/*        i        x-advance: 38.187500 */
 2907 {'M', 0x414f3f92, 0xc29655e8},
 2908 {'l', 0x4145957a, 0x00000000},
 2909 {'4', 0x012c0000, 0x0000ffcf},
 2910 {'6', 0xfed40000, 0xff8b0000},
 2911 {'0', 0x3e000031, 0xc20000cf},
 2912 {'@', 0x0000006a, 0x00002630},/*        j        x-advance: 38.187500 */
 2913 {'M', 0x414f3f92, 0xc29655e8},
 2914 {'4', 0x00000031, 0x01320000},
 2915 {'8', 0x53ea3900, 0x19ba19eb},
 2916 {'4', 0x0000ffee, 0xffd70000},
 2917 {'l', 0x40527845, 0x00000000},
 2918 {'8', 0xf426001c, 0xca0af30a},
 2919 {'6', 0xfece0000, 0xff8b0000},
 2920 {'0', 0x3e000031, 0xc20000cf},
 2921 {'@', 0x0000006b, 0x00004f98},/*        k        x-advance: 79.593750 */
 2922 {'M', 0x4147bb46, 0xc2d0dbeb},
 2923 {'l', 0x4146a860, 0x00000000},
 2924 {'l', 0x00000000, 0x4276b61e},
 2925 {'l', 0x421361ee, 0xc201aa18},
 2926 {'l', 0x417c5958, 0x00000000},
 2927 {'l', 0xc21f768d, 0x420cabd0},
 2928 {'l', 0x42262cab, 0x42200000},
 2929 {'l', 0xc180dbea, 0x00000000},
 2930 {'l', 0xc218c06e, 0xc212d87b},
 2931 {'l', 0x36000000, 0x4212d87b},
 2932 {'l', 0xc146a860, 0x00000000},
 2933 {'l', 0x00000000, 0xc2d0dbeb},
 2934 {'@', 0x0000006c, 0x00002630},/*        l        x-advance: 38.187500 */
 2935 {'M', 0x414f3f92, 0xc2d0dbeb},
 2936 {'l', 0x4145957a, 0x00000000},
 2937 {'l', 0x00000000, 0x42d0dbeb},
 2938 {'l', 0xc145957a, 0x00000000},
 2939 {'l', 0x00000000, 0xc2d0dbeb},
 2940 {'@', 0x0000006d, 0x000085e4},/*        m        x-advance: 133.890625 */
 2941 {'M', 0x428ef3f9, 0xc272f3f9},
 2942 {'8', 0xcf2cdf12, 0xf13cf119},
 2943 {'8', 0x2148002e, 0x5d192019},
 2944 {'4', 0x00b50000, 0x0000ffcf},
 2945 {'l', 0x00000000, 0xc233dda3},
 2946 {'8', 0xc0f1d500, 0xecd2ecf1},
 2947 {'8', 0x19c400da, 0x45ea19ea},
 2948 {'4', 0x00a90000, 0x0000ffcf},
 2949 {'l', 0x00000000, 0xc233dda3},
 2950 {'8', 0xc0f1d500, 0xecd1ecf1},
 2951 {'8', 0x19c400db, 0x45ea19ea},
 2952 {'l', 0x00000000, 0x4229eed1},
 2953 {'l', 0xc146a860, 0x00000000},
 2954 {'4', 0xfed40000, 0x00000031},
 2955 {'l', 0x00000000, 0x413ad87c},
 2956 {'8', 0xd828e510, 0xf338f317},
 2957 {'8', 0x10370020, 0x30221017},
 2958 {'@', 0x0000006e, 0x0000571d},/*        n        x-advance: 87.113281 */
 2959 {'M', 0x4296df5b, 0xc23579fc},
 2960 {'4', 0x00b50000, 0x0000ffcf},
 2961 {'l', 0x00000000, 0xc233dda3},
 2962 {'8', 0xc1f0d600, 0xebcfebf0},
 2963 {'8', 0x19c100d8, 0x45e919e9},
 2964 {'l', 0x00000000, 0x4229eed1},
 2965 {'l', 0xc146a860, 0x00000000},
 2966 {'4', 0xfed40000, 0x00000031},
 2967 {'l', 0x00000000, 0x413ad87c},
 2968 {'8', 0xd829e511, 0xf337f318},
 2969 {'8', 0x204e0033, 0x5e1a1f1a},
 2970 {'@', 0x0000006f, 0x00005418},/*        o        x-advance: 84.093750 */
 2971 {'M', 0x42285278, 0xc2850527},
 2972 {'8', 0x1fc200d9, 0x54e91ee9},
 2973 {'8', 0x55163500, 0x1e3f1e17},
 2974 {'8', 0xe13e0027, 0xac17e117},
 2975 {'8', 0xace9cb00, 0xe1c2e1e9},
 2976 {'m', 0x00000000, 0xc1278450},
 2977 {'q', 0x4180dbec, 0x00000000},
 2978 {0, 0x41ca6a84, 0x41278450},
 2979 {'q', 0x41131d38, 0x41278448},
 2980 {0, 0x41131d38, 0x41e7f240},
 2981 {'q', 0x00000000, 0x4193a6a8},
 2982 {0, 0xc1131d38, 0x41e7f240},
 2983 {'8', 0x299b29dc, 0xd79b00c0},
 2984 {'q', 0xc1120a4e, 0xc1289731},
 2985 {0, 0xc1120a4e, 0xc1e7f240},
 2986 {'q', 0xb5000000, 0xc194301c},
 2987 {0, 0x41120a4e, 0xc1e7f240},
 2988 {'q', 0x41131d36, 0xc1278450},
 2989 {0, 0x41caf3f9, 0xc1278450},
 2990 {'[', 0x002d006f, 0x0000028c},
 2991 {'@', 0x00000070, 0x0000573f},/*        p        x-advance: 87.246094 */
 2992 {'M', 0x41c731d3, 0xc1346716},
 2993 {'l', 0x00000000, 0x421f768c},
 2994 {'l', 0xc146a860, 0x36000000},
 2995 {'4', 0xfe610000, 0x00000031},
 2996 {'l', 0x00000000, 0x41368ce4},
 2997 {'8', 0xd927e60f, 0xf338f317},
 2998 {'q', 0x415b0f74, 0x00000000},
 2999 {0, 0x41b1b7d6, 0x412df5b0},
 3000 {'q', 0x41097320, 0x412df5b4},
 3001 {0, 0x41097320, 0x41e4b990},
 3002 {'q', 0x00000000, 0x418dbeb6},
 3003 {0, 0xc1097320, 0x41e4b98e},
 3004 {'8', 0x2ba82bde, 0xf4c800df},
 3005 {'9', 0xfff3ffe9, 0xffd8ffd9},
 3006 {'m', 0x42280dbe, 0xc1d1eed1},
 3007 {'8', 0xabeaca00, 0xe1c3e1ea},
 3008 {'8', 0x1fc300d9, 0x55ea1eea},
 3009 {'8', 0x55163600, 0x1e3d1e16},
 3010 {'8', 0xe23d0027, 0xab16e116},
 3011 {'@', 0x00000071, 0x0000573f},/*        q        x-advance: 87.246094 */
 3012 {'M', 0x41a2af3f, 0xc216112e},
 3013 {'8', 0x55163600, 0x1e3d1e16},
 3014 {'8', 0xe23d0027, 0xab16e116},
 3015 {'8', 0xabeaca00, 0xe1c3e1ea},
 3016 {'8', 0x1fc300d9, 0x55ea1eea},
 3017 {'m', 0x42285278, 0x41d1eed1},
 3018 {'8', 0x28d91af1, 0x0cc80ce9},
 3019 {'q', 0xc159fc90, 0x34000000},
 3020 {0, 0xc1b1b7d7, 0xc12df5b0},
 3021 {'q', 0xc1086036, 0xc12df5b0},
 3022 {0, 0xc1086036, 0xc1e4b98e},
 3023 {'q', 0xb5000000, 0xc18dbeb6},
 3024 {0, 0x41086036, 0xc1e4b990},
 3025 {'8', 0xd558d522, 0x0d380021},
 3026 {'9', 0x000c0017, 0x00270027},
 3027 {'l', 0x00000000, 0xc1368ce4},
 3028 {'l', 0x41459578, 0x00000000},
 3029 {'l', 0x00000000, 0x42cf844c},
 3030 {'l', 0xc1459578, 0xb6800000},
 3031 {'l', 0x00000000, 0xc21f768c},
 3032 {'@', 0x00000072, 0x00003882},/*        r        x-advance: 56.507812 */
 3033 {'M', 0x42620a4f, 0xc27e7f24},
 3034 {'8', 0xfaeefcf8, 0xfeebfef7},
 3035 {'8', 0x1bc000d7, 0x4eea1bea},
 3036 {'l', 0x00000000, 0x421e63a6},
 3037 {'l', 0xc146a860, 0x00000000},
 3038 {'4', 0xfed40000, 0x00000031},
 3039 {'l', 0x00000000, 0x413ad87c},
 3040 {'8', 0xd828e50f, 0xf33cf318},
 3041 {'8', 0x000b0005, 0x010d0006},
 3042 {'l', 0x3d897400, 0x414af3f8},
 3043 {'@', 0x00000073, 0x0000479c},/*        s        x-advance: 71.609375 */
 3044 {'M', 0x42737d6c, 0xc291e7f2},
 3045 {'l', 0x00000000, 0x413ad87c},
 3046 {'8', 0xf0d5f6ec, 0xfbd2fbea},
 3047 {'8', 0x0bc900dc, 0x21ee0bee},
 3048 {'8', 0x1b0d1100, 0x1234090d},
 3049 {'l', 0x40874d50, 0x3f708980},
 3050 {'8', 0x1f4a0b34, 0x39161416},
 3051 {'8', 0x42df2900, 0x18a518df},
 3052 {'8', 0xfcce00e8, 0xf2c9fce6},
 3053 {'l', 0x00000000, 0xc14c06df},
 3054 {'8', 0x15350e1b, 0x0634061a},
 3055 {'8', 0xf5350022, 0xdf12f412},
 3056 {'8', 0xe2f3ec00, 0xecc5f6f3},
 3057 {'l', 0xc0897320, 0xbf80dbe0},
 3058 {'8', 0xe3bef7d3, 0xc9ececec},
 3059 {'8', 0xbf1ed600, 0xe955e91e},
 3060 {'8', 0x0433001b, 0x0c2c0418},
 3061 {'@', 0x00000074, 0x000035e4},/*        t        x-advance: 53.890625 */
 3062 {'M', 0x41c9579f, 0xc2c10527},
 3063 {'0', 0x00655500, 0x009b2600},
 3064 {'l', 0x00000000, 0x422338b2},
 3065 {'8', 0x2f092400, 0x0a290a0a},
 3066 {'4', 0x00000032, 0x00290000},
 3067 {'l', 0xc14af3f8, 0x00000000},
 3068 {'8', 0xebb200c7, 0xb3ebebeb},
 3069 {'l', 0x00000000, 0xc22338b2},
 3070 {'0', 0xda0000dc, 0xab000024},
 3071 {'l', 0x4146a85f, 0x00000000},
 3072 {'@', 0x00000075, 0x0000571d},/*        u        x-advance: 87.113281 */
 3073 {'M', 0x413ad87b, 0xc1ed50c0},
 3074 {'4', 0xff4a0000, 0x00000031},
 3075 {'l', 0x00000000, 0x4234225d},
 3076 {'8', 0x40102a00, 0x15311510},
 3077 {'8', 0xe73f0028, 0xbb17e717},
 3078 {'l', 0x00000000, 0xc22a7845},
 3079 {'l', 0x41459574, 0x00000000},
 3080 {'4', 0x012c0000, 0x0000ffcf},
 3081 {'l', 0x00000000, 0xc138b2af},
 3082 {'8', 0x28d71bef, 0x0dc90de9},
 3083 {'8', 0xe0b200cd, 0xa2e6e0e6},
 3084 {'m', 0x41f89732, 0xc23d4302},
 3085 {'l', 0x00000000, 0x00000000},
 3086 {'@', 0x00000076, 0x00005157},/*        v        x-advance: 81.339844 */
 3087 {'M', 0x408301b8, 0xc29655e8},
 3088 {'l', 0x4151655e, 0x00000000},
 3089 {'l', 0x41bbeb61, 0x427c5958},
 3090 {'l', 0x41bbeb62, 0xc27c5958},
 3091 {'l', 0x41516560, 0x00000000},
 3092 {'l', 0xc1e180dc, 0x429655e8},
 3093 {'l', 0xc1863a6a, 0x00000000},
 3094 {'l', 0xc1e180dc, 0xc29655e8},
 3095 {'@', 0x00000077, 0x0000706a},/*        w        x-advance: 112.414062 */
 3096 {'M', 0x40b8b2af, 0xc29655e8},
 3097 {'l', 0x4145957a, 0x00000000},
 3098 {'l', 0x4176fad6, 0x426aa181},
 3099 {'l', 0x4175e7f4, 0xc26aa181},
 3100 {'l', 0x41690528, 0x00000000},
 3101 {'l', 0x4176fad4, 0x426aa181},
 3102 {'l', 0x4175e7f8, 0xc26aa181},
 3103 {'l', 0x41459578, 0x00000000},
 3104 {'l', 0xc19d50c0, 0x429655e8},
 3105 {'l', 0xc1690528, 0x00000000},
 3106 {'l', 0xc1816560, 0xc2767165},
 3107 {'l', 0xc181eed0, 0x42767165},
 3108 {'l', 0xc1690528, 0x00000000},
 3109 {'l', 0xc19d50c0, 0xc29655e8},
 3110 {'@', 0x00000078, 0x00005157},/*        x        x-advance: 81.339844 */
 3111 {'M', 0x4296df5b, 0xc29655e8},
 3112 {'l', 0xc1d9731e, 0x42124f09},
 3113 {'l', 0x41e4b98e, 0x421a5cc7},
 3114 {'l', 0xc1690524, 0x00000000},
 3115 {'l', 0xc1af0898, 0xc1ec3dda},
 3116 {'l', 0xc1af0897, 0x41ec3dda},
 3117 {'l', 0xc1690527, 0x00000000},
 3118 {'l', 0x41e98e9a, 0xc21d50c0},
 3119 {'l', 0xc1d5b0f7, 0xc20f5b10},
 3120 {'0', 0x6b4f003a, 0x003a954f},
 3121 {'@', 0x00000079, 0x00005157},/*        y        x-advance: 81.339844 */
 3122 {'M', 0x4230e9aa, 0x40df5b0f},
 3123 {'8', 0x46d835ec, 0x10cb10ed},
 3124 {'4', 0x0000ffd9, 0xffd70000},
 3125 {'l', 0x40e7f242, 0x00000000},
 3126 {'8', 0xf71f0014, 0xd318f70b},
 3127 {'l', 0x400dbeb0, 0xc0b46716},
 3128 {'l', 0xc1f338b2, 0xc293eb62},
 3129 {'l', 0x4151655e, 0x00000000},
 3130 {'l', 0x41bbeb61, 0x426b2af4},
 3131 {'l', 0x41bbeb62, 0xc26b2af4},
 3132 {'l', 0x41516560, 0x00000000},
 3133 {'l', 0xc204149e, 0x42a44b99},
 3134 {'@', 0x0000007a, 0x00004825},/*        z        x-advance: 72.144531 */
 3135 {'M', 0x40f2af3f, 0xc29655e8},
 3136 {'l', 0x426aa180, 0x00000000},
 3137 {'l', 0x00000000, 0x41346718},
 3138 {'l', 0xc239c595, 0x42581b7d},
 3139 {'l', 0x4239c595, 0x35800000},
 3140 {'l', 0x00000000, 0x411dda33},
 3141 {'l', 0xc271579f, 0x00000000},
 3142 {'l', 0x00000000, 0xc1346716},
 3143 {'l', 0x4239c595, 0xc2581b7c},
 3144 {'l', 0xc2330f76, 0x00000000},
 3145 {'l', 0xb5000000, 0xc11dda38},
 3146 {'@', 0x0000007b, 0x00005773},/*        {        x-advance: 87.449219 */
 3147 {'M', 0x428c8973, 0x414c06df},
 3148 {'4', 0x00260000, 0x0000fff0},
 3149 {'8', 0xeda700be, 0xb1eaedea},
 3150 {'l', 0x00000000, 0xc1805278},
 3151 {'8', 0xc8f2d800, 0xf1ccf1f2},
 3152 {'4', 0x0000fff0, 0xffda0000},
 3153 {'l', 0x408301b8, 0x00000000},
 3154 {'8', 0xf1340026, 0xc90ef10e},
 3155 {'l', 0x00000000, 0xc180dbec},
 3156 {'8', 0xb216c500, 0xed59ed16},
 3157 {'4', 0x00000010, 0x00260000},
 3158 {'l', 0xc0920a50, 0x00000000},
 3159 {'8', 0x0bcf00db, 0x31f50bf5},
 3160 {'l', 0x00000000, 0x41852786},
 3161 {'8', 0x3df42a00, 0x19d713f4},
 3162 {'8', 0x1a29071d, 0x3c0c130c},
 3163 {'l', 0x00000000, 0x41852785},
 3164 {'8', 0x310b2500, 0x0b310b0b},
 3165 {'l', 0x40920a50, 0x00000000},
 3166 {'@', 0x0000007c, 0x00002e4f},/*        |        x-advance: 46.308594 */
 3167 {'M', 0x41e6df5b, 0xc2d2112e},
 3168 {'l', 0x00000000, 0x4309731d},
 3169 {'l', 0xc1368ce4, 0x00000000},
 3170 {'l', 0x00000000, 0xc309731d},
 3171 {'l', 0x41368ce4, 0x00000000},
 3172 {'@', 0x0000007d, 0x00005773},/*        }        x-advance: 87.449219 */
 3173 {'M', 0x4189731d, 0x414c06df},
 3174 {'l', 0x409655e8, 0x00000000},
 3175 {'8', 0xf5300025, 0xcf0bf50b},
 3176 {'l', 0x00000000, 0xc1852784},
 3177 {'8', 0xc40cd700, 0xe629ed0c},
 3178 {'8', 0xe7d7fae3, 0xc3f4edf4},
 3179 {'l', 0x00000000, 0xc1852786},
 3180 {'8', 0xcff5da00, 0xf5d0f5f5},
 3181 {'4', 0x0000ffee, 0xffda0000},
 3182 {'l', 0x40874d50, 0x00000000},
 3183 {'8', 0x13590042, 0x4e161316},
 3184 {'l', 0x00000000, 0x4180dbec},
 3185 {'8', 0x370e2800, 0x0f340f0e},
 3186 {'4', 0x00000010, 0x00260000},
 3187 {'l', 0xc0852780, 0x00000000},
 3188 {'8', 0x0fcc00da, 0x38f20ff2},
 3189 {'l', 0x00000000, 0x41805278},
 3190 {'8', 0x4fea3b00, 0x13a713ea},
 3191 {'l', 0xc0874d50, 0x00000000},
 3192 {'l', 0x00000000, 0xc11aa181},
 3193 {'@', 0x0000007e, 0x0000732a},/*        ~        x-advance: 115.164062 */
 3194 {'M', 0x42c93543, 0xc25b5430},
 3195 {'l', 0x00000000, 0x413f2414},
 3196 {'8', 0x1ecc15e4, 0x09cf09e9},
 3197 {'8', 0xf1bc00e3, 0xfffcfffe},
 3198 {'8', 0xfefb00ff, 0xf0bef0d7},
 3199 {'8', 0x0ad200e9, 0x20cf0ae9},
 3200 {'l', 0x00000000, 0xc13f2414},
 3201 {'8', 0xe234eb1c, 0xf732f718},
 3202 {'8', 0x1044001d, 0x01040102},
 3203 {'8', 0x02050002, 0x10421029},
 3204 {'8', 0xf62d0017, 0xe032f616},
 3205 };
 3206 #define CTX_FONT_ascii 1
 3207 #endif
 3208 #endif //_CTX_INTERNAL_FONT_
 3209 #ifndef __CTX_LIST__
 3210 #define __CTX_LIST__
 3211 
 3212 #include <stdlib.h>
 3213 
 3214 /* The whole ctx_list implementation is in the header and will be inlined
 3215  * wherever it is used.
 3216  */
 3217 
 3218 static inline void *ctx_calloc (size_t size, size_t count)
 3219 {
 3220   size_t byte_size = size * count;
 3221   char *ret = (char*)malloc (byte_size);
 3222   for (size_t i = 0; i < byte_size; i++)
 3223      ret[i] = 0;
 3224   return ret;
 3225 }
 3226 
 3227 typedef struct _CtxList CtxList;
 3228 struct _CtxList {
 3229   void *data;
 3230   CtxList *next;
 3231   void (*freefunc)(void *data, void *freefunc_data);
 3232   void *freefunc_data;
 3233 };
 3234 
 3235 static inline void ctx_list_prepend_full (CtxList **list, void *data,
 3236     void (*freefunc)(void *data, void *freefunc_data),
 3237     void *freefunc_data)
 3238 {
 3239   CtxList *new_= (CtxList*)ctx_calloc (sizeof (CtxList), 1);
 3240   new_->next = *list;
 3241   new_->data=data;
 3242   new_->freefunc=freefunc;
 3243   new_->freefunc_data = freefunc_data;
 3244   *list = new_;
 3245 }
 3246 
 3247 static inline int ctx_list_length (CtxList *list)
 3248 {
 3249   int length = 0;
 3250   CtxList *l;
 3251   for (l = list; l; l = l->next, length++);
 3252   return length;
 3253 }
 3254 
 3255 static inline void ctx_list_prepend (CtxList **list, void *data)
 3256 {
 3257   CtxList *new_ = (CtxList*) ctx_calloc (sizeof (CtxList), 1);
 3258   new_->next= *list;
 3259   new_->data=data;
 3260   *list = new_;
 3261 }
 3262 
 3263 static inline CtxList *ctx_list_nth (CtxList *list, int no)
 3264 {
 3265   while (no-- && list)
 3266     { list = list->next; }
 3267   return list;
 3268 }
 3269 
 3270 static inline void *ctx_list_nth_data (CtxList *list, int no)
 3271 {
 3272   CtxList *l = ctx_list_nth (list, no);
 3273   if (l)
 3274     return l->data;
 3275   return NULL;
 3276 }
 3277 
 3278 
 3279 static inline void
 3280 ctx_list_insert_before (CtxList **list, CtxList *sibling,
 3281                        void *data)
 3282 {
 3283   if (*list == NULL || *list == sibling)
 3284     {
 3285       ctx_list_prepend (list, data);
 3286     }
 3287   else
 3288     {
 3289       CtxList *prev = NULL;
 3290       for (CtxList *l = *list; l; l=l->next)
 3291         {
 3292           if (l == sibling)
 3293             { break; }
 3294           prev = l;
 3295         }
 3296       if (prev)
 3297         {
 3298           CtxList *new_ = (CtxList*)ctx_calloc (sizeof (CtxList), 1);
 3299           new_->next = sibling;
 3300           new_->data = data;
 3301           prev->next=new_;
 3302         }
 3303     }
 3304 }
 3305 
 3306 static inline void ctx_list_remove_link (CtxList **list, CtxList *link)
 3307 {
 3308   CtxList *iter, *prev = NULL;
 3309   if ((*list) == link)
 3310     {
 3311       prev = (*list)->next;
 3312       *list = prev;
 3313       link->next = NULL;
 3314       return;
 3315     }
 3316   for (iter = *list; iter; iter = iter->next)
 3317     if (iter == link)
 3318       {
 3319         if (prev)
 3320           prev->next = iter->next;
 3321         link->next = NULL;
 3322         return;
 3323       }
 3324     else
 3325       prev = iter;
 3326 }
 3327 
 3328 static inline void ctx_list_remove (CtxList **list, void *data)
 3329 {
 3330   CtxList *iter, *prev = NULL;
 3331   if ((*list)->data == data)
 3332     {
 3333       if ((*list)->freefunc)
 3334         (*list)->freefunc ((*list)->data, (*list)->freefunc_data);
 3335       prev = (*list)->next;
 3336       free (*list);
 3337       *list = prev;
 3338       return;
 3339     }
 3340   for (iter = *list; iter; iter = iter->next)
 3341     if (iter->data == data)
 3342       {
 3343         if (iter->freefunc)
 3344           iter->freefunc (iter->data, iter->freefunc_data);
 3345         prev->next = iter->next;
 3346         free (iter);
 3347         break;
 3348       }
 3349     else
 3350       prev = iter;
 3351 }
 3352 
 3353 static inline void ctx_list_free (CtxList **list)
 3354 {
 3355   while (*list)
 3356     ctx_list_remove (list, (*list)->data);
 3357 }
 3358 
 3359 static inline void
 3360 ctx_list_reverse (CtxList **list)
 3361 {
 3362   CtxList *new_ = NULL;
 3363   CtxList *l;
 3364   for (l = *list; l; l=l->next)
 3365     ctx_list_prepend (&new_, l->data);
 3366   ctx_list_free (list);
 3367   *list = new_;
 3368 }
 3369 
 3370 static inline void *ctx_list_last (CtxList *list)
 3371 {
 3372   if (list)
 3373     {
 3374       CtxList *last;
 3375       for (last = list; last->next; last=last->next);
 3376       return last->data;
 3377     }
 3378   return NULL;
 3379 }
 3380 
 3381 static inline void ctx_list_concat (CtxList **list, CtxList *list_b)
 3382 {
 3383   if (*list)
 3384     {
 3385       CtxList *last;
 3386       for (last = *list; last->next; last=last->next);
 3387       last->next = list_b;
 3388       return;
 3389     }
 3390   *list = list_b;
 3391 }
 3392 
 3393 static inline void ctx_list_append_full (CtxList **list, void *data,
 3394     void (*freefunc)(void *data, void *freefunc_data),
 3395     void *freefunc_data)
 3396 {
 3397   CtxList *new_ = (CtxList*) ctx_calloc (sizeof (CtxList), 1);
 3398   new_->data=data;
 3399   new_->freefunc = freefunc;
 3400   new_->freefunc_data = freefunc_data;
 3401   ctx_list_concat (list, new_);
 3402 }
 3403 
 3404 static inline void ctx_list_append (CtxList **list, void *data)
 3405 {
 3406   ctx_list_append_full (list, data, NULL, NULL);
 3407 }
 3408 
 3409 static inline void
 3410 ctx_list_insert_at (CtxList **list,
 3411                     int       no,
 3412                     void     *data)
 3413 {
 3414   if (*list == NULL || no == 0)
 3415     {
 3416       ctx_list_prepend (list, data);
 3417     }
 3418   else
 3419     {
 3420       int pos = 0;
 3421       CtxList *prev = NULL;
 3422       CtxList *sibling = NULL;
 3423       for (CtxList *l = *list; l && pos < no; l=l->next)
 3424         {
 3425           prev = sibling;
 3426           sibling = l;
 3427           pos ++;
 3428         }
 3429       if (prev)
 3430         {
 3431           CtxList *new_ = (CtxList*)ctx_calloc (sizeof (CtxList), 1);
 3432           new_->next = sibling;
 3433           new_->data = data;
 3434           prev->next=new_;
 3435           return;
 3436         }
 3437       ctx_list_append (list, data);
 3438     }
 3439 }
 3440 
 3441 static CtxList*
 3442 ctx_list_merge_sorted (CtxList* list1,
 3443                        CtxList* list2,
 3444     int(*compare)(const void *a, const void *b, void *userdata), void 
 3445         *userdata
 3446 )
 3447 {
 3448   if (list1 == NULL)
 3449      return(list2);
 3450   else if (list2==NULL)
 3451      return(list1);
 3452 
 3453   if (compare (list1->data, list2->data, userdata) >= 0)
 3454   {
 3455     list1->next = ctx_list_merge_sorted (list1->next,list2, compare, 
 3456                   userdata);
 3457     /*list1->next->prev = list1;
 3458       list1->prev = NULL;*/
 3459     return list1;
 3460   }
 3461   else
 3462   {
 3463     list2->next = ctx_list_merge_sorted (list1,list2->next, compare, 
 3464                   userdata);
 3465     /*list2->next->prev = list2;
 3466       list2->prev = NULL;*/
 3467     return list2;
 3468   }
 3469 }
 3470 
 3471 static void
 3472 ctx_list_split_half (CtxList*  head,
 3473                      CtxList** list1,
 3474                      CtxList** list2)
 3475 {
 3476   CtxList* fast;
 3477   CtxList* slow;
 3478   if (head==NULL || head->next==NULL)
 3479   {
 3480     *list1 = head;
 3481     *list2 = NULL;
 3482   }
 3483   else
 3484   {
 3485     slow = head;
 3486     fast = head->next;
 3487 
 3488     while (fast != NULL)
 3489     {
 3490       fast = fast->next;
 3491       if (fast != NULL)
 3492       {
 3493         slow = slow->next;
 3494         fast = fast->next;
 3495       }
 3496     }
 3497 
 3498     *list1 = head;
 3499     *list2 = slow->next;
 3500     slow->next = NULL;
 3501   }
 3502 }
 3503 
 3504 static inline void ctx_list_sort (CtxList **head,
 3505     int(*compare)(const void *a, const void *b, void *userdata),
 3506     void *userdata)
 3507 {
 3508   CtxList* list1;
 3509   CtxList* list2;
 3510 
 3511   /* Base case -- length 0 or 1 */
 3512   if ((*head == NULL) || ((*head)->next == NULL))
 3513   {
 3514     return;
 3515   }
 3516 
 3517   ctx_list_split_half (*head, &list1, &list2);
 3518   ctx_list_sort (&list1, compare, userdata);
 3519   ctx_list_sort (&list2, compare, userdata);
 3520   *head = ctx_list_merge_sorted (list1, list2, compare, userdata);
 3521 }
 3522 
 3523 static inline void ctx_list_insert_sorted (CtxList **list,
 3524                                            void     *item,
 3525     int(*compare)(const void *a, const void *b, void *userdata),
 3526                                            void     *userdata)
 3527 {
 3528   ctx_list_prepend (list, item);
 3529   ctx_list_sort (list, compare, userdata);
 3530 }
 3531 
 3532 
 3533 static inline CtxList *ctx_list_find_custom (CtxList *list,
 3534                                          void    *needle,
 3535                                          int(*compare)(const void *a, const 
 3536                                              void *b),
 3537                                          void *userdata)
 3538 {
 3539   CtxList *l;
 3540   for (l = list; l; l = l->next)
 3541   {
 3542     if (compare (l->data, needle) == 0)
 3543       return l;
 3544   }
 3545   return NULL;
 3546 }
 3547 
 3548 #endif
 3549 
 3550 /* definitions that determine which features are included and their 
 3551 settings,
 3552  * for particular platforms - in particular microcontrollers ctx might need
 3553  * tuning for different quality/performance/resource constraints.
 3554  *
 3555  * the way to configure ctx is to set these defines, before both including 
 3556  it
 3557  * as a header and in the file where CTX_IMPLEMENTATION is set to include 
 3558  the
 3559  * implementation for different featureset and runtime settings.
 3560  *
 3561  */
 3562 
 3563 /* whether the font rendering happens in backend or front-end of API, the
 3564  * option is used set to 0 by the tool that converts ttf fonts to ctx 
 3565  internal
 3566  * representation - both should be possible so that this tool can be made
 3567  * into a TTF/OTF font import at runtime (perhaps even with live subsetting)
 3568                                           .
 3569  */
 3570 #ifndef CTX_BACKEND_TEXT
 3571 #define CTX_BACKEND_TEXT 1
 3572 #endif
 3573 
 3574 /* force full antialising - turns of adaptive AA when set to 1 
 3575  */
 3576 #ifndef CTX_RASTERIZER_FORCE_AA
 3577 #define CTX_RASTERIZER_FORCE_AA  0
 3578 #endif
 3579 
 3580 /* when AA is not forced, the slope below which full AA get enabled.
 3581  */
 3582 
 3583 #define CTX_RASTERIZER_AA_SLOPE_LIMIT    (2125/CTX_SUBDIV/rasterizer->aa)
 3584 
 3585 #ifndef CTX_RASTERIZER_AA_SLOPE_DEBUG
 3586 #define CTX_RASTERIZER_AA_SLOPE_DEBUG 0
 3587 #endif
 3588 
 3589 
 3590 /* subpixel-aa coordinates used in BITPACKing of drawlist
 3591  */
 3592 #define CTX_SUBDIV   4 // higher gives higher quality, but 4096wide 
 3593 rendering
 3594                        // stops working
 3595 
 3596 // 8    12 68 40 24
 3597 // 16   12 68 40 24
 3598 /* scale-factor for font outlines prior to bit quantization by CTX_SUBDIV
 3599  *
 3600  * changing this also changes font file format - the value should be baked
 3601  * into the ctxf files making them less dependent on the ctx used to
 3602  * generate them
 3603  */
 3604 #define CTX_BAKE_FONT_SIZE    160
 3605 
 3606 /* pack some linetos/curvetos/movetos into denser drawlist instructions,
 3607  * permitting more vectors to be stored in the same space, experimental
 3608  * feature with added overhead.
 3609  */
 3610 #ifndef CTX_BITPACK
 3611 #define CTX_BITPACK           1
 3612 #endif
 3613 
 3614 /* whether we have a shape-cache where we keep pre-rasterized bitmaps of
 3615  * commonly occuring small shapes, disabled by default since it has some
 3616  * glitches (and potential hangs with multi threading).
 3617  */
 3618 #ifndef CTX_SHAPE_CACHE
 3619 #define CTX_SHAPE_CACHE        0
 3620 #endif
 3621 
 3622 /* size (in pixels, w*h) that we cache rasterization for
 3623  */
 3624 #ifndef CTX_SHAPE_CACHE_DIM
 3625 #define CTX_SHAPE_CACHE_DIM      (16*16)
 3626 #endif
 3627 
 3628 #ifndef CTX_SHAPE_CACHE_MAX_DIM
 3629 #define CTX_SHAPE_CACHE_MAX_DIM  32
 3630 #endif
 3631 
 3632 /* maximum number of entries in shape cache
 3633  */
 3634 #ifndef CTX_SHAPE_CACHE_ENTRIES
 3635 #define CTX_SHAPE_CACHE_ENTRIES  160
 3636 #endif
 3637 
 3638 
 3639 #ifndef CTX_PARSER_FIXED_TEMP
 3640 #define CTX_PARSER_FIXED_TEMP 0
 3641          // when 1  CTX_PARSER_MAXLEN is the fixed max stringlen
 3642 #endif   // and no allocations happens beyond creating the parser,
 3643          // when 0 the scratchbuf for parsing is a separate dynamically
 3644          // growing buffer, that maxes out at CTX_PARSER_MAXLEN
 3645          //
 3646 #ifndef CTX_PARSER_MAXLEN
 3647 #if CTX_PARSER_FIXED_TEMP
 3648 #define CTX_PARSER_MAXLEN  1024*128        // This is the maximum 
 3649 texture/string size supported
 3650 #else
 3651 #define CTX_PARSER_MAXLEN  1024*1024*16    // 16mb
 3652 #endif
 3653 #endif
 3654 
 3655 #ifndef CTX_COMPOSITING_GROUPS
 3656 #define CTX_COMPOSITING_GROUPS   1
 3657 #endif
 3658 
 3659 /* maximum nesting level of compositing groups
 3660  */
 3661 #ifndef CTX_GROUP_MAX
 3662 #define CTX_GROUP_MAX             8
 3663 #endif
 3664 
 3665 #ifndef CTX_ENABLE_CLIP
 3666 #define CTX_ENABLE_CLIP           1
 3667 #endif
 3668 
 3669 /* use a 1bit clip buffer, saving RAM on microcontrollers, other rendering
 3670  * will still be antialiased.
 3671  */
 3672 #ifndef CTX_1BIT_CLIP
 3673 #define CTX_1BIT_CLIP             0
 3674 #endif
 3675 
 3676 
 3677 #ifndef CTX_ENABLE_SHADOW_BLUR
 3678 #define CTX_ENABLE_SHADOW_BLUR    1
 3679 #endif
 3680 
 3681 #ifndef CTX_GRADIENTS
 3682 #define CTX_GRADIENTS             1
 3683 #endif
 3684 
 3685 /* some optinal micro-optimizations that are known to increase code size
 3686  */
 3687 #ifndef CTX_BLOATY_FAST_PATHS
 3688 #define CTX_BLOATY_FAST_PATHS     1
 3689 #endif
 3690 
 3691 #ifndef CTX_GRADIENT_CACHE
 3692 #define CTX_GRADIENT_CACHE        1
 3693 #endif
 3694 
 3695 #ifndef CTX_FONTS_FROM_FILE
 3696 #define CTX_FONTS_FROM_FILE 1
 3697 #endif
 3698 
 3699 #ifndef CTX_FORMATTER
 3700 #define CTX_FORMATTER       1
 3701 #endif
 3702 
 3703 #ifndef CTX_PARSER
 3704 #define CTX_PARSER          1
 3705 #endif
 3706 
 3707 #ifndef CTX_CURRENT_PATH
 3708 #define CTX_CURRENT_PATH    1
 3709 #endif
 3710 
 3711 #ifndef CTX_XML
 3712 #define CTX_XML             1
 3713 #endif
 3714 
 3715 /* when ctx_math is defined, which it is by default, we use ctx' own
 3716  * implementations of math functions, instead of relying on math.h
 3717  * the possible inlining gives us a slight speed-gain, and on
 3718  * embedded platforms guarantees that we do not do double precision
 3719  * math.
 3720  */
 3721 #ifndef CTX_MATH
 3722 #define CTX_MATH           1  // use internal fast math for sqrt,sin,cos,
 3723 atan2f etc.
 3724 #endif
 3725 
 3726 #define ctx_log(fmt, ...)
 3727 //#define ctx_log(str, a...) fprintf(stderr, str, ##a)
 3728 
 3729 /* the initial journal size - for both rasterizer
 3730  * edgelist and drawlist.
 3731  */
 3732 #ifndef CTX_MIN_JOURNAL_SIZE
 3733 #define CTX_MIN_JOURNAL_SIZE      512
 3734 #endif
 3735 
 3736 /* The maximum size we permit the drawlist to grow to,
 3737  * the memory used is this number * 9, where 9 is sizeof(CtxEntry)
 3738  */
 3739 #ifndef CTX_MAX_JOURNAL_SIZE
 3740 //#define CTX_MAX_JOURNAL_SIZE   CTX_MIN_JOURNAL_SIZE
 3741 #define CTX_MAX_JOURNAL_SIZE 1024*1024*16
 3742 #endif
 3743 
 3744 #ifndef CTX_DRAWLIST_STATIC
 3745 #define CTX_DRAWLIST_STATIC  0
 3746 #endif
 3747 
 3748 #ifndef CTX_MIN_EDGE_LIST_SIZE
 3749 #define CTX_MIN_EDGE_LIST_SIZE   1024
 3750 #endif
 3751 
 3752 #ifndef CTX_RASTERIZER_AA
 3753 #define CTX_RASTERIZER_AA 5   // vertical-AA of CTX_ANTIALIAS_DEFAULT
 3754 #endif
 3755 
 3756 /* The maximum complexity of a single path
 3757  */
 3758 #ifndef CTX_MAX_EDGE_LIST_SIZE
 3759 #define CTX_MAX_EDGE_LIST_SIZE  CTX_MIN_EDGE_LIST_SIZE
 3760 #endif
 3761 
 3762 #ifndef CTX_STRINGPOOL_SIZE
 3763   // XXX should be possible to make zero and disappear when codepaths not 
 3764   in use
 3765   //     to save size, for card10 this is defined as a low number (some 
 3766                                                                    text
 3767   //     properties still make use of it)
 3768   //     
 3769   //     for desktop-use this should be fully dynamic, possibly
 3770   //     with chained pools, gradients are stored here.
 3771 #define CTX_STRINGPOOL_SIZE     1000 //
 3772 #endif
 3773 
 3774 /* whether we dither or not for gradients
 3775  */
 3776 #ifndef CTX_DITHER
 3777 #define CTX_DITHER 1
 3778 #endif
 3779 
 3780 /*  only source-over clear and copy will work, the API still
 3781  *  through - but the renderer is limited, for use to measure
 3782  *  size and possibly in severely constrained ROMs.
 3783  */
 3784 #ifndef CTX_BLENDING_AND_COMPOSITING
 3785 #define CTX_BLENDING_AND_COMPOSITING 1
 3786 #endif
 3787 
 3788 /*  this forces the inlining of some performance
 3789  *  critical paths.
 3790  */
 3791 #ifndef CTX_FORCE_INLINES
 3792 #define CTX_FORCE_INLINES               1
 3793 #endif
 3794 
 3795 /* create one-off inlined inner loop for normal blend mode
 3796  */
 3797 #ifndef CTX_INLINED_NORMAL     
 3798 #define CTX_INLINED_NORMAL      1
 3799 #endif
 3800 
 3801 #ifndef CTX_INLINED_GRADIENTS
 3802 #define CTX_INLINED_GRADIENTS   1
 3803 #endif
 3804 
 3805 #ifndef CTX_BRAILLE_TEXT
 3806 #define CTX_BRAILLE_TEXT        0
 3807 #endif
 3808 
 3809 /* including immintrin.h triggers building of AVX2 code paths, if - like
 3810  * sometimes when including SDL one does want it at all do a
 3811  * #define CTX_AVX2 0  before including ctx.h for implementation.
 3812  */
 3813 #ifndef CTX_AVX2
 3814 #ifdef _IMMINTRIN_H_INCLUDED
 3815 #define CTX_AVX2         1
 3816 #else
 3817 #define CTX_AVX2         0
 3818 #endif
 3819 #endif
 3820 
 3821 /* Build code paths for grayscale rasterization, normally this is handled
 3822  * by the RGBA8 codepaths; on microcontrollers with eink this might be
 3823  * a better option.
 3824  */
 3825 #ifndef CTX_NATIVE_GRAYA8
 3826 #define CTX_NATIVE_GRAYA8       0
 3827 #endif
 3828 
 3829 /* enable CMYK rasterization targets
 3830  */
 3831 #ifndef CTX_ENABLE_CMYK
 3832 #define CTX_ENABLE_CMYK         1
 3833 #endif
 3834 
 3835 /* enable color management, slightly increases CtxColor struct size, can
 3836  * be disabled for microcontrollers.
 3837  */
 3838 #ifndef CTX_ENABLE_CM
 3839 #define CTX_ENABLE_CM           1
 3840 #endif
 3841 
 3842 #ifndef CTX_EVENTS
 3843 #define CTX_EVENTS              1
 3844 #endif
 3845 
 3846 #ifndef CTX_LIMIT_FORMATS
 3847 #define CTX_LIMIT_FORMATS       0
 3848 #endif
 3849 
 3850 #ifndef CTX_ENABLE_FLOAT
 3851 #define CTX_ENABLE_FLOAT 0
 3852 #endif
 3853 
 3854 /* by default ctx includes all pixel formats, on microcontrollers
 3855  * it can be useful to slim down code and runtime size by only
 3856  * defining the used formats, set CTX_LIMIT_FORMATS to 1, and
 3857  * manually add CTX_ENABLE_ flags for each of them.
 3858  */
 3859 #if CTX_LIMIT_FORMATS
 3860 #else
 3861 
 3862 #define CTX_ENABLE_GRAY1                1
 3863 #define CTX_ENABLE_GRAY2                1
 3864 #define CTX_ENABLE_GRAY4                1
 3865 #define CTX_ENABLE_GRAY8                1
 3866 #define CTX_ENABLE_GRAYA8               1
 3867 #define CTX_ENABLE_GRAYF                1
 3868 #define CTX_ENABLE_GRAYAF               1
 3869 
 3870 #define CTX_ENABLE_RGB8                 1
 3871 #define CTX_ENABLE_RGBA8                1
 3872 #define CTX_ENABLE_BGRA8                1
 3873 #define CTX_ENABLE_RGB332               1
 3874 #define CTX_ENABLE_RGB565               1
 3875 #define CTX_ENABLE_RGB565_BYTESWAPPED   1
 3876 #define CTX_ENABLE_RGBAF                1
 3877 #ifdef CTX_ENABLE_FLOAT
 3878 #undef CTX_ENABLE_FLOAT
 3879 #endif
 3880 #define CTX_ENABLE_FLOAT                1
 3881 
 3882 #if CTX_ENABLE_CMYK
 3883 #define CTX_ENABLE_CMYK8                1
 3884 #define CTX_ENABLE_CMYKA8               1
 3885 #define CTX_ENABLE_CMYKAF               1
 3886 #endif
 3887 #endif
 3888 
 3889 /* by including ctx-font-regular.h, or ctx-font-mono.h the
 3890  * built-in fonts using ctx drawlist encoding is enabled
 3891  */
 3892 #if CTX_FONT_regular || CTX_FONT_mono || CTX_FONT_bold \
 3893   || CTX_FONT_italic || CTX_FONT_sans || CTX_FONT_serif \
 3894   || CTX_FONT_ascii
 3895 #ifndef CTX_FONT_ENGINE_CTX
 3896 #define CTX_FONT_ENGINE_CTX        1
 3897 #endif
 3898 #endif
 3899 
 3900 #ifndef CTX_FONT_ENGINE_CTX_FS
 3901 #define CTX_FONT_ENGINE_CTX_FS 0
 3902 #endif
 3903 
 3904 /* If stb_strutype.h is included before ctx.h add integration code for 
 3905 runtime loading
 3906  * of opentype fonts.
 3907  */
 3908 #ifdef __STB_INCLUDE_STB_TRUETYPE_H__
 3909 #ifndef CTX_FONT_ENGINE_STB
 3910 #define CTX_FONT_ENGINE_STB        1
 3911 #endif
 3912 #else
 3913 #define CTX_FONT_ENGINE_STB        0
 3914 #endif
 3915 
 3916 #ifdef _BABL_H
 3917 #define CTX_BABL 1
 3918 #else
 3919 #define CTX_BABL 0
 3920 #endif
 3921 
 3922 
 3923 /* force add format if we have shape cache */
 3924 #if CTX_SHAPE_CACHE
 3925 #ifdef CTX_ENABLE_GRAY8
 3926 #undef CTX_ENABLE_GRAY8
 3927 #endif
 3928 #define CTX_ENABLE_GRAY8  1
 3929 #endif
 3930 
 3931 /* include the bitpack packer, can be opted out of to decrease code size
 3932  */
 3933 #ifndef CTX_BITPACK_PACKER
 3934 #define CTX_BITPACK_PACKER 0
 3935 #endif
 3936 
 3937 /* enable RGBA8 intermediate format for
 3938  *the indirectly implemented pixel-formats.
 3939  */
 3940 #if CTX_ENABLE_GRAY1 | CTX_ENABLE_GRAY2 | CTX_ENABLE_GRAY4 | 
 3941 CTX_ENABLE_RGB565 | CTX_ENABLE_RGB565_BYTESWAPPED | CTX_ENABLE_RGB8 | 
 3942 CTX_ENABLE_RGB332
 3943 
 3944   #ifdef CTX_ENABLE_RGBA8
 3945     #undef CTX_ENABLE_RGBA8
 3946   #endif
 3947   #define CTX_ENABLE_RGBA8  1
 3948 #endif
 3949 
 3950 #ifdef CTX_ENABLE_CMYKF
 3951 #ifdef CTX_ENABLE_FLOAT
 3952 #undef CTX_ENABLE_FLOAT
 3953 #endif
 3954 #define CTX_ENABLE_FLOAT 1
 3955 #endif
 3956 
 3957 #ifdef CTX_ENABLE_GRAYF
 3958 #ifdef CTX_ENABLE_FLOAT
 3959 #undef CTX_ENABLE_FLOAT
 3960 #endif
 3961 #define CTX_ENABLE_FLOAT 1
 3962 #endif
 3963 
 3964 #ifdef CTX_ENABLE_GRAYAF
 3965 #ifdef CTX_ENABLE_FLOAT
 3966 #undef CTX_ENABLE_FLOAT
 3967 #endif
 3968 #define CTX_ENABLE_FLOAT 1
 3969 #endif
 3970 
 3971 #ifdef CTX_ENABLE_RGBAF
 3972 #ifdef CTX_ENABLE_FLOAT
 3973 #undef CTX_ENABLE_FLOAT
 3974 #endif
 3975 #define CTX_ENABLE_FLOAT 1
 3976 #endif
 3977 
 3978 #ifdef CTX_ENABLE_CMYKAF
 3979 #ifdef CTX_ENABLE_FLOAT
 3980 #undef CTX_ENABLE_FLOAT
 3981 #endif
 3982 #define CTX_ENABLE_FLOAT 1
 3983 #endif
 3984 
 3985 #ifdef CTX_ENABLE_CMYKF
 3986 #ifdef CTX_ENABLE_FLOAT
 3987 #undef CTX_ENABLE_FLOAT
 3988 #endif
 3989 #define CTX_ENABLE_FLOAT 1
 3990 #endif
 3991 
 3992 
 3993 /* enable cmykf which is cmyk intermediate format
 3994  */
 3995 #ifdef CTX_ENABLE_CMYK8
 3996 #ifdef CTX_ENABLE_CMYKF
 3997 #undef CTX_ENABLE_CMYKF
 3998 #endif
 3999 #define CTX_ENABLE_CMYKF  1
 4000 #endif
 4001 #ifdef CTX_ENABLE_CMYKA8
 4002 #ifdef CTX_ENABLE_CMYKF
 4003 #undef CTX_ENABLE_CMYKF
 4004 #endif
 4005 #define CTX_ENABLE_CMYKF  1
 4006 #endif
 4007 
 4008 #ifdef CTX_ENABLE_CMYKF8
 4009 #ifdef CTX_ENABLE_CMYK
 4010 #undef CTX_ENABLE_CMYK
 4011 #endif
 4012 #define CTX_ENABLE_CMYK   1
 4013 #endif
 4014 
 4015 #define CTX_PI                              3.141592653589793f
 4016 #ifndef CTX_RASTERIZER_MAX_CIRCLE_SEGMENTS
 4017 #define CTX_RASTERIZER_MAX_CIRCLE_SEGMENTS  120
 4018 #endif
 4019 
 4020 #ifndef CTX_MAX_FONTS
 4021 #define CTX_MAX_FONTS            3
 4022 #endif
 4023 
 4024 #ifndef CTX_MAX_STATES
 4025 #define CTX_MAX_STATES           10
 4026 #endif
 4027 
 4028 #ifndef CTX_MAX_EDGES
 4029 #define CTX_MAX_EDGES            257
 4030 #endif
 4031 
 4032 #ifndef CTX_MAX_LINGERING_EDGES
 4033 #define CTX_MAX_LINGERING_EDGES  64
 4034 #endif
 4035 
 4036 
 4037 #ifndef CTX_MAX_PENDING
 4038 #define CTX_MAX_PENDING          128
 4039 #endif
 4040 
 4041 #ifndef CTX_MAX_TEXTURES
 4042 #define CTX_MAX_TEXTURES         16
 4043 #endif
 4044 
 4045 #ifndef CTX_HASH_ROWS
 4046 #define CTX_HASH_ROWS            8
 4047 #endif
 4048 #ifndef CTX_HASH_COLS
 4049 #define CTX_HASH_COLS            8
 4050 #endif
 4051 
 4052 #ifndef CTX_MAX_THREADS
 4053 #define CTX_MAX_THREADS          8 // runtime is max of cores/2 and this
 4054 #endif
 4055 
 4056 
 4057 
 4058 #define CTX_RASTERIZER_EDGE_MULTIPLIER  1024
 4059 
 4060 #ifndef CTX_COMPOSITE_SUFFIX
 4061 #define CTX_COMPOSITE_SUFFIX(symbol)     symbol##_default
 4062 #endif
 4063 
 4064 #ifndef CTX_IMPLEMENTATION
 4065 #define CTX_IMPLEMENTATION 0
 4066 #else
 4067 #undef CTX_IMPLEMENTATION
 4068 #define CTX_IMPLEMENTATION 1
 4069 #endif
 4070 
 4071 
 4072 #ifdef CTX_RASTERIZER
 4073 #if CTX_RASTERIZER==0
 4074 #else
 4075 #undef CTX_RASTERIZER
 4076 #define CTX_RASTERIZER 1
 4077 #endif
 4078 #endif
 4079 
 4080 #if CTX_RASTERIZER
 4081 #ifndef CTX_COMPOSITE
 4082 #define CTX_COMPOSITE 1
 4083 #endif
 4084 #else
 4085 #ifndef CTX_COMPOSITE
 4086 #define CTX_COMPOSITE 0
 4087 #endif
 4088 #endif
 4089 
 4090 #ifndef CTX_DAMAGE_CONTROL
 4091 #define CTX_DAMAGE_CONTROL 0
 4092 #endif
 4093 
 4094 
 4095 #ifndef CTX_GRADIENT_CACHE_ELEMENTS
 4096 #define CTX_GRADIENT_CACHE_ELEMENTS 256
 4097 #endif
 4098 
 4099 #ifndef CTX_PARSER_MAX_ARGS
 4100 #define CTX_PARSER_MAX_ARGS 20
 4101 #endif
 4102 
 4103 
 4104 #ifndef CTX_SCREENSHOT
 4105 #define CTX_SCREENSHOT 0
 4106 #endif
 4107 
 4108 
 4109 #ifndef CTX_TILED
 4110 #if CTX_SDL || CTX_FB
 4111 #define CTX_TILED 1
 4112 #else
 4113 #define CTX_TILED 0
 4114 #endif
 4115 #endif
 4116 
 4117  /* Copyright (C) 2020 Øyvind Kolås <pippin@gimp.org>
 4118  */
 4119 
 4120 #if CTX_FORMATTER
 4121 
 4122 /* returns the maximum string length including terminating \0 */
 4123 static int ctx_a85enc_len (int input_length)
 4124 {
 4125   return (input_length / 4 + 1) * 5;
 4126 }
 4127 
 4128 static int ctx_a85enc (const void *srcp, char *dst, int count)
 4129 {
 4130   const uint8_t *src = (uint8_t*)srcp;
 4131   int out_len = 0;
 4132 
 4133   int padding = 4-(count % 4);
 4134   if (padding == 4) padding = 0;
 4135 
 4136   for (int i = 0; i < (count+3)/4; i ++)
 4137   {
 4138     uint32_t input = 0;
 4139     for (int j = 0; j < 4; j++)
 4140     {
 4141       input = (input << 8);
 4142       if (i*4+j<=count)
 4143         input += src[i*4+j];
 4144     }
 4145 
 4146     int divisor = 85 * 85 * 85 * 85;
 4147 #if 0
 4148     if (input == 0)
 4149     {
 4150         dst[out_len++] = 'z';
 4151     }
 4152     /* todo: encode 4 spaces as 'y' */
 4153     else
 4154 #endif
 4155     {
 4156       for (int j = 0; j < 5; j++)
 4157       {
 4158         dst[out_len++] = ((input / divisor) % 85) + '!';
 4159         divisor /= 85;
 4160       }
 4161     }
 4162   }
 4163   out_len -= padding;
 4164   dst[out_len]=0;
 4165   return out_len;
 4166 }
 4167 #endif
 4168 
 4169 #if CTX_PARSER
 4170 
 4171 static int ctx_a85dec (const char *src, char *dst, int count)
 4172 {
 4173   int out_len = 0;
 4174   uint32_t val = 0;
 4175   int k = 0;
 4176   int i = 0;
 4177   for (i = 0; i < count; i ++)
 4178   {
 4179     val *= 85;
 4180     if (src[i] == '~')
 4181     {
 4182       break;
 4183     }
 4184 #if 0
 4185     else if (src[i] == 'z')
 4186     {
 4187       for (int j = 0; j < 4; j++)
 4188         dst[out_len++] = 0;
 4189       k = 0;
 4190     }
 4191     else if (src[i] == 'y') /* lets support this extension */
 4192     {
 4193       for (int j = 0; j < 4; j++)
 4194         dst[out_len++] = 32;
 4195       k = 0;
 4196     }
 4197 #endif
 4198     else if (src[i] >= '!' && src[i] <= 'u')
 4199     {
 4200       val += src[i]-'!';
 4201       if (k % 5 == 4)
 4202       {
 4203          for (int j = 0; j < 4; j++)
 4204          {
 4205            dst[out_len++] = (val & (0xff << 24)) >> 24;
 4206            val <<= 8;
 4207          }
 4208          val = 0;
 4209       }
 4210       k++;
 4211     }
 4212     // we treat all other chars as whitespace
 4213   }
 4214   if (src[i] != '~')
 4215   { 
 4216     val *= 85;
 4217   }
 4218   k = k % 5;
 4219   if (k)
 4220   {
 4221     val += 84;
 4222     for (int j = k; j < 4; j++)
 4223     {
 4224       val *= 85;
 4225       val += 84;
 4226     }
 4227 
 4228     for (int j = 0; j < k-1; j++)
 4229     {
 4230       dst[out_len++] = (val & (0xff << 24)) >> 24;
 4231       val <<= 8;
 4232     }
 4233     val = 0;
 4234   }
 4235   dst[out_len] = 0;
 4236   return out_len;
 4237 }
 4238 
 4239 #if 0
 4240 static int ctx_a85len (const char *src, int count)
 4241 {
 4242   int out_len = 0;
 4243   int k = 0;
 4244   for (int i = 0; i < count; i ++)
 4245   {
 4246     if (src[i] == '~')
 4247       break;
 4248     else if (src[i] == 'z')
 4249     {
 4250       for (int j = 0; j < 4; j++)
 4251         out_len++;
 4252       k = 0;
 4253     }
 4254     else if (src[i] >= '!' && src[i] <= 'u')
 4255     {
 4256       if (k % 5 == 4)
 4257         out_len += 4;
 4258       k++;
 4259     }
 4260     // we treat all other chars as whitespace
 4261   }
 4262   k = k % 5;
 4263   if (k)
 4264     out_len += k-1;
 4265   return out_len;
 4266 }
 4267 #endif
 4268 
 4269 #endif
 4270 #ifndef __CTX_EXTRA_H
 4271 #define __CTX_EXTRA_H
 4272 
 4273 
 4274 #define CTX_CLAMP(val,min,max) ((val)<(min)?(min):(val)>(max)?(max):(val))
 4275 static inline int   ctx_mini (int a, int b)     { if (a < b) return a; 
 4276                               return b; }
 4277 static inline float ctx_minf (float a, float b) { if (a < b) return a; 
 4278                               return b; }
 4279 static inline int   ctx_maxi (int a, int b)     { if (a > b) return a; 
 4280                               return b; }
 4281 static inline float ctx_maxf (float a, float b) { if (a > b) return a; 
 4282                               return b; }
 4283 
 4284 
 4285 typedef enum CtxOutputmode
 4286 {
 4287   CTX_OUTPUT_MODE_QUARTER,
 4288   CTX_OUTPUT_MODE_BRAILLE,
 4289   CTX_OUTPUT_MODE_SIXELS,
 4290   CTX_OUTPUT_MODE_GRAYS,
 4291   CTX_OUTPUT_MODE_CTX,
 4292   CTX_OUTPUT_MODE_CTX_COMPACT,
 4293   CTX_OUTPUT_MODE_UI
 4294 } CtxOutputmode;
 4295 
 4296 
 4297 
 4298 
 4299 
 4300 #if CTX_FORCE_INLINES
 4301 #define CTX_INLINE inline __attribute__((always_inline))
 4302 #else
 4303 #define CTX_INLINE inline
 4304 #endif
 4305 
 4306 static inline float ctx_pow2 (float a) { return a * a; }
 4307 #if CTX_MATH
 4308 
 4309 static inline float
 4310 ctx_fabsf (float x)
 4311 {
 4312   union
 4313   {
 4314     float f;
 4315     uint32_t i;
 4316   } u = { x };
 4317   u.i &= 0x7fffffff;
 4318   return u.f;
 4319 }
 4320 
 4321 static inline float
 4322 ctx_invsqrtf (float x)
 4323 {
 4324   void *foo = &x;
 4325   float xhalf = 0.5f * x;
 4326   int i=* (int *) foo;
 4327   void *bar = &i;
 4328   i = 0x5f3759df - (i >> 1);
 4329   x = * (float *) bar;
 4330   x *= (1.5f - xhalf * x * x);
 4331   x *= (1.5f - xhalf * x * x); //repeating Newton-Raphson step for higher 
 4332        precision
 4333   return x;
 4334 }
 4335 
 4336 CTX_INLINE static float
 4337 ctx_sinf (float x)
 4338 {
 4339   if (x < -CTX_PI * 2)
 4340     {
 4341       x = -x;
 4342       long ix = x / (CTX_PI * 2);
 4343       x = x - ix * CTX_PI * 2;
 4344       x = -x;
 4345     }
 4346   if (x < -CTX_PI * 1000)
 4347   {
 4348     x = -0.5;
 4349   }
 4350   if (x > CTX_PI * 1000)
 4351   {
 4352           // really large numbers tend to cause practically inifinite
 4353           // loops since the > CTX_PI * 2 seemingly fails
 4354     x = 0.5;
 4355   }
 4356   if (x > CTX_PI * 2)
 4357     { 
 4358       long ix = x / (CTX_PI * 2);
 4359       x = x - (ix * CTX_PI * 2);
 4360     }
 4361   while (x < -CTX_PI)
 4362     { x += CTX_PI * 2; }
 4363   while (x > CTX_PI)
 4364     { x -= CTX_PI * 2; }
 4365 
 4366   /* source : http://mooooo.ooo/chebyshev-sine-approximation/ */
 4367   float coeffs[]=
 4368   {
 4369     -0.10132118f,           // x
 4370       0.0066208798f,         // x^3
 4371       -0.00017350505f,        // x^5
 4372       0.0000025222919f,      // x^7
 4373       -0.000000023317787f,    // x^9
 4374       0.00000000013291342f
 4375     }; // x^11
 4376   float x2 = x*x;
 4377   float p11 = coeffs[5];
 4378   float p9  = p11*x2 + coeffs[4];
 4379   float p7  = p9*x2  + coeffs[3];
 4380   float p5  = p7*x2  + coeffs[2];
 4381   float p3  = p5*x2  + coeffs[1];
 4382   float p1  = p3*x2  + coeffs[0];
 4383   return (x - CTX_PI + 0.00000008742278f) *
 4384          (x + CTX_PI - 0.00000008742278f) * p1 * x;
 4385 }
 4386 
 4387 static inline float ctx_atan2f (float y, float x)
 4388 {
 4389   float atan, z;
 4390   if ( x == 0.0f )
 4391     {
 4392       if ( y > 0.0f )
 4393         { return CTX_PI/2; }
 4394       if ( y == 0.0f )
 4395         { return 0.0f; }
 4396       return -CTX_PI/2;
 4397     }
 4398   z = y/x;
 4399   if ( ctx_fabsf ( z ) < 1.0f )
 4400     {
 4401       atan = z/ (1.0f + 0.28f*z*z);
 4402       if (x < 0.0f)
 4403         {
 4404           if ( y < 0.0f )
 4405             { return atan - CTX_PI; }
 4406           return atan + CTX_PI;
 4407         }
 4408     }
 4409   else
 4410     {
 4411       atan = CTX_PI/2 - z/ (z*z + 0.28f);
 4412       if ( y < 0.0f ) { return atan - CTX_PI; }
 4413     }
 4414   return atan;
 4415 }
 4416 
 4417 CTX_INLINE static float ctx_sqrtf (float a)
 4418 {
 4419   return 1.0f/ctx_invsqrtf (a);
 4420 }
 4421 
 4422 CTX_INLINE static float ctx_hypotf (float a, float b)
 4423 {
 4424   return ctx_sqrtf (ctx_pow2 (a)+ctx_pow2 (b) );
 4425 }
 4426 
 4427 static inline float ctx_atanf (float a)
 4428 {
 4429   return ctx_atan2f ( (a), 1.0f);
 4430 }
 4431 
 4432 static inline float ctx_asinf (float x)
 4433 {
 4434   return ctx_atanf ( (x) * (ctx_invsqrtf (1.0f-ctx_pow2 (x) ) ) );
 4435 }
 4436 
 4437 static inline float ctx_acosf (float x)
 4438 {
 4439   return ctx_atanf ( (ctx_sqrtf (1.0f-ctx_pow2 (x) ) / (x) ) );
 4440 }
 4441 
 4442 CTX_INLINE static float ctx_cosf (float a)
 4443 {
 4444   return ctx_sinf ( (a) + CTX_PI/2.0f);
 4445 }
 4446 
 4447 static inline float ctx_tanf (float a)
 4448 {
 4449   return (ctx_cosf (a) /ctx_sinf (a) );
 4450 }
 4451 static inline float
 4452 ctx_floorf (float x)
 4453 {
 4454   return (int)x; // XXX
 4455 }
 4456 static inline float
 4457 ctx_expf (float x)
 4458 {
 4459   union { uint32_t i; float f; } v =
 4460     { (1 << 23) * (x + 183.1395965) };
 4461   return v.f;
 4462 }
 4463 
 4464 /* define more trig based on having sqrt, sin and atan2 */
 4465 
 4466 #else
 4467 #include <math.h>
 4468 static inline float ctx_fabsf (float x)           { return fabsf (x); }
 4469 static inline float ctx_floorf (float x)          { return floorf (x); }
 4470 static inline float ctx_sinf (float x)            { return sinf (x); }
 4471 static inline float ctx_atan2f (float y, float x) { return atan2f (y, x); }
 4472 static inline float ctx_hypotf (float a, float b) { return hypotf (a, b); }
 4473 static inline float ctx_acosf (float a)           { return acosf (a); }
 4474 static inline float ctx_cosf (float a)            { return cosf (a); }
 4475 static inline float ctx_tanf (float a)            { return tanf (a); }
 4476 static inline float ctx_expf (float p)            { return expf (p); }
 4477 static inline float ctx_sqrtf (float a)           { return sqrtf (a); }
 4478 #endif
 4479 
 4480 static inline float _ctx_parse_float (const char *str, char **endptr)
 4481 {
 4482   return strtod (str, endptr); /* XXX: , vs . problem in some locales */
 4483 }
 4484 
 4485 const char *ctx_get_string (Ctx *ctx, uint64_t hash);
 4486 void ctx_set_string (Ctx *ctx, uint64_t hash, const char *value);
 4487 typedef struct _CtxColor CtxColor;
 4488 typedef struct _CtxBuffer CtxBuffer;
 4489 
 4490 typedef struct _CtxMatrix     CtxMatrix;
 4491 struct
 4492   _CtxMatrix
 4493 {
 4494   float m[3][2];
 4495 };
 4496 void ctx_get_matrix (Ctx *ctx, CtxMatrix *matrix);
 4497 
 4498 int ctx_color_fill (Ctx *ctx, const char *string);
 4499 int ctx_color_stroke (Ctx *ctx, const char *string);
 4500 typedef struct _CtxState CtxState;
 4501 CtxColor *ctx_color_new ();
 4502 CtxState *ctx_get_state (Ctx *ctx);
 4503 void ctx_color_get_rgba (CtxState *state, CtxColor *color, float *out);
 4504 void ctx_color_set_rgba (CtxState *state, CtxColor *color, float r, float g,
 4505                          float b, float a);
 4506 void ctx_color_free (CtxColor *color);
 4507 void ctx_set_color (Ctx *ctx, uint64_t hash, CtxColor *color);
 4508 int  ctx_get_color (Ctx *ctx, uint64_t hash, CtxColor *color);
 4509 int ctx_color_set_from_string (Ctx *ctx, CtxColor *color, const char 
 4510                                *string);
 4511 
 4512 int ctx_color_is_transparent (CtxColor *color);
 4513 int ctx_utf8_len (const unsigned char first_byte);
 4514 
 4515 void ctx_user_to_device          (Ctx *ctx, float *x, float *y);
 4516 void ctx_user_to_device_distance (Ctx *ctx, float *x, float *y);
 4517 const char *ctx_utf8_skip (const char *s, int utf8_length);
 4518 void ctx_apply_matrix (Ctx *ctx, CtxMatrix *matrix);
 4519 void ctx_matrix_apply_transform (const CtxMatrix *m, float *x, float *y);
 4520 void ctx_matrix_invert (CtxMatrix *m);
 4521 void ctx_matrix_identity (CtxMatrix *matrix);
 4522 void ctx_matrix_scale (CtxMatrix *matrix, float x, float y);
 4523 void ctx_matrix_rotate (CtxMatrix *matrix, float angle);
 4524 void ctx_matrix_multiply (CtxMatrix       *result,
 4525                           const CtxMatrix *t,
 4526                           const CtxMatrix *s);
 4527 void
 4528 ctx_matrix_translate (CtxMatrix *matrix, float x, float y);
 4529 int ctx_is_set_now (Ctx *ctx, uint64_t hash);
 4530 void ctx_set_size (Ctx *ctx, int width, int height);
 4531 
 4532 #if CTX_FONTS_FROM_FILE
 4533 int   ctx_load_font_ttf_file (const char *name, const char *path);
 4534 int
 4535 _ctx_file_get_contents (const char     *path,
 4536                         unsigned char **contents,
 4537                         long           *length);
 4538 #endif
 4539 
 4540 #endif
 4541 #ifndef __CTX_CONSTANTS
 4542 #define __CTX_CONSTANTS
 4543 
 4544 #define TOKENHASH(a)    ((uint64_t)a)
 4545 
 4546 #define CTX_add_stop 	TOKENHASH(1274978316678)
 4547 #define CTX_addStop 	TOKENHASH(40799943078278)
 4548 #define CTX_alphabetic 	TOKENHASH(2629359926678406)
 4549 #define CTX_arc 	TOKENHASH(11526)
 4550 #define CTX_arc_to 	TOKENHASH(1187065094)
 4551 #define CTX_arcTo 	TOKENHASH(38558051590)
 4552 #define CTX_begin_path 	TOKENHASH(3004110681622984)
 4553 #define CTX_beginPath 	TOKENHASH(8437143659599196)
 4554 #define CTX_bevel 	TOKENHASH(29868488)
 4555 #define CTX_bottom 	TOKENHASH(1043772488)
 4556 #define CTX_cap 	TOKENHASH(37066)
 4557 #define CTX_center 	TOKENHASH(1358332362)
 4558 #define CTX_clear 	TOKENHASH(42154890)
 4559 #define CTX_color 	TOKENHASH(43086922)
 4560 #define CTX_copy 	TOKENHASH(1807434)
 4561 #define CTX_clip 	TOKENHASH(1203082)
 4562 #define CTX_close_path 	TOKENHASH(3004110663420810)
 4563 #define CTX_closePath 	TOKENHASH(8437144279135038)
 4564 #define CTX_cmyka 	TOKENHASH(7199690)
 4565 #define CTX_cmyk 	TOKENHASH(908234)
 4566 #define CTX_cmykaS 	TOKENHASH(36313095114)
 4567 #define CTX_cmykS 	TOKENHASH(1135467466)
 4568 #define CTX_color 	TOKENHASH(43086922)
 4569 #define CTX_blending 	TOKENHASH(653586873224)
 4570 #define CTX_blend 	TOKENHASH(13646728)
 4571 #define CTX_blending_mode 	TOKENHASH(8147360531130856)
 4572 #define CTX_blendingMode 	TOKENHASH(7483585768187540)
 4573 #define CTX_blend_mode 	TOKENHASH(2758775686577032)
 4574 #define CTX_blendMode 	TOKENHASH(7773213171090182)
 4575 #define CTX_composite 	TOKENHASH(16930059746378)
 4576 #define CTX_compositing_mode 	TOKENHASH(2417816728103524)
 4577 #define CTX_compositingMode 	TOKENHASH(2807194446992106)
 4578 #define CTX_curve_to 	TOKENHASH(1215559149002)
 4579 #define CTX_curveTo 	TOKENHASH(39483449320906)
 4580 #define CTX_darken 	TOKENHASH(1089315020)
 4581 #define CTX_defineGlyph 	TOKENHASH(2497926167421194)
 4582 #define CTX_defineTexture 	TOKENHASH(2623744577477404)
 4583 #define CTX_kerningPair 	TOKENHASH(6964644556489058)
 4584 #define CTX_destinationIn 	TOKENHASH(8153299143600102)
 4585 #define CTX_destination_in 	TOKENHASH(3824201982576824)
 4586 #define CTX_destinationAtop 	TOKENHASH(8185118415574560)
 4587 #define CTX_destination_atop 	TOKENHASH(7742210324901698)
 4588 #define CTX_destinationOver 	TOKENHASH(3261713333438500)
 4589 #define CTX_destination_over 	TOKENHASH(7742210324728474)
 4590 #define CTX_destinationOut 	TOKENHASH(7742210322269456)
 4591 #define CTX_destination_out 	TOKENHASH(8153299143489102)
 4592 #define CTX_difference 	TOKENHASH(2756492040618700)
 4593 #define CTX_done 	TOKENHASH(492620)
 4594 #define CTX_drgba 	TOKENHASH(6573324)
 4595 #define CTX_drgb 	TOKENHASH(281868)
 4596 #define CTX_drgbaS 	TOKENHASH(36312468748)
 4597 #define CTX_drgbS 	TOKENHASH(1134841100)
 4598 #define CTX_end 	TOKENHASH(13326)
 4599 #define CTX_endfun 	TOKENHASH(1122513934)
 4600 #define CTX_end_group 	TOKENHASH(41200834917390)
 4601 #define CTX_endGroup 	TOKENHASH(3570227948106766)
 4602 #define CTX_even_odd 	TOKENHASH(426345774606)
 4603 #define CTX_evenOdd 	TOKENHASH(13671748091406)
 4604 #define CTX_exit 	TOKENHASH(1465998)
 4605 #define CTX_fill 	TOKENHASH(946896)
 4606 #define CTX_fill_rule 	TOKENHASH(16405972808400)
 4607 #define CTX_fillRule 	TOKENHASH(2776813389378256)
 4608 #define CTX_flush 	TOKENHASH(22395792)
 4609 #define CTX_font 	TOKENHASH(1475664)
 4610 #define CTX_font_size 	TOKENHASH(17342343316560)
 4611 #define CTX_setFontSize 	TOKENHASH(8657699789799734)
 4612 #define CTX_fontSize 	TOKENHASH(2806775148872784)
 4613 #define CTX_function 	TOKENHASH(1136803546576)
 4614 #define CTX_getkey 	TOKENHASH(1827516882)
 4615 #define CTX_global_alpha 	TOKENHASH(6945103263242432)
 4616 #define CTX_globalAlpha 	TOKENHASH(2684560928159160)
 4617 #define CTX_glyph 	TOKENHASH(22207378)
 4618 #define CTX_gradient_add_stop 	TOKENHASH(7829524561074416)
 4619 #define CTX_gradientAddStop 	TOKENHASH(8126442749593072)
 4620 #define CTX_graya 	TOKENHASH(8068370)
 4621 #define CTX_gray 	TOKENHASH(1776914)
 4622 #define CTX_grayaS 	TOKENHASH(36313963794)
 4623 #define CTX_grayS 	TOKENHASH(1136336146)
 4624 #define CTX_hanging 	TOKENHASH(20424786132)
 4625 #define CTX_height 	TOKENHASH(1497979348)
 4626 #define CTX_hor_line_to 	TOKENHASH(8345271542735158)
 4627 #define CTX_horLineTo 	TOKENHASH(3629696407754856)
 4628 #define CTX_hue 	TOKENHASH(15828)
 4629 #define CTX_identity 	TOKENHASH(1903455910294)
 4630 #define CTX_ideographic 	TOKENHASH(4370819675496700)
 4631 #define CTX_imageSmoothing 	TOKENHASH(4268778175825416)
 4632 #define CTX_join 	TOKENHASH(1072216)
 4633 #define CTX_laba 	TOKENHASH(205020)
 4634 #define CTX_lab 	TOKENHASH(8412)
 4635 #define CTX_lcha 	TOKENHASH(217436)
 4636 #define CTX_lch 	TOKENHASH(20828)
 4637 #define CTX_labaS 	TOKENHASH(1134764252)
 4638 #define CTX_labS 	TOKENHASH(35463388)
 4639 #define CTX_lchaS 	TOKENHASH(1134776668)
 4640 #define CTX_lchS 	TOKENHASH(35475804)
 4641 #define CTX_left 	TOKENHASH(1458652)
 4642 #define CTX_lighter 	TOKENHASH(43466246876)
 4643 #define CTX_lighten 	TOKENHASH(34876312284)
 4644 #define CTX_linear_gradient 	TOKENHASH(7801595375834212)
 4645 #define CTX_linearGradient 	TOKENHASH(4439260636789186)
 4646 #define CTX_line_cap 	TOKENHASH(1243731165916)
 4647 #define CTX_lineCap 	TOKENHASH(3436510399409980)
 4648 #define CTX_setLineCap 	TOKENHASH(7897176123029482)
 4649 #define CTX_line_height 	TOKENHASH(3300223516389168)
 4650 #define CTX_line_join 	TOKENHASH(35977601450716)
 4651 #define CTX_lineJoin 	TOKENHASH(3403122163024604)
 4652 #define CTX_setLineJoin 	TOKENHASH(2768281536656332)
 4653 #define CTX_line_spacing 	TOKENHASH(2519451230887150)
 4654 #define CTX_line_to 	TOKENHASH(37986206428)
 4655 #define CTX_lineTo 	TOKENHASH(1233857774300)
 4656 #define CTX_lineDash 	TOKENHASH(3001937455186652)
 4657 #define CTX_lineDashOffset 	TOKENHASH(3704120356324362)
 4658 #define CTX_line_width 	TOKENHASH(3004303386575580)
 4659 #define CTX_lineWidth 	TOKENHASH(8241159254028040)
 4660 #define CTX_setLineWidth 	TOKENHASH(8037913618228476)
 4661 #define CTX_view_box 	TOKENHASH(1823485803248)
 4662 #define CTX_viewBox 	TOKENHASH(3915860941641152)
 4663 #define CTX_middle 	TOKENHASH(499528414)
 4664 #define CTX_miter 	TOKENHASH(42447582)
 4665 #define CTX_miter_limit 	TOKENHASH(4281255327472850)
 4666 #define CTX_miterLimit 	TOKENHASH(7937453649653124)
 4667 #define CTX_move_to 	TOKENHASH(37986223198)
 4668 #define CTX_moveTo 	TOKENHASH(1233857791070)
 4669 #define CTX_multiply 	TOKENHASH(1886723143134)
 4670 #define CTX_new_page 	TOKENHASH(500602882528)
 4671 #define CTX_newPage 	TOKENHASH(16020123011552)
 4672 #define CTX_new_path 	TOKENHASH(734678600160)
 4673 #define CTX_newPath 	TOKENHASH(23510545975776)
 4674 #define CTX_new_state 	TOKENHASH(16912954280416)
 4675 #define CTX_none 	TOKENHASH(492640)
 4676 #define CTX_normal 	TOKENHASH(946840672)
 4677 #define CTX_quad_to 	TOKENHASH(37986115046)
 4678 #define CTX_quadTo 	TOKENHASH(1233857682918)
 4679 #define CTX_radial_gradient 	TOKENHASH(8267515704460560)
 4680 #define CTX_radialGradient 	TOKENHASH(4399889250822134)
 4681 #define CTX_rectangle 	TOKENHASH(16375644301800)
 4682 #define CTX_rect 	TOKENHASH(1452520)
 4683 #define CTX_rel_arc_to 	TOKENHASH(3496527781786088)
 4684 #define CTX_relArcTo 	TOKENHASH(3209152175601038)
 4685 #define CTX_rel_curve_to 	TOKENHASH(4439651822639910)
 4686 #define CTX_relCurveTo 	TOKENHASH(7294415873689320)
 4687 #define CTX_rel_hor_line_to 	TOKENHASH(7051067105640810)
 4688 #define CTX_relHorLineTo 	TOKENHASH(8737419863647946)
 4689 #define CTX_relVerLineTo 	TOKENHASH(8737441317512906)
 4690 #define CTX_rel_line_to 	TOKENHASH(8345271542378314)
 4691 #define CTX_relLineTo 	TOKENHASH(3629696197927444)
 4692 #define CTX_rel_move_to 	TOKENHASH(8344984486309706)
 4693 #define CTX_relMoveTo 	TOKENHASH(3571677202293268)
 4694 #define CTX_rel_quad_to 	TOKENHASH(8343627754794826)
 4695 #define CTX_relQuadTo 	TOKENHASH(7894357900599828)
 4696 #define CTX_rel_smoothq_to 	TOKENHASH(7340038162167138)
 4697 #define CTX_relSmoothqTo 	TOKENHASH(3188040406230844)
 4698 #define CTX_rel_smooth_to 	TOKENHASH(8144941131301668)
 4699 #define CTX_relSmoothTo 	TOKENHASH(8947422784198618)
 4700 #define CTX_rel_ver_line_to 	TOKENHASH(8148126344839530)
 4701 #define CTX_restore 	TOKENHASH(16411699688)
 4702 #define CTX_reset 	TOKENHASH(46639592)
 4703 #define CTX_rgba 	TOKENHASH(205416)
 4704 #define CTX_rgb 	TOKENHASH(8808)
 4705 #define CTX_rgbaS 	TOKENHASH(1134764648)
 4706 #define CTX_rgbS 	TOKENHASH(35463784)
 4707 #define CTX_right 	TOKENHASH(46811880)
 4708 #define CTX_rotate 	TOKENHASH(516142184)
 4709 #define CTX_round 	TOKENHASH(13679720)
 4710 #define CTX_round_rectangle 	TOKENHASH(4332080966833870)
 4711 #define CTX_roundRectangle 	TOKENHASH(8317255488676642)
 4712 #define CTX_save 	TOKENHASH(508138)
 4713 #define CTX_scale 	TOKENHASH(15604074)
 4714 #define CTX_screen 	TOKENHASH(1088921962)
 4715 #define CTX_setkey 	TOKENHASH(1827516906)
 4716 #define CTX_shadowBlur 	TOKENHASH(2924056626980284)
 4717 #define CTX_shadowColor 	TOKENHASH(3509599043947446)
 4718 #define CTX_shadowOffsetX 	TOKENHASH(8499312693589794)
 4719 #define CTX_shadowOffsetY 	TOKENHASH(8499312693589796)
 4720 #define CTX_smooth_quad_to 	TOKENHASH(6832232668547050)
 4721 #define CTX_smoothQuadTo 	TOKENHASH(8278352345012646)
 4722 #define CTX_smooth_to 	TOKENHASH(38898089692138)
 4723 #define CTX_smoothTo 	TOKENHASH(3515270388878314)
 4724 #define CTX_sourceIn 	TOKENHASH(3444145493687402)
 4725 #define CTX_source_in 	TOKENHASH(35942915423338)
 4726 #define CTX_sourceAtop 	TOKENHASH(2920281959978332)
 4727 #define CTX_source_atop 	TOKENHASH(3007410591464110)
 4728 #define CTX_sourceOut 	TOKENHASH(7371294932695718)
 4729 #define CTX_source_out 	TOKENHASH(3851660580666474)
 4730 #define CTX_sourceOver 	TOKENHASH(7584784067385004)
 4731 #define CTX_source_over 	TOKENHASH(8690648756484770)
 4732 #define CTX_square 	TOKENHASH(511950058)
 4733 #define CTX_start 	TOKENHASH(47455658)
 4734 #define CTX_start_move 	TOKENHASH(2798358138985898)
 4735 #define CTX_start_group 	TOKENHASH(7836274863228782)
 4736 #define CTX_startGroup 	TOKENHASH(3812645199786240)
 4737 #define CTX_stroke 	TOKENHASH(498181546)
 4738 #define CTX_text_align 	TOKENHASH(3398277113762284)
 4739 #define CTX_textAlign 	TOKENHASH(3063795447820748)
 4740 #define CTX_texture 	TOKENHASH(16424292844)
 4741 #define CTX_text_baseline 	TOKENHASH(2589194334827348)
 4742 #define CTX_text_baseline 	TOKENHASH(2589194334827348)
 4743 #define CTX_textBaseline 	TOKENHASH(8381669925369340)
 4744 #define CTX_fillRect 	TOKENHASH(3811453831115472)
 4745 #define CTX_text 	TOKENHASH(1495532)
 4746 #define CTX_text_direction 	TOKENHASH(3614589880641524)
 4747 #define CTX_textDirection 	TOKENHASH(6790122975782654)
 4748 #define CTX_text_indent 	TOKENHASH(3633795456290560)
 4749 #define CTX_text_stroke 	TOKENHASH(8259523149811490)
 4750 #define CTX_strokeText 	TOKENHASH(8131451867629426)
 4751 #define CTX_strokeRect 	TOKENHASH(8165399289138988)
 4752 #define CTX_top 	TOKENHASH(37996)
 4753 #define CTX_transform 	TOKENHASH(34396827557164)
 4754 #define CTX_translate 	TOKENHASH(16912418348332)
 4755 #define CTX_verLineTo 	TOKENHASH(3629696413166220)
 4756 #define CTX_ver_line_to 	TOKENHASH(8345271542726354)
 4757 #define CTX_width 	TOKENHASH(22426354)
 4758 #define CTX_winding 	TOKENHASH(20424590066)
 4759 #define CTX_x 	TOKENHASH(52)
 4760 #define CTX_xor 	TOKENHASH(42100)
 4761 #define CTX_y 	TOKENHASH(54)
 4762 #define CTX_colorSpace 	TOKENHASH(3674150843793134)
 4763 #define CTX_userRGB 	TOKENHASH(59177128181102)
 4764 #define CTX_userCMYK 	TOKENHASH(3354734206905240)
 4765 #define CTX_deviceRGB 	TOKENHASH(7818727413767480)
 4766 #define CTX_deviceCMYK 	TOKENHASH(8943291245184210)
 4767 #define CTX_silver 	TOKENHASH(1358459626)
 4768 #define CTX_fuchsia 	TOKENHASH(7225355728)
 4769 #define CTX_gray 	TOKENHASH(1776914)
 4770 #define CTX_yellow 	TOKENHASH(1714319862)
 4771 #define CTX_white 	TOKENHASH(16145074)
 4772 #define CTX_maroon 	TOKENHASH(1110548702)
 4773 #define CTX_magenta 	TOKENHASH(7952877790)
 4774 #define CTX_blue 	TOKENHASH(506760)
 4775 #define CTX_green 	TOKENHASH(34028818)
 4776 #define CTX_red 	TOKENHASH(12776)
 4777 #define CTX_purple 	TOKENHASH(500344292)
 4778 #define CTX_olive 	TOKENHASH(16276386)
 4779 #define CTX_teal 	TOKENHASH(924140)
 4780 #define CTX_black 	TOKENHASH(27597704)
 4781 #define CTX_cyan 	TOKENHASH(1056458)
 4782 #define CTX_navy 	TOKENHASH(1818848)
 4783 #define CTX_lime 	TOKENHASH(490204)
 4784 #define CTX_aqua 	TOKENHASH(244934)
 4785 #define CTX_transparent 	TOKENHASH(3654078210101184)
 4786 #define CTX_currentColor 	TOKENHASH(7501877057638746)
 4787 
 4788 #endif
 4789 #ifndef __CTX_LIBC_H
 4790 #define __CTX_LIBC_H
 4791 
 4792 #include <stddef.h>
 4793 
 4794 #if 0
 4795 static inline void
 4796 ctx_memset (void *ptr, uint8_t val, int length)
 4797 {
 4798   uint8_t *p = (uint8_t *) ptr;
 4799   for (int i = 0; i < length; i ++)
 4800     { p[i] = val; }
 4801 }
 4802 #else
 4803 #define ctx_memset memset
 4804 #endif
 4805 
 4806 
 4807 static inline void ctx_strcpy (char *dst, const char *src)
 4808 {
 4809   int i = 0;
 4810   for (i = 0; src[i]; i++)
 4811     { dst[i] = src[i]; }
 4812   dst[i] = 0;
 4813 }
 4814 
 4815 static inline char *_ctx_strchr (const char *haystack, char needle)
 4816 {
 4817   const char *p = haystack;
 4818   while (*p && *p != needle)
 4819     {
 4820       p++;
 4821     }
 4822   if (*p == needle)
 4823     { return (char *) p; }
 4824   return NULL;
 4825 }
 4826 static inline char *ctx_strchr (const char *haystack, char needle)
 4827 {
 4828   return _ctx_strchr (haystack, needle);
 4829 }
 4830 
 4831 static inline int ctx_strcmp (const char *a, const char *b)
 4832 {
 4833   int i;
 4834   for (i = 0; a[i] && b[i]; a++, b++)
 4835     if (a[0] != b[0])
 4836       { return 1; }
 4837   if (a[0] == 0 && b[0] == 0) { return 0; }
 4838   return 1;
 4839 }
 4840 
 4841 static inline int ctx_strncmp (const char *a, const char *b, size_t n)
 4842 {
 4843   size_t i;
 4844   for (i = 0; a[i] && b[i] && i < n; a++, b++)
 4845     if (a[0] != b[0])
 4846       { return 1; }
 4847   return 0;
 4848 }
 4849 
 4850 static inline int ctx_strlen (const char *s)
 4851 {
 4852   int len = 0;
 4853   for (; *s; s++) { len++; }
 4854   return len;
 4855 }
 4856 
 4857 static inline char *ctx_strstr (const char *h, const char *n)
 4858 {
 4859   int needle_len = ctx_strlen (n);
 4860   if (n[0]==0)
 4861     { return (char *) h; }
 4862   while (h)
 4863     {
 4864       h = ctx_strchr (h, n[0]);
 4865       if (!h)
 4866         { return NULL; }
 4867       if (!ctx_strncmp (h, n, needle_len) )
 4868         { return (char *) h; }
 4869       h++;
 4870     }
 4871   return NULL;
 4872 }
 4873 
 4874 #endif
 4875 
 4876 #if CTX_IMPLEMENTATION|CTX_COMPOSITE
 4877 
 4878 #ifndef __CTX_INTERNAL_H
 4879 #define __CTX_INTERNAL_H
 4880 
 4881 #include <stdlib.h>
 4882 #include <stdio.h>
 4883 #include <unistd.h>
 4884 #include <math.h>
 4885 #include <sys/select.h> 
 4886 
 4887 typedef struct _CtxRasterizer CtxRasterizer;
 4888 typedef struct _CtxGState     CtxGState;
 4889 typedef struct _CtxState      CtxState;
 4890 
 4891 typedef struct _CtxSource CtxSource;
 4892 
 4893 
 4894 #define CTX_VALID_RGBA_U8     (1<<0)
 4895 #define CTX_VALID_RGBA_DEVICE (1<<1)
 4896 #if CTX_ENABLE_CM
 4897 #define CTX_VALID_RGBA        (1<<2)
 4898 #endif
 4899 #if CTX_ENABLE_CMYK
 4900 #define CTX_VALID_CMYKA       (1<<3)
 4901 #define CTX_VALID_DCMYKA      (1<<4)
 4902 #endif
 4903 #define CTX_VALID_GRAYA       (1<<5)
 4904 #define CTX_VALID_GRAYA_U8    (1<<6)
 4905 #define CTX_VALID_LABA        ((1<<7) | CTX_VALID_GRAYA)
 4906 
 4907 struct _CtxColor
 4908 {
 4909   uint8_t magic; // for colors used in keydb, set to a non valid start of
 4910                  // string value.
 4911   uint8_t rgba[4];
 4912   uint8_t l_u8;
 4913   uint8_t original; // the bitmask of the originally set color
 4914   uint8_t valid;    // bitmask of which members contain valid
 4915   // values, gets denser populated as more
 4916   // formats are requested from a set color.
 4917   float   device_red;
 4918   float   device_green;
 4919   float   device_blue;
 4920   float   alpha;
 4921   float   l;        // luminance and gray
 4922 #if CTX_ENABLE_LAB  // NYI
 4923   float   a;
 4924   float   b;
 4925 #endif
 4926 #if CTX_ENABLE_CMYK
 4927   float   device_cyan;
 4928   float   device_magenta;
 4929   float   device_yellow;
 4930   float   device_key;
 4931   float   cyan;
 4932   float   magenta;
 4933   float   yellow;
 4934   float   key;
 4935 #endif
 4936 
 4937 #if CTX_ENABLE_CM
 4938 #if CTX_BABL
 4939   const Babl *space; // gets copied from state when color is declared
 4940 #else
 4941   void   *space; // gets copied from state when color is declared, 
 4942 #endif
 4943   float   red;
 4944   float   green;
 4945   float   blue;
 4946 #endif
 4947 };
 4948 
 4949 typedef struct _CtxGradientStop CtxGradientStop;
 4950 
 4951 struct _CtxGradientStop
 4952 {
 4953   float   pos;
 4954   CtxColor color;
 4955 };
 4956 
 4957 
 4958 enum _CtxSourceType
 4959 {
 4960   CTX_SOURCE_COLOR = 0,
 4961   CTX_SOURCE_IMAGE,
 4962   CTX_SOURCE_LINEAR_GRADIENT,
 4963   CTX_SOURCE_RADIAL_GRADIENT,
 4964 };
 4965 
 4966 typedef enum _CtxSourceType CtxSourceType;
 4967 
 4968 typedef struct _CtxPixelFormatInfo CtxPixelFormatInfo;
 4969 
 4970 
 4971 struct _CtxBuffer
 4972 {
 4973   void               *data;
 4974   int                 width;
 4975   int                 height;
 4976   int                 stride;
 4977   char               *eid;        // might be NULL, when not - should be 
 4978   unique for pixel contents
 4979   int                 frame;      // last frame used in, everything > 3 can 
 4980   be removed,
 4981                                   // as clients wont rely on it.
 4982   CtxPixelFormatInfo *format;
 4983   void (*free_func) (void *pixels, void *user_data);
 4984   void               *user_data;
 4985 
 4986 #if CTX_ENABLE_CM
 4987 #if CTX_BABL
 4988   const Babl *space;
 4989 #else
 4990   void       *space; 
 4991 #endif
 4992 #endif
 4993 #if 0
 4994   CtxBuffer          *color_managed; /* only valid for one render target, 
 4995   cache
 4996                                         for a specific space
 4997                                         */
 4998 #endif
 4999 };
 5000 
 5001 //void _ctx_user_to_device          (CtxState *state, float *x, float *y);
 5002 //void _ctx_user_to_device_distance (CtxState *state, float *x, float *y);
 5003 
 5004 typedef struct _CtxGradient CtxGradient;
 5005 struct _CtxGradient
 5006 {
 5007   CtxGradientStop stops[16];
 5008   int n_stops;
 5009 };
 5010 
 5011 struct _CtxSource
 5012 {
 5013   int type;
 5014   CtxMatrix  transform;
 5015   union
 5016   {
 5017     CtxColor color;
 5018     struct
 5019     {
 5020       uint8_t rgba[4]; // shares data with set color
 5021       uint8_t pad;
 5022       float x0;
 5023       float y0;
 5024       CtxBuffer *buffer;
 5025     } image;
 5026     struct
 5027     {
 5028       float x0;
 5029       float y0;
 5030       float x1;
 5031       float y1;
 5032       float dx;
 5033       float dy;
 5034       float start;
 5035       float end;
 5036       float length;
 5037       float rdelta;
 5038     } linear_gradient;
 5039     struct
 5040     {
 5041       float x0;
 5042       float y0;
 5043       float r0;
 5044       float x1;
 5045       float y1;
 5046       float r1;
 5047       float rdelta;
 5048     } radial_gradient;
 5049   };
 5050 };
 5051 
 5052 struct _CtxGState
 5053 {
 5054   int           keydb_pos;
 5055   int           stringpool_pos;
 5056 
 5057   CtxMatrix     transform;
 5058   CtxSource     source_stroke;
 5059   CtxSource     source_fill;
 5060   float         global_alpha_f;
 5061   uint8_t       global_alpha_u8;
 5062 
 5063   float         line_width;
 5064   float         line_dash_offset;
 5065   float         miter_limit;
 5066   float         font_size;
 5067 #if CTX_ENABLE_SHADOW_BLUR
 5068   float         shadow_blur;
 5069   float         shadow_offset_x;
 5070   float         shadow_offset_y;
 5071 #endif
 5072   int           clipped:1;
 5073 
 5074   int16_t       clip_min_x;
 5075   int16_t       clip_min_y;
 5076   int16_t       clip_max_x;
 5077   int16_t       clip_max_y;
 5078 
 5079 #if CTX_ENABLE_CM
 5080 #if CTX_BABL
 5081   const Babl   *device_space;
 5082   const Babl   *texture_space;
 5083   const Babl   *rgb_space;       
 5084   const Babl   *cmyk_space;
 5085 
 5086   const Babl   *fish_rgbaf_user_to_device;
 5087   const Babl   *fish_rgbaf_texture_to_device;
 5088   const Babl   *fish_rgbaf_device_to_user;
 5089 
 5090 #else
 5091   void         *device_space;
 5092   void         *texture_space;
 5093   void         *rgb_space;       
 5094   void         *cmyk_space;
 5095   void         *fish_rgbaf_user_to_device; // dummy padding
 5096   void         *fish_rgbaf_texture_to_device; // dummy padding
 5097   void         *fish_rgbaf_device_to_user; // dummy padding
 5098 #endif
 5099 #endif
 5100   CtxCompositingMode  compositing_mode; // bitfield refs lead to
 5101   CtxBlend                  blend_mode; // non-vectorization
 5102 
 5103   float dashes[CTX_PARSER_MAX_ARGS];
 5104   int n_dashes;
 5105 
 5106   CtxColorModel    color_model;
 5107   /* bitfield-pack small state-parts */
 5108   CtxLineCap          line_cap:2;
 5109   CtxLineJoin        line_join:2;
 5110   CtxFillRule        fill_rule:1;
 5111   unsigned int image_smoothing:1;
 5112   unsigned int            font:6;
 5113   unsigned int            bold:1;
 5114   unsigned int          italic:1;
 5115 };
 5116 
 5117 typedef enum
 5118 {
 5119   CTX_TRANSFORMATION_NONE         = 0,
 5120   CTX_TRANSFORMATION_SCREEN_SPACE = 1,
 5121   CTX_TRANSFORMATION_RELATIVE     = 2,
 5122 #if CTX_BITPACK
 5123   CTX_TRANSFORMATION_BITPACK      = 4,
 5124 #endif
 5125   CTX_TRANSFORMATION_STORE_CLEAR  = 16,
 5126 } CtxTransformation;
 5127 
 5128 #define CTX_DRAWLIST_DOESNT_OWN_ENTRIES   64
 5129 #define CTX_DRAWLIST_EDGE_LIST            128
 5130 #define CTX_DRAWLIST_CURRENT_PATH         512
 5131 // BITPACK
 5132 
 5133 struct _CtxDrawlist
 5134 {
 5135   CtxEntry *entries;
 5136   int       count;
 5137   int       size;
 5138   uint32_t  flags;
 5139   int       bitpack_pos;  // stream is bitpacked up to this offset
 5140 };
 5141 
 5142 #define CTX_MAX_KEYDB 64 // number of entries in keydb
 5143                          // entries are "copy-on-change" between states
 5144 
 5145 // the keydb consists of keys set to floating point values,
 5146 // that might also be interpreted as integers for enums.
 5147 //
 5148 // the hash
 5149 typedef struct _CtxKeyDbEntry CtxKeyDbEntry;
 5150 struct _CtxKeyDbEntry
 5151 {
 5152   uint64_t key;
 5153   float value;
 5154   //union { float f[1]; uint8_t u8[4]; }value;
 5155 };
 5156 
 5157 struct _CtxState
 5158 {
 5159   int           has_moved:1;
 5160   int           has_clipped:1;
 5161   float         x;
 5162   float         y;
 5163   int           min_x;
 5164   int           min_y;
 5165   int           max_x;
 5166   int           max_y;
 5167   int16_t       gstate_no;
 5168   CtxGState     gstate;
 5169   CtxGState     gstate_stack[CTX_MAX_STATES];//at end, so can be made 
 5170   dynamic
 5171 #if CTX_GRADIENTS
 5172   CtxGradient   gradient; /* we keep only one gradient,
 5173                              this goes icky with multiple
 5174                              restores - it should really be part of
 5175                              graphics state..
 5176                              XXX, with the stringpool gradients
 5177                              can be stored there.
 5178                            */
 5179 #endif
 5180   CtxKeyDbEntry keydb[CTX_MAX_KEYDB];
 5181   char          stringpool[CTX_STRINGPOOL_SIZE];
 5182 };
 5183 
 5184 
 5185 typedef struct _CtxFont       CtxFont;
 5186 typedef struct _CtxFontEngine CtxFontEngine;
 5187 
 5188 struct _CtxFontEngine
 5189 {
 5190 #if CTX_FONTS_FROM_FILE
 5191   int   (*load_file)   (const char *name, const char *path);
 5192 #endif
 5193   int   (*load_memory) (const char *name, const void *data, int length);
 5194   int   (*glyph)       (CtxFont *font, Ctx *ctx, uint32_t unichar, int 
 5195          stroke);
 5196   float (*glyph_width) (CtxFont *font, Ctx *ctx, uint32_t unichar);
 5197   float (*glyph_kern)  (CtxFont *font, Ctx *ctx, uint32_t unicharA, 
 5198          uint32_t unicharB);
 5199 };
 5200 
 5201 struct _CtxFont
 5202 {
 5203   CtxFontEngine *engine;
 5204   const char *name;
 5205   int type; // 0 ctx    1 stb    2 monobitmap
 5206   union
 5207   {
 5208     struct
 5209     {
 5210       CtxEntry *data;
 5211       int length;
 5212       /* we've got ~110 bytes to fill to cover as
 5213          much data as stbtt_fontinfo */
 5214       //int16_t glyph_pos[26]; // for a..z
 5215       int       glyphs; // number of glyphs
 5216       uint32_t *index;
 5217     } ctx;
 5218     struct
 5219     {
 5220       char *path;
 5221     } ctx_fs;
 5222 #if CTX_FONT_ENGINE_STB
 5223     struct
 5224     {
 5225       stbtt_fontinfo ttf_info;
 5226       int cache_index;
 5227       uint32_t cache_unichar;
 5228     } stb;
 5229 #endif
 5230     struct { int start; int end; int gw; int gh; const uint8_t *data;} 
 5231              monobitmap;
 5232   };
 5233 };
 5234 
 5235 
 5236 enum _CtxIteratorFlag
 5237 {
 5238   CTX_ITERATOR_FLAT           = 0,
 5239   CTX_ITERATOR_EXPAND_BITPACK = 2,
 5240   CTX_ITERATOR_DEFAULTS       = CTX_ITERATOR_EXPAND_BITPACK
 5241 };
 5242 typedef enum _CtxIteratorFlag CtxIteratorFlag;
 5243 
 5244 
 5245 struct
 5246   _CtxIterator
 5247 {
 5248   int              pos;
 5249   int              first_run;
 5250   CtxDrawlist *drawlist;
 5251   int              end_pos;
 5252   int              flags;
 5253 
 5254   int              bitpack_pos;
 5255   int              bitpack_length;     // if non 0 bitpack is active
 5256   CtxEntry         bitpack_command[6]; // the command returned to the
 5257   // user if unpacking is needed.
 5258 };
 5259 #define CTX_MAX_DEVICES 16
 5260 #define CTX_MAX_KEYBINDINGS         256
 5261 
 5262 #if CTX_EVENTS 
 5263 
 5264 // include list implementation - since it already is a header+inline online
 5265 // implementation?
 5266 
 5267 typedef struct CtxItemCb {
 5268   CtxEventType types;
 5269   CtxCb        cb;
 5270   void*        data1;
 5271   void*        data2;
 5272 
 5273   void (*finalize) (void *data1, void *data2, void *finalize_data);
 5274   void  *finalize_data;
 5275 
 5276 } CtxItemCb;
 5277 
 5278 
 5279 #define CTX_MAX_CBS              128
 5280 
 5281 typedef struct CtxItem {
 5282   CtxMatrix inv_matrix;  /* for event coordinate transforms */
 5283 
 5284   /* bounding box */
 5285   float          x0;
 5286   float          y0;
 5287   float          x1;
 5288   float          y1;
 5289 
 5290   void *path;
 5291   double          path_hash;
 5292 
 5293   CtxCursor       cursor; /* if 0 then UNSET and no cursor change is 
 5294   requested
 5295                            */
 5296 
 5297   CtxEventType   types;   /* all cb's ored together */
 5298   CtxItemCb cb[CTX_MAX_CBS];
 5299   int       cb_count;
 5300   int       ref_count;
 5301 } CtxItem;
 5302 
 5303 
 5304 typedef struct _CtxEvents CtxEvents;
 5305 struct _CtxEvents
 5306 {
 5307   int             frozen;
 5308   int             fullscreen;
 5309   CtxList        *grabs; /* could split the grabs per device in the same 
 5310   way,
 5311                             to make dispatch overhead smaller,. probably
 5312                             not much to win though. */
 5313   CtxItem         *prev[CTX_MAX_DEVICES];
 5314   float            pointer_x[CTX_MAX_DEVICES];
 5315   float            pointer_y[CTX_MAX_DEVICES];
 5316   unsigned char    pointer_down[CTX_MAX_DEVICES];
 5317   CtxEvent         drag_event[CTX_MAX_DEVICES];
 5318   CtxList         *idles;
 5319   CtxList         *events; // for ctx_get_event
 5320   int              ctx_get_event_enabled;
 5321   int              idle_id;
 5322   CtxBinding       bindings[CTX_MAX_KEYBINDINGS]; /*< better as list, uses 
 5323   no mem if unused */
 5324   int              n_bindings;
 5325   int              width;
 5326   int              height;
 5327   CtxList         *items;
 5328   CtxItem         *last_item;
 5329   CtxModifierState modifier_state;
 5330   int              tap_delay_min;
 5331   int              tap_delay_max;
 5332   int              tap_delay_hold;
 5333   double           tap_hysteresis;
 5334 };
 5335 
 5336 
 5337 #endif
 5338 
 5339 typedef struct _CtxEidInfo
 5340 {
 5341   char *eid;
 5342   int   frame;
 5343   int   width;
 5344   int   height;
 5345 } CtxEidInfo;
 5346 
 5347 struct _Ctx
 5348 {
 5349   CtxImplementation *renderer;
 5350   CtxDrawlist        drawlist;
 5351   int                transformation;
 5352   CtxBuffer          texture[CTX_MAX_TEXTURES];
 5353   Ctx               *texture_cache;
 5354   CtxList           *eid_db;
 5355   int                rev;
 5356   void              *backend;
 5357   CtxState           state;        /**/
 5358   int                frame; /* used for texture lifetime */
 5359 #if CTX_EVENTS 
 5360   CtxCursor          cursor;
 5361   int                quit;
 5362   int                dirty;
 5363   CtxEvents          events;
 5364   int                mouse_fd;
 5365   int                mouse_x;
 5366   int                mouse_y;
 5367 #endif
 5368 #if CTX_CURRENT_PATH
 5369   CtxDrawlist    current_path; // possibly transformed coordinates !
 5370   CtxIterator        current_path_iterator;
 5371 #endif
 5372 };
 5373 
 5374 
 5375 void ctx_process (Ctx *ctx, CtxEntry *entry);
 5376 CtxBuffer *ctx_buffer_new (int width, int height,
 5377                            CtxPixelFormat pixel_format);
 5378 void ctx_buffer_free (CtxBuffer *buffer);
 5379 
 5380 void
 5381 ctx_state_gradient_clear_stops (CtxState *state);
 5382 
 5383 void ctx_interpret_style         (CtxState *state, CtxEntry *entry, void 
 5384                                   *data);
 5385 void ctx_interpret_transforms    (CtxState *state, CtxEntry *entry, void 
 5386                                   *data);
 5387 void ctx_interpret_pos           (CtxState *state, CtxEntry *entry, void 
 5388                                   *data);
 5389 void ctx_interpret_pos_transform (CtxState *state, CtxEntry *entry, void 
 5390                                   *data);
 5391 
 5392 struct _CtxInternalFsEntry
 5393 {
 5394   char *path;
 5395   int   length;
 5396   char *data;
 5397 };
 5398 
 5399 struct _CtxPixelFormatInfo
 5400 {
 5401   CtxPixelFormat pixel_format;
 5402   uint8_t        components:4; /* number of components */
 5403   uint8_t        bpp; /* bits  per pixel - for doing offset computations
 5404                          along with rowstride found elsewhere, if 0 it 
 5405                          indicates
 5406                          1/8  */
 5407   uint8_t        ebpp; /*effective bytes per pixel - for doing offset
 5408                          computations, for formats that get converted, the
 5409                          ebpp of the working space applied */
 5410   uint8_t        dither_red_blue;
 5411   uint8_t        dither_green;
 5412   CtxPixelFormat composite_format;
 5413 
 5414   void         (*to_comp) (CtxRasterizer *r,
 5415                            int x, const void * __restrict__ src, uint8_t * 
 5416                            __restrict__ comp, int count);
 5417   void         (*from_comp) (CtxRasterizer *r,
 5418                              int x, const uint8_t * __restrict__ comp, void 
 5419                              *__restrict__ dst, int count);
 5420   void         (*apply_coverage) (CtxRasterizer *r, uint8_t * __restrict__ 
 5421                 dst, uint8_t * __restrict__ src, int x, uint8_t *coverage,
 5422                           int count);
 5423   void         (*setup) (CtxRasterizer *r);
 5424 };
 5425 
 5426 static void
 5427 _ctx_user_to_device (CtxState *state, float *x, float *y);
 5428 static void
 5429 _ctx_user_to_device_distance (CtxState *state, float *x, float *y);
 5430 static void ctx_state_init (CtxState *state);
 5431 void
 5432 ctx_interpret_pos_bare (CtxState *state, CtxEntry *entry, void *data);
 5433 void
 5434 ctx_drawlist_deinit (CtxDrawlist *drawlist);
 5435 
 5436 CtxPixelFormatInfo *
 5437 ctx_pixel_format_info (CtxPixelFormat format);
 5438 
 5439 
 5440 int ctx_utf8_len (const unsigned char first_byte);
 5441 const char *ctx_utf8_skip (const char *s, int utf8_length);
 5442 int ctx_utf8_strlen (const char *s);
 5443 int
 5444 ctx_unichar_to_utf8 (uint32_t  ch,
 5445                      uint8_t  *dest);
 5446 
 5447 uint32_t
 5448 ctx_utf8_to_unichar (const char *input);
 5449 
 5450 
 5451 typedef struct _CtxHasher CtxHasher;
 5452 
 5453 typedef struct CtxEdge
 5454 {
 5455 #if CTX_BLOATY_FAST_PATHS
 5456   uint32_t index;  // provide for more aligned memory accesses.
 5457   uint32_t pad;    //
 5458 #else
 5459   uint16_t index;
 5460 #endif
 5461   int32_t  x;     /* the center-line intersection      */
 5462   int32_t  dx;
 5463 } CtxEdge;
 5464 
 5465 typedef void (*CtxFragment) (CtxRasterizer *rasterizer, float x, float y, 
 5466               void *out);
 5467 
 5468 #define CTX_MAX_GAUSSIAN_KERNEL_DIM    512
 5469 
 5470 struct _CtxShapeEntry
 5471 {
 5472   uint32_t hash;
 5473   uint16_t width;
 5474   uint16_t height;
 5475   int      last_frame; // xxx
 5476   uint32_t uses;  // instrumented for longer keep-alive
 5477   uint8_t  data[];
 5478 };
 5479 
 5480 typedef struct _CtxShapeEntry CtxShapeEntry;
 5481 
 5482 
 5483 struct _CtxShapeCache
 5484 {
 5485   CtxShapeEntry *entries[CTX_SHAPE_CACHE_ENTRIES];
 5486   long size;
 5487 };
 5488 
 5489 typedef struct _CtxShapeCache CtxShapeCache;
 5490 
 5491 
 5492 struct _CtxRasterizer
 5493 {
 5494   CtxImplementation vfuncs;
 5495   /* these should be initialized and used as the bounds for rendering into 
 5496   the
 5497      buffer as well XXX: not yet in use, and when in use will only be
 5498      correct for axis aligned clips - proper rasterization of a clipping 
 5499      path
 5500      would be yet another refinement on top.
 5501    */
 5502 
 5503 #if CTX_ENABLE_SHADOW_BLUR
 5504   float      kernel[CTX_MAX_GAUSSIAN_KERNEL_DIM];
 5505 #endif
 5506 
 5507   int        aa;          // level of vertical aa
 5508   int        force_aa;    // force full AA
 5509   int        active_edges;
 5510 #if CTX_RASTERIZER_FORCE_AA==0
 5511   int        pending_edges;   // this-scanline
 5512   int        ending_edges;    // count of edges ending this scanline
 5513 #endif
 5514   int        edge_pos;         // where we're at in iterating all edges
 5515   CtxEdge    edges[CTX_MAX_EDGES];
 5516 
 5517   int        scanline;
 5518   int        scan_min;
 5519   int        scan_max;
 5520   int        col_min;
 5521   int        col_max;
 5522 
 5523 #if CTX_BRAILLE_TEXT
 5524   CtxList   *glyphs;
 5525 #endif
 5526 
 5527   CtxDrawlist edge_list;
 5528 
 5529   CtxState  *state;
 5530   Ctx       *ctx;
 5531   Ctx       *texture_source; /* normally same as ctx */
 5532 
 5533   void      *buf;
 5534 
 5535 #if CTX_COMPOSITING_GROUPS
 5536   void      *saved_buf; // when group redirected
 5537   CtxBuffer *group[CTX_GROUP_MAX];
 5538 #endif
 5539 
 5540   float      x;  // < redundant? use state instead?
 5541   float      y;
 5542 
 5543   float      first_x;
 5544   float      first_y;
 5545   int8_t     needs_aa; // count of how many edges implies antialiasing
 5546   int        has_shape:2;
 5547   int        has_prev:2;
 5548   int        preserve:1;
 5549   int        uses_transforms:1;
 5550 #if CTX_BRAILLE_TEXT
 5551   int        term_glyphs:1; // store appropriate glyphs for redisplay
 5552 #endif
 5553 
 5554   int16_t    blit_x;
 5555   int16_t    blit_y;
 5556   int16_t    blit_width;
 5557   int16_t    blit_height;
 5558   int16_t    blit_stride;
 5559 
 5560   CtxPixelFormatInfo *format;
 5561 
 5562 #if CTX_ENABLE_SHADOW_BLUR
 5563   int in_shadow;
 5564 #endif
 5565   int in_text;
 5566   int shadow_x;
 5567   int shadow_y;
 5568 
 5569   CtxFragment         fragment;
 5570   int swap_red_green;
 5571   uint8_t             color[4*5];
 5572 
 5573 #define CTX_COMPOSITE_ARGUMENTS CtxRasterizer *rasterizer, uint8_t * 
 5574 __restrict__ dst, uint8_t * __restrict__ src, int x0, uint8_t * 
 5575 __restrict__ coverage, int count
 5576 
 5577   void (*comp_op)(CTX_COMPOSITE_ARGUMENTS);
 5578 #if CTX_ENABLE_CLIP
 5579   CtxBuffer *clip_buffer;
 5580 #endif
 5581 
 5582   int clip_rectangle;
 5583 
 5584 #if CTX_SHAPE_CACHE
 5585   CtxShapeCache shape_cache;
 5586 #endif
 5587 };
 5588 
 5589 struct _CtxHasher
 5590 {
 5591   CtxRasterizer rasterizer;
 5592   int           cols;
 5593   int           rows;
 5594   uint8_t      *hashes;
 5595   int           salt;
 5596 };
 5597 
 5598 #if CTX_RASTERIZER
 5599 void ctx_rasterizer_deinit (CtxRasterizer *rasterizer);
 5600 #endif
 5601 
 5602 #if CTX_EVENTS
 5603 extern int ctx_native_events;
 5604 
 5605 #if CTX_SDL
 5606 extern int ctx_sdl_events;
 5607 int ctx_sdl_consume_events (Ctx *ctx);
 5608 #endif
 5609 
 5610 #if CTX_FB
 5611 extern int ctx_fb_events;
 5612 int ctx_fb_consume_events (Ctx *ctx);
 5613 #endif
 5614 
 5615 
 5616 int ctx_nct_consume_events (Ctx *ctx);
 5617 int ctx_ctx_consume_events (Ctx *ctx);
 5618 
 5619 #endif
 5620 
 5621 enum {
 5622   NC_MOUSE_NONE  = 0,
 5623   NC_MOUSE_PRESS = 1,  /* "mouse-pressed", "mouse-released" */
 5624   NC_MOUSE_DRAG  = 2,  /* + "mouse-drag"   (motion with pressed button) */
 5625   NC_MOUSE_ALL   = 3   /* + "mouse-motion" (also delivered for release) */
 5626 };
 5627 void _ctx_mouse (Ctx *term, int mode);
 5628 void nc_at_exit (void);
 5629 
 5630 int ctx_terminal_width  (void);
 5631 int ctx_terminal_height (void);
 5632 int ctx_terminal_cols   (void);
 5633 int ctx_terminal_rows   (void);
 5634 extern int ctx_frame_ack;
 5635 
 5636 int ctx_nct_consume_events (Ctx *ctx);
 5637 
 5638 typedef struct _CtxCtx CtxCtx;
 5639 struct _CtxCtx
 5640 {
 5641    void (*render) (void *ctxctx, CtxCommand *command);
 5642    void (*reset)  (void *ctxvtx);
 5643    void (*flush)  (void *ctxctx);
 5644    char *(*get_clipboard) (void *ctxctx);
 5645    void (*set_clipboard) (void *ctxctx, const char *text);
 5646    void (*free)   (void *ctxctx);
 5647    Ctx *ctx;
 5648    int  width;
 5649    int  height;
 5650    int  cols;
 5651    int  rows;
 5652    int  was_down;
 5653 };
 5654 
 5655 
 5656 extern int _ctx_max_threads;
 5657 extern int _ctx_enable_hash_cache;
 5658 void
 5659 ctx_set (Ctx *ctx, uint64_t key_hash, const char *string, int len);
 5660 const char *
 5661 ctx_get (Ctx *ctx, const char *key);
 5662 
 5663 int ctx_renderer_is_braille (Ctx *ctx);
 5664 Ctx *ctx_new_ctx (int width, int height);
 5665 Ctx *ctx_new_fb (int width, int height, int drm);
 5666 Ctx *ctx_new_sdl (int width, int height);
 5667 Ctx *ctx_new_braille (int width, int height);
 5668 
 5669 int ctx_resolve_font (const char *name);
 5670 extern float ctx_u8_float[256];
 5671 #define ctx_u8_to_float(val_u8) ctx_u8_float[((uint8_t)(val_u8))]
 5672 //#define ctx_u8_to_float(val_u8) (val_u8/255.0f)
 5673 //
 5674 //
 5675 
 5676 
 5677 static uint8_t ctx_float_to_u8 (float val_f)
 5678 {
 5679    return (val_f * 255.99f);
 5680 #if 0
 5681   int val_i = val_f * 255.999f;
 5682   if (val_i < 0) { return 0; }
 5683   else if (val_i > 255) { return 255; }
 5684   return val_i;
 5685 #endif
 5686 }
 5687 
 5688 
 5689 #define CTX_CSS_LUMINANCE_RED   0.3f
 5690 #define CTX_CSS_LUMINANCE_GREEN 0.59f
 5691 #define CTX_CSS_LUMINANCE_BLUE  0.11f
 5692 
 5693 /* works on both float and uint8_t */
 5694 #define CTX_CSS_RGB_TO_LUMINANCE(rgb)  (\
 5695   (rgb[0]) * CTX_CSS_LUMINANCE_RED + \
 5696   (rgb[1]) * CTX_CSS_LUMINANCE_GREEN +\
 5697   (rgb[2]) * CTX_CSS_LUMINANCE_BLUE)
 5698 
 5699 const char *ctx_nct_get_event (Ctx *n, int timeoutms, int *x, int *y);
 5700 const char *ctx_native_get_event (Ctx *n, int timeoutms);
 5701 void
 5702 ctx_color_get_rgba8 (CtxState *state, CtxColor *color, uint8_t *out);
 5703 void ctx_color_get_graya_u8 (CtxState *state, CtxColor *color, uint8_t *out)
 5704                              ;
 5705 float ctx_float_color_rgb_to_gray (CtxState *state, const float *rgb);
 5706 void ctx_color_get_graya (CtxState *state, CtxColor *color, float *out);
 5707 void ctx_rgb_to_cmyk (float r, float g, float b,
 5708               float *c_out, float *m_out, float *y_out, float *k_out);
 5709 uint8_t ctx_u8_color_rgb_to_gray (CtxState *state, const uint8_t *rgb);
 5710 #if CTX_ENABLE_CMYK
 5711 void ctx_color_get_cmyka (CtxState *state, CtxColor *color, float *out);
 5712 #endif
 5713 static void ctx_color_set_RGBA8 (CtxState *state, CtxColor *color, uint8_t 
 5714                                  r, uint8_t g, uint8_t b, uint8_t a);
 5715 void ctx_color_set_rgba (CtxState *state, CtxColor *color, float r, float g,
 5716                          float b, float a);
 5717 static void ctx_color_set_drgba (CtxState *state, CtxColor *color, float r, 
 5718                                  float g, float b, float a);
 5719 void ctx_color_get_cmyka (CtxState *state, CtxColor *color, float *out);
 5720 static void ctx_color_set_cmyka (CtxState *state, CtxColor *color, float c, 
 5721                                  float m, float y, float k, float a);
 5722 static void ctx_color_set_dcmyka (CtxState *state, CtxColor *color, float c,
 5723                                   float m, float y, float k, float a);
 5724 static void ctx_color_set_graya (CtxState *state, CtxColor *color, float 
 5725                                  gray, float alpha);
 5726 
 5727 int ctx_color_model_get_components (CtxColorModel model);
 5728 
 5729 void ctx_state_set (CtxState *state, uint64_t key, float value);
 5730 static void
 5731 ctx_matrix_set (CtxMatrix *matrix, float a, float b, float c, float d, 
 5732                 float e, float f);
 5733 static void ctx_font_setup ();
 5734 float ctx_state_get (CtxState *state, uint64_t hash);
 5735 
 5736 #if CTX_RASTERIZER
 5737 
 5738 static void
 5739 ctx_rasterizer_rel_move_to (CtxRasterizer *rasterizer, float x, float y);
 5740 static void
 5741 ctx_rasterizer_rel_line_to (CtxRasterizer *rasterizer, float x, float y);
 5742 
 5743 static void
 5744 ctx_rasterizer_move_to (CtxRasterizer *rasterizer, float x, float y);
 5745 static void
 5746 ctx_rasterizer_line_to (CtxRasterizer *rasterizer, float x, float y);
 5747 static void
 5748 ctx_rasterizer_curve_to (CtxRasterizer *rasterizer,
 5749                          float x0, float y0,
 5750                          float x1, float y1,
 5751                          float x2, float y2);
 5752 static void
 5753 ctx_rasterizer_rel_curve_to (CtxRasterizer *rasterizer,
 5754                          float x0, float y0,
 5755                          float x1, float y1,
 5756                          float x2, float y2);
 5757 
 5758 static void
 5759 ctx_rasterizer_reset (CtxRasterizer *rasterizer);
 5760 static uint32_t ctx_rasterizer_poly_to_hash (CtxRasterizer *rasterizer);
 5761 static void
 5762 ctx_rasterizer_arc (CtxRasterizer *rasterizer,
 5763                     float        x,
 5764                     float        y,
 5765                     float        radius,
 5766                     float        start_angle,
 5767                     float        end_angle,
 5768                     int          anticlockwise);
 5769 
 5770 static void
 5771 ctx_rasterizer_quad_to (CtxRasterizer *rasterizer,
 5772                         float        cx,
 5773                         float        cy,
 5774                         float        x,
 5775                         float        y);
 5776 
 5777 static void
 5778 ctx_rasterizer_rel_quad_to (CtxRasterizer *rasterizer,
 5779                         float        cx,
 5780                         float        cy,
 5781                         float        x,
 5782                         float        y);
 5783 
 5784 static void
 5785 ctx_rasterizer_rectangle (CtxRasterizer *rasterizer,
 5786                           float x,
 5787                           float y,
 5788                           float width,
 5789                           float height);
 5790 
 5791 static void ctx_rasterizer_finish_shape (CtxRasterizer *rasterizer);
 5792 static void ctx_rasterizer_clip (CtxRasterizer *rasterizer);
 5793 static void
 5794 ctx_rasterizer_set_font (CtxRasterizer *rasterizer, const char *font_name);
 5795 
 5796 static void
 5797 ctx_rasterizer_gradient_add_stop (CtxRasterizer *rasterizer, float pos, 
 5798                                   float *rgba);
 5799 static void
 5800 ctx_rasterizer_set_pixel (CtxRasterizer *rasterizer,
 5801                           uint16_t x,
 5802                           uint16_t y,
 5803                           uint8_t r,
 5804                           uint8_t g,
 5805                           uint8_t b,
 5806                           uint8_t a);
 5807 static void
 5808 ctx_rasterizer_rectangle (CtxRasterizer *rasterizer,
 5809                           float x,
 5810                           float y,
 5811                           float width,
 5812                           float height);
 5813 static void
 5814 ctx_rasterizer_round_rectangle (CtxRasterizer *rasterizer, float x, float y,
 5815                                 float width, float height, float 
 5816                                 corner_radius);
 5817 
 5818 #endif
 5819 
 5820 #if CTX_ENABLE_CM // XXX to be moved to ctx.h
 5821 void
 5822 ctx_set_drgb_space (Ctx *ctx, int device_space);
 5823 void
 5824 ctx_set_dcmyk_space (Ctx *ctx, int device_space);
 5825 void
 5826 ctx_rgb_space (Ctx *ctx, int device_space);
 5827 void
 5828 ctx_set_cmyk_space (Ctx *ctx, int device_space);
 5829 #endif
 5830 
 5831 #endif
 5832 
 5833 CtxRasterizer *
 5834 ctx_rasterizer_init (CtxRasterizer *rasterizer, Ctx *ctx, Ctx 
 5835                      *texture_source, CtxState *state, void *data, int x, 
 5836                      int y, int width, int height, int stride, 
 5837                      CtxPixelFormat pixel_format, CtxAntialias antialias);
 5838 
 5839 
 5840 CTX_INLINE static uint8_t ctx_lerp_u8 (uint8_t v0, uint8_t v1, uint8_t dx)
 5841 {
 5842 #if 0
 5843   return v0 + ((v1-v0) * dx)/255;
 5844 #else
 5845   return ( ( ( ( (v0) <<8) + (dx) * ( (v1) - (v0) ) ) ) >>8);
 5846 #endif
 5847 }
 5848 
 5849 CTX_INLINE static float
 5850 ctx_lerpf (float v0, float v1, float dx)
 5851 {
 5852   return v0 + (v1-v0) * dx;
 5853 }
 5854 
 5855 
 5856 #ifndef CTX_MIN
 5857 #define CTX_MIN(a,b)  (((a)<(b))?(a):(b))
 5858 #endif
 5859 #ifndef CTX_MAX
 5860 #define CTX_MAX(a,b)  (((a)>(b))?(a):(b))
 5861 #endif
 5862 
 5863 static inline void *ctx_calloc (size_t size, size_t count);
 5864 
 5865 void ctx_screenshot (Ctx *ctx, const char *output_path);
 5866 
 5867 
 5868 CtxSHA1 *ctx_sha1_new (void);
 5869 void ctx_sha1_free (CtxSHA1 *sha1);
 5870 int ctx_sha1_process(CtxSHA1 *sha1, const unsigned char * msg, unsigned 
 5871                      long len);
 5872 int ctx_sha1_done(CtxSHA1 * sha1, unsigned char *out);
 5873 
 5874 void _ctx_texture_lock (void);
 5875 void _ctx_texture_unlock (void);
 5876 uint8_t *ctx_define_texture_pixel_data (CtxEntry *entry);
 5877 void ctx_buffer_pixels_free (void *pixels, void *userdata);
 5878 
 5879 /*ctx_texture_init:
 5880  * return value: eid, as passed in or if NULL generated by hashing pixels 
 5881  and width/height
 5882  * XXX  this is low-level and not to be used directly use define_texture 
 5883  instead.  XXX
 5884  */
 5885 const char *ctx_texture_init (
 5886                       Ctx        *ctx,
 5887                       const char *eid,
 5888                       int         width,
 5889                       int         height,
 5890                       int         stride,
 5891                       CtxPixelFormat format,
 5892                       void       *space,
 5893                       uint8_t    *pixels,
 5894                       void (*freefunc) (void *pixels, void *user_data),
 5895                       void *user_data);
 5896 
 5897 #if CTX_TILED
 5898 #include <threads.h>
 5899 #endif
 5900 typedef struct _CtxTiled CtxTiled;
 5901 
 5902 struct _CtxTiled
 5903 {
 5904    void (*render)    (void *braille, CtxCommand *command);
 5905    void (*reset)     (void *braille);
 5906    void (*flush)     (void *braille);
 5907    char *(*get_clipboard) (void *ctxctx);
 5908    void (*set_clipboard) (void *ctxctx, const char *text);
 5909    void (*free)      (void *braille);
 5910    Ctx          *ctx;
 5911    int           width;
 5912    int           height;
 5913    int           cols;
 5914    int           rows;
 5915    int           was_down;
 5916    uint8_t      *pixels;
 5917    Ctx          *ctx_copy;
 5918    Ctx          *host[CTX_MAX_THREADS];
 5919    CtxAntialias  antialias;
 5920    int           quit;
 5921 #if CTX_TILED
 5922    _Atomic int   thread_quit;
 5923 #endif
 5924    int           shown_frame;
 5925    int           render_frame;
 5926    int           rendered_frame[CTX_MAX_THREADS];
 5927    int           frame;
 5928    int       min_col; // hasher cols and rows
 5929    int       min_row;
 5930    int       max_col;
 5931    int       max_row;
 5932    uint8_t  hashes[CTX_HASH_ROWS * CTX_HASH_COLS *  20];
 5933    int8_t    tile_affinity[CTX_HASH_ROWS * CTX_HASH_COLS]; // which render 
 5934    thread no is
 5935                                                            // responsible 
 5936                                                            for a tile
 5937                                                            //
 5938 
 5939    int           pointer_down[3];
 5940 
 5941    CtxCursor     shown_cursor;
 5942 #if CTX_TILED
 5943    cnd_t  cond;
 5944    mtx_t  mtx;
 5945 #endif
 5946 };
 5947 
 5948 
 5949 #endif
 5950 
 5951 
 5952 #if CTX_IMPLEMENTATION
 5953 
 5954 #define SHA1_IMPLEMENTATION
 5955 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
 5956  *
 5957  * LibTomCrypt is a library that provides various cryptographic
 5958  * algorithms in a highly modular and flexible manner.
 5959  *
 5960  * The library is free for all purposes without any express
 5961  * guarantee it works.
 5962  *
 5963  * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
 5964  *
 5965  * The plain ANSIC sha1 functionality has been extracted from libtomcrypt,
 5966  * and is included directly in the sources. /Øyvind K. - since libtomcrypt
 5967  * is public domain the adaptations done here to make the sha1 self 
 5968  contained
 5969  * also is public domain.
 5970  */
 5971 #ifndef __SHA1_H
 5972 #define __SHA1_H
 5973 #include <inttypes.h>
 5974 
 5975 struct _CtxSHA1 {
 5976     uint64_t length;
 5977     uint32_t state[5], curlen;
 5978     unsigned char buf[64];
 5979 };
 5980 
 5981 int ctx_sha1_init(CtxSHA1 * sha1);
 5982 CtxSHA1 *ctx_sha1_new (void)
 5983 {
 5984   CtxSHA1 *state = (CtxSHA1*)calloc (sizeof (CtxSHA1), 1);
 5985   ctx_sha1_init (state);
 5986   return state;
 5987 }
 5988 void ctx_sha1_free (CtxSHA1 *sha1)
 5989 {
 5990   free (sha1);
 5991 }
 5992 
 5993 #if 0
 5994           CtxSHA1 sha1;
 5995           ctx_sha1_init (&sha1);
 5996           ctx_sha1_process(&sha1, (unsigned char*)&shape_rect, sizeof (
 5997                            CtxIntRectangle));
 5998           ctx_sha1_done(&sha1, (unsigned char*)ctx_sha1_hash);
 5999 #endif
 6000 
 6001 #ifdef FF0
 6002 #undef FF0
 6003 #endif
 6004 #ifdef FF1
 6005 #undef FF1
 6006 #endif
 6007 
 6008 #ifdef SHA1_IMPLEMENTATION
 6009 #include <stdlib.h>
 6010 #include <string.h>
 6011 
 6012 #define STORE64H(x,                                                         
 6013                  y)                                                         
 6014                  \
 6015    { (y)[0] = (unsigned char)(((x)>>56)&255); (y)[1] = (unsigned            
 6016      char)(((x)>>48)&255);     \
 6017      (y)[2] = (unsigned char)(((x)>>40)&255); (y)[3] = (unsigned            
 6018       char)(((x)>>32)&255);     \
 6019      (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned            
 6020       char)(((x)>>16)&255);     \
 6021      (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)
 6022       &255); }
 6023 
 6024 #define STORE32H(x,                                                         
 6025                  y)                                                         
 6026                  \
 6027      { (y)[0] = (unsigned char)(((x)>>24)&255); (y)[1] = (unsigned          
 6028        char)(((x)>>16)&255);   \
 6029        (y)[2] = (unsigned char)(((x)>>8)&255); (y)[3] = (unsigned           
 6030         char)((x)&255); }
 6031 
 6032 #define LOAD32H(x, y)                            \
 6033      { x = ((unsigned long)((y)[0] & 255)<<24) | \
 6034            ((unsigned long)((y)[1] & 255)<<16) | \
 6035            ((unsigned long)((y)[2] & 255)<<8)  | \
 6036            ((unsigned long)((y)[3] & 255)); }
 6037 
 6038 /* rotates the hard way */
 6039 #define ROL(x, y)  ((((unsigned long)(x)<<(unsigned long)((y)&31)) | (((
 6040             unsigned long)(x)&0xFFFFFFFFUL)>>(unsigned long)(32-((y)&31)))) 
 6041             & 0xFFFFFFFFUL)
 6042 #define ROLc(x, y) ROL(x,y)
 6043 
 6044 #define CRYPT_OK     0
 6045 #define CRYPT_ERROR  1
 6046 #define CRYPT_NOP    2
 6047 
 6048 #ifndef MAX
 6049    #define MAX(x, y) ( ((x)>(y))?(x):(y) )
 6050 #endif
 6051 #ifndef MIN
 6052    #define MIN(x, y) ( ((x)<(y))?(x):(y) )
 6053 #endif
 6054 
 6055 /* a simple macro for making hash "process" functions */
 6056 #define HASH_PROCESS(func_name, compress_name, state_var, block_size)       
 6057                      \
 6058 int func_name (CtxSHA1 *sha1, const unsigned char *in, unsigned long inlen) 
 6059                \
 6060 
 6061 \
 6062     unsigned long n;                                                        
 6063     \
 6064     int           err;                                                      
 6065     \
 6066     assert (sha1 != NULL);                                                  
 6067             \
 6068     assert (in != NULL);                                                    
 6069             \
 6070     if (sha1->curlen > sizeof(sha1->buf)) {                                 
 6071         \
 6072        return -1;                                                           
 6073        \
 6074     }                                                                       
 6075     \
 6076     while (inlen > 0) {                                                     
 6077            \
 6078         if (sha1->curlen == 0 && inlen >= block_size) {                     
 6079             \
 6080            if ((err = compress_name (sha1, (unsigned char *)in)) != 
 6081                CRYPT_OK) {     \
 6082               return err;                                                   
 6083               \
 6084            }                                                                
 6085            \
 6086            sha1->length += block_size * 8;                                  
 6087                            \
 6088            in             += block_size;                                    
 6089                              \
 6090            inlen          -= block_size;                                    
 6091                              \
 6092 
 6093 \
 6094            n = MIN(inlen, (block_size - sha1->curlen));                     
 6095                \
 6096            memcpy(sha1->buf + sha1->curlen, in, (size_t)n);                 
 6097                   \
 6098            sha1->curlen += n;                                               
 6099                            \
 6100            in             += n;                                             
 6101                              \
 6102            inlen          -= n;                                             
 6103                              \
 6104            if (sha1->curlen == block_size) {                                
 6105                \
 6106               if ((err = compress_name (sha1, sha1->buf)) != CRYPT_OK) {    
 6107                   \
 6108                  return err;                                                
 6109                  \
 6110               }                                                             
 6111               \
 6112               sha1->length += 8*block_size;                                 
 6113                               \
 6114               sha1->curlen = 0;                                             
 6115                              \
 6116            }                                                                
 6117            \
 6118