-
Notifications
You must be signed in to change notification settings - Fork 77
cannot read property 'Unicode' of undefined #48
Comments
After a while tracking trough jsPDF source code, I have seen that this issue initially caused by A workaround for this is by giving
Notice that i put option value with : Wonder if there any proper solution compared to this hacky ways. Maybe something that can produce properly an array of font character widths from the actual custom font defined, rather than giving another font character widths. |
I'm using openfont.js to read a font and look up every character width and character pair kerning. Might be overkill. 😬 Below is how I'm getting widths and kerning after already using openfont.js to read the font. export function getTextWidthsAndKerning(text, font) {
const chars = uniq(text);
const widths = {};
const kerning = {};
for (let i = 0; i < chars.length; i += 1) {
const char = chars[i];
widths[char] = get(font.charToGlyph(char), 'advanceWidth');
kerning[char] = {};
for (let j = 0; j < chars.length; j += 1) {
const kerningChar = chars[j];
kerning[char][kerningChar] = font.getKerningValue(
font.charToGlyph(char),
font.charToGlyph(kerningChar),
);
}
}
return { widths, kerning };
} |
i found a way to solve the problem. |
@gpbmike , thanks for the suggestion. Looks not so overkill :). I feel excited to try that soon. @2linziyi2 : I am pretty sure that I am using JSPDF version 1.4.1, and the jspdf-customfonts version is: 0.0.4-rc.4. That is weird if yours is work without any trick as I and @gpbmike did. |
this is all my operation, you can try it.
steps:
React
I am using the Chinese language pack, it works fine. |
@2linziyi2 thank you very much for sharing your scripts and environment setup. Looks like we have a slight difference about jspdf-customfonts version. And I am not sure whether I did |
Hi, I have success loading font with this plugin, however, it gives me a problem when trying to do
splitTextToSize()
. I got an error message: can not read property 'Unicode' of undefined. While I am using built-in fonts, it just running fine.In order to load custom fonts, I am using
node makeFonts.js
approach.Here is the font which I used: https://fonts.google.com/specimen/Nunito+Sans . Is there any clue what kind of fonts that I can use with this plugin?
Any help will be highly appreciated. Thank you in advance.
The text was updated successfully, but these errors were encountered: