jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
218 stars 56 forks source link

Feature/text() #106

Closed ghost closed 6 years ago

ghost commented 6 years ago

jscad

var roboto = include('roboto-2014/Roboto-Regular.ttf');
var stylus = include('Deftone-Stylus/Deftone-Stylus.ttf');

function main(params) {
  var f1 = font(roboto);
  var f2 = font(stylus);

  var t1 = text({ text: 'OpenJSCAD', font: f1 });
  var t2 = text({ text: 'OpenJSCAD', font: f1, center: [true, true], letterSpacing: 10 });
  var t3 = text({ text: 'OpenJSCAD', font: f2, center: [true, true], width: 100 });
  var t4 = text({ text: 'OpenJSCAD', font: f2, center: [true, true], width: 100, height: 40 });

  return [
    t1.translate([0,  50, 0]),
    t2.translate([0,  30, 0]),
    t3.translate([0,   0, 0]),
    t4.translate([0, -50, 0])
  ];
}

EDIT: font() et include() implemented in https://github.com/lautr3k/OpenJSCAD.org/tree/feature/text()

kaosat-dev commented 6 years ago

This rocks :) thanks ! I'll take a look

kaosat-dev commented 6 years ago

@lautr3k : overall super good :) ! As discussed yesterday Only change that would be important is having the actual text/string as a seperate parameter not part of the options ie
text(options, textString)

const t1 = text({font: f1 }, 'OpenJSCAD')

Something else I thought of today while taking another look at your PR:

z3dev commented 6 years ago

What are the default options? The function should return something meaningful for simple cases.

ghost commented 6 years ago

Default font size is 10 if not set in options.height For the default font, I will use vector_text() as fallback

z3dev commented 6 years ago

That sounds reasonable. Just wondering, is there a better “vector” font available? Could another default font be created? Or found? The current vector font is very limited.

ghost commented 6 years ago

@z3dev limited in terms of what? number of characters supported? encoding?

z3dev commented 6 years ago

The number of supported characters is limited. And it’s really not meant to be rendered at another font size, style, etc.

Can the vector font be removed?

Maybe a default font isn’t necessary. Fonts are pretty easy to locate and down load. We could also supply links to some good ones, like the one used to make the JSCAD logo.

What’s are the steps to use a font? URL? Download? Installation?

ghost commented 6 years ago

web -> drag/drop fonts files then var myFont = include('myFont.ttf') desktop -> local fonts can be used or drag/drop

z3dev commented 6 years ago

Sounds really easy. Also, there's a huge list of fonts already available.

So... Can does HTML / CSS standard specify a standard font? One that every OS / Browser must have?

Look like fonts are located by family. Does opentype.js support this feature?

ghost commented 6 years ago

No, opentype need a font file to work.

z3dev commented 6 years ago

Hmm... not so trival then. Should we include a single font file as part of the library?

z3dev commented 6 years ago

@lautr3k General question... we need a few more eyes for reviews and opinions for design questions... can we ask (you) for reviews / comments when relevant?

ghost commented 6 years ago

Of course, feel free to ask. But note that I have already started another refactoring of the textes functions in another branch. I rushed on that one and mixed too much stuff at once. I would like to do it again in two stages (PR): 1 - Refactoring of vector_char() & vector_text() : options first, font-size, line-height, letter-spacing, optimization. 2 - Add the text() function

z3dev commented 6 years ago

@lautr3k Feel free to rework the PR. I like the ambitious goals. If you need to close this one then please do.

Thanks again!

z3dev commented 6 years ago

@lautr3k Any issues with the new PR? I'm looking forward to playing with the new functionalty.