Example #1
0
static VALUE font_initialize(VALUE self, VALUE name)
{
    caca_font_t *font;

    font = caca_load_font(StringValuePtr(name), 0);
    if(font == NULL)
    {
        rb_raise(rb_eRuntimeError, strerror(errno));
    }
    _SELF = font;
    return self;
}
void
_mod_caca_plasma_anim (lw6sys_context_t * sys_context, _mod_caca_context_t * caca_context)
{
  if (frame != 0)
    {
      _increment_frame (sys_context, caca_context, NULL, NULL, NULL);
      return;
    }
  int wc, hc;
  caca_canvas_t *cv = NULL;
  caca_font_t *f = NULL;
  caca_dither_t *d = NULL;
  uint8_t *buf = NULL;
  char const *const *fonts;

  cv = caca_create_canvas (10, 1);
  if (cv == NULL)
    {
      lw6sys_log (sys_context, LW6SYS_LOG_ERROR, _x_ ("Can't create tmp canvas"));
      return;
    }
  hc = caca_get_canvas_height (caca_context->canvas);
  wc = caca_get_canvas_width (caca_context->canvas);
  _plasma (sys_context, PREPARE, caca_context->canvas);
  _plasma (sys_context, INIT, caca_context->canvas);

  caca_set_color_ansi (cv, CACA_BLACK, CACA_TRANSPARENT);
  caca_put_str (cv, 0, 0, "LiquidWar6");
  fonts = caca_get_font_list ();
  if (fonts[0] == NULL || fonts[1] == NULL)
    {
      lw6sys_log (sys_context, LW6SYS_LOG_ERROR, _x_ ("libcaca was compiled without any fonts"));
      return;
    }
  f = caca_load_font (fonts[1], 0);
  if (f == NULL)
    {
      lw6sys_log (sys_context, LW6SYS_LOG_ERROR, _x_ ("could not load font : '%s'"), fonts[0]);
      return;
    }
  buf = malloc (4 * wc * hc);
  if (buf == NULL)
    return;
  caca_render_canvas (cv, f, buf, wc, hc, 4 * wc);
  d = caca_create_dither (32, wc, hc, 4 * wc, 0xff00, 0xff0000, 0xff000000, 0xff);
  _increment_frame (sys_context, caca_context, f, d, buf);
  _mod_caca_splash_free (sys_context, caca_context, f, d, buf, 1);
  caca_free_canvas (cv);
}
Example #3
0
JNIEXPORT jlong JNICALL
Java_org_zoy_caca_Font_loadFont__Ljava_lang_String_2(JNIEnv *env, jclass cls, jstring font_name)
{
  const char *font_name_chars;
  caca_font_t *font;

  font_name_chars = (*env)->GetStringUTFChars(env, font_name, 0);
  font = caca_load_font(font_name_chars, 0);
  (*env)->ReleaseStringUTFChars(env, font_name, font_name_chars);

  if (!font)
  {
    THROW_EX(FONT_CREATION_ERROR);
    return 0;
  }

  return (jlong)font;
}
Example #4
0
JNIEXPORT jlong JNICALL
Java_org_zoy_caca_Font_loadFont___3B(JNIEnv *env, jclass cls, jbyteArray font_bytes)
{
  jbyte *elems;
  jsize size;
  caca_font_t *font;

  elems = (*env)->GetByteArrayElements(env, font_bytes, 0);
  size = (*env)->GetArrayLength(env, font_bytes);
  font = caca_load_font(elems, size);
  (*env)->ReleaseByteArrayElements(env, font_bytes, elems, 0);

  if (!font)
  {
    THROW_EX(FONT_CREATION_ERROR);
    return 0;
  }

  return (jlong)font;
}
Example #5
0
int main(int argc, char *argv[])
{
    caca_canvas_t *cv;
    caca_display_t *dp;
    caca_font_t *f;
    caca_dither_t *d;
    uint8_t *buf;
    unsigned int w, h;
    char const * const * fonts;

    /* Create a canvas */
    cv = caca_create_canvas(8, 2);
    if(cv == NULL)
    {
        printf("Can't create canvas\n");
        return -1;
    }


    /* Draw stuff on our canvas */
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
    caca_put_str(cv, 0, 0, "ABcde");
    caca_set_color_ansi(cv, CACA_LIGHTRED, CACA_BLACK);
    caca_put_str(cv, 5, 0, "\\o/");
    caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
    caca_put_str(cv, 0, 1, "&$âøÿØ?!");

    /* Load a libcaca internal font */
    fonts = caca_get_font_list();
    if(fonts[0] == NULL)
    {
        fprintf(stderr, "error: libcaca was compiled without any fonts\n");
        return -1;
    }
    f = caca_load_font(fonts[0], 0);
    if(f == NULL)
    {
        fprintf(stderr, "error: could not load font \"%s\"\n", fonts[0]);
        return -1;
    }

    /* Create our bitmap buffer (32-bit ARGB) */
    w = caca_get_canvas_width(cv) * caca_get_font_width(f);
    h = caca_get_canvas_height(cv) * caca_get_font_height(f);
    buf = malloc(4 * w * h);

    /* Render the canvas onto our image buffer */
    caca_render_canvas(cv, f, buf, w, h, 4 * w);

    /* Just for fun, render the image using libcaca */
    caca_set_canvas_size(cv, 80, 32);
    dp = caca_create_display(cv);

    {
#if defined(HAVE_ENDIAN_H)
        if(__BYTE_ORDER == __BIG_ENDIAN)
#else
        /* This is compile-time optimised with at least -O1 or -Os */
        uint32_t const tmp = 0x12345678;
        if(*(uint8_t const *)&tmp == 0x12)
#endif
            d = caca_create_dither(32, w, h, 4 * w,
                                    0xff0000, 0xff00, 0xff, 0xff000000);
        else
            d = caca_create_dither(32, w, h, 4 * w,
                                    0xff00, 0xff0000, 0xff000000, 0xff);
    }

    caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
                                  caca_get_canvas_height(cv), d, buf);
    caca_refresh_display(dp);

    caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1);

    /* Free everything */
    caca_free_display(dp);
    free(buf);
    caca_free_dither(d);
    caca_free_font(f);
    caca_free_canvas(cv);

    return 0;
}