Results 1 to 30 of 30

Thread: GDI+ Font

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    GDI+ Font

    Hello, I need to write a word and on the lines of the letters put points so that I can read the position of these points. I wish I could define the distance between these points. Like this. http://www.type.co.uk/a_to_z/id/45874
    Thanks
    Attached Images Attached Images  

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Hi tucoali,

    It's easy enough to draw dotted text programmatically: draw the text in GDI+ using a dotted pen (as in post #8 of the thread you visited on the Graphics and Games forum), or use a dotted font. But identifying the locations of dots on the screen is much more difficult, and arranging the dots found into a path is even more problematic. Still, I have an idea that it could be done using dotted fonts.

    There's quite a few good (free) dotted fonts on the internet, for example at https://www.1001freefonts.com/dotted-fonts.php. The second and third fonts listed -- Codystar and Raleway Dots -- both look excellent for the present purpose. Above all, both those fonts have a fairly regular a dot spacing (unlike the scruffy sample you posted above!) Please download them.

    What I have in mind is to blow up a piece of dotted text to a size where you can click on the exact centre of each dot. That will make it possible to record the x/y location of each dot.

    I hope I can find some time to go further with this in the weekend. Meanwhile please download my ZoomPictureBox control using the link in my signature below (2 files). I don't have any impression of how experienced you are with programming, but I assume you will have no trouble installing a ZoomPictureBox and trying it out with an image. If not, ask.

    BB

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: GDI+ Font

    Have a look at the docs for the TextureBrush Class...

    https://docs.microsoft.com/en-us/dot...tframework-4.8

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: GDI+ Font

    Quote Originally Posted by boops boops View Post
    Hi tucoali,

    It's easy enough to draw dotted text programmatically: draw the text in GDI+ using a dotted pen (as in post #8 of the thread you visited on the Graphics and Games forum)

    BB
    That's for drawing shapes, rather than characters?

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Quote Originally Posted by .paul. View Post
    That's for drawing shapes, rather than characters?
    Not necessarily. You can add the text to a GraphicsPath with GraphicsPath.AddString, then draw it with Graphics.DrawPath. The result is similar to DrawString but the GraphicsPath remains available for other purposes.

    Quote Originally Posted by .paul. View Post
    Have a look at the docs for the TextureBrush Class...

    https://docs.microsoft.com/en-us/dot...tframework-4.8
    I don't think TextureBrush is relevant here. This CodeBank thread, to which tucoali appended a question, makes the context a bit clearer.

    BB

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Hello Boops and all, the post "This CodeBank Thread" deals with exactly what I need, but it has some problems because when the letter has straight segments the application sets only the beginning and end of this segment. This is a problem with machining because it is different from curved regions where it has one point next to the other. On large machines with throttle and motion control, this is not a problem, but I do machines using arduino and raspberry where controls are limited. Because of all this, I need points evenly distributed across the length of the letters and still be able to control the distance between those points.
    I found this post that can also help "https://binaryworld.net/Main/CodeDetail.aspx?CodeId=3794" but I don't know how to change to what I want.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Hello Boops and all, the post "This CodeBank Thread" deals with exactly what I need, but it has some problems because when the letter has straight segments the application sets only the beginning and end of this segment. This is a problem with machining because it is different from curved regions where it has one point next to the other. On large machines with throttle and motion control, this is not a problem, but I do machines using arduino and raspberry where controls are limited. Because of all this, I need points evenly distributed across the length of the letters and still be able to control the distance between those points.
    I found this post that can also help "https://binaryworld.net/Main/CodeDetail.aspx?CodeId=3794" but I don't know how to change to what I want.
    Last edited by tucoali; Jan 10th, 2020 at 07:38 AM. Reason: error duplicate message

  8. #8
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Thanks, tucoali, that makes things a bit clearer. Interpolating extra points along a straight line is itself largely a matter of fairly simple geometry, but it will take some work to get the whole process working. Probably you won't need the dotted fonts or the ZoomPictureBox after all. I'll be in touch soon with some more detailed ideas.

    BB

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: GDI+ Font

    Quote Originally Posted by boops boops View Post
    Not necessarily. You can add the text to a GraphicsPath with GraphicsPath.AddString, then draw it with Graphics.DrawPath. The result is similar to DrawString but the GraphicsPath remains available for other purposes.
    I've never tried creating text with a dotted pen, but you're light years ahead of me with VS graphics capabilities...

  10. #10
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Here's a solution which I think will do the job. I've designed a "GraphicsPathEqualizer" Class to convert a normal GraphicsPath into a path with points spaced at fairly regular intervals along the straight sections. You can also adjust the point spacing along the curves. Here's a couple of output examples:
    Name:  path points 1.jpg
Views: 441
Size:  19.8 KB
    or something more florid...
    Name:  Carrington.jpg
Views: 422
Size:  23.6 KB

    The yellow dots represent path points on the output GraphicsPath. (They are not the result of using a dotted font or a dotted pen!)

    This is an example of how you could convert a path in VB.Net code, using the GraphicsPathEqualizer (download below):
    Code:
           Dim SourcePath, ResultPath As New Drawing2D.GraphicsPath
           SourcePath.AddString("ABC", New FontFamily("Arial"), 0, 300, Point.Empty, Nothing)
           Dim minSpacing As Single = 2.5
           Dim maxSpacing As Single = 5.0
           Dim equalizer As New GraphicsPathEqualizer(SourcePath, minSpacing, maxSpacing)
           ResultPath = equalizer.ResultPath
    The font size (300 in the above example) doesn't matter too much except for feedback. You will have to scale the resulting path anyway to whatever real-world dimensions you need. Steinie's G-Code presumably provides a way of doing that. Both maximum and minimum spacing values represent percentages of the font size.

    The maximum spacing mainly affects straight lines and sometimes shallow curves. Tighter curves are affected by the minimum spacing (as in the Carrington example).

    At present the resulting path points show some irregularities in spacing, as you may notice if you look carefully at the examples above. They tend to occur where a straight line segment meets a curve, at tight corners or where two curves meet. I will look for possible ways of improving these defects in the future, with the idea of posting the results to the VB.Net CodeBank. I am also developing a demo form which will help in choosing fonts as well as suitable minimum and maximum spacing values.

    Perhaps the maximum spacing can already be used to set a reliable upper limit for machining, 3D printing etc. Irregularities in the dot spacing can be reduced or practically eliminated by lowering the minimum spacing (e.g. to 0.5) Reducing possibly the maximum spacing may help too. This is inevitably at the expense of having more path points to process.

    For graphic uses of the equalized path, I think keeping the maximum and minimum values equal looks best.

    You can download the GraphicsPathEqualizer here: GraphicsPathEqualizer.vb Add the class to your VB.Net project using the menu Project/Add Existing Item.

    BB

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Boops,
    I'll try

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 419
Size:  22.7 KB
    Boops

    Sorry for my ignorance, but I did what is there and nothing shows up. What is missing?

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 419
Size:  22.7 KB
    Boops

    Sorry for my ignorance, but I did what is there and nothing shows up. What is missing?

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 414
Size:  24.3 KB
    what's wrong?

  15. #15
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Quote Originally Posted by tucoali View Post
    what's wrong?
    Not much. However, you are drawing the path, not the path points! The yellow dots are the way I chose to show where the path points are.

    I meant the values of MinSpacing and MaxSpacing to be expressed percentages of the font size, but I didn't tell you how to do that. They were already adjusted in my previous examples. For the moment, just multiply the present spacing values by 3 (for font size 300). In your code that would mean a spacing of 3 instead of 1, although that's still a bit close together for my taste.

    Here's how you can draw the dots:
    Code:
          For Each pf As PointF In ResultPath.PathPoints
             Dim r As New RectangleF(pf.X - 1.5F, pf.Y - 1.5F, 3, 3)
             G.FillEllipse(Brushes.Yellow, r)
          Next
    Put this after (or instead of) the DrawPath line.

    For display purposes, I suggest you also give the background a dark colour; otherwise it will be hard to see the yellow dots. You could do that in the Paint sub with G.Clear(Color.DimGray). Alternatively change the dot colour to something darker. A graphics smoothing mode such as G.SmoothingMode=AntiAlias would also make the points easier to distinguish.

    BB

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 410
Size:  31.2 KB
    Boops, see.
    In the corner there is no point. Your idea was perfect, but I would like to say that at each vertex it must have a point because that point defines the beginning and end of the straight path and defines the letter. I think it would be better to set the points by distance between them and make sure you have the start and end points. The machining and control process of the machine will be easier if by distance regardless of the font size. The user will write letters inside a rectangle and the size will change according to the number of letters to fit the rectangle. So it would be better to have absolute distance between points and not relative to the font size.

  17. #17
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    You invisible point isn't very visible -- partly but not entirely due to VB Forums' characteristic blurriness. The real problem, however, is that I can't reproduce defect using the same font and the same minSpacing and maxSpacing as shown in your screenshot. What I get (magnified) is this:

    Name:  P.jpg
Views: 362
Size:  16.4 KB

    Could it be a different version of the font? In fact I have looked at dozens of different fonts at all kinds of sizes and spacings but I have never yet seen a "missing" corner on a simple rectangular section like the foot of the P. This isn't to say that defects don't occur, such as the suspiciously wide gap on the top edge of the P. Does that exceed the maximum, and if so why?

    Missing corners tend to appear at a junction of a curve with a straight segment, such as this:

    Name:  e.jpg
Views: 330
Size:  15.8 KB

    Here the SourcePath is drawn in black, the ResultPath in white and then the yellow dots, all against a DimGray background. I find this combination of colours a good way of revealing defects.

    The font size used for displaying the paths and points has no bearing whatsoever on your final user interface. It's just feedback for the present methods, which are still under development as I hope you realize. It seemed like a good idea to link the spacing values to the font size to facilitate viewing at different scales. But you can set the spacings to any value so it's not too important. It may even turn out that the minimum spacing is superfluous. Anyway, your eventual user interface will have different requirements.

    I have some ideas about how to deal with potential missing corners, but I'll have to find time to explore them.

    BB

    EDIT: Images wouldn't display, reloaded.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Hello Boops, I don't know how you are creating the points, but an idea would be, initially, to identify all the straight segments and put a point at the beginning and end, this guarantees that all corners will have a vertex. Then just measure the segments and assign a number of points according to the distance between them. I don't know if that was useful.
    Sorry for my bad English.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.JPG
Views: 377
Size:  27.7 KB

    I noticed this accumulation of points as well.
    I made a list of the coordinates and realized that there are points of type "1" and type "129", what kind of point is this?

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 393
Size:  23.0 KB

  21. #21
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Quote Originally Posted by tucoali View Post
    Hello Boops, I don't know how you are creating the points, but an idea would be, initially, to identify all the straight segments and put a point at the beginning and end, this guarantees that all corners will have a vertex. Then just measure the segments and assign a number of points according to the distance between them. I don't know if that was useful.
    Sorry for my bad English.
    Yes, we should identify the vertices in the (flattened) source path. But they can't be inserted arbitrarily. The points must be correctly integrated into the code that builds the Result path so that the sequence is correct.

    I noticed this accumulation of points as well.
    I made a list of the coordinates and realized that there are points of type "1" and type "129", what kind of point is this?
    How on earth did you get that messy C? When I draw a C with Arial 300 with spacing 5/5 I get uniformly spaced dots. Perhaps you are drawing the SourcePath pathpoints as well as the ResultPath pathpoints, or perhaps you are handling the form's Paint event somewhere as well as overriding the OnPaint sub. Please check your code. (By the way, on a Form it's conventional to handle the Paint event rather than code the OnPaint sub; there are reasons for that, mainly to avoid confusion. That "On" subs are better is a myth.)

    About 1 and 129. PathType 1 indicates one end of a straight line. After flattening, all path types will end with 1. The value 129 is 128 + 1, and 128 indicates the last point of a closed subpath. It looks more logical in binary: 10000001. The letter P has two subpaths (also called figures): the outline of the P and the hole in the P. The string "PB" consists of five subpaths, two letters and three holes. The Subpaths play an essential part in the GraphicsPathEqualizer class.

    BB

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Name:  Capturar.jpg
Views: 402
Size:  39.9 KB

    Hello Boops, see my code. Now the "C" corner has not come out.

  23. #23
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Try reducing the minimum spacing, for example to 5 or less. That will have to suffice for the while, until the "lost corners" bug is completely resolved. BB

    edit: and the maximum spacing, too.

  24. #24

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Quote Originally Posted by boops boops View Post
    Try reducing the minimum spacing, for example to 5 or less. That will have to suffice for the while, until the "lost corners" bug is completely resolved. BB

    edit: and the maximum spacing, too.

    Hi Boops, yes, changing the values ​​of "minSpacing" and "maxSpacing" the broken corners appear and disappear. OK

  25. #25
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Hi tucoali and others,
    If anyone is still interested, I've made a new version of the GraphicsPathEqualizer that resolves the "broken corners" problem. Reply here if you want a copy. BB

  26. #26

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Quote Originally Posted by boops boops View Post
    Hi tucoali and others,
    If anyone is still interested, I've made a new version of the GraphicsPathEqualizer that resolves the "broken corners" problem. Reply here if you want a copy. BB

    Yes, I'm still interested and I was waiting for your answer.

  27. #27
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Here's a Zip file with the new GraphicsPathEqualizer.vb class: GraphicsPathEqualizer.zip

    You can display the fixed corners (I call them inflections in the code) like this :
    Code:
                For Each p as PointF in equalizer.inflectionsList               
                   g.FillEllipse(... 'choose preferred brush colour and size as in Post #15 above)
                Next
    Still to do: make the spacing method with use of min. space more accurate.

    BB

  28. #28

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Thank you very much, I will test and keep you informed

  29. #29

    Thread Starter
    Junior Member
    Join Date
    Dec 2019
    Posts
    21

    Re: GDI+ Font

    Quote Originally Posted by boops boops View Post
    Here's a Zip file with the new GraphicsPathEqualizer.vb class: GraphicsPathEqualizer.zip

    You can display the fixed corners (I call them inflections in the code) like this :
    Code:
                For Each p as PointF in equalizer.inflectionsList               
                   g.FillEllipse(... 'choose preferred brush colour and size as in Post #15 above)
                Next
    Still to do: make the spacing method with use of min. space more accurate.

    BB








    Hello friend boops
    You all right?
    One doubt, would it be possible to transform this library to android? Would there be a library on android to do the same job? I am using B4A and it is very good.

  30. #30
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: GDI+ Font

    Hi tucoali, I'm still alive (roughly speaking) but feeling my age. I'm glad to hear you are getting along with B4A -- I hadn't heard of it before.

    As far as I know, .Net code can't be converted to run in Android. Maybe someone else knows for sure.

    By the way, how did the GraphicsPathEqualizer work out for machining letters? Did it work satisfactorily?

    BB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width