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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - How to draw hatches
  FAQ FAQ  Forum Search   Register Register  Login Login

How to draw hatches

 Post Reply Post Reply
Author
Message
kaiken1987 View Drop Down
Beginner
Beginner
Avatar

Joined: 27 Jan 12
Location: United States
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kaiken1987 Quote  Post ReplyReply Direct Link To This Post Topic: How to draw hatches
    Posted: 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.
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post 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);

Back to Top
kaiken1987 View Drop Down
Beginner
Beginner
Avatar

Joined: 27 Jan 12
Location: United States
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote kaiken1987 Quote  Post ReplyReply Direct Link To This Post Posted: 02 Feb 12 at 1:58PM
Thank you that worked for me very well.
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store