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

TypeError: Cannot set property 'font' of null #7

Open
xiakehc opened this issue Jan 30, 2018 · 4 comments
Open

TypeError: Cannot set property 'font' of null #7

xiakehc opened this issue Jan 30, 2018 · 4 comments

Comments

@xiakehc
Copy link

xiakehc commented Jan 30, 2018

image

@xiakehc
Copy link
Author

xiakehc commented Feb 1, 2018

how to solve?

@atkinchris
Copy link

atkinchris commented Feb 25, 2018

Are you using node-canvas, with Cairo installed, and passing the canvas and context in the options?

@atkinchris
Copy link

@hktalent - as per my comment above, are you using node-canvas, and passing the canvas and it's context
as canvas and context respectively in the options object?

const { createCanvas } = require('canvas')
const vectorizeText = require('vectorize-text')

const width = 200
const height = 200
const canvas = createCanvas(width, height)
const context = canvas.getContext('2d')

vectorizeText('Hello world', {
  font: 'Sans-serif',
  width,
  canvas,
  context,
})

@GuiRitter
Copy link

GuiRitter commented Aug 8, 2018

I adapted the example provided in the read me with the comment above and this is what I'm seeing:

vectorize-text-test

example.js

const { createCanvas } = require('canvas')
var vectorizeText = require("vectorize-text")

const width = 500
const height = 80
const canvas = createCanvas(width, height)
const context = canvas.getContext('2d')

var graph = vectorizeText("Hello world! 你好", {
  //width: 500,
  textBaseline: "hanging",
  font: 'Sans-serif',
  width,
  canvas,
  context,
})

var svg = ['<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  width="500"  height="80" >']
graph.edges.forEach(function(e) {
  var p0 = graph.positions[e[0]]
  var p1 = graph.positions[e[1]]
  svg.push('<line x1="' + p0[0] + '" y1="' + p0[1] +
    '" x2="' + p1[0] + '" y2="' + p1[1] +
    '" stroke-width="1" stroke="black" />')
})
svg.push("</svg>")

console.log(svg.join(""))

EDIT: for those looking for a solution, I reccomend text-to-svg instead.

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

3 participants