| @@ -33,6 +33,7 @@ libcucul_la_SOURCES = \ | |||||
| export_html.c \ | export_html.c \ | ||||
| export_ps.c \ | export_ps.c \ | ||||
| export_svg.c \ | export_svg.c \ | ||||
| export_bitmap.c \ | |||||
| $(NULL) | $(NULL) | ||||
| libcucul_la_LDFLAGS = -no-undefined | libcucul_la_LDFLAGS = -no-undefined | ||||
| libcucul_la_LIBADD = @CUCUL_LIBS@ | libcucul_la_LIBADD = @CUCUL_LIBS@ | ||||
| @@ -256,7 +256,9 @@ void cucul_free(cucul_t *qq) | |||||
| * | * | ||||
| * \li \e "ps": export a PostScript document. | * \li \e "ps": export a PostScript document. | ||||
| * | * | ||||
| * \li \e "svg": export an SVG document. | |||||
| * \li \e "svg": export an SVG vector image. | |||||
| * | |||||
| * \li \e "tga": export a TGA image. | |||||
| * | * | ||||
| * \param qq A libcucul canvas | * \param qq A libcucul canvas | ||||
| * \param format A string describing the requested output format. | * \param format A string describing the requested output format. | ||||
| @@ -266,6 +268,8 @@ cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format) | |||||
| cucul_buffer_t *ex; | cucul_buffer_t *ex; | ||||
| ex = malloc(sizeof(cucul_buffer_t)); | ex = malloc(sizeof(cucul_buffer_t)); | ||||
| ex->size = 0; | |||||
| ex->data = NULL; | |||||
| if(!strcasecmp("ansi", format)) | if(!strcasecmp("ansi", format)) | ||||
| _cucul_get_ansi(qq, ex); | _cucul_get_ansi(qq, ex); | ||||
| @@ -279,7 +283,10 @@ cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format) | |||||
| _cucul_get_ps(qq, ex); | _cucul_get_ps(qq, ex); | ||||
| else if(!strcasecmp("svg", format)) | else if(!strcasecmp("svg", format)) | ||||
| _cucul_get_svg(qq, ex); | _cucul_get_svg(qq, ex); | ||||
| else | |||||
| else if(!strcasecmp("tga", format)) | |||||
| _cucul_get_tga(qq, ex); | |||||
| if(ex->size == 0) | |||||
| { | { | ||||
| free(ex); | free(ex); | ||||
| return NULL; | return NULL; | ||||
| @@ -304,9 +311,10 @@ char const * const * cucul_get_export_list(void) | |||||
| "ansi", "ANSI", | "ansi", "ANSI", | ||||
| "html", "HTML", | "html", "HTML", | ||||
| "html3", "backwards-compatible HTML", | "html3", "backwards-compatible HTML", | ||||
| "irc", "IRC (mIRC colours)", | |||||
| "ps", "PostScript", | |||||
| "svg", "SVG", | |||||
| "irc", "IRC with mIRC colours", | |||||
| "ps", "PostScript document", | |||||
| "svg", "SVG vector image", | |||||
| "tga", "TGA image", | |||||
| NULL, NULL | NULL, NULL | ||||
| }; | }; | ||||
| @@ -78,5 +78,6 @@ extern void _cucul_get_html3(cucul_t *, cucul_buffer_t *); | |||||
| extern void _cucul_get_irc(cucul_t *, cucul_buffer_t *); | extern void _cucul_get_irc(cucul_t *, cucul_buffer_t *); | ||||
| extern void _cucul_get_ps(cucul_t *, cucul_buffer_t *); | extern void _cucul_get_ps(cucul_t *, cucul_buffer_t *); | ||||
| extern void _cucul_get_svg(cucul_t *, cucul_buffer_t *); | extern void _cucul_get_svg(cucul_t *, cucul_buffer_t *); | ||||
| extern void _cucul_get_tga(cucul_t *, cucul_buffer_t *); | |||||
| #endif /* __CUCUL_INTERNALS_H__ */ | #endif /* __CUCUL_INTERNALS_H__ */ | ||||
| @@ -0,0 +1,83 @@ | |||||
| /* | |||||
| * libcucul Canvas for ultrafast compositing of Unicode letters | |||||
| * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||||
| * All Rights Reserved | |||||
| * | |||||
| * $Id$ | |||||
| * | |||||
| * 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. | |||||
| */ | |||||
| /* | |||||
| * This file contains export functions for bitmap formats | |||||
| */ | |||||
| #include "config.h" | |||||
| #if !defined(__KERNEL__) | |||||
| # include <stdlib.h> | |||||
| # include <stdio.h> | |||||
| # include <string.h> | |||||
| #endif | |||||
| #include "cucul.h" | |||||
| #include "cucul_internals.h" | |||||
| void _cucul_get_tga(cucul_t *qq, cucul_buffer_t *ex) | |||||
| { | |||||
| char const * const * fonts; | |||||
| char * cur; | |||||
| cucul_font_t *f; | |||||
| unsigned int i, w, h; | |||||
| fonts = cucul_get_font_list(); | |||||
| if(!fonts[0]) | |||||
| return; | |||||
| f = cucul_load_font(fonts[0], 0); | |||||
| w = cucul_get_width(qq) * cucul_get_font_width(f); | |||||
| h = cucul_get_height(qq) * cucul_get_font_height(f); | |||||
| ex->size = w * h * 4 + 18; | |||||
| ex->data = malloc(ex->size); | |||||
| cur = ex->data; | |||||
| /* ID Length */ | |||||
| cur += sprintf(cur, "%c", 0); | |||||
| /* Color Map Type: no colormap */ | |||||
| cur += sprintf(cur, "%c", 0); | |||||
| /* Image Type: uncompressed truecolor */ | |||||
| cur += sprintf(cur, "%c", 2); | |||||
| /* Color Map Specification: no color map */ | |||||
| memset(cur, 0, 5); cur += 5; | |||||
| /* Image Specification */ | |||||
| cur += sprintf(cur, "%c%c", 0, 0); /* X Origin */ | |||||
| cur += sprintf(cur, "%c%c", 0, 0); /* Y Origin */ | |||||
| cur += sprintf(cur, "%c%c", w & 0xff, w >> 8); /* Width */ | |||||
| cur += sprintf(cur, "%c%c", h & 0xff, h >> 8); /* Height */ | |||||
| cur += sprintf(cur, "%c", 32); /* Pixel Depth */ | |||||
| cur += sprintf(cur, "%c", 40); /* Image Descriptor */ | |||||
| /* Image ID: no ID */ | |||||
| /* Color Map Data: no colormap */ | |||||
| /* Image Data */ | |||||
| cucul_render_canvas(qq, f, cur, w, h, 4 * w); | |||||
| /* Swap bytes. What a waste of time. */ | |||||
| for(i = 0; i < w * h * 4; i += 4) | |||||
| { | |||||
| char w; | |||||
| w = cur[i]; cur[i] = cur[i + 3]; cur[i + 3] = w; | |||||
| w = cur[i + 1]; cur[i + 1] = cur[i + 2]; cur[i + 2] = w; | |||||
| } | |||||
| cucul_free_font(f); | |||||
| } | |||||