Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
How to draw hatches |
Post Reply
|
| Author | |
kaiken1987
Beginner
Joined: 27 Jan 12 Location: United States Status: Offline Points: 5 |
Post Options
Thanks(0)
Quote Reply
Topic: How to draw hatchesPosted: 31 Jan 12 at 2:56PM |
|
I'm trying to find a way to draw filled polygons with holes in them, something like the widows GDI polypolygon function. The only way I've been able to figure out is to call GetCanvasDC, RenderToDC, use the polypolygon function and then call LoadFromCanvasDC. That seems terribly slow and inefficient and I assume the must be a better way then that.
|
|
![]() |
|
AndrewC
Moderator Group
Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
Quote Reply
Posted: 01 Feb 12 at 8:25AM |
|
Here is some code to draw a hollow star..
// Draw a hollow star QP.SetFillColor(1, 0, 0); QP.SetLineColor(0, 1, 0); QP.StartPath(100, 60); QP.AddLineToPath(306, 600); QP.AddLineToPath(512, 60); QP.AddLineToPath(20, 400); QP.AddLineToPath(592, 400); QP.ClosePath(); QP.DrawPathEvenOdd(2); // Draw a hollow donut QP.NewPage(); QP.SetFillColor(1, 0, 0); QP.SetLineColor(0, 1, 0); QP.StartPath(100, 200); QP.AddArcToPath(200, 200, 360); QP.MovePath(150, 200); QP.AddArcToPath(200, 200, 360); QP.ClosePath(); QP.DrawPathEvenOdd(2); |
|
![]() |
|
kaiken1987
Beginner
Joined: 27 Jan 12 Location: United States Status: Offline Points: 5 |
Post Options
Thanks(0)
Quote Reply
Posted: 02 Feb 12 at 1:58PM |
|
Thank you that worked for me very well.
|
|
![]() |
|
edvoigt
Senior Member
Joined: 26 Mar 11 Location: Berlin, Germany Status: Offline Points: 111 |
Post Options
Thanks(0)
Quote Reply
Posted: 03 Feb 12 at 8:18PM |
|
Hi,
there is something more to say. Because hatch or not hatch is a question of orientation. ![]() My first example shows a normal drawn box and for clipping a path consisting of a circle and a hatch-box in it. Here the source: QP.SetOrigin(0); // Bottomleft QP.SetMeasurementUnits(1); // Millimeter QP.SetPageDimensions(210, 297); QP.SetLineWidth(0.1); QP.SetLineColor(1, 0, 0); QP.SetFillColor(1, 1, 0); x0 := 25; x1 := 175; y0 := 170; y1 := 270; r := 70; // 1. draw without clipping QP.DrawBox(x0, y1, x1-x0, y1-y0, 1); QP.DrawCircle((x0+x1)/2, y1-r, r, 0); QP.SaveState; // for later use without clipping // 2. define clipping path QP.StartPath((x0+x1)/2, y1); QP.AddArcToPath((x0+x1)/2, y1-r, 360); // the "normal" path for clipping // 3. hatch-box-building // hatch or not hatch is a question of orientation QP.MovePath(x0+20, y0+75); // upper left corner QP.AddLineToPath(x0+20, y0+50); // lower left QP.AddLineToPath(x0+50, y0+50); // lower right QP.AddLineToPath(x0+50, y0+75); // upper right QP.AddLineToPath(x0+20, y0+75); // close hatch, important! QP.SetClippingPath; // 4. draw clipped things // it will be drawn only inside the first circle and outside our hatchbox QP.DrawBox(x0, y1, x1-x0, y1-y0, 0); for i:=0 to 52 do QP.DrawLine(x1-i*5, y0, x1, y0+i*5); QP.SetFillColor(0, 1, 0); QP.DrawCircle(x0+50, y0+75, 10, 2); QP.LoadState; // stop clipping from here QP.SetLineColor(0, 0, 0); QP.DrawLine(x0, y0, (x0+x1)/2, y1); The second example is more interessting. Using four lines two triangles are builded, but only one of them becomes to be hatch. That's so because of orientation during AddLineToPath-sequence. ![]() Wandering from P1 over P2 to P3 upper triangle is ever on your right side. But the other Triangle is on the way from P3 over P4 to P1 on left side. Areas on right side are are parts of the path, but areas on left side dont't belong to path, they are hatches. Source for this: x0 := 100; y1 := y0-50; y0 := 20; r := 30; QP.SaveState; // for later use without clipping QP.StartPath(x0-r-5, y1+5); //first a box as clipping area QP.AddLineToPath(x0+2*r, y1); QP.AddLineToPath(x0+2*r, y0-1); QP.AddLineToPath(x0-r, y0-1); QP.AddLineToPath(x0-r, y1); // and now a special kind of half hatch QP.MovePath(x0, y1); QP.AddLineToPath(x0+r, y1); QP.AddLineToPath(x0-r, y0); QP.AddLineToPath(x0+r, y0); QP.AddLineToPath(x0, y1); QP.SetClippingPath; QP.DrawBox(x0-r, y1, 2*r, y1-y0, 1); // show hatch construction QP.SetLineColor(0, 0, 0); QP.SetLineWidth(1.0); QP.DrawLine(x0, y1, x0+r, y1); // show the contour QP.DrawLine(x0+r, y1, x0-r, y0); QP.DrawLine(x0-r, y0, x0+r, y0); QP.DrawLine(x0+r, y0, x0, y1); QP.LoadState; // stop clipping now again QP.DrawText(x0, y1+2, 'P1'); QP.DrawText(x0+r, y1+2, 'P2'); QP.DrawText(x0-r, y0-5, 'P3'); QP.DrawText(x0+r, y0-5, 'P4'); Cheers, Werner Edited by edvoigt - 03 Feb 12 at 8:20PM |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store