How to use the fontkit.openSync function in fontkit

To help you get started, we’ve selected a few fontkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github svgdotjs / svgdom / utils / textUtils.js View on Github external
fontFamily = families[i]
      break
    }
  }

  if (!fontFamily) {
    fontFamily = defaults.fontFamily
  }

  if (details.preloaded[fontFamily]) {
    font = details.preloaded[fontFamily]
  } else {
    let filename = path.join(fontDir, fontMap[fontFamily])

    try {
      font = fontkit.openSync(filename)
    } catch (e) {
      console.warn(`Could not open font "${fontFamily}" in file "${filename}". ${e.toString()}`)
      return new Box()
    }

    details.preloaded[fontFamily] = font
  }

  var fontHeight = font.ascent - font.descent
  var lineHeight = fontHeight > font.unitsPerEm ? fontHeight : fontHeight + font.lineGap

  var height = lineHeight / font.unitsPerEm * fontSize
  var width = font.layout(text).glyphs.reduce((last, curr) => last + curr.advanceWidth, 0) / font.unitsPerEm * fontSize

  // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor
  var xAdjust = 0
github devongovett / apple-color-emoji / build.js View on Github external
function getFont() {
  if (fs.existsSync(collectionPath)) return fontkit.openSync(collectionPath).fonts[0]; // both fonts in the collection seem to be identical
  if (fs.existsSync(fontPath)) return fontkit.openSync(fontPath);
  console.log('Could not find the emoji font');
  return null;
}
github devongovett / apple-color-emoji / build.js View on Github external
function getFont() {
  if (fs.existsSync(collectionPath)) return fontkit.openSync(collectionPath).fonts[0]; // both fonts in the collection seem to be identical
  if (fs.existsSync(fontPath)) return fontkit.openSync(fontPath);
  console.log('Could not find the emoji font');
  return null;
}
github sidorares / ntk / examples / fontkit.js View on Github external
async function main() {
  const app = await ntk.createClient();
  const window = app.createWindow();
  window.map();
  window.setActions();

  //const path =
  //  '/usr/share/texlive/texmf-dist/fonts/truetype/huerta/alegreya/AlegreyaSans-LightItalic.ttf';
  //const path = '/usr/share/fonts/truetype/ubuntu/Ubuntu.ttf';

  //const path = 'PT-Serif.woff2';
  const path = 'LibreBaskerville.woff2';
  var font = fontkit.openSync(path);

  // layout a string, using default shaping features.
  // returns a GlyphRun, describing glyphs and positions.
  var run = font.layout(
    'Simp' //lifies a 2D polyline, first using a radial distance check, and then a recursive Douglas-Peucker algorithm.'
  );

  //console.log(run);
  let size = 900;

  const ctx = window.getContext('2d');
  const _update = () => {
    let left = 0;
    let scale = size / 2048;
    const svgs = run.glyphs.map((g, index) => {
      var path = g.path.scale(scale, -scale).translate(10 + left * scale, 800);
github semencov / tailwindcss-font-inter / update.js View on Github external
.then(() => {
    console.info("Fetching font files...");

    for (fontFile of interFiles) {
      let file = download(fontFile);
      let font = fontkit.openSync(file);

      inter.version = font.version.replace(/Version\s/, "");
      font.availableFeatures.forEach(feature =>
        inter.availableFeatures.add(feature)
      );
    }

    inter.availableFeatures = [...inter.availableFeatures].sort();

    console.log("Font version:", inter.version);
    console.log("Found font features:", inter.availableFeatures.join(", "));
  })
  .then(async () => {
github svgdotjs / svgdom / dom.js View on Github external
preloadFonts () {
    var map = this.document.fontFamilyMappings
    var filename

    for (var i in map) {
      filename = path.join(this.document.fontDir, map[i])

      try {
        this.document._preloaded[i] = fontkit.openSync(filename)
      } catch (e) {
        console.warn('Could not load font file for ' + i + '.' + e)
      }
    }

    return this

  }
  getComputedStyle (node) {
github dana-ross / adrian / app / src / server.js View on Github external
const addFont = (path, log = true) => { 
    if(path.match(/\/([^.])[^\/]*\.(otf|ttf|woff|woff2)$/i)) {
        const font = fontkit.openSync(path)

        fonts[path] = {
            filename: path,
            type: fontType(font),
            fullName: font.fullName,
            familyName: font.familyName,
            subfamilyName: font.subfamilyName,
            copyright: font.copyright,
            uniqueID: fontUniqueID(config, font) 
        }

        apicache.clear(null)

        if(log) { logger.log(`Added font ${path}`) }

        return true
github foliojs / textkit / packages / font-substitution-engine / index.js View on Github external
getFont(fontDescriptor) {
      if (this.fontCache.has(fontDescriptor.postscriptName)) {
        return this.fontCache.get(fontDescriptor.postscriptName);
      }
      let font = fontkit.openSync(fontDescriptor.path);
      if (font.postscriptName !== fontDescriptor.postscriptName) {
        font = font.getFont(fontDescriptor.postscriptName);
      }

      this.fontCache.set(font.postscriptName, font);
      return font;
    }

fontkit

An advanced font engine for Node and the browser

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis