Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

How to add a single point to PDF page content

More
11 years 1 month ago #8455 by ashughes
I need to draw only a single point in the content of a PDF page. I tried to draw a line from and to the same x,y point, but no point appears in the PDF. For example:
Code:
PageContent content = new PageContent(); content.GSSave(); content.SetStrokeColor(color); content.SetStrokeJoin(1); // round content.SetStrokeCap(1); // round content.SetStrokeWidth(width); Path path = new Path(); path.MoveTo(x1, y1); path.LineTo(x1, y1); content.StrokePath(path); path.Destroy(); content.GSRestore(); pdfPage.AddContent(content, false); content.Destroy();
However, when I tried just adding a small amount to the point passed into LineTo(), it did work:
Code:
PageContent content = new PageContent(); content.GSSave(); content.SetStrokeColor(color); content.SetStrokeJoin(1); // round content.SetStrokeCap(1); // round content.SetStrokeWidth(width); Path path = new Path(); path.MoveTo(x1, y1); path.LineTo(x1+0.001f, y1+0.001f); // <- Added 0.001f to the point content.StrokePath(path); path.Destroy(); content.GSRestore(); pdfPage.AddContent(content, false); content.Destroy();
Is this what I need to do? Or is there a more correct way to draw a single point to the content of a PDF page? Or is this a bug in the SDK?

Thanks,
Andrew
More
11 years 1 month ago #8525 by radaee
it is checked in native library, if moveto is same to lineto point, shall ignored lineto point.
to draw single point: add a small rectangle to page is better.
More
11 years 1 month ago #8546 by ashughes
Thanks for the clarification. I don't see any methods in PageContent or Path to draw a rectangle. Could you clarify what you mean?

Are there any issues with the way I mentioned in my original post (adding a second point to a line that is very slightly different than the first point)?

Thanks,
Andrew
More
11 years 3 weeks ago #8577 by ashughes
This is what I ended up doing to work around the issue:
Code:
private void drawPoint(PageContent content, float x, float y, float width) { content.SetStrokeWidth(width); Path path = new Path(); path.MoveTo(x, y); path.LineTo(Float.intBitsToFloat(Float.floatToIntBits(x) + 1), Float.intBitsToFloat(Float.floatToIntBits(y) + 1)); // This adds one bit to the floats x and y, causing them to be the smallest possible difference from x and y content.StrokePath(path); path.Destroy(); }

It seems like a better solution would be to add a
Code:
PageContent.DrawPoint(float x, float y, float width)
or
Code:
PageContent.StrokePoint(float x, float y)
that uses the width from
Code:
PageContent.SetStrokeWidth(width)
or even adding something to Path that adds a point.

Thanks,
Andrew
More
11 years 2 weeks ago #8597 by radaee
to draw single point:
Path path = new Path();
path.MoveTo(x1, y1);
path.LineTo(x1, y1 + 1);
path.LineTo(x1 + 1, y1 + 1);
path.LineTo(x1 + 1, y1);
path.ClosePath();
content.FillPath(path);
path.Destroy();
//todo: add content to page.
Time to create page: 0.411 seconds
Powered by Kunena Forum