Git Product home page Git Product logo

opentype.jscad's Introduction

opentype.jscad

Wrapper opentypejs for openjscad, early version.

Example

include("https://raw.githubusercontent.com/ojsc/opentype.jscad/master/dist/opentype.min.jscad");
include("https://raw.githubusercontent.com/ojsc/opentype.jscad/master/dist/fonts/purisa_ttf.jscad");
include("https://raw.githubusercontent.com/ojsc/opentype.jscad/master/dist/fonts/mainframe_spore_ttf.jscad");
include("https://raw.githubusercontent.com/ojsc/opentype.jscad/master/dist/fonts/emojisymbols_regular_woff.jscad");

function main () {
  let fPurisa = Font3D.parse(purisa_ttf_data.buffer);
  let cagPurisa = Font3D.cagFromString(fPurisa, "Hello", 14);
  let csgPurisa = linear_extrude({ height: 5 }, cagPurisa[0].union(cagPurisa));
  csgPurisa = csgPurisa.center().translate([0,20,0]);
  csgPurisa = color("orange", csgPurisa);
  
  let fMainframe = Font3D.parse(mainframe_spore_ttf_data.buffer);
  let cagMainframe = Font3D.cagFromString(fMainframe, "World", 14);
  let csgMainframe = linear_extrude({ height: 5 }, cagMainframe[0].union(cagMainframe));
  csgMainframe = csgMainframe.center();
  
  let fEmoji = Font3D.parse(emojisymbols_regular_woff_data.buffer);
  
  csgFox = drawGlyph(fEmoji, 262, 24, 3).translate([0,-20,0]);
  csgFox = color("lime", csgFox);
  csgMonkey = drawGlyph(fEmoji, 222, 24, 3).translate([-20,-20,0]);
  csgMonkey = color("red", csgMonkey);
  csgParty = drawGlyph(fEmoji, 134, 24, 3).translate([20,-20,0]);
  csgParty = color("blue", csgParty)
  

  return [csgPurisa, csgMainframe, csgFox, csgMonkey, csgParty];
}

function drawGlyph(font, number,size,height) {
  let cagFox = Font3D.cagFromGlyph(font,number,size);
  return linear_extrude({ height:height}, cagFox).center();
}

Warning

Please check if you have the right to use the font in the way you want.

Working

The way the cags are made from a font is as follows:

  • Asume all paths are closed
  • Make cags from paths
  • Sort cags in a tree. cag in cag in cag
  • Cut cags out of cags recursively

Not Working

To bad some glyphs currently dont work.. Got some path itersections (maybe i'm doing the bezierCurves wrong). Some glyphs stall...(bug in tree?)

opentype.jscad's People

Watchers

James Cloos avatar  avatar

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.