Comments (27)
What is the error message you're getting?
from fontkit.
I tried the following code with Noto CJK (Japanese otf version) Regular:
var fontkit = require('fontkit');
var fs = require('fs');
var font = fontkit.openSync('NotoSansCJKjp-Regular.otf');
var run = font.layout('こりゃどうも');
var aw = 0;
var svg = run.glyphs.map((g,i) => {
var g = [
" <g transform='translate("+aw+",0)'>",
" <path fill='black' d='"+g.path.toSVG()+"'/>",
" </g>"
].join('\n');
aw += run.positions[i].xAdvance;
return g;
});
svg = [
"<svg width='"+aw+"' height='0' viewBox='0 0 "+aw+" 1000'>",
"<g transform='translate(0,1000) scale(1,-1)'>",
svg.join('\n'),
"</g>",
"</svg>"
].join('\n');
fs.writeFileSync("test.svg", svg);
And that works just fine.
http://jsbin.com/lipuwinamu/edit?html,css,output
from fontkit.
This is the error message I receive: "Not a supported font format or standard PDF font."
Just to make sure I'm not causing confusion, I'm using fontkit within pdfkit (fontkit branch from github) and running in NodeJS (v0.10.36 and v0.12.9).
from fontkit.
Sounds like a PDFKit problem, not a fontkit problem. How are you passing your font to PDFKit? String paths, Buffers, Uint8Arrays, or ArrayBuffers are supported.
from fontkit.
On a side note, you probably want to update your Node.js to 5.6 (or even 4.3LTS), as that uses a much newer version of V8, with many improvements.
from fontkit.
@devongovett I'm using string paths at the moment.
@Pomax I use the latest on most projects, but in this case, our code runs on AWS Lambda and they are stuck in the dark ages.
from fontkit.
@mmejia27 that might also be part of it then. A look at what AWS Lambda supports gives us Node 0.10, which is incredibly out of date, and might very well rely on a version of V8 so old that it doesn't support some of the things that we've since come to rely on for binary data parsing...
from fontkit.
The tests pass in node 0.10 on Travis, so I don't think that's the issue. Are you certain the file exists where you think it does? Can you try running your program locally? Same issue?
from fontkit.
I have been running this code locally against 0.10.36. I haven't deployed this yet to Lambda because I haven't gotten it to work. I'm in the process of pulling in all the projects again to see if that helps.
from fontkit.
If you can, please post a code snippet that reproduces the issue. Also, if you can send a link to the font file you're using, that would help as well.
from fontkit.
If it helps, I grabbed the Japenese noto from https://www.google.com/get/noto by filtering for Japanese and the downloading the "Noto Sans CJK JP" font (there's multiple files because different CJK languages can have different ways to write the same unicode character).
from fontkit.
@devongovett Thanks for asking me to do this as it helped find the real issue. Turns out npm wasn't installing the fontkit branch of pdfkit. When I tried doing the snippet to re-create the issue, I kept on getting an error that it couldn't find pdfkit. Looks like there might be an issue in using github references in npm. I ended up using a local module and it picked it right up and I was able to use my font.
Now I have run into a slightly different issue. It looks like a bunch of the characters are missing in my generated PDF whenever a colon is used in the text. Below is the snippet to re-create the issue.
This is the font I am using: https://github.com/googlei18n/noto-cjk/blob/master/NotoSansCJKsc-Regular.otf
var PDFDocument = require('../pdfkit');
var fs = require('fs');
var pdfFile = 'test.pdf';
var fontFile = 'NotoSansCJKsc-Regular.otf';
var doc = new PDFDocument({ bufferPages: true });
var pdfStream = fs.createWriteStream(pdfFile);
doc.pipe(pdfStream);
doc.fontSize(12)
.font(fontFile)
.text("This is a test: The quick brown fox jumps over the lazy dog.");
doc.end();
from fontkit.
If I install pdfkit the normal npm
way, using npm install pdfkit --save
, I get the error you were seeing with your snippet:
C:\Users\Mike\Documents\Git projects\temp\mo>node test.js
J:\Junctions\Users\Mike\Documents\Git projects\temp\mo\node_modules\pdfkit\js\font.js:36
throw new Error('Not a supported font format or standard PDF font.');
^
Error: Not a supported font format or standard PDF font.
at new PDFFont (J:\Junctions\Users\Mike\Documents\Git projects\temp\mo\node_modules\pdfkit\js\font.js:36:17)
at PDFDocument.module.exports.font (J:\Junctions\Users\Mike\Documents\Git projects\temp\mo\node_modules\pdfkit\js\mixins\fonts.js:39:20)
at Object.<anonymous> (J:\Junctions\Users\Mike\Documents\Git projects\temp\mo\test.js:11:5)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:140:18)
at node.js:1001:3
Worth filing over on https://github.com/devongovett/pdfkit/issues
from fontkit.
@Pomax I was actually trying to install with npm install git+https://[email protected]/devongovett/pdfkit.git#fontkit
in order to use the fontkit branch. npm seems to install all the modules, but then require ('pdfkit')
does not find it. The master branch hasn't merged in fontkit yet.
from fontkit.
Try git+ssh
instead of git+https
from fontkit.
The npm version does not use fontkit yet. That's why you need to use the branch from github.
from fontkit.
@devongovett Using ssh didn't make a difference. I did dig into the node_modules directory and saw pdfkit in there. Inside the directory, though, there's only the LICENSE, Makefile, package.json, and README.md files. A wild guess tells me that maybe npm isn't "smart" enough to know it has to pull the .coffee files and prepublish/run make js
.
from fontkit.
Oh, it's because of the .npmignore
, which ignores the coffeescript files. Didn't realize npm deleted them after pulling in the repo, assumed that was only used for publishing.
from fontkit.
Interesting! I thought the same thing and didn't even think it could be that. For now I can work with a local module and will see about how I can deploy this later on.
Do you think the issue with missing characters after using a colon is a pdfkit issue, or fontkit?
from fontkit.
ah, yeah npm (at least, 3) actually does some interesting things - it'll download a package into global cache, clean it out, then use that as the base for installing into local dirs.
from fontkit.
@devongovett @Pomax Do you guys have an idea on the issue of characters not displaying if a colon is used in the text?
from fontkit.
I can't say I do, does it happen in fontkit, too, or only in when used in pdfkit?
from fontkit.
Well, I don't use fontkit directly in any project, so I can't say for sure. I can say this, though. I'm using pdfkit (from npm, no fontkit) with a regular TTF font and no issues with using a colon there. Using my above snippet reproduces the error with the OTF font. As soon as you remove the colon, though, the rest of the characters show up correctly, so my hunch is something in fontkit.
from fontkit.
if you use the code from #23 (comment), does it reproduce in just-fontkit? If not, this is probably an issue to file over on the pdfkit tracker, so that people can find and comment on it there
from fontkit.
So, using that code, I didn't get the same issue. All of the letters came out in the svg, but there was still an issue with the colon. It seems to be printed, but way too far to the left (bad kerning?).
This is the output:
http://jsbin.com/gekatanexo/edit?html,css,output
Should read as follows:
This is a test: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. the quick brown fox jumps over the lazy dog.
@Pomax @devongovett Should I open an issue in pdfkit as well?
from fontkit.
that could also just be my glyph positioning based solely on the advanceWidth value from the positions array - if the colon does show up (which it seems to) then that feels like a different issue, so I'd recommend filing this over on the pdfkit repo.
from fontkit.
Thanks your help on this! I'll close it out for now as I have opened the issue in pdfkit.
from fontkit.
Related Issues (20)
- when i use fontkit to genetate the subset of ttf file,but can not open the subset file,shows ‘not a valid font file’ HOT 3
- [Performance] WOFF font format for CJK languages is 5x slower in Chrome and Unresponsive in Firefox HOT 1
- seac-like endchar compatibility syntax not handled HOT 1
- Cannot use Fontkit on CodeSandbox.io HOT 3
- How to extract individual TTF from a font collection (TTC) file?
- Missing initialisation for pts variable for glyphs HOT 1
- Trouble with Kerning / Letter Spacing HOT 1
- fontkit library installing on react js project while importing we have issue
- fonkit 2.0.0 create from ArrayBuffer returns empty `variationAxes` and null parameters HOT 1
- Newest version of restructure doesn't support all string encodings HOT 6
- Empty _table object
- Fontkit.Font to Buffer
- Question: How to lookup name record by nameID
- postscriptname null in some version of fontkit HOT 2
- OS/2 vs hhea font metrics for ascender/descender
- Due to a bug in vhea.js, the advanceHeight is not taken correctly.
- Problem with TTFGlyph caching for Arabic Presentation Forms
- Vulnerability - Malware in legacy-swc-helpers HOT 6
- Latest npm version (2.0.3) throws an error TypeError: (0 , $parcel$interopDefault(...)) is not a function HOT 4
- Issue with namedVariations in Variable Font (SourceSans3VF.otf) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fontkit.