Android Question Text to GCode CNC Machine

Discussion in 'Android Questions' started by fernando.oliboni, Jul 27, 2018.

  1. ilan

    ilan Expert Licensed User

    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.
     
    DonManfred likes this.
  2. ilan

    ilan Expert Licensed 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
     
  3. fernando.oliboni

    fernando.oliboni Member Licensed 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.
     
  4. ilan

    ilan Expert Licensed User

    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.
     
    Peter Simpson likes this.
  5. fernando.oliboni

    fernando.oliboni Member Licensed User

    Does B4A have any library for manipulating TTF fonts?
     
  6. ilan

    ilan Expert Licensed User

    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 :)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

  8. ilan

    ilan Expert Licensed 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 :)
     
  9. Sandman

    Sandman Well-Known Member Licensed User

    How are you planning to get the kerning pairs? Or are you planning on using only monospaced fonts?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

  11. ilan

    ilan Expert Licensed User

    Any font any letter. My own algorythm. Will post the explaination when i have a working example. :)
     
    Peter Simpson likes this.
  12. ilan

    ilan Expert Licensed User

    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.
     
  13. Sandman

    Sandman Well-Known Member Licensed User

    I'm curious, can you also produce a screenshot of the word VAN, all caps? Preferably large size.
     
  14. ilan

    ilan Expert Licensed User

    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
     
    Sandman likes this.
  15. ilan

    ilan Expert Licensed User


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

    Code:
    Sub measureTextWidth(Text As Stringfont As FontAs 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:

    Code:
    Sub measureTextWidth(Text As Stringfont As FontAs 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.
     
  16. Sandman

    Sandman Well-Known Member Licensed 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. :)
     
  17. ilan

    ilan Expert Licensed User

    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??
     
  18. Sandman

    Sandman Well-Known Member Licensed 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.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

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

    [​IMG]

    Code:
    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"150FalseFalse)
       DrawTextWithBorder(cvs, 
    "VAN", fnt, xui.Color_Red, Pane1.Width / 2, Pane1.Height / 2)
       cvs.Invalidate
    End Sub
     
  20. ilan

    ilan Expert Licensed User

    The letter width (not whole text)

    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: Jul 29, 2018
    Peter Simpson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice