/* * libcucul Canvas for ultrafast compositing of Unicode letters * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ /** \file export_svg.c * \version \$Id$ * \author Sam Hocevar * \author Jean-Yves Lamoureux * \brief Export function * * This file contains export functions for SVG (Scalable Vector Graphics files */ #include "config.h" #if !defined(__KERNEL__) # include # include # include #endif #include "cucul.h" #include "cucul_internals.h" static char const svg_header[] = "\n" "\n" " \n" " \n"); cur += sprintf(cur, " \n"); cur += sprintf(cur, " \n"); /* Background */ for(y = 0; y < qq->height; y++) { uint32_t *lineattr = qq->attr + y * qq->width; for(x = 0; x < qq->width; x++) { cur += sprintf(cur, "\n", _cucul_argb32_to_ansi8(*lineattr++), x * 6, y * 10); } } /* Text */ for(y = 0; y < qq->height; y++) { uint32_t *lineattr = qq->attr + y * qq->width; uint32_t *linechar = qq->chars + y * qq->width; for(x = 0; x < qq->width; x++) { uint32_t c = *linechar++; cur += sprintf(cur, "", _cucul_argb32_to_ansi8(*lineattr++), x * 6, (y * 10) + 10); if(c < 0x00000020) cur += sprintf(cur, "?"); else if(c > 0x0000007f) { static const uint8_t mark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; char buf[10], *parser; int bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4; buf[bytes] = '\0'; parser = buf + bytes; switch(bytes) { case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6; case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6; case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6; } *--parser = c | mark[bytes]; cur += sprintf(cur, "%s", buf); } else switch((uint8_t)c) { case '>': cur += sprintf(cur, ">"); break; case '<': cur += sprintf(cur, "<"); break; case '&': cur += sprintf(cur, "&"); break; default: cur += sprintf(cur, "%c", c); break; } cur += sprintf(cur, "\n"); } } cur += sprintf(cur, " \n"); cur += sprintf(cur, "\n"); /* Crop to really used size */ ex->size = (uintptr_t)(cur - ex->data); ex->data = realloc(ex->data, ex->size); }