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

Add control of shading pattern's number of samples #3471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Trisard
Copy link

@Trisard Trisard commented Aug 24, 2022

Adding control of shading pattern's number of samples

Control of shading pattern's number of samples was implemented but not used, we can now specify (optionally) the number of samples wanted on shading pattern adding.

Example code

import { jsPDF } from "jspdf";

const doc = new jsPDF();

const pattern = doc.ShadingPattern(
    "axial",
    [10, 100, 100, 10],
    [
        { offset: 0, color: [255, 255, 0] },
        { offset: 0.05, color: [0, 0, 255] },
        { offset: 0.1, color: [255, 255, 0] },
        { offset: 0.15, color: [0, 0, 255] },
        { offset: 0.20, color: [255, 255, 0] },
        { offset: 0.25, color: [0, 0, 255] },
        { offset: 0.30, color: [255, 255, 0] },
        { offset: 0.35, color: [0, 0, 255] },
        { offset: 0.40, color: [255, 255, 0] },
        { offset: 0.45, color: [0, 0, 255] },
        { offset: 0.50, color: [255, 255, 0] },
        { offset: 0.55, color: [0, 0, 255] },
        { offset: 0.60, color: [255, 255, 0] },
        { offset: 0.65, color: [0, 0, 255] },
        { offset: 0.70, color: [255, 255, 0] },
        { offset: 0.75, color: [0, 0, 255] },
        { offset: 0.80, color: [255, 255, 0] },
        { offset: 0.85, color: [0, 0, 255] },
        { offset: 0.90, color: [255, 255, 0] },
        { offset: 0.95, color: [0, 0, 255] },
        { offset: 1, color: [255, 255, 0] },
    ]
);

doc.advancedAPI(doc => {
    doc.addShadingPattern("testPattern", pattern, 5);
});

doc.path([
    { op: "m", c: [10, 10] },
    { op: "l", c: [100, 10] },
    { op: "l", c: [100, 10] },
    { op: "l", c: [100, 100] },
    { op: "l", c: [10, 100] }
]);

doc.fill({key:"testPattern"});

doc.save();

Result with a number of samples at 5

image

Result with a number of samples at 80

For this example, any number equal or upper 21 gonna give this result

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant