Giter Club home page Giter Club logo

Comments (10)

twardoch avatar twardoch commented on August 20, 2024 2

<script type="text/javascript" src="fontkit.js"></script>
<script>
function fkOpenFont (fkFontPath) {
  var xhr = new XMLHttpRequest()
  xhr.open('GET', fkFontPath, true)
  xhr.responseType = 'arraybuffer'
  var fkFont = null
  xhr.onload = function (e) {
    if (this.status == 200) {
      var fkBlob = this.response
      var fkBuffer = new Buffer(fkBlob)
      fkFont = fontkit.create(fkBuffer)
    }
  }
  xhr.send();
}

fkOpenFont('../fonts/Monoto-VF.woff')
</script>

from fontkit.

twardoch avatar twardoch commented on August 20, 2024 2

Well do. I still need another week, well have much better sample code then. This is the first time I touched JS since Netscape Navigator :)

from fontkit.

christiangenco avatar christiangenco commented on August 20, 2024 1

@twardoch's solution is even easier with the new fetch API:

const fontUrl = "https://fonts.gstatic.com/s/raviprakash/v3/8EzbM7Rymjk25jWeHxbO6CXeN0lhaNKjYxc8tNqs5DA.woff2";

fetch(fontUrl).then(res => res.arrayBuffer()).then(ab => {
  const font = fontkit.create(new Buffer(ab));
});

from fontkit.

twardoch avatar twardoch commented on August 20, 2024

I found a way, shown here:

from fontkit.

Harbs avatar Harbs commented on August 20, 2024

Adam,
Thanks for this! I was just struggling with this myself a few days ago.

from fontkit.

twardoch avatar twardoch commented on August 20, 2024

The main point that I had to discover is that node.js has the fs module which uses a Buffer object that fontkit uses. Browserify has a built-in Buffer object that can be used to convert an ArrayBuffer into a fontkit-compatible Buffer. XMLHttpRequest that is built into browsers can return an ArrayBuffer. So it works.

from fontkit.

prady91 avatar prady91 commented on August 20, 2024

Thanks Adam!

from fontkit.

Pomax avatar Pomax commented on August 20, 2024

Worth filing a quick PR that adds this code (or some form of) to the README.md?

from fontkit.

Pomax avatar Pomax commented on August 20, 2024

welcome back to JS, it's a brave new world =D

(with so much new functionality it's pretty much a completely different language compared to what we had in '98)

from fontkit.

moffsugita avatar moffsugita commented on August 20, 2024

Does it really support browser not node?
I don't want to use <script type="text/javascript" src="fontkit.js"></script>
I use for React.js. And installed from npm.

from fontkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.