|
@@ -1,6 +1,8 @@
|
|
|
package com.compdfkitpdf.reactnative.util.annotation;
|
|
|
|
|
|
+import com.compdfkit.core.annotation.CPDFAnnotation;
|
|
|
import com.compdfkit.core.annotation.CPDFAnnotation.Type;
|
|
|
+import com.compdfkit.core.annotation.form.CPDFWidget;
|
|
|
import com.compdfkit.core.annotation.form.CPDFWidget.WidgetType;
|
|
|
import com.compdfkit.core.page.CPDFPage;
|
|
|
import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFCheckBoxWidget;
|
|
@@ -13,33 +15,38 @@ import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFSignatureFieldsWi
|
|
|
import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFTextFieldWidget;
|
|
|
import com.facebook.react.bridge.Arguments;
|
|
|
import com.facebook.react.bridge.WritableArray;
|
|
|
+import com.facebook.react.bridge.WritableMap;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class RCPDFAnnotFactory {
|
|
|
|
|
|
private CPDFPage cpdfPage;
|
|
|
|
|
|
+ private List<CPDFAnnotation> cachedAnnotations;
|
|
|
+
|
|
|
HashMap<Type, RCPDFAnnotation> annotImpls = new HashMap<>();
|
|
|
HashMap<WidgetType, RCPDFWidget> widgetsImpls = new HashMap<>();
|
|
|
|
|
|
public RCPDFAnnotFactory(CPDFPage cpdfPage) {
|
|
|
this.cpdfPage = cpdfPage;
|
|
|
+ cachedAnnotations = cpdfPage.getAnnotations();
|
|
|
annotImpls = createAnnotationImpl();
|
|
|
widgetsImpls = getWidgetsImpl();
|
|
|
}
|
|
|
|
|
|
private HashMap<Type, RCPDFAnnotation> createAnnotationImpl(){
|
|
|
HashMap<Type, RCPDFAnnotation> map = new HashMap<>();
|
|
|
- RCPDFMarkupAnnotation markupAnnotation = new RCPDFMarkupAnnotation(cpdfPage);
|
|
|
- map.put(Type.TEXT, new RCPDFNoteAnnotation(cpdfPage));
|
|
|
+ RCPDFMarkupAnnotation markupAnnotation = new RCPDFMarkupAnnotation();
|
|
|
+ map.put(Type.TEXT, new RCPDFNoteAnnotation());
|
|
|
map.put(Type.HIGHLIGHT, markupAnnotation);
|
|
|
map.put(Type.UNDERLINE, markupAnnotation);
|
|
|
map.put(Type.SQUIGGLY, markupAnnotation);
|
|
|
map.put(Type.STRIKEOUT, markupAnnotation);
|
|
|
- map.put(Type.INK, new RCPDFInkAnnotation(cpdfPage));
|
|
|
+ map.put(Type.INK, new RCPDFInkAnnotation());
|
|
|
map.put(Type.CIRCLE, markupAnnotation);
|
|
|
map.put(Type.SQUARE, markupAnnotation);
|
|
|
- map.put(Type.LINE, markupAnnotation);
|
|
|
+ map.put(Type.LINE, new RCPDFLineAnnotation());
|
|
|
map.put(Type.STAMP, markupAnnotation);
|
|
|
map.put(Type.FREETEXT, markupAnnotation);
|
|
|
map.put(Type.SOUND, markupAnnotation);
|
|
@@ -48,26 +55,27 @@ public class RCPDFAnnotFactory {
|
|
|
|
|
|
private HashMap<WidgetType, RCPDFWidget> getWidgetsImpl(){
|
|
|
HashMap<WidgetType, RCPDFWidget> map = new HashMap<>();
|
|
|
- map.put(WidgetType.Widget_TextField, new RCPDFTextFieldWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_ListBox, new RCPDFListBoxWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_ComboBox, new RCPDFComboBoxWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_RadioButton, new RCPDFRadioButtonWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_CheckBox, new RCPDFCheckBoxWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_SignatureFields, new RCPDFSignatureFieldsWidget(cpdfPage));
|
|
|
- map.put(WidgetType.Widget_PushButton, new RCPDFPushbuttonWidget(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_TextField, new RCPDFTextFieldWidget());
|
|
|
+ map.put(WidgetType.Widget_ListBox, new RCPDFListBoxWidget());
|
|
|
+ map.put(WidgetType.Widget_ComboBox, new RCPDFComboBoxWidget());
|
|
|
+ map.put(WidgetType.Widget_RadioButton, new RCPDFRadioButtonWidget());
|
|
|
+ map.put(WidgetType.Widget_CheckBox, new RCPDFCheckBoxWidget());
|
|
|
+ map.put(WidgetType.Widget_SignatureFields, new RCPDFSignatureFieldsWidget());
|
|
|
+ map.put(WidgetType.Widget_PushButton, new RCPDFPushbuttonWidget());
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
public WritableArray getAnnotations(){
|
|
|
+ if (cachedAnnotations == null || !cpdfPage.isValid()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
WritableArray array = Arguments.createArray();
|
|
|
- for (Type type : annotImpls.keySet()) {
|
|
|
- RCPDFAnnotation rcpdfAnnotation = annotImpls.get(type);
|
|
|
+ for (CPDFAnnotation annotation : cachedAnnotations) {
|
|
|
+ RCPDFAnnotation rcpdfAnnotation = annotImpls.get(annotation.getType());
|
|
|
if (rcpdfAnnotation != null){
|
|
|
- WritableArray writableArray = rcpdfAnnotation.getAnnotation(type);
|
|
|
- if (writableArray != null && writableArray.size() > 0){
|
|
|
- for (int i = 0; i < writableArray.size(); i++) {
|
|
|
- array.pushMap(writableArray.getMap(i));
|
|
|
- }
|
|
|
+ WritableMap map = rcpdfAnnotation.getAnnotation(annotation);
|
|
|
+ if (map != null){
|
|
|
+ array.pushMap(map);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -76,15 +84,20 @@ public class RCPDFAnnotFactory {
|
|
|
|
|
|
|
|
|
public WritableArray getWidgets(){
|
|
|
+ if (cachedAnnotations == null || !cpdfPage.isValid()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
WritableArray array = Arguments.createArray();
|
|
|
- for (WidgetType widgetType : widgetsImpls.keySet()) {
|
|
|
- RCPDFWidget rcpdfWidget = widgetsImpls.get(widgetType);
|
|
|
+ for (CPDFAnnotation annotation : cachedAnnotations) {
|
|
|
+ if (annotation.getType() != Type.WIDGET){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ CPDFWidget widget = (CPDFWidget) annotation;
|
|
|
+ RCPDFWidget rcpdfWidget = widgetsImpls.get(widget.getWidgetType());
|
|
|
if (rcpdfWidget != null){
|
|
|
- WritableArray writableArray = rcpdfWidget.getWidget(widgetType);
|
|
|
- if (writableArray != null && writableArray.size() > 0){
|
|
|
- for (int i = 0; i < writableArray.size(); i++) {
|
|
|
- array.pushMap(writableArray.getMap(i));
|
|
|
- }
|
|
|
+ WritableMap writableMap = rcpdfWidget.getWidget(annotation);
|
|
|
+ if (writableMap != null){
|
|
|
+ array.pushMap(writableMap);
|
|
|
}
|
|
|
}
|
|
|
}
|