Android Question Text to GCode CNC Machine

fernando.oliboni

Active Member
Licensed User
Longtime User
Hi, I need to create an app that transforms texts into GCodes. Example:
upload_2018-7-27_8-22-8.png


Can someone help me?

Thank you
 

ilan

Expert
Licensed User
Longtime User
The last photo on the right is part of a polymer extrusion die....?

it is 1 of 2 parts. the second part (i also did) fits on the cone of the part you see in the picture. when both are assembled together they inject something inside. it is meant for the agriculture. but i dont know exactly what it does.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
btw i am working right now on a b4j app that will simulate engraving and also create the gcode. i already did the gcode creation now i only need to make the simulation. i am also planing to make a very very simple 3axis cnc app where you can create simple parts and output Gcode. this will be very interesting :)

cnc.png
 
Upvote 0

fernando.oliboni

Active Member
Licensed User
Longtime User
Ilan,
See the google store app "Text to CNC".
I have read some articles that talk about manipulating TTF fonts or "engraving fonts" and I think that is the way. Would you or anyone here from the fourm help me with any code? I have no idea how to do this.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Ilan,
See the google store app "Text to CNC".
I have read some articles that talk about manipulating TTF fonts or "engraving fonts" and I think that is the way. Would you or anyone here from the fourm help me with any code? I have no idea how to do this.

creating the gcode is really easy i already do it in my code but if you plan to do that with several fonts that will need some work.
i am not planning to waste to much time on this project but i will try to make a basic app that will work.

if a font would output a path it would be much simpler. so try to find a way to convert a text to a path of lines or dots and then it will be simple to create from that a gcode.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Does B4A have any library for manipulating TTF fonts?

you know what i have a good idea how to do that. but it could be a slow process to get the path. i was thinking of drawing the text on a white background with black textcolor then go through all pixels and if pixel is black add that dot to an array and then i will have an array of all dots and then i could create a path out of it.

but this is just an idea :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I am very close to a solution that will get the outer frame and inner frane of a letter and create a path of it and get the xy coordinates for the gcode output.

The problem in this is to get the points sorted so u can go from each point to the other and create the letter out of it.

But i have a solution. i will need to test it and see the performance. This lib could be used in many scenarios. But first i need to get it working for my app :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Another relevant example: https://www.b4x.com/android/forum/threads/b4x-xui-minisearchview-autocomplete-field.93564/#content

The characters are manually drawn as there is no "CSBuilder" in B4J. It is not 100% perfect. There are some inaccuracies mostly with space characters.

i am not sure this will help. so what i am trying to do is getting the lines of a letter of any font and get from it the path so i can create an array of vectors and from that array create a Gcode for CNC engraving. (like here https://www.b4x.com/android/forum/threads/text-to-gcode-cnc-machine.95534/#post-603468)

you can see in the picture that i am getting the dots from the letters (it can be done with any font) and now i am trying to sort them so you can go with the spotdrill and engrave the letters in a cnc machine.

b4xdots.jpg


i have already an idea how to sort them right and create a path for the cnc program that will also reduce as much dots as possible so the cnc program will not be too long. for now i am just getting the dots and what i need now is to sort them right in my list and reduce unnecessary dots.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I'm curious, can you also produce a screenshot of the word VAN, all caps? Preferably large size.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I'm curious, can you also produce a screenshot of the word VAN, all caps? Preferably large size.

Please open a new thread for this question! (sorry i had to get my revenge :p )

yes sure here is an example (DEFAULT FONT)

b4xdots2.jpg


and here with a different Font (Segoe Script):

b4xdots3.jpg
 
Upvote 0

ilan

Expert
Licensed User
Longtime User


after some test i found a different code much accurate then this one:

B4X:
Sub measureTextWidth(Text As String, font As Font) As Float
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text = Text
    lbl.Font = font
    MainForm.RootPane.AddNode(lbl,0,0,-1,-1)
    lbl.Snapshot
    lbl.RemoveNodeFromParent
    Return lbl.Width
End Sub

with this code i am getting a very accurate width of the letter with the Segoe Script font but your example above using b4x canvas mesuretext does not give me an accurate result.

this is my code:

B4X:
Sub measureTextWidth(Text As String, font As Font) As Float
    Dim cnx As B4XCanvas
    cnx.Initialize(MainForm.RootPane)
    Return cnx.MeasureText(Text, font).Width
   
'    Dim lbl As Label
'    lbl.Initialize("")
'    lbl.Text = Text
'    lbl.Font = font
'    MainForm.RootPane.AddNode(lbl,0,0,-1,-1)
'    lbl.Snapshot
'    lbl.RemoveNodeFromParent
'    Return lbl.Width
End Sub

and result:

b4xdots4.jpg


you can see it is not that accurate so the code with the label is working much better.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Of course, I would expect nothing less! :)

The lack of kerning is visible in both pics, the last one most. Looking forward to seeing the magic method you will be using to solve that. :)

in my opinion it looks good enough but i could increase the dots amount and get a much accurate result. the question is what needs you have with that lib??
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Kerning is the space between individual characters. As each character can be followed by many different characters, there needs to be a lookup table with all the combinations. This is called kerning pairs, and it's something that typographers spend many, many hours perfecting for each typeface.

I'm afk at the moment so difficult to illustrate with your screenshots, but take a look at https://en.wikipedia.org/wiki/Kerning to see some illustrations.

And as Erel hinted, don't underestimate the complexity of kerning - it's a seriously difficult problem to solve.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not exactly sure what you are measuring. DrawTextWithBorder seems to be accurate with this font:

SS-2018-07-29_10.10.45.png


B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   Dim cvs As B4XCanvas
   cvs.Initialize(Pane1)
   Dim fnt As Font = jFX.CreateFont("Segoe Script", 150, False, False)
   DrawTextWithBorder(cvs, "VAN", fnt, xui.Color_Red, Pane1.Width / 2, Pane1.Height / 2)
   cvs.Invalidate
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I'm not exactly sure what you are measuring. DrawTextWithBorder seems to be accurate with this font:

The letter width (not whole text)

Kerning is the space between individual characters. As each character can be followed by many different characters, there needs to be a lookup table with all the combinations. This is called kerning pairs, and it's something that typographers spend many, many hours perfecting for each typeface.

This is not relevant for my needs. In cnc you need to leave some space between letters they should not be to close. Anyway it is very simple to do what u are asking but i didnot do it in my app. But i can show you that it is possible.

Example with a different Font and kerning!:

cncndots1.jpg


you can see that the letters are inside each other.
 
Last edited:
Upvote 0
Top