Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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