Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

182 linhas
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. # include <stdio.h>
  21. # include <stdlib.h>
  22. # include <string.h>
  23. #endif
  24. #include "cucul.h"
  25. #include "cucul_internals.h"
  26. /*
  27. * Functions from canvas.c
  28. */
  29. int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch)
  30. {
  31. return cucul_put_char(cv, x, y, ch);
  32. }
  33. int cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
  34. {
  35. return cucul_put_str(cv, x, y, s);
  36. }
  37. /*
  38. * Functions from color.c
  39. */
  40. int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
  41. {
  42. return cucul_set_color_ansi(cv, fg, bg);
  43. }
  44. int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
  45. {
  46. return cucul_set_color_argb(cv, fg, bg);
  47. }
  48. /*
  49. * Functions from import.c
  50. */
  51. cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *buf, char const *format)
  52. {
  53. cucul_canvas_t *cv = cucul_create_canvas(0, 0);
  54. int ret = cucul_import_memory(cv, (unsigned char const *)buf->data,
  55. buf->size, format);
  56. if(ret < 0)
  57. {
  58. cucul_free_canvas(cv);
  59. return NULL;
  60. }
  61. return cv;
  62. }
  63. /*
  64. * Functions from export.c
  65. */
  66. cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *cv, char const *format)
  67. {
  68. cucul_buffer_t *ex;
  69. ex = malloc(sizeof(cucul_buffer_t));
  70. if(!ex)
  71. {
  72. seterrno(ENOMEM);
  73. return NULL;
  74. }
  75. ex->data = cucul_export_memory(cv, format, &ex->size);
  76. if(!ex->data)
  77. {
  78. free(ex);
  79. return NULL;
  80. }
  81. ex->user_data = 0;
  82. return ex;
  83. }
  84. /*
  85. * Functions from buffer.c
  86. */
  87. cucul_buffer_t *cucul_load_memory(void *data, unsigned long int size)
  88. {
  89. cucul_buffer_t *buf;
  90. buf = malloc(sizeof(cucul_buffer_t));
  91. if(!buf)
  92. return NULL;
  93. buf->data = data;
  94. buf->size = size;
  95. buf->user_data = 1;
  96. return buf;
  97. }
  98. #if !defined(__KERNEL__)
  99. cucul_buffer_t *cucul_load_file(char const *file)
  100. {
  101. cucul_buffer_t *buf;
  102. FILE *fp;
  103. long int size;
  104. fp = fopen(file, "rb");
  105. if(!fp)
  106. return NULL;
  107. buf = malloc(sizeof(cucul_buffer_t));
  108. if(!buf)
  109. {
  110. fclose(fp);
  111. return NULL;
  112. }
  113. fseek(fp, 0, SEEK_END);
  114. size = ftell(fp);
  115. buf->data = malloc(size);
  116. if(!buf->data)
  117. {
  118. free(buf);
  119. fclose(fp);
  120. return NULL;
  121. }
  122. buf->size = size;
  123. buf->user_data = 0;
  124. fseek(fp, 0, SEEK_SET);
  125. fread(buf->data, buf->size, 1, fp);
  126. fclose(fp);
  127. return buf;
  128. }
  129. #endif
  130. unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf)
  131. {
  132. return buf->size;
  133. }
  134. void * cucul_get_buffer_data(cucul_buffer_t *buf)
  135. {
  136. return buf->data;
  137. }
  138. int cucul_free_buffer(cucul_buffer_t *buf)
  139. {
  140. if(!buf->user_data)
  141. free(buf->data);
  142. free(buf);
  143. return 0;
  144. }