Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG icons #275

Open
robin-swift opened this issue Jan 16, 2022 · 1 comment
Open

SVG icons #275

robin-swift opened this issue Jan 16, 2022 · 1 comment
Assignees
Milestone

Comments

@robin-swift
Copy link
Member

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
Copy link
Member Author

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 robin-swift added this to the Version 2.1+ milestone Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants