Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. // Draw an ellipse inside a rectangle using Bézier curves. Specify a square to draw a circle
  2. void DrawEllipse(const IJawsMakoPtr jawsMako, IDOMFixedPagePtr& fixedPage, const FRect rect,
  3. const double strokeThickness, const IDOMBrushPtr solidBrush)
  4. {
  5. // We can approximate a circle using four béziers. This is the parameter that is
  6. // used inside Jaws for this purpose
  7. double l = ((0.7071067812 - 0.5) * 8.0 / 3.0);
  8.  
  9. // And so we will offset the bézier control points by half that amount as the entire
  10. // circle is one unit in diameter.
  11. double c = l / 2.0;
  12.  
  13. // Create the geometry
  14. IDOMPathGeometryPtr geometry = createInstance<IDOMPathGeometry>(jawsMako);
  15.  
  16. // Scale to required size. As what we are scaling is 1x1, the scaling factor is simply the rect dimensions
  17. geometry->setRenderTransform(FMatrix(rect.dX , 0, 0, rect.dY, rect.x, rect.y));
  18.  
  19. // And a figure. We start at the top and head clockwise. But remember
  20. // we are upside down compared to PDF, so the direction and start point changes.
  21. IDOMPathFigure::Data params;
  22. params.startPoint = FPoint(0.5, 0.0);
  23. params.isClosed = true;
  24. params.isFilled = true;
  25. IDOMPathFigurePtr figure = createInstance<IDOMPathFigure>(jawsMako);
  26. figure->init(&params);
  27.  
  28. // And finally the bézier segment
  29. IDOMPolyBezierSegmentPtr segment = createInstance<IDOMPolyBezierSegment>(jawsMako);
  30.  
  31. // With the points as follows
  32. segment->addPoint(FPoint(0.5 + c, 0.0));
  33. segment->addPoint(FPoint(1.0, 0.5 - c));
  34. segment->addPoint(FPoint(1.0, 0.5));
  35.  
  36. segment->addPoint(FPoint(1.0, 0.5 + c));
  37. segment->addPoint(FPoint(0.5 + c, 1.0));
  38. segment->addPoint(FPoint(0.5, 1.0));
  39.  
  40. segment->addPoint(FPoint(0.5 - c, 1.0));
  41. segment->addPoint(FPoint(0.0, 0.5 + c));
  42. segment->addPoint(FPoint(0.0, 0.5));
  43.  
  44. segment->addPoint(FPoint(0.0, 0.5 - c));
  45. segment->addPoint(FPoint(0.5 - c, 0.0));
  46. segment->addPoint(FPoint(0.5, 0.0));
  47.  
  48. figure->addSegment(segment);
  49. geometry->addFigure(figure);
  50.  
  51. // And now draw a path using the marker brush
  52. IDOMPathNodePtr path;
  53. if (strokeThickness) {
  54. path = IDOMPathNode::createStroked(jawsMako, geometry, solidBrush);
  55. path->setStrokeThickness(strokeThickness);
  56. }
  57. else
  58. path = IDOMPathNode::createFilled(jawsMako, geometry, solidBrush);
  59.  
  60. // Finally add to the fixed page
  61. fixedPage->appendChild(path);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement