-
Notifications
You must be signed in to change notification settings - Fork 56
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
Refactoring/vector_xxx() #107
Conversation
- reduce and move simple font definition - options first - clean docs
This reverts commit 8727759.
SMILE |
I'm compiling some single line fonts, it's coming soon... |
This is going to be awesome. Take your time... we can wait a little longer. Do you need this merged now? |
@z3dev no need to merge now ;) |
Wow this is great once more ! |
I agree, I also hesitate to add it. In addition it raises some circular dependencies in unit tests... |
Sorry for the slowness @lautr3k but I think I can review in full tomorrow :) |
Small nit: would be great if we could change the argument pattern from |
@jonsadka the order of arguments is (options, text) on purpose and is our standard for the upcoming 'V2' of csg.js as well for multiple reasons
|
I was playing with a new design, and downloaded the HAVANA font. http://legionfonts.com/fonts/habana This is really small, only 19.1K. Is there anyway to embed this font (or another) rather then the vector based font? FYI, the code for the vector based font is 45K. |
What ??? the new code for vectorXXX is now about 8K (5K without the comments)....
We can embed/replace what you want, but your font is not single-line and will not work with vectorXXX, remember what i said "I'm compiling some single line fonts, it's coming soon..," Most of the fonts come from there with an explanation of what a single-line font is. For all other fonts wait for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR once again , thanks for all the great work !
I added a few points that I think need tweaking, but great work overall !
@@ -1,41 +1,213 @@ | |||
const test = require('ava') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of very thorough tests, awesome !
// -- reduced to save some bytes... | ||
// { [ascii code]: [width, x, y, ...] } - undefined value as path separator | ||
module.exports = { | ||
height: 21, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice & compact
src/api/text.test.js
Outdated
// FIXME ! circular dependencies (only in test) | ||
// location: core\math\Path2.js:197 | ||
// message : CAG.fromSides is not a function | ||
test.failing('vectorChar ({ height, extrude }, char)', t => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hurray for v2 !
char = char.charCodeAt(0) | ||
char -= 32 | ||
if (char < 0 || char >= 95) return { width: 0, segments: [] } | ||
const defaultsVectorParams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I understand why the defaults are outside the function ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because is shared from the two functions (avoid multiple sources of truths and save some bytes)
src/api/text.js
Outdated
char -= 32 | ||
if (char < 0 || char >= 95) return { width: 0, segments: [] } | ||
const defaultsVectorParams = { | ||
x: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think x & y should be named xOffset & yOffset : clarity is better than concision, and I did not immediately understand their purpose in the tests before looking the implementation up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those names probably come from SCAD API.
But I must agree that xoffset, yoffset are more meaningful.
src/api/text.js
Outdated
height: 21, // == old vector_xxx simplex font height | ||
lineSpacing: 1.4285714285714286, // == 30/21 == old vector_xxx ratio | ||
letterSpacing: 1, | ||
extrude: { w: 0, h: 0 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like x&y , I think w
should be width and h
should be height, again for clarity rather than concision
src/api/text.js
Outdated
* let vectorCharObject = vector_char(36, 0, 'B') | ||
*/ | ||
function vector_char (x, y, char) { | ||
return vectorChar({ x, y }, char) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice way of doing non breaking changes ! 👍
src/api/text.js
Outdated
* let textSegments = vector_text(0, -20, 'OpenJSCAD') | ||
*/ | ||
function vector_text (x, y, text) { | ||
return vectorText({ x, y }, text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, well done ! 👍
src/api/text.js
Outdated
* @param {Float} [options.extrude.h=0] - extrusion height, if > 0 the function return a CSG object | ||
* @param {String} [options.input='?'] - ascii character (ignored/overwrited if provided as seconds parameter) | ||
* @param {String} [char='?'] - ascii character | ||
* @returns {VectorCharObject|CSG} vectorCharObject or an CSG object if `options.extrude.h` is > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed, I really think extrusion to a CSG should be left out of this , there are already tools for that , single purpose functions are better :)
Compact is good! Thanks again for the explanations. |
@lautr3k thanks for the changes and sorry for the delay ! |
@lautr3k thanks! If you think the fonts can / will be reused then we could maintain another special repository. Could be interesting. And even more valuable if characters beside ASCII are included. Are there single line fonts that supply the complete UTF8 set? That would be quite large. |
@z3dev i have made a vector font "compiler" (provided in the repo). You'll be able to virtualy compile any single line fonts you want. |
@z3dev @kaosat-dev https://github.com/lautr3k/jscad-vector-fonts the documentation is very basic, but that's enough to understand I think? All the fonts are not present yet, but there's already 22, that's enough to test. |
Once again... so nice. Thanks! |
@lautr3k thanks for the addition, great work :)
|
@lautr3k |
thanks a lot @lautr3k for your huge work , merging ! |
Awesome! |
New features
extrusion (see note below)New syntax
vectorChar([options], char)
vectorText([options], text)
Old syntax supported but discouraged
vector_char(x, y, char)
vector_text(x, y, text)
Text height and extrusion
uppercaselowecase letters.options.extrudeOffset
.Or you can set bothoptions.extrude.w
andoptions.extrude.h
and get a CSG rather than text or char segments.Preview
Example