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