1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MEDIAPROVIDER_PDF_JNI_CONVERSION_H_ 18 #define MEDIAPROVIDER_PDF_JNI_CONVERSION_H_ 19 20 #include <jni.h> 21 22 #include <vector> 23 24 #include "document.h" 25 #include "file.h" 26 #include "form_widget_info.h" 27 #include "page.h" 28 #include "rect.h" 29 30 using pdfClient::Document; 31 using pdfClient::FormWidgetInfo; 32 using pdfClient::GotoLink; 33 using pdfClient::GotoLinkDest; 34 using pdfClient::Option; 35 using pdfClient::Rectangle_i; 36 using pdfClient::SelectionBoundary; 37 using pdfClient::Status; 38 using std::vector; 39 40 namespace convert { 41 42 // Creates a Java PdfDocument object to wrap this Document instance. 43 jobject ToJavaPdfDocument(JNIEnv* env, const Document* doc); 44 45 // Creates a Java LoadPdfResult object using c++ objects status, Document and size of the pdf. 46 jobject ToJavaLoadPdfResult(JNIEnv* env, const Status status, std::unique_ptr<Document> doc, 47 size_t pdfSizeInByte); 48 49 // Gets the PDF document pointer from the PdfDocument java object. 50 Document* GetPdfDocPtr(JNIEnv* env, jobject jPdfDocument); 51 52 // Convert a Java SelectionBoundary to a C++ SelectionBoundary. 53 SelectionBoundary ToNativeBoundary(JNIEnv* env, jobject jBoundary); 54 55 // Convert a Java Integer to an C++ int. 56 int ToNativeInteger(JNIEnv* env, jobject jInteger); 57 58 // Convert a Java List<Integer> to C++ vector<int>. 59 vector<int> ToNativeIntegerVector(JNIEnv* env, jintArray jintArray); 60 61 // Convert a Java Set<Integer> to C++ std::unordered_set<int>. 62 std::unordered_set<int> ToNativeIntegerUnorderedSet(JNIEnv* env, jintArray jintArray); 63 64 // Convert a pdfClient rectangle to an android.graphics.Rect. 65 jobject ToJavaRect(JNIEnv* env, const Rectangle_i& r); 66 67 // Convert a vector of pdfClient Rectangle_i to List<android.graphics.Rect>. 68 jobject ToJavaRects(JNIEnv* env, const vector<Rectangle_i>& rects); 69 70 // Convert a pdfClient rectangle to a projector Dimensions. 71 jobject ToJavaDimensions(JNIEnv* env, const Rectangle_i& r); 72 73 // Convert the vector of UTF-8 strings into a List<String>. 74 jobject ToJavaStrings(JNIEnv* env, const std::vector<std::string>& strings); 75 76 // Convert the vector of pdfClient rectangles into a projector MatchRects. 77 jobject ToJavaMatchRects(JNIEnv* env, const std::vector<Rectangle_i>& rects, 78 const vector<int>& match_to_rect, const vector<int>& char_indexes); 79 80 // Convert a C++ SelectionBoundary to Java Selection$Boundary. 81 jobject ToJavaBoundary(JNIEnv* env, const SelectionBoundary& boundary); 82 83 // Convert the boundaries and vector of rectangles to a projector Selection. 84 jobject ToJavaSelection(JNIEnv* env, const int page, const SelectionBoundary& start, 85 const SelectionBoundary& stop, const vector<Rectangle_i>& rects, 86 const std::string& text); 87 88 // Convert the vector of pdfClient rectangles into a projector LinkRects. 89 jobject ToJavaLinkRects(JNIEnv* env, const std::vector<Rectangle_i>& rects, 90 const vector<int>& link_to_rect, const vector<std::string>& urls); 91 92 // Convert the pdfClient::Option into a projector ChoiceOption. 93 jobject ToJavaChoiceOption(JNIEnv* env, const Option& option); 94 95 // Obtain a projector WidgetOption value for the widgetType id. 96 jobject ToJavaWidgetType(JNIEnv* env, int widgetType); 97 98 // Convert the pdfClient::FormWidgetInfo into a projector FormWidgetInfo. 99 jobject ToJavaFormWidgetInfo(JNIEnv* env, const FormWidgetInfo& form_action_result); 100 101 // Convert a vector<pdfClient::FormWidgetInfo> into a Java List of projector 102 // FormWidgetInfo. 103 jobject ToJavaFormWidgetInfos(JNIEnv* env, const std::vector<FormWidgetInfo>& widget_infos); 104 105 jobject ToJavaDestination(JNIEnv* env, const GotoLinkDest dest); 106 107 jobject ToJavaGotoLink(JNIEnv* env, const GotoLink link); 108 109 jobject ToJavaGotoLinks(JNIEnv* env, const vector<GotoLink>& links); 110 111 } // namespace convert 112 113 #endif // MEDIAPROVIDER_PDF_JNI_CONVERSION_H_