I am tying to use custom fontello font in Canvas so I can export the icon as PNG, but I am getting only an empty square - ⎕ This is the outcome no matter which code I use from this font:
So basically I am trying to use it like this:
ctx.font = `30px fontello`;
ctx.fillText('\ue804', canvas.width / 2, canvas.height / 2);
const image = canvas.toDataURL('image/png');
The font is correctly loaded in the document, I've been using it in other places, also testing to use it like this works:
const span = document.createElement('span');
span.style.fontFamily = 'fontello'
span.innerHTML = ''
document.body.appendChild(span)
I also tried
ctx.font = `30px "fontello"`;
ctx.fillText('\\ue804', canvas.width / 2, canvas.height / 2);
ctx.fillText('\uE804', canvas.width / 2, canvas.height / 2);
ctx.fillText('', canvas.width / 2, canvas.height / 2);
ctx.fillText('', canvas.width / 2, canvas.height / 2);
All of the above does not work. Any suggestions will be appreciated.
const canvas = document.createElement('canvas');
canvas.width = 30;
canvas.height = 30;
const ctx = canvas.getContext('2d');
const circleStrokeColor = filter.filter_color.polyline;
const circleFillColor = filter.filter_color.polygon;
const circleRadius = Math.min(canvas.width, canvas.height) / 2 - 1;
ctx.strokeStyle = this.hexToRgb(circleStrokeColor);
ctx.fillStyle = this.hexToRgb(circleFillColor);
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2, circleRadius, 0, 2 * Math.PI);
ctx.fill();
ctx.lineWidth = 1;
ctx.stroke();
ctx.fillStyle = this.hexToRgb(circleStrokeColor);
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.font = `30px fontello`;
ctx.fillText('\ue804', canvas.width / 2, canvas.height / 2);
const image = canvas.toDataURL('image/png');
console.log(image)
return image
@font-face {
font-family: 'fontello';
src: url('../font/fontello.eot?41849995');
src: url('../font/fontello.eot?41849995#iefix') format('embedded-opentype'),
url('../font/fontello.woff2?41849995') format('woff2'),
url('../font/fontello.woff?41849995') format('woff'),
url('../font/fontello.ttf?41849995') format('truetype'),
url('../font/fontello.svg?41849995#fontello') format('svg');
font-weight: normal;
font-style: normal;
}
/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
/*
@media screen and (-webkit-min-device-pixel-ratio:0) {
@font-face {
font-family: 'fontello';
src: url('../font/fontello.svg?41849995#fontello') format('svg');
}
}
*/
[class^="icon-"]:before, [class*=" icon-"]:before {
font-family: "fontello";
font-style: normal;
font-weight: normal;
speak: never;
display: inline-block;
text-decoration: inherit;
width: 1em;
margin-right: .2em;
text-align: center;
/* opacity: .8; */
/* For safety - reset parent styles, that can break glyph codes*/
font-variant: normal;
text-transform: none;
/* fix buttons height, for twitter bootstrap */
line-height: 1em;
/* Animation center compensation - margins should be symmetric */
/* remove if not needed */
margin-left: .2em;
/* you can be more comfortable with increased icons size */
/* font-size: 120%; */
/* Font smoothing. That was taken from TWBS */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* Uncomment for 3D effect */
/* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
}
.icon-gebouwen:before { content: '\e800'; } /* '' */
.icon-groen:before { content: '\e801'; } /* '' */
.icon-kabels-leidingen:before { content: '\e802'; } /* '' */
.icon-kunstwerken:before { content: '\e803'; } /* '' */
.icon-legenda:before { content: '\e804'; } /* '' */
.icon-meubilair:before { content: '\e805'; } /* '' */
.icon-riolering:before { content: '\e806'; } /* '' */
.icon-rioolgemalen:before { content: '\e807'; } /* '' */
.icon-speeltoestellen:before { content: '\e808'; } /* '' */
.icon-spoor-masten:before { content: '\e809'; } /* '' */
.icon-sport:before { content: '\e80a'; } /* '' */
.icon-verhardingen:before { content: '\e80b'; } /* '' */
.icon-verlichting:before { content: '\e80c'; } /* '' */
.icon-vri:before { content: '\e80d'; } /* '' */
.icon-water:before { content: '\e80e'; } /* '' */