Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filling Shapes with Pattern using Line command 2

Status
Not open for further replies.

kpkale

Programmer
Sep 5, 2009
9
IN
I am trying to draw hatch patterns inside outline text (TTF) just as you do in a CAD program. Can anyone help to do this effectively.
 
I am at present successful in reading a TTF File and getting the glyph points for characters and then drawing them on a picturebox using .line method of the picturebox.
I can rotate them, or make them appear circular.. Attached bitmap No.1 will show the output at present. and the attached bitmap No. 2 (which I have modified using Paint. I have modified only 3 characters "Sim" as an example.) will show you exactly what I want to do. Where I can have the hatching at any angle and change distance between hatch lines.

OH I just noticed that it is not possible to upload attachments for free...
I have used the code available at this link for the TTF functions... THat will explain what I have already done.
 
I don't know if you'll be able to fill your shapes with it but have you investigated the Fillstyle Property as in this simple example;

Private Sub Command1_Click()
Me.FillStyle = vbUpwardDiagonal
Me.Circle (1000, 1000), 500
End Sub
 
Yes, The link I indicated does not do filling of shapes.

I know of this FillStyle method verywell. However, that is not useful as I using only Line and PSet Commands to draw the characters in the Font. And in the same way for drawing various shapes, I am using only Line and Pset Commands.

 
After a first glance at the referenced code I would be tempted to place all the drawing points (ie. the xs and the ys) into an array and then feed it to the PolyGon API for drawing instead of using Pset and Line. The shape drawn should be filled with the current FillStyle of the object being drawn on.

An example of using the the Polygon API at The MSDN deets are at
 
>noticed that it is not possible to upload attachments for free

It is. Box.net will give you free space when you set uop an 'account' - they just don't make this very clear.

>Line and PSet Commands to draw the characters in the Font

Is there any specific reason why you use this technique? There are much simpler and faster methods for drawing the outline of a TT font (and for filling it with any brush design you fancy). Thise methods might not be appropriate, however.



 
Though Line and Pset is not the best way of drawing on a picturebox, they are at present giving me the flexibility of drawing the TTF Fonts on screen. The Filling i require is mainly for filling of fonts. When using FillStyle, it does not differentiate between the holes that are not to be filled as seen in a character "B".
Moreover, my ultimate aim of doing this exercise is to drive a pen plotter to fill the fonts with hatched lines. SO in that case, I require to know the co-ordinates of each and every line that is drawn in the filling so that I can drive the pen in vector mode.
Here is the link to Youtube video of what I ultimately want to achieve.
At present the simplest method for me was to export a HPGL file from AutoCad and then just send it to pen plotter. But now I want to write my own program to do it as a next step of my project.
 
>it does not differentiate between the holes that are not to be filled as seen in a character "B".

Well, the problem there is not that it doesn't recognize the holes; it is more that you have derived three seperate polygons, not one polygon with holes in it ...

Here's an example of about the simplest way of doing this (needs a form with one button):
Code:
[blue]Option Explicit
Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function StrokeAndFillPath Lib "gdi32" (ByVal hdc As Long) As Long

Private Sub Command1_Click()
    BeginPath Form1.hdc
    Form1.Print "Hello"
    EndPath Form1.hdc
    StrokeAndFillPath Form1.hdc
End Sub

' Set up an appropriate font and fill style
Private Sub Form_Load()
    Form1.FillStyle = vbUpwardDiagonal
    Form1.FontName = "Arial Bold"
    Form1.FontSize = 36
End Sub[/blue]
 
That was indeed a great code. Thanks for that.

However, I was wondering if it would solve my problem. Will I get the co-ordinates of the hatch lines as well as the text drawn by using getpath API Call?
 
No. I'm afraid not. The brush used for standard hatch fills (in fact, for any of the standard GDI fills) is actually a bitmap.

 
Any way that you know where I could get the logic for hatching and still get the co-ordinates so that i could drive my pen?
Logically, I feel that I will have to execute the rastering or font filling algorithm that is used by windows to fill fonts. I plan to write some code.. will post it as soon as I have something concrete. In the meanwhile... Any help available is welcome......
 
It's still a bitmap, Hugh. Brushes are bitmaps, and all that code does is make your own brush ...


One possibiity, which I have not tried (and have no idea whether it would work for a plotter) would be to use the SlectCLipPath API call after creating the text path, and then using Line and Pset methods or their API equivalents) to draw your own hatching, which should get clipped to the interior of the text. But, as I say, I don't know how this would translate to a pen plotter.
 
Hi All of you

I could solve this problem using Regions and Path functionality of GDI.

but your tips very valuable in solving this.

Thanks for all your advice.
 
Er, my tips are using the Path functionality of the GDI ...
 
Er yes.

Anyway just for the record re SelectClipPath I have this working.

Private Sub Command1_Click()

Dim i

BeginPath Form1.hdc
Form1.Print "Hello"
EndPath Form1.hdc

SelectClipPath Form1.hdc, RGN_COPY
'lines drawn are clipped to only appear inside the Path outline
For i = 0 To ScaleWidth Step Screen.TwipsPerPixelX * 5
Form1.Line (i, 0)-(i, ScaleHeight)
Next

End Sub

Just out of interest once that is done is it possible to Un-SelectClipPath so that drawing can continue outside the clipped area.
 
I did the following:

beginpath
draw the glyphs
end path
pathtoregion and make a region
And in the rectagle for every pixel check if the pixel is in the region... find the first and last point of every line of hatch...
the draw the hatch.

I have still not finished it, but expect to complete it today.
 
BTW, when I said
>which I have not tried
I didn't mean I hadn't tried SetClipPath, rather that I hadn't tried working it with a pen plotter. So I can indeed tell you how to un-SelectClipPath :)

What you have to know is that clipping is done by regions, not by paths. So SelectClipPath actually selects a Path as a clipping region rather than a clipping path. This might seem to be splitting hairs, but it helps explains why there is no ResetClipPath or UnSelectClipPath function: we need to be looking at regions.

And what we like to do with regions is record the current clipping region and then restore it after we've done our custom clipping. So the API functions that you want to look at are:

[tt]GetClipRgn[/tt]

and

[tt]SelectClipRgn[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top