-
-
Notifications
You must be signed in to change notification settings - Fork 666
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
Conversation
There was a problem hiding this 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.
pdf/lib/src/widgets/annotations.dart
Outdated
), | ||
); | ||
} | ||
} | ||
|
||
class AnnotationUrl extends AnnotationBuilder { | ||
AnnotationUrl(this.destination); | ||
AnnotationUrl(this.destination, {this.date, this.subject, this.author}); |
There was a problem hiding this comment.
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
?
pdf/lib/src/pdf/annotation.dart
Outdated
|
||
final PdfColor? interiorColor; | ||
|
||
void addAppearance() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pdf/lib/src/widgets/annotations.dart
Outdated
} | ||
|
||
class AnnotationPolygon extends AnnotationBuilder { | ||
AnnotationPolygon(this.points, {this.color, this.interiorColor, this.border, this.date, this.subject, this.author}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pdf/lib/src/pdf/annotation.dart
Outdated
|
||
final PdfColor? interiorColor; | ||
|
||
void addAppearance() { |
There was a problem hiding this comment.
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.
pdf/lib/src/pdf/annotation.dart
Outdated
|
||
final PdfColor? interiorColor; | ||
|
||
void addAppearance() { |
There was a problem hiding this comment.
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.
pdf/lib/src/widgets/annotations.dart
Outdated
} | ||
|
||
class AnnotationPolygon extends AnnotationBuilder { | ||
AnnotationPolygon(this.points, {this.color, this.interiorColor, this.border, this.date, this.subject, this.author}); |
There was a problem hiding this comment.
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 Report
@@ 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
Continue to review full report at Codecov.
|
String? author, | ||
String? content,}) | ||
: super( | ||
subtype: '/InkList', |
There was a problem hiding this comment.
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.
pdf/lib/src/widgets/annotations.dart
Outdated
String? subject, | ||
String? content, | ||
}) : super( | ||
child: Rectangle( |
There was a problem hiding this comment.
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: ...
pdf/lib/src/widgets/annotations.dart
Outdated
String? content, | ||
String? subject, | ||
}) : super( | ||
child: InkList( |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
pdf/lib/src/widgets/annotations.dart
Outdated
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxY - maxX?
pdf/lib/src/pdf/annotation.dart
Outdated
date: date, | ||
color: color, | ||
subject: subject, | ||
author: author); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/pdf/annotation.dart
Outdated
date: date, | ||
color: color, | ||
subject: subject, | ||
author: author); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/pdf/annotation.dart
Outdated
date: date, | ||
color: color, | ||
subject: subject, | ||
author: author); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/pdf/annotation.dart
Outdated
date: date, | ||
color: color, | ||
subject: subject, | ||
author: author); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/pdf/annotation.dart
Outdated
String? author, | ||
bool closed = true}) | ||
: super( | ||
subtype: closed ? "/PolyLine" : '/Polygon', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use single quotes.
pdf/lib/src/widgets/annotations.dart
Outdated
url: destination, | ||
date: date, | ||
author: author, | ||
subject: subject), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/widgets/annotations.dart
Outdated
interiorColor: interiorColor, | ||
date: date, | ||
author: author, | ||
subject: subject), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/widgets/annotations.dart
Outdated
interiorColor: interiorColor, | ||
date: date, | ||
author: author, | ||
subject: subject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
pdf/lib/src/widgets/annotations.dart
Outdated
interiorColor: interiorColor, | ||
date: date, | ||
author: author, | ||
subject: subject), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comma
Merged, thanks. |
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.