David PHAM-VAN

Mark some internal functions as protected

@@ -93,8 +93,8 @@ class PdfAnnot extends PdfObject { @@ -93,8 +93,8 @@ class PdfAnnot extends PdfObject {
93 /// 93 ///
94 /// @param os OutputStream to send the object to 94 /// @param os OutputStream to send the object to
95 @override 95 @override
96 - void prepare() {  
97 - super.prepare(); 96 + void _prepare() {
  97 + super._prepare();
98 98
99 params["/Subtype"] = PdfStream.string(subtype); 99 params["/Subtype"] = PdfStream.string(subtype);
100 params["/Rect"] = PdfStream.string( 100 params["/Rect"] = PdfStream.string(
@@ -24,8 +24,8 @@ class PdfArrayObject extends PdfObject { @@ -24,8 +24,8 @@ class PdfArrayObject extends PdfObject {
24 PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument); 24 PdfArrayObject(PdfDocument pdfDocument, this.values) : super(pdfDocument);
25 25
26 @override 26 @override
27 - void writeContent(PdfStream os) {  
28 - super.writeContent(os); 27 + void _writeContent(PdfStream os) {
  28 + super._writeContent(os);
29 29
30 os.putStringArray(values); 30 os.putStringArray(values);
31 } 31 }
@@ -61,8 +61,8 @@ class PdfBorder extends PdfObject { @@ -61,8 +61,8 @@ class PdfBorder extends PdfObject {
61 61
62 /// @param os OutputStream to send the object to 62 /// @param os OutputStream to send the object to
63 @override 63 @override
64 - void writeContent(PdfStream os) {  
65 - super.writeContent(os); 64 + void _writeContent(PdfStream os) {
  65 + super._writeContent(os);
66 66
67 var data = List<PdfStream>(); 67 var data = List<PdfStream>();
68 data.add(PdfStream.string("/S")); 68 data.add(PdfStream.string("/S"));
@@ -38,8 +38,8 @@ class PdfCatalog extends PdfObject { @@ -38,8 +38,8 @@ class PdfCatalog extends PdfObject {
38 38
39 /// @param os OutputStream to send the object to 39 /// @param os OutputStream to send the object to
40 @override 40 @override
41 - void prepare() {  
42 - super.prepare(); 41 + void _prepare() {
  42 + super._prepare();
43 43
44 params["/Pages"] = pdfPageList.ref(); 44 params["/Pages"] = pdfPageList.ref();
45 45
@@ -130,7 +130,7 @@ class PdfDocument { @@ -130,7 +130,7 @@ class PdfDocument {
130 /// completion. It is up to the caller to close the stream. 130 /// completion. It is up to the caller to close the stream.
131 /// 131 ///
132 /// @param os OutputStream to write the document to 132 /// @param os OutputStream to write the document to
133 - void write(PdfStream os) { 133 + void _write(PdfStream os) {
134 PdfOutput pos = PdfOutput(os); 134 PdfOutput pos = PdfOutput(os);
135 135
136 // Write each object to the [PdfStream]. We call via the output 136 // Write each object to the [PdfStream]. We call via the output
@@ -145,7 +145,7 @@ class PdfDocument { @@ -145,7 +145,7 @@ class PdfDocument {
145 145
146 List<int> save() { 146 List<int> save() {
147 PdfStream os = PdfStream(); 147 PdfStream os = PdfStream();
148 - write(os); 148 + _write(os);
149 return os.output(); 149 return os.output();
150 } 150 }
151 } 151 }
@@ -41,8 +41,8 @@ class PdfFont extends PdfObject { @@ -41,8 +41,8 @@ class PdfFont extends PdfObject {
41 41
42 /// @param os OutputStream to send the object to 42 /// @param os OutputStream to send the object to
43 @override 43 @override
44 - void prepare() {  
45 - super.prepare(); 44 + void _prepare() {
  45 + super._prepare();
46 46
47 params["/Subtype"] = PdfStream.string(subtype); 47 params["/Subtype"] = PdfStream.string(subtype);
48 params["/Name"] = PdfStream.string(name); 48 params["/Name"] = PdfStream.string(name);
@@ -26,8 +26,8 @@ class PdfFontDescriptor extends PdfObject { @@ -26,8 +26,8 @@ class PdfFontDescriptor extends PdfObject {
26 : super(ttfFont.pdfDocument, "/FontDescriptor"); 26 : super(ttfFont.pdfDocument, "/FontDescriptor");
27 27
28 @override 28 @override
29 - void prepare() {  
30 - super.prepare(); 29 + void _prepare() {
  30 + super._prepare();
31 31
32 params["/FontName"] = PdfStream.string(ttfFont.baseFont); 32 params["/FontName"] = PdfStream.string(ttfFont.baseFont);
33 params["/FontFile2"] = file.ref(); 33 params["/FontFile2"] = file.ref();
@@ -38,8 +38,8 @@ class PdfFormXObject extends PdfXObject { @@ -38,8 +38,8 @@ class PdfFormXObject extends PdfXObject {
38 } 38 }
39 39
40 @override 40 @override
41 - void prepare() {  
42 - super.prepare(); 41 + void _prepare() {
  42 + super._prepare();
43 43
44 // Now the resources 44 // Now the resources
45 /// This holds any resources for this FormXObject 45 /// This holds any resources for this FormXObject
@@ -77,7 +77,7 @@ class PdfImage extends PdfXObject { @@ -77,7 +77,7 @@ class PdfImage extends PdfXObject {
77 } 77 }
78 78
79 @override 79 @override
80 - void prepare() { 80 + void _prepare() {
81 // write the pixels to the stream 81 // write the pixels to the stream
82 // print("Processing image ${img.width}x${img.height} pixels"); 82 // print("Processing image ${img.width}x${img.height} pixels");
83 83
@@ -101,7 +101,7 @@ class PdfImage extends PdfXObject { @@ -101,7 +101,7 @@ class PdfImage extends PdfXObject {
101 101
102 buf.putBytes(out); 102 buf.putBytes(out);
103 103
104 - super.prepare(); 104 + super._prepare();
105 } 105 }
106 106
107 /// Get the name 107 /// Get the name
@@ -34,8 +34,8 @@ class PdfInfo extends PdfObject { @@ -34,8 +34,8 @@ class PdfInfo extends PdfObject {
34 34
35 /// @param os OutputStream to send the object to 35 /// @param os OutputStream to send the object to
36 @override 36 @override
37 - void prepare() {  
38 - super.prepare(); 37 + void _prepare() {
  38 + super._prepare();
39 39
40 if (author != null) params["/Author"] = PdfStream.text(author); 40 if (author != null) params["/Author"] = PdfStream.text(author);
41 if (creator != null) params["/Creator"] = PdfStream.text(creator); 41 if (creator != null) params["/Creator"] = PdfStream.text(creator);
@@ -50,16 +50,16 @@ class PdfObject { @@ -50,16 +50,16 @@ class PdfObject {
50 /// it's Kids, as they will be written by the calling routine. 50 /// it's Kids, as they will be written by the calling routine.
51 /// 51 ///
52 /// @param os OutputStream to send the object to 52 /// @param os OutputStream to send the object to
53 - void write(PdfStream os) {  
54 - prepare();  
55 - writeStart(os);  
56 - writeContent(os);  
57 - writeEnd(os); 53 + void _write(PdfStream os) {
  54 + _prepare();
  55 + _writeStart(os);
  56 + _writeContent(os);
  57 + _writeEnd(os);
58 } 58 }
59 59
60 /// Prepare the object to be written to the stream 60 /// Prepare the object to be written to the stream
61 @mustCallSuper 61 @mustCallSuper
62 - void prepare() {} 62 + void _prepare() {}
63 63
64 /// The write method should call this before writing anything to the 64 /// The write method should call this before writing anything to the
65 /// OutputStream. This will send the standard header for each object. 65 /// OutputStream. This will send the standard header for each object.
@@ -67,11 +67,11 @@ class PdfObject { @@ -67,11 +67,11 @@ class PdfObject {
67 /// Note: There are a few rare cases where this method is not called. 67 /// Note: There are a few rare cases where this method is not called.
68 /// 68 ///
69 /// @param os OutputStream to write to 69 /// @param os OutputStream to write to
70 - void writeStart(PdfStream os) { 70 + void _writeStart(PdfStream os) {
71 os.putString("$objser $objgen obj\n"); 71 os.putString("$objser $objgen obj\n");
72 } 72 }
73 73
74 - void writeContent(PdfStream os) { 74 + void _writeContent(PdfStream os) {
75 if (params.length > 0) { 75 if (params.length > 0) {
76 os.putDictionary(params); 76 os.putDictionary(params);
77 os.putString("\n"); 77 os.putString("\n");
@@ -84,7 +84,7 @@ class PdfObject { @@ -84,7 +84,7 @@ class PdfObject {
84 /// Note: There are a few rare cases where this method is not called. 84 /// Note: There are a few rare cases where this method is not called.
85 /// 85 ///
86 /// @param os OutputStream to write to 86 /// @param os OutputStream to write to
87 - void writeEnd(PdfStream os) { 87 + void _writeEnd(PdfStream os) {
88 os.putString("endobj\n"); 88 os.putString("endobj\n");
89 } 89 }
90 90
@@ -38,8 +38,8 @@ class PdfObjectStream extends PdfObject { @@ -38,8 +38,8 @@ class PdfObjectStream extends PdfObject {
38 List<int> _data; 38 List<int> _data;
39 39
40 @override 40 @override
41 - void prepare() {  
42 - super.prepare(); 41 + void _prepare() {
  42 + super._prepare();
43 43
44 if (pdfDocument.deflate != null) { 44 if (pdfDocument.deflate != null) {
45 _data = pdfDocument.deflate(buf.output()); 45 _data = pdfDocument.deflate(buf.output());
@@ -57,8 +57,8 @@ class PdfObjectStream extends PdfObject { @@ -57,8 +57,8 @@ class PdfObjectStream extends PdfObject {
57 } 57 }
58 58
59 @override 59 @override
60 - void writeContent(PdfStream os) {  
61 - super.writeContent(os); 60 + void _writeContent(PdfStream os) {
  61 + super._writeContent(os);
62 62
63 os.putString("stream\n"); 63 os.putString("stream\n");
64 os.putBytes(_data); 64 os.putBytes(_data);
@@ -82,8 +82,8 @@ class PdfOutline extends PdfObject { @@ -82,8 +82,8 @@ class PdfOutline extends PdfObject {
82 82
83 /// @param os OutputStream to send the object to 83 /// @param os OutputStream to send the object to
84 @override 84 @override
85 - void prepare() {  
86 - super.prepare(); 85 + void _prepare() {
  86 + super._prepare();
87 87
88 // These are for kids only 88 // These are for kids only
89 if (parent != null) { 89 if (parent != null) {
@@ -49,7 +49,7 @@ class PdfOutput { @@ -49,7 +49,7 @@ class PdfOutput {
49 if (ob is PdfInfo) infoID = ob; 49 if (ob is PdfInfo) infoID = ob;
50 50
51 offsets.add(PdfXref(ob.objser, os.offset)); 51 offsets.add(PdfXref(ob.objser, os.offset));
52 - ob.write(os); 52 + ob._write(os);
53 } 53 }
54 54
55 /// This closes the Stream, writing the xref table 55 /// This closes the Stream, writing the xref table
@@ -76,8 +76,8 @@ class PdfPage extends PdfObject { @@ -76,8 +76,8 @@ class PdfPage extends PdfObject {
76 76
77 /// @param os OutputStream to send the object to 77 /// @param os OutputStream to send the object to
78 @override 78 @override
79 - void prepare() {  
80 - super.prepare(); 79 + void _prepare() {
  80 + super._prepare();
81 81
82 // the /Parent pages object 82 // the /Parent pages object
83 params["/Parent"] = pdfDocument.pdfPageList.ref(); 83 params["/Parent"] = pdfDocument.pdfPageList.ref();
@@ -31,8 +31,8 @@ class PdfPageList extends PdfObject { @@ -31,8 +31,8 @@ class PdfPageList extends PdfObject {
31 PdfPage getPage(int page) => pages[page]; 31 PdfPage getPage(int page) => pages[page];
32 32
33 @override 33 @override
34 - void prepare() {  
35 - super.prepare(); 34 + void _prepare() {
  35 + super._prepare();
36 36
37 params["/Kids"] = PdfStream()..putObjectArray(pages); 37 params["/Kids"] = PdfStream()..putObjectArray(pages);
38 params["/Count"] = PdfStream.intNum(pages.length); 38 params["/Count"] = PdfStream.intNum(pages.length);
@@ -74,8 +74,8 @@ class PdfTtfFont extends PdfFont { @@ -74,8 +74,8 @@ class PdfTtfFont extends PdfFont {
74 } 74 }
75 75
76 @override 76 @override
77 - void prepare() {  
78 - super.prepare(); 77 + void _prepare() {
  78 + super._prepare();
79 79
80 params["/FirstChar"] = PdfStream.intNum(_charMin); 80 params["/FirstChar"] = PdfStream.intNum(_charMin);
81 params["/LastChar"] = PdfStream.intNum(_charMax); 81 params["/LastChar"] = PdfStream.intNum(_charMax);
  1 +import 'dart:io';
  2 +import 'dart:math';
  3 +import 'dart:typed_data';
  4 +
  5 +import 'package:pdf/pdf.dart';
  6 +import 'package:test/test.dart';
  7 +import 'package:vector_math/vector_math_64.dart';
  8 +
  9 +void main() {
  10 + test('Pdf', () {
  11 + var pdf = PdfDocument();
  12 + var page = PdfPage(pdf, pageFormat: const PdfPageFormat(500.0, 300.0));
  13 +
  14 + page.annotations.add(PdfAnnot.annotation(page, "Hello", PdfRect(100.0, 100.0, 50.0, 50.0)));
  15 +
  16 + var file = File('annot.pdf');
  17 + file.writeAsBytesSync(pdf.save());
  18 + });
  19 +}