|
@@ -1,67 +1,95 @@
|
|
|
package com.compdfkitpdf.reactnative.util.annotation;
|
|
|
|
|
|
-import android.hardware.lights.LightState;
|
|
|
-import com.compdfkit.core.annotation.CPDFAnnotation;
|
|
|
import com.compdfkit.core.annotation.CPDFAnnotation.Type;
|
|
|
+import com.compdfkit.core.annotation.form.CPDFWidget.WidgetType;
|
|
|
import com.compdfkit.core.page.CPDFPage;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFBaseForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFCheckBoxForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFComboBoxForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFListBoxForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFRadioButtonForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFSignatureFieldsForms;
|
|
|
+import com.compdfkitpdf.reactnative.util.annotation.forms.RCPDFTextFieldForms;
|
|
|
import com.facebook.react.bridge.Arguments;
|
|
|
import com.facebook.react.bridge.WritableArray;
|
|
|
-import com.facebook.react.bridge.WritableMap;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
-/**
|
|
|
- * @classname:
|
|
|
- * @author: LiuXiaoLong
|
|
|
- * @date: 2025/3/3 description:
|
|
|
- */
|
|
|
public class RCPDFAnnotFactory {
|
|
|
|
|
|
-
|
|
|
private CPDFPage cpdfPage;
|
|
|
|
|
|
HashMap<Type, RCPDFAnnotation> annotImpls = new HashMap<>();
|
|
|
+ HashMap<WidgetType, RCPDFForms> formImpls = new HashMap<>();
|
|
|
|
|
|
public RCPDFAnnotFactory(CPDFPage cpdfPage) {
|
|
|
this.cpdfPage = cpdfPage;
|
|
|
annotImpls = getAnnotImpls();
|
|
|
+ formImpls = getFormImpls();
|
|
|
}
|
|
|
|
|
|
- public WritableArray getAnnotations(CPDFAnnotation.Type type){
|
|
|
- RCPDFAnnotation annotImpl = annotImpls.get(type);
|
|
|
- if (annotImpl != null){
|
|
|
- return annotImpl.getAnnotation(type);
|
|
|
- }
|
|
|
- return Arguments.createArray();
|
|
|
+ private HashMap<Type, RCPDFAnnotation> getAnnotImpls(){
|
|
|
+ HashMap<Type, RCPDFAnnotation> map = new HashMap<>();
|
|
|
+ RCPDFMarkupAnnotation markupAnnotation = new RCPDFMarkupAnnotation(cpdfPage);
|
|
|
+ map.put(Type.TEXT, new RCPDFNoteAnnotation(cpdfPage));
|
|
|
+ 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.CIRCLE, markupAnnotation);
|
|
|
+ map.put(Type.SQUARE, markupAnnotation);
|
|
|
+ map.put(Type.LINE, markupAnnotation);
|
|
|
+ map.put(Type.STAMP, markupAnnotation);
|
|
|
+ map.put(Type.FREETEXT, markupAnnotation);
|
|
|
+ map.put(Type.SOUND, markupAnnotation);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HashMap<WidgetType, RCPDFForms> getFormImpls(){
|
|
|
+ HashMap<WidgetType, RCPDFForms> map = new HashMap<>();
|
|
|
+ map.put(WidgetType.Widget_TextField, new RCPDFTextFieldForms(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_ListBox, new RCPDFListBoxForms(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_ComboBox, new RCPDFComboBoxForms(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_RadioButton, new RCPDFRadioButtonForms(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_CheckBox, new RCPDFCheckBoxForms(cpdfPage));
|
|
|
+ map.put(WidgetType.Widget_SignatureFields, new RCPDFSignatureFieldsForms(cpdfPage));
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
public WritableArray getAnnotations(){
|
|
|
WritableArray array = Arguments.createArray();
|
|
|
- RCPDFMarkupAnnotation markupAnnotation = new RCPDFMarkupAnnotation(cpdfPage);
|
|
|
for (Type type : annotImpls.keySet()) {
|
|
|
-
|
|
|
+ RCPDFAnnotation rcpdfAnnotation = annotImpls.get(type);
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return array;
|
|
|
}
|
|
|
|
|
|
- private List<RCPDFAnnotation> getAnnotImpl(Type type){
|
|
|
- return Arrays.asList(
|
|
|
- new RCPDFMarkupAnnotation(cpdfPage)
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- private HashMap<Type, RCPDFAnnotation> getAnnotImpls(){
|
|
|
- HashMap<Type, RCPDFAnnotation> map = new HashMap<>();
|
|
|
- RCPDFMarkupAnnotation markupAnnotation = new RCPDFMarkupAnnotation(cpdfPage);
|
|
|
- map.put(Type.HIGHLIGHT, markupAnnotation);
|
|
|
- map.put(Type.UNDERLINE, markupAnnotation);
|
|
|
- map.put(Type.SQUIGGLY, markupAnnotation);
|
|
|
- map.put(Type.STRIKEOUT, markupAnnotation);
|
|
|
- return map;
|
|
|
+ public WritableArray getForms(){
|
|
|
+ WritableArray array = Arguments.createArray();
|
|
|
+ for (WidgetType widgetType : formImpls.keySet()) {
|
|
|
+ RCPDFForms rcpdfForms = formImpls.get(widgetType);
|
|
|
+ if (rcpdfForms != null){
|
|
|
+ WritableArray writableArray = rcpdfForms.getForm(widgetType);
|
|
|
+ if (writableArray != null && writableArray.size() > 0){
|
|
|
+ for (int i = 0; i < writableArray.size(); i++) {
|
|
|
+ array.pushMap(writableArray.getMap(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return array;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|