You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

187 lines
3.3 KiB

  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. /*
  14. * This file contains legacy functions that we keep around until all
  15. * applications are ported.
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #if !defined(__KERNEL__)
  20. # if defined(HAVE_ERRNO_H)
  21. # include <errno.h>
  22. # endif
  23. # include <stdio.h>
  24. # include <stdlib.h>
  25. # include <string.h>
  26. #endif
  27. #include "cucul.h"
  28. #include "cucul_internals.h"
  29. /*
  30. * Functions from canvas.c
  31. */
  32. int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
  33. {
  34. return cucul_put_char(cv, x, y, ch);
  35. }
  36. int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
  37. {
  38. return cucul_put_str(cv, x, y, s);
  39. }
  40. /*
  41. * Functions from color.c
  42. */
  43. int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
  44. {
  45. return cucul_set_color_ansi(cv, fg, bg);
  46. }
  47. int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
  48. {
  49. return cucul_set_color_argb(cv, fg, bg);
  50. }
  51. /*
  52. * Functions from import.c
  53. */
  54. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  55. {
  56. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  57. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  58. buf->size, format);
  59. if(ret < 0)
  60. {
  61. cucul_free_canvas(cv);
  62. return NULL;
  63. }
  64. return cv;
  65. }
  66. /*
  67. * Functions from export.c
  68. */
  69. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  70. {
  71. cucul_buffer_t *ex;
  72. ex = malloc(sizeof(cucul_buffer_t));
  73. if(!ex)
  74. {
  75. #if defined(HAVE_ERRNO_H)
  76. errno = ENOMEM;
  77. #endif
  78. return NULL;
  79. }
  80. ex->data = cucul_export_memory(cv, format, &ex->size);
  81. if(!ex->data)
  82. {
  83. free(ex);
  84. return NULL;
  85. }
  86. ex->user_data = 0;
  87. return ex;
  88. }
  89. /*
  90. * Functions from buffer.c
  91. */
  92. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  93. {
  94. cucul_buffer_t *buf;
  95. buf = malloc(sizeof(cucul_buffer_t));
  96. if(!buf)
  97. return NULL;
  98. buf->data = data;
  99. buf->size = size;
  100. buf->user_data = 1;
  101. return buf;
  102. }
  103. #if !defined(__KERNEL__)
  104. cucul_buffer_t *cucul_load_file(char const *file)
  105. {
  106. cucul_buffer_t *buf;
  107. FILE *fp;
  108. long int size;
  109. fp = fopen(file, "rb");
  110. if(!fp)
  111. return NULL;
  112. buf = malloc(sizeof(cucul_buffer_t));
  113. if(!buf)
  114. {
  115. fclose(fp);
  116. return NULL;
  117. }
  118. fseek(fp, 0, SEEK_END);
  119. size = ftell(fp);
  120. buf->data = malloc(size);
  121. if(!buf->data)
  122. {
  123. free(buf);
  124. fclose(fp);
  125. return NULL;
  126. }
  127. buf->size = size;
  128. buf->user_data = 0;
  129. fseek(fp, 0, SEEK_SET);
  130. fread(buf->data, buf->size, 1, fp);
  131. fclose(fp);
  132. return buf;
  133. }
  134. #endif
  135. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  136. {
  137. return buf->size;
  138. }
  139. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  140. {
  141. return buf->data;
  142. }
  143. int cucul_free_buffer(cucul_buffer_t *buf)
  144. {
  145. if(!buf->user_data)
  146. free(buf->data);
  147. free(buf);
  148. return 0;
  149. }