Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Draw an ellipse inside a rectangle using Bézier curves. Specify a square to draw a circle
- void DrawEllipse(const IJawsMakoPtr jawsMako, IDOMFixedPagePtr& fixedPage, const FRect rect,
- const double strokeThickness, const IDOMBrushPtr solidBrush)
- {
- // We can approximate a circle using four béziers. This is the parameter that is
- // used inside Jaws for this purpose
- double l = ((0.7071067812 - 0.5) * 8.0 / 3.0);
- // And so we will offset the bézier control points by half that amount as the entire
- // circle is one unit in diameter.
- double c = l / 2.0;
- // Create the geometry
- IDOMPathGeometryPtr geometry = createInstance<IDOMPathGeometry>(jawsMako);
- // Scale to required size. As what we are scaling is 1x1, the scaling factor is simply the rect dimensions
- geometry->setRenderTransform(FMatrix(rect.dX , 0, 0, rect.dY, rect.x, rect.y));
- // And a figure. We start at the top and head clockwise. But remember
- // we are upside down compared to PDF, so the direction and start point changes.
- IDOMPathFigure::Data params;
- params.startPoint = FPoint(0.5, 0.0);
- params.isClosed = true;
- params.isFilled = true;
- IDOMPathFigurePtr figure = createInstance<IDOMPathFigure>(jawsMako);
- figure->init(¶ms);
- // And finally the bézier segment
- IDOMPolyBezierSegmentPtr segment = createInstance<IDOMPolyBezierSegment>(jawsMako);
- // With the points as follows
- segment->addPoint(FPoint(0.5 + c, 0.0));
- segment->addPoint(FPoint(1.0, 0.5 - c));
- segment->addPoint(FPoint(1.0, 0.5));
- segment->addPoint(FPoint(1.0, 0.5 + c));
- segment->addPoint(FPoint(0.5 + c, 1.0));
- segment->addPoint(FPoint(0.5, 1.0));
- segment->addPoint(FPoint(0.5 - c, 1.0));
- segment->addPoint(FPoint(0.0, 0.5 + c));
- segment->addPoint(FPoint(0.0, 0.5));
- segment->addPoint(FPoint(0.0, 0.5 - c));
- segment->addPoint(FPoint(0.5 - c, 0.0));
- segment->addPoint(FPoint(0.5, 0.0));
- figure->addSegment(segment);
- geometry->addFigure(figure);
- // And now draw a path using the marker brush
- IDOMPathNodePtr path;
- if (strokeThickness) {
- path = IDOMPathNode::createStroked(jawsMako, geometry, solidBrush);
- path->setStrokeThickness(strokeThickness);
- }
- else
- path = IDOMPathNode::createFilled(jawsMako, geometry, solidBrush);
- // Finally add to the fixed page
- fixedPage->appendChild(path);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement