Skip to content

Adding Additional Annotation Support #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

johncharris
Copy link

I'm working on more complete annotation support. I ran into an issue I'm unsure of.

Where is the best place to add the appearance? I added a method to do this, but I think there is a better way.

Once I get feedback on this I'll add more types of annotations.

Copy link
Owner

@DavBfr DavBfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run make format to reformat all the code.
or dart format --fix . if you can't run the Makefile.

),
);
}
}

class AnnotationUrl extends AnnotationBuilder {
AnnotationUrl(this.destination);
AnnotationUrl(this.destination, {this.date, this.subject, this.author});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comma after this.author?


final PdfColor? interiorColor;

void addAppearance() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should not have this here, see the other comment on AnnotationPolygon

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were is the best place to run the code that will make the appearance stream? I agree this isn't it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have /Vertices, so the annotation seems fine. Then the appearance would be used to display user graphics on top of that, but still part of the annotation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the appearance code from here, and add it to the Widget AnnotationPolygon as a child widget.

Same as PdfButtonField => FlatButton. Basically everything in lib/src/pdf is low-level dumb PDF, and lib/src/widgets is what developers expect for an easy-to-use API.

}

class AnnotationPolygon extends AnnotationBuilder {
AnnotationPolygon(this.points, {this.color, this.interiorColor, this.border, this.date, this.subject, this.author});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the Flutter spirit of Widgets, the polygon drawing should be a child widget.
A Polygon widget will get the same List on its constructor and will just draw. It can be used outside the AnnotationPolygon with more settings, maybe a ClipPolygon widget can be interesting to clip its child, this child can be used to draw anything else within the defined annotation.
What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For proper PDF compatibility it should be use the different annotation subtypes Polygon, Polyline, Ink, etc.

That said, I had issues rendering the polygon annotation without the stream. Notably, PDF.js has issues with this 6810.

My preference would be to do it by the book for the most compatibility. I like the idea of having some drawing widgets the convert into streams. I haven't looked too see what this library has for that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the Signature Widget: it draws its child into an appearance stream.


final PdfColor? interiorColor;

void addAppearance() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have /Vertices, so the annotation seems fine. Then the appearance would be used to display user graphics on top of that, but still part of the annotation.


final PdfColor? interiorColor;

void addAppearance() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the appearance code from here, and add it to the Widget AnnotationPolygon as a child widget.

Same as PdfButtonField => FlatButton. Basically everything in lib/src/pdf is low-level dumb PDF, and lib/src/widgets is what developers expect for an easy-to-use API.

}

class AnnotationPolygon extends AnnotationBuilder {
AnnotationPolygon(this.points, {this.color, this.interiorColor, this.border, this.date, this.subject, this.author});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the Signature Widget: it draws its child into an appearance stream.

@codecov-commenter
Copy link

Codecov Report

Merging #742 (2d53d45) into master (2e17c62) will decrease coverage by 0.24%.
The diff coverage is 8.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #742      +/-   ##
==========================================
- Coverage   42.54%   42.30%   -0.25%     
==========================================
  Files         123      123              
  Lines       16022    16126     +104     
==========================================
+ Hits         6817     6822       +5     
- Misses       9205     9304      +99     
Impacted Files Coverage Δ
pdf/lib/src/widgets/widget.dart 80.57% <0.00%> (-2.39%) ⬇️
pdf/lib/src/pdf/annotation.dart 63.97% <4.54%> (-18.42%) ⬇️
pdf/lib/src/widgets/annotations.dart 48.36% <11.47%> (-24.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e17c62...2d53d45. Read the comment docs.

String? author,
String? content,})
: super(
subtype: '/InkList',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this annotation type in the PDF documentation. Only Ink which has an InkList key.

String? subject,
String? content,
}) : super(
child: Rectangle(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about having this:

SquareAnnotation({
...
  Widget? child,
  }) : super(
            child: child ?? Rectangle(...),
            builder: ...

String? content,
String? subject,
}) : super(
child: InkList(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be replaced by a list of Polygons

));
}

class PolyLineAnnotation extends Annotation {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reuse Polygon with a closed parameter?

final maxX = allPoints.map((point) => point.x).reduce(max);
final maxY = allPoints.map((point) => point.y).reduce(max);
final rect =
context.localToGlobal(PdfRect(minX, minY, maxX - minX, maxY - maxX));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxY - maxX?

date: date,
color: color,
subject: subject,
author: author);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

date: date,
color: color,
subject: subject,
author: author);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

date: date,
color: color,
subject: subject,
author: author);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

date: date,
color: color,
subject: subject,
author: author);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

String? author,
bool closed = true})
: super(
subtype: closed ? "/PolyLine" : '/Polygon',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single quotes.

url: destination,
date: date,
author: author,
subject: subject),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

interiorColor: interiorColor,
date: date,
author: author,
subject: subject),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

interiorColor: interiorColor,
date: date,
author: author,
subject: subject);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

interiorColor: interiorColor,
date: date,
author: author,
subject: subject),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

@johncharris johncharris marked this pull request as ready for review July 13, 2021 18:41
@DavBfr
Copy link
Owner

DavBfr commented Jul 22, 2021

Merged, thanks.

@DavBfr DavBfr closed this Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants