Beispiel #1
0
static int http_on_header_field(http_parser* parser, const char* field, size_t len) {
    Connection* connection = (Connection*) parser->data;
    if (!circa_is_null(&connection->httpPendingHeaderValue))
        http_flush_finished_header(connection);
    circa_string_append_len(&connection->httpPendingHeaderField, field, len);
    return 0;
}
Beispiel #2
0
void fill_audio(void *udata, Uint8 *stream, int numBytes)
{
    uint16_t* samples = (uint16_t*) stream;
    int sampleCount = numBytes / 4;

    if (circa_is_null(&audio->currentEffect)) {
        memset(stream, 0, numBytes);
        return;
    }

    char* effectBytes;
    uint32_t effectNumBytes;
    circa_blob_data(&audio->currentEffect, &effectBytes, &effectNumBytes);

    int remainingEffectBytes = effectNumBytes - audio->effectPos;

    if (remainingEffectBytes <= 0) {
        circa_set_null(&audio->currentEffect);
        memset(stream, 0, numBytes);
        return;
    }

    if (remainingEffectBytes > numBytes)
        remainingEffectBytes = numBytes;

    memcpy(stream, effectBytes + audio->effectPos, remainingEffectBytes);
    audio->effectPos += remainingEffectBytes;
}
Beispiel #3
0
static void http_flush_finished_header(Connection* connection)
{
    if (!circa_is_null(&connection->httpPendingHeaderField)) {
        circa_move(&connection->httpPendingHeaderValue,
            circa_map_insert_move(&connection->httpHeaders, &connection->httpPendingHeaderField));
    }
}
Beispiel #4
0
void load_font(caStack* stack)
{
    caValue* filename = circa_input(stack, 0);

    FontFace* font = new FontFace();

    circa_read_file_with_stack(stack, circa_string(filename), &font->rawData);
    if (circa_is_null(&font->rawData))
        return circa_output_error(stack, "Failed to load file");
    
    if (!g_ftLibraryInitialized) {
        FT_Init_FreeType(&g_ftLibrary);
        g_ftLibraryInitialized = true;
    }
    
    int error = FT_New_Memory_Face(g_ftLibrary,
                   (FT_Byte*) circa_blob(&font->rawData),
                   circa_blob_size(&font->rawData),
                   0,
                   &font->ftFace);

    if (error)
        return circa_output_error(stack, "FT_New_Memory_Face failed");

    font->cairoFace = cairo_ft_font_face_create_for_ft_face(font->ftFace, 0);

    caValue* out = circa_set_default_output(stack, 0);
    circa_set_native_ptr(circa_index(out, 0), font, FontFaceRelease);
}