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

Deleting canvas data in mobile devices #35

Open
Mustafa-eksi opened this issue May 20, 2023 · 0 comments
Open

Deleting canvas data in mobile devices #35

Mustafa-eksi opened this issue May 20, 2023 · 0 comments

Comments

@Mustafa-eksi
Copy link

when you try to put text on a image it removes the image and puts only text.
I encountered this issue only in mobile devices, works fine on my pc. I was using webpack but I don't think that matters.
It cleans canvas at https://github.com/namniak/canvas-text-wrapper/blob/268a8620ab05336d4355c34cc1b6df6b66c9a061/canvas-text-wrapper.js#LL49C1-L49C13 and it doesn't draw it back.
I simply commented this section:

if (opts.renderHDPI && devicePixelRatio > 1) {
var tempCtx = {};
// store context settings in a temp object before scaling otherwise they will be lost
for (var key in context) {
tempCtx[key] = context[key];
}
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
scale = devicePixelRatio;
canvas.width = canvasWidth * scale;
canvas.height = canvasHeight * scale;
canvas.style.width = canvasWidth * scale * 0.5 + 'px';
canvas.style.height = canvasHeight * scale * 0.5 + 'px';
// restore context settings
for (var key in tempCtx) {
try {
context[key] = tempCtx[key];
} catch (e) {
}
}
context.scale(scale, scale);
}
and it worked.
this is the fork I solved the porblem but I don't know if there is a better solution: https://github.com/Mustafa-eksi/canvas-text-wrapper

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

No branches or pull requests

1 participant