Embroidermodder icon indicating copy to clipboard operation
Embroidermodder copied to clipboard

SVG icons

Open robin-swift opened this issue 3 years ago • 1 comments

So in trying to separate code from data for the ruler drawing algorithm (View::createRulerTextPath) I found that using SVG path strings worked quite well.

This means that, in principle, we can have all of our logos as SVG, which I think is generally how it's done now:

  1. it means scaling the UI is not an issue, we don't have to worry about bit crushing
  2. we can share information like palettes using CSS or similar tag systems
  3. embedding the logos in the documentation requires less storage which keeps the size of the PDF down which does seem to effect load times.

I thought I'd pitch this here before spending time on it because it's a fairly major change, especially since converting raster images to vector images is lossy so it takes a bit of artistic flourish.

Cheers, Robin

robin-swift avatar Jan 16 '22 22:01 robin-swift

The relevant code:

void get_n_floats(const char *command, float *out, int n)
{
    int i;
    char modifyable[100];
    strcpy(modifyable, command);
    char *rest = (char*)modifyable;
    for (i=0; i<n; i++) {
        char *tok = strtok_r(rest, " ", &rest);
        out[i] = atof(tok);
        printf("%f\n", out[i]);
    }
}

void add_to_path(QPainterPath *path, const char *command, float pos[2], float scale[2])
{
    int j;
    float out[10];
    printf("%s\n", command);
    for (j=0; j<strlen(command); j++) {
        switch (command[j]) {
        case 'M':
            printf("%s\n", command+j+2);
            get_n_floats(command+j+2, out, 2);
            path->moveTo(pos[0]+out[0]*scale[0], pos[1]+out[1]*scale[1]);
            break;
        case 'L':
            printf("%s\n", command+j+2);
            get_n_floats(command+j+2, out, 2);
            path->lineTo(pos[0]+out[0]*scale[0], pos[1]+out[1]*scale[1]);
            break;
        case 'A':
            get_n_floats(command+j+2, out, 6);
            path->arcTo(pos[0]+out[0]*scale[0], pos[1]+out[1]*scale[1],
                        out[2], out[3], out[4], out[5]);
            break;
        case 'a':
            get_n_floats(command+j+2, out, 5);
            path->arcMoveTo(pos[0]+out[0]*scale[0], pos[1]+out[1]*scale[1],
                        out[2]*scale[0], out[3]*scale[1],
                        out[4]);
            break;
        case 'E':
            get_n_floats(command+j+2, out, 4);
            path->addEllipse(
                QPointF(pos[0]+out[0]*scale[0],  pos[1]+out[1]*scale[1]),
                out[2]*scale[0], out[3]*scale[1]);
            break;
        default:
            break;
        }
    }
}

robin-swift avatar Jan 16 '22 22:01 robin-swift