sammycage / plutovg

Tiny 2D vector graphics library in C
MIT License
329 stars 32 forks source link

Extract stroke/fill outline points #35

Closed soufianekhiat closed 3 months ago

soufianekhiat commented 3 months ago

How could we extract points of the outline of each stroke/fill/... Internally the state/stack based is destructive after each stroke:

        PVG_FT_Stroker stroker;
        PVG_FT_Stroker_New(&stroker);
        PVG_FT_Stroker_Set(stroker, ftWidth, ftCap, ftJoin, ftMiterLimit);
        PVG_FT_Stroker_ParseOutline(stroker, &outline);

        PVG_FT_UInt points;
        PVG_FT_UInt contours;
        PVG_FT_Stroker_GetCounts(stroker, &points, &contours);

        ft_outline_init(&outline, pluto, points, contours);
        PVG_FT_Stroker_Export(stroker, &outline);
        PVG_FT_Stroker_Done(stroker);

Ideally:

    struct vec2 { double x, y; };
    const int width = 150;
    const int height = 150;

    plutovg_surface_t* surface = plutovg_surface_create(width, height);
    plutovg_t* pluto = plutovg_create(surface);

    double center_x = width * 0.5;
    double center_y = height * 0.5;
    double face_radius = 70;
    double eye_radius = 10;
    double mouth_radius = 50;
    double eye_offset_x = 25;
    double eye_offset_y = 20;
    double eye_x = center_x - eye_offset_x;
    double eye_y = center_y - eye_offset_y;

    const double pi = 3.14159265358979323846;

    int pts_count;
    plutovg_save(pluto);
    plutovg_arc(pluto, center_x, center_y, face_radius, 0, 2 * pi, 0);
    plutovg_set_rgb(pluto, 1, 1, 0);
    plutovg_fill_preserve(pluto);
    plutovg_set_rgb(pluto, 0, 0, 0);
    plutovg_set_line_width(pluto, 5);
    //plutovg_stroke(pluto);
    pts_count = plutovg_get_outline_stroke_points_count(pluto);
    vec2* pts = malloc( sizeof( vec2 ) * pts_count );
    plutovg_get_outline_stroke_points(&pts.x, pts_count);
    // Do something with points
    free( pts );
    plutovg_restore(pluto);

    plutovg_save(pluto);
    plutovg_arc(pluto, eye_x, eye_y, eye_radius, 0, 2 * pi, 0);
    plutovg_arc(pluto, center_x + eye_offset_x, eye_y, eye_radius, 0, 2 * pi, 0);
    //plutovg_fill(pluto);
    pts_count = plutovg_get_outline_fill_points_count(pluto);
    vec2* pts = malloc( sizeof( vec2 ) * pts_count );
    plutovg_get_outline_fill_points(&pts.x, pts_count);
    // Do something with points
    free( pts );
    plutovg_restore(pluto);

    plutovg_save(pluto);
    plutovg_arc(pluto, center_x, center_y, mouth_radius, 0, pi, 0);
    plutovg_set_line_width(pluto, 5);
    //plutovg_stroke(pluto);
    pts_count = plutovg_get_outline_stroke_points_count(pluto);
    vec2* pts = malloc( sizeof( vec2 ) * pts_count );
    plutovg_get_outline_stroke_points(&pts.x, pts_count);
    // Do something with points
    free( pts );
    plutovg_restore(pluto);

    plutovg_surface_destroy(surface);
    plutovg_destroy(pluto);
sammycage commented 3 months ago

@soufianekhiat I understand what you are trying to do, but this is out of scope of this library.

soufianekhiat commented 3 months ago

So we can close my issue (:

sammycage commented 3 months ago

I am so sorry, buddy. This library is undergoing a serious upgrade. I will close the issue when I am unable to implement something like that.

sammycage commented 3 months ago

I really wanted to make this work, but I couldn't. So, with a heavy heart, I'm closing this issue.