123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- import 'dart:io';
- import 'dart:ui';
- import 'package:compdfkit_flutter/util/extension/cpdf_color_extension.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import '../document/cpdf_document.dart';
- class CPDFReaderWidgetController {
- late MethodChannel _channel;
- late CPDFDocument _document;
- CPDFReaderWidgetController(int id) {
- _channel = MethodChannel('com.compdfkit.flutter.ui.pdfviewer.$id');
- _channel.setMethodCallHandler((call) async {});
- _document = CPDFDocument(_channel);
- }
-
-
-
-
- Future<bool> save() async {
- return await _channel.invokeMethod('save');
- }
-
-
-
-
-
-
-
- Future<void> setScale(double scale) async {
- await _channel.invokeMethod('set_scale', scale);
- }
-
-
-
-
-
-
- Future<double> getScale() async {
- return await _channel.invokeMethod('get_scale');
- }
-
-
-
-
-
-
-
- Future<void> setCanScale(bool canScale) async {
- await _channel.invokeMethod('set_can_scale', canScale);
- }
-
-
-
-
-
-
-
- Future<void> setReadBackgroundColor(Color color) async {
- await _channel.invokeMethod('set_read_background_color', color.toHex());
- }
-
-
-
-
-
-
- Future<Color> getReadBackgroundColor() async {
- String hexColor = await _channel.invokeMethod('get_read_background_color');
- return HexColor.fromHex(hexColor);
- }
-
-
-
-
-
-
-
- Future<void> setFormFieldHighlight(bool isFormFieldHighlight) async {
- await _channel.invokeMethod(
- 'set_form_field_highlight', isFormFieldHighlight);
- }
-
-
-
-
-
-
- Future<bool> isFormFieldHighlight() async {
- return await _channel.invokeMethod('is_form_field_highlight');
- }
-
-
-
-
-
-
-
-
- Future<void> setLinkHighlight(bool isLinkHighlight) async {
- await _channel.invokeMethod('set_link_highlight', isLinkHighlight);
- }
-
-
-
-
-
-
- Future<bool> isLinkHighlight() async {
- return await _channel.invokeMethod('is_link_highlight');
- }
-
-
-
-
-
-
-
-
- Future<void> setVerticalMode(bool isVerticalMode) async {
- await _channel.invokeMethod('set_vertical_mode', isVerticalMode);
- }
-
-
-
-
-
-
- Future<bool> isVerticalMode() async {
- return await _channel.invokeMethod('is_vertical_mode');
- }
-
-
-
-
-
-
-
-
- Future<void> setPageSpacing(int spacing) async {
- await _channel.invokeMethod('set_page_spacing', spacing);
- }
-
-
-
-
-
-
-
-
- Future<void> setContinueMode(bool isContinueMode) async {
- await _channel.invokeMethod('set_continue_mode', isContinueMode);
- }
-
-
-
-
-
-
- Future<bool> isContinueMode() async {
- return await _channel.invokeMethod('is_continue_mode');
- }
-
-
-
-
-
-
-
-
- Future<void> setDoublePageMode(bool isDoublePageMode) async {
- await _channel.invokeMethod('set_double_page_mode', isDoublePageMode);
- }
-
-
-
-
-
-
- Future<bool> isDoublePageMode() async {
- return await _channel.invokeMethod('is_double_page_mode');
- }
-
-
-
-
-
-
- Future<void> setCoverPageMode(bool coverPageMode) async {
- await _channel.invokeMethod('set_cover_page_mode', coverPageMode);
- }
-
-
-
-
-
-
- Future<bool> isCoverPageMode() async {
- return await _channel.invokeMethod('is_cover_page_mode');
- }
-
-
-
-
-
-
-
-
- Future<void> setCropMode(bool isCropMode) async {
- await _channel.invokeMethod('set_crop_mode', isCropMode);
- }
-
-
-
-
-
-
- Future<bool> isCropMode() async {
- return await _channel.invokeMethod('is_crop_mode');
- }
-
-
-
-
-
-
-
-
-
- Future<void> setDisplayPageIndex(int pageIndex,
- {bool isRecordLastJumpPageNum = true}) async {
- await _channel.invokeMethod('set_display_page_index', {
- 'pageIndex': pageIndex,
- 'isRecordLastJumpPageNum': isRecordLastJumpPageNum
- });
- }
-
-
-
-
-
-
- Future<int> getCurrentPageIndex() async {
- return await _channel.invokeMethod('get_current_page_index');
- }
-
-
-
-
-
-
-
-
- Future<void> setPageSameWidth(bool isSame) async {
- assert(Platform.isAndroid, 'This method is only supported on Android');
- await _channel.invokeMethod('set_page_same_width', isSame);
- }
-
-
-
-
-
-
- Future<bool> isPageInScreen(int pageIndex) async {
- return await _channel.invokeMethod('is_page_in_screen', pageIndex);
- }
-
-
-
-
- Future<void> setFixedScroll(bool isFixedScroll) async {
- await _channel.invokeMethod('set_fixed_scroll', isFixedScroll);
- }
-
-
-
-
-
-
-
- Future<Size> getPageSize(int pageIndex, {bool noZoom = true}) async {
- final Map<String, double>? pageSizeMap = await _channel.invokeMapMethod(
- 'get_page_size', {'pageIndex': pageIndex, 'noZoom': noZoom});
- if (pageSizeMap == null) {
- throw Exception('Failed to get page size');
- }
- final double width = pageSizeMap['width'] ?? 0;
- final double height = pageSizeMap['height'] ?? 0;
- return Size(width, height);
- }
- }
|