From d122ef719fd57367c04a6e8d1c958e2d4d3e924c Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 13 May 2024 17:06:05 -0300 Subject: [PATCH 01/13] chore: Add initialFocalLatLng property to MapZoomPanBehavior --- packages/syncfusion_flutter_maps/lib/maps.dart | 15 +++++++++++++++ .../lib/src/elements/toolbar.dart | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/syncfusion_flutter_maps/lib/maps.dart b/packages/syncfusion_flutter_maps/lib/maps.dart index 051647e6a..d29ad0400 100644 --- a/packages/syncfusion_flutter_maps/lib/maps.dart +++ b/packages/syncfusion_flutter_maps/lib/maps.dart @@ -2344,6 +2344,7 @@ class MapZoomPanBehavior extends MapBehavior { MapToolbarSettings toolbarSettings = const MapToolbarSettings(), }) : _zoomLevel = zoomLevel.clamp(minZoomLevel, maxZoomLevel), _focalLatLng = focalLatLng, + _initialFocalLatLng = focalLatLng, _latLngBounds = latLngBounds, _minZoomLevel = minZoomLevel, _maxZoomLevel = maxZoomLevel, @@ -2416,6 +2417,20 @@ class MapZoomPanBehavior extends MapBehavior { } } + /// Specifies the initial focal latitude and longitude position. + /// This is used to reset the focalLatLng to the initial position + /// when pressing the reset button of the toolbar. + MapLatLng? get initialFocalLatLng => _initialFocalLatLng; + MapLatLng? _initialFocalLatLng; + set initialFocalLatLng(MapLatLng? value) { + if (_initialFocalLatLng == value) { + return; + } + + _initialFocalLatLng = value; + focalLatLng = value; + } + /// Specifies the current latlng bounds of the maps. The maps zoom level /// and focalLatLng get updated based on the given bounds. /// diff --git a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart index 5ea59e82a..ffcb259cd 100644 --- a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart +++ b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart @@ -131,7 +131,9 @@ class _ToolbarItemState extends State<_ToolbarItem> { break; case _ToolbarIcon.reset: enabled = widget.zoomPanBehavior.zoomLevel != - widget.zoomPanBehavior.minZoomLevel; + widget.zoomPanBehavior.minZoomLevel || + widget.zoomPanBehavior.focalLatLng != + widget.zoomPanBehavior.initialFocalLatLng; break; } @@ -250,6 +252,7 @@ class _ToolbarItemState extends State<_ToolbarItem> { void _handlePointerUp() { double newZoomLevel; + MapLatLng? newFocalLatLng; switch (widget.icon) { case _ToolbarIcon.zoomIn: newZoomLevel = widget.zoomPanBehavior.zoomLevel + _increment; @@ -259,6 +262,7 @@ class _ToolbarItemState extends State<_ToolbarItem> { break; case _ToolbarIcon.reset: newZoomLevel = widget.zoomPanBehavior.minZoomLevel; + newFocalLatLng = widget.zoomPanBehavior.initialFocalLatLng; break; } @@ -267,6 +271,9 @@ class _ToolbarItemState extends State<_ToolbarItem> { if (widget.controller != null && newZoomLevel != widget.zoomPanBehavior.zoomLevel) { widget.controller!.notifyToolbarZoomedListeners(newZoomLevel); + if (newFocalLatLng != null) { + widget.zoomPanBehavior.focalLatLng = newFocalLatLng; + } } } } From 7f90a493803fc9dd8938f591c04d1ee4a57d0939 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 13 May 2024 17:08:48 -0300 Subject: [PATCH 02/13] chore: Update syncfusion_flutter_core dependency to version 25.2.3 --- packages/syncfusion_flutter_maps/pubspec.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 291eee25c..40ea080e5 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -10,8 +10,7 @@ dependencies: flutter: sdk: flutter - syncfusion_flutter_core: - path: ../syncfusion_flutter_core + syncfusion_flutter_core: ^25.2.3 http: ^1.0.0 vector_math: ">=2.1.0 <=3.0.0" From 916d288d44094ff319114dd750043386241fb343 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 13 May 2024 17:09:01 -0300 Subject: [PATCH 03/13] chore: Bump syncfusion_flutter_maps version to 24.2.10 --- packages/syncfusion_flutter_maps/pubspec.lock | 227 ++++++++++++++++++ packages/syncfusion_flutter_maps/pubspec.yaml | 2 +- .../.plugin_symlinks/path_provider_linux | 1 + .../ephemeral/Flutter-Generated.xcconfig | 11 + .../ephemeral/flutter_export_environment.sh | 12 + .../.plugin_symlinks/path_provider_windows | 1 + .../.plugin_symlinks/path_provider_linux | 1 + .../ephemeral/Flutter-Generated.xcconfig | 11 + .../ephemeral/flutter_export_environment.sh | 12 + .../.plugin_symlinks/path_provider_windows | 1 + .../.plugin_symlinks/device_info_plus | 1 + .../syncfusion_pdfviewer_windows | 1 + .../.plugin_symlinks/url_launcher_windows | 1 + 13 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 packages/syncfusion_flutter_maps/pubspec.lock create mode 120000 packages/syncfusion_officechart/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux create mode 100644 packages/syncfusion_officechart/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig create mode 100755 packages/syncfusion_officechart/example/macos/Flutter/ephemeral/flutter_export_environment.sh create mode 120000 packages/syncfusion_officechart/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows create mode 120000 packages/syncfusion_officecore/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux create mode 100644 packages/syncfusion_officecore/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig create mode 100755 packages/syncfusion_officecore/example/macos/Flutter/ephemeral/flutter_export_environment.sh create mode 120000 packages/syncfusion_officecore/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows create mode 120000 packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/device_info_plus create mode 120000 packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/syncfusion_pdfviewer_windows create mode 120000 packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows diff --git a/packages/syncfusion_flutter_maps/pubspec.lock b/packages/syncfusion_flutter_maps/pubspec.lock new file mode 100644 index 000000000..c3d005f5a --- /dev/null +++ b/packages/syncfusion_flutter_maps/pubspec.lock @@ -0,0 +1,227 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + http: + dependency: "direct main" + description: + name: http + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: transitive + description: + name: meta + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + url: "https://pub.dev" + source: hosted + version: "1.11.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + syncfusion_flutter_core: + dependency: "direct main" + description: + path: "../syncfusion_flutter_core" + relative: true + source: path + version: "24.2.7" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" + source: hosted + version: "0.6.1" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" +sdks: + dart: ">=3.3.0 <4.0.0" diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 40ea080e5..4236b426c 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -1,6 +1,6 @@ name: syncfusion_flutter_maps description: A Flutter Maps library for creating beautiful, interactive, and customizable maps from shape files or WMTS services to visualize the geographical area. -version: 24.2.9 +version: 24.2.10 homepage: https://github.com/syncfusion/flutter-widgets/tree/master/packages/syncfusion_flutter_maps environment: diff --git a/packages/syncfusion_officechart/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux b/packages/syncfusion_officechart/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux new file mode 120000 index 000000000..b388bcb85 --- /dev/null +++ b/packages/syncfusion_officechart/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/ \ No newline at end of file diff --git a/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig b/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig new file mode 100644 index 000000000..2999e8674 --- /dev/null +++ b/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig @@ -0,0 +1,11 @@ +// This is a generated file; do not edit or check into version control. +FLUTTER_ROOT=/Users/lucaspolazzo/fvm/versions/3.13.3 +FLUTTER_APPLICATION_PATH=/Users/lucaspolazzo/dev/projects/flutter/plugins/flutter-widgets/packages/syncfusion_officechart/example +COCOAPODS_PARALLEL_CODE_SIGN=true +FLUTTER_BUILD_DIR=build +FLUTTER_BUILD_NAME=1.0.0 +FLUTTER_BUILD_NUMBER=1 +DART_OBFUSCATION=false +TRACK_WIDGET_CREATION=true +TREE_SHAKE_ICONS=false +PACKAGE_CONFIG=.dart_tool/package_config.json diff --git a/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/flutter_export_environment.sh b/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/flutter_export_environment.sh new file mode 100755 index 000000000..ec53d2d54 --- /dev/null +++ b/packages/syncfusion_officechart/example/macos/Flutter/ephemeral/flutter_export_environment.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/lucaspolazzo/fvm/versions/3.13.3" +export "FLUTTER_APPLICATION_PATH=/Users/lucaspolazzo/dev/projects/flutter/plugins/flutter-widgets/packages/syncfusion_officechart/example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_BUILD_DIR=build" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.dart_tool/package_config.json" diff --git a/packages/syncfusion_officechart/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows b/packages/syncfusion_officechart/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows new file mode 120000 index 000000000..87c3ace05 --- /dev/null +++ b/packages/syncfusion_officechart/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/ \ No newline at end of file diff --git a/packages/syncfusion_officecore/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux b/packages/syncfusion_officecore/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux new file mode 120000 index 000000000..b388bcb85 --- /dev/null +++ b/packages/syncfusion_officecore/example/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/ \ No newline at end of file diff --git a/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig b/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig new file mode 100644 index 000000000..6c8617cc6 --- /dev/null +++ b/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig @@ -0,0 +1,11 @@ +// This is a generated file; do not edit or check into version control. +FLUTTER_ROOT=/Users/lucaspolazzo/fvm/versions/3.13.3 +FLUTTER_APPLICATION_PATH=/Users/lucaspolazzo/dev/projects/flutter/plugins/flutter-widgets/packages/syncfusion_officecore/example +COCOAPODS_PARALLEL_CODE_SIGN=true +FLUTTER_BUILD_DIR=build +FLUTTER_BUILD_NAME=1.0.0 +FLUTTER_BUILD_NUMBER=1 +DART_OBFUSCATION=false +TRACK_WIDGET_CREATION=true +TREE_SHAKE_ICONS=false +PACKAGE_CONFIG=.dart_tool/package_config.json diff --git a/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/flutter_export_environment.sh b/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/flutter_export_environment.sh new file mode 100755 index 000000000..438f82a37 --- /dev/null +++ b/packages/syncfusion_officecore/example/macos/Flutter/ephemeral/flutter_export_environment.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/lucaspolazzo/fvm/versions/3.13.3" +export "FLUTTER_APPLICATION_PATH=/Users/lucaspolazzo/dev/projects/flutter/plugins/flutter-widgets/packages/syncfusion_officecore/example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_BUILD_DIR=build" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.dart_tool/package_config.json" diff --git a/packages/syncfusion_officecore/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows b/packages/syncfusion_officecore/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows new file mode 120000 index 000000000..87c3ace05 --- /dev/null +++ b/packages/syncfusion_officecore/example/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/ \ No newline at end of file diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/device_info_plus b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/device_info_plus new file mode 120000 index 000000000..caf249986 --- /dev/null +++ b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/device_info_plus @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/device_info_plus-8.2.2/ \ No newline at end of file diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/syncfusion_pdfviewer_windows b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/syncfusion_pdfviewer_windows new file mode 120000 index 000000000..74cd38501 --- /dev/null +++ b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/syncfusion_pdfviewer_windows @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/syncfusion_pdfviewer_windows-21.2.10/ \ No newline at end of file diff --git a/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows new file mode 120000 index 000000000..efb082b6e --- /dev/null +++ b/packages/syncfusion_pdfviewer_platform_interface/example/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows @@ -0,0 +1 @@ +/Users/lucaspolazzo/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.8/ \ No newline at end of file From ffc7675a35471dedf0889b48330e7931d10e388c Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 13 May 2024 17:12:33 -0300 Subject: [PATCH 04/13] Fixed reset button initial lat lng --- packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart | 3 ++- packages/syncfusion_flutter_maps/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart index ffcb259cd..892d140d5 100644 --- a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart +++ b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart @@ -269,7 +269,8 @@ class _ToolbarItemState extends State<_ToolbarItem> { newZoomLevel = newZoomLevel.clamp(widget.zoomPanBehavior.minZoomLevel, widget.zoomPanBehavior.maxZoomLevel); if (widget.controller != null && - newZoomLevel != widget.zoomPanBehavior.zoomLevel) { + (newZoomLevel != widget.zoomPanBehavior.zoomLevel || + newFocalLatLng != null)) { widget.controller!.notifyToolbarZoomedListeners(newZoomLevel); if (newFocalLatLng != null) { widget.zoomPanBehavior.focalLatLng = newFocalLatLng; diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 4236b426c..6d2e9689c 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -1,6 +1,6 @@ name: syncfusion_flutter_maps description: A Flutter Maps library for creating beautiful, interactive, and customizable maps from shape files or WMTS services to visualize the geographical area. -version: 24.2.10 +version: 24.2.11 homepage: https://github.com/syncfusion/flutter-widgets/tree/master/packages/syncfusion_flutter_maps environment: From e511752e44cc7bd1c83ac5a021fa5198c32905b0 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 13 May 2024 17:23:05 -0300 Subject: [PATCH 05/13] chore: Add initialZoomLevel property to MapZoomPanBehavior --- packages/syncfusion_flutter_maps/lib/maps.dart | 13 +++++++++++++ .../lib/src/elements/toolbar.dart | 6 ++++-- packages/syncfusion_flutter_maps/pubspec.yaml | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/syncfusion_flutter_maps/lib/maps.dart b/packages/syncfusion_flutter_maps/lib/maps.dart index d29ad0400..26b2ce592 100644 --- a/packages/syncfusion_flutter_maps/lib/maps.dart +++ b/packages/syncfusion_flutter_maps/lib/maps.dart @@ -2343,6 +2343,7 @@ class MapZoomPanBehavior extends MapBehavior { bool showToolbar = true, MapToolbarSettings toolbarSettings = const MapToolbarSettings(), }) : _zoomLevel = zoomLevel.clamp(minZoomLevel, maxZoomLevel), + _initialZoomLevel = zoomLevel.clamp(minZoomLevel, maxZoomLevel), _focalLatLng = focalLatLng, _initialFocalLatLng = focalLatLng, _latLngBounds = latLngBounds, @@ -2431,6 +2432,18 @@ class MapZoomPanBehavior extends MapBehavior { focalLatLng = value; } + /// Specifies the initial zoom level to be setted when pressing the reset + double? get initialZoomLevel => _initialZoomLevel; + double? _initialZoomLevel; + set initialZoomLevel(double? value) { + if (_initialZoomLevel == value) { + return; + } + + _initialZoomLevel = value; + zoomLevel = value!; + } + /// Specifies the current latlng bounds of the maps. The maps zoom level /// and focalLatLng get updated based on the given bounds. /// diff --git a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart index 892d140d5..703bb367a 100644 --- a/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart +++ b/packages/syncfusion_flutter_maps/lib/src/elements/toolbar.dart @@ -131,7 +131,8 @@ class _ToolbarItemState extends State<_ToolbarItem> { break; case _ToolbarIcon.reset: enabled = widget.zoomPanBehavior.zoomLevel != - widget.zoomPanBehavior.minZoomLevel || + (widget.zoomPanBehavior.initialZoomLevel ?? + widget.zoomPanBehavior.minZoomLevel) || widget.zoomPanBehavior.focalLatLng != widget.zoomPanBehavior.initialFocalLatLng; break; @@ -261,7 +262,8 @@ class _ToolbarItemState extends State<_ToolbarItem> { newZoomLevel = widget.zoomPanBehavior.zoomLevel - _increment; break; case _ToolbarIcon.reset: - newZoomLevel = widget.zoomPanBehavior.minZoomLevel; + newZoomLevel = widget.zoomPanBehavior.initialZoomLevel ?? + widget.zoomPanBehavior.minZoomLevel; newFocalLatLng = widget.zoomPanBehavior.initialFocalLatLng; break; } diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 6d2e9689c..6a71fb183 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -1,6 +1,6 @@ name: syncfusion_flutter_maps description: A Flutter Maps library for creating beautiful, interactive, and customizable maps from shape files or WMTS services to visualize the geographical area. -version: 24.2.11 +version: 24.2.12 homepage: https://github.com/syncfusion/flutter-widgets/tree/master/packages/syncfusion_flutter_maps environment: From 5f5af9c7b2f846945fc7d2b9588d9e15760e00f8 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Tue, 2 Jul 2024 00:38:53 -0300 Subject: [PATCH 06/13] Added minY/maxY to SparkLine graph --- .gitignore | 3 +- .../sparkline/renderers/renderer_base.dart | 105 ++++----- .../renderers/spark_line_renderer.dart | 87 ++++---- .../src/sparkline/series/spark_line_base.dart | 16 +- .../syncfusion_flutter_charts/pubspec.lock | 204 ++++++++++++++++++ .../syncfusion_flutter_charts/pubspec.yaml | 3 +- packages/syncfusion_flutter_maps/pubspec.yaml | 2 +- 7 files changed, 311 insertions(+), 109 deletions(-) create mode 100644 packages/syncfusion_flutter_charts/pubspec.lock diff --git a/.gitignore b/.gitignore index 0cdd19f1d..98c26ac90 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,5 @@ svc-keyfile.json !**/ios/**/default.mode2v3 !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages \ No newline at end of file +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +packages/syncfusion_flutter_maps/example/build \ No newline at end of file diff --git a/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/renderer_base.dart b/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/renderer_base.dart index 3b4b1d29a..baa4cb638 100644 --- a/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/renderer_base.dart +++ b/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/renderer_base.dart @@ -98,31 +98,32 @@ abstract class SfSparkChartRenderObjectWidget extends LeafRenderObjectWidget { /// Represents the RenderSparkChart class. abstract class RenderSparkChart extends RenderBox { /// Creates the render object widget. - RenderSparkChart( - { - //ignore: avoid_unused_constructor_parameters - Widget? child, - List? data, - int? dataCount, - SparkChartIndexedValueMapper? xValueMapper, - SparkChartIndexedValueMapper? yValueMapper, - bool? isInversed, - double? axisCrossesAt, - double? axisLineWidth, - Color? axisLineColor, - List? axisLineDashArray, - Color? color, - Color? firstPointColor, - Color? lastPointColor, - Color? highPointColor, - Color? lowPointColor, - Color? negativePointColor, - SparkChartPlotBand? plotBand, - SparkChartDataDetails? sparkChartDataDetails, - SfSparkChartThemeData? themeData, - List? coordinatePoints, - List? dataPoints}) - : _data = data, + RenderSparkChart({ + //ignore: avoid_unused_constructor_parameters + Widget? child, + List? data, + int? dataCount, + SparkChartIndexedValueMapper? xValueMapper, + SparkChartIndexedValueMapper? yValueMapper, + bool? isInversed, + double? axisCrossesAt, + double? axisLineWidth, + Color? axisLineColor, + List? axisLineDashArray, + Color? color, + Color? firstPointColor, + Color? lastPointColor, + Color? highPointColor, + Color? lowPointColor, + Color? negativePointColor, + SparkChartPlotBand? plotBand, + SparkChartDataDetails? sparkChartDataDetails, + SfSparkChartThemeData? themeData, + List? coordinatePoints, + List? dataPoints, + double? minY, + double? maxY, + }) : _data = data, _dataCount = dataCount, _xValueMapper = xValueMapper, _yValueMapper = yValueMapper, @@ -141,7 +142,9 @@ abstract class RenderSparkChart extends RenderBox { _sparkChartDataDetails = sparkChartDataDetails, _themeData = themeData, _dataPoints = dataPoints, - _coordinatePoints = coordinatePoints { + _coordinatePoints = coordinatePoints, + _minYFixed = minY, + _maxYFixed = maxY { processDataSource(); if (isInversed ?? false) { inverseDataPoints(); @@ -447,9 +450,11 @@ abstract class RenderSparkChart extends RenderBox { /// Specifies the minimum Y value. double? minY; + double? _minYFixed; /// Specifies the maximum X value. double? maxY; + double? _maxYFixed; /// Defines the Y difference. double? diffY; @@ -478,10 +483,18 @@ abstract class RenderSparkChart extends RenderBox { maxX ??= currentPoint.x.toDouble(); minX = math.min(minX!, currentPoint.x.toDouble()); maxX = math.max(maxX!, currentPoint.x.toDouble()); - minY ??= currentPoint.y.toDouble(); - maxY ??= currentPoint.y.toDouble(); - minY = math.min(minY!, currentPoint.y.toDouble()); - maxY = math.max(maxY!, currentPoint.y.toDouble()); + if (_minYFixed != null) { + minY = _minYFixed; + } else { + minY ??= currentPoint.y.toDouble(); + minY = math.min(minY!, currentPoint.y.toDouble()); + } + if (_maxYFixed != null) { + maxY = _maxYFixed; + } else { + maxY ??= currentPoint.y.toDouble(); + maxY = math.max(maxY!, currentPoint.y.toDouble()); + } } /// Method to process the data source. @@ -511,10 +524,7 @@ abstract class RenderSparkChart extends RenderBox { num? yValue; late String labelX; dynamic actualX; - if (xValueMapper != null && - yValueMapper != null && - dataCount != null && - dataCount! > 0) { + if (xValueMapper != null && yValueMapper != null && dataCount != null && dataCount! > 0) { for (int i = 0; i < dataCount!; i++) { xValue = xValueMapper!(i); actualX = xValue; @@ -523,8 +533,7 @@ abstract class RenderSparkChart extends RenderBox { xValue = i.toDouble(); } else if (xValue is DateTime) { xValue = xValue.millisecondsSinceEpoch; - labelX = DateFormat.yMd() - .format(DateTime.fromMillisecondsSinceEpoch(xValue)); + labelX = DateFormat.yMd().format(DateTime.fromMillisecondsSinceEpoch(xValue)); } else if (xValue is num) { labelX = _getDataLabel(xValue); } @@ -563,16 +572,15 @@ abstract class RenderSparkChart extends RenderBox { /// Method to calculate axis height. double? getAxisHeight() { final double value = axisCrossesAt!; - double? axisLineHeight = - areaSize!.height - ((areaSize!.height / diffY!) * (-minY!)); + double? axisLineHeight = areaSize!.height - ((areaSize!.height / diffY!) * (-minY!)); axisLineHeight = minY! < 0 && maxY! <= 0 ? 0 : (minY! < 0 && maxY! > 0) ? axisHeight : areaSize!.height; if (value >= minY! && value <= maxY!) { - axisLineHeight = areaSize!.height - - (areaSize!.height * ((value - minY!) / diffY!)).roundToDouble(); + axisLineHeight = + areaSize!.height - (areaSize!.height * ((value - minY!) / diffY!)).roundToDouble(); } return axisLineHeight; } @@ -607,8 +615,8 @@ abstract class RenderSparkChart extends RenderBox { for (int i = 0; i < dataPoints!.length; i++) { x = dataPoints![i].x.toDouble(); y = dataPoints![i].y.toDouble(); - visiblePoint = transformToCoordinatePoint(minX!, maxX!, minY!, maxY!, - diffX!, diffY!, areaSize!, x, y, dataPoints!.length); + visiblePoint = transformToCoordinatePoint( + minX!, maxX!, minY!, maxY!, diffX!, diffY!, areaSize!, x, y, dataPoints!.length); coordinatePoints!.add(visiblePoint); } coordinatePoints = sortScreenCoordinatePoints(coordinatePoints!); @@ -656,16 +664,12 @@ abstract class RenderSparkChart extends RenderBox { void renderPlotBand(Canvas canvas, Offset offset) { if (plotBandStartHeight != plotBandEndHeight) { final Paint paint = Paint()..color = plotBand!.color; - final Rect plotBandRect = Rect.fromLTRB( - offset.dx, - offset.dy + plotBandStartHeight!, - offset.dx + areaSize!.width, - offset.dy + plotBandEndHeight!); + final Rect plotBandRect = Rect.fromLTRB(offset.dx, offset.dy + plotBandStartHeight!, + offset.dx + areaSize!.width, offset.dy + plotBandEndHeight!); if (plotBandRect.top >= sparkChartAreaRect!.top && plotBandRect.bottom >= sparkChartAreaRect!.bottom) { canvas.drawRect(plotBandRect, paint); - if (plotBand!.borderColor != Colors.transparent && - plotBand!.borderWidth > 0) { + if (plotBand!.borderColor != Colors.transparent && plotBand!.borderWidth > 0) { final Paint borderPaint = Paint() ..style = PaintingStyle.stroke ..strokeWidth = plotBand!.borderWidth @@ -679,8 +683,7 @@ abstract class RenderSparkChart extends RenderBox { ..style = PaintingStyle.stroke ..strokeWidth = 3; final Offset point1 = Offset(offset.dx, offset.dy + plotBandStartHeight!); - final Offset point2 = - Offset(offset.dx + areaSize!.width, offset.dy + plotBandStartHeight!); + final Offset point2 = Offset(offset.dx + areaSize!.width, offset.dy + plotBandStartHeight!); canvas.drawLine(point1, point2, paint); } } diff --git a/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/spark_line_renderer.dart b/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/spark_line_renderer.dart index 25b9f46bf..b819f2b9d 100644 --- a/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/spark_line_renderer.dart +++ b/packages/syncfusion_flutter_charts/lib/src/sparkline/renderers/spark_line_renderer.dart @@ -7,8 +7,7 @@ import '../utils/helper.dart'; import 'renderer_base.dart'; /// Represents the render object for spark chart. -class SfSparkLineChartRenderObjectWidget - extends SfSparkChartRenderObjectWidget { +class SfSparkLineChartRenderObjectWidget extends SfSparkChartRenderObjectWidget { /// Creates the render object for spark chart. const SfSparkLineChartRenderObjectWidget( {Key? key, @@ -36,7 +35,9 @@ class SfSparkLineChartRenderObjectWidget SfSparkChartThemeData? themeData, SparkChartDataDetails? sparkChartDataDetails, List? coordinatePoints, - List? dataPoints}) + List? dataPoints, + this.maxY, + this.minY}) : super( key: key, data: data, @@ -75,6 +76,10 @@ class SfSparkLineChartRenderObjectWidget /// Specifies the spark chart data label style. final TextStyle? labelStyle; + final double? maxY; + + final double? minY; + @override RenderObject createRenderObject(BuildContext context) { return _RenderSparkLineChart( @@ -102,7 +107,9 @@ class SfSparkLineChartRenderObjectWidget themeData: themeData!, sparkChartDataDetails: sparkChartDataDetails, coordinatePoints: coordinatePoints, - dataPoints: dataPoints); + dataPoints: dataPoints, + maxY: maxY, + minY: minY); } @override @@ -166,7 +173,9 @@ class _RenderSparkLineChart extends RenderSparkChart { SparkChartDataDetails? sparkChartDataDetails, SfSparkChartThemeData? themeData, List? coordinatePoints, - List? dataPoints}) + List? dataPoints, + super.maxY, + super.minY}) : _width = width, _dashArray = dashArray, _marker = marker, @@ -294,17 +303,15 @@ class _RenderSparkLineChart extends RenderSparkChart { } if (i < coordinatePoints!.length - 1) { - point1 = Offset(offset.dx + coordinatePoints![i].dx, - offset.dy + coordinatePoints![i].dy); - point2 = Offset(offset.dx + coordinatePoints![i + 1].dx, - offset.dy + coordinatePoints![i + 1].dy); + point1 = + Offset(offset.dx + coordinatePoints![i].dx, offset.dy + coordinatePoints![i].dy); + point2 = Offset( + offset.dx + coordinatePoints![i + 1].dx, offset.dy + coordinatePoints![i + 1].dy); drawDashedPath(canvas, paint, point1, point2, dashArray); } - if (labelDisplayMode != SparkChartLabelDisplayMode.none && - labelStyle != null) { + if (labelDisplayMode != SparkChartLabelDisplayMode.none && labelStyle != null) { size = getTextSize(dataLabels![i], labelStyle!); - yPosition = marker != null && - marker!.displayMode != SparkChartMarkerDisplayMode.none + yPosition = marker != null && marker!.displayMode != SparkChartMarkerDisplayMode.none ? (dataPoints![i].y > 0 ? (coordinatePoints![i].dy - size.height - marker!.size / 2) : (coordinatePoints![i].dy + marker!.size / 2)) @@ -312,8 +319,7 @@ class _RenderSparkLineChart extends RenderSparkChart { ? (coordinatePoints![i].dy - size.height) : (coordinatePoints![i].dy); dataPoints![i].dataLabelOffset = Offset( - (offset.dx + coordinatePoints![i].dx) - size.width / 2, - offset.dy + yPosition); + (offset.dx + coordinatePoints![i].dx) - size.width / 2, offset.dy + yPosition); _positionDataLabels(dataPoints![i], size, offset); } } @@ -329,20 +335,17 @@ class _RenderSparkLineChart extends RenderSparkChart { } if (i == 0) { - path.moveTo(offset.dx + coordinatePoints![i].dx, - offset.dy + coordinatePoints![i].dy); + path.moveTo(offset.dx + coordinatePoints![i].dx, offset.dy + coordinatePoints![i].dy); } if (i < coordinatePoints!.length - 1) { - path.lineTo(offset.dx + coordinatePoints![i + 1].dx, - offset.dy + coordinatePoints![i + 1].dy); + path.lineTo( + offset.dx + coordinatePoints![i + 1].dx, offset.dy + coordinatePoints![i + 1].dy); } - if (labelDisplayMode != SparkChartLabelDisplayMode.none && - labelStyle != null) { + if (labelDisplayMode != SparkChartLabelDisplayMode.none && labelStyle != null) { size = getTextSize(dataLabels![i], labelStyle!); - yPosition = marker != null && - marker!.displayMode != SparkChartMarkerDisplayMode.none + yPosition = marker != null && marker!.displayMode != SparkChartMarkerDisplayMode.none ? (dataPoints![i].y > 0 ? (coordinatePoints![i].dy - size.height - marker!.size / 2) : (coordinatePoints![i].dy + marker!.size / 2)) @@ -350,8 +353,7 @@ class _RenderSparkLineChart extends RenderSparkChart { ? (coordinatePoints![i].dy - size.height) : (coordinatePoints![i].dy); dataPoints![i].dataLabelOffset = Offset( - (offset.dx + coordinatePoints![i].dx) - size.width / 2, - offset.dy + yPosition); + (offset.dx + coordinatePoints![i].dx) - size.width / 2, offset.dy + yPosition); _positionDataLabels(dataPoints![i], size, offset); } } @@ -361,24 +363,20 @@ class _RenderSparkLineChart extends RenderSparkChart { } } - void _positionDataLabels( - SparkChartPoint dataPoint, Size size, Offset offset) { + void _positionDataLabels(SparkChartPoint dataPoint, Size size, Offset offset) { if (dataPoint.dataLabelOffset!.dx <= offset.dx) { - dataPoint.dataLabelOffset = - Offset(offset.dx, dataPoint.dataLabelOffset!.dy); + dataPoint.dataLabelOffset = Offset(offset.dx, dataPoint.dataLabelOffset!.dy); } if (dataPoint.dataLabelOffset!.dx >= offset.dx + areaSize!.width) { - dataPoint.dataLabelOffset = Offset( - (offset.dx + areaSize!.width) - size.width, - dataPoint.dataLabelOffset!.dy); + dataPoint.dataLabelOffset = + Offset((offset.dx + areaSize!.width) - size.width, dataPoint.dataLabelOffset!.dy); } if (dataPoint.dataLabelOffset!.dy <= offset.dy) { dataPoint.dataLabelOffset = Offset( dataPoint.dataLabelOffset!.dx, offset.dy + - (marker != null && - marker!.displayMode != SparkChartMarkerDisplayMode.none + (marker != null && marker!.displayMode != SparkChartMarkerDisplayMode.none ? marker!.size / 2 + size.height : size.height)); } @@ -387,8 +385,7 @@ class _RenderSparkLineChart extends RenderSparkChart { dataPoint.dataLabelOffset = Offset( dataPoint.dataLabelOffset!.dx, (offset.dy + areaSize!.height) - - (marker != null && - marker!.displayMode != SparkChartMarkerDisplayMode.none + (marker != null && marker!.displayMode != SparkChartMarkerDisplayMode.none ? marker!.size / 2 + size.height : size.height)); } @@ -424,21 +421,9 @@ class _RenderSparkLineChart extends RenderSparkChart { firstPointColor, lastPointColor); } - if (labelDisplayMode != null && - labelDisplayMode != SparkChartLabelDisplayMode.none) { - renderDataLabel( - context.canvas, - dataLabels!, - dataPoints!, - coordinatePoints!, - labelStyle!, - labelDisplayMode!, - 'Line', - themeData!, - offset, - color!, - _highPoint, - _lowPoint); + if (labelDisplayMode != null && labelDisplayMode != SparkChartLabelDisplayMode.none) { + renderDataLabel(context.canvas, dataLabels!, dataPoints!, coordinatePoints!, labelStyle!, + labelDisplayMode!, 'Line', themeData!, offset, color!, _highPoint, _lowPoint); } } } diff --git a/packages/syncfusion_flutter_charts/lib/src/sparkline/series/spark_line_base.dart b/packages/syncfusion_flutter_charts/lib/src/sparkline/series/spark_line_base.dart index 51934b647..4f32d6add 100644 --- a/packages/syncfusion_flutter_charts/lib/src/sparkline/series/spark_line_base.dart +++ b/packages/syncfusion_flutter_charts/lib/src/sparkline/series/spark_line_base.dart @@ -58,7 +58,9 @@ class SfSparkLineChart extends StatefulWidget { this.marker, this.labelDisplayMode, this.labelStyle, - this.trackball}) + this.trackball, + this.maxY, + this.minY}) : _sparkChartDataDetails = SparkChartDataDetails(data: data), super(key: key); @@ -142,7 +144,9 @@ class SfSparkLineChart extends StatefulWidget { this.trackball, this.marker, this.labelDisplayMode, - this.labelStyle}) + this.labelStyle, + this.maxY, + this.minY}) : _sparkChartDataDetails = SparkChartDataDetails( dataCount: dataCount, xValueMapper: xValueMapper, @@ -556,6 +560,10 @@ class SfSparkLineChart extends StatefulWidget { /// Specifies the spark chart data details. final SparkChartDataDetails _sparkChartDataDetails; + final double? maxY; + + final double? minY; + @override State createState() { return _SfSparkLineChartState(); @@ -706,7 +714,9 @@ class _SfSparkLineChartState extends State { themeData: _chartThemeData, sparkChartDataDetails: widget._sparkChartDataDetails, dataPoints: _dataPoints, - coordinatePoints: _coordinatePoints), + coordinatePoints: _coordinatePoints, + maxY: widget.maxY, + minY: widget.minY), SparkChartTrackballRenderer( trackball: widget.trackball, coordinatePoints: _coordinatePoints, diff --git a/packages/syncfusion_flutter_charts/pubspec.lock b/packages/syncfusion_flutter_charts/pubspec.lock new file mode 100644 index 000000000..fa573e8ca --- /dev/null +++ b/packages/syncfusion_flutter_charts/pubspec.lock @@ -0,0 +1,204 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + intl: + dependency: "direct main" + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + url: "https://pub.dev" + source: hosted + version: "10.0.4" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + url: "https://pub.dev" + source: hosted + version: "3.0.3" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + url: "https://pub.dev" + source: hosted + version: "0.8.0" + meta: + dependency: transitive + description: + name: meta + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + url: "https://pub.dev" + source: hosted + version: "1.12.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + syncfusion_flutter_core: + dependency: "direct main" + description: + path: "../syncfusion_flutter_core" + relative: true + source: path + version: "24.2.7" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + url: "https://pub.dev" + source: hosted + version: "0.7.0" + vector_math: + dependency: "direct main" + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + url: "https://pub.dev" + source: hosted + version: "14.2.1" +sdks: + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/packages/syncfusion_flutter_charts/pubspec.yaml b/packages/syncfusion_flutter_charts/pubspec.yaml index 6878c9dc3..441859e31 100644 --- a/packages/syncfusion_flutter_charts/pubspec.yaml +++ b/packages/syncfusion_flutter_charts/pubspec.yaml @@ -25,8 +25,7 @@ dependencies: sdk: flutter intl: '>=0.18.1 <0.20.0' vector_math: ">=2.1.0 <=3.0.0" - syncfusion_flutter_core: - path: ../syncfusion_flutter_core + syncfusion_flutter_core: ^26.1.39 dev_dependencies: flutter_test: diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 6f2ed0ad5..c2e223b36 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter: sdk: flutter - syncfusion_flutter_core: ^25.2.3 + syncfusion_flutter_core: ^26.1.39 http: ^1.0.0 vector_math: ">=2.1.0 <=3.0.0" From 06c4056e4adaa65db06c370a689b464159f436f9 Mon Sep 17 00:00:00 2001 From: Eric Parker Date: Sat, 7 Sep 2024 21:36:32 +0000 Subject: [PATCH 07/13] updated core_tooltip with markNeedsLayout --- .../lib/src/charts/common/core_tooltip.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/common/core_tooltip.dart b/packages/syncfusion_flutter_charts/lib/src/charts/common/core_tooltip.dart index 95ca5fe42..beaad4a1d 100644 --- a/packages/syncfusion_flutter_charts/lib/src/charts/common/core_tooltip.dart +++ b/packages/syncfusion_flutter_charts/lib/src/charts/common/core_tooltip.dart @@ -165,7 +165,7 @@ class CoreTooltipState extends State if (renderObject != null && renderObject.attached && renderObject is RenderConstrainedLayoutBuilder) { - renderObject.markNeedsBuild(); + renderObject.markNeedsLayout(); } } } From 30163f663844298cf5ae02fa87c733732da0c5f9 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Sun, 8 Sep 2024 10:10:03 -0300 Subject: [PATCH 08/13] Fixed markNeedsBuild error --- packages/syncfusion_flutter_charts/lib/src/charts/base.dart | 2 +- .../lib/src/charts/cartesian_chart.dart | 2 +- .../lib/src/charts/common/core_legend.dart | 2 +- .../lib/src/charts/common/element_widget.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/base.dart b/packages/syncfusion_flutter_charts/lib/src/charts/base.dart index 8d8bdca5e..46018179b 100644 --- a/packages/syncfusion_flutter_charts/lib/src/charts/base.dart +++ b/packages/syncfusion_flutter_charts/lib/src/charts/base.dart @@ -3257,7 +3257,7 @@ class RenderLoadingIndicator extends RenderProxyBox } } if (buildLoadMoreIndicator) { - markNeedsBuild(); + markNeedsLayout(); } } diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/cartesian_chart.dart b/packages/syncfusion_flutter_charts/lib/src/charts/cartesian_chart.dart index 7f1483242..c86e486a9 100644 --- a/packages/syncfusion_flutter_charts/lib/src/charts/cartesian_chart.dart +++ b/packages/syncfusion_flutter_charts/lib/src/charts/cartesian_chart.dart @@ -1364,7 +1364,7 @@ class SfCartesianChartState extends State if (renderObject != null && renderObject.attached && renderObject is RenderConstrainedLayoutBuilder) { - renderObject.markNeedsBuild(); + renderObject.markNeedsLayout(); } } } diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/common/core_legend.dart b/packages/syncfusion_flutter_charts/lib/src/charts/common/core_legend.dart index 573069d2d..62af90b1a 100644 --- a/packages/syncfusion_flutter_charts/lib/src/charts/common/core_legend.dart +++ b/packages/syncfusion_flutter_charts/lib/src/charts/common/core_legend.dart @@ -449,7 +449,7 @@ class LegendLayoutState extends State { if (renderObject != null && renderObject.attached && renderObject is RenderConstrainedLayoutBuilder) { - renderObject.markNeedsBuild(); + renderObject.markNeedsLayout(); } } } diff --git a/packages/syncfusion_flutter_charts/lib/src/charts/common/element_widget.dart b/packages/syncfusion_flutter_charts/lib/src/charts/common/element_widget.dart index 91cbf542f..5d47aae52 100644 --- a/packages/syncfusion_flutter_charts/lib/src/charts/common/element_widget.dart +++ b/packages/syncfusion_flutter_charts/lib/src/charts/common/element_widget.dart @@ -110,7 +110,7 @@ class RenderChartElementLayoutBuilder extends RenderBox } void refresh() { - markNeedsBuild(); + markNeedsLayout(); (child as RenderChartFadeTransition?)?.refresh(); } From 5c7a39f252991995a27eb0f08a5e7d82536b37dc Mon Sep 17 00:00:00 2001 From: LucazzP Date: Wed, 2 Oct 2024 08:57:11 -0300 Subject: [PATCH 09/13] Updated syncfusion_core to 27.1.51 --- packages/syncfusion_flutter_charts/pubspec.yaml | 2 +- packages/syncfusion_flutter_maps/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/syncfusion_flutter_charts/pubspec.yaml b/packages/syncfusion_flutter_charts/pubspec.yaml index 4a8f1cf85..9a0a6510d 100644 --- a/packages/syncfusion_flutter_charts/pubspec.yaml +++ b/packages/syncfusion_flutter_charts/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: sdk: flutter intl: '>=0.18.1 <0.20.0' vector_math: ">=2.1.0 <=3.0.0" - syncfusion_flutter_core: ^26.1.39 + syncfusion_flutter_core: ^27.1.51 dev_dependencies: flutter_test: diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index 09557766e..d697e8cff 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter: sdk: flutter - syncfusion_flutter_core: ^26.1.39 + syncfusion_flutter_core: ^27.1.51 http: ^1.0.0 vector_math: ">=2.1.0 <=3.0.0" From 817b664480a8b8d1c92afc5c6e77c999db487d09 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Thu, 3 Oct 2024 15:09:51 -0300 Subject: [PATCH 10/13] Added alternate row color --- .../lib/src/theme/color_scheme.dart | 49 ++--- .../lib/src/theme/datagrid_theme.dart | 13 ++ .../lib/src/theme/theme_widget.dart | 2 + .../lib/src/datagrid_widget/sfdatagrid.dart | 3 + .../widgets/rendering_widget.dart | 4 + .../syncfusion_flutter_datagrid/pubspec.lock | 196 ++++++++++++++++++ 6 files changed, 234 insertions(+), 33 deletions(-) create mode 100644 packages/syncfusion_flutter_datagrid/pubspec.lock diff --git a/packages/syncfusion_flutter_core/lib/src/theme/color_scheme.dart b/packages/syncfusion_flutter_core/lib/src/theme/color_scheme.dart index 57f714037..4e3bc45ae 100644 --- a/packages/syncfusion_flutter_core/lib/src/theme/color_scheme.dart +++ b/packages/syncfusion_flutter_core/lib/src/theme/color_scheme.dart @@ -21,6 +21,7 @@ class SfColorScheme { required Color outlineVariant, required this.splashColor, required this.hoverColor, + required this.alternateRowColor, required this.highlightColor, required this.valueIndicatorColor, required this.textColor, @@ -88,12 +89,8 @@ class SfColorScheme { 31: surface.withOpacity(0.12), 143: surface.withOpacity(0.56), 150: surface, - 250: brightness == Brightness.light - ? const Color(0xFFFAFAFA) - : const Color(0xFF303030), - 251: brightness == Brightness.light - ? const Color(0xFFFAFAFA) - : const Color(0xFF303030), + 250: brightness == Brightness.light ? const Color(0xFFFAFAFA) : const Color(0xFF303030), + 251: brightness == Brightness.light ? const Color(0xFFFAFAFA) : const Color(0xFF303030), 255: surface, }, ); @@ -108,9 +105,7 @@ class SfColorScheme { 20: onSurface.withOpacity(0.08), 21: onSurface.withOpacity(0.081), 22: onSurface.withOpacity(0.08), - 24: brightness == Brightness.light - ? onPrimary - : onSurface.withOpacity(0.09), + 24: brightness == Brightness.light ? onPrimary : onSurface.withOpacity(0.09), 23: onSurface.withOpacity(0.09), 28: onSurface.withOpacity(0.11), 29: brightness == Brightness.light @@ -135,9 +130,7 @@ class SfColorScheme { 61: onSurface.withOpacity(0.24), 66: onSurface.withOpacity(0.26), 69: onSurface.withOpacity(0.27), - 70: brightness == Brightness.light - ? const Color(0xFF212121) - : const Color(0xFFE0E0E0), + 70: brightness == Brightness.light ? const Color(0xFF212121) : const Color(0xFFE0E0E0), 71: brightness == Brightness.light ? onSurface.withOpacity(0.28) : onSurface.withOpacity(0.33), @@ -160,14 +153,10 @@ class SfColorScheme { 153: onSurface.withOpacity(0.6), 154: onSurface.withOpacity(0.6), 179: onSurface.withOpacity(0.7), - 184: brightness == Brightness.light - ? onSurface.withOpacity(0.72) - : onSurface, + 184: brightness == Brightness.light ? onSurface.withOpacity(0.72) : onSurface, 217: onSurface.withOpacity(0.85), 222: onSurface.withOpacity(0.87), - 223: brightness == Brightness.light - ? onSurface.withOpacity(0.87) - : onSurface, + 223: brightness == Brightness.light ? onSurface.withOpacity(0.87) : onSurface, 224: brightness == Brightness.light ? const Color.fromRGBO(97, 97, 97, 1) : const Color.fromRGBO(224, 224, 224, 1), @@ -223,9 +212,7 @@ class SfColorScheme { this.inverseSurface = MaterialColor( inverseSurface.value, { - 255: brightness == Brightness.light - ? const Color(0xFFFAFAFA) - : const Color(0xFF424242), + 255: brightness == Brightness.light ? const Color(0xFFFAFAFA) : const Color(0xFF424242), 257: Colors.transparent, 79: brightness == Brightness.light ? const Color.fromRGBO(79, 79, 79, 1) @@ -304,6 +291,7 @@ class SfColorScheme { required Color outlineVariant, required this.splashColor, required this.hoverColor, + required this.alternateRowColor, required this.highlightColor, required this.valueIndicatorColor, required this.textColor, @@ -315,9 +303,7 @@ class SfColorScheme { primary.value, { 1: primaryContainer, - 27: brightness == Brightness.light - ? primary.withOpacity(0.1) - : primary.withOpacity(0.3), + 27: brightness == Brightness.light ? primary.withOpacity(0.1) : primary.withOpacity(0.3), 28: primary, 30: primary.withOpacity(0.12), 31: primary.withOpacity(0.08), @@ -361,9 +347,7 @@ class SfColorScheme { ? const Color.fromRGBO(150, 60, 112, 1) : const Color.fromRGBO(77, 170, 255, 1), 250: surface, - 251: brightness == Brightness.light - ? const Color(0xFFEEE8F4) - : const Color(0xFF302D38), + 251: brightness == Brightness.light ? const Color(0xFFEEE8F4) : const Color(0xFF302D38), 255: surface, }, ); @@ -371,17 +355,13 @@ class SfColorScheme { this.onSurface = MaterialColor( onSurface.value, { - 0: brightness == Brightness.light - ? const Color(0xFFEEE8F4) - : const Color(0xFF302D38), + 0: brightness == Brightness.light ? const Color(0xFFEEE8F4) : const Color(0xFF302D38), 10: primary.withOpacity(0.08), 11: onSurface.withOpacity(0.04), 19: primaryContainer, 20: primary.withOpacity(0.12), 22: surfaceVariant, - 24: brightness == Brightness.light - ? onPrimary - : onSurface.withOpacity(0.09), + 24: brightness == Brightness.light ? onPrimary : onSurface.withOpacity(0.09), 29: surfaceVariant, 31: onSurface.withOpacity(0.12), 32: outline, @@ -532,6 +512,9 @@ class SfColorScheme { /// A color that is used to paint the hover effect of the components. Color hoverColor; + /// A color that is used to paint the alternate row color of the components. + Color alternateRowColor; + /// A color that is used to paint the highlight effect of the components. Color highlightColor; diff --git a/packages/syncfusion_flutter_core/lib/src/theme/datagrid_theme.dart b/packages/syncfusion_flutter_core/lib/src/theme/datagrid_theme.dart index c7c3165da..be40fa1da 100644 --- a/packages/syncfusion_flutter_core/lib/src/theme/datagrid_theme.dart +++ b/packages/syncfusion_flutter_core/lib/src/theme/datagrid_theme.dart @@ -122,6 +122,7 @@ class SfDataGridThemeData with Diagnosticable { this.columnResizeIndicatorStrokeWidth, this.rowHoverColor, this.rowHoverTextStyle, + this.alternateRowColor, this.sortIcon, this.filterIcon, this.filterIconColor, @@ -151,6 +152,7 @@ class SfDataGridThemeData with Diagnosticable { Color? headerColor, double? frozenPaneElevation, Color? rowHoverColor, + Color? alternateRowColor, Color? columnResizeIndicatorColor, double? columnResizeIndicatorStrokeWidth, TextStyle? rowHoverTextStyle, @@ -181,6 +183,7 @@ class SfDataGridThemeData with Diagnosticable { headerColor: headerColor, frozenPaneElevation: frozenPaneElevation, rowHoverColor: rowHoverColor, + alternateRowColor: alternateRowColor, columnResizeIndicatorColor: columnResizeIndicatorColor, columnResizeIndicatorStrokeWidth: columnResizeIndicatorStrokeWidth, rowHoverTextStyle: rowHoverTextStyle, @@ -326,6 +329,9 @@ class SfDataGridThemeData with Diagnosticable { /// The color for the row when a pointer is hovering over it. final Color? rowHoverColor; + /// The color for the row when the row is even, to differentiate the rows. + final Color? alternateRowColor; + /// The default [TextStyle] for the row when a pointer is hovering over it. final TextStyle? rowHoverTextStyle; @@ -515,6 +521,7 @@ class SfDataGridThemeData with Diagnosticable { Color? columnResizeIndicatorColor, double? columnResizeIndicatorStrokeWidth, Color? rowHoverColor, + Color? alternateRowColor, TextStyle? rowHoverTextStyle, Widget? sortIcon, Widget? filterIcon, @@ -547,6 +554,7 @@ class SfDataGridThemeData with Diagnosticable { columnResizeIndicatorStrokeWidth: columnResizeIndicatorStrokeWidth ?? this.columnResizeIndicatorStrokeWidth, rowHoverColor: rowHoverColor ?? this.rowHoverColor, + alternateRowColor: alternateRowColor ?? this.alternateRowColor, rowHoverTextStyle: rowHoverTextStyle ?? this.rowHoverTextStyle, sortIcon: sortIcon ?? this.sortIcon, filterIcon: filterIcon ?? this.filterIcon, @@ -590,6 +598,8 @@ class SfDataGridThemeData with Diagnosticable { frozenPaneElevation: lerpDouble(a.frozenPaneElevation, b.frozenPaneElevation, t), rowHoverColor: Color.lerp(a.rowHoverColor, b.rowHoverColor, t), + alternateRowColor: + Color.lerp(a.alternateRowColor, b.alternateRowColor, t), columnResizeIndicatorColor: Color.lerp( a.columnResizeIndicatorColor, b.columnResizeIndicatorColor, t), columnResizeIndicatorStrokeWidth: lerpDouble( @@ -643,6 +653,7 @@ class SfDataGridThemeData with Diagnosticable { other.headerColor == headerColor && other.frozenPaneElevation == frozenPaneElevation && other.rowHoverColor == rowHoverColor && + other.alternateRowColor == alternateRowColor && other.columnResizeIndicatorColor == columnResizeIndicatorColor && other.columnResizeIndicatorStrokeWidth == columnResizeIndicatorStrokeWidth && @@ -731,6 +742,8 @@ class SfDataGridThemeData with Diagnosticable { defaultValue: defaultData.columnResizeIndicatorStrokeWidth)); properties.add(ColorProperty('rowHoverColor', rowHoverColor, defaultValue: defaultData.rowHoverColor)); + properties.add(ColorProperty('alternateRowColor', alternateRowColor, + defaultValue: defaultData.alternateRowColor)); properties.add(DiagnosticsProperty( 'rowHoverTextStyle', rowHoverTextStyle, defaultValue: defaultData.rowHoverTextStyle)); diff --git a/packages/syncfusion_flutter_core/lib/src/theme/theme_widget.dart b/packages/syncfusion_flutter_core/lib/src/theme/theme_widget.dart index 8ba3d5005..cd37af5a2 100644 --- a/packages/syncfusion_flutter_core/lib/src/theme/theme_widget.dart +++ b/packages/syncfusion_flutter_core/lib/src/theme/theme_widget.dart @@ -130,6 +130,7 @@ class SfTheme extends StatelessWidget { textColor: themeData.colorScheme.onSurface, splashColor: themeData.splashColor, hoverColor: themeData.hoverColor, + alternateRowColor: Colors.grey.withOpacity(0.1), highlightColor: themeData.highlightColor, valueIndicatorColor: Colors.transparent, transparent: Colors.transparent, @@ -155,6 +156,7 @@ class SfTheme extends StatelessWidget { textColor: themeData.colorScheme.onSurface, splashColor: themeData.splashColor, hoverColor: themeData.hoverColor, + alternateRowColor: Colors.grey.withOpacity(0.1), highlightColor: themeData.highlightColor, valueIndicatorColor: Colors.transparent, transparent: Colors.transparent, diff --git a/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/sfdatagrid.dart b/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/sfdatagrid.dart index 1c55b2fed..a6d852af1 100644 --- a/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/sfdatagrid.dart +++ b/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/sfdatagrid.dart @@ -5013,6 +5013,8 @@ class DataGridThemeHelper { headerHoverColor = defaults.headerHoverColor ?? sfDataGridThemeData.headerHoverColor; rowHoverColor = defaults.rowHoverColor ?? sfDataGridThemeData.rowHoverColor; + alternateRowColor = defaults.alternateRowColor ?? + sfDataGridThemeData.alternateRowColor; sortIconColor = defaults.sortIconColor ?? sfDataGridThemeData.sortIconColor; frozenPaneLineColor = defaults.frozenPaneLineColor ?? sfDataGridThemeData.frozenPaneLineColor; @@ -5119,6 +5121,7 @@ class DataGridThemeHelper { /// To do late final Color? rowHoverColor; + late final Color? alternateRowColor; /// To do diff --git a/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/widgets/rendering_widget.dart b/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/widgets/rendering_widget.dart index fa5f25c77..53fae8ede 100644 --- a/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/widgets/rendering_widget.dart +++ b/packages/syncfusion_flutter_datagrid/lib/src/datagrid_widget/widgets/rendering_widget.dart @@ -713,6 +713,10 @@ class RenderVirtualizingCellsWidget extends RenderBox Color? backgroundColor; Color getDefaultRowBackgroundColor() { + final isEven = dataRow.rowIndex.isEven; + if (isEven) { + return dataGridConfiguration.dataGridThemeHelper!.alternateRowColor!; + } return dataGridConfiguration.colorScheme!.transparent; } diff --git a/packages/syncfusion_flutter_datagrid/pubspec.lock b/packages/syncfusion_flutter_datagrid/pubspec.lock new file mode 100644 index 000000000..6cd004697 --- /dev/null +++ b/packages/syncfusion_flutter_datagrid/pubspec.lock @@ -0,0 +1,196 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: "direct main" + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + syncfusion_flutter_core: + dependency: "direct main" + description: + path: "../syncfusion_flutter_core" + relative: true + source: path + version: "27.1.48" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" + source: hosted + version: "0.7.2" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" + source: hosted + version: "14.2.5" +sdks: + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" From 78c1f12bfd7f9aa1c3e3486ff6d78d1241d94ca0 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Thu, 3 Oct 2024 15:13:02 -0300 Subject: [PATCH 11/13] Updated pubspec --- packages/syncfusion_flutter_charts/pubspec.yaml | 3 ++- packages/syncfusion_flutter_maps/pubspec.yaml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/syncfusion_flutter_charts/pubspec.yaml b/packages/syncfusion_flutter_charts/pubspec.yaml index 9a0a6510d..47e1b602f 100644 --- a/packages/syncfusion_flutter_charts/pubspec.yaml +++ b/packages/syncfusion_flutter_charts/pubspec.yaml @@ -25,7 +25,8 @@ dependencies: sdk: flutter intl: '>=0.18.1 <0.20.0' vector_math: ">=2.1.0 <=3.0.0" - syncfusion_flutter_core: ^27.1.51 + syncfusion_flutter_core: + path: ../syncfusion_flutter_core dev_dependencies: flutter_test: diff --git a/packages/syncfusion_flutter_maps/pubspec.yaml b/packages/syncfusion_flutter_maps/pubspec.yaml index d697e8cff..07cae8829 100644 --- a/packages/syncfusion_flutter_maps/pubspec.yaml +++ b/packages/syncfusion_flutter_maps/pubspec.yaml @@ -16,7 +16,8 @@ dependencies: flutter: sdk: flutter - syncfusion_flutter_core: ^27.1.51 + syncfusion_flutter_core: + path: ../syncfusion_flutter_core http: ^1.0.0 vector_math: ">=2.1.0 <=3.0.0" From c074657fdf540dd714bb9ed9b36e32af26b39dc5 Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 7 Apr 2025 12:53:17 -0300 Subject: [PATCH 12/13] Removed flutter dependency from pdf parser --- .../annotations/pdf_annotation.dart | 561 ++++------- .../pdf_document_link_annotation.dart | 75 +- .../annotations/pdf_ellipse_annotation.dart | 168 ++-- .../annotations/pdf_line_annotation.dart | 311 +++--- .../annotations/pdf_paintparams.dart | 2 +- .../annotations/pdf_polygon_annotation.dart | 208 ++-- .../annotations/pdf_popup_annotation.dart | 63 +- .../annotations/pdf_rectangle_annotation.dart | 200 ++-- .../pdf_text_markup_annotation.dart | 243 ++--- .../annotations/pdf_text_web_link.dart | 39 +- .../annotations/pdf_uri_annotation.dart | 42 +- .../annotations/xfdf_parser.dart | 339 +++---- .../pdf/implementation/drawing/drawing.dart | 2 +- .../exporting/pdf_text_extractor/glyph.dart | 2 +- .../pdf_text_extractor/image_renderer.dart | 181 ++-- .../pdf_text_extractor/matched_item.dart | 2 +- .../pdf_text_extractor/matrix_helper.dart | 48 +- .../pdf_text_extractor.dart | 518 ++++------ .../pdf_text_extractor/text_element.dart | 275 ++---- .../pdf_text_extractor/text_glyph.dart | 8 +- .../pdf_text_extractor/text_line.dart | 2 +- .../pdf_text_extractor/text_word.dart | 10 +- .../forms/pdf_button_field.dart | 229 ++--- .../forms/pdf_check_box_field.dart | 304 +++--- .../forms/pdf_combo_box_field.dart | 132 +-- .../pdf/implementation/forms/pdf_field.dart | 889 +++++++----------- .../implementation/forms/pdf_field_item.dart | 70 +- .../forms/pdf_field_painter.dart | 251 ++--- .../forms/pdf_list_box_field.dart | 72 +- .../implementation/forms/pdf_list_field.dart | 66 +- .../forms/pdf_radio_button_list_field.dart | 94 +- .../forms/pdf_signature_field.dart | 220 ++--- .../forms/pdf_text_box_field.dart | 182 ++-- .../general/pdf_destination.dart | 2 +- .../general/pdf_named_destination.dart | 37 +- .../figures/base/element_layouter.dart | 9 +- .../graphics/figures/base/layout_element.dart | 32 +- .../graphics/figures/base/shape_layouter.dart | 86 +- .../graphics/figures/base/text_layouter.dart | 88 +- .../graphics/figures/pdf_bezier_curve.dart | 10 +- .../graphics/figures/pdf_path.dart | 31 +- .../graphics/figures/pdf_template.dart | 47 +- .../graphics/fonts/pdf_font.dart | 24 +- .../graphics/images/pdf_bitmap.dart | 32 +- .../graphics/images/pdf_image.dart | 2 +- .../implementation/graphics/pdf_graphics.dart | 575 +++++------ .../pdf/implementation/pages/pdf_layer.dart | 193 ++-- .../pdf/implementation/pages/pdf_page.dart | 263 ++---- .../pages/pdf_page_collection.dart | 174 ++-- .../implementation/pages/pdf_page_layer.dart | 161 ++-- .../pages/pdf_page_settings.dart | 8 +- .../pages/pdf_page_template_element.dart | 34 +- .../pdf/implementation/pages/pdf_section.dart | 237 ++--- .../automatic_fields/pdf_automatic_field.dart | 28 +- .../pdf_destination_page_number_field.dart | 8 +- .../automatic_fields/pdf_dynamic_field.dart | 2 +- .../pdf_multiple_value_field.dart | 30 +- .../pdf_page_count_field.dart | 9 +- .../pdf_page_number_field.dart | 12 +- .../pdf_single_value_field.dart | 46 +- .../automatic_fields/pdf_static_field.dart | 37 +- .../pdf_document/outlines/pdf_outline.dart | 198 ++-- .../grid/layouting/pdf_grid_layouter.dart | 825 ++++++---------- .../structured_elements/grid/pdf_grid.dart | 801 ++++++---------- .../grid/pdf_grid_cell.dart | 428 +++------ .../lists/bullets/pdf_unordered_marker.dart | 12 +- .../lists/pdf_list_layouter.dart | 185 ++-- packages/syncfusion_flutter_pdf/pubspec.lock | 149 +++ packages/syncfusion_flutter_pdf/pubspec.yaml | 9 +- 69 files changed, 3918 insertions(+), 6714 deletions(-) create mode 100644 packages/syncfusion_flutter_pdf/pubspec.lock diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_annotation.dart index 4a1a6b8e0..00bce1e54 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_annotation.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -171,33 +171,20 @@ class PdfAnnotationHelper { List? flags, bool? setAppearance}) { base._helper = this; - initializeAnnotationProperties( - page, - text, - bounds, - border, - color, - innerColor, - author, - opacity, - subject, - modifiedDate, - flags, - setAppearance); + initializeAnnotationProperties(page, text, bounds, border, color, innerColor, author, opacity, + subject, modifiedDate, flags, setAppearance); } /// internal method /// Initialize [PdfAnnotation] object - void initializeExistingAnnotation( - PdfDictionary dictionary, PdfCrossTable crossTable) { + void initializeExistingAnnotation(PdfDictionary dictionary, PdfCrossTable crossTable) { base._helper = this; this.dictionary = dictionary; this.crossTable = crossTable; isLoadedAnnotation = true; PdfName? name; if (dictionary.containsKey(PdfDictionaryProperties.subtype)) { - name = dictionary.items![PdfName(PdfDictionaryProperties.subtype)] - as PdfName?; + name = dictionary.items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; } if (name != null) { if (name.name == PdfDictionaryProperties.circle || @@ -209,8 +196,7 @@ class PdfAnnotationHelper { name.name == PdfDictionaryProperties.squiggly || name.name == PdfDictionaryProperties.strikeOut || name.name == PdfDictionaryProperties.text) { - PdfDocumentHelper.getHelper(crossTable.document!).catalog.beginSave = - dictionaryBeginSave; + PdfDocumentHelper.getHelper(crossTable.document!).catalog.beginSave = dictionaryBeginSave; PdfDocumentHelper.getHelper(crossTable.document!).catalog.modify(); } } @@ -319,8 +305,8 @@ class PdfAnnotationHelper { final PdfRectangle rect = PdfRectangle.fromRect(value); if (rectangle != rect) { rectangle = rect; - dictionary!.setProperty(PdfName(PdfDictionaryProperties.rect), - PdfArray.fromRectangle(rect)); + dictionary! + .setProperty(PdfName(PdfDictionaryProperties.rect), PdfArray.fromRectangle(rect)); } } else { isBounds = true; @@ -346,12 +332,10 @@ class PdfAnnotationHelper { } else { annotationBorder ??= _obtainBorder(); if (!isLineBorder()) { - dictionary! - .setProperty(PdfDictionaryProperties.border, annotationBorder); + dictionary!.setProperty(PdfDictionaryProperties.border, annotationBorder); } } - PdfAnnotationBorderHelper.getHelper(annotationBorder!).isLineBorder = - isLineBorder(); + PdfAnnotationBorderHelper.getHelper(annotationBorder!).isLineBorder = isLineBorder(); return annotationBorder!; } @@ -361,8 +345,7 @@ class PdfAnnotationHelper { if (isLineBorder()) { dictionary!.setProperty(PdfName(PdfDictionaryProperties.bs), border); } else { - dictionary!.setProperty( - PdfName(PdfDictionaryProperties.border), annotationBorder); + dictionary!.setProperty(PdfName(PdfDictionaryProperties.border), annotationBorder); } } @@ -371,14 +354,11 @@ class PdfAnnotationHelper { String get text { if (!isLoadedAnnotation) { if (dictionary!.containsKey(PdfDictionaryProperties.contents)) { - textValue = - (dictionary![PdfDictionaryProperties.contents]! as PdfString).value; + textValue = (dictionary![PdfDictionaryProperties.contents]! as PdfString).value; } return textValue!; } else { - return textValue == null || textValue!.isEmpty - ? _obtainText()! - : textValue!; + return textValue == null || textValue!.isEmpty ? _obtainText()! : textValue!; } } @@ -400,9 +380,8 @@ class PdfAnnotationHelper { annotationColor = value; PdfColorSpace? cs = PdfColorSpace.rgb; if (page != null && !PdfPageHelper.getHelper(page!).isLoadedPage) { - cs = PdfSectionCollectionHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(page!).section!) - .parent!) + cs = PdfSectionCollectionHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page!).section!).parent!) .document! .colorSpace; } @@ -426,8 +405,8 @@ class PdfAnnotationHelper { annotationInnerColor = value; if (isLoadedAnnotation) { if (PdfColorHelper.getHelper(annotationInnerColor!).alpha != 0) { - dictionary!.setProperty(PdfDictionaryProperties.iC, - PdfColorHelper.toArray(annotationInnerColor!)); + dictionary! + .setProperty(PdfDictionaryProperties.iC, PdfColorHelper.toArray(annotationInnerColor!)); } else if (dictionary!.containsKey(PdfDictionaryProperties.iC)) { dictionary!.remove(PdfDictionaryProperties.iC); } @@ -438,11 +417,9 @@ class PdfAnnotationHelper { String get author { if (!isLoadedAnnotation) { if (dictionary!.containsKey(PdfDictionaryProperties.author)) { - annotationAuthor = - (dictionary![PdfDictionaryProperties.author]! as PdfString).value; + annotationAuthor = (dictionary![PdfDictionaryProperties.author]! as PdfString).value; } else if (dictionary!.containsKey(PdfDictionaryProperties.t)) { - annotationAuthor = - (dictionary![PdfDictionaryProperties.t]! as PdfString).value; + annotationAuthor = (dictionary![PdfDictionaryProperties.t]! as PdfString).value; } } else { annotationAuthor = _obtainAuthor(); @@ -464,11 +441,9 @@ class PdfAnnotationHelper { annotationSubject = _obtainSubject(); } else { if (dictionary!.containsKey(PdfDictionaryProperties.subject)) { - annotationSubject = - (dictionary![PdfDictionaryProperties.subject]! as PdfString).value; + annotationSubject = (dictionary![PdfDictionaryProperties.subject]! as PdfString).value; } else if (dictionary!.containsKey(PdfDictionaryProperties.subj)) { - annotationSubject = - (dictionary![PdfDictionaryProperties.subj]! as PdfString).value; + annotationSubject = (dictionary![PdfDictionaryProperties.subj]! as PdfString).value; } } return annotationSubject!; @@ -483,15 +458,13 @@ class PdfAnnotationHelper { } /// Gets the ModifiedDate of the annotation. - DateTime? get modifiedDate => - isLoadedAnnotation ? _obtainModifiedDate() : annotationModifiedDate; + DateTime? get modifiedDate => isLoadedAnnotation ? _obtainModifiedDate() : annotationModifiedDate; /// Sets the ModifiedDate of the annotation. set modifiedDate(DateTime? value) { if (annotationModifiedDate != value) { annotationModifiedDate = value; - dictionary! - .setDateTime(PdfDictionaryProperties.m, annotationModifiedDate!); + dictionary!.setDateTime(PdfDictionaryProperties.m, annotationModifiedDate!); } } @@ -516,8 +489,7 @@ class PdfAnnotationHelper { } if (annotationOpacity != value) { annotationOpacity = value; - dictionary!.setProperty( - PdfDictionaryProperties.ca, PdfNumber(annotationOpacity)); + dictionary!.setProperty(PdfDictionaryProperties.ca, PdfNumber(annotationOpacity)); } } @@ -561,8 +533,8 @@ class PdfAnnotationHelper { List? flags, bool? setAppearance) { dictionary!.beginSave = dictionaryBeginSave; - dictionary!.setProperty(PdfName(PdfDictionaryProperties.type), - PdfName(PdfDictionaryProperties.annot)); + dictionary! + .setProperty(PdfName(PdfDictionaryProperties.type), PdfName(PdfDictionaryProperties.annot)); if (page != null) { this.page = page; } @@ -571,8 +543,7 @@ class PdfAnnotationHelper { } if (annotText != null) { text = annotText; - dictionary!.setProperty( - PdfName(PdfDictionaryProperties.contents), PdfString(text)); + dictionary!.setProperty(PdfName(PdfDictionaryProperties.contents), PdfString(text)); } if (border != null) { this.border = border; @@ -617,11 +588,9 @@ class PdfAnnotationHelper { bool contains = false; PdfArray? annotation; if (page != null && - PdfPageHelper.getHelper(page!) - .dictionary! - .containsKey(PdfDictionaryProperties.annots)) { - annotation = PdfCrossTable.dereference(PdfPageHelper.getHelper(page!) - .dictionary![PdfDictionaryProperties.annots]) as PdfArray?; + PdfPageHelper.getHelper(page!).dictionary!.containsKey(PdfDictionaryProperties.annots)) { + annotation = PdfCrossTable.dereference( + PdfPageHelper.getHelper(page!).dictionary![PdfDictionaryProperties.annots]) as PdfArray?; if (annotation != null && annotation.elements.isNotEmpty && annotation.contains(annotation.elements[0]!)) { @@ -635,21 +604,17 @@ class PdfAnnotationHelper { void saveAnnotation() { final PdfDocument? document = PdfPageHelper.getHelper(page!).document; if (document != null && - PdfDocumentHelper.getHelper(document).conformanceLevel != - PdfConformanceLevel.none) { + PdfDocumentHelper.getHelper(document).conformanceLevel != PdfConformanceLevel.none) { if (base is PdfActionAnnotation && - PdfDocumentHelper.getHelper(document).conformanceLevel == - PdfConformanceLevel.a1b) { + PdfDocumentHelper.getHelper(document).conformanceLevel == PdfConformanceLevel.a1b) { throw ArgumentError( 'The specified annotation type is not supported by PDF/A1-B or PDF/A1-A standard documents.'); } //This is needed to attain specific PDF/A conformance. if (base is! PdfLinkAnnotation && !setAppearance && - (PdfDocumentHelper.getHelper(document).conformanceLevel == - PdfConformanceLevel.a2b || - PdfDocumentHelper.getHelper(document).conformanceLevel == - PdfConformanceLevel.a3b)) { + (PdfDocumentHelper.getHelper(document).conformanceLevel == PdfConformanceLevel.a2b || + PdfDocumentHelper.getHelper(document).conformanceLevel == PdfConformanceLevel.a3b)) { throw ArgumentError( "The appearance dictionary doesn't contain an entry. Enable setAppearance in PdfAnnotation class to overcome this error."); } @@ -659,22 +624,20 @@ class PdfAnnotationHelper { if (isLineBorder()) { dictionary!.setProperty(PdfDictionaryProperties.bs, border); } else { - dictionary! - .setProperty(PdfName(PdfDictionaryProperties.border), border); + dictionary!.setProperty(PdfName(PdfDictionaryProperties.border), border); } } if ((base is! PdfLinkAnnotation && base is! PdfTextWebLink) || - ((base is PdfLinkAnnotation || base is PdfTextWebLink) && - !isLoadedAnnotation)) { + ((base is PdfLinkAnnotation || base is PdfTextWebLink) && !isLoadedAnnotation)) { final PdfRectangle nativeRectangle = _obtainNativeRectangle(); if (annotationInnerColor != null && !annotationInnerColor!.isEmpty && PdfColorHelper.getHelper(annotationInnerColor!).alpha != 0.0) { - dictionary!.setProperty(PdfName(PdfDictionaryProperties.ic), - PdfColorHelper.toArray(annotationInnerColor!)); + dictionary!.setProperty( + PdfName(PdfDictionaryProperties.ic), PdfColorHelper.toArray(annotationInnerColor!)); } - dictionary!.setProperty(PdfName(PdfDictionaryProperties.rect), - PdfArray.fromRectangle(nativeRectangle)); + dictionary!.setProperty( + PdfName(PdfDictionaryProperties.rect), PdfArray.fromRectangle(nativeRectangle)); } } @@ -686,8 +649,8 @@ class PdfAnnotationHelper { if (page != null) { if (!PdfPageHelper.getHelper(page!).isLoadedPage) { final PdfSection section = PdfPageHelper.getHelper(page!).section!; - nativeRectangle.location = PdfSectionHelper.getHelper(section) - .pointToNativePdf(page!, nativeRectangle.location); + nativeRectangle.location = + PdfSectionHelper.getHelper(section).pointToNativePdf(page!, nativeRectangle.location); } else { size = page!.size; nativeRectangle.y = size.height - rectangle.bottom; @@ -698,10 +661,10 @@ class PdfAnnotationHelper { if (cropOrMediaBox.count > 2) { if ((cropOrMediaBox[0]! as PdfNumber).value != 0 || (cropOrMediaBox[1]! as PdfNumber).value != 0) { - nativeRectangle.x = nativeRectangle.x + - (cropOrMediaBox[0]! as PdfNumber).value!.toDouble(); - nativeRectangle.y = nativeRectangle.y + - (cropOrMediaBox[1]! as PdfNumber).value!.toDouble(); + nativeRectangle.x = + nativeRectangle.x + (cropOrMediaBox[0]! as PdfNumber).value!.toDouble(); + nativeRectangle.y = + nativeRectangle.y + (cropOrMediaBox[1]! as PdfNumber).value!.toDouble(); } } } @@ -712,11 +675,10 @@ class PdfAnnotationHelper { final PdfDictionary dictionary = PdfPageHelper.getHelper(page).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.cropBox)) { cropOrMediaBox = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.cropBox]) - as PdfArray?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.cropBox]) as PdfArray?; } else if (dictionary.containsKey(PdfDictionaryProperties.mediaBox)) { - cropOrMediaBox = PdfCrossTable.dereference( - dictionary[PdfDictionaryProperties.mediaBox]) as PdfArray?; + cropOrMediaBox = + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.mediaBox]) as PdfArray?; } return cropOrMediaBox; } @@ -727,15 +689,13 @@ class PdfAnnotationHelper { final PdfDocument? document = PdfPageHelper.getHelper(page!).document; if (!PdfPageHelper.getHelper(pdfPage).isLoadedPage) { if (document != null) { - final PdfCatalog catalog = - PdfDocumentHelper.getHelper(document).catalog; + final PdfCatalog catalog = PdfDocumentHelper.getHelper(document).catalog; catalog.beginSaveList ??= []; - final PdfGraphics graphics = - pdfPage.graphics; //Accessed for creating page content. + final PdfGraphics graphics = pdfPage.graphics; //Accessed for creating page content. ArgumentError.checkNotNull(graphics); if (dictionary!.containsKey(PdfDictionaryProperties.subtype)) { - final PdfName? name = dictionary! - .items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; + final PdfName? name = + dictionary!.items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; if (name != null) { if (name.name == PdfDictionaryProperties.text || name.name == PdfDictionaryProperties.square || @@ -755,11 +715,10 @@ class PdfAnnotationHelper { } } else { if (document != null) { - final PdfCatalog catalog = - PdfDocumentHelper.getHelper(document).catalog; + final PdfCatalog catalog = PdfDocumentHelper.getHelper(document).catalog; if (dictionary!.containsKey(PdfDictionaryProperties.subtype)) { - final PdfName? name = dictionary! - .items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; + final PdfName? name = + dictionary!.items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; catalog.beginSaveList ??= []; if (name != null) { if (name.name == PdfDictionaryProperties.circle || @@ -783,8 +742,7 @@ class PdfAnnotationHelper { } } if (page != null && !PdfPageHelper.getHelper(page!).isLoadedPage) { - dictionary!.setProperty( - PdfName(PdfDictionaryProperties.p), PdfReferenceHolder(page)); + dictionary!.setProperty(PdfName(PdfDictionaryProperties.p), PdfReferenceHolder(page)); } } @@ -792,8 +750,7 @@ class PdfAnnotationHelper { PdfRectangle _getBounds(PdfDictionary dictionary, PdfCrossTable crossTable) { PdfArray? array; if (dictionary.containsKey(PdfDictionaryProperties.rect)) { - array = crossTable.getObject(dictionary[PdfDictionaryProperties.rect]) - as PdfArray?; + array = crossTable.getObject(dictionary[PdfDictionaryProperties.rect]) as PdfArray?; } return array!.toRectangle(); } @@ -803,25 +760,22 @@ class PdfAnnotationHelper { final PdfAnnotationBorder border = PdfAnnotationBorder(); if (dictionary!.containsKey(PdfDictionaryProperties.border)) { final PdfArray? borderArray = - PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.border]) - as PdfArray?; + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.border]) as PdfArray?; if (borderArray != null && borderArray.count >= 2) { if (borderArray[0] is PdfNumber && borderArray[1] is PdfNumber && borderArray[2] is PdfNumber) { final double width = (borderArray[0]! as PdfNumber).value!.toDouble(); - final double hRadius = - (borderArray[1]! as PdfNumber).value!.toDouble(); - final double vRadius = - (borderArray[2]! as PdfNumber).value!.toDouble(); + final double hRadius = (borderArray[1]! as PdfNumber).value!.toDouble(); + final double vRadius = (borderArray[2]! as PdfNumber).value!.toDouble(); border.width = vRadius; border.horizontalRadius = width; border.verticalRadius = hRadius; } } } else if (dictionary!.containsKey(PdfDictionaryProperties.bs)) { - final PdfDictionary lbDic = crossTable - .getObject(dictionary![PdfDictionaryProperties.bs])! as PdfDictionary; + final PdfDictionary lbDic = + crossTable.getObject(dictionary![PdfDictionaryProperties.bs])! as PdfDictionary; if (lbDic.containsKey(PdfDictionaryProperties.w)) { final PdfNumber? value = lbDic[PdfDictionaryProperties.w] as PdfNumber?; if (value != null) { @@ -830,14 +784,12 @@ class PdfAnnotationHelper { } if (lbDic.containsKey(PdfDictionaryProperties.s)) { final PdfName bstr = - PdfCrossTable.dereference(lbDic[PdfDictionaryProperties.s])! - as PdfName; + PdfCrossTable.dereference(lbDic[PdfDictionaryProperties.s])! as PdfName; border.borderStyle = _getBorderStyle(bstr.name.toString()); } if (lbDic.containsKey(PdfDictionaryProperties.d)) { final PdfArray? dasharray = - PdfCrossTable.dereference(lbDic[PdfDictionaryProperties.d]) - as PdfArray?; + PdfCrossTable.dereference(lbDic[PdfDictionaryProperties.d]) as PdfArray?; if (dasharray != null) { final PdfNumber dashArray = dasharray[0]! as PdfNumber; final int dashArrayValue = dashArray.value!.toInt(); @@ -855,8 +807,8 @@ class PdfAnnotationHelper { String? _obtainText() { String tempText; if (dictionary!.containsKey(PdfDictionaryProperties.contents)) { - final PdfString? mText = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.contents]) as PdfString?; + final PdfString? mText = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.contents]) as PdfString?; if (mText != null) { textValue = mText.value.toString(); } @@ -894,10 +846,7 @@ class PdfAnnotationHelper { final PdfNumber? color1 = crossTable.getObject(colours[1]) as PdfNumber?; final PdfNumber? color2 = crossTable.getObject(colours[2]) as PdfNumber?; final PdfNumber? color3 = crossTable.getObject(colours[3]) as PdfNumber?; - if (color0 != null && - color1 != null && - color2 != null && - color3 != null) { + if (color0 != null && color1 != null && color2 != null && color3 != null) { //Convert the float color values into bytes final double cyan = color0.value! as double; final double magenta = color1.value! as double; @@ -931,19 +880,15 @@ class PdfAnnotationHelper { String _obtainAuthor() { String author = ''; if (dictionary!.containsKey(PdfDictionaryProperties.author)) { - final IPdfPrimitive? tempAuthor = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.author]); - if (tempAuthor != null && - tempAuthor is PdfString && - tempAuthor.value != null) { + final IPdfPrimitive? tempAuthor = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.author]); + if (tempAuthor != null && tempAuthor is PdfString && tempAuthor.value != null) { author = tempAuthor.value!; } } else if (dictionary!.containsKey(PdfDictionaryProperties.t)) { final IPdfPrimitive? tempAuthor = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.t]); - if (tempAuthor != null && - tempAuthor is PdfString && - tempAuthor.value != null) { + if (tempAuthor != null && tempAuthor is PdfString && tempAuthor.value != null) { author = tempAuthor.value!; } } @@ -954,19 +899,15 @@ class PdfAnnotationHelper { String _obtainSubject() { String subject = ''; if (dictionary!.containsKey(PdfDictionaryProperties.subject)) { - final IPdfPrimitive? tempSubject = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.subject]); - if (tempSubject != null && - tempSubject is PdfString && - tempSubject.value != null) { + final IPdfPrimitive? tempSubject = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.subject]); + if (tempSubject != null && tempSubject is PdfString && tempSubject.value != null) { subject = tempSubject.value!; } } else if (dictionary!.containsKey(PdfDictionaryProperties.subj)) { final IPdfPrimitive? tempSubject = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.subj]); - if (tempSubject != null && - tempSubject is PdfString && - tempSubject.value != null) { + if (tempSubject != null && tempSubject is PdfString && tempSubject.value != null) { subject = tempSubject.value!; } } @@ -977,8 +918,7 @@ class PdfAnnotationHelper { DateTime? _obtainModifiedDate() { if (dictionary!.containsKey(PdfDictionaryProperties.modificationDate) || dictionary!.containsKey(PdfDictionaryProperties.m)) { - PdfString? modifiedDate = - dictionary![PdfDictionaryProperties.modificationDate] as PdfString?; + PdfString? modifiedDate = dictionary![PdfDictionaryProperties.modificationDate] as PdfString?; modifiedDate ??= dictionary![PdfDictionaryProperties.m] as PdfString?; annotationModifiedDate = dictionary!.getDateTime(modifiedDate!); } @@ -997,16 +937,11 @@ class PdfAnnotationHelper { PdfColor color = PdfColor.empty; PdfArray? colours; if (dictionary!.containsKey(PdfDictionaryProperties.iC)) { - colours = - PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.iC]) - as PdfArray?; + colours = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.iC]) as PdfArray?; if (colours != null && colours.count > 0) { - final int red = - ((colours[0]! as PdfNumber).value! * 255).round().toUnsigned(8); - final int green = - ((colours[1]! as PdfNumber).value! * 255).round().toUnsigned(8); - final int blue = - ((colours[2]! as PdfNumber).value! * 255).round().toUnsigned(8); + final int red = ((colours[0]! as PdfNumber).value! * 255).round().toUnsigned(8); + final int green = ((colours[1]! as PdfNumber).value! * 255).round().toUnsigned(8); + final int blue = ((colours[2]! as PdfNumber).value! * 255).round().toUnsigned(8); color = PdfColor(red, green, blue); } } @@ -1024,45 +959,33 @@ class PdfAnnotationHelper { /// internal method void flattenPopup() { if (page != null && !isLoadedAnnotation) { - _flattenAnnotationPopups( - page!, color, bounds, border, author, subject, text); + _flattenAnnotationPopups(page!, color, bounds, border, author, subject, text); } } void _flattenAnnotationPopups(PdfPage page, PdfColor color, Rect annotBounds, PdfAnnotationBorder border, String author, String subject, String text) { - final Size clientSize = PdfPageHelper.getHelper(page).isLoadedPage - ? page.size - : page.getClientSize(); + final Size clientSize = + PdfPageHelper.getHelper(page).isLoadedPage ? page.size : page.getClientSize(); final double x = clientSize.width - 180; - final double y = (annotBounds.top + 142) < clientSize.height - ? annotBounds.top - : clientSize.height - 142; + final double y = + (annotBounds.top + 142) < clientSize.height ? annotBounds.top : clientSize.height - 142; Rect bounds = Rect.fromLTWH(x, y, 180, 142); // Draw annotation based on bounds if (dictionary![PdfDictionaryProperties.popup] != null) { final IPdfPrimitive? obj = dictionary![PdfDictionaryProperties.popup]; - final PdfDictionary? tempDictionary = - PdfCrossTable.dereference(obj) as PdfDictionary?; + final PdfDictionary? tempDictionary = PdfCrossTable.dereference(obj) as PdfDictionary?; if (tempDictionary != null) { - final PdfArray? rectValue = PdfCrossTable.dereference( - tempDictionary[PdfDictionaryProperties.rect]) as PdfArray?; - final PdfCrossTable? crosstable = - PdfPageHelper.getHelper(page).crossTable; + final PdfArray? rectValue = + PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.rect]) as PdfArray?; + final PdfCrossTable? crosstable = PdfPageHelper.getHelper(page).crossTable; if (rectValue != null) { - final PdfNumber left = - crosstable!.getReference(rectValue[0]) as PdfNumber; - final PdfNumber top = - crosstable.getReference(rectValue[1]) as PdfNumber; - final PdfNumber width = - crosstable.getReference(rectValue[2]) as PdfNumber; - final PdfNumber height = - crosstable.getReference(rectValue[3]) as PdfNumber; - bounds = Rect.fromLTWH( - left.value! as double, - top.value! as double, - width.value! - (left.value! as double), - height.value! - (top.value! as double)); + final PdfNumber left = crosstable!.getReference(rectValue[0]) as PdfNumber; + final PdfNumber top = crosstable.getReference(rectValue[1]) as PdfNumber; + final PdfNumber width = crosstable.getReference(rectValue[2]) as PdfNumber; + final PdfNumber height = crosstable.getReference(rectValue[3]) as PdfNumber; + bounds = Rect.fromLTWH(left.value! as double, top.value! as double, + width.value! - (left.value! as double), height.value! - (top.value! as double)); } } } @@ -1071,33 +994,28 @@ class PdfAnnotationHelper { double? trackingHeight = 0; final PdfBrush aBrush = PdfSolidBrush(_getForeColor(color)); if (author != '') { - final Map returnedValue = _drawAuthor(author, subject, - bounds, backBrush, aBrush, page, trackingHeight, border); + final Map returnedValue = + _drawAuthor(author, subject, bounds, backBrush, aBrush, page, trackingHeight, border); trackingHeight = returnedValue['height']; } else if (subject != '') { - final Rect titleRect = Rect.fromLTWH(bounds.left + borderWidth, - bounds.top + borderWidth, bounds.width - border.width, 40); + final Rect titleRect = Rect.fromLTWH( + bounds.left + borderWidth, bounds.top + borderWidth, bounds.width - border.width, 40); _saveGraphics(page, PdfBlendMode.hardLight); - page.graphics.drawRectangle( - pen: PdfPens.black, brush: backBrush, bounds: titleRect); + page.graphics.drawRectangle(pen: PdfPens.black, brush: backBrush, bounds: titleRect); page.graphics.restore(); - Rect contentRect = Rect.fromLTWH(titleRect.left + 11, titleRect.top, - titleRect.width, titleRect.height / 2); - contentRect = Rect.fromLTWH( - contentRect.left, - contentRect.top + contentRect.height - 2, - contentRect.width, - titleRect.height / 2); + Rect contentRect = + Rect.fromLTWH(titleRect.left + 11, titleRect.top, titleRect.width, titleRect.height / 2); + contentRect = Rect.fromLTWH(contentRect.left, contentRect.top + contentRect.height - 2, + contentRect.width, titleRect.height / 2); _saveGraphics(page, PdfBlendMode.normal); _drawSubject(subject, contentRect, page); page.graphics.restore(); trackingHeight = 40; } else { _saveGraphics(page, PdfBlendMode.hardLight); - final Rect titleRect = Rect.fromLTWH(bounds.left + borderWidth, - bounds.top + borderWidth, bounds.width - border.width, 20); - page.graphics.drawRectangle( - pen: PdfPens.black, brush: backBrush, bounds: titleRect); + final Rect titleRect = Rect.fromLTWH( + bounds.left + borderWidth, bounds.top + borderWidth, bounds.width - border.width, 20); + page.graphics.drawRectangle(pen: PdfPens.black, brush: backBrush, bounds: titleRect); trackingHeight = 20; page.graphics.restore(); } @@ -1107,23 +1025,18 @@ class PdfAnnotationHelper { bounds.width - border.width, bounds.height - (trackingHeight + border.width)); _saveGraphics(page, PdfBlendMode.hardLight); - page.graphics.drawRectangle( - pen: PdfPens.black, brush: PdfBrushes.white, bounds: cRect); - cRect = Rect.fromLTWH( - cRect.left + 11, cRect.top + 5, cRect.width - 22, cRect.height); + page.graphics.drawRectangle(pen: PdfPens.black, brush: PdfBrushes.white, bounds: cRect); + cRect = Rect.fromLTWH(cRect.left + 11, cRect.top + 5, cRect.width - 22, cRect.height); page.graphics.restore(); _saveGraphics(page, PdfBlendMode.normal); - page.graphics.drawString( - text, PdfStandardFont(PdfFontFamily.helvetica, 10.5), + page.graphics.drawString(text, PdfStandardFont(PdfFontFamily.helvetica, 10.5), brush: PdfBrushes.black, bounds: cRect); page.graphics.restore(); } void _drawSubject(String subject, Rect bounds, PdfPage page) { page.graphics.drawString( - subject, - PdfStandardFont(PdfFontFamily.helvetica, 10.5, - style: PdfFontStyle.bold), + subject, PdfStandardFont(PdfFontFamily.helvetica, 10.5, style: PdfFontStyle.bold), brush: PdfBrushes.black, bounds: bounds, format: PdfStringFormat(lineAlignment: PdfVerticalAlignment.middle)); @@ -1131,65 +1044,44 @@ class PdfAnnotationHelper { void _saveGraphics(PdfPage page, PdfBlendMode mode) { page.graphics.save(); - PdfGraphicsHelper.getHelper(page.graphics) - .applyTransparency(0.8, 8.0, mode); + PdfGraphicsHelper.getHelper(page.graphics).applyTransparency(0.8, 8.0, mode); } PdfColor _getForeColor(PdfColor c) { - return (((c.r + c.b + c.g) / 3) > 128) - ? PdfColor(0, 0, 0) - : PdfColor(255, 255, 255); - } - - Map _drawAuthor( - String author, - String subject, - Rect bounds, - PdfBrush backBrush, - PdfBrush aBrush, - PdfPage page, - double? trackingHeight, - PdfAnnotationBorder border) { + return (((c.r + c.b + c.g) / 3) > 128) ? PdfColor(0, 0, 0) : PdfColor(255, 255, 255); + } + + Map _drawAuthor(String author, String subject, Rect bounds, PdfBrush backBrush, + PdfBrush aBrush, PdfPage page, double? trackingHeight, PdfAnnotationBorder border) { final double borderWidth = border.width / 2; final PdfRectangle titleRect = PdfRectangle.fromRect(Rect.fromLTWH( - bounds.left + borderWidth, - bounds.top + borderWidth, - bounds.width - border.width, - 20)); + bounds.left + borderWidth, bounds.top + borderWidth, bounds.width - border.width, 20)); if (subject != '') { titleRect.height += 20; trackingHeight = titleRect.height; _saveGraphics(page, PdfBlendMode.hardLight); - page.graphics.drawRectangle( - pen: PdfPens.black, brush: backBrush, bounds: titleRect.rect); + page.graphics.drawRectangle(pen: PdfPens.black, brush: backBrush, bounds: titleRect.rect); page.graphics.restore(); - Rect contentRect = Rect.fromLTWH( - titleRect.x + 11, titleRect.y, titleRect.width, titleRect.height / 2); + Rect contentRect = + Rect.fromLTWH(titleRect.x + 11, titleRect.y, titleRect.width, titleRect.height / 2); _saveGraphics(page, PdfBlendMode.normal); page.graphics.drawString( - author, - PdfStandardFont(PdfFontFamily.helvetica, 10.5, - style: PdfFontStyle.bold), + author, PdfStandardFont(PdfFontFamily.helvetica, 10.5, style: PdfFontStyle.bold), brush: aBrush, bounds: contentRect, format: PdfStringFormat(lineAlignment: PdfVerticalAlignment.middle)); - contentRect = Rect.fromLTWH( - contentRect.left, - contentRect.top + contentRect.height - 2, - contentRect.width, - titleRect.height / 2); + contentRect = Rect.fromLTWH(contentRect.left, contentRect.top + contentRect.height - 2, + contentRect.width, titleRect.height / 2); _drawSubject(subject, contentRect, page); page.graphics.restore(); } else { _saveGraphics(page, PdfBlendMode.hardLight); - page.graphics.drawRectangle( - pen: PdfPens.black, brush: backBrush, bounds: titleRect.rect); + page.graphics.drawRectangle(pen: PdfPens.black, brush: backBrush, bounds: titleRect.rect); page.graphics.restore(); - final Rect contentRect = Rect.fromLTWH( - titleRect.x + 11, titleRect.y, titleRect.width, titleRect.height); + final Rect contentRect = + Rect.fromLTWH(titleRect.x + 11, titleRect.y, titleRect.width, titleRect.height); _saveGraphics(page, PdfBlendMode.normal); - page.graphics.drawString( - author, PdfStandardFont(PdfFontFamily.helvetica, 10.5), + page.graphics.drawString(author, PdfStandardFont(PdfFontFamily.helvetica, 10.5), brush: aBrush, bounds: contentRect, format: PdfStringFormat(lineAlignment: PdfVerticalAlignment.middle)); @@ -1202,13 +1094,10 @@ class PdfAnnotationHelper { /// internal method Rect calculateTemplateBounds( Rect bounds, PdfPage? page, PdfTemplate? template, bool isNormalMatrix) { - double x = bounds.left, - y = bounds.top, - width = bounds.width, - height = bounds.height; + double x = bounds.left, y = bounds.top, width = bounds.width, height = bounds.height; if (page != null) { - final int graphicsRotation = _obtainGraphicsRotation( - PdfGraphicsHelper.getHelper(page.graphics).matrix); + final int graphicsRotation = + _obtainGraphicsRotation(PdfGraphicsHelper.getHelper(page.graphics).matrix); if (graphicsRotation == 0 && !isNormalMatrix) { x = bounds.left; y = bounds.top + bounds.height - bounds.width; @@ -1221,8 +1110,7 @@ class PdfAnnotationHelper { int _obtainGraphicsRotation(PdfTransformationMatrix matrix) { int angle = 0; - final double radians = - atan2(matrix.matrix.elements[2], matrix.matrix.elements[0]); + final double radians = atan2(matrix.matrix.elements[2], matrix.matrix.elements[0]); angle = (radians * 180 / pi).round(); switch (angle) { case -90: @@ -1277,13 +1165,8 @@ class PdfAnnotationHelper { } /// internal method - PdfRectangle calculateLineBounds( - List linePoints, - int leaderLineExt, - int leaderLineValue, - int leaderOffset, - PdfArray lineStyle, - double borderLength) { + PdfRectangle calculateLineBounds(List linePoints, int leaderLineExt, int leaderLineValue, + int leaderOffset, PdfArray lineStyle, double borderLength) { PdfRectangle tempBounds = PdfRectangle.fromRect(bounds); final PdfPath path = PdfPath(); if (linePoints.length == 4) { @@ -1323,16 +1206,16 @@ class PdfAnnotationHelper { linePoints[3] = offsetPoint2[1].toInt(); } - final List startingPoint = getAxisValue( - x1y1, lineAngle + 90, (leaderLine + leaderOffset).toDouble()); - final List endingPoint = getAxisValue( - x2y2, lineAngle + 90, (leaderLine + leaderOffset).toDouble()); + final List startingPoint = + getAxisValue(x1y1, lineAngle + 90, (leaderLine + leaderOffset).toDouble()); + final List endingPoint = + getAxisValue(x2y2, lineAngle + 90, (leaderLine + leaderOffset).toDouble()); - final List beginLineLeader = getAxisValue(x1y1, lineAngle + 90, - (leaderLineExt + leaderLine + leaderOffset).toDouble()); + final List beginLineLeader = getAxisValue( + x1y1, lineAngle + 90, (leaderLineExt + leaderLine + leaderOffset).toDouble()); - final List endLineLeader = getAxisValue(x2y2, lineAngle + 90, - (leaderLineExt + leaderLine + leaderOffset).toDouble()); + final List endLineLeader = getAxisValue( + x2y2, lineAngle + 90, (leaderLineExt + leaderLine + leaderOffset).toDouble()); final List stylePoint = []; @@ -1386,8 +1269,7 @@ class PdfAnnotationHelper { final List widthX = List.filled(2, 0); final List heightY = List.filled(2, 0); - if ((lineAngle >= 45 && lineAngle <= 135) || - (lineAngle >= 225 && lineAngle <= 315)) { + if ((lineAngle >= 45 && lineAngle <= 135) || (lineAngle >= 225 && lineAngle <= 315)) { widthX[0] = stylePoint[0].y; heightY[0] = stylePoint[0].x; widthX[1] = stylePoint[1].y; @@ -1400,12 +1282,10 @@ class PdfAnnotationHelper { } final double height = max(heightY[0], heightY[1]); - if (startingPoint[0] == - [startingPoint[0], endingPoint[0]].reduce(min)) { + if (startingPoint[0] == [startingPoint[0], endingPoint[0]].reduce(min)) { startingPoint[0] -= widthX[0] * borderLength; endingPoint[0] += widthX[1] * borderLength; - startingPoint[0] = - [startingPoint[0], linePoints[0].toDouble()].reduce(min); + startingPoint[0] = [startingPoint[0], linePoints[0].toDouble()].reduce(min); startingPoint[0] = min(startingPoint[0], beginLineLeader[0]); endingPoint[0] = max(endingPoint[0], linePoints[2].toDouble()); endingPoint[0] = max(endingPoint[0], endLineLeader[0]); @@ -1432,8 +1312,8 @@ class PdfAnnotationHelper { endingPoint[1] = min(endingPoint[1], linePoints[3].toDouble()); endingPoint[1] = min(endingPoint[1], endLineLeader[1]); } - path.addLine(Offset(startingPoint[0], startingPoint[1]), - Offset(endingPoint[0], endingPoint[1])); + path.addLine( + Offset(startingPoint[0], startingPoint[1]), Offset(endingPoint[0], endingPoint[1])); tempBounds = PdfPathHelper.getHelper(path).getBoundsInternal(); } return tempBounds; @@ -1499,22 +1379,15 @@ class PdfAnnotationHelper { switch (lineEndingStyle.name) { case 'Square': { - final Rect rect = Rect.fromLTWH( - axisPoint[0] - (3 * borderLength), - -(axisPoint[1] + (3 * borderLength)), - 6 * borderLength, - 6 * borderLength); - graphics! - .drawRectangle(bounds: rect, pen: borderPen, brush: backBrush); + final Rect rect = Rect.fromLTWH(axisPoint[0] - (3 * borderLength), + -(axisPoint[1] + (3 * borderLength)), 6 * borderLength, 6 * borderLength); + graphics!.drawRectangle(bounds: rect, pen: borderPen, brush: backBrush); } break; case 'Circle': { - final Rect rect = Rect.fromLTWH( - axisPoint[0] - (3 * borderLength), - -(axisPoint[1] + (3 * borderLength)), - 6 * borderLength, - 6 * borderLength); + final Rect rect = Rect.fromLTWH(axisPoint[0] - (3 * borderLength), + -(axisPoint[1] + (3 * borderLength)), 6 * borderLength, 6 * borderLength); graphics!.drawEllipse(rect, pen: borderPen, brush: backBrush); } break; @@ -1533,16 +1406,12 @@ class PdfAnnotationHelper { } else { startPoint = getAxisValue(axisPoint, angle, -borderLength); } - final List point1 = - getAxisValue(startPoint, angle + arraowAngle, length); - final List point2 = - getAxisValue(startPoint, angle - arraowAngle, length); + final List point1 = getAxisValue(startPoint, angle + arraowAngle, length); + final List point2 = getAxisValue(startPoint, angle - arraowAngle, length); final PdfPath path = PdfPath(pen: borderPen); - path.addLine(Offset(startPoint[0], -startPoint[1]), - Offset(point1[0], -point1[1])); - path.addLine(Offset(startPoint[0], -startPoint[1]), - Offset(point2[0], -point2[1])); + path.addLine(Offset(startPoint[0], -startPoint[1]), Offset(point1[0], -point1[1])); + path.addLine(Offset(startPoint[0], -startPoint[1]), Offset(point2[0], -point2[1])); graphics!.drawPath(path, pen: borderPen); } break; @@ -1561,10 +1430,8 @@ class PdfAnnotationHelper { } else { startPoint = getAxisValue(axisPoint, angle, -borderLength); } - final List point1 = - getAxisValue(startPoint, angle + arraowAngle, length); - final List point2 = - getAxisValue(startPoint, angle - arraowAngle, length); + final List point1 = getAxisValue(startPoint, angle + arraowAngle, length); + final List point2 = getAxisValue(startPoint, angle - arraowAngle, length); final List points = [ Offset(startPoint[0], -startPoint[1]), Offset(point1[0], -point1[1]), @@ -1588,16 +1455,12 @@ class PdfAnnotationHelper { } else { startPoint = getAxisValue(axisPoint, angle, borderLength); } - final List point1 = - getAxisValue(startPoint, angle + arraowAngle, length); - final List point2 = - getAxisValue(startPoint, angle - arraowAngle, length); + final List point1 = getAxisValue(startPoint, angle + arraowAngle, length); + final List point2 = getAxisValue(startPoint, angle - arraowAngle, length); final PdfPath path = PdfPath(pen: borderPen); - path.addLine(Offset(startPoint[0], -startPoint[1]), - Offset(point1[0], -point1[1])); - path.addLine(Offset(startPoint[0], -startPoint[1]), - Offset(point2[0], -point2[1])); + path.addLine(Offset(startPoint[0], -startPoint[1]), Offset(point1[0], -point1[1])); + path.addLine(Offset(startPoint[0], -startPoint[1]), Offset(point2[0], -point2[1])); graphics!.drawPath(path, pen: borderPen); } break; @@ -1617,10 +1480,8 @@ class PdfAnnotationHelper { startPoint = getAxisValue(axisPoint, angle, borderLength); } - final List point1 = - getAxisValue(startPoint, angle + arraowAngle, length); - final List point2 = - getAxisValue(startPoint, angle - arraowAngle, length); + final List point1 = getAxisValue(startPoint, angle + arraowAngle, length); + final List point2 = getAxisValue(startPoint, angle - arraowAngle, length); final List points = [ Offset(startPoint[0], -startPoint[1]), Offset(point1[0], -point1[1]), @@ -1632,14 +1493,12 @@ class PdfAnnotationHelper { case 'Slash': { final double length = 9 * borderLength; - final List point1 = - getAxisValue(axisPoint, angle + 60, length); - final List point2 = - getAxisValue(axisPoint, angle - 120, length); - graphics!.drawLine(borderPen!, Offset(axisPoint[0], -axisPoint[1]), - Offset(point1[0], -point1[1])); - graphics.drawLine(borderPen, Offset(axisPoint[0], -axisPoint[1]), - Offset(point2[0], -point2[1])); + final List point1 = getAxisValue(axisPoint, angle + 60, length); + final List point2 = getAxisValue(axisPoint, angle - 120, length); + graphics!.drawLine( + borderPen!, Offset(axisPoint[0], -axisPoint[1]), Offset(point1[0], -point1[1])); + graphics.drawLine( + borderPen, Offset(axisPoint[0], -axisPoint[1]), Offset(point2[0], -point2[1])); } break; case 'Diamond': @@ -1661,13 +1520,11 @@ class PdfAnnotationHelper { case 'Butt': { final double length = 3 * borderLength; - final List point1 = - getAxisValue(axisPoint, angle + 90, length); - final List point2 = - getAxisValue(axisPoint, angle - 90, length); + final List point1 = getAxisValue(axisPoint, angle + 90, length); + final List point2 = getAxisValue(axisPoint, angle - 90, length); - graphics!.drawLine(borderPen!, Offset(point1[0], -point1[1]), - Offset(point2[0], -point2[1])); + graphics! + .drawLine(borderPen!, Offset(point1[0], -point1[1]), Offset(point2[0], -point2[1])); } break; } @@ -1679,8 +1536,7 @@ class PdfAnnotationHelper { bool isRotatedMatrix = false; if (dictionary.containsKey(PdfDictionaryProperties.matrix)) { final PdfArray? matrix = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.matrix]) - as PdfArray?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.matrix]) as PdfArray?; if (matrix != null && matrix.count > 3) { if ((matrix[0]! as PdfNumber).value == 1 && (matrix[1]! as PdfNumber).value == 0 && @@ -1696,8 +1552,7 @@ class PdfAnnotationHelper { } /// Returns the boolean if the template matrix is valid or not - bool isValidTemplateMatrix( - PdfDictionary dictionary, Offset bounds, PdfTemplate template) { + bool isValidTemplateMatrix(PdfDictionary dictionary, Offset bounds, PdfTemplate template) { bool isValidMatrix = true; Offset point = bounds; if (dictionary.containsKey(PdfDictionaryProperties.matrix)) { @@ -1756,19 +1611,17 @@ class PdfAnnotationHelper { if (opacity < 1) { page!.graphics.setTransparency(opacity); } - final Rect bound = - calculateTemplateBounds(bounds, page, appearance, isNormalMatrix); + final Rect bound = calculateTemplateBounds(bounds, page, appearance, isNormalMatrix); page!.graphics.drawPdfTemplate(appearance, bound.topLeft, bounds.size); page!.graphics.restore(state); page!.annotations.remove(base); } /// Draw CloudStye to the Shapes - void drawCloudStyle(PdfGraphics graphics, PdfBrush? brush, PdfPen? pen, - double radius, double overlap, List points, bool isAppearance) { + void drawCloudStyle(PdfGraphics graphics, PdfBrush? brush, PdfPen? pen, double radius, + double overlap, List points, bool isAppearance) { if (_isClockWise(points)) { - points = List.generate( - points.length, (int i) => points[points.length - (i + 1)]); + points = List.generate(points.length, (int i) => points[points.length - (i + 1)]); } // Create a list of circles @@ -1785,8 +1638,7 @@ class PdfAnnotationHelper { final double d = circleOverlap; for (double a = 0; a + 0.1 * d < len; a += d) { final _CloudStyleArc cur = _CloudStyleArc(); - cur.point = - Offset(previousPoint.dx + a * dx, previousPoint.dy + a * dy); + cur.point = Offset(previousPoint.dx + a * dx, previousPoint.dy + a * dy); circles.add(cur); } previousPoint = currentPoint; @@ -1809,12 +1661,10 @@ class PdfAnnotationHelper { PdfPath path = PdfPath(); for (int i = 0; i < circles.length; i++) { final _CloudStyleArc curr = circles[i]; - final double angle = curr.startAngle < 0 - ? ((curr.startAngle * -1) % 360) * -1 - : curr.startAngle % 360; - final double angle1 = curr.endAngle < 0 - ? ((curr.endAngle * -1) % 360) * -1 - : curr.endAngle % 360; + final double angle = + curr.startAngle < 0 ? ((curr.startAngle * -1) % 360) * -1 : curr.startAngle % 360; + final double angle1 = + curr.endAngle < 0 ? ((curr.endAngle * -1) % 360) * -1 : curr.endAngle % 360; double sweepAngel = 0; if (angle > 0 && angle1 < 0) { sweepAngel = (180 - angle) + (180 - (angle1 < 0 ? -angle1 : angle1)); @@ -1842,8 +1692,7 @@ class PdfAnnotationHelper { } curr.endAngle = sweepAngel; path.addArc( - Rect.fromLTWH(curr.point.dx - radius, curr.point.dy - radius, - 2 * radius, 2 * radius), + Rect.fromLTWH(curr.point.dx - radius, curr.point.dy - radius, 2 * radius, 2 * radius), angle, sweepAngel); } @@ -1856,13 +1705,9 @@ class PdfAnnotationHelper { -PdfPathHelper.getHelper(path).points[i].dy)); } } else { - PdfPathHelper.getHelper(pdfPath) - .points - .addAll(PdfPathHelper.getHelper(path).points); + PdfPathHelper.getHelper(pdfPath).points.addAll(PdfPathHelper.getHelper(path).points); } - PdfPathHelper.getHelper(pdfPath) - .pathTypes - .addAll(PdfPathHelper.getHelper(path).pathTypes); + PdfPathHelper.getHelper(pdfPath).pathTypes.addAll(PdfPathHelper.getHelper(path).pathTypes); if (brush != null) { graphics.drawPath(pdfPath, brush: brush); } @@ -1871,8 +1716,7 @@ class PdfAnnotationHelper { for (int i = 0; i < circles.length; i++) { final _CloudStyleArc curr = circles[i]; path.addArc( - Rect.fromLTWH(curr.point.dx - radius, curr.point.dy - radius, - 2 * radius, 2 * radius), + Rect.fromLTWH(curr.point.dx - radius, curr.point.dy - radius, 2 * radius, 2 * radius), curr.startAngle, curr.endAngle + incise); } @@ -1885,13 +1729,9 @@ class PdfAnnotationHelper { -PdfPathHelper.getHelper(path).points[i].dy)); } } else { - PdfPathHelper.getHelper(pdfPath) - .points - .addAll(PdfPathHelper.getHelper(path).points); + PdfPathHelper.getHelper(pdfPath).points.addAll(PdfPathHelper.getHelper(path).points); } - PdfPathHelper.getHelper(pdfPath) - .pathTypes - .addAll(PdfPathHelper.getHelper(path).pathTypes); + PdfPathHelper.getHelper(pdfPath).pathTypes.addAll(PdfPathHelper.getHelper(path).pathTypes); graphics.drawPath(pdfPath, pen: pen); } @@ -1918,8 +1758,7 @@ class PdfAnnotationHelper { } final double radian = atan2(dy, dx); final double cosvalue = acos(a); - return Offset((radian - cosvalue) * (180 / pi), - (pi + radian + cosvalue) * (180 / pi)); + return Offset((radian - cosvalue) * (180 / pi), (pi + radian + cosvalue) * (180 / pi)); } // Searches the in parents. @@ -1932,8 +1771,7 @@ class PdfAnnotationHelper { primitive = crossTable!.getObject(dic[value]); } else { if (dic.containsKey(PdfDictionaryProperties.parent)) { - dic = crossTable!.getObject(dic[PdfDictionaryProperties.parent]) - as PdfDictionary?; + dic = crossTable!.getObject(dic[PdfDictionaryProperties.parent]) as PdfDictionary?; } else { dic = null; } @@ -1943,8 +1781,8 @@ class PdfAnnotationHelper { } /// internal method - static IPdfPrimitive? getValue(PdfDictionary dictionary, - PdfCrossTable? crossTable, String value, bool inheritable) { + static IPdfPrimitive? getValue( + PdfDictionary dictionary, PdfCrossTable? crossTable, String value, bool inheritable) { IPdfPrimitive? primitive; if (dictionary.containsKey(value)) { primitive = crossTable!.getObject(dictionary[value]); @@ -1986,8 +1824,7 @@ class PdfAnnotationHelper { isSaveComplete = true; } if (!PdfAnnotationHelper.getHelper(annotation).flatten) { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); if (helper.flag != null) { int flagValue = 0; for (int i = 0; i < helper.flag!.length; i++) { @@ -2006,9 +1843,7 @@ class PdfAnnotationHelper { if (dictionary!.containsKey(PdfDictionaryProperties.f)) { final IPdfPrimitive? annotFlags = getValue(dictionary!, crossTable, PdfDictionaryProperties.f, false); - if (annotFlags != null && - annotFlags is PdfNumber && - annotFlags.value != null) { + if (annotFlags != null && annotFlags is PdfNumber && annotFlags.value != null) { return annotFlags.value!.toInt(); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_document_link_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_document_link_annotation.dart index 8ab185eab..b2e99c095 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_document_link_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_document_link_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -55,8 +55,7 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { this.destination = destination; } - PdfDocumentLinkAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable) { + PdfDocumentLinkAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable) { _helper = PdfDocumentLinkAnnotationHelper._(this, dictionary, crossTable); } @@ -84,10 +83,9 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { /// //Dispose the document. /// document.dispose(); /// ``` - PdfDestination? get destination => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _obtainDestination() - : _helper.destination; + PdfDestination? get destination => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _obtainDestination() + : _helper.destination; set destination(PdfDestination? value) { if (value != null) { if (value != _helper.destination) { @@ -122,29 +120,24 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { // Gets the destination of the document link annotation PdfDestination? _obtainDestination() { PdfDestination? dest; - final PdfDictionary dictionary = - PdfAnnotationHelper.getHelper(this).dictionary!; - final PdfCrossTable crossTable = - PdfAnnotationHelper.getHelper(this).crossTable; + final PdfDictionary dictionary = PdfAnnotationHelper.getHelper(this).dictionary!; + final PdfCrossTable crossTable = PdfAnnotationHelper.getHelper(this).crossTable; if (dictionary.containsKey(PdfDictionaryProperties.dest)) { - final IPdfPrimitive? obj = - crossTable.getObject(dictionary[PdfDictionaryProperties.dest]); + final IPdfPrimitive? obj = crossTable.getObject(dictionary[PdfDictionaryProperties.dest]); PdfArray? array; if (obj is PdfArray) { array = obj; } else if (crossTable.document != null && PdfDocumentHelper.getHelper(crossTable.document!).isLoadedDocument) { if (obj is PdfName || obj is PdfString) { - array = PdfDocumentHelper.getHelper(crossTable.document!) - .getNamedDestination(obj!); + array = PdfDocumentHelper.getHelper(crossTable.document!).getNamedDestination(obj!); } } PdfPage page; if (array != null && array[0] is PdfReferenceHolder) { - final PdfDictionary? dic = crossTable - .getObject(array[0]! as PdfReferenceHolder) as PdfDictionary?; - page = PdfPageCollectionHelper.getHelper(crossTable.document!.pages) - .getPage(dic); + final PdfDictionary? dic = + crossTable.getObject(array[0]! as PdfReferenceHolder) as PdfDictionary?; + page = PdfPageCollectionHelper.getHelper(crossTable.document!.pages).getPage(dic); final PdfName? mode = array[1] as PdfName?; if (mode != null) { if (mode.name == 'XYZ') { @@ -160,10 +153,8 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { if (array[4] is PdfNumber) { zoom = array[4]! as PdfNumber; } - final double topValue = - (top == null) ? 0 : page.size.height - (top.value!.toDouble()); - final double leftValue = - (left == null) ? 0 : left.value!.toDouble(); + final double topValue = (top == null) ? 0 : page.size.height - (top.value!.toDouble()); + final double leftValue = (left == null) ? 0 : left.value!.toDouble(); dest = PdfDestination(page, Offset(leftValue, topValue)); if (zoom != null) { dest.zoom = zoom.value!.toDouble(); @@ -186,16 +177,15 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { final double top = (array[3]! as PdfNumber).value!.toDouble(); final double width = (array[4]! as PdfNumber).value!.toDouble(); final double height = (array[5]! as PdfNumber).value!.toDouble(); - dest = PdfDestinationHelper.getDestination( - page, PdfRectangle(left, top, width, height)); + dest = + PdfDestinationHelper.getDestination(page, PdfRectangle(left, top, width, height)); dest.mode = PdfDestinationMode.fitR; } } } } } else if (dictionary.containsKey(PdfDictionaryProperties.a)) { - IPdfPrimitive obj = - crossTable.getObject(dictionary[PdfDictionaryProperties.a])!; + IPdfPrimitive obj = crossTable.getObject(dictionary[PdfDictionaryProperties.a])!; final PdfDictionary destDic = obj as PdfDictionary; obj = destDic[PdfDictionaryProperties.d]!; if (obj is PdfReferenceHolder) { @@ -207,8 +197,7 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { } else if (crossTable.document != null && PdfDocumentHelper.getHelper(crossTable.document!).isLoadedDocument) { if (obj is PdfName || obj is PdfString) { - array = PdfDocumentHelper.getHelper(crossTable.document!) - .getNamedDestination(obj); + array = PdfDocumentHelper.getHelper(crossTable.document!).getNamedDestination(obj); } } if (array != null && array[0] is PdfReferenceHolder) { @@ -217,8 +206,7 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { final IPdfPrimitive? primitiveObj = PdfCrossTable.dereference(holder); final PdfDictionary? dic = primitiveObj as PdfDictionary?; if (dic != null) { - page = PdfPageCollectionHelper.getHelper(crossTable.document!.pages) - .getPage(dic); + page = PdfPageCollectionHelper.getHelper(crossTable.document!.pages).getPage(dic); } if (page != null) { final PdfName mode = array[1]! as PdfName; @@ -227,8 +215,7 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { if (array[2] is PdfNumber) { top = array[2]! as PdfNumber; } - final double topValue = - (top == null) ? 0 : page.size.height - (top.value!.toDouble()); + final double topValue = (top == null) ? 0 : page.size.height - (top.value!.toDouble()); dest = PdfDestination(page, Offset(0, topValue)); dest.mode = PdfDestinationMode.fitH; } else if (mode.name == 'XYZ') { @@ -244,10 +231,8 @@ class PdfDocumentLinkAnnotation extends PdfLinkAnnotation { if (array[4] is PdfNumber) { zoom = array[4]! as PdfNumber; } - final double topValue = - (top == null) ? 0 : page.size.height - (top.value!.toDouble()); - final double leftValue = - (left == null) ? 0 : left.value!.toDouble(); + final double topValue = (top == null) ? 0 : page.size.height - (top.value!.toDouble()); + final double leftValue = (left == null) ? 0 : left.value!.toDouble(); dest = PdfDestination(page, Offset(leftValue, topValue)); if (zoom != null) { dest.zoom = zoom.value!.toDouble(); @@ -283,8 +268,8 @@ class PdfDocumentLinkAnnotationHelper extends PdfLinkAnnotationHelper { /// internal constructor PdfDocumentLinkAnnotationHelper(this.documentLinkHelper, Rect bounds) : super(documentLinkHelper, bounds); - PdfDocumentLinkAnnotationHelper._(this.documentLinkHelper, - PdfDictionary dictionary, PdfCrossTable crossTable) + PdfDocumentLinkAnnotationHelper._( + this.documentLinkHelper, PdfDictionary dictionary, PdfCrossTable crossTable) : super.load(documentLinkHelper, dictionary, crossTable); /// internal field @@ -300,21 +285,19 @@ class PdfDocumentLinkAnnotationHelper extends PdfLinkAnnotationHelper { /// internal method void save() { if (destination != null) { - PdfAnnotationHelper.getHelper(base).dictionary!.setProperty( - PdfName(PdfDictionaryProperties.dest), - IPdfWrapper.getElement(destination!)); + PdfAnnotationHelper.getHelper(base) + .dictionary! + .setProperty(PdfName(PdfDictionaryProperties.dest), IPdfWrapper.getElement(destination!)); } } /// internal method - static PdfDocumentLinkAnnotation load( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfDocumentLinkAnnotation load(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfDocumentLinkAnnotation._(dictionary, crossTable); } /// internal method - static PdfDocumentLinkAnnotationHelper getHelper( - PdfDocumentLinkAnnotation annotation) { + static PdfDocumentLinkAnnotationHelper getHelper(PdfDocumentLinkAnnotation annotation) { return annotation._helper; } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_ellipse_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_ellipse_annotation.dart index 73ef55a58..0b8d454de 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_ellipse_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_ellipse_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/pdf_annotation_border.dart'; @@ -66,8 +66,7 @@ class PdfEllipseAnnotation extends PdfAnnotation { setAppearance: setAppearance); } - PdfEllipseAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + PdfEllipseAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { _helper = PdfEllipseAnnotationHelper._(this, dictionary, crossTable); this.text = text; } @@ -136,12 +135,11 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { opacity: opacity, flags: flags, setAppearance: setAppearance); - dictionary!.setProperty(PdfDictionaryProperties.subtype, - PdfName(PdfDictionaryProperties.circle)); + dictionary! + .setProperty(PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.circle)); } - PdfEllipseAnnotationHelper._( - this.annotation, PdfDictionary dictionary, PdfCrossTable crossTable) + PdfEllipseAnnotationHelper._(this.annotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super(annotation) { initializeExistingAnnotation(dictionary, crossTable); } @@ -151,10 +149,8 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { /// internal method void save() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); - if (PdfAnnotationCollectionHelper.getHelper(annotation.page!.annotations) - .flatten) { + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); + if (PdfAnnotationCollectionHelper.getHelper(annotation.page!.annotations).flatten) { helper.flatten = true; } final PdfAppearance? pdfAppearance = helper.appearance; @@ -175,15 +171,14 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { } else { if (appearance != null) { annotation.appearance.normal = appearance; - helper.dictionary!.setProperty(PdfDictionaryProperties.ap, - PdfReferenceHolder(annotation.appearance)); + helper.dictionary! + .setProperty(PdfDictionaryProperties.ap, PdfReferenceHolder(annotation.appearance)); } } } if (!helper.flatten && !isLoadedAnnotation) { helper.saveAnnotation(); - helper.dictionary! - .setProperty(PdfDictionaryProperties.bs, annotation.border); + helper.dictionary!.setProperty(PdfDictionaryProperties.bs, annotation.border); } if (helper.flattenPopups) { helper.flattenPopup(); @@ -191,32 +186,29 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { } void _flattenAnnotation(PdfPage? page, PdfTemplate? appearance) { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); if (helper.isLoadedAnnotation) { - final bool isContainsAP = - helper.dictionary!.containsKey(PdfDictionaryProperties.ap); + final bool isContainsAP = helper.dictionary!.containsKey(PdfDictionaryProperties.ap); if (appearance == null) { if (isContainsAP) { - PdfDictionary? appearanceDictionary = PdfCrossTable.dereference( - helper.dictionary![PdfDictionaryProperties.ap]) as PdfDictionary?; + PdfDictionary? appearanceDictionary = + PdfCrossTable.dereference(helper.dictionary![PdfDictionaryProperties.ap]) + as PdfDictionary?; if (appearanceDictionary != null) { - appearanceDictionary = PdfCrossTable.dereference( - appearanceDictionary[PdfDictionaryProperties.n]) - as PdfDictionary?; + appearanceDictionary = + PdfCrossTable.dereference(appearanceDictionary[PdfDictionaryProperties.n]) + as PdfDictionary?; if (appearanceDictionary != null) { - final PdfStream appearanceStream = - appearanceDictionary as PdfStream; + final PdfStream appearanceStream = appearanceDictionary as PdfStream; appearance = PdfTemplateHelper.fromPdfStream(appearanceStream); - final bool isNormalMatrix = - helper.validateTemplateMatrix(appearanceDictionary); + final bool isNormalMatrix = helper.validateTemplateMatrix(appearanceDictionary); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } else { annotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } @@ -225,53 +217,47 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { annotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } } else { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { page!.graphics.save(); - final Rect rectangle = helper.calculateTemplateBounds( - annotation.bounds, page, appearance, true); + final Rect rectangle = + helper.calculateTemplateBounds(annotation.bounds, page, appearance, true); if (annotation.opacity < 1) { page.graphics.setTransparency(annotation.opacity); } - page.graphics.drawPdfTemplate( - appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); + page.graphics + .drawPdfTemplate(appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); page.annotations.remove(annotation); page.graphics.restore(); } } PdfTemplate? _createAppearance() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); final bool isLoadedAnnotation = helper.isLoadedAnnotation; if (isLoadedAnnotation && !annotation.setAppearance) { return null; } final PdfRectangle nativeRectangle = PdfRectangle(0, 0, annotation.bounds.width, annotation.bounds.height); - final PdfTemplate template = - PdfTemplateHelper.fromRect(nativeRectangle.rect); - PdfAnnotationHelper.setMatrixToZeroRotation( - PdfTemplateHelper.getHelper(template).content); - if (isLoadedAnnotation && - helper.dictionary!.containsKey(PdfDictionaryProperties.be)) { + final PdfTemplate template = PdfTemplateHelper.fromRect(nativeRectangle.rect); + PdfAnnotationHelper.setMatrixToZeroRotation(PdfTemplateHelper.getHelper(template).content); + if (isLoadedAnnotation && helper.dictionary!.containsKey(PdfDictionaryProperties.be)) { PdfTemplateHelper.getHelper(template).writeTransformation = false; } final PaintParams paintParams = PaintParams(); final double borderWidth = annotation.border.width / 2; - final PdfPen mBorderPen = - PdfPen(annotation.color, width: annotation.border.width); - if (annotation.border.width > 0 && - PdfColorHelper.getHelper(annotation.color).alpha != 0) { + final PdfPen mBorderPen = PdfPen(annotation.color, width: annotation.border.width); + if (annotation.border.width > 0 && PdfColorHelper.getHelper(annotation.color).alpha != 0) { paintParams.borderPen = mBorderPen; } PdfBrush? mBackBrush; @@ -286,8 +272,7 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { graphics.setTransparency(annotation.opacity); } if (isLoadedAnnotation) { - final PdfRectangle rectangle = - _obtainStyle(mBorderPen, nativeRectangle, borderWidth); + final PdfRectangle rectangle = _obtainStyle(mBorderPen, nativeRectangle, borderWidth); if (helper.dictionary!.containsKey(PdfDictionaryProperties.be)) { _drawAppearance(rectangle, borderWidth, graphics, paintParams); } else { @@ -298,14 +283,11 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { brush: paintParams.backBrush); } } else { - final Rect rect = Rect.fromLTWH(nativeRectangle.left, nativeRectangle.top, - nativeRectangle.width, nativeRectangle.height); + final Rect rect = Rect.fromLTWH( + nativeRectangle.left, nativeRectangle.top, nativeRectangle.width, nativeRectangle.height); graphics!.drawEllipse( - Rect.fromLTWH( - rect.left + borderWidth, - rect.top + borderWidth, - rect.width - annotation.border.width, - rect.height - annotation.border.width), + Rect.fromLTWH(rect.left + borderWidth, rect.top + borderWidth, + rect.width - annotation.border.width, rect.height - annotation.border.width), pen: paintParams.borderPen, brush: paintParams.backBrush); } @@ -316,24 +298,18 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { } // Obtain Style for annotation - PdfRectangle _obtainStyle( - PdfPen mBorderPen, PdfRectangle rectangle, double borderWidth) { - final PdfDictionary dictionary = - PdfAnnotationHelper.getHelper(annotation).dictionary!; + PdfRectangle _obtainStyle(PdfPen mBorderPen, PdfRectangle rectangle, double borderWidth) { + final PdfDictionary dictionary = PdfAnnotationHelper.getHelper(annotation).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.bs)) { final PdfDictionary? bSDictionary = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.bs]) - as PdfDictionary?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.bs]) as PdfDictionary?; - if (bSDictionary != null && - bSDictionary.containsKey(PdfDictionaryProperties.d)) { + if (bSDictionary != null && bSDictionary.containsKey(PdfDictionaryProperties.d)) { final PdfArray dashPatternArray = - PdfCrossTable.dereference(bSDictionary[PdfDictionaryProperties.d])! - as PdfArray; + PdfCrossTable.dereference(bSDictionary[PdfDictionaryProperties.d])! as PdfArray; final List dashPattern = []; for (int i = 0; i < dashPatternArray.count; i++) { - dashPattern.add( - (dashPatternArray.elements[i]! as PdfNumber).value!.toDouble()); + dashPattern.add((dashPatternArray.elements[i]! as PdfNumber).value!.toDouble()); } mBorderPen.dashStyle = PdfDashStyle.dash; mBorderPen.dashPattern = dashPattern; @@ -342,8 +318,7 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { if (!PdfAnnotationHelper.getHelper(annotation).isBounds && dictionary[PdfDictionaryProperties.rd] != null) { final PdfArray? mRdArray = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.rd]) - as PdfArray?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.rd]) as PdfArray?; if (mRdArray != null) { final PdfNumber num1 = mRdArray.elements[0]! as PdfNumber; final PdfNumber num2 = mRdArray.elements[1]! as PdfNumber; @@ -363,8 +338,8 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { } // Draw appearance for annotation - void _drawAppearance(PdfRectangle rectangle, double borderWidth, - PdfGraphics? graphics, PaintParams paintParams) { + void _drawAppearance( + PdfRectangle rectangle, double borderWidth, PdfGraphics? graphics, PaintParams paintParams) { final PdfPath graphicsPath = PdfPath(); graphicsPath.addEllipse(Rect.fromLTWH( rectangle.x + borderWidth, @@ -375,10 +350,9 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { if (PdfAnnotationHelper.getHelper(annotation) .dictionary! .containsKey(PdfDictionaryProperties.rd)) { - final PdfArray? rdArray = PdfCrossTable.dereference( - PdfAnnotationHelper.getHelper(annotation) - .dictionary! - .items![PdfName(PdfDictionaryProperties.rd)]) as PdfArray?; + final PdfArray? rdArray = PdfCrossTable.dereference(PdfAnnotationHelper.getHelper(annotation) + .dictionary! + .items![PdfName(PdfDictionaryProperties.rd)]) as PdfArray?; if (rdArray != null) { radius = (rdArray.elements[0]! as PdfNumber).value as double?; } @@ -410,17 +384,10 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { endPointList.add(Offset(rect.right, rect.top + (rect.height / 2))); for (int i = 0; i < controlPointList.length; i++) { - _createBezier( - startPointList[i], controlPointList[i], endPointList[i], points); + _createBezier(startPointList[i], controlPointList[i], endPointList[i], points); } PdfAnnotationHelper.getHelper(annotation).drawCloudStyle( - graphics!, - paintParams.backBrush, - paintParams.borderPen, - radius, - 0.833, - points, - false); + graphics!, paintParams.backBrush, paintParams.borderPen, radius, 0.833, points, false); startPointList.clear(); controlPointList.clear(); endPointList.clear(); @@ -435,32 +402,29 @@ class PdfEllipseAnnotationHelper extends PdfAnnotationHelper { } // Create bezier curve - void _createBezier( - Offset ctrl1, Offset ctrl2, Offset ctrl3, List bezierPoints) { + void _createBezier(Offset ctrl1, Offset ctrl2, Offset ctrl3, List bezierPoints) { bezierPoints.add(ctrl1); // add the first control point _populateBezierPoints(ctrl1, ctrl2, ctrl3, 0, bezierPoints); bezierPoints.add(ctrl3); // add the last control point } // calculate bezier points - void _populateBezierPoints(Offset ctrl1, Offset ctrl2, Offset ctrl3, - int currentIteration, List bezierPoints) { + void _populateBezierPoints( + Offset ctrl1, Offset ctrl2, Offset ctrl3, int currentIteration, List bezierPoints) { if (currentIteration < 2) { //calculate next mid points - final Offset midPoint1 = - Offset((ctrl1.dx + ctrl2.dx) / 2, (ctrl1.dy + ctrl2.dy) / 2); - final Offset midPoint2 = - Offset((ctrl2.dx + ctrl3.dx) / 2, (ctrl2.dy + ctrl3.dy) / 2); - final Offset midPoint3 = Offset( - (midPoint1.dx + midPoint2.dx) / 2, (midPoint1.dy + midPoint2.dy) / 2); + final Offset midPoint1 = Offset((ctrl1.dx + ctrl2.dx) / 2, (ctrl1.dy + ctrl2.dy) / 2); + final Offset midPoint2 = Offset((ctrl2.dx + ctrl3.dx) / 2, (ctrl2.dy + ctrl3.dy) / 2); + final Offset midPoint3 = + Offset((midPoint1.dx + midPoint2.dx) / 2, (midPoint1.dy + midPoint2.dy) / 2); //the next control point currentIteration++; - _populateBezierPoints(ctrl1, midPoint1, midPoint3, currentIteration, - bezierPoints); //left branch + _populateBezierPoints( + ctrl1, midPoint1, midPoint3, currentIteration, bezierPoints); //left branch bezierPoints.add(midPoint3); //add the next control point - _populateBezierPoints(midPoint3, midPoint2, ctrl3, currentIteration, - bezierPoints); //right branch + _populateBezierPoints( + midPoint3, midPoint2, ctrl3, currentIteration, bezierPoints); //right branch } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_line_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_line_annotation.dart index 82ea30a31..c5ee536cf 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_line_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_line_annotation.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/pdf_annotation_border.dart'; @@ -95,8 +95,7 @@ class PdfLineAnnotation extends PdfAnnotation { } } - PdfLineAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String annotText) { + PdfLineAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String annotText) { _helper = PdfLineAnnotationHelper._(this, dictionary, crossTable); text = annotText; } @@ -128,10 +127,9 @@ class PdfLineAnnotation extends PdfAnnotation { } /// Gets the line points of the annotation. - List get linePoints => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._obtainLinePoints() - : _helper.points; + List get linePoints => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._obtainLinePoints() + : _helper.points; /// Sets the line points of the annotation. set linePoints(List value) { @@ -139,16 +137,14 @@ class PdfLineAnnotation extends PdfAnnotation { _helper.points = value; _helper.linePoints = PdfArray(_helper.points); if (helper.isLoadedAnnotation) { - helper.dictionary! - .setProperty(PdfDictionaryProperties.l, _helper.linePoints); + helper.dictionary!.setProperty(PdfDictionaryProperties.l, _helper.linePoints); } } /// Gets the line intent of the annotation. - PdfLineIntent get lineIntent => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._obtainLineIntent() - : _lineIntent; + PdfLineIntent get lineIntent => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._obtainLineIntent() + : _lineIntent; /// Sets the line intent of the annotation. set lineIntent(PdfLineIntent value) { @@ -156,8 +152,7 @@ class PdfLineAnnotation extends PdfAnnotation { if (!helper.isLoadedAnnotation) { _lineIntent = value; } else { - helper.dictionary!.setName( - PdfName(PdfDictionaryProperties.it), helper.getEnumName(value)); + helper.dictionary!.setName(PdfName(PdfDictionaryProperties.it), helper.getEnumName(value)); } } @@ -177,10 +172,9 @@ class PdfLineAnnotation extends PdfAnnotation { } /// Gets the leader line extension. - int get leaderLineExt => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._obtainLeaderExt() - : _leaderLineExt; + int get leaderLineExt => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._obtainLeaderExt() + : _leaderLineExt; /// Sets the leader line extension. set leaderLineExt(int value) { @@ -193,10 +187,9 @@ class PdfLineAnnotation extends PdfAnnotation { } /// Gets the begin line style of the annotation. - PdfLineEndingStyle get beginLineStyle => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._getLineStyle(0) - : _beginLineStyle; + PdfLineEndingStyle get beginLineStyle => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._getLineStyle(0) + : _beginLineStyle; /// Sets the end line style of the annotation. set beginLineStyle(PdfLineEndingStyle value) { @@ -210,19 +203,16 @@ class PdfLineAnnotation extends PdfAnnotation { } else { lineStyle.elements.removeAt(0); } - lineStyle.insert( - 0, - PdfName(helper.getEnumName( - _helper._getLineStyle(helper.getEnumName(value.toString()))))); + lineStyle.insert(0, + PdfName(helper.getEnumName(_helper._getLineStyle(helper.getEnumName(value.toString()))))); helper.dictionary!.setProperty(PdfDictionaryProperties.le, lineStyle); } } /// Gets the end line style of the annotation. - PdfLineEndingStyle get endLineStyle => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._getLineStyle(1) - : _endLineStyle; + PdfLineEndingStyle get endLineStyle => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._getLineStyle(1) + : _endLineStyle; /// Sets the end line style of the annotation. set endLineStyle(PdfLineEndingStyle value) { @@ -236,19 +226,16 @@ class PdfLineAnnotation extends PdfAnnotation { } else { lineStyle.elements.removeAt(1); } - lineStyle.insert( - 1, - PdfName(helper.getEnumName( - _helper._getLineStyle(helper.getEnumName(value.toString()))))); + lineStyle.insert(1, + PdfName(helper.getEnumName(_helper._getLineStyle(helper.getEnumName(value.toString()))))); helper.dictionary!.setProperty(PdfDictionaryProperties.le, lineStyle); } } /// Gets the caption type of the annotation. - PdfLineCaptionType get captionType => - PdfAnnotationHelper.getHelper(this).isLoadedAnnotation - ? _helper._obtainCaptionType() - : _captionType; + PdfLineCaptionType get captionType => PdfAnnotationHelper.getHelper(this).isLoadedAnnotation + ? _helper._obtainCaptionType() + : _captionType; /// Sets the caption type of the annotation. set captionType(PdfLineCaptionType value) { @@ -258,8 +245,8 @@ class PdfLineAnnotation extends PdfAnnotation { } else { helper.dictionary!.setProperty( PdfDictionaryProperties.cp, - PdfName(helper.getEnumName( - _helper._getCaptionType(helper.getEnumName(value.toString()))))); + PdfName( + helper.getEnumName(_helper._getCaptionType(helper.getEnumName(value.toString()))))); } } @@ -273,8 +260,7 @@ class PdfLineAnnotation extends PdfAnnotation { final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(this); if (helper.textValue != value) { helper.textValue = value; - helper.dictionary! - .setString(PdfDictionaryProperties.contents, helper.textValue); + helper.dictionary!.setString(PdfDictionaryProperties.contents, helper.textValue); } } @@ -316,8 +302,7 @@ class PdfLineAnnotation extends PdfAnnotation { /// [PdfLineAnnotation] helper class PdfLineAnnotationHelper extends PdfAnnotationHelper { /// internal constructor - PdfLineAnnotationHelper( - this.lineAnnotation, List linePoints, String text, + PdfLineAnnotationHelper(this.lineAnnotation, List linePoints, String text, {PdfColor? color, PdfColor? innerColor, PdfAnnotationBorder? border, @@ -341,11 +326,9 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { setAppearance: setAppearance); this.linePoints = PdfArray(linePoints); points = linePoints; - dictionary!.setProperty( - PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.line)); + dictionary!.setProperty(PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.line)); } - PdfLineAnnotationHelper._( - this.lineAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) + PdfLineAnnotationHelper._(this.lineAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super(lineAnnotation) { initializeExistingAnnotation(dictionary, crossTable); } @@ -376,11 +359,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { /// internal method void save() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); - if (PdfAnnotationCollectionHelper.getHelper( - lineAnnotation.page!.annotations) - .flatten) { + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); + if (PdfAnnotationCollectionHelper.getHelper(lineAnnotation.page!.annotations).flatten) { helper.flatten = true; } if (helper.flatten || lineAnnotation.setAppearance) { @@ -394,8 +374,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } else { if (appearance != null) { lineAnnotation.appearance.normal = appearance; - helper.dictionary!.setProperty(PdfDictionaryProperties.ap, - PdfReferenceHolder(lineAnnotation.appearance)); + helper.dictionary!.setProperty( + PdfDictionaryProperties.ap, PdfReferenceHolder(lineAnnotation.appearance)); } } } @@ -409,18 +389,14 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } void _savePdfLineDictionary() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); helper.saveAnnotation(); lineStyle = PdfArray(); if (lineStyle!.elements.isNotEmpty) { - lineStyle!.insert( - 0, PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); - lineStyle! - .insert(1, PdfName(helper.getEnumName(lineAnnotation.endLineStyle))); + lineStyle!.insert(0, PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); + lineStyle!.insert(1, PdfName(helper.getEnumName(lineAnnotation.endLineStyle))); } else { - lineStyle! - .add(PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); + lineStyle!.add(PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); lineStyle!.add(PdfName(helper.getEnumName(lineAnnotation.endLineStyle))); } final PdfDictionary dictionary = helper.dictionary!; @@ -440,58 +416,50 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { dictionary.setProperty(PdfDictionaryProperties.bs, lineAnnotation.border); if (!lineAnnotation.innerColor.isEmpty && PdfColorHelper.getHelper(lineAnnotation.innerColor).alpha != 0) { - dictionary.setProperty(PdfDictionaryProperties.ic, - PdfColorHelper.toArray(lineAnnotation.innerColor)); + dictionary.setProperty( + PdfDictionaryProperties.ic, PdfColorHelper.toArray(lineAnnotation.innerColor)); } - dictionary[PdfDictionaryProperties.c] = - PdfColorHelper.toArray(lineAnnotation.color); - - dictionary.setProperty(PdfDictionaryProperties.it, - PdfName(helper.getEnumName(lineAnnotation.lineIntent))); + dictionary[PdfDictionaryProperties.c] = PdfColorHelper.toArray(lineAnnotation.color); dictionary.setProperty( - PdfDictionaryProperties.lle, PdfNumber(lineAnnotation.leaderLineExt)); + PdfDictionaryProperties.it, PdfName(helper.getEnumName(lineAnnotation.lineIntent))); - dictionary.setProperty(PdfDictionaryProperties.ll, PdfNumber(leaderLine)); + dictionary.setProperty(PdfDictionaryProperties.lle, PdfNumber(lineAnnotation.leaderLineExt)); - dictionary.setProperty(PdfDictionaryProperties.cp, - PdfName(helper.getEnumName(lineAnnotation.captionType))); + dictionary.setProperty(PdfDictionaryProperties.ll, PdfNumber(leaderLine)); dictionary.setProperty( - PdfDictionaryProperties.cap, PdfBoolean(lineAnnotation.lineCaption)); + PdfDictionaryProperties.cp, PdfName(helper.getEnumName(lineAnnotation.captionType))); + + dictionary.setProperty(PdfDictionaryProperties.cap, PdfBoolean(lineAnnotation.lineCaption)); - dictionary.setProperty(PdfDictionaryProperties.rect, - PdfArray.fromRectangle(_obtainLineBounds())); + dictionary.setProperty( + PdfDictionaryProperties.rect, PdfArray.fromRectangle(_obtainLineBounds())); } void _flattenAnnotation(PdfPage? page, PdfTemplate? appearance) { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); final PdfDictionary dictionary = helper.dictionary!; if (helper.isLoadedAnnotation) { - final bool isContainsAP = - dictionary.containsKey(PdfDictionaryProperties.ap); + final bool isContainsAP = dictionary.containsKey(PdfDictionaryProperties.ap); if (isContainsAP && appearance == null) { PdfDictionary? appearanceDictionary = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ap]) - as PdfDictionary?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ap]) as PdfDictionary?; if (appearanceDictionary != null) { - appearanceDictionary = PdfCrossTable.dereference( - appearanceDictionary[PdfDictionaryProperties.n]) - as PdfDictionary?; + appearanceDictionary = + PdfCrossTable.dereference(appearanceDictionary[PdfDictionaryProperties.n]) + as PdfDictionary?; if (appearanceDictionary != null) { - final PdfStream appearanceStream = - appearanceDictionary as PdfStream; + final PdfStream appearanceStream = appearanceDictionary as PdfStream; appearance = PdfTemplateHelper.fromPdfStream(appearanceStream); - final bool isNormalMatrix = - helper.validateTemplateMatrix(appearanceDictionary); + final bool isNormalMatrix = helper.validateTemplateMatrix(appearanceDictionary); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } else { lineAnnotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } @@ -500,45 +468,42 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { lineAnnotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance!).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance!).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { page!.graphics.save(); - final Rect rectangle = helper.calculateTemplateBounds( - lineAnnotation.bounds, page, appearance, true); + final Rect rectangle = + helper.calculateTemplateBounds(lineAnnotation.bounds, page, appearance, true); if (lineAnnotation.opacity < 1) { page.graphics.setTransparency(lineAnnotation.opacity); } - page.graphics.drawPdfTemplate( - appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); + page.graphics + .drawPdfTemplate(appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); page.annotations.remove(lineAnnotation); page.graphics.restore(); } } PdfTemplate? _createAppearance() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); final bool isLoadedAnnotation = helper.isLoadedAnnotation; if (isLoadedAnnotation && !lineAnnotation.setAppearance) { return null; } final Rect nativeRectangle = _obtainLineBounds().rect; final PdfTemplate template = PdfTemplateHelper.fromRect(nativeRectangle); - PdfAnnotationHelper.setMatrixToZeroRotation( - PdfTemplateHelper.getHelper(template).content); + PdfAnnotationHelper.setMatrixToZeroRotation(PdfTemplateHelper.getHelper(template).content); PdfTemplateHelper.getHelper(template).writeTransformation = false; final PaintParams paintParams = PaintParams(); final PdfGraphics? graphics = template.graphics; - final PdfPen mBorderPen = - PdfPen(lineAnnotation.color, width: lineAnnotation.border.width); + final PdfPen mBorderPen = PdfPen(lineAnnotation.color, width: lineAnnotation.border.width); if (lineAnnotation.border.borderStyle == PdfBorderStyle.dashed) { mBorderPen.dashStyle = PdfDashStyle.dash; } else if (lineAnnotation.border.borderStyle == PdfBorderStyle.dot) { @@ -546,14 +511,12 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } paintParams.borderPen = mBorderPen; paintParams.foreBrush = PdfSolidBrush(lineAnnotation.color); - final PdfFont mFont = PdfStandardFont( - PdfFontFamily.helvetica, isLoadedAnnotation ? 10 : 9, + final PdfFont mFont = PdfStandardFont(PdfFontFamily.helvetica, isLoadedAnnotation ? 10 : 9, style: PdfFontStyle.regular); final PdfStringFormat format = PdfStringFormat(); format.alignment = PdfTextAlignment.center; format.lineAlignment = PdfVerticalAlignment.middle; - final double lineWidth = - mFont.measureString(lineAnnotation.text, format: format).width; + final double lineWidth = mFont.measureString(lineAnnotation.text, format: format).width; final List linePoints = _obtainLinePoints(); if (linePoints.length == 4) { final double x1 = linePoints[0].toDouble(); @@ -581,34 +544,25 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } final List x1y1 = [x1, y1]; final List x2y2 = [x2, y2]; - final double line = leadLine + - (isLoadedAnnotation ? _obtainLeaderOffset().toDouble() : 0); - final List startingPoint = - helper.getAxisValue(x1y1, lineAngle + 90, line); - final List endingPoint = - helper.getAxisValue(x2y2, lineAngle + 90, line); + final double line = leadLine + (isLoadedAnnotation ? _obtainLeaderOffset().toDouble() : 0); + final List startingPoint = helper.getAxisValue(x1y1, lineAngle + 90, line); + final List endingPoint = helper.getAxisValue(x2y2, lineAngle + 90, line); final double lineDistance = sqrt( - pow(endingPoint[0] - startingPoint[0], 2) + - pow(endingPoint[1] - startingPoint[1], 2)); - final double centerWidth = - lineDistance / 2 - ((lineWidth / 2) + lineAnnotation.border.width); - final List middlePoint1 = - helper.getAxisValue(startingPoint, angle, centerWidth); - final List middlePoint2 = - helper.getAxisValue(endingPoint, angle + 180, centerWidth); + pow(endingPoint[0] - startingPoint[0], 2) + pow(endingPoint[1] - startingPoint[1], 2)); + final double centerWidth = lineDistance / 2 - ((lineWidth / 2) + lineAnnotation.border.width); + final List middlePoint1 = helper.getAxisValue(startingPoint, angle, centerWidth); + final List middlePoint2 = helper.getAxisValue(endingPoint, angle + 180, centerWidth); List lineStartingPoint; List lineEndingPoint; if (lineAnnotation.beginLineStyle == PdfLineEndingStyle.openArrow || lineAnnotation.beginLineStyle == PdfLineEndingStyle.closedArrow) { - lineStartingPoint = helper.getAxisValue( - startingPoint, angle, lineAnnotation.border.width); + lineStartingPoint = helper.getAxisValue(startingPoint, angle, lineAnnotation.border.width); } else { lineStartingPoint = startingPoint; } if (lineAnnotation.endLineStyle == PdfLineEndingStyle.openArrow || lineAnnotation.endLineStyle == PdfLineEndingStyle.closedArrow) { - lineEndingPoint = helper.getAxisValue( - endingPoint, angle, -lineAnnotation.border.width); + lineEndingPoint = helper.getAxisValue(endingPoint, angle, -lineAnnotation.border.width); } else { lineEndingPoint = endingPoint; } @@ -617,21 +571,13 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { graphics!.save(); graphics.setTransparency(lineAnnotation.opacity); } - if (lineAnnotation.text.isEmpty || - caption == 'Top' || - !lineAnnotation.lineCaption) { - graphics!.drawLine( - mBorderPen, - Offset(lineStartingPoint[0], -lineStartingPoint[1]), + if (lineAnnotation.text.isEmpty || caption == 'Top' || !lineAnnotation.lineCaption) { + graphics!.drawLine(mBorderPen, Offset(lineStartingPoint[0], -lineStartingPoint[1]), Offset(lineEndingPoint[0], -lineEndingPoint[1])); } else { - graphics!.drawLine( - mBorderPen, - Offset(lineStartingPoint[0], -lineStartingPoint[1]), + graphics!.drawLine(mBorderPen, Offset(lineStartingPoint[0], -lineStartingPoint[1]), Offset(middlePoint1[0], -middlePoint1[1])); - graphics.drawLine( - mBorderPen, - Offset(lineEndingPoint[0], -lineEndingPoint[1]), + graphics.drawLine(mBorderPen, Offset(lineEndingPoint[0], -lineEndingPoint[1]), Offset(middlePoint2[0], -middlePoint2[1])); } if (lineAnnotation.opacity < 1) { @@ -640,20 +586,18 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { //Set begin and end line style. final PdfBrush backBrush = PdfSolidBrush(lineAnnotation.innerColor); final PdfArray lineStyle = PdfArray(); - lineStyle.insert( - 0, PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); - lineStyle.insert( - 1, PdfName(helper.getEnumName(lineAnnotation.endLineStyle))); + lineStyle.insert(0, PdfName(helper.getEnumName(lineAnnotation.beginLineStyle))); + lineStyle.insert(1, PdfName(helper.getEnumName(lineAnnotation.endLineStyle))); final double borderLength = lineAnnotation.border.width; - helper.setLineEndingStyles(startingPoint, endingPoint, graphics, angle, - mBorderPen, backBrush, lineStyle, borderLength); + helper.setLineEndingStyles(startingPoint, endingPoint, graphics, angle, mBorderPen, backBrush, + lineStyle, borderLength); //Set leader extension. - final List beginLineExt = helper.getAxisValue(startingPoint, - lineAngle + 90, lineAnnotation.leaderLineExt.toDouble()); + final List beginLineExt = helper.getAxisValue( + startingPoint, lineAngle + 90, lineAnnotation.leaderLineExt.toDouble()); graphics.drawLine(mBorderPen, Offset(startingPoint[0], -startingPoint[1]), Offset(beginLineExt[0], -beginLineExt[1])); - final List endLineExt = helper.getAxisValue( - endingPoint, lineAngle + 90, lineAnnotation.leaderLineExt.toDouble()); + final List endLineExt = + helper.getAxisValue(endingPoint, lineAngle + 90, lineAnnotation.leaderLineExt.toDouble()); graphics.drawLine(mBorderPen, Offset(endingPoint[0], -endingPoint[1]), Offset(endLineExt[0], -endLineExt[1])); //Set leader line @@ -661,15 +605,13 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { helper.getAxisValue(startingPoint, lineAngle - 90, leadLine); graphics.drawLine(mBorderPen, Offset(startingPoint[0], -startingPoint[1]), Offset(beginLeaderLine[0], -beginLeaderLine[1])); - final List endLeaderLine = - helper.getAxisValue(endingPoint, lineAngle - 90, leadLine); + final List endLeaderLine = helper.getAxisValue(endingPoint, lineAngle - 90, leadLine); graphics.drawLine(mBorderPen, Offset(endingPoint[0], -endingPoint[1]), Offset(endLeaderLine[0], -endLeaderLine[1])); //Set caption Type. if (lineAnnotation.lineCaption) { final double midpoint = lineDistance / 2; - final List centerPoint = - helper.getAxisValue(startingPoint, angle, midpoint); + final List centerPoint = helper.getAxisValue(startingPoint, angle, midpoint); final List captionPosition = _getCaptionPosition(caption, centerPoint, angle, mFont); graphics.translateTransform(captionPosition[0], -captionPosition[1]); @@ -679,8 +621,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } } if (isLoadedAnnotation) { - helper.dictionary!.setProperty(PdfDictionaryProperties.rect, - PdfArray.fromRectangle(_obtainLineBounds())); + helper.dictionary! + .setProperty(PdfDictionaryProperties.rect, PdfArray.fromRectangle(_obtainLineBounds())); } if (!isLoadedAnnotation && helper.flatten) { final double pageHeight = lineAnnotation.page!.size.height; @@ -688,9 +630,7 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { if (lineAnnotation.page != null) { lineAnnotation.bounds = Rect.fromLTWH( nativeRectangle.left - margins!.left, - pageHeight - - (nativeRectangle.top + nativeRectangle.height) - - margins.top, + pageHeight - (nativeRectangle.top + nativeRectangle.height) - margins.top, nativeRectangle.width, nativeRectangle.height); } else { @@ -707,11 +647,10 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { List _getCaptionPosition( String caption, List centerPoint, double angle, PdfFont font) { List captionPosition = List.filled(2, 0); - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); if (helper.isLoadedAnnotation) { - final bool isContainsMeasure = helper.dictionary!.items! - .containsKey(PdfName(PdfDictionaryProperties.measure)); + final bool isContainsMeasure = + helper.dictionary!.items!.containsKey(PdfName(PdfDictionaryProperties.measure)); final double length = caption == 'Top' ? isContainsMeasure ? 2 * font.height @@ -721,8 +660,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { : font.height / 2; captionPosition = helper.getAxisValue(centerPoint, angle + 90, length); } else { - captionPosition = helper.getAxisValue(centerPoint, angle + 90, - caption == 'Top' ? font.height : font.height / 2); + captionPosition = helper.getAxisValue( + centerPoint, angle + 90, caption == 'Top' ? font.height : font.height / 2); } return captionPosition; } @@ -730,11 +669,9 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { // Gets leader line of the lineAnnotation. int _obtainLeaderLine() { int lLine = 0; - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); if (helper.dictionary!.containsKey(PdfDictionaryProperties.ll)) { - final PdfNumber ll = - helper.dictionary![PdfDictionaryProperties.ll]! as PdfNumber; + final PdfNumber ll = helper.dictionary![PdfDictionaryProperties.ll]! as PdfNumber; lLine = ll.value!.toInt(); } return lLine; @@ -743,12 +680,10 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { // Gets the line intent of the annotation. PdfLineIntent _obtainLineIntent() { PdfLineIntent lineintentValue = PdfLineIntent.lineArrow; - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); if (helper.dictionary!.containsKey(PdfDictionaryProperties.it)) { - final PdfName lineintent = helper.crossTable - .getObject(helper.dictionary![PdfDictionaryProperties.it])! - as PdfName; + final PdfName lineintent = + helper.crossTable.getObject(helper.dictionary![PdfDictionaryProperties.it])! as PdfName; lineintentValue = _getLineIntentText(lineintent.name.toString()); } return lineintentValue; @@ -783,9 +718,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { if (PdfAnnotationHelper.getHelper(lineAnnotation) .dictionary! .containsKey(PdfDictionaryProperties.l)) { - linePoints = PdfCrossTable.dereference( - PdfAnnotationHelper.getHelper(lineAnnotation) - .dictionary![PdfDictionaryProperties.l]) as PdfArray?; + linePoints = PdfCrossTable.dereference(PdfAnnotationHelper.getHelper(lineAnnotation) + .dictionary![PdfDictionaryProperties.l]) as PdfArray?; if (linePoints != null) { points = []; // ignore: prefer_final_in_for_each @@ -874,8 +808,7 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { PdfRectangle _obtainLineBounds() { PdfRectangle bounds = PdfRectangle.fromRect(lineAnnotation.bounds); - if (points.length == 4 || - PdfAnnotationHelper.getHelper(lineAnnotation).isLoadedAnnotation) { + if (points.length == 4 || PdfAnnotationHelper.getHelper(lineAnnotation).isLoadedAnnotation) { final List lPoints = _obtainLinePoints(); if (lPoints.length == 4) { final PdfArray lineStyle = PdfArray(); @@ -892,8 +825,7 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { lineStyle.add(PdfName(lineAnnotation.beginLineStyle.toString())); lineStyle.add(PdfName(lineAnnotation.endLineStyle.toString())); } - bounds = PdfAnnotationHelper.getHelper(lineAnnotation) - .isLoadedAnnotation + bounds = PdfAnnotationHelper.getHelper(lineAnnotation).isLoadedAnnotation ? PdfAnnotationHelper.getHelper(lineAnnotation).calculateLineBounds( lPoints, lineAnnotation.leaderLineExt, @@ -908,8 +840,8 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { 0, lineStyle, lineAnnotation.border.width); - bounds = PdfRectangle(bounds.left - 8, bounds.top - 8, - bounds.width + 2 * 8, bounds.height + 2 * 8); + bounds = PdfRectangle( + bounds.left - 8, bounds.top - 8, bounds.width + 2 * 8, bounds.height + 2 * 8); } } return bounds; @@ -931,12 +863,10 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { // Gets line style of the annotation. PdfArray? _obtainLineStyle() { PdfArray? array; - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(lineAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(lineAnnotation); if (helper.dictionary!.containsKey(PdfDictionaryProperties.le)) { - array = helper.crossTable - .getObject(helper.dictionary![PdfDictionaryProperties.le]) - as PdfArray?; + array = + helper.crossTable.getObject(helper.dictionary![PdfDictionaryProperties.le]) as PdfArray?; } return array; } @@ -966,8 +896,7 @@ class PdfLineAnnotationHelper extends PdfAnnotationHelper { } /// internal method - static PdfLineAnnotation load( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + static PdfLineAnnotation load(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { return PdfLineAnnotation._(dictionary, crossTable, text); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_paintparams.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_paintparams.dart index 2d5332c93..d562f6404 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_paintparams.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_paintparams.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../graphics/brushes/pdf_solid_brush.dart'; import '../graphics/pdf_pen.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_polygon_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_polygon_annotation.dart index 86019e60d..d2f734bb6 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_polygon_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_polygon_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/pdf_annotation_border.dart'; @@ -72,8 +72,7 @@ class PdfPolygonAnnotation extends PdfAnnotation { setAppearance: setAppearance); } - PdfPolygonAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + PdfPolygonAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { _helper = PdfPolygonAnnotationHelper._(this, dictionary, crossTable); this.text = text; } @@ -85,11 +84,9 @@ class PdfPolygonAnnotation extends PdfAnnotation { List get polygonPoints { if (_helper.isLoadedAnnotation) { final List points = []; - final PdfDictionary dictionary = - PdfAnnotationHelper.getHelper(this).dictionary!; + final PdfDictionary dictionary = PdfAnnotationHelper.getHelper(this).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.vertices)) { - final PdfArray? linePoints = - dictionary[PdfDictionaryProperties.vertices] as PdfArray?; + final PdfArray? linePoints = dictionary[PdfDictionaryProperties.vertices] as PdfArray?; if (linePoints != null) { // ignore: avoid_function_literals_in_foreach_calls linePoints.elements.forEach((IPdfPrimitive? element) { @@ -165,13 +162,12 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { opacity: opacity, flags: flags, setAppearance: setAppearance); - dictionary!.setProperty(PdfDictionaryProperties.subtype, - PdfName(PdfDictionaryProperties.polygon)); + dictionary! + .setProperty(PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.polygon)); linePoints = PdfArray(points); _polygonPoints = points; } - PdfPolygonAnnotationHelper._( - this.annotation, PdfDictionary dictionary, PdfCrossTable crossTable) + PdfPolygonAnnotationHelper._(this.annotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super(annotation) { initializeExistingAnnotation(dictionary, crossTable); } @@ -205,8 +201,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { /// internal method void save() { - if (PdfAnnotationCollectionHelper.getHelper(annotation.page!.annotations) - .flatten) { + if (PdfAnnotationCollectionHelper.getHelper(annotation.page!.annotations).flatten) { PdfAnnotationHelper.getHelper(annotation).flatten = true; } if (PdfAnnotationHelper.getHelper(annotation).isLoadedAnnotation) { @@ -217,8 +212,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } void _saveNewPolygonAnnotation() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); final PdfDictionary dictionary = helper.dictionary!; Rect nativeRectangle = Rect.zero; if (annotation.setAppearance) { @@ -230,47 +224,38 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { annotation.bounds.height + (2 * annotation.border.width)); dictionary.setProperty(PdfDictionaryProperties.ap, annotation.appearance); if (dictionary[PdfDictionaryProperties.ap] != null) { - annotation.appearance.normal = - PdfTemplateHelper.fromRect(nativeRectangle); + annotation.appearance.normal = PdfTemplateHelper.fromRect(nativeRectangle); final PdfTemplate template = annotation.appearance.normal; PdfTemplateHelper.getHelper(template).writeTransformation = false; final PdfGraphics? graphics = template.graphics; - final PdfBrush? backBrushColor = annotation.innerColor.isEmpty - ? null - : PdfSolidBrush(annotation.innerColor); + final PdfBrush? backBrushColor = + annotation.innerColor.isEmpty ? null : PdfSolidBrush(annotation.innerColor); PdfPen? borderPenColor; - if (annotation.border.width > 0 && - PdfColorHelper.getHelper(annotation.color).alpha != 0) { - borderPenColor = - PdfPen(annotation.color, width: annotation.border.width); + if (annotation.border.width > 0 && PdfColorHelper.getHelper(annotation.color).alpha != 0) { + borderPenColor = PdfPen(annotation.color, width: annotation.border.width); } if (helper.flatten) { annotation.page!.annotations.remove(annotation); - annotation.page!.graphics.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backBrushColor); + annotation.page!.graphics + .drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backBrushColor); } else { - graphics!.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backBrushColor); + graphics!.drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backBrushColor); } } } if (helper.flatten && !annotation.setAppearance) { annotation.page!.annotations.remove(annotation); PdfPen? borderPenColor; - if (annotation.border.width > 0 && - PdfColorHelper.getHelper(annotation.color).alpha != 0) { - borderPenColor = - PdfPen(annotation.color, width: annotation.border.width); + if (annotation.border.width > 0 && PdfColorHelper.getHelper(annotation.color).alpha != 0) { + borderPenColor = PdfPen(annotation.color, width: annotation.border.width); } - final PdfBrush? backBrushColor = annotation.innerColor.isEmpty - ? null - : PdfSolidBrush(annotation.innerColor); - annotation.page!.graphics.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backBrushColor); + final PdfBrush? backBrushColor = + annotation.innerColor.isEmpty ? null : PdfSolidBrush(annotation.innerColor); + annotation.page!.graphics + .drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backBrushColor); } else if (!helper.flatten) { helper.saveAnnotation(); - dictionary.setProperty( - PdfDictionaryProperties.vertices, PdfArray(linePoints)); + dictionary.setProperty(PdfDictionaryProperties.vertices, PdfArray(linePoints)); dictionary.setProperty(PdfDictionaryProperties.bs, annotation.border); _getBoundsValue(); dictionary.setProperty(PdfDictionaryProperties.rect, @@ -283,8 +268,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } void _saveOldPolygonAnnotation() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); PdfGraphicsState? state; PdfRectangle nativeRectangle = PdfRectangle.empty; final PdfDictionary dictionary = helper.dictionary!; @@ -300,8 +284,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { annotation.bounds.height + (2 * annotation.border.width)); dictionary.setProperty(PdfDictionaryProperties.ap, annotation.appearance); if (dictionary[PdfDictionaryProperties.ap] != null) { - annotation.appearance.normal = - PdfTemplateHelper.fromRect(nativeRectangle.rect); + annotation.appearance.normal = PdfTemplateHelper.fromRect(nativeRectangle.rect); final PdfTemplate template = annotation.appearance.normal; PdfTemplateHelper.getHelper(template).writeTransformation = false; final PdfGraphics? graphics = annotation.appearance.normal.graphics; @@ -311,32 +294,26 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } PdfPen? borderPenColor; if (annotation.border.width > 0) { - borderPenColor = - PdfPen(annotation.color, width: annotation.border.width); + borderPenColor = PdfPen(annotation.color, width: annotation.border.width); } if (dictionary.containsKey(PdfDictionaryProperties.bs)) { PdfDictionary? bSDictionary; - if (dictionary.items![PdfName(PdfDictionaryProperties.bs)] - is PdfReferenceHolder) { + if (dictionary.items![PdfName(PdfDictionaryProperties.bs)] is PdfReferenceHolder) { bSDictionary = - (dictionary.items![PdfName(PdfDictionaryProperties.bs)]! - as PdfReferenceHolder) + (dictionary.items![PdfName(PdfDictionaryProperties.bs)]! as PdfReferenceHolder) .object as PdfDictionary?; } else { - bSDictionary = dictionary - .items![PdfName(PdfDictionaryProperties.bs)] as PdfDictionary?; + bSDictionary = dictionary.items![PdfName(PdfDictionaryProperties.bs)] as PdfDictionary?; } if (bSDictionary!.containsKey(PdfDictionaryProperties.d)) { - final PdfArray? dashPatternArray = PdfCrossTable.dereference( - bSDictionary.items![PdfName(PdfDictionaryProperties.d)]) - as PdfArray?; + final PdfArray? dashPatternArray = + PdfCrossTable.dereference(bSDictionary.items![PdfName(PdfDictionaryProperties.d)]) + as PdfArray?; if (dashPatternArray != null) { - final List dashPattern = List.filled( - dashPatternArray.count, 0, - growable: true); + final List dashPattern = + List.filled(dashPatternArray.count, 0, growable: true); for (int i = 0; i < dashPatternArray.count; i++) { - final IPdfPrimitive? pdfPrimitive = - dashPatternArray.elements[i]; + final IPdfPrimitive? pdfPrimitive = dashPatternArray.elements[i]; if (pdfPrimitive != null && pdfPrimitive is PdfNumber) { dashPattern[i] = pdfPrimitive.value!.toDouble(); } @@ -355,27 +332,26 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } if (dictionary.containsKey(PdfDictionaryProperties.be)) { final PdfDictionary beDictionary = - dictionary[PdfName(PdfDictionaryProperties.be)]! - as PdfDictionary; - final double? iNumber = (beDictionary - .items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber) - .value as double?; + dictionary[PdfName(PdfDictionaryProperties.be)]! as PdfDictionary; + final double? iNumber = + (beDictionary.items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber).value + as double?; final double radius = iNumber == 1 ? 5 : 10; if (radius > 0) { final List points = _getLinePoints()!; if (points[0].dy > points[points.length - 1].dy) { - helper.drawCloudStyle(graphics!, backgroundBrush, - borderPenColor, radius, 0.833, _getLinePoints()!, false); + helper.drawCloudStyle(graphics!, backgroundBrush, borderPenColor, radius, 0.833, + _getLinePoints()!, false); } - helper.drawCloudStyle(annotation.page!.graphics, backgroundBrush, - borderPenColor, radius, 0.833, _getLinePoints()!, false); + helper.drawCloudStyle(annotation.page!.graphics, backgroundBrush, borderPenColor, + radius, 0.833, _getLinePoints()!, false); } else { - annotation.page!.graphics.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backgroundBrush); + annotation.page!.graphics + .drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backgroundBrush); } } else { - annotation.page!.graphics.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backgroundBrush); + annotation.page!.graphics + .drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backgroundBrush); } if (annotation.opacity < 1) { annotation.page!.graphics.restore(state); @@ -387,11 +363,10 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } if (dictionary.containsKey(PdfDictionaryProperties.be)) { final PdfDictionary beDictionary = - dictionary[PdfName(PdfDictionaryProperties.be)]! - as PdfDictionary; - final double? iNumber = (beDictionary - .items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber) - .value as double?; + dictionary[PdfName(PdfDictionaryProperties.be)]! as PdfDictionary; + final double? iNumber = + (beDictionary.items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber).value + as double?; final double radius = iNumber == 1 ? 5 : 10; List points = _getLinePoints()!; if (points[0].dy > points[points.length - 1].dy) { @@ -400,22 +375,21 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { point.add(Offset(points[i].dx, -points[i].dy)); } points = point; - helper.drawCloudStyle(graphics!, backgroundBrush, borderPenColor, - radius, 0.833, points, true); + helper.drawCloudStyle( + graphics!, backgroundBrush, borderPenColor, radius, 0.833, points, true); } else { - helper.drawCloudStyle(graphics!, backgroundBrush, borderPenColor, - radius, 0.833, points, false); + helper.drawCloudStyle( + graphics!, backgroundBrush, borderPenColor, radius, 0.833, points, false); } } else { - graphics!.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backgroundBrush); + graphics!.drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backgroundBrush); } if (annotation.opacity < 1) { graphics.restore(state); } } - dictionary.setProperty(PdfDictionaryProperties.rect, - PdfArray.fromRectangle(nativeRectangle)); + dictionary.setProperty( + PdfDictionaryProperties.rect, PdfArray.fromRectangle(nativeRectangle)); } } if (helper.flatten && !annotation.setAppearance) { @@ -436,38 +410,33 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { final bool isNormalMatrix = helper.validateTemplateMatrix(dic); final Rect rect = helper.calculateTemplateBounds( annotation.bounds, annotation.page, template, isNormalMatrix); - annotation.page!.graphics - .drawPdfTemplate(template, rect.topLeft, rect.size); + annotation.page!.graphics.drawPdfTemplate(template, rect.topLeft, rect.size); annotation.page!.graphics.restore(state); annotation.page!.annotations.remove(annotation); } } } else { annotation.page!.annotations.remove(annotation); - final PdfPen borderPenColor = - PdfPen(annotation.color, width: annotation.border.width); - final PdfBrush? backgroundBrush = annotation.innerColor.isEmpty - ? null - : PdfSolidBrush(annotation.innerColor); + final PdfPen borderPenColor = PdfPen(annotation.color, width: annotation.border.width); + final PdfBrush? backgroundBrush = + annotation.innerColor.isEmpty ? null : PdfSolidBrush(annotation.innerColor); if (annotation.opacity < 1) { state = annotation.page!.graphics.save(); annotation.page!.graphics.setTransparency(annotation.opacity); } if (dictionary.containsKey(PdfDictionaryProperties.be)) { - final IPdfPrimitive? primitive = - dictionary[PdfName(PdfDictionaryProperties.be)]; - final PdfDictionary beDictionary = (primitive is PdfReferenceHolder - ? primitive.object - : primitive)! as PdfDictionary; - final double? iNumber = (beDictionary - .items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber) - .value as double?; + final IPdfPrimitive? primitive = dictionary[PdfName(PdfDictionaryProperties.be)]; + final PdfDictionary beDictionary = + (primitive is PdfReferenceHolder ? primitive.object : primitive)! as PdfDictionary; + final double? iNumber = + (beDictionary.items![PdfName(PdfDictionaryProperties.i)]! as PdfNumber).value + as double?; final double radius = iNumber == 1 ? 5 : 10; - helper.drawCloudStyle(annotation.page!.graphics, backgroundBrush, - borderPenColor, radius, 0.833, _getLinePoints()!, false); + helper.drawCloudStyle(annotation.page!.graphics, backgroundBrush, borderPenColor, radius, + 0.833, _getLinePoints()!, false); } else { - annotation.page!.graphics.drawPolygon(_getLinePoints()!, - pen: borderPenColor, brush: backgroundBrush); + annotation.page!.graphics + .drawPolygon(_getLinePoints()!, pen: borderPenColor, brush: backgroundBrush); } if (annotation.opacity < 1) { annotation.page!.graphics.restore(state); @@ -480,8 +449,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } List? _getLinePoints() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); if (helper.isLoadedAnnotation) { List? points; if (helper.dictionary!.containsKey(PdfDictionaryProperties.vertices)) { @@ -496,8 +464,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { points = []; for (int j = 0; j < point.length; j = j + 2) { if (helper.flatten) { - points.add(Offset( - point[j], annotation.page!.size.height - point[j + 1])); + points.add(Offset(point[j], annotation.page!.size.height - point[j + 1])); } else { points.add(Offset(point[j], -point[j + 1])); } @@ -519,8 +486,7 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { final double pageHeight = annotation.page!.size.height; if (helper.flatten) { PdfPageHelper.getHelper(annotation.page!).isLoadedPage - ? points.add( - Offset(pointsValue[j], pageHeight - pointsValue[j + 1])) + ? points.add(Offset(pointsValue[j], pageHeight - pointsValue[j + 1])) : points.add(Offset( pointsValue[j] - PdfPageHelper.getHelper(annotation.page!) @@ -545,20 +511,18 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } void _getBoundsValue() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(annotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(annotation); if (helper.isLoadedAnnotation) { - final PdfArray rect = - helper.dictionary![PdfDictionaryProperties.rect]! as PdfArray; + final PdfArray rect = helper.dictionary![PdfDictionaryProperties.rect]! as PdfArray; annotation.bounds = rect.toRectangle().rect; final List xval = []; final List yval = []; if (helper.dictionary!.containsKey(PdfDictionaryProperties.vertices)) { - final PdfArray linePoints = PdfCrossTable.dereference( - helper.dictionary![PdfDictionaryProperties.vertices])! as PdfArray; + final PdfArray linePoints = + PdfCrossTable.dereference(helper.dictionary![PdfDictionaryProperties.vertices])! + as PdfArray; if (linePoints.count > 0) { - final List points = - List.filled(linePoints.count, 0, growable: true); + final List points = List.filled(linePoints.count, 0, growable: true); for (int j = 0; j < linePoints.count; j++) { final PdfNumber number = linePoints[j]! as PdfNumber; points[j] = number.value!.toDouble(); @@ -574,8 +538,8 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } xval.sort(); yval.sort(); - annotation.bounds = Rect.fromLTWH(xval[0], yval[0], - xval[xval.length - 1] - xval[0], yval[yval.length - 1] - yval[0]); + annotation.bounds = Rect.fromLTWH( + xval[0], yval[0], xval[xval.length - 1] - xval[0], yval[yval.length - 1] - yval[0]); } else { final List xval = []; final List yval = []; @@ -597,8 +561,8 @@ class PdfPolygonAnnotationHelper extends PdfAnnotationHelper { } xval.sort(); yval.sort(); - annotation.bounds = Rect.fromLTWH(xval[0], yval[0], - xval[xval.length - 1] - xval[0], yval[yval.length - 1] - yval[0]); + annotation.bounds = Rect.fromLTWH( + xval[0], yval[0], xval[xval.length - 1] - xval[0], yval[yval.length - 1] - yval[0]); } } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_popup_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_popup_annotation.dart index 2f93a18b7..f63a389ab 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_popup_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_popup_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../graphics/brushes/pdf_brush.dart'; @@ -43,12 +43,11 @@ class PdfPopupAnnotation extends PdfAnnotation { PdfPopupIcon? icon, List? flags, bool? setAppearance}) { - _helper = PdfPopupAnnotationHelper(this, bounds, text, open, author, color, - subject, opacity, modifiedDate, icon, flags, setAppearance); + _helper = PdfPopupAnnotationHelper(this, bounds, text, open, author, color, subject, opacity, + modifiedDate, icon, flags, setAppearance); } - PdfPopupAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + PdfPopupAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { _helper = PdfPopupAnnotationHelper._(this, dictionary, crossTable, text); } @@ -110,13 +109,12 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { flags: flags, setAppearance: setAppearance); this.open = open ??= false; - dictionary!.setProperty( - PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.text)); + dictionary!.setProperty(PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.text)); this.icon = icon ?? PdfPopupIcon.note; } - PdfPopupAnnotationHelper._(this.popupAnnotation, PdfDictionary dictionary, - PdfCrossTable crossTable, String text) + PdfPopupAnnotationHelper._( + this.popupAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable, String text) : super(popupAnnotation) { this.text = text; initializeExistingAnnotation(dictionary, crossTable); @@ -134,8 +132,7 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { } /// internal method - static PdfPopupAnnotation load( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + static PdfPopupAnnotation load(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { return PdfPopupAnnotation._(dictionary, crossTable, text); } @@ -152,15 +149,13 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { } /// Gets the icon style of the annotation. - PdfPopupIcon get icon => - isLoadedAnnotation ? obtainIcon() : _icon ?? PdfPopupIcon.note; + PdfPopupIcon get icon => isLoadedAnnotation ? obtainIcon() : _icon ?? PdfPopupIcon.note; /// Sets the icon style of the annotation. set icon(PdfPopupIcon value) { if (_icon != value) { _icon = value; - dictionary! - .setName(PdfName(PdfDictionaryProperties.name), getEnumName(_icon)); + dictionary!.setName(PdfName(PdfDictionaryProperties.name), getEnumName(_icon)); } } @@ -213,20 +208,15 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { /// Internal method. void save() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(popupAnnotation); - if (PdfAnnotationCollectionHelper.getHelper( - popupAnnotation.page!.annotations) - .flatten) { + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(popupAnnotation); + if (PdfAnnotationCollectionHelper.getHelper(popupAnnotation.page!.annotations).flatten) { helper.flatten = true; } if (helper.isLoadedAnnotation) { if (helper.setAppearance) { - popupAnnotation.appearance.normal = - PdfTemplate(bounds.width, bounds.height); + popupAnnotation.appearance.normal = PdfTemplate(bounds.width, bounds.height); drawIcon(popupAnnotation.appearance.normal.graphics!); - dictionary!.setProperty( - PdfDictionaryProperties.ap, popupAnnotation.appearance); + dictionary!.setProperty(PdfDictionaryProperties.ap, popupAnnotation.appearance); } if (helper.flatten) { bool isFlattenPopup = true; @@ -240,8 +230,7 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { } } if (dictionary![PdfDictionaryProperties.ap] != null && isFlattenPopup) { - IPdfPrimitive? dic = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.ap]); + IPdfPrimitive? dic = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.ap]); PdfTemplate template; if (dic != null && dic is PdfDictionary) { dic = PdfCrossTable.dereference(dic[PdfDictionaryProperties.n]); @@ -252,8 +241,7 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { page!.graphics.save(); page!.graphics.setTransparency(opacity); } - page!.graphics - .drawPdfTemplate(template, bounds.topLeft, bounds.size); + page!.graphics.drawPdfTemplate(template, bounds.topLeft, bounds.size); if (!setAppearance && opacity < 1) { page!.graphics.restore(); } @@ -267,12 +255,11 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { if (helper.setAppearance || helper.flatten) { drawIcon(popupAnnotation.appearance.normal.graphics!); if (helper.flatten) { - page!.graphics.drawPdfTemplate(popupAnnotation.appearance.normal, - bounds.topLeft, popupAnnotation.appearance.normal.size); + page!.graphics.drawPdfTemplate(popupAnnotation.appearance.normal, bounds.topLeft, + popupAnnotation.appearance.normal.size); page!.annotations.remove(popupAnnotation); } else { - dictionary!.setProperty( - PdfDictionaryProperties.ap, popupAnnotation.appearance); + dictionary!.setProperty(PdfDictionaryProperties.ap, popupAnnotation.appearance); } } } @@ -289,8 +276,7 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { if (name != null && name is PdfName && name.name == 'Comment') { if (flatten) { popupAnnotation.appearance.normal = PdfTemplate( - bounds.width > 24 ? bounds.width : 24, - bounds.height > 22 ? bounds.height : 22); + bounds.width > 24 ? bounds.width : 24, bounds.height > 22 ? bounds.height : 22); graphics = popupAnnotation.appearance.normal.graphics!; } final PdfPen pen = PdfPen(PdfColor(0, 0, 0), width: 0.3); @@ -310,15 +296,12 @@ class PdfPopupAnnotationHelper extends PdfAnnotationHelper { template.graphics!.save(); template.graphics!.setTransparency(opacity); } - template.graphics!.drawRectangle( - bounds: const Rect.fromLTWH(0, 0, 24, 22), pen: pen, brush: brush); template.graphics! - .drawPolygon(points, pen: pen, brush: PdfBrushes.white); + .drawRectangle(bounds: const Rect.fromLTWH(0, 0, 24, 22), pen: pen, brush: brush); + template.graphics!.drawPolygon(points, pen: pen, brush: PdfBrushes.white); path.addEllipse(const Rect.fromLTWH(2.5, 2.5, 19, 14)); template.graphics!.drawPath(pen: pen, brush: PdfBrushes.white, path); - template.graphics!.drawArc( - const Rect.fromLTWH(2.5, 2.5, 19, 14), 110.7, 10.3, - pen: pen1); + template.graphics!.drawArc(const Rect.fromLTWH(2.5, 2.5, 19, 14), 110.7, 10.3, pen: pen1); if (opacity < 1) { template.graphics!.restore(); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_rectangle_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_rectangle_annotation.dart index 277ffbbb7..0a4983553 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_rectangle_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_rectangle_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/pdf_annotation_border.dart'; @@ -60,8 +60,7 @@ class PdfRectangleAnnotation extends PdfAnnotation { setAppearance: setAppearance); } - PdfRectangleAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + PdfRectangleAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { _helper = PdfRectangleAnnotationHelper._(this, dictionary, crossTable); this.text = text; } @@ -108,8 +107,7 @@ class PdfRectangleAnnotation extends PdfAnnotation { /// [PdfRectangleAnnotation] helper class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { /// internal constructor - PdfRectangleAnnotationHelper( - this.rectangleAnnotation, Rect bounds, String text, + PdfRectangleAnnotationHelper(this.rectangleAnnotation, Rect bounds, String text, {PdfColor? color, PdfColor? innerColor, PdfAnnotationBorder? border, @@ -132,11 +130,11 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { opacity: opacity, flags: flags, setAppearance: setAppearance); - dictionary!.setProperty(PdfDictionaryProperties.subtype, - PdfName(PdfDictionaryProperties.square)); + dictionary! + .setProperty(PdfDictionaryProperties.subtype, PdfName(PdfDictionaryProperties.square)); } - PdfRectangleAnnotationHelper._(this.rectangleAnnotation, - PdfDictionary dictionary, PdfCrossTable crossTable) + PdfRectangleAnnotationHelper._( + this.rectangleAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super(rectangleAnnotation) { initializeExistingAnnotation(dictionary, crossTable); } @@ -145,8 +143,7 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { late PdfRectangleAnnotation rectangleAnnotation; /// internal method - static PdfRectangleAnnotationHelper getHelper( - PdfRectangleAnnotation annotation) { + static PdfRectangleAnnotationHelper getHelper(PdfRectangleAnnotation annotation) { return annotation._helper; } @@ -166,16 +163,11 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { /// internal method void save() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(rectangleAnnotation); - if (PdfAnnotationCollectionHelper.getHelper( - rectangleAnnotation.page!.annotations) - .flatten) { + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(rectangleAnnotation); + if (PdfAnnotationCollectionHelper.getHelper(rectangleAnnotation.page!.annotations).flatten) { helper.flatten = true; } - if (helper.flatten || - rectangleAnnotation.setAppearance || - helper.appearance != null) { + if (helper.flatten || rectangleAnnotation.setAppearance || helper.appearance != null) { PdfTemplate? appearance; if (helper.appearance != null) { appearance = helper.appearance!.normal; @@ -191,15 +183,14 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } else { if (appearance != null) { rectangleAnnotation.appearance.normal = appearance; - helper.dictionary!.setProperty(PdfDictionaryProperties.ap, - PdfReferenceHolder(rectangleAnnotation.appearance)); + helper.dictionary!.setProperty( + PdfDictionaryProperties.ap, PdfReferenceHolder(rectangleAnnotation.appearance)); } } } if (!helper.flatten && !helper.isLoadedAnnotation) { helper.saveAnnotation(); - helper.dictionary! - .setProperty(PdfDictionaryProperties.bs, rectangleAnnotation.border); + helper.dictionary!.setProperty(PdfDictionaryProperties.bs, rectangleAnnotation.border); } if (helper.flattenPopups) { helper.flattenPopup(); @@ -207,33 +198,26 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } PdfTemplate? _createAppearance() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(rectangleAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(rectangleAnnotation); if (helper.isLoadedAnnotation) { if (rectangleAnnotation.setAppearance) { final PaintParams paintParams = PaintParams(); final double borderWidth = rectangleAnnotation.border.width / 2; - final PdfPen mBorderPen = PdfPen(rectangleAnnotation.color, - width: rectangleAnnotation.border.width); + final PdfPen mBorderPen = + PdfPen(rectangleAnnotation.color, width: rectangleAnnotation.border.width); PdfBrush? mBackBrush; final Map result = _calculateCloudBorderBounds(); final double borderIntensity = result['borderIntensity'] as double; final String? borderStyle = result['borderStyle'] as String?; - final PdfRectangle nativeRectangle = PdfRectangle( - 0, - 0, - rectangleAnnotation.bounds.width, - rectangleAnnotation.bounds.height); - final PdfTemplate template = - PdfTemplateHelper.fromRect(nativeRectangle.rect); - PdfAnnotationHelper.setMatrixToZeroRotation( - PdfTemplateHelper.getHelper(template).content); + final PdfRectangle nativeRectangle = + PdfRectangle(0, 0, rectangleAnnotation.bounds.width, rectangleAnnotation.bounds.height); + final PdfTemplate template = PdfTemplateHelper.fromRect(nativeRectangle.rect); + PdfAnnotationHelper.setMatrixToZeroRotation(PdfTemplateHelper.getHelper(template).content); if (borderIntensity > 0 && borderStyle == 'C') { PdfTemplateHelper.getHelper(template).writeTransformation = false; } final PdfGraphics? graphics = template.graphics; - if (PdfColorHelper.getHelper(rectangleAnnotation.innerColor).alpha != - 0) { + if (PdfColorHelper.getHelper(rectangleAnnotation.innerColor).alpha != 0) { mBackBrush = PdfSolidBrush(rectangleAnnotation.innerColor); } if (rectangleAnnotation.border.width > 0) { @@ -241,22 +225,19 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } paintParams.foreBrush = PdfSolidBrush(rectangleAnnotation.color); paintParams.backBrush = mBackBrush; - final PdfRectangle rectangle = _obtainStyle( - mBorderPen, nativeRectangle, borderWidth, + final PdfRectangle rectangle = _obtainStyle(mBorderPen, nativeRectangle, borderWidth, borderIntensity: borderIntensity, borderStyle: borderStyle); if (rectangleAnnotation.opacity < 1) { graphics!.save(); graphics.setTransparency(rectangleAnnotation.opacity); } if (borderIntensity > 0 && borderStyle == 'C') { - _drawAppearance( - rectangle, borderWidth, graphics, paintParams, borderIntensity); + _drawAppearance(rectangle, borderWidth, graphics, paintParams, borderIntensity); } else { graphics!.drawRectangle( pen: paintParams.borderPen, brush: paintParams.backBrush, - bounds: Rect.fromLTWH( - rectangle.x, rectangle.y, rectangle.width, rectangle.height)); + bounds: Rect.fromLTWH(rectangle.x, rectangle.y, rectangle.width, rectangle.height)); } if (rectangleAnnotation.opacity < 1) { graphics!.restore(); @@ -265,18 +246,17 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } return null; } else { - final Rect nativeRectangle = Rect.fromLTWH(0, 0, - rectangleAnnotation.bounds.width, rectangleAnnotation.bounds.height); - final PdfTemplate template = PdfTemplate( - rectangleAnnotation.bounds.width, rectangleAnnotation.bounds.height); - PdfAnnotationHelper.setMatrixToZeroRotation( - PdfTemplateHelper.getHelper(template).content); + final Rect nativeRectangle = + Rect.fromLTWH(0, 0, rectangleAnnotation.bounds.width, rectangleAnnotation.bounds.height); + final PdfTemplate template = + PdfTemplate(rectangleAnnotation.bounds.width, rectangleAnnotation.bounds.height); + PdfAnnotationHelper.setMatrixToZeroRotation(PdfTemplateHelper.getHelper(template).content); final PaintParams paintParams = PaintParams(); final PdfGraphics graphics = template.graphics!; if (rectangleAnnotation.border.width > 0 && PdfColorHelper.getHelper(rectangleAnnotation.color).alpha != 0) { - final PdfPen mBorderPen = PdfPen(rectangleAnnotation.color, - width: rectangleAnnotation.border.width); + final PdfPen mBorderPen = + PdfPen(rectangleAnnotation.color, width: rectangleAnnotation.border.width); paintParams.borderPen = mBorderPen; } PdfBrush? mBackBrush; @@ -289,8 +269,8 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { if (paintParams.foreBrush != PdfSolidBrush(rectangleAnnotation.color)) { paintParams.foreBrush = PdfSolidBrush(rectangleAnnotation.color); } - final Rect rect = Rect.fromLTWH(nativeRectangle.left, nativeRectangle.top, - nativeRectangle.width, nativeRectangle.height); + final Rect rect = Rect.fromLTWH( + nativeRectangle.left, nativeRectangle.top, nativeRectangle.width, nativeRectangle.height); if (rectangleAnnotation.opacity < 1) { graphics.save(); graphics.setTransparency(rectangleAnnotation.opacity); @@ -311,23 +291,19 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } Map _calculateCloudBorderBounds() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(rectangleAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(rectangleAnnotation); double borderIntensity = 0; String borderStyle = ''; final PdfDictionary dictionary = helper.dictionary!; if (!dictionary.containsKey(PdfDictionaryProperties.rd) && dictionary.containsKey(PdfDictionaryProperties.be)) { final PdfDictionary dict = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.be])! - as PdfDictionary; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.be])! as PdfDictionary; if (dict.containsKey(PdfDictionaryProperties.s)) { - borderStyle = helper - .getEnumName((dict[PdfDictionaryProperties.s]! as PdfName).name); + borderStyle = helper.getEnumName((dict[PdfDictionaryProperties.s]! as PdfName).name); } if (dict.containsKey(PdfDictionaryProperties.i)) { - borderIntensity = - (dict[PdfDictionaryProperties.i]! as PdfNumber).value!.toDouble(); + borderIntensity = (dict[PdfDictionaryProperties.i]! as PdfNumber).value!.toDouble(); } if (borderIntensity != 0 && borderStyle == 'C') { final Rect cloudRectangle = Rect.fromLTWH( @@ -355,8 +331,7 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } } if (!helper.isBounds && dictionary[PdfDictionaryProperties.rd] != null) { - final PdfArray mRdArray = - dictionary[PdfDictionaryProperties.rd]! as PdfArray; + final PdfArray mRdArray = dictionary[PdfDictionaryProperties.rd]! as PdfArray; final PdfNumber num1 = mRdArray.elements[0]! as PdfNumber; final PdfNumber num2 = mRdArray.elements[1]! as PdfNumber; final PdfNumber num3 = mRdArray.elements[2]! as PdfNumber; @@ -368,18 +343,10 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { rectangleAnnotation.bounds.height - num4.value!.toDouble() * 2); if (borderIntensity != 0 && borderStyle == 'C') { cloudRectangle = Rect.fromLTWH( - cloudRectangle.left - - borderIntensity * 5 - - rectangleAnnotation.border.width / 2, - cloudRectangle.top - - borderIntensity * 5 - - rectangleAnnotation.border.width / 2, - cloudRectangle.width + - borderIntensity * 10 + - rectangleAnnotation.border.width, - cloudRectangle.height + - borderIntensity * 10 + - rectangleAnnotation.border.width); + cloudRectangle.left - borderIntensity * 5 - rectangleAnnotation.border.width / 2, + cloudRectangle.top - borderIntensity * 5 - rectangleAnnotation.border.width / 2, + cloudRectangle.width + borderIntensity * 10 + rectangleAnnotation.border.width, + cloudRectangle.height + borderIntensity * 10 + rectangleAnnotation.border.width); final double radius = borderIntensity * 5; final List arr = [ radius + rectangleAnnotation.border.width / 2, @@ -393,40 +360,32 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } rectangleAnnotation.bounds = cloudRectangle; } - return { - 'borderIntensity': borderIntensity, - 'borderStyle': borderStyle - }; + return {'borderIntensity': borderIntensity, 'borderStyle': borderStyle}; } void _flattenAnnotation(PdfPage? page, PdfTemplate? appearance) { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(rectangleAnnotation); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(rectangleAnnotation); final PdfDictionary dictionary = helper.dictionary!; if (helper.isLoadedAnnotation) { - final bool isContainsAP = - dictionary.containsKey(PdfDictionaryProperties.ap); + final bool isContainsAP = dictionary.containsKey(PdfDictionaryProperties.ap); if (isContainsAP && appearance == null) { PdfDictionary? appearanceDictionary = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ap]) - as PdfDictionary?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ap]) as PdfDictionary?; if (appearanceDictionary != null) { - appearanceDictionary = PdfCrossTable.dereference( - appearanceDictionary[PdfDictionaryProperties.n]) - as PdfDictionary?; + appearanceDictionary = + PdfCrossTable.dereference(appearanceDictionary[PdfDictionaryProperties.n]) + as PdfDictionary?; if (appearanceDictionary != null) { - final PdfStream appearanceStream = - appearanceDictionary as PdfStream; + final PdfStream appearanceStream = appearanceDictionary as PdfStream; appearance = PdfTemplateHelper.fromPdfStream(appearanceStream); - final bool isNormalMatrix = - helper.validateTemplateMatrix(appearanceDictionary); + final bool isNormalMatrix = helper.validateTemplateMatrix(appearanceDictionary); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } else { rectangleAnnotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } @@ -435,33 +394,32 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { rectangleAnnotation.setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { - final bool isNormalMatrix = helper.validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance!).content); + final bool isNormalMatrix = + helper.validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance!).content); helper.flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { page!.graphics.save(); - final Rect rectangle = helper.calculateTemplateBounds( - rectangleAnnotation.bounds, page, appearance, true); + final Rect rectangle = + helper.calculateTemplateBounds(rectangleAnnotation.bounds, page, appearance, true); if (rectangleAnnotation.opacity < 1) { page.graphics.setTransparency(rectangleAnnotation.opacity); } - page.graphics.drawPdfTemplate( - appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); + page.graphics + .drawPdfTemplate(appearance!, Offset(rectangle.left, rectangle.top), rectangle.size); page.annotations.remove(rectangleAnnotation); page.graphics.restore(); } } // Obtain Style from annotation - PdfRectangle _obtainStyle( - PdfPen mBorderPen, PdfRectangle rectangle, double borderWidth, + PdfRectangle _obtainStyle(PdfPen mBorderPen, PdfRectangle rectangle, double borderWidth, {double? borderIntensity, String? borderStyle}) { if (PdfAnnotationHelper.getHelper(rectangleAnnotation) .dictionary! @@ -469,15 +427,12 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { final PdfDictionary? bSDictionary = PdfCrossTable.dereference( PdfAnnotationHelper.getHelper(rectangleAnnotation) .dictionary![PdfDictionaryProperties.bs]) as PdfDictionary?; - if (bSDictionary != null && - bSDictionary.containsKey(PdfDictionaryProperties.d)) { + if (bSDictionary != null && bSDictionary.containsKey(PdfDictionaryProperties.d)) { final PdfArray dashPatternArray = - PdfCrossTable.dereference(bSDictionary[PdfDictionaryProperties.d])! - as PdfArray; + PdfCrossTable.dereference(bSDictionary[PdfDictionaryProperties.d])! as PdfArray; final List dashPattern = []; for (int i = 0; i < dashPatternArray.count; i++) { - dashPattern.add( - (dashPatternArray.elements[i]! as PdfNumber).value!.toDouble()); + dashPattern.add((dashPatternArray.elements[i]! as PdfNumber).value!.toDouble()); } mBorderPen.dashStyle = PdfDashStyle.dash; mBorderPen.dashPattern = dashPattern; @@ -502,8 +457,8 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { } // Draw appearance for annotation - void _drawAppearance(PdfRectangle rectangle, double borderWidth, - PdfGraphics? graphics, PaintParams paintParams, double borderIntensity) { + void _drawAppearance(PdfRectangle rectangle, double borderWidth, PdfGraphics? graphics, + PaintParams paintParams, double borderIntensity) { final PdfPath graphicsPath = PdfPath(); graphicsPath.addRectangle(rectangle.rect); final double radius = borderIntensity * 4.25; @@ -513,29 +468,18 @@ class PdfRectangleAnnotationHelper extends PdfAnnotationHelper { PdfPathHelper.getHelper(graphicsPath).points.removeAt(4); } final List points = []; - for (int i = 0; - i < PdfPathHelper.getHelper(graphicsPath).points.length; - i++) { + for (int i = 0; i < PdfPathHelper.getHelper(graphicsPath).points.length; i++) { points.add(Offset(PdfPathHelper.getHelper(graphicsPath).points[i].dx, -PdfPathHelper.getHelper(graphicsPath).points[i].dy)); } PdfAnnotationHelper.getHelper(rectangleAnnotation).drawCloudStyle( - graphics!, - paintParams.backBrush, - paintParams.borderPen, - radius, - 0.833, - points, - false); + graphics!, paintParams.backBrush, paintParams.borderPen, radius, 0.833, points, false); } else { graphics!.drawRectangle( pen: paintParams.borderPen, brush: paintParams.backBrush, - bounds: Rect.fromLTWH( - rectangle.x + borderWidth, - rectangle.y, - rectangle.width - rectangleAnnotation.border.width, - rectangle.height)); + bounds: Rect.fromLTWH(rectangle.x + borderWidth, rectangle.y, + rectangle.width - rectangleAnnotation.border.width, rectangle.height)); } } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_markup_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_markup_annotation.dart index a4816bc51..3a9572c36 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_markup_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_markup_annotation.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -63,25 +63,14 @@ class PdfTextMarkupAnnotation extends PdfAnnotation { List? boundsCollection, List? flags, PdfTextMarkupAnnotationType? textMarkupAnnotationType}) { - _helper = PdfTextMarkupAnnotationHelper( - this, - bounds, - text, - color, - author, - subject, - opacity, - modifiedDate, - setAppearance, - flags, - textMarkupAnnotationType); + _helper = PdfTextMarkupAnnotationHelper(this, bounds, text, color, author, subject, opacity, + modifiedDate, setAppearance, flags, textMarkupAnnotationType); if (boundsCollection != null) { this.boundsCollection = boundsCollection; } } - PdfTextMarkupAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable) { + PdfTextMarkupAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable) { _helper = PdfTextMarkupAnnotationHelper._(this, dictionary, crossTable); } @@ -98,8 +87,7 @@ class PdfTextMarkupAnnotation extends PdfAnnotation { } /// Gets text markup annotation Type. - PdfTextMarkupAnnotationType get textMarkupAnnotationType => - _helper.textMarkupAnnotationType; + PdfTextMarkupAnnotationType get textMarkupAnnotationType => _helper.textMarkupAnnotationType; /// Sets text markup annotation Type. set textMarkupAnnotationType(PdfTextMarkupAnnotationType value) { @@ -148,8 +136,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { PdfName(getEnumName(this.textMarkupAnnotationType.toString()))); } - PdfTextMarkupAnnotationHelper._(this.textMarkupAnnotation, - PdfDictionary dictionary, PdfCrossTable crossTable) + PdfTextMarkupAnnotationHelper._( + this.textMarkupAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super(textMarkupAnnotation) { initializeExistingAnnotation(dictionary, crossTable); } @@ -166,14 +154,12 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { PdfTextMarkupAnnotationType? _textMarkupAnnotationType; /// internal method - static PdfTextMarkupAnnotationHelper getHelper( - PdfTextMarkupAnnotation annotation) { + static PdfTextMarkupAnnotationHelper getHelper(PdfTextMarkupAnnotation annotation) { return annotation._helper; } /// internal method - static PdfTextMarkupAnnotation load( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfTextMarkupAnnotation load(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfTextMarkupAnnotation._(dictionary, crossTable); } @@ -203,9 +189,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } /// Gets text markup annotation Type. - PdfTextMarkupAnnotationType get textMarkupAnnotationType => isLoadedAnnotation - ? _obtainTextMarkupAnnotationType() - : _textMarkupAnnotationType!; + PdfTextMarkupAnnotationType get textMarkupAnnotationType => + isLoadedAnnotation ? _obtainTextMarkupAnnotationType() : _textMarkupAnnotationType!; /// Sets text markup annotation Type. set textMarkupAnnotationType(PdfTextMarkupAnnotationType value) { @@ -223,8 +208,7 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { final double pageHeight = pageSize.height; final PdfMargins margins = obtainMargin()!; if (bounds.width == 0 && bounds.height == 0) { - bounds = - Rect.fromLTWH(bounds.left, bounds.top, bounds.width, bounds.height); + bounds = Rect.fromLTWH(bounds.left, bounds.top, bounds.width, bounds.height); } if (_boundsCollection.isEmpty && !_boundsCollection.contains(bounds)) { _boundsCollection.add(bounds); @@ -233,68 +217,52 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { final List textQuadLocation = List.filled(length, 0); final int noofRect = length ~/ 8; for (int i = 0; i < noofRect; i++) { - final double locationX = _boundsCollection[i].left, - locationY = _boundsCollection[i].top; + final double locationX = _boundsCollection[i].left, locationY = _boundsCollection[i].top; textQuadLocation[0 + (i * 8)] = locationX + margins.left; textQuadLocation[1 + (i * 8)] = (pageHeight - locationY) - margins.top; - textQuadLocation[2 + (i * 8)] = - (locationX + _boundsCollection[i].width) + margins.left; + textQuadLocation[2 + (i * 8)] = (locationX + _boundsCollection[i].width) + margins.left; textQuadLocation[3 + (i * 8)] = (pageHeight - locationY) - margins.top; textQuadLocation[4 + (i * 8)] = locationX + margins.left; - textQuadLocation[5 + (i * 8)] = - textQuadLocation[1 + (i * 8)] - _boundsCollection[i].height; - textQuadLocation[6 + (i * 8)] = - (locationX + _boundsCollection[i].width) + margins.left; + textQuadLocation[5 + (i * 8)] = textQuadLocation[1 + (i * 8)] - _boundsCollection[i].height; + textQuadLocation[6 + (i * 8)] = (locationX + _boundsCollection[i].width) + margins.left; textQuadLocation[7 + (i * 8)] = textQuadLocation[5 + (i * 8)]; } points = PdfArray(textQuadLocation); dictionary!.setProperty(PdfDictionaryProperties.quadPoints, points); } else { - final List textQuadLocation = - List.filled(_boundsCollection.length * 8, 0); + final List textQuadLocation = List.filled(_boundsCollection.length * 8, 0); final double pageHeight = pageSize.height; for (int i = 0; i < _boundsCollection.length; i++) { - final double locationX = _boundsCollection[i].left, - locationY = _boundsCollection[i].top; + final double locationX = _boundsCollection[i].left, locationY = _boundsCollection[i].top; textQuadLocation[0 + (i * 8)] = locationX; textQuadLocation[1 + (i * 8)] = pageHeight - locationY; textQuadLocation[2 + (i * 8)] = locationX + _boundsCollection[i].width; textQuadLocation[3 + (i * 8)] = pageHeight - locationY; textQuadLocation[4 + (i * 8)] = locationX; - textQuadLocation[5 + (i * 8)] = - textQuadLocation[1 + (i * 8)] - _boundsCollection[i].height; + textQuadLocation[5 + (i * 8)] = textQuadLocation[1 + (i * 8)] - _boundsCollection[i].height; textQuadLocation[6 + (i * 8)] = locationX + _boundsCollection[i].width; textQuadLocation[7 + (i * 8)] = textQuadLocation[5 + (i * 8)]; } - dictionary!.setProperty( - PdfDictionaryProperties.quadPoints, PdfArray(textQuadLocation)); + dictionary!.setProperty(PdfDictionaryProperties.quadPoints, PdfArray(textQuadLocation)); } } List _obtainBoundsValue() { final List collection = []; if (dictionary!.containsKey(PdfDictionaryProperties.quadPoints)) { - final IPdfPrimitive? points = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.quadPoints]); + final IPdfPrimitive? points = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.quadPoints]); double x, y, width, height; if (points != null && points is PdfArray) { for (int i = 0; i < (points.count / 8).round(); i++) { - final double q1 = - (points[0 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q2 = - (points[1 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q3 = - (points[2 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q4 = - (points[3 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q5 = - (points[4 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q6 = - (points[5 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q7 = - (points[6 + (i * 8)]! as PdfNumber).value!.toDouble(); - final double q8 = - (points[7 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q1 = (points[0 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q2 = (points[1 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q3 = (points[2 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q4 = (points[3 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q5 = (points[4 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q6 = (points[5 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q7 = (points[6 + (i * 8)]! as PdfNumber).value!.toDouble(); + final double q8 = (points[7 + (i * 8)]! as PdfNumber).value!.toDouble(); x = q5 - q1; y = q6 - q2; height = sqrt((x * x) + (y * y)); @@ -312,8 +280,7 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } PdfTextMarkupAnnotationType _getTextMarkupAnnotation(String aType) { - PdfTextMarkupAnnotationType annotType = - PdfTextMarkupAnnotationType.highlight; + PdfTextMarkupAnnotationType annotType = PdfTextMarkupAnnotationType.highlight; switch (aType) { case 'Highlight': annotType = PdfTextMarkupAnnotationType.highlight; @@ -333,11 +300,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { /// internal method void save() { - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(textMarkupAnnotation); - if (PdfAnnotationCollectionHelper.getHelper( - textMarkupAnnotation.page!.annotations) - .flatten) { + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(textMarkupAnnotation); + if (PdfAnnotationCollectionHelper.getHelper(textMarkupAnnotation.page!.annotations).flatten) { helper.flatten = true; } if (!helper.isLoadedAnnotation) { @@ -369,8 +333,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } else { if (appearance != null) { textMarkupAnnotation.appearance.normal = appearance; - dictionary!.setProperty(PdfDictionaryProperties.ap, - PdfReferenceHolder(textMarkupAnnotation.appearance)); + dictionary!.setProperty( + PdfDictionaryProperties.ap, PdfReferenceHolder(textMarkupAnnotation.appearance)); } } } @@ -397,8 +361,7 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } void _saveTextMarkUpDictionary() { - dictionary!.setProperty( - PdfDictionaryProperties.subtype, PdfName(_getMarkupAnnotationType())); + dictionary!.setProperty(PdfDictionaryProperties.subtype, PdfName(_getMarkupAnnotationType())); } PdfTemplate? _createAppearance() { @@ -417,8 +380,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { height = rectangle.height; } else { if (dictionary!.containsKey(PdfDictionaryProperties.quadPoints)) { - final IPdfPrimitive? mQuadPoints = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.quadPoints]); + final IPdfPrimitive? mQuadPoints = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.quadPoints]); if (mQuadPoints != null && mQuadPoints is PdfArray) { for (int i = 0; i < (mQuadPoints.count / 8); i++) { if (isLoadedAnnotation) { @@ -426,10 +389,8 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { List.filled(mQuadPoints.count ~/ 2, Offset.zero); int j = 0; for (int k = 0; k < mQuadPoints.count;) { - final double x1 = - (mQuadPoints[k]! as PdfNumber).value!.toDouble(); - final double y1 = - (mQuadPoints[k + 1]! as PdfNumber).value!.toDouble(); + final double x1 = (mQuadPoints[k]! as PdfNumber).value!.toDouble(); + final double y1 = (mQuadPoints[k + 1]! as PdfNumber).value!.toDouble(); quadPoints[j] = Offset(x1, y1); k = k + 2; j++; @@ -461,14 +422,12 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } } final PdfTemplate template = PdfTemplate(width, height); - PdfAnnotationHelper.setMatrixToZeroRotation( - PdfTemplateHelper.getHelper(template).content); + PdfAnnotationHelper.setMatrixToZeroRotation(PdfTemplateHelper.getHelper(template).content); final PdfGraphics graphics = template.graphics!; graphics.setTransparency(opacity, mode: PdfBlendMode.multiply); if (boundsCollection.length > 1) { for (int i = 0; i < boundsCollection.length; i++) { - if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.highlight) { + if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.highlight) { graphics.drawRectangle( brush: PdfSolidBrush(color), bounds: Rect.fromLTWH( @@ -476,49 +435,36 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { boundsCollection[i].top - rectangle.y, boundsCollection[i].width, boundsCollection[i].height)); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.underline) { + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.underline) { graphics.drawLine( PdfPen(color, width: boundsCollection[i].height * 0.05), Offset( boundsCollection[i].left - rectangle!.x, (boundsCollection[i].top - rectangle.y) + - (boundsCollection[i].height - - ((boundsCollection[i].height / 2) / 3))), + (boundsCollection[i].height - ((boundsCollection[i].height / 2) / 3))), Offset( - boundsCollection[i].width + - (boundsCollection[i].left - rectangle.x), + boundsCollection[i].width + (boundsCollection[i].left - rectangle.x), (boundsCollection[i].top - rectangle.y) + - (boundsCollection[i].height - - ((boundsCollection[i].height / 2) / 3)))); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.strikethrough) { + (boundsCollection[i].height - ((boundsCollection[i].height / 2) / 3)))); + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.strikethrough) { graphics.drawLine( PdfPen(color, width: boundsCollection[i].height * 0.05), Offset( boundsCollection[i].left - rectangle!.x, (boundsCollection[i].top - rectangle.y) + - (boundsCollection[i].height - - (boundsCollection[i].height / 2))), + (boundsCollection[i].height - (boundsCollection[i].height / 2))), Offset( - boundsCollection[i].width + - (boundsCollection[i].left - rectangle.x), + boundsCollection[i].width + (boundsCollection[i].left - rectangle.x), (boundsCollection[i].top - rectangle.y) + - (boundsCollection[i].height - - (boundsCollection[i].height / 2)))); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.squiggly) { - final PdfPen pdfPen = - PdfPen(color, width: boundsCollection[i].height * 0.02); + (boundsCollection[i].height - (boundsCollection[i].height / 2)))); + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.squiggly) { + final PdfPen pdfPen = PdfPen(color, width: boundsCollection[i].height * 0.02); graphics.save(); - graphics.translateTransform(boundsCollection[i].left - rectangle!.x, - boundsCollection[i].top - rectangle.y); + graphics.translateTransform( + boundsCollection[i].left - rectangle!.x, boundsCollection[i].top - rectangle.y); graphics.setClip( - bounds: Rect.fromLTWH(0, 0, boundsCollection[i].width, - boundsCollection[i].height)); - graphics.drawPath( - _drawSquiggly( - boundsCollection[i].width, boundsCollection[i].height), + bounds: Rect.fromLTWH(0, 0, boundsCollection[i].width, boundsCollection[i].height)); + graphics.drawPath(_drawSquiggly(boundsCollection[i].width, boundsCollection[i].height), pen: pdfPen); graphics.restore(); } @@ -526,26 +472,19 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { } else { if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.highlight) { graphics.drawRectangle( - brush: PdfSolidBrush(color), - bounds: Rect.fromLTWH(0, 0, width, height)); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.underline) { - graphics.drawLine( - PdfPen(color, width: height * 0.05), - Offset(0, height - ((height / 2) / 3)), - Offset(width, height - ((height / 2) / 3))); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.strikethrough) { + brush: PdfSolidBrush(color), bounds: Rect.fromLTWH(0, 0, width, height)); + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.underline) { graphics.drawLine(PdfPen(color, width: height * 0.05), - Offset(0, height / 2), Offset(width, height / 2)); - } else if (textMarkupAnnotationType == - PdfTextMarkupAnnotationType.squiggly) { + Offset(0, height - ((height / 2) / 3)), Offset(width, height - ((height / 2) / 3))); + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.strikethrough) { + graphics.drawLine(PdfPen(color, width: height * 0.05), Offset(0, height / 2), + Offset(width, height / 2)); + } else if (textMarkupAnnotationType == PdfTextMarkupAnnotationType.squiggly) { final PdfPen pdfPen = PdfPen(color, width: height * 0.02); graphics.drawPath(_drawSquiggly(width, height), pen: pdfPen); } if (isLoadedAnnotation) { - dictionary![PdfDictionaryProperties.rect] = - PdfArray.fromRectangle(rectangle!); + dictionary![PdfDictionaryProperties.rect] = PdfArray.fromRectangle(rectangle!); } } return template; @@ -565,8 +504,7 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { double zigZag = location; double x = 0; for (int i = 0; i < mPathPoints.length; i++, x += length) { - mPathPoints[i] = - Offset(x, ((height - location) + zigZag) - (height * 0.02)); + mPathPoints[i] = Offset(x, ((height - location) + zigZag) - (height * 0.02)); if (zigZag == 0) { zigZag = location; } else { @@ -581,13 +519,12 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { if (!isLoadedAnnotation) { if (appearance != null) { page.graphics.save(); - final Rect rectangle = - calculateTemplateBounds(bounds, page, appearance, true); + final Rect rectangle = calculateTemplateBounds(bounds, page, appearance, true); if (opacity < 1) { page.graphics.setTransparency(opacity); } - page.graphics.drawPdfTemplate( - appearance, Offset(rectangle.left, rectangle.top), rectangle.size); + page.graphics + .drawPdfTemplate(appearance, Offset(rectangle.left, rectangle.top), rectangle.size); page.annotations.remove(textMarkupAnnotation); page.graphics.restore(); } @@ -597,51 +534,43 @@ class PdfTextMarkupAnnotationHelper extends PdfAnnotationHelper { appearance == null) { IPdfPrimitive? appearanceDictionary = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.ap]); - if (appearanceDictionary != null && - appearanceDictionary is PdfDictionary) { - appearanceDictionary = PdfCrossTable.dereference( - appearanceDictionary[PdfDictionaryProperties.n]); - if (appearanceDictionary != null && - appearanceDictionary is PdfStream) { + if (appearanceDictionary != null && appearanceDictionary is PdfDictionary) { + appearanceDictionary = + PdfCrossTable.dereference(appearanceDictionary[PdfDictionaryProperties.n]); + if (appearanceDictionary != null && appearanceDictionary is PdfStream) { appearance = PdfTemplateHelper.fromPdfStream(appearanceDictionary); - final bool isNormalMatrix = - validateTemplateMatrix(appearanceDictionary); - if (isNormalMatrix && - page.rotation != PdfPageRotateAngle.rotateAngle0) { + final bool isNormalMatrix = validateTemplateMatrix(appearanceDictionary); + if (isNormalMatrix && page.rotation != PdfPageRotateAngle.rotateAngle0) { flattenAnnotationTemplate(appearance, isNormalMatrix); } else if (isNormalMatrix && - isValidTemplateMatrix( - appearanceDictionary, bounds.topLeft, appearance)) { + isValidTemplateMatrix(appearanceDictionary, bounds.topLeft, appearance)) { flattenAnnotationTemplate(appearance, isNormalMatrix); } } else { setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); flattenAnnotationTemplate(appearance, isNormalMatrix); } } } - } else if (!dictionary!.containsKey(PdfDictionaryProperties.ap) && - appearance == null) { + } else if (!dictionary!.containsKey(PdfDictionaryProperties.ap) && appearance == null) { setAppearance = true; appearance = _createAppearance(); if (appearance != null) { - final bool isNormalMatrix = validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + final bool isNormalMatrix = + validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); flattenAnnotationTemplate(appearance, isNormalMatrix); } - } else if (!dictionary!.containsKey(PdfDictionaryProperties.ap) && - appearance != null) { - final bool isNormalMatrix = validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + } else if (!dictionary!.containsKey(PdfDictionaryProperties.ap) && appearance != null) { + final bool isNormalMatrix = + validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); flattenAnnotationTemplate(appearance, isNormalMatrix); - } else if (dictionary!.containsKey(PdfDictionaryProperties.ap) && - appearance != null) { - final bool isNormalMatrix = validateTemplateMatrix( - PdfTemplateHelper.getHelper(appearance).content); + } else if (dictionary!.containsKey(PdfDictionaryProperties.ap) && appearance != null) { + final bool isNormalMatrix = + validateTemplateMatrix(PdfTemplateHelper.getHelper(appearance).content); flattenAnnotationTemplate(appearance, isNormalMatrix); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_web_link.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_web_link.dart index d39f37d4f..d70e15c4a 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_web_link.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_text_web_link.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../graphics/brushes/pdf_solid_brush.dart'; @@ -71,8 +71,7 @@ class PdfTextWebLink extends PdfAnnotation { this.url = url; } - PdfTextWebLink._( - PdfDictionary dictionary, PdfCrossTable crossTable, String? annotText) { + PdfTextWebLink._(PdfDictionary dictionary, PdfCrossTable crossTable, String? annotText) { _helper = PdfTextWebLinkHelper._(this, dictionary, crossTable); text = annotText != null && annotText.isNotEmpty ? annotText : ''; } @@ -216,12 +215,10 @@ class PdfTextWebLink extends PdfAnnotation { } _url = value; if (PdfAnnotationHelper.getHelper(this).isLoadedAnnotation) { - final PdfDictionary tempDictionary = - PdfAnnotationHelper.getHelper(this).dictionary!; + final PdfDictionary tempDictionary = PdfAnnotationHelper.getHelper(this).dictionary!; if (tempDictionary.containsKey(PdfDictionaryProperties.a)) { final PdfDictionary? dictionary = - PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) - as PdfDictionary?; + PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) as PdfDictionary?; if (dictionary != null) { dictionary.setString(PdfDictionaryProperties.uri, _url); } @@ -231,8 +228,8 @@ class PdfTextWebLink extends PdfAnnotation { } // implementation - void _initializeWebLink(String? annotText, PdfFont? font, PdfPen? pen, - PdfBrush? brush, PdfStringFormat? format) { + void _initializeWebLink( + String? annotText, PdfFont? font, PdfPen? pen, PdfBrush? brush, PdfStringFormat? format) { text = annotText != null && annotText.isNotEmpty ? annotText : ''; if (font != null) { this.font = font; @@ -271,11 +268,9 @@ class PdfTextWebLink extends PdfAnnotation { /// ``` void draw(PdfPage page, Offset location) { if (!PdfAnnotationHelper.getHelper(this).isLoadedAnnotation) { - final PdfFont pdfFont = - font != null ? font! : PdfStandardFont(PdfFontFamily.helvetica, 8); + final PdfFont pdfFont = font != null ? font! : PdfStandardFont(PdfFontFamily.helvetica, 8); final Size textSize = pdfFont.measureString(text); - final Rect rect = Rect.fromLTWH( - location.dx, location.dy, textSize.width, textSize.height); + final Rect rect = Rect.fromLTWH(location.dx, location.dy, textSize.width, textSize.height); _uriAnnotation = PdfUriAnnotation(bounds: rect, uri: url); _uriAnnotation.border = PdfAnnotationBorder(0, 0, 0); page.annotations.add(_uriAnnotation); @@ -290,17 +285,13 @@ class PdfTextWebLink extends PdfAnnotation { String? _obtainUrl() { String? url = ''; - final PdfDictionary tempDictionary = - PdfAnnotationHelper.getHelper(this).dictionary!; + final PdfDictionary tempDictionary = PdfAnnotationHelper.getHelper(this).dictionary!; if (tempDictionary.containsKey(PdfDictionaryProperties.a)) { final PdfDictionary? dictionary = - PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) - as PdfDictionary?; - if (dictionary != null && - dictionary.containsKey(PdfDictionaryProperties.uri)) { + PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) as PdfDictionary?; + if (dictionary != null && dictionary.containsKey(PdfDictionaryProperties.uri)) { final PdfString? uriText = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.uri]) - as PdfString?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.uri]) as PdfString?; if (uriText != null) { url = uriText.value; } @@ -318,8 +309,7 @@ class PdfTextWebLinkHelper extends PdfAnnotationHelper { } /// internal constructor - PdfTextWebLinkHelper._( - this.webLinkHelper, PdfDictionary dictionary, PdfCrossTable crossTable) + PdfTextWebLinkHelper._(this.webLinkHelper, PdfDictionary dictionary, PdfCrossTable crossTable) : super(webLinkHelper) { initializeExistingAnnotation(dictionary, crossTable); } @@ -332,8 +322,7 @@ class PdfTextWebLinkHelper extends PdfAnnotationHelper { IPdfPrimitive? element; /// internal method - static PdfTextWebLink load( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + static PdfTextWebLink load(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { return PdfTextWebLink._(dictionary, crossTable, text); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_uri_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_uri_annotation.dart index 828624668..8a689c266 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_uri_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_uri_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../actions/pdf_action.dart'; @@ -23,8 +23,7 @@ class PdfUriAnnotation extends PdfActionLinkAnnotation { this.uri = uri; } - PdfUriAnnotation._( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + PdfUriAnnotation._(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { _helper = PdfUriAnnotationHelper._(this, dictionary, crossTable); super.text = text; } @@ -51,8 +50,9 @@ class PdfUriAnnotation extends PdfActionLinkAnnotation { if (_uri != value) { _uri = value; if (tempDictionary.containsKey(PdfDictionaryProperties.a)) { - final PdfDictionary? dictionary = PdfCrossTable.dereference( - tempDictionary[PdfDictionaryProperties.a]) as PdfDictionary?; + final PdfDictionary? dictionary = + PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) + as PdfDictionary?; if (dictionary != null) { dictionary.setString(PdfDictionaryProperties.uri, _uri); dictionary.modify(); @@ -66,8 +66,8 @@ class PdfUriAnnotation extends PdfActionLinkAnnotation { if (helper.isLoadedAnnotation) { PdfDictionary? dictionary = tempDictionary; if (tempDictionary.containsKey(PdfDictionaryProperties.a)) { - dictionary = PdfCrossTable.dereference( - tempDictionary[PdfDictionaryProperties.a]) as PdfDictionary?; + dictionary = PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) + as PdfDictionary?; if (dictionary != null) { dictionary.setString(PdfDictionaryProperties.uri, _uri); } @@ -111,17 +111,13 @@ class PdfUriAnnotation extends PdfActionLinkAnnotation { String? _getUriText() { String? uriText = ''; - final PdfDictionary tempDictionary = - PdfAnnotationHelper.getHelper(this).dictionary!; + final PdfDictionary tempDictionary = PdfAnnotationHelper.getHelper(this).dictionary!; if (tempDictionary.containsKey(PdfDictionaryProperties.a)) { final PdfDictionary? dictionary = - PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) - as PdfDictionary?; - if (dictionary != null && - dictionary.containsKey(PdfDictionaryProperties.uri)) { + PdfCrossTable.dereference(tempDictionary[PdfDictionaryProperties.a]) as PdfDictionary?; + if (dictionary != null && dictionary.containsKey(PdfDictionaryProperties.uri)) { final PdfString? tempText = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.uri]) - as PdfString?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.uri]) as PdfString?; if (tempText != null) { uriText = tempText.value; } @@ -134,20 +130,17 @@ class PdfUriAnnotation extends PdfActionLinkAnnotation { /// [PdfUriAnnotation] helper class PdfUriAnnotationHelper extends PdfActionLinkAnnotationHelper { /// internal constructor - PdfUriAnnotationHelper(this.uriAnnotation, Rect bounds) - : super(uriAnnotation, bounds) { + PdfUriAnnotationHelper(this.uriAnnotation, Rect bounds) : super(uriAnnotation, bounds) { _uriAction ??= PdfUriAction(); - dictionary!.setProperty(PdfName(PdfDictionaryProperties.subtype), - PdfName(PdfDictionaryProperties.link)); + dictionary!.setProperty( + PdfName(PdfDictionaryProperties.subtype), PdfName(PdfDictionaryProperties.link)); final IPdfPrimitive? element = IPdfWrapper.getElement(_uriAction!); if (element == null) { - IPdfWrapper.setElement( - _uriAction!, PdfActionHelper.getHelper(_uriAction!).dictionary); + IPdfWrapper.setElement(_uriAction!, PdfActionHelper.getHelper(_uriAction!).dictionary); } dictionary!.setProperty(PdfName(PdfDictionaryProperties.a), element); } - PdfUriAnnotationHelper._( - this.uriAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) + PdfUriAnnotationHelper._(this.uriAnnotation, PdfDictionary dictionary, PdfCrossTable crossTable) : super.load(uriAnnotation, dictionary, crossTable); /// internal field @@ -159,8 +152,7 @@ class PdfUriAnnotationHelper extends PdfActionLinkAnnotationHelper { IPdfPrimitive? element; /// internal method - static PdfUriAnnotation load( - PdfDictionary dictionary, PdfCrossTable crossTable, String text) { + static PdfUriAnnotation load(PdfDictionary dictionary, PdfCrossTable crossTable, String text) { return PdfUriAnnotation._(dictionary, crossTable, text); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/xfdf_parser.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/xfdf_parser.dart index adf8bf8da..5a454b0c8 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/xfdf_parser.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/xfdf_parser.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import 'package:convert/convert.dart'; import 'package:xml/xml.dart'; @@ -48,8 +48,7 @@ class XfdfParser { //Implementation. /// internal method. void parseAndImportAnnotationData() { - for (final XmlNode node - in _xmlDocument.rootElement.firstElementChild!.children) { + for (final XmlNode node in _xmlDocument.rootElement.firstElementChild!.children) { if (node is XmlElement) { _parseAnnotationData(node); } @@ -62,13 +61,10 @@ class XfdfParser { if (pageIndexString != null && !isNullOrEmpty(pageIndexString)) { final int pageIndex = int.parse(pageIndexString); if (pageIndex >= 0 && pageIndex < _document.pages.count) { - PdfPageHelper.getHelper(_document.pages[pageIndex]).importAnnotation = - true; - final PdfDictionary annotationDictionary = - _getAnnotation(element, pageIndex); + PdfPageHelper.getHelper(_document.pages[pageIndex]).importAnnotation = true; + final PdfDictionary annotationDictionary = _getAnnotation(element, pageIndex); if (annotationDictionary.count > 0) { - final PdfReferenceHolder holder = - PdfReferenceHolder(annotationDictionary); + final PdfReferenceHolder holder = PdfReferenceHolder(annotationDictionary); if (annotationDictionary.containsKey('NM') || annotationDictionary.containsKey(PdfDictionaryProperties.irt)) { _addReferenceToGroup(holder, annotationDictionary); @@ -79,8 +75,8 @@ class XfdfParser { if (!pageDictionary.containsKey(PdfDictionaryProperties.annots)) { pageDictionary[PdfDictionaryProperties.annots] = PdfArray(); } - final IPdfPrimitive? annots = PdfCrossTable.dereference( - pageDictionary[PdfDictionaryProperties.annots]); + final IPdfPrimitive? annots = + PdfCrossTable.dereference(pageDictionary[PdfDictionaryProperties.annots]); if (annots != null && annots is PdfArray) { annots.elements.add(holder); _handlePopUp(annots, holder, annotationDictionary); @@ -93,11 +89,10 @@ class XfdfParser { } } - void _handlePopUp(PdfArray annots, PdfReferenceHolder holder, - PdfDictionary annotDictionary) { + void _handlePopUp(PdfArray annots, PdfReferenceHolder holder, PdfDictionary annotDictionary) { if (annotDictionary.containsKey(PdfDictionaryProperties.popup)) { - final IPdfPrimitive? popup = PdfCrossTable.dereference( - annotDictionary[PdfDictionaryProperties.popup]); + final IPdfPrimitive? popup = + PdfCrossTable.dereference(annotDictionary[PdfDictionaryProperties.popup]); if (popup != null && popup is PdfDictionary) { popup.setProperty(PdfDictionaryProperties.parent, holder); annots.add(popup); @@ -113,8 +108,8 @@ class XfdfParser { if (!isNullOrEmpty(element.localName)) { switch (element.localName.toLowerCase()) { case 'line': - annotationDictionary.setName(PdfName(PdfDictionaryProperties.subtype), - PdfDictionaryProperties.line); + annotationDictionary.setName( + PdfName(PdfDictionaryProperties.subtype), PdfDictionaryProperties.line); final String? start = element.getAttribute('start'); final String? end = element.getAttribute('end'); if (start != null && end != null) { @@ -122,8 +117,7 @@ class XfdfParser { _addLinePoints(linePoints, start); _addLinePoints(linePoints, end); if (linePoints.length == 4) { - annotationDictionary.setProperty( - PdfDictionaryProperties.l, PdfArray(linePoints)); + annotationDictionary.setProperty(PdfDictionaryProperties.l, PdfArray(linePoints)); } linePoints.clear(); } @@ -138,8 +132,7 @@ class XfdfParser { PdfDictionaryProperties.subtype, PdfDictionaryProperties.square); break; case 'polyline': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'PolyLine'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'PolyLine'); _addLineEndStyle(element, annotationDictionary); break; case 'polygon': @@ -159,49 +152,42 @@ class XfdfParser { PdfDictionaryProperties.subtype, PdfDictionaryProperties.text); break; case 'freetext': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'FreeText'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'FreeText'); _addLineEndStyle(element, annotationDictionary); break; case 'stamp': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'Stamp'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'Stamp'); break; case 'highlight': - annotationDictionary.setName(PdfDictionaryProperties.subtype, - PdfDictionaryProperties.highlight); + annotationDictionary.setName( + PdfDictionaryProperties.subtype, PdfDictionaryProperties.highlight); break; case 'squiggly': - annotationDictionary.setName(PdfDictionaryProperties.subtype, - PdfDictionaryProperties.squiggly); + annotationDictionary.setName( + PdfDictionaryProperties.subtype, PdfDictionaryProperties.squiggly); break; case 'underline': - annotationDictionary.setName(PdfDictionaryProperties.subtype, - PdfDictionaryProperties.underline); + annotationDictionary.setName( + PdfDictionaryProperties.subtype, PdfDictionaryProperties.underline); break; case 'strikeout': - annotationDictionary.setName(PdfDictionaryProperties.subtype, - PdfDictionaryProperties.strikeOut); + annotationDictionary.setName( + PdfDictionaryProperties.subtype, PdfDictionaryProperties.strikeOut); break; case 'fileattachment': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'FileAttachment'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'FileAttachment'); break; case 'sound': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'Sound'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'Sound'); break; case 'caret': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'Caret'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'Caret'); break; case 'redact': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'Redact'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'Redact'); break; case 'watermark': - annotationDictionary.setName( - PdfDictionaryProperties.subtype, 'Watermark'); + annotationDictionary.setName(PdfDictionaryProperties.subtype, 'Watermark'); break; default: isValidType = false; @@ -214,8 +200,7 @@ class XfdfParser { return annotationDictionary; } - void _addAnnotationData( - PdfDictionary annotDictionary, XmlElement element, int pageIndex) { + void _addAnnotationData(PdfDictionary annotDictionary, XmlElement element, int pageIndex) { _addBorderStyle(annotDictionary, element); _applyAttributeValues(annotDictionary, element); _parseInnerElements(annotDictionary, element, pageIndex); @@ -228,8 +213,7 @@ class XfdfParser { final PdfDictionary borderStyleDictionary = PdfDictionary(); String? attribute = element.getAttribute('width'); if (!isNullOrEmpty(attribute)) { - borderStyleDictionary.setNumber( - PdfDictionaryProperties.w, double.parse(attribute!)); + borderStyleDictionary.setNumber(PdfDictionaryProperties.w, double.parse(attribute!)); } bool isBasicStyle = true; attribute = element.getAttribute('style'); @@ -261,32 +245,30 @@ class XfdfParser { .setName(PdfDictionaryProperties.s, style); attribute = element.getAttribute('intensity'); if (!isBasicStyle && !isNullOrEmpty(attribute)) { - borderEffectDictionary.setNumber( - PdfDictionaryProperties.i, double.parse(attribute!)); + borderEffectDictionary.setNumber(PdfDictionaryProperties.i, double.parse(attribute!)); } else { attribute = element.getAttribute('dashes'); if (!isNullOrEmpty(attribute)) { final List dashPoints = _obtainFloatPoints(attribute!); if (dashPoints.isNotEmpty) { - borderStyleDictionary.setProperty( - PdfDictionaryProperties.d, PdfArray(dashPoints)); + borderStyleDictionary.setProperty(PdfDictionaryProperties.d, PdfArray(dashPoints)); } } } } } if (borderEffectDictionary.count > 0) { - annotDictionary.setProperty(PdfDictionaryProperties.be, - PdfReferenceHolder(borderEffectDictionary)); + annotDictionary.setProperty( + PdfDictionaryProperties.be, PdfReferenceHolder(borderEffectDictionary)); } else { borderEffectDictionary.clear(); borderEffectDictionary.isSaving = false; } if (borderStyleDictionary.count > 0) { - borderStyleDictionary.setProperty(PdfDictionaryProperties.type, - PdfName(PdfDictionaryProperties.border)); - annotDictionary.setProperty(PdfDictionaryProperties.bs, - PdfReferenceHolder(borderStyleDictionary)); + borderStyleDictionary.setProperty( + PdfDictionaryProperties.type, PdfName(PdfDictionaryProperties.border)); + annotDictionary.setProperty( + PdfDictionaryProperties.bs, PdfReferenceHolder(borderStyleDictionary)); } else { borderStyleDictionary.clear(); borderStyleDictionary.isSaving = false; @@ -320,8 +302,7 @@ class XfdfParser { } } - void _applyAttributeValues( - PdfDictionary annotDictionary, XmlElement element) { + void _applyAttributeValues(PdfDictionary annotDictionary, XmlElement element) { for (final XmlAttribute attribute in element.attributes) { final String value = attribute.value; final XmlName name = attribute.name; @@ -353,16 +334,14 @@ class XfdfParser { case 'rect': final List points = _obtainFloatPoints(value); if (points.isNotEmpty && points.length == 4) { - annotDictionary.setProperty( - PdfDictionaryProperties.rect, PdfArray(points)); + annotDictionary.setProperty(PdfDictionaryProperties.rect, PdfArray(points)); } break; case 'color': if (!isNullOrEmpty(value)) { final PdfArray? colorArray = _getColorArray(value); if (colorArray != null) { - annotDictionary.setProperty( - PdfDictionaryProperties.c, colorArray); + annotDictionary.setProperty(PdfDictionaryProperties.c, colorArray); } } break; @@ -370,8 +349,7 @@ class XfdfParser { if (!isNullOrEmpty(value)) { final PdfArray? colorArray = _getColorArray(value); if (colorArray != null) { - annotDictionary.setProperty( - PdfDictionaryProperties.ic, colorArray); + annotDictionary.setProperty(PdfDictionaryProperties.ic, colorArray); } } break; @@ -379,8 +357,7 @@ class XfdfParser { _addString(annotDictionary, PdfDictionaryProperties.m, value); break; case 'creationdate': - _addString( - annotDictionary, PdfDictionaryProperties.creationDate, value); + _addString(annotDictionary, PdfDictionaryProperties.creationDate, value); break; case 'name': _addString(annotDictionary, 'NM', value); @@ -391,12 +368,10 @@ class XfdfParser { } break; case 'subject': - _addString(annotDictionary, PdfDictionaryProperties.subj, - _getFormattedString(value)); + _addString(annotDictionary, PdfDictionaryProperties.subj, _getFormattedString(value)); break; case 'title': - _addString(annotDictionary, PdfDictionaryProperties.t, - _getFormattedString(value)); + _addString(annotDictionary, PdfDictionaryProperties.t, _getFormattedString(value)); break; case 'rotation': _addInt(annotDictionary, PdfDictionaryProperties.rotate, value); @@ -405,8 +380,7 @@ class XfdfParser { _addInt(annotDictionary, PdfDictionaryProperties.q, value); break; case 'fringe': - _addFloatPoints(annotDictionary, _obtainFloatPoints(value), - PdfDictionaryProperties.rd); + _addFloatPoints(annotDictionary, _obtainFloatPoints(value), PdfDictionaryProperties.rd); break; case 'it': if (!isNullOrEmpty(value)) { @@ -420,15 +394,13 @@ class XfdfParser { if (!isNullOrEmpty(value)) { final double? leaderExtend = double.tryParse(value); if (leaderExtend != null) { - annotDictionary.setNumber( - PdfDictionaryProperties.lle, leaderExtend); + annotDictionary.setNumber(PdfDictionaryProperties.lle, leaderExtend); } } break; case 'caption': if (!isNullOrEmpty(value)) { - annotDictionary.setBoolean( - PdfDictionaryProperties.cap, value.toLowerCase() == 'yes'); + annotDictionary.setBoolean(PdfDictionaryProperties.cap, value.toLowerCase() == 'yes'); } break; case 'caption-style': @@ -440,12 +412,12 @@ class XfdfParser { _addFloatPoints(annotDictionary, _obtainFloatPoints(value), 'CL'); break; case 'coords': - _addFloatPoints(annotDictionary, _obtainFloatPoints(value), - PdfDictionaryProperties.quadPoints); + _addFloatPoints( + annotDictionary, _obtainFloatPoints(value), PdfDictionaryProperties.quadPoints); break; case 'border': - _addFloatPoints(annotDictionary, _obtainFloatPoints(value), - PdfDictionaryProperties.border); + _addFloatPoints( + annotDictionary, _obtainFloatPoints(value), PdfDictionaryProperties.border); break; case 'opacity': if (!isNullOrEmpty(value)) { @@ -457,8 +429,7 @@ class XfdfParser { break; case 'flags': if (!isNullOrEmpty(value)) { - final List annotationFlags = - []; + final List annotationFlags = []; final List flags = value.split(','); for (int i = 0; i < flags.length; i++) { final PdfAnnotationFlags flagType = mapAnnotationFlags(flags[i]); @@ -468,8 +439,7 @@ class XfdfParser { } int flagValue = 0; for (int i = 0; i < annotationFlags.length; i++) { - flagValue |= PdfAnnotationHelper.getAnnotationFlagsValue( - annotationFlags[i]); + flagValue |= PdfAnnotationHelper.getAnnotationFlagsValue(annotationFlags[i]); } if (flagValue > 0) { annotDictionary.setNumber(PdfDictionaryProperties.f, flagValue); @@ -478,8 +448,8 @@ class XfdfParser { break; case 'open': if (!isNullOrEmpty(value)) { - annotDictionary.setBoolean(PdfDictionaryProperties.open, - value == 'true' || value == 'yes'); + annotDictionary.setBoolean( + PdfDictionaryProperties.open, value == 'true' || value == 'yes'); } break; case 'calibrate': @@ -492,8 +462,7 @@ class XfdfParser { _addString(annotDictionary, 'OverlayText', value); break; case 'repeat': - annotDictionary.setBoolean( - 'Repeat', value == 'true' || value == 'yes'); + annotDictionary.setBoolean('Repeat', value == 'true' || value == 'yes'); break; default: break; @@ -501,8 +470,7 @@ class XfdfParser { } } - void _parseInnerElements( - PdfDictionary annotDictionary, XmlElement element, int pageIndex) { + void _parseInnerElements(PdfDictionary annotDictionary, XmlElement element, int pageIndex) { if (element.attributes.isNotEmpty) { for (final XmlNode childNode in element.children) { if (childNode is XmlElement) { @@ -510,13 +478,10 @@ class XfdfParser { switch (childName.local.toLowerCase()) { case 'popup': if (childNode.attributes.isNotEmpty) { - final PdfDictionary popupDictionary = - _getAnnotation(childNode, pageIndex); + final PdfDictionary popupDictionary = _getAnnotation(childNode, pageIndex); if (popupDictionary.count > 0) { - final PdfReferenceHolder holder = - PdfReferenceHolder(popupDictionary); - annotDictionary.setProperty( - PdfDictionaryProperties.popup, holder); + final PdfReferenceHolder holder = PdfReferenceHolder(popupDictionary); + annotDictionary.setProperty(PdfDictionaryProperties.popup, holder); if (popupDictionary.containsKey('NM')) { _addReferenceToGroup(holder, popupDictionary); } @@ -528,8 +493,7 @@ class XfdfParser { if (!isNullOrEmpty(contents)) { contents = contents.replaceAll('<', '<'); contents = contents.replaceAll('>', '>'); - annotDictionary.setString( - PdfDictionaryProperties.contents, contents); + annotDictionary.setString(PdfDictionaryProperties.contents, contents); } break; case 'contents-richtext': @@ -539,15 +503,11 @@ class XfdfParser { final String contentText = childNode.innerText; if (!isNullOrEmpty(richTextContents) && !isNullOrEmpty(contentText) && - !annotDictionary - .containsKey(PdfDictionaryProperties.contents)) { - annotDictionary.setString( - 'RC', '$richTextContents'); - annotDictionary.setString( - PdfDictionaryProperties.contents, contentText); + !annotDictionary.containsKey(PdfDictionaryProperties.contents)) { + annotDictionary.setString('RC', '$richTextContents'); + annotDictionary.setString(PdfDictionaryProperties.contents, contentText); } else if (!isNullOrEmpty(richTextContents)) { - annotDictionary.setString( - 'RC', '$richTextContents'); + annotDictionary.setString('RC', '$richTextContents'); } } break; @@ -555,31 +515,26 @@ class XfdfParser { _addString(annotDictionary, 'DS', childNode.innerText); break; case 'defaultappearance': - _addString(annotDictionary, PdfDictionaryProperties.da, - childNode.innerText); + _addString(annotDictionary, PdfDictionaryProperties.da, childNode.innerText); break; case 'vertices': if (!isNullOrEmpty(childNode.innerText)) { - final String verticesValue = - childNode.innerText.replaceAll(';', ','); + final String verticesValue = childNode.innerText.replaceAll(';', ','); if (verticesValue != '') { final List verticesList = []; _addLinePoints(verticesList, verticesValue); if (verticesList.isNotEmpty && verticesList.length.isEven) { annotDictionary.setProperty( - PdfDictionaryProperties.vertices, - PdfArray(verticesList)); + PdfDictionaryProperties.vertices, PdfArray(verticesList)); } } } break; case 'appearance': if (!isNullOrEmpty(childNode.innerText)) { - final List appearanceArray = - base64.decode(childNode.innerText); + final List appearanceArray = base64.decode(childNode.innerText); if (appearanceArray.isNotEmpty) { - final XmlDocument appearanceDoc = - XmlDocument.parse(utf8.decode(appearanceArray)); + final XmlDocument appearanceDoc = XmlDocument.parse(utf8.decode(appearanceArray)); final List childNodes = appearanceDoc.children; for (final XmlNode rootElement in childNodes) { if (rootElement is XmlElement) { @@ -588,8 +543,7 @@ class XfdfParser { if (rootName.local == XfdfProperties.dict) { final String? rootAttribute = rootElement.getAttribute(XfdfProperties.key); - if (rootAttribute != null && - !isNullOrEmpty(rootAttribute)) { + if (rootAttribute != null && !isNullOrEmpty(rootAttribute)) { if (rootAttribute == 'AP') { final PdfDictionary appearance = PdfDictionary(); final List childs = rootElement.children; @@ -599,8 +553,7 @@ class XfdfParser { } } if (appearance.count > 0) { - annotDictionary.setProperty( - PdfDictionaryProperties.ap, appearance); + annotDictionary.setProperty(PdfDictionaryProperties.ap, appearance); } } } @@ -623,8 +576,7 @@ class XfdfParser { final XmlName childNodeName = child.name; if (childNodeName.local.toLowerCase() == 'gesture' && !isNullOrEmpty(child.innerText)) { - final String pointsArrayValue = - child.innerText.replaceAll(';', ','); + final String pointsArrayValue = child.innerText.replaceAll(';', ','); if (pointsArrayValue != '') { final PdfArray inkListCollection = PdfArray(); final List pointsList = []; @@ -634,8 +586,7 @@ class XfdfParser { } pointsList.clear(); if (inkListCollection.count > 0) { - annotDictionary.setProperty( - 'InkList', inkListCollection); + annotDictionary.setProperty('InkList', inkListCollection); } } } @@ -645,26 +596,23 @@ class XfdfParser { break; case 'data': if (!isNullOrEmpty(childNode.innerText)) { - final List raw = - List.from(hex.decode(childNode.innerText)); + final List raw = List.from(hex.decode(childNode.innerText)); if (raw.isNotEmpty) { - if (annotDictionary - .containsKey(PdfDictionaryProperties.subtype)) { - final IPdfPrimitive? subtype = PdfCrossTable.dereference( - annotDictionary[PdfDictionaryProperties.subtype]); + if (annotDictionary.containsKey(PdfDictionaryProperties.subtype)) { + final IPdfPrimitive? subtype = + PdfCrossTable.dereference(annotDictionary[PdfDictionaryProperties.subtype]); if (subtype != null && subtype is PdfName) { if (subtype.name == 'FileAttachment') { final PdfDictionary fileDictionary = PdfDictionary(); - fileDictionary.setName(PdfDictionaryProperties.type, - PdfDictionaryProperties.filespec); - _addElementStrings(fileDictionary, element, 'file', - PdfDictionaryProperties.f); - _addElementStrings(fileDictionary, element, 'file', - PdfDictionaryProperties.uf); + fileDictionary.setName( + PdfDictionaryProperties.type, PdfDictionaryProperties.filespec); + _addElementStrings( + fileDictionary, element, 'file', PdfDictionaryProperties.f); + _addElementStrings( + fileDictionary, element, 'file', PdfDictionaryProperties.uf); final PdfStream fileStream = PdfStream(); final PdfDictionary param = PdfDictionary(); - final String? sizeAttributes = - element.getAttribute('size'); + final String? sizeAttributes = element.getAttribute('size'); if (!isNullOrEmpty(sizeAttributes)) { final int? size = int.tryParse(sizeAttributes!); if (size != null) { @@ -674,42 +622,34 @@ class XfdfParser { } _addElementStrings(param, element, 'modification', PdfDictionaryProperties.modificationDate); - _addElementStrings(param, element, 'creation', - PdfDictionaryProperties.creationDate); - fileStream.setProperty( - PdfDictionaryProperties.params, param); - _addElementStrings(fileStream, element, 'mimetype', - PdfDictionaryProperties.subtype); + _addElementStrings( + param, element, 'creation', PdfDictionaryProperties.creationDate); + fileStream.setProperty(PdfDictionaryProperties.params, param); + _addElementStrings( + fileStream, element, 'mimetype', PdfDictionaryProperties.subtype); fileStream.data = raw; final PdfDictionary embeddedFile = PdfDictionary(); - embeddedFile.setProperty(PdfDictionaryProperties.f, - PdfReferenceHolder(fileStream)); - fileDictionary.setProperty( - PdfDictionaryProperties.ef, embeddedFile); - annotDictionary.setProperty(PdfDictionaryProperties.fs, - PdfReferenceHolder(fileDictionary)); + embeddedFile.setProperty( + PdfDictionaryProperties.f, PdfReferenceHolder(fileStream)); + fileDictionary.setProperty(PdfDictionaryProperties.ef, embeddedFile); + annotDictionary.setProperty( + PdfDictionaryProperties.fs, PdfReferenceHolder(fileDictionary)); } else if (subtype.name == 'Sound') { final PdfStream soundStream = PdfStream(); - soundStream.setName( - PdfDictionaryProperties.type, 'Sound'); + soundStream.setName(PdfDictionaryProperties.type, 'Sound'); _addNumber(soundStream, element, 'bits', 'B'); - _addNumber(soundStream, element, 'rate', - PdfDictionaryProperties.r); - _addNumber(soundStream, element, 'channels', - PdfDictionaryProperties.c); + _addNumber(soundStream, element, 'rate', PdfDictionaryProperties.r); + _addNumber(soundStream, element, 'channels', PdfDictionaryProperties.c); String? attribute = element.getAttribute('encoding'); if (!isNullOrEmpty(attribute)) { - soundStream.setName( - PdfDictionaryProperties.e, attribute); + soundStream.setName(PdfDictionaryProperties.e, attribute); } soundStream.data = raw; attribute = element.getAttribute('filter'); if (!isNullOrEmpty(attribute)) { - soundStream - .addFilter(PdfDictionaryProperties.flateDecode); + soundStream.addFilter(PdfDictionaryProperties.flateDecode); } - annotDictionary.setProperty( - 'Sound', PdfReferenceHolder(soundStream)); + annotDictionary.setProperty('Sound', PdfReferenceHolder(soundStream)); } } } @@ -722,8 +662,8 @@ class XfdfParser { } } - void _addElementStrings(PdfDictionary dictionary, XmlElement element, - String attributeName, String key) { + void _addElementStrings( + PdfDictionary dictionary, XmlElement element, String attributeName, String key) { if (element.attributes.isNotEmpty) { final String? attribute = element.getAttribute(attributeName); if (!isNullOrEmpty(attribute)) { @@ -732,8 +672,7 @@ class XfdfParser { } } - void _addNumber(PdfDictionary dictionary, XmlElement element, - String attributeName, String key) { + void _addNumber(PdfDictionary dictionary, XmlElement element, String attributeName, String key) { if (element.attributes.isNotEmpty) { final String? attribute = element.getAttribute(attributeName); if (!isNullOrEmpty(attribute)) { @@ -749,8 +688,8 @@ class XfdfParser { .replaceAll('data:image/bmp;base64,', ''); final List appearanceArray = base64.decode(convert); final PdfBitmap image = PdfBitmap(appearanceArray); - final IPdfPrimitive? array = PdfCrossTable.dereference( - annotDictionary[PdfDictionaryProperties.rect]); + final IPdfPrimitive? array = + PdfCrossTable.dereference(annotDictionary[PdfDictionaryProperties.rect]); if (array != null && array is PdfArray) { const double x = 0; const double y = 0; @@ -758,24 +697,21 @@ class XfdfParser { final double height = (array[3]! as PdfNumber).value!.toDouble(); final Rect rect = Rect.fromLTWH(x, y, width, height); final PdfTemplate template = PdfTemplate(width, height); - _setMatrix( - PdfTemplateHelper.getHelper(template).content, annotDictionary); + _setMatrix(PdfTemplateHelper.getHelper(template).content, annotDictionary); template.graphics!.drawImage(image, rect); final PdfReferenceHolder refHolder = PdfReferenceHolder(template); final PdfDictionary appearanceDictionary = PdfDictionary(); appearanceDictionary.setProperty(PdfDictionaryProperties.n, refHolder); - annotDictionary.setProperty( - PdfDictionaryProperties.ap, appearanceDictionary); + annotDictionary.setProperty(PdfDictionaryProperties.ap, appearanceDictionary); } } void _setMatrix(PdfDictionary template, PdfDictionary annotDictionary) { - final IPdfPrimitive? bbox = - PdfCrossTable.dereference(template[PdfDictionaryProperties.bBox]); + final IPdfPrimitive? bbox = PdfCrossTable.dereference(template[PdfDictionaryProperties.bBox]); if (bbox != null && bbox is PdfArray) { if (annotDictionary.containsKey(PdfDictionaryProperties.rotate)) { - final IPdfPrimitive? rotate = PdfCrossTable.dereference( - annotDictionary[PdfDictionaryProperties.rotate]); + final IPdfPrimitive? rotate = + PdfCrossTable.dereference(annotDictionary[PdfDictionaryProperties.rotate]); if (rotate is PdfNumber && rotate.value != 0) { int rotateAngle = rotate.value!.toInt(); if (rotateAngle == 0) { @@ -848,8 +784,8 @@ class XfdfParser { } bool isImage = false; if (appearance.containsKey(PdfDictionaryProperties.subtype)) { - final IPdfPrimitive? subtype = PdfCrossTable.dereference( - appearance[PdfDictionaryProperties.subtype]); + final IPdfPrimitive? subtype = + PdfCrossTable.dereference(appearance[PdfDictionaryProperties.subtype]); if (subtype != null && subtype is PdfName && subtype.name == PdfDictionaryProperties.image) { @@ -874,8 +810,7 @@ class XfdfParser { return appearance; } - void _addMeasureDictionary( - PdfDictionary annotDictionary, XmlElement element) { + void _addMeasureDictionary(PdfDictionary annotDictionary, XmlElement element) { XmlElement? measurement; XmlElement? area; XmlElement? distance; @@ -900,8 +835,7 @@ class XfdfParser { measureDictionary.items![PdfName(PdfDictionaryProperties.d)] = dArray; measureDictionary.items![PdfName(PdfDictionaryProperties.x)] = xArray; if (measurement != null) { - measureDictionary.setName( - PdfDictionaryProperties.type, PdfDictionaryProperties.measure); + measureDictionary.setName(PdfDictionaryProperties.type, PdfDictionaryProperties.measure); if (measurement.attributes.isNotEmpty) { final String? attribute = measurement.getAttribute('rateValue'); if (!isNullOrEmpty(attribute)) { @@ -948,16 +882,14 @@ class XfdfParser { if (attribute != null) { final double? d = double.tryParse(attribute); if (d != null) { - dictionary.setProperty( - PdfName(PdfDictionaryProperties.d), PdfNumber(d)); + dictionary.setProperty(PdfName(PdfDictionaryProperties.d), PdfNumber(d)); } } attribute = element.getAttribute(PdfDictionaryProperties.c.toLowerCase()); if (attribute != null) { final double? c = double.tryParse(attribute); if (c != null) { - dictionary.setProperty( - PdfName(PdfDictionaryProperties.c), PdfNumber(c)); + dictionary.setProperty(PdfName(PdfDictionaryProperties.c), PdfNumber(c)); } } attribute = element.getAttribute('rt'); @@ -966,8 +898,7 @@ class XfdfParser { } attribute = element.getAttribute('rd'); if (attribute != null) { - dictionary.items![PdfName(PdfDictionaryProperties.rd)] = - PdfString(attribute); + dictionary.items![PdfName(PdfDictionaryProperties.rd)] = PdfString(attribute); } attribute = element.getAttribute('ss'); if (attribute != null) { @@ -975,13 +906,11 @@ class XfdfParser { } attribute = element.getAttribute(PdfDictionaryProperties.u.toLowerCase()); if (attribute != null) { - dictionary.items![PdfName(PdfDictionaryProperties.u)] = - PdfString(attribute); + dictionary.items![PdfName(PdfDictionaryProperties.u)] = PdfString(attribute); } attribute = element.getAttribute(PdfDictionaryProperties.f.toLowerCase()); if (attribute != null) { - dictionary.items![PdfName(PdfDictionaryProperties.f)] = - PdfName(attribute); + dictionary.items![PdfName(PdfDictionaryProperties.f)] = PdfName(attribute); } attribute = element.getAttribute('fd'); if (attribute != null) { @@ -1002,8 +931,7 @@ class XfdfParser { return stream; } - void _addKey( - IPdfPrimitive? primitive, PdfDictionary dictionary, XmlElement element) { + void _addKey(IPdfPrimitive? primitive, PdfDictionary dictionary, XmlElement element) { if (primitive != null && element.attributes.isNotEmpty) { final String? attribute = element.getAttribute(XfdfProperties.key); if (!isNullOrEmpty(attribute)) { @@ -1147,11 +1075,9 @@ class XfdfParser { final String? mode = element.getAttribute(XfdfProperties.mode); final String? encoding = element.getAttribute('ENCODING'); if (!isNullOrEmpty(mode) && !isNullOrEmpty(encoding)) { - if (mode == XfdfProperties.filtered && - encoding == XfdfProperties.ascii) { + if (mode == XfdfProperties.filtered && encoding == XfdfProperties.ascii) { return [...utf8.encode(element.innerText)]; - } else if (mode == XfdfProperties.raw && - encoding == XfdfProperties.hex) { + } else if (mode == XfdfProperties.raw && encoding == XfdfProperties.hex) { return _hexToBytes(element.innerText); } } else if (!isNullOrEmpty(encoding) && encoding == XfdfProperties.hex) { @@ -1170,8 +1096,7 @@ class XfdfParser { return bytes; } - void _addReferenceToGroup( - PdfReferenceHolder holder, PdfDictionary dictionary) { + void _addReferenceToGroup(PdfReferenceHolder holder, PdfDictionary dictionary) { IPdfPrimitive? name = PdfCrossTable.dereference(dictionary['NM']); if (name != null && name is PdfString && !isNullOrEmpty(name.value)) { _groupReferences ??= {}; @@ -1182,14 +1107,11 @@ class XfdfParser { } } else if (name == null) { if (dictionary.containsKey(PdfDictionaryProperties.irt)) { - name = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.irt]); + name = PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.irt]); } if (name != null && name is PdfString && !isNullOrEmpty(name.value)) { - if (_groupReferences != null && - _groupReferences!.containsKey(name.value)) { - final PdfReferenceHolder referenceHolder = - _groupReferences![name.value]!; + if (_groupReferences != null && _groupReferences!.containsKey(name.value)) { + final PdfReferenceHolder referenceHolder = _groupReferences![name.value]!; dictionary[PdfDictionaryProperties.irt] = referenceHolder; } } @@ -1304,8 +1226,7 @@ class XfdfParser { final PdfArray lineEndingStyles = PdfArray(); lineEndingStyles.add(PdfName(beginLineStyle)); lineEndingStyles.add(PdfName(endLineStyle)); - annotDictionary.setProperty( - PdfDictionaryProperties.le, lineEndingStyles); + annotDictionary.setProperty(PdfDictionaryProperties.le, lineEndingStyles); } else { annotDictionary.setName(PdfDictionaryProperties.le, beginLineStyle); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/drawing/drawing.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/drawing/drawing.dart index 8ff239fa7..a34715176 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/drawing/drawing.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/drawing/drawing.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; /// Represents the size values. class PdfSize { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/glyph.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/glyph.dart index 779637261..e56d78d09 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/glyph.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/glyph.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/fonts/enums.dart'; import 'matrix_helper.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart index 4505853ab..c3add6e3c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/image_renderer.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import 'font_structure.dart'; import 'glyph.dart'; @@ -14,23 +14,22 @@ import 'xobject_element.dart'; /// internal class class ImageRenderer { /// internal constructor - ImageRenderer(PdfRecordCollection? contentElements, - PdfPageResources resources, this.currentPageHeight, + ImageRenderer( + PdfRecordCollection? contentElements, PdfPageResources resources, this.currentPageHeight, [GraphicsObject? g]) { const int dpiX = 96; _graphicsObject = GraphicsObject(); _graphicsState = GraphicStateCollection(); graphicsObjects = GraphicObjectDataCollection(); final GraphicObjectData newObject = GraphicObjectData(); - newObject.currentTransformationMatrix = - MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + newObject.currentTransformationMatrix = MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); final MatrixHelper transformMatrix = g != null ? g.transformMatrix! : _graphicsObject!.transformMatrix!; - newObject.currentTransformationMatrix!.translate( - transformMatrix.offsetX / 1.333, transformMatrix.offsetY / 1.333); + newObject.currentTransformationMatrix! + .translate(transformMatrix.offsetX / 1.333, transformMatrix.offsetY / 1.333); newObject.drawing2dMatrixCTM = MatrixHelper(1, 0, 0, 1, 0, 0); - newObject.drawing2dMatrixCTM!.translate( - transformMatrix.offsetX / 1.333, transformMatrix.offsetY / 1.333); + newObject.drawing2dMatrixCTM! + .translate(transformMatrix.offsetX / 1.333, transformMatrix.offsetY / 1.333); newObject.documentMatrix = MatrixHelper( 1.33333333333333 * (dpiX / 96) * transformMatrix.m11, 0, @@ -235,14 +234,11 @@ class ImageRenderer { if (_skipRendering) { _inlayersCount++; } - if (elements[1].contains('ActualText') && - elements[1].contains('(')) { - _actualText = elements[1].substring( - elements[1].indexOf('(') + 1, - elements[1].lastIndexOf(')')); + if (elements[1].contains('ActualText') && elements[1].contains('(')) { + _actualText = elements[1] + .substring(elements[1].indexOf('(') + 1, elements[1].lastIndexOf(')')); const String bigEndianPreambleString = 'þÿ'; - if (_actualText != null && - _actualText!.startsWith(bigEndianPreambleString)) { + if (_actualText != null && _actualText!.startsWith(bigEndianPreambleString)) { _actualText = null; } } @@ -265,8 +261,7 @@ class ImageRenderer { final GraphicObjectData data = GraphicObjectData(); if (graphicsObjects!.count > 0) { final GraphicObjectData prevData = graphicsObjects!.last; - data.currentTransformationMatrix = - prevData.currentTransformationMatrix; + data.currentTransformationMatrix = prevData.currentTransformationMatrix; data.mitterLength = prevData.mitterLength; data.textLineMatrix = prevData.textLineMatrix; data.documentMatrix = prevData.documentMatrix; @@ -318,8 +313,7 @@ class ImageRenderer { } final GraphicsState? state = _graphicsObject!.save(); _graphicsState!.push(state); - _graphicsObject! - .multiplyTransform(MatrixHelper(a, -b, -c, d, e, -f)); + _graphicsObject!.multiplyTransform(MatrixHelper(a, -b, -c, d, e, -f)); currentLocation = Offset.zero; _textMatrix = true; break; @@ -355,8 +349,7 @@ class ImageRenderer { } if (_renderingMode == 2 && pdfRecordCollection.recordCollection.length > i + 1 && - pdfRecordCollection.recordCollection[i + 1].operatorName != - 'q') { + pdfRecordCollection.recordCollection[i + 1].operatorName != 'q') { _renderingMode = 0; } break; @@ -390,17 +383,15 @@ class ImageRenderer { case "'": { _moveToNextLineWithCurrentTextLeading(); - final MatrixHelper transformMatrix = - _getTextRenderingMatrix(false); + final MatrixHelper transformMatrix = _getTextRenderingMatrix(false); objects.textMatrixUpdate = transformMatrix; if (_textScaling != 100) { final GraphicsState? state = _graphicsObject!.save(); _graphicsState!.push(state); _graphicsObject!.scaleTransform(_textScaling! / 100, 1); isScaledText = true; - currentLocation = Offset( - currentLocation!.dx / (_textScaling! / 100), - currentLocation!.dy); + currentLocation = + Offset(currentLocation!.dx / (_textScaling! / 100), currentLocation!.dy); } _renderTextElementWithLeading(elements!, token); break; @@ -413,8 +404,7 @@ class ImageRenderer { } case 'TD': { - currentLocation = Offset( - currentLocation!.dx + double.tryParse(elements![0])!, + currentLocation = Offset(currentLocation!.dx + double.tryParse(elements![0])!, currentLocation!.dy - double.tryParse(elements[1])!); _moveToNextLineWithLeading(elements); break; @@ -423,8 +413,7 @@ class ImageRenderer { { final double dx = double.tryParse(elements![0])!; final double dy = double.tryParse(elements[1])!; - currentLocation = - Offset(currentLocation!.dx + dx, currentLocation!.dy - dy); + currentLocation = Offset(currentLocation!.dx + dx, currentLocation!.dy - dy); _moveToNextLine(dx, dy); break; } @@ -462,13 +451,10 @@ class ImageRenderer { break; } if (i < pdfRecordCollection.count && - pdfRecordCollection.recordCollection[i + 1].operatorName == - 'f') { + pdfRecordCollection.recordCollection[i + 1].operatorName == 'f') { _isNextFill = true; } - if (!(drawing2dMatrixCTM!.m11 == 0 && - drawing2dMatrixCTM!.m21 == 0 && - _isNextFill)) { + if (!(drawing2dMatrixCTM!.m11 == 0 && drawing2dMatrixCTM!.m21 == 0 && _isNextFill)) { _getClipRectangle(elements!); } break; @@ -489,18 +475,10 @@ class ImageRenderer { drawing2dMatrixCTM!.offsetY); final MatrixHelper result = currentCTM * initialmatrix; final MatrixHelper transformMatrix = MatrixHelper( - result.m11, - result.m12, - result.m21, - result.m22, - result.offsetX, - result.offsetY); - MatrixHelper graphicsTransformMatrix = - MatrixHelper(1, 0, 0, 1, 0, 0); - graphicsTransformMatrix = - graphicsTransformMatrix * transformMatrix; - _graphicsObject!.transformMatrix = - MatrixHelper(1, 0, 0, 1, 0, 0) * transformMatrix; + result.m11, result.m12, result.m21, result.m22, result.offsetX, result.offsetY); + MatrixHelper graphicsTransformMatrix = MatrixHelper(1, 0, 0, 1, 0, 0); + graphicsTransformMatrix = graphicsTransformMatrix * transformMatrix; + _graphicsObject!.transformMatrix = MatrixHelper(1, 0, 0, 1, 0, 0) * transformMatrix; break; } case 'W': @@ -558,8 +536,7 @@ class ImageRenderer { } fontSize = double.tryParse(fontElements[i + 1]); if (_resources!.containsKey(currentFont)) { - final FontStructure structure = - _resources![currentFont!] as FontStructure; + final FontStructure structure = _resources![currentFont!] as FontStructure; if (structure.isStandardFont) { structure.createStandardFont(fontSize!); } else if (structure.isStandardCJKFont) { @@ -577,8 +554,7 @@ class ImageRenderer { ? _currentLocation!.dy - (-textLeading!) : _currentLocation!.dy + (-textLeading!)); } else { - _currentLocation = - Offset(_currentLocation!.dx, _currentLocation!.dy + fontSize!); + _currentLocation = Offset(_currentLocation!.dx, _currentLocation!.dy + fontSize!); } } @@ -599,20 +575,14 @@ class ImageRenderer { xObjectElement.isPrintSelected = selectablePrintDocument; xObjectElement.pageHeight = pageHeight; } - final Map result = xObjectElement.renderTextElement( - _graphicsObject, - _resources, - _graphicsState, - graphicsObjects, - currentPageHeight, - xObjectGlyphs); + final Map result = xObjectElement.renderTextElement(_graphicsObject, + _resources, _graphicsState, graphicsObjects, currentPageHeight, xObjectGlyphs); _graphicsState = result['graphicStates'] as GraphicStateCollection?; graphicsObjects = result['objects'] as GraphicObjectDataCollection?; xObjectGlyphs = result['glyphList'] as List?; final List? tempExtractTextElement = result['extractTextElement'] as List?; - if (tempExtractTextElement != null && - tempExtractTextElement.isNotEmpty) { + if (tempExtractTextElement != null && tempExtractTextElement.isNotEmpty) { extractTextElement.addAll(tempExtractTextElement); } imageRenderGlyphList.addAll(xObjectGlyphs!); @@ -621,26 +591,19 @@ class ImageRenderer { } } - void _renderTextElementWithLeading( - List textElements, String tokenType) { + void _renderTextElementWithLeading(List textElements, String tokenType) { String text = textElements.join(); final List retrievedCharCodes = []; if (_resources!.containsKey(currentFont)) { - final FontStructure structure = - _resources![currentFont!] as FontStructure; + final FontStructure structure = _resources![currentFont!] as FontStructure; structure.isSameFont = _resources!.isSameFont(); structure.fontSize = fontSize; - if (!structure.isEmbedded && - structure.font != null && - structure.isStandardCJKFont) { + if (!structure.isEmbedded && structure.font != null && structure.isStandardCJKFont) { text = structure.fromUnicodeText(structure.getEncodedText(text, true)); - } else if (!structure.isEmbedded && - structure.font != null && - structure.isStandardFont) { + } else if (!structure.isEmbedded && structure.font != null && structure.isStandardFont) { text = structure.getEncodedText(text, true); } else { - text = structure.decodeTextExtraction( - text, _resources!.isSameFont(), retrievedCharCodes); + text = structure.decodeTextExtraction(text, _resources!.isSameFont(), retrievedCharCodes); } if (_actualText != null && _actualText!.isNotEmpty) { text = _actualText!; @@ -685,8 +648,7 @@ class ImageRenderer { _endTextPosition = currentLocation!; final Map renderedResult = element.renderTextElement( _graphicsObject, - Offset(_endTextPosition.dx, - _endTextPosition.dy + ((-textLeading!) / 4)), + Offset(_endTextPosition.dx, _endTextPosition.dy + ((-textLeading!) / 4)), _textScaling, glyphWidths, structure.type1GlyphHeight, @@ -698,12 +660,10 @@ class ImageRenderer { _textElementWidth = renderedResult['textElementWidth'] as double; textMatrix = renderedResult['tempTextMatrix'] as MatrixHelper; } else { - _endTextPosition = Offset( - _endTextPosition.dx + _textElementWidth, _endTextPosition.dy); + _endTextPosition = Offset(_endTextPosition.dx + _textElementWidth, _endTextPosition.dy); final Map renderedResult = element.renderTextElement( _graphicsObject, - Offset( - _endTextPosition.dx, _endTextPosition.dy + (-textLeading! / 4)), + Offset(_endTextPosition.dx, _endTextPosition.dy + (-textLeading! / 4)), _textScaling, glyphWidths, structure.type1GlyphHeight, @@ -715,18 +675,12 @@ class ImageRenderer { textMatrix = renderedResult['tempTextMatrix'] as MatrixHelper; } if (!structure.isWhiteSpace) { - if (_whiteSpace.isNotEmpty && - extractTextElement.isNotEmpty && - _whiteSpace.length == 1) { - if (extractTextElement[extractTextElement.length - 1] - .textLineMatrix! - .offsetY == + if (_whiteSpace.isNotEmpty && extractTextElement.isNotEmpty && _whiteSpace.length == 1) { + if (extractTextElement[extractTextElement.length - 1].textLineMatrix!.offsetY == element.textLineMatrix!.offsetY && - _whiteSpace[0].textLineMatrix!.offsetY == - element.textLineMatrix!.offsetY) { + _whiteSpace[0].textLineMatrix!.offsetY == element.textLineMatrix!.offsetY) { if (_whiteSpace[0].text.isNotEmpty) { - element.textElementGlyphList - .insert(0, _whiteSpace[0].textElementGlyphList[0]); + element.textElementGlyphList.insert(0, _whiteSpace[0].textElementGlyphList[0]); } extractTextElement.add(_whiteSpace[0]); } @@ -743,32 +697,24 @@ class ImageRenderer { } } - void _renderTextElementWithSpacing( - List textElements, String tokenType) { + void _renderTextElementWithSpacing(List textElements, String tokenType) { List decodedList = []; - Map, String> decodedListCollection = - , String>{}; + Map, String> decodedListCollection = , String>{}; final String text = textElements.join(); if (_resources!.containsKey(currentFont)) { - final FontStructure structure = - _resources![currentFont!] as FontStructure; + final FontStructure structure = _resources![currentFont!] as FontStructure; structure.isSameFont = _resources!.isSameFont(); structure.fontSize = fontSize; List? characterSpacings; - if (!structure.isEmbedded && - structure.isStandardCJKFont && - structure.font != null) { - decodedList = - structure.decodeCjkTextExtractionTJ(text, _resources!.isSameFont()); + if (!structure.isEmbedded && structure.isStandardCJKFont && structure.font != null) { + decodedList = structure.decodeCjkTextExtractionTJ(text, _resources!.isSameFont()); for (final String decodedString in decodedList) { decodedListCollection[[]] = decodedString; } } else { - decodedListCollection = - structure.decodeTextExtractionTJ(text, _resources!.isSameFont()); + decodedListCollection = structure.decodeTextExtractionTJ(text, _resources!.isSameFont()); } - final List bytes = - utf8.encode(structure.getEncodedText(text, _resources!.isSameFont())); + final List bytes = utf8.encode(structure.getEncodedText(text, _resources!.isSameFont())); final Map encodedTextBytes = {}; int z = 0; for (int j = 0; j < bytes.length; j = j + 2) { @@ -819,8 +765,7 @@ class ImageRenderer { _isCurrentPositionChanged = false; _endTextPosition = currentLocation!; } else { - _endTextPosition = Offset( - _endTextPosition.dx + _textElementWidth, _endTextPosition.dy); + _endTextPosition = Offset(_endTextPosition.dx + _textElementWidth, _endTextPosition.dy); } final Map renderedResult = element.renderWithSpacing( _graphicsObject, @@ -837,18 +782,12 @@ class ImageRenderer { _textElementWidth = renderedResult['textElementWidth'] as double; textMatrix = renderedResult['tempTextMatrix'] as MatrixHelper; if (!structure.isWhiteSpace) { - if (_whiteSpace.isNotEmpty && - extractTextElement.isNotEmpty && - _whiteSpace.length == 1) { - if (extractTextElement[extractTextElement.length - 1] - .textLineMatrix! - .offsetY == - element.textLineMatrix!.offsetY && - _whiteSpace[0].textLineMatrix!.offsetY == + if (_whiteSpace.isNotEmpty && extractTextElement.isNotEmpty && _whiteSpace.length == 1) { + if (extractTextElement[extractTextElement.length - 1].textLineMatrix!.offsetY == element.textLineMatrix!.offsetY && + _whiteSpace[0].textLineMatrix!.offsetY == element.textLineMatrix!.offsetY && _whiteSpace[0].textElementGlyphList.isNotEmpty) { - element.textElementGlyphList - .insert(0, _whiteSpace[0].textElementGlyphList[0]); + element.textElementGlyphList.insert(0, _whiteSpace[0].textElementGlyphList[0]); extractTextElement.add(_whiteSpace[0]); } _whiteSpace = []; @@ -880,16 +819,14 @@ class ImageRenderer { textLineMatrix = textMatrix!.clone(); } - void _setTextMatrix( - double a, double b, double c, double d, double e, double f) { + void _setTextMatrix(double a, double b, double c, double d, double e, double f) { textMatrix = MatrixHelper(a, b, c, d, e, f); textLineMatrix = textMatrix!.clone(); } - MatrixHelper _setMatrix( - double a, double b, double c, double d, double e, double f) { - currentTransformationMatrix = MatrixHelper(a, b, c, d, e, f) * - graphicsObjects!.last.currentTransformationMatrix!; + MatrixHelper _setMatrix(double a, double b, double c, double d, double e, double f) { + currentTransformationMatrix = + MatrixHelper(a, b, c, d, e, f) * graphicsObjects!.last.currentTransformationMatrix!; return MatrixHelper( currentTransformationMatrix!.m11, currentTransformationMatrix!.m12, diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matched_item.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matched_item.dart index f45afd710..bca51f821 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matched_item.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matched_item.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; /// Details of the searched text class MatchedItem { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matrix_helper.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matrix_helper.dart index f79692d86..22ff2605b 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matrix_helper.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/matrix_helper.dart @@ -1,18 +1,16 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; /// internal class class MatrixHelper { /// internal constructor - MatrixHelper( - this.m11, this.m12, this.m21, this.m22, this.offsetX, this.offsetY) { + MatrixHelper(this.m11, this.m12, this.m21, this.m22, this.offsetX, this.offsetY) { type = MatrixTypes.unknown; _checkMatrixType(); } /// internal property - static MatrixHelper get identity => - MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + static MatrixHelper get identity => MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); //Fields /// internal field @@ -59,16 +57,15 @@ class MatrixHelper { } else { this.offsetX += offsetX; this.offsetY += offsetY; - type = _getType( - _getTypeIndex(type) | _getTypeIndex(MatrixTypes.translation)); + type = _getType(_getTypeIndex(type) | _getTypeIndex(MatrixTypes.translation)); } } return this; } /// internal method - void setMatrix(double m11, double m12, double m21, double m22, double offsetX, - double offsetY, MatrixTypes type) { + void setMatrix(double m11, double m12, double m21, double m22, double offsetX, double offsetY, + MatrixTypes type) { this.m11 = m11; this.m12 = m12; this.m21 = m21; @@ -88,8 +85,7 @@ class MatrixHelper { type = MatrixTypes.scaling; } if (offsetX != 0.0 || offsetY != 0.0) { - type = _getType( - _getTypeIndex(type) | _getTypeIndex(MatrixTypes.translation)); + type = _getType(_getTypeIndex(type) | _getTypeIndex(MatrixTypes.translation)); } if (_getTypeIndex(type) & 3 == _getTypeIndex(MatrixTypes.identity)) { type = MatrixTypes.identity; @@ -128,12 +124,10 @@ class MatrixHelper { } /// internal method - MatrixHelper scale( - double scaleX, double scaleY, double centerX, double centerY) { - final MatrixHelper newMatrix = - MatrixHelper(scaleX, 0.0, 0.0, scaleY, centerX, centerY) * this; - setMatrix(newMatrix.m11, newMatrix.m12, newMatrix.m21, newMatrix.m22, - newMatrix.offsetX, newMatrix.offsetY, newMatrix.type); + MatrixHelper scale(double scaleX, double scaleY, double centerX, double centerY) { + final MatrixHelper newMatrix = MatrixHelper(scaleX, 0.0, 0.0, scaleY, centerX, centerY) * this; + setMatrix(newMatrix.m11, newMatrix.m12, newMatrix.m21, newMatrix.m22, newMatrix.offsetX, + newMatrix.offsetY, newMatrix.type); return this; } @@ -142,30 +136,24 @@ class MatrixHelper { angle = 3.1415926535897931 * angle / 180.0; final double num1 = sin(angle); final double num2 = cos(angle); - MatrixHelper matrix = MatrixHelper( - num2, - num1, - -num1, - num2, - centerX * (1.0 - num2) + centerY * num1, - centerY * (1.0 - num2) - centerX * num1); + MatrixHelper matrix = MatrixHelper(num2, num1, -num1, num2, + centerX * (1.0 - num2) + centerY * num1, centerY * (1.0 - num2) - centerX * num1); matrix.type = MatrixTypes.unknown; matrix *= this; - setMatrix(matrix.m11, matrix.m12, matrix.m21, matrix.m22, matrix.offsetX, - matrix.offsetY, matrix.type); + setMatrix(matrix.m11, matrix.m12, matrix.m21, matrix.m22, matrix.offsetX, matrix.offsetY, + matrix.type); return this; } /// internal method Offset transform(Offset point) { - return Offset(point.dx * m11 + point.dy * m21 + offsetX, - point.dx * m12 + point.dy * m22 + offsetY); + return Offset( + point.dx * m11 + point.dy * m21 + offsetX, point.dx * m12 + point.dy * m22 + offsetY); } /// internal method MatrixHelper clone() { - final MatrixHelper result = - MatrixHelper(m11, m12, m21, m22, offsetX, offsetY); + final MatrixHelper result = MatrixHelper(m11, m12, m21, m22, offsetX, offsetY); result.type = type; return result; } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart index 0c35ab612..80f919915 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/pdf_text_extractor.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import 'package:intl/intl.dart' as bidi; @@ -48,8 +48,7 @@ class PdfTextExtractor { /// ``` PdfTextExtractor(PdfDocument document) { if (!PdfDocumentHelper.getHelper(document).isLoadedDocument) { - ArgumentError.value(document, 'document', - 'document instance is not a loaded PDF document'); + ArgumentError.value(document, 'document', 'document instance is not a loaded PDF document'); } _document = document; _initialize(); @@ -103,8 +102,7 @@ class PdfTextExtractor { /// //Dispose the document. /// document.dispose(); /// ``` - String extractText( - {int? startPageIndex, int? endPageIndex, bool? layoutText}) { + String extractText({int? startPageIndex, int? endPageIndex, bool? layoutText}) { _isLayout = layoutText ?? false; return _extractText(startPageIndex, endPageIndex); } @@ -156,9 +154,7 @@ class PdfTextExtractor { /// document.dispose(); /// ``` List findText(List searchString, - {int? startPageIndex, - int? endPageIndex, - TextSearchOption? searchOption}) { + {int? startPageIndex, int? endPageIndex, TextSearchOption? searchOption}) { return _findText(searchString, startPageIndex, endPageIndex, searchOption); } @@ -182,8 +178,8 @@ class PdfTextExtractor { String _extractText(int? startPageIndex, int? endPageIndex) { if (startPageIndex == null) { if (endPageIndex != null) { - throw ArgumentError.value(endPageIndex, 'endPageIndex', - 'Invalid argument. start page index cannot be null'); + throw ArgumentError.value( + endPageIndex, 'endPageIndex', 'Invalid argument. start page index cannot be null'); } else { return _extractTextFromRange(0, _document.pages.count - 1); } @@ -201,8 +197,8 @@ class PdfTextExtractor { List _extractTextLines(int? startPageIndex, int? endPageIndex) { if (startPageIndex == null) { if (endPageIndex != null) { - throw ArgumentError.value(endPageIndex, 'endPageIndex', - 'Invalid argument. start page index cannot be null'); + throw ArgumentError.value( + endPageIndex, 'endPageIndex', 'Invalid argument. start page index cannot be null'); } else { return _extractTextLineFromRange(0, _document.pages.count - 1); } @@ -217,26 +213,23 @@ class PdfTextExtractor { } } - List _findText(List searchString, int? startPageIndex, - int? endPageIndex, TextSearchOption? searchOption) { + List _findText(List searchString, int? startPageIndex, int? endPageIndex, + TextSearchOption? searchOption) { if (startPageIndex == null) { if (endPageIndex != null) { - throw ArgumentError.value(endPageIndex, 'endPageIndex', - 'Invalid argument. start page index cannot be null'); + throw ArgumentError.value( + endPageIndex, 'endPageIndex', 'Invalid argument. start page index cannot be null'); } else { - return _findTextFromRange( - 0, _document.pages.count - 1, searchString, searchOption); + return _findTextFromRange(0, _document.pages.count - 1, searchString, searchOption); } } else if (endPageIndex == null) { _checkPageNumber(startPageIndex); _currentPageIndex = startPageIndex; - return _searchInBackground( - _document.pages[startPageIndex], searchString, searchOption); + return _searchInBackground(_document.pages[startPageIndex], searchString, searchOption); } else { _checkPageNumber(startPageIndex); _checkPageNumber(endPageIndex); - return _findTextFromRange( - startPageIndex, endPageIndex, searchString, searchOption); + return _findTextFromRange(startPageIndex, endPageIndex, searchString, searchOption); } } @@ -245,8 +238,7 @@ class PdfTextExtractor { for (int i = startPageIndex; i <= endPageIndex; i++) { final String text = _getText(_document.pages[i]); resultText = resultText + - (i > startPageIndex && - (!_isLayout || (_isLayout && !resultText.endsWith('\n'))) + (i > startPageIndex && (!_isLayout || (_isLayout && !resultText.endsWith('\n'))) ? '\r\n' : '') + text; @@ -254,8 +246,7 @@ class PdfTextExtractor { return resultText; } - List _extractTextLineFromRange( - int startPageIndex, int endPageIndex) { + List _extractTextLineFromRange(int startPageIndex, int endPageIndex) { final List result = []; for (int i = startPageIndex; i <= endPageIndex; i++) { _currentPageIndex = i; @@ -292,8 +283,8 @@ class PdfTextExtractor { String resultantText; if (_isLayout) { try { - _initialTransform = MatrixHelper(1.3333333333333333, 0, 0, - -1.3333333333333333, 0, page.size.height * 1.3333333333333333); + _initialTransform = MatrixHelper(1.3333333333333333, 0, 0, -1.3333333333333333, 0, + page.size.height * 1.3333333333333333); } catch (e) { _initialTransform = MatrixHelper.identity; } @@ -336,10 +327,9 @@ class PdfTextExtractor { final bool isChanged = _checkPageDictionary(pdfPage); final bool isContentChanged = _checkContentArray(pdfPage); final PdfRecordCollection? recordCollection = _getRecordCollection(pdfPage); - final PdfPageResources pageResources = - _resourceLoader.getPageResources(pdfPage); - final ImageRenderer renderer = ImageRenderer(recordCollection, - pageResources, pdfPage.size.height * 1.3333333333333333); + final PdfPageResources pageResources = _resourceLoader.getPageResources(pdfPage); + final ImageRenderer renderer = + ImageRenderer(recordCollection, pageResources, pdfPage.size.height * 1.3333333333333333); renderer.isExtractLineCollection = true; final double rotation = _getPageRotation(pdfPage); renderer.pageRotation = rotation; @@ -380,15 +370,14 @@ class PdfTextExtractor { (i == renderer.imageRenderGlyphList.length - 1)) { offsetY = yPos.toInt(); if (textLine.wordCollection.isNotEmpty) { - result.add(_prepareTextLine( - textLine, renderer, lineStartIndex, i, rotation)); + result.add(_prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); } lineStartIndex = i; textLine = TextLineHelper.initialize(); } final TextElement textElement = renderer.extractTextElement[k]; - final List words = _splitRenderedText( - textElement.renderedText, renderer.imageRenderGlyphList, i); + final List words = + _splitRenderedText(textElement.renderedText, renderer.imageRenderGlyphList, i); textElement.text = ' '; TextWord? textwords; List glyphs = []; @@ -399,8 +388,8 @@ class PdfTextExtractor { for (int m = i; m < i + words[x].length; m++) { final Glyph tempGlyph = renderer.imageRenderGlyphList[m]; final Rect tempBounds = tempGlyph.boundingRect; - final Rect glyphBounds = Rect.fromLTRB(tempBounds.left, - tempBounds.top, tempBounds.right, tempBounds.bottom); + final Rect glyphBounds = Rect.fromLTRB( + tempBounds.left, tempBounds.top, tempBounds.right, tempBounds.bottom); final TextGlyph textGlyph = TextGlyphHelper.initialize( tempGlyph.toUnicode, textElement.fontName, @@ -416,40 +405,26 @@ class PdfTextExtractor { dy = renderer.imageRenderGlyphList[i].boundingRect.top; if (hasRotation && rotation == 270) { width = renderer.imageRenderGlyphList[i].boundingRect.width; - height = renderer - .imageRenderGlyphList[lastIndex].boundingRect.bottom; + height = renderer.imageRenderGlyphList[lastIndex].boundingRect.bottom; wordBound = Rect.fromLTWH(dx, dy, width, height - dy); } else { height = renderer.imageRenderGlyphList[i].boundingRect.height; - if (dx > - renderer - .imageRenderGlyphList[lastIndex].boundingRect.left) { - width = (dx - - renderer.imageRenderGlyphList[lastIndex].boundingRect - .left) + - renderer - .imageRenderGlyphList[lastIndex].boundingRect.width; + if (dx > renderer.imageRenderGlyphList[lastIndex].boundingRect.left) { + width = (dx - renderer.imageRenderGlyphList[lastIndex].boundingRect.left) + + renderer.imageRenderGlyphList[lastIndex].boundingRect.width; } else { - width = (renderer - .imageRenderGlyphList[lastIndex].boundingRect.left) + - renderer - .imageRenderGlyphList[lastIndex].boundingRect.width; + width = (renderer.imageRenderGlyphList[lastIndex].boundingRect.left) + + renderer.imageRenderGlyphList[lastIndex].boundingRect.width; } wordBound = Rect.fromLTWH(dx, dy, width - dx, height); } i = lastIndex + 1; String word = words[x]; if (word.isNotEmpty && bidi.Bidi.hasAnyRtl(word)) { - word = _bidi.getLogicalToVisualString(word, true)['rtlText'] - as String; + word = _bidi.getLogicalToVisualString(word, true)['rtlText'] as String; } - textwords = TextWordHelper.initialize( - word, - textElement.fontName, - textElement.fontStyle, - glyphs, - _calculateBounds(wordBound), - textElement.fontSize); + textwords = TextWordHelper.initialize(word, textElement.fontName, + textElement.fontStyle, glyphs, _calculateBounds(wordBound), textElement.fontSize); textLine.wordCollection.add(textwords); } textElement.text = words[x]; @@ -458,14 +433,13 @@ class PdfTextExtractor { i <= renderer.imageRenderGlyphList.length - 1 && renderer.imageRenderGlyphList[i].toUnicode == ' ') { if (i != 0) { - final Map tempResult = _addSpace(textwords, - renderer, textElement, i, dx, dy, width, height); + final Map tempResult = + _addSpace(textwords, renderer, textElement, i, dx, dy, width, height); dx = tempResult['dx'] as double?; dy = tempResult['dy'] as double?; width = tempResult['width'] as double?; height = tempResult['height'] as double?; - final Rect wordBound = - Rect.fromLTWH(dx!, dy!, width!, height!); + final Rect wordBound = Rect.fromLTWH(dx!, dy!, width!, height!); tempResult['word'].bounds = _calculateBounds(wordBound); textLine.wordCollection.add(tempResult['word']); } @@ -476,24 +450,20 @@ class PdfTextExtractor { renderer.imageRenderGlyphList[i].toUnicode == ' ' && ((renderer.imageRenderGlyphList[i].isRotated && (rotation == 270 || rotation == 90)) || - renderer.imageRenderGlyphList[i].boundingRect.top - .toInt() == - offsetY)) { + renderer.imageRenderGlyphList[i].boundingRect.top.toInt() == offsetY)) { i = i + 1; } } else { if (i <= renderer.imageRenderGlyphList.length - 1) { - if (x != words.length - 1 && - renderer.imageRenderGlyphList[i].toUnicode == ' ') { + if (x != words.length - 1 && renderer.imageRenderGlyphList[i].toUnicode == ' ') { if (i != 0) { - final Map tempResult = _addSpace(textwords, - renderer, textElement, i, dx, dy, width, height); + final Map tempResult = + _addSpace(textwords, renderer, textElement, i, dx, dy, width, height); dx = tempResult['dx'] as double?; dy = tempResult['dy'] as double?; width = tempResult['width'] as double?; height = tempResult['height'] as double?; - final Rect wordBound = - Rect.fromLTWH(dx!, dy!, width!, height!); + final Rect wordBound = Rect.fromLTWH(dx!, dy!, width!, height!); tempResult['word'].bounds = _calculateBounds(wordBound); textLine.wordCollection.add(tempResult['word']); } @@ -510,8 +480,7 @@ class PdfTextExtractor { if (renderer.extractTextElement.isNotEmpty && k == 0) { offsetY = yPos.toInt(); if (textLine.wordCollection.isNotEmpty) { - result.add(_prepareTextLine( - textLine, renderer, lineStartIndex, i, rotation)); + result.add(_prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); } lineStartIndex = i; textLine = TextLineHelper.initialize(); @@ -525,14 +494,12 @@ class PdfTextExtractor { !result.contains(textLine) && element.renderedText != '' && element.renderedText != ' ') { - result.add( - _prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); + result.add(_prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); textLine = TextLineHelper.initialize(); } } if (textLine.wordCollection.isNotEmpty && !result.contains(textLine)) { - result.add( - _prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); + result.add(_prepareTextLine(textLine, renderer, lineStartIndex, i, rotation)); textLine = TextLineHelper.initialize(); } PdfPageHelper.getHelper(pdfPage).contents.changed = isContentChanged; @@ -569,9 +536,7 @@ class PdfTextExtractor { } final Rect currentRect = textGlyph.boundingRect; if (previousRect != null) { - if ((previousRect.left + previousRect.width - currentRect.left) - .abs() > - 1.5) { + if ((previousRect.left + previousRect.width - currentRect.left).abs() > 1.5) { isSplit = true; } else { tempString += text[j]; @@ -611,20 +576,17 @@ class PdfTextExtractor { _isLayout = false; final bool containsRtl = bidi.Bidi.hasAnyRtl(pageText); if (pageText != '') { - bool isMatched = - _isMatchFound(searchString, searchOption, pageText, containsRtl); + bool isMatched = _isMatchFound(searchString, searchOption, pageText, containsRtl); if (isMatched || containsRtl) { _currentPage = page; _fontSize = 0; PdfPageHelper.getHelper(page).isTextExtraction = true; final bool isChanged = _checkPageDictionary(page); final bool isContentChanged = _checkContentArray(page); - final PdfRecordCollection? recordCollection = - _getRecordCollection(page); - final PdfPageResources pageResources = - _resourceLoader.getPageResources(page); - final ImageRenderer renderer = ImageRenderer(recordCollection, - pageResources, page.size.height * 1.3333333333333333); + final PdfRecordCollection? recordCollection = _getRecordCollection(page); + final PdfPageResources pageResources = _resourceLoader.getPageResources(page); + final ImageRenderer renderer = + ImageRenderer(recordCollection, pageResources, page.size.height * 1.3333333333333333); renderer.pageRotation = _getPageRotation(page); renderer.renderAsImage(); String renderedString = ''; @@ -642,8 +604,7 @@ class PdfTextExtractor { final Map visualOrderResult = _bidi.getLogicalToVisualString(renderedString, true); renderedString = visualOrderResult['rtlText'] as String; - final List visualOrderIndexes = - visualOrderResult['orderedIndexes'] as List; + final List visualOrderIndexes = visualOrderResult['orderedIndexes'] as List; visualOrderedTextGlyph = []; if (combinedGlyphLength.isNotEmpty) { combinedGlyphLength.forEach((int key, int value) { @@ -651,12 +612,9 @@ class PdfTextExtractor { final int newIndex = visualOrderIndexes.indexOf(key); if (newIndex + 1 < visualOrderIndexes.length && visualOrderIndexes[newIndex + 1] == key + 1) { - visualOrderIndexes.removeRange( - newIndex + 1, newIndex + value); - } else if (newIndex - 1 > -1 && - visualOrderIndexes[newIndex - 1] == key + 1) { - visualOrderIndexes.removeRange( - newIndex - value + 1, newIndex); + visualOrderIndexes.removeRange(newIndex + 1, newIndex + value); + } else if (newIndex - 1 > -1 && visualOrderIndexes[newIndex - 1] == key + 1) { + visualOrderIndexes.removeRange(newIndex - value + 1, newIndex); } } }); @@ -669,8 +627,7 @@ class PdfTextExtractor { for (final int element in combinedGlyphLength.values) { tempValue += element - 1; } - for (final int key - in combinedGlyphLength.keys.toList().reversed) { + for (final int key in combinedGlyphLength.keys.toList().reversed) { if (index > key) { index -= tempValue; break; @@ -679,23 +636,18 @@ class PdfTextExtractor { } } if (index < glyphListLength) { - visualOrderedTextGlyph - .add(renderer.imageRenderGlyphList[index]); + visualOrderedTextGlyph.add(renderer.imageRenderGlyphList[index]); } } } - final List renderedStringCollection = [ - renderedString - ]; + final List renderedStringCollection = [renderedString]; final List?> textGlyphCollection = ?>[ visualOrderedTextGlyph ?? renderer.imageRenderGlyphList ]; - if (renderedString.contains(' ') || - renderedString.contains('\t\t')) { + if (renderedString.contains(' ') || renderedString.contains('\t\t')) { String innerSpaceTrimmedString = renderedString; final List innerSpaceTrimmedTextGlyph = - (visualOrderedTextGlyph ?? renderer.imageRenderGlyphList) - .toList(); + (visualOrderedTextGlyph ?? renderer.imageRenderGlyphList).toList(); while (innerSpaceTrimmedString.contains(' ') || innerSpaceTrimmedString.contains('\t\t')) { int spaceStartIndex = innerSpaceTrimmedString.indexOf(' '); @@ -703,8 +655,7 @@ class PdfTextExtractor { spaceStartIndex = innerSpaceTrimmedString.indexOf('\t\t'); } if (spaceStartIndex >= 0) { - final List stringList = - innerSpaceTrimmedString.split(''); + final List stringList = innerSpaceTrimmedString.split(''); int i = spaceStartIndex + 2; for (i = spaceStartIndex + 2; i < stringList.length; i++) { if (stringList[i] == ' ' || stringList[i] == '\t') { @@ -713,8 +664,7 @@ class PdfTextExtractor { break; } else { stringList.removeRange(spaceStartIndex + 1, i); - innerSpaceTrimmedTextGlyph.removeRange( - spaceStartIndex + 1, i); + innerSpaceTrimmedTextGlyph.removeRange(spaceStartIndex + 1, i); break; } } @@ -729,22 +679,15 @@ class PdfTextExtractor { } if (!isMatched) { for (final String renderedText in renderedStringCollection) { - isMatched = _isMatchFound( - searchString, searchOption, renderedText, containsRtl); + isMatched = _isMatchFound(searchString, searchOption, renderedText, containsRtl); if (isMatched) { break; } } } if (isMatched) { - _getMatchedItems( - page, - searchString, - searchOption, - renderedStringCollection, - combinedGlyphLength, - textGlyphCollection, - result); + _getMatchedItems(page, searchString, searchOption, renderedStringCollection, + combinedGlyphLength, textGlyphCollection, result); } } PdfPageHelper.getHelper(page).contents.changed = isContentChanged; @@ -755,8 +698,8 @@ class PdfTextExtractor { return result; } - bool _isMatchFound(List searchString, TextSearchOption? searchOption, - String pageText, bool containsRtl) { + bool _isMatchFound(List searchString, TextSearchOption? searchOption, String pageText, + bool containsRtl) { ArabicShapeRenderer? shapeRenderer; if (containsRtl) { shapeRenderer = ArabicShapeRenderer(); @@ -791,8 +734,7 @@ class PdfTextExtractor { List termCollection = [term]; for (int j = 0; j < term.length; j++) { if (shapeRenderer.arabicMapTable.containsKey(term[j])) { - final List? shapedChars = - shapeRenderer.arabicMapTable[term[j]]; + final List? shapedChars = shapeRenderer.arabicMapTable[term[j]]; if (shapedChars != null && shapedChars.isNotEmpty) { final List tempTermCollection = termCollection.toList(); for (final String char in shapedChars) { @@ -803,9 +745,7 @@ class PdfTextExtractor { if (!tempTermCollection.contains(tempRenderedTerm)) { tempTermCollection.add(tempRenderedTerm); if (!searchString.contains(tempRenderedTerm) && - pageText - .toLowerCase() - .contains(tempRenderedTerm.toLowerCase())) { + pageText.toLowerCase().contains(tempRenderedTerm.toLowerCase())) { searchString.add(tempRenderedTerm); isMatched = true; } @@ -833,16 +773,14 @@ class PdfTextExtractor { Map combinedGlyphLength, List?> glyphListCollection, List result) { - if (renderedStringCollection.isNotEmpty && - renderedStringCollection[0] != '') { + if (renderedStringCollection.isNotEmpty && renderedStringCollection[0] != '') { final Map> mappedIndexes = >{}; final List textLengthCollection = []; for (int i = 0; i < renderedStringCollection.length; i++) { if (searchOption == null || (searchOption != TextSearchOption.caseSensitive && searchOption != TextSearchOption.both)) { - renderedStringCollection[i] = - renderedStringCollection[i].toLowerCase(); + renderedStringCollection[i] = renderedStringCollection[i].toLowerCase(); } textLengthCollection.add(renderedStringCollection[i].length); } @@ -859,26 +797,20 @@ class PdfTextExtractor { for (int i = 0; i < renderedStringCollection.length; i++) { while (startIndex <= textLengthCollection[i] && renderedStringCollection[i].contains(currentText, startIndex)) { - int index = - renderedStringCollection[i].indexOf(currentText, startIndex); + int index = renderedStringCollection[i].indexOf(currentText, startIndex); final int tempIndex = index; if (searchOption != null && (searchOption == TextSearchOption.wholeWords || searchOption == TextSearchOption.both)) { - if (index == 0 || - _hasEscapeCharacter( - renderedStringCollection[i][index - 1])) { + if (index == 0 || _hasEscapeCharacter(renderedStringCollection[i][index - 1])) { if (index + length == textLengthCollection[i]) { if (combinedGlyphLength.isNotEmpty) { - index = - _checkCombinedTextIndex(index, combinedGlyphLength); + index = _checkCombinedTextIndex(index, combinedGlyphLength); } indexes.add(index); - } else if (_hasEscapeCharacter( - renderedStringCollection[i][index + length])) { + } else if (_hasEscapeCharacter(renderedStringCollection[i][index + length])) { if (combinedGlyphLength.isNotEmpty) { - index = - _checkCombinedTextIndex(index, combinedGlyphLength); + index = _checkCombinedTextIndex(index, combinedGlyphLength); } indexes.add(index); } @@ -893,16 +825,10 @@ class PdfTextExtractor { } if (indexes.isNotEmpty) { for (final int index in indexes) { - if (glyphListCollection[i] != null && - index < glyphListCollection[i]!.length) { + if (glyphListCollection[i] != null && index < glyphListCollection[i]!.length) { final List rect = _calculatedTextounds( - glyphListCollection[i]!, - term, - index, - page, - bidi.Bidi.hasAnyRtl(term)); - result.add(MatchedItemHelper.initialize( - term, rect, _currentPageIndex)); + glyphListCollection[i]!, term, index, page, bidi.Bidi.hasAnyRtl(term)); + result.add(MatchedItemHelper.initialize(term, rect, _currentPageIndex)); } } break; @@ -913,8 +839,7 @@ class PdfTextExtractor { } } - int _checkCombinedTextIndex( - int textIndex, Map combinedGlyphLength) { + int _checkCombinedTextIndex(int textIndex, Map combinedGlyphLength) { int adjustableLength = 0; combinedGlyphLength.forEach((int index, int length) { if (index < textIndex) { @@ -927,8 +852,7 @@ class PdfTextExtractor { PdfRecordCollection? _getRecordCollection(PdfPage page) { PdfRecordCollection? recordCollection; List? combinedData = - PdfPageLayerCollectionHelper.getHelper(page.layers) - .combineContent(true); + PdfPageLayerCollectionHelper.getHelper(page.layers).combineContent(true); if (combinedData != null) { final ContentParser parser = ContentParser(combinedData); parser.isTextExtractionProcess = true; @@ -947,11 +871,9 @@ class PdfTextExtractor { bool _checkContentArray(PdfPage page) { bool isContentChanged = false; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.contents)) { - final IPdfPrimitive? contents = PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.contents]; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.contents)) { + final IPdfPrimitive? contents = + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.contents]; if (contents is PdfReferenceHolder) { final PdfReferenceHolder holder = contents; final IPdfPrimitive? primitive = holder.object; @@ -967,18 +889,11 @@ class PdfTextExtractor { return isContentChanged; } - Map _addSpace( - TextWord? textwords, - ImageRenderer renderer, - TextElement textElement, - int i, - double? dx, - double? dy, - double? width, - double? height) { + Map _addSpace(TextWord? textwords, ImageRenderer renderer, + TextElement textElement, int i, double? dx, double? dy, double? width, double? height) { final Rect tempBounds = renderer.imageRenderGlyphList[i].boundingRect; - final Rect glyphBounds = Rect.fromLTWH( - tempBounds.left, tempBounds.top, tempBounds.width, tempBounds.height); + final Rect glyphBounds = + Rect.fromLTWH(tempBounds.left, tempBounds.top, tempBounds.width, tempBounds.height); final TextGlyph textGlyph = TextGlyphHelper.initialize( renderer.imageRenderGlyphList[i].toUnicode, textElement.fontName, @@ -997,13 +912,8 @@ class PdfTextExtractor { renderer.imageRenderGlyphList[i].boundingRect.width; } return { - 'word': TextWordHelper.initialize( - ' ', - textElement.fontName, - textElement.fontStyle, - [textGlyph], - Rect.fromLTWH(dx, dy, width, height), - textElement.fontSize), + 'word': TextWordHelper.initialize(' ', textElement.fontName, textElement.fontStyle, + [textGlyph], Rect.fromLTWH(dx, dy, width, height), textElement.fontSize), 'dx': dx, 'dy': dy, 'width': width, @@ -1047,11 +957,9 @@ class PdfTextExtractor { } textCollection.forEach((int key, String value) { if (bidi.Bidi.hasAnyRtl(value)) { - boundsCollection - .add(_calculateBounds(_getRTLBounds(glyphs, value, key, page))); + boundsCollection.add(_calculateBounds(_getRTLBounds(glyphs, value, key, page))); } else { - boundsCollection - .add(_calculateBounds(_getLTRBounds(glyphs, value, key, page))); + boundsCollection.add(_calculateBounds(_getLTRBounds(glyphs, value, key, page))); } }); return boundsCollection; @@ -1082,8 +990,7 @@ class PdfTextExtractor { } final Glyph endGlyph = glyphs[endIndex]; if (startGlyph.boundingRect.top == endGlyph.boundingRect.top || - (startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < - 0.001) { + (startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < 0.001) { if (x > endGlyph.boundingRect.left) { width = (x - endGlyph.boundingRect.left) + endGlyph.boundingRect.width; if (page.rotation == PdfPageRotateAngle.rotateAngle0 || @@ -1109,11 +1016,9 @@ class PdfTextExtractor { width = (endGlyph.boundingRect.left - x) + endGlyph.boundingRect.width; } } else if (startGlyph.boundingRect.left == endGlyph.boundingRect.left || - (startGlyph.boundingRect.left - endGlyph.boundingRect.left).abs() < - 0.001) { + (startGlyph.boundingRect.left - endGlyph.boundingRect.left).abs() < 0.001) { if (startGlyph.boundingRect.top != endGlyph.boundingRect.top && - !((startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < - 0.001)) { + !((startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < 0.001)) { height = 0; if (page.rotation == PdfPageRotateAngle.rotateAngle0 || page.rotation == PdfPageRotateAngle.rotateAngle180) { @@ -1134,8 +1039,7 @@ class PdfTextExtractor { if (y > endGlyph.boundingRect.top || startGlyph.rotationAngle == 270) { x = startGlyph.boundingRect.left - width + 1; y = startGlyph.boundingRect.top - height; - } else if (y < endGlyph.boundingRect.top || - startGlyph.rotationAngle == 90) { + } else if (y < endGlyph.boundingRect.top || startGlyph.rotationAngle == 90) { x = startGlyph.boundingRect.left - 1; y = startGlyph.boundingRect.top; } @@ -1162,8 +1066,7 @@ class PdfTextExtractor { } final Glyph endGlyph = glyphs[endIndex]; if (startGlyph.boundingRect.top == endGlyph.boundingRect.top || - (startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < - 0.001) { + (startGlyph.boundingRect.top - endGlyph.boundingRect.top).abs() < 0.001) { width = (x - endGlyph.boundingRect.left) + startGlyph.boundingRect.width; x = startGlyph.boundingRect.left + startGlyph.boundingRect.width - width; } @@ -1189,16 +1092,13 @@ class PdfTextExtractor { if (!PdfPageHelper.getHelper(_currentPage!).cropBox.isEmpty && PdfPageHelper.getHelper(_currentPage!).cropBox != PdfPageHelper.getHelper(_currentPage!).mediaBox) { - final double x = - bounds.left - PdfPageHelper.getHelper(_currentPage!).cropBox.left; - final double y = - bounds.top + PdfPageHelper.getHelper(_currentPage!).cropBox.top; + final double x = bounds.left - PdfPageHelper.getHelper(_currentPage!).cropBox.left; + final double y = bounds.top + PdfPageHelper.getHelper(_currentPage!).cropBox.top; return Rect.fromLTWH(x, y, bounds.width, bounds.height); } else if (!PdfPageHelper.getHelper(_currentPage!).mediaBox.isEmpty && (PdfPageHelper.getHelper(_currentPage!).mediaBox.left != 0 || PdfPageHelper.getHelper(_currentPage!).mediaBox.top != 0)) { - final double cLeft = - PdfPageHelper.getHelper(_currentPage!).mediaBox.left; + final double cLeft = PdfPageHelper.getHelper(_currentPage!).mediaBox.left; final double ctop = PdfPageHelper.getHelper(_currentPage!).mediaBox.top; final double x = bounds.left - cLeft; final double y = bounds.top + ctop; @@ -1208,8 +1108,8 @@ class PdfTextExtractor { return bounds; } - TextLine _prepareTextLine(TextLine textLine, ImageRenderer renderer, - int lineStartIndex, int glyphIndex, double rotation) { + TextLine _prepareTextLine(TextLine textLine, ImageRenderer renderer, int lineStartIndex, + int glyphIndex, double rotation) { bool isSameFontName = true; bool isSameFontSize = true; bool isSameFontStyle = true; @@ -1217,8 +1117,7 @@ class PdfTextExtractor { double? fontSize = 0; textLine.pageIndex = _currentPageIndex; List? fontStyle = [PdfFontStyle.regular]; - if (rotation == 270 && - renderer.imageRenderGlyphList[lineStartIndex].isRotated) { + if (rotation == 270 && renderer.imageRenderGlyphList[lineStartIndex].isRotated) { textLine.bounds = Rect.fromLTWH( renderer.imageRenderGlyphList[lineStartIndex].boundingRect.left, renderer.imageRenderGlyphList[lineStartIndex].boundingRect.top, @@ -1280,17 +1179,14 @@ class PdfTextExtractor { } } if (textLine.text.isNotEmpty && bidi.Bidi.hasAnyRtl(textLine.text)) { - textLine.text = _bidi.getLogicalToVisualString( - textLine.text, true)['rtlText'] as String; + textLine.text = _bidi.getLogicalToVisualString(textLine.text, true)['rtlText'] as String; } return textLine; } - String _renderText( - PdfRecordCollection? recordCollection, PdfPageResources pageResources) { + String _renderText(PdfRecordCollection? recordCollection, PdfPageResources pageResources) { String resultantText = ''; - if (recordCollection != null && - recordCollection.recordCollection.isNotEmpty) { + if (recordCollection != null && recordCollection.recordCollection.isNotEmpty) { final List records = recordCollection.recordCollection; for (int i = 0; i < records.length; i++) { final PdfRecord record = records[i]; @@ -1334,8 +1230,7 @@ class PdfTextExtractor { case 'TJ': case "'": { - final String? resultText = (_actualText != null && - _actualText!.isNotEmpty) + final String? resultText = (_actualText != null && _actualText!.isNotEmpty) ? _actualText : _renderTextElement(elements!, token, pageResources, null); if (resultText != null) { @@ -1348,8 +1243,7 @@ class PdfTextExtractor { } case 'Do': { - final String? result = - _getXObject(resultantText, elements!, pageResources); + final String? result = _getXObject(resultantText, elements!, pageResources); if (result != null && result != '') { resultantText += result; } @@ -1381,8 +1275,7 @@ class PdfTextExtractor { bool spaceBetweenWord = false; bool isSpaceAdded = false; _tempBoundingRectangle = Rect.zero; - if (recordCollection != null && - recordCollection.recordCollection.isNotEmpty) { + if (recordCollection != null && recordCollection.recordCollection.isNotEmpty) { final List records = recordCollection.recordCollection; for (int i = 0; i < records.length; i++) { final PdfRecord record = records[i]; @@ -1476,18 +1369,11 @@ class PdfTextExtractor { { textLeading = double.tryParse(elements![1]); _textMatrix = MatrixHelper( - 1, - 0, - 0, - 1, - double.tryParse(elements[0])!, - double.tryParse(elements[1])!) * + 1, 0, 0, 1, double.tryParse(elements[0])!, double.tryParse(elements[1])!) * _textLineMatrix!; _textLineMatrix = _textMatrix!.clone(); if (_textLineMatrix!.offsetY != _currentTextMatrix!.offsetY || - (_hasBDC && - _textLineMatrix!.offsetX != _currentTextMatrix!.offsetX && - !hasTj)) { + (_hasBDC && _textLineMatrix!.offsetX != _currentTextMatrix!.offsetX && !hasTj)) { _tempBoundingRectangle = Rect.zero; _hasBDC = false; } @@ -1496,28 +1382,18 @@ class PdfTextExtractor { case 'Td': { _textMatrix = MatrixHelper( - 1, - 0, - 0, - 1, - double.tryParse(elements![0])!, - double.tryParse(elements[1])!) * + 1, 0, 0, 1, double.tryParse(elements![0])!, double.tryParse(elements[1])!) * _textLineMatrix!; _textLineMatrix = _textMatrix!.clone(); if (_textLineMatrix!.offsetY != _currentTextMatrix!.offsetY || - (_hasBDC && - _textLineMatrix!.offsetX != - _currentTextMatrix!.offsetX)) { + (_hasBDC && _textLineMatrix!.offsetX != _currentTextMatrix!.offsetX)) { _tempBoundingRectangle = Rect.zero; _hasBDC = false; } - if ((_textLineMatrix!.offsetX - _currentTextMatrix!.offsetX) - .abs() > - 0 && + if ((_textLineMatrix!.offsetX - _currentTextMatrix!.offsetX).abs() > 0 && !spaceBetweenWord && hasTj) { - differenceX = - _textLineMatrix!.offsetX - _currentTextMatrix!.offsetX; + differenceX = _textLineMatrix!.offsetX - _currentTextMatrix!.offsetX; spaceBetweenWord = true; } break; @@ -1535,8 +1411,7 @@ class PdfTextExtractor { } case 'T*': { - _textMatrix = - MatrixHelper(1, 0, 0, 1, 0, textLeading!) * _textLineMatrix!; + _textMatrix = MatrixHelper(1, 0, 0, 1, 0, textLeading!) * _textLineMatrix!; _textLineMatrix = _textMatrix!.clone(); break; } @@ -1549,8 +1424,7 @@ class PdfTextExtractor { { _hasET = true; final double endTextPosition = - (_textLineMatrix!.offsetX - _tempBoundingRectangle!.right) / - 10; + (_textLineMatrix!.offsetX - _tempBoundingRectangle!.right) / 10; if (_hasLeading && endTextPosition == 0 && hasNoSpacing) { resultantText += ' '; _tempBoundingRectangle = Rect.zero; @@ -1568,8 +1442,7 @@ class PdfTextExtractor { if (_fontSize! >= 10) { difference = ((currentY - prevY!) / 10).round().toDouble(); } else { - difference = - ((currentY - prevY!) / _fontSize!).round().toDouble(); + difference = ((currentY - prevY!) / _fontSize!).round().toDouble(); } if (difference < 0) { difference = -difference; @@ -1585,8 +1458,7 @@ class PdfTextExtractor { bool isEncoded = true; if (elements != null) { final String text = elements.join(); - isEncoded = text[0] != '(' || - (text[0] == '(' && _hasOctalEscape(text)); + isEncoded = text[0] != '(' || (text[0] == '(' && _hasOctalEscape(text)); } if (currentToken == 'Tj' && (_hasET || !isEncoded) && @@ -1598,10 +1470,8 @@ class PdfTextExtractor { spaceBetweenWord = false; hasTj = true; currentText = currentToken == 'TJ' - ? _renderTextElementTJ( - elements!, token, pageResources, horizontalScaling) - : _renderTextElement( - elements!, token, pageResources, horizontalScaling); + ? _renderTextElementTJ(elements!, token, pageResources, horizontalScaling) + : _renderTextElement(elements!, token, pageResources, horizontalScaling); if (_actualText != null && _actualText!.isNotEmpty) { currentText = _actualText; _actualText = null; @@ -1631,48 +1501,38 @@ class PdfTextExtractor { if (_fontSize! >= 10) { difference = ((currentY - prevY!) / 10).round().toDouble(); } else { - difference = - ((currentY - prevY!) / _fontSize!).round().toDouble(); + difference = ((currentY - prevY!) / _fontSize!).round().toDouble(); } if (difference < 0) { difference = -difference; } _hasLeading = true; if (prevY != 0 && - (difference >= 1 || - (i > 0 && records[i - 1].operatorName! == "'")) && + (difference >= 1 || (i > 0 && records[i - 1].operatorName! == "'")) && resultantText.isNotEmpty && !resultantText.endsWith('\n')) { - if (isSpaceAdded && - resultantText.isNotEmpty && - resultantText.endsWith(' ')) { - resultantText = - resultantText.substring(0, resultantText.length - 1); + if (isSpaceAdded && resultantText.isNotEmpty && resultantText.endsWith(' ')) { + resultantText = resultantText.substring(0, resultantText.length - 1); } resultantText += '\r\n'; } isSpaceAdded = false; prevY = currentY; - final int currentXPosition = - _textLineMatrix!.offsetX.toInt().toSigned(64); - final int prevXPosition = - _currentTextMatrix!.offsetX.toInt().toSigned(64); + final int currentXPosition = _textLineMatrix!.offsetX.toInt().toSigned(64); + final int prevXPosition = _currentTextMatrix!.offsetX.toInt().toSigned(64); if ((prevXPosition - currentXPosition) > 0) { hasNoSpacing = true; } - _textMatrix = - MatrixHelper(1, 0, 0, 1, 0, textLeading!) * _textLineMatrix!; + _textMatrix = MatrixHelper(1, 0, 0, 1, 0, textLeading!) * _textLineMatrix!; _textLineMatrix = _textMatrix!.clone(); - currentText = _renderTextElement( - elements!, token, pageResources, horizontalScaling); + currentText = _renderTextElement(elements!, token, pageResources, horizontalScaling); _currentTextMatrix = _textLineMatrix!.clone(); resultantText += currentText!; break; } case 'Do': { - final String? result = - _getXObject(resultantText, elements!, pageResources); + final String? result = _getXObject(resultantText, elements!, pageResources); if (result != null && result != '') { resultantText += result; } @@ -1683,14 +1543,10 @@ class PdfTextExtractor { } } } - if (isSpaceAdded && - resultantText.isNotEmpty && - resultantText.endsWith(' ')) { + if (isSpaceAdded && resultantText.isNotEmpty && resultantText.endsWith(' ')) { resultantText = resultantText.substring(0, resultantText.length - 1); } - return resultantText - .replaceAll(RegExp(r' {2,}'), ' ') - .replaceAll(' \r\n', '\r\n'); + return resultantText.replaceAll(RegExp(r' {2,}'), ' ').replaceAll(' \r\n', '\r\n'); } bool _hasOctalEscape(String input) { @@ -1701,8 +1557,7 @@ class PdfTextExtractor { void _initializeActualText(String text) { _actualText = text.substring(text.indexOf('(') + 1, text.lastIndexOf(')')); const String bigEndianPreambleString = 'þÿ'; - if (_actualText != null && - _actualText!.startsWith(bigEndianPreambleString)) { + if (_actualText != null && _actualText!.startsWith(bigEndianPreambleString)) { _actualText = null; } } @@ -1713,8 +1568,7 @@ class PdfTextExtractor { index = text.indexOf(r'\', index + 1); if (text.length > index + 1) { final String nextLiteral = text[index + 1]; - if (index >= 0 && - (nextLiteral == r'\' || nextLiteral == '(' || nextLiteral == ')')) { + if (index >= 0 && (nextLiteral == r'\' || nextLiteral == '(' || nextLiteral == ')')) { text = text.replaceFirst(text[index], '', index); } } else { @@ -1762,34 +1616,29 @@ class PdfTextExtractor { if (!fontStructure.isEmbedded && fontStructure.isStandardCJKFont && fontStructure.font != null) { - decodedList = fontStructure.decodeCjkTextExtractionTJ( - text, pageResources.isSameFont()); + decodedList = fontStructure.decodeCjkTextExtractionTJ(text, pageResources.isSameFont()); } else { - decodedListCollection = fontStructure.decodeTextExtractionTJ( - text, pageResources.isSameFont()); + decodedListCollection = + fontStructure.decodeTextExtractionTJ(text, pageResources.isSameFont()); decodedList = decodedListCollection.values.toList(); } fontStructure.isTextExtraction = false; - tempText = - _renderTextFromTJ(decodedList, horizontalScaling, fontStructure); + tempText = _renderTextFromTJ(decodedList, horizontalScaling, fontStructure); if (bidi.Bidi.hasAnyRtl(tempText)) { - tempText = - _bidi.getLogicalToVisualString(tempText, true)['rtlText'] as String; + tempText = _bidi.getLogicalToVisualString(tempText, true)['rtlText'] as String; } } return tempText; } - String _renderTextFromTJ(List decodedList, double? horizontalScaling, - FontStructure? fontStructure) { + String _renderTextFromTJ( + List decodedList, double? horizontalScaling, FontStructure? fontStructure) { String extractedText = ''; for (String word in decodedList) { final double? space = double.tryParse(word); if (space != null) { - _textLineMatrix = - _updateTextMatrixWithSpacing(space, horizontalScaling!); - if ((_textLineMatrix!.offsetX - _textMatrix!.offsetX).toInt() > 1 && - !_hasBDC) { + _textLineMatrix = _updateTextMatrixWithSpacing(space, horizontalScaling!); + if ((_textLineMatrix!.offsetX - _textMatrix!.offsetX).toInt() > 1 && !_hasBDC) { extractedText += ' '; } } else { @@ -1797,8 +1646,7 @@ class PdfTextExtractor { if (word != '' && word[word.length - 1] == 's') { word = word.substring(0, word.length - 1); } - if (fontStructure != null && - fontStructure.fontEncoding == 'MacRomanEncoding') { + if (fontStructure != null && fontStructure.fontEncoding == 'MacRomanEncoding') { String tempstring = ''; for (int i = 0; i < word.length; i++) { final int b = word[i].codeUnitAt(0).toUnsigned(8); @@ -1820,20 +1668,18 @@ class PdfTextExtractor { fontStructure.isStandardFont && fontStructure.font != null) { final PdfStandardFont font = fontStructure.font! as PdfStandardFont; - characterWidth = PdfStandardFontHelper.getHelper(font) - .getCharWidthInternal(renderedCharacter) * - PdfFontHelper.characterSizeMultiplier; + characterWidth = + PdfStandardFontHelper.getHelper(font).getCharWidthInternal(renderedCharacter) * + PdfFontHelper.characterSizeMultiplier; } else if (!fontStructure.isEmbedded && fontStructure.isStandardCJKFont && fontStructure.font != null) { - final PdfCjkStandardFont font = - fontStructure.font! as PdfCjkStandardFont; - characterWidth = PdfCjkStandardFontHelper.getHelper(font) - .getCharWidthInternal(renderedCharacter) * - PdfFontHelper.characterSizeMultiplier; - } else { + final PdfCjkStandardFont font = fontStructure.font! as PdfCjkStandardFont; characterWidth = - _getCharacterWidth(renderedCharacter, fontStructure); + PdfCjkStandardFontHelper.getHelper(font).getCharWidthInternal(renderedCharacter) * + PdfFontHelper.characterSizeMultiplier; + } else { + characterWidth = _getCharacterWidth(renderedCharacter, fontStructure); } _textMatrix = _getTextRenderingMatrix(horizontalScaling!); final MatrixHelper identity = MatrixHelper.identity.clone(); @@ -1860,19 +1706,15 @@ class PdfTextExtractor { tempFontSize); if (_tempBoundingRectangle != null) { final double boundingDifference = - ((boundingRect.left - _tempBoundingRectangle!.right) / 10) - .round() - .toDouble(); - if ((_tempBoundingRectangle!.right != 0 && - boundingRect.left != 0) && + ((boundingRect.left - _tempBoundingRectangle!.right) / 10).round().toDouble(); + if ((_tempBoundingRectangle!.right != 0 && boundingRect.left != 0) && boundingDifference >= 1 && _hasLeading) { extractedText += ' '; } } extractedText += renderedCharacter; - _textLineMatrix = - _updateTextMatrix(characterWidth, horizontalScaling); + _textLineMatrix = _updateTextMatrix(characterWidth, horizontalScaling); _tempBoundingRectangle = boundingRect; _textMatrix = _textLineMatrix!.clone(); } @@ -1900,8 +1742,7 @@ class PdfTextExtractor { fontStructure.fontSize = _fontSize; text = fontStructure.decodeTextExtraction(text, true); if (_isLayout) { - text = _renderTextFromLeading( - text, _textLineMatrix, fontStructure, horizontalScaling); + text = _renderTextFromLeading(text, _textLineMatrix, fontStructure, horizontalScaling); } fontStructure.isTextExtraction = false; } @@ -1923,14 +1764,12 @@ class PdfTextExtractor { double characterWidth; if (structure.isStandardFont) { final PdfStandardFont font = structure.font! as PdfStandardFont; - characterWidth = - PdfStandardFontHelper.getHelper(font).getCharWidthInternal(ch) * - PdfFontHelper.characterSizeMultiplier; + characterWidth = PdfStandardFontHelper.getHelper(font).getCharWidthInternal(ch) * + PdfFontHelper.characterSizeMultiplier; } else if (structure.isStandardCJKFont) { final PdfCjkStandardFont font = structure.font! as PdfCjkStandardFont; - characterWidth = - PdfCjkStandardFontHelper.getHelper(font).getCharWidthInternal(ch) * - PdfFontHelper.characterSizeMultiplier; + characterWidth = PdfCjkStandardFontHelper.getHelper(font).getCharWidthInternal(ch) * + PdfFontHelper.characterSizeMultiplier; } else { characterWidth = _getCharacterWidth(ch, structure); } @@ -1963,9 +1802,7 @@ class PdfTextExtractor { tempFontSize); if (_tempBoundingRectangle != null) { final double boundingDifference = - ((boundingRect.left - _tempBoundingRectangle!.right) / 10) - .round() - .toDouble(); + ((boundingRect.left - _tempBoundingRectangle!.right) / 10).round().toDouble(); if ((_tempBoundingRectangle!.right != 0 && boundingRect.left != 0) && boundingDifference >= 1 && _hasLeading) { @@ -1979,8 +1816,8 @@ class PdfTextExtractor { return extractedText; } - String? _getXObject(String resultantText, List xobjectElement, - PdfPageResources pageResources) { + String? _getXObject( + String resultantText, List xobjectElement, PdfPageResources pageResources) { String? result; final String key = xobjectElement[0].replaceAll('/', ''); if (pageResources.containsKey(key)) { @@ -1991,18 +1828,16 @@ class PdfTextExtractor { PdfPageResources childResource = PdfPageResources(); if (xobjects.containsKey(PdfDictionaryProperties.resources)) { PdfDictionary? pageDictionary = PdfDictionary(); - final IPdfPrimitive? resource = - xobjects[PdfDictionaryProperties.resources]; - if (resource is PdfReferenceHolder && - resource.object is PdfDictionary) { + final IPdfPrimitive? resource = xobjects[PdfDictionaryProperties.resources]; + if (resource is PdfReferenceHolder && resource.object is PdfDictionary) { pageDictionary = resource.object as PdfDictionary?; } else if (resource is PdfDictionary) { pageDictionary = resource; } childResource = _resourceLoader.updatePageResources( childResource, _resourceLoader.getFormResources(pageDictionary)); - childResource = _resourceLoader.updatePageResources(childResource, - _resourceLoader.getFontResources(pageDictionary, _currentPage)); + childResource = _resourceLoader.updatePageResources( + childResource, _resourceLoader.getFontResources(pageDictionary, _currentPage)); } else { childResource = _updateFontResources(pageResources); } @@ -2028,8 +1863,7 @@ class PdfTextExtractor { return resources; } - MatrixHelper? _updateTextMatrixWithSpacing( - double space, double horizontalScaling) { + MatrixHelper? _updateTextMatrixWithSpacing(double space, double horizontalScaling) { final double x = -(space * 0.001 * _fontSize! * horizontalScaling / 100); final Offset point = _textLineMatrix!.transform(Offset.zero); final Offset point2 = _textLineMatrix!.transform(Offset(x, 0.0)); @@ -2042,8 +1876,8 @@ class PdfTextExtractor { } MatrixHelper _getTextRenderingMatrix(double textHorizontalScaling) { - return MatrixHelper(_fontSize! * (textHorizontalScaling / 100), 0, 0, - -_fontSize!, 0, _fontSize!) * + return MatrixHelper( + _fontSize! * (textHorizontalScaling / 100), 0, 0, -_fontSize!, 0, _fontSize!) * _textLineMatrix! * _currentTransformationMatrix; } @@ -2057,11 +1891,9 @@ class PdfTextExtractor { : 1.0; } - MatrixHelper _updateTextMatrix( - double characterWidth, double horizontalScaling) { - final double offsetX = - (characterWidth * _fontSize! + _characterSpacing + _wordSpacing) * - (horizontalScaling / 100); + MatrixHelper _updateTextMatrix(double characterWidth, double horizontalScaling) { + final double offsetX = (characterWidth * _fontSize! + _characterSpacing + _wordSpacing) * + (horizontalScaling / 100); return MatrixHelper(1.0, 0.0, 0.0, 1.0, offsetX, 0.0) * _textLineMatrix!; } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_element.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_element.dart index 3c389833d..4d52f2e2c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_element.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_element.dart @@ -1,5 +1,5 @@ import 'dart:collection'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import 'package:intl/intl.dart' as bidi; @@ -302,8 +302,8 @@ class TextElement { } MatrixHelper _getTextRenderingMatrix() { - return MatrixHelper(fontSize * (textHorizontalScaling! / 100), 0, 0, - -fontSize, 0, fontSize + rise!) * + return MatrixHelper( + fontSize * (textHorizontalScaling! / 100), 0, 0, -fontSize, 0, fontSize + rise!) * textLineMatrix! * currentTransformationMatrix!; } @@ -343,13 +343,11 @@ class TextElement { glyph.charSpacing = characterSpacing!; if (structure.isStandardFont) { final PdfStandardFont font = structure.font! as PdfStandardFont; - glyph.width = PdfStandardFontHelper.getHelper(font) - .getCharWidthInternal(character) * + glyph.width = PdfStandardFontHelper.getHelper(font).getCharWidthInternal(character) * PdfFontHelper.characterSizeMultiplier; } else if (structure.isStandardCJKFont) { final PdfCjkStandardFont font = structure.font! as PdfCjkStandardFont; - glyph.width = PdfCjkStandardFontHelper.getHelper(font) - .getCharWidthInternal(character) * + glyph.width = PdfCjkStandardFontHelper.getHelper(font).getCharWidthInternal(character) * PdfFontHelper.characterSizeMultiplier; } final MatrixHelper identity = MatrixHelper.identity.clone(); @@ -363,8 +361,7 @@ class TextElement { double? tempFontSize = 0; if (glyph.transformMatrix.m11 > 0) { tempFontSize = glyph.transformMatrix.m11; - } else if (glyph.transformMatrix.m12 != 0 && - glyph.transformMatrix.m21 != 0) { + } else if (glyph.transformMatrix.m12 != 0 && glyph.transformMatrix.m21 != 0) { if (glyph.transformMatrix.m12 < 0) { tempFontSize = -glyph.transformMatrix.m12; } else { @@ -378,9 +375,7 @@ class TextElement { } glyph.boundingRect = Rect.fromLTWH( (matrix.offsetX / 1.3333333333333333) / zoomFactor!, - ((matrix.offsetY - (tempFontSize * zoomFactor!)) / - 1.3333333333333333) / - zoomFactor!, + ((matrix.offsetY - (tempFontSize * zoomFactor!)) / 1.3333333333333333) / zoomFactor!, glyph.width * tempFontSize, tempFontSize); textElementGlyphList.add(glyph); @@ -392,8 +387,7 @@ class TextElement { txtMatrix = textLineMatrix; } else { int letterCount = 0; - if ((retrievedCharCodes != null && - text.length != retrievedCharCodes.length) || + if ((retrievedCharCodes != null && text.length != retrievedCharCodes.length) || !bidi.Bidi.hasAnyRtl(text)) { retrievedCharCodes = null; } @@ -408,12 +402,10 @@ class TextElement { letterCount += 1; final int charCode = letter.codeUnitAt(0); isTextGlyphAdded = false; - if (charCode.toUnsigned(8) > 126 && - fontEncoding == 'MacRomanEncoding' && - !isEmbeddedFont) { + if (charCode.toUnsigned(8) > 126 && fontEncoding == 'MacRomanEncoding' && !isEmbeddedFont) { isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - letter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(letter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { @@ -422,35 +414,31 @@ class TextElement { } else { if (renderingMode == 1) { isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - letter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(letter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { isTextGlyphAdded = false; } - } else if (reverseMapTable!.isNotEmpty && - reverseMapTable!.containsKey(letter)) { + } else if (reverseMapTable!.isNotEmpty && reverseMapTable!.containsKey(letter)) { final int tempCharCode = reverseMapTable![letter]!.toInt(); if (fontGlyphWidths != null) { - currentGlyphWidth = (fontGlyphWidths! - .containsKey(retrievedCharCode ?? tempCharCode) + currentGlyphWidth = (fontGlyphWidths!.containsKey(retrievedCharCode ?? tempCharCode) ? fontGlyphWidths![retrievedCharCode ?? tempCharCode] : defaultGlyphWidth)! * charSizeMultiplier; } else { currentGlyphWidth = defaultGlyphWidth! * charSizeMultiplier; } - txtMatrix = - drawGlyphs(currentGlyphWidth, g!, txtMatrix, letter, false); + txtMatrix = drawGlyphs(currentGlyphWidth, g!, txtMatrix, letter, false); isTextGlyphAdded = true; } else { - if (characterMapTable.isNotEmpty && - characterMapTable.containsKey(charCode)) { + if (characterMapTable.isNotEmpty && characterMapTable.containsKey(charCode)) { final String tempLetter = characterMapTable[charCode]![0]; isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - tempLetter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(tempLetter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { @@ -459,8 +447,7 @@ class TextElement { } } if (!isTextGlyphAdded) { - if (characterMapTable.isNotEmpty && - characterMapTable.containsKey(charCode)) { + if (characterMapTable.isNotEmpty && characterMapTable.containsKey(charCode)) { final String unicode = characterMapTable[charCode]![0]; if (fontGlyphWidths == null) { currentGlyphWidth = defaultGlyphWidth! * charSizeMultiplier; @@ -470,33 +457,25 @@ class TextElement { cidToGidReverseMapTable!.containsKey(charCode) && !structure.isMappingDone) { currentGlyphWidth = - fontGlyphWidths![cidToGidReverseMapTable![charCode]!]! * - charSizeMultiplier; + fontGlyphWidths![cidToGidReverseMapTable![charCode]!]! * charSizeMultiplier; } else if (fontGlyphWidths!.containsKey(charCode)) { - currentGlyphWidth = - fontGlyphWidths![charCode]! * charSizeMultiplier; + currentGlyphWidth = fontGlyphWidths![charCode]! * charSizeMultiplier; } else { if (reverseMapTable!.containsKey(unicode) && - !fontGlyphWidths! - .containsKey(reverseMapTable![unicode]!.toInt())) { - currentGlyphWidth = - defaultGlyphWidth! * charSizeMultiplier; + !fontGlyphWidths!.containsKey(reverseMapTable![unicode]!.toInt())) { + currentGlyphWidth = defaultGlyphWidth! * charSizeMultiplier; } } } else if (structure.fontType!.name == 'TrueType' && fontGlyphWidths!.containsKey(charCode)) { - currentGlyphWidth = - fontGlyphWidths![charCode]! * charSizeMultiplier; + currentGlyphWidth = fontGlyphWidths![charCode]! * charSizeMultiplier; } } - } else if (cidToGidReverseMapTable != null && - cidToGidReverseMapTable!.isNotEmpty) { + } else if (cidToGidReverseMapTable != null && cidToGidReverseMapTable!.isNotEmpty) { if (cidToGidReverseMapTable!.containsKey(charCode)) { final int? cidGidKey = cidToGidReverseMapTable![charCode]; - if (fontGlyphWidths != null && - fontGlyphWidths!.containsKey(cidGidKey)) { - currentGlyphWidth = - fontGlyphWidths![cidGidKey!]! * charSizeMultiplier; + if (fontGlyphWidths != null && fontGlyphWidths!.containsKey(cidGidKey)) { + currentGlyphWidth = fontGlyphWidths![cidGidKey!]! * charSizeMultiplier; } } } else if (fontGlyphWidths != null) { @@ -511,16 +490,12 @@ class TextElement { location = Offset(location.dx + characterSpacing!, location.dy); } if (!isTextGlyphAdded) { - txtMatrix = - drawGlyphs(currentGlyphWidth, g!, txtMatrix, letter, false); + txtMatrix = drawGlyphs(currentGlyphWidth, g!, txtMatrix, letter, false); } } } changeInX = location.dx - changeInX; - return { - 'textElementWidth': changeInX, - 'tempTextMatrix': txtMatrix - }; + return {'textElementWidth': changeInX, 'tempTextMatrix': txtMatrix}; } /// internal method @@ -549,8 +524,7 @@ class TextElement { if (!isEmbeddedFont && structure.font != null && (structure.isStandardFont || structure.isStandardCJKFont)) { - final MatrixHelper defaultTransformations = - g!.transformMatrix!.clone(); + final MatrixHelper defaultTransformations = g!.transformMatrix!.clone(); if (word != '' && word[word.length - 1] == 's') { word = word.substring(0, word.length - 1); } @@ -569,15 +543,13 @@ class TextElement { glyph.charSpacing = this.characterSpacing!; if (structure.isStandardFont) { final PdfStandardFont font = structure.font! as PdfStandardFont; - glyph.width = PdfStandardFontHelper.getHelper(font) - .getCharWidthInternal(character) * + glyph.width = PdfStandardFontHelper.getHelper(font).getCharWidthInternal(character) * PdfFontHelper.characterSizeMultiplier; } else if (structure.isStandardCJKFont) { - final PdfCjkStandardFont font = - structure.font! as PdfCjkStandardFont; - glyph.width = PdfCjkStandardFontHelper.getHelper(font) - .getCharWidthInternal(character) * - PdfFontHelper.characterSizeMultiplier; + final PdfCjkStandardFont font = structure.font! as PdfCjkStandardFont; + glyph.width = + PdfCjkStandardFontHelper.getHelper(font).getCharWidthInternal(character) * + PdfFontHelper.characterSizeMultiplier; } final MatrixHelper identity = MatrixHelper.identity.clone(); identity.scale(0.01, 0.01, 0.0, 0.0); @@ -590,8 +562,7 @@ class TextElement { double? tempFontSize = 0; if (glyph.transformMatrix.m11 > 0) { tempFontSize = glyph.transformMatrix.m11; - } else if (glyph.transformMatrix.m12 != 0 && - glyph.transformMatrix.m21 != 0) { + } else if (glyph.transformMatrix.m12 != 0 && glyph.transformMatrix.m21 != 0) { if (glyph.transformMatrix.m12 < 0) { tempFontSize = -glyph.transformMatrix.m12; } else { @@ -602,8 +573,7 @@ class TextElement { } glyph.boundingRect = Rect.fromLTWH( (matrix.offsetX / 1.3333333333333333) / zoomFactor!, - ((matrix.offsetY - (tempFontSize * zoomFactor!)) / - 1.3333333333333333) / + ((matrix.offsetY - (tempFontSize * zoomFactor!)) / 1.3333333333333333) / zoomFactor!, glyph.width * tempFontSize, tempFontSize); @@ -619,9 +589,7 @@ class TextElement { word = word.substring(0, word.length - 1); } final bool containsRTL = bidi.Bidi.hasAnyRtl(word); - if ((keys != null && - word.length > keys.length && - keys.length > word.length + 2) || + if ((keys != null && word.length > keys.length && keys.length > word.length + 2) || !containsRTL) { keys = null; } @@ -632,19 +600,16 @@ class TextElement { reverseMapTable!.isNotEmpty && reverseMapTable!.containsKey(word)) { final int charCode = reverseMapTable![word]!.toInt(); - final dynamic retrievedCharCode = (keys != null && - keys.isNotEmpty && - keys[0] != null && - keys[0] != 0) - ? keys[0] - : null; - if (characterMapTable.isNotEmpty && - characterMapTable.containsKey(charCode)) { + final dynamic retrievedCharCode = + (keys != null && keys.isNotEmpty && keys[0] != null && keys[0] != 0) + ? keys[0] + : null; + if (characterMapTable.isNotEmpty && characterMapTable.containsKey(charCode)) { final String tempLetter = characterMapTable[charCode]!; isTextGlyphAdded = true; isComplexScript = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - tempLetter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(tempLetter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { @@ -658,19 +623,17 @@ class TextElement { final String letter = word[i]; letterCount += 1; int charCode = letter.codeUnitAt(0); - final dynamic retrievedCharCode = (keys != null && - i < keys.length && - keys[i] != null && - keys[i] != 0) - ? keys[i] - : null; + final dynamic retrievedCharCode = + (keys != null && i < keys.length && keys[i] != null && keys[i] != 0) + ? keys[i] + : null; isTextGlyphAdded = false; if (charCode.toUnsigned(8) > 126 && fontEncoding == 'MacRomanEncoding' && !isEmbeddedFont) { isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - letter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(letter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { @@ -679,24 +642,22 @@ class TextElement { } else { if (renderingMode == 1) { isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - letter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(letter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { isTextGlyphAdded = false; } } else { - if (reverseMapTable!.isNotEmpty && - reverseMapTable!.containsKey(letter)) { + if (reverseMapTable!.isNotEmpty && reverseMapTable!.containsKey(letter)) { charCode = reverseMapTable![letter]!.toInt(); } - if (characterMapTable.isNotEmpty && - characterMapTable.containsKey(charCode)) { + if (characterMapTable.isNotEmpty && characterMapTable.containsKey(charCode)) { final String tempLetter = characterMapTable[charCode]![0]; isTextGlyphAdded = true; - final MatrixHelper? tempMatrix = drawSystemFontGlyphShape( - tempLetter, g!, txtMatrix, retrievedCharCode); + final MatrixHelper? tempMatrix = + drawSystemFontGlyphShape(tempLetter, g!, txtMatrix, retrievedCharCode); if (tempMatrix != null) { txtMatrix = tempMatrix; } else { @@ -704,45 +665,37 @@ class TextElement { } } } - if (characterMapTable.isNotEmpty && - characterMapTable.containsKey(charCode)) { + if (characterMapTable.isNotEmpty && characterMapTable.containsKey(charCode)) { final String unicode = characterMapTable[charCode]![0]; if (fontGlyphWidths == null) { - currentGlyphWidth = - defaultGlyphWidth! * charSizeMultiplier; + currentGlyphWidth = defaultGlyphWidth! * charSizeMultiplier; } else { if (structure.fontType!.name == 'Type0') { if (cidToGidReverseMapTable != null && cidToGidReverseMapTable!.containsKey(charCode) && !structure.isMappingDone) { - currentGlyphWidth = fontGlyphWidths![ - cidToGidReverseMapTable![charCode]!]! * - charSizeMultiplier; - } else if (fontGlyphWidths!.containsKey(charCode)) { currentGlyphWidth = - fontGlyphWidths![charCode]! * charSizeMultiplier; + fontGlyphWidths![cidToGidReverseMapTable![charCode]!]! * + charSizeMultiplier; + } else if (fontGlyphWidths!.containsKey(charCode)) { + currentGlyphWidth = fontGlyphWidths![charCode]! * charSizeMultiplier; } else { if (reverseMapTable!.containsKey(unicode) && - !fontGlyphWidths!.containsKey( - reverseMapTable![unicode]!.toInt())) { - currentGlyphWidth = - defaultGlyphWidth! * charSizeMultiplier; + !fontGlyphWidths!.containsKey(reverseMapTable![unicode]!.toInt())) { + currentGlyphWidth = defaultGlyphWidth! * charSizeMultiplier; } } } else if (structure.fontType!.name == 'TrueType' && fontGlyphWidths!.containsKey(charCode)) { - currentGlyphWidth = - fontGlyphWidths![charCode]! * charSizeMultiplier; + currentGlyphWidth = fontGlyphWidths![charCode]! * charSizeMultiplier; } } } else if (cidToGidReverseMapTable != null && cidToGidReverseMapTable!.isNotEmpty) { if (cidToGidReverseMapTable!.containsKey(charCode)) { final int? cidGidKey = cidToGidReverseMapTable![charCode]; - if (fontGlyphWidths != null && - fontGlyphWidths!.containsKey(cidGidKey)) { - currentGlyphWidth = - fontGlyphWidths![cidGidKey!]! * charSizeMultiplier; + if (fontGlyphWidths != null && fontGlyphWidths!.containsKey(cidGidKey)) { + currentGlyphWidth = fontGlyphWidths![cidGidKey!]! * charSizeMultiplier; } } } else if (fontGlyphWidths != null) { @@ -753,15 +706,12 @@ class TextElement { } } if (letterCount < word.length) { - location = - Offset(location.dx + this.characterSpacing!, location.dy); + location = Offset(location.dx + this.characterSpacing!, location.dy); } if (!isTextGlyphAdded && (retrievedCharCode == null || - (retrievedCharCode != null && - retrievedCharCode is! String))) { - txtMatrix = drawGlyphs( - currentGlyphWidth, g!, txtMatrix, letter, i == 0); + (retrievedCharCode != null && retrievedCharCode is! String))) { + txtMatrix = drawGlyphs(currentGlyphWidth, g!, txtMatrix, letter, i == 0); } } } @@ -770,15 +720,12 @@ class TextElement { } }); changeInX = location.dx - changeInX; - return { - 'textElementWidth': changeInX, - 'tempTextMatrix': txtMatrix - }; + return {'textElementWidth': changeInX, 'tempTextMatrix': txtMatrix}; } /// internal method - MatrixHelper? drawGlyphs(double? glyphwidth, GraphicsObject g, - MatrixHelper? temptextmatrix, String? glyphChar, bool renderWithSpace) { + MatrixHelper? drawGlyphs(double? glyphwidth, GraphicsObject g, MatrixHelper? temptextmatrix, + String? glyphChar, bool renderWithSpace) { final MatrixHelper defaultTransformations = g.transformMatrix!.clone(); g.transformMatrix = MatrixHelper(1, 0, 0, 1, 0, 0); final Glyph glyph = Glyph(); @@ -804,16 +751,14 @@ class TextElement { if (cidToGidReverseMapTable != null && cidToGidReverseMapTable!.containsKey(glyphChar!.codeUnitAt(0)) && (structure.characterMapTable.isNotEmpty)) { - glyphChar = characterMapTable[ - cidToGidReverseMapTable![glyphChar.codeUnitAt(0)]]; + glyphChar = characterMapTable[cidToGidReverseMapTable![glyphChar.codeUnitAt(0)]]; } else if (structure.characterMapTable.isNotEmpty) { glyphChar = structure.mapCharactersFromTable(glyphChar!); } else if (structure.differencesDictionary.isNotEmpty) { glyphChar = structure.mapDifferences(glyphChar); - } else if (structure.cidToGidReverseMapTable - .containsKey(glyphChar!.codeUnitAt(0))) { - glyphChar = String.fromCharCode( - structure.cidToGidReverseMapTable[glyphChar.codeUnitAt(0)]!); + } else if (structure.cidToGidReverseMapTable.containsKey(glyphChar!.codeUnitAt(0))) { + glyphChar = + String.fromCharCode(structure.cidToGidReverseMapTable[glyphChar.codeUnitAt(0)]!); } if (glyphChar!.contains('\u0092')) { glyphChar = glyphChar.replaceAll('\u0092', '’'); @@ -822,17 +767,14 @@ class TextElement { double? tempFontSize; if (glyph.transformMatrix.m11 > 0) { tempFontSize = glyph.transformMatrix.m11; - } else if (glyph.transformMatrix.m12 != 0 && - glyph.transformMatrix.m21 != 0) { - tempFontSize = glyph.transformMatrix.m12 < 0 - ? -glyph.transformMatrix.m12 - : glyph.transformMatrix.m12; + } else if (glyph.transformMatrix.m12 != 0 && glyph.transformMatrix.m21 != 0) { + tempFontSize = + glyph.transformMatrix.m12 < 0 ? -glyph.transformMatrix.m12 : glyph.transformMatrix.m12; } else { tempFontSize = glyph.fontSize; } final String glyphText = glyphChar!; - if (!structure.macRomanEncoded && - structure.fontEncoding == 'MacRomanEncoding') { + if (!structure.macRomanEncoded && structure.fontEncoding == 'MacRomanEncoding') { String tempstring = ''; for (int i = 0; i < glyphText.length; i++) { final int b = glyphText[i].codeUnitAt(0).toUnsigned(8); @@ -859,14 +801,11 @@ class TextElement { } else if (matrix.m12 < 0 && matrix.m21 < 0) { glyph.rotationAngle = 180; } - final double x = ((matrix.offsetX + - ((tempFontSize + (glyph.ascent / 1000.0)) * matrix.m21)) / + final double x = ((matrix.offsetX + ((tempFontSize + (glyph.ascent / 1000.0)) * matrix.m21)) / 1.3333333333333333) / zoomFactor!; double y = ((matrix.offsetY - - ((pageRotation == 270 - ? tempFontSize - : (glyph.width * tempFontSize)) * + ((pageRotation == 270 ? tempFontSize : (glyph.width * tempFontSize)) * zoomFactor!)) / 1.3333333333333333) / zoomFactor!; @@ -876,8 +815,7 @@ class TextElement { if (textElementGlyphList.isEmpty || renderWithSpace) { y += width; } else { - final Glyph tempGlyph = - textElementGlyphList[textElementGlyphList.length - 1]; + final Glyph tempGlyph = textElementGlyphList[textElementGlyphList.length - 1]; if (textElementGlyphList.length == 1 && tempGlyph.toUnicode == ' ') { y += width; } else { @@ -891,9 +829,7 @@ class TextElement { } else { glyph.boundingRect = Rect.fromLTWH( (matrix.offsetX / 1.3333333333333333) / zoomFactor!, - ((matrix.offsetY - (tempFontSize * zoomFactor!)) / - 1.3333333333333333) / - zoomFactor!, + ((matrix.offsetY - (tempFontSize * zoomFactor!)) / 1.3333333333333333) / zoomFactor!, glyph.width * tempFontSize, tempFontSize); } @@ -944,8 +880,7 @@ class TextElement { } } } else if (fontGlyphWidths!.containsKey(letter.codeUnitAt(0))) { - systemFontGlyph = - fontGlyphWidths![letter.codeUnitAt(0)]! * charSizeMultiplier; + systemFontGlyph = fontGlyphWidths![letter.codeUnitAt(0)]! * charSizeMultiplier; } } else if (defaultGlyphWidth != null && defaultGlyphWidth! > 0) { systemFontGlyph = defaultGlyphWidth! * charSizeMultiplier; @@ -963,9 +898,8 @@ class TextElement { if (gly.transformMatrix.m11 > 0) { tempFontSize = gly.transformMatrix.m11; } else if (gly.transformMatrix.m12 != 0 && gly.transformMatrix.m21 != 0) { - tempFontSize = gly.transformMatrix.m12 < 0 - ? -gly.transformMatrix.m12 - : gly.transformMatrix.m12; + tempFontSize = + gly.transformMatrix.m12 < 0 ? -gly.transformMatrix.m12 : gly.transformMatrix.m12; } else { tempFontSize = gly.fontSize; } @@ -974,23 +908,20 @@ class TextElement { if (cidToGidReverseMapTable != null && cidToGidReverseMapTable!.containsKey(glyphName.codeUnitAt(0)) && (structure.characterMapTable.isNotEmpty)) { - glyphName = characterMapTable[ - cidToGidReverseMapTable![glyphName.codeUnitAt(0)]]; + glyphName = characterMapTable[cidToGidReverseMapTable![glyphName.codeUnitAt(0)]]; } else if (structure.characterMapTable.isNotEmpty) { glyphName = structure.mapCharactersFromTable(glyphName); } else if (structure.differencesDictionary.isNotEmpty) { glyphName = structure.mapDifferences(glyphName); - } else if (structure.cidToGidReverseMapTable - .containsKey(glyphName.codeUnitAt(0))) { - glyphName = String.fromCharCode( - structure.cidToGidReverseMapTable[glyphName.codeUnitAt(0)]!); + } else if (structure.cidToGidReverseMapTable.containsKey(glyphName.codeUnitAt(0))) { + glyphName = + String.fromCharCode(structure.cidToGidReverseMapTable[glyphName.codeUnitAt(0)]!); } if (glyphName!.contains('\u0092')) { glyphName = glyphName.replaceAll('\u0092', '’'); } } - if (!structure.macRomanEncoded && - structure.fontEncoding == 'MacRomanEncoding') { + if (!structure.macRomanEncoded && structure.fontEncoding == 'MacRomanEncoding') { String tempstring = ''; for (int i = 0; i < glyphName.length; i++) { final int b = glyphName[i].codeUnitAt(0).toUnsigned(8); @@ -1010,16 +941,14 @@ class TextElement { gly.toUnicode = glyphName; gly.boundingRect = Rect.fromLTWH( (matrix.offsetX / 1.3333333333333333) / zoomFactor!, - ((matrix.offsetY - (tempFontSize * zoomFactor!)) / 1.3333333333333333) / - zoomFactor!, + ((matrix.offsetY - (tempFontSize * zoomFactor!)) / 1.3333333333333333) / zoomFactor!, gly.width * tempFontSize, tempFontSize); textElementGlyphList.add(gly); if (isExtractTextData && gly.toUnicode.length != 1) { for (int i = 0; i < gly.toUnicode.length - 1; i++) { final Glyph emptyGlyph = Glyph(); - emptyGlyph.boundingRect = - Rect.fromLTWH(gly.boundingRect.right, gly.boundingRect.top, 0, 0); + emptyGlyph.boundingRect = Rect.fromLTWH(gly.boundingRect.right, gly.boundingRect.top, 0, 0); textElementGlyphList.add(emptyGlyph); } } @@ -1051,18 +980,16 @@ class TextElement { glyph.wordSpacing = wordSpacing!; } final double width = glyph.width; - final double offsetX = - (width * glyph.fontSize + glyph.charSpacing + glyph.wordSpacing) * - (glyph.horizontalScaling / 100); + final double offsetX = (width * glyph.fontSize + glyph.charSpacing + glyph.wordSpacing) * + (glyph.horizontalScaling / 100); return MatrixHelper(1.0, 0.0, 0.0, 1.0, offsetX, 0.0) * m; } } class TransformationStack { TransformationStack([MatrixHelper? transformMatrix]) { - _initialTransform = (transformMatrix != null) - ? transformMatrix - : MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + _initialTransform = + (transformMatrix != null) ? transformMatrix : MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); transformStack = Queue(); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_glyph.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_glyph.dart index ff98b656b..3dda51d1d 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_glyph.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_glyph.dart @@ -1,10 +1,9 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/fonts/enums.dart'; /// Gets the details of character in the word. class TextGlyph { - TextGlyph._(this.text, this.fontName, this.fontStyle, this.bounds, - this.fontSize, this.isRotated); + TextGlyph._(this.text, this.fontName, this.fontStyle, this.bounds, this.fontSize, this.isRotated); //Fields /// Gets the bounds of glyph. @@ -30,8 +29,7 @@ class TextGlyph { /// [TextGlyph] helper class TextGlyphHelper { /// internal method - static TextGlyph initialize( - String text, String fontName, List fontStyle, + static TextGlyph initialize(String text, String fontName, List fontStyle, [Rect bounds = Rect.zero, double fontSize = 0, bool isRotated = false]) { return TextGlyph._(text, fontName, fontStyle, bounds, fontSize, isRotated); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_line.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_line.dart index 47f5f3ad1..687304f12 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_line.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_line.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/fonts/enums.dart'; import 'text_word.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_word.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_word.dart index dbd183972..c497dbb4f 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_word.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/exporting/pdf_text_extractor/text_word.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/fonts/enums.dart'; import 'text_glyph.dart'; @@ -6,8 +6,8 @@ import 'text_glyph.dart'; /// Details of a word present in the line. class TextWord { //constructor - TextWord._(this.text, this.fontName, this.fontStyle, List glyphs, - this.bounds, this.fontSize) { + TextWord._(this.text, this.fontName, this.fontStyle, List glyphs, this.bounds, + this.fontSize) { _glyphs = glyphs; } @@ -37,8 +37,8 @@ class TextWord { /// [TextWord] helper class TextWordHelper { /// internal method - static TextWord initialize(String text, String fontName, - List fontStyle, List glyphs, + static TextWord initialize( + String text, String fontName, List fontStyle, List glyphs, [Rect bounds = Rect.zero, double fontSize = 0]) { return TextWord._(text, fontName, fontStyle, glyphs, bounds, fontSize); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_button_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_button_field.dart index 55bea49e7..58d346adb 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_button_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_button_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../actions/pdf_field_actions.dart'; @@ -59,8 +59,8 @@ class PdfButtonField extends PdfField { borderWidth: borderWidth, highlightMode: highlightMode, borderStyle: borderStyle); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); if (backColor == null) { _helper.backColor = PdfColor(211, 211, 211); } @@ -90,9 +90,7 @@ class PdfButtonField extends PdfField { } else { if (_text != value) { _text = value; - WidgetAnnotationHelper.getHelper(_helper.widget!) - .widgetAppearance! - .normalCaption = _text; + WidgetAnnotationHelper.getHelper(_helper.widget!).widgetAppearance!.normalCaption = _text; } } } @@ -154,22 +152,19 @@ class PdfButtonField extends PdfField { if (_helper.isLoadedField && _helper.actions == null) { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.aa)) { final PdfDictionary actionDict = _helper.crossTable! - .getObject(_helper.dictionary![PdfDictionaryProperties.aa])! - as PdfDictionary; + .getObject(_helper.dictionary![PdfDictionaryProperties.aa])! as PdfDictionary; _helper.actions = PdfFieldActionsHelper.load(actionDict); _helper.widget!.actions = PdfFieldActionsHelper.getHelper(_helper.actions!).annotationActions; } else { _helper.actions = PdfFieldActionsHelper.load(PdfDictionary()); - _helper.dictionary! - .setProperty(PdfDictionaryProperties.aa, _helper.actions); + _helper.dictionary!.setProperty(PdfDictionaryProperties.aa, _helper.actions); } _helper.changed = true; } else { if (_helper.actions == null) { _helper.actions = PdfFieldActions(_helper.widget!.actions!); - _helper.dictionary! - .setProperty(PdfDictionaryProperties.aa, _helper.actions); + _helper.dictionary!.setProperty(PdfDictionaryProperties.aa, _helper.actions); } } return _helper.actions!; @@ -204,8 +199,7 @@ class PdfButtonFieldHelper extends PdfFieldHelper { buttonField.text = txt ?? buttonField.name!; if (action != null) { actions = action; - widget!.actions = - PdfFieldActionsHelper.getHelper(action).annotationActions; + widget!.actions = PdfFieldActionsHelper.getHelper(action).annotationActions; dictionary!.setProperty(PdfDictionaryProperties.aa, actions); } } @@ -213,29 +207,22 @@ class PdfButtonFieldHelper extends PdfFieldHelper { /// Adds Print action to current button field. void addPrintAction() { final PdfDictionary actionDictionary = PdfDictionary(); - actionDictionary.setProperty( - PdfDictionaryProperties.n, PdfName(PdfDictionaryProperties.print)); + actionDictionary.setProperty(PdfDictionaryProperties.n, PdfName(PdfDictionaryProperties.print)); actionDictionary.setProperty(PdfDictionaryProperties.s, PdfName('Named')); if (isLoadedField) { - final PdfArray? kidsArray = crossTable! - .getObject(dictionary![PdfDictionaryProperties.kids]) as PdfArray?; + final PdfArray? kidsArray = + crossTable!.getObject(dictionary![PdfDictionaryProperties.kids]) as PdfArray?; if (kidsArray != null) { - final PdfReferenceHolder buttonObject = - kidsArray[0]! as PdfReferenceHolder; - final PdfDictionary buttonDictionary = - buttonObject.object! as PdfDictionary; - buttonDictionary.setProperty( - PdfDictionaryProperties.a, actionDictionary); + final PdfReferenceHolder buttonObject = kidsArray[0]! as PdfReferenceHolder; + final PdfDictionary buttonDictionary = buttonObject.object! as PdfDictionary; + buttonDictionary.setProperty(PdfDictionaryProperties.a, actionDictionary); } else { dictionary!.setProperty(PdfDictionaryProperties.a, actionDictionary); } } else { - final PdfArray kidsArray = - dictionary![PdfDictionaryProperties.kids]! as PdfArray; - final PdfReferenceHolder buttonObject = - kidsArray[0]! as PdfReferenceHolder; - final PdfDictionary buttonDictionary = - buttonObject.object! as PdfDictionary; + final PdfArray kidsArray = dictionary![PdfDictionaryProperties.kids]! as PdfArray; + final PdfReferenceHolder buttonObject = kidsArray[0]! as PdfReferenceHolder; + final PdfDictionary buttonDictionary = buttonObject.object! as PdfDictionary; buttonDictionary.setProperty(PdfDictionaryProperties.a, actionDictionary); } } @@ -258,16 +245,13 @@ class PdfButtonFieldHelper extends PdfFieldHelper { .insert(buttonField.tabIndex, widget!); } } - if (buttonField.form != null && - !PdfFormHelper.getHelper(buttonField.form!).needAppearances!) { + if (buttonField.form != null && !PdfFormHelper.getHelper(buttonField.form!).needAppearances!) { if (PdfAnnotationHelper.getHelper(widget!).appearance == null) { drawAppearance(widget!.appearance.normal); } } - if (buttonField.form != null && - !PdfFormHelper.getHelper(buttonField.form!).needAppearances!) { - if (PdfAppearanceHelper.getHelper(widget!.appearance).templatePressed == - null) { + if (buttonField.form != null && !PdfFormHelper.getHelper(buttonField.form!).needAppearances!) { + if (PdfAppearanceHelper.getHelper(widget!.appearance).templatePressed == null) { _drawPressedAppearance(widget!.appearance.pressed); } } @@ -281,20 +265,15 @@ class PdfButtonFieldHelper extends PdfFieldHelper { buttonField.text = buttonField.name!; } final PaintParams paintParams = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, widget!.bounds.size.width, widget!.bounds.size.height), + bounds: Rect.fromLTWH(0, 0, widget!.bounds.size.width, widget!.bounds.size.height), backBrush: PdfSolidBrush(buttonField.backColor), foreBrush: PdfSolidBrush(buttonField.foreColor), borderPen: borderPen, style: buttonField.borderStyle, borderWidth: borderWidth, shadowBrush: PdfSolidBrush(buttonField.backColor)); - FieldPainter().drawButton( - template.graphics!, - paintParams, - buttonField.text, - (font == null) ? PdfStandardFont(PdfFontFamily.helvetica, 8) : font!, - format); + FieldPainter().drawButton(template.graphics!, paintParams, buttonField.text, + (font == null) ? PdfStandardFont(PdfFontFamily.helvetica, 8) : font!, format); } void _drawPressedAppearance(PdfTemplate template) { @@ -302,39 +281,32 @@ class PdfButtonFieldHelper extends PdfFieldHelper { buttonField.text = buttonField.name!; } final PaintParams paintParams = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, widget!.bounds.size.width, widget!.bounds.size.height), + bounds: Rect.fromLTWH(0, 0, widget!.bounds.size.width, widget!.bounds.size.height), backBrush: PdfSolidBrush(buttonField.backColor), foreBrush: PdfSolidBrush(buttonField.foreColor), borderPen: borderPen, style: buttonField.borderStyle, borderWidth: borderWidth, shadowBrush: PdfSolidBrush(buttonField.backColor)); - FieldPainter().drawPressedButton( - template.graphics!, - paintParams, - buttonField.text, - (font == null) ? PdfStandardFont(PdfFontFamily.helvetica, 8) : font!, - format); + FieldPainter().drawPressedButton(template.graphics!, paintParams, buttonField.text, + (font == null) ? PdfStandardFont(PdfFontFamily.helvetica, 8) : font!, format); } String _obtainText() { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); String? str; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final PdfDictionary appearance = crossTable! - .getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; + final PdfDictionary appearance = + crossTable!.getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; if (appearance.containsKey(PdfDictionaryProperties.ca)) { - final PdfString text = crossTable! - .getObject(appearance[PdfDictionaryProperties.ca])! as PdfString; + final PdfString text = + crossTable!.getObject(appearance[PdfDictionaryProperties.ca])! as PdfString; str = text.value; } } if (str == null) { - PdfString? val = crossTable! - .getObject(dictionary![PdfDictionaryProperties.v]) as PdfString?; - val ??= PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true) + PdfString? val = crossTable!.getObject(dictionary![PdfDictionaryProperties.v]) as PdfString?; + val ??= PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true) as PdfString?; if (val != null) { str = val.value; @@ -349,16 +321,14 @@ class PdfButtonFieldHelper extends PdfFieldHelper { final String text = value; final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); if (widget.containsKey(PdfDictionaryProperties.mk)) { - final PdfDictionary appearance = crossTable! - .getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; + final PdfDictionary appearance = + crossTable!.getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; appearance.setString(PdfDictionaryProperties.ca, text); - widget.setProperty( - PdfDictionaryProperties.mk, PdfReferenceHolder(appearance)); + widget.setProperty(PdfDictionaryProperties.mk, PdfReferenceHolder(appearance)); } else { final PdfDictionary appearance = PdfDictionary(); appearance.setString(PdfDictionaryProperties.ca, text); - widget.setProperty( - PdfDictionaryProperties.mk, PdfReferenceHolder(appearance)); + widget.setProperty(PdfDictionaryProperties.mk, PdfReferenceHolder(appearance)); } if (widget.containsKey(PdfDictionaryProperties.ap)) { _applyAppearance(widget, null); @@ -373,8 +343,7 @@ class PdfButtonFieldHelper extends PdfFieldHelper { final PdfArray? kids = obtainKids(); if (kids != null) { for (int i = 0; i < kids.count; ++i) { - final PdfDictionary? widget = - crossTable!.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? widget = crossTable!.getObject(kids[i]) as PdfDictionary?; _applyAppearance(widget, buttonField); } } @@ -389,8 +358,7 @@ class PdfButtonFieldHelper extends PdfFieldHelper { if ((kids != null) && (kids.count > 1)) { for (int i = 0; i < kids.count; ++i) { if (buttonField.page != null) { - final PdfDictionary? widget = - crossTable!.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? widget = crossTable!.getObject(kids[i]) as PdfDictionary?; _drawButton(buttonField.page!.graphics, buttonField, widget); } } @@ -398,17 +366,14 @@ class PdfButtonFieldHelper extends PdfFieldHelper { _drawButton(buttonField.page!.graphics, null); } } else { - final PdfAppearance? appearance = - PdfAnnotationHelper.getHelper(widget!).appearance; + final PdfAppearance? appearance = PdfAnnotationHelper.getHelper(widget!).appearance; if (appearance != null) { - buttonField.page!.graphics.drawPdfTemplate( - appearance.normal, Offset(widget!.bounds.left, widget!.bounds.top)); + buttonField.page!.graphics + .drawPdfTemplate(appearance.normal, Offset(widget!.bounds.left, widget!.bounds.top)); } else { Rect rect = buttonField.bounds; - rect = Rect.fromLTWH( - 0, 0, buttonField.bounds.width, buttonField.bounds.height); - final PdfFont tempFont = - font ?? PdfStandardFont(PdfFontFamily.helvetica, 8); + rect = Rect.fromLTWH(0, 0, buttonField.bounds.width, buttonField.bounds.height); + final PdfFont tempFont = font ?? PdfStandardFont(PdfFontFamily.helvetica, 8); final PaintParams params = PaintParams( bounds: rect, backBrush: backBrush, @@ -418,73 +383,52 @@ class PdfButtonFieldHelper extends PdfFieldHelper { borderWidth: buttonField.borderWidth, shadowBrush: shadowBrush); final PdfTemplate template = PdfTemplate(rect.width, rect.height); - FieldPainter().drawButton(template.graphics!, params, buttonField.text, - tempFont, stringFormat); - buttonField.page!.graphics.drawPdfTemplate(template, - Offset(buttonField.bounds.left, buttonField.bounds.top), rect.size); + FieldPainter() + .drawButton(template.graphics!, params, buttonField.text, tempFont, stringFormat); + buttonField.page!.graphics.drawPdfTemplate( + template, Offset(buttonField.bounds.left, buttonField.bounds.top), rect.size); buttonField.page!.graphics.drawString( - (buttonField.text.isEmpty) ? buttonField.name! : buttonField.text, - tempFont, - brush: params.foreBrush, - bounds: buttonField.bounds, - format: stringFormat); + (buttonField.text.isEmpty) ? buttonField.name! : buttonField.text, tempFont, + brush: params.foreBrush, bounds: buttonField.bounds, format: stringFormat); } } } void _applyAppearance(PdfDictionary? widget, PdfButtonField? item) { - if ((actions != null) && - PdfFieldActionsHelper.getHelper(actions!).changed) { + if ((actions != null) && PdfFieldActionsHelper.getHelper(actions!).changed) { widget!.setProperty(PdfDictionaryProperties.aa, actions); } if ((widget != null) && (widget.containsKey(PdfDictionaryProperties.ap))) { - final PdfDictionary? appearance = crossTable! - .getObject(widget[PdfDictionaryProperties.ap]) as PdfDictionary?; - if ((appearance != null) && - (appearance.containsKey(PdfDictionaryProperties.n))) { + final PdfDictionary? appearance = + crossTable!.getObject(widget[PdfDictionaryProperties.ap]) as PdfDictionary?; + if ((appearance != null) && (appearance.containsKey(PdfDictionaryProperties.n))) { final Rect bounds = (item == null) ? buttonField.bounds : item.bounds; PdfTemplate template = PdfTemplate(bounds.width, bounds.height); - final PdfTemplate pressedTemplate = - PdfTemplate(bounds.width, bounds.height); + final PdfTemplate pressedTemplate = PdfTemplate(bounds.width, bounds.height); if (widget.containsKey(PdfDictionaryProperties.mk)) { PdfDictionary? mkDic; if (widget[PdfDictionaryProperties.mk] is PdfReferenceHolder) { - mkDic = crossTable!.getObject(widget[PdfDictionaryProperties.mk]) - as PdfDictionary?; + mkDic = crossTable!.getObject(widget[PdfDictionaryProperties.mk]) as PdfDictionary?; } else { mkDic = widget[PdfDictionaryProperties.mk] as PdfDictionary?; } if (mkDic != null && mkDic.containsKey(PdfDictionaryProperties.r)) { - final PdfNumber? angle = - mkDic[PdfDictionaryProperties.r] as PdfNumber?; + final PdfNumber? angle = mkDic[PdfDictionaryProperties.r] as PdfNumber?; if (angle != null) { if (angle.value == 90) { template = PdfTemplate(bounds.size.height, bounds.size.width); - PdfTemplateHelper.getHelper(template).writeTransformation = - false; - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = + PdfTemplateHelper.getHelper(template).writeTransformation = false; + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = PdfArray([0, 1, -1, 0, bounds.size.width, 0]); } else if (angle.value == 180) { template = PdfTemplate(bounds.size.width, bounds.size.height); - PdfTemplateHelper.getHelper(template).writeTransformation = - false; - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = - PdfArray([ - -1, - 0, - 0, - -1, - bounds.size.width, - bounds.size.height - ]); + PdfTemplateHelper.getHelper(template).writeTransformation = false; + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = + PdfArray([-1, 0, 0, -1, bounds.size.width, bounds.size.height]); } else if (angle.value == 270) { template = PdfTemplate(bounds.size.height, bounds.size.width); - PdfTemplateHelper.getHelper(template).writeTransformation = - false; - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = + PdfTemplateHelper.getHelper(template).writeTransformation = false; + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = PdfArray([0, -1, 1, 0, 0, bounds.size.height]); } } @@ -492,20 +436,16 @@ class PdfButtonFieldHelper extends PdfFieldHelper { } _drawButton(template.graphics, item, widget); _drawButton(pressedTemplate.graphics, item, widget); - appearance.setProperty( - PdfDictionaryProperties.n, PdfReferenceHolder(template)); - appearance.setProperty( - PdfDictionaryProperties.d, PdfReferenceHolder(pressedTemplate)); + appearance.setProperty(PdfDictionaryProperties.n, PdfReferenceHolder(template)); + appearance.setProperty(PdfDictionaryProperties.d, PdfReferenceHolder(pressedTemplate)); widget.setProperty(PdfDictionaryProperties.ap, appearance); } - } else if (PdfFormHelper.getHelper(buttonField.form!) - .setAppearanceDictionary) { + } else if (PdfFormHelper.getHelper(buttonField.form!).setAppearanceDictionary) { PdfFormHelper.getHelper(buttonField.form!).needAppearances = true; } } - void _drawButton(PdfGraphics? graphics, PdfButtonField? item, - [PdfDictionary? widget]) { + void _drawButton(PdfGraphics? graphics, PdfButtonField? item, [PdfDictionary? widget]) { final GraphicsProperties gp = GraphicsProperties(buttonField); if (!flattenField) { gp.bounds = Rect.fromLTWH(0, 0, gp.bounds!.width, gp.bounds!.height); @@ -524,19 +464,16 @@ class PdfButtonFieldHelper extends PdfFieldHelper { PdfPageRotateAngle.rotateAngle0)) { IPdfPrimitive? buttonAppearance = dictionary![PdfDictionaryProperties.ap]; buttonAppearance ??= widget![PdfDictionaryProperties.ap]; - PdfDictionary? buttonResource = - PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; + PdfDictionary? buttonResource = PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; if (buttonResource != null) { buttonAppearance = buttonResource[PdfDictionaryProperties.n]; - buttonResource = - PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; + buttonResource = PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; if (buttonResource != null) { final PdfStream? stream = buttonResource as PdfStream?; if (stream != null) { - final PdfTemplate buttonShape = - PdfTemplateHelper.fromPdfStream(stream); - buttonField.page!.graphics.drawPdfTemplate(buttonShape, - Offset(buttonField.bounds.left, buttonField.bounds.top)); + final PdfTemplate buttonShape = PdfTemplateHelper.fromPdfStream(stream); + buttonField.page!.graphics.drawPdfTemplate( + buttonShape, Offset(buttonField.bounds.left, buttonField.bounds.top)); } } } @@ -545,34 +482,28 @@ class PdfButtonFieldHelper extends PdfFieldHelper { !(PdfGraphicsHelper.getHelper(graphics!).layer != null && PdfGraphicsHelper.getHelper(graphics).page!.rotation != PdfPageRotateAngle.rotateAngle0)) { - IPdfPrimitive? buttonAppearance = - item._helper.dictionary![PdfDictionaryProperties.ap]; + IPdfPrimitive? buttonAppearance = item._helper.dictionary![PdfDictionaryProperties.ap]; buttonAppearance ??= widget![PdfDictionaryProperties.ap]; - PdfDictionary? buttonResource = - PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; + PdfDictionary? buttonResource = PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; if (buttonResource != null) { buttonAppearance = buttonResource[PdfDictionaryProperties.n]; - buttonResource = - PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; + buttonResource = PdfCrossTable.dereference(buttonAppearance) as PdfDictionary?; if (buttonResource != null) { final PdfStream? stream = buttonResource as PdfStream?; if (stream != null) { - final PdfTemplate buttonShape = - PdfTemplateHelper.fromPdfStream(stream); - buttonField.page!.graphics.drawPdfTemplate(buttonShape, - Offset(buttonField.bounds.left, buttonField.bounds.top)); + final PdfTemplate buttonShape = PdfTemplateHelper.fromPdfStream(stream); + buttonField.page!.graphics.drawPdfTemplate( + buttonShape, Offset(buttonField.bounds.left, buttonField.bounds.top)); } } } } else { - FieldPainter().drawButton( - graphics!, prms, buttonField.text, gp.font!, gp.stringFormat); + FieldPainter().drawButton(graphics!, prms, buttonField.text, gp.font!, gp.stringFormat); } } /// internal method - static PdfButtonField loadButtonField( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfButtonField loadButtonField(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfButtonField._loaded(dictionary, crossTable); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_check_box_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_check_box_field.dart index 76d18905d..a928aaee5 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_check_box_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_check_box_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -60,8 +60,7 @@ class PdfCheckBoxField extends PdfCheckFieldBase { final PdfArray? kids = _helper.kids; if (kids != null) { for (int i = 0; i < kids.count; ++i) { - final PdfDictionary? itemDictionary = - crossTable.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? itemDictionary = crossTable.getObject(kids[i]) as PdfDictionary?; PdfFieldItemCollectionHelper.getHelper(_items!) .add(PdfCheckBoxItemHelper.getItem(this, i, itemDictionary)); } @@ -86,15 +85,11 @@ class PdfCheckBoxField extends PdfCheckFieldBase { .dictionary![PdfDictionaryProperties.usageApplication]); if (state == null) { final IPdfPrimitive? name = PdfFieldHelper.getValue( - _helper.dictionary!, - _helper.crossTable, - PdfDictionaryProperties.v, - false); + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.v, false); if (name != null && name is PdfName) { _checked = name.name == _helper.getItemValue( - PdfFieldItemHelper.getHelper(items![_helper.defaultIndex]) - .dictionary!, + PdfFieldItemHelper.getHelper(items![_helper.defaultIndex]).dictionary!, _helper.crossTable); } } else if (state is PdfName) { @@ -104,13 +99,10 @@ class PdfCheckBoxField extends PdfCheckFieldBase { } if (_helper.dictionary!.containsKey(PdfDictionaryProperties.v)) { if (_helper.dictionary![PdfDictionaryProperties.v]! is PdfName) { - final PdfName chk = - _helper.dictionary![PdfDictionaryProperties.v]! as PdfName; + final PdfName chk = _helper.dictionary![PdfDictionaryProperties.v]! as PdfName; _checked = chk.name != 'Off'; - } else if (_helper.dictionary![PdfDictionaryProperties.v]! - is PdfString) { - final PdfString chk = - _helper.dictionary![PdfDictionaryProperties.v]! as PdfString; + } else if (_helper.dictionary![PdfDictionaryProperties.v]! is PdfString) { + final PdfString chk = _helper.dictionary![PdfDictionaryProperties.v]! as PdfString; _checked = chk.value != 'Off'; } } @@ -122,17 +114,14 @@ class PdfCheckBoxField extends PdfCheckFieldBase { if (_helper.isLoadedField) { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.v)) { if (_helper.dictionary![PdfDictionaryProperties.v]! is PdfName) { - final PdfName chk = - _helper.dictionary![PdfDictionaryProperties.v]! as PdfName; + final PdfName chk = _helper.dictionary![PdfDictionaryProperties.v]! as PdfName; if (chk.name!.isNotEmpty) { _checked = chk.name != 'Off'; } else { _helper.dictionary!.remove(PdfDictionaryProperties.v); } - } else if (_helper.dictionary![PdfDictionaryProperties.v]! - is PdfString) { - final PdfString chk = - _helper.dictionary![PdfDictionaryProperties.v]! as PdfString; + } else if (_helper.dictionary![PdfDictionaryProperties.v]! is PdfString) { + final PdfString chk = _helper.dictionary![PdfDictionaryProperties.v]! as PdfString; if (chk.value!.isNotEmpty) { _checked = chk.value != 'Off'; } else { @@ -153,18 +142,15 @@ class PdfCheckBoxField extends PdfCheckFieldBase { val = _helper._enableItems(value, val); } if (_checked) { - _helper.dictionary!.setName(PdfName(PdfDictionaryProperties.v), - val ?? PdfDictionaryProperties.yes); + _helper.dictionary! + .setName(PdfName(PdfDictionaryProperties.v), val ?? PdfDictionaryProperties.yes); _helper.dictionary!.setProperty( - PdfDictionaryProperties.usageApplication, - PdfName(val ?? PdfDictionaryProperties.yes)); + PdfDictionaryProperties.usageApplication, PdfName(val ?? PdfDictionaryProperties.yes)); } else { _helper.dictionary!.remove(PdfDictionaryProperties.v); - if (_helper.dictionary! - .containsKey(PdfDictionaryProperties.usageApplication)) { + if (_helper.dictionary!.containsKey(PdfDictionaryProperties.usageApplication)) { _helper.dictionary!.setName( - PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.off); + PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.off); } } } @@ -194,8 +180,7 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { } /// internal method - static PdfCheckBoxField loadCheckBoxField( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfCheckBoxField loadCheckBoxField(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfCheckBoxField._loaded(dictionary, crossTable); } @@ -228,8 +213,8 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { bool isChecked = false; String? val; if (dictionary!.containsKey(PdfDictionaryProperties.usageApplication)) { - final IPdfPrimitive? state = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.usageApplication]); + final IPdfPrimitive? state = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.usageApplication]); if (state != null && state is PdfName) { isChecked = state.name != PdfDictionaryProperties.off; } @@ -250,8 +235,7 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { if (checkBoxField.items != null && checkBoxField.items!.count > 0) { (checkBoxField.items![defaultIndex] as PdfCheckBoxItem).checked = check; final PdfDictionary? dic = - PdfFieldItemHelper.getHelper(checkBoxField.items![defaultIndex]) - .dictionary; + PdfFieldItemHelper.getHelper(checkBoxField.items![defaultIndex]).dictionary; if (dic != null) { value = getItemValue(dic, crossTable); } @@ -262,8 +246,7 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { /// internal method void drawCheckAppearance() { final PaintParams paintParams = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, widget!.bounds.size.width, widget!.bounds.size.height), + bounds: Rect.fromLTWH(0, 0, widget!.bounds.size.width, widget!.bounds.size.height), backBrush: backBrush, foreBrush: foreBrush, borderPen: borderPen, @@ -271,25 +254,17 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { borderWidth: checkBoxField.borderWidth, shadowBrush: shadowBrush); PdfTemplate template = widget!.extendedAppearance!.normal.activate!; - FieldPainter().drawCheckBox(template.graphics!, paintParams, - styleToString(checkBoxField.style), PdfCheckFieldState.checked, font); + FieldPainter().drawCheckBox(template.graphics!, paintParams, styleToString(checkBoxField.style), + PdfCheckFieldState.checked, font); template = widget!.extendedAppearance!.normal.off!; - FieldPainter().drawCheckBox(template.graphics!, paintParams, - styleToString(checkBoxField.style), PdfCheckFieldState.unchecked, font); + FieldPainter().drawCheckBox(template.graphics!, paintParams, styleToString(checkBoxField.style), + PdfCheckFieldState.unchecked, font); template = widget!.extendedAppearance!.pressed.activate!; - FieldPainter().drawCheckBox( - template.graphics!, - paintParams, - styleToString(checkBoxField.style), - PdfCheckFieldState.pressedChecked, - font); + FieldPainter().drawCheckBox(template.graphics!, paintParams, styleToString(checkBoxField.style), + PdfCheckFieldState.pressedChecked, font); template = widget!.extendedAppearance!.pressed.off!; - FieldPainter().drawCheckBox( - template.graphics!, - paintParams, - styleToString(checkBoxField.style), - PdfCheckFieldState.pressedUnchecked, - font); + FieldPainter().drawCheckBox(template.graphics!, paintParams, styleToString(checkBoxField.style), + PdfCheckFieldState.pressedUnchecked, font); } /// internal method @@ -298,8 +273,7 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { final PdfArray? kids = obtainKids(); if (kids != null) { for (int i = 0; i < kids.count; ++i) { - final PdfDictionary? widget = - crossTable!.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? widget = crossTable!.getObject(kids[i]) as PdfDictionary?; applyAppearance(widget, null, checkBoxField._items![i]); } } else { @@ -311,9 +285,8 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { @override void draw() { super.draw(); - PdfCheckFieldState state = checkBoxField.isChecked - ? PdfCheckFieldState.checked - : PdfCheckFieldState.unchecked; + PdfCheckFieldState state = + checkBoxField.isChecked ? PdfCheckFieldState.checked : PdfCheckFieldState.unchecked; if (!isLoadedField) { final PaintParams params = PaintParams( bounds: checkBoxField.bounds, @@ -333,21 +306,18 @@ class PdfCheckBoxFieldHelper extends PdfCheckFieldBaseHelper { params.style = item.borderStyle; params.borderWidth = item.borderWidth; params.shadowBrush = item._helper.shadowBrush; - FieldPainter().drawCheckBox( - item.page!.graphics, params, styleToString(item.style), state); + FieldPainter() + .drawCheckBox(item.page!.graphics, params, styleToString(item.style), state); } } else { - FieldPainter().drawCheckBox(checkBoxField.page!.graphics, params, - styleToString(checkBoxField.style), state); + FieldPainter().drawCheckBox( + checkBoxField.page!.graphics, params, styleToString(checkBoxField.style), state); } } else { if (kids != null) { for (int i = 0; i < kids!.count; ++i) { - final PdfCheckBoxItem item = - checkBoxField._items![i] as PdfCheckBoxItem; - state = item.checked - ? PdfCheckFieldState.checked - : PdfCheckFieldState.unchecked; + final PdfCheckBoxItem item = checkBoxField._items![i] as PdfCheckBoxItem; + state = item.checked ? PdfCheckFieldState.checked : PdfCheckFieldState.unchecked; if (item.page != null) { drawStateItem(item.page!.graphics, state, null, item); } @@ -374,8 +344,7 @@ abstract class PdfCheckFieldBase extends PdfField { set style(PdfCheckBoxStyle value) { if (_checkBaseHelper.isLoadedField) { _checkBaseHelper.assignStyle(value); - if (this is PdfCheckBoxField && - (this as PdfCheckBoxField).items != null) { + if (this is PdfCheckBoxField && (this as PdfCheckBoxField).items != null) { final PdfFieldItemCollection items = (this as PdfCheckBoxField).items!; for (int i = 0; i < items.count; i++) { PdfCheckBoxItemHelper.setStyle(items[i] as PdfCheckBoxItem, value); @@ -388,9 +357,8 @@ abstract class PdfCheckFieldBase extends PdfField { } else { if (_style != value) { _style = value; - WidgetAnnotationHelper.getHelper(_checkBaseHelper.widget!) - .widgetAppearance! - .normalCaption = _checkBaseHelper.styleToString(_style); + WidgetAnnotationHelper.getHelper(_checkBaseHelper.widget!).widgetAppearance!.normalCaption = + _checkBaseHelper.styleToString(_style); } } } @@ -476,8 +444,7 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { highlightMode: highlightMode, borderStyle: borderStyle, tooltip: tooltip); - dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); + dictionary!.setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); checkField._initValues(style); } @@ -505,17 +472,13 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { void save() { super.save(); if (checkField.form != null) { - final Map checkValue = - _createTemplate(_checkedTemplate); + final Map checkValue = _createTemplate(_checkedTemplate); _checkedTemplate = checkValue['template']; - final Map unCheckValue = - _createTemplate(_uncheckedTemplate); + final Map unCheckValue = _createTemplate(_uncheckedTemplate); _uncheckedTemplate = unCheckValue['template']; - final Map pressedValue = - _createTemplate(_pressedCheckedTemplate); + final Map pressedValue = _createTemplate(_pressedCheckedTemplate); _pressedCheckedTemplate = pressedValue['template']; - final Map unPressedValue = - _createTemplate(_pressedUncheckedTemplate); + final Map unPressedValue = _createTemplate(_pressedUncheckedTemplate); _pressedUncheckedTemplate = unPressedValue['template']; widget!.extendedAppearance!.normal.activate = _checkedTemplate; widget!.extendedAppearance!.normal.off = _uncheckedTemplate; @@ -532,8 +495,7 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { Map _createTemplate(PdfTemplate? template) { if (template == null) { - template = - PdfTemplate(widget!.bounds.size.width, widget!.bounds.size.height); + template = PdfTemplate(widget!.bounds.size.width, widget!.bounds.size.height); } else { template.reset(widget!.bounds.size.width, widget!.bounds.size.height); } @@ -551,29 +513,24 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { if (checkField is PdfCheckBoxField) { (checkField as PdfCheckBoxField)._helper.drawCheckAppearance(); } else if (checkField is PdfRadioButtonListItem) { - PdfRadioButtonListItemHelper.getHelper( - checkField as PdfRadioButtonListItem) + PdfRadioButtonListItemHelper.getHelper(checkField as PdfRadioButtonListItem) .drawCheckAppearance(); } } /// internal method - void applyAppearance(PdfDictionary? widget, PdfCheckFieldBase? item, - [PdfFieldItem? fieldItem]) { + void applyAppearance(PdfDictionary? widget, PdfCheckFieldBase? item, [PdfFieldItem? fieldItem]) { if (widget != null && item != null) { - if (item._checkBaseHelper.dictionary! - .containsKey(PdfDictionaryProperties.v) && + if (item._checkBaseHelper.dictionary!.containsKey(PdfDictionaryProperties.v) && item is! PdfRadioButtonListItem) { + widget.setName(PdfName(PdfDictionaryProperties.v), PdfDictionaryProperties.yes); widget.setName( - PdfName(PdfDictionaryProperties.v), PdfDictionaryProperties.yes); - widget.setName(PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.yes); - } else if (!item._checkBaseHelper.dictionary! - .containsKey(PdfDictionaryProperties.v) && + PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.yes); + } else if (!item._checkBaseHelper.dictionary!.containsKey(PdfDictionaryProperties.v) && item is! PdfRadioButtonListItem) { widget.remove(PdfDictionaryProperties.v); - widget.setName(PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.off); + widget.setName( + PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.off); } } else if (widget != null && fieldItem != null) { widget = PdfFieldItemHelper.getHelper(fieldItem).dictionary; @@ -581,74 +538,58 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { widget = item!._checkBaseHelper.dictionary; } if ((widget != null) && (widget.containsKey(PdfDictionaryProperties.ap))) { - final PdfDictionary? appearance = crossTable! - .getObject(widget[PdfDictionaryProperties.ap]) as PdfDictionary?; - if ((appearance != null) && - (appearance.containsKey(PdfDictionaryProperties.n))) { + final PdfDictionary? appearance = + crossTable!.getObject(widget[PdfDictionaryProperties.ap]) as PdfDictionary?; + if ((appearance != null) && (appearance.containsKey(PdfDictionaryProperties.n))) { String? value = ''; Rect rect; if (item != null) { value = getItemValue(widget, item._checkBaseHelper.crossTable); rect = item.bounds; } else if (fieldItem != null) { - value = getItemValue( - widget, - PdfFieldHelper.getHelper( - PdfFieldItemHelper.getHelper(fieldItem).field) - .crossTable); + value = getItemValue(widget, + PdfFieldHelper.getHelper(PdfFieldItemHelper.getHelper(fieldItem).field).crossTable); rect = fieldItem.bounds; } else { value = getItemValue(widget, crossTable); rect = checkField.bounds; } - IPdfPrimitive? holder = - PdfCrossTable.dereference(appearance[PdfDictionaryProperties.n]); + IPdfPrimitive? holder = PdfCrossTable.dereference(appearance[PdfDictionaryProperties.n]); PdfDictionary? normal = holder as PdfDictionary?; if (fieldChanged == true && normal != null) { normal = PdfDictionary(); - final PdfTemplate checkedTemplate = - PdfTemplate(rect.width, rect.height); - final PdfTemplate unchekedTemplate = - PdfTemplate(rect.width, rect.height); - drawStateItem(checkedTemplate.graphics!, PdfCheckFieldState.checked, - item, fieldItem); - drawStateItem(unchekedTemplate.graphics!, - PdfCheckFieldState.unchecked, item, fieldItem); + final PdfTemplate checkedTemplate = PdfTemplate(rect.width, rect.height); + final PdfTemplate unchekedTemplate = PdfTemplate(rect.width, rect.height); + drawStateItem(checkedTemplate.graphics!, PdfCheckFieldState.checked, item, fieldItem); + drawStateItem(unchekedTemplate.graphics!, PdfCheckFieldState.unchecked, item, fieldItem); normal.setProperty(value, PdfReferenceHolder(checkedTemplate)); - normal.setProperty(PdfDictionaryProperties.off, - PdfReferenceHolder(unchekedTemplate)); + normal.setProperty(PdfDictionaryProperties.off, PdfReferenceHolder(unchekedTemplate)); appearance.remove(PdfDictionaryProperties.n); appearance[PdfDictionaryProperties.n] = PdfReferenceHolder(normal); } - holder = - PdfCrossTable.dereference(appearance[PdfDictionaryProperties.d]); + holder = PdfCrossTable.dereference(appearance[PdfDictionaryProperties.d]); PdfDictionary? pressed = holder as PdfDictionary?; if (fieldChanged == true && pressed != null) { pressed = PdfDictionary(); - final PdfTemplate checkedTemplate = - PdfTemplate(rect.width, rect.height); - final PdfTemplate unchekedTemplate = - PdfTemplate(rect.width, rect.height); - drawStateItem(checkedTemplate.graphics!, - PdfCheckFieldState.pressedChecked, item, fieldItem); - drawStateItem(unchekedTemplate.graphics!, - PdfCheckFieldState.pressedUnchecked, item, fieldItem); - pressed.setProperty(PdfDictionaryProperties.off, - PdfReferenceHolder(unchekedTemplate)); + final PdfTemplate checkedTemplate = PdfTemplate(rect.width, rect.height); + final PdfTemplate unchekedTemplate = PdfTemplate(rect.width, rect.height); + drawStateItem( + checkedTemplate.graphics!, PdfCheckFieldState.pressedChecked, item, fieldItem); + drawStateItem( + unchekedTemplate.graphics!, PdfCheckFieldState.pressedUnchecked, item, fieldItem); + pressed.setProperty(PdfDictionaryProperties.off, PdfReferenceHolder(unchekedTemplate)); pressed.setProperty(value, PdfReferenceHolder(checkedTemplate)); appearance.remove(PdfDictionaryProperties.d); appearance[PdfDictionaryProperties.d] = PdfReferenceHolder(pressed); } } widget.setProperty(PdfDictionaryProperties.ap, appearance); - } else if (PdfFormHelper.getHelper(checkField.form!) - .setAppearanceDictionary) { + } else if (PdfFormHelper.getHelper(checkField.form!).setAppearanceDictionary) { PdfFormHelper.getHelper(checkField.form!).needAppearances = true; } else if (PdfFormHelper.getHelper(form!).setAppearanceDictionary && !PdfFormHelper.getHelper(form!).needAppearances!) { final PdfDictionary dic = PdfDictionary(); - final PdfTemplate template = - PdfTemplate(checkField.bounds.width, checkField.bounds.height); + final PdfTemplate template = PdfTemplate(checkField.bounds.width, checkField.bounds.height); drawAppearance(template); dic.setProperty(PdfDictionaryProperties.n, PdfReferenceHolder(template)); widget!.setProperty(PdfDictionaryProperties.ap, dic); @@ -659,8 +600,8 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfCheckBoxStyle style = PdfCheckBoxStyle.check; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final PdfDictionary bs = crossTable! - .getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; + final PdfDictionary bs = + crossTable!.getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; style = _createStyle(bs); } return style; @@ -669,8 +610,7 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { PdfCheckBoxStyle _createStyle(PdfDictionary bs) { PdfCheckBoxStyle style = PdfCheckBoxStyle.check; if (bs.containsKey(PdfDictionaryProperties.ca)) { - final PdfString? name = - crossTable!.getObject(bs[PdfDictionaryProperties.ca]) as PdfString?; + final PdfString? name = crossTable!.getObject(bs[PdfDictionaryProperties.ca]) as PdfString?; if (name != null) { final String ch = name.value!.toLowerCase(); switch (ch) { @@ -724,16 +664,16 @@ class PdfCheckFieldBaseHelper extends PdfFieldHelper { break; } if (widget[PdfDictionaryProperties.mk] is PdfReferenceHolder) { - final PdfDictionary widgetDict = crossTable! - .getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; + final PdfDictionary widgetDict = + crossTable!.getObject(widget[PdfDictionaryProperties.mk])! as PdfDictionary; if (widgetDict.containsKey(PdfDictionaryProperties.ca)) { widgetDict[PdfDictionaryProperties.ca] = PdfString(style); } else { widgetDict.setProperty(PdfDictionaryProperties.ca, PdfString(style)); } } else { - (widget[PdfDictionaryProperties.mk]! - as PdfDictionary)[PdfDictionaryProperties.ca] = PdfString(style); + (widget[PdfDictionaryProperties.mk]! as PdfDictionary)[PdfDictionaryProperties.ca] = + PdfString(style); } WidgetAnnotationHelper.getHelper(checkField._checkBaseHelper.widget!) .widgetAppearance! @@ -787,13 +727,13 @@ class PdfRadioButtonListItem extends PdfCheckFieldBase { this.value = value; _radioButtonListItemHelper.dictionary!.beginSave = _radioButtonListItemHelper.dictionaryBeginSave; - WidgetAnnotationHelper.getHelper(_radioButtonListItemHelper.widget!) - .beginSave = _radioButtonListItemHelper._widgetSave; + WidgetAnnotationHelper.getHelper(_radioButtonListItemHelper.widget!).beginSave = + _radioButtonListItemHelper._widgetSave; style = PdfCheckBoxStyle.circle; } - PdfRadioButtonListItem._loaded(PdfDictionary dictionary, - PdfCrossTable crossTable, PdfRadioButtonListField field) { + PdfRadioButtonListItem._loaded( + PdfDictionary dictionary, PdfCrossTable crossTable, PdfRadioButtonListField field) { _radioButtonListItemHelper = PdfRadioButtonListItemHelper(this); _radioButtonListItemHelper.load(dictionary, crossTable); _radioButtonListItemHelper._field = field; @@ -804,10 +744,8 @@ class PdfRadioButtonListItem extends PdfCheckFieldBase { ///Gets or sets the value. String get value { if (_radioButtonListItemHelper.isLoadedField) { - _radioButtonListItemHelper._value = - _radioButtonListItemHelper.getItemValue( - _radioButtonListItemHelper.dictionary!, - _radioButtonListItemHelper.crossTable); + _radioButtonListItemHelper._value = _radioButtonListItemHelper.getItemValue( + _radioButtonListItemHelper.dictionary!, _radioButtonListItemHelper.crossTable); } return _radioButtonListItemHelper._value!; } @@ -824,27 +762,23 @@ class PdfRadioButtonListItem extends PdfCheckFieldBase { /// Gets the form of the field.{Read-Only} @override - PdfForm? get form => (_radioButtonListItemHelper._field != null) - ? _radioButtonListItemHelper._field!.form - : null; + PdfForm? get form => + (_radioButtonListItemHelper._field != null) ? _radioButtonListItemHelper._field!.form : null; @override set style(PdfCheckBoxStyle value) { if (_radioButtonListItemHelper.isLoadedField) { _radioButtonListItemHelper.assignStyle(value); if (PdfFormHelper.getHelper(form!).needAppearances == false) { - PdfFieldHelper.getHelper(_radioButtonListItemHelper._field!).changed = - true; - PdfFieldHelper.getHelper(_radioButtonListItemHelper._field!) - .fieldChanged = true; + PdfFieldHelper.getHelper(_radioButtonListItemHelper._field!).changed = true; + PdfFieldHelper.getHelper(_radioButtonListItemHelper._field!).fieldChanged = true; } } else { if (super.style != value) { super.style = value; WidgetAnnotationHelper.getHelper(_radioButtonListItemHelper.widget!) - .widgetAppearance! - .normalCaption = - _radioButtonListItemHelper.styleToString(super.style); + .widgetAppearance! + .normalCaption = _radioButtonListItemHelper.styleToString(super.style); } } } @@ -864,8 +798,8 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { String? optionValue; /// internal method - static PdfRadioButtonListItem loaded(PdfDictionary dictionary, - PdfCrossTable crossTable, PdfRadioButtonListField field) { + static PdfRadioButtonListItem loaded( + PdfDictionary dictionary, PdfCrossTable crossTable, PdfRadioButtonListField field) { return PdfRadioButtonListItem._loaded(dictionary, crossTable, field); } @@ -949,27 +883,24 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { void _setItemValue(String value) { final String str = value; if (dictionary!.containsKey(PdfDictionaryProperties.ap)) { - PdfDictionary dic = crossTable! - .getObject(dictionary![PdfDictionaryProperties.ap])! as PdfDictionary; + PdfDictionary dic = + crossTable!.getObject(dictionary![PdfDictionaryProperties.ap])! as PdfDictionary; if (dic.containsKey(PdfDictionaryProperties.n)) { - final PdfReference normal = - crossTable!.getReference(dic[PdfDictionaryProperties.n]); + final PdfReference normal = crossTable!.getReference(dic[PdfDictionaryProperties.n]); dic = crossTable!.getObject(normal)! as PdfDictionary; final String? dicValue = getItemValue(dictionary!, crossTable); if (dic.containsKey(dicValue)) { final PdfReference valRef = crossTable!.getReference(dic[dicValue]); dic.remove(base.value); - dic.setProperty( - str, PdfReferenceHolder.fromReference(valRef, crossTable)); + dic.setProperty(str, PdfReferenceHolder.fromReference(valRef, crossTable)); } } } if (str == _field!.selectedValue) { - dictionary! - .setName(PdfName(PdfDictionaryProperties.usageApplication), str); + dictionary!.setName(PdfName(PdfDictionaryProperties.usageApplication), str); } else { - dictionary!.setName(PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.off); + dictionary! + .setName(PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.off); } } @@ -992,8 +923,8 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { if ((_field!.selectedIndex >= 0) && (_field!.selectedValue == base.value)) { state = PdfCheckFieldState.checked; } - FieldPainter().drawRadioButton( - _field!.page!.graphics, params, styleToString(base.style), state); + FieldPainter() + .drawRadioButton(_field!.page!.graphics, params, styleToString(base.style), state); } /// internal method @@ -1008,15 +939,13 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { bounds = array.toRectangle().rect; double? y = 0; if ((PdfCrossTable.dereference(array[1])! as PdfNumber).value! < 0) { - y = (PdfCrossTable.dereference(array[1])! as PdfNumber).value - as double?; + y = (PdfCrossTable.dereference(array[1])! as PdfNumber).value as double?; if ((PdfCrossTable.dereference(array[1])! as PdfNumber).value! > (PdfCrossTable.dereference(array[3])! as PdfNumber).value!) { y = y! - bounds.height; } } - bounds = Rect.fromLTWH( - bounds.left, y! <= 0 ? bounds.top : y, bounds.width, bounds.height); + bounds = Rect.fromLTWH(bounds.left, y! <= 0 ? bounds.top : y, bounds.width, bounds.height); } else { bounds = Rect.zero; } @@ -1026,8 +955,7 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { /// internal method void drawCheckAppearance() { final PaintParams paintParams = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, widget!.bounds.size.width, widget!.bounds.size.height), + bounds: Rect.fromLTWH(0, 0, widget!.bounds.size.width, widget!.bounds.size.height), backBrush: PdfSolidBrush(base.backColor), foreBrush: PdfSolidBrush(base.foreColor), borderPen: borderPen, @@ -1036,19 +964,19 @@ class PdfRadioButtonListItemHelper extends PdfCheckFieldBaseHelper { shadowBrush: PdfSolidBrush(base.backColor)); PdfTemplate template = widget!.extendedAppearance!.normal.activate!; - FieldPainter().drawRadioButton(template.graphics, paintParams, - styleToString(base.style), PdfCheckFieldState.checked); + FieldPainter().drawRadioButton( + template.graphics, paintParams, styleToString(base.style), PdfCheckFieldState.checked); template = widget!.extendedAppearance!.normal.off!; - FieldPainter().drawRadioButton(template.graphics, paintParams, - styleToString(base.style), PdfCheckFieldState.unchecked); + FieldPainter().drawRadioButton( + template.graphics, paintParams, styleToString(base.style), PdfCheckFieldState.unchecked); template = widget!.extendedAppearance!.pressed.activate!; - FieldPainter().drawRadioButton(template.graphics, paintParams, - styleToString(base.style), PdfCheckFieldState.pressedChecked); + FieldPainter().drawRadioButton(template.graphics, paintParams, styleToString(base.style), + PdfCheckFieldState.pressedChecked); template = widget!.extendedAppearance!.pressed.off!; - FieldPainter().drawRadioButton(template.graphics, paintParams, - styleToString(base.style), PdfCheckFieldState.pressedUnchecked); + FieldPainter().drawRadioButton(template.graphics, paintParams, styleToString(base.style), + PdfCheckFieldState.pressedUnchecked); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_combo_box_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_combo_box_field.dart index b7897fdff..b055b7729 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_combo_box_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_combo_box_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -82,8 +82,7 @@ class PdfComboBoxField extends PdfListField { /// The default value is false. bool get editable { if (_helper.isLoadedField) { - _editable = _helper.isFlagPresent(FieldFlags.edit) || - _helper.flags.contains(FieldFlags.edit); + _editable = _helper.isFlagPresent(FieldFlags.edit) || _helper.flags.contains(FieldFlags.edit); } return _editable; } @@ -100,15 +99,13 @@ class PdfComboBoxField extends PdfListField { } /// Gets or sets the selected index in the list. - int get selectedIndex => - _helper.selectedIndexes.isEmpty ? -1 : _helper.selectedIndexes[0]; + int get selectedIndex => _helper.selectedIndexes.isEmpty ? -1 : _helper.selectedIndexes[0]; set selectedIndex(int value) { _helper.selectedIndexes = [value]; } /// Gets or sets the selected value in the list. - String get selectedValue => - _helper.selectedValues.isEmpty ? '' : _helper.selectedValues[0]; + String get selectedValue => _helper.selectedValues.isEmpty ? '' : _helper.selectedValues[0]; set selectedValue(String value) { _helper.selectedValues = [value]; } @@ -127,8 +124,7 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { PdfComboBoxField comboBoxField; /// internal method - static PdfComboBoxField loadComboBox( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfComboBoxField loadComboBox(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfComboBoxField._load(dictionary, crossTable); } @@ -142,8 +138,7 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { void drawAppearance(PdfTemplate template) { super.drawAppearance(template); final PaintParams params = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height), + bounds: Rect.fromLTWH(0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height), backBrush: backBrush, foreBrush: foreBrush, borderPen: borderPen, @@ -153,25 +148,19 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { FieldPainter().drawRectangularControl(template.graphics!, params); if (comboBoxField.selectedIndex != -1 && comboBoxField.items[comboBoxField.selectedIndex].text != '' && - PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(comboBoxField.page!).document!) + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(comboBoxField.page!).document!) .conformanceLevel == PdfConformanceLevel.none) { - final int multiplier = params.style == PdfBorderStyle.beveled || - params.style == PdfBorderStyle.inset - ? 2 - : 1; + final int multiplier = + params.style == PdfBorderStyle.beveled || params.style == PdfBorderStyle.inset ? 2 : 1; final Rect rectangle = Rect.fromLTWH( params.bounds!.left + (2 * multiplier) * params.borderWidth!, params.bounds!.top + (2 * multiplier) * params.borderWidth!, params.bounds!.width - (4 * multiplier) * params.borderWidth!, params.bounds!.height - (4 * multiplier) * params.borderWidth!); - template.graphics!.drawString( - comboBoxField.items[comboBoxField.selectedIndex].text, + template.graphics!.drawString(comboBoxField.items[comboBoxField.selectedIndex].text, comboBoxField.font ?? PdfStandardFont(PdfFontFamily.timesRoman, 12), - brush: params.foreBrush, - bounds: rectangle, - format: format); + brush: params.foreBrush, bounds: rectangle, format: format); } } @@ -185,25 +174,20 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { void _applyAppearance(PdfDictionary widget) { if (widget.containsKey(PdfDictionaryProperties.ap) && !PdfFormHelper.getHelper(comboBoxField.form!).needAppearances!) { - final IPdfPrimitive? appearance = - crossTable!.getObject(widget[PdfDictionaryProperties.ap]); + final IPdfPrimitive? appearance = crossTable!.getObject(widget[PdfDictionaryProperties.ap]); if ((appearance != null) && appearance is PdfDictionary && (appearance.containsKey(PdfDictionaryProperties.n))) { - final PdfTemplate template = PdfTemplate( - comboBoxField.bounds.width, comboBoxField.bounds.height); + final PdfTemplate template = + PdfTemplate(comboBoxField.bounds.width, comboBoxField.bounds.height); _drawComboBox(template.graphics); appearance.remove(PdfDictionaryProperties.n); - appearance.setProperty( - PdfDictionaryProperties.n, PdfReferenceHolder(template)); + appearance.setProperty(PdfDictionaryProperties.n, PdfReferenceHolder(template)); widget.setProperty(PdfDictionaryProperties.ap, appearance); } - } else if (comboBoxField.form!.readOnly == true || - comboBoxField.readOnly == true) { - PdfFormHelper.getHelper(comboBoxField.form!).setAppearanceDictionary = - true; - } else if (PdfFormHelper.getHelper(comboBoxField.form!) - .setAppearanceDictionary && + } else if (comboBoxField.form!.readOnly == true || comboBoxField.readOnly == true) { + PdfFormHelper.getHelper(comboBoxField.form!).setAppearanceDictionary = true; + } else if (PdfFormHelper.getHelper(comboBoxField.form!).setAppearanceDictionary && !PdfFormHelper.getHelper(comboBoxField.form!).needAppearances!) { final PdfDictionary dic = PdfDictionary(); final PdfTemplate template = @@ -218,16 +202,14 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { @override void draw() { super.draw(); - if (!isLoadedField && - PdfAnnotationHelper.getHelper(widget!).appearance != null) { - comboBoxField.page!.graphics.drawPdfTemplate( - widget!.appearance.normal, comboBoxField.bounds.topLeft); + if (!isLoadedField && PdfAnnotationHelper.getHelper(widget!).appearance != null) { + comboBoxField.page!.graphics + .drawPdfTemplate(widget!.appearance.normal, comboBoxField.bounds.topLeft); } else { - final Rect rect = Rect.fromLTWH( - 0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height); + final Rect rect = + Rect.fromLTWH(0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height); final PdfFont font = comboBoxField.font ?? - PdfStandardFont( - PdfFontFamily.helvetica, getFontHeight(PdfFontFamily.helvetica)); + PdfStandardFont(PdfFontFamily.helvetica, getFontHeight(PdfFontFamily.helvetica)); final PaintParams parameters = PaintParams( bounds: rect, backBrush: backBrush, @@ -252,11 +234,10 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { } } else if (dictionary!.containsKey(PdfDictionaryProperties.dv)) { if (dictionary![PdfDictionaryProperties.dv] is PdfString) { - text = - (dictionary![PdfDictionaryProperties.dv]! as PdfString).value; + text = (dictionary![PdfDictionaryProperties.dv]! as PdfString).value; } else { - final IPdfPrimitive? str = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.dv]); + final IPdfPrimitive? str = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.dv]); if (str != null && str is PdfString) { text = str.value; } @@ -267,20 +248,16 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { FieldPainter().drawRectangularControl(template.graphics!, parameters); final double borderWidth = parameters.borderWidth!.toDouble(); final double doubleBorderWidth = 2 * borderWidth; - final bool padding = parameters.style == PdfBorderStyle.inset || - parameters.style == PdfBorderStyle.beveled; + final bool padding = + parameters.style == PdfBorderStyle.inset || parameters.style == PdfBorderStyle.beveled; final Offset point = padding ? Offset(2 * doubleBorderWidth, 2 * borderWidth) : Offset(doubleBorderWidth, borderWidth); final double width = parameters.bounds!.width - doubleBorderWidth; - final Rect itemTextBound = Rect.fromLTWH( - point.dx, - point.dy, - width - point.dx, - parameters.bounds!.height - - (padding ? doubleBorderWidth : borderWidth)); - template.graphics!.drawString(text!, font, - brush: foreBrush, bounds: itemTextBound, format: format); + final Rect itemTextBound = Rect.fromLTWH(point.dx, point.dy, width - point.dx, + parameters.bounds!.height - (padding ? doubleBorderWidth : borderWidth)); + template.graphics! + .drawString(text!, font, brush: foreBrush, bounds: itemTextBound, format: format); comboBoxField.page!.graphics .drawPdfTemplate(template, comboBoxField.bounds.topLeft, rect.size); } else { @@ -296,16 +273,15 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { if (gp.font!.height > comboBoxField.bounds.height) { setFittingFontSize(gp, prms, text!); } - FieldPainter().drawComboBox( - comboBoxField.page!.graphics, prms, text, gp.font, gp.stringFormat); + FieldPainter() + .drawComboBox(comboBoxField.page!.graphics, prms, text, gp.font, gp.stringFormat); } } } void _drawComboBox(PdfGraphics? graphics) { final GraphicsProperties gp = GraphicsProperties(comboBoxField); - gp.bounds = Rect.fromLTWH( - 0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height); + gp.bounds = Rect.fromLTWH(0, 0, comboBoxField.bounds.width, comboBoxField.bounds.height); final PaintParams prms = PaintParams( bounds: gp.bounds, backBrush: gp.backBrush, @@ -315,12 +291,9 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { borderWidth: gp.borderWidth, shadowBrush: gp.shadowBrush); String? text; - if (selectedItems.count > 0 && - comboBoxField.selectedIndex != -1 && - !flattenField) { + if (selectedItems.count > 0 && comboBoxField.selectedIndex != -1 && !flattenField) { text = selectedItems[0].text; - } else if (dictionary!.containsKey(PdfDictionaryProperties.dv) && - !flattenField) { + } else if (dictionary!.containsKey(PdfDictionaryProperties.dv) && !flattenField) { final IPdfPrimitive? defaultValue = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.dv]); if (defaultValue != null && defaultValue is PdfString) { @@ -328,11 +301,10 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { } } if (selectedItems.count == 0) { - FieldPainter().drawComboBox(graphics!, prms, comboBoxField.selectedValue, - gp.font, gp.stringFormat); - } else if (text != null && !flattenField) { FieldPainter() - .drawComboBox(graphics!, prms, text, gp.font, gp.stringFormat); + .drawComboBox(graphics!, prms, comboBoxField.selectedValue, gp.font, gp.stringFormat); + } else if (text != null && !flattenField) { + FieldPainter().drawComboBox(graphics!, prms, text, gp.font, gp.stringFormat); } else { FieldPainter().drawRectangularControl(graphics!, prms); } @@ -345,23 +317,19 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { final List widths = []; if (comboBoxField.selectedIndex != -1) { final PdfFont itemFont = PdfStandardFont(family, 12); - widths - .add(itemFont.measureString(comboBoxField.selectedItem!.text).width); + widths.add(itemFont.measureString(comboBoxField.selectedItem!.text).width); } else { final PdfFont sfont = PdfStandardFont(family, 12); double max = sfont.measureString(comboBoxField.items[0].text).width; for (int i = 1; i < comboBoxField.items.count; ++i) { - final double value = - sfont.measureString(comboBoxField.items[i].text).width; + final double value = sfont.measureString(comboBoxField.items[i].text).width; max = (max > value) ? max : value; widths.add(max); } } widths.sort(); double s = widths.isNotEmpty - ? ((12 * - (comboBoxField.bounds.size.width - - 4 * comboBoxField.borderWidth)) / + ? ((12 * (comboBoxField.bounds.size.width - 4 * comboBoxField.borderWidth)) / widths[widths.length - 1]) : 12; if (comboBoxField.selectedIndex != -1) { @@ -370,22 +338,18 @@ class PdfComboBoxFieldHelper extends PdfListFieldHelper { final Size textSize = font.measureString(text); if (textSize.width > comboBoxField.bounds.width || textSize.height > comboBoxField.bounds.height) { - final double width = - comboBoxField.bounds.width - 4 * comboBoxField.borderWidth; - final double h = - comboBoxField.bounds.height - 4 * comboBoxField.borderWidth; + final double width = comboBoxField.bounds.width - 4 * comboBoxField.borderWidth; + final double h = comboBoxField.bounds.height - 4 * comboBoxField.borderWidth; const double minimumFontSize = 0.248; for (double i = 1; i <= comboBoxField.bounds.height; i++) { PdfFontHelper.getHelper(font).setSize(i); Size textSize = font.measureString(text); - if (textSize.width > comboBoxField.bounds.width || - textSize.height > h) { + if (textSize.width > comboBoxField.bounds.width || textSize.height > h) { fontSize = i; do { fontSize = fontSize - 0.001; PdfFontHelper.getHelper(font).setSize(fontSize); - final double textWidth = - PdfFontHelper.getLineWidth(font, text, format); + final double textWidth = PdfFontHelper.getLineWidth(font, text, format); if (fontSize < minimumFontSize) { PdfFontHelper.getHelper(font).setSize(minimumFontSize); break; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field.dart index 745dd080c..9f8a39700 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import 'package:xml/xml.dart'; import '../../interfaces/pdf_interface.dart'; @@ -84,8 +84,7 @@ abstract class PdfField implements IPdfWrapper { this.bounds = bounds; if (name != null) { _fieldHelper.name = name; - _fieldHelper.dictionary! - .setProperty(PdfDictionaryProperties.t, PdfString(name)); + _fieldHelper.dictionary!.setProperty(PdfDictionaryProperties.t, PdfString(name)); } if (font != null) { _fieldHelper.font = font; @@ -120,8 +119,7 @@ abstract class PdfField implements IPdfWrapper { } /// internal constructor - void _load(PdfDictionary dictionary, PdfCrossTable crossTable, - PdfFieldHelper helper) { + void _load(PdfDictionary dictionary, PdfCrossTable crossTable, PdfFieldHelper helper) { _fieldHelper = helper; _fieldHelper.dictionary = dictionary; _fieldHelper.crossTable = crossTable; @@ -147,8 +145,7 @@ abstract class PdfField implements IPdfWrapper { } else if (_fieldHelper.page != null && PdfPageHelper.getHelper(_fieldHelper.page!).isLoadedPage && _fieldHelper.changed || - (_fieldHelper.form != null && - PdfFormHelper.getHelper(_fieldHelper.form!).flatten) || + (_fieldHelper.form != null && PdfFormHelper.getHelper(_fieldHelper.form!).flatten) || _fieldHelper.flattenField) { _fieldHelper.page = _getLoadedPage(); } @@ -157,8 +154,7 @@ abstract class PdfField implements IPdfWrapper { /// Gets or sets the name of the [PdfField]. String? get name { - if (_fieldHelper.isLoadedField && - (_fieldHelper.name == null || _fieldHelper.name!.isEmpty)) { + if (_fieldHelper.isLoadedField && (_fieldHelper.name == null || _fieldHelper.name!.isEmpty)) { _fieldHelper.name = _getFieldName(); } return _fieldHelper.name; @@ -189,13 +185,9 @@ abstract class PdfField implements IPdfWrapper { /// Gets or sets the mapping name to be used when exporting interactive form /// field data from the document. String get mappingName { - if (_fieldHelper.isLoadedField && - (_mappingName == null || _mappingName!.isEmpty)) { + if (_fieldHelper.isLoadedField && (_mappingName == null || _mappingName!.isEmpty)) { final IPdfPrimitive? str = PdfFieldHelper.getValue( - _fieldHelper.dictionary!, - _fieldHelper.crossTable, - PdfDictionaryProperties.tm, - false); + _fieldHelper.dictionary!, _fieldHelper.crossTable, PdfDictionaryProperties.tm, false); if (str != null && str is PdfString) { _mappingName = str.value; } @@ -206,8 +198,7 @@ abstract class PdfField implements IPdfWrapper { set mappingName(String value) { if (_mappingName != value) { _mappingName = value; - _fieldHelper.dictionary! - .setString(PdfDictionaryProperties.tm, _mappingName); + _fieldHelper.dictionary!.setString(PdfDictionaryProperties.tm, _mappingName); } if (_fieldHelper.isLoadedField) { _fieldHelper.changed = true; @@ -218,10 +209,7 @@ abstract class PdfField implements IPdfWrapper { String get tooltip { if (_fieldHelper.isLoadedField && (_tooltip == null || _tooltip!.isEmpty)) { final IPdfPrimitive? str = PdfFieldHelper.getValue( - _fieldHelper.dictionary!, - _fieldHelper.crossTable, - PdfDictionaryProperties.tu, - false); + _fieldHelper.dictionary!, _fieldHelper.crossTable, PdfDictionaryProperties.tu, false); if (str != null && str is PdfString) { _tooltip = str.value; } @@ -268,16 +256,14 @@ abstract class PdfField implements IPdfWrapper { double x = 0; double y = 0; if (page != null) { - final PdfDictionary dictionary = - PdfPageHelper.getHelper(page!).dictionary!; + final PdfDictionary dictionary = PdfPageHelper.getHelper(page!).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.cropBox)) { PdfArray? cropBox; if (dictionary[PdfDictionaryProperties.cropBox] is PdfArray) { cropBox = dictionary[PdfDictionaryProperties.cropBox] as PdfArray?; } else { final PdfReferenceHolder cropBoxHolder = - dictionary[PdfDictionaryProperties.cropBox]! - as PdfReferenceHolder; + dictionary[PdfDictionaryProperties.cropBox]! as PdfReferenceHolder; cropBox = cropBoxHolder.object as PdfArray?; } if ((cropBox![0]! as PdfNumber).value != 0 || @@ -291,10 +277,9 @@ abstract class PdfField implements IPdfWrapper { } } else if (dictionary.containsKey(PdfDictionaryProperties.mediaBox)) { PdfArray? mediaBox; - if (PdfCrossTable.dereference( - dictionary[PdfDictionaryProperties.mediaBox]) is PdfArray) { - mediaBox = PdfCrossTable.dereference( - dictionary[PdfDictionaryProperties.mediaBox]) as PdfArray?; + if (PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.mediaBox]) is PdfArray) { + mediaBox = PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.mediaBox]) + as PdfArray?; } if ((mediaBox![0]! as PdfNumber).value! > 0 || (mediaBox[1]! as PdfNumber).value! > 0 || @@ -311,8 +296,7 @@ abstract class PdfField implements IPdfWrapper { } else { y = rect.top + rect.height; } - return Rect.fromLTWH(x == 0 ? rect.left : x, y == 0 ? rect.top : y, - rect.width, rect.height); + return Rect.fromLTWH(x == 0 ? rect.left : x, y == 0 ? rect.top : y, rect.width, rect.height); } else { return _fieldHelper.widget!.bounds; } @@ -333,8 +317,7 @@ abstract class PdfField implements IPdfWrapper { ]; PdfDictionary dic = _fieldHelper.dictionary!; if (!dic.containsKey(PdfDictionaryProperties.rect)) { - dic = _fieldHelper.getWidgetAnnotation( - _fieldHelper.dictionary!, _fieldHelper.crossTable); + dic = _fieldHelper.getWidgetAnnotation(_fieldHelper.dictionary!, _fieldHelper.crossTable); } dic.setArray(PdfDictionaryProperties.rect, values); _fieldHelper.changed = true; @@ -349,12 +332,11 @@ abstract class PdfField implements IPdfWrapper { int get tabIndex { if (_fieldHelper.isLoadedField) { if (page != null) { - final PdfDictionary annotDic = _fieldHelper.getWidgetAnnotation( - _fieldHelper.dictionary!, _fieldHelper.crossTable); + final PdfDictionary annotDic = + _fieldHelper.getWidgetAnnotation(_fieldHelper.dictionary!, _fieldHelper.crossTable); final PdfReference reference = PdfPageHelper.getHelper(page!).crossTable!.getReference(annotDic); - _tabIndex = - PdfPageHelper.getHelper(page!).annotsReference.indexOf(reference); + _tabIndex = PdfPageHelper.getHelper(page!).annotsReference.indexOf(reference); } } return _tabIndex; @@ -365,19 +347,17 @@ abstract class PdfField implements IPdfWrapper { if (_fieldHelper.isLoadedField && page != null && page!.formFieldsTabOrder == PdfFormFieldsTabOrder.manual) { - final PdfAnnotation annotationReference = WidgetAnnotationHelper.load( - _fieldHelper.dictionary!, _fieldHelper.crossTable!); + final PdfAnnotation annotationReference = + WidgetAnnotationHelper.load(_fieldHelper.dictionary!, _fieldHelper.crossTable!); final PdfReference reference = PdfPageHelper.getHelper(page!) .crossTable! .getReference(IPdfWrapper.getElement(annotationReference)); - int index = - PdfPageHelper.getHelper(page!).annotsReference.indexOf(reference); + int index = PdfPageHelper.getHelper(page!).annotsReference.indexOf(reference); if (index < 0) { index = _fieldHelper.annotationIndex; } - final PdfArray? annots = - PdfAnnotationCollectionHelper.getHelper(page!.annotations) - .rearrange(reference, _tabIndex, index); + final PdfArray? annots = PdfAnnotationCollectionHelper.getHelper(page!.annotations) + .rearrange(reference, _tabIndex, index); PdfPageHelper.getHelper(page!) .dictionary! .setProperty(PdfDictionaryProperties.annots, annots); @@ -392,28 +372,24 @@ abstract class PdfField implements IPdfWrapper { //Implementations void _initialize() { - _fieldHelper.dictionary!.beginSave = this is PdfSignatureField - ? _fieldHelper.dictionaryBeginSave - : _dictBeginSave; + _fieldHelper.dictionary!.beginSave = + this is PdfSignatureField ? _fieldHelper.dictionaryBeginSave : _dictBeginSave; _fieldHelper.widget = WidgetAnnotation(); if (this is PdfSignatureField && form!.fieldAutoNaming) { _fieldHelper._createBorderPen(); _fieldHelper._createBackBrush(); - _fieldHelper.dictionary = - PdfAnnotationHelper.getHelper(_fieldHelper.widget!).dictionary; + _fieldHelper.dictionary = PdfAnnotationHelper.getHelper(_fieldHelper.widget!).dictionary; } else { _fieldHelper.widget!.parent = this; if (this is! PdfSignatureField) { _fieldHelper.format = PdfStringFormat( - alignment: _fieldHelper.widget!.alignment!, - lineAlignment: PdfVerticalAlignment.middle); + alignment: _fieldHelper.widget!.alignment!, lineAlignment: PdfVerticalAlignment.middle); _fieldHelper._createBorderPen(); _fieldHelper._createBackBrush(); } final PdfArray array = PdfArray(); array.add(PdfReferenceHolder(_fieldHelper.widget)); - _fieldHelper.dictionary! - .setProperty(PdfDictionaryProperties.kids, PdfArray(array)); + _fieldHelper.dictionary!.setProperty(PdfDictionaryProperties.kids, PdfArray(array)); } _fieldHelper.widget!.defaultAppearance.fontName = 'TiRo'; } @@ -427,49 +403,38 @@ abstract class PdfField implements IPdfWrapper { PdfString? str; if (!_fieldHelper.dictionary!.containsKey(PdfDictionaryProperties.parent)) { str = PdfFieldHelper.getValue( - _fieldHelper.dictionary!, - _fieldHelper.crossTable, - PdfDictionaryProperties.t, - false) as PdfString?; + _fieldHelper.dictionary!, _fieldHelper.crossTable, PdfDictionaryProperties.t, false) + as PdfString?; } else { IPdfPrimitive? dic = _fieldHelper.crossTable! .getObject(_fieldHelper.dictionary![PdfDictionaryProperties.parent]); - while (dic != null && - dic is PdfDictionary && - dic.containsKey(PdfDictionaryProperties.parent)) { + while ( + dic != null && dic is PdfDictionary && dic.containsKey(PdfDictionaryProperties.parent)) { if (dic.containsKey(PdfDictionaryProperties.t)) { name = name == null - ? (PdfFieldHelper.getValue(dic, _fieldHelper.crossTable, - PdfDictionaryProperties.t, false)! as PdfString) + ? (PdfFieldHelper.getValue( + dic, _fieldHelper.crossTable, PdfDictionaryProperties.t, false)! as PdfString) .value : '${(PdfFieldHelper.getValue(dic, _fieldHelper.crossTable, PdfDictionaryProperties.t, false)! as PdfString).value!}.$name'; } - dic = _fieldHelper.crossTable! - .getObject(dic[PdfDictionaryProperties.parent]) as PdfDictionary?; + dic = _fieldHelper.crossTable!.getObject(dic[PdfDictionaryProperties.parent]) + as PdfDictionary?; } - if (dic != null && - dic is PdfDictionary && - dic.containsKey(PdfDictionaryProperties.t)) { + if (dic != null && dic is PdfDictionary && dic.containsKey(PdfDictionaryProperties.t)) { name = name == null - ? (PdfFieldHelper.getValue(dic, _fieldHelper.crossTable, - PdfDictionaryProperties.t, false)! as PdfString) + ? (PdfFieldHelper.getValue( + dic, _fieldHelper.crossTable, PdfDictionaryProperties.t, false)! as PdfString) .value : '${(PdfFieldHelper.getValue(dic, _fieldHelper.crossTable, PdfDictionaryProperties.t, false)! as PdfString).value!}.$name'; final IPdfPrimitive? strName = PdfFieldHelper.getValue( - _fieldHelper.dictionary!, - _fieldHelper.crossTable, - PdfDictionaryProperties.t, - false); + _fieldHelper.dictionary!, _fieldHelper.crossTable, PdfDictionaryProperties.t, false); if (strName != null && strName is PdfString) { name = '${name!}.${strName.value!}'; } - } else if (_fieldHelper.dictionary! - .containsKey(PdfDictionaryProperties.t)) { + } else if (_fieldHelper.dictionary!.containsKey(PdfDictionaryProperties.t)) { str = PdfFieldHelper.getValue( - _fieldHelper.dictionary!, - _fieldHelper.crossTable, - PdfDictionaryProperties.t, - false) as PdfString?; + _fieldHelper.dictionary!, _fieldHelper.crossTable, PdfDictionaryProperties.t, false) + as PdfString?; } } if (str != null) { @@ -481,42 +446,34 @@ abstract class PdfField implements IPdfWrapper { PdfPage? _getLoadedPage() { PdfPage? page = _fieldHelper.page; if (page == null || - (PdfPageHelper.getHelper(page).isLoadedPage) && - _fieldHelper.crossTable != null) { + (PdfPageHelper.getHelper(page).isLoadedPage) && _fieldHelper.crossTable != null) { final PdfDocument? doc = _fieldHelper.crossTable!.document; - final PdfDictionary widget = _fieldHelper.getWidgetAnnotation( - _fieldHelper.dictionary!, _fieldHelper.crossTable); + final PdfDictionary widget = + _fieldHelper.getWidgetAnnotation(_fieldHelper.dictionary!, _fieldHelper.crossTable); if (widget.containsKey(PdfDictionaryProperties.p) && - PdfCrossTable.dereference(widget[PdfDictionaryProperties.p]) - is! PdfNull) { - final IPdfPrimitive? pageRef = _fieldHelper.crossTable! - .getObject(widget[PdfDictionaryProperties.p]); + PdfCrossTable.dereference(widget[PdfDictionaryProperties.p]) is! PdfNull) { + final IPdfPrimitive? pageRef = + _fieldHelper.crossTable!.getObject(widget[PdfDictionaryProperties.p]); if (pageRef != null && pageRef is PdfDictionary) { page = PdfPageCollectionHelper.getHelper(doc!.pages).getPage(pageRef); } } else { - final PdfReference widgetReference = - _fieldHelper.crossTable!.getReference(widget); + final PdfReference widgetReference = _fieldHelper.crossTable!.getReference(widget); for (int j = 0; j < doc!.pages.count; j++) { final PdfPage loadedPage = doc.pages[j]; - final PdfArray? lAnnots = - PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); + final PdfArray? lAnnots = PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); if (lAnnots != null) { for (int i = 0; i < lAnnots.count; i++) { final IPdfPrimitive? holder = lAnnots[i]; - if (holder != null && - holder is PdfReferenceHolder && - holder.reference != null) { + if (holder != null && holder is PdfReferenceHolder && holder.reference != null) { if (holder.reference!.objNum == widgetReference.objNum && holder.reference!.genNum == widgetReference.genNum) { page = loadedPage; return page; } else if (_fieldHelper.requiredReference != null && _fieldHelper.requiredReference!.reference != null && - _fieldHelper.requiredReference!.reference!.objNum == - holder.reference!.objNum && - _fieldHelper.requiredReference!.reference!.genNum == - holder.reference!.genNum) { + _fieldHelper.requiredReference!.reference!.objNum == holder.reference!.objNum && + _fieldHelper.requiredReference!.reference!.genNum == holder.reference!.genNum) { page = loadedPage; return page; } @@ -527,17 +484,13 @@ abstract class PdfField implements IPdfWrapper { } } if (page != null && - PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.tabs)) { + PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.tabs)) { final IPdfPrimitive? tabName = PdfCrossTable.dereference( - PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.tabs]); + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.tabs]); if (tabName != null && ((tabName is PdfName && tabName.name == '') || (tabName is PdfString && tabName.value == ''))) { - PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.tabs] = PdfName(' '); + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.tabs] = PdfName(' '); } } return page; @@ -545,8 +498,9 @@ abstract class PdfField implements IPdfWrapper { void _addAnnotationToPage(PdfPage? page, PdfAnnotation? widget) { if (page != null && !PdfPageHelper.getHelper(page).isLoadedPage) { - PdfAnnotationHelper.getHelper(widget!).dictionary!.setProperty( - PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)); + PdfAnnotationHelper.getHelper(widget!) + .dictionary! + .setProperty(PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)); } else { final PdfDictionary pageDic = PdfPageHelper.getHelper(page!).dictionary!; PdfArray? annots; @@ -563,23 +517,20 @@ abstract class PdfField implements IPdfWrapper { .dictionary! .setProperty(PdfDictionaryProperties.p, PdfReferenceHolder(page)); form!.fieldAutoNaming - ? PdfAnnotationHelper.getHelper(widget).dictionary!.setProperty( - PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)) - : _fieldHelper.dictionary!.setProperty( - PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)); + ? PdfAnnotationHelper.getHelper(widget) + .dictionary! + .setProperty(PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)) + : _fieldHelper.dictionary! + .setProperty(PdfDictionaryProperties.t, PdfString(_fieldHelper.name!)); annots.add(PdfReferenceHolder(widget)); - PdfPageHelper.getHelper(page) - .dictionary! - .setProperty(PdfDictionaryProperties.annots, annots); + PdfPageHelper.getHelper(page).dictionary!.setProperty(PdfDictionaryProperties.annots, annots); } } - List _getWidgetAnnotations( - PdfDictionary dictionary, PdfCrossTable crossTable) { + List _getWidgetAnnotations(PdfDictionary dictionary, PdfCrossTable crossTable) { final List widgetAnnotationCollection = []; if (dictionary.containsKey(PdfDictionaryProperties.kids)) { - final IPdfPrimitive? array = - crossTable.getObject(dictionary[PdfDictionaryProperties.kids]); + final IPdfPrimitive? array = crossTable.getObject(dictionary[PdfDictionaryProperties.kids]); if (array != null && array is PdfArray && array.count > 0) { for (int i = 0; i < array.count; i++) { final IPdfPrimitive item = array[i]!; @@ -591,11 +542,8 @@ abstract class PdfField implements IPdfWrapper { } } } else if (dictionary.containsKey(PdfDictionaryProperties.subtype)) { - final IPdfPrimitive? type = - crossTable.getObject(dictionary[PdfDictionaryProperties.subtype]); - if (type != null && - type is PdfName && - type.name == PdfDictionaryProperties.widget) { + final IPdfPrimitive? type = crossTable.getObject(dictionary[PdfDictionaryProperties.subtype]); + if (type != null && type is PdfName && type.name == PdfDictionaryProperties.widget) { widgetAnnotationCollection.add(dictionary); } } @@ -756,27 +704,22 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfColor bc = PdfColor.empty; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final IPdfPrimitive? getObject = - crossTable!.getObject(widget[PdfDictionaryProperties.mk]); + final IPdfPrimitive? getObject = crossTable!.getObject(widget[PdfDictionaryProperties.mk]); if (getObject != null && getObject is PdfDictionary && getObject.containsKey(PdfDictionaryProperties.bc)) { - final PdfArray array = - getObject[PdfDictionaryProperties.bc]! as PdfArray; + final PdfArray array = getObject[PdfDictionaryProperties.bc]! as PdfArray; bc = _createColor(array); } } return bc; } else { - return WidgetAnnotationHelper.getHelper(widget!) - .widgetAppearance! - .borderColor; + return WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor; } } set borderColor(PdfColor value) { - WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor = - value; + WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor = value; if (isLoadedField) { PdfFormHelper.getHelper(field.form!).setAppearanceDictionary = true; assignBorderColor(value); @@ -801,16 +744,14 @@ class PdfFieldHelper { fieldChanged = true; } } else { - WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.backColor = - value; + WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.backColor = value; _createBackBrush(); } } //Creates the back brush. void _createBackBrush() { - final PdfColor bc = - WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.backColor; + final PdfColor bc = WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.backColor; backBrush = PdfSolidBrush(bc); final PdfColor color = PdfColor(bc.r, bc.g, bc.b); color.r = (color.r - 64 >= 0 ? color.r - 64 : 0).toUnsigned(8); @@ -825,12 +766,12 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfColor color = PdfColor(0, 0, 0); if (widget.containsKey(PdfDictionaryProperties.da)) { - final PdfString defaultAppearance = crossTable! - .getObject(widget[PdfDictionaryProperties.da])! as PdfString; + final PdfString defaultAppearance = + crossTable!.getObject(widget[PdfDictionaryProperties.da])! as PdfString; color = _getForeColor(defaultAppearance.value); } else { - final IPdfPrimitive? defaultAppearance = widget.getValue( - PdfDictionaryProperties.da, PdfDictionaryProperties.parent); + final IPdfPrimitive? defaultAppearance = + widget.getValue(PdfDictionaryProperties.da, PdfDictionaryProperties.parent); if (defaultAppearance != null && defaultAppearance is PdfString) { color = _getForeColor(defaultAppearance.value); } @@ -852,8 +793,7 @@ class PdfFieldHelper { name = fontName['name'] as String?; height = fontName['height'] as double?; } else if (dictionary!.containsKey(PdfDictionaryProperties.da)) { - final PdfString str = - dictionary![PdfDictionaryProperties.da]! as PdfString; + final PdfString str = dictionary![PdfDictionaryProperties.da]! as PdfString; final dynamic fontName = _fontName(str.value!); name = fontName['name'] as String?; height = fontName['height'] as double?; @@ -863,29 +803,23 @@ class PdfFieldHelper { defaultAppearance.fontName = name; defaultAppearance.fontSize = height; defaultAppearance.foreColor = value; - widget[PdfDictionaryProperties.da] = - PdfString(defaultAppearance.getString()); + widget[PdfDictionaryProperties.da] = PdfString(defaultAppearance.getString()); } else if (font != null) { final PdfDefaultAppearance defaultAppearance = PdfDefaultAppearance(); defaultAppearance.fontName = font!.name; defaultAppearance.fontSize = font!.size; defaultAppearance.foreColor = value; - widget[PdfDictionaryProperties.da] = - PdfString(defaultAppearance.getString()); + widget[PdfDictionaryProperties.da] = PdfString(defaultAppearance.getString()); } PdfFormHelper.getHelper(field.form!).setAppearanceDictionary = true; } else { - WidgetAnnotationHelper.getHelper(widget!) - .pdfDefaultAppearance! - .foreColor = value; + WidgetAnnotationHelper.getHelper(widget!).pdfDefaultAppearance!.foreColor = value; foreBrush = PdfSolidBrush(value); } } /// Gets or sets the width of the border. - int get borderWidth => isLoadedField - ? _obtainBorderWidth() - : widget!.widgetBorder!.width.toInt(); + int get borderWidth => isLoadedField ? _obtainBorderWidth() : widget!.widgetBorder!.width.toInt(); set borderWidth(int value) { if (widget!.widgetBorder!.width != value) { widget!.widgetBorder!.width = value.toDouble(); @@ -893,9 +827,8 @@ class PdfFieldHelper { _assignBorderWidth(value); } else { value == 0 - ? WidgetAnnotationHelper.getHelper(widget!) - .widgetAppearance! - .borderColor = PdfColor(255, 255, 255) + ? WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor = + PdfColor(255, 255, 255) : _createBorderPen(); } } @@ -904,9 +837,8 @@ class PdfFieldHelper { /// Gets or sets the highlighting mode. PdfHighlightMode get highlightMode => isLoadedField ? _obtainHighlightMode() : widget!.highlightMode!; - set highlightMode(PdfHighlightMode value) => isLoadedField - ? _assignHighlightMode(value) - : widget!.highlightMode = value; + set highlightMode(PdfHighlightMode value) => + isLoadedField ? _assignHighlightMode(value) : widget!.highlightMode = value; /// Gets or sets the border style. PdfBorderStyle get borderStyle => @@ -928,8 +860,8 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfBorderStyle style = PdfBorderStyle.solid; if (widget.containsKey(PdfDictionaryProperties.bs)) { - final PdfDictionary bs = crossTable! - .getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; + final PdfDictionary bs = + crossTable!.getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; style = _createBorderStyle(bs); } return style; @@ -938,8 +870,7 @@ class PdfFieldHelper { PdfBorderStyle _createBorderStyle(PdfDictionary bs) { PdfBorderStyle style = PdfBorderStyle.solid; if (bs.containsKey(PdfDictionaryProperties.s)) { - final IPdfPrimitive? name = - crossTable!.getObject(bs[PdfDictionaryProperties.s]); + final IPdfPrimitive? name = crossTable!.getObject(bs[PdfDictionaryProperties.s]); if (name != null && name is PdfName) { switch (name.name!.toLowerCase()) { case 'd': @@ -973,8 +904,7 @@ class PdfFieldHelper { dictionary!.containsKey(PdfDictionaryProperties.da)) { IPdfPrimitive? defaultAppearance = crossTable!.getObject(widget[PdfDictionaryProperties.da]); - defaultAppearance ??= - crossTable!.getObject(dictionary![PdfDictionaryProperties.da]); + defaultAppearance ??= crossTable!.getObject(dictionary![PdfDictionaryProperties.da]); String? fontName; if (defaultAppearance != null && defaultAppearance is PdfString) { final Map value = _getFont(defaultAppearance.value!); @@ -982,10 +912,8 @@ class PdfFieldHelper { isCorrectFont = value['isCorrectFont'] as bool?; fontName = value['fontName'] as String?; if (!isCorrectFont! && fontName != null) { - widget.setProperty( - PdfDictionaryProperties.da, - PdfString( - defaultAppearance.value!.replaceAll(fontName, '/Helv'))); + widget.setProperty(PdfDictionaryProperties.da, + PdfString(defaultAppearance.value!.replaceAll(fontName, '/Helv'))); } } } @@ -1006,21 +934,17 @@ class PdfFieldHelper { defaultAppearance.fontSize = _internalFont!.size; defaultAppearance.foreColor = foreColor; final IPdfPrimitive? fontDictionary = PdfCrossTable.dereference( - PdfFormHelper.getHelper(form!) - .resources[PdfDictionaryProperties.font]); + PdfFormHelper.getHelper(form!).resources[PdfDictionaryProperties.font]); if (fontDictionary != null && fontDictionary is PdfDictionary && !fontDictionary.containsKey(defaultAppearance.fontName)) { final IPdfWrapper fontWrapper = _internalFont!; - final PdfDictionary? fontElement = - IPdfWrapper.getElement(fontWrapper) as PdfDictionary?; + final PdfDictionary? fontElement = IPdfWrapper.getElement(fontWrapper) as PdfDictionary?; fontDictionary.items![PdfName(defaultAppearance.fontName)] = PdfReferenceHolder(fontElement); } - final PdfDictionary widget = - getWidgetAnnotation(dictionary!, crossTable); - widget[PdfDictionaryProperties.da] = - PdfString(defaultAppearance.getString()); + final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); + widget[PdfDictionaryProperties.da] = PdfString(defaultAppearance.getString()); } else { _defineDefaultAppearance(); } @@ -1028,8 +952,7 @@ class PdfFieldHelper { } /// Gets or sets the text alignment. - PdfTextAlignment get textAlignment => - isLoadedField ? format!.alignment : widget!.textAlignment!; + PdfTextAlignment get textAlignment => isLoadedField ? format!.alignment : widget!.textAlignment!; set textAlignment(PdfTextAlignment value) { if (isLoadedField) { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); @@ -1037,8 +960,7 @@ class PdfFieldHelper { changed = true; } else if (widget!.textAlignment != value) { widget!.textAlignment = value; - format = PdfStringFormat( - alignment: value, lineAlignment: PdfVerticalAlignment.middle); + format = PdfStringFormat(alignment: value, lineAlignment: PdfVerticalAlignment.middle); } } @@ -1096,8 +1018,7 @@ class PdfFieldHelper { } /// internal property - PdfStringFormat? get format => - isLoadedField ? _assignStringFormat() : stringFormat; + PdfStringFormat? get format => isLoadedField ? _assignStringFormat() : stringFormat; set format(PdfStringFormat? value) => stringFormat = value; /// internal property @@ -1106,8 +1027,7 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfColor c = PdfColor.empty; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final IPdfPrimitive? bs = - crossTable!.getObject(widget[PdfDictionaryProperties.mk]); + final IPdfPrimitive? bs = crossTable!.getObject(widget[PdfDictionaryProperties.mk]); if (bs is PdfDictionary) { IPdfPrimitive? array; if (bs.containsKey(PdfDictionaryProperties.bg)) { @@ -1169,8 +1089,7 @@ class PdfFieldHelper { void setFlags(List value) { int flagValue = isLoadedField ? this.flagValue : 0; // ignore: avoid_function_literals_in_foreach_calls - value.forEach( - (FieldFlags element) => flagValue |= _getFieldFlagsValue(element)); + value.forEach((FieldFlags element) => flagValue |= _getFieldFlagsValue(element)); flagValues = flagValue; dictionary!.setNumber(PdfDictionaryProperties.fieldFlags, flagValues); } @@ -1182,45 +1101,38 @@ class PdfFieldHelper { /// internal method int getFlagValue() { - final IPdfPrimitive? number = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.fieldFlags, true); + final IPdfPrimitive? number = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.fieldFlags, true); return number != null && number is PdfNumber ? number.value!.toInt() : 0; } void _defineDefaultAppearance() { if (field.form != null && _internalFont != null) { if (isLoadedField) { - final PdfDictionary widget = - getWidgetAnnotation(dictionary!, crossTable); - final PdfName name = - PdfFormHelper.getHelper(form!).resources.getName(font!); + final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); + final PdfName name = PdfFormHelper.getHelper(form!).resources.getName(font!); PdfFormHelper.getHelper(form!).resources.add(_internalFont, name); PdfFormHelper.getHelper(form!).needAppearances = true; final PdfDefaultAppearance defaultAppearance = PdfDefaultAppearance(); defaultAppearance.fontName = name.name; defaultAppearance.fontSize = _internalFont!.size; defaultAppearance.foreColor = foreColor; - widget[PdfDictionaryProperties.da] = - PdfString(defaultAppearance.getString()); + widget[PdfDictionaryProperties.da] = PdfString(defaultAppearance.getString()); if (field is PdfRadioButtonListField) { - final PdfRadioButtonListField radioButtonListField = - field as PdfRadioButtonListField; + final PdfRadioButtonListField radioButtonListField = field as PdfRadioButtonListField; for (int i = 0; i < radioButtonListField.items.count; i++) { final PdfRadioButtonListItem item = radioButtonListField.items[i]; if (PdfFieldHelper.getHelper(item).font != null) { PdfFormHelper.getHelper(field.form!).resources.add( PdfFieldHelper.getHelper(radioButtonListField.items[i]).font, - PdfName(WidgetAnnotationHelper.getHelper( - PdfFieldHelper.getHelper(item).widget!) + PdfName(WidgetAnnotationHelper.getHelper(PdfFieldHelper.getHelper(item).widget!) .pdfDefaultAppearance! .fontName)); } } } } else { - final PdfName name = PdfFormHelper.getHelper(field.form!) - .resources - .getName(_internalFont!); + final PdfName name = PdfFormHelper.getHelper(field.form!).resources.getName(_internalFont!); widget!.defaultAppearance.fontName = name.name; widget!.defaultAppearance.fontSize = _internalFont!.size; } @@ -1265,15 +1177,12 @@ class PdfFieldHelper { } /// Gets the widget annotation. - PdfDictionary getWidgetAnnotation( - PdfDictionary dictionary, PdfCrossTable? crossTable) { + PdfDictionary getWidgetAnnotation(PdfDictionary dictionary, PdfCrossTable? crossTable) { PdfDictionary? dic; if (dictionary.containsKey(PdfDictionaryProperties.kids)) { - final IPdfPrimitive? array = - crossTable!.getObject(dictionary[PdfDictionaryProperties.kids]); + final IPdfPrimitive? array = crossTable!.getObject(dictionary[PdfDictionaryProperties.kids]); if (array is PdfArray && array.count > 0) { - final IPdfPrimitive reference = - crossTable.getReference(array[defaultIndex]); + final IPdfPrimitive reference = crossTable.getReference(array[defaultIndex]); if (reference is PdfReference) { dic = crossTable.getObject(reference) as PdfDictionary?; } @@ -1288,19 +1197,15 @@ class PdfFieldHelper { if ((font is PdfStandardFont || font is PdfCjkStandardFont) && page != null && PdfPageHelper.getHelper(page!).document != null && - PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!) - .conformanceLevel != + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel != PdfConformanceLevel.none) { throw ArgumentError( 'All the fonts must be embedded in ${PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel} document.'); } else if (font is PdfTrueTypeFont && PdfPageHelper.getHelper(page!).document != null && - PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!) - .conformanceLevel == + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel == PdfConformanceLevel.a1b) { - PdfTrueTypeFontHelper.getHelper(font! as PdfTrueTypeFont) - .fontInternal - .initializeCidSet(); + PdfTrueTypeFontHelper.getHelper(font! as PdfTrueTypeFont).fontInternal.initializeCidSet(); } } } @@ -1316,9 +1221,8 @@ class PdfFieldHelper { final String? name = fontNameDic['name'] as String?; double height = fontNameDic['height'] as double; PdfFont font = PdfStandardFont(PdfFontFamily.helvetica, height); - IPdfPrimitive? fontDictionary = crossTable!.getObject( - PdfFormHelper.getHelper(field.form!) - .resources[PdfDictionaryProperties.font]); + IPdfPrimitive? fontDictionary = crossTable! + .getObject(PdfFormHelper.getHelper(field.form!).resources[PdfDictionaryProperties.font]); if (height == 0) { if (font is PdfStandardFont) { height = getFontHeight(font.fontFamily); @@ -1336,19 +1240,14 @@ class PdfFieldHelper { if (fontDictionary != null && fontDictionary is PdfDictionary && fontDictionary.containsKey(PdfDictionaryProperties.subtype)) { - final PdfName fontSubtype = crossTable! - .getObject(fontDictionary[PdfDictionaryProperties.subtype])! - as PdfName; + final PdfName fontSubtype = + crossTable!.getObject(fontDictionary[PdfDictionaryProperties.subtype])! as PdfName; if (fontSubtype.name == PdfDictionaryProperties.type1) { - final PdfName baseFont = crossTable! - .getObject(fontDictionary[PdfDictionaryProperties.baseFont])! - as PdfName; - final List fontStyle = - _getFontStyle(PdfName.decodeName(baseFont.name)!); - final dynamic fontFamilyDic = - _getFontFamily(PdfName.decodeName(baseFont.name)!); - final PdfFontFamily? fontFamily = - fontFamilyDic['fontFamily'] as PdfFontFamily?; + final PdfName baseFont = + crossTable!.getObject(fontDictionary[PdfDictionaryProperties.baseFont])! as PdfName; + final List fontStyle = _getFontStyle(PdfName.decodeName(baseFont.name)!); + final dynamic fontFamilyDic = _getFontFamily(PdfName.decodeName(baseFont.name)!); + final PdfFontFamily? fontFamily = fontFamilyDic['fontFamily'] as PdfFontFamily?; final String? standardName = fontFamilyDic['standardName'] as String?; if (standardName == null) { font = PdfStandardFont(fontFamily!, height, multiStyle: fontStyle); @@ -1359,26 +1258,20 @@ class PdfFieldHelper { if (height == 0 && standardName != getEnumName(fontFamily)) { PdfDictionary? appearanceDictionary = PdfDictionary(); if (dictionary!.containsKey(PdfDictionaryProperties.ap)) { - appearanceDictionary = - dictionary![PdfDictionaryProperties.ap] as PdfDictionary?; + appearanceDictionary = dictionary![PdfDictionaryProperties.ap] as PdfDictionary?; } else { if (dictionary!.containsKey(PdfDictionaryProperties.kids) && dictionary![PdfDictionaryProperties.kids] is PdfArray) { - final PdfArray kidsArray = - dictionary![PdfDictionaryProperties.kids]! as PdfArray; + final PdfArray kidsArray = dictionary![PdfDictionaryProperties.kids]! as PdfArray; for (int i = 0; i < kidsArray.count; i++) { if (kidsArray[i] is PdfReferenceHolder) { - final PdfReferenceHolder kids = - kidsArray[i]! as PdfReferenceHolder; + final PdfReferenceHolder kids = kidsArray[i]! as PdfReferenceHolder; final IPdfPrimitive? dictionary = kids.object; appearanceDictionary = dictionary != null && dictionary is PdfDictionary && - dictionary - .containsKey(PdfDictionaryProperties.ap) && - dictionary[PdfDictionaryProperties.ap] - is PdfDictionary - ? dictionary[PdfDictionaryProperties.ap] - as PdfDictionary? + dictionary.containsKey(PdfDictionaryProperties.ap) && + dictionary[PdfDictionaryProperties.ap] is PdfDictionary + ? dictionary[PdfDictionaryProperties.ap] as PdfDictionary? : null; break; } @@ -1387,13 +1280,12 @@ class PdfFieldHelper { } if (appearanceDictionary != null && appearanceDictionary.containsKey(PdfDictionaryProperties.n)) { - final IPdfPrimitive? dic = PdfCrossTable.dereference( - appearanceDictionary[PdfDictionaryProperties.n]); + final IPdfPrimitive? dic = + PdfCrossTable.dereference(appearanceDictionary[PdfDictionaryProperties.n]); if (dic != null && dic is PdfStream) { final PdfStream stream = dic; stream.decompress(); - final dynamic fontNameDict = - _fontName(utf8.decode(stream.dataStream!.toList())); + final dynamic fontNameDict = _fontName(utf8.decode(stream.dataStream!.toList())); height = fontNameDict['height'] as double; } } @@ -1404,43 +1296,34 @@ class PdfFieldHelper { font = PdfStandardFont.prototype(stdf, height); } if (fontStyle != [PdfFontStyle.regular]) { - font = PdfStandardFont(PdfFontFamily.helvetica, height, - multiStyle: fontStyle); + font = PdfStandardFont(PdfFontFamily.helvetica, height, multiStyle: fontStyle); } if (standardName != getEnumName(fontFamily)) { font = _updateFontEncoding(font, fontDictionary); } - PdfFontHelper.getHelper(font).metrics = - _createFont(fontDictionary, height, baseFont); + PdfFontHelper.getHelper(font).metrics = _createFont(fontDictionary, height, baseFont); PdfFontHelper.getHelper(font).fontInternals = fontDictionary; } } else if (fontSubtype.name == 'TrueType') { - final PdfName baseFont = crossTable! - .getObject(fontDictionary[PdfDictionaryProperties.baseFont])! - as PdfName; + final PdfName baseFont = + crossTable!.getObject(fontDictionary[PdfDictionaryProperties.baseFont])! as PdfName; final List fontStyle = _getFontStyle(baseFont.name!); - font = PdfStandardFont.prototype( - PdfStandardFont(PdfFontFamily.helvetica, 8), height, + font = PdfStandardFont.prototype(PdfStandardFont(PdfFontFamily.helvetica, 8), height, multiStyle: fontStyle); - font = _createFontFromFontStream( - font, fontDictionary, height, fontStyle); - final IPdfPrimitive? tempName = - fontDictionary[PdfDictionaryProperties.name]; + font = _createFontFromFontStream(font, fontDictionary, height, fontStyle); + final IPdfPrimitive? tempName = fontDictionary[PdfDictionaryProperties.name]; if (tempName != null && tempName is PdfName) { if (font is PdfStandardFont && font.name != tempName.name) { final PdfFontHelper fontHelper = PdfFontHelper.getHelper(font); final WidthTable? widthTable = fontHelper.metrics!.widthTable; - fontHelper.metrics = - _createFont(fontDictionary, height, baseFont); + fontHelper.metrics = _createFont(fontDictionary, height, baseFont); fontHelper.metrics!.widthTable = widthTable; } } } else if (fontSubtype.name == PdfDictionaryProperties.type0) { - final IPdfPrimitive? baseFont = crossTable! - .getObject(fontDictionary[PdfDictionaryProperties.baseFont]); - if (baseFont != null && - baseFont is PdfName && - _isCjkFont(baseFont.name)) { + final IPdfPrimitive? baseFont = + crossTable!.getObject(fontDictionary[PdfDictionaryProperties.baseFont]); + if (baseFont != null && baseFont is PdfName && _isCjkFont(baseFont.name)) { font = PdfCjkStandardFont(_getCjkFontFamily(baseFont.name)!, height, multiStyle: _getFontStyle(baseFont.name!)); } else { @@ -1449,8 +1332,8 @@ class PdfFieldHelper { IPdfPrimitive? fontDescriptor; IPdfPrimitive? fontDescriptorDic; IPdfPrimitive? fontName; - descendantFontsArray = crossTable!.getObject( - fontDictionary[PdfDictionaryProperties.descendantFonts]); + descendantFontsArray = + crossTable!.getObject(fontDictionary[PdfDictionaryProperties.descendantFonts]); if (descendantFontsArray != null && descendantFontsArray is PdfArray && descendantFontsArray.count > 0) { @@ -1458,26 +1341,19 @@ class PdfFieldHelper { ? descendantFontsArray[0] : (descendantFontsArray[0]! as PdfReferenceHolder).object; } - if (descendantFontsDic != null && - descendantFontsDic is PdfDictionary) { - fontDescriptor = - descendantFontsDic[PdfDictionaryProperties.fontDescriptor]; + if (descendantFontsDic != null && descendantFontsDic is PdfDictionary) { + fontDescriptor = descendantFontsDic[PdfDictionaryProperties.fontDescriptor]; } - if (fontDescriptor != null && - fontDescriptor is PdfReferenceHolder) { + if (fontDescriptor != null && fontDescriptor is PdfReferenceHolder) { fontDescriptorDic = fontDescriptor.object; } - if (fontDescriptorDic != null && - fontDescriptorDic is PdfDictionary) { + if (fontDescriptorDic != null && fontDescriptorDic is PdfDictionary) { fontName = fontDescriptorDic[PdfDictionaryProperties.fontName]; } if (fontName != null && fontName is PdfName) { - String fontNameStr = - fontName.name!.substring(fontName.name!.indexOf('+') + 1); - final PdfFontMetrics fontMetrics = _createFont( - descendantFontsDic! as PdfDictionary, - height, - PdfName(fontNameStr)); + String fontNameStr = fontName.name!.substring(fontName.name!.indexOf('+') + 1); + final PdfFontMetrics fontMetrics = + _createFont(descendantFontsDic! as PdfDictionary, height, PdfName(fontNameStr)); if (fontNameStr.contains('PSMT')) { fontNameStr = fontNameStr.replaceAll('PSMT', ''); } @@ -1488,8 +1364,7 @@ class PdfFieldHelper { fontNameStr = fontNameStr.replaceAll('-', ''); } if (font.name != fontNameStr) { - final WidthTable? widthTable = - PdfFontHelper.getHelper(font).metrics!.widthTable; + final WidthTable? widthTable = PdfFontHelper.getHelper(font).metrics!.widthTable; PdfFontHelper.getHelper(font).metrics = fontMetrics; PdfFontHelper.getHelper(font).metrics!.widthTable = widthTable; } @@ -1501,39 +1376,33 @@ class PdfFieldHelper { final PdfFont? usedFont = _getFontByName(name, height); usedFont != null ? font = usedFont : isCorrectFont = false; } - return { - 'font': font, - 'isCorrectFont': isCorrectFont, - 'FontName': name - }; + return {'font': font, 'isCorrectFont': isCorrectFont, 'FontName': name}; } - PdfFont _createFontFromFontStream(PdfFont font, PdfDictionary fontDictionary, - double height, List fontStyle) { + PdfFont _createFontFromFontStream( + PdfFont font, PdfDictionary fontDictionary, double height, List fontStyle) { if (fontDictionary.containsKey(PdfDictionaryProperties.fontDescriptor)) { - IPdfPrimitive? fontDescriptor = PdfCrossTable.dereference( - fontDictionary[PdfDictionaryProperties.fontDescriptor]); + IPdfPrimitive? fontDescriptor = + PdfCrossTable.dereference(fontDictionary[PdfDictionaryProperties.fontDescriptor]); if (fontDescriptor == null && fontDescriptor is PdfDictionary && fontDictionary.containsKey(PdfDictionaryProperties.descendantFonts)) { - final IPdfPrimitive? descendFonts = PdfCrossTable.dereference( - fontDictionary[PdfDictionaryProperties.descendantFonts]); + final IPdfPrimitive? descendFonts = + PdfCrossTable.dereference(fontDictionary[PdfDictionaryProperties.descendantFonts]); if (descendFonts != null && descendFonts is PdfArray) { - final IPdfPrimitive? descendDict = - PdfCrossTable.dereference(descendFonts[0]); + final IPdfPrimitive? descendDict = PdfCrossTable.dereference(descendFonts[0]); if (descendDict != null && descendDict is PdfDictionary && descendDict.containsKey(PdfDictionaryProperties.fontDescriptor)) { - fontDescriptor = PdfCrossTable.dereference( - descendDict[PdfDictionaryProperties.fontDescriptor]); + fontDescriptor = + PdfCrossTable.dereference(descendDict[PdfDictionaryProperties.fontDescriptor]); } } } IPdfPrimitive? fontFile; if (fontDescriptor != null && fontDescriptor is PdfDictionary) { if (fontDescriptor.containsKey(PdfDictionaryProperties.fontFile2)) { - fontFile = PdfCrossTable.dereference( - fontDescriptor[PdfDictionaryProperties.fontFile2]); + fontFile = PdfCrossTable.dereference(fontDescriptor[PdfDictionaryProperties.fontFile2]); } if (fontDescriptor.containsKey('FontFile3')) { fontFile = PdfCrossTable.dereference(fontDescriptor['FontFile3']); @@ -1545,8 +1414,7 @@ class PdfFieldHelper { try { fontFile.position = 0; if (fontFile.dataStream != null) { - font = PdfTrueTypeFont(fontFile.dataStream!, height, - multiStyle: fontStyle); + font = PdfTrueTypeFont(fontFile.dataStream!, height, multiStyle: fontStyle); } } catch (e) { return font; @@ -1556,29 +1424,22 @@ class PdfFieldHelper { return font; } - PdfFontMetrics _createFont( - PdfDictionary fontDictionary, double? height, PdfName baseFont) { + PdfFontMetrics _createFont(PdfDictionary fontDictionary, double? height, PdfName baseFont) { final PdfFontMetrics fontMetrics = PdfFontMetrics(); if (fontDictionary.containsKey(PdfDictionaryProperties.fontDescriptor)) { IPdfPrimitive? createFontDictionary; final IPdfPrimitive? fontReferenceHolder = fontDictionary[PdfDictionaryProperties.fontDescriptor]; - if (fontReferenceHolder != null && - fontReferenceHolder is PdfReferenceHolder) { + if (fontReferenceHolder != null && fontReferenceHolder is PdfReferenceHolder) { createFontDictionary = fontReferenceHolder.object; } else { - createFontDictionary = - fontDictionary[PdfDictionaryProperties.fontDescriptor]; + createFontDictionary = fontDictionary[PdfDictionaryProperties.fontDescriptor]; } - if (createFontDictionary != null && - createFontDictionary is PdfDictionary) { + if (createFontDictionary != null && createFontDictionary is PdfDictionary) { fontMetrics.ascent = - (createFontDictionary[PdfDictionaryProperties.ascent]! as PdfNumber) - .value! as double; + (createFontDictionary[PdfDictionaryProperties.ascent]! as PdfNumber).value! as double; fontMetrics.descent = - (createFontDictionary[PdfDictionaryProperties.descent]! - as PdfNumber) - .value! as double; + (createFontDictionary[PdfDictionaryProperties.descent]! as PdfNumber).value! as double; fontMetrics.size = height!; fontMetrics.height = fontMetrics.ascent - fontMetrics.descent; fontMetrics.postScriptName = baseFont.name; @@ -1586,12 +1447,10 @@ class PdfFieldHelper { } PdfArray? array; if (fontDictionary.containsKey(PdfDictionaryProperties.widths)) { - if (fontDictionary[PdfDictionaryProperties.widths] - is PdfReferenceHolder) { + if (fontDictionary[PdfDictionaryProperties.widths] is PdfReferenceHolder) { final PdfReferenceHolder tableReference = PdfReferenceHolder(fontDictionary[PdfDictionaryProperties.widths]); - final PdfReferenceHolder tableArray = - tableReference.object! as PdfReferenceHolder; + final PdfReferenceHolder tableArray = tableReference.object! as PdfReferenceHolder; array = tableArray.object as PdfArray?; final List widthTable = []; for (int i = 0; i < array!.count; i++) { @@ -1619,33 +1478,27 @@ class PdfFieldHelper { multiStyle: [PdfFontStyle.bold, PdfFontStyle.italic]); break; case 'CoBo': //"Courier-Bold" - font = PdfStandardFont(PdfFontFamily.courier, height, - style: PdfFontStyle.bold); + font = PdfStandardFont(PdfFontFamily.courier, height, style: PdfFontStyle.bold); break; case 'CoOb': //"Courier-Oblique" - font = PdfStandardFont(PdfFontFamily.courier, height, - style: PdfFontStyle.italic); + font = PdfStandardFont(PdfFontFamily.courier, height, style: PdfFontStyle.italic); break; case 'Courier': case 'Cour': //"Courier" - font = PdfStandardFont(PdfFontFamily.courier, height, - style: PdfFontStyle.regular); + font = PdfStandardFont(PdfFontFamily.courier, height, style: PdfFontStyle.regular); break; case 'HeBO': //"Helvetica-BoldOblique" font = PdfStandardFont(PdfFontFamily.helvetica, height, multiStyle: [PdfFontStyle.bold, PdfFontStyle.italic]); break; case 'HeBo': //"Helvetica-Bold" - font = PdfStandardFont(PdfFontFamily.helvetica, height, - style: PdfFontStyle.bold); + font = PdfStandardFont(PdfFontFamily.helvetica, height, style: PdfFontStyle.bold); break; case 'HeOb': //"Helvetica-Oblique" - font = PdfStandardFont(PdfFontFamily.helvetica, height, - style: PdfFontStyle.italic); + font = PdfStandardFont(PdfFontFamily.helvetica, height, style: PdfFontStyle.italic); break; case 'Helv': //"Helvetica" - font = PdfStandardFont(PdfFontFamily.helvetica, height, - style: PdfFontStyle.regular); + font = PdfStandardFont(PdfFontFamily.helvetica, height, style: PdfFontStyle.regular); break; case 'Symb': // "Symbol" font = PdfStandardFont(PdfFontFamily.symbol, height); @@ -1655,16 +1508,13 @@ class PdfFieldHelper { multiStyle: [PdfFontStyle.bold, PdfFontStyle.italic]); break; case 'TiBo': // "Times-Bold" - font = PdfStandardFont(PdfFontFamily.timesRoman, height, - style: PdfFontStyle.bold); + font = PdfStandardFont(PdfFontFamily.timesRoman, height, style: PdfFontStyle.bold); break; case 'TiIt': // "Times-Italic" - font = PdfStandardFont(PdfFontFamily.timesRoman, height, - style: PdfFontStyle.italic); + font = PdfStandardFont(PdfFontFamily.timesRoman, height, style: PdfFontStyle.italic); break; case 'TiRo': // "Times-Roman" - font = PdfStandardFont(PdfFontFamily.timesRoman, height, - style: PdfFontStyle.regular); + font = PdfStandardFont(PdfFontFamily.timesRoman, height, style: PdfFontStyle.regular); break; case 'ZaDb': // "ZapfDingbats" font = PdfStandardFont(PdfFontFamily.zapfDingbats, height); @@ -1696,12 +1546,10 @@ class PdfFieldHelper { colour = PdfColorHelper.fromGray(_parseFloatColour(operands.last!)); } else if (token == 'rg') { colour = PdfColor( - (_parseFloatColour(operands.elementAt(operands.length - 3)!) * - 255) + (_parseFloatColour(operands.elementAt(operands.length - 3)!) * 255) .toInt() .toUnsigned(8), - (_parseFloatColour(operands.elementAt(operands.length - 2)!) * - 255) + (_parseFloatColour(operands.elementAt(operands.length - 2)!) * 255) .toInt() .toUnsigned(8), (_parseFloatColour(operands.last!) * 255).toInt().toUnsigned(8)); @@ -1735,10 +1583,9 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); final PdfStringFormat stringFormat = PdfStringFormat(); stringFormat.lineAlignment = PdfVerticalAlignment.middle; - stringFormat.lineAlignment = - ((flagValue & _getFieldFlagsValue(FieldFlags.multiline)) > 0) - ? PdfVerticalAlignment.top - : PdfVerticalAlignment.middle; + stringFormat.lineAlignment = ((flagValue & _getFieldFlagsValue(FieldFlags.multiline)) > 0) + ? PdfVerticalAlignment.top + : PdfVerticalAlignment.middle; IPdfPrimitive? number; if (widget.containsKey(PdfDictionaryProperties.q)) { number = crossTable!.getObject(widget[PdfDictionaryProperties.q]); @@ -1904,28 +1751,22 @@ class PdfFieldHelper { fontFamily = PdfFontFamily.values[fontFamilyList.indexOf(standardName)]; standardName = null; } - return { - 'fontFamily': fontFamily, - 'standardName': standardName - }; + return {'fontFamily': fontFamily, 'standardName': standardName}; } PdfFont _updateFontEncoding(PdfFont font, PdfDictionary fontDictionary) { final PdfDictionary? fontInternalDictionary = PdfFontHelper.getHelper(font).fontInternals as PdfDictionary?; - if (fontDictionary.items! - .containsKey(PdfName(PdfDictionaryProperties.encoding))) { + if (fontDictionary.items!.containsKey(PdfName(PdfDictionaryProperties.encoding))) { final PdfName encodingName = PdfName(PdfDictionaryProperties.encoding); final IPdfPrimitive? encodingReferenceHolder = fontDictionary.items![PdfName(PdfDictionaryProperties.encoding)]; - if (encodingReferenceHolder != null && - encodingReferenceHolder is PdfReferenceHolder) { + if (encodingReferenceHolder != null && encodingReferenceHolder is PdfReferenceHolder) { final IPdfPrimitive? dictionary = encodingReferenceHolder.object; if (dictionary != null && dictionary is PdfDictionary) { if (fontInternalDictionary!.items! .containsKey(PdfName(PdfDictionaryProperties.encoding))) { - fontInternalDictionary.items! - .remove(PdfName(PdfDictionaryProperties.encoding)); + fontInternalDictionary.items!.remove(PdfName(PdfDictionaryProperties.encoding)); } fontInternalDictionary.items![encodingName] = dictionary; } @@ -1935,8 +1776,7 @@ class PdfFieldHelper { if (encodingDictionary != null && encodingDictionary is PdfDictionary) { if (fontInternalDictionary!.items! .containsKey(PdfName(PdfDictionaryProperties.encoding))) { - fontInternalDictionary.items! - .remove(PdfName(PdfDictionaryProperties.encoding)); + fontInternalDictionary.items!.remove(PdfName(PdfDictionaryProperties.encoding)); } fontInternalDictionary.items![encodingName] = encodingDictionary; } @@ -1946,11 +1786,9 @@ class PdfFieldHelper { } /// internal method - void setFittingFontSize( - GraphicsProperties gp, PaintParams prms, String text) { + void setFittingFontSize(GraphicsProperties gp, PaintParams prms, String text) { double fontSize = 0; - final double width = prms.style == PdfBorderStyle.beveled || - prms.style == PdfBorderStyle.inset + final double width = prms.style == PdfBorderStyle.beveled || prms.style == PdfBorderStyle.inset ? gp.bounds!.width - 8 * prms.borderWidth! : gp.bounds!.width - 4 * prms.borderWidth!; final double height = gp.bounds!.height - 2 * gp.borderWidth!; @@ -1966,8 +1804,7 @@ class PdfFieldHelper { do { fontSize = fontSize - 0.001; PdfFontHelper.getHelper(gp.font!).setSize(fontSize); - final double textWidth = - PdfFontHelper.getLineWidth(gp.font!, text, gp.stringFormat); + final double textWidth = PdfFontHelper.getLineWidth(gp.font!, text, gp.stringFormat); if (fontSize < minimumFontSize) { PdfFontHelper.getHelper(gp.font!).setSize(minimumFontSize); break; @@ -2004,12 +1841,10 @@ class PdfFieldHelper { } /// internal method - void drawStateItem( - PdfGraphics graphics, PdfCheckFieldState state, PdfCheckFieldBase? item, + void drawStateItem(PdfGraphics graphics, PdfCheckFieldState state, PdfCheckFieldBase? item, [PdfFieldItem? fieldItem]) { - final GraphicsProperties gp = item != null - ? GraphicsProperties(item) - : GraphicsProperties.fromFieldItem(fieldItem!); + final GraphicsProperties gp = + item != null ? GraphicsProperties(item) : GraphicsProperties.fromFieldItem(fieldItem!); if (!flattenField) { gp.bounds = Rect.fromLTWH(0, 0, gp.bounds!.width, gp.bounds!.height); } @@ -2028,9 +1863,7 @@ class PdfFieldHelper { if (fieldChanged == true) { _drawFields(graphics, gp, prms, state); } else { - PdfGraphicsHelper.getHelper(graphics) - .streamWriter! - .setTextRenderingMode(0); + PdfGraphicsHelper.getHelper(graphics).streamWriter!.setTextRenderingMode(0); final PdfTemplate? stateTemplate = _getStateTemplate( state, item != null @@ -2045,22 +1878,17 @@ class PdfFieldHelper { bool encryptedContent = false; if (crossTable != null && crossTable!.document != null && - PdfDocumentHelper.getHelper(crossTable!.document!) - .isLoadedDocument) { + PdfDocumentHelper.getHelper(crossTable!.document!).isLoadedDocument) { final PdfDocument? loadedDocument = crossTable!.document; - if (loadedDocument != null && - PdfDocumentHelper.getHelper(loadedDocument).isEncrypted) { - if (PdfSecurityHelper.getHelper(loadedDocument.security) - .encryptor - .isEncrypt! && + if (loadedDocument != null && PdfDocumentHelper.getHelper(loadedDocument).isEncrypted) { + if (PdfSecurityHelper.getHelper(loadedDocument.security).encryptor.isEncrypt! && loadedDocument.security.encryptionOptions == PdfEncryptionOptions.encryptAllContents) { encryptedContent = true; } } } - final PdfStream pdfStream = - PdfTemplateHelper.getHelper(stateTemplate).content; + final PdfStream pdfStream = PdfTemplateHelper.getHelper(stateTemplate).content; if (encryptedContent && pdfStream.encrypt! && !pdfStream.decrypted! && @@ -2083,29 +1911,22 @@ class PdfFieldHelper { graphics.restore(); } - PdfTemplate? _getStateTemplate( - PdfCheckFieldState state, PdfDictionary? itemDictionary) { + PdfTemplate? _getStateTemplate(PdfCheckFieldState state, PdfDictionary? itemDictionary) { final PdfDictionary dic = itemDictionary ?? dictionary!; final String? value = state == PdfCheckFieldState.checked ? getItemValue(dic, crossTable) : PdfDictionaryProperties.off; PdfTemplate? template; if (dic.containsKey(PdfDictionaryProperties.ap)) { - final IPdfPrimitive? appearance = - PdfCrossTable.dereference(dic[PdfDictionaryProperties.ap]); + final IPdfPrimitive? appearance = PdfCrossTable.dereference(dic[PdfDictionaryProperties.ap]); if (appearance != null && appearance is PdfDictionary) { final IPdfPrimitive? norm = PdfCrossTable.dereference(appearance[PdfDictionaryProperties.n]); - if (value != null && - value.isNotEmpty && - norm != null && - norm is PdfDictionary) { + if (value != null && value.isNotEmpty && norm != null && norm is PdfDictionary) { final IPdfPrimitive? xObject = PdfCrossTable.dereference(norm[value]); if (xObject != null && xObject is PdfStream) { template = PdfTemplateHelper.fromPdfStream(xObject); - if (value == PdfDictionaryProperties.off && - xObject.encrypt! && - xObject.decrypted!) { + if (value == PdfDictionaryProperties.off && xObject.encrypt! && xObject.decrypted!) { //AP stream undecrypted might cause document corruption template = null; } @@ -2116,8 +1937,8 @@ class PdfFieldHelper { return template; } - void _drawFields(PdfGraphics graphics, GraphicsProperties gp, - PaintParams params, PdfCheckFieldState state) { + void _drawFields( + PdfGraphics graphics, GraphicsProperties gp, PaintParams params, PdfCheckFieldState state) { if (gp.font!.size >= 0) { gp.font = null; } @@ -2133,8 +1954,7 @@ class PdfFieldHelper { FieldPainter().drawRadioButton( graphics, params, - PdfRadioButtonListItemHelper.getHelper( - field as PdfRadioButtonListItem) + PdfRadioButtonListItemHelper.getHelper(field as PdfRadioButtonListItem) .styleToString((field as PdfRadioButtonListItem).style), state); } @@ -2142,8 +1962,8 @@ class PdfFieldHelper { /// internal method void importFieldValue(Object fieldValue) { - final IPdfPrimitive? primitive = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.ft, true); + final IPdfPrimitive? primitive = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.ft, true); String? value; if (fieldValue is String) { value = fieldValue; @@ -2162,8 +1982,7 @@ class PdfFieldHelper { break; case 'Ch': if (field is PdfListBoxField) { - (field as PdfListBoxField).selectedValues = - valueArray ?? [value]; + (field as PdfListBoxField).selectedValues = valueArray ?? [value]; } else if (field is PdfComboBoxField) { (field as PdfComboBoxField).selectedValue = value; } @@ -2173,19 +1992,15 @@ class PdfFieldHelper { final PdfCheckBoxField field1 = field as PdfCheckBoxField; if (value.toUpperCase() == 'OFF' || value.toUpperCase() == 'NO') { field1.isChecked = false; - } else if (value.toUpperCase() == 'ON' || - value.toUpperCase() == 'YES') { + } else if (value.toUpperCase() == 'ON' || value.toUpperCase() == 'YES') { field1.isChecked = true; - } else if (_containsExportValue( - value, field1._fieldHelper.dictionary!)) { + } else if (_containsExportValue(value, field1._fieldHelper.dictionary!)) { field1.isChecked = true; } else if (field1.items != null && field1.items!.count > 0) { bool isChecked = false; for (int i = 0; i < field1.items!.count; i++) { if (_containsExportValue( - value, - PdfFieldItemHelper.getHelper(field1.items![i]) - .dictionary!)) { + value, PdfFieldItemHelper.getHelper(field1.items![i]).dictionary!)) { (field1.items![i] as PdfCheckBoxItem).checked = true; isChecked = true; } @@ -2228,16 +2043,15 @@ class PdfFieldHelper { break; } if (widget[PdfDictionaryProperties.bs] is PdfReferenceHolder) { - final PdfDictionary widgetDict = crossTable! - .getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; + final PdfDictionary widgetDict = + crossTable!.getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; if (widgetDict.containsKey(PdfDictionaryProperties.s)) { widgetDict[PdfDictionaryProperties.s] = PdfName(style); } else { widgetDict.setProperty(PdfDictionaryProperties.s, PdfName(style)); } } else { - final PdfDictionary bsDict = - widget[PdfDictionaryProperties.bs]! as PdfDictionary; + final PdfDictionary bsDict = widget[PdfDictionaryProperties.bs]! as PdfDictionary; if (bsDict.containsKey(PdfDictionaryProperties.s)) { bsDict[PdfDictionaryProperties.s] = PdfName(style); } else { @@ -2248,16 +2062,13 @@ class PdfFieldHelper { } else { if (!widget.containsKey(PdfDictionaryProperties.bs)) { this.widget!.widgetBorder!.borderStyle = borderStyle!; - widget.setProperty( - PdfDictionaryProperties.bs, - PdfAnnotationBorderHelper.getHelper(this.widget!.widgetBorder!) - .dictionary); + widget.setProperty(PdfDictionaryProperties.bs, + PdfAnnotationBorderHelper.getHelper(this.widget!.widgetBorder!).dictionary); } } if (widget.containsKey(PdfDictionaryProperties.mk) && widget[PdfDictionaryProperties.mk] is PdfDictionary) { - final PdfDictionary mkDict = - widget[PdfDictionaryProperties.mk]! as PdfDictionary; + final PdfDictionary mkDict = widget[PdfDictionaryProperties.mk]! as PdfDictionary; if (!mkDict.containsKey(PdfDictionaryProperties.bc) && !mkDict.containsKey(PdfDictionaryProperties.bg)) { WidgetAnnotationHelper.getHelper(this.widget!) @@ -2299,8 +2110,7 @@ class PdfFieldHelper { bool _containsExportValue(String value, PdfDictionary dictionary) { bool result = false; - final PdfDictionary widgetDictionary = - getWidgetAnnotation(dictionary, crossTable); + final PdfDictionary widgetDictionary = getWidgetAnnotation(dictionary, crossTable); if (widgetDictionary.containsKey(PdfDictionaryProperties.ap)) { final IPdfPrimitive? appearance = crossTable!.getObject(widgetDictionary[PdfDictionaryProperties.ap]); @@ -2327,27 +2137,25 @@ class PdfFieldHelper { kids = crossTable!.getObject(dictionary![PdfDictionaryProperties.kids]); if (kids != null && kids is PdfArray) { for (int i = 0; i < kids.count; i++) { - flag = flag || - (kids[i] is PdfField && - (kids[i]! as PdfField)._fieldHelper.isLoadedField); + flag = flag || (kids[i] is PdfField && (kids[i]! as PdfField)._fieldHelper.isLoadedField); } } } - final IPdfPrimitive? name = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.ft, true); + final IPdfPrimitive? name = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.ft, true); String? strValue = ''; if (name != null && name is PdfName) { switch (name.name) { case 'Tx': - final IPdfPrimitive? tempName = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? tempName = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if (tempName != null && tempName is PdfString) { strValue = tempName.value; } break; case 'Ch': - final IPdfPrimitive? checkBoxPrimitive = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? checkBoxPrimitive = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if (checkBoxPrimitive != null) { final String? value = getExportValue(field, checkBoxPrimitive); if (value != null && value.isNotEmpty) { @@ -2356,14 +2164,13 @@ class PdfFieldHelper { } break; case 'Btn': - final IPdfPrimitive? buttonFieldPrimitive = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? buttonFieldPrimitive = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if (buttonFieldPrimitive != null) { final String? value = getExportValue(field, buttonFieldPrimitive); if (value != null && value.isNotEmpty) { strValue = value; - } else if (field is PdfRadioButtonListField || - field is PdfCheckBoxField) { + } else if (field is PdfRadioButtonListField || field is PdfCheckBoxField) { if (!exportEmptyField) { strValue = PdfDictionaryProperties.off; } @@ -2372,10 +2179,8 @@ class PdfFieldHelper { if (field is PdfRadioButtonListField) { strValue = getAppearanceStateValue(field); } else { - final PdfDictionary holder = - getWidgetAnnotation(dictionary!, crossTable); - final IPdfPrimitive? holderName = - holder[PdfDictionaryProperties.usageApplication]; + final PdfDictionary holder = getWidgetAnnotation(dictionary!, crossTable); + final IPdfPrimitive? holderName = holder[PdfDictionaryProperties.usageApplication]; if (holderName != null && holderName is PdfName) { strValue = holderName.name; } @@ -2383,9 +2188,7 @@ class PdfFieldHelper { } break; } - if ((strValue != null && strValue.isNotEmpty) || - exportEmptyField || - flag) { + if ((strValue != null && strValue.isNotEmpty) || exportEmptyField || flag) { if (flag && kids != null && kids is PdfArray) { for (int i = 0; i < kids.count; i++) { final IPdfPrimitive? field = kids[i]; @@ -2401,8 +2204,7 @@ class PdfFieldHelper { } objID = objectID; objectID++; - final PdfString stringValue = PdfString(strValue!) - ..encode = ForceEncoding.ascii; + final PdfString stringValue = PdfString(strValue!)..encode = ForceEncoding.ascii; final StringBuffer buffer = StringBuffer(); buffer.write( '$objID 0 obj< /Kids ['); @@ -2425,13 +2227,10 @@ class PdfFieldHelper { if (field is PdfCheckBoxField || field is PdfRadioButtonListField) { strValue = '/${strValue!}'; } else { - final PdfString stringFieldValue = PdfString(strValue!) - ..encode = ForceEncoding.ascii; - strValue = - '<${PdfString.bytesToHex(stringFieldValue.value!.codeUnits)}>'; + final PdfString stringFieldValue = PdfString(strValue!)..encode = ForceEncoding.ascii; + strValue = '<${PdfString.bytesToHex(stringFieldValue.value!.codeUnits)}>'; } - final PdfString stringFieldName = PdfString(this.name!) - ..encode = ForceEncoding.ascii; + final PdfString stringFieldName = PdfString(this.name!)..encode = ForceEncoding.ascii; final PdfString buildString = PdfString( '$objID 0 obj< /V $strValue >>endobj\n') ..encode = ForceEncoding.ascii; @@ -2449,8 +2248,7 @@ class PdfFieldHelper { value = buttonFieldPrimitive.name; } else if (buttonFieldPrimitive is PdfString) { value = buttonFieldPrimitive.value; - } else if (buttonFieldPrimitive is PdfArray && - buttonFieldPrimitive.count > 0) { + } else if (buttonFieldPrimitive is PdfArray && buttonFieldPrimitive.count > 0) { for (int i = 0; i < buttonFieldPrimitive.count; i++) { final IPdfPrimitive? primitive = buttonFieldPrimitive[i]; if (primitive is PdfName) { @@ -2467,10 +2265,8 @@ class PdfFieldHelper { final PdfRadioButtonListItem? item = field.selectedItem; if (item != null) { if (item.value == value || - PdfRadioButtonListItemHelper.getHelper(item).optionValue == - value) { - final String? optionValue = - PdfRadioButtonListItemHelper.getHelper(item).optionValue; + PdfRadioButtonListItemHelper.getHelper(item).optionValue == value) { + final String? optionValue = PdfRadioButtonListItemHelper.getHelper(item).optionValue; if (optionValue != null && optionValue.isNotEmpty) { value = optionValue; } @@ -2483,15 +2279,12 @@ class PdfFieldHelper { /// internal method String getAppearanceStateValue(PdfField field) { - final List holders = field._getWidgetAnnotations( - field._fieldHelper.dictionary!, field._fieldHelper.crossTable!); + final List holders = + field._getWidgetAnnotations(field._fieldHelper.dictionary!, field._fieldHelper.crossTable!); String? value; for (int i = 0; i < holders.length; i++) { - final IPdfPrimitive? pdfName = - holders[i][PdfDictionaryProperties.usageApplication]; - if (pdfName != null && - pdfName is PdfName && - pdfName.name != PdfDictionaryProperties.off) { + final IPdfPrimitive? pdfName = holders[i][PdfDictionaryProperties.usageApplication]; + if (pdfName != null && pdfName is PdfName && pdfName.name != PdfDictionaryProperties.off) { value = pdfName.name; } } @@ -2503,8 +2296,8 @@ class PdfFieldHelper { /// internal method XmlElement? exportFieldForXml() { - final IPdfPrimitive? name = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.ft, true); + final IPdfPrimitive? name = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.ft, true); String fieldName = this.name!.replaceAll(' ', '_x0020_'); fieldName = fieldName .replaceAll(r'\', '_x005C_') @@ -2521,8 +2314,8 @@ class PdfFieldHelper { if (name != null && name is PdfName) { switch (name.name) { case 'Tx': - final IPdfPrimitive? str = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? str = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if ((str != null && str is PdfString) || exportEmptyField) { element = XmlElement(XmlName(fieldName)); if (str != null && str is PdfString) { @@ -2533,8 +2326,8 @@ class PdfFieldHelper { } break; case 'Ch': - final IPdfPrimitive? str = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? str = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if (str != null && str is PdfName) { final XmlElement element = XmlElement(XmlName(fieldName)); element.innerText = str.name!; @@ -2548,8 +2341,8 @@ class PdfFieldHelper { } break; case 'Btn': - final IPdfPrimitive? buttonFieldPrimitive = PdfFieldHelper.getValue( - dictionary!, crossTable, PdfDictionaryProperties.v, true); + final IPdfPrimitive? buttonFieldPrimitive = + PdfFieldHelper.getValue(dictionary!, crossTable, PdfDictionaryProperties.v, true); if (buttonFieldPrimitive != null) { final String? value = getExportValue(field, buttonFieldPrimitive); if ((value != null && value.isNotEmpty) || exportEmptyField) { @@ -2559,8 +2352,7 @@ class PdfFieldHelper { } else if (exportEmptyField) { element.innerText = ''; } - } else if (field is PdfRadioButtonListField || - field is PdfCheckBoxField) { + } else if (field is PdfRadioButtonListField || field is PdfCheckBoxField) { element = XmlElement(XmlName(fieldName)); if (exportEmptyField) { element.innerText = ''; @@ -2571,16 +2363,12 @@ class PdfFieldHelper { } else { if (field is PdfRadioButtonListField) { element = XmlElement(XmlName(fieldName)); - element.innerText = - getAppearanceStateValue(field as PdfRadioButtonListField); + element.innerText = getAppearanceStateValue(field as PdfRadioButtonListField); } else { - final PdfDictionary holder = - getWidgetAnnotation(dictionary!, crossTable); - if ((holder[PdfDictionaryProperties.usageApplication] - is PdfName) || + final PdfDictionary holder = getWidgetAnnotation(dictionary!, crossTable); + if ((holder[PdfDictionaryProperties.usageApplication] is PdfName) || exportEmptyField) { - final IPdfPrimitive? holderName = - holder[PdfDictionaryProperties.usageApplication]; + final IPdfPrimitive? holderName = holder[PdfDictionaryProperties.usageApplication]; element = XmlElement(XmlName(fieldName)); if (holderName != null && holderName is PdfName) { element.innerText = holderName.name!; @@ -2611,15 +2399,12 @@ class PdfFieldHelper { flags.add(FieldFlags.readOnly); } setFlags(flags); - if (page != null && - page!.formFieldsTabOrder == PdfFormFieldsTabOrder.manual) { + if (page != null && page!.formFieldsTabOrder == PdfFormFieldsTabOrder.manual) { page!.annotations.remove(widget!); PdfAnnotationCollectionHelper.getHelper(page!.annotations) .annotations .insert(field.tabIndex, PdfReferenceHolder(widget)); - PdfObjectCollectionHelper.getHelper(page!.annotations) - .list - .insert(field.tabIndex, widget!); + PdfObjectCollectionHelper.getHelper(page!.annotations).list.insert(field.tabIndex, widget!); } if (form != null && !PdfFormHelper.getHelper(form!).needAppearances! && @@ -2634,9 +2419,8 @@ class PdfFieldHelper { String? value = ''; PdfName? name; if (dictionary.containsKey(PdfDictionaryProperties.usageApplication)) { - name = crossTable! - .getObject(dictionary[PdfDictionaryProperties.usageApplication]) - as PdfName?; + name = + crossTable!.getObject(dictionary[PdfDictionaryProperties.usageApplication]) as PdfName?; if (name != null && name.name != PdfDictionaryProperties.off) { value = PdfName.decodeName(name.name); } @@ -2644,13 +2428,10 @@ class PdfFieldHelper { if (value!.isEmpty) { if (dictionary.containsKey(PdfDictionaryProperties.ap)) { final PdfDictionary dic = - crossTable!.getObject(dictionary[PdfDictionaryProperties.ap])! - as PdfDictionary; + crossTable!.getObject(dictionary[PdfDictionaryProperties.ap])! as PdfDictionary; if (dic.containsKey(PdfDictionaryProperties.n)) { - final PdfReference reference = - crossTable.getReference(dic[PdfDictionaryProperties.n]); - final PdfDictionary normalAppearance = - crossTable.getObject(reference)! as PdfDictionary; + final PdfReference reference = crossTable.getReference(dic[PdfDictionaryProperties.n]); + final PdfDictionary normalAppearance = crossTable.getObject(reference)! as PdfDictionary; final List list = []; normalAppearance.items!.forEach((PdfName? key, IPdfPrimitive? value) { list.add(key); @@ -2676,16 +2457,13 @@ class PdfFieldHelper { page.annotations.remove(widget!); } else { final PdfDictionary pageDic = PdfPageHelper.getHelper(page).dictionary!; - final PdfArray annots = pageDic - .containsKey(PdfDictionaryProperties.annots) + final PdfArray annots = pageDic.containsKey(PdfDictionaryProperties.annots) ? PdfPageHelper.getHelper(page) .crossTable! .getObject(pageDic[PdfDictionaryProperties.annots])! as PdfArray : PdfArray(); - final PdfAnnotationHelper helper = - PdfAnnotationHelper.getHelper(widget!); - helper.dictionary! - .setProperty(PdfDictionaryProperties.p, PdfReferenceHolder(page)); + final PdfAnnotationHelper helper = PdfAnnotationHelper.getHelper(widget!); + helper.dictionary!.setProperty(PdfDictionaryProperties.p, PdfReferenceHolder(page)); for (int i = 0; i < annots.count; i++) { final IPdfPrimitive? obj = annots[i]; if (obj != null && @@ -2707,11 +2485,9 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfPen? pen; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final IPdfPrimitive? mk = - crossTable!.getObject(widget[PdfDictionaryProperties.mk]); + final IPdfPrimitive? mk = crossTable!.getObject(widget[PdfDictionaryProperties.mk]); if (mk is PdfDictionary && mk.containsKey(PdfDictionaryProperties.bc)) { - final PdfArray array = - crossTable!.getObject(mk[PdfDictionaryProperties.bc])! as PdfArray; + final PdfArray array = crossTable!.getObject(mk[PdfDictionaryProperties.bc])! as PdfArray; pen = PdfPen(_createColor(array)); } } @@ -2735,8 +2511,7 @@ class PdfFieldHelper { if (borderStyle == PdfBorderStyle.dashed) { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); if (widget.containsKey(PdfDictionaryProperties.d)) { - final IPdfPrimitive? dashes = - crossTable!.getObject(widget[PdfDictionaryProperties.d]); + final IPdfPrimitive? dashes = crossTable!.getObject(widget[PdfDictionaryProperties.d]); if (dashes != null && dashes is PdfArray) { if (dashes.count == 2) { array = [0, 0]; @@ -2764,10 +2539,8 @@ class PdfFieldHelper { /// internal method void _assignHighlightMode(PdfHighlightMode? highlightMode) { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); - widget.setName( - PdfName(PdfDictionaryProperties.h), - WidgetAnnotationHelper.getHelper(this.widget!) - .highlightModeToString(highlightMode)); + widget.setName(PdfName(PdfDictionaryProperties.h), + WidgetAnnotationHelper.getHelper(this.widget!).highlightModeToString(highlightMode)); changed = true; } @@ -2782,27 +2555,22 @@ class PdfFieldHelper { } else { if (dictionary!.containsKey(PdfDictionaryProperties.parent)) { final IPdfPrimitive? parentDictionary = - (dictionary![PdfDictionaryProperties.parent]! as PdfReferenceHolder) - .object; + (dictionary![PdfDictionaryProperties.parent]! as PdfReferenceHolder).object; if (parentDictionary != null && parentDictionary is PdfDictionary && parentDictionary.containsKey(PdfDictionaryProperties.kids)) { if (parentDictionary.containsKey(PdfDictionaryProperties.ft) && (parentDictionary[PdfDictionaryProperties.ft]! as PdfName).name == PdfDictionaryProperties.btn) { - final PdfDictionary widget = - getWidgetAnnotation(parentDictionary, crossTable); + final PdfDictionary widget = getWidgetAnnotation(parentDictionary, crossTable); if (widget.containsKey(PdfDictionaryProperties.rect)) { - array = - crossTable!.getObject(widget[PdfDictionaryProperties.rect]); + array = crossTable!.getObject(widget[PdfDictionaryProperties.rect]); } } } } - if (array == null && - dictionary!.containsKey(PdfDictionaryProperties.rect)) { - array = - crossTable!.getObject(dictionary![PdfDictionaryProperties.rect]); + if (array == null && dictionary!.containsKey(PdfDictionaryProperties.rect)) { + array = crossTable!.getObject(dictionary![PdfDictionaryProperties.rect]); } } Rect bounds; @@ -2823,8 +2591,7 @@ class PdfFieldHelper { y = y - bounds.height; } } - bounds = Rect.fromLTWH( - bounds.left, y <= 0 ? bounds.top : y, bounds.width, bounds.height); + bounds = Rect.fromLTWH(bounds.left, y <= 0 ? bounds.top : y, bounds.width, bounds.height); } else { bounds = Rect.zero; } @@ -2836,8 +2603,7 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); PdfColor c = PdfColor.empty; if (widget.containsKey(PdfDictionaryProperties.mk)) { - final IPdfPrimitive? bs = - crossTable!.getObject(widget[PdfDictionaryProperties.mk]); + final IPdfPrimitive? bs = crossTable!.getObject(widget[PdfDictionaryProperties.mk]); if (bs is PdfDictionary) { IPdfPrimitive? array; if (bs.containsKey(PdfDictionaryProperties.bg)) { @@ -2865,20 +2631,15 @@ class PdfFieldHelper { case 1: color = (colors[0] > 0.0) && (colors[0] <= 1.0) ? PdfColorHelper.fromGray(colors[0]) - : PdfColorHelper.fromGray( - colors[0].toInt().toUnsigned(8).toDouble()); + : PdfColorHelper.fromGray(colors[0].toInt().toUnsigned(8).toDouble()); break; case 3: color = ((colors[0] > 0.0) && (colors[0] <= 1.0)) || ((colors[1] > 0.0) && (colors[1] <= 1.0)) || ((colors[2] > 0.0) && (colors[2] <= 1.0)) - ? PdfColor( - (colors[0] * 255).toInt().toUnsigned(8), - (colors[1] * 255).toInt().toUnsigned(8), - (colors[2] * 255).toInt().toUnsigned(8)) - : PdfColor( - colors[0].toInt().toUnsigned(8), - colors[1].toInt().toUnsigned(8), + ? PdfColor((colors[0] * 255).toInt().toUnsigned(8), + (colors[1] * 255).toInt().toUnsigned(8), (colors[2] * 255).toInt().toUnsigned(8)) + : PdfColor(colors[0].toInt().toUnsigned(8), colors[1].toInt().toUnsigned(8), colors[2].toInt().toUnsigned(8)); break; case 4: @@ -2902,9 +2663,8 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); if (widget.containsKey(PdfDictionaryProperties.mk)) { final PdfDictionary mk = (crossTable != null - ? crossTable!.getObject(widget[PdfDictionaryProperties.mk]) - : PdfCrossTable.dereference(widget[PdfDictionaryProperties.mk]))! - as PdfDictionary; + ? crossTable!.getObject(widget[PdfDictionaryProperties.mk]) + : PdfCrossTable.dereference(widget[PdfDictionaryProperties.mk]))! as PdfDictionary; final PdfArray array = PdfColorHelper.toArray(value!); mk[PdfDictionaryProperties.bg] = array; } else { @@ -2919,8 +2679,7 @@ class PdfFieldHelper { /// internal method void assignBorderColor(PdfColor borderColor) { if (dictionary!.containsKey(PdfDictionaryProperties.kids)) { - final IPdfPrimitive? kids = - crossTable!.getObject(dictionary![PdfDictionaryProperties.kids]); + final IPdfPrimitive? kids = crossTable!.getObject(dictionary![PdfDictionaryProperties.kids]); if (kids != null && kids is PdfArray) { for (int i = 0; i < kids.count; i++) { final IPdfPrimitive? widget = PdfCrossTable.dereference(kids[i]); @@ -2928,8 +2687,7 @@ class PdfFieldHelper { if (widget.containsKey(PdfDictionaryProperties.mk)) { final IPdfPrimitive? mk = crossTable != null ? crossTable!.getObject(widget[PdfDictionaryProperties.mk]) - : PdfCrossTable.dereference( - widget[PdfDictionaryProperties.mk]); + : PdfCrossTable.dereference(widget[PdfDictionaryProperties.mk]); if (mk != null && mk is PdfDictionary) { final PdfArray array = PdfColorHelper.toArray(borderColor); if (PdfColorHelper.getHelper(borderColor).alpha == 0) { @@ -2981,14 +2739,12 @@ class PdfFieldHelper { int _obtainBorderWidth() { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); int width = 0; - final IPdfPrimitive? name = - crossTable!.getObject(widget[PdfDictionaryProperties.ft]); + final IPdfPrimitive? name = crossTable!.getObject(widget[PdfDictionaryProperties.ft]); if (widget.containsKey(PdfDictionaryProperties.bs)) { width = 1; - final PdfDictionary bs = crossTable! - .getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; - final IPdfPrimitive? number = - crossTable!.getObject(bs[PdfDictionaryProperties.w]); + final PdfDictionary bs = + crossTable!.getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; + final IPdfPrimitive? number = crossTable!.getObject(bs[PdfDictionaryProperties.w]); if (number != null && number is PdfNumber) { width = number.value!.toInt(); } @@ -3002,24 +2758,22 @@ class PdfFieldHelper { final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); if (widget.containsKey(PdfDictionaryProperties.bs)) { if (widget[PdfDictionaryProperties.bs] is PdfReferenceHolder) { - final PdfDictionary widgetDict = crossTable! - .getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; + final PdfDictionary widgetDict = + crossTable!.getObject(widget[PdfDictionaryProperties.bs])! as PdfDictionary; if (widgetDict.containsKey(PdfDictionaryProperties.w)) { widgetDict[PdfDictionaryProperties.w] = PdfNumber(width); } else { widgetDict.setProperty(PdfDictionaryProperties.w, PdfNumber(width)); } } else { - (widget[PdfDictionaryProperties.bs]! - as PdfDictionary)[PdfDictionaryProperties.w] = PdfNumber(width); + (widget[PdfDictionaryProperties.bs]! as PdfDictionary)[PdfDictionaryProperties.w] = + PdfNumber(width); } _createBorderPen(); } else { if (!widget.containsKey(PdfDictionaryProperties.bs)) { - widget.setProperty( - PdfDictionaryProperties.bs, - PdfAnnotationBorderHelper.getHelper(this.widget!.widgetBorder!) - .dictionary); + widget.setProperty(PdfDictionaryProperties.bs, + PdfAnnotationBorderHelper.getHelper(this.widget!.widgetBorder!).dictionary); (widget[PdfDictionaryProperties.bs]! as PdfDictionary) .setProperty(PdfDictionaryProperties.w, PdfNumber(width)); _createBorderPen(); @@ -3030,8 +2784,7 @@ class PdfFieldHelper { //Creates the border pen. void _createBorderPen() { final double width = widget!.widgetBorder!.width; - borderPen = PdfPen( - WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor, + borderPen = PdfPen(WidgetAnnotationHelper.getHelper(widget!).widgetAppearance!.borderColor, width: width); if (widget!.widgetBorder!.borderStyle == PdfBorderStyle.dashed || widget!.widgetBorder!.borderStyle == PdfBorderStyle.dot) { @@ -3053,17 +2806,14 @@ class PdfFieldHelper { if (kids != null && kids is PdfArray) { for (int i = 0; i < kids.count; i++) { final IPdfPrimitive? kidsReferenceHolder = kids.elements[i]; - if (kidsReferenceHolder != null && - kidsReferenceHolder is PdfReferenceHolder) { + if (kidsReferenceHolder != null && kidsReferenceHolder is PdfReferenceHolder) { final IPdfPrimitive? widgetAnnot = kidsReferenceHolder.object; if (widgetAnnot != null && widgetAnnot is PdfDictionary && !widgetAnnot.containsKey(PdfDictionaryProperties.tu)) { - final IPdfPrimitive? toolTip = - dictionary![PdfDictionaryProperties.tu]; + final IPdfPrimitive? toolTip = dictionary![PdfDictionaryProperties.tu]; if (toolTip != null && toolTip is PdfString) { - widgetAnnot.setString( - PdfDictionaryProperties.tu, toolTip.value); + widgetAnnot.setString(PdfDictionaryProperties.tu, toolTip.value); } } } @@ -3073,8 +2823,8 @@ class PdfFieldHelper { } /// Gets the value. - static IPdfPrimitive? getValue(PdfDictionary dictionary, - PdfCrossTable? crossTable, String value, bool inheritable) { + static IPdfPrimitive? getValue( + PdfDictionary dictionary, PdfCrossTable? crossTable, String value, bool inheritable) { IPdfPrimitive? primitive; if (dictionary.containsKey(value)) { primitive = crossTable!.getObject(dictionary[value]); @@ -3094,8 +2844,7 @@ class PdfFieldHelper { primitive = crossTable!.getObject(dic[value]); } else { dic = dic.containsKey(PdfDictionaryProperties.parent) - ? (crossTable!.getObject(dic[PdfDictionaryProperties.parent]) - as PdfDictionary?)! + ? (crossTable!.getObject(dic[PdfDictionaryProperties.parent]) as PdfDictionary?)! : null; } } @@ -3119,8 +2868,7 @@ class GraphicsProperties { if ((!field._fieldHelper.isLoadedField) && field.page != null && field.page!.rotation != PdfPageRotateAngle.rotateAngle0) { - bounds = - _rotateTextbox(field.bounds, field.page!.size, field.page!.rotation); + bounds = _rotateTextbox(field.bounds, field.page!.size, field.page!.rotation); } } @@ -3139,8 +2887,7 @@ class GraphicsProperties { if ((!helper.field._fieldHelper.isLoadedField) && item.page != null && item.page!.rotation != PdfPageRotateAngle.rotateAngle0) { - bounds = - _rotateTextbox(item.bounds, item.page!.size, item.page!.rotation); + bounds = _rotateTextbox(item.bounds, item.page!.size, item.page!.rotation); } } @@ -3180,12 +2927,12 @@ class GraphicsProperties { size.height - rect.top - rect.height, rect.width, rect.height); } if (angle == PdfPageRotateAngle.rotateAngle270) { - rectangle = Rect.fromLTWH(rect.top, size!.width - rect.left - rect.width, - rect.height, rect.width); + rectangle = + Rect.fromLTWH(rect.top, size!.width - rect.left - rect.width, rect.height, rect.width); } if (angle == PdfPageRotateAngle.rotateAngle90) { - rectangle = Rect.fromLTWH(size!.height - rect.top - rect.height, - rect.left, rect.height, rect.width); + rectangle = + Rect.fromLTWH(size!.height - rect.top - rect.height, rect.left, rect.height, rect.width); } return rectangle; } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_item.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_item.dart index 6bbfd82f1..b129761a7 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_item.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_item.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -73,15 +73,13 @@ class PdfFieldItem { final PdfDocument? doc = crosstable.document; if (doc != null && PdfDocumentHelper.getHelper(doc).isLoadedDocument) { if (_helper.dictionary!.containsKey(pName)) { - final IPdfPrimitive? pageRef = crosstable - .getObject(_helper.dictionary![PdfDictionaryProperties.p]); + final IPdfPrimitive? pageRef = + crosstable.getObject(_helper.dictionary![PdfDictionaryProperties.p]); if (pageRef != null && pageRef is PdfDictionary) { - final PdfReference widgetReference = - crosstable.getReference(_helper.dictionary); + final PdfReference widgetReference = crosstable.getReference(_helper.dictionary); for (int i = 0; i < doc.pages.count; i++) { final PdfPage loadedPage = doc.pages[i]; - final PdfArray? lAnnots = - PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); + final PdfArray? lAnnots = PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); if (lAnnots != null) { for (int i = 0; i < lAnnots.count; i++) { final IPdfPrimitive? holder = lAnnots[i]; @@ -90,21 +88,17 @@ class PdfFieldItem { holder.reference != null && holder.reference!.objNum == widgetReference.objNum && holder.reference!.genNum == widgetReference.genNum) { - _page = PdfPageCollectionHelper.getHelper(doc.pages) - .getPage(pageRef); + _page = PdfPageCollectionHelper.getHelper(doc.pages).getPage(pageRef); helper.defaultIndex = backUpIndex; return _page; } } } - if (_helper.dictionary! - .containsKey(PdfDictionaryProperties.p)) { - final IPdfPrimitive? itemPageDict = PdfCrossTable.dereference( - _helper.dictionary![PdfDictionaryProperties.p]); - final PdfDictionary pageDict = - PdfPageHelper.getHelper(loadedPage).dictionary!; - if (itemPageDict is PdfDictionary && - itemPageDict == pageDict) { + if (_helper.dictionary!.containsKey(PdfDictionaryProperties.p)) { + final IPdfPrimitive? itemPageDict = + PdfCrossTable.dereference(_helper.dictionary![PdfDictionaryProperties.p]); + final PdfDictionary pageDict = PdfPageHelper.getHelper(loadedPage).dictionary!; + if (itemPageDict is PdfDictionary && itemPageDict == pageDict) { _page = loadedPage; helper.defaultIndex = backUpIndex; return _page; @@ -115,12 +109,10 @@ class PdfFieldItem { _page = null; } } else { - final PdfReference widgetReference = - crosstable.getReference(_helper.dictionary); + final PdfReference widgetReference = crosstable.getReference(_helper.dictionary); for (int i = 0; i < doc.pages.count; i++) { final PdfPage loadedPage = doc.pages[i]; - final PdfArray? lAnnots = - PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); + final PdfArray? lAnnots = PdfPageHelper.getHelper(loadedPage).obtainAnnotations(); if (lAnnots != null) { for (int i = 0; i < lAnnots.count; i++) { final IPdfPrimitive? holder = lAnnots[i]; @@ -250,19 +242,14 @@ class PdfFieldItemHelper { bool check = false; IPdfPrimitive? state; if (dictionary!.containsKey(PdfDictionaryProperties.usageApplication)) { - state = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.usageApplication]); + state = PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.usageApplication]); } if (state == null) { final PdfFieldHelper fieldHelper = PdfFieldHelper.getHelper(field); final IPdfPrimitive? name = PdfFieldHelper.getValue( - fieldHelper.dictionary!, - fieldHelper.crossTable, - PdfDictionaryProperties.v, - false); + fieldHelper.dictionary!, fieldHelper.crossTable, PdfDictionaryProperties.v, false); if (name != null && name is PdfName) { - check = (name.name == - fieldHelper.getItemValue(dictionary!, fieldHelper.crossTable)); + check = (name.name == fieldHelper.getItemValue(dictionary!, fieldHelper.crossTable)); } } else if (state is PdfName) { check = (state.name != PdfDictionaryProperties.off); @@ -282,20 +269,18 @@ class PdfFieldItemHelper { val = PdfDictionaryProperties.yes; } fieldHelper.dictionary!.setName(PdfName(PdfDictionaryProperties.v), val); - dictionary! - .setProperty(PdfDictionaryProperties.usageApplication, PdfName(val)); + dictionary!.setProperty(PdfDictionaryProperties.usageApplication, PdfName(val)); dictionary!.setProperty(PdfDictionaryProperties.v, PdfName(val)); } else { IPdfPrimitive? v; if (fieldHelper.dictionary!.containsKey(PdfDictionaryProperties.v)) { - v = PdfCrossTable.dereference( - fieldHelper.dictionary![PdfDictionaryProperties.v]); + v = PdfCrossTable.dereference(fieldHelper.dictionary![PdfDictionaryProperties.v]); } if (v != null && v is PdfName && val == v.name) { fieldHelper.dictionary!.remove(PdfDictionaryProperties.v); } - dictionary!.setProperty(PdfDictionaryProperties.usageApplication, - PdfName(PdfDictionaryProperties.off)); + dictionary!.setProperty( + PdfDictionaryProperties.usageApplication, PdfName(PdfDictionaryProperties.off)); } fieldHelper.changed = true; } @@ -312,8 +297,7 @@ class PdfFieldItemHelper { final PdfFieldItem item = items[i]; if (item != fieldItem && item is PdfCheckBoxItem) { final String? val = fieldHelper.getItemValue( - PdfFieldItemHelper.getHelper(item).dictionary!, - fieldHelper.crossTable); + PdfFieldItemHelper.getHelper(item).dictionary!, fieldHelper.crossTable); final bool v = val != null && val == value; if (v && check) { item.checked = true; @@ -340,8 +324,7 @@ class PdfCheckBoxItem extends PdfFieldItem { if (!_helper.field.readOnly) { if (value != checked) { _helper.setCheckedStatus(value); - PdfFormHelper.getHelper(_helper.field.form!).setAppearanceDictionary = - true; + PdfFormHelper.getHelper(_helper.field.form!).setAppearanceDictionary = true; } } } @@ -377,8 +360,7 @@ class PdfCheckBoxItem extends PdfFieldItem { if (widgetDict.containsKey(PdfDictionaryProperties.ca)) { widgetDict[PdfDictionaryProperties.ca] = PdfString(style); } else { - widgetDict.setProperty( - PdfDictionaryProperties.ca, PdfString(style)); + widgetDict.setProperty(PdfDictionaryProperties.ca, PdfString(style)); } } } else if (mk is PdfDictionary) { @@ -397,8 +379,7 @@ class PdfCheckBoxItemHelper { } /// internal method - static PdfCheckBoxItem getItem( - PdfField field, int index, PdfDictionary? dictionary) { + static PdfCheckBoxItem getItem(PdfField field, int index, PdfDictionary? dictionary) { return PdfCheckBoxItem._(field, index, dictionary); } } @@ -412,8 +393,7 @@ class PdfTextBoxItem extends PdfFieldItem { /// [PdfTextBoxItem] helper class PdfTextBoxItemHelper { /// internal method - static PdfTextBoxItem getItem( - PdfField field, int index, PdfDictionary? dictionary) { + static PdfTextBoxItem getItem(PdfField field, int index, PdfDictionary? dictionary) { return PdfTextBoxItem._(field, index, dictionary); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_painter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_painter.dart index 0f81f6eb2..d176a6246 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_painter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_field_painter.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../annotations/enum.dart'; import '../annotations/pdf_paintparams.dart'; @@ -27,22 +27,16 @@ class FieldPainter { //Implementations /// Draws a rectangular control. void drawRectangularControl(PdfGraphics graphics, PaintParams params) { - graphics.drawRectangle( - bounds: params.bounds ?? Rect.zero, brush: params.backBrush); - drawBorder(graphics, params.bounds, params.borderPen, params.style, - params.borderWidth); + graphics.drawRectangle(bounds: params.bounds ?? Rect.zero, brush: params.backBrush); + drawBorder(graphics, params.bounds, params.borderPen, params.style, params.borderWidth); switch (params.style) { case PdfBorderStyle.inset: - drawLeftTopShadow( - graphics, params.bounds!, params.borderWidth!, PdfBrushes.gray); - drawRightBottomShadow( - graphics, params.bounds!, params.borderWidth!, PdfBrushes.silver); + drawLeftTopShadow(graphics, params.bounds!, params.borderWidth!, PdfBrushes.gray); + drawRightBottomShadow(graphics, params.bounds!, params.borderWidth!, PdfBrushes.silver); break; case PdfBorderStyle.beveled: - drawLeftTopShadow( - graphics, params.bounds!, params.borderWidth!, PdfBrushes.white); - drawRightBottomShadow( - graphics, params.bounds!, params.borderWidth!, params.shadowBrush); + drawLeftTopShadow(graphics, params.bounds!, params.borderWidth!, PdfBrushes.white); + drawRightBottomShadow(graphics, params.bounds!, params.borderWidth!, params.shadowBrush); break; // ignore: no_default_cases default: @@ -51,16 +45,15 @@ class FieldPainter { } /// internal method - void drawCheckBox(PdfGraphics g, PaintParams paintParams, String checkSymbol, - PdfCheckFieldState state, + void drawCheckBox( + PdfGraphics g, PaintParams paintParams, String checkSymbol, PdfCheckFieldState state, [PdfFont? font]) { switch (state) { case PdfCheckFieldState.unchecked: case PdfCheckFieldState.checked: if (paintParams.borderPen != null && PdfColorHelper.getHelper(paintParams.borderPen!.color).alpha != 0) { - g.drawRectangle( - brush: paintParams.backBrush, bounds: paintParams.bounds!); + g.drawRectangle(brush: paintParams.backBrush, bounds: paintParams.bounds!); } break; @@ -69,40 +62,33 @@ class FieldPainter { if ((paintParams.style == PdfBorderStyle.beveled) || (paintParams.style == PdfBorderStyle.underline)) { if (paintParams.borderPen != null && - PdfColorHelper.getHelper(paintParams.borderPen!.color).alpha != - 0) { - g.drawRectangle( - brush: paintParams.backBrush, bounds: paintParams.bounds!); + PdfColorHelper.getHelper(paintParams.borderPen!.color).alpha != 0) { + g.drawRectangle(brush: paintParams.backBrush, bounds: paintParams.bounds!); } } else { if (paintParams.borderPen != null && - PdfColorHelper.getHelper(paintParams.borderPen!.color).alpha != - 0) { - g.drawRectangle( - brush: paintParams.shadowBrush, bounds: paintParams.bounds!); + PdfColorHelper.getHelper(paintParams.borderPen!.color).alpha != 0) { + g.drawRectangle(brush: paintParams.shadowBrush, bounds: paintParams.bounds!); } } break; } - drawBorder(g, paintParams.bounds, paintParams.borderPen, paintParams.style, - paintParams.borderWidth); + drawBorder( + g, paintParams.bounds, paintParams.borderPen, paintParams.style, paintParams.borderWidth); if ((state == PdfCheckFieldState.pressedChecked) || (state == PdfCheckFieldState.pressedUnchecked)) { switch (paintParams.style) { case PdfBorderStyle.inset: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - PdfBrushes.black); - drawRightBottomShadow(g, paintParams.bounds!, - paintParams.borderWidth!, PdfBrushes.white); + drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.black); + drawRightBottomShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.white); break; case PdfBorderStyle.beveled: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - paintParams.shadowBrush); - drawRightBottomShadow(g, paintParams.bounds!, - paintParams.borderWidth!, PdfBrushes.white); + drawLeftTopShadow( + g, paintParams.bounds!, paintParams.borderWidth!, paintParams.shadowBrush); + drawRightBottomShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.white); break; // ignore: no_default_cases default: @@ -110,17 +96,15 @@ class FieldPainter { } else { switch (paintParams.style) { case PdfBorderStyle.inset: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - PdfBrushes.gray); - drawRightBottomShadow(g, paintParams.bounds!, - paintParams.borderWidth!, PdfBrushes.silver); + drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.gray); + drawRightBottomShadow( + g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.silver); break; case PdfBorderStyle.beveled: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - PdfBrushes.white); - drawRightBottomShadow(g, paintParams.bounds!, - paintParams.borderWidth!, paintParams.shadowBrush); + drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.white); + drawRightBottomShadow( + g, paintParams.bounds!, paintParams.borderWidth!, paintParams.shadowBrush); break; // ignore: no_default_cases default: @@ -132,17 +116,15 @@ class FieldPainter { case PdfCheckFieldState.pressedChecked: case PdfCheckFieldState.checked: if (font == null) { - final bool extraBorder = - paintParams.style == PdfBorderStyle.beveled || - paintParams.style == PdfBorderStyle.inset; + final bool extraBorder = paintParams.style == PdfBorderStyle.beveled || + paintParams.style == PdfBorderStyle.inset; double borderWidth = paintParams.borderWidth!.toDouble(); if (extraBorder) { borderWidth *= 2; } - double xPosition = extraBorder - ? 2.0 * paintParams.borderWidth! - : paintParams.borderWidth!.toDouble(); + double xPosition = + extraBorder ? 2.0 * paintParams.borderWidth! : paintParams.borderWidth!.toDouble(); xPosition = max(xPosition, 1); final double xOffset = min(borderWidth, xPosition); @@ -164,19 +146,14 @@ class FieldPainter { } if (size < font.size) { - ArgumentError.value( - 'Font size cannot be greater than CheckBox height'); + ArgumentError.value('Font size cannot be greater than CheckBox height'); } g.drawString(checkSymbol, font, brush: paintParams.foreBrush, - bounds: Rect.fromLTWH( - paintParams.bounds!.left, - paintParams.bounds!.top - yOffset, - paintParams.bounds!.width, - paintParams.bounds!.height), + bounds: Rect.fromLTWH(paintParams.bounds!.left, paintParams.bounds!.top - yOffset, + paintParams.bounds!.width, paintParams.bounds!.height), format: PdfStringFormat( - alignment: PdfTextAlignment.center, - lineAlignment: PdfVerticalAlignment.middle)); + alignment: PdfTextAlignment.center, lineAlignment: PdfVerticalAlignment.middle)); break; // ignore: no_default_cases default: @@ -184,33 +161,28 @@ class FieldPainter { } /// Draws a border. - void drawBorder(PdfGraphics graphics, Rect? bounds, PdfPen? borderPen, - PdfBorderStyle? style, int? borderWidth) { + void drawBorder(PdfGraphics graphics, Rect? bounds, PdfPen? borderPen, PdfBorderStyle? style, + int? borderWidth) { if (borderPen != null) { if (borderWidth! > 0 && !borderPen.color.isEmpty) { if (style == PdfBorderStyle.underline) { graphics.drawLine( borderPen, - Offset( - bounds!.left, bounds.top + bounds.height - borderWidth / 2), - Offset(bounds.left + bounds.width, - bounds.top + bounds.height - borderWidth / 2)); + Offset(bounds!.left, bounds.top + bounds.height - borderWidth / 2), + Offset(bounds.left + bounds.width, bounds.top + bounds.height - borderWidth / 2)); } else { graphics.drawRectangle( pen: borderPen, - bounds: Rect.fromLTWH( - bounds!.left + borderWidth / 2, - bounds.top + borderWidth / 2, - bounds.width - borderWidth, - bounds.height - borderWidth)); + bounds: Rect.fromLTWH(bounds!.left + borderWidth / 2, bounds.top + borderWidth / 2, + bounds.width - borderWidth, bounds.height - borderWidth)); } } } } /// internal method - void drawRadioButton(PdfGraphics? g, PaintParams paintParams, - String checkSymbol, PdfCheckFieldState state) { + void drawRadioButton( + PdfGraphics? g, PaintParams paintParams, String checkSymbol, PdfCheckFieldState state) { //if the symbol is not a circle type ("l") then we need to draw the checkbox appearance if (checkSymbol != 'l') { drawCheckBox(g!, paintParams, checkSymbol, state); @@ -232,8 +204,7 @@ class FieldPainter { break; } - drawRoundBorder(g, paintParams.bounds, paintParams.borderPen, - paintParams.borderWidth); + drawRoundBorder(g, paintParams.bounds, paintParams.borderPen, paintParams.borderWidth); drawRoundShadow(g, paintParams, state); switch (state) { case PdfCheckFieldState.checked: @@ -249,8 +220,7 @@ class FieldPainter { checkedBounds.top + (outward.width / 4), checkedBounds.width - (outward.width / 2), checkedBounds.height - (outward.width / 2)); - g.drawEllipse(checkedBounds, - brush: paintParams.foreBrush ?? PdfBrushes.black); + g.drawEllipse(checkedBounds, brush: paintParams.foreBrush ?? PdfBrushes.black); break; // ignore: no_default_cases default: @@ -260,8 +230,7 @@ class FieldPainter { } /// Draws the left top shadow. - void drawLeftTopShadow( - PdfGraphics graphics, Rect bounds, int width, PdfBrush? brush) { + void drawLeftTopShadow(PdfGraphics graphics, Rect bounds, int width, PdfBrush? brush) { final List points = [ Offset(bounds.left + width, bounds.top + width), Offset(bounds.left + width, bounds.bottom - width), @@ -274,8 +243,7 @@ class FieldPainter { } /// Draws the right bottom shadow. - void drawRightBottomShadow( - PdfGraphics graphics, Rect bounds, int width, PdfBrush? brush) { + void drawRightBottomShadow(PdfGraphics graphics, Rect bounds, int width, PdfBrush? brush) { final List points = [ Offset(bounds.left + width, bounds.bottom - width), Offset(bounds.left + 2 * width, bounds.bottom - 2 * width), @@ -288,80 +256,68 @@ class FieldPainter { } /// internal method - void drawButton(PdfGraphics g, PaintParams paintParams, String text, - PdfFont font, PdfStringFormat? format) { + void drawButton( + PdfGraphics g, PaintParams paintParams, String text, PdfFont font, PdfStringFormat? format) { drawRectangularControl(g, paintParams); final Rect? rectangle = paintParams.bounds; - g.drawString(text, font, - brush: paintParams.foreBrush, bounds: rectangle, format: format); + g.drawString(text, font, brush: paintParams.foreBrush, bounds: rectangle, format: format); } /// internal method - void drawPressedButton(PdfGraphics g, PaintParams paintParams, String text, - PdfFont font, PdfStringFormat? format) { + void drawPressedButton( + PdfGraphics g, PaintParams paintParams, String text, PdfFont font, PdfStringFormat? format) { switch (paintParams.style) { case PdfBorderStyle.inset: - g.drawRectangle( - brush: paintParams.shadowBrush, bounds: paintParams.bounds!); + g.drawRectangle(brush: paintParams.shadowBrush, bounds: paintParams.bounds!); break; // ignore: no_default_cases default: - g.drawRectangle( - brush: paintParams.backBrush, bounds: paintParams.bounds!); + g.drawRectangle(brush: paintParams.backBrush, bounds: paintParams.bounds!); break; } - drawBorder(g, paintParams.bounds, paintParams.borderPen, paintParams.style, - paintParams.borderWidth); + drawBorder( + g, paintParams.bounds, paintParams.borderPen, paintParams.style, paintParams.borderWidth); final Rect rectangle = Rect.fromLTWH( paintParams.borderWidth!.toDouble(), paintParams.borderWidth!.toDouble(), paintParams.bounds!.size.width - paintParams.borderWidth!, paintParams.bounds!.size.height - paintParams.borderWidth!); - g.drawString(text, font, - brush: paintParams.foreBrush, bounds: rectangle, format: format); + g.drawString(text, font, brush: paintParams.foreBrush, bounds: rectangle, format: format); switch (paintParams.style) { case PdfBorderStyle.inset: - drawLeftTopShadow( - g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.gray); - drawRightBottomShadow(g, paintParams.bounds!, paintParams.borderWidth!, - PdfBrushes.silver); + drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.gray); + drawRightBottomShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.silver); break; case PdfBorderStyle.beveled: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - paintParams.shadowBrush); - drawRightBottomShadow( - g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.white); + drawLeftTopShadow( + g, paintParams.bounds!, paintParams.borderWidth!, paintParams.shadowBrush); + drawRightBottomShadow(g, paintParams.bounds!, paintParams.borderWidth!, PdfBrushes.white); break; // ignore: no_default_cases default: - drawLeftTopShadow(g, paintParams.bounds!, paintParams.borderWidth!, - paintParams.shadowBrush); + drawLeftTopShadow( + g, paintParams.bounds!, paintParams.borderWidth!, paintParams.shadowBrush); break; } } /// internal method - void drawRoundBorder( - PdfGraphics? g, Rect? bounds, PdfPen? borderPen, int? borderWidth) { + void drawRoundBorder(PdfGraphics? g, Rect? bounds, PdfPen? borderPen, int? borderWidth) { Rect? outward = bounds; if (outward != Rect.zero) { - outward = Rect.fromLTWH( - bounds!.left + borderWidth! / 2.0, - bounds.top + borderWidth / 2.0, - bounds.width - borderWidth, - bounds.height - borderWidth); + outward = Rect.fromLTWH(bounds!.left + borderWidth! / 2.0, bounds.top + borderWidth / 2.0, + bounds.width - borderWidth, bounds.height - borderWidth); g!.drawEllipse(outward, pen: borderPen); } } /// internal method - void drawRoundShadow( - PdfGraphics? g, PaintParams paintParams, PdfCheckFieldState state) { + void drawRoundShadow(PdfGraphics? g, PaintParams paintParams, PdfCheckFieldState state) { final double borderWidth = paintParams.borderWidth!.toDouble(); final Rect rectangle = paintParams.bounds!; rectangle.inflate(-1.5 * borderWidth); @@ -376,8 +332,7 @@ class FieldPainter { case PdfCheckFieldState.pressedChecked: case PdfCheckFieldState.pressedUnchecked: leftTopPen = PdfPen(shadowColor, width: borderWidth); - rightBottomPen = - PdfPen(PdfColor(255, 255, 255), width: borderWidth); + rightBottomPen = PdfPen(PdfColor(255, 255, 255), width: borderWidth); break; case PdfCheckFieldState.checked: @@ -398,10 +353,8 @@ class FieldPainter { case PdfCheckFieldState.checked: case PdfCheckFieldState.unchecked: - leftTopPen = - PdfPen(PdfColor(255, 128, 128, 128), width: borderWidth); - rightBottomPen = - PdfPen(PdfColor(255, 192, 192, 192), width: borderWidth); + leftTopPen = PdfPen(PdfColor(255, 128, 128, 128), width: borderWidth); + rightBottomPen = PdfPen(PdfColor(255, 192, 192, 192), width: borderWidth); break; } break; @@ -415,8 +368,8 @@ class FieldPainter { } /// Draws the combo box - void drawComboBox(PdfGraphics graphics, PaintParams paintParams, String? text, - PdfFont? font, PdfStringFormat? format) { + void drawComboBox(PdfGraphics graphics, PaintParams paintParams, String? text, PdfFont? font, + PdfStringFormat? format) { drawRectangularControl(graphics, paintParams); final Rect? rectangle = paintParams.bounds; graphics.drawString(text!, font!, @@ -424,25 +377,18 @@ class FieldPainter { } /// Draws the list box - void drawListBox( - PdfGraphics graphics, - PaintParams params, - PdfListFieldItemCollection items, - List selectedItem, - PdfFont font, - PdfStringFormat? stringFormat) { + void drawListBox(PdfGraphics graphics, PaintParams params, PdfListFieldItemCollection items, + List selectedItem, PdfFont font, PdfStringFormat? stringFormat) { FieldPainter().drawRectangularControl(graphics, params); for (int index = 0; index < items.count; index++) { final PdfListFieldItem item = items[index]; final int borderWidth = params.borderWidth!; final double doubleBorderWidth = (2 * borderWidth).toDouble(); - final bool padding = params.style == PdfBorderStyle.inset || - params.style == PdfBorderStyle.beveled; + final bool padding = + params.style == PdfBorderStyle.inset || params.style == PdfBorderStyle.beveled; final Offset point = padding - ? Offset(2 * doubleBorderWidth, - (index + 2) * borderWidth + font.size * index) - : Offset( - doubleBorderWidth, (index + 1) * borderWidth + font.size * index); + ? Offset(2 * doubleBorderWidth, (index + 2) * borderWidth + font.size * index) + : Offset(doubleBorderWidth, (index + 1) * borderWidth + font.size * index); PdfBrush? brush = params.foreBrush; double width = params.bounds!.width - doubleBorderWidth; final Rect rectangle = Rect.fromLTWH( @@ -465,8 +411,7 @@ class FieldPainter { } brush = PdfSolidBrush(PdfColor(51, 153, 255)); graphics.drawRectangle( - brush: brush, - bounds: Rect.fromLTWH(x, point.dy, width, font.height)); + brush: brush, bounds: Rect.fromLTWH(x, point.dy, width, font.height)); brush = PdfSolidBrush(PdfColor(255, 255, 255)); } final String value = item.text; @@ -480,15 +425,13 @@ class FieldPainter { } /// Draws the text box - void drawTextBox(PdfGraphics graphics, PaintParams params, String text, - PdfFont font, PdfStringFormat format, bool insertSpaces, bool multiline) { + void drawTextBox(PdfGraphics graphics, PaintParams params, String text, PdfFont font, + PdfStringFormat format, bool insertSpaces, bool multiline) { if (!insertSpaces) { FieldPainter().drawRectangularControl(graphics, params); } - final int multiplier = params.style == PdfBorderStyle.beveled || - params.style == PdfBorderStyle.inset - ? 2 - : 1; + final int multiplier = + params.style == PdfBorderStyle.beveled || params.style == PdfBorderStyle.inset ? 2 : 1; Rect rectangle = Rect.fromLTWH( params.bounds!.left + (2 * multiplier) * params.borderWidth!, params.bounds!.top + (2 * multiplier) * params.borderWidth!, @@ -496,34 +439,26 @@ class FieldPainter { params.bounds!.height - (4 * multiplier) * params.borderWidth!); // Calculate position of the text. if (multiline) { - final double tempHeight = - format.lineSpacing == 0 ? font.height : format.lineSpacing; - final bool subScript = - format.subSuperscript == PdfSubSuperscript.subscript; - final double ascent = - PdfFontHelper.getHelper(font).metrics!.getAscent(format); - final double descent = - PdfFontHelper.getHelper(font).metrics!.getDescent(format); - final double shift = subScript - ? tempHeight - (font.height + descent) - : tempHeight - ascent; + final double tempHeight = format.lineSpacing == 0 ? font.height : format.lineSpacing; + final bool subScript = format.subSuperscript == PdfSubSuperscript.subscript; + final double ascent = PdfFontHelper.getHelper(font).metrics!.getAscent(format); + final double descent = PdfFontHelper.getHelper(font).metrics!.getDescent(format); + final double shift = subScript ? tempHeight - (font.height + descent) : tempHeight - ascent; if (rectangle.left == 0 && rectangle.top == 0) { - rectangle = Rect.fromLTWH(rectangle.left, -(rectangle.top - shift), - rectangle.width, rectangle.height); + rectangle = Rect.fromLTWH( + rectangle.left, -(rectangle.top - shift), rectangle.width, rectangle.height); } graphics.drawString(text, font, brush: params.foreBrush, bounds: rectangle, - format: PdfStringFormat( - alignment: format.alignment, lineAlignment: format.lineAlignment) + format: PdfStringFormat(alignment: format.alignment, lineAlignment: format.lineAlignment) ..lineLimit = false); } else { graphics.drawString(text, font, brush: params.foreBrush, bounds: rectangle, format: PdfStringFormat( - alignment: format.alignment, - lineAlignment: PdfVerticalAlignment.middle) + alignment: format.alignment, lineAlignment: PdfVerticalAlignment.middle) ..lineLimit = false); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_box_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_box_field.dart index 638f1a200..f508bb835 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_box_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_box_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -104,8 +104,7 @@ class PdfListBoxField extends PdfListField { /// Otherwise only the first index in the collection will be selected. List get selectedIndexes => _helper.selectedIndexes; set selectedIndexes(List value) { - _helper.selectedIndexes = - multiSelect || value.isEmpty ? value : [value[0]]; + _helper.selectedIndexes = multiSelect || value.isEmpty ? value : [value[0]]; } /// Gets or sets the selected values in the list. @@ -114,8 +113,7 @@ class PdfListBoxField extends PdfListField { /// Otherwise only the first value in the collection will be selected. List get selectedValues => _helper.selectedValues; set selectedValues(List value) { - _helper.selectedValues = - multiSelect || value.isEmpty ? value : [value[0]]; + _helper.selectedValues = multiSelect || value.isEmpty ? value : [value[0]]; } /// Gets the selected items in the list. @@ -140,8 +138,7 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { void drawAppearance(PdfTemplate template) { super.drawAppearance(template); final PaintParams params = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, listBoxField.bounds.width, listBoxField.bounds.height), + bounds: Rect.fromLTWH(0, 0, listBoxField.bounds.width, listBoxField.bounds.height), backBrush: backBrush, foreBrush: foreBrush, borderPen: borderPen, @@ -151,20 +148,17 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { PdfFont font; if (listBoxField.font == null) { if (PdfPageHelper.getHelper(listBoxField.page!).document != null && - PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(listBoxField.page!).document!) + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(listBoxField.page!).document!) .conformanceLevel != PdfConformanceLevel.none) { - throw ArgumentError( - 'Font data is not embedded to the conformance PDF.'); + throw ArgumentError('Font data is not embedded to the conformance PDF.'); } - font = PdfStandardFont( - PdfFontFamily.timesRoman, getFontHeight(PdfFontFamily.timesRoman)); + font = PdfStandardFont(PdfFontFamily.timesRoman, getFontHeight(PdfFontFamily.timesRoman)); } else { font = listBoxField.font!; } - FieldPainter().drawListBox(template.graphics!, params, listBoxField.items, - selectedIndexes, font, format); + FieldPainter() + .drawListBox(template.graphics!, params, listBoxField.items, selectedIndexes, font, format); } /// internal method @@ -173,14 +167,13 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { super.draw(); if (!isLoadedField) { if (PdfAnnotationHelper.getHelper(widget!).appearance != null) { - listBoxField.page!.graphics.drawPdfTemplate( - widget!.appearance.normal, listBoxField.bounds.topLeft); + listBoxField.page!.graphics + .drawPdfTemplate(widget!.appearance.normal, listBoxField.bounds.topLeft); } else { - final Rect rect = Rect.fromLTWH( - 0, 0, listBoxField.bounds.width, listBoxField.bounds.height); + final Rect rect = + Rect.fromLTWH(0, 0, listBoxField.bounds.width, listBoxField.bounds.height); final PdfFont font = listBoxField.font ?? - PdfStandardFont(PdfFontFamily.helvetica, - getFontHeight(PdfFontFamily.helvetica)); + PdfStandardFont(PdfFontFamily.helvetica, getFontHeight(PdfFontFamily.helvetica)); final PaintParams parameters = PaintParams( bounds: rect, backBrush: backBrush, @@ -190,8 +183,8 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { borderWidth: listBoxField.borderWidth, shadowBrush: shadowBrush); final PdfTemplate template = PdfTemplate(rect.width, rect.height); - FieldPainter().drawListBox(template.graphics!, parameters, - listBoxField.items, listBoxField.selectedIndexes, font, format); + FieldPainter().drawListBox(template.graphics!, parameters, listBoxField.items, + listBoxField.selectedIndexes, font, format); listBoxField.page!.graphics .drawPdfTemplate(template, listBoxField.bounds.topLeft, rect.size); } @@ -199,8 +192,7 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { final PdfTemplate template = PdfTemplate(listBoxField.bounds.width, listBoxField.bounds.height); _drawListBox(template.graphics!); - listBoxField.page!.graphics - .drawPdfTemplate(template, listBoxField.bounds.topLeft); + listBoxField.page!.graphics.drawPdfTemplate(template, listBoxField.bounds.topLeft); } } @@ -214,29 +206,22 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { void _applyAppearance(PdfDictionary widget) { if (widget.containsKey(PdfDictionaryProperties.ap) && !PdfFormHelper.getHelper(listBoxField.form!).needAppearances!) { - final IPdfPrimitive? appearance = - crossTable!.getObject(widget[PdfDictionaryProperties.ap]); + final IPdfPrimitive? appearance = crossTable!.getObject(widget[PdfDictionaryProperties.ap]); if (appearance != null && appearance is PdfDictionary && appearance.containsKey(PdfDictionaryProperties.n)) { final PdfTemplate template = PdfTemplate(listBoxField.bounds.width, listBoxField.bounds.height); PdfTemplateHelper.getHelper(template).writeTransformation = false; - beginMarkupSequence(PdfGraphicsHelper.getHelper(template.graphics!) - .streamWriter! - .stream!); + beginMarkupSequence(PdfGraphicsHelper.getHelper(template.graphics!).streamWriter!.stream!); PdfGraphicsHelper.getHelper(template.graphics!).initializeCoordinates(); _drawListBox(template.graphics!); - endMarkupSequence(PdfGraphicsHelper.getHelper(template.graphics!) - .streamWriter! - .stream!); + endMarkupSequence(PdfGraphicsHelper.getHelper(template.graphics!).streamWriter!.stream!); appearance.remove(PdfDictionaryProperties.n); - appearance.setProperty( - PdfDictionaryProperties.n, PdfReferenceHolder(template)); + appearance.setProperty(PdfDictionaryProperties.n, PdfReferenceHolder(template)); widget.setProperty(PdfDictionaryProperties.ap, appearance); } - } else if (PdfFormHelper.getHelper(listBoxField.form!) - .setAppearanceDictionary && + } else if (PdfFormHelper.getHelper(listBoxField.form!).setAppearanceDictionary && !PdfFormHelper.getHelper(listBoxField.form!).needAppearances!) { final PdfDictionary dic = PdfDictionary(); final PdfTemplate template = @@ -249,8 +234,7 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { void _drawListBox(PdfGraphics graphics) { final GraphicsProperties gp = GraphicsProperties(listBoxField); - gp.bounds = Rect.fromLTWH( - 0, 0, listBoxField.bounds.width, listBoxField.bounds.height); + gp.bounds = Rect.fromLTWH(0, 0, listBoxField.bounds.width, listBoxField.bounds.height); final PaintParams prms = PaintParams( bounds: gp.bounds, backBrush: gp.backBrush, @@ -263,8 +247,8 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { !PdfFormHelper.getHelper(listBoxField.form!).flatten) { prms.backBrush = null; } - FieldPainter().drawListBox(graphics, prms, listBoxField.items, - selectedIndexes, gp.font!, gp.stringFormat); + FieldPainter().drawListBox( + graphics, prms, listBoxField.items, selectedIndexes, gp.font!, gp.stringFormat); } /// internal method @@ -275,8 +259,7 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { final PdfFont font = PdfStandardFont(family, 12); double max = font.measureString(listBoxField.items[0].text).width; for (int i = 1; i < listBoxField.items.count; ++i) { - final double temp = - font.measureString(listBoxField.items[i].text).width; + final double temp = font.measureString(listBoxField.items[i].text).width; max = (max > temp) ? max : temp; } s = (12 * (listBoxField.bounds.size.width - 4 * borderWidth)) / max; @@ -286,8 +269,7 @@ class PdfListBoxFieldHelper extends PdfListFieldHelper { } /// internal method - static PdfListBoxField loadListBox( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfListBoxField loadListBox(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfListBoxField._load(dictionary, crossTable); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_field.dart index 3a7d486f4..008a91a15 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_list_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -45,18 +45,15 @@ abstract class PdfListField extends PdfField { highlightMode: highlightMode, borderStyle: borderStyle, tooltip: tooltip); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.ch)); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.ch)); if (items != null && items.isNotEmpty) { - items - .toList() - .forEach((PdfListFieldItem element) => this.items.add(element)); + items.toList().forEach((PdfListFieldItem element) => this.items.add(element)); } } /// internal constructor - void _load(PdfDictionary dictionary, PdfCrossTable crossTable, - PdfListFieldHelper helper) { + void _load(PdfDictionary dictionary, PdfCrossTable crossTable, PdfListFieldHelper helper) { _helper = helper; _helper.load(dictionary, crossTable); } @@ -70,8 +67,7 @@ abstract class PdfListField extends PdfField { if (_helper._items == null) { if (!_helper.isLoadedField) { _helper._items = PdfListFieldItemCollectionHelper.itemCollection(); - _helper.dictionary! - .setProperty(PdfDictionaryProperties.opt, _helper._items); + _helper.dictionary!.setProperty(PdfDictionaryProperties.opt, _helper._items); } else { _helper._items = _getListItemCollection(); } @@ -143,27 +139,21 @@ abstract class PdfListField extends PdfField { // Gets the list item. PdfListFieldItemCollection _getListItemCollection() { - final PdfListFieldItemCollection items = - PdfListFieldItemCollectionHelper.itemCollection(this); - final IPdfPrimitive? array = PdfFieldHelper.getValue(_helper.dictionary!, - _helper.crossTable, PdfDictionaryProperties.opt, true); + final PdfListFieldItemCollection items = PdfListFieldItemCollectionHelper.itemCollection(this); + final IPdfPrimitive? array = PdfFieldHelper.getValue( + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.opt, true); if (array != null && array is PdfArray) { for (int i = 0; i < array.count; i++) { - final IPdfPrimitive? primitive = - _helper.crossTable!.getObject(array[i]); + final IPdfPrimitive? primitive = _helper.crossTable!.getObject(array[i]); PdfListFieldItem item; if (primitive is PdfString) { final PdfString str = primitive; - item = PdfListFieldItemHelper.load( - str.value, null, this, _helper.crossTable); + item = PdfListFieldItemHelper.load(str.value, null, this, _helper.crossTable); } else { final PdfArray arr = primitive! as PdfArray; - final PdfString value = - _helper.crossTable!.getObject(arr[0])! as PdfString; - final PdfString text = - _helper.crossTable!.getObject(arr[1])! as PdfString; - item = PdfListFieldItemHelper.load( - text.value, value.value, this, _helper.crossTable); + final PdfString value = _helper.crossTable!.getObject(arr[0])! as PdfString; + final PdfString text = _helper.crossTable!.getObject(arr[1])! as PdfString; + item = PdfListFieldItemHelper.load(text.value, value.value, this, _helper.crossTable); } PdfListFieldItemCollectionHelper.getHelper(items).addItem(item); } @@ -221,8 +211,7 @@ class PdfListFieldHelper extends PdfFieldHelper { } /// internal method - List get selectedIndexes => - isLoadedField ? _obtainSelectedIndex() : selectedIndex; + List get selectedIndexes => isLoadedField ? _obtainSelectedIndex() : selectedIndex; set selectedIndexes(List value) { for (final int element in value) { if (element < 0 || element >= listField.items.count) { @@ -234,8 +223,7 @@ class PdfListFieldHelper extends PdfFieldHelper { } else { if (selectedIndex != value) { selectedIndex = value; - dictionary! - .setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndex)); + dictionary!.setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndex)); } } } @@ -270,8 +258,7 @@ class PdfListFieldHelper extends PdfFieldHelper { break; } } - dictionary! - .setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndex)); + dictionary!.setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndex)); } } @@ -281,14 +268,10 @@ class PdfListFieldHelper extends PdfFieldHelper { throw ArgumentError('No item is selected.'); } final PdfListFieldItemCollection item = - PdfListFieldItemCollectionHelper.itemCollection( - isLoadedField ? listField : null); + PdfListFieldItemCollectionHelper.itemCollection(isLoadedField ? listField : null); for (final int index in selectedIndexes) { - if (index > -1 && - listField.items.count > 0 && - listField.items.count > index) { - PdfListFieldItemCollectionHelper.getHelper(item) - .addItem(listField.items[index]); + if (index > -1 && listField.items.count > 0 && listField.items.count > index) { + PdfListFieldItemCollectionHelper.getHelper(item).addItem(listField.items[index]); } } return item; @@ -297,8 +280,7 @@ class PdfListFieldHelper extends PdfFieldHelper { List _obtainSelectedIndex() { final List selectedIndex = []; if (dictionary!.containsKey(PdfDictionaryProperties.i)) { - final IPdfPrimitive? array = - crossTable!.getObject(dictionary![PdfDictionaryProperties.i]); + final IPdfPrimitive? array = crossTable!.getObject(dictionary![PdfDictionaryProperties.i]); if (array != null && array is PdfArray) { if (array.count > 0) { for (int i = 0; i < array.count; i++) { @@ -309,8 +291,7 @@ class PdfListFieldHelper extends PdfFieldHelper { } } } else { - final IPdfPrimitive? number = - crossTable!.getObject(dictionary![PdfDictionaryProperties.i]); + final IPdfPrimitive? number = crossTable!.getObject(dictionary![PdfDictionaryProperties.i]); if (number != null && number is PdfNumber) { selectedIndex.add(number.value!.toInt()); } @@ -403,8 +384,7 @@ class PdfListFieldHelper extends PdfFieldHelper { } if (selectedIndexes.isNotEmpty) { selectedIndexes.sort(); - dictionary! - .setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndexes)); + dictionary!.setProperty(PdfDictionaryProperties.i, PdfArray(selectedIndexes)); } else { dictionary!.remove(PdfDictionaryProperties.i); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_radio_button_list_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_radio_button_list_field.dart index dba208a20..7afaa7a5c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_radio_button_list_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_radio_button_list_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../general/pdf_collection.dart'; @@ -21,19 +21,16 @@ class PdfRadioButtonListField extends PdfField { /// Initializes a new instance of the [PdfRadioButtonListField] class with /// the specific page, name and bounds. PdfRadioButtonListField(PdfPage page, String name, - {List? items, - int? selectedIndex, - String? selectedValue}) { + {List? items, int? selectedIndex, String? selectedValue}) { _helper = PdfRadioButtonListFieldHelper(this); _helper.internal(page, name, Rect.zero); _initValues(items, selectedIndex, selectedValue); _helper.flags.add(FieldFlags.radio); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.btn)); } - PdfRadioButtonListField._loaded( - PdfDictionary dictionary, PdfCrossTable crossTable) { + PdfRadioButtonListField._loaded(PdfDictionary dictionary, PdfCrossTable crossTable) { _helper = PdfRadioButtonListFieldHelper(this); _helper.load(dictionary, crossTable); _retrieveOptionValue(); @@ -47,8 +44,7 @@ class PdfRadioButtonListField extends PdfField { /// Gets the items of the radio button field.{Read-Only} PdfRadioButtonItemCollection get items { if (_helper.isLoadedField) { - _items ??= _getRadioButtonListItems( - PdfRadioButtonItemCollectionHelper.getCollection(this)); + _items ??= _getRadioButtonListItems(PdfRadioButtonItemCollectionHelper.getCollection(this)); return _items!; } else { if (_items == null) { @@ -119,8 +115,7 @@ class PdfRadioButtonListField extends PdfField { _assignSelectedValue(value); _helper.changed = true; } else { - final List objects = - PdfObjectCollectionHelper.getHelper(items).list; + final List objects = PdfObjectCollectionHelper.getHelper(items).list; for (final Object? item in objects) { if (item is PdfRadioButtonListItem && item.value == value) { _helper.selectedIndex = items.indexOf(item); @@ -134,12 +129,9 @@ class PdfRadioButtonListField extends PdfField { } //Implementation - void _initValues( - List? radioItems, int? index, String? value) { + void _initValues(List? radioItems, int? index, String? value) { if (radioItems != null) { - radioItems - .toList() - .forEach((PdfRadioButtonListItem item) => items.add(item)); + radioItems.toList().forEach((PdfRadioButtonListItem item) => items.add(item)); } if (index != null) { selectedIndex = index; @@ -149,18 +141,15 @@ class PdfRadioButtonListField extends PdfField { } } - PdfRadioButtonItemCollection _getRadioButtonListItems( - PdfRadioButtonItemCollection listItems) { + PdfRadioButtonItemCollection _getRadioButtonListItems(PdfRadioButtonItemCollection listItems) { final PdfArray? fieldKids = _helper.obtainKids(); if (fieldKids != null) { for (int i = 0; i < fieldKids.count; i++) { final IPdfPrimitive? kidsDict = PdfCrossTable.dereference(fieldKids[i]); if (kidsDict != null && kidsDict is PdfDictionary) { final PdfRadioButtonListItem item = - PdfRadioButtonListItemHelper.loaded( - kidsDict, _helper.crossTable!, this); - PdfRadioButtonItemCollectionHelper.getHelper(listItems) - .doAdd(item, true); + PdfRadioButtonListItemHelper.loaded(kidsDict, _helper.crossTable!, this); + PdfRadioButtonItemCollectionHelper.getHelper(listItems).doAdd(item, true); } } } @@ -172,15 +161,14 @@ class PdfRadioButtonListField extends PdfField { for (int i = 0; i < items.count; ++i) { final PdfRadioButtonListItem item = items[i]; final PdfDictionary dic = PdfFieldHelper.getHelper(item).dictionary!; - final IPdfPrimitive? checkNamePrimitive = PdfFieldHelper.searchInParents( - dic, _helper.crossTable, PdfDictionaryProperties.v); + final IPdfPrimitive? checkNamePrimitive = + PdfFieldHelper.searchInParents(dic, _helper.crossTable, PdfDictionaryProperties.v); if (dic.containsKey(PdfDictionaryProperties.usageApplication) && (checkNamePrimitive is PdfName || checkNamePrimitive is PdfString)) { - final IPdfPrimitive? name = _helper.crossTable! - .getObject(dic[PdfDictionaryProperties.usageApplication]); + final IPdfPrimitive? name = + _helper.crossTable!.getObject(dic[PdfDictionaryProperties.usageApplication]); if (name is PdfName && name.name!.toLowerCase() != 'off') { - if (checkNamePrimitive is PdfName && - checkNamePrimitive.name!.toLowerCase() != 'off') { + if (checkNamePrimitive is PdfName && checkNamePrimitive.name!.toLowerCase() != 'off') { if (name.name == checkNamePrimitive.name) { index = i; } @@ -212,14 +200,13 @@ class PdfRadioButtonListField extends PdfField { final PdfRadioButtonListItem item = items[i]; if (item.value == name.name) { PdfFieldHelper.getHelper(item).dictionary!.setName( - PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.off); + PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.off); } } } - PdfFieldHelper.getHelper(items[value]).dictionary!.setName( - PdfName(PdfDictionaryProperties.usageApplication), - items[value].value); + PdfFieldHelper.getHelper(items[value]) + .dictionary! + .setName(PdfName(PdfDictionaryProperties.usageApplication), items[value].value); } } @@ -236,28 +223,21 @@ class PdfRadioButtonListField extends PdfField { final PdfRadioButtonListItem item = items[i]; if (item.value == PdfName.decodeName(name.name)) { PdfFieldHelper.getHelper(item).dictionary!.setName( - PdfName(PdfDictionaryProperties.usageApplication), - PdfDictionaryProperties.off); + PdfName(PdfDictionaryProperties.usageApplication), PdfDictionaryProperties.off); } } } - final List objects = - PdfObjectCollectionHelper.getHelper(items).list; + final List objects = PdfObjectCollectionHelper.getHelper(items).list; for (final Object? item in objects) { if (item is PdfRadioButtonListItem && (item.value == value || - PdfRadioButtonListItemHelper.getHelper(item).optionValue == - value)) { + PdfRadioButtonListItemHelper.getHelper(item).optionValue == value)) { _helper.selectedIndex = items.indexOf(item); - _helper.dictionary! - .setName(PdfName(PdfDictionaryProperties.v), item.value); - _helper.dictionary! - .setName(PdfName(PdfDictionaryProperties.dv), item.value); + _helper.dictionary!.setName(PdfName(PdfDictionaryProperties.v), item.value); + _helper.dictionary!.setName(PdfName(PdfDictionaryProperties.dv), item.value); final PdfFieldHelper helper = PdfFieldHelper.getHelper(item); - helper.dictionary!.setName( - PdfName(PdfDictionaryProperties.usageApplication), item.value); - helper.dictionary! - .setName(PdfName(PdfDictionaryProperties.v), item.value); + helper.dictionary!.setName(PdfName(PdfDictionaryProperties.usageApplication), item.value); + helper.dictionary!.setName(PdfName(PdfDictionaryProperties.v), item.value); break; } } @@ -265,20 +245,17 @@ class PdfRadioButtonListField extends PdfField { void _retrieveOptionValue() { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.opt)) { - final IPdfPrimitive optionArray = - _helper.dictionary![PdfDictionaryProperties.opt]!; + final IPdfPrimitive optionArray = _helper.dictionary![PdfDictionaryProperties.opt]!; final IPdfPrimitive? options = optionArray is PdfReferenceHolder ? optionArray.object : optionArray; if (options != null && options is PdfArray) { - final int count = - (options.count <= items.count) ? options.count : items.count; + final int count = (options.count <= items.count) ? options.count : items.count; for (int i = 0; i < count; i++) { final IPdfPrimitive? option = options[i] is PdfReferenceHolder ? (options[i]! as PdfReferenceHolder).object : options[i]; if (option != null && option is PdfString) { - PdfRadioButtonListItemHelper.getHelper(items[i]).optionValue = - option.value; + PdfRadioButtonListItemHelper.getHelper(items[i]).optionValue = option.value; } } } @@ -298,14 +275,12 @@ class PdfRadioButtonListFieldHelper extends PdfFieldHelper { int selectedIndex = -1; /// internal method - static PdfRadioButtonListFieldHelper getHelper( - PdfRadioButtonListField radioButtonList) { + static PdfRadioButtonListFieldHelper getHelper(PdfRadioButtonListField radioButtonList) { return radioButtonList._helper; } /// internal method - static PdfRadioButtonListField loaded( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfRadioButtonListField loaded(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfRadioButtonListField._loaded(dictionary, crossTable); } @@ -317,8 +292,7 @@ class PdfRadioButtonListFieldHelper extends PdfFieldHelper { int i = 0; if (kids != null) { for (i = 0; i < kids.count; ++i) { - final PdfDictionary? widget = - crossTable!.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? widget = crossTable!.getObject(kids[i]) as PdfDictionary?; final PdfRadioButtonListItem item = radioButtonList.items[i]; PdfCheckFieldBaseHelper.getHelper(item).applyAppearance(widget, item); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart index 85ca8e582..b90f0045e 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_signature_field.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -52,10 +52,9 @@ class PdfSignatureField extends PdfField { form!.fieldAutoNaming ? PdfAnnotationHelper.getHelper(_helper.widget!) .dictionary! - .setProperty(PdfDictionaryProperties.ft, - PdfName(PdfDictionaryProperties.sig)) - : _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)); + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)) + : _helper.dictionary! + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.sig)); if (PdfPageHelper.getHelper(page).document != null) { PdfFormHelper.getHelper(form!).signatureFlags = [ SignatureFlags.signaturesExists, @@ -65,10 +64,7 @@ class PdfSignatureField extends PdfField { if (signature != null) { this.signature = signature; } - if (borderWidth != null || - borderColor != null || - backColor != null || - borderStyle != null) { + if (borderWidth != null || borderColor != null || backColor != null || borderStyle != null) { _helper.appearance = true; } } @@ -171,23 +167,18 @@ class PdfSignatureField extends PdfField { _signature = value; PdfSignatureHelper.getHelper(_signature!).page = page; PdfSignatureHelper.getHelper(_signature!).document = - PdfPageHelper.getHelper( - PdfSignatureHelper.getHelper(_signature!).page!) - .document; + PdfPageHelper.getHelper(PdfSignatureHelper.getHelper(_signature!).page!).document; PdfSignatureHelper.getHelper(_signature!) .checkAnnotationElementsContainsSignature(page!, name); PdfSignatureHelper.getHelper(_signature!).field = this; - PdfDocumentHelper.getHelper( - PdfSignatureHelper.getHelper(_signature!).document!) - .catalog - .beginSave = - PdfSignatureHelper.getHelper(_signature!).catalogBeginSave; + PdfDocumentHelper.getHelper(PdfSignatureHelper.getHelper(_signature!).document!) + .catalog + .beginSave = PdfSignatureHelper.getHelper(_signature!).catalogBeginSave; _helper.dictionary!.beginSaveList ??= []; _helper.dictionary!.beginSaveList! .add(PdfSignatureHelper.getHelper(_signature!).dictionaryBeginSave); if (!_helper.skipKidsCertificate) { - final PdfDocument document = - PdfSignatureHelper.getHelper(_signature!).document!; + final PdfDocument document = PdfSignatureHelper.getHelper(_signature!).document!; PdfSignatureHelper.getHelper(_signature!).signatureDictionary = PdfSignatureDictionary(document, _signature!); final PdfSignatureDictionary signatureDictionary = @@ -195,9 +186,7 @@ class PdfSignatureField extends PdfField { if (!PdfDocumentHelper.getHelper(document).isLoadedDocument || document.fileStructure.incrementalUpdate != false) { signatureDictionary.dictionary!.archive = false; - PdfDocumentHelper.getHelper(document) - .objects - .add(signatureDictionary.element); + PdfDocumentHelper.getHelper(document).objects.add(signatureDictionary.element); PdfDocumentHelper.getHelper(document) .objects[PdfDocumentHelper.getHelper(document).objects.count - 1] .isModified = true; @@ -208,19 +197,16 @@ class PdfSignatureField extends PdfField { SignatureFlags.signaturesExists, SignatureFlags.appendOnly ]; - final PdfDictionary widget = _helper.getWidgetAnnotation( - _helper.dictionary!, _helper.crossTable); - widget[PdfDictionaryProperties.v] = - PdfReferenceHolder(signatureDictionary); + final PdfDictionary widget = + _helper.getWidgetAnnotation(_helper.dictionary!, _helper.crossTable); + widget[PdfDictionaryProperties.v] = PdfReferenceHolder(signatureDictionary); widget.modify(); _helper.changed = true; widget.setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); signatureDictionary.dictionary!.archive = false; } else { - final PdfDictionary widget = - PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!; - widget.setProperty(PdfDictionaryProperties.v, - PdfReferenceHolder(signatureDictionary)); + final PdfDictionary widget = PdfAnnotationHelper.getHelper(_helper.widget!).dictionary!; + widget.setProperty(PdfDictionaryProperties.v, PdfReferenceHolder(signatureDictionary)); widget.setProperty(PdfDictionaryProperties.fieldFlags, PdfNumber(0)); } } else { @@ -237,14 +223,13 @@ class PdfSignatureField extends PdfField { if (signature is PdfReferenceHolder && signature.object != null && signature.object is PdfDictionary) { - final PdfDictionary signatureDictionary = - signature.object! as PdfDictionary; + final PdfDictionary signatureDictionary = signature.object! as PdfDictionary; _signature = PdfSignature(); PdfSignatureHelper.getHelper(_signature!).document = crossTable!.document; String? subFilterType = ''; if (signatureDictionary.containsKey(PdfDictionaryProperties.subFilter)) { - final IPdfPrimitive? filter = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.subFilter]); + final IPdfPrimitive? filter = + PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.subFilter]); if (filter != null && filter is PdfName) { subFilterType = filter.name; } @@ -254,70 +239,60 @@ class PdfSignatureField extends PdfField { } if (crossTable.document != null && !PdfDocumentHelper.getHelper(crossTable.document!).isLoadedDocument) { - if (signatureDictionary - .containsKey(PdfDictionaryProperties.reference)) { - final IPdfPrimitive? tempArray = - signatureDictionary[PdfDictionaryProperties.reference]; + if (signatureDictionary.containsKey(PdfDictionaryProperties.reference)) { + final IPdfPrimitive? tempArray = signatureDictionary[PdfDictionaryProperties.reference]; if (tempArray != null && tempArray is PdfArray) { final IPdfPrimitive? tempDictionary = tempArray.elements[0]; if (tempDictionary != null && tempDictionary is PdfDictionary) { if (tempDictionary.containsKey(PdfDictionaryProperties.data)) { final PdfMainObjectCollection mainObjectCollection = PdfDocumentHelper.getHelper(crossTable.document!).objects; - IPdfPrimitive? tempReferenceHolder = - tempDictionary[PdfDictionaryProperties.data]; + IPdfPrimitive? tempReferenceHolder = tempDictionary[PdfDictionaryProperties.data]; if (tempReferenceHolder != null && tempReferenceHolder is PdfReferenceHolder && - !mainObjectCollection - .containsReference(tempReferenceHolder.reference!)) { + !mainObjectCollection.containsReference(tempReferenceHolder.reference!)) { final IPdfPrimitive? tempObject = mainObjectCollection - .objectCollection![ - tempReferenceHolder.reference!.objectCollectionIndex!] + .objectCollection![tempReferenceHolder.reference!.objectCollectionIndex!] .object; tempReferenceHolder = PdfReferenceHolder(tempObject); - tempDictionary.setProperty( - PdfDictionaryProperties.data, tempReferenceHolder); + tempDictionary.setProperty(PdfDictionaryProperties.data, tempReferenceHolder); } } } } } signatureDictionary.remove(PdfDictionaryProperties.byteRange); - PdfSignatureDictionary.fromDictionary( - crossTable.document!, signatureDictionary); + PdfSignatureDictionary.fromDictionary(crossTable.document!, signatureDictionary); _helper.dictionary!.remove(PdfDictionaryProperties.contents); _helper.dictionary!.remove(PdfDictionaryProperties.byteRange); } if (signatureDictionary.containsKey(PdfDictionaryProperties.m) && signatureDictionary[PdfDictionaryProperties.m] is PdfString) { - PdfSignatureHelper.getHelper(_signature!).dateOfSign = - _helper.dictionary!.getDateTime( - signatureDictionary[PdfDictionaryProperties.m]! as PdfString); + PdfSignatureHelper.getHelper(_signature!).dateOfSign = _helper.dictionary! + .getDateTime(signatureDictionary[PdfDictionaryProperties.m]! as PdfString); } if (signatureDictionary.containsKey(PdfDictionaryProperties.name) && signatureDictionary[PdfDictionaryProperties.name] is PdfString) { _signature!.signedName = - (signatureDictionary[PdfDictionaryProperties.name]! as PdfString) - .value; + (signatureDictionary[PdfDictionaryProperties.name]! as PdfString).value; } if (signatureDictionary.containsKey(PdfDictionaryProperties.reason)) { - final IPdfPrimitive? reason = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.reason]); + final IPdfPrimitive? reason = + PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.reason]); if (reason != null && reason is PdfString) { _signature!.reason = reason.value; } } if (signatureDictionary.containsKey(PdfDictionaryProperties.location)) { - final IPdfPrimitive? location = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.location]); + final IPdfPrimitive? location = + PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.location]); if (location != null && location is PdfString) { _signature!.locationInfo = location.value; } } - if (signatureDictionary - .containsKey(PdfDictionaryProperties.contactInfo)) { - final IPdfPrimitive? contactInfo = PdfCrossTable.dereference( - signatureDictionary[PdfDictionaryProperties.contactInfo]); + if (signatureDictionary.containsKey(PdfDictionaryProperties.contactInfo)) { + final IPdfPrimitive? contactInfo = + PdfCrossTable.dereference(signatureDictionary[PdfDictionaryProperties.contactInfo]); if (contactInfo != null && contactInfo is PdfString) { _signature!.contactInfo = contactInfo.value; } @@ -329,33 +304,26 @@ class PdfSignatureField extends PdfField { final PdfDictionary catalog = crossTable.documentCatalog!; bool hasPermission = false; if (catalog.containsKey(PdfDictionaryProperties.perms)) { - final IPdfPrimitive? primitive = - catalog[PdfDictionaryProperties.perms]; + final IPdfPrimitive? primitive = catalog[PdfDictionaryProperties.perms]; final IPdfPrimitive? catalogDictionary = - (primitive is PdfReferenceHolder) - ? primitive.object - : primitive; + (primitive is PdfReferenceHolder) ? primitive.object : primitive; if (catalogDictionary != null && catalogDictionary is PdfDictionary && catalogDictionary.containsKey(PdfDictionaryProperties.docMDP)) { final IPdfPrimitive? docPermission = catalogDictionary[PdfDictionaryProperties.docMDP]; final IPdfPrimitive? permissionDictionary = - (docPermission is PdfReferenceHolder) - ? docPermission.object - : docPermission; + (docPermission is PdfReferenceHolder) ? docPermission.object : docPermission; if (permissionDictionary != null && permissionDictionary is PdfDictionary && - permissionDictionary - .containsKey(PdfDictionaryProperties.byteRange)) { + permissionDictionary.containsKey(PdfDictionaryProperties.byteRange)) { final IPdfPrimitive? byteRange = PdfCrossTable.dereference( permissionDictionary[PdfDictionaryProperties.byteRange]); bool isValid = true; if (byteRange != null && byteRange is PdfArray && _signature != null && - PdfSignatureHelper.getHelper(_signature!).byteRange != - null) { + PdfSignatureHelper.getHelper(_signature!).byteRange != null) { for (int i = 0; i < byteRange.count; i++) { final IPdfPrimitive? byteValue = byteRange[i]; final IPdfPrimitive? signByte = @@ -374,17 +342,13 @@ class PdfSignatureField extends PdfField { } } } - if (hasPermission && - signatureDictionary - .containsKey(PdfDictionaryProperties.reference)) { - IPdfPrimitive? primitive = - signatureDictionary[PdfDictionaryProperties.reference]; + if (hasPermission && signatureDictionary.containsKey(PdfDictionaryProperties.reference)) { + IPdfPrimitive? primitive = signatureDictionary[PdfDictionaryProperties.reference]; if (primitive is PdfArray) { primitive = primitive.elements[0]; } - IPdfPrimitive? reference = (primitive is PdfReferenceHolder) - ? primitive.object - : primitive; + IPdfPrimitive? reference = + (primitive is PdfReferenceHolder) ? primitive.object : primitive; if (reference != null && reference is PdfDictionary && reference.containsKey('TransformParams')) { @@ -394,15 +358,12 @@ class PdfSignatureField extends PdfField { } else if (primitive is PdfDictionary) { reference = primitive; } - if (reference is PdfDictionary && - reference.containsKey(PdfDictionaryProperties.p)) { + if (reference is PdfDictionary && reference.containsKey(PdfDictionaryProperties.p)) { final IPdfPrimitive? permissionNumber = - PdfCrossTable.dereference( - reference[PdfDictionaryProperties.p]); + PdfCrossTable.dereference(reference[PdfDictionaryProperties.p]); if (permissionNumber != null && permissionNumber is PdfNumber) { - _signature!.documentPermissions = - PdfSignatureHelper.getHelper(_signature!) - .getCertificateFlags(permissionNumber.value!.toInt()); + _signature!.documentPermissions = PdfSignatureHelper.getHelper(_signature!) + .getCertificateFlags(permissionNumber.value!.toInt()); } } } @@ -433,8 +394,7 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { } /// internal method - static PdfSignatureField loadSignatureField( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfSignatureField loadSignatureField(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfSignatureField._(dictionary, crossTable); } @@ -446,50 +406,38 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { @override void draw() { if (!isLoadedField) { - if (PdfAnnotationHelper.getHelper(widget!).appearance == null && - appearance) { - PdfAnnotationHelper.getHelper(widget!).appearance = - PdfAppearance(widget!); - PdfAnnotationHelper.getHelper(widget!).appearance!.normal = PdfTemplate( - signatureField.bounds.width, signatureField.bounds.height); - drawAppearance( - PdfAnnotationHelper.getHelper(widget!).appearance!.normal); + if (PdfAnnotationHelper.getHelper(widget!).appearance == null && appearance) { + PdfAnnotationHelper.getHelper(widget!).appearance = PdfAppearance(widget!); + PdfAnnotationHelper.getHelper(widget!).appearance!.normal = + PdfTemplate(signatureField.bounds.width, signatureField.bounds.height); + drawAppearance(PdfAnnotationHelper.getHelper(widget!).appearance!.normal); } super.draw(); if (PdfAnnotationHelper.getHelper(widget!).appearance != null) { - signatureField.page!.graphics.drawPdfTemplate( - widget!.appearance.normal, signatureField.bounds.topLeft); + signatureField.page!.graphics + .drawPdfTemplate(widget!.appearance.normal, signatureField.bounds.topLeft); } } else if (flattenField) { if (!isLoadedSign && - PdfAppearanceHelper.getHelper(signatureField.appearance) - .templateNormal != - null) { - final PdfDictionary widget = - getWidgetAnnotation(dictionary!, crossTable); - widget.setProperty( - PdfDictionaryProperties.ap, signatureField.appearance); + PdfAppearanceHelper.getHelper(signatureField.appearance).templateNormal != null) { + final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); + widget.setProperty(PdfDictionaryProperties.ap, signatureField.appearance); } if (dictionary![PdfDictionaryProperties.ap] != null) { - final IPdfPrimitive? tempDictionary = - dictionary![PdfDictionaryProperties.ap]; - final IPdfPrimitive? appearanceDictionary = - PdfCrossTable.dereference(tempDictionary); + final IPdfPrimitive? tempDictionary = dictionary![PdfDictionaryProperties.ap]; + final IPdfPrimitive? appearanceDictionary = PdfCrossTable.dereference(tempDictionary); PdfTemplate template; - if (appearanceDictionary != null && - appearanceDictionary is PdfDictionary) { + if (appearanceDictionary != null && appearanceDictionary is PdfDictionary) { final IPdfPrimitive? appearanceRefHolder = appearanceDictionary[PdfDictionaryProperties.n]; - final IPdfPrimitive? objectDictionary = - PdfCrossTable.dereference(appearanceRefHolder); + final IPdfPrimitive? objectDictionary = PdfCrossTable.dereference(appearanceRefHolder); if (objectDictionary != null && objectDictionary is PdfDictionary) { if (objectDictionary is PdfStream && objectDictionary.dataStream != null && objectDictionary.dataStream!.isNotEmpty && (isLoadedSign || (!isLoadedSign && !appearance))) { final PdfStream stream = objectDictionary; - template = - _drawRotatedTemplate(PdfTemplateHelper.fromPdfStream(stream)); + template = _drawRotatedTemplate(PdfTemplateHelper.fromPdfStream(stream)); signatureField.page!.graphics .drawPdfTemplate(template, signatureField.bounds.topLeft); } else { @@ -510,31 +458,26 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { PdfCrossTable.dereference(content[PdfDictionaryProperties.matrix]); if (matrix != null && matrix is PdfArray) { final int angle = _obtainGraphicsRotation( - (matrix.elements[2]! as PdfNumber).value!, - (matrix.elements[0]! as PdfNumber).value!); + (matrix.elements[2]! as PdfNumber).value!, (matrix.elements[0]! as PdfNumber).value!); if (angle != 0) { PdfAnnotationHelper.setMatrixToZeroRotation(content); final PdfTemplate rotatedTemplate = PdfTemplate(template.size.width, template.size.height); rotatedTemplate.graphics!.save(); if (angle == 90) { - rotatedTemplate.graphics! - .translateTransform(0, template.size.height); + rotatedTemplate.graphics!.translateTransform(0, template.size.height); rotatedTemplate.graphics!.rotateTransform(-90); - rotatedTemplate.graphics!.drawPdfTemplate(template, Offset.zero, - Size(template.size.height, template.size.width)); + rotatedTemplate.graphics!.drawPdfTemplate( + template, Offset.zero, Size(template.size.height, template.size.width)); } else if (angle == 180) { - rotatedTemplate.graphics! - .translateTransform(template.size.width, template.size.height); + rotatedTemplate.graphics!.translateTransform(template.size.width, template.size.height); rotatedTemplate.graphics!.rotateTransform(-180); - rotatedTemplate.graphics! - .drawPdfTemplate(template, Offset.zero, template.size); + rotatedTemplate.graphics!.drawPdfTemplate(template, Offset.zero, template.size); } else if (angle == 270) { - rotatedTemplate.graphics! - .translateTransform(template.size.width, 0); + rotatedTemplate.graphics!.translateTransform(template.size.width, 0); rotatedTemplate.graphics!.rotateTransform(-270); - rotatedTemplate.graphics!.drawPdfTemplate(template, Offset.zero, - Size(template.size.height, template.size.width)); + rotatedTemplate.graphics!.drawPdfTemplate( + template, Offset.zero, Size(template.size.height, template.size.width)); } rotatedTemplate.graphics!.restore(); return rotatedTemplate; @@ -583,8 +526,7 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { super.drawAppearance(template); if (appearance) { final PaintParams params = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, signatureField.bounds.width, signatureField.bounds.height), + bounds: Rect.fromLTWH(0, 0, signatureField.bounds.width, signatureField.bounds.height), backBrush: backBrush, foreBrush: foreBrush, borderPen: borderPen, @@ -596,8 +538,8 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { FieldPainter().drawSignature( template.graphics!, PaintParams( - bounds: Rect.fromLTWH(0, 0, signatureField.bounds.width, - signatureField.bounds.height))); + bounds: + Rect.fromLTWH(0, 0, signatureField.bounds.width, signatureField.bounds.height))); } } @@ -606,11 +548,9 @@ class PdfSignatureFieldHelper extends PdfFieldHelper { void beginSave() { if (!isLoadedSign && appearance && - PdfAppearanceHelper.getHelper(signatureField.appearance) - .templateNormal == - null) { - signatureField.appearance.normal = PdfTemplate( - signatureField.bounds.width, signatureField.bounds.height); + PdfAppearanceHelper.getHelper(signatureField.appearance).templateNormal == null) { + signatureField.appearance.normal = + PdfTemplate(signatureField.bounds.width, signatureField.bounds.height); drawAppearance(signatureField.appearance.normal); final PdfDictionary widget = getWidgetAnnotation(dictionary!, crossTable); widget.setProperty(PdfDictionaryProperties.ap, signatureField.appearance); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_text_box_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_text_box_field.dart index ce71adb51..240af52d6 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_text_box_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/forms/pdf_text_box_field.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/enum.dart'; @@ -64,11 +64,11 @@ class PdfTextBoxField extends PdfField { borderStyle: borderStyle, tooltip: tooltip); this.font = font ?? PdfStandardFont(PdfFontFamily.helvetica, 8); - _init(text, defaultValue, maxLength, spellCheck, insertSpaces, multiline, - isPassword, scrollable); + _init( + text, defaultValue, maxLength, spellCheck, insertSpaces, multiline, isPassword, scrollable); _helper.flags.add(FieldFlags.doNotSpellCheck); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.tx)); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.ft, PdfName(PdfDictionaryProperties.tx)); } /// Initializes a new instance of the [PdfTextBoxField] class. @@ -79,8 +79,7 @@ class PdfTextBoxField extends PdfField { final PdfArray? kids = _helper.kids; if (kids != null) { for (int i = 0; i < kids.count; ++i) { - final PdfDictionary? itemDictionary = - crossTable.getObject(kids[i]) as PdfDictionary?; + final PdfDictionary? itemDictionary = crossTable.getObject(kids[i]) as PdfDictionary?; PdfFieldItemCollectionHelper.getHelper(_items!) .add(PdfTextBoxItemHelper.getItem(this, i, itemDictionary)); } @@ -105,11 +104,9 @@ class PdfTextBoxField extends PdfField { String get text { if (_helper.isLoadedField) { IPdfPrimitive? str; - final IPdfPrimitive? referenceHolder = - _helper.dictionary![PdfDictionaryProperties.v]; + final IPdfPrimitive? referenceHolder = _helper.dictionary![PdfDictionaryProperties.v]; if (referenceHolder != null && referenceHolder is PdfReferenceHolder) { - final IPdfPrimitive? textObject = - PdfCrossTable.dereference(referenceHolder); + final IPdfPrimitive? textObject = PdfCrossTable.dereference(referenceHolder); if (textObject is PdfStream) { final PdfStream stream = referenceHolder.object! as PdfStream; stream.decompress(); @@ -117,14 +114,14 @@ class PdfTextBoxField extends PdfField { final String data = utf8.decode(bytes); str = PdfString(data); } else if (textObject is PdfString) { - str = PdfFieldHelper.getValue(_helper.dictionary!, _helper.crossTable, - PdfDictionaryProperties.v, true); + str = PdfFieldHelper.getValue( + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.v, true); } else { str = PdfString(''); } } else { - str = PdfFieldHelper.getValue(_helper.dictionary!, _helper.crossTable, - PdfDictionaryProperties.v, true); + str = PdfFieldHelper.getValue( + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.v, true); } _text = str != null && str is PdfString ? str.value : ''; return _text!; @@ -138,25 +135,21 @@ class PdfTextBoxField extends PdfField { if (!_helper.isFlagPresent(FieldFlags.readOnly)) { _helper.isTextChanged = true; if (_helper.dictionary!.containsKey(PdfDictionaryProperties.aa)) { - final IPdfPrimitive? dic = - _helper.dictionary![PdfDictionaryProperties.aa]; + final IPdfPrimitive? dic = _helper.dictionary![PdfDictionaryProperties.aa]; if (dic != null && dic is PdfDictionary) { final IPdfPrimitive? dicRef = dic[PdfDictionaryProperties.k]; if (dicRef != null && dicRef is PdfReferenceHolder) { final IPdfPrimitive? dict = dicRef.object; if (dict != null && dict is PdfDictionary) { - final IPdfPrimitive? str = - PdfCrossTable.dereference(dict['JS']); + final IPdfPrimitive? str = PdfCrossTable.dereference(dict['JS']); if (str != null && str is PdfString) { - _helper.dictionary!.setProperty( - PdfDictionaryProperties.v, PdfString(str.value!)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.v, PdfString(str.value!)); } } } } } - _helper.dictionary! - .setProperty(PdfDictionaryProperties.v, PdfString(value)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.v, PdfString(value)); _helper.changed = true; PdfFormHelper.getHelper(super.form!).setAppearanceDictionary = true; if (PdfFormHelper.getHelper(super.form!).isUR3) { @@ -183,8 +176,8 @@ class PdfTextBoxField extends PdfField { /// Gets or sets the default value. String get defaultValue { if (_helper.isLoadedField) { - final IPdfPrimitive? str = PdfFieldHelper.getValue(_helper.dictionary!, - _helper.crossTable, PdfDictionaryProperties.dv, true); + final IPdfPrimitive? str = PdfFieldHelper.getValue( + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.dv, true); if (str != null && str is PdfString) { _defaultValue = str.value; } @@ -207,8 +200,8 @@ class PdfTextBoxField extends PdfField { /// The default value is 0. int get maxLength { if (_helper.isLoadedField) { - final IPdfPrimitive? number = PdfFieldHelper.getValue(_helper.dictionary!, - _helper.crossTable, PdfDictionaryProperties.maxLen, true); + final IPdfPrimitive? number = PdfFieldHelper.getValue( + _helper.dictionary!, _helper.crossTable, PdfDictionaryProperties.maxLen, true); if (number != null && number is PdfNumber) { _maxLength = number.value!.toInt(); } @@ -312,8 +305,8 @@ class PdfTextBoxField extends PdfField { /// The default value is false. bool get isPassword { if (_helper.isLoadedField) { - _password = _helper.isFlagPresent(FieldFlags.password) || - _helper.flags.contains(FieldFlags.password); + _password = + _helper.isFlagPresent(FieldFlags.password) || _helper.flags.contains(FieldFlags.password); } return _password; } @@ -416,8 +409,8 @@ class PdfTextBoxField extends PdfField { _helper.beginSave(); } - void _init(String? text, String? defaultValue, int maxLength, bool spellCheck, - bool insertSpaces, bool multiline, bool password, bool scrollable) { + void _init(String? text, String? defaultValue, int maxLength, bool spellCheck, bool insertSpaces, + bool multiline, bool password, bool scrollable) { if (text != null) { this.text = text; } @@ -432,8 +425,7 @@ class PdfTextBoxField extends PdfField { this.scrollable = scrollable; } - void _drawTextBox(PdfGraphics? graphics, - {PaintParams? params, PdfFieldItem? item}) { + void _drawTextBox(PdfGraphics? graphics, {PaintParams? params, PdfFieldItem? item}) { if (params != null) { String newText = text; if (isPassword && text.isNotEmpty) { @@ -448,14 +440,11 @@ class PdfTextBoxField extends PdfField { final List ch = text.split(''); if (maxLength > 0) { width = params.bounds!.width / maxLength; - graphics.drawRectangle( - bounds: params.bounds!, pen: _helper.borderPen); + graphics.drawRectangle(bounds: params.bounds!, pen: _helper.borderPen); for (int i = 0; i < maxLength; i++) { if (_helper.format!.alignment != PdfTextAlignment.right) { - if (_helper.format!.alignment == PdfTextAlignment.center && - ch.length < maxLength) { - final int startLocation = - (maxLength / 2 - (ch.length / 2).ceil()).toInt(); + if (_helper.format!.alignment == PdfTextAlignment.center && ch.length < maxLength) { + final int startLocation = (maxLength / 2 - (ch.length / 2).ceil()).toInt(); newText = i >= startLocation && i < startLocation + ch.length ? ch[i - startLocation] : ''; @@ -463,47 +452,40 @@ class PdfTextBoxField extends PdfField { newText = ch.length > i ? ch[i] : ''; } } else { - newText = maxLength - ch.length <= i - ? ch[i - (maxLength - ch.length)] - : ''; + newText = maxLength - ch.length <= i ? ch[i - (maxLength - ch.length)] : ''; } - params.bounds = Rect.fromLTWH(params.bounds!.left, - params.bounds!.top, width, params.bounds!.height); + params.bounds = Rect.fromLTWH( + params.bounds!.left, params.bounds!.top, width, params.bounds!.height); final PdfStringFormat format = PdfStringFormat( - alignment: PdfTextAlignment.center, - lineAlignment: _helper.format!.lineAlignment); - FieldPainter().drawTextBox(graphics, params, newText, font, format, - insertSpaces, multiline); - params.bounds = Rect.fromLTWH(params.bounds!.left + width, - params.bounds!.top, width, params.bounds!.height); + alignment: PdfTextAlignment.center, lineAlignment: _helper.format!.lineAlignment); + FieldPainter() + .drawTextBox(graphics, params, newText, font, format, insertSpaces, multiline); + params.bounds = Rect.fromLTWH( + params.bounds!.left + width, params.bounds!.top, width, params.bounds!.height); if (params.borderWidth != 0) { - graphics.drawLine( - params.borderPen!, - Offset(params.bounds!.left, params.bounds!.top), - Offset(params.bounds!.left, - params.bounds!.top + params.bounds!.height)); + graphics.drawLine(params.borderPen!, Offset(params.bounds!.left, params.bounds!.top), + Offset(params.bounds!.left, params.bounds!.top + params.bounds!.height)); } } } else { - FieldPainter().drawTextBox(graphics, params, newText, font, - _helper.format!, insertSpaces, multiline); + FieldPainter().drawTextBox( + graphics, params, newText, font, _helper.format!, insertSpaces, multiline); } } else { - FieldPainter().drawTextBox(graphics, params, newText, font, - _helper.format!, insertSpaces, multiline); + FieldPainter() + .drawTextBox(graphics, params, newText, font, _helper.format!, insertSpaces, multiline); } graphics.restore(); } else { - final GraphicsProperties gp = item != null - ? GraphicsProperties.fromFieldItem(item) - : GraphicsProperties(this); + final GraphicsProperties gp = + item != null ? GraphicsProperties.fromFieldItem(item) : GraphicsProperties(this); if (gp.borderWidth == 0 && gp.borderPen != null) { gp.borderWidth = 1; gp.borderPen!.width = 1; } if (PdfGraphicsHelper.getHelper(graphics!).layer == null) { - gp.bounds = Rect.fromLTWH(gp.bounds!.left, gp.bounds!.top, - graphics.size.width, graphics.size.height); + gp.bounds = Rect.fromLTWH( + gp.bounds!.left, gp.bounds!.top, graphics.size.width, graphics.size.height); } if (!_helper.flattenField) { gp.bounds = Rect.fromLTWH(0, 0, gp.bounds!.width, gp.bounds!.height); @@ -522,8 +504,7 @@ class PdfTextBoxField extends PdfField { void _applyAppearance(PdfDictionary? widget, [PdfFieldItem? item]) { if (PdfFormHelper.getHelper(super.form!).setAppearanceDictionary) { - if (widget != null && - !PdfFormHelper.getHelper(super.form!).needAppearances!) { + if (widget != null && !PdfFormHelper.getHelper(super.form!).needAppearances!) { final PdfDictionary appearance = PdfDictionary(); final Rect bounds = item == null ? this.bounds : item.bounds; PdfTemplate? template; @@ -536,29 +517,19 @@ class PdfTextBoxField extends PdfField { if (angle != null && angle is PdfNumber) { if (angle.value == 90) { template = PdfTemplate(bounds.size.height, bounds.size.width); - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = PdfArray([0, 1, -1, 0, bounds.size.width, 0]); } else if (angle.value == 180) { template = PdfTemplate(bounds.size.width, bounds.size.height); - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = PdfArray([ - -1, - 0, - 0, - -1, - bounds.size.width, - bounds.size.height - ]); + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = + PdfArray([-1, 0, 0, -1, bounds.size.width, bounds.size.height]); } else if (angle.value == 270) { template = PdfTemplate(bounds.size.height, bounds.size.width); - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = PdfArray([0, -1, 1, 0, 0, bounds.size.height]); } if (template != null) { - PdfTemplateHelper.getHelper(template).writeTransformation = - false; + PdfTemplateHelper.getHelper(template).writeTransformation = false; } } } @@ -566,27 +537,20 @@ class PdfTextBoxField extends PdfField { if (template == null) { template = PdfTemplate(bounds.size.width, bounds.size.height); PdfTemplateHelper.getHelper(template).writeTransformation = false; - PdfTemplateHelper.getHelper(template) - .content[PdfDictionaryProperties.matrix] = + PdfTemplateHelper.getHelper(template).content[PdfDictionaryProperties.matrix] = PdfArray([1, 0, 0, 1, 0, 0]); } if (item != null) { _helper.beginMarkupSequence( - PdfGraphicsHelper.getHelper(template.graphics!) - .streamWriter! - .stream!); - PdfGraphicsHelper.getHelper(template.graphics!) - .initializeCoordinates(); + PdfGraphicsHelper.getHelper(template.graphics!).streamWriter!.stream!); + PdfGraphicsHelper.getHelper(template.graphics!).initializeCoordinates(); _drawTextBox(template.graphics, item: item); _helper.endMarkupSequence( - PdfGraphicsHelper.getHelper(template.graphics!) - .streamWriter! - .stream!); + PdfGraphicsHelper.getHelper(template.graphics!).streamWriter!.stream!); } else { _helper.drawAppearance(template); } - appearance.setProperty( - PdfDictionaryProperties.n, PdfReferenceHolder(template)); + appearance.setProperty(PdfDictionaryProperties.n, PdfReferenceHolder(template)); widget.setProperty(PdfDictionaryProperties.ap, appearance); } else { PdfFormHelper.getHelper(super.form!).needAppearances = true; @@ -615,8 +579,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { } /// internal method - static PdfTextBoxField loadTextBox( - PdfDictionary dictionary, PdfCrossTable crossTable) { + static PdfTextBoxField loadTextBox(PdfDictionary dictionary, PdfCrossTable crossTable) { return PdfTextBoxField._load(dictionary, crossTable); } @@ -638,8 +601,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { void drawAppearance(PdfTemplate template) { super.drawAppearance(template); final PaintParams params = PaintParams( - bounds: Rect.fromLTWH( - 0, 0, textBoxField.bounds.width, textBoxField.bounds.height), + bounds: Rect.fromLTWH(0, 0, textBoxField.bounds.width, textBoxField.bounds.height), backBrush: backBrush, foreBrush: foreBrush, borderPen: borderPen, @@ -648,16 +610,14 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { shadowBrush: shadowBrush); PdfTemplateHelper.getHelper(template).writeTransformation = false; final PdfGraphics graphics = template.graphics!; - beginMarkupSequence( - PdfGraphicsHelper.getHelper(graphics).streamWriter!.stream!); + beginMarkupSequence(PdfGraphicsHelper.getHelper(graphics).streamWriter!.stream!); PdfGraphicsHelper.getHelper(graphics).initializeCoordinates(); if (params.borderWidth == 0 && params.borderPen != null) { params.borderWidth = 1; params.borderPen!.width = 1; } textBoxField._drawTextBox(graphics, params: params); - endMarkupSequence( - PdfGraphicsHelper.getHelper(graphics).streamWriter!.stream!); + endMarkupSequence(PdfGraphicsHelper.getHelper(graphics).streamWriter!.stream!); } /// internal method @@ -666,13 +626,11 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { super.beginSave(); if (kids != null) { for (int i = 0; i < kids!.count; ++i) { - final PdfDictionary? widget = - crossTable!.getObject(kids![i]) as PdfDictionary?; + final PdfDictionary? widget = crossTable!.getObject(kids![i]) as PdfDictionary?; textBoxField._applyAppearance(widget, textBoxField.items![i]); } } else { - textBoxField - ._applyAppearance(getWidgetAnnotation(dictionary!, crossTable)); + textBoxField._applyAppearance(getWidgetAnnotation(dictionary!, crossTable)); } } @@ -683,9 +641,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { if (!textBoxField.multiline) { final PdfStandardFont font = PdfStandardFont(family, 12); final Size fontSize = font.measureString(textBoxField.text); - s = (8 * - (textBoxField.bounds.size.width - 4 * textBoxField.borderWidth)) / - fontSize.width; + s = (8 * (textBoxField.bounds.size.width - 4 * textBoxField.borderWidth)) / fontSize.width; s = (s > 8) ? 8 : s; } else { s = 12.5; @@ -697,8 +653,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { @override void draw() { super.draw(); - if (!isLoadedField && - PdfAnnotationHelper.getHelper(widget!).appearance != null) { + if (!isLoadedField && PdfAnnotationHelper.getHelper(widget!).appearance != null) { textBoxField.page!.graphics.drawPdfTemplate( PdfAnnotationHelper.getHelper(widget!).appearance!.normal, Offset(textBoxField.bounds.width, textBoxField.bounds.height)); @@ -707,9 +662,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { final PdfTextBoxField field = fieldItems![i] as PdfTextBoxField; field.text = textBoxField.text; field.page!.graphics.drawPdfTemplate( - PdfAnnotationHelper.getHelper(field._helper.widget!) - .appearance! - .normal, + PdfAnnotationHelper.getHelper(field._helper.widget!).appearance!.normal, Offset(field.bounds.width, field.bounds.height)); } } @@ -718,8 +671,7 @@ class PdfTextBoxFieldHelper extends PdfFieldHelper { if (kids != null) { for (int i = 0; i < kids!.count; ++i) { final PdfFieldItem item = textBoxField.items![i]; - if (item.page != null && - PdfPageHelper.getHelper(item.page!).isLoadedPage) { + if (item.page != null && PdfPageHelper.getHelper(item.page!).isLoadedPage) { textBoxField._drawTextBox(item.page!.graphics, item: item); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_destination.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_destination.dart index 1e6c42c3e..108a62a7d 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_destination.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_destination.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_named_destination.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_named_destination.dart index 91efaa163..9621fac00 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_named_destination.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/general/pdf_named_destination.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../io/pdf_constants.dart'; @@ -25,8 +25,7 @@ class PdfNamedDestination implements IPdfWrapper { _initialize(); } - PdfNamedDestination._( - PdfDictionary dictionary, PdfCrossTable crossTable, bool isLoaded) + PdfNamedDestination._(PdfDictionary dictionary, PdfCrossTable crossTable, bool isLoaded) : super() { _helper = PdfNamedDestinationHelper(this); _helper.dictionary = dictionary; @@ -65,14 +64,13 @@ class PdfNamedDestination implements IPdfWrapper { if (_isLoaded) { String? title = ''; if (_helper.dictionary!.containsKey(PdfDictionaryProperties.title)) { - final PdfString str = _crossTable.getObject( - _helper.dictionary![PdfDictionaryProperties.title])! as PdfString; + final PdfString str = + _crossTable.getObject(_helper.dictionary![PdfDictionaryProperties.title])! as PdfString; title = str.value; } return title!; } else { - final PdfString? title = - _helper.dictionary![PdfDictionaryProperties.title] as PdfString?; + final PdfString? title = _helper.dictionary![PdfDictionaryProperties.title] as PdfString?; String? value; if (title != null) { value = title.value; @@ -91,38 +89,33 @@ class PdfNamedDestination implements IPdfWrapper { _helper.dictionary!.beginSave = (Object sender, SavePdfPrimitiveArgs? ars) { _helper.dictionary!.setProperty(PdfDictionaryProperties.d, _destination); }; - _helper.dictionary!.setProperty( - PdfDictionaryProperties.s, PdfName(PdfDictionaryProperties.goTo)); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.s, PdfName(PdfDictionaryProperties.goTo)); } PdfDestination? _obtainDestination() { - if (_helper.dictionary!.containsKey(PdfDictionaryProperties.d) && - (_destination == null)) { + if (_helper.dictionary!.containsKey(PdfDictionaryProperties.d) && (_destination == null)) { final IPdfPrimitive? obj = _crossTable.getObject(_helper.dictionary![PdfDictionaryProperties.d]); final PdfArray? destination = obj as PdfArray?; if (destination != null && destination.count > 1) { - final PdfReferenceHolder? referenceHolder = - destination[0] as PdfReferenceHolder?; + final PdfReferenceHolder? referenceHolder = destination[0] as PdfReferenceHolder?; PdfPage? page; if (referenceHolder != null) { final PdfDictionary? dictionary = _crossTable.getObject(referenceHolder) as PdfDictionary?; if (dictionary != null) { page = - PdfPageCollectionHelper.getHelper(_crossTable.document!.pages) - .getPage(dictionary); + PdfPageCollectionHelper.getHelper(_crossTable.document!.pages).getPage(dictionary); } } final PdfName? mode = destination[1] as PdfName?; if (mode != null) { - if ((mode.name == 'FitBH' || mode.name == 'FitH') && - destination.count > 2) { + if ((mode.name == 'FitBH' || mode.name == 'FitH') && destination.count > 2) { final PdfNumber? top = destination[2] as PdfNumber?; if (page != null) { - final double topValue = - (top == null) ? 0 : page.size.height - top.value!; + final double topValue = (top == null) ? 0 : page.size.height - top.value!; _destination = PdfDestination(page, Offset(0, topValue)); _destination!.mode = PdfDestinationMode.fitH; } @@ -134,10 +127,8 @@ class PdfNamedDestination implements IPdfWrapper { zoom = destination[4]! as PdfNumber; } if (page != null) { - final double topValue = - (top == null) ? 0 : page.size.height - top.value!; - final double leftValue = - (left == null) ? 0 : left.value! as double; + final double topValue = (top == null) ? 0 : page.size.height - top.value!; + final double leftValue = (left == null) ? 0 : left.value! as double; _destination = PdfDestination(page, Offset(leftValue, topValue)); if (zoom != null) { _destination!.zoom = zoom.value!.toDouble(); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/element_layouter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/element_layouter.dart index d7c53e67e..a4f7e2e2d 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/element_layouter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/element_layouter.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../pages/pdf_page.dart'; @@ -49,8 +49,7 @@ abstract class ElementLayouter { PdfRectangle getPaginateBounds(PdfLayoutParams param) { return param.format!._boundsSet ? PdfRectangle.fromRect(param.format!.paginateBounds) - : PdfRectangle( - param.bounds!.x, 0, param.bounds!.width, param.bounds!.height); + : PdfRectangle(param.bounds!.x, 0, param.bounds!.width, param.bounds!.height); } } @@ -59,9 +58,7 @@ class PdfLayoutFormat { //Constructor /// Initializes a new instance of the [PdfLayoutFormat] class. PdfLayoutFormat( - {PdfLayoutType? layoutType, - PdfLayoutBreakType? breakType, - Rect? paginateBounds}) { + {PdfLayoutType? layoutType, PdfLayoutBreakType? breakType, Rect? paginateBounds}) { this.breakType = breakType ?? PdfLayoutBreakType.fitPage; this.layoutType = layoutType ?? PdfLayoutType.paginate; if (paginateBounds != null) { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/layout_element.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/layout_element.dart index 9973ef5ff..f69498e7b 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/layout_element.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/layout_element.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../pages/pdf_page.dart'; @@ -31,22 +31,18 @@ abstract class PdfLayoutElement { /// If both graphics and page provide in the arguments /// then page takes more precedence than graphics PdfLayoutResult? draw( - {PdfGraphics? graphics, - PdfPage? page, - Rect? bounds, - PdfLayoutFormat? format}) { + {PdfGraphics? graphics, PdfPage? page, Rect? bounds, PdfLayoutFormat? format}) { return _draw(graphics, page, bounds, format); } //Implementation - PdfLayoutResult? _draw(PdfGraphics? graphics, PdfPage? page, Rect? bounds, - PdfLayoutFormat? format) { + PdfLayoutResult? _draw( + PdfGraphics? graphics, PdfPage? page, Rect? bounds, PdfLayoutFormat? format) { if (page != null) { final PdfLayoutParams param = PdfLayoutParams(); param.page = page; - param.bounds = - bounds != null ? PdfRectangle.fromRect(bounds) : PdfRectangle.empty; + param.bounds = bounds != null ? PdfRectangle.fromRect(bounds) : PdfRectangle.empty; param.format = (format != null) ? format : PdfLayoutFormat(); return _helper.layout(param); } else if (graphics != null) { @@ -100,8 +96,7 @@ class PdfLayoutElementHelper { if (base is PdfShapeElement) { return PdfShapeElementHelper.layout(base as PdfShapeElement, param); } else if (base is PdfTextElement) { - return PdfTextElementHelper.getHelper(base as PdfTextElement) - .layout(param); + return PdfTextElementHelper.getHelper(base as PdfTextElement).layout(param); } else if (base is PdfList) { return PdfListHelper.getHelper(base as PdfList).layout(param); } else if (base is PdfGrid) { @@ -127,16 +122,13 @@ class PdfLayoutElementHelper { /// internal method void drawInternal(PdfGraphics graphics, PdfRectangle bounds) { if (base is PdfBezierCurve) { - PdfBezierCurveHelper.getHelper(base as PdfBezierCurve) - .drawInternal(graphics, bounds); + PdfBezierCurveHelper.getHelper(base as PdfBezierCurve).drawInternal(graphics, bounds); } else if (base is PdfPath) { PdfPathHelper.getHelper(base as PdfPath).drawInternal(graphics, bounds); } else if (base is PdfTextElement) { - PdfTextElementHelper.getHelper(base as PdfTextElement) - .drawInternal(graphics, bounds); + PdfTextElementHelper.getHelper(base as PdfTextElement).drawInternal(graphics, bounds); } else if (base is PdfImage) { - PdfBitmapHelper.getHelper(base as PdfBitmap) - .drawInternal(graphics, bounds); + PdfBitmapHelper.getHelper(base as PdfBitmap).drawInternal(graphics, bounds); } else if (base is PdfList) { PdfListHelper.getHelper(base as PdfList).drawInternal(graphics, bounds); } else if (base is PdfGrid) { @@ -206,10 +198,8 @@ class PdfCancelArgs { /// Represents the method that will handle an event /// that before lay outing on the page. -typedef BeginPageLayoutCallback = void Function( - Object sender, BeginPageLayoutArgs args); +typedef BeginPageLayoutCallback = void Function(Object sender, BeginPageLayoutArgs args); /// Represents the method that will handle an event, /// once completed the lay outing on the page. -typedef EndPageLayoutCallback = void Function( - Object sender, EndPageLayoutArgs args); +typedef EndPageLayoutCallback = void Function(Object sender, EndPageLayoutArgs args); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/shape_layouter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/shape_layouter.dart index 9fb5915d4..0c9f4c93f 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/shape_layouter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/shape_layouter.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../pages/pdf_page.dart'; @@ -41,8 +41,7 @@ class ShapeLayouter extends ElementLayouter { currentBounds = PdfRectangle.fromRect(returnedValue['bounds']); EndPageLayoutArgs? endArgs; if (!cancel) { - pageResult = _layoutOnPage( - currentPage!, currentBounds, shapeLayoutBounds!, param); + pageResult = _layoutOnPage(currentPage!, currentBounds, shapeLayoutBounds!, param); endArgs = _raiseEndPageLayout(pageResult); cancel = endArgs != null && endArgs.cancel; } @@ -60,12 +59,10 @@ class ShapeLayouter extends ElementLayouter { return result; } - Map _raiseBeforePageLayout( - PdfPage? currentPage, Rect currentBounds) { + Map _raiseBeforePageLayout(PdfPage? currentPage, Rect currentBounds) { bool cancel = false; if (PdfLayoutElementHelper.getHelper(element!).raiseBeginPageLayout) { - final BeginPageLayoutArgs args = - BeginPageLayoutArgs(currentBounds, currentPage!); + final BeginPageLayoutArgs args = BeginPageLayoutArgs(currentBounds, currentPage!); PdfLayoutElementHelper.getHelper(element!).onBeginPageLayout(args); cancel = args.cancel; currentBounds = args.bounds; @@ -73,89 +70,68 @@ class ShapeLayouter extends ElementLayouter { return {'cancel': cancel, 'bounds': currentBounds}; } - _ShapeLayoutResult _layoutOnPage( - PdfPage currentPage, - PdfRectangle currentBounds, - PdfRectangle shapeLayoutBounds, - PdfLayoutParams param) { + _ShapeLayoutResult _layoutOnPage(PdfPage currentPage, PdfRectangle currentBounds, + PdfRectangle shapeLayoutBounds, PdfLayoutParams param) { final _ShapeLayoutResult result = _ShapeLayoutResult(); - currentBounds = _checkCorrectCurrentBounds( - currentPage, currentBounds, shapeLayoutBounds, param); + currentBounds = + _checkCorrectCurrentBounds(currentPage, currentBounds, shapeLayoutBounds, param); final bool fitToPage = _fitsToBounds(currentBounds, shapeLayoutBounds); - final bool canDraw = - !(param.format!.breakType == PdfLayoutBreakType.fitElement && - !fitToPage && - currentPage == param.page); + final bool canDraw = !(param.format!.breakType == PdfLayoutBreakType.fitElement && + !fitToPage && + currentPage == param.page); bool shapeFinished = false; if (canDraw) { - final PdfRectangle drawRectangle = - _getDrawBounds(currentBounds, shapeLayoutBounds); + final PdfRectangle drawRectangle = _getDrawBounds(currentBounds, shapeLayoutBounds); _drawShape(currentPage.graphics, currentBounds.rect, drawRectangle); - result._bounds = - _getPageResultBounds(currentBounds, shapeLayoutBounds).rect; - shapeFinished = - currentBounds.height.toInt() >= shapeLayoutBounds.height.toInt(); + result._bounds = _getPageResultBounds(currentBounds, shapeLayoutBounds).rect; + shapeFinished = currentBounds.height.toInt() >= shapeLayoutBounds.height.toInt(); } - result._end = - shapeFinished || param.format!.layoutType == PdfLayoutType.onePage; + result._end = shapeFinished || param.format!.layoutType == PdfLayoutType.onePage; result._page = currentPage; return result; } - PdfRectangle _checkCorrectCurrentBounds( - PdfPage currentPage, - PdfRectangle currentBounds, - PdfRectangle shapeLayoutBounds, - PdfLayoutParams param) { + PdfRectangle _checkCorrectCurrentBounds(PdfPage currentPage, PdfRectangle currentBounds, + PdfRectangle shapeLayoutBounds, PdfLayoutParams param) { final Size pageSize = currentPage.graphics.clientSize; - currentBounds.width = (currentBounds.width > 0) - ? currentBounds.width - : pageSize.width - currentBounds.x; - currentBounds.height = (currentBounds.height > 0) - ? currentBounds.height - : pageSize.height - currentBounds.y; + currentBounds.width = + (currentBounds.width > 0) ? currentBounds.width : pageSize.width - currentBounds.x; + currentBounds.height = + (currentBounds.height > 0) ? currentBounds.height : pageSize.height - currentBounds.y; return currentBounds; } - bool _fitsToBounds( - PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { + bool _fitsToBounds(PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { final bool fits = shapeLayoutBounds.height <= currentBounds.height; return fits; } - PdfRectangle _getDrawBounds( - PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { - final PdfRectangle result = PdfRectangle(currentBounds.x, currentBounds.y, - currentBounds.width, currentBounds.height); + PdfRectangle _getDrawBounds(PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { + final PdfRectangle result = + PdfRectangle(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height); result.y -= shapeLayoutBounds.y; result.height += shapeLayoutBounds.y; return result; } - void _drawShape( - PdfGraphics g, Rect currentBounds, PdfRectangle drawRectangle) { + void _drawShape(PdfGraphics g, Rect currentBounds, PdfRectangle drawRectangle) { final PdfGraphicsState gState = g.save(); try { g.setClip(bounds: currentBounds); - element!.draw( - graphics: g, - bounds: Rect.fromLTWH(drawRectangle.x, drawRectangle.y, 0, 0)); + element!.draw(graphics: g, bounds: Rect.fromLTWH(drawRectangle.x, drawRectangle.y, 0, 0)); } finally { g.restore(gState); } } - PdfRectangle _getPageResultBounds( - PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { + PdfRectangle _getPageResultBounds(PdfRectangle currentBounds, PdfRectangle shapeLayoutBounds) { final PdfRectangle result = currentBounds; - result.height = (result.height > shapeLayoutBounds.height) - ? shapeLayoutBounds.height - : result.height; + result.height = + (result.height > shapeLayoutBounds.height) ? shapeLayoutBounds.height : result.height; return result; } - PdfRectangle _getNextShapeBounds( - PdfRectangle shapeLayoutBounds, _ShapeLayoutResult pageResult) { + PdfRectangle _getNextShapeBounds(PdfRectangle shapeLayoutBounds, _ShapeLayoutResult pageResult) { shapeLayoutBounds.y += pageResult._bounds!.height; shapeLayoutBounds.height -= pageResult._bounds!.height; return shapeLayoutBounds; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/text_layouter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/text_layouter.dart index d96c4cb39..b627d4081 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/text_layouter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/base/text_layouter.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../pages/pdf_page.dart'; @@ -27,8 +27,8 @@ class TextLayouter extends ElementLayouter { super.element is PdfTextElement ? super.element as PdfTextElement? : null; //Implementation - _TextPageLayoutResult _layoutOnPage(String text, PdfPage currentPage, - PdfRectangle currentBounds, PdfLayoutParams param) { + _TextPageLayoutResult _layoutOnPage( + String text, PdfPage currentPage, PdfRectangle currentBounds, PdfLayoutParams param) { final _TextPageLayoutResult result = _TextPageLayoutResult(); result.remainder = text; result.page = currentPage; @@ -36,19 +36,15 @@ class TextLayouter extends ElementLayouter { if (currentBounds.height < 0) { currentPage = getNextPage(currentPage)!; result.page = currentPage; - currentBounds = PdfRectangle( - currentBounds.x, 0, currentBounds.width, currentBounds.height); + currentBounds = PdfRectangle(currentBounds.x, 0, currentBounds.width, currentBounds.height); } final PdfStringLayouter layouter = PdfStringLayouter(); - final PdfStringLayoutResult stringResult = layouter.layout( - text, element!.font, _format, + final PdfStringLayoutResult stringResult = layouter.layout(text, element!.font, _format, bounds: currentBounds, pageHeight: currentPage.getClientSize().height); - final bool textFinished = - stringResult.remainder == null || stringResult.remainder!.isEmpty; - final bool doesntFit = - param.format!.breakType == PdfLayoutBreakType.fitElement && - currentPage == param.page && - !textFinished; + final bool textFinished = stringResult.remainder == null || stringResult.remainder!.isEmpty; + final bool doesntFit = param.format!.breakType == PdfLayoutBreakType.fitElement && + currentPage == param.page && + !textFinished; final bool canDraw = !(doesntFit || stringResult.isEmpty); if (canDraw) { final PdfGraphics graphics = currentPage.graphics; @@ -60,86 +56,69 @@ class TextLayouter extends ElementLayouter { currentBounds, _format); final LineInfo lineInfo = stringResult.lines![stringResult.lineCount - 1]; - result.lastLineBounds = PdfGraphicsHelper.getHelper(graphics) - .getLineBounds(stringResult.lineCount - 1, stringResult, - element!.font, currentBounds, _format); - result.bounds = - _getTextPageBounds(currentPage, currentBounds, stringResult); + result.lastLineBounds = PdfGraphicsHelper.getHelper(graphics).getLineBounds( + stringResult.lineCount - 1, stringResult, element!.font, currentBounds, _format); + result.bounds = _getTextPageBounds(currentPage, currentBounds, stringResult); result.remainder = stringResult.remainder; _checkCorectStringFormat(lineInfo); } else { - result.bounds = - _getTextPageBounds(currentPage, currentBounds, stringResult); + result.bounds = _getTextPageBounds(currentPage, currentBounds, stringResult); } final bool stopLayouting = stringResult.isEmpty && ((param.format!.breakType != PdfLayoutBreakType.fitElement) && (param.format!.layoutType != PdfLayoutType.paginate) && canDraw) || - (param.format!.breakType == PdfLayoutBreakType.fitElement && - currentPage != param.page); - result.end = textFinished || - stopLayouting || - param.format!.layoutType == PdfLayoutType.onePage; + (param.format!.breakType == PdfLayoutBreakType.fitElement && currentPage != param.page); + result.end = textFinished || stopLayouting || param.format!.layoutType == PdfLayoutType.onePage; return result; } - PdfRectangle _checkCorrectBounds( - PdfPage currentPage, PdfRectangle currentBounds) { + PdfRectangle _checkCorrectBounds(PdfPage currentPage, PdfRectangle currentBounds) { final Size pageSize = currentPage.graphics.clientSize; - currentBounds.height = (currentBounds.height > 0) - ? currentBounds.height - : pageSize.height - currentBounds.y; + currentBounds.height = + (currentBounds.height > 0) ? currentBounds.height : pageSize.height - currentBounds.y; return currentBounds; } - Rect _getTextPageBounds(PdfPage currentPage, PdfRectangle currentBounds, - PdfStringLayoutResult stringResult) { + Rect _getTextPageBounds( + PdfPage currentPage, PdfRectangle currentBounds, PdfStringLayoutResult stringResult) { final PdfSize textSize = stringResult.size; double? x = currentBounds.x; double? y = currentBounds.y; - final double width = - (currentBounds.width > 0) ? currentBounds.width : textSize.width; + final double width = (currentBounds.width > 0) ? currentBounds.width : textSize.width; final double height = textSize.height; - final PdfRectangle shiftedRect = - PdfGraphicsHelper.getHelper(currentPage.graphics) - .checkCorrectLayoutRectangle( - textSize, currentBounds.x, currentBounds.y, _format); + final PdfRectangle shiftedRect = PdfGraphicsHelper.getHelper(currentPage.graphics) + .checkCorrectLayoutRectangle(textSize, currentBounds.x, currentBounds.y, _format); if (currentBounds.width <= 0) { x = shiftedRect.x; } if (currentBounds.height <= 0) { y = shiftedRect.y; } - final double verticalShift = - PdfGraphicsHelper.getHelper(currentPage.graphics) - .getTextVerticalAlignShift( - textSize.height, currentBounds.height, _format); + final double verticalShift = PdfGraphicsHelper.getHelper(currentPage.graphics) + .getTextVerticalAlignShift(textSize.height, currentBounds.height, _format); y += verticalShift; return Rect.fromLTWH(x, y, width, height); } void _checkCorectStringFormat(LineInfo lineInfo) { if (_format != null) { - PdfStringFormatHelper.getHelper(_format!).firstLineIndent = (lineInfo - .lineType & - PdfStringLayouter.getLineTypeValue(LineType.newLineBreak)! > - 0) - ? PdfStringFormatHelper.getHelper(element!.stringFormat!) - .firstLineIndent - : 0; + PdfStringFormatHelper.getHelper(_format!).firstLineIndent = + (lineInfo.lineType & PdfStringLayouter.getLineTypeValue(LineType.newLineBreak)! > 0) + ? PdfStringFormatHelper.getHelper(element!.stringFormat!).firstLineIndent + : 0; } } PdfTextLayoutResult _getLayoutResult(_TextPageLayoutResult pageResult) { - return PdfTextLayoutResult._(pageResult.page, pageResult.bounds, - pageResult.remainder, pageResult.lastLineBounds); + return PdfTextLayoutResult._( + pageResult.page, pageResult.bounds, pageResult.remainder, pageResult.lastLineBounds); } bool _raiseBeforePageLayout(PdfPage? currentPage, Rect currentBounds) { bool cancel = false; if (PdfLayoutElementHelper.getHelper(element!).raiseBeginPageLayout) { - final BeginPageLayoutArgs args = - BeginPageLayoutArgs(currentBounds, currentPage!); + final BeginPageLayoutArgs args = BeginPageLayoutArgs(currentBounds, currentPage!); PdfLayoutElementHelper.getHelper(element!).onBeginPageLayout(args); cancel = args.cancel; currentBounds = args.bounds; @@ -201,8 +180,7 @@ class TextLayouter extends ElementLayouter { /// Represents the text lay outing result settings. class PdfTextLayoutResult extends PdfLayoutResult { //Contructor - PdfTextLayoutResult._( - PdfPage? page, Rect? bounds, String? remainder, Rect? lastLineBounds) + PdfTextLayoutResult._(PdfPage? page, Rect? bounds, String? remainder, Rect? lastLineBounds) : super._(page!, bounds!) { _remainder = remainder; _lastLineBounds = lastLineBounds; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_bezier_curve.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_bezier_curve.dart index 973ba731a..abcb229d0 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_bezier_curve.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_bezier_curve.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../pdf_graphics.dart'; @@ -10,8 +10,8 @@ class PdfBezierCurve extends PdfShapeElement { // constructor /// Initializes a new instance of the [PdfBezierCurve] class /// with the specified [PdfPen] and [Offset] structure. - PdfBezierCurve(Offset startPoint, Offset firstControlPoint, - Offset secondControlPoint, Offset endPoint, + PdfBezierCurve( + Offset startPoint, Offset firstControlPoint, Offset secondControlPoint, Offset endPoint, {PdfPen? pen}) { _helper = PdfBezierCurveHelper(this); if (pen != null) { @@ -79,8 +79,8 @@ class PdfBezierCurveHelper { /// internal method void drawInternal(PdfGraphics graphics, PdfRectangle bounds) { - graphics.drawBezier(base.startPoint, base.firstControlPoint, - base.secondControlPoint, base.endPoint, + graphics.drawBezier( + base.startPoint, base.firstControlPoint, base.secondControlPoint, base.endPoint, pen: PdfShapeElementHelper.obtainPen(base)); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_path.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_path.dart index 2332b6887..4059117aa 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_path.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_path.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../brushes/pdf_solid_brush.dart'; @@ -78,8 +78,7 @@ class PdfPath extends PdfShapeElement { void addPath(List pathPoints, List pathTypes) { final int count = pathPoints.length; if (count != pathTypes.length) { - throw ArgumentError.value( - 'The argument arrays should be of equal length.'); + throw ArgumentError.value('The argument arrays should be of equal length.'); } _helper.points.addAll(pathPoints); _helper.pathTypes.addAll(_assignPathtype(pathTypes)); @@ -87,8 +86,7 @@ class PdfPath extends PdfShapeElement { /// Adds a line void addLine(Offset point1, Offset point2) { - _addPoints([point1.dx, point1.dy, point2.dx, point2.dy], - PathPointType.line); + _addPoints([point1.dx, point1.dy, point2.dx, point2.dy], PathPointType.line); } /// Adds a rectangle @@ -112,8 +110,7 @@ class PdfPath extends PdfShapeElement { startFigure(); addArc(bounds, startAngle, sweepAngle); _addPoint( - Offset(bounds.left + bounds.width / 2, bounds.top + bounds.height / 2), - PathPointType.line); + Offset(bounds.left + bounds.width / 2, bounds.top + bounds.height / 2), PathPointType.line); closeFigure(); } @@ -125,8 +122,8 @@ class PdfPath extends PdfShapeElement { } /// Adds an bezier curve - void addBezier(Offset startPoint, Offset firstControlPoint, - Offset secondControlPoint, Offset endPoint) { + void addBezier( + Offset startPoint, Offset firstControlPoint, Offset secondControlPoint, Offset endPoint) { final List points = []; points.add(startPoint.dx); points.add(startPoint.dy); @@ -141,13 +138,8 @@ class PdfPath extends PdfShapeElement { /// Adds an arc void addArc(Rect bounds, double startAngle, double sweepAngle) { - final List> points = PdfGraphicsHelper.getBezierArcPoints( - bounds.left, - bounds.top, - bounds.left + bounds.width, - bounds.top + bounds.height, - startAngle, - sweepAngle); + final List> points = PdfGraphicsHelper.getBezierArcPoints(bounds.left, bounds.top, + bounds.left + bounds.width, bounds.top + bounds.height, startAngle, sweepAngle); final List list = []; for (int i = 0; i < points.length; ++i) { final List pt = points[i]; @@ -190,12 +182,9 @@ class PdfPath extends PdfShapeElement { if (_helper.points.isEmpty || _bStartFigure) { _addPoint(point, PathPointType.start); _bStartFigure = false; - } else if (point != - _helper.points.elementAt(_helper.points.length - 1) && - !_isBeziers3) { + } else if (point != _helper.points.elementAt(_helper.points.length - 1) && !_isBeziers3) { _addPoint(point, PathPointType.line); - } else if (point != - _helper.points.elementAt(_helper.points.length - 1)) { + } else if (point != _helper.points.elementAt(_helper.points.length - 1)) { _addPoint(point, PathPointType.bezier3); } } else { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_template.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_template.dart index 240f5a5ef..04f18aa05 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_template.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/figures/pdf_template.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../interfaces/pdf_interface.dart'; import '../../drawing/drawing.dart'; @@ -48,39 +48,34 @@ class PdfTemplate implements IPdfWrapper { _helper = PdfTemplateHelper(this); _helper.content = PdfStream(); _setSize(width, height); - _helper.content[PdfDictionaryProperties.type] = - PdfName(PdfDictionaryProperties.xObject); - _helper.content[PdfDictionaryProperties.subtype] = - PdfName(PdfDictionaryProperties.form); + _helper.content[PdfDictionaryProperties.type] = PdfName(PdfDictionaryProperties.xObject); + _helper.content[PdfDictionaryProperties.subtype] = PdfName(PdfDictionaryProperties.form); } PdfTemplate._fromRect(Rect bounds) { _helper = PdfTemplateHelper(this); _helper.content = PdfStream(); _setBounds(bounds); - _helper.content[PdfDictionaryProperties.type] = - PdfName(PdfDictionaryProperties.xObject); - _helper.content[PdfDictionaryProperties.subtype] = - PdfName(PdfDictionaryProperties.form); + _helper.content[PdfDictionaryProperties.type] = PdfName(PdfDictionaryProperties.xObject); + _helper.content[PdfDictionaryProperties.subtype] = PdfName(PdfDictionaryProperties.form); } PdfTemplate._fromPdfStream(PdfStream template) { _helper = PdfTemplateHelper(this); _helper.content = template; - final IPdfPrimitive obj = PdfCrossTable.dereference( - _helper.content[PdfDictionaryProperties.bBox])!; + final IPdfPrimitive obj = + PdfCrossTable.dereference(_helper.content[PdfDictionaryProperties.bBox])!; final PdfRectangle rect = (obj as PdfArray).toRectangle(); _size = rect.size; _helper.isReadonly = true; } - PdfTemplate._(Offset origin, Size size, List stream, - PdfDictionary resources, bool isLoadedPage, PdfPageHelper page) + PdfTemplate._(Offset origin, Size size, List stream, PdfDictionary resources, + bool isLoadedPage, PdfPageHelper page) : super() { _helper = PdfTemplateHelper(this); if (size == Size.zero) { - throw ArgumentError.value( - size, 'size', 'The size of the new PdfTemplate cannot be empty.'); + throw ArgumentError.value(size, 'size', 'The size of the new PdfTemplate cannot be empty.'); } _helper.content = PdfStream(); if (page.cropBox.left > 0 && page.cropBox.top > 0) { @@ -96,8 +91,7 @@ class PdfTemplate implements IPdfWrapper { } _initialize(); _helper.content.dataStream!.addAll(stream); - _helper.content[PdfDictionaryProperties.resources] = - PdfDictionary(resources); + _helper.content[PdfDictionaryProperties.resources] = PdfDictionary(resources); _helper._resources = PdfResources(resources); _helper.isLoadedPageTemplate = isLoadedPage; _helper.isReadonly = true; @@ -214,14 +208,12 @@ class PdfTemplate implements IPdfWrapper { void _setSize(double width, double height, [Offset? origin]) { if (origin != null) { - final PdfArray array = - PdfArray([origin.dx, origin.dy, width, height]); + final PdfArray array = PdfArray([origin.dx, origin.dy, width, height]); _helper.content[PdfDictionaryProperties.bBox] = array; _size = PdfSize(width, height); } else { final PdfRectangle rectangle = PdfRectangle(0, 0, width, height); - _helper.content[PdfDictionaryProperties.bBox] = - PdfArray.fromRectangle(rectangle); + _helper.content[PdfDictionaryProperties.bBox] = PdfArray.fromRectangle(rectangle); _size = PdfSize(width, height); } } @@ -234,10 +226,8 @@ class PdfTemplate implements IPdfWrapper { } void _initialize() { - _helper.content[PdfDictionaryProperties.type] = - PdfName(PdfDictionaryProperties.xObject); - _helper.content[PdfDictionaryProperties.subtype] = - PdfName(PdfDictionaryProperties.form); + _helper.content[PdfDictionaryProperties.type] = PdfName(PdfDictionaryProperties.xObject); + _helper.content[PdfDictionaryProperties.subtype] = PdfName(PdfDictionaryProperties.form); } } @@ -290,8 +280,8 @@ class PdfTemplateHelper { } /// internal method - static PdfTemplate internal(Offset origin, Size size, List stream, - PdfDictionary resources, bool isLoadedPage, PdfPageHelper page) { + static PdfTemplate internal(Offset origin, Size size, List stream, PdfDictionary resources, + bool isLoadedPage, PdfPageHelper page) { return PdfTemplate._(origin, size, stream, resources, isLoadedPage, page); } @@ -300,8 +290,7 @@ class PdfTemplateHelper { if (_resources != null && crossTable != null) { final List prevReference = crossTable.prevReference!; crossTable.prevReference = []; - final PdfDictionary? resourceDict = - _resources!.cloneObject(crossTable) as PdfDictionary?; + final PdfDictionary? resourceDict = _resources!.cloneObject(crossTable) as PdfDictionary?; crossTable.prevReference!.addAll(prevReference); _resources = PdfResources(resourceDict); content[PdfDictionaryProperties.resources] = resourceDict; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/fonts/pdf_font.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/fonts/pdf_font.dart index b0ac6114a..eb2e1b567 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/fonts/pdf_font.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/fonts/pdf_font.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../interfaces/pdf_interface.dart'; import 'enums.dart'; @@ -128,8 +128,8 @@ abstract class PdfFont implements IPdfWrapper { Size measureString(String text, {Size? layoutArea, PdfStringFormat? format}) { layoutArea ??= Size.zero; final PdfStringLayouter layouter = PdfStringLayouter(); - final PdfStringLayoutResult result = layouter.layout(text, this, format, - width: layoutArea.width, height: layoutArea.height); + final PdfStringLayoutResult result = + layouter.layout(text, this, format, width: layoutArea.width, height: layoutArea.height); return result.size.size; } @@ -139,8 +139,7 @@ abstract class PdfFont implements IPdfWrapper { double _getLineWidth(String line, PdfStringFormat? format); /// Applies settings to the default line width. - double _applyFormatSettings( - String line, PdfStringFormat? format, double width) { + double _applyFormatSettings(String line, PdfStringFormat? format, double width) { double realWidth = width; if (format != null && width > 0) { if (format.characterSpacing != 0) { @@ -210,18 +209,15 @@ class PdfFontHelper { /// internal field //ignore:unused_element - bool get isUnderline => - fontStyle & getPdfFontStyle(PdfFontStyle.underline) > 0; + bool get isUnderline => fontStyle & getPdfFontStyle(PdfFontStyle.underline) > 0; /// internal field //ignore:unused_element - bool get isStrikeout => - fontStyle & getPdfFontStyle(PdfFontStyle.strikethrough) > 0; + bool get isStrikeout => fontStyle & getPdfFontStyle(PdfFontStyle.strikethrough) > 0; /// Initializes a new instance of the [PdfFont] class /// with font size and style. - void initialize(double size, - {PdfFontStyle? style, List? multiStyle}) { + void initialize(double size, {PdfFontStyle? style, List? multiStyle}) { setSize(size); setStyle(style, multiStyle); } @@ -277,11 +273,9 @@ class PdfFontHelper { } /// internal method - static double getLineWidth( - PdfFont font, String line, PdfStringFormat? format) { + static double getLineWidth(PdfFont font, String line, PdfStringFormat? format) { if (font is PdfCjkStandardFont) { - return PdfCjkStandardFontHelper.getHelper(font) - .getLineWidth(line, format); + return PdfCjkStandardFontHelper.getHelper(font).getLineWidth(line, format); } else if (font is PdfStandardFont) { return PdfStandardFontHelper.getHelper(font).getLineWidth(line, format); } else if (font is PdfTrueTypeFont) { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_bitmap.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_bitmap.dart index b7c908192..e4cad62fa 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_bitmap.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_bitmap.dart @@ -1,5 +1,5 @@ import 'dart:convert'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/pdf_graphics.dart'; @@ -186,8 +186,7 @@ class PdfBitmap extends PdfImage { _height = _decoder!.height; _width = _decoder!.width; } - PdfImageHelper.setJpegOrientationAngle( - this, _decoder!.jpegDecoderOrientationAngle); + PdfImageHelper.setJpegOrientationAngle(this, _decoder!.jpegDecoderOrientationAngle); _imageStatus = false; } else { throw UnsupportedError('Invalid/Unsupported image stream'); @@ -196,38 +195,31 @@ class PdfBitmap extends PdfImage { void _setColorSpace() { final PdfStream stream = PdfImageHelper.getImageStream(this)!; - final PdfName? color = - stream[PdfDictionaryProperties.colorSpace] as PdfName?; + final PdfName? color = stream[PdfDictionaryProperties.colorSpace] as PdfName?; if (color!.name == PdfDictionaryProperties.deviceCMYK) { _helper.colorSpace = PdfColorSpace.cmyk; } else if (color.name == PdfDictionaryProperties.deviceGray) { _helper.colorSpace = PdfColorSpace.grayScale; } - if (_decoder is PngDecoder && - (_decoder! as PngDecoder).colorSpace != null) { + if (_decoder is PngDecoder && (_decoder! as PngDecoder).colorSpace != null) { _helper.colorSpace = PdfColorSpace.indexed; } switch (_helper.colorSpace) { case PdfColorSpace.cmyk: stream[PdfDictionaryProperties.decode] = PdfArray([1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0]); - stream[PdfDictionaryProperties.colorSpace] = - PdfName(PdfDictionaryProperties.deviceCMYK); + stream[PdfDictionaryProperties.colorSpace] = PdfName(PdfDictionaryProperties.deviceCMYK); break; case PdfColorSpace.grayScale: stream[PdfDictionaryProperties.decode] = PdfArray([0.0, 1.0]); - stream[PdfDictionaryProperties.colorSpace] = - PdfName(PdfDictionaryProperties.deviceGray); + stream[PdfDictionaryProperties.colorSpace] = PdfName(PdfDictionaryProperties.deviceGray); break; case PdfColorSpace.rgb: - stream[PdfDictionaryProperties.decode] = - PdfArray([0.0, 1.0, 0.0, 1.0, 0.0, 1.0]); - stream[PdfDictionaryProperties.colorSpace] = - PdfName(PdfDictionaryProperties.deviceRGB); + stream[PdfDictionaryProperties.decode] = PdfArray([0.0, 1.0, 0.0, 1.0, 0.0, 1.0]); + stream[PdfDictionaryProperties.colorSpace] = PdfName(PdfDictionaryProperties.deviceRGB); break; case PdfColorSpace.indexed: - stream[PdfDictionaryProperties.colorSpace] = - (_decoder! as PngDecoder).colorSpace; + stream[PdfDictionaryProperties.colorSpace] = (_decoder! as PngDecoder).colorSpace; break; // ignore: no_default_cases default: @@ -256,8 +248,7 @@ class PdfBitmapHelper { void save() { if (!bitmap._imageStatus) { bitmap._imageStatus = true; - PdfImageHelper.setImageStream( - bitmap, bitmap._decoder!.getImageDictionary()); + PdfImageHelper.setImageStream(bitmap, bitmap._decoder!.getImageDictionary()); if (bitmap._decoder!.format == ImageType.png) { final PngDecoder? decoder = bitmap._decoder as PngDecoder?; if (decoder != null && decoder.isDecode) { @@ -275,8 +266,7 @@ class PdfBitmapHelper { /// internal method void drawInternal(PdfGraphics graphics, PdfRectangle bounds) { - graphics.drawImage(bitmap, - Rect.fromLTWH(0, 0, bitmap._width * 0.75, bitmap._height * 0.75)); + graphics.drawImage(bitmap, Rect.fromLTWH(0, 0, bitmap._width * 0.75, bitmap._height * 0.75)); } /// internal method diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_image.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_image.dart index 30a75ab47..9549f0f3c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_image.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/images/pdf_image.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../interfaces/pdf_interface.dart'; import '../../primitives/pdf_stream.dart'; import '../figures/base/pdf_shape_element.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/pdf_graphics.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/pdf_graphics.dart index efe6f5a97..312d236b2 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/pdf_graphics.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/graphics/pdf_graphics.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../drawing/drawing.dart'; import '../general/pdf_collection.dart'; @@ -139,8 +139,7 @@ class PdfGraphics { /// //Dispose the document. /// doc.dispose(); /// ``` - Size get clientSize => - Size(_helper.clipBounds.width, _helper.clipBounds.height); + Size get clientSize => Size(_helper.clipBounds.width, _helper.clipBounds.height); //Public methods /// Changes the origin of the coordinate system @@ -265,8 +264,7 @@ class PdfGraphics { } } else { if (state._graphics != this) { - throw ArgumentError.value( - this, 'The graphics state belongs to another graphics object'); + throw ArgumentError.value(this, 'The graphics state belongs to another graphics object'); } if (_graphicsState.contains(state)) { while (true) { @@ -319,10 +317,7 @@ class PdfGraphics { s = _normalizeText(font, s); _helper.layoutString(s, font, - pen: pen, - brush: brush, - layoutRectangle: layoutRectangle, - format: format); + pen: pen, brush: brush, layoutRectangle: layoutRectangle, format: format); } /// Draws a line connecting the two points specified by the coordinate pairs. @@ -347,8 +342,7 @@ class PdfGraphics { _helper.streamWriter!.appendLineSegment(point2.dx, point2.dy); _helper.streamWriter!.strokePath(); _helper.endMarkContent(); - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.pdf); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.pdf); } /// Draws a rectangle specified by a pen, a brush and a Rect structure. @@ -370,12 +364,10 @@ class PdfGraphics { void drawRectangle({PdfPen? pen, PdfBrush? brush, required Rect bounds}) { _helper._beginMarkContent(); _helper._stateControl(pen, brush, null, null); - _helper.streamWriter! - .appendRectangle(bounds.left, bounds.top, bounds.width, bounds.height); + _helper.streamWriter!.appendRectangle(bounds.left, bounds.top, bounds.width, bounds.height); _drawPath(pen, brush, PdfFillMode.winding, false); _helper.endMarkContent(); - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.pdf); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.pdf); } /// Draws a template at the specified location and size. @@ -468,13 +460,11 @@ class PdfGraphics { void setClip({Rect? bounds, PdfPath? path, PdfFillMode? mode}) { if (bounds != null) { mode ??= PdfFillMode.winding; - _helper.streamWriter!.appendRectangle( - bounds.left, bounds.top, bounds.width, bounds.height); + _helper.streamWriter!.appendRectangle(bounds.left, bounds.top, bounds.width, bounds.height); _helper.streamWriter!.clipPath(mode == PdfFillMode.alternate); } else if (path != null) { mode ??= PdfPathHelper.getHelper(path).fillMode; - _buildUpPath(PdfPathHelper.getHelper(path).points, - PdfPathHelper.getHelper(path).pathTypes); + _buildUpPath(PdfPathHelper.getHelper(path).points, PdfPathHelper.getHelper(path).pathTypes); _helper.streamWriter!.clipPath(mode == PdfFillMode.alternate); } } @@ -496,15 +486,15 @@ class PdfGraphics { /// //Dispose the document. /// doc.dispose(); /// ``` - void drawBezier(Offset startPoint, Offset firstControlPoint, - Offset secondControlPoint, Offset endPoint, + void drawBezier( + Offset startPoint, Offset firstControlPoint, Offset secondControlPoint, Offset endPoint, {PdfPen? pen}) { _helper._beginMarkContent(); _helper._stateControl(pen, null, null, null); final PdfStreamWriter sw = _helper.streamWriter!; sw.beginPath(startPoint.dx, startPoint.dy); - sw.appendBezierSegment(firstControlPoint.dx, firstControlPoint.dy, - secondControlPoint.dx, secondControlPoint.dy, endPoint.dx, endPoint.dy); + sw.appendBezierSegment(firstControlPoint.dx, firstControlPoint.dy, secondControlPoint.dx, + secondControlPoint.dy, endPoint.dx, endPoint.dy); sw.strokePath(); _helper.endMarkContent(); } @@ -532,8 +522,7 @@ class PdfGraphics { void drawPath(PdfPath path, {PdfPen? pen, PdfBrush? brush}) { _helper._beginMarkContent(); _helper._stateControl(pen, brush, null, null); - _buildUpPath(PdfPathHelper.getHelper(path).points, - PdfPathHelper.getHelper(path).pathTypes); + _buildUpPath(PdfPathHelper.getHelper(path).points, PdfPathHelper.getHelper(path).pathTypes); _drawPath(pen, brush, PdfPathHelper.getHelper(path).fillMode, false); _helper.endMarkContent(); } @@ -555,15 +544,14 @@ class PdfGraphics { /// //Dispose the document. /// doc.dispose(); /// ``` - void drawPie(Rect bounds, double startAngle, double sweepAngle, - {PdfPen? pen, PdfBrush? brush}) { + void drawPie(Rect bounds, double startAngle, double sweepAngle, {PdfPen? pen, PdfBrush? brush}) { if (sweepAngle != 0) { _helper._beginMarkContent(); _helper._stateControl(pen, brush, null, null); _constructArcPath(bounds.left, bounds.top, bounds.left + bounds.width, bounds.top + bounds.height, startAngle, sweepAngle); - _helper.streamWriter!.appendLineSegment( - bounds.left + bounds.width / 2, bounds.top + bounds.height / 2); + _helper.streamWriter! + .appendLineSegment(bounds.left + bounds.width / 2, bounds.top + bounds.height / 2); _drawPath(pen, brush, PdfFillMode.winding, true); _helper.endMarkContent(); } @@ -588,8 +576,7 @@ class PdfGraphics { void drawEllipse(Rect bounds, {PdfPen? pen, PdfBrush? brush}) { _helper._beginMarkContent(); _helper._stateControl(pen, brush, null, null); - _constructArcPath( - bounds.left, bounds.top, bounds.right, bounds.bottom, 0, 360); + _constructArcPath(bounds.left, bounds.top, bounds.right, bounds.bottom, 0, 360); _drawPath(pen, brush, PdfFillMode.winding, true); _helper.endMarkContent(); } @@ -610,8 +597,7 @@ class PdfGraphics { /// //Dispose the document. /// doc.dispose(); /// ``` - void drawArc(Rect bounds, double startAngle, double sweepAngle, - {PdfPen? pen}) { + void drawArc(Rect bounds, double startAngle, double sweepAngle, {PdfPen? pen}) { if (sweepAngle != 0) { _helper._beginMarkContent(); _helper._stateControl(pen, null, null, null); @@ -645,12 +631,10 @@ class PdfGraphics { return; } _helper._stateControl(pen, brush, null, null); - _helper.streamWriter! - .beginPath(points.elementAt(0).dx, points.elementAt(0).dy); + _helper.streamWriter!.beginPath(points.elementAt(0).dx, points.elementAt(0).dy); for (int i = 1; i < points.length; ++i) { - _helper.streamWriter! - .appendLineSegment(points.elementAt(i).dx, points.elementAt(i).dy); + _helper.streamWriter!.appendLineSegment(points.elementAt(i).dx, points.elementAt(i).dy); } _drawPath(pen, brush, PdfFillMode.winding, true); _helper.endMarkContent(); @@ -694,16 +678,14 @@ class PdfGraphics { _helper._previousTextScaling = -100.0; _helper.clipBounds = PdfRectangle(0, 0, size.width, size.height); _graphicsState = []; - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.pdf); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.pdf); } void _drawImage(PdfImage image, Rect rectangle) { _helper._beginMarkContent(); final PdfRectangle bounds = PdfRectangle.fromRect( (rectangle.width <= 0 && rectangle.height <= 0) - ? Rect.fromLTWH(rectangle.left, rectangle.top, image.width * 0.75, - image.height * 0.75) + ? Rect.fromLTWH(rectangle.left, rectangle.top, image.width * 0.75, image.height * 0.75) : rectangle); PdfGraphicsState? beforeOrientation; final int angle = PdfImageHelper.getJpegOrientationAngle(image)!.toInt(); @@ -762,20 +744,15 @@ class PdfGraphics { _helper.endMarkContent(); (_helper._getResources!() as PdfResources) .requireProcset(PdfDictionaryProperties.grayScaleImage); - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.colorImage); - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.indexedImage); - (_helper._getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.text); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.colorImage); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.indexedImage); + (_helper._getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.text); } - void _drawPath( - PdfPen? pen, PdfBrush? brush, PdfFillMode fillMode, bool needClosing) { - final bool isPen = - pen != null && PdfColorHelper.getHelper(pen.color).isFilled; - final bool isBrush = brush != null && - PdfColorHelper.getHelper((brush as PdfSolidBrush).color).isFilled; + void _drawPath(PdfPen? pen, PdfBrush? brush, PdfFillMode fillMode, bool needClosing) { + final bool isPen = pen != null && PdfColorHelper.getHelper(pen.color).isFilled; + final bool isBrush = + brush != null && PdfColorHelper.getHelper((brush as PdfSolidBrush).color).isFilled; final bool isEvenOdd = fillMode == PdfFillMode.alternate; if (isPen && isBrush) { if (needClosing) { @@ -806,29 +783,23 @@ class PdfGraphics { _helper._beginMarkContent(); if (_helper.layer != null && PdfPageHelper.getHelper(_helper.page!).document != null && - PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).document!) + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).document!) .conformanceLevel != PdfConformanceLevel.none && PdfGraphicsHelper.getHelper(template.graphics!)._currentFont != null && - (PdfGraphicsHelper.getHelper(template.graphics!)._currentFont - is PdfStandardFont || - PdfGraphicsHelper.getHelper(template.graphics!)._currentFont - is PdfCjkStandardFont)) { + (PdfGraphicsHelper.getHelper(template.graphics!)._currentFont is PdfStandardFont || + PdfGraphicsHelper.getHelper(template.graphics!)._currentFont is PdfCjkStandardFont)) { throw ArgumentError( 'All the fonts must be embedded in ${PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).document!).conformanceLevel} document.'); } else if (_helper.layer != null && PdfPageHelper.getHelper(_helper.page!).document != null && - PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).document!) + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).document!) .conformanceLevel == PdfConformanceLevel.a1b && PdfGraphicsHelper.getHelper(template.graphics!)._currentFont != null && - PdfGraphicsHelper.getHelper(template.graphics!)._currentFont - is PdfTrueTypeFont) { + PdfGraphicsHelper.getHelper(template.graphics!)._currentFont is PdfTrueTypeFont) { PdfTrueTypeFontHelper.getHelper( - PdfGraphicsHelper.getHelper(template.graphics!)._currentFont! - as PdfTrueTypeFont) + PdfGraphicsHelper.getHelper(template.graphics!)._currentFont! as PdfTrueTypeFont) .fontInternal .initializeCidSet(); } @@ -837,13 +808,12 @@ class PdfGraphics { PdfCrossTable? crossTable; if (PdfPageHelper.getHelper(_helper.page!).isLoadedPage) { if (PdfPageHelper.getHelper(_helper.page!).section != null) { - crossTable = PdfDocumentHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).section!) - .document!) + crossTable = PdfDocumentHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).section!) + .document!) .crossTable; } else { - crossTable = PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).document!) + crossTable = PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).document!) .crossTable; } } else { @@ -852,17 +822,16 @@ class PdfGraphics { PdfPageHelper.getHelper(_helper.page!).section!) .document != null) - ? PdfDocumentHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).section!) - .document!) + ? PdfDocumentHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).section!) + .document!) .crossTable - : PdfDocumentHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).section!) - .pdfDocument!) + : PdfDocumentHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).section!) + .pdfDocument!) .crossTable; } else { - crossTable = PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(_helper.page!).document!) + crossTable = PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(_helper.page!).document!) .crossTable; } } @@ -876,10 +845,8 @@ class PdfGraphics { template.size > size) { size = template.size; } - final double scaleX = - (template.size.width > 0) ? size.width / template.size.width : 1; - final double scaleY = - (template.size.height > 0) ? size.height / template.size.height : 1; + final double scaleX = (template.size.width > 0) ? size.width / template.size.width : 1; + final double scaleY = (template.size.height > 0) ? size.height / template.size.height : 1; final bool hasScale = !(scaleX == 1 && scaleY == 1); final PdfGraphicsState state = save(); final PdfTransformationMatrix matrix = PdfTransformationMatrix(); @@ -888,24 +855,20 @@ class PdfGraphics { PdfTemplateHelper.getHelper(template).isLoadedPageTemplate && PdfPageHelper.getHelper(_helper.page!).isLoadedPage) { bool needTransformation = false; - final PdfDictionary dictionary = - PdfPageHelper.getHelper(_helper.page!).dictionary!; + final PdfDictionary dictionary = PdfPageHelper.getHelper(_helper.page!).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.cropBox) && dictionary.containsKey(PdfDictionaryProperties.mediaBox)) { PdfArray? cropBox; PdfArray? mediaBox; if (dictionary[PdfDictionaryProperties.cropBox] is PdfReferenceHolder) { - cropBox = (dictionary[PdfDictionaryProperties.cropBox]! - as PdfReferenceHolder) - .object as PdfArray?; + cropBox = (dictionary[PdfDictionaryProperties.cropBox]! as PdfReferenceHolder).object + as PdfArray?; } else { cropBox = dictionary[PdfDictionaryProperties.cropBox] as PdfArray?; } - if (dictionary[PdfDictionaryProperties.mediaBox] - is PdfReferenceHolder) { - mediaBox = (dictionary[PdfDictionaryProperties.mediaBox]! - as PdfReferenceHolder) - .object as PdfArray?; + if (dictionary[PdfDictionaryProperties.mediaBox] is PdfReferenceHolder) { + mediaBox = (dictionary[PdfDictionaryProperties.mediaBox]! as PdfReferenceHolder).object + as PdfArray?; } else { mediaBox = dictionary[PdfDictionaryProperties.mediaBox] as PdfArray?; } @@ -917,11 +880,9 @@ class PdfGraphics { } if (dictionary.containsKey(PdfDictionaryProperties.mediaBox)) { PdfArray? mBox; - if (dictionary[PdfDictionaryProperties.mediaBox] - is PdfReferenceHolder) { - mBox = (dictionary[PdfDictionaryProperties.mediaBox]! - as PdfReferenceHolder) - .object as PdfArray?; + if (dictionary[PdfDictionaryProperties.mediaBox] is PdfReferenceHolder) { + mBox = (dictionary[PdfDictionaryProperties.mediaBox]! as PdfReferenceHolder).object + as PdfArray?; } else { mBox = dictionary[PdfDictionaryProperties.mediaBox] as PdfArray?; } @@ -946,8 +907,7 @@ class PdfGraphics { PdfTemplateHelper.getHelper(template).origin.dy > 0 && location.dx == 0 && location.dy == 0) { - matrix.translate( - location.dx - PdfTemplateHelper.getHelper(template).origin.dx, + matrix.translate(location.dx - PdfTemplateHelper.getHelper(template).origin.dx, -(location.dy + size.height)); } else { matrix.translate(location.dx, -(location.dy + size.height)); @@ -966,20 +926,16 @@ class PdfGraphics { final PdfGraphics? g = template.graphics; if (g != null) { - for (final Object? fieldInfo in PdfObjectCollectionHelper.getHelper( - PdfGraphicsHelper.getHelper(g).autoFields!) - .list) { + for (final Object? fieldInfo + in PdfObjectCollectionHelper.getHelper(PdfGraphicsHelper.getHelper(g).autoFields!).list) { if (fieldInfo is PdfAutomaticFieldInfo) { - final PdfPoint newLocation = PdfPoint( - fieldInfo.location.x + location.dx, - fieldInfo.location.y + location.dy); - final double scalingX = - template.size.width == 0 ? 0 : size.width / template.size.width; - final double scalingY = template.size.height == 0 - ? 0 - : size.height / template.size.height; - _helper.autoFields!.add(PdfAutomaticFieldInfo( - fieldInfo.field, newLocation, scalingX, scalingY)); + final PdfPoint newLocation = + PdfPoint(fieldInfo.location.x + location.dx, fieldInfo.location.y + location.dy); + final double scalingX = template.size.width == 0 ? 0 : size.width / template.size.width; + final double scalingY = + template.size.height == 0 ? 0 : size.height / template.size.height; + _helper.autoFields! + .add(PdfAutomaticFieldInfo(fieldInfo.field, newLocation, scalingX, scalingY)); PdfPageHelper.getHelper(_helper.page!).dictionary!.modify(); } } @@ -1017,14 +973,12 @@ class PdfGraphics { case PathPointType.bezier3: Offset? p2, p3; - final Map returnValue = - _getBezierPoints(points, types, i, p2, p3); + final Map returnValue = _getBezierPoints(points, types, i, p2, p3); i = returnValue['i'] as int; final List p = returnValue['points'] as List; p2 = p.first; p3 = p.last; - _helper.streamWriter!.appendBezierSegment( - point.dx, point.dy, p2.dx, p2.dy, p3.dx, p3.dy); + _helper.streamWriter!.appendBezierSegment(point.dx, point.dy, p2.dx, p2.dy, p3.dx, p3.dy); break; case PathPointType.line: @@ -1038,8 +992,8 @@ class PdfGraphics { } } - Map _getBezierPoints(List points, - List types, int i, Offset? p2, Offset? p3) { + Map _getBezierPoints( + List points, List types, int i, Offset? p2, Offset? p3) { const String errorMsg = 'Malforming path.'; ++i; if (types[i] == PathPointType.bezier3) { @@ -1059,10 +1013,9 @@ class PdfGraphics { }; } - void _constructArcPath(double x1, double y1, double x2, double y2, - double startAng, double sweepAngle) { - final List> points = - _getBezierArcPoints(x1, y1, x2, y2, startAng, sweepAngle); + void _constructArcPath( + double x1, double y1, double x2, double y2, double startAng, double sweepAngle) { + final List> points = _getBezierArcPoints(x1, y1, x2, y2, startAng, sweepAngle); if (points.isEmpty) { return; } @@ -1070,13 +1023,12 @@ class PdfGraphics { _helper.streamWriter!.beginPath(pt[0], pt[1]); for (int i = 0; i < points.length; ++i) { pt = points.elementAt(i); - _helper.streamWriter! - .appendBezierSegment(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); + _helper.streamWriter!.appendBezierSegment(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]); } } - static List> _getBezierArcPoints(double x1, double y1, double x2, - double y2, double startAng, double extent) { + static List> _getBezierArcPoints( + double x1, double y1, double x2, double y2, double startAng, double extent) { if (x1 > x2) { double tmp; tmp = x1; @@ -1104,8 +1056,7 @@ class PdfGraphics { final double rx = (x2 - x1) / 2; final double ry = (y2 - y1) / 2; final double halfAng = fragAngle * pi / 360.0; - final double kappa = - (4.0 / 3.0 * (1.0 - cos(halfAng)) / sin(halfAng)).abs(); + final double kappa = (4.0 / 3.0 * (1.0 - cos(halfAng)) / sin(halfAng)).abs(); final List> pointList = >[]; for (int i = 0; i < numFragments; ++i) { final double theta0 = (startAng + i * fragAngle) * pi / 180.0; @@ -1213,8 +1164,7 @@ class _TransparencyData { @override // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => - alphaPen.hashCode + alphaBrush.hashCode + blendMode.hashCode; + int get hashCode => alphaPen.hashCode + alphaBrush.hashCode + blendMode.hashCode; } /// Specifies the text rendering mode. @@ -1348,8 +1298,7 @@ class PdfGraphicsHelper { void applyTransparency(double alpha, double alphaBrush, PdfBlendMode mode) { _trasparencies ??= <_TransparencyData, PdfTransparency>{}; PdfTransparency? transparency; - final _TransparencyData transparencyData = - _TransparencyData(alpha, alphaBrush, mode); + final _TransparencyData transparencyData = _TransparencyData(alpha, alphaBrush, mode); if (_trasparencies!.containsKey(transparencyData)) { transparency = _trasparencies![transparencyData]; } @@ -1357,8 +1306,7 @@ class PdfGraphicsHelper { transparency = PdfTransparency(alpha, alphaBrush, mode, conformance: layer != null && PdfPageHelper.getHelper(page!).document != null && - PdfDocumentHelper.getHelper( - PdfPageHelper.getHelper(page!).document!) + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!) .conformanceLevel == PdfConformanceLevel.a1b); _trasparencies![transparencyData] = transparency; @@ -1382,8 +1330,8 @@ class PdfGraphicsHelper { result = layouter.layout(s, font, format, width: layoutRectangle.width, height: layoutRectangle.height); if (!result.isEmpty) { - final PdfRectangle rectangle = checkCorrectLayoutRectangle( - result.size, layoutRectangle.x, layoutRectangle.y, format); + final PdfRectangle rectangle = + checkCorrectLayoutRectangle(result.size, layoutRectangle.x, layoutRectangle.y, format); if (layoutRectangle.width <= 0) { layoutRectangle.x = rectangle.x; layoutRectangle.width = rectangle.width; @@ -1397,58 +1345,44 @@ class PdfGraphicsHelper { } drawStringLayoutResult(result, font, pen, brush, layoutRectangle, format); stringLayoutResult = result; - (_getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.text); + (_getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.text); } } /// internal method - void drawStringLayoutResult( - PdfStringLayoutResult result, - PdfFont font, - PdfPen? pen, - PdfBrush? brush, - PdfRectangle layoutRectangle, - PdfStringFormat? format) { + void drawStringLayoutResult(PdfStringLayoutResult result, PdfFont font, PdfPen? pen, + PdfBrush? brush, PdfRectangle layoutRectangle, PdfStringFormat? format) { if (!result.isEmpty) { _beginMarkContent(); PdfGraphicsState? gState; if (font is PdfTrueTypeFont && - PdfTrueTypeFontHelper.getHelper(font).fontInternal.ttfMetrics != - null && - !PdfTrueTypeFontHelper.getHelper(font) - .fontInternal - .ttfMetrics! - .isItalic && + PdfTrueTypeFontHelper.getHelper(font).fontInternal.ttfMetrics != null && + !PdfTrueTypeFontHelper.getHelper(font).fontInternal.ttfMetrics!.isItalic && PdfFontHelper.getHelper(font).isItalic) { gState = base.save(); _isItalic = true; } _applyStringSettings(font, pen, brush, format, layoutRectangle); - final double textScaling = format != null - ? PdfStringFormatHelper.getHelper(format).scalingFactor - : 100.0; + final double textScaling = + format != null ? PdfStringFormatHelper.getHelper(format).scalingFactor : 100.0; if (textScaling != _previousTextScaling) { streamWriter!.setTextScaling(textScaling); _previousTextScaling = textScaling; } - double verticalAlignShift = getTextVerticalAlignShift( - result.size.height, layoutRectangle.height, format); + double verticalAlignShift = + getTextVerticalAlignShift(result.size.height, layoutRectangle.height, format); double? height; if (_isItalic) { height = (format == null || format.lineSpacing == 0) ? font.height : format.lineSpacing + font.height; - final bool subScript = format != null && - format.subSuperscript == PdfSubSuperscript.subscript; + final bool subScript = + format != null && format.subSuperscript == PdfSubSuperscript.subscript; final double shift = subScript - ? height - - (font.height + - PdfFontHelper.getHelper(font).metrics!.getDescent(format)) - : (height - - PdfFontHelper.getHelper(font).metrics!.getAscent(format)); - base.translateTransform(layoutRectangle.left + font.size / 5, - layoutRectangle.top - shift + verticalAlignShift); + ? height - (font.height + PdfFontHelper.getHelper(font).metrics!.getDescent(format)) + : (height - PdfFontHelper.getHelper(font).metrics!.getAscent(format)); + base.translateTransform( + layoutRectangle.left + font.size / 5, layoutRectangle.top - shift + verticalAlignShift); base.skewTransform(0, -11); } if (!_isItalic) { @@ -1456,14 +1390,9 @@ class PdfGraphicsHelper { matrix.translate( layoutRectangle.x, (-(layoutRectangle.y + font.height) - - (PdfFontHelper.getHelper(font).metrics!.getDescent(format) > - 0 - ? -PdfFontHelper.getHelper(font) - .metrics! - .getDescent(format) - : PdfFontHelper.getHelper(font) - .metrics! - .getDescent(format))) - + (PdfFontHelper.getHelper(font).metrics!.getDescent(format) > 0 + ? -PdfFontHelper.getHelper(font).metrics!.getDescent(format) + : PdfFontHelper.getHelper(font).metrics!.getDescent(format))) - verticalAlignShift); streamWriter!.modifyTransformationMatrix(matrix); } else { @@ -1475,29 +1404,26 @@ class PdfGraphicsHelper { streamWriter!.writeOperator(PdfOperators.setTextLeading); } if (layoutRectangle.height < font.size) { - if ((result.size.height - layoutRectangle.height) < - (font.size / 2) - 1) { + if ((result.size.height - layoutRectangle.height) < (font.size / 2) - 1) { verticalAlignShift = 0.0; } } _drawLayoutResult(result, font, format, layoutRectangle); if (verticalAlignShift != 0) { - streamWriter! - .startNextLine(0, -(verticalAlignShift - result.lineHeight)); + streamWriter!.startNextLine(0, -(verticalAlignShift - result.lineHeight)); } streamWriter!.endText(); if (gState != null) { base.restore(gState); _isItalic = false; } - _underlineStrikeoutText( - pen, brush, result, font, layoutRectangle, format); + _underlineStrikeoutText(pen, brush, result, font, layoutRectangle, format); endMarkContent(); } } - void _drawLayoutResult(PdfStringLayoutResult result, PdfFont font, - PdfStringFormat? format, PdfRectangle layoutRectangle) { + void _drawLayoutResult(PdfStringLayoutResult result, PdfFont font, PdfStringFormat? format, + PdfRectangle layoutRectangle) { bool? unicode = false; if (font is PdfTrueTypeFont) { unicode = PdfTrueTypeFontHelper.getHelper(font).unicode; @@ -1511,8 +1437,8 @@ class PdfGraphicsHelper { final String? line = lineInfo.text; final double? lineWidth = lineInfo.width; if ((line == null || line.isEmpty) && !_isItalic) { - final double verticalAlignShift = getTextVerticalAlignShift( - result.size.height, layoutRectangle.height, format); + final double verticalAlignShift = + getTextVerticalAlignShift(result.size.height, layoutRectangle.height, format); final PdfTransformationMatrix matrix = PdfTransformationMatrix(); double baseline = (-(layoutRectangle.y + font.height) - PdfFontHelper.getHelper(font).metrics!.getDescent(format)) - @@ -1523,8 +1449,7 @@ class PdfGraphicsHelper { } else { double horizontalAlignShift = _getHorizontalAlignShift(lineWidth, layoutRectangle.width, format); - final double? lineIndent = - _getLineIndent(lineInfo, format, layoutRectangle, i == 0); + final double? lineIndent = _getLineIndent(lineInfo, format, layoutRectangle, i == 0); horizontalAlignShift += (!_rightToLeft(format)) ? lineIndent! : 0; if (horizontalAlignShift != 0) { @@ -1540,8 +1465,8 @@ class PdfGraphicsHelper { if (i + 1 != lines.length) { if (!_isItalic) { - final double verticalAlignShift = getTextVerticalAlignShift( - result.size.height, layoutRectangle.height, format); + final double verticalAlignShift = + getTextVerticalAlignShift(result.size.height, layoutRectangle.height, format); final PdfTransformationMatrix matrix = PdfTransformationMatrix(); double baseline = (-(layoutRectangle.y + font.height) - PdfFontHelper.getHelper(font).metrics!.getDescent(format)) - @@ -1551,31 +1476,25 @@ class PdfGraphicsHelper { streamWriter!.modifyTransformationMatrix(matrix); } else { //tan(11) = 0.19486, theta value for italic skewAngle (11 degree). - streamWriter! - .startNextLine(font.height * 0.19486 - horizontalAlignShift, 0); + streamWriter!.startNextLine(font.height * 0.19486 - horizontalAlignShift, 0); } } } } - (_getResources!() as PdfResources) - .requireProcset(PdfDictionaryProperties.text); + (_getResources!() as PdfResources).requireProcset(PdfDictionaryProperties.text); } bool _rightToLeft(PdfStringFormat? format) { - bool rtl = - format != null && format.textDirection == PdfTextDirection.rightToLeft; + bool rtl = format != null && format.textDirection == PdfTextDirection.rightToLeft; if (format != null && format.textDirection != PdfTextDirection.none) { rtl = true; } return rtl; } - double _getHorizontalAlignShift( - double? lineWidth, double boundsWidth, PdfStringFormat? format) { + double _getHorizontalAlignShift(double? lineWidth, double boundsWidth, PdfStringFormat? format) { double shift = 0; - if (boundsWidth >= 0 && - format != null && - format.alignment != PdfTextAlignment.left) { + if (boundsWidth >= 0 && format != null && format.alignment != PdfTextAlignment.left) { switch (format.alignment) { case PdfTextAlignment.center: shift = (boundsWidth - lineWidth!) / 2; @@ -1591,16 +1510,16 @@ class PdfGraphicsHelper { return shift; } - void _drawAsciiLine(LineInfo lineInfo, PdfRectangle layoutRectangle, - PdfFont font, PdfStringFormat? format) { + void _drawAsciiLine( + LineInfo lineInfo, PdfRectangle layoutRectangle, PdfFont font, PdfStringFormat? format) { _justifyLine(lineInfo, layoutRectangle.width, format); final PdfString str = PdfString(lineInfo.text!); str.isAsciiEncode = true; streamWriter!.showNextLineText(str); } - void _drawCjkString(LineInfo lineInfo, PdfRectangle layoutRectangle, - PdfFont font, PdfStringFormat? format) { + void _drawCjkString( + LineInfo lineInfo, PdfRectangle layoutRectangle, PdfFont font, PdfStringFormat? format) { _justifyLine(lineInfo, layoutRectangle.width, format); final String line = lineInfo.text!; final List str = _getCjkString(line); @@ -1609,16 +1528,14 @@ class PdfGraphicsHelper { String _addChars(PdfTrueTypeFont font, String line, PdfStringFormat? format) { String text = line; - final UnicodeTrueTypeFont internalFont = - PdfTrueTypeFontHelper.getHelper(font).fontInternal; + final UnicodeTrueTypeFont internalFont = PdfTrueTypeFontHelper.getHelper(font).fontInternal; final TtfReader ttfReader = internalFont.reader; // Reconvert string according to unicode standard. text = ttfReader.convertString(text); if (format != null) { internalFont.setSymbols(line, ttfReader.internalUsedChars); } else { - PdfTrueTypeFontHelper.getHelper(font) - .setSymbols(text, ttfReader.internalUsedChars); + PdfTrueTypeFontHelper.getHelper(font).setSymbols(text, ttfReader.internalUsedChars); } ttfReader.internalUsedChars = null; final List bytes = PdfString.toUnicodeArray(text); @@ -1626,23 +1543,20 @@ class PdfGraphicsHelper { return text; } - void _drawUnicodeLine(LineInfo lineInfo, PdfRectangle layoutRectangle, - PdfFont font, PdfStringFormat? format) { + void _drawUnicodeLine( + LineInfo lineInfo, PdfRectangle layoutRectangle, PdfFont font, PdfStringFormat? format) { final String? line = lineInfo.text; - final bool useWordSpace = format != null && - (format.wordSpacing != 0 || - format.alignment == PdfTextAlignment.justify); + final bool useWordSpace = + format != null && (format.wordSpacing != 0 || format.alignment == PdfTextAlignment.justify); final PdfTrueTypeFont ttfFont = font as PdfTrueTypeFont; - final double wordSpacing = - _justifyLine(lineInfo, layoutRectangle.width, format); + final double wordSpacing = _justifyLine(lineInfo, layoutRectangle.width, format); if (format != null && format.textDirection != PdfTextDirection.none) { final ArabicShapeRenderer renderer = ArabicShapeRenderer(); final String txt = renderer.shape(line!.split(''), 0); final Bidi bidi = Bidi(); bidi.isVisualOrder = false; - final String result = bidi.getLogicalToVisualString(txt, - format.textDirection == PdfTextDirection.rightToLeft)['rtlText'] - as String; + final String result = bidi.getLogicalToVisualString( + txt, format.textDirection == PdfTextDirection.rightToLeft)['rtlText'] as String; bidi.isVisualOrder = true; final List blocks = []; if (useWordSpace) { @@ -1672,8 +1586,8 @@ class PdfGraphicsHelper { } } - void _drawUnicodeBlocks(List blocks, List words, - PdfTrueTypeFont font, PdfStringFormat? format, double wordSpacing) { + void _drawUnicodeBlocks(List blocks, List words, PdfTrueTypeFont font, + PdfStringFormat? format, double wordSpacing) { streamWriter!.startNextLine(); double x = 0; double xShift = 0; @@ -1681,19 +1595,15 @@ class PdfGraphicsHelper { double paragraphIndent = 0; try { if (format != null) { - firstLineIndent = - PdfStringFormatHelper.getHelper(format).firstLineIndent; + firstLineIndent = PdfStringFormatHelper.getHelper(format).firstLineIndent; paragraphIndent = format.paragraphIndent; PdfStringFormatHelper.getHelper(format).firstLineIndent = 0; format.paragraphIndent = 0; } double spaceWidth = - PdfTrueTypeFontHelper.getHelper(font).getCharWidth(' ', format) + - wordSpacing; - final double characterSpacing = - format != null ? format.characterSpacing : 0; - final double wordSpace = - format != null && wordSpacing == 0 ? format.wordSpacing : 0; + PdfTrueTypeFontHelper.getHelper(font).getCharWidth(' ', format) + wordSpacing; + final double characterSpacing = format != null ? format.characterSpacing : 0; + final double wordSpace = format != null && wordSpacing == 0 ? format.wordSpacing : 0; spaceWidth += characterSpacing + wordSpace; for (int i = 0; i < blocks.length; i++) { final String token = blocks[i]; @@ -1719,15 +1629,13 @@ class PdfGraphicsHelper { } } finally { if (format != null) { - PdfStringFormatHelper.getHelper(format).firstLineIndent = - firstLineIndent; + PdfStringFormatHelper.getHelper(format).firstLineIndent = firstLineIndent; format.paragraphIndent = paragraphIndent; } } } - dynamic _breakUnicodeLine( - String line, PdfTrueTypeFont ttfFont, List? words) { + dynamic _breakUnicodeLine(String line, PdfTrueTypeFont ttfFont, List? words) { words = line.split(' '); final List tokens = []; for (int i = 0; i < words.length; i++) { @@ -1746,8 +1654,7 @@ class PdfGraphicsHelper { return val; } - int _getTextRenderingMode( - PdfPen? pen, PdfBrush? brush, PdfStringFormat? format) { + int _getTextRenderingMode(PdfPen? pen, PdfBrush? brush, PdfStringFormat? format) { int tm = _TextRenderingMode.none; if (pen != null && brush != null) { tm = _TextRenderingMode.fillStroke; @@ -1762,16 +1669,13 @@ class PdfGraphicsHelper { return tm; } - void _applyStringSettings(PdfFont font, PdfPen? pen, PdfBrush? brush, - PdfStringFormat? format, PdfRectangle bounds) { + void _applyStringSettings( + PdfFont font, PdfPen? pen, PdfBrush? brush, PdfStringFormat? format, PdfRectangle bounds) { int renderingMode = _getTextRenderingMode(pen, brush, format); bool setLineWidth = false; if (font is PdfTrueTypeFont && PdfTrueTypeFontHelper.getHelper(font).fontInternal.ttfMetrics != null && - !PdfTrueTypeFontHelper.getHelper(font) - .fontInternal - .ttfMetrics! - .isBold && + !PdfTrueTypeFontHelper.getHelper(font).fontInternal.ttfMetrics!.isBold && PdfFontHelper.getHelper(font).isBold) { if (pen == null && brush != null && brush is PdfSolidBrush) { pen = PdfPen(brush.color); @@ -1788,8 +1692,7 @@ class PdfGraphicsHelper { streamWriter!.setTextRenderingMode(renderingMode); base._previousTextRenderingMode = renderingMode; } - final double characterSpace = - (format != null) ? format.characterSpacing : 0; + final double characterSpace = (format != null) ? format.characterSpacing : 0; if (characterSpace != base._previousCharacterSpacing) { streamWriter!.setCharacterSpacing(characterSpace); base._previousCharacterSpacing = characterSpace; @@ -1801,19 +1704,17 @@ class PdfGraphicsHelper { } } - void _stateControl( - PdfPen? pen, PdfBrush? brush, PdfFont? font, PdfStringFormat? format) { + void _stateControl(PdfPen? pen, PdfBrush? brush, PdfFont? font, PdfStringFormat? format) { if (brush != null) { if (layer != null) { if (!PdfPageHelper.getHelper(page!).isLoadedPage && - !PdfDocumentHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(page!).section!) - .pdfDocument!) + !PdfDocumentHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page!).section!) + .pdfDocument!) .isLoadedDocument) { if (_colorSpaceChanged == false) { if (page != null) { - base.colorSpace = - PdfPageHelper.getHelper(page!).document!.colorSpace; + base.colorSpace = PdfPageHelper.getHelper(page!).document!.colorSpace; } _colorSpaceChanged = true; } @@ -1823,9 +1724,9 @@ class PdfGraphicsHelper { } else if (pen != null) { if (layer != null) { if (!PdfPageHelper.getHelper(page!).isLoadedPage && - !PdfDocumentHelper.getHelper(PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(page!).section!) - .pdfDocument!) + !PdfDocumentHelper.getHelper( + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page!).section!) + .pdfDocument!) .isLoadedDocument) { base.colorSpace = PdfPageHelper.getHelper(page!).document!.colorSpace; } @@ -1839,10 +1740,8 @@ class PdfGraphicsHelper { void _initCurrentColorSpace(PdfColorSpace? colorspace) { if (!_isColorSpaceInitialized) { - streamWriter!.setColorSpace( - PdfName('Device${_colorSpaces[base.colorSpace]!}'), true); - streamWriter!.setColorSpace( - PdfName('Device${_colorSpaces[base.colorSpace]!}'), false); + streamWriter!.setColorSpace(PdfName('Device${_colorSpaces[base.colorSpace]!}'), true); + streamWriter!.setColorSpace(PdfName('Device${_colorSpaces[base.colorSpace]!}'), false); _isColorSpaceInitialized = true; } } @@ -1851,16 +1750,16 @@ class PdfGraphicsHelper { if (pen != null) { _currentPen = pen; base.colorSpace = PdfColorSpace.rgb; - PdfPenHelper.getHelper(pen).monitorChanges(_currentPen, streamWriter!, - _getResources, saveState, base.colorSpace, matrix); + PdfPenHelper.getHelper(pen).monitorChanges( + _currentPen, streamWriter!, _getResources, saveState, base.colorSpace, matrix); _currentPen = pen; } } void _brushControl(PdfBrush? brush, bool saveState) { if (brush != null) { - PdfBrushHelper.monitorChanges(brush as PdfSolidBrush, _currentBrush, - streamWriter, _getResources, saveState, base.colorSpace); + PdfBrushHelper.monitorChanges(brush as PdfSolidBrush, _currentBrush, streamWriter, + _getResources, saveState, base.colorSpace); _currentBrush = brush; brush = null; } @@ -1871,16 +1770,14 @@ class PdfGraphicsHelper { if ((font is PdfStandardFont || font is PdfCjkStandardFont) && layer != null && PdfPageHelper.getHelper(page!).document != null && - PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!) - .conformanceLevel != + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel != PdfConformanceLevel.none) { throw ArgumentError( 'All the fonts must be embedded in ${PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel} document.'); } else if (font is PdfTrueTypeFont && layer != null && PdfPageHelper.getHelper(page!).document != null && - PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!) - .conformanceLevel == + PdfDocumentHelper.getHelper(PdfPageHelper.getHelper(page!).document!).conformanceLevel == PdfConformanceLevel.a1b) { PdfTrueTypeFontHelper.getHelper(font).fontInternal.initializeCidSet(); } @@ -1893,8 +1790,8 @@ class PdfGraphicsHelper { final PdfResources resources = _getResources!() as PdfResources; _currentFont = font; currentStringFormat = format; - streamWriter!.setFont(font, resources.getName(font), - PdfFontHelper.getHelper(font).metrics!.getSize(format)!); + streamWriter!.setFont( + font, resources.getName(font), PdfFontHelper.getHelper(font).metrics!.getSize(format)!); } } } @@ -1910,9 +1807,7 @@ class PdfGraphicsHelper { if (_documentLayer != null) { if (PdfLayerHelper.getHelper(_documentLayer!).isEndState && PdfLayerHelper.getHelper(_documentLayer!).parentLayer.isNotEmpty) { - for (int i = 0; - i < PdfLayerHelper.getHelper(_documentLayer!).parentLayer.length; - i++) { + for (int i = 0; i < PdfLayerHelper.getHelper(_documentLayer!).parentLayer.length; i++) { streamWriter!.write('EMC\n'); } } @@ -1925,8 +1820,7 @@ class PdfGraphicsHelper { /// internal method PdfRectangle checkCorrectLayoutRectangle( PdfSize textSize, double? x, double? y, PdfStringFormat? format) { - final PdfRectangle layoutedRectangle = - PdfRectangle(x!, y!, textSize.width, textSize.width); + final PdfRectangle layoutedRectangle = PdfRectangle(x!, y!, textSize.width, textSize.width); if (format != null) { switch (format.alignment) { case PdfTextAlignment.center: @@ -1953,20 +1847,13 @@ class PdfGraphicsHelper { return layoutedRectangle; } - void _underlineStrikeoutText( - PdfPen? pen, - PdfBrush? brush, - PdfStringLayoutResult result, - PdfFont font, - PdfRectangle layoutRectangle, - PdfStringFormat? format) { - if (PdfFontHelper.getHelper(font).isUnderline | - PdfFontHelper.getHelper(font).isStrikeout) { - final PdfPen? linePen = - _createUnderlineStikeoutPen(pen, brush, font, format); + void _underlineStrikeoutText(PdfPen? pen, PdfBrush? brush, PdfStringLayoutResult result, + PdfFont font, PdfRectangle layoutRectangle, PdfStringFormat? format) { + if (PdfFontHelper.getHelper(font).isUnderline | PdfFontHelper.getHelper(font).isStrikeout) { + final PdfPen? linePen = _createUnderlineStikeoutPen(pen, brush, font, format); if (linePen != null) { - final double verticalShift = getTextVerticalAlignShift( - result.size.height, layoutRectangle.height, format); + final double verticalShift = + getTextVerticalAlignShift(result.size.height, layoutRectangle.height, format); double underlineYOffset = layoutRectangle.y + verticalShift + PdfFontHelper.getHelper(font).metrics!.getAscent(format) + @@ -1979,24 +1866,20 @@ class PdfGraphicsHelper { for (int i = 0; i < result.lines!.length; i++) { final LineInfo lineInfo = lines![i]; final double? lineWidth = lineInfo.width; - double horizontalShift = _getHorizontalAlignShift( - lineWidth, layoutRectangle.width, format); - final double? lineIndent = - _getLineIndent(lineInfo, format, layoutRectangle, i == 0); + double horizontalShift = + _getHorizontalAlignShift(lineWidth, layoutRectangle.width, format); + final double? lineIndent = _getLineIndent(lineInfo, format, layoutRectangle, i == 0); horizontalShift += (!_rightToLeft(format)) ? lineIndent! : 0; final double x1 = layoutRectangle.x + horizontalShift; - final double x2 = - (!_shouldJustify(lineInfo, layoutRectangle.width, format)) - ? x1 + lineWidth! - lineIndent! - : x1 + layoutRectangle.width - lineIndent!; + final double x2 = (!_shouldJustify(lineInfo, layoutRectangle.width, format)) + ? x1 + lineWidth! - lineIndent! + : x1 + layoutRectangle.width - lineIndent!; if (PdfFontHelper.getHelper(font).isUnderline) { - base.drawLine(linePen, Offset(x1, underlineYOffset), - Offset(x2, underlineYOffset)); + base.drawLine(linePen, Offset(x1, underlineYOffset), Offset(x2, underlineYOffset)); underlineYOffset += result.lineHeight; } if (PdfFontHelper.getHelper(font).isStrikeout) { - base.drawLine(linePen, Offset(x1, strikeoutYOffset), - Offset(x2, strikeoutYOffset)); + base.drawLine(linePen, Offset(x1, strikeoutYOffset), Offset(x2, strikeoutYOffset)); strikeoutYOffset += result.lineHeight; } } @@ -2006,8 +1889,7 @@ class PdfGraphicsHelper { PdfPen? _createUnderlineStikeoutPen( PdfPen? pen, PdfBrush? brush, PdfFont font, PdfStringFormat? format) { - final double lineWidth = - PdfFontHelper.getHelper(font).metrics!.getSize(format)! / 20; + final double lineWidth = PdfFontHelper.getHelper(font).metrics!.getSize(format)! / 20; PdfPen? linePen; if (pen != null) { linePen = PdfPen(pen.color, width: lineWidth); @@ -2028,10 +1910,7 @@ class PdfGraphicsHelper { final double cropY = (cropBox![1]! as PdfNumber).value!.toDouble(); final double cropW = (cropBox![2]! as PdfNumber).value!.toDouble(); final double cropH = (cropBox![3]! as PdfNumber).value!.toDouble(); - if (cropX != 0 || - cropY != 0 || - base.size.width == cropW || - base.size.height == cropH) { + if (cropX != 0 || cropY != 0 || base.size.width == cropW || base.size.height == cropH) { base.translateTransform(cropX, -cropH); } else { _translate(); @@ -2041,8 +1920,7 @@ class PdfGraphicsHelper { } void _translate() { - if (mediaBoxUpperRightBound == base.size.height || - mediaBoxUpperRightBound == 0) { + if (mediaBoxUpperRightBound == base.size.height || mediaBoxUpperRightBound == 0) { base.translateTransform(0, -base.size.height); } else { base.translateTransform(0, -mediaBoxUpperRightBound!); @@ -2053,8 +1931,7 @@ class PdfGraphicsHelper { void clipTranslateMarginsWithBounds(PdfRectangle clipBounds) { this.clipBounds = clipBounds; streamWriter!.writeComment('Clip margins.'); - streamWriter!.appendRectangle( - clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); + streamWriter!.appendRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); streamWriter!.closePath(); streamWriter!.clipPath(false); streamWriter!.writeComment('Translate co-ordinate system.'); @@ -2062,14 +1939,13 @@ class PdfGraphicsHelper { } /// internal method - void clipTranslateMargins(double x, double y, double left, double top, - double right, double bottom) { - final PdfRectangle clipArea = PdfRectangle(left, top, - base.size.width - left - right, base.size.height - top - bottom); + void clipTranslateMargins( + double x, double y, double left, double top, double right, double bottom) { + final PdfRectangle clipArea = + PdfRectangle(left, top, base.size.width - left - right, base.size.height - top - bottom); clipBounds = clipArea; streamWriter!.writeComment('Clip margins.'); - streamWriter!.appendRectangle( - clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); + streamWriter!.appendRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); streamWriter!.closePath(); streamWriter!.clipPath(false); streamWriter!.writeComment('Translate co-ordinate system.'); @@ -2092,11 +1968,8 @@ class PdfGraphicsHelper { for (final Object? fieldInfo in PdfObjectCollectionHelper.getHelper(_automaticFields!).list) { if (fieldInfo is PdfAutomaticFieldInfo) { - PdfAutomaticFieldHelper.getHelper(fieldInfo.field).performDraw( - base, - fieldInfo.location, - fieldInfo.scalingX, - fieldInfo.scalingY); + PdfAutomaticFieldHelper.getHelper(fieldInfo.field) + .performDraw(base, fieldInfo.location, fieldInfo.scalingX, fieldInfo.scalingY); } } } @@ -2111,8 +1984,7 @@ class PdfGraphicsHelper { group[PdfDictionaryProperties.k] = PdfBoolean(false); group[PdfDictionaryProperties.s] = PdfName('Transparency'); group[PdfDictionaryProperties.i] = PdfBoolean(false); - PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.group] = - group; + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.group] = group; } /// internal method @@ -2127,9 +1999,7 @@ class PdfGraphicsHelper { double getTextVerticalAlignShift( double? textHeight, double boundsHeight, PdfStringFormat? format) { double shift = 0; - if (boundsHeight >= 0 && - format != null && - format.lineAlignment != PdfVerticalAlignment.top) { + if (boundsHeight >= 0 && format != null && format.lineAlignment != PdfVerticalAlignment.top) { switch (format.lineAlignment) { case PdfVerticalAlignment.middle: shift = (boundsHeight - textHeight!) / 2; @@ -2150,33 +2020,28 @@ class PdfGraphicsHelper { PdfRectangle bounds = PdfRectangle.empty; if (!result.isEmpty && lineIndex < result.lineCount && lineIndex >= 0) { final LineInfo line = result.lines![lineIndex]; - final double verticalShift = getTextVerticalAlignShift( - result.size.height, layoutRectangle.height, format); - final double y = - verticalShift + layoutRectangle.y + (result.lineHeight * lineIndex); + final double verticalShift = + getTextVerticalAlignShift(result.size.height, layoutRectangle.height, format); + final double y = verticalShift + layoutRectangle.y + (result.lineHeight * lineIndex); final double? lineWidth = line.width; - double horizontalShift = - _getHorizontalAlignShift(lineWidth, layoutRectangle.width, format); - final double? lineIndent = - _getLineIndent(line, format, layoutRectangle, lineIndex == 0); + double horizontalShift = _getHorizontalAlignShift(lineWidth, layoutRectangle.width, format); + final double? lineIndent = _getLineIndent(line, format, layoutRectangle, lineIndex == 0); horizontalShift += (!_rightToLeft(format)) ? lineIndent! : 0; final double x = layoutRectangle.x + horizontalShift; - final double width = - (!_shouldJustify(line, layoutRectangle.width, format)) - ? lineWidth! - lineIndent! - : layoutRectangle.width - lineIndent!; + final double width = (!_shouldJustify(line, layoutRectangle.width, format)) + ? lineWidth! - lineIndent! + : layoutRectangle.width - lineIndent!; final double height = result.lineHeight; bounds = PdfRectangle(x, y, width, height); } return bounds.rect; } - double? _getLineIndent(LineInfo lineInfo, PdfStringFormat? format, - PdfRectangle layoutBounds, bool firstLine) { + double? _getLineIndent( + LineInfo lineInfo, PdfStringFormat? format, PdfRectangle layoutBounds, bool firstLine) { double? lineIndent = 0; - final bool firstParagraphLine = (lineInfo.lineType & - PdfStringLayouter.getLineTypeValue(LineType.firstParagraphLine)!) > - 0; + final bool firstParagraphLine = + (lineInfo.lineType & PdfStringLayouter.getLineTypeValue(LineType.firstParagraphLine)!) > 0; if (format != null && firstParagraphLine) { lineIndent = firstLine ? PdfStringFormatHelper.getHelper(format).firstLineIndent @@ -2190,11 +2055,9 @@ class PdfGraphicsHelper { String? _convertToUnicode(String text, PdfTrueTypeFont font) { String? token; - final TtfReader ttfReader = - PdfTrueTypeFontHelper.getHelper(font).fontInternal.reader; + final TtfReader ttfReader = PdfTrueTypeFontHelper.getHelper(font).fontInternal.reader; token = ttfReader.convertString(text); - PdfTrueTypeFontHelper.getHelper(font) - .setSymbols(text, ttfReader.internalUsedChars); + PdfTrueTypeFontHelper.getHelper(font).setSymbols(text, ttfReader.internalUsedChars); ttfReader.internalUsedChars = null; final List bytes = PdfString.toUnicodeArray(token); token = PdfString.byteToString(bytes); @@ -2207,14 +2070,12 @@ class PdfGraphicsHelper { return value; } - double _justifyLine( - LineInfo lineInfo, double boundsWidth, PdfStringFormat? format) { + double _justifyLine(LineInfo lineInfo, double boundsWidth, PdfStringFormat? format) { final String line = lineInfo.text!; double? lineWidth = lineInfo.width; final bool shouldJustify = _shouldJustify(lineInfo, boundsWidth, format); final bool hasWordSpacing = format != null && format.wordSpacing != 0; - final int whitespacesCount = - StringTokenizer.getCharacterCount(line, StringTokenizer.spaces); + final int whitespacesCount = StringTokenizer.getCharacterCount(line, StringTokenizer.spaces); double wordSpace = 0; if (shouldJustify) { if (hasWordSpacing) { @@ -2229,28 +2090,22 @@ class PdfGraphicsHelper { return wordSpace; } - bool _shouldJustify( - LineInfo lineInfo, double boundsWidth, PdfStringFormat? format) { + bool _shouldJustify(LineInfo lineInfo, double boundsWidth, PdfStringFormat? format) { final String line = lineInfo.text!; final double? lineWidth = lineInfo.width; - final bool justifyStyle = - format != null && format.alignment == PdfTextAlignment.justify; + final bool justifyStyle = format != null && format.alignment == PdfTextAlignment.justify; final bool goodWidth = boundsWidth >= 0 && lineWidth! < boundsWidth; - final int whitespacesCount = - StringTokenizer.getCharacterCount(line, StringTokenizer.spaces); - final bool hasSpaces = - whitespacesCount > 0 && line[0] != StringTokenizer.whiteSpace; - final bool goodLineBreakStyle = (lineInfo.lineType & - PdfStringLayouter.getLineTypeValue(LineType.layoutBreak)!) > - 0; - final bool shouldJustify = - justifyStyle && goodWidth && hasSpaces && goodLineBreakStyle; + final int whitespacesCount = StringTokenizer.getCharacterCount(line, StringTokenizer.spaces); + final bool hasSpaces = whitespacesCount > 0 && line[0] != StringTokenizer.whiteSpace; + final bool goodLineBreakStyle = + (lineInfo.lineType & PdfStringLayouter.getLineTypeValue(LineType.layoutBreak)!) > 0; + final bool shouldJustify = justifyStyle && goodWidth && hasSpaces && goodLineBreakStyle; return shouldJustify; } /// internal method - static List> getBezierArcPoints(double x1, double y1, double x2, - double y2, double startAng, double extent) { + static List> getBezierArcPoints( + double x1, double y1, double x2, double y2, double startAng, double extent) { return PdfGraphics._getBezierArcPoints(x1, y1, x2, y2, startAng, extent); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_layer.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_layer.dart index 87fe5a9c6..a97fe1dc4 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_layer.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_layer.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -37,8 +37,7 @@ class PdfLayer implements IPdfWrapper { late PdfLayerHelper _helper; bool _clipPageTemplates = true; PdfGraphics? _graphics; - final Map _graphicsMap = - {}; + final Map _graphicsMap = {}; final Map _pageGraphics = {}; bool _isEmptyLayer = false; String? _name; @@ -54,8 +53,7 @@ class PdfLayer implements IPdfWrapper { set name(String? value) { _name = value; if (_helper.dictionary != null && _name != null && _name != '') { - _helper.dictionary! - .setProperty(PdfDictionaryProperties.name, PdfString(_name!)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.name, PdfString(_name!)); } } @@ -63,9 +61,7 @@ class PdfLayer implements IPdfWrapper { bool get visible { if (_helper.dictionary != null && _helper.dictionary!.containsKey(PdfDictionaryProperties.visible)) { - _visible = - (_helper.dictionary![PdfDictionaryProperties.visible]! as PdfBoolean) - .value!; + _visible = (_helper.dictionary![PdfDictionaryProperties.visible]! as PdfBoolean).value!; } return _visible; } @@ -80,8 +76,7 @@ class PdfLayer implements IPdfWrapper { /// Gets the collection of child [PdfLayer] PdfLayerCollection get layers { - _layerCollection ??= - PdfLayerCollectionHelper.withLayer(_helper.document, _helper.layer); + _layerCollection ??= PdfLayerCollectionHelper.withLayer(_helper.document, _helper.layer); return _layerCollection!; } @@ -90,9 +85,7 @@ class PdfLayer implements IPdfWrapper { PdfGraphics createGraphics(PdfPage page) { _helper.page = page; if (_graphics == null) { - PdfPageHelper.getHelper(page) - .contents - .add(PdfReferenceHolder(_helper.layer)); + PdfPageHelper.getHelper(page).contents.add(PdfReferenceHolder(_helper.layer)); } final PdfResources? resource = PdfPageHelper.getHelper(page).getResources(); if (PdfLayerHelper.getHelper(_helper.layer!).layerId == null || @@ -100,8 +93,7 @@ class PdfLayer implements IPdfWrapper { PdfLayerHelper.getHelper(_helper.layer!).layerId = 'OCG_${PdfResources.globallyUniqueIdentifier}'; } - if (resource != null && - resource.containsKey(PdfDictionaryProperties.properties)) { + if (resource != null && resource.containsKey(PdfDictionaryProperties.properties)) { final PdfDictionary? propertie = resource[PdfDictionaryProperties.properties] as PdfDictionary?; if (propertie != null) { @@ -136,8 +128,7 @@ class PdfLayer implements IPdfWrapper { double ury = 0; final PdfArray? mediaBox = PdfPageHelper.getHelper(page) .dictionary! - .getValue(PdfDictionaryProperties.mediaBox, - PdfDictionaryProperties.parent) as PdfArray?; + .getValue(PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent) as PdfArray?; if (mediaBox != null) { // Lower Left X co-ordinate Value. llx = (mediaBox[0]! as PdfNumber).value!.toDouble(); @@ -149,12 +140,10 @@ class PdfLayer implements IPdfWrapper { ury = (mediaBox[3]! as PdfNumber).value!.toDouble(); } PdfArray? cropBox; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.cropBox)) { - cropBox = PdfPageHelper.getHelper(page).dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) - as PdfArray?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.cropBox)) { + cropBox = PdfPageHelper.getHelper(page) + .dictionary! + .getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) as PdfArray?; final double cropX = (cropBox![0]! as PdfNumber).value!.toDouble(); final double cropY = (cropBox[1]! as PdfNumber).value!.toDouble(); final double cropRX = (cropBox[2]! as PdfNumber).value!.toDouble(); @@ -162,40 +151,32 @@ class PdfLayer implements IPdfWrapper { if ((cropX < 0 || cropY < 0 || cropRX < 0 || cropRY < 0) && (cropY.abs().floor() == page.size.height.abs().floor()) && (cropX.abs().floor()) == page.size.width.abs().floor()) { - final Size pageSize = Size([cropX, cropRX].reduce(max), - [cropY, cropRY].reduce(max)); - _graphics = - PdfGraphicsHelper.load(pageSize, resources, _helper._content!); + final Size pageSize = + Size([cropX, cropRX].reduce(max), [cropY, cropRY].reduce(max)); + _graphics = PdfGraphicsHelper.load(pageSize, resources, _helper._content!); } else { - _graphics = - PdfGraphicsHelper.load(page.size, resources, _helper._content!); + _graphics = PdfGraphicsHelper.load(page.size, resources, _helper._content!); PdfGraphicsHelper.getHelper(_graphics!).cropBox = cropBox; } } else if ((llx < 0 || lly < 0 || urx < 0 || ury < 0) && (lly.abs().floor() == page.size.height.abs().floor()) && (urx.abs().floor() == page.size.width.abs().floor())) { - final Size pageSize = Size( - [llx, urx].reduce(max), [lly, ury].reduce(max)); + final Size pageSize = Size([llx, urx].reduce(max), [lly, ury].reduce(max)); if (pageSize.width <= 0 || pageSize.height <= 0) { - _graphics = - PdfGraphicsHelper.load(pageSize, resources, _helper._content!); + _graphics = PdfGraphicsHelper.load(pageSize, resources, _helper._content!); } } else { - _graphics = - PdfGraphicsHelper.load(page.size, resources, _helper._content!); + _graphics = PdfGraphicsHelper.load(page.size, resources, _helper._content!); } if (isPageHasMediaBox) { PdfGraphicsHelper.getHelper(_graphics!).mediaBoxUpperRightBound = ury; } if (!PdfPageHelper.getHelper(page).isLoadedPage) { final PdfSectionCollection? sectionCollection = - PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page).section!) - .parent; + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page).section!).parent; if (sectionCollection != null) { _graphics!.colorSpace = - PdfSectionCollectionHelper.getHelper(sectionCollection) - .document! - .colorSpace; + PdfSectionCollectionHelper.getHelper(sectionCollection).document!.colorSpace; } } if (!_graphicsMap.containsKey(_graphics)) { @@ -213,9 +194,7 @@ class PdfLayer implements IPdfWrapper { return _graphics!; } } - PdfGraphicsHelper.getHelper(_graphics!) - .streamWriter! - .write(PdfOperators.newLine); + PdfGraphicsHelper.getHelper(_graphics!).streamWriter!.write(PdfOperators.newLine); _graphics!.save(); PdfGraphicsHelper.getHelper(_graphics!).initializeCoordinates(); if (PdfGraphicsHelper.getHelper(_graphics!).hasTransparencyBrush) { @@ -227,12 +206,10 @@ class PdfLayer implements IPdfWrapper { .dictionary! .containsKey(PdfDictionaryProperties.rotate))) { PdfArray? cropBox; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.cropBox)) { - cropBox = PdfPageHelper.getHelper(page).dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) - as PdfArray?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.cropBox)) { + cropBox = PdfPageHelper.getHelper(page) + .dictionary! + .getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) as PdfArray?; } _updatePageRotation(page, _graphics, cropBox); } @@ -243,19 +220,12 @@ class PdfLayer implements IPdfWrapper { if (_clipPageTemplates) { if (PdfPageHelper.getHelper(page).origin.dx >= 0 && PdfPageHelper.getHelper(page).origin.dy >= 0) { - PdfGraphicsHelper.getHelper(_graphics!) - .clipTranslateMarginsWithBounds(clipRect); + PdfGraphicsHelper.getHelper(_graphics!).clipTranslateMarginsWithBounds(clipRect); } } else { - final PdfMargins margins = - PdfPageHelper.getHelper(page).section!.pageSettings.margins; + final PdfMargins margins = PdfPageHelper.getHelper(page).section!.pageSettings.margins; PdfGraphicsHelper.getHelper(_graphics!).clipTranslateMargins( - clipRect.x, - clipRect.y, - margins.left, - margins.top, - margins.right, - margins.bottom); + clipRect.x, clipRect.y, margins.left, margins.top, margins.right, margins.bottom); } } if (!_helper.pages.contains(page)) { @@ -265,17 +235,13 @@ class PdfLayer implements IPdfWrapper { return _graphics!; } - void _updatePageRotation( - PdfPage page, PdfGraphics? graphics, PdfArray? cropBox) { + void _updatePageRotation(PdfPage page, PdfGraphics? graphics, PdfArray? cropBox) { PdfNumber? rotation; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.rotate)) { - rotation = PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.rotate] as PdfNumber?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.rotate)) { + rotation = + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.rotate] as PdfNumber?; rotation ??= rotation = PdfCrossTable.dereference( - PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.rotate]) as PdfNumber?; + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.rotate]) as PdfNumber?; } else if (page.rotation != PdfPageRotateAngle.rotateAngle0) { if (page.rotation == PdfPageRotateAngle.rotateAngle90) { rotation = PdfNumber(90); @@ -290,22 +256,16 @@ class PdfLayer implements IPdfWrapper { graphics.rotateTransform(-90); if (cropBox != null) { final double height = (cropBox[3]! as PdfNumber).value!.toDouble(); - final Size cropBoxSize = Size( - (cropBox[2]! as PdfNumber).value!.toDouble(), - height != 0 - ? height - : (cropBox[1]! as PdfNumber).value!.toDouble()); - final Offset cropBoxOffset = Offset( - (cropBox[0]! as PdfNumber).value!.toDouble(), + final Size cropBoxSize = Size((cropBox[2]! as PdfNumber).value!.toDouble(), + height != 0 ? height : (cropBox[1]! as PdfNumber).value!.toDouble()); + final Offset cropBoxOffset = Offset((cropBox[0]! as PdfNumber).value!.toDouble(), (cropBox[1]! as PdfNumber).value!.toDouble()); if (page.size.height < cropBoxSize.height) { - PdfGraphicsHelper.getHelper(graphics).clipBounds.size = PdfSize( - page.size.height - cropBoxOffset.dy, - cropBoxSize.width - cropBoxOffset.dx); + PdfGraphicsHelper.getHelper(graphics).clipBounds.size = + PdfSize(page.size.height - cropBoxOffset.dy, cropBoxSize.width - cropBoxOffset.dx); } else { - PdfGraphicsHelper.getHelper(graphics).clipBounds.size = PdfSize( - cropBoxSize.height - cropBoxOffset.dy, - cropBoxSize.width - cropBoxOffset.dx); + PdfGraphicsHelper.getHelper(graphics).clipBounds.size = + PdfSize(cropBoxSize.height - cropBoxOffset.dy, cropBoxSize.width - cropBoxOffset.dx); } } else { PdfGraphicsHelper.getHelper(graphics).clipBounds.size = @@ -324,8 +284,8 @@ class PdfLayer implements IPdfWrapper { void _graphicsContent(PdfPage page) { final PdfStream stream = PdfStream(); - _graphics = PdfGraphicsHelper.load( - page.size, PdfPageHelper.getHelper(page).getResources, stream); + _graphics = + PdfGraphicsHelper.load(page.size, PdfPageHelper.getHelper(page).getResources, stream); PdfPageHelper.getHelper(page).contents.add(PdfReferenceHolder(stream)); stream.beginSave = _beginSaveContent; if (!_graphicsMap.containsKey(_graphics)) { @@ -438,8 +398,9 @@ class PdfLayerHelper { base._isEmptyLayer = true; if (parentLayer.isNotEmpty) { for (int i = 0; i < parentLayer.length; i++) { - PdfGraphicsHelper.getHelper(base._graphics!).streamWriter!.write( - '/OC /${PdfLayerHelper.getHelper(parentLayer[i]).layerId!} BDC\n'); + PdfGraphicsHelper.getHelper(base._graphics!) + .streamWriter! + .write('/OC /${PdfLayerHelper.getHelper(parentLayer[i]).layerId!} BDC\n'); } } if (base.name != null && base.name != '') { @@ -456,29 +417,27 @@ class PdfLayerHelper { /// internal method void parsingLayerPage() { - if (document != null && - PdfDocumentHelper.getHelper(document!).isLoadedDocument) { + if (document != null && PdfDocumentHelper.getHelper(document!).isLoadedDocument) { for (int i = 0; i < document!.pages.count; i++) { final PdfDictionary pageDictionary = PdfPageHelper.getHelper(document!.pages[i]).dictionary!; final PdfPage page = document!.pages[i]; if (pageDictionary.containsKey(PdfDictionaryProperties.resources)) { - final PdfDictionary? resources = PdfCrossTable.dereference( - pageDictionary[PdfDictionaryProperties.resources]) - as PdfDictionary?; - if (resources != null && - (resources.containsKey(PdfDictionaryProperties.properties)) || + final PdfDictionary? resources = + PdfCrossTable.dereference(pageDictionary[PdfDictionaryProperties.resources]) + as PdfDictionary?; + if (resources != null && (resources.containsKey(PdfDictionaryProperties.properties)) || (resources!.containsKey(PdfDictionaryProperties.xObject))) { - final PdfDictionary? properties = PdfCrossTable.dereference( - resources[PdfDictionaryProperties.properties]) - as PdfDictionary?; - final PdfDictionary? xObject = PdfCrossTable.dereference( - resources[PdfDictionaryProperties.xObject]) as PdfDictionary?; + final PdfDictionary? properties = + PdfCrossTable.dereference(resources[PdfDictionaryProperties.properties]) + as PdfDictionary?; + final PdfDictionary? xObject = + PdfCrossTable.dereference(resources[PdfDictionaryProperties.xObject]) + as PdfDictionary?; if (properties != null) { properties.items!.forEach((PdfName? key, IPdfPrimitive? value) { if (value is PdfReferenceHolder) { - final PdfDictionary? dictionary = - value.object as PdfDictionary?; + final PdfDictionary? dictionary = value.object as PdfDictionary?; _parsingDictionary(dictionary, value, page, key); } }); @@ -493,14 +452,10 @@ class PdfLayerHelper { if (dictionary.containsKey('OC')) { final PdfName? layerID = key; reference = dictionary['OC']! as PdfReferenceHolder; - dictionary = PdfCrossTable.dereference(dictionary['OC'])! - as PdfDictionary; - final bool isPresent = - _parsingDictionary(dictionary, reference, page, layerID)!; + dictionary = PdfCrossTable.dereference(dictionary['OC'])! as PdfDictionary; + final bool isPresent = _parsingDictionary(dictionary, reference, page, layerID)!; if (isPresent) { - PdfLayerHelper.getHelper(layer!) - .xobject - .add(layerID!.name!); + PdfLayerHelper.getHelper(layer!).xobject.add(layerID!.name!); } } }); @@ -514,23 +469,20 @@ class PdfLayerHelper { } } - bool? _parsingDictionary(PdfDictionary? dictionary, - PdfReferenceHolder? reference, PdfPage? page, PdfName? layerID) { + bool? _parsingDictionary( + PdfDictionary? dictionary, PdfReferenceHolder? reference, PdfPage? page, PdfName? layerID) { if (base._isPresent == null || !base._isPresent!) { base._isPresent = false; if (!dictionary!.containsKey(PdfDictionaryProperties.name) && dictionary.containsKey(PdfDictionaryProperties.ocg)) { if (dictionary.containsKey(PdfDictionaryProperties.ocg)) { final PdfArray? pdfArray = - PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ocg]) - as PdfArray?; + PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ocg]) as PdfArray?; if (pdfArray == null) { - reference = - dictionary[PdfDictionaryProperties.ocg] as PdfReferenceHolder?; - dictionary = PdfCrossTable.dereference( - dictionary[PdfDictionaryProperties.ocg]) as PdfDictionary?; - if (dictionary != null && - dictionary.containsKey(PdfDictionaryProperties.name)) { + reference = dictionary[PdfDictionaryProperties.ocg] as PdfReferenceHolder?; + dictionary = PdfCrossTable.dereference(dictionary[PdfDictionaryProperties.ocg]) + as PdfDictionary?; + if (dictionary != null && dictionary.containsKey(PdfDictionaryProperties.name)) { base._isPresent = _setLayerPage(reference, page, layerID); } } else { @@ -552,14 +504,11 @@ class PdfLayerHelper { } } - bool _setLayerPage( - PdfReferenceHolder? reference, PdfPage? page, PdfName? layerID) { + bool _setLayerPage(PdfReferenceHolder? reference, PdfPage? page, PdfName? layerID) { bool isPresent = false; if (PdfLayerHelper.getHelper(layer!).referenceHolder != null) { - if (identical( - PdfLayerHelper.getHelper(layer!).referenceHolder, reference) || - identical(PdfLayerHelper.getHelper(layer!).referenceHolder!.object, - reference!.object) || + if (identical(PdfLayerHelper.getHelper(layer!).referenceHolder, reference) || + identical(PdfLayerHelper.getHelper(layer!).referenceHolder!.object, reference!.object) || PdfLayerHelper.getHelper(layer!).referenceHolder?.reference?.objNum == reference.reference?.objNum) { PdfLayerHelper.getHelper(layer!).pageParsed = true; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page.dart index 4e89a0a0f..0c9b6592e 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../annotations/pdf_annotation_collection.dart'; @@ -66,8 +66,8 @@ class PdfPage implements IPdfWrapper { _initialize(); } - PdfPage._fromDictionary(PdfDocument document, PdfCrossTable crossTable, - PdfDictionary dictionary) { + PdfPage._fromDictionary( + PdfDocument document, PdfCrossTable crossTable, PdfDictionary dictionary) { _helper = PdfPageHelper(this); _helper._pdfDocument = document; _helper.dictionary = dictionary; @@ -104,10 +104,10 @@ class PdfPage implements IPdfWrapper { if (_size == null || (_size!.width == 0 && _size!.height == 0)) { double width = 0; double height = 0; - final IPdfPrimitive? mBox = _helper.dictionary!.getValue( - PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent); - final IPdfPrimitive? cBox = _helper.dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent); + final IPdfPrimitive? mBox = _helper.dictionary! + .getValue(PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent); + final IPdfPrimitive? cBox = _helper.dictionary! + .getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent); if (cBox != null && cBox is PdfArray) { final num c0 = (cBox[0]! as PdfNumber).value!; final num? c1 = (cBox[1]! as PdfNumber).value; @@ -154,11 +154,9 @@ class PdfPage implements IPdfWrapper { _helper._annotations = PdfAnnotationCollection(this); if (!_helper.dictionary!.containsKey(PdfDictionaryProperties.annots)) { _helper.dictionary![PdfDictionaryProperties.annots] = - PdfAnnotationCollectionHelper.getHelper(_helper._annotations!) - .internalAnnotations; + PdfAnnotationCollectionHelper.getHelper(_helper._annotations!).internalAnnotations; } - PdfAnnotationCollectionHelper.getHelper(_helper._annotations!) - .internalAnnotations = + PdfAnnotationCollectionHelper.getHelper(_helper._annotations!).internalAnnotations = _helper.dictionary![PdfDictionaryProperties.annots] as PdfArray?; } } else { @@ -334,10 +332,7 @@ class PdfPage implements IPdfWrapper { Size getClientSize() { return _helper.isLoadedPage ? size - : PdfSectionHelper.getHelper(_helper.section!) - .getActualBounds(this, true) - .size - .size; + : PdfSectionHelper.getHelper(_helper.section!).getActualBounds(this, true).size.size; } /// Creates a template from the page content. @@ -378,30 +373,26 @@ class PdfPage implements IPdfWrapper { void _drawPageTemplates(PdfDocument doc) { // Draw Background templates. - final bool hasBackTemplates = PdfSectionHelper.getHelper(_helper.section!) - .containsTemplates(doc, this, false); + final bool hasBackTemplates = + PdfSectionHelper.getHelper(_helper.section!).containsTemplates(doc, this, false); if (hasBackTemplates) { - final PdfPageLayer backLayer = - PdfPageLayerHelper.fromClipPageTemplate(this, false); + final PdfPageLayer backLayer = PdfPageLayerHelper.fromClipPageTemplate(this, false); final PdfPageLayerCollection layer = PdfPageLayerCollection(this); _layers = layer; _layers!.addLayer(backLayer); - PdfSectionHelper.getHelper(_helper.section!) - .drawTemplates(this, backLayer, doc, false); + PdfSectionHelper.getHelper(_helper.section!).drawTemplates(this, backLayer, doc, false); } // Draw Foreground templates. - final bool hasFrontTemplates = PdfSectionHelper.getHelper(_helper.section!) - .containsTemplates(doc, this, true); + final bool hasFrontTemplates = + PdfSectionHelper.getHelper(_helper.section!).containsTemplates(doc, this, true); if (hasFrontTemplates) { - final PdfPageLayer frontLayer = - PdfPageLayerHelper.fromClipPageTemplate(this, false); + final PdfPageLayer frontLayer = PdfPageLayerHelper.fromClipPageTemplate(this, false); final PdfPageLayerCollection layer = PdfPageLayerCollection(this); _layers = layer; _layers!.addLayer(frontLayer); - PdfSectionHelper.getHelper(_helper.section!) - .drawTemplates(this, frontLayer, doc, true); + PdfSectionHelper.getHelper(_helper.section!).drawTemplates(this, frontLayer, doc, true); } } @@ -412,8 +403,7 @@ class PdfPage implements IPdfWrapper { if (parent.containsKey(PdfDictionaryProperties.rotate)) { if (parent[PdfDictionaryProperties.rotate] is PdfReferenceHolder) { angle = - (parent[PdfDictionaryProperties.rotate]! as PdfReferenceHolder) - .object as PdfNumber?; + (parent[PdfDictionaryProperties.rotate]! as PdfReferenceHolder).object as PdfNumber?; } else { angle = parent[PdfDictionaryProperties.rotate] as PdfNumber?; } @@ -422,9 +412,8 @@ class PdfPage implements IPdfWrapper { IPdfPrimitive? parentPrimitive = parent[PdfDictionaryProperties.parent]; if (parentPrimitive != null) { parentPrimitive = PdfCrossTable.dereference(parentPrimitive); - parent = parentPrimitive != null && parentPrimitive is PdfDictionary - ? parentPrimitive - : null; + parent = + parentPrimitive != null && parentPrimitive is PdfDictionary ? parentPrimitive : null; } else { parent = null; } @@ -436,8 +425,7 @@ class PdfPage implements IPdfWrapper { if (angle.value!.toInt() < 0) { angle.value = 360 + angle.value!.toInt(); } - final PdfPageRotateAngle rotateAngle = - _getRotationFromAngle(angle.value! ~/ 90); + final PdfPageRotateAngle rotateAngle = _getRotationFromAngle(angle.value! ~/ 90); return rotateAngle; } @@ -481,8 +469,8 @@ class PdfPageHelper { } /// internal method - static PdfPage fromDictionary(PdfDocument document, PdfCrossTable crossTable, - PdfDictionary dictionary) { + static PdfPage fromDictionary( + PdfDocument document, PdfCrossTable crossTable, PdfDictionary dictionary) { return PdfPage._fromDictionary(document, crossTable, dictionary); } @@ -535,9 +523,7 @@ class PdfPageHelper { /// internal method Offset get origin { if (section != null) { - return PdfPageSettingsHelper.getHelper(section!.pageSettings) - .origin - .offset; + return PdfPageSettingsHelper.getHelper(section!.pageSettings).origin.offset; } else { return Offset.zero; } @@ -550,8 +536,7 @@ class PdfPageHelper { } else { if (section != null) { if (PdfSectionHelper.getHelper(section!).parent != null) { - return PdfSectionCollectionHelper.getHelper( - PdfSectionHelper.getHelper(section!).parent!) + return PdfSectionCollectionHelper.getHelper(PdfSectionHelper.getHelper(section!).parent!) .document; } else if (PdfSectionHelper.getHelper(section!).document != null) { return PdfSectionHelper.getHelper(section!).document; @@ -571,8 +556,8 @@ class PdfPageHelper { /// Gets the crop box. Rect get cropBox { if (_cBox.isEmpty) { - final IPdfPrimitive? cBox = dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent); + final IPdfPrimitive? cBox = + dictionary!.getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent); if (cBox != null && cBox is PdfArray) { final double width = (cBox[2]! as PdfNumber).value!.toDouble(); final double height = (cBox[3]! as PdfNumber).value != 0 @@ -589,8 +574,8 @@ class PdfPageHelper { /// Gets the media box. Rect get mediaBox { if (_mBox.isEmpty) { - final IPdfPrimitive? mBox = dictionary!.getValue( - PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent); + final IPdfPrimitive? mBox = + dictionary!.getValue(PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent); if (mBox != null && mBox is PdfArray) { final double width = (mBox[2]! as PdfNumber).value!.toDouble(); final double height = (mBox[3]! as PdfNumber).value != 0 @@ -606,8 +591,7 @@ class PdfPageHelper { /// Gets array of page's content. PdfArray get contents { - final IPdfPrimitive? contentArray = - dictionary![PdfDictionaryProperties.contents]; + final IPdfPrimitive? contentArray = dictionary![PdfDictionaryProperties.contents]; PdfArray? elements; if (contentArray is PdfReferenceHolder) { final PdfReferenceHolder holder = contentArray; @@ -663,8 +647,7 @@ class PdfPageHelper { _resources = PdfResources(); dictionary![PdfDictionaryProperties.resources] = _resources; } else { - if (!dictionary!.containsKey(PdfDictionaryProperties.resources) || - _checkResources) { + if (!dictionary!.containsKey(PdfDictionaryProperties.resources) || _checkResources) { _resources = PdfResources(); dictionary![PdfDictionaryProperties.resources] = _resources; // Check for the resources in the corresponding page section. @@ -683,43 +666,36 @@ class PdfPageHelper { dictionary![PdfDictionaryProperties.resources] = obj; _resources = PdfResources(obj); final PdfDictionary xobjects = PdfDictionary(); - if (_resources! - .containsKey(PdfDictionaryProperties.xObject)) { + if (_resources!.containsKey(PdfDictionaryProperties.xObject)) { final PdfDictionary? xObject = - _resources![PdfDictionaryProperties.xObject] - as PdfDictionary?; + _resources![PdfDictionaryProperties.xObject] as PdfDictionary?; if (xObject != null) { - final IPdfPrimitive? content = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.contents]); + final IPdfPrimitive? content = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.contents]); if (content != null) { if (content is PdfArray) { for (int i = 0; i < content.count; i++) { final PdfStream pageContent = - PdfCrossTable.dereference(content[i])! - as PdfStream; + PdfCrossTable.dereference(content[i])! as PdfStream; pageContent.decompress(); } } else if (content is PdfStream) { content.decompress(); } } - _resources!.setProperty( - PdfDictionaryProperties.xObject, xobjects); + _resources!.setProperty(PdfDictionaryProperties.xObject, xobjects); setResources(_resources); } } } else if (obj is PdfReferenceHolder) { bool isValueEqual = false; - final PdfDictionary pageSourceDictionary = - obj.object! as PdfDictionary; - if (pageSourceDictionary.items!.length == - _resources!.items!.length || + final PdfDictionary pageSourceDictionary = obj.object! as PdfDictionary; + if (pageSourceDictionary.items!.length == _resources!.items!.length || _resources!.items!.isEmpty) { for (final PdfName? key in _resources!.items!.keys) { if (pageSourceDictionary.items!.containsKey(key)) { - if (pageSourceDictionary.items! - .containsValue(_resources![key])) { + if (pageSourceDictionary.items!.containsValue(_resources![key])) { isValueEqual = true; } } else { @@ -738,19 +714,16 @@ class PdfPageHelper { } } } else { - final IPdfPrimitive? dicObj = - dictionary![PdfDictionaryProperties.resources]; - final PdfDictionary? dic = - crossTable!.getObject(dicObj) as PdfDictionary?; + final IPdfPrimitive? dicObj = dictionary![PdfDictionaryProperties.resources]; + final PdfDictionary? dic = crossTable!.getObject(dicObj) as PdfDictionary?; _resources = PdfResources(dic); dictionary![PdfDictionaryProperties.resources] = _resources; if (dictionary!.containsKey(PdfDictionaryProperties.parent)) { - final PdfDictionary? parentDic = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.parent]) as PdfDictionary?; - if (parentDic != null && - parentDic.containsKey(PdfDictionaryProperties.resources)) { - final IPdfPrimitive? resource = - parentDic[PdfDictionaryProperties.resources]; + final PdfDictionary? parentDic = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.parent]) + as PdfDictionary?; + if (parentDic != null && parentDic.containsKey(PdfDictionaryProperties.resources)) { + final IPdfPrimitive? resource = parentDic[PdfDictionaryProperties.resources]; if (dicObj is PdfReferenceHolder && resource is PdfReferenceHolder && resource.reference == dicObj.reference) { @@ -780,45 +753,35 @@ class PdfPageHelper { void createAnnotations(List widgetReferences) { IPdfPrimitive? annots; if (dictionary!.containsKey(PdfDictionaryProperties.annots)) { - annots = - crossTable!.getObject(dictionary![PdfDictionaryProperties.annots]); + annots = crossTable!.getObject(dictionary![PdfDictionaryProperties.annots]); if (annots != null && annots is PdfArray) { for (int count = 0; count < annots.count; ++count) { PdfDictionary? annotDictionary; if (crossTable!.getObject(annots[count]) is PdfDictionary) { - annotDictionary = - crossTable!.getObject(annots[count]) as PdfDictionary?; + annotDictionary = crossTable!.getObject(annots[count]) as PdfDictionary?; } PdfReferenceHolder? annotReference; if (crossTable!.getObject(annots[count]) is PdfReferenceHolder) { - annotReference = - crossTable!.getObject(annots[count]) as PdfReferenceHolder?; + annotReference = crossTable!.getObject(annots[count]) as PdfReferenceHolder?; } if (document != null && - PdfDocumentHelper.getHelper(document!).crossTable.encryptor != - null && - PdfDocumentHelper.getHelper(document!) - .crossTable - .encryptor! - .encryptAttachmentOnly!) { + PdfDocumentHelper.getHelper(document!).crossTable.encryptor != null && + PdfDocumentHelper.getHelper(document!).crossTable.encryptor!.encryptAttachmentOnly!) { if (annotDictionary != null && annotDictionary.containsKey(PdfDictionaryProperties.subtype)) { - final IPdfPrimitive? primitive = annotDictionary - .items![PdfName(PdfDictionaryProperties.subtype)]; + final IPdfPrimitive? primitive = + annotDictionary.items![PdfName(PdfDictionaryProperties.subtype)]; if (primitive is PdfName && primitive.name == 'FileAttachment' && annotDictionary.containsKey(PdfDictionaryProperties.fs)) { - final IPdfPrimitive? file = - annotDictionary[PdfDictionaryProperties.fs]; + final IPdfPrimitive? file = annotDictionary[PdfDictionaryProperties.fs]; if (file != null && file is PdfReferenceHolder) { final IPdfPrimitive? streamDictionary = file.object; if (streamDictionary != null && streamDictionary is PdfDictionary && - streamDictionary - .containsKey(PdfDictionaryProperties.ef)) { + streamDictionary.containsKey(PdfDictionaryProperties.ef)) { PdfDictionary? attachmentStream; - IPdfPrimitive? holder = - streamDictionary[PdfDictionaryProperties.ef]; + IPdfPrimitive? holder = streamDictionary[PdfDictionaryProperties.ef]; if (holder is PdfReferenceHolder) { holder = holder.object; if (holder != null && holder is PdfDictionary) { @@ -828,37 +791,28 @@ class PdfPageHelper { attachmentStream = holder; } if (attachmentStream != null && - attachmentStream - .containsKey(PdfDictionaryProperties.f)) { + attachmentStream.containsKey(PdfDictionaryProperties.f)) { holder = attachmentStream[PdfDictionaryProperties.f]; if (holder != null && holder is PdfReferenceHolder) { final PdfReference? reference = holder.reference; holder = holder.object; if (holder != null && holder is PdfStream) { final PdfStream encryptedObj = holder; - if (PdfDocumentHelper.getHelper(document!) - .isLoadedDocument) { + if (PdfDocumentHelper.getHelper(document!).isLoadedDocument) { if (document!.onPdfPassword != null && - PdfDocumentHelper.getHelper(document!) - .password == - '') { - final PdfPasswordArgs args = - PdfPasswordArgsHelper.load(); - PdfDocumentHelper.getHelper(document!) - .setUserPassword(args); + PdfDocumentHelper.getHelper(document!).password == '') { + final PdfPasswordArgs args = PdfPasswordArgsHelper.load(); + PdfDocumentHelper.getHelper(document!).setUserPassword(args); PdfDocumentHelper.getHelper(document!).password = args.attachmentOpenPassword; } - PdfDocumentHelper.getHelper(document!) - .checkEncryption( - PdfDocumentHelper.getHelper(document!) - .crossTable - .encryptor! - .encryptAttachmentOnly); - encryptedObj.decrypt( + PdfDocumentHelper.getHelper(document!).checkEncryption( PdfDocumentHelper.getHelper(document!) .crossTable - .encryptor!, + .encryptor! + .encryptAttachmentOnly); + encryptedObj.decrypt( + PdfDocumentHelper.getHelper(document!).crossTable.encryptor!, reference!.objNum); } } @@ -871,8 +825,8 @@ class PdfPageHelper { } if (annotDictionary != null && annotDictionary.containsKey(PdfDictionaryProperties.subtype)) { - final PdfName? name = annotDictionary - .items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; + final PdfName? name = + annotDictionary.items![PdfName(PdfDictionaryProperties.subtype)] as PdfName?; if (name != null && name.name.toString() != 'Widget') { if (!terminalAnnotation.contains(annotDictionary)) { terminalAnnotation.add(annotDictionary); @@ -880,16 +834,13 @@ class PdfPageHelper { } else if (name != null && name.name.toString() == 'Widget') { if (annotDictionary.containsKey(PdfDictionaryProperties.parent)) { final PdfDictionary? annotParentDictionary = (annotDictionary - .items![PdfName(PdfDictionaryProperties.parent)]! - as PdfReferenceHolder) + .items![PdfName(PdfDictionaryProperties.parent)]! as PdfReferenceHolder) .object as PdfDictionary?; if (annotParentDictionary != null) { - if (!annotParentDictionary - .containsKey(PdfDictionaryProperties.fields)) { + if (!annotParentDictionary.containsKey(PdfDictionaryProperties.fields)) { if (annotReference != null && annotReference.reference != null && - !widgetReferences - .contains(annotReference.reference!.objNum)) { + !widgetReferences.contains(annotReference.reference!.objNum)) { if (!PdfFormHelper.getHelper(document!.form) .terminalFields .contains(annotParentDictionary)) { @@ -897,13 +848,11 @@ class PdfPageHelper { .terminalFields .add(annotParentDictionary); } - } else if (annotParentDictionary - .containsKey(PdfDictionaryProperties.kids) && + } else if (annotParentDictionary.containsKey(PdfDictionaryProperties.kids) && annotParentDictionary.count == 1) { annotDictionary.remove(PdfDictionaryProperties.parent); } - } else if (!annotParentDictionary - .containsKey(PdfDictionaryProperties.kids)) { + } else if (!annotParentDictionary.containsKey(PdfDictionaryProperties.kids)) { annotDictionary.remove(PdfDictionaryProperties.parent); } } @@ -915,26 +864,20 @@ class PdfPageHelper { if (widgetDictionary == null) { PdfFormHelper.getHelper(document!.form).widgetDictionary = >{}; - widgetDictionary = - PdfFormHelper.getHelper(document!.form).widgetDictionary; + widgetDictionary = PdfFormHelper.getHelper(document!.form).widgetDictionary; } if (annotDictionary.containsKey(PdfDictionaryProperties.t)) { - final String? fieldName = (annotDictionary - .items![PdfName(PdfDictionaryProperties.t)]! - as PdfString) - .value; + final String? fieldName = + (annotDictionary.items![PdfName(PdfDictionaryProperties.t)]! as PdfString) + .value; if (widgetDictionary!.containsKey(fieldName)) { - final List dict = - widgetDictionary[fieldName]!; + final List dict = widgetDictionary[fieldName]!; dict.add(annotDictionary); } else { - if (!PdfFormFieldCollectionHelper.getHelper( - document!.form.fields) + if (!PdfFormFieldCollectionHelper.getHelper(document!.form.fields) .addedFieldNames .contains(fieldName)) { - widgetDictionary[fieldName] = [ - annotDictionary - ]; + widgetDictionary[fieldName] = [annotDictionary]; } } } @@ -946,30 +889,24 @@ class PdfPageHelper { annotsReference.add(annotReference.reference!); } bool skip = false; - if (document != null && - widgetReferences.contains(annotReference.reference!.objNum)) { + if (document != null && widgetReferences.contains(annotReference.reference!.objNum)) { final PdfFormFieldCollection collection = document!.form.fields; for (int i = 0; i < collection.count; i++) { final PdfField field = collection[i]; final PdfFieldHelper helper = PdfFieldHelper.getHelper(field); if (helper.isLoadedField) { - final IPdfPrimitive widget = helper.getWidgetAnnotation( - helper.dictionary!, helper.crossTable); - final PdfReference widgetReference = - crossTable!.getReference(widget); - if (annotReference.reference!.objNum == - widgetReference.objNum && - annotReference.reference!.genNum == - widgetReference.genNum) { + final IPdfPrimitive widget = + helper.getWidgetAnnotation(helper.dictionary!, helper.crossTable); + final PdfReference widgetReference = crossTable!.getReference(widget); + if (annotReference.reference!.objNum == widgetReference.objNum && + annotReference.reference!.genNum == widgetReference.genNum) { skip = true; } } } } if (annotDictionary != null && annotReference.reference != null) { - if (!widgetReferences - .contains(annotReference.reference!.objNum) && - !skip) { + if (!widgetReferences.contains(annotReference.reference!.objNum) && !skip) { if (!terminalAnnotation.contains(annotDictionary)) { terminalAnnotation.add(annotDictionary); } @@ -987,12 +924,11 @@ class PdfPageHelper { PdfTemplate _getContent() { final List combinedData = - PdfPageLayerCollectionHelper.getHelper(base.layers) - .combineContent(false)!; - final PdfDictionary? resources = PdfCrossTable.dereference( - dictionary![PdfDictionaryProperties.resources]) as PdfDictionary?; - final PdfTemplate template = PdfTemplateHelper.internal( - origin, base.size, combinedData, resources!, isLoadedPage, this); + PdfPageLayerCollectionHelper.getHelper(base.layers).combineContent(false)!; + final PdfDictionary? resources = + PdfCrossTable.dereference(dictionary![PdfDictionaryProperties.resources]) as PdfDictionary?; + final PdfTemplate template = + PdfTemplateHelper.internal(origin, base.size, combinedData, resources!, isLoadedPage, this); return template; } @@ -1007,9 +943,7 @@ class PdfPageHelper { final IPdfPrimitive widget = helper.getWidgetAnnotation(helper.dictionary!, helper.crossTable); final Map widgetReference = - PdfDocumentHelper.getHelper(document!) - .objects - .getReference(widget, false); + PdfDocumentHelper.getHelper(document!).objects.getReference(widget, false); widgetReferences.add(((widgetReference['isNew'] as bool) ? crossTable!.getReference(widget).objNum : (widgetReference['reference'] as PdfReference).objNum)! @@ -1022,9 +956,8 @@ class PdfPageHelper { /// internal method PdfArray? obtainAnnotations() { - final IPdfPrimitive? obj = dictionary!.getValue( - PdfDictionaryProperties.annots, PdfDictionaryProperties.parent); - return (obj != null && obj is PdfReferenceHolder ? obj.object : obj) - as PdfArray?; + final IPdfPrimitive? obj = + dictionary!.getValue(PdfDictionaryProperties.annots, PdfDictionaryProperties.parent); + return (obj != null && obj is PdfReferenceHolder ? obj.object : obj) as PdfArray?; } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_collection.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_collection.dart index 27d88e5f0..ee5d83965 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_collection.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_collection.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../forms/pdf_form_field_collection.dart'; @@ -36,8 +36,7 @@ class PdfPageCollection { _helper._pageCache ??= {}; } - PdfPageCollection._fromCrossTable( - PdfDocument document, PdfCrossTable crossTable) { + PdfPageCollection._fromCrossTable(PdfDocument document, PdfCrossTable crossTable) { _helper = PdfPageCollectionHelper(this); _helper.document = document; _helper._crossTable = crossTable; @@ -65,10 +64,9 @@ class PdfPageCollection { int get count { if (PdfDocumentHelper.getHelper(_helper.document!).isLoadedDocument) { int tempCount = 0; - final IPdfPrimitive? obj = PdfDocumentHelper.getHelper(_helper.document!) - .catalog[PdfDictionaryProperties.pages]; - final PdfDictionary? node = - PdfCrossTable.dereference(obj) as PdfDictionary?; + final IPdfPrimitive? obj = + PdfDocumentHelper.getHelper(_helper.document!).catalog[PdfDictionaryProperties.pages]; + final PdfDictionary? node = PdfCrossTable.dereference(obj) as PdfDictionary?; if (node != null) { tempCount = _getNodeCount(node); } @@ -146,9 +144,8 @@ class PdfPageCollection { size = PdfPageSize.a4; } rotation ??= PdfPageRotateAngle.rotateAngle0; - orientation ??= (size.width > size.height) - ? PdfPageOrientation.landscape - : PdfPageOrientation.portrait; + orientation ??= + (size.width > size.height) ? PdfPageOrientation.landscape : PdfPageOrientation.portrait; final PdfPage page = PdfPage(); final PdfPageSettings settings = PdfPageSettings(size, orientation); if (margins == null) { @@ -162,18 +159,15 @@ class PdfPageCollection { PdfSectionHelper.getHelper(sec).add(page); PdfDictionary dic = IPdfWrapper.getElement(sec)! as PdfDictionary; int? localIndex = 0; - final Map result = - _getValidParent(index, localIndex, false); + final Map result = _getValidParent(index, localIndex, false); final PdfDictionary parent = result['node'] as PdfDictionary; localIndex = result['index'] as int?; if (parent.containsKey(PdfDictionaryProperties.rotate)) { final int rotationValue = page.rotation.index * 90; - final PdfNumber parentRotation = - parent[PdfDictionaryProperties.rotate]! as PdfNumber; + final PdfNumber parentRotation = parent[PdfDictionaryProperties.rotate]! as PdfNumber; if (parentRotation.value!.toInt() != rotationValue && (!dic.containsKey(PdfDictionaryProperties.rotate))) { - PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.rotate] = + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.rotate] = PdfNumber(rotationValue); } } @@ -184,9 +178,8 @@ class PdfPageCollection { dic = IPdfWrapper.getElement(page)! as PdfDictionary; _helper._pageCache![dic] = page; page.graphics.colorSpace = _helper.document!.colorSpace; - PdfPageLayerHelper.getHelper( - PdfGraphicsHelper.getHelper(page.graphics).layer!) - .colorSpace = _helper.document!.colorSpace; + PdfPageLayerHelper.getHelper(PdfGraphicsHelper.getHelper(page.graphics).layer!).colorSpace = + _helper.document!.colorSpace; return page; } @@ -227,8 +220,8 @@ class PdfPageCollection { //Implementation int _getNodeCount(PdfDictionary node) { - final PdfNumber? number = _helper._crossTable! - .getObject(node[PdfDictionaryProperties.count]) as PdfNumber?; + final PdfNumber? number = + _helper._crossTable!.getObject(node[PdfDictionaryProperties.count]) as PdfNumber?; return (number == null) ? 0 : number.value!.toInt(); } @@ -242,8 +235,7 @@ class PdfPageCollection { int i = localIndex; int j = 0; while (true) { - node = - _helper._crossTable!.getObject(kids![localIndex])! as PdfDictionary; + node = _helper._crossTable!.getObject(kids![localIndex])! as PdfDictionary; if ((node[PdfDictionaryProperties.type]! as PdfName).name == 'Pages') { i++; node = _helper._crossTable!.getObject(kids[i])! as PdfDictionary; @@ -252,8 +244,7 @@ class PdfPageCollection { break; } if (innerKids.count > 0) { - node = - _helper._crossTable!.getObject(innerKids[j])! as PdfDictionary; + node = _helper._crossTable!.getObject(innerKids[j])! as PdfDictionary; j++; break; } @@ -264,8 +255,7 @@ class PdfPageCollection { return _helper.getPage(node); } else { if (_helper._section != null) { - return PdfSectionHelper.getHelper(_helper._section!) - .getPageByIndex(index); + return PdfSectionHelper.getHelper(_helper._section!).getPageByIndex(index); } else { if (index < 0 || index >= count) { throw ArgumentError.value('index', 'out of range'); @@ -279,8 +269,7 @@ class PdfPageCollection { sectionCount = PdfSectionHelper.getHelper(section).count; pageIndex = index - sectionStartIndex; if (index >= sectionStartIndex && pageIndex < sectionCount) { - page = - PdfSectionHelper.getHelper(section).getPageByIndex(pageIndex); + page = PdfSectionHelper.getHelper(section).getPageByIndex(pageIndex); break; } sectionStartIndex += sectionCount; @@ -294,18 +283,16 @@ class PdfPageCollection { while (parent != null) { final int count = _getNodeCount(parent) + 1; parent[PdfDictionaryProperties.count] = PdfNumber(count); - parent = PdfCrossTable.dereference(parent[PdfDictionaryProperties.parent]) - as PdfDictionary?; + parent = PdfCrossTable.dereference(parent[PdfDictionaryProperties.parent]) as PdfDictionary?; } } - Map _getValidParent( - int index, int? localIndex, bool zeroValid) { + Map _getValidParent(int index, int? localIndex, bool zeroValid) { if (index < 0 && index > count) { throw ArgumentError.value(index, 'page index is not within range'); } - final IPdfPrimitive? obj = PdfDocumentHelper.getHelper(_helper.document!) - .catalog[PdfDictionaryProperties.pages]; + final IPdfPrimitive? obj = + PdfDocumentHelper.getHelper(_helper.document!).catalog[PdfDictionaryProperties.pages]; PdfDictionary node = _helper._crossTable!.getObject(obj)! as PdfDictionary; int lowIndex = 0; localIndex = _getNodeCount(node); @@ -317,8 +304,7 @@ class PdfPageCollection { final IPdfPrimitive? primitive = kids.elements[i]; if (primitive != null && primitive is PdfReferenceHolder) { final PdfReferenceHolder pageReferenceHolder = primitive; - final PdfDictionary kidsCollection = - pageReferenceHolder.object! as PdfDictionary; + final PdfDictionary kidsCollection = pageReferenceHolder.object! as PdfDictionary; final List keys = kidsCollection.items!.keys.toList(); for (int keyIndex = 0; keyIndex < keys.length; keyIndex++) { final PdfName key = keys[keyIndex]!; @@ -338,12 +324,9 @@ class PdfPageCollection { } } for (int i = 0, count = kids.count; i < count; ++i) { - final PdfDictionary subNode = - _helper._crossTable!.getObject(kids[i])! as PdfDictionary; - String? pageValue = - (subNode[PdfDictionaryProperties.type]! as PdfName).name; - if (_isNodeLeaf(subNode) && - !(pageValue == PdfDictionaryProperties.pages)) { + final PdfDictionary subNode = _helper._crossTable!.getObject(kids[i])! as PdfDictionary; + String? pageValue = (subNode[PdfDictionaryProperties.type]! as PdfName).name; + if (_isNodeLeaf(subNode) && !(pageValue == PdfDictionaryProperties.pages)) { if ((lowIndex + i) == index) { localIndex = i; break; @@ -359,8 +342,7 @@ class PdfPageCollection { if (nodeCount == count) { final PdfDictionary kidsSubNode = _helper._crossTable!.getObject(kids[0])! as PdfDictionary; - pageValue = - (kidsSubNode[PdfDictionaryProperties.type]! as PdfName).name; + pageValue = (kidsSubNode[PdfDictionaryProperties.type]! as PdfName).name; if (pageValue == PdfDictionaryProperties.pages) { continue; } else { @@ -384,13 +366,12 @@ class PdfPageCollection { if (index < 0 && index > count) { throw ArgumentError.value(index, 'page index is not within range'); } - _pageCatalog ??= PdfDocumentHelper.getHelper(_helper.document!) - .catalog[PdfDictionaryProperties.pages]; + _pageCatalog ??= + PdfDocumentHelper.getHelper(_helper.document!).catalog[PdfDictionaryProperties.pages]; bool isNodeChanged = false; PdfDictionary? node; if (_nodeDictionary == null) { - _nodeDictionary = - _helper._crossTable!.getObject(_pageCatalog) as PdfDictionary?; + _nodeDictionary = _helper._crossTable!.getObject(_pageCatalog) as PdfDictionary?; node = _nodeDictionary; _nodeCount = _getNodeCount(node!); _lastCrossTable = _helper._crossTable; @@ -398,8 +379,7 @@ class PdfPageCollection { } else if (_helper._crossTable == _lastCrossTable) { node = _nodeDictionary; } else { - _nodeDictionary = - _helper._crossTable!.getObject(_pageCatalog) as PdfDictionary?; + _nodeDictionary = _helper._crossTable!.getObject(_pageCatalog) as PdfDictionary?; node = _nodeDictionary; _nodeCount = _getNodeCount(node!); _lastCrossTable = _helper._crossTable; @@ -415,8 +395,7 @@ class PdfPageCollection { final IPdfPrimitive? primitive = kids.elements[i]; if (primitive != null && primitive is PdfReferenceHolder) { final PdfReferenceHolder pageReferenceHolder = primitive; - final PdfDictionary kidsCollection = - pageReferenceHolder.object! as PdfDictionary; + final PdfDictionary kidsCollection = pageReferenceHolder.object! as PdfDictionary; final List keys = kidsCollection.items!.keys.toList(); for (int keyIndex = 0; keyIndex < keys.length; keyIndex++) { final PdfName key = keys[keyIndex]!; @@ -439,8 +418,7 @@ class PdfPageCollection { kids = _nodeKids; } int kidStartIndex = 0; - if ((_lastPageIndex == index - 1 || _lastPageIndex < index) && - _lastKidIndex < kids!.count) { + if ((_lastPageIndex == index - 1 || _lastPageIndex < index) && _lastKidIndex < kids!.count) { kidStartIndex = _lastKidIndex; } bool? isParentNodeFetched = false; @@ -448,21 +426,21 @@ class PdfPageCollection { int? tempLocalIndex = 0; if (kids!.count == count) { - Map returnValue = _getParentNode(kidStartIndex, kids, - 0, index, tempNode, tempLocalIndex, isParentNodeFetched); + Map returnValue = _getParentNode( + kidStartIndex, kids, 0, index, tempNode, tempLocalIndex, isParentNodeFetched); tempNode = returnValue['tempNode'] as PdfDictionary?; tempLocalIndex = returnValue['tempLocalIndex'] as int?; isParentNodeFetched = returnValue['isParentNodeFetched'] as bool?; if (!isParentNodeFetched!) { - returnValue = _getParentNode( - 0, kids, 0, index, tempNode, tempLocalIndex, isParentNodeFetched); + returnValue = + _getParentNode(0, kids, 0, index, tempNode, tempLocalIndex, isParentNodeFetched); tempNode = returnValue['tempNode'] as PdfDictionary?; tempLocalIndex = returnValue['tempLocalIndex'] as int?; isParentNodeFetched = returnValue['isParentNodeFetched'] as bool?; } } else { - final Map returnValue = _getParentNode( - 0, kids, 0, index, tempNode, tempLocalIndex, isParentNodeFetched); + final Map returnValue = + _getParentNode(0, kids, 0, index, tempNode, tempLocalIndex, isParentNodeFetched); tempNode = returnValue['tempNode'] as PdfDictionary?; tempLocalIndex = returnValue['tempLocalIndex'] as int?; isParentNodeFetched = returnValue['isParentNodeFetched'] as bool?; @@ -487,14 +465,8 @@ class PdfPageCollection { return kids; } - Map _getParentNode( - int kidStartIndex, - PdfArray kids, - int lowIndex, - int pageIndex, - PdfDictionary? node, - int? localIndex, - bool? isParentFetched) { + Map _getParentNode(int kidStartIndex, PdfArray kids, int lowIndex, int pageIndex, + PdfDictionary? node, int? localIndex, bool? isParentFetched) { isParentFetched = false; node = null; localIndex = -1; @@ -504,10 +476,8 @@ class PdfPageCollection { final IPdfPrimitive? primitive = _helper._crossTable!.getObject(kids[i]); if (primitive != null && primitive is PdfDictionary) { final PdfDictionary subNode = primitive; - final String? pageValue = - (subNode[PdfDictionaryProperties.type]! as PdfName).name; - if (_isNodeLeaf(subNode) && - !(pageValue == PdfDictionaryProperties.pages)) { + final String? pageValue = (subNode[PdfDictionaryProperties.type]! as PdfName).name; + if (_isNodeLeaf(subNode) && !(pageValue == PdfDictionaryProperties.pages)) { if ((lowIndex + i) == pageIndex) { localIndex = i; isParentFetched = true; @@ -548,10 +518,7 @@ class PdfPageCollection { final PdfSectionCollection sectionCollection = _helper.document!.sections!; int count = 0; for (int i = 0; - i < - PdfSectionCollectionHelper.getHelper(sectionCollection) - .sections - .length; + i < PdfSectionCollectionHelper.getHelper(sectionCollection).sections.length; i++) { final PdfSection section = sectionCollection[i]; count += PdfSectionHelper.getHelper(section).count; @@ -560,11 +527,9 @@ class PdfPageCollection { } void _removePage(PdfPage? page, int index) { - if (PdfDocumentHelper.getHelper(_helper.document!).isLoadedDocument && - index > -1) { + if (PdfDocumentHelper.getHelper(_helper.document!).isLoadedDocument && index > -1) { final Map? pageToBookmarkDic = - PdfDocumentHelper.getHelper(_helper.document!) - .createBookmarkDestinationDictionary(); + PdfDocumentHelper.getHelper(_helper.document!).createBookmarkDestinationDictionary(); if (pageToBookmarkDic != null) { List? bookmarks; if (pageToBookmarkDic.containsKey(page)) { @@ -600,8 +565,7 @@ class PdfPageCollection { dic[PdfDictionaryProperties.parent] = PdfReferenceHolder(parent); PdfArray? kids = _getNodeKids(parent); if (index == 0) { - final PdfCrossTable table = - PdfDocumentHelper.getHelper(_helper.document!).crossTable; + final PdfCrossTable table = PdfDocumentHelper.getHelper(_helper.document!).crossTable; if (table.documentCatalog != null) { final IPdfPrimitive? primitive = table.documentCatalog!['OpenAction']; PdfArray? documentCatalog; @@ -622,8 +586,7 @@ class PdfPageCollection { final IPdfPrimitive? entry = documentObject[i]; if (entry != null && entry is PdfReferenceHolder) { final IPdfPrimitive? referenceDictionary = entry.object; - if (referenceDictionary != null && - referenceDictionary == dic) { + if (referenceDictionary != null && referenceDictionary == dic) { documentObject.remove(entry); } } @@ -637,9 +600,7 @@ class PdfPageCollection { PdfReferenceHolder? remove; for (int i = 0; i < kids!.count; i++) { final IPdfPrimitive? holder = kids[i]; - if (holder != null && - holder is PdfReferenceHolder && - holder.object == dic) { + if (holder != null && holder is PdfReferenceHolder && holder.object == dic) { remove = holder; break; } @@ -647,8 +608,7 @@ class PdfPageCollection { if (remove != null) { _removeFormFields(remove); kids.remove(remove); - if (kids.count == 0 && - parent.containsKey(PdfDictionaryProperties.parent)) { + if (kids.count == 0 && parent.containsKey(PdfDictionaryProperties.parent)) { PdfDictionary? parentDic; IPdfPrimitive? holder = parent[PdfDictionaryProperties.parent]; if (holder is PdfReferenceHolder) { @@ -660,8 +620,7 @@ class PdfPageCollection { parentDic = holder; } if (parentDic != null) { - IPdfPrimitive? kidsPrimitive = - parentDic[PdfDictionaryProperties.kids]; + IPdfPrimitive? kidsPrimitive = parentDic[PdfDictionaryProperties.kids]; if (kidsPrimitive is PdfReferenceHolder) { kidsPrimitive = kidsPrimitive.object; if (kidsPrimitive != null && kidsPrimitive is PdfArray) { @@ -673,9 +632,7 @@ class PdfPageCollection { PdfReferenceHolder? remove; for (int i = 0; i < kids.count; i++) { final IPdfPrimitive? holder = kids[i]; - if (holder != null && - holder is PdfReferenceHolder && - holder.object == parent) { + if (holder != null && holder is PdfReferenceHolder && holder.object == parent) { remove = holder; break; } @@ -717,8 +674,7 @@ class PdfPageCollection { parent[PdfDictionaryProperties.count] = PdfNumber(count); final IPdfPrimitive? primitive = PdfCrossTable.dereference(parent[PdfDictionaryProperties.parent]); - parent = - (primitive != null && primitive is PdfDictionary) ? primitive : null; + parent = (primitive != null && primitive is PdfDictionary) ? primitive : null; } } } @@ -742,8 +698,7 @@ class PdfPageCollectionHelper { } /// internal method - static PdfPageCollection fromCrossTable( - PdfDocument document, PdfCrossTable crossTable) { + static PdfPageCollection fromCrossTable(PdfDocument document, PdfCrossTable crossTable) { return PdfPageCollection._fromCrossTable(document, crossTable); } @@ -763,8 +718,7 @@ class PdfPageCollectionHelper { if (_section == null) { if (!_checkPageSettings(PdfSectionHelper.getHelper(section).settings)) { section = document!.sections!.add(); - section.pageSettings = - PdfPageSettingsHelper.getHelper(document!.pageSettings).clone(); + section.pageSettings = PdfPageSettingsHelper.getHelper(document!.pageSettings).clone(); } if (!pageCollectionIndex.containsKey(page)) { pageCollectionIndex[page] = _count++; @@ -775,16 +729,11 @@ class PdfPageCollectionHelper { PdfSection _getLastSection() { final PdfSectionCollection sectionCollection = document!.sections!; - if (PdfSectionCollectionHelper.getHelper(sectionCollection) - .sections - .isEmpty) { + if (PdfSectionCollectionHelper.getHelper(sectionCollection).sections.isEmpty) { sectionCollection.add(); } return sectionCollection[ - PdfSectionCollectionHelper.getHelper(sectionCollection) - .sections - .length - - 1]; + PdfSectionCollectionHelper.getHelper(sectionCollection).sections.length - 1]; } bool _checkPageSettings(PdfPageSettings sectionSettings) { @@ -804,8 +753,7 @@ class PdfPageCollectionHelper { } else { bool value = false; for (int i = 0; i < document!.sections!.count; i++) { - value |= PdfPageCollectionHelper.getHelper(document!.sections![i].pages) - .contains(page); + value |= PdfPageCollectionHelper.getHelper(document!.sections![i].pages).contains(page); } return value; } @@ -824,10 +772,8 @@ class PdfPageCollectionHelper { PdfSectionHelper.getHelper(_section!).remove(page); } else { for (int i = 0; i < document!.sections!.count; i++) { - if (PdfPageCollectionHelper.getHelper(document!.sections![i].pages) - .contains(page)) { - PdfPageCollectionHelper.getHelper(document!.sections![i].pages) - .remove(page); + if (PdfPageCollectionHelper.getHelper(document!.sections![i].pages).contains(page)) { + PdfPageCollectionHelper.getHelper(document!.sections![i].pages).remove(page); break; } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_layer.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_layer.dart index f768a3f0d..ed45afc1c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_layer.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_layer.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -34,8 +34,7 @@ class PdfPageLayer implements IPdfWrapper { _initialize(pdfPage, true); } - PdfPageLayer._fromClipPageTemplate(PdfPage pdfPage, - [bool? clipPageTemplates]) { + PdfPageLayer._fromClipPageTemplate(PdfPage pdfPage, [bool? clipPageTemplates]) { _helper = PdfPageLayerHelper(this); _initialize(pdfPage, clipPageTemplates); } @@ -80,9 +79,7 @@ class PdfPageLayer implements IPdfWrapper { bool get visible { if (_helper.dictionary != null && _helper.dictionary!.containsKey(PdfDictionaryProperties.visible)) { - _visible = - (_helper.dictionary![PdfDictionaryProperties.visible]! as PdfBoolean) - .value!; + _visible = (_helper.dictionary![PdfDictionaryProperties.visible]! as PdfBoolean).value!; } return _visible; } @@ -124,8 +121,7 @@ class PdfPageLayer implements IPdfWrapper { double ury = 0; final PdfArray? mediaBox = PdfPageHelper.getHelper(page) .dictionary! - .getValue(PdfDictionaryProperties.mediaBox, - PdfDictionaryProperties.parent) as PdfArray?; + .getValue(PdfDictionaryProperties.mediaBox, PdfDictionaryProperties.parent) as PdfArray?; final PdfReferenceHolder referenceHolder = PdfReferenceHolder(this); if (mediaBox != null) { // Lower Left X co-ordinate Value. @@ -138,12 +134,10 @@ class PdfPageLayer implements IPdfWrapper { ury = (mediaBox[3]! as PdfNumber).value!.toDouble(); } PdfArray? cropBox; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.cropBox)) { - cropBox = PdfPageHelper.getHelper(page).dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) - as PdfArray?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.cropBox)) { + cropBox = PdfPageHelper.getHelper(page) + .dictionary! + .getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) as PdfArray?; final double cropX = (cropBox![0]! as PdfNumber).value!.toDouble(); final double cropY = (cropBox[1]! as PdfNumber).value!.toDouble(); final double cropRX = (cropBox[2]! as PdfNumber).value!.toDouble(); @@ -151,36 +145,27 @@ class PdfPageLayer implements IPdfWrapper { if ((cropX < 0 || cropY < 0 || cropRX < 0 || cropRY < 0) && (cropY.abs().floor() == page.size.height.abs().floor()) && (cropX.abs().floor()) == page.size.width.abs().floor()) { - final Size pageSize = Size([cropX, cropRX].reduce(max), - [cropY, cropRY].reduce(max)); - _helper.graphics = - PdfGraphicsHelper.load(pageSize, resources, _helper._content!); - if (!PdfPageHelper.getHelper(page) - .contents - .contains(referenceHolder) && + final Size pageSize = + Size([cropX, cropRX].reduce(max), [cropY, cropRY].reduce(max)); + _helper.graphics = PdfGraphicsHelper.load(pageSize, resources, _helper._content!); + if (!PdfPageHelper.getHelper(page).contents.contains(referenceHolder) && !PdfPageHelper.getHelper(page).isDefaultGraphics && - !_isContainsPageContent( - PdfPageHelper.getHelper(page).contents, referenceHolder)) { + !_isContainsPageContent(PdfPageHelper.getHelper(page).contents, referenceHolder)) { PdfPageHelper.getHelper(page).contents.add(referenceHolder); } } else { - _helper.graphics = - PdfGraphicsHelper.load(page.size, resources, _helper._content!); + _helper.graphics = PdfGraphicsHelper.load(page.size, resources, _helper._content!); PdfGraphicsHelper.getHelper(_helper.graphics!).cropBox = cropBox; - if (!PdfPageHelper.getHelper(page) - .contents - .contains(referenceHolder) && + if (!PdfPageHelper.getHelper(page).contents.contains(referenceHolder) && !PdfPageHelper.getHelper(page).isDefaultGraphics && - !_isContainsPageContent( - PdfPageHelper.getHelper(page).contents, referenceHolder)) { + !_isContainsPageContent(PdfPageHelper.getHelper(page).contents, referenceHolder)) { PdfPageHelper.getHelper(page).contents.add(referenceHolder); } } } else if ((llx < 0 || lly < 0 || urx < 0 || ury < 0) && (lly.abs().floor() == page.size.height.abs().floor()) && (urx.abs().floor() == page.size.width.abs().floor())) { - Size pageSize = Size( - [llx, urx].reduce(max), [lly, ury].reduce(max)); + Size pageSize = Size([llx, urx].reduce(max), [lly, ury].reduce(max)); if (pageSize.width <= 0 || pageSize.height <= 0) { isInvalidSize = true; if (llx < 0) { @@ -193,26 +178,19 @@ class PdfPageLayer implements IPdfWrapper { } else if (ury < 0) { ury = -ury; } - pageSize = Size( - [llx, urx].reduce(max), [lly, ury].reduce(max)); - _helper.graphics = - PdfGraphicsHelper.load(pageSize, resources, _helper._content!); - if (!PdfPageHelper.getHelper(page) - .contents - .contains(referenceHolder) && + pageSize = Size([llx, urx].reduce(max), [lly, ury].reduce(max)); + _helper.graphics = PdfGraphicsHelper.load(pageSize, resources, _helper._content!); + if (!PdfPageHelper.getHelper(page).contents.contains(referenceHolder) && !PdfPageHelper.getHelper(page).isDefaultGraphics && - !_isContainsPageContent( - PdfPageHelper.getHelper(page).contents, referenceHolder)) { + !_isContainsPageContent(PdfPageHelper.getHelper(page).contents, referenceHolder)) { PdfPageHelper.getHelper(page).contents.add(referenceHolder); } } } else { - _helper.graphics = - PdfGraphicsHelper.load(page.size, resources, _helper._content!); + _helper.graphics = PdfGraphicsHelper.load(page.size, resources, _helper._content!); if (!PdfPageHelper.getHelper(page).contents.contains(referenceHolder) && !PdfPageHelper.getHelper(page).isDefaultGraphics && - !_isContainsPageContent( - PdfPageHelper.getHelper(page).contents, referenceHolder)) { + !_isContainsPageContent(PdfPageHelper.getHelper(page).contents, referenceHolder)) { PdfPageHelper.getHelper(page).contents.add(referenceHolder); } } @@ -223,17 +201,12 @@ class PdfPageLayer implements IPdfWrapper { } if (!PdfPageHelper.getHelper(page).isLoadedPage) { final PdfSectionCollection? sectionCollection = - PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page).section!) - .parent; + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page).section!).parent; if (sectionCollection != null) { _helper.graphics!.colorSpace = - PdfSectionCollectionHelper.getHelper(sectionCollection) - .document! - .colorSpace; + PdfSectionCollectionHelper.getHelper(sectionCollection).document!.colorSpace; _helper.colorSpace = - PdfSectionCollectionHelper.getHelper(sectionCollection) - .document! - .colorSpace; + PdfSectionCollectionHelper.getHelper(sectionCollection).document!.colorSpace; } } _helper._content!.beginSave = _beginSaveContent; @@ -247,8 +220,7 @@ class PdfPageLayer implements IPdfWrapper { } PdfGraphicsHelper.getHelper(_helper.graphics!).initializeCoordinates(); if (PdfGraphicsHelper.getHelper(_helper.graphics!).hasTransparencyBrush) { - PdfGraphicsHelper.getHelper(_helper.graphics!) - .setTransparencyGroup(page!); + PdfGraphicsHelper.getHelper(_helper.graphics!).setTransparencyGroup(page!); } if (page != null && (!PdfPageHelper.getHelper(page).isLoadedPage) && @@ -257,12 +229,10 @@ class PdfPageLayer implements IPdfWrapper { .dictionary! .containsKey(PdfDictionaryProperties.rotate))) { PdfArray? cropBox; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.cropBox)) { - cropBox = PdfPageHelper.getHelper(page).dictionary!.getValue( - PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) - as PdfArray?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.cropBox)) { + cropBox = PdfPageHelper.getHelper(page) + .dictionary! + .getValue(PdfDictionaryProperties.cropBox, PdfDictionaryProperties.parent) as PdfArray?; } _updatePageRotation(page, _helper.graphics, cropBox); } @@ -273,36 +243,25 @@ class PdfPageLayer implements IPdfWrapper { if (_clipPageTemplates!) { if (PdfPageHelper.getHelper(page).origin.dx >= 0 && PdfPageHelper.getHelper(page).origin.dy >= 0) { - PdfGraphicsHelper.getHelper(_helper.graphics!) - .clipTranslateMarginsWithBounds(clipRect); + PdfGraphicsHelper.getHelper(_helper.graphics!).clipTranslateMarginsWithBounds(clipRect); } } else { - final PdfMargins margins = - PdfPageHelper.getHelper(page).section!.pageSettings.margins; + final PdfMargins margins = PdfPageHelper.getHelper(page).section!.pageSettings.margins; PdfGraphicsHelper.getHelper(_helper.graphics!).clipTranslateMargins( - clipRect.x, - clipRect.y, - margins.left, - margins.top, - margins.right, - margins.bottom); + clipRect.x, clipRect.y, margins.left, margins.top, margins.right, margins.bottom); } } PdfGraphicsHelper.getHelper(_helper.graphics!).setLayer(this); _isSaved = false; } - void _updatePageRotation( - PdfPage page, PdfGraphics? graphics, PdfArray? cropBox) { + void _updatePageRotation(PdfPage page, PdfGraphics? graphics, PdfArray? cropBox) { PdfNumber? rotation; - if (PdfPageHelper.getHelper(page) - .dictionary! - .containsKey(PdfDictionaryProperties.rotate)) { - rotation = PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.rotate] as PdfNumber?; + if (PdfPageHelper.getHelper(page).dictionary!.containsKey(PdfDictionaryProperties.rotate)) { + rotation = + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.rotate] as PdfNumber?; rotation ??= rotation = PdfCrossTable.dereference( - PdfPageHelper.getHelper(page) - .dictionary![PdfDictionaryProperties.rotate]) as PdfNumber?; + PdfPageHelper.getHelper(page).dictionary![PdfDictionaryProperties.rotate]) as PdfNumber?; } else if (page.rotation != PdfPageRotateAngle.rotateAngle0) { if (page.rotation == PdfPageRotateAngle.rotateAngle90) { rotation = PdfNumber(90); @@ -317,22 +276,16 @@ class PdfPageLayer implements IPdfWrapper { graphics.rotateTransform(-90); if (cropBox != null) { final double height = (cropBox[3]! as PdfNumber).value!.toDouble(); - final Size cropBoxSize = Size( - (cropBox[2]! as PdfNumber).value!.toDouble(), - height != 0 - ? height - : (cropBox[1]! as PdfNumber).value!.toDouble()); - final Offset cropBoxOffset = Offset( - (cropBox[0]! as PdfNumber).value!.toDouble(), + final Size cropBoxSize = Size((cropBox[2]! as PdfNumber).value!.toDouble(), + height != 0 ? height : (cropBox[1]! as PdfNumber).value!.toDouble()); + final Offset cropBoxOffset = Offset((cropBox[0]! as PdfNumber).value!.toDouble(), (cropBox[1]! as PdfNumber).value!.toDouble()); if (page.size.height < cropBoxSize.height) { - PdfGraphicsHelper.getHelper(graphics).clipBounds.size = PdfSize( - page.size.height - cropBoxOffset.dy, - cropBoxSize.width - cropBoxOffset.dx); + PdfGraphicsHelper.getHelper(graphics).clipBounds.size = + PdfSize(page.size.height - cropBoxOffset.dy, cropBoxSize.width - cropBoxOffset.dx); } else { - PdfGraphicsHelper.getHelper(graphics).clipBounds.size = PdfSize( - cropBoxSize.height - cropBoxOffset.dy, - cropBoxSize.width - cropBoxOffset.dx); + PdfGraphicsHelper.getHelper(graphics).clipBounds.size = + PdfSize(cropBoxSize.height - cropBoxOffset.dy, cropBoxSize.width - cropBoxOffset.dx); } } else { PdfGraphicsHelper.getHelper(graphics).clipBounds.size = @@ -352,9 +305,7 @@ class PdfPageLayer implements IPdfWrapper { void _beginSaveContent(Object sender, SavePdfPrimitiveArgs? args) { if (_graphicsState != null) { if (_isEndState) { - PdfGraphicsHelper.getHelper(_helper.graphics!) - .streamWriter! - .write('EMC\n'); + PdfGraphicsHelper.getHelper(_helper.graphics!).streamWriter!.write('EMC\n'); _isEndState = false; } graphics.restore(_graphicsState); @@ -376,10 +327,8 @@ class PdfPageLayer implements IPdfWrapper { final PdfDictionary? defaultView = oCProperties[PdfDictionaryProperties.defaultView] as PdfDictionary?; if (defaultView != null) { - PdfArray? ocgON = - defaultView[PdfDictionaryProperties.ocgOn] as PdfArray?; - PdfArray? ocgOFF = - defaultView[PdfDictionaryProperties.ocgOff] as PdfArray?; + PdfArray? ocgON = defaultView[PdfDictionaryProperties.ocgOn] as PdfArray?; + PdfArray? ocgOFF = defaultView[PdfDictionaryProperties.ocgOff] as PdfArray?; if (_helper.referenceHolder != null) { if (value == false) { if (ocgON != null) { @@ -387,8 +336,7 @@ class PdfPageLayer implements IPdfWrapper { } if (ocgOFF == null) { ocgOFF = PdfArray(); - defaultView.items![PdfName(PdfDictionaryProperties.ocgOff)] = - ocgOFF; + defaultView.items![PdfName(PdfDictionaryProperties.ocgOff)] = ocgOFF; } ocgOFF.insert(ocgOFF.count, _helper.referenceHolder!); } else if (value ?? true) { @@ -397,8 +345,7 @@ class PdfPageLayer implements IPdfWrapper { } if (ocgON == null) { ocgON = PdfArray(); - defaultView.items![PdfName(PdfDictionaryProperties.ocgOn)] = - ocgON; + defaultView.items![PdfName(PdfDictionaryProperties.ocgOn)] = ocgON; } ocgON.insert(ocgON.count, _helper.referenceHolder!); } @@ -407,8 +354,7 @@ class PdfPageLayer implements IPdfWrapper { } } - bool _isContainsPageContent( - PdfArray content, PdfReferenceHolder referenceHolder) { + bool _isContainsPageContent(PdfArray content, PdfReferenceHolder referenceHolder) { for (int i = 0; i < content.count; i++) { final IPdfPrimitive? primitive = content.elements[i]; if (primitive != null && primitive is PdfReferenceHolder) { @@ -465,8 +411,7 @@ class PdfPageLayerHelper { } /// internal method - static PdfPageLayer fromClipPageTemplate(PdfPage pdfPage, - [bool? clipPageTemplates]) { + static PdfPageLayer fromClipPageTemplate(PdfPage pdfPage, [bool? clipPageTemplates]) { return PdfPageLayer._fromClipPageTemplate(pdfPage, clipPageTemplates); } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_settings.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_settings.dart index c1ae3fd8e..01aae1eb8 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_settings.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_settings.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../drawing/drawing.dart'; import '../graphics/pdf_margins.dart'; @@ -63,8 +63,7 @@ class PdfPageSettings { /// ``` PdfMargins get margins => _margins; set margins(PdfMargins value) { - if (!PdfMarginsHelper.getHelper(_margins).equals(value) && - !_helper.isPageAdded) { + if (!PdfMarginsHelper.getHelper(_margins).equals(value) && !_helper.isPageAdded) { _margins = value; } } @@ -248,8 +247,7 @@ class PdfPageSettings { void setMargins(double all, [double? top, double? right, double? bottom]) { if (!_helper.isPageAdded) { if (top != null && right != null && bottom != null) { - PdfMarginsHelper.getHelper(margins) - .setMarginsAll(all, top, right, bottom); + PdfMarginsHelper.getHelper(margins).setMarginsAll(all, top, right, bottom); } else if (top != null && right == null) { PdfMarginsHelper.getHelper(margins).setMarginsLT(all, top); } else if (top == null && bottom != null) { diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_template_element.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_template_element.dart index 26042a5bf..dfed5d756 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_template_element.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_page_template_element.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../drawing/drawing.dart'; import '../graphics/figures/pdf_template.dart'; @@ -319,8 +319,7 @@ class PdfPageTemplateElement { /// ``` double get width => _helper._template!.size.width; set width(double value) { - if (_helper._template!.size.width != value && - _helper.type == TemplateType.none) { + if (_helper._template!.size.width != value && _helper.type == TemplateType.none) { _helper._template!.reset(value, _helper._template!.size.height); } } @@ -349,8 +348,7 @@ class PdfPageTemplateElement { /// ``` double get height => _helper._template!.size.height; set height(double value) { - if (_helper._template!.size.height != value && - _helper.type == TemplateType.none) { + if (_helper._template!.size.height != value && _helper.type == TemplateType.none) { _helper._template!.reset(_helper._template!.size.width, value); } } @@ -439,8 +437,8 @@ class PdfPageTemplateElement { alignment == PdfAlignmentStyle.none; break; case PdfDockStyle.fill: - canBeSet = alignment == PdfAlignmentStyle.middleCenter || - alignment == PdfAlignmentStyle.none; + canBeSet = + alignment == PdfAlignmentStyle.middleCenter || alignment == PdfAlignmentStyle.none; break; case PdfDockStyle.none: break; @@ -537,8 +535,8 @@ class PdfPageTemplateElementHelper { Rect _getSimpleAlignmentBounds(PdfPage page, PdfDocument document) { final Rect result = base.bounds; final PdfSection section = PdfPageHelper.getHelper(page).section!; - final PdfRectangle actualBounds = PdfSectionHelper.getHelper(section) - .getActualBounds(page, false, document); + final PdfRectangle actualBounds = + PdfSectionHelper.getHelper(section).getActualBounds(page, false, document); double x = base.location.dx; double y = base.location.dy; @@ -626,8 +624,8 @@ class PdfPageTemplateElementHelper { Rect _getSimpleDockBounds(PdfPage page, PdfDocument document) { Rect result = base.bounds; final PdfSection section = PdfPageHelper.getHelper(page).section!; - final PdfRectangle actualBounds = PdfSectionHelper.getHelper(section) - .getActualBounds(page, false, document); + final PdfRectangle actualBounds = + PdfSectionHelper.getHelper(section).getActualBounds(page, false, document); double x = base.location.dx; double y = base.location.dy; double? width = base.width; @@ -682,10 +680,10 @@ class PdfPageTemplateElementHelper { Rect _getTemplateDockBounds(PdfPage page, PdfDocument document) { final PdfSection section = PdfPageHelper.getHelper(page).section!; - final PdfRectangle actualBounds = PdfSectionHelper.getHelper(section) - .getActualBounds(page, false, document); - final PdfSize actualSize = PdfSize.fromSize( - PdfPageSettingsHelper.getHelper(section.pageSettings).getActualSize()); + final PdfRectangle actualBounds = + PdfSectionHelper.getHelper(section).getActualBounds(page, false, document); + final PdfSize actualSize = + PdfSize.fromSize(PdfPageSettingsHelper.getHelper(section.pageSettings).getActualSize()); double x = base.location.dx; double y = base.location.dy; double? width = base.width; @@ -712,8 +710,7 @@ class PdfPageTemplateElementHelper { case PdfDockStyle.right: x = actualBounds.width + - PdfSectionHelper.getHelper(section) - .getRightIndentWidth(document, page, false) - + PdfSectionHelper.getHelper(section).getRightIndentWidth(document, page, false) - base.width; y = 0.0; width = base.width; @@ -723,8 +720,7 @@ class PdfPageTemplateElementHelper { case PdfDockStyle.bottom: x = -actualBounds.x; y = actualBounds.height + - PdfSectionHelper.getHelper(section) - .getBottomIndentHeight(document, page, false) - + PdfSectionHelper.getHelper(section).getBottomIndentHeight(document, page, false) - base.height; width = actualSize.width; height = base.height; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_section.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_section.dart index d1270149b..ec8fe1967 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_section.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pages/pdf_section.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../drawing/drawing.dart'; @@ -47,8 +47,7 @@ class PdfSection implements IPdfWrapper { _helper._section!.beginSave = _helper.beginSave; _helper._pageCount = PdfNumber(0); _helper._section![PdfDictionaryProperties.count] = _helper._pageCount; - _helper._section![PdfDictionaryProperties.type] = - PdfName(PdfDictionaryProperties.pages); + _helper._section![PdfDictionaryProperties.type] = PdfName(PdfDictionaryProperties.pages); _helper._section![PdfDictionaryProperties.kids] = _helper.pageReferences; _helper.pdfDocument = document; _helper.settings = settings != null @@ -133,10 +132,8 @@ class PdfSection implements IPdfWrapper { /// document.dispose(); /// ``` PdfPageSettings get pageSettings { - PdfMarginsHelper.getHelper(_helper.settings.margins).isPageAdded = - _helper._pages.isNotEmpty; - PdfPageSettingsHelper.getHelper(_helper.settings).isPageAdded = - _helper._pages.isNotEmpty; + PdfMarginsHelper.getHelper(_helper.settings.margins).isPageAdded = _helper._pages.isNotEmpty; + PdfPageSettingsHelper.getHelper(_helper.settings).isPageAdded = _helper._pages.isNotEmpty; return _helper.settings; } @@ -234,9 +231,7 @@ class PdfSectionHelper { final PdfSectionCollection? sectionCollection = parent; if (sectionCollection != null) { PdfPageCollectionHelper.getHelper( - PdfSectionCollectionHelper.getHelper(sectionCollection) - .document! - .pages) + PdfSectionCollectionHelper.getHelper(sectionCollection).document!.pages) .onPageAdded(args); } _pageCount!.value = count; @@ -271,18 +266,14 @@ class PdfSectionHelper { } /// internal method - PdfRectangle getActualBounds(PdfPage page, bool includeMargins, - [PdfDocument? document]) { + PdfRectangle getActualBounds(PdfPage page, bool includeMargins, [PdfDocument? document]) { if (document == null) { if (parent != null) { - final PdfDocument? pdfDocument = - PdfSectionCollectionHelper.getHelper(parent!).document; + final PdfDocument? pdfDocument = PdfSectionCollectionHelper.getHelper(parent!).document; return getActualBounds(page, includeMargins, pdfDocument); } else { final PdfSize size = includeMargins - ? PdfSize.fromSize( - PdfPageSettingsHelper.getHelper(base.pageSettings) - .getActualSize()) + ? PdfSize.fromSize(PdfPageSettingsHelper.getHelper(base.pageSettings).getActualSize()) : base.pageSettings.size as PdfSize; final double left = includeMargins ? base.pageSettings.margins.left : 0; final double top = includeMargins ? base.pageSettings.margins.top : 0; @@ -298,8 +289,7 @@ class PdfSectionHelper { final double left = getLeftIndentWidth(document, page, includeMargins); final double top = getTopIndentHeight(document, page, includeMargins); final double right = getRightIndentWidth(document, page, includeMargins); - final double bottom = - getBottomIndentHeight(document, page, includeMargins); + final double bottom = getBottomIndentHeight(document, page, includeMargins); bounds.x += left; bounds.y += top; bounds.width -= left + right; @@ -309,21 +299,15 @@ class PdfSectionHelper { } /// internal method - double getLeftIndentWidth( - PdfDocument document, PdfPage page, bool includeMargins) { + double getLeftIndentWidth(PdfDocument document, PdfPage page, bool includeMargins) { double value = includeMargins ? base.pageSettings.margins.left : 0; final double templateWidth = PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page) != null - ? PdfDocumentTemplateHelper.getHelper(base.template) - .getLeft(page)! - .width + ? PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page)!.width : 0; final double docTemplateWidth = - PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page) != - null - ? PdfDocumentTemplateHelper.getHelper(document.template) - .getLeft(page)! - .width + PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page) != null + ? PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page)!.width : 0; value += base.template.leftTemplate ? (templateWidth >= docTemplateWidth ? templateWidth : docTemplateWidth) @@ -332,47 +316,32 @@ class PdfSectionHelper { } /// internal method - double getTopIndentHeight( - PdfDocument document, PdfPage page, bool includeMargins) { + double getTopIndentHeight(PdfDocument document, PdfPage page, bool includeMargins) { double value = includeMargins ? base.pageSettings.margins.top : 0; final double templateHeight = PdfDocumentTemplateHelper.getHelper(base.template).getTop(page) != null - ? PdfDocumentTemplateHelper.getHelper(base.template) - .getTop(page)! - .height + ? PdfDocumentTemplateHelper.getHelper(base.template).getTop(page)!.height : 0; final double docTemplateHeight = - PdfDocumentTemplateHelper.getHelper(document.template).getTop(page) != - null - ? PdfDocumentTemplateHelper.getHelper(document.template) - .getTop(page)! - .height + PdfDocumentTemplateHelper.getHelper(document.template).getTop(page) != null + ? PdfDocumentTemplateHelper.getHelper(document.template).getTop(page)!.height : 0; value += base.template.topTemplate - ? (templateHeight >= docTemplateHeight - ? templateHeight - : docTemplateHeight) + ? (templateHeight >= docTemplateHeight ? templateHeight : docTemplateHeight) : templateHeight; return value; } /// internal method - double getRightIndentWidth( - PdfDocument document, PdfPage page, bool includeMargins) { + double getRightIndentWidth(PdfDocument document, PdfPage page, bool includeMargins) { double value = includeMargins ? base.pageSettings.margins.right : 0; final double templateWidth = - PdfDocumentTemplateHelper.getHelper(base.template).getRight(page) != - null - ? PdfDocumentTemplateHelper.getHelper(base.template) - .getRight(page)! - .width + PdfDocumentTemplateHelper.getHelper(base.template).getRight(page) != null + ? PdfDocumentTemplateHelper.getHelper(base.template).getRight(page)!.width : 0; final double docTemplateWidth = - PdfDocumentTemplateHelper.getHelper(document.template).getRight(page) != - null - ? PdfDocumentTemplateHelper.getHelper(document.template) - .getRight(page)! - .width + PdfDocumentTemplateHelper.getHelper(document.template).getRight(page) != null + ? PdfDocumentTemplateHelper.getHelper(document.template).getRight(page)!.width : 0; value += base.template.rightTemplate ? (templateWidth >= docTemplateWidth ? templateWidth : docTemplateWidth) @@ -381,28 +350,18 @@ class PdfSectionHelper { } /// internal method - double getBottomIndentHeight( - PdfDocument document, PdfPage page, bool includeMargins) { + double getBottomIndentHeight(PdfDocument document, PdfPage page, bool includeMargins) { double value = includeMargins ? base.pageSettings.margins.bottom : 0; final double templateHeight = - PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page) != - null - ? PdfDocumentTemplateHelper.getHelper(base.template) - .getBottom(page)! - .height + PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page) != null + ? PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page)!.height : 0; final double docTemplateHeight = - PdfDocumentTemplateHelper.getHelper(document.template) - .getBottom(page) != - null - ? PdfDocumentTemplateHelper.getHelper(document.template) - .getBottom(page)! - .height + PdfDocumentTemplateHelper.getHelper(document.template).getBottom(page) != null + ? PdfDocumentTemplateHelper.getHelper(document.template).getBottom(page)!.height : 0; value += base.template.bottomTemplate - ? (templateHeight >= docTemplateHeight - ? templateHeight - : docTemplateHeight) + ? (templateHeight >= docTemplateHeight ? templateHeight : docTemplateHeight) : templateHeight; return value; } @@ -418,46 +377,35 @@ class PdfSectionHelper { } } - void _setPageSettings(PdfDictionary container, - [PdfPageSettings? parentSettings]) { - if (parentSettings == null || - base.pageSettings.size != parentSettings.size) { + void _setPageSettings(PdfDictionary container, [PdfPageSettings? parentSettings]) { + if (parentSettings == null || base.pageSettings.size != parentSettings.size) { final PdfRectangle bounds = PdfRectangle( PdfPageSettingsHelper.getHelper(settings).origin.x, PdfPageSettingsHelper.getHelper(settings).origin.y, settings.size.width, settings.size.height); - container[PdfDictionaryProperties.mediaBox] = - PdfArray.fromRectangle(bounds); + container[PdfDictionaryProperties.mediaBox] = PdfArray.fromRectangle(bounds); } - if (parentSettings == null || - base.pageSettings.rotate != parentSettings.rotate) { + if (parentSettings == null || base.pageSettings.rotate != parentSettings.rotate) { int rotate = 0; if (_sectionCollection != null) { if (PdfPageSettingsHelper.getHelper(base.pageSettings).isRotation && - !PdfPageSettingsHelper.getHelper(document!.pageSettings) - .isRotation) { - rotate = PdfSectionCollectionHelper.rotateFactor * - base.pageSettings.rotate.index; + !PdfPageSettingsHelper.getHelper(document!.pageSettings).isRotation) { + rotate = PdfSectionCollectionHelper.rotateFactor * base.pageSettings.rotate.index; } else { - if (!PdfPageSettingsHelper.getHelper(document!.pageSettings) - .isRotation && + if (!PdfPageSettingsHelper.getHelper(document!.pageSettings).isRotation && base.pageSettings.rotate != PdfPageRotateAngle.rotateAngle0) { - rotate = PdfSectionCollectionHelper.rotateFactor * - base.pageSettings.rotate.index; + rotate = PdfSectionCollectionHelper.rotateFactor * base.pageSettings.rotate.index; } else { if (PdfPageSettingsHelper.getHelper(base.pageSettings).isRotation) { - rotate = PdfSectionCollectionHelper.rotateFactor * - base.pageSettings.rotate.index; + rotate = PdfSectionCollectionHelper.rotateFactor * base.pageSettings.rotate.index; } else if (parentSettings != null) { - rotate = PdfSectionCollectionHelper.rotateFactor * - parentSettings.rotate.index; + rotate = PdfSectionCollectionHelper.rotateFactor * parentSettings.rotate.index; } } } } else { - rotate = PdfSectionCollectionHelper.rotateFactor * - base.pageSettings.rotate.index; + rotate = PdfSectionCollectionHelper.rotateFactor * base.pageSettings.rotate.index; } final PdfNumber angle = PdfNumber(rotate); if (angle.value != 0) { @@ -497,54 +445,33 @@ class PdfSectionHelper { final List templates = []; if (headers) { if (base.template.topTemplate && - PdfDocumentTemplateHelper.getHelper(document.template).getTop(page) != - null && - PdfDocumentTemplateHelper.getHelper(document.template) - .getTop(page)! - .foreground == + PdfDocumentTemplateHelper.getHelper(document.template).getTop(page) != null && + PdfDocumentTemplateHelper.getHelper(document.template).getTop(page)!.foreground == foreground) { - templates.add(PdfDocumentTemplateHelper.getHelper(document.template) - .getTop(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(document.template).getTop(page)!); } if (base.template.bottomTemplate && - PdfDocumentTemplateHelper.getHelper(document.template) - .getBottom(page) != - null && - PdfDocumentTemplateHelper.getHelper(document.template) - .getBottom(page)! - .foreground == + PdfDocumentTemplateHelper.getHelper(document.template).getBottom(page) != null && + PdfDocumentTemplateHelper.getHelper(document.template).getBottom(page)!.foreground == foreground) { - templates.add(PdfDocumentTemplateHelper.getHelper(document.template) - .getBottom(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(document.template).getBottom(page)!); } if (base.template.leftTemplate && - PdfDocumentTemplateHelper.getHelper(document.template) - .getLeft(page) != - null && - PdfDocumentTemplateHelper.getHelper(document.template) - .getLeft(page)! - .foreground == + PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page) != null && + PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page)!.foreground == foreground) { - templates.add(PdfDocumentTemplateHelper.getHelper(document.template) - .getLeft(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(document.template).getLeft(page)!); } if (base.template.rightTemplate && - PdfDocumentTemplateHelper.getHelper(document.template) - .getRight(page) != - null && - PdfDocumentTemplateHelper.getHelper(document.template) - .getRight(page)! - .foreground == + PdfDocumentTemplateHelper.getHelper(document.template).getRight(page) != null && + PdfDocumentTemplateHelper.getHelper(document.template).getRight(page)!.foreground == foreground) { - templates.add(PdfDocumentTemplateHelper.getHelper(document.template) - .getRight(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(document.template).getRight(page)!); } } else if (base.template.stamp) { - final List list = - PdfObjectCollectionHelper.getHelper(document.template.stamps).list; + final List list = PdfObjectCollectionHelper.getHelper(document.template.stamps).list; for (int i = 0; i < list.length; i++) { - final PdfPageTemplateElement template = - list[i] as PdfPageTemplateElement; + final PdfPageTemplateElement template = list[i] as PdfPageTemplateElement; if (template.foreground == foreground) { templates.add(template); } @@ -553,49 +480,31 @@ class PdfSectionHelper { return templates; } - List _getSectionTemplates( - PdfPage page, bool headers, bool foreground) { + List _getSectionTemplates(PdfPage page, bool headers, bool foreground) { final List templates = []; if (headers) { - if (PdfDocumentTemplateHelper.getHelper(base.template).getTop(page) != - null && - PdfDocumentTemplateHelper.getHelper(base.template) - .getTop(page)! - .foreground == + if (PdfDocumentTemplateHelper.getHelper(base.template).getTop(page) != null && + PdfDocumentTemplateHelper.getHelper(base.template).getTop(page)!.foreground == foreground) { - templates.add( - PdfDocumentTemplateHelper.getHelper(base.template).getTop(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(base.template).getTop(page)!); } - if (PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page) != - null && - PdfDocumentTemplateHelper.getHelper(base.template) - .getBottom(page)! - .foreground == + if (PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page) != null && + PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page)!.foreground == foreground) { - templates.add(PdfDocumentTemplateHelper.getHelper(base.template) - .getBottom(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(base.template).getBottom(page)!); } - if (PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page) != - null && - PdfDocumentTemplateHelper.getHelper(base.template) - .getLeft(page)! - .foreground == + if (PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page) != null && + PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page)!.foreground == foreground) { - templates.add( - PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(base.template).getLeft(page)!); } - if (PdfDocumentTemplateHelper.getHelper(base.template).getRight(page) != - null && - PdfDocumentTemplateHelper.getHelper(base.template) - .getRight(page)! - .foreground == + if (PdfDocumentTemplateHelper.getHelper(base.template).getRight(page) != null && + PdfDocumentTemplateHelper.getHelper(base.template).getRight(page)!.foreground == foreground) { - templates.add( - PdfDocumentTemplateHelper.getHelper(base.template).getRight(page)!); + templates.add(PdfDocumentTemplateHelper.getHelper(base.template).getRight(page)!); } } else { - final List list = - PdfObjectCollectionHelper.getHelper(base.template.stamps).list; + final List list = PdfObjectCollectionHelper.getHelper(base.template.stamps).list; for (int i = 0; i < list.length; i++) { final PdfPageTemplateElement temp = list[i] as PdfPageTemplateElement; if (temp.foreground == foreground) { @@ -607,8 +516,7 @@ class PdfSectionHelper { } /// internal method - void drawTemplates( - PdfPage page, PdfPageLayer layer, PdfDocument document, bool foreground) { + void drawTemplates(PdfPage page, PdfPageLayer layer, PdfDocument document, bool foreground) { final List documentHeaders = _getDocumentTemplates(document, page, true, foreground); final List documentTemplates = @@ -630,8 +538,8 @@ class PdfSectionHelper { } } - void _internaldrawTemplates(PdfPageLayer layer, PdfDocument document, - List templates) { + void _internaldrawTemplates( + PdfPageLayer layer, PdfDocument document, List templates) { if (templates.isNotEmpty) { for (final PdfPageTemplateElement template in templates) { PdfPageTemplateElementHelper.getHelper(template).draw(layer, document); @@ -650,8 +558,7 @@ class PdfSectionHelper { /// internal method void dropCropBox() { _setPageSettings(_section!); - _section![PdfDictionaryProperties.cropBox] = - _section![PdfDictionaryProperties.mediaBox]; + _section![PdfDictionaryProperties.cropBox] = _section![PdfDictionaryProperties.mediaBox]; } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_automatic_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_automatic_field.dart index 60dc96206..f6bf2aef4 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_automatic_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_automatic_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_brush.dart'; @@ -23,8 +23,7 @@ import 'pdf_static_field.dart'; /// Represents a fields which is calculated before the document saves. abstract class PdfAutomaticField { /// Initialize [PdfAutomaticField] object - void _internal(PdfFont? font, - {Rect? bounds, PdfBrush? brush, PdfAutomaticFieldHelper? helper}) { + void _internal(PdfFont? font, {Rect? bounds, PdfBrush? brush, PdfAutomaticFieldHelper? helper}) { _helper = helper!; this.font = font ?? PdfStandardFont(PdfFontFamily.helvetica, 8); if (bounds != null) { @@ -432,31 +431,26 @@ class PdfAutomaticFieldHelper { /// internal method String? getValue(PdfGraphics graphics) { if (base is PdfCompositeField) { - return PdfCompositeFieldHelper.getValue( - base as PdfCompositeField, graphics); + return PdfCompositeFieldHelper.getValue(base as PdfCompositeField, graphics); } else if (base is PdfDateTimeField) { - return PdfDateTimeFieldHelper.getValue( - base as PdfDateTimeField, graphics); + return PdfDateTimeFieldHelper.getValue(base as PdfDateTimeField, graphics); } else if (base is PdfDestinationPageNumberField) { return PdfDestinationPageNumberFieldHelper.getValue( base as PdfDestinationPageNumberField, graphics); } else if (base is PdfPageNumberField) { - return PdfPageNumberFieldHelper.getHelper(base as PdfPageNumberField) - .getValue(graphics); + return PdfPageNumberFieldHelper.getHelper(base as PdfPageNumberField).getValue(graphics); } else if (base is PdfPageCountField) { - return PdfPageCountFieldHelper.getValue( - base as PdfPageCountField, graphics); + return PdfPageCountFieldHelper.getValue(base as PdfPageCountField, graphics); } return graphics as String; } /// internal method - void performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, - double scalingY) { + void performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, double scalingY) { if (base.bounds.height == 0 || base.bounds.width == 0) { final String text = getValue(graphics)!; - _templateSize = base.font.measureString(text, - layoutArea: base.bounds.size, format: base.stringFormat); + _templateSize = + base.font.measureString(text, layoutArea: base.bounds.size, format: base.stringFormat); } if (base is PdfStaticField) { PdfStaticFieldHelper.performDraw( @@ -465,8 +459,8 @@ class PdfAutomaticFieldHelper { PdfSingleValueFieldHelper.performDraw( base as PdfSingleValueField, graphics, location, scalingX, scalingY); } else if (base is PdfMultipleValueField) { - PdfMultipleValueFieldHelper.performDraw(base as PdfMultipleValueField, - graphics, location, scalingX, scalingY); + PdfMultipleValueFieldHelper.performDraw( + base as PdfMultipleValueField, graphics, location, scalingX, scalingY); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_destination_page_number_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_destination_page_number_field.dart index 1e691b452..2d991ac00 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_destination_page_number_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_destination_page_number_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; import '../../graphics/fonts/pdf_font.dart'; @@ -11,8 +11,7 @@ class PdfDestinationPageNumberField extends PdfPageNumberField { // constructor /// Initializes a new instance of the [PdfDestinationPageNumberField] class /// may include with [PdfFont], [PdfBrush] and [Rect]. - PdfDestinationPageNumberField( - {PdfPage? page, super.font, super.brush, super.bounds}) { + PdfDestinationPageNumberField({PdfPage? page, super.font, super.brush, super.bounds}) { if (page != null) { this.page = page; } @@ -31,8 +30,7 @@ class PdfDestinationPageNumberField extends PdfPageNumberField { /// [PdfDestinationPageNumberField] helper class PdfDestinationPageNumberFieldHelper { /// internal method - static String getValue( - PdfDestinationPageNumberField field, PdfGraphics graphics) { + static String getValue(PdfDestinationPageNumberField field, PdfGraphics graphics) { return field._getValue(graphics); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_dynamic_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_dynamic_field.dart index e9d57882d..aa123d51d 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_dynamic_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_dynamic_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; import '../../graphics/fonts/pdf_font.dart'; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_multiple_value_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_multiple_value_field.dart index 897c668de..83eac6f00 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_multiple_value_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_multiple_value_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/figures/pdf_template.dart'; @@ -14,14 +14,11 @@ abstract class PdfMultipleValueField extends PdfDynamicField { PdfMultipleValueField({super.font, super.brush, super.bounds}); // fields - final Map _list = - {}; + final Map _list = {}; // implementation - void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, - double scalingY) { - final String? value = - PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); + void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, double scalingY) { + final String? value = PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); if (_list.containsKey(graphics)) { final PdfTemplateValuePair pair = _list[graphics]!; if (pair.value != value) { @@ -41,19 +38,12 @@ abstract class PdfMultipleValueField extends PdfDynamicField { template.graphics!.drawString(value, font, pen: pen, brush: brush, - bounds: Rect.fromLTWH( - 0, - 0, - PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, + bounds: Rect.fromLTWH(0, 0, PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, PdfAutomaticFieldHelper.getHelper(this).obtainSize().height), format: stringFormat); - final Offset drawLocation = - Offset(location!.x + bounds.left, location.y + bounds.top); - graphics.drawPdfTemplate( - template, - drawLocation, - Size( - template.size.width * scalingX, template.size.height * scalingY)); + final Offset drawLocation = Offset(location!.x + bounds.left, location.y + bounds.top); + graphics.drawPdfTemplate(template, drawLocation, + Size(template.size.width * scalingX, template.size.height * scalingY)); } } } @@ -62,8 +52,8 @@ abstract class PdfMultipleValueField extends PdfDynamicField { /// [PdfMultipleValueField] helper class PdfMultipleValueFieldHelper { /// internal method - static void performDraw(PdfMultipleValueField field, PdfGraphics graphics, - PdfPoint? location, double scalingX, double scalingY) { + static void performDraw(PdfMultipleValueField field, PdfGraphics graphics, PdfPoint? location, + double scalingX, double scalingY) { field._performDraw(graphics, location, scalingX, scalingY); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_count_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_count_field.dart index 7c76e88f8..ca01a7f67 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_count_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_count_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; import '../../graphics/fonts/pdf_font.dart'; @@ -93,8 +93,7 @@ class PdfPageCountField extends PdfSingleValueField { /// //Dispose the document. /// document.dispose(); /// ``` - PdfPageCountField( - {PdfFont? font, PdfBrush? brush, Rect? bounds, bool? isSectionPageCount}) + PdfPageCountField({PdfFont? font, PdfBrush? brush, Rect? bounds, bool? isSectionPageCount}) : super(font, brush, bounds) { _isSectionPageCount = isSectionPageCount != null && isSectionPageCount; } @@ -154,9 +153,7 @@ class PdfPageCountField extends PdfSingleValueField { return PdfAutomaticFieldHelper.convert(count, numberStyle); } else { final PdfDocument document = PdfSectionCollectionHelper.getHelper( - PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(page).section!) - .parent!) + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page).section!).parent!) .document!; final int number = document.pages.count; return PdfAutomaticFieldHelper.convert(number, numberStyle); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_number_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_number_field.dart index c4bb78108..30107dccb 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_number_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_page_number_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; import '../../graphics/fonts/pdf_font.dart'; @@ -92,11 +92,9 @@ class PdfPageNumberField extends PdfMultipleValueField { /// //Dispose the document. /// document.dispose(); /// ``` - PdfPageNumberField( - {super.font, super.brush, super.bounds, bool? isSectionPageNumber}) { + PdfPageNumberField({super.font, super.brush, super.bounds, bool? isSectionPageNumber}) { _helper = PdfPageNumberFieldHelper(this); - _helper._isSectionPageNumber = - isSectionPageNumber != null && isSectionPageNumber; + _helper._isSectionPageNumber = isSectionPageNumber != null && isSectionPageNumber; } // fields @@ -176,9 +174,7 @@ class PdfPageNumberFieldHelper { return PdfAutomaticFieldHelper.convert(index, base.numberStyle); } else { final PdfDocument document = PdfSectionCollectionHelper.getHelper( - PdfSectionHelper.getHelper( - PdfPageHelper.getHelper(page!).section!) - .parent!) + PdfSectionHelper.getHelper(PdfPageHelper.getHelper(page!).section!).parent!) .document!; final int pageIndex = document.pages.indexOf(page) + 1; return PdfAutomaticFieldHelper.convert(pageIndex, base.numberStyle); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_single_value_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_single_value_field.dart index 3d2d5b60f..ac70a8837 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_single_value_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_single_value_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; @@ -19,40 +19,29 @@ abstract class PdfSingleValueField extends PdfDynamicField { : super(font: font, bounds: bounds, brush: brush); // field - final Map _list = - {}; + final Map _list = {}; final List _painterGraphics = []; // implementation - void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, - double scalingY) { + void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, double scalingY) { if (PdfGraphicsHelper.getHelper(graphics).page is PdfPage) { final PdfPage page = PdfDynamicField.getPageFromGraphics(graphics); final PdfDocument? document = PdfPageHelper.getHelper(page).document; - final String? value = - PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); + final String? value = PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); if (_list.containsKey(document)) { final PdfTemplateValuePair pair = _list[document]!; if (pair.value != value) { - final Size size = - PdfAutomaticFieldHelper.getHelper(this).obtainSize(); + final Size size = PdfAutomaticFieldHelper.getHelper(this).obtainSize(); pair.template.reset(size.width, size.height); pair.template.graphics!.drawString(value!, font, - pen: pen, - brush: brush, - bounds: bounds.topLeft & size, - format: stringFormat); + pen: pen, brush: brush, bounds: bounds.topLeft & size, format: stringFormat); } if (!_painterGraphics.contains(graphics)) { - final Offset drawLocation = - Offset(location!.x + bounds.left, location.y + bounds.top); - graphics.drawPdfTemplate( - pair.template, - drawLocation, - Size(pair.template.size.width * scalingX, - pair.template.size.height * scalingY)); + final Offset drawLocation = Offset(location!.x + bounds.left, location.y + bounds.top); + graphics.drawPdfTemplate(pair.template, drawLocation, + Size(pair.template.size.width * scalingX, pair.template.size.height * scalingY)); _painterGraphics.add(graphics); } } else { @@ -64,16 +53,11 @@ abstract class PdfSingleValueField extends PdfDynamicField { template.graphics!.drawString(value, font, pen: pen, brush: brush, - bounds: Rect.fromLTWH( - bounds.left, bounds.top, bounds.width, bounds.height), + bounds: Rect.fromLTWH(bounds.left, bounds.top, bounds.width, bounds.height), format: stringFormat); - final Offset drawLocation = - Offset(location!.x + bounds.left, location.y + bounds.top); - graphics.drawPdfTemplate( - pair.template, - drawLocation, - Size(pair.template.size.width * scalingX, - pair.template.size.height * scalingY)); + final Offset drawLocation = Offset(location!.x + bounds.left, location.y + bounds.top); + graphics.drawPdfTemplate(pair.template, drawLocation, + Size(pair.template.size.width * scalingX, pair.template.size.height * scalingY)); _painterGraphics.add(graphics); } } @@ -84,8 +68,8 @@ abstract class PdfSingleValueField extends PdfDynamicField { /// [PdfSingleValueField] value class PdfSingleValueFieldHelper { /// internal method - static void performDraw(PdfSingleValueField field, PdfGraphics graphics, - PdfPoint? location, double scalingX, double scalingY) { + static void performDraw(PdfSingleValueField field, PdfGraphics graphics, PdfPoint? location, + double scalingX, double scalingY) { field._performDraw(graphics, location, scalingX, scalingY); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_static_field.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_static_field.dart index 7033a69af..e12ccd48c 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_static_field.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/automatic_fields/pdf_static_field.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; @@ -21,39 +21,26 @@ abstract class PdfStaticField extends PdfAutomaticField { final List _graphicsList = []; // implementation - void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, - double scalingY) { - final String? value = - PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); - final Offset drawLocation = - Offset(location!.x + bounds.left, location.y + bounds.top); + void _performDraw(PdfGraphics graphics, PdfPoint? location, double scalingX, double scalingY) { + final String? value = PdfAutomaticFieldHelper.getHelper(this).getValue(graphics); + final Offset drawLocation = Offset(location!.x + bounds.left, location.y + bounds.top); if (_template == null) { - _template = PdfTemplate( - PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, + _template = PdfTemplate(PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, PdfAutomaticFieldHelper.getHelper(this).obtainSize().height); _template!.graphics!.drawString(value!, font, pen: pen, brush: brush, - bounds: Rect.fromLTWH( - 0, - 0, - PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, + bounds: Rect.fromLTWH(0, 0, PdfAutomaticFieldHelper.getHelper(this).obtainSize().width, PdfAutomaticFieldHelper.getHelper(this).obtainSize().height), format: stringFormat); - graphics.drawPdfTemplate( - _template!, - drawLocation, - Size(_template!.size.width * scalingX, - _template!.size.height * scalingY)); + graphics.drawPdfTemplate(_template!, drawLocation, + Size(_template!.size.width * scalingX, _template!.size.height * scalingY)); _graphicsList.add(graphics); } else { if (!_graphicsList.contains(graphics)) { - graphics.drawPdfTemplate( - _template!, - drawLocation, - Size(_template!.size.width * scalingX, - _template!.size.height * scalingY)); + graphics.drawPdfTemplate(_template!, drawLocation, + Size(_template!.size.width * scalingX, _template!.size.height * scalingY)); _graphicsList.add(graphics); } } @@ -64,8 +51,8 @@ abstract class PdfStaticField extends PdfAutomaticField { /// [PdfStaticField] helper class PdfStaticFieldHelper { /// internal method - static void performDraw(PdfStaticField staticField, PdfGraphics graphics, - PdfPoint? location, double scalingX, double scalingY) { + static void performDraw(PdfStaticField staticField, PdfGraphics graphics, PdfPoint? location, + double scalingX, double scalingY) { staticField._performDraw(graphics, location, scalingX, scalingY); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/outlines/pdf_outline.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/outlines/pdf_outline.dart index c240a07c9..57e9db378 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/outlines/pdf_outline.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/pdf_document/outlines/pdf_outline.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../interfaces/pdf_interface.dart'; import '../../actions/pdf_action.dart'; @@ -40,8 +40,8 @@ import 'enums.dart'; class PdfBookmark extends PdfBookmarkBase { //Constructor /// Initializes a new instance of the [PdfBookmark] class. - PdfBookmark._internal(String title, PdfBookmarkBase parent, - PdfBookmark? previous, PdfBookmark? next, + PdfBookmark._internal( + String title, PdfBookmarkBase parent, PdfBookmark? previous, PdfBookmark? next, {bool isExpanded = false, PdfColor? color, PdfDestination? destination, @@ -50,8 +50,7 @@ class PdfBookmark extends PdfBookmarkBase { List? textStyle}) : super._internal() { _parent = parent; - _helper.dictionary!.setProperty( - PdfDictionaryProperties.parent, PdfReferenceHolder(parent)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.parent, PdfReferenceHolder(parent)); _previous = previous; _next = next; this.title = title; @@ -73,8 +72,7 @@ class PdfBookmark extends PdfBookmarkBase { } } - PdfBookmark._load(super.dictionary, PdfCrossTable super.crossTable) - : super._load(); + PdfBookmark._load(super.dictionary, PdfCrossTable super.crossTable) : super._load(); //Fields /// Internal variable to store destination. @@ -430,12 +428,9 @@ class PdfBookmark extends PdfBookmarkBase { if (value != null && _namedDestination != value) { _namedDestination = value; final PdfDictionary dictionary = PdfDictionary(); - dictionary.setProperty( - PdfDictionaryProperties.d, PdfString(_namedDestination!.title)); - dictionary.setProperty( - PdfDictionaryProperties.s, PdfName(PdfDictionaryProperties.goTo)); - dictionary.setProperty( - PdfDictionaryProperties.a, PdfReferenceHolder(dictionary)); + dictionary.setProperty(PdfDictionaryProperties.d, PdfString(_namedDestination!.title)); + dictionary.setProperty(PdfDictionaryProperties.s, PdfName(PdfDictionaryProperties.goTo)); + dictionary.setProperty(PdfDictionaryProperties.a, PdfReferenceHolder(dictionary)); } } @@ -460,8 +455,7 @@ class PdfBookmark extends PdfBookmarkBase { if (_isLoadedBookmark) { return _obtainTitle(); } else { - final PdfString? title = - _helper.dictionary![PdfDictionaryProperties.title] as PdfString?; + final PdfString? title = _helper.dictionary![PdfDictionaryProperties.title] as PdfString?; if (title != null && title.value != null) { return title.value!; } else { @@ -603,8 +597,7 @@ class PdfBookmark extends PdfBookmarkBase { set _previous(PdfBookmark? value) { if (_previousBookmark != value) { _previousBookmark = value; - _helper.dictionary! - .setProperty(PdfDictionaryProperties.prev, PdfReferenceHolder(value)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.prev, PdfReferenceHolder(value)); } } @@ -621,8 +614,7 @@ class PdfBookmark extends PdfBookmarkBase { set _next(PdfBookmark? value) { if (_nextBookmark != value) { _nextBookmark = value; - _helper.dictionary! - .setProperty(PdfDictionaryProperties.next, PdfReferenceHolder(value)); + _helper.dictionary!.setProperty(PdfDictionaryProperties.next, PdfReferenceHolder(value)); } } @@ -641,13 +633,11 @@ class PdfBookmark extends PdfBookmarkBase { } void _updateColor() { - final PdfArray? array = - _helper.dictionary![PdfDictionaryProperties.c] as PdfArray?; + final PdfArray? array = _helper.dictionary![PdfDictionaryProperties.c] as PdfArray?; if (array != null && _color.isEmpty) { _helper.dictionary!.remove(PdfDictionaryProperties.c); } else { - _helper.dictionary![PdfDictionaryProperties.c] = - PdfColorHelper.toArray(_color); + _helper.dictionary![PdfDictionaryProperties.c] = PdfColorHelper.toArray(_color); } } @@ -667,17 +657,16 @@ class PdfBookmark extends PdfBookmarkBase { String _obtainTitle() { String title = ''; if (_helper.dictionary!.containsKey(PdfDictionaryProperties.title)) { - final PdfString? str = PdfCrossTable.dereference( - _helper.dictionary![PdfDictionaryProperties.title]) as PdfString?; + final PdfString? str = + PdfCrossTable.dereference(_helper.dictionary![PdfDictionaryProperties.title]) + as PdfString?; if (str != null && str.value != null) { title = str.value!; if (_regex.hasMatch(title)) { for (int i = 0; i < title.length; i++) { if (_regex.hasMatch(title[i])) { - title = title.replaceAll( - title[i], - String.fromCharCode( - _pdfEncodingByteToChar[title.codeUnitAt(i) & 0xff])); + title = title.replaceAll(title[i], + String.fromCharCode(_pdfEncodingByteToChar[title.codeUnitAt(i) & 0xff])); } } } @@ -689,14 +678,13 @@ class PdfBookmark extends PdfBookmarkBase { PdfColor _obtainColor() { PdfColor color = PdfColor(0, 0, 0); if (_helper.dictionary!.containsKey(PdfDictionaryProperties.c)) { - final PdfArray? colours = PdfCrossTable.dereference( - _helper.dictionary![PdfDictionaryProperties.c]) as PdfArray?; + final PdfArray? colours = + PdfCrossTable.dereference(_helper.dictionary![PdfDictionaryProperties.c]) as PdfArray?; if (colours != null && colours.count > 2) { double? red = 0; double green = 0; double blue = 0; - PdfNumber? colorValue = - PdfCrossTable.dereference(colours[0]) as PdfNumber?; + PdfNumber? colorValue = PdfCrossTable.dereference(colours[0]) as PdfNumber?; if (colorValue != null) { red = colorValue.value as double?; } @@ -717,8 +705,8 @@ class PdfBookmark extends PdfBookmarkBase { PdfTextStyle _obtainTextStyle() { PdfTextStyle style = PdfTextStyle.regular; if (_helper.dictionary!.containsKey(PdfDictionaryProperties.f)) { - final PdfNumber? flag = PdfCrossTable.dereference( - _helper.dictionary![PdfDictionaryProperties.f]) as PdfNumber?; + final PdfNumber? flag = + PdfCrossTable.dereference(_helper.dictionary![PdfDictionaryProperties.f]) as PdfNumber?; int flagValue = 0; if (flag != null) { flagValue = flag.value!.toInt() - 1; @@ -737,8 +725,7 @@ class PdfBookmark extends PdfBookmarkBase { } else { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.next)) { final PdfDictionary? next = _helper._crossTable - .getObject(_helper.dictionary![PdfDictionaryProperties.next]) - as PdfDictionary?; + .getObject(_helper.dictionary![PdfDictionaryProperties.next]) as PdfDictionary?; nextBookmark = PdfBookmark._load(next, _helper._crossTable); } } @@ -754,8 +741,7 @@ class PdfBookmark extends PdfBookmarkBase { } else { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.prev)) { final PdfDictionary? prev = _helper._crossTable - .getObject(_helper.dictionary![PdfDictionaryProperties.prev]) - as PdfDictionary?; + .getObject(_helper.dictionary![PdfDictionaryProperties.prev]) as PdfDictionary?; prevBookmark = PdfBookmark._load(prev, _helper._crossTable); } } @@ -763,11 +749,7 @@ class PdfBookmark extends PdfBookmarkBase { } void _assignColor(PdfColor color) { - final List rgb = [ - color.r.toDouble(), - color.g.toDouble(), - color.b.toDouble() - ]; + final List rgb = [color.r.toDouble(), color.g.toDouble(), color.b.toDouble()]; final PdfArray colors = PdfArray(rgb); _helper.dictionary!.setProperty(PdfDictionaryProperties.c, colors); } @@ -790,16 +772,15 @@ class PdfBookmark extends PdfBookmarkBase { IPdfPrimitive? destination; if (namedCollection != null) { if (_helper.dictionary!.containsKey(PdfDictionaryProperties.a)) { - final PdfDictionary? action = PdfCrossTable.dereference( - _helper.dictionary![PdfDictionaryProperties.a]) as PdfDictionary?; + final PdfDictionary? action = + PdfCrossTable.dereference(_helper.dictionary![PdfDictionaryProperties.a]) + as PdfDictionary?; if (action != null && action.containsKey(PdfDictionaryProperties.d)) { - destination = - PdfCrossTable.dereference(action[PdfDictionaryProperties.d]); + destination = PdfCrossTable.dereference(action[PdfDictionaryProperties.d]); } - } else if (_helper.dictionary! - .containsKey(PdfDictionaryProperties.dest)) { - destination = _helper._crossTable - .getObject(_helper.dictionary![PdfDictionaryProperties.dest]); + } else if (_helper.dictionary!.containsKey(PdfDictionaryProperties.dest)) { + destination = + _helper._crossTable.getObject(_helper.dictionary![PdfDictionaryProperties.dest]); } if (destination != null) { @@ -826,10 +807,9 @@ class PdfBookmark extends PdfBookmarkBase { } PdfDestination? _obtainDestination() { - if (_helper.dictionary!.containsKey(PdfDictionaryProperties.dest) && - (_destination == null)) { - final IPdfPrimitive? obj = _helper._crossTable - .getObject(_helper.dictionary![PdfDictionaryProperties.dest]); + if (_helper.dictionary!.containsKey(PdfDictionaryProperties.dest) && (_destination == null)) { + final IPdfPrimitive? obj = + _helper._crossTable.getObject(_helper.dictionary![PdfDictionaryProperties.dest]); PdfArray? array = obj as PdfArray?; final PdfName? name = (obj is PdfName) ? obj as PdfName? : null; final PdfDocument? ldDoc = _helper._crossTable.document; @@ -867,17 +847,13 @@ class PdfBookmark extends PdfBookmarkBase { zoom = array[4]; } if (page != null) { - final double topValue = (top != null && top is PdfNumber) - ? page.size.height - top.value! - : 0; - final double leftValue = (left != null && left is PdfNumber) - ? left.value! as double - : 0; - _destination = - PdfDestination(page, Offset(leftValue, topValue)); - _destination!.zoom = (zoom != null && zoom is PdfNumber) - ? zoom.value!.toDouble() - : 0; + final double topValue = + (top != null && top is PdfNumber) ? page.size.height - top.value! : 0; + final double leftValue = + (left != null && left is PdfNumber) ? left.value! as double : 0; + _destination = PdfDestination(page, Offset(leftValue, topValue)); + _destination!.zoom = + (zoom != null && zoom is PdfNumber) ? zoom.value!.toDouble() : 0; } } else { if (mode.name == PdfDictionaryProperties.fitR) { @@ -901,18 +877,10 @@ class PdfBookmark extends PdfBookmarkBase { _destination = PdfDestinationHelper.getDestination( page, PdfRectangle( - (left != null && left is PdfNumber) - ? left.value!.toDouble() - : 0, - (bottom != null && bottom is PdfNumber) - ? bottom.value!.toDouble() - : 0, - (right != null && right is PdfNumber) - ? right.value!.toDouble() - : 0, - (top != null && top is PdfNumber) - ? top.value!.toDouble() - : 0)); + (left != null && left is PdfNumber) ? left.value!.toDouble() : 0, + (bottom != null && bottom is PdfNumber) ? bottom.value!.toDouble() : 0, + (right != null && right is PdfNumber) ? right.value!.toDouble() : 0, + (top != null && top is PdfNumber) ? top.value!.toDouble() : 0)); _destination!.mode = PdfDestinationMode.fitR; } } else if (mode.name == PdfDictionaryProperties.fitBH || @@ -922,9 +890,8 @@ class PdfBookmark extends PdfBookmarkBase { top = array[2]; } if (page != null) { - final double topValue = (top != null && top is PdfNumber) - ? page.size.height - top.value! - : 0; + final double topValue = + (top != null && top is PdfNumber) ? page.size.height - top.value! : 0; _destination = PdfDestination(page, Offset(0, topValue)); _destination!.mode = PdfDestinationMode.fitH; } @@ -945,8 +912,8 @@ class PdfBookmark extends PdfBookmarkBase { } } else if (_helper.dictionary!.containsKey(PdfDictionaryProperties.a) && (_destination == null)) { - IPdfPrimitive? obj = _helper._crossTable - .getObject(_helper.dictionary![PdfDictionaryProperties.a]); + IPdfPrimitive? obj = + _helper._crossTable.getObject(_helper.dictionary![PdfDictionaryProperties.a]); PdfDictionary? destDic; if (obj is PdfDictionary) { destDic = obj; @@ -986,9 +953,8 @@ class PdfBookmark extends PdfBookmarkBase { top = array[2]; } if (page != null) { - final double topValue = (top != null && top is PdfNumber) - ? page.size.height - top.value! - : 0; + final double topValue = + (top != null && top is PdfNumber) ? page.size.height - top.value! : 0; _destination = PdfDestination(page, Offset(0, topValue)); _destination!.mode = PdfDestinationMode.fitH; } @@ -1006,16 +972,12 @@ class PdfBookmark extends PdfBookmarkBase { zoom = array[4]; } if (page != null) { - final double topValue = (top != null && top is PdfNumber) - ? page.size.height - top.value! - : 0; - final double leftValue = (left != null && left is PdfNumber) - ? left.value! as double - : 0; + final double topValue = + (top != null && top is PdfNumber) ? page.size.height - top.value! : 0; + final double leftValue = + (left != null && left is PdfNumber) ? left.value! as double : 0; _destination = PdfDestination(page, Offset(leftValue, topValue)); - _destination!.zoom = (zoom != null && zoom is PdfNumber) - ? zoom.value!.toDouble() - : 0; + _destination!.zoom = (zoom != null && zoom is PdfNumber) ? zoom.value!.toDouble() : 0; } } else { if (page != null && mode.name == PdfDictionaryProperties.fit) { @@ -1136,8 +1098,7 @@ class PdfBookmarkBase implements IPdfWrapper { /// Gets whether to expand the node or not bool get _isExpanded { if (_helper.dictionary!.containsKey('Count')) { - final PdfNumber number = - _helper.dictionary![PdfDictionaryProperties.count]! as PdfNumber; + final PdfNumber number = _helper.dictionary![PdfDictionaryProperties.count]! as PdfNumber; return !(number.value! < 0); } else { return _expanded; @@ -1177,8 +1138,7 @@ class PdfBookmarkBase implements IPdfWrapper { PdfAction? action, List? textStyle}) { final PdfBookmark? previous = (count < 1) ? null : this[count - 1]; - final PdfBookmark outline = - PdfBookmark._internal(title, this, previous, null); + final PdfBookmark outline = PdfBookmark._internal(title, this, previous, null); if (previous != null) { previous._next = outline; } @@ -1265,8 +1225,7 @@ class PdfBookmarkBase implements IPdfWrapper { } final PdfBookmark current = _bookmark![index]; if (index == 0) { - if (current._helper.dictionary! - .containsKey(PdfDictionaryProperties.next)) { + if (current._helper.dictionary!.containsKey(PdfDictionaryProperties.next)) { _helper.dictionary!.setProperty(PdfDictionaryProperties.first, current._helper.dictionary![PdfDictionaryProperties.next]); } else { @@ -1277,19 +1236,15 @@ class PdfBookmarkBase implements IPdfWrapper { (current._previous != null) && (current._next != null)) { current._previous!._helper.dictionary!.setProperty( - PdfDictionaryProperties.next, - current._helper.dictionary![PdfDictionaryProperties.next]); + PdfDictionaryProperties.next, current._helper.dictionary![PdfDictionaryProperties.next]); current._next!._helper.dictionary!.setProperty( - PdfDictionaryProperties.prev, - current._helper.dictionary![PdfDictionaryProperties.prev]); + PdfDictionaryProperties.prev, current._helper.dictionary![PdfDictionaryProperties.prev]); } else if ((current._parent != null) && (current._previous != null) && (current._next == null)) { - current._previous!._helper.dictionary! - .remove(PdfDictionaryProperties.next); + current._previous!._helper.dictionary!.remove(PdfDictionaryProperties.next); current._parent!._helper.dictionary!.setProperty( - PdfDictionaryProperties.last, - current._helper.dictionary![PdfDictionaryProperties.prev]); + PdfDictionaryProperties.last, current._helper.dictionary![PdfDictionaryProperties.prev]); } if (current._parent != null) { current._parent!._list.remove(current); @@ -1361,10 +1316,9 @@ class PdfBookmarkBase implements IPdfWrapper { if (count > 0) { final int newCount = _isExpanded ? _list.length : -_list.length; _helper.dictionary![PdfDictionaryProperties.count] = PdfNumber(newCount); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.first, PdfReferenceHolder(this[0])); - _helper.dictionary!.setProperty( - PdfDictionaryProperties.last, PdfReferenceHolder(this[count - 1])); + _helper.dictionary!.setProperty(PdfDictionaryProperties.first, PdfReferenceHolder(this[0])); + _helper.dictionary! + .setProperty(PdfDictionaryProperties.last, PdfReferenceHolder(this[count - 1])); } else { _helper.dictionary!.clear(); } @@ -1380,8 +1334,8 @@ class PdfBookmarkBase implements IPdfWrapper { /// [PdfBookmark] helper class PdfBookmarkHelper { /// internal method - static PdfBookmark internal(String title, PdfBookmarkBase parent, - PdfBookmark? previous, PdfBookmark? next, + static PdfBookmark internal( + String title, PdfBookmarkBase parent, PdfBookmark? previous, PdfBookmark? next, {bool isExpanded = false, PdfColor? color, PdfDestination? destination, @@ -1438,8 +1392,7 @@ class PdfBookmarkBaseHelper { } /// internal method - static PdfBookmarkBase loaded( - PdfDictionary? dictionary, PdfCrossTable crossTable) { + static PdfBookmarkBase loaded(PdfDictionary? dictionary, PdfCrossTable crossTable) { return PdfBookmarkBase._load(dictionary, crossTable); } @@ -1453,8 +1406,7 @@ class PdfBookmarkBaseHelper { void reproduceTree() { PdfBookmark? currentBookmark = _getFirstBookMark(base); bool isBookmark = currentBookmark != null; - while (isBookmark && - PdfBookmarkBaseHelper(currentBookmark!).dictionary != null) { + while (isBookmark && PdfBookmarkBaseHelper(currentBookmark!).dictionary != null) { PdfBookmarkHelper.setParent(currentBookmark, base); _bookmarkList.add(currentBookmark); currentBookmark = currentBookmark._next; @@ -1464,12 +1416,10 @@ class PdfBookmarkBaseHelper { PdfBookmark? _getFirstBookMark(PdfBookmarkBase bookmark) { PdfBookmark? firstBookmark; - final PdfDictionary dictionary = - PdfBookmarkBaseHelper.getHelper(bookmark).dictionary!; + final PdfDictionary dictionary = PdfBookmarkBaseHelper.getHelper(bookmark).dictionary!; if (dictionary.containsKey(PdfDictionaryProperties.first)) { final PdfDictionary? first = - _crossTable.getObject(dictionary[PdfDictionaryProperties.first]) - as PdfDictionary?; + _crossTable.getObject(dictionary[PdfDictionaryProperties.first]) as PdfDictionary?; firstBookmark = PdfBookmark._load(first, _crossTable); } return firstBookmark; diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/layouting/pdf_grid_layouter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/layouting/pdf_grid_layouter.dart index 80620fffe..37fe21d7a 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/layouting/pdf_grid_layouter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/layouting/pdf_grid_layouter.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../graphics/figures/base/element_layouter.dart'; @@ -87,13 +87,11 @@ class PdfGridLayouter extends ElementLayouter { _currentGraphics = graphics; if (PdfGraphicsHelper.getHelper(_currentGraphics!).layer != null && PdfGraphicsHelper.getHelper(_currentGraphics!).page != null) { - final int index = PdfSectionHelper.getHelper(PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) - .section!) + final int index = PdfSectionHelper.getHelper( + PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + .section!) .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!); - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(index)) { + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(index)) { PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(index); } } @@ -101,17 +99,14 @@ class PdfGridLayouter extends ElementLayouter { } PdfLayoutFormat _getFormat(PdfLayoutFormat? format) { - return format != null - ? PdfLayoutFormat.fromFormat(format) - : PdfLayoutFormat(); + return format != null ? PdfLayoutFormat.fromFormat(format) : PdfLayoutFormat(); } void _determineColumnDrawRanges() { int startColumn = 0; int endColumn = 0; double cellWidths = 0; - final double availableWidth = - _currentGraphics!.clientSize.width - _currentBounds.x; + final double availableWidth = _currentGraphics!.clientSize.width - _currentBounds.x; for (int i = 0; i < _grid!.columns.count; i++) { cellWidths += _grid!.columns[i].width; if (cellWidths >= availableWidth) { @@ -147,24 +142,21 @@ class PdfGridLayouter extends ElementLayouter { _cellStartIndex = range[0]; _cellEndIndex = range[1]; if (_currentPage != null) { - final Map pageLayoutResult = _raiseBeforePageLayout( - _currentPage, _currentBounds.rect, _currentRowIndex); - _currentBounds = - PdfRectangle.fromRect(pageLayoutResult['currentBounds']); + final Map pageLayoutResult = + _raiseBeforePageLayout(_currentPage, _currentBounds.rect, _currentRowIndex); + _currentBounds = PdfRectangle.fromRect(pageLayoutResult['currentBounds']); _currentRowIndex = pageLayoutResult['currentRow'] as int; if (pageLayoutResult['cancel'] as bool) { - result = - PdfLayoutResultHelper.load(_currentPage!, _currentBounds.rect); + result = PdfLayoutResultHelper.load(_currentPage!, _currentBounds.rect); break; } } bool drawHeader; if (PdfGridHelper.getHelper(_grid!).isBuiltinStyle && PdfGridHelper.getHelper(_grid!).parentCell == null) { - if (PdfGridHelper.getHelper(_grid!).gridBuiltinStyle != - PdfGridBuiltInStyle.tableGrid) { - PdfGridHelper.getHelper(_grid!).applyBuiltinStyles( - PdfGridHelper.getHelper(_grid!).gridBuiltinStyle); + if (PdfGridHelper.getHelper(_grid!).gridBuiltinStyle != PdfGridBuiltInStyle.tableGrid) { + PdfGridHelper.getHelper(_grid!) + .applyBuiltinStyles(PdfGridHelper.getHelper(_grid!).gridBuiltinStyle); } } for (int rowIndex = 0; rowIndex < _grid!.headers.count; rowIndex++) { @@ -174,8 +166,7 @@ class PdfGridLayouter extends ElementLayouter { if (startPage != _currentPage) { for (int k = _cellStartIndex; k <= _cellEndIndex; k++) { if (PdfGridCellHelper.getHelper(row.cells[k]).isCellMergeContinue) { - PdfGridCellHelper.getHelper(row.cells[k]).isCellMergeContinue = - false; + PdfGridCellHelper.getHelper(row.cells[k]).isCellMergeContinue = false; row.cells[k].value = ''; } } @@ -194,8 +185,7 @@ class PdfGridLayouter extends ElementLayouter { _startLocation.x = _currentBounds.x; _currentPage = _getNextPage(format); _startLocation.y = _currentBounds.y; - if (PdfRectangle.fromRect(format.paginateBounds) == - PdfRectangle.empty) { + if (PdfRectangle.fromRect(format.paginateBounds) == PdfRectangle.empty) { _currentBounds.x = _currentBounds.x + _startLocation.x; } _drawRow(row); @@ -207,29 +197,21 @@ class PdfGridLayouter extends ElementLayouter { double? startingHeight = 0; bool flag = true; if (isParentCell!) { - _cellEndIndex = - _cellStartIndex = PdfGridHelper.getHelper(_grid!).parentCellIndex; + _cellEndIndex = _cellStartIndex = PdfGridHelper.getHelper(_grid!).parentCellIndex; _parentCellIndexList = []; - _parentCellIndexList - .add(PdfGridHelper.getHelper(_grid!).parentCellIndex); - PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) - .present = true; + _parentCellIndexList.add(PdfGridHelper.getHelper(_grid!).parentCellIndex); + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).present = true; PdfGrid parentGrid = PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).row!) .grid; while (PdfGridHelper.getHelper(parentGrid).parentCell != null) { - _parentCellIndexList - .add(PdfGridHelper.getHelper(parentGrid).parentCellIndex); + _parentCellIndexList.add(PdfGridHelper.getHelper(parentGrid).parentCellIndex); _cellEndIndex = PdfGridHelper.getHelper(parentGrid).parentCellIndex; _cellStartIndex = PdfGridHelper.getHelper(parentGrid).parentCellIndex; - PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(parentGrid).parentCell!) - .present = true; - parentGrid = PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(parentGrid).parentCell!) - .row!) + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(parentGrid).parentCell!).present = + true; + parentGrid = PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(parentGrid).parentCell!).row!) .grid; if (PdfGridHelper.getHelper(parentGrid).parentCell == null) { _parentCellIndexList.removeAt(_parentCellIndexList.length - 1); @@ -238,11 +220,8 @@ class PdfGridLayouter extends ElementLayouter { PdfSection section = PdfPageHelper.getHelper(_currentPage!).section!; int index = PdfSectionHelper.getHelper(section).indexOf(_currentPage!); if ((!PdfGridHelper.getHelper(parentGrid).isDrawn) || - (!PdfGridHelper.getHelper(parentGrid) - .listOfNavigatePages - .contains(index))) { - section = PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + (!PdfGridHelper.getHelper(parentGrid).listOfNavigatePages.contains(index))) { + section = PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) .section!; index = PdfSectionHelper.getHelper(section).indexOf(_currentPage!); PdfGridHelper.getHelper(parentGrid).isDrawn = true; @@ -250,8 +229,7 @@ class PdfGridLayouter extends ElementLayouter { final PdfGridRow row = parentGrid.rows[rowIndex]; final PdfGridCell cell = row.cells[_cellStartIndex]; cell.value = ''; - final PdfPoint location = - PdfPoint(_currentBounds.x, _currentBounds.y); + final PdfPoint location = PdfPoint(_currentBounds.x, _currentBounds.y); double width = parentGrid.columns[_cellStartIndex].width; if (width > _currentGraphics!.clientSize.width) { width = _currentGraphics!.clientSize.width - 2 * location.x; @@ -260,8 +238,8 @@ class PdfGridLayouter extends ElementLayouter { if (row.height > cell.height) { height = row.height; } - PdfGridCellHelper.getHelper(cell).draw(_currentGraphics, - PdfRectangle(location.x, location.y, width, height), false); + PdfGridCellHelper.getHelper(cell) + .draw(_currentGraphics, PdfRectangle(location.x, location.y, width, height), false); _currentBounds.y = _currentBounds.y + height; } _currentBounds.y = 0; @@ -278,44 +256,29 @@ class PdfGridLayouter extends ElementLayouter { double? originalHeight = _currentBounds.y; startPage = _currentPage; repeatRowIndex = -1; - if (flag && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid!) { + if (flag && PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid!) { startingHeight = originalHeight; flag = false; } - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell! - .rowSpan > - 1 && - (startingHeight! + _childHeight).toInt() < - (_currentBounds.y + row.height).toInt()) { + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell!.rowSpan > 1 && + (startingHeight! + _childHeight).toInt() < (_currentBounds.y + row.height).toInt()) { if (_grid!.rows.count > i) { - final PdfGrid temp = PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) - .parentCell!) - .row!) + final PdfGrid temp = PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell!) + .row!) .grid; - for (int tempRowIndex = 0; - tempRowIndex < temp.rows.count; - tempRowIndex++) { + for (int tempRowIndex = 0; tempRowIndex < temp.rows.count; tempRowIndex++) { final PdfGridRow tempRow = temp.rows[tempRowIndex]; - if (tempRow.cells[PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) + if (tempRow.cells[PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) .parentCellIndex] == - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell) { + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell) { final dynamic grid = tempRow - .cells[PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) + .cells[PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) .parentCellIndex] .value; if (grid is PdfGrid) { - PdfGridRowCollectionHelper.getRows(grid.rows) - .removeRange(0, i - 1); + PdfGridRowCollectionHelper.getRows(grid.rows).removeRange(0, i - 1); } } } @@ -328,26 +291,20 @@ class PdfGridLayouter extends ElementLayouter { double x = 0; for (int l = 0; l < row.cells.count; l++) { bool isNestedRowBreak = false; - if (row.height == row.cells[l].height && - row.cells[l].value is PdfGrid) { + if (row.height == row.cells[l].height && row.cells[l].value is PdfGrid) { final PdfGrid grid = row.cells[l].value as PdfGrid; for (int m = grid.rows.count; 0 < m; m--) { - if (PdfGridRowHelper.getHelper(grid.rows[m - 1]) - .rowBreakHeight > - 0) { + if (PdfGridRowHelper.getHelper(grid.rows[m - 1]).rowBreakHeight > 0) { isNestedRowBreak = true; break; } - if (PdfGridRowHelper.getHelper(grid.rows[m - 1]) - .isRowBreaksNextPage) { + if (PdfGridRowHelper.getHelper(grid.rows[m - 1]).isRowBreaksNextPage) { PdfGridRowHelper.getHelper(row).rowBreakHeight = - PdfGridRowHelper.getHelper(grid.rows[m - 1]) - .rowBreakHeight; + PdfGridRowHelper.getHelper(grid.rows[m - 1]).rowBreakHeight; break; } PdfGridRowHelper.getHelper(row).rowBreakHeight = - PdfGridRowHelper.getHelper(row).rowBreakHeight + - grid.rows[m - 1].height; + PdfGridRowHelper.getHelper(row).rowBreakHeight + grid.rows[m - 1].height; } } if (isNestedRowBreak) { @@ -359,35 +316,20 @@ class PdfGridLayouter extends ElementLayouter { row.cells[j].value = ''; PdfRectangle rect; PdfPage page = getNextPage(_currentPage!)!; - final PdfSection section = - PdfPageHelper.getHelper(_currentPage!).section!; - final int index = - PdfSectionHelper.getHelper(section).indexOf(page); + final PdfSection section = PdfPageHelper.getHelper(_currentPage!).section!; + final int index = PdfSectionHelper.getHelper(section).indexOf(page); for (int k = 0; - k < - (PdfSectionHelper.getHelper(section) - .pageReferences! - .count - - 1) - - index; + k < (PdfSectionHelper.getHelper(section).pageReferences!.count - 1) - index; k++) { - rect = PdfRectangle( - x, - 0, - PdfGridRowHelper.getHelper(row).grid.columns[j].width, + rect = PdfRectangle(x, 0, PdfGridRowHelper.getHelper(row).grid.columns[j].width, page.getClientSize().height); repeatRowIndex = -1; - PdfGridCellHelper.getHelper(row.cells[j]) - .draw(page.graphics, rect, false); + PdfGridCellHelper.getHelper(row.cells[j]).draw(page.graphics, rect, false); page = getNextPage(page)!; } - rect = PdfRectangle( - x, - 0, - PdfGridRowHelper.getHelper(row).grid.columns[j].width, + rect = PdfRectangle(x, 0, PdfGridRowHelper.getHelper(row).grid.columns[j].width, PdfGridRowHelper.getHelper(row).rowBreakHeight); - PdfGridCellHelper.getHelper(row.cells[j]) - .draw(page.graphics, rect, false); + PdfGridCellHelper.getHelper(row.cells[j]).draw(page.graphics, rect, false); } x += PdfGridRowHelper.getHelper(row).grid.columns[j].width; } @@ -402,21 +344,14 @@ class PdfGridLayouter extends ElementLayouter { while (!rowResult.isFinish && startPage != null) { final PdfLayoutResult tempResult = _getLayoutResult(); if (startPage != _currentPage) { - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell != - null) { - final PdfRectangle bounds = PdfRectangle( - format.paginateBounds.left, - format.paginateBounds.top, - param.bounds!.width, - tempResult.bounds.height); + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell != null) { + final PdfRectangle bounds = PdfRectangle(format.paginateBounds.left, + format.paginateBounds.top, param.bounds!.width, tempResult.bounds.height); bounds.x = bounds.x + param.bounds!.x; bounds.y = bounds.y + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) .parentCell!) .row!) .grid @@ -427,8 +362,7 @@ class PdfGridLayouter extends ElementLayouter { bounds.height = _currentPageBounds.height - bounds.y; bounds.height = bounds.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) .parentCell!) .row!) .grid @@ -441,18 +375,14 @@ class PdfGridLayouter extends ElementLayouter { double cellWidth = 0.0; if (cell.columnSpan > 1) { for (; c < cell.columnSpan; c++) { - cellWidth += - PdfGridRowHelper.getHelper(row).grid.columns[c].width; + cellWidth += PdfGridRowHelper.getHelper(row).grid.columns[c].width; } } else { - cellWidth = max(cell.width, - PdfGridRowHelper.getHelper(row).grid.columns[c].width); + cellWidth = + max(cell.width, PdfGridRowHelper.getHelper(row).grid.columns[c].width); } - _currentGraphics = PdfGridCellHelper.getHelper(cell) - .drawCellBorders( - _currentGraphics!, - PdfRectangle( - bounds.x, bounds.y, cellWidth, bounds.height)); + _currentGraphics = PdfGridCellHelper.getHelper(cell).drawCellBorders( + _currentGraphics!, PdfRectangle(bounds.x, bounds.y, cellWidth, bounds.height)); bounds.x = bounds.x + cellWidth; c += cell.columnSpan - 1; } @@ -470,19 +400,15 @@ class PdfGridLayouter extends ElementLayouter { final PdfPoint location = PdfPoint( PdfGridHelper.getHelper(_grid!).defaultBorder.right.width / 2, PdfGridHelper.getHelper(_grid!).defaultBorder.top.width / 2); - if (PdfRectangle.fromRect(format.paginateBounds) == - PdfRectangle.empty && + if (PdfRectangle.fromRect(format.paginateBounds) == PdfRectangle.empty && _startLocation == location) { _currentBounds.x = _currentBounds.x + _startLocation.x; _currentBounds.y = _currentBounds.y + _startLocation.y; } if (PdfGridHelper.getHelper(_grid!).isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell != - null) { + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell != null) { if (PdfGridStyleHelper.getPadding(PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) .row!) .grid .style) != @@ -497,8 +423,7 @@ class PdfGridLayouter extends ElementLayouter { .top < _currentBounds.height) { _currentBounds.y = PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) .row!) .grid .style @@ -507,45 +432,37 @@ class PdfGridLayouter extends ElementLayouter { } } } - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell != - null) { + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell != null) { PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row).grid) - .parentCell!) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell!) .row!) .isRowBreaksNextPage = true; PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell!) - .row!) - .rowBreakHeight = - PdfGridRowHelper.getHelper(row).rowBreakHeight + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell!) + .row!) + .rowBreakHeight = PdfGridRowHelper.getHelper(row) + .rowBreakHeight + + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) .row!) - .grid - .style - .cellPadding - .top + - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).row!) - .grid - .style - .cellPadding - .bottom; + .grid + .style + .cellPadding + .top + + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) + .grid + .style + .cellPadding + .bottom; } if (PdfGridRowHelper.getHelper(row).noOfPageCount > 1) { - final double temp = - PdfGridRowHelper.getHelper(row).rowBreakHeight; - for (int j = 1; - j < PdfGridRowHelper.getHelper(row).noOfPageCount; - j++) { + final double temp = PdfGridRowHelper.getHelper(row).rowBreakHeight; + for (int j = 1; j < PdfGridRowHelper.getHelper(row).noOfPageCount; j++) { PdfGridRowHelper.getHelper(row).rowBreakHeight = 0; - row.height = - (PdfGridRowHelper.getHelper(row).noOfPageCount - 1) * - _currentPage!.getClientSize().height; + row.height = (PdfGridRowHelper.getHelper(row).noOfPageCount - 1) * + _currentPage!.getClientSize().height; _drawRow(row); _currentPage = _getNextPage(format); startPage = _currentPage; @@ -578,8 +495,7 @@ class PdfGridLayouter extends ElementLayouter { } } if (isWidthGreaterthanParent && - PdfGridCellHelper.getHelper(_grid! - .rows[j].cells[_rowBreakPageHeightCellIndex]) + PdfGridCellHelper.getHelper(_grid!.rows[j].cells[_rowBreakPageHeightCellIndex]) .pageCount > 0) { isAddNextPage = true; @@ -587,8 +503,7 @@ class PdfGridLayouter extends ElementLayouter { } } if (!PdfGridHelper.getHelper(_grid!).isRearranged && isAddNextPage) { - final PdfSection section = - PdfPageHelper.getHelper(_currentPage!).section!; + final PdfSection section = PdfPageHelper.getHelper(_currentPage!).section!; final PdfPage page = PdfPage(); PdfSectionHelper.getHelper(section).isNewPageSection = true; PdfSectionHelper.getHelper(section).add(page); @@ -596,20 +511,13 @@ class PdfGridLayouter extends ElementLayouter { PdfSectionHelper.getHelper(section).isNewPageSection = false; _currentGraphics = _currentPage!.graphics; final Size clientSize = _currentPage!.getClientSize(); - _currentBounds = - PdfRectangle(0, 0, clientSize.width, clientSize.height); + _currentBounds = PdfRectangle(0, 0, clientSize.width, clientSize.height); final int pageindex = PdfSectionHelper.getHelper( - PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!) - .page!) + PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) .section!) .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!); - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(pageindex)) { - PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .add(pageindex); + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(pageindex)) { + PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(pageindex); } } else { if (endArgs.nextPage == null) { @@ -618,24 +526,18 @@ class PdfGridLayouter extends ElementLayouter { _currentPage = endArgs.nextPage; _currentGraphics = endArgs.nextPage!.graphics; _currentBounds = PdfRectangle( - 0, - 0, - _currentGraphics!.clientSize.width, - _currentGraphics!.clientSize.height); + 0, 0, _currentGraphics!.clientSize.width, _currentGraphics!.clientSize.height); } } - final bool isSameSection = - PdfPageHelper.getHelper(_currentPage!).section == - PdfPageHelper.getHelper(param.page!).section; + final bool isSameSection = PdfPageHelper.getHelper(_currentPage!).section == + PdfPageHelper.getHelper(param.page!).section; _currentBounds.y = format.paginateBounds.top == 0 ? PdfGridHelper.getHelper(_grid!).defaultBorder.top.width / 2 : format.paginateBounds.top; if (_currentPage != null) { final Map pageLayoutResult = - _raiseBeforePageLayout( - _currentPage, _currentBounds.rect, _currentRowIndex); - _currentBounds = - PdfRectangle.fromRect(pageLayoutResult['currentBounds']); + _raiseBeforePageLayout(_currentPage, _currentBounds.rect, _currentRowIndex); + _currentBounds = PdfRectangle.fromRect(pageLayoutResult['currentBounds']); _currentRowIndex = pageLayoutResult['currentRow'] as int; if (pageLayoutResult['cancel'] as bool) { break; @@ -650,68 +552,52 @@ class PdfGridLayouter extends ElementLayouter { _currentBounds.height = param.bounds!.height; } _startLocation.y = _currentBounds.y; - if (PdfRectangle.fromRect(format.paginateBounds) == - PdfRectangle.empty) { + if (PdfRectangle.fromRect(format.paginateBounds) == PdfRectangle.empty) { _currentBounds.x = _currentBounds.x + _startLocation.x; } - if (_currentBounds.x == - PdfGridHelper.getHelper(_grid!).defaultBorder.left.width / 2) { + if (_currentBounds.x == PdfGridHelper.getHelper(_grid!).defaultBorder.left.width / 2) { _currentBounds.y = _currentBounds.y + _startLocation.x; } if (_grid!.repeatHeader) { - for (int headerIndex = 0; - headerIndex < _grid!.headers.count; - headerIndex++) { + for (int headerIndex = 0; headerIndex < _grid!.headers.count; headerIndex++) { _drawRow(_grid!.headers[headerIndex]); } } _drawRow(row); - if (_currentPage != null && - !layoutedPages.containsKey(_currentPage)) { + if (_currentPage != null && !layoutedPages.containsKey(_currentPage)) { layoutedPages[_currentPage] = range; } } if (PdfGridRowHelper.getHelper(row).gridResult != null) { _currentPage = PdfGridRowHelper.getHelper(row).gridResult!.page; _currentGraphics = _currentPage!.graphics; - _startLocation = PdfPoint( - PdfGridRowHelper.getHelper(row).gridResult!.bounds.left, + _startLocation = PdfPoint(PdfGridRowHelper.getHelper(row).gridResult!.bounds.left, PdfGridRowHelper.getHelper(row).gridResult!.bounds.top); - _currentBounds.y = - PdfGridRowHelper.getHelper(row).gridResult!.bounds.bottom; + _currentBounds.y = PdfGridRowHelper.getHelper(row).gridResult!.bounds.bottom; if (startPage != _currentPage) { - final PdfSection secion = - PdfPageHelper.getHelper(_currentPage!).section!; - final int startIndex = - PdfSectionHelper.getHelper(secion).indexOf(startPage!) + 1; - final int endIndex = - PdfSectionHelper.getHelper(secion).indexOf(_currentPage!); + final PdfSection secion = PdfPageHelper.getHelper(_currentPage!).section!; + final int startIndex = PdfSectionHelper.getHelper(secion).indexOf(startPage!) + 1; + final int endIndex = PdfSectionHelper.getHelper(secion).indexOf(_currentPage!); for (int page = startIndex; page < endIndex + 1; page++) { - PdfGraphics pageGraphics = PdfSectionHelper.getHelper(secion) - .getPageByIndex(page)! - .graphics; - final PdfPoint location = PdfPoint( - format.paginateBounds.left, format.paginateBounds.top); + PdfGraphics pageGraphics = + PdfSectionHelper.getHelper(secion).getPageByIndex(page)!.graphics; + final PdfPoint location = + PdfPoint(format.paginateBounds.left, format.paginateBounds.top); if (location == PdfPoint.empty && _currentBounds.x > location.x && - !PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell == + !PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell == null) { location.x = _currentBounds.x; } double height = page == endIndex - ? (PdfGridRowHelper.getHelper(row).gridResult!.bounds.height - - param.bounds!.y) + ? (PdfGridRowHelper.getHelper(row).gridResult!.bounds.height - param.bounds!.y) : (_currentBounds.height - location.y); if (height <= pageGraphics.clientSize.height) { height += param.bounds!.y; } - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .parentCell != + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).parentCell != null) { location.x = location.x + param.bounds!.x; } @@ -721,25 +607,15 @@ class PdfGridLayouter extends ElementLayouter { double cellWidth = 0.0; if (cell.columnSpan > 1) { for (; c < cell.columnSpan; c++) { - cellWidth += - PdfGridRowHelper.getHelper(row).grid.columns[c].width; + cellWidth += PdfGridRowHelper.getHelper(row).grid.columns[c].width; } } else { cellWidth = PdfGridHelper.getHelper(_grid!).isWidthSet - ? min(cell.width, - PdfGridRowHelper.getHelper(row).grid.columns[c].width) - : max( - cell.width, - PdfGridRowHelper.getHelper(row) - .grid - .columns[c] - .width); + ? min(cell.width, PdfGridRowHelper.getHelper(row).grid.columns[c].width) + : max(cell.width, PdfGridRowHelper.getHelper(row).grid.columns[c].width); } - pageGraphics = PdfGridCellHelper.getHelper(cell) - .drawCellBorders( - pageGraphics, - PdfRectangle( - location.x, location.y, cellWidth, height)); + pageGraphics = PdfGridCellHelper.getHelper(cell).drawCellBorders( + pageGraphics, PdfRectangle(location.x, location.y, cellWidth, height)); location.x = location.x + cellWidth; c += cell.columnSpan - 1; } @@ -756,19 +632,14 @@ class PdfGridLayouter extends ElementLayouter { final List> largeNavigatePage = List>.filled(1, List.filled(2, 0)); for (int c = 0; c < _grid!.rows.count; c++) { - if (_cellEndIndex != -1 && - _grid!.rows[c].cells[_cellEndIndex].value is PdfGrid) { - final PdfGrid grid = - _grid!.rows[c].cells[_cellEndIndex].value as PdfGrid; + if (_cellEndIndex != -1 && _grid!.rows[c].cells[_cellEndIndex].value is PdfGrid) { + final PdfGrid grid = _grid!.rows[c].cells[_cellEndIndex].value as PdfGrid; PdfGridHelper.getHelper(_grid!).rowLayoutBoundswidth = PdfGridHelper.getHelper(grid).rowLayoutBoundswidth; isPdfGrid = true; - if (largeNavigatePage[0][0]! < - PdfGridHelper.getHelper(grid).listOfNavigatePages.length) { - largeNavigatePage[0][0] = PdfGridHelper.getHelper(grid) - .listOfNavigatePages - .length - .toDouble(); + if (largeNavigatePage[0][0]! < PdfGridHelper.getHelper(grid).listOfNavigatePages.length) { + largeNavigatePage[0][0] = + PdfGridHelper.getHelper(grid).listOfNavigatePages.length.toDouble(); largeNavigatePage[0][1] = cellBounds[c]; } else if ((largeNavigatePage[0][0] == PdfGridHelper.getHelper(grid).listOfNavigatePages.length) && @@ -783,21 +654,17 @@ class PdfGridLayouter extends ElementLayouter { maximumCellBoundsWidth = cellBounds[c]!; } } - PdfGridHelper.getHelper(_grid!).rowLayoutBoundswidth = - maximumCellBoundsWidth; + PdfGridHelper.getHelper(_grid!).rowLayoutBoundswidth = maximumCellBoundsWidth; } else { - PdfGridHelper.getHelper(_grid!).rowLayoutBoundswidth = - largeNavigatePage[0][1]!; + PdfGridHelper.getHelper(_grid!).rowLayoutBoundswidth = largeNavigatePage[0][1]!; } if (_columnRanges!.indexOf(range) < _columnRanges!.length - 1 && startPage != null && format.layoutType != PdfLayoutType.onePage) { isParentCell = PdfGridHelper.getHelper(_grid!).isChildGrid; if (largeNavigatePage[0][0]!.toInt() != 0) { - final PdfSection section = - PdfPageHelper.getHelper(_currentPage!).section!; - final int pageIndex = - PdfSectionHelper.getHelper(section).indexOf(_currentPage!); + final PdfSection section = PdfPageHelper.getHelper(_currentPage!).section!; + final int pageIndex = PdfSectionHelper.getHelper(section).indexOf(_currentPage!); if (PdfSectionHelper.getHelper(section).count > pageIndex + largeNavigatePage[0][0]!.toInt()) { _currentPage = PdfSectionHelper.getHelper(section) @@ -810,18 +677,12 @@ class PdfGridLayouter extends ElementLayouter { } _currentGraphics = _currentPage!.graphics; _currentBounds = PdfRectangle( - 0, - 0, - _currentGraphics!.clientSize.width, - _currentGraphics!.clientSize.height); + 0, 0, _currentGraphics!.clientSize.width, _currentGraphics!.clientSize.height); final int pageindex = PdfSectionHelper.getHelper( - PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) .section!) .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!); - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(pageindex)) { + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(pageindex)) { PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(pageindex); } } else { @@ -830,8 +691,7 @@ class PdfGridLayouter extends ElementLayouter { final PdfPoint location = PdfPoint( PdfGridHelper.getHelper(_grid!).defaultBorder.right.width / 2, PdfGridHelper.getHelper(_grid!).defaultBorder.top.width / 2); - if (PdfRectangle.fromRect(format.paginateBounds) == - PdfRectangle.empty && + if (PdfRectangle.fromRect(format.paginateBounds) == PdfRectangle.empty && _startLocation == location) { _currentBounds.x = _currentBounds.x + _startLocation.x; _currentBounds.y = _currentBounds.y + _startLocation.y; @@ -841,8 +701,7 @@ class PdfGridLayouter extends ElementLayouter { if (_currentPage != null) { result = _getLayoutResult(); if (_grid!.style.allowHorizontalOverflow && - _grid!.style.horizontalOverflowType == - PdfHorizontalOverflowType.nextPage) { + _grid!.style.horizontalOverflowType == PdfHorizontalOverflowType.nextPage) { _reArrangeLayoutedPages(layoutedPages); } _raisePageLayouted(result); @@ -867,27 +726,23 @@ class PdfGridLayouter extends ElementLayouter { } final double height = row.height > cell.height ? row.height : cell.height; if (_isChildGrid!) { - PdfGridCellHelper.getHelper(cell).draw(_currentGraphics, - PdfRectangle(location.x, location.y, width, height), false); + PdfGridCellHelper.getHelper(cell) + .draw(_currentGraphics, PdfRectangle(location.x, location.y, width, height), false); } _currentBounds.y = _currentBounds.y + height; } for (int j = 0; j < grid.rows.count; j++) { - if (PdfGridCellHelper.getHelper(grid.rows[j].cells[_cellStartIndex]) - .present) { + if (PdfGridCellHelper.getHelper(grid.rows[j].cells[_cellStartIndex]).present) { present = true; if (grid.rows[j].cells[_cellStartIndex].value is PdfGrid) { - final PdfGrid? childGrid = - grid.rows[j].cells[_cellStartIndex].value as PdfGrid?; - PdfGridCellHelper.getHelper(grid.rows[j].cells[_cellStartIndex]) - .present = false; + final PdfGrid? childGrid = grid.rows[j].cells[_cellStartIndex].value as PdfGrid?; + PdfGridCellHelper.getHelper(grid.rows[j].cells[_cellStartIndex]).present = false; if (childGrid == _grid) { if (!_isChildGrid!) { _currentBounds.y = y!; } else { if (j == 0) { - _currentBounds.y = _currentBounds.y - - PdfGridHelper.getHelper(grid).size.height; + _currentBounds.y = _currentBounds.y - PdfGridHelper.getHelper(grid).size.height; } else { int k = j; while (k < grid.rows.count) { @@ -898,32 +753,26 @@ class PdfGridLayouter extends ElementLayouter { } PdfGridHelper.getHelper(childGrid!).isDrawn = true; grid.rows[j].cells[_cellStartIndex].value = childGrid; - _currentBounds.x = _currentBounds.x + - grid.style.cellPadding.left + - grid.style.cellPadding.right; - _currentBounds.y = _currentBounds.y + - grid.style.cellPadding.top + - grid.style.cellPadding.bottom; + _currentBounds.x = + _currentBounds.x + grid.style.cellPadding.left + grid.style.cellPadding.right; + _currentBounds.y = + _currentBounds.y + grid.style.cellPadding.top + grid.style.cellPadding.bottom; _currentBounds.width = _currentBounds.width - 2 * _currentBounds.x; break; } else { _isChildGrid = true; if (_parentCellIndexList.isNotEmpty) { - _cellStartIndex = - _parentCellIndexList[_parentCellIndexList.length - 1]; + _cellStartIndex = _parentCellIndexList[_parentCellIndexList.length - 1]; _parentCellIndexList.removeAt(_parentCellIndexList.length - 1); } _currentBounds.y = y!; - _currentBounds.x = _currentBounds.x + - grid.style.cellPadding.left + - grid.style.cellPadding.right; - _currentBounds.y = _currentBounds.y + - grid.style.cellPadding.top + - grid.style.cellPadding.bottom; + _currentBounds.x = + _currentBounds.x + grid.style.cellPadding.left + grid.style.cellPadding.right; + _currentBounds.y = + _currentBounds.y + grid.style.cellPadding.top + grid.style.cellPadding.bottom; final bool isPresent = _drawParentGridRow(childGrid!); if (!isPresent) { - _currentBounds.y = _currentBounds.y - - PdfGridHelper.getHelper(childGrid).size.height; + _currentBounds.y = _currentBounds.y - PdfGridHelper.getHelper(childGrid).size.height; } _isChildGrid = false; break; @@ -938,8 +787,7 @@ class PdfGridLayouter extends ElementLayouter { return present; } - _RowLayoutResult? _drawRow(PdfGridRow? row, - [_RowLayoutResult? result, double? height]) { + _RowLayoutResult? _drawRow(PdfGridRow? row, [_RowLayoutResult? result, double? height]) { if (result == null && height == null) { _RowLayoutResult result = _RowLayoutResult(); double rowHeightWithSpan = 0; @@ -948,15 +796,13 @@ class PdfGridLayouter extends ElementLayouter { int currRowIndex = PdfGridRowCollectionHelper.indexOf(_grid!.rows, row); int maxSpan = PdfGridRowHelper.getHelper(row).maximumRowSpan; if (currRowIndex == -1) { - currRowIndex = PdfGridHeaderCollectionHelper.getHelper(_grid!.headers) - .indexOf(row); + currRowIndex = PdfGridHeaderCollectionHelper.getHelper(_grid!.headers).indexOf(row); if (currRowIndex != -1) { isHeader = true; } } for (int i = currRowIndex; i < currRowIndex + maxSpan; i++) { - rowHeightWithSpan += - isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; + rowHeightWithSpan += isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; } if ((rowHeightWithSpan > _currentBounds.height || rowHeightWithSpan + _currentBounds.y > _currentBounds.height) && @@ -967,32 +813,23 @@ class PdfGridLayouter extends ElementLayouter { final PdfGridCell cell = row.cells[cellIndex]; maxSpan = cell.rowSpan; for (int i = currRowIndex; i < currRowIndex + maxSpan; i++) { - rowHeightWithSpan += - isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; - if ((_currentBounds.y + rowHeightWithSpan) > - _currentPageBounds.height) { - rowHeightWithSpan -= - isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; - for (int j = 0; - j < _grid!.rows[currRowIndex].cells.count; - j++) { + rowHeightWithSpan += isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; + if ((_currentBounds.y + rowHeightWithSpan) > _currentPageBounds.height) { + rowHeightWithSpan -= isHeader ? _grid!.headers[i].height : _grid!.rows[i].height; + for (int j = 0; j < _grid!.rows[currRowIndex].cells.count; j++) { final int newSpan = i - currRowIndex; - if (!isHeader && - (_grid!.rows[currRowIndex].cells[j].rowSpan == maxSpan)) { - _grid!.rows[currRowIndex].cells[j].rowSpan = + if (!isHeader && (_grid!.rows[currRowIndex].cells[j].rowSpan == maxSpan)) { + _grid!.rows[currRowIndex].cells[j].rowSpan = newSpan == 0 ? 1 : newSpan; + PdfGridRowHelper.getHelper(_grid!.rows[currRowIndex]).maximumRowSpan = newSpan == 0 ? 1 : newSpan; - PdfGridRowHelper.getHelper(_grid!.rows[currRowIndex]) - .maximumRowSpan = newSpan == 0 ? 1 : newSpan; _grid!.rows[i].cells[j].rowSpan = maxSpan - newSpan; PdfGrid? pdfGrid; if (_grid!.rows[currRowIndex].cells[j].value is PdfGrid) { - pdfGrid = - _grid!.rows[currRowIndex].cells[j].value as PdfGrid?; + pdfGrid = _grid!.rows[currRowIndex].cells[j].value as PdfGrid?; } _grid!.rows[i].cells[j].stringFormat = _grid!.rows[currRowIndex].cells[j].stringFormat; - _grid!.rows[i].cells[j].style = - _grid!.rows[currRowIndex].cells[j].style; + _grid!.rows[i].cells[j].style = _grid!.rows[currRowIndex].cells[j].style; _grid!.rows[i].cells[j].style.backgroundImage = null; _grid!.rows[i].cells[j].columnSpan = _grid!.rows[currRowIndex].cells[j].columnSpan; @@ -1003,36 +840,27 @@ class PdfGridLayouter extends ElementLayouter { pdfGrid.style.cellPadding.top + pdfGrid.style.cellPadding.bottom >= _currentBounds.height) { - _grid!.rows[i].cells[j].value = - _grid!.rows[currRowIndex].cells[j].value; + _grid!.rows[i].cells[j].value = _grid!.rows[currRowIndex].cells[j].value; } else if (pdfGrid is! PdfGrid) { - _grid!.rows[i].cells[j].value = - _grid!.rows[currRowIndex].cells[j].value; + _grid!.rows[i].cells[j].value = _grid!.rows[currRowIndex].cells[j].value; } if (i > 0) { - PdfGridRowHelper.getHelper(_grid!.rows[i - 1]) - .rowSpanExists = true; + PdfGridRowHelper.getHelper(_grid!.rows[i - 1]).rowSpanExists = true; } - PdfGridCellHelper.getHelper(_grid!.rows[i].cells[j]) - .isRowMergeContinue = false; + PdfGridCellHelper.getHelper(_grid!.rows[i].cells[j]).isRowMergeContinue = false; } else if (isHeader && - (_grid!.headers[currRowIndex].cells[j].rowSpan == - maxSpan)) { - _grid!.headers[currRowIndex].cells[j].rowSpan = - newSpan == 0 ? 1 : newSpan; + (_grid!.headers[currRowIndex].cells[j].rowSpan == maxSpan)) { + _grid!.headers[currRowIndex].cells[j].rowSpan = newSpan == 0 ? 1 : newSpan; _grid!.headers[i].cells[j].rowSpan = maxSpan - newSpan; _grid!.headers[i].cells[j].stringFormat = _grid!.headers[currRowIndex].cells[j].stringFormat; - _grid!.headers[i].cells[j].style = - _grid!.headers[currRowIndex].cells[j].style; + _grid!.headers[i].cells[j].style = _grid!.headers[currRowIndex].cells[j].style; _grid!.headers[i].cells[j].columnSpan = _grid!.headers[currRowIndex].cells[j].columnSpan; - _grid!.headers[i].cells[j].value = - _grid!.headers[currRowIndex].cells[j].value; - PdfGridRowHelper.getHelper(_grid!.headers[i - 1]) - .rowSpanExists = false; - PdfGridCellHelper.getHelper(_grid!.headers[i].cells[j]) - .isRowMergeContinue = false; + _grid!.headers[i].cells[j].value = _grid!.headers[currRowIndex].cells[j].value; + PdfGridRowHelper.getHelper(_grid!.headers[i - 1]).rowSpanExists = false; + PdfGridCellHelper.getHelper(_grid!.headers[i].cells[j]).isRowMergeContinue = + false; } } break; @@ -1064,9 +892,9 @@ class PdfGridLayouter extends ElementLayouter { if (PdfGridHelper.getHelper(_grid!).isChildGrid! && PdfGridRowHelper.getHelper(row).rowBreakHeight > 0) { _currentBounds.y = _currentBounds.y + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) .grid .style .cellPadding @@ -1077,18 +905,18 @@ class PdfGridLayouter extends ElementLayouter { result = _drawRowWithBreak(row, result, height); } else { _currentBounds.y = _currentBounds.y + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) .grid .style .cellPadding .top; height = _currentBounds.height - _currentBounds.y - - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) .grid .style .cellPadding @@ -1105,7 +933,9 @@ class PdfGridLayouter extends ElementLayouter { height > _currentPageBounds.height || _currentBounds.y + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) .grid .style .cellPadding @@ -1113,25 +943,23 @@ class PdfGridLayouter extends ElementLayouter { height > _currentBounds.height || _currentBounds.y + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).row!) .grid .style .cellPadding .bottom + rowHeightWithSpan > _currentPageBounds.height) { - if (repeatRowIndex > -1 && - repeatRowIndex == PdfGridRowHelper.getHelper(row).index) { + if (repeatRowIndex > -1 && repeatRowIndex == PdfGridRowHelper.getHelper(row).index) { if (_grid!.allowRowBreakingAcrossPages) { result.isFinish = true; if (PdfGridHelper.getHelper(_grid!).isChildGrid! && PdfGridRowHelper.getHelper(row).rowBreakHeight > 0) { _currentBounds.y = _currentBounds.y + - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!) + .row!) .grid .style .cellPadding @@ -1152,9 +980,8 @@ class PdfGridLayouter extends ElementLayouter { result.isFinish = true; if (PdfGridHelper.getHelper(_grid!).isChildGrid! && PdfGridRowHelper.getHelper(row).rowBreakHeight > 0) { - height += PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper(_grid!).parentCell!) - .row!) + height += PdfGridRowHelper.getHelper( + PdfGridCellHelper.getHelper(PdfGridHelper.getHelper(_grid!).parentCell!).row!) .grid .style .cellPadding @@ -1174,8 +1001,7 @@ class PdfGridLayouter extends ElementLayouter { } else if (_currentBounds.y + height > _currentPageBounds.height || _currentBounds.y + height > _currentBounds.height || _currentBounds.y + rowHeightWithSpan > _currentPageBounds.height) { - if (repeatRowIndex > -1 && - repeatRowIndex == PdfGridRowHelper.getHelper(row).index) { + if (repeatRowIndex > -1 && repeatRowIndex == PdfGridRowHelper.getHelper(row).index) { if (_grid!.allowRowBreakingAcrossPages) { result.isFinish = true; result = _drawRowWithBreak(row, result, height); @@ -1195,31 +1021,26 @@ class PdfGridLayouter extends ElementLayouter { } else { bool? skipcell = false; final PdfPoint location = _currentBounds.location; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid! && + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid! && PdfGridRowHelper.getHelper(row).grid.allowRowBreakingAcrossPages && _startLocation.x != _currentBounds.x && - PdfGridRowHelper.getHelper(row).getWidth() < - _currentPage!.getClientSize().width) { + PdfGridRowHelper.getHelper(row).getWidth() < _currentPage!.getClientSize().width) { location.x = _startLocation.x; } result!.bounds = PdfRectangle(location.x, location.y, 0, 0); height = _reCalculateHeight(row, height!); for (int i = _cellStartIndex; i <= _cellEndIndex; i++) { - final bool cancelSpans = - i > _cellEndIndex + 1 && row.cells[i].columnSpan > 1; + final bool cancelSpans = i > _cellEndIndex + 1 && row.cells[i].columnSpan > 1; if (!cancelSpans) { for (int j = 1; j < row.cells[i].columnSpan; j++) { - PdfGridCellHelper.getHelper(row.cells[i + j]).isCellMergeContinue = - true; + PdfGridCellHelper.getHelper(row.cells[i + j]).isCellMergeContinue = true; } } final PdfSize size = PdfSize(_grid!.columns[i].width, height); if (size.width > _currentGraphics!.clientSize.width) { size.width = _currentGraphics!.clientSize.width; } - if (PdfGridHelper.getHelper(_grid!).isChildGrid! && - _grid!.style.allowHorizontalOverflow) { + if (PdfGridHelper.getHelper(_grid!).isChildGrid! && _grid!.style.allowHorizontalOverflow) { if (size.width >= _currentGraphics!.clientSize.width) { size.width = size.width - 2 * _currentBounds.x; } @@ -1232,9 +1053,7 @@ class PdfGridLayouter extends ElementLayouter { PdfGridCellStyle cellstyle = row.cells[i].style; final Map bclResult = _raiseBeforeCellLayout( _currentGraphics, - PdfGridRowHelper.getHelper(row).isHeaderRow - ? _currentHeaderRowIndex - : _currentRowIndex, + PdfGridRowHelper.getHelper(row).isHeaderRow ? _currentHeaderRowIndex : _currentRowIndex, i, PdfRectangle(location.x, location.y, size.width, size.height), (row.cells[i].value is String) ? row.cells[i].value.toString() : '', @@ -1252,39 +1071,30 @@ class PdfGridLayouter extends ElementLayouter { final PdfGrid grid = row.cells[i].value as PdfGrid; PdfGridHelper.getHelper(grid).parentCellIndex = i; } - final PdfStringLayoutResult? stringResult = - PdfGridCellHelper.getHelper(row.cells[i]).draw( - _currentGraphics, - PdfRectangle(location.x, location.y, size.width, size.height), + final PdfStringLayoutResult? stringResult = PdfGridCellHelper.getHelper(row.cells[i]) + .draw(_currentGraphics, PdfRectangle(location.x, location.y, size.width, size.height), cancelSpans); - if (PdfGridRowHelper.getHelper(row) - .grid - .style - .allowHorizontalOverflow && + if (PdfGridRowHelper.getHelper(row).grid.style.allowHorizontalOverflow && (row.cells[i].columnSpan > _cellEndIndex || i + row.cells[i].columnSpan > _cellEndIndex + 1) && _cellEndIndex < row.cells.count - 1) { PdfGridRowHelper.getHelper(row).rowOverflowIndex = _cellEndIndex; } - if (PdfGridRowHelper.getHelper(row) - .grid - .style - .allowHorizontalOverflow && + if (PdfGridRowHelper.getHelper(row).grid.style.allowHorizontalOverflow && (PdfGridRowHelper.getHelper(row).rowOverflowIndex >= 0 && (row.cells[i].columnSpan > _cellEndIndex || i + row.cells[i].columnSpan > _cellEndIndex + 1)) && row.cells[i].columnSpan - _cellEndIndex + i - 1 > 0) { - row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1] - .value = + row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1].value = stringResult != null && stringResult.remainder != null ? stringResult.remainder : ''; - row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1] - .stringFormat = row.cells[i].stringFormat; - row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1] - .style = row.cells[i].style; - row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1] - .columnSpan = row.cells[i].columnSpan - _cellEndIndex + i - 1; + row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1].stringFormat = + row.cells[i].stringFormat; + row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1].style = + row.cells[i].style; + row.cells[PdfGridRowHelper.getHelper(row).rowOverflowIndex + 1].columnSpan = + row.cells[i].columnSpan - _cellEndIndex + i - 1; } } @@ -1294,9 +1104,7 @@ class PdfGridLayouter extends ElementLayouter { _currentRowIndex, i, PdfRectangle(location.x, location.y, size.width, size.height), - (row.cells[i].value is String) - ? row.cells[i].value.toString() - : '', + (row.cells[i].value is String) ? row.cells[i].value.toString() : '', row.cells[i].style, PdfGridRowHelper.getHelper(row).isHeaderRow); } @@ -1306,17 +1114,10 @@ class PdfGridLayouter extends ElementLayouter { PdfGridCellHelper.getHelper(row.cells[i]).pageCount = PdfGridHelper.getHelper(grid).listOfNavigatePages.length; _rowBreakPageHeightCellIndex = i; - for (int k = 0; - k < PdfGridHelper.getHelper(grid).listOfNavigatePages.length; - k++) { - final int pageIndex = - PdfGridHelper.getHelper(grid).listOfNavigatePages[k]; - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(pageIndex)) { - PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .add(pageIndex); + for (int k = 0; k < PdfGridHelper.getHelper(grid).listOfNavigatePages.length; k++) { + final int pageIndex = PdfGridHelper.getHelper(grid).listOfNavigatePages[k]; + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(pageIndex)) { + PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(pageIndex); } } if (_grid!.columns[i].width >= _currentGraphics!.clientSize.width) { @@ -1333,8 +1134,7 @@ class PdfGridLayouter extends ElementLayouter { PdfGridRowHelper.getHelper(row).isRowHeightSet) { _currentBounds.y = _currentBounds.y + height; } - result.bounds = PdfRectangle( - result.bounds.x, result.bounds.y, location.x, location.y); + result.bounds = PdfRectangle(result.bounds.x, result.bounds.y, location.x, location.y); return null; } } @@ -1343,21 +1143,16 @@ class PdfGridLayouter extends ElementLayouter { double newHeight = 0.0; for (int i = _cellStartIndex; i <= _cellEndIndex; i++) { if (PdfGridCellHelper.getHelper(row!.cells[i]).remainingString != null && - PdfGridCellHelper.getHelper(row.cells[i]) - .remainingString! - .isNotEmpty) { - newHeight = max(newHeight, - PdfGridCellHelper.getHelper(row.cells[i]).measureHeight()); + PdfGridCellHelper.getHelper(row.cells[i]).remainingString!.isNotEmpty) { + newHeight = max(newHeight, PdfGridCellHelper.getHelper(row.cells[i]).measureHeight()); } } return max(height, newHeight); } - _RowLayoutResult _drawRowWithBreak( - PdfGridRow row, _RowLayoutResult result, double? height) { + _RowLayoutResult _drawRowWithBreak(PdfGridRow row, _RowLayoutResult result, double? height) { final PdfPoint location = _currentBounds.location; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid! && + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid! && PdfGridRowHelper.getHelper(row).grid.allowRowBreakingAcrossPages && _startLocation.x != _currentBounds.x) { location.x = _startLocation.x; @@ -1384,20 +1179,17 @@ class PdfGridLayouter extends ElementLayouter { if (PdfGridCellHelper.getHelper(cell).measureHeight() == height) { PdfGridRowHelper.getHelper(row).rowBreakHeight = cell.value is PdfGrid ? 0 - : _currentBounds.y + height - _currentBounds.height < - _currentPageBounds.height + : _currentBounds.y + height - _currentBounds.height < _currentPageBounds.height ? _currentBounds.height : _currentPageBounds.height; } } for (int i = _cellStartIndex; i <= _cellEndIndex; i++) { final bool cancelSpans = - row.cells[i].columnSpan + i > _cellEndIndex + 1 && - row.cells[i].columnSpan > 1; + row.cells[i].columnSpan + i > _cellEndIndex + 1 && row.cells[i].columnSpan > 1; if (!cancelSpans) { for (int j = 1; j < row.cells[i].columnSpan; j++) { - PdfGridCellHelper.getHelper(row.cells[i + j]).isCellMergeContinue = - true; + PdfGridCellHelper.getHelper(row.cells[i + j]).isCellMergeContinue = true; } } PdfSize size = PdfSize( @@ -1417,9 +1209,7 @@ class PdfGridLayouter extends ElementLayouter { PdfGridCellStyle cellstyle = row.cells[i].style; final Map cellLayoutResult = _raiseBeforeCellLayout( _currentGraphics, - PdfGridRowHelper.getHelper(row).isHeaderRow - ? _currentHeaderRowIndex - : _currentRowIndex, + PdfGridRowHelper.getHelper(row).isHeaderRow ? _currentHeaderRowIndex : _currentRowIndex, i, PdfRectangle(location.x, location.y, size.width, size.height), row.cells[i].value is String ? row.cells[i].value.toString() : '', @@ -1432,28 +1222,22 @@ class PdfGridLayouter extends ElementLayouter { final bool skipcell = bclArgs != null && bclArgs.skip; PdfStringLayoutResult? stringResult; if (!skipcell) { - stringResult = PdfGridCellHelper.getHelper(row.cells[i]).draw( - _currentGraphics, - PdfRectangle(location.x, location.y, size.width, size.height), - cancelSpans); + stringResult = PdfGridCellHelper.getHelper(row.cells[i]).draw(_currentGraphics, + PdfRectangle(location.x, location.y, size.width, size.height), cancelSpans); } if (PdfGridRowHelper.getHelper(row).rowBreakHeight > 0.0) { if (stringResult != null) { PdfGridCellHelper.getHelper(row.cells[i]).finished = false; - PdfGridCellHelper.getHelper(row.cells[i]).remainingString = - stringResult.remainder ?? ''; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid) - .isChildGrid!) { - PdfGridRowHelper.getHelper(row).rowBreakHeight = - height - stringResult.size.height; + PdfGridCellHelper.getHelper(row.cells[i]).remainingString = stringResult.remainder ?? ''; + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row).grid).isChildGrid!) { + PdfGridRowHelper.getHelper(row).rowBreakHeight = height - stringResult.size.height; } } else if (row.cells[i].value is PdfImage) { PdfGridCellHelper.getHelper(row.cells[i]).finished = false; } } - result.isFinish = (!result.isFinish) - ? result.isFinish - : PdfGridCellHelper.getHelper(row.cells[i]).finished; + result.isFinish = + (!result.isFinish) ? result.isFinish : PdfGridCellHelper.getHelper(row.cells[i]).finished; if (!cancelSpans) { _raiseAfterCellLayout( _currentGraphics, @@ -1469,14 +1253,9 @@ class PdfGridLayouter extends ElementLayouter { _rowBreakPageHeightCellIndex = i; PdfGridCellHelper.getHelper(row.cells[i]).pageCount = PdfGridHelper.getHelper(grid).listOfNavigatePages.length; - for (int i = 0; - i < PdfGridHelper.getHelper(grid).listOfNavigatePages.length; - i++) { - final int pageIndex = - PdfGridHelper.getHelper(grid).listOfNavigatePages[i]; - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(pageIndex)) { + for (int i = 0; i < PdfGridHelper.getHelper(grid).listOfNavigatePages.length; i++) { + final int pageIndex = PdfGridHelper.getHelper(grid).listOfNavigatePages[i]; + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(pageIndex)) { PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(pageIndex); } } @@ -1490,10 +1269,8 @@ class PdfGridLayouter extends ElementLayouter { location.x = location.x + _grid!.columns[i].width; } } - _currentBounds.y = - _currentBounds.y + (_newheight > 0.0 ? _newheight : height); - result.bounds = - PdfRectangle(result.bounds.x, result.bounds.y, location.x, location.y); + _currentBounds.y = _currentBounds.y + (_newheight > 0.0 ? _newheight : height); + result.bounds = PdfRectangle(result.bounds.x, result.bounds.y, location.x, location.y); return result; } @@ -1519,8 +1296,7 @@ class PdfGridLayouter extends ElementLayouter { } void _reArrangeLayoutedPages(Map> layoutedPages) { - final PdfDocument? document = - PdfPageHelper.getHelper(_currentPage!).document; + final PdfDocument? document = PdfPageHelper.getHelper(_currentPage!).document; final List pages = layoutedPages.keys.toList(); for (int i = 0; i < pages.length; i++) { final PdfPage page = pages[i]!; @@ -1586,8 +1362,7 @@ class PdfGridLayouter extends ElementLayouter { PdfPage? _getNextPage(PdfLayoutFormat format) { final PdfSection section = PdfPageHelper.getHelper(_currentPage!).section!; PdfPage? nextPage; - final int index = - PdfSectionHelper.getHelper(section).indexOf(_currentPage!); + final int index = PdfSectionHelper.getHelper(section).indexOf(_currentPage!); if (PdfPageHelper.getHelper(_currentPage!).document!.pages.count > 1 && _hType == PdfHorizontalOverflowType.nextPage && flag && @@ -1605,17 +1380,14 @@ class PdfGridLayouter extends ElementLayouter { nextPage = PdfSectionHelper.getHelper(section).getPageByIndex(index + 1); } _currentGraphics = nextPage!.graphics; - final int pageindex = PdfSectionHelper.getHelper(PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) - .section!) + final int pageindex = PdfSectionHelper.getHelper( + PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!).section!) .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!); - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(pageindex)) { + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(pageindex)) { PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(pageindex); } - _currentBounds = PdfRectangle(0, 0, _currentGraphics!.clientSize.width, - _currentGraphics!.clientSize.height); + _currentBounds = + PdfRectangle(0, 0, _currentGraphics!.clientSize.width, _currentGraphics!.clientSize.height); if (PdfRectangle.fromRect(format.paginateBounds) != PdfRectangle.empty) { _currentBounds.x = format.paginateBounds.left; _currentBounds.y = format.paginateBounds.top; @@ -1625,8 +1397,7 @@ class PdfGridLayouter extends ElementLayouter { } PdfLayoutResult _getLayoutResult() { - if (PdfGridHelper.getHelper(_grid!).isChildGrid! && - _grid!.allowRowBreakingAcrossPages) { + if (PdfGridHelper.getHelper(_grid!).isChildGrid! && _grid!.allowRowBreakingAcrossPages) { for (int rowIndex = 0; rowIndex < _grid!.rows.count; rowIndex++) { final PdfGridRow row = _grid!.rows[rowIndex]; if (PdfGridRowHelper.getHelper(row).rowBreakHeight > 0) { @@ -1635,10 +1406,10 @@ class PdfGridLayouter extends ElementLayouter { } } final Rect bounds = _isChanged - ? Rect.fromLTWH(_currentLocation.x, _currentLocation.y, - _currentBounds.width, _currentBounds.y - _currentLocation.y) - : Rect.fromLTWH(_startLocation.x, _startLocation.y, - _currentBounds.width, _currentBounds.y - _startLocation.y); + ? Rect.fromLTWH(_currentLocation.x, _currentLocation.y, _currentBounds.width, + _currentBounds.y - _currentLocation.y) + : Rect.fromLTWH(_startLocation.x, _startLocation.y, _currentBounds.width, + _currentBounds.y - _startLocation.y); return PdfLayoutResultHelper.load(_currentPage!, bounds); } @@ -1647,18 +1418,13 @@ class PdfGridLayouter extends ElementLayouter { bool cancel = false; if (PdfLayoutElementHelper.getHelper(element!).raiseBeginPageLayout) { final PdfGridBeginPageLayoutArgs args = - PdfGridBeginPageLayoutArgsHelper.load( - currentBounds, currentPage!, currentRow); + PdfGridBeginPageLayoutArgsHelper.load(currentBounds, currentPage!, currentRow); PdfLayoutElementHelper.getHelper(element!).onBeginPageLayout(args); - if (PdfRectangle.fromRect(currentBounds) != - PdfRectangle.fromRect(args.bounds)) { + if (PdfRectangle.fromRect(currentBounds) != PdfRectangle.fromRect(args.bounds)) { _isChanged = true; _currentLocation = PdfPoint(args.bounds.left, args.bounds.top); - PdfGridHelper.getHelper(_grid!).measureColumnsWidth(PdfRectangle( - args.bounds.left, - args.bounds.top, - args.bounds.width + args.bounds.left, - args.bounds.height)); + PdfGridHelper.getHelper(_grid!).measureColumnsWidth(PdfRectangle(args.bounds.left, + args.bounds.top, args.bounds.width + args.bounds.left, args.bounds.height)); } cancel = args.cancel; currentBounds = args.bounds; @@ -1672,22 +1438,15 @@ class PdfGridLayouter extends ElementLayouter { } PdfGridEndPageLayoutArgs _raisePageLayouted(PdfLayoutResult result) { - final PdfGridEndPageLayoutArgs args = - PdfGridEndPageLayoutArgsHelper.load(result); + final PdfGridEndPageLayoutArgs args = PdfGridEndPageLayoutArgsHelper.load(result); if (PdfLayoutElementHelper.getHelper(element!).raisePageLayouted) { PdfLayoutElementHelper.getHelper(element!).onEndPageLayout(args); } return args; } - Map _raiseBeforeCellLayout( - PdfGraphics? graphics, - int rowIndex, - int cellIndex, - PdfRectangle bounds, - String value, - PdfGridCellStyle? style, - bool isHeaderRow) { + Map _raiseBeforeCellLayout(PdfGraphics? graphics, int rowIndex, int cellIndex, + PdfRectangle bounds, String value, PdfGridCellStyle? style, bool isHeaderRow) { PdfGridBeginCellLayoutArgs? args; if (PdfGridHelper.getHelper(_grid!).raiseBeginCellLayout) { args = PdfGridBeginCellLayoutArgsHelper.load( @@ -1698,18 +1457,12 @@ class PdfGridLayouter extends ElementLayouter { return {'args': args, 'style': style}; } - void _raiseAfterCellLayout( - PdfGraphics? graphics, - int rowIndex, - int cellIndex, - PdfRectangle bounds, - String value, - PdfGridCellStyle? cellstyle, - bool isHeaderRow) { + void _raiseAfterCellLayout(PdfGraphics? graphics, int rowIndex, int cellIndex, + PdfRectangle bounds, String value, PdfGridCellStyle? cellstyle, bool isHeaderRow) { PdfGridEndCellLayoutArgs args; if (PdfGridHelper.getHelper(_grid!).raiseEndCellLayout) { - args = PdfGridEndCellLayoutArgsHelper.load(graphics!, rowIndex, cellIndex, - bounds, value, cellstyle, isHeaderRow); + args = PdfGridEndCellLayoutArgsHelper.load( + graphics!, rowIndex, cellIndex, bounds, value, cellstyle, isHeaderRow); PdfGridHelper.getHelper(_grid!).onEndCellLayout(args); } } @@ -1724,8 +1477,7 @@ class PdfGridLayouter extends ElementLayouter { final double pageHeight = size.height; final double pageWidth = size.width; if (pageHeight > pageWidth || - (PdfPageHelper.getHelper(param.page!).orientation == - PdfPageOrientation.landscape && + (PdfPageHelper.getHelper(param.page!).orientation == PdfPageOrientation.landscape && format.breakType == PdfLayoutBreakType.fitPage)) { _currentPageBounds = PdfSize.fromSize(size); } else { @@ -1738,19 +1490,15 @@ class PdfGridLayouter extends ElementLayouter { _currentGraphics = _currentPage!.graphics; } if (PdfGraphicsHelper.getHelper(_currentGraphics!).layer != null) { - final int index = !PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) - .isLoadedPage - ? PdfSectionHelper.getHelper(PdfPageHelper.getHelper( - PdfGraphicsHelper.getHelper(_currentGraphics!).page!) - .section!) - .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) - : PdfGraphicsHelper.getHelper(_currentGraphics!) - .page! - .defaultLayerIndex; - if (!PdfGridHelper.getHelper(_grid!) - .listOfNavigatePages - .contains(index)) { + final int index = + !PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + .isLoadedPage + ? PdfSectionHelper.getHelper( + PdfPageHelper.getHelper(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + .section!) + .indexOf(PdfGraphicsHelper.getHelper(_currentGraphics!).page!) + : PdfGraphicsHelper.getHelper(_currentGraphics!).page!.defaultLayerIndex; + if (!PdfGridHelper.getHelper(_grid!).listOfNavigatePages.contains(index)) { PdfGridHelper.getHelper(_grid!).listOfNavigatePages.add(index); } } @@ -1758,37 +1506,31 @@ class PdfGridLayouter extends ElementLayouter { param.bounds!.x, param.bounds!.y, format.breakType == PdfLayoutBreakType.fitColumnsToPage - ? PdfGridColumnCollectionHelper.getHelper(_grid!.columns) - .columnWidth + ? PdfGridColumnCollectionHelper.getHelper(_grid!.columns).columnWidth : _currentGraphics!.clientSize.width, _currentGraphics!.clientSize.height); if (_grid!.rows.count != 0) { _currentBounds.width = (param.bounds!.width > 0) ? param.bounds!.width - : (_currentBounds.width - - _grid!.rows[0].cells[0].style.borders.left.width / 2); + : (_currentBounds.width - _grid!.rows[0].cells[0].style.borders.left.width / 2); } else if (_grid!.headers.count != 0) { _currentBounds.width = (param.bounds!.width > 0) ? param.bounds!.width - : (_currentBounds.width - - _grid!.headers[0].cells[0].style.borders.left.width / 2); + : (_currentBounds.width - _grid!.headers[0].cells[0].style.borders.left.width / 2); } _startLocation = param.bounds!.location; if (_grid!.style.allowHorizontalOverflow && _currentBounds.width > _currentGraphics!.clientSize.width) { - _currentBounds.width = - _currentGraphics!.clientSize.width - _currentBounds.x; + _currentBounds.width = _currentGraphics!.clientSize.width - _currentBounds.x; } if (PdfGridHelper.getHelper(_grid!).isChildGrid!) { _childHeight = param.bounds!.height; } - if (param.format != null && - PdfLayoutFormatHelper.isBoundsSet(param.format!)) { + if (param.format != null && PdfLayoutFormatHelper.isBoundsSet(param.format!)) { if (param.format!.paginateBounds.height > 0) { _currentBounds.height = param.format!.paginateBounds.height; } - } else if (param.bounds!.height > 0 && - !PdfGridHelper.getHelper(_grid!).isChildGrid!) { + } else if (param.bounds!.height > 0 && !PdfGridHelper.getHelper(_grid!).isChildGrid!) { _currentBounds.height = param.bounds!.height; } if (PdfGridHelper.getHelper(_grid!).isChildGrid!) { @@ -1807,8 +1549,7 @@ class PdfGridLayouter extends ElementLayouter { if (!PdfGridRowHelper.getHelper(_grid!.rows[i]).isRowHeightSet) { PdfGridRowHelper.getHelper(_grid!.rows[i]).isRowHeightSet = true; } else { - PdfGridRowHelper.getHelper(_grid!.rows[i]).isRowSpanRowHeightSet = - true; + PdfGridRowHelper.getHelper(_grid!.rows[i]).isRowSpanRowHeightSet = true; } } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid.dart index 58b00f4af..3761b4435 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid.dart @@ -1,5 +1,5 @@ import 'dart:math'; -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_solid_brush.dart'; @@ -529,10 +529,7 @@ class PdfGrid extends PdfLayoutElement { /// ``` @override PdfLayoutResult? draw( - {Rect? bounds, - PdfLayoutFormat? format, - PdfGraphics? graphics, - PdfPage? page}) { + {Rect? bounds, PdfLayoutFormat? format, PdfGraphics? graphics, PdfPage? page}) { final PdfRectangle rectangle = bounds != null ? PdfRectangle.fromRect(bounds) : PdfRectangle.empty; _helper.initialWidth = rectangle.width == 0 @@ -542,8 +539,7 @@ class PdfGrid extends PdfLayoutElement { : rectangle.width; _helper.isWidthSet = true; if (page != null) { - final PdfLayoutResult? result = - super.draw(page: page, bounds: bounds, format: format); + final PdfLayoutResult? result = super.draw(page: page, bounds: bounds, format: format); _helper.isComplete = true; return result; } else if (graphics != null) { @@ -591,8 +587,7 @@ class PdfGrid extends PdfLayoutElement { /// //Dispose the document. /// document.dispose(); /// ``` - void applyBuiltInStyle(PdfGridBuiltInStyle gridStyle, - {PdfGridBuiltInStyleSettings? settings}) { + void applyBuiltInStyle(PdfGridBuiltInStyle gridStyle, {PdfGridBuiltInStyleSettings? settings}) { _intializeBuiltInStyle(gridStyle, settings: settings); } @@ -619,16 +614,14 @@ class PdfGrid extends PdfLayoutElement { _boldFontCache ??= {}; if (font is PdfStandardFont) { final PdfStandardFont standardFont = font; - return PdfStandardFont(standardFont.fontFamily, font.size, - style: PdfFontStyle.bold); + return PdfStandardFont(standardFont.fontFamily, font.size, style: PdfFontStyle.bold); } else { if (_boldFontCache!.containsKey(font)) { return _boldFontCache![font as PdfTrueTypeFont]; } else { final PdfTrueTypeFont trueTypeFont = font as PdfTrueTypeFont; final PdfFont boldStyleFont = PdfTrueTypeFont( - PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, - font.size, + PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, font.size, style: PdfFontStyle.bold); _boldFontCache![font] = boldStyleFont as PdfTrueTypeFont; return boldStyleFont; @@ -640,16 +633,14 @@ class PdfGrid extends PdfLayoutElement { _regularFontCache ??= {}; if (font is PdfStandardFont) { final PdfStandardFont standardFont = font; - return PdfStandardFont(standardFont.fontFamily, font.size, - style: PdfFontStyle.regular); + return PdfStandardFont(standardFont.fontFamily, font.size, style: PdfFontStyle.regular); } else { if (_regularFontCache!.containsKey(font)) { return _regularFontCache![font as PdfTrueTypeFont]; } else { final PdfTrueTypeFont trueTypeFont = font as PdfTrueTypeFont; final PdfFont ttfFont = PdfTrueTypeFont( - PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, - font.size, + PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, font.size, style: PdfFontStyle.regular); _regularFontCache![font] = ttfFont as PdfTrueTypeFont; return ttfFont; @@ -661,19 +652,16 @@ class PdfGrid extends PdfLayoutElement { _italicFontCache ??= {}; if (font is PdfStandardFont) { final PdfStandardFont standardFont = font; - return PdfStandardFont(standardFont.fontFamily, font.size, - style: PdfFontStyle.italic); + return PdfStandardFont(standardFont.fontFamily, font.size, style: PdfFontStyle.italic); } else { if (_italicFontCache!.containsKey(font)) { return _italicFontCache![font! as PdfTrueTypeFont]; } else { final PdfTrueTypeFont trueTypeFont = font! as PdfTrueTypeFont; final PdfFont italicStyleFont = PdfTrueTypeFont( - PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, - font.size, + PdfTrueTypeFontHelper.getHelper(trueTypeFont).fontInternal.fontData, font.size, style: PdfFontStyle.italic); - _italicFontCache![font as PdfTrueTypeFont] = - italicStyleFont as PdfTrueTypeFont; + _italicFontCache![font as PdfTrueTypeFont] = italicStyleFont as PdfTrueTypeFont; return italicStyleFont; } } @@ -689,8 +677,7 @@ class PdfGrid extends PdfLayoutElement { return pdfFont; } - PdfBrush? _applyBandedColStyle( - bool firstColumn, PdfColor backColor, int cellIndex) { + PdfBrush? _applyBandedColStyle(bool firstColumn, PdfColor backColor, int cellIndex) { PdfBrush? backBrush; if (firstColumn) { if (cellIndex.isEven) { @@ -704,8 +691,7 @@ class PdfGrid extends PdfLayoutElement { return backBrush; } - PdfBrush? _applyBandedRowStyle( - bool headerRow, PdfColor backColor, int rowIndex) { + PdfBrush? _applyBandedRowStyle(bool headerRow, PdfColor backColor, int rowIndex) { PdfBrush? backBrush; if (headerRow) { if (rowIndex.isOdd) { @@ -757,8 +743,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.font = _changeFontStyle(font); cell.style.borders.all = borderPen; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_lastColumn && j == row.cells.count) { cell.style.backgroundBrush = null; @@ -810,26 +795,21 @@ class PdfGrid extends PdfLayoutElement { } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_lastColumn && j == row.cells.count) { if (!(_totalRow && i == rows.count)) { cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -848,8 +828,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.top = PdfPen(borderColor); if (_bandedColumn) { if (!(_lastColumn && j == row.cells.count)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } } } @@ -980,8 +959,7 @@ class PdfGrid extends PdfLayoutElement { final PdfGridCell cell = row.cells[j - 1]; cell.style.borders.all = whitePen; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_headerRow) { final PdfFont font = cell.style.font ?? @@ -1054,11 +1032,9 @@ class PdfGrid extends PdfLayoutElement { final PdfGridCell cell = row.cells[j - 1]; cell.style.borders.all = whitePen; if (_bandedRow && _bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; } @@ -1067,8 +1043,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; @@ -1079,8 +1054,7 @@ class PdfGrid extends PdfLayoutElement { } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; } @@ -1104,8 +1078,7 @@ class PdfGrid extends PdfLayoutElement { cell.value = cellvalue.toUpperCase(); } if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; @@ -1141,8 +1114,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } cell.style.borders.all = whitePen; } else if (_bandedColumn) { @@ -1168,8 +1140,7 @@ class PdfGrid extends PdfLayoutElement { final PdfGridCell cell = row.cells[j - 1]; cell.style.borders.all = whitePen; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_headerRow) { final PdfFont font = cell.style.font ?? @@ -1182,8 +1153,7 @@ class PdfGrid extends PdfLayoutElement { cell.value = cellvalue.toUpperCase(); } if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_lastColumn && j == row.cells.count) { cell.style.backgroundBrush = null; @@ -1247,26 +1217,21 @@ class PdfGrid extends PdfLayoutElement { } } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_lastColumn && j == row.cells.count) { if (!(_totalRow && i == rows.count)) { cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -1297,8 +1262,7 @@ class PdfGrid extends PdfLayoutElement { } if (_bandedColumn) { if (!(_lastColumn && j == row.cells.count)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } } } @@ -1331,8 +1295,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; @@ -1384,10 +1347,8 @@ class PdfGrid extends PdfLayoutElement { final PdfGridCell cell = row.cells[j - 1]; cell.style.borders.all = whitePen; if (_bandedRow && _bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; @@ -1397,8 +1358,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; @@ -1408,8 +1368,7 @@ class PdfGrid extends PdfLayoutElement { } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (_firstColumn && j == 2) { cell.style.borders.left = borderPen; } else { @@ -1563,8 +1522,7 @@ class PdfGrid extends PdfLayoutElement { _helper.defaultFont; cell.style.font = _changeFontStyle(font); cell.style.borders.all = PdfPen(PdfColor.empty); - if (PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(cell).row!) + if (PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(cell).row!) .grid .style .cellSpacing > @@ -1573,8 +1531,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (j == 1) { cell.style.borders.left = backColorPen; @@ -1639,10 +1596,8 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.right = emptyPen; } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); - cell.style.backgroundBrush ??= - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (j == 1) { cell.style.borders.left = backColorPen; @@ -1652,8 +1607,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { if (j == 1) { @@ -1664,8 +1618,7 @@ class PdfGrid extends PdfLayoutElement { } } if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (j == 1) { cell.style.borders.left = backColorPen; @@ -1703,8 +1656,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.font = _changeFontStyle(font); cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush == null) { cell.style.borders.right = emptyPen; } @@ -1742,8 +1694,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = whitePen; } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { if (i % 2 != 0) { @@ -1780,19 +1731,15 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = borderPen; if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_totalRow && i == rows.count) { @@ -1840,8 +1787,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyGridTable4( - PdfColor borderColor, PdfColor backColor, PdfColor headerBackColor) { + void _applyGridTable4(PdfColor borderColor, PdfColor backColor, PdfColor headerBackColor) { final PdfPen borderPen = PdfPen(borderColor, width: 0.5); final PdfBrush backBrush = PdfSolidBrush(backColor); final PdfPen headerBackColorPen = PdfPen(headerBackColor, width: 0.5); @@ -1862,8 +1808,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.backgroundBrush = PdfSolidBrush(headerBackColor); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { if (i % 2 != 0) { @@ -1880,8 +1825,7 @@ class PdfGrid extends PdfLayoutElement { if (_lastColumn && j == row.cells.count) { cell.style.backgroundBrush = null; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -1910,25 +1854,20 @@ class PdfGrid extends PdfLayoutElement { } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_totalRow && i == rows.count) { cell.style.backgroundBrush = null; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } final PdfFont font = cell.style.font ?? @@ -1942,8 +1881,7 @@ class PdfGrid extends PdfLayoutElement { if (!(_totalRow && i == rows.count)) { cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } final PdfFont font = cell.style.font ?? @@ -1965,8 +1903,8 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyGridTable5Dark(PdfColor headerBackColor, PdfColor oddRowBackColor, - PdfColor evenRowBackColor) { + void _applyGridTable5Dark( + PdfColor headerBackColor, PdfColor oddRowBackColor, PdfColor evenRowBackColor) { final PdfPen whitePen = PdfPen(PdfColor(255, 255, 255), width: 0.5); final PdfBrush evenRowBrush = PdfSolidBrush(evenRowBackColor); final PdfBrush oddRowBrush = PdfSolidBrush(oddRowBackColor); @@ -1996,8 +1934,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, oddRowBackColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, oddRowBackColor, j); cell.style.backgroundBrush ??= evenRowBrush; } @@ -2006,8 +1943,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.backgroundBrush = oddRowBrush; } } - if ((_firstColumn && j == 1) || - (_lastColumn && j == row.cells.count)) { + if ((_firstColumn && j == 1) || (_lastColumn && j == row.cells.count)) { cell.style.backgroundBrush = headerBrush; final PdfFont font = cell.style.font ?? row.style.font ?? @@ -2029,24 +1965,20 @@ class PdfGrid extends PdfLayoutElement { cell.style.backgroundBrush = evenRowBrush; if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, oddRowBackColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, oddRowBackColor, j); if (cell.style.backgroundBrush == null) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, oddRowBackColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, oddRowBackColor, i); cell.style.backgroundBrush ??= evenRowBrush; } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, oddRowBackColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, oddRowBackColor, j); cell.style.backgroundBrush ??= evenRowBrush; } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, oddRowBackColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, oddRowBackColor, i); cell.style.backgroundBrush ??= evenRowBrush; } @@ -2082,8 +2014,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyGridTable6Colorful( - PdfColor borderColor, PdfColor backColor, PdfColor textColor) { + void _applyGridTable6Colorful(PdfColor borderColor, PdfColor backColor, PdfColor textColor) { final PdfPen borderPen = PdfPen(borderColor, width: 0.5); final PdfBrush backBrush = PdfSolidBrush(backColor); final PdfPen headerBottomPen = PdfPen(borderColor); @@ -2096,8 +2027,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = borderPen; cell.style.textBrush = textBrush; if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_headerRow) { final PdfFont font = cell.style.font ?? @@ -2145,26 +2075,21 @@ class PdfGrid extends PdfLayoutElement { cell.style.textBrush = textBrush; if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_totalRow && i == rows.count) { cell.style.backgroundBrush = null; if (_bandedColumn && (!(_lastColumn && j == row.cells.count))) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -2186,8 +2111,7 @@ class PdfGrid extends PdfLayoutElement { if (!(_totalRow && i == rows.count)) { cell.style.backgroundBrush = null; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -2204,8 +2128,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyGridTable7Colorful( - PdfColor borderColor, PdfColor backColor, PdfColor textColor) { + void _applyGridTable7Colorful(PdfColor borderColor, PdfColor backColor, PdfColor textColor) { final PdfPen borderPen = PdfPen(borderColor, width: 0.5); final PdfBrush backBrush = PdfSolidBrush(backColor); final PdfBrush textBrush = PdfSolidBrush(textColor); @@ -2227,8 +2150,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = PdfPen(PdfColor(255, 255, 255)); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { @@ -2267,19 +2189,15 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = borderPen; cell.style.textBrush = textBrush; if (_bandedRow && _bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } } if (_totalRow && i == rows.count) { @@ -2353,8 +2271,7 @@ class PdfGrid extends PdfLayoutElement { } if (_bandedColumn) { if (_lastColumn && j == rows.count) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; @@ -2366,8 +2283,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; } @@ -2411,25 +2327,21 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.all = emptyPen; if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; } @@ -2451,8 +2363,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.backgroundBrush = null; cell.style.borders.all = emptyPen; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); } final PdfFont font = cell.style.font ?? row.style.font ?? @@ -2471,8 +2382,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.font = _changeFontStyle(font); if (_bandedColumn) { if (!(_lastColumn && j == row.cells.count)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (cell.style.backgroundBrush != null) { cell.style.borders.all = backBrushPen; @@ -2510,8 +2420,7 @@ class PdfGrid extends PdfLayoutElement { _helper.defaultFont; cell.style.font = _changeFontStyle(font); if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (_lastColumn && j == row.cells.count) { cell.style.backgroundBrush = null; } @@ -2522,8 +2431,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; cell.style.borders.left = backColorPen; @@ -2573,27 +2481,23 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.bottom = borderPen; cell.style.borders.top = borderPen; if (_bandedRow && _bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; cell.style.borders.left = backColorPen; } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; cell.style.borders.left = backColorPen; } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.left = backColorPen; cell.style.borders.right = backColorPen; @@ -2614,8 +2518,7 @@ class PdfGrid extends PdfLayoutElement { if (_bandedColumn) { if (!(j == row.cells.count && _lastColumn)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; @@ -2638,8 +2541,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.left = emptyPen; cell.style.borders.right = emptyPen; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; } @@ -2755,8 +2657,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyListTable4( - PdfColor borderColor, PdfColor headerBackColor, PdfColor bandRowColor) { + void _applyListTable4(PdfColor borderColor, PdfColor headerBackColor, PdfColor bandRowColor) { final PdfPen borderColorPen = PdfPen(borderColor, width: 0.5); final PdfBrush headerBrush = PdfSolidBrush(headerBackColor); final PdfBrush bandRowBrush = PdfSolidBrush(bandRowColor); @@ -2785,8 +2686,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.textBrush = PdfSolidBrush(PdfColor(255, 255, 255)); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, bandRowColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, bandRowColor, j); } if (_bandedRow) { if (i % 2 != 0) { @@ -2829,18 +2729,14 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.right = borderColorPen; } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, bandRowColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, bandRowColor, i); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, bandRowColor, j); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, bandRowColor, i); } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, bandRowColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, bandRowColor, j); } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, bandRowColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, bandRowColor, i); } } if (_totalRow && i == rows.count) { @@ -2853,8 +2749,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.top = PdfPen(borderColor); if (_bandedColumn) { if (!(_lastColumn && j == rows.count)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, bandRowColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, bandRowColor, j); } } } @@ -2870,8 +2765,7 @@ class PdfGrid extends PdfLayoutElement { if (_lastColumn && j == row.cells.count) { if (!(_totalRow && i == rows.count)) { cell.style.backgroundBrush = null; - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, bandRowColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, bandRowColor, i); final PdfFont font = cell.style.font ?? row.style.font ?? PdfGridRowHelper.getHelper(row).grid.style.font ?? @@ -2909,8 +2803,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.font = _changeFontStyle(font); cell.style.backgroundBrush = backColorBrush; cell.style.textBrush = whiteBrush; - cell.style.borders.bottom = - PdfPen(PdfColor(255, 255, 255), width: 2); + cell.style.borders.bottom = PdfPen(PdfColor(255, 255, 255), width: 2); if (_bandedColumn) { if (j > 1) { cell.style.borders.left = whitePen; @@ -3007,8 +2900,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyListTable6Colorful( - PdfColor borderColor, PdfColor backColor, PdfColor textColor) { + void _applyListTable6Colorful(PdfColor borderColor, PdfColor backColor, PdfColor textColor) { final PdfBrush backColorBrush = PdfSolidBrush(backColor); final PdfPen borderColorPen = PdfPen(borderColor, width: 0.5); final PdfPen backColorPen = PdfPen(backColor, width: 0.5); @@ -3026,8 +2918,7 @@ class PdfGrid extends PdfLayoutElement { if (_headerRow) { if (_bandedColumn) { if (!(_lastColumn && j == row.cells.count)) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); } if (cell.style.backgroundBrush != null) { cell.style.borders.left = backColorPen; @@ -3043,8 +2934,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.bottom = borderColorPen; } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { if (i == 1 && _headerRow) { cell.style.borders.top = borderColorPen; @@ -3106,11 +2996,9 @@ class PdfGrid extends PdfLayoutElement { } if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { if (j == 1) { cell.style.borders.left = backColorPen; @@ -3123,8 +3011,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.left = backColorPen; cell.style.borders.right = backColorPen; @@ -3134,8 +3021,7 @@ class PdfGrid extends PdfLayoutElement { } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (j == 1) { cell.style.borders.left = backColorPen; } else if (j == row.cells.count) { @@ -3161,8 +3047,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.borders.left = emptyPen; cell.style.borders.right = emptyPen; if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.right = backColorPen; } @@ -3191,8 +3076,7 @@ class PdfGrid extends PdfLayoutElement { cell.style.font = _changeFontStyle(font); cell.style.borders.top = PdfPen(borderColor); if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (_lastColumn && j == row.cells.count) { cell.style.backgroundBrush = null; } @@ -3206,8 +3090,7 @@ class PdfGrid extends PdfLayoutElement { } } - void _applyListTable7Colorful( - PdfColor borderColor, PdfColor backColor, PdfColor textColor) { + void _applyListTable7Colorful(PdfColor borderColor, PdfColor backColor, PdfColor textColor) { final PdfPen borderPen = PdfPen(borderColor, width: 0.5); final PdfPen emptyPen = PdfPen(PdfColor.empty); final PdfBrush backBrush = PdfSolidBrush(backColor); @@ -3234,8 +3117,7 @@ class PdfGrid extends PdfLayoutElement { } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backColorPen; } @@ -3283,25 +3165,21 @@ class PdfGrid extends PdfLayoutElement { cell.style.textBrush = textBrush; if (_bandedColumn && _bandedRow) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); - cell.style.backgroundBrush ??= - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush ??= _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backColorPen; } } else { if (_bandedColumn) { - cell.style.backgroundBrush = - _applyBandedColStyle(_firstColumn, backColor, j); + cell.style.backgroundBrush = _applyBandedColStyle(_firstColumn, backColor, j); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backColorPen; } } if (_bandedRow) { - cell.style.backgroundBrush = - _applyBandedRowStyle(_headerRow, backColor, i); + cell.style.backgroundBrush = _applyBandedRowStyle(_headerRow, backColor, i); if (cell.style.backgroundBrush != null) { cell.style.borders.all = backColorPen; } @@ -3447,8 +3325,7 @@ class PdfGridHelper { /// internal method PdfSize _measure() { double height = 0; - final double width = - PdfGridColumnCollectionHelper.getHelper(base.columns).columnWidth; + final double width = PdfGridColumnCollectionHelper.getHelper(base.columns).columnWidth; for (int i = 0; i < base.headers.count; i++) { height += base.headers[i].height; } @@ -3473,12 +3350,10 @@ class PdfGridHelper { !PdfGridCellHelper.getHelper(cell).isRowMergeContinue && (cell.columnSpan > 1 || cell.rowSpan > 1)) { if (cell.columnSpan + j > row.cells.count) { - throw ArgumentError.value( - 'Invalid span specified at row $j column $i'); + throw ArgumentError.value('Invalid span specified at row $j column $i'); } if (cell.rowSpan + i > base.headers.count) { - throw ArgumentError.value( - 'Invalid span specified at row $j column $i'); + throw ArgumentError.value('Invalid span specified at row $j column $i'); } if (cell.columnSpan > 1 && cell.rowSpan > 1) { colSpan = cell.columnSpan; @@ -3487,10 +3362,8 @@ class PdfGridHelper { currentRowIndex = i; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isCellMergeContinue = true; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isRowMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isCellMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isRowMergeContinue = true; row.cells[currentCellIndex].rowSpan = rowSpan; colSpan--; } @@ -3498,20 +3371,16 @@ class PdfGridHelper { colSpan = cell.columnSpan; while (rowSpan > 1) { currentRowIndex++; - PdfGridCellHelper.getHelper( - base.headers[currentRowIndex].cells[j]) + PdfGridCellHelper.getHelper(base.headers[currentRowIndex].cells[j]) .isRowMergeContinue = true; - PdfGridCellHelper.getHelper( - base.headers[currentRowIndex].cells[currentCellIndex]) + PdfGridCellHelper.getHelper(base.headers[currentRowIndex].cells[currentCellIndex]) .isRowMergeContinue = true; rowSpan--; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper( - base.headers[currentRowIndex].cells[currentCellIndex]) + PdfGridCellHelper.getHelper(base.headers[currentRowIndex].cells[currentCellIndex]) .isCellMergeContinue = true; - PdfGridCellHelper.getHelper( - base.headers[currentRowIndex].cells[currentCellIndex]) + PdfGridCellHelper.getHelper(base.headers[currentRowIndex].cells[currentCellIndex]) .isRowMergeContinue = true; colSpan--; } @@ -3523,8 +3392,7 @@ class PdfGridHelper { currentCellIndex = j; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isCellMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isCellMergeContinue = true; colSpan--; } } else if (cell.columnSpan == 1 && cell.rowSpan > 1) { @@ -3532,8 +3400,7 @@ class PdfGridHelper { currentRowIndex = i; while (rowSpan > 1) { currentRowIndex++; - PdfGridCellHelper.getHelper( - base.headers[currentRowIndex].cells[j]) + PdfGridCellHelper.getHelper(base.headers[currentRowIndex].cells[j]) .isRowMergeContinue = true; rowSpan--; } @@ -3555,12 +3422,10 @@ class PdfGridHelper { !PdfGridCellHelper.getHelper(cell).isRowMergeContinue && (cell.columnSpan > 1 || cell.rowSpan > 1)) { if (cell.columnSpan + j > row.cells.count) { - throw ArgumentError.value( - 'Invalid span specified at row $j column $i'); + throw ArgumentError.value('Invalid span specified at row $j column $i'); } if (cell.rowSpan + i > base.rows.count) { - throw ArgumentError.value( - 'Invalid span specified at row $j column $i'); + throw ArgumentError.value('Invalid span specified at row $j column $i'); } if (cell.columnSpan > 1 && cell.rowSpan > 1) { colSpan = cell.columnSpan; @@ -3569,10 +3434,8 @@ class PdfGridHelper { currentRowIndex = i; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isCellMergeContinue = true; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isRowMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isCellMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isRowMergeContinue = true; colSpan--; } currentCellIndex = j; @@ -3581,19 +3444,16 @@ class PdfGridHelper { currentRowIndex++; PdfGridCellHelper.getHelper(base.rows[currentRowIndex].cells[j]) .isRowMergeContinue = true; - PdfGridCellHelper.getHelper( - base.rows[currentRowIndex].cells[currentCellIndex]) + PdfGridCellHelper.getHelper(base.rows[currentRowIndex].cells[currentCellIndex]) .isRowMergeContinue = true; rowSpan--; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper( - PdfGridRowHelper.getHelper(base.rows[currentRowIndex]) - .cells![currentCellIndex]) + PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(base.rows[currentRowIndex]) + .cells![currentCellIndex]) .isCellMergeContinue = true; - PdfGridCellHelper.getHelper( - PdfGridRowHelper.getHelper(base.rows[currentRowIndex]) - .cells![currentCellIndex]) + PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(base.rows[currentRowIndex]) + .cells![currentCellIndex]) .isRowMergeContinue = true; colSpan--; } @@ -3605,8 +3465,7 @@ class PdfGridHelper { currentCellIndex = j; while (colSpan > 1) { currentCellIndex++; - PdfGridCellHelper.getHelper(row.cells[currentCellIndex]) - .isCellMergeContinue = true; + PdfGridCellHelper.getHelper(row.cells[currentCellIndex]).isCellMergeContinue = true; colSpan--; } } else if (cell.columnSpan == 1 && cell.rowSpan > 1) { @@ -3646,31 +3505,18 @@ class PdfGridHelper { cellWidth = 0; for (int i = 0; i < base.columns.count; i++) { for (int j = 0; j < base.rows.count; j++) { - final bool isGrid = base.rows[j].cells[i].value != null && - base.rows[j].cells[i].value is PdfGrid; + final bool isGrid = + base.rows[j].cells[i].value != null && base.rows[j].cells[i].value is PdfGrid; if ((base.rows[j].cells[i].columnSpan == 1 && - !PdfGridCellHelper.getHelper(base.rows[j].cells[i]) - .isCellMergeContinue) || + !PdfGridCellHelper.getHelper(base.rows[j].cells[i]).isCellMergeContinue) || isGrid) { if (isGrid && - !PdfGridRowHelper.getHelper(base.rows[j]) - .grid - .style - .allowHorizontalOverflow && + !PdfGridRowHelper.getHelper(base.rows[j]).grid.style.allowHorizontalOverflow && initialWidth != 0) { - PdfGridHelper.getHelper(base.rows[j].cells[i].value as PdfGrid) - .initialWidth = + PdfGridHelper.getHelper(base.rows[j].cells[i].value as PdfGrid).initialWidth = initialWidth - - (PdfGridRowHelper.getHelper(base.rows[j]) - .grid - .style - .cellPadding - .right + - PdfGridRowHelper.getHelper(base.rows[j]) - .grid - .style - .cellPadding - .left + + (PdfGridRowHelper.getHelper(base.rows[j]).grid.style.cellPadding.right + + PdfGridRowHelper.getHelper(base.rows[j]).grid.style.cellPadding.left + base.rows[j].cells[i].style.borders.left.width / 2 + base._gridLocation.x); } @@ -3707,21 +3553,19 @@ class PdfGridHelper { } } if (isChildGrid! && initialWidth != 0) { - widths = PdfGridColumnCollectionHelper.getHelper(base.columns) - .getDefaultWidths(initialWidth); + widths = + PdfGridColumnCollectionHelper.getHelper(base.columns).getDefaultWidths(initialWidth); } for (int i = 0; i < base.columns.count; i++) { if (base.columns[i].width < 0 || (base.columns[i].width > 0 && - !PdfGridColumnHelper.getHelper(base.columns[i]) - .isCustomWidth)) { + !PdfGridColumnHelper.getHelper(base.columns[i]).isCustomWidth)) { PdfGridColumnHelper.getHelper(base.columns[i]).width = widths[i]!; } } } else { - List widths = - PdfGridColumnCollectionHelper.getHelper(base.columns) - .getDefaultWidths(bounds.width - bounds.x); + List widths = PdfGridColumnCollectionHelper.getHelper(base.columns) + .getDefaultWidths(bounds.width - bounds.x); for (int i = 0; i < base.columns.count; i++) { if (base.columns[i].width < 0) { PdfGridColumnHelper.getHelper(base.columns[i]).width = widths[i]!; @@ -3734,8 +3578,7 @@ class PdfGridHelper { } if (parentCell != null && (!base.style.allowHorizontalOverflow) && - (!PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) + (!PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!) .grid .style .allowHorizontalOverflow)) { @@ -3743,25 +3586,21 @@ class PdfGridHelper { double columnWidth = 0; int columnCount = base.columns.count; if (parentCell!.style.cellPadding != null) { - padding += parentCell!.style.cellPadding!.left + - parentCell!.style.cellPadding!.right; + padding += parentCell!.style.cellPadding!.left + parentCell!.style.cellPadding!.right; } else { - padding += PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) + padding += PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!) .grid .style .cellPadding .left + - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!) .grid .style .cellPadding .right; } for (int i = 0; i < parentCell!.columnSpan; i++) { - columnWidth += PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) + columnWidth += PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!) .grid .columns[parentCellIndex + i] .width; @@ -3774,32 +3613,25 @@ class PdfGridHelper { } } if (columnWidth > padding) { - final double childGridColumnWidth = - (columnWidth - padding) / columnCount; - if (parentCell != null && - parentCell!.stringFormat.alignment != PdfTextAlignment.right) { + final double childGridColumnWidth = (columnWidth - padding) / columnCount; + if (parentCell != null && parentCell!.stringFormat.alignment != PdfTextAlignment.right) { for (int j = 0; j < base.columns.count; j++) { - if (!PdfGridColumnHelper.getHelper(base.columns[j]) - .isCustomWidth) { - PdfGridColumnHelper.getHelper(base.columns[j]).width = - childGridColumnWidth; + if (!PdfGridColumnHelper.getHelper(base.columns[j]).isCustomWidth) { + PdfGridColumnHelper.getHelper(base.columns[j]).width = childGridColumnWidth; } } } } } if (parentCell != null && - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) - .getWidth() > + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!).getWidth() > 0) { if (isChildGrid! && size.width > - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(parentCell!).row!) + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(parentCell!).row!) .getWidth()) { - widths = PdfGridColumnCollectionHelper.getHelper(base.columns) - .getDefaultWidths(bounds.width); + widths = + PdfGridColumnCollectionHelper.getHelper(base.columns).getDefaultWidths(bounds.width); for (int i = 0; i < base.columns.count; i++) { base.columns[i].width = widths[i]!; } @@ -3864,8 +3696,7 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.plainTable1: - base._applyPlainTable1( - PdfColor(191, 191, 191), PdfColor(242, 242, 242)); + base._applyPlainTable1(PdfColor(191, 191, 191), PdfColor(242, 242, 242)); break; case PdfGridBuiltInStyle.plainTable2: @@ -3873,8 +3704,7 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.plainTable3: - base._applyPlainTable3( - PdfColor(127, 127, 127), PdfColor(242, 242, 242)); + base._applyPlainTable3(PdfColor(127, 127, 127), PdfColor(242, 242, 242)); break; case PdfGridBuiltInStyle.plainTable4: @@ -3882,42 +3712,34 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.plainTable5: - base._applyPlainTable5( - PdfColor(127, 127, 127), PdfColor(242, 242, 242)); + base._applyPlainTable5(PdfColor(127, 127, 127), PdfColor(242, 242, 242)); break; case PdfGridBuiltInStyle.gridTable1Light: - base._applyGridTable1Light( - PdfColor(153, 153, 153), PdfColor(102, 102, 102)); + base._applyGridTable1Light(PdfColor(153, 153, 153), PdfColor(102, 102, 102)); break; case PdfGridBuiltInStyle.gridTable1LightAccent1: - base._applyGridTable1Light( - PdfColor(189, 214, 238), PdfColor(156, 194, 229)); + base._applyGridTable1Light(PdfColor(189, 214, 238), PdfColor(156, 194, 229)); break; case PdfGridBuiltInStyle.gridTable1LightAccent2: - base._applyGridTable1Light( - PdfColor(247, 202, 172), PdfColor(244, 176, 131)); + base._applyGridTable1Light(PdfColor(247, 202, 172), PdfColor(244, 176, 131)); break; case PdfGridBuiltInStyle.gridTable1LightAccent3: - base._applyGridTable1Light( - PdfColor(219, 219, 219), PdfColor(201, 201, 201)); + base._applyGridTable1Light(PdfColor(219, 219, 219), PdfColor(201, 201, 201)); break; case PdfGridBuiltInStyle.gridTable1LightAccent4: - base._applyGridTable1Light( - PdfColor(255, 229, 153), PdfColor(255, 217, 102)); + base._applyGridTable1Light(PdfColor(255, 229, 153), PdfColor(255, 217, 102)); break; case PdfGridBuiltInStyle.gridTable1LightAccent5: - base._applyGridTable1Light( - PdfColor(180, 198, 231), PdfColor(142, 170, 219)); + base._applyGridTable1Light(PdfColor(180, 198, 231), PdfColor(142, 170, 219)); break; case PdfGridBuiltInStyle.gridTable1LightAccent6: - base._applyGridTable1Light( - PdfColor(192, 224, 179), PdfColor(168, 208, 141)); + base._applyGridTable1Light(PdfColor(192, 224, 179), PdfColor(168, 208, 141)); break; case PdfGridBuiltInStyle.gridTable2: @@ -3977,177 +3799,169 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.gridTable4: - base._applyGridTable4(PdfColor(102, 102, 102), PdfColor(204, 204, 204), - PdfColor(0, 0, 0)); + base._applyGridTable4(PdfColor(102, 102, 102), PdfColor(204, 204, 204), PdfColor(0, 0, 0)); break; case PdfGridBuiltInStyle.gridTable4Accent1: - base._applyGridTable4(PdfColor(156, 194, 229), PdfColor(222, 234, 246), - PdfColor(91, 155, 213)); + base._applyGridTable4( + PdfColor(156, 194, 229), PdfColor(222, 234, 246), PdfColor(91, 155, 213)); break; case PdfGridBuiltInStyle.gridTable4Accent2: - base._applyGridTable4(PdfColor(244, 176, 131), PdfColor(251, 228, 213), - PdfColor(237, 125, 49)); + base._applyGridTable4( + PdfColor(244, 176, 131), PdfColor(251, 228, 213), PdfColor(237, 125, 49)); break; case PdfGridBuiltInStyle.gridTable4Accent3: - base._applyGridTable4(PdfColor(201, 201, 201), PdfColor(237, 237, 237), - PdfColor(165, 165, 165)); + base._applyGridTable4( + PdfColor(201, 201, 201), PdfColor(237, 237, 237), PdfColor(165, 165, 165)); break; case PdfGridBuiltInStyle.gridTable4Accent4: - base._applyGridTable4(PdfColor(255, 217, 102), PdfColor(255, 242, 204), - PdfColor(255, 192, 0)); + base._applyGridTable4( + PdfColor(255, 217, 102), PdfColor(255, 242, 204), PdfColor(255, 192, 0)); break; case PdfGridBuiltInStyle.gridTable4Accent5: - base._applyGridTable4(PdfColor(142, 170, 219), PdfColor(217, 226, 243), - PdfColor(68, 114, 196)); + base._applyGridTable4( + PdfColor(142, 170, 219), PdfColor(217, 226, 243), PdfColor(68, 114, 196)); break; case PdfGridBuiltInStyle.gridTable4Accent6: - base._applyGridTable4(PdfColor(168, 208, 141), PdfColor(226, 239, 217), - PdfColor(112, 173, 71)); + base._applyGridTable4( + PdfColor(168, 208, 141), PdfColor(226, 239, 217), PdfColor(112, 173, 71)); break; case PdfGridBuiltInStyle.gridTable5Dark: - base._applyGridTable5Dark(PdfColor(0, 0, 0), PdfColor(153, 153, 153), - PdfColor(204, 204, 204)); + base._applyGridTable5Dark( + PdfColor(0, 0, 0), PdfColor(153, 153, 153), PdfColor(204, 204, 204)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent1: - base._applyGridTable5Dark(PdfColor(91, 155, 213), - PdfColor(189, 214, 238), PdfColor(222, 234, 246)); + base._applyGridTable5Dark( + PdfColor(91, 155, 213), PdfColor(189, 214, 238), PdfColor(222, 234, 246)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent2: - base._applyGridTable5Dark(PdfColor(237, 125, 49), - PdfColor(247, 202, 172), PdfColor(251, 228, 213)); + base._applyGridTable5Dark( + PdfColor(237, 125, 49), PdfColor(247, 202, 172), PdfColor(251, 228, 213)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent3: - base._applyGridTable5Dark(PdfColor(165, 165, 165), - PdfColor(219, 219, 219), PdfColor(237, 237, 237)); + base._applyGridTable5Dark( + PdfColor(165, 165, 165), PdfColor(219, 219, 219), PdfColor(237, 237, 237)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent4: - base._applyGridTable5Dark(PdfColor(255, 192, 0), - PdfColor(255, 229, 153), PdfColor(255, 242, 204)); + base._applyGridTable5Dark( + PdfColor(255, 192, 0), PdfColor(255, 229, 153), PdfColor(255, 242, 204)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent5: - base._applyGridTable5Dark(PdfColor(68, 114, 196), - PdfColor(180, 198, 231), PdfColor(217, 226, 243)); + base._applyGridTable5Dark( + PdfColor(68, 114, 196), PdfColor(180, 198, 231), PdfColor(217, 226, 243)); break; case PdfGridBuiltInStyle.gridTable5DarkAccent6: - base._applyGridTable5Dark(PdfColor(112, 171, 71), - PdfColor(197, 224, 179), PdfColor(226, 239, 217)); + base._applyGridTable5Dark( + PdfColor(112, 171, 71), PdfColor(197, 224, 179), PdfColor(226, 239, 217)); break; case PdfGridBuiltInStyle.gridTable6Colorful: - base._applyGridTable6Colorful(PdfColor(102, 102, 102), - PdfColor(204, 204, 204), PdfColor(0, 0, 0)); + base._applyGridTable6Colorful( + PdfColor(102, 102, 102), PdfColor(204, 204, 204), PdfColor(0, 0, 0)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent1: - base._applyGridTable6Colorful(PdfColor(156, 194, 229), - PdfColor(222, 234, 246), PdfColor(46, 116, 181)); + base._applyGridTable6Colorful( + PdfColor(156, 194, 229), PdfColor(222, 234, 246), PdfColor(46, 116, 181)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent2: - base._applyGridTable6Colorful(PdfColor(244, 176, 131), - PdfColor(251, 228, 213), PdfColor(196, 89, 17)); + base._applyGridTable6Colorful( + PdfColor(244, 176, 131), PdfColor(251, 228, 213), PdfColor(196, 89, 17)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent3: - base._applyGridTable6Colorful(PdfColor(201, 201, 201), - PdfColor(237, 237, 237), PdfColor(123, 123, 123)); + base._applyGridTable6Colorful( + PdfColor(201, 201, 201), PdfColor(237, 237, 237), PdfColor(123, 123, 123)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent4: - base._applyGridTable6Colorful(PdfColor(255, 217, 102), - PdfColor(255, 242, 204), PdfColor(191, 143, 0)); + base._applyGridTable6Colorful( + PdfColor(255, 217, 102), PdfColor(255, 242, 204), PdfColor(191, 143, 0)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent5: - base._applyGridTable6Colorful(PdfColor(142, 170, 219), - PdfColor(217, 226, 243), PdfColor(47, 84, 150)); + base._applyGridTable6Colorful( + PdfColor(142, 170, 219), PdfColor(217, 226, 243), PdfColor(47, 84, 150)); break; case PdfGridBuiltInStyle.gridTable6ColorfulAccent6: - base._applyGridTable6Colorful(PdfColor(168, 208, 141), - PdfColor(226, 239, 217), PdfColor(83, 129, 53)); + base._applyGridTable6Colorful( + PdfColor(168, 208, 141), PdfColor(226, 239, 217), PdfColor(83, 129, 53)); break; case PdfGridBuiltInStyle.gridTable7Colorful: - base._applyGridTable7Colorful(PdfColor(102, 102, 102), - PdfColor(204, 204, 204), PdfColor(0, 0, 0)); + base._applyGridTable7Colorful( + PdfColor(102, 102, 102), PdfColor(204, 204, 204), PdfColor(0, 0, 0)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent1: - base._applyGridTable7Colorful(PdfColor(156, 194, 229), - PdfColor(222, 234, 246), PdfColor(46, 116, 181)); + base._applyGridTable7Colorful( + PdfColor(156, 194, 229), PdfColor(222, 234, 246), PdfColor(46, 116, 181)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent2: - base._applyGridTable7Colorful(PdfColor(244, 176, 131), - PdfColor(251, 228, 213), PdfColor(196, 89, 17)); + base._applyGridTable7Colorful( + PdfColor(244, 176, 131), PdfColor(251, 228, 213), PdfColor(196, 89, 17)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent3: - base._applyGridTable7Colorful(PdfColor(201, 201, 201), - PdfColor(237, 237, 237), PdfColor(123, 123, 123)); + base._applyGridTable7Colorful( + PdfColor(201, 201, 201), PdfColor(237, 237, 237), PdfColor(123, 123, 123)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent4: - base._applyGridTable7Colorful(PdfColor(255, 217, 102), - PdfColor(255, 242, 204), PdfColor(191, 143, 0)); + base._applyGridTable7Colorful( + PdfColor(255, 217, 102), PdfColor(255, 242, 204), PdfColor(191, 143, 0)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent5: - base._applyGridTable7Colorful(PdfColor(142, 170, 219), - PdfColor(217, 226, 243), PdfColor(47, 84, 150)); + base._applyGridTable7Colorful( + PdfColor(142, 170, 219), PdfColor(217, 226, 243), PdfColor(47, 84, 150)); break; case PdfGridBuiltInStyle.gridTable7ColorfulAccent6: - base._applyGridTable7Colorful(PdfColor(168, 208, 141), - PdfColor(226, 239, 217), PdfColor(83, 129, 53)); + base._applyGridTable7Colorful( + PdfColor(168, 208, 141), PdfColor(226, 239, 217), PdfColor(83, 129, 53)); break; case PdfGridBuiltInStyle.listTable1Light: - base._applyListTable1Light( - PdfColor(102, 102, 102), PdfColor(204, 204, 204)); + base._applyListTable1Light(PdfColor(102, 102, 102), PdfColor(204, 204, 204)); break; case PdfGridBuiltInStyle.listTable1LightAccent1: - base._applyListTable1Light( - PdfColor(156, 194, 229), PdfColor(222, 234, 246)); + base._applyListTable1Light(PdfColor(156, 194, 229), PdfColor(222, 234, 246)); break; case PdfGridBuiltInStyle.listTable1LightAccent2: - base._applyListTable1Light( - PdfColor(244, 176, 131), PdfColor(251, 228, 213)); + base._applyListTable1Light(PdfColor(244, 176, 131), PdfColor(251, 228, 213)); break; case PdfGridBuiltInStyle.listTable1LightAccent3: - base._applyListTable1Light( - PdfColor(201, 201, 201), PdfColor(237, 237, 237)); + base._applyListTable1Light(PdfColor(201, 201, 201), PdfColor(237, 237, 237)); break; case PdfGridBuiltInStyle.listTable1LightAccent4: - base._applyListTable1Light( - PdfColor(255, 217, 102), PdfColor(255, 242, 204)); + base._applyListTable1Light(PdfColor(255, 217, 102), PdfColor(255, 242, 204)); break; case PdfGridBuiltInStyle.listTable1LightAccent5: - base._applyListTable1Light( - PdfColor(142, 170, 219), PdfColor(217, 226, 243)); + base._applyListTable1Light(PdfColor(142, 170, 219), PdfColor(217, 226, 243)); break; case PdfGridBuiltInStyle.listTable1LightAccent6: - base._applyListTable1Light( - PdfColor(168, 208, 141), PdfColor(226, 239, 217)); + base._applyListTable1Light(PdfColor(168, 208, 141), PdfColor(226, 239, 217)); break; case PdfGridBuiltInStyle.listTable2: @@ -4207,38 +4021,37 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.listTable4: - base._applyListTable4(PdfColor(102, 102, 102), PdfColor(0, 0, 0), - PdfColor(204, 204, 204)); + base._applyListTable4(PdfColor(102, 102, 102), PdfColor(0, 0, 0), PdfColor(204, 204, 204)); break; case PdfGridBuiltInStyle.listTable4Accent1: - base._applyListTable4(PdfColor(156, 194, 229), PdfColor(91, 155, 213), - PdfColor(222, 234, 246)); + base._applyListTable4( + PdfColor(156, 194, 229), PdfColor(91, 155, 213), PdfColor(222, 234, 246)); break; case PdfGridBuiltInStyle.listTable4Accent2: - base._applyListTable4(PdfColor(244, 176, 131), PdfColor(237, 125, 49), - PdfColor(251, 228, 213)); + base._applyListTable4( + PdfColor(244, 176, 131), PdfColor(237, 125, 49), PdfColor(251, 228, 213)); break; case PdfGridBuiltInStyle.listTable4Accent3: - base._applyListTable4(PdfColor(201, 201, 201), PdfColor(165, 165, 165), - PdfColor(237, 237, 237)); + base._applyListTable4( + PdfColor(201, 201, 201), PdfColor(165, 165, 165), PdfColor(237, 237, 237)); break; case PdfGridBuiltInStyle.listTable4Accent4: - base._applyListTable4(PdfColor(255, 217, 102), PdfColor(255, 192, 0), - PdfColor(255, 242, 204)); + base._applyListTable4( + PdfColor(255, 217, 102), PdfColor(255, 192, 0), PdfColor(255, 242, 204)); break; case PdfGridBuiltInStyle.listTable4Accent5: - base._applyListTable4(PdfColor(142, 170, 219), PdfColor(68, 114, 196), - PdfColor(217, 226, 243)); + base._applyListTable4( + PdfColor(142, 170, 219), PdfColor(68, 114, 196), PdfColor(217, 226, 243)); break; case PdfGridBuiltInStyle.listTable4Accent6: - base._applyListTable4(PdfColor(168, 208, 141), PdfColor(112, 173, 71), - PdfColor(226, 239, 217)); + base._applyListTable4( + PdfColor(168, 208, 141), PdfColor(112, 173, 71), PdfColor(226, 239, 217)); break; case PdfGridBuiltInStyle.listTable5Dark: @@ -4270,73 +4083,73 @@ class PdfGridHelper { break; case PdfGridBuiltInStyle.listTable6Colorful: - base._applyListTable6Colorful(PdfColor(102, 102, 102), - PdfColor(204, 204, 204), PdfColor(0, 0, 0)); + base._applyListTable6Colorful( + PdfColor(102, 102, 102), PdfColor(204, 204, 204), PdfColor(0, 0, 0)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent1: - base._applyListTable6Colorful(PdfColor(91, 155, 213), - PdfColor(222, 234, 246), PdfColor(46, 116, 181)); + base._applyListTable6Colorful( + PdfColor(91, 155, 213), PdfColor(222, 234, 246), PdfColor(46, 116, 181)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent2: - base._applyListTable6Colorful(PdfColor(237, 125, 49), - PdfColor(251, 228, 213), PdfColor(196, 89, 17)); + base._applyListTable6Colorful( + PdfColor(237, 125, 49), PdfColor(251, 228, 213), PdfColor(196, 89, 17)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent3: - base._applyListTable6Colorful(PdfColor(165, 165, 165), - PdfColor(237, 237, 237), PdfColor(123, 123, 123)); + base._applyListTable6Colorful( + PdfColor(165, 165, 165), PdfColor(237, 237, 237), PdfColor(123, 123, 123)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent4: - base._applyListTable6Colorful(PdfColor(255, 192, 0), - PdfColor(255, 242, 204), PdfColor(191, 143, 0)); + base._applyListTable6Colorful( + PdfColor(255, 192, 0), PdfColor(255, 242, 204), PdfColor(191, 143, 0)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent5: - base._applyListTable6Colorful(PdfColor(68, 114, 196), - PdfColor(217, 226, 243), PdfColor(47, 84, 150)); + base._applyListTable6Colorful( + PdfColor(68, 114, 196), PdfColor(217, 226, 243), PdfColor(47, 84, 150)); break; case PdfGridBuiltInStyle.listTable6ColorfulAccent6: - base._applyListTable6Colorful(PdfColor(112, 173, 71), - PdfColor(226, 239, 217), PdfColor(83, 129, 53)); + base._applyListTable6Colorful( + PdfColor(112, 173, 71), PdfColor(226, 239, 217), PdfColor(83, 129, 53)); break; case PdfGridBuiltInStyle.listTable7Colorful: - base._applyListTable7Colorful(PdfColor(102, 102, 102), - PdfColor(204, 204, 204), PdfColor(0, 0, 0)); + base._applyListTable7Colorful( + PdfColor(102, 102, 102), PdfColor(204, 204, 204), PdfColor(0, 0, 0)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent1: - base._applyListTable7Colorful(PdfColor(91, 155, 213), - PdfColor(222, 234, 246), PdfColor(46, 116, 181)); + base._applyListTable7Colorful( + PdfColor(91, 155, 213), PdfColor(222, 234, 246), PdfColor(46, 116, 181)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent2: - base._applyListTable7Colorful(PdfColor(237, 125, 49), - PdfColor(251, 228, 213), PdfColor(196, 89, 17)); + base._applyListTable7Colorful( + PdfColor(237, 125, 49), PdfColor(251, 228, 213), PdfColor(196, 89, 17)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent3: - base._applyListTable7Colorful(PdfColor(165, 165, 165), - PdfColor(237, 237, 237), PdfColor(123, 123, 123)); + base._applyListTable7Colorful( + PdfColor(165, 165, 165), PdfColor(237, 237, 237), PdfColor(123, 123, 123)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent4: - base._applyListTable7Colorful(PdfColor(255, 192, 0), - PdfColor(255, 242, 204), PdfColor(191, 143, 0)); + base._applyListTable7Colorful( + PdfColor(255, 192, 0), PdfColor(255, 242, 204), PdfColor(191, 143, 0)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent5: - base._applyListTable7Colorful(PdfColor(68, 114, 196), - PdfColor(217, 226, 243), PdfColor(47, 84, 150)); + base._applyListTable7Colorful( + PdfColor(68, 114, 196), PdfColor(217, 226, 243), PdfColor(47, 84, 150)); break; case PdfGridBuiltInStyle.listTable7ColorfulAccent6: - base._applyListTable7Colorful(PdfColor(112, 173, 71), - PdfColor(226, 239, 217), PdfColor(83, 129, 53)); + base._applyListTable7Colorful( + PdfColor(112, 173, 71), PdfColor(226, 239, 217), PdfColor(83, 129, 53)); break; // ignore: no_default_cases @@ -4350,20 +4163,13 @@ typedef PdfGridBeginCellLayoutCallback = void Function( Object sender, PdfGridBeginCellLayoutArgs args); /// Delegate for handling EndCellLayoutEvent. -typedef PdfGridEndCellLayoutCallback = void Function( - Object sender, PdfGridEndCellLayoutArgs args); +typedef PdfGridEndCellLayoutCallback = void Function(Object sender, PdfGridEndCellLayoutArgs args); /// Represents arguments of StartCellLayout Event. class PdfGridBeginCellLayoutArgs extends GridCellLayoutArgs { //Constructor - PdfGridBeginCellLayoutArgs._( - PdfGraphics graphics, - int rowIndex, - int cellInder, - PdfRectangle bounds, - String value, - PdfGridCellStyle? style, - bool isHeaderRow) + PdfGridBeginCellLayoutArgs._(PdfGraphics graphics, int rowIndex, int cellInder, + PdfRectangle bounds, String value, PdfGridCellStyle? style, bool isHeaderRow) : super._(graphics, rowIndex, cellInder, bounds, value, isHeaderRow) { if (style != null) { this.style = style; @@ -4421,14 +4227,8 @@ class PdfGridBeginCellLayoutArgs extends GridCellLayoutArgs { /// [PdfGridBeginCellLayoutArgs] helper class PdfGridBeginCellLayoutArgsHelper { /// internal method - static PdfGridBeginCellLayoutArgs load( - PdfGraphics graphics, - int rowIndex, - int cellInder, - PdfRectangle bounds, - String value, - PdfGridCellStyle? style, - bool isHeaderRow) { + static PdfGridBeginCellLayoutArgs load(PdfGraphics graphics, int rowIndex, int cellInder, + PdfRectangle bounds, String value, PdfGridCellStyle? style, bool isHeaderRow) { return PdfGridBeginCellLayoutArgs._( graphics, rowIndex, cellInder, bounds, value, style, isHeaderRow); } @@ -4437,14 +4237,8 @@ class PdfGridBeginCellLayoutArgsHelper { /// Represents arguments of EndCellLayout Event. class PdfGridEndCellLayoutArgs extends GridCellLayoutArgs { //Constructor - PdfGridEndCellLayoutArgs._( - PdfGraphics graphics, - int rowIndex, - int cellInder, - PdfRectangle bounds, - String value, - PdfGridCellStyle? style, - bool isHeaderRow) + PdfGridEndCellLayoutArgs._(PdfGraphics graphics, int rowIndex, int cellInder, PdfRectangle bounds, + String value, PdfGridCellStyle? style, bool isHeaderRow) : super._(graphics, rowIndex, cellInder, bounds, value, isHeaderRow) { if (style != null) { this.style = style; @@ -4459,14 +4253,8 @@ class PdfGridEndCellLayoutArgs extends GridCellLayoutArgs { /// [PdfGridEndCellLayoutArgs] helper class PdfGridEndCellLayoutArgsHelper { /// internal method - static PdfGridEndCellLayoutArgs load( - PdfGraphics graphics, - int rowIndex, - int cellInder, - PdfRectangle bounds, - String value, - PdfGridCellStyle? style, - bool isHeaderRow) { + static PdfGridEndCellLayoutArgs load(PdfGraphics graphics, int rowIndex, int cellInder, + PdfRectangle bounds, String value, PdfGridCellStyle? style, bool isHeaderRow) { return PdfGridEndCellLayoutArgs._( graphics, rowIndex, cellInder, bounds, value, style, isHeaderRow); } @@ -4476,8 +4264,8 @@ class PdfGridEndCellLayoutArgsHelper { abstract class GridCellLayoutArgs { //Constructors /// Initializes a new instance of the [StartCellLayoutArgs] class. - GridCellLayoutArgs._(PdfGraphics graphics, int rowIndex, int cellIndex, - PdfRectangle bounds, String value, bool isHeaderRow) { + GridCellLayoutArgs._(PdfGraphics graphics, int rowIndex, int cellIndex, PdfRectangle bounds, + String value, bool isHeaderRow) { _rowIndex = rowIndex; _cellIndex = cellIndex; _value = value; @@ -4818,8 +4606,7 @@ class PdfGridBeginPageLayoutArgs extends BeginPageLayoutArgs { /// [PdfGridBeginPageLayoutArgs] helper class PdfGridBeginPageLayoutArgsHelper { /// internal method - static PdfGridBeginPageLayoutArgs load( - Rect bounds, PdfPage page, int? startRow) { + static PdfGridBeginPageLayoutArgs load(Rect bounds, PdfPage page, int? startRow) { return PdfGridBeginPageLayoutArgs._(bounds, page, startRow); } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid_cell.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid_cell.dart index 5d99f75df..12475073a 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid_cell.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/grid/pdf_grid_cell.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_brush.dart'; @@ -201,8 +201,7 @@ class PdfGridCell { /// ``` double get width { if (_width == -1 || - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid) - .isComplete) { + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid).isComplete) { _width = _measureWidth(); } return double.parse(_width.toStringAsFixed(4)); @@ -316,14 +315,13 @@ class PdfGridCell { int get rowSpan => _rowSpan; set rowSpan(int value) { if (value < 1) { - throw ArgumentError.value('value', 'row span', - 'Invalid span specified, must be greater than or equal to 1'); + throw ArgumentError.value( + 'value', 'row span', 'Invalid span specified, must be greater than or equal to 1'); } if (value > 1) { _rowSpan = value; PdfGridRowHelper.getHelper(_helper.row!).rowSpanExists = true; - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid) - .hasRowSpan = true; + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid).hasRowSpan = true; } } @@ -385,13 +383,12 @@ class PdfGridCell { int get columnSpan => _columnSpan; set columnSpan(int value) { if (value < 1) { - throw ArgumentError.value('value', 'column span', - 'Invalid span specified, must be greater than or equal to 1'); + throw ArgumentError.value( + 'value', 'column span', 'Invalid span specified, must be greater than or equal to 1'); } if (value > 1) { _columnSpan = value; - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid) - .hasColumnSpan = true; + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid).hasColumnSpan = true; } } @@ -605,8 +602,8 @@ class PdfGridCell { } //Implementation - void _initialize(PdfGridCellStyle? style, PdfStringFormat? format, - PdfGridRow? row, int? rowSpan, int? columnSpan) { + void _initialize(PdfGridCellStyle? style, PdfStringFormat? format, PdfGridRow? row, int? rowSpan, + int? columnSpan) { if (row != null) { _helper.row = row; } @@ -646,8 +643,7 @@ class PdfGridCell { throw ArgumentError.value(value, 'value', 'value cannot be null'); } if (_value is PdfGrid) { - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid) - .isSingleGrid = false; + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid).isSingleGrid = false; PdfGridHelper.getHelper(_value as PdfGrid).parentCell = this; PdfGridHelper.getHelper(_value as PdfGrid).isChildGrid = true; for (int i = 0; i < _value.rows.count; i++) { @@ -664,8 +660,7 @@ class PdfGridCell { return style.font ?? _helper.row!.style.font ?? PdfGridRowHelper.getHelper(_helper.row!).grid.style.font ?? - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid) - .defaultFont; + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(_helper.row!).grid).defaultFont; } PdfBrush? _getTextBrush() { @@ -695,8 +690,7 @@ class PdfGridCell { if (_parent != null) { defaultWidth = _getColumnWidth(); } - final PdfStringLayoutResult result = layouter.layout( - value, _getTextFont()!, stringFormat, + final PdfStringLayoutResult result = layouter.layout(value, _getTextFont()!, stringFormat, width: defaultWidth, height: _maxValue); width += result.size.width; width += (style.borders.left.width + style.borders.right.width) * 2; @@ -710,8 +704,7 @@ class PdfGridCell { final PdfTextElement element = value as PdfTextElement; String? temp = element.text; if (!_helper.finished) { - temp = (_helper.remainingString != null && - _helper.remainingString!.isNotEmpty) + temp = (_helper.remainingString != null && _helper.remainingString!.isNotEmpty) ? _helper.remainingString : value as String; } @@ -725,22 +718,13 @@ class PdfGridCell { PdfGridRowHelper.getHelper(_helper.row!).grid.style.cellSpacing + (style.cellPadding != null ? (style.cellPadding!.left + style.cellPadding!.right) - : (PdfGridRowHelper.getHelper(_helper.row!) - .grid - .style - .cellPadding - .left + - PdfGridRowHelper.getHelper(_helper.row!) - .grid - .style - .cellPadding - .right)); + : (PdfGridRowHelper.getHelper(_helper.row!).grid.style.cellPadding.left + + PdfGridRowHelper.getHelper(_helper.row!).grid.style.cellPadding.right)); } double _getColumnWidth() { - double defaultWidth = - PdfGridCellHelper.getHelper(_parent!)._calculateWidth()! / - PdfGridRowHelper.getHelper(_helper.row!).grid.columns.count; + double defaultWidth = PdfGridCellHelper.getHelper(_parent!)._calculateWidth()! / + PdfGridRowHelper.getHelper(_helper.row!).grid.columns.count; if (defaultWidth <= 0) { defaultWidth = _maxValue; } @@ -810,8 +794,7 @@ class PdfGridCellHelper { temp!, element.font, element.stringFormat ?? base.stringFormat, width: width, height: base._maxValue); height += result.size.height + - ((base.style.borders.top.width + base.style.borders.bottom.width) * - 2); + ((base.style.borders.top.width + base.style.borders.bottom.width) * 2); } else if (base.value is String || remainingString is String) { String? currentValue = base.value as String; if (!finished) { @@ -823,8 +806,7 @@ class PdfGridCellHelper { currentValue!, base._getTextFont()!, base.stringFormat, width: width, height: base._maxValue); height += result.size.height + - ((base.style.borders.top.width + base.style.borders.bottom.width) * - 2); + ((base.style.borders.top.width + base.style.borders.bottom.width) * 2); } else if (base.value is PdfGrid) { height = PdfGridHelper.getHelper(base.value as PdfGrid).size.height; } else if (base.value is PdfImage) { @@ -844,32 +826,25 @@ class PdfGridCellHelper { final int columnSpan = base.columnSpan; double width = 0; for (int i = 0; i < columnSpan; i++) { - width += - PdfGridRowHelper.getHelper(row!).grid.columns[cellIndex + i].width; + width += PdfGridRowHelper.getHelper(row!).grid.columns[cellIndex + i].width; } if (base._parent != null && - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(base._parent!).row!) - .getWidth() > + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(base._parent!).row!).getWidth() > 0 && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid! && (PdfGridRowHelper.getHelper(row!).getWidth() > - PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(base._parent!).row!) + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(base._parent!).row!) .getWidth())) { width = 0; for (int j = 0; j < base._parent!.columnSpan; j++) { - width += PdfGridRowHelper.getHelper( - PdfGridCellHelper.getHelper(base._parent!).row!) + width += PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(base._parent!).row!) .grid .columns[j] .width; } width = width / row!.cells.count; } else if (base._parent != null && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid! && width == -1) { width = _findGridColumnWidth(base._parent!); width = width / row!.cells.count; @@ -918,8 +893,7 @@ class PdfGridCellHelper { pen = base._style!.borders.right; if (bounds.x + bounds.width > graphics.clientSize.width - pen.width / 2) { p1 = Offset(graphics.clientSize.width - pen.width / 2, bounds.y); - p2 = Offset(graphics.clientSize.width - pen.width / 2, - bounds.y + bounds.height); + p2 = Offset(graphics.clientSize.width - pen.width / 2, bounds.y + bounds.height); } if (base._style!.borders.right.dashStyle == PdfDashStyle.solid && !PdfPenHelper.getHelper(pen).isImmutable) { @@ -941,10 +915,8 @@ class PdfGridCellHelper { p1 = Offset(bounds.x + bounds.width, bounds.y + bounds.height); p2 = Offset(bounds.x, bounds.y + bounds.height); pen = base._style!.borders.bottom; - if (bounds.y + bounds.height > - graphics.clientSize.height - pen.width / 2) { - p1 = Offset(bounds.x + bounds.width, - graphics.clientSize.height - pen.width / 2); + if (bounds.y + bounds.height > graphics.clientSize.height - pen.width / 2) { + p1 = Offset(bounds.x + bounds.width, graphics.clientSize.height - pen.width / 2); p2 = Offset(bounds.x, graphics.clientSize.height - pen.width / 2); } if (base._style!.borders.bottom.dashStyle == PdfDashStyle.solid && @@ -967,17 +939,13 @@ class PdfGridCellHelper { PdfStringLayoutResult? draw( PdfGraphics? graphics, PdfRectangle bounds, bool cancelSubsequentSpans) { bool isrowbreak = false; - if (!PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isSingleGrid) { + if (!PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isSingleGrid) { if ((remainingString != null) || (PdfGridLayouter.repeatRowIndex != -1)) { _drawParentCells(graphics!, bounds, true); } else if (PdfGridRowHelper.getHelper(row!).grid.rows.count > 1) { - for (int i = 0; - i < PdfGridRowHelper.getHelper(row!).grid.rows.count; - i++) { + for (int i = 0; i < PdfGridRowHelper.getHelper(row!).grid.rows.count; i++) { if (row == PdfGridRowHelper.getHelper(row!).grid.rows[i]) { - if (PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[i]) + if (PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[i]) .rowBreakHeight > 0) { isrowbreak = true; @@ -992,9 +960,7 @@ class PdfGridCellHelper { PdfStringLayoutResult? result; if (cancelSubsequentSpans) { final int currentCellIndex = row!.cells.indexOf(base); - for (int i = currentCellIndex + 1; - i <= currentCellIndex + base._columnSpan; - i++) { + for (int i = currentCellIndex + 1; i <= currentCellIndex + base._columnSpan; i++) { PdfGridCellHelper.getHelper(row!.cells[i]).isCellMergeContinue = false; PdfGridCellHelper.getHelper(row!.cells[i]).isRowMergeContinue = false; } @@ -1006,8 +972,7 @@ class PdfGridCellHelper { if ((PdfGridRowHelper.getHelper(row!).rowOverflowIndex > 0 && (row!.cells.indexOf(base) != PdfGridRowHelper.getHelper(row!).rowOverflowIndex + 1)) || - (PdfGridRowHelper.getHelper(row!).rowOverflowIndex == 0 && - isCellMergeContinue)) { + (PdfGridRowHelper.getHelper(row!).rowOverflowIndex == 0 && isCellMergeContinue)) { return result; } } else { @@ -1019,19 +984,16 @@ class PdfGridCellHelper { final PdfPen? textPen = base._getTextPen(); final PdfBrush? textBrush = base._getTextBrush(); final PdfFont? font = base._getTextFont(); - final PdfStringFormat strFormat = - base.style.stringFormat ?? base.stringFormat; + final PdfStringFormat strFormat = base.style.stringFormat ?? base.stringFormat; PdfRectangle innerLayoutArea = bounds.clone(); if (innerLayoutArea.height >= graphics!.clientSize.height) { if (PdfGridRowHelper.getHelper(row!).grid.allowRowBreakingAcrossPages) { innerLayoutArea.height = innerLayoutArea.height - innerLayoutArea.y; bounds.height = bounds.height - bounds.y; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid!) { + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid!) { innerLayoutArea.height = innerLayoutArea.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) .parentCell!) .row!) .grid @@ -1054,11 +1016,8 @@ class PdfGridCellHelper { PdfGridHelper.getHelper(childGrid).listOfNavigatePages = []; PdfGridLayouter layouter = PdfGridLayouter(childGrid); PdfLayoutFormat? format = PdfLayoutFormat(); - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .layoutFormat != - null) { - format = PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .layoutFormat; + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).layoutFormat != null) { + format = PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).layoutFormat; } else { format.layoutType = PdfLayoutType.paginate; } @@ -1087,15 +1046,14 @@ class PdfGridCellHelper { final String textElementString = textelement.text; PdfTextLayoutResult? textlayoutresult; if (finished) { - textlayoutresult = textelement.draw( - page: page, bounds: innerLayoutArea.rect) as PdfTextLayoutResult?; + textlayoutresult = + textelement.draw(page: page, bounds: innerLayoutArea.rect) as PdfTextLayoutResult?; } else { textelement.text = remainingString!; - textlayoutresult = textelement.draw( - page: page, bounds: innerLayoutArea.rect) as PdfTextLayoutResult?; + textlayoutresult = + textelement.draw(page: page, bounds: innerLayoutArea.rect) as PdfTextLayoutResult?; } - if (textlayoutresult!.remainder != null && - textlayoutresult.remainder!.isNotEmpty) { + if (textlayoutresult!.remainder != null && textlayoutresult.remainder!.isNotEmpty) { remainingString = textlayoutresult.remainder; finished = false; } else { @@ -1107,22 +1065,17 @@ class PdfGridCellHelper { String? temp; PdfRectangle layoutRectangle; if (innerLayoutArea.height < font!.height) { - layoutRectangle = PdfRectangle(innerLayoutArea.x, innerLayoutArea.y, - innerLayoutArea.width, font.height); + layoutRectangle = + PdfRectangle(innerLayoutArea.x, innerLayoutArea.y, innerLayoutArea.width, font.height); } else { layoutRectangle = innerLayoutArea; } if (innerLayoutArea.height < font.height && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid! && - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .parentCell != - null) { + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid! && + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).parentCell != null) { final double height = layoutRectangle.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) - .parentCell!) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).parentCell!) .row!) .grid .style @@ -1131,28 +1084,15 @@ class PdfGridCellHelper { PdfGridRowHelper.getHelper(row!).grid.style.cellPadding.bottom; if (height > 0 && height < font.height) { layoutRectangle.height = height; - } else if (height + - PdfGridRowHelper.getHelper(row!) - .grid - .style - .cellPadding - .bottom > - 0 && - height + - PdfGridRowHelper.getHelper(row!) - .grid - .style - .cellPadding - .bottom < - font.height) { - layoutRectangle.height = height + - PdfGridRowHelper.getHelper(row!).grid.style.cellPadding.bottom; + } else if (height + PdfGridRowHelper.getHelper(row!).grid.style.cellPadding.bottom > 0 && + height + PdfGridRowHelper.getHelper(row!).grid.style.cellPadding.bottom < font.height) { + layoutRectangle.height = + height + PdfGridRowHelper.getHelper(row!).grid.style.cellPadding.bottom; } else if (bounds.height < font.height) { layoutRectangle.height = bounds.height; } else if (bounds.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) .parentCell!) .row!) .grid @@ -1162,8 +1102,7 @@ class PdfGridCellHelper { font.height) { layoutRectangle.height = bounds.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) .parentCell!) .row!) .grid @@ -1177,36 +1116,26 @@ class PdfGridCellHelper { base.style.cellPadding!.left == 0 && base.style.cellPadding!.right == 0 && base.style.cellPadding!.top == 0) { - layoutRectangle.width = layoutRectangle.width - - base.style.borders.left.width + - base.style.borders.right.width; + layoutRectangle.width = + layoutRectangle.width - base.style.borders.left.width + base.style.borders.right.width; } if (finished) { temp = remainingString != null && remainingString!.isEmpty ? remainingString : base.value as String; graphics.drawString(temp!, font, - pen: textPen, - brush: textBrush, - bounds: layoutRectangle.rect, - format: strFormat); + pen: textPen, brush: textBrush, bounds: layoutRectangle.rect, format: strFormat); } else { graphics.drawString(remainingString!, font, - pen: textPen, - brush: textBrush, - bounds: layoutRectangle.rect, - format: strFormat); + pen: textPen, brush: textBrush, bounds: layoutRectangle.rect, format: strFormat); } result = PdfGraphicsHelper.getHelper(graphics).stringLayoutResult; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .isChildGrid! && + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).isChildGrid! && PdfGridRowHelper.getHelper(row!).rowBreakHeight > 0 && result != null) { bounds.height = bounds.height - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper( - PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) - .parentCell!) + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).parentCell!) .row!) .grid .style @@ -1215,8 +1144,7 @@ class PdfGridCellHelper { } } else if (base._value is PdfImage) { if (base.style.cellPadding != null && - base.style.cellPadding != - PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { + base.style.cellPadding != PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { final PdfPaddings padding = base.style.cellPadding!; bounds = PdfRectangle( bounds.x + padding.left, @@ -1225,8 +1153,7 @@ class PdfGridCellHelper { bounds.height - (padding.top + padding.bottom)); } else if (PdfGridRowHelper.getHelper(row!).grid.style.cellPadding != PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { - final PdfPaddings padding = - PdfGridRowHelper.getHelper(row!).grid.style.cellPadding; + final PdfPaddings padding = PdfGridRowHelper.getHelper(row!).grid.style.cellPadding; bounds = PdfRectangle( bounds.x + padding.left, bounds.y + padding.top, @@ -1282,17 +1209,15 @@ class PdfGridCellHelper { imgWidth = bounds.width; imgHeight = imgHeight / ratio; } - final PdfPage graphicsPage = - PdfGraphicsHelper.getHelper(graphics).page!; + final PdfPage graphicsPage = PdfGraphicsHelper.getHelper(graphics).page!; final PdfGraphicsState st = graphicsPage.graphics.save(); + graphicsPage.graphics.setClip(bounds: bounds.rect, mode: PdfFillMode.winding); graphicsPage.graphics - .setClip(bounds: bounds.rect, mode: PdfFillMode.winding); - graphicsPage.graphics.drawImage( - img, Rect.fromLTWH(bounds.x, bounds.y, imgWidth, imgHeight)); + .drawImage(img, Rect.fromLTWH(bounds.x, bounds.y, imgWidth, imgHeight)); graphicsPage.graphics.restore(st); } else { - graphics = _setImagePosition(graphics, img, - PdfRectangle(bounds.x, bounds.y, imgWidth, imgHeight)); + graphics = + _setImagePosition(graphics, img, PdfRectangle(bounds.x, bounds.y, imgWidth, imgHeight)); } graphics!.save(); } @@ -1302,56 +1227,38 @@ class PdfGridCellHelper { void _drawParentCells(PdfGraphics graphics, PdfRectangle bounds, bool b) { final PdfPoint location = PdfPoint( - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .defaultBorder - .right - .width / + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).defaultBorder.right.width / 2, - PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .defaultBorder - .top - .width / - 2); + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).defaultBorder.top.width / 2); if ((bounds.height < graphics.clientSize.height) && (b == true)) { bounds.height = bounds.height + bounds.y - location.y; } - final PdfRectangle rect = - PdfRectangle(location.x, location.y, bounds.width, bounds.height); + final PdfRectangle rect = PdfRectangle(location.x, location.y, bounds.width, bounds.height); if (b == false) { rect.y = bounds.y; rect.height = bounds.height; } PdfGridCell? c = base; if (base._parent != null) { - if ((PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) - .grid - .rows - .count == - 1) && + if ((PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!).grid.rows.count == 1) && (PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) .grid .rows[0] .cells .count == 1)) { - PdfGridCellHelper.getHelper( - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) - .grid - .rows[0] - .cells[0]) + PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) + .grid + .rows[0] + .cells[0]) .present = true; } else { for (int rowIndex = 0; rowIndex < - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) - .grid - .rows - .count; + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!).grid.rows.count; rowIndex++) { final PdfGridRow r = - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!) - .grid - .rows[rowIndex]; + PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!).grid.rows[rowIndex]; if (r == PdfGridCellHelper.getHelper(c).row) { for (int cellIndex = 0; cellIndex < row!.cells.count; cellIndex++) { final PdfGridCell cell = row!.cells[cellIndex]; @@ -1380,12 +1287,10 @@ class PdfGridCellHelper { rect.x = bounds.x; } } - PdfGrid pdfGrid = - PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!).grid; + PdfGrid pdfGrid = PdfGridRowHelper.getHelper(PdfGridCellHelper.getHelper(c).row!).grid; for (int i = 0; i < pdfGrid.rows.count; i++) { for (int j = 0; j < pdfGrid.rows[i].cells.count; j++) { - if (PdfGridCellHelper.getHelper(pdfGrid.rows[i].cells[j]).present == - true) { + if (PdfGridCellHelper.getHelper(pdfGrid.rows[i].cells[j]).present == true) { int cellcount = 0; if (pdfGrid.rows[i].style.backgroundBrush != null) { base.style.backgroundBrush = pdfGrid.rows[i].style.backgroundBrush; @@ -1395,16 +1300,12 @@ class PdfGridCellHelper { cellwidth += pdfGrid.columns[n].width; } } - rect.width = - PdfGridRowHelper.getHelper(pdfGrid.rows[i]).getWidth() - - cellwidth; + rect.width = PdfGridRowHelper.getHelper(pdfGrid.rows[i]).getWidth() - cellwidth; final PdfGrid? grid = pdfGrid.rows[i].cells[j].value as PdfGrid?; if (grid != null) { for (int l = 0; l < grid.rows.count; l++) { for (int m = 0; m < grid.rows[l].cells.count; m++) { - if ((PdfGridCellHelper.getHelper(grid.rows[l].cells[m]) - .present) && - m > 0) { + if ((PdfGridCellHelper.getHelper(grid.rows[l].cells[m]).present) && m > 0) { rect.width = grid.rows[l].cells[m].width; cellcount = m; } @@ -1415,8 +1316,7 @@ class PdfGridCellHelper { } PdfGridCellHelper.getHelper(pdfGrid.rows[i].cells[j]).present = false; if (pdfGrid.rows[i].cells[j].style.backgroundBrush != null) { - base.style.backgroundBrush = - pdfGrid.rows[i].cells[j].style.backgroundBrush; + base.style.backgroundBrush = pdfGrid.rows[i].cells[j].style.backgroundBrush; if (cellcount == 0) { rect.width = pdfGrid.columns[j].width; } @@ -1459,8 +1359,7 @@ class PdfGridCellHelper { if (base.style.backgroundImage != null) { final PdfImage? image = base.style.backgroundImage; if (base.style.cellPadding != null && - base.style.cellPadding != - PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { + base.style.cellPadding != PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { final PdfPaddings padding = base.style.cellPadding!; bounds = PdfRectangle( bounds.x + padding.left, @@ -1469,8 +1368,7 @@ class PdfGridCellHelper { bounds.height - (padding.top + padding.bottom)); } else if (PdfGridRowHelper.getHelper(row!).grid.style.cellPadding != PdfPaddings(left: 0, right: 0, top: 0, bottom: 0)) { - final PdfPaddings padding = - PdfGridRowHelper.getHelper(row!).grid.style.cellPadding; + final PdfPaddings padding = PdfGridRowHelper.getHelper(row!).grid.style.cellPadding; bounds = PdfRectangle( bounds.x + padding.left, bounds.y + padding.top, @@ -1491,10 +1389,8 @@ class PdfGridCellHelper { bounds.width = bounds.width - (padding.right + padding.left); bounds.height = bounds.height - (padding.bottom + padding.top); if (base.stringFormat.alignment == PdfTextAlignment.center) { - bounds.x = - bounds.x + padding.left + ((bounds.width - size.width) / 2); - bounds.y = - bounds.y + padding.top + ((bounds.height - size.height) / 2); + bounds.x = bounds.x + padding.left + ((bounds.width - size.width) / 2); + bounds.y = bounds.y + padding.top + ((bounds.height - size.height) / 2); } else if (base.stringFormat.alignment == PdfTextAlignment.left) { bounds.x = bounds.x + padding.left; bounds.y = bounds.y + padding.top; @@ -1508,10 +1404,8 @@ class PdfGridCellHelper { bounds.height = bounds.height - (padding.bottom + padding.top); if (base.stringFormat.alignment == PdfTextAlignment.center) { - bounds.x = - bounds.x + padding.left + ((bounds.width - size.width) / 2); - bounds.y = - bounds.y + padding.top + ((bounds.height - size.height) / 2); + bounds.x = bounds.x + padding.left + ((bounds.width - size.width) / 2); + bounds.y = bounds.y + padding.top + ((bounds.height - size.height) / 2); } else if (base.stringFormat.alignment == PdfTextAlignment.left) { bounds.x = bounds.x + padding.left; bounds.y = bounds.y + padding.top; @@ -1540,8 +1434,7 @@ class PdfGridCellHelper { PdfRectangle _adjustOuterLayoutArea(PdfRectangle bounds, PdfGraphics? g) { bool isHeader = false; - final double cellSpacing = - PdfGridRowHelper.getHelper(row!).grid.style.cellSpacing; + final double cellSpacing = PdfGridRowHelper.getHelper(row!).grid.style.cellSpacing; if (cellSpacing > 0) { bounds = PdfRectangle(bounds.x + cellSpacing, bounds.y + cellSpacing, bounds.width - cellSpacing, bounds.height - cellSpacing); @@ -1549,8 +1442,7 @@ class PdfGridCellHelper { final int currentColIndex = row!.cells.indexOf(base); if (base.columnSpan > 1 || (PdfGridRowHelper.getHelper(row!).rowOverflowIndex > 0 && - (currentColIndex == - PdfGridRowHelper.getHelper(row!).rowOverflowIndex + 1) && + (currentColIndex == PdfGridRowHelper.getHelper(row!).rowOverflowIndex + 1) && isCellMergeContinue)) { int span = base.columnSpan; if (span == 1 && isCellMergeContinue) { @@ -1566,30 +1458,18 @@ class PdfGridCellHelper { } double totalWidth = 0; for (int i = currentColIndex; i < currentColIndex + span; i++) { - if (PdfGridRowHelper.getHelper(row!) - .grid - .style - .allowHorizontalOverflow) { + if (PdfGridRowHelper.getHelper(row!).grid.style.allowHorizontalOverflow) { double width; - final double compWidth = PdfGridHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid) - .size - .width < - g!.clientSize.width - ? PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .size - .width - : g.clientSize.width; - if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid) - .size - .width > + final double compWidth = + PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).size.width < + g!.clientSize.width + ? PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).size.width + : g.clientSize.width; + if (PdfGridHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid).size.width > g.clientSize.width) { - width = bounds.x + - totalWidth + - PdfGridRowHelper.getHelper(row!).grid.columns[i].width; + width = bounds.x + totalWidth + PdfGridRowHelper.getHelper(row!).grid.columns[i].width; } else { - width = totalWidth + - PdfGridRowHelper.getHelper(row!).grid.columns[i].width; + width = totalWidth + PdfGridRowHelper.getHelper(row!).grid.columns[i].width; } if (width > compWidth) { break; @@ -1602,12 +1482,12 @@ class PdfGridCellHelper { } if (base.rowSpan > 1 || PdfGridRowHelper.getHelper(row!).rowSpanExists) { int span = base.rowSpan; - int currentRowIndex = PdfGridRowCollectionHelper.indexOf( - PdfGridRowHelper.getHelper(row!).grid.rows, row); + int currentRowIndex = + PdfGridRowCollectionHelper.indexOf(PdfGridRowHelper.getHelper(row!).grid.rows, row); if (currentRowIndex == -1) { - currentRowIndex = PdfGridHeaderCollectionHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.headers) - .indexOf(row!); + currentRowIndex = + PdfGridHeaderCollectionHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.headers) + .indexOf(row!); if (currentRowIndex != -1) { isHeader = true; } @@ -1617,15 +1497,11 @@ class PdfGridCellHelper { j < PdfGridRowHelper.getHelper(row!).grid.rows.count; j++) { if (isHeader - ? PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(row!) - .grid - .headers[j] - .cells[currentColIndex]) + ? PdfGridCellHelper.getHelper( + PdfGridRowHelper.getHelper(row!).grid.headers[j].cells[currentColIndex]) .isCellMergeContinue - : PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(row!) - .grid - .rows[j] - .cells[currentColIndex]) + : PdfGridCellHelper.getHelper( + PdfGridRowHelper.getHelper(row!).grid.rows[j].cells[currentColIndex]) .isCellMergeContinue) { span++; } else { @@ -1637,49 +1513,38 @@ class PdfGridCellHelper { double max = 0; if (isHeader) { for (int i = currentRowIndex; i < currentRowIndex + span; i++) { - totalHeight += - PdfGridRowHelper.getHelper(row!).grid.headers[i].height; + totalHeight += PdfGridRowHelper.getHelper(row!).grid.headers[i].height; } totalHeight -= PdfGridRowHelper.getHelper(row!).grid.style.cellSpacing; bounds.height = totalHeight; } else { for (int i = currentRowIndex; i < currentRowIndex + span; i++) { - if (!PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[i]) + if (!PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[i]) .isRowSpanRowHeightSet) { - PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[i]) + PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[i]) .isRowHeightSet = false; } totalHeight += isHeader ? PdfGridRowHelper.getHelper(row!).grid.headers[i].height : PdfGridRowHelper.getHelper(row!).grid.rows[i].height; - final PdfGridRow gridRow = - PdfGridRowHelper.getHelper(row!).grid.rows[i]; + final PdfGridRow gridRow = PdfGridRowHelper.getHelper(row!).grid.rows[i]; final int rowIndex = PdfGridRowCollectionHelper.indexOf( PdfGridRowHelper.getHelper(row!).grid.rows, gridRow); if (base.rowSpan > 1) { - for (int cellIndex = 0; - cellIndex < gridRow.cells.count; - cellIndex++) { + for (int cellIndex = 0; cellIndex < gridRow.cells.count; cellIndex++) { final PdfGridCell cell = gridRow.cells[cellIndex]; if (cell.rowSpan > 1) { double tempHeight = 0; for (int j = i; j < i + cell.rowSpan; j++) { - if (!PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[j]) + if (!PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[j]) .isRowSpanRowHeightSet) { - PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[j]) + PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[j]) .isRowHeightSet = false; } - tempHeight += - PdfGridRowHelper.getHelper(row!).grid.rows[j].height; - if (!PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[j]) + tempHeight += PdfGridRowHelper.getHelper(row!).grid.rows[j].height; + if (!PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[j]) .isRowSpanRowHeightSet) { - PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[j]) + PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[j]) .isRowHeightSet = true; } } @@ -1696,39 +1561,34 @@ class PdfGridCellHelper { .rows[(rowIndex + cell.rowSpan) - 1] .cells[index]) .rowSpanRemainingHeight = max; - base._tempRowSpanRemainingHeight = - PdfGridCellHelper.getHelper( - PdfGridRowHelper.getHelper(row!) - .grid - .rows[(rowIndex + cell.rowSpan) - 1] - .cells[index]) - .rowSpanRemainingHeight; + base._tempRowSpanRemainingHeight = PdfGridCellHelper.getHelper( + PdfGridRowHelper.getHelper(row!) + .grid + .rows[(rowIndex + cell.rowSpan) - 1] + .cells[index]) + .rowSpanRemainingHeight; } } } } } - if (!PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[i]) + if (!PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[i]) .isRowSpanRowHeightSet) { - PdfGridRowHelper.getHelper( - PdfGridRowHelper.getHelper(row!).grid.rows[i]) + PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!).grid.rows[i]) .isRowHeightSet = true; } } final int cellIndex = row!.cells.indexOf(base); totalHeight -= PdfGridRowHelper.getHelper(row!).grid.style.cellSpacing; if (row!.cells[cellIndex].height > totalHeight && - (!PdfGridRowHelper.getHelper(PdfGridRowHelper.getHelper(row!) - .grid - .rows[(currentRowIndex + span) - 1]) + (!PdfGridRowHelper.getHelper( + PdfGridRowHelper.getHelper(row!).grid.rows[(currentRowIndex + span) - 1]) .isRowHeightSet)) { PdfGridCellHelper.getHelper(PdfGridRowHelper.getHelper(row!) - .grid - .rows[(currentRowIndex + span) - 1] - .cells[cellIndex]) - .rowSpanRemainingHeight = - row!.cells[cellIndex].height - totalHeight; + .grid + .rows[(currentRowIndex + span) - 1] + .cells[cellIndex]) + .rowSpanRemainingHeight = row!.cells[cellIndex].height - totalHeight; totalHeight = row!.cells[cellIndex].height; bounds.height = totalHeight; } else { @@ -1742,8 +1602,7 @@ class PdfGridCellHelper { return bounds; } - PdfGraphics? _setImagePosition( - PdfGraphics? graphics, PdfImage? image, PdfRectangle bounds) { + PdfGraphics? _setImagePosition(PdfGraphics? graphics, PdfImage? image, PdfRectangle bounds) { if (base._imagePosition == PdfGridImagePosition.stretch) { graphics!.drawImage(image!, bounds.rect); } else if (base._imagePosition == PdfGridImagePosition.center) { @@ -1752,9 +1611,7 @@ class PdfGridCellHelper { gridCentreX = bounds.x + (bounds.width / 4); gridCentreY = bounds.y + (bounds.height / 4); graphics!.drawImage( - image!, - Rect.fromLTWH( - gridCentreX, gridCentreY, bounds.width / 2, bounds.height / 2)); + image!, Rect.fromLTWH(gridCentreX, gridCentreY, bounds.width / 2, bounds.height / 2)); } else if (base._imagePosition == PdfGridImagePosition.fit) { final double imageWidth = image!.physicalDimension.width; final double imageHeight = image.physicalDimension.height; @@ -1763,13 +1620,11 @@ class PdfGridCellHelper { if (imageHeight > imageWidth) { y = bounds.y; x = bounds.x + bounds.width / 4; - graphics!.drawImage( - image, Rect.fromLTWH(x, y, bounds.width / 2, bounds.height)); + graphics!.drawImage(image, Rect.fromLTWH(x, y, bounds.width / 2, bounds.height)); } else { x = bounds.x; y = bounds.y + (bounds.height / 4); - graphics!.drawImage( - image, Rect.fromLTWH(x, y, bounds.width, bounds.height / 2)); + graphics!.drawImage(image, Rect.fromLTWH(x, y, bounds.width, bounds.height / 2)); } } else if (base._imagePosition == PdfGridImagePosition.tile) { final double cellLeft = bounds.x; @@ -1781,8 +1636,7 @@ class PdfGridCellHelper { for (; y < bounds.bottom;) { for (x = cellLeft; x! < bounds.right;) { if (x + pWidth > bounds.right && y + pHeight > bounds.bottom) { - final PdfTemplate template = - PdfTemplate(bounds.right - x, bounds.bottom - y); + final PdfTemplate template = PdfTemplate(bounds.right - x, bounds.bottom - y); template.graphics!.drawImage(image!, Rect.zero); graphics!.drawPdfTemplate(template, Offset(x, y)); } else if (x + pWidth > bounds.right) { @@ -1808,11 +1662,9 @@ class PdfGridCellHelper { double _physicalDimension(PdfImage? image, bool isHorizontal) { if (isHorizontal) { return image!.width / - ((image.horizontalResolution > 0 ? image.horizontalResolution : 96) / - 72); + ((image.horizontalResolution > 0 ? image.horizontalResolution : 96) / 72); } else { - return image!.height / - ((image.verticalResolution > 0 ? image.verticalResolution : 96) / 72); + return image!.height / ((image.verticalResolution > 0 ? image.verticalResolution : 96) / 72); } } } diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/bullets/pdf_unordered_marker.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/bullets/pdf_unordered_marker.dart index 2a2b7aee4..197ea62d7 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/bullets/pdf_unordered_marker.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/bullets/pdf_unordered_marker.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../../drawing/drawing.dart'; import '../../../graphics/brushes/pdf_solid_brush.dart'; @@ -177,14 +177,12 @@ class PdfUnorderedMarkerHelper extends PdfMarkerHelper { late PdfFont unicodeFont; /// Draws the specified graphics. - void draw(PdfGraphics? graphics, Offset point, PdfBrush? brush, PdfPen? pen, - [PdfList? curList]) { + void draw(PdfGraphics? graphics, Offset point, PdfBrush? brush, PdfPen? pen, [PdfList? curList]) { final PdfTemplate templete = PdfTemplate(size!.width, size!.height); Offset offset = Offset(point.dx, point.dy); switch (base.style) { case PdfUnorderedMarkerStyle.customTemplate: - templete.graphics! - .drawPdfTemplate(base._template!, Offset.zero, size!.size); + templete.graphics!.drawPdfTemplate(base._template!, Offset.zero, size!.size); offset = Offset( point.dx, point.dy + @@ -206,9 +204,7 @@ class PdfUnorderedMarkerHelper extends PdfMarkerHelper { location.y = location.y + pen.width; } templete.graphics!.drawString(getStyledText(), unicodeFont, - pen: pen, - brush: brush, - bounds: Rect.fromLTWH(location.x, location.y, 0, 0)); + pen: pen, brush: brush, bounds: Rect.fromLTWH(location.x, location.y, 0, 0)); break; } graphics!.drawPdfTemplate(templete, offset); diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/pdf_list_layouter.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/pdf_list_layouter.dart index d4cf4817f..6b881bf1f 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/pdf_list_layouter.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/structured_elements/lists/pdf_list_layouter.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../drawing/drawing.dart'; import '../../graphics/brushes/pdf_brush.dart'; @@ -86,9 +86,7 @@ class PdfListLayouter extends ElementLayouter { PdfLayoutResult? layoutInternal(PdfLayoutParams param) { currentPage = param.page; bounds = param.bounds!.clone(); - if (param.bounds!.height == 0 && - param.bounds!.width == 0 && - currentPage != null) { + if (param.bounds!.height == 0 && param.bounds!.width == 0 && currentPage != null) { bounds.width = currentPage!.getClientSize().width; bounds.height = currentPage!.getClientSize().height; bounds.width = bounds.width - bounds.x; @@ -158,8 +156,7 @@ class PdfListLayouter extends ElementLayouter { final Rect finalBounds = Rect.fromLTWH(bounds.x, pageResult.y!, bounds.width, resultHeight ?? 0); if (currentPage != null) { - final PdfLayoutResult result = - PdfLayoutResultHelper.load(currentPage!, finalBounds); + final PdfLayoutResult result = PdfLayoutResultHelper.load(currentPage!, finalBounds); return result; } else { return null; @@ -182,8 +179,8 @@ class PdfListLayouter extends ElementLayouter { if (currentPage != null && !pageResult!.broken) { _beforeItemLayout(item, currentPage!); } - final Map returnedValue = _drawItem( - pageResult!, x, curList!, index, indent!, info, item, height!, y!); + final Map returnedValue = + _drawItem(pageResult!, x, curList!, index, indent!, info, item, height!, y!); pageResult = returnedValue['pageResult'] as _PageLayoutResult?; height = returnedValue['height'] as double?; y = returnedValue['y'] as double?; @@ -201,8 +198,8 @@ class PdfListLayouter extends ElementLayouter { if (curList is PdfOrderedList) { final PdfOrderedList oList = curList! as PdfOrderedList; PdfOrderedMarkerHelper.getHelper(oList.marker).currentIndex = index; - final ListInfo listInfo = ListInfo(curList, index, - PdfOrderedMarkerHelper.getHelper(oList.marker).getNumber()); + final ListInfo listInfo = ListInfo( + curList, index, PdfOrderedMarkerHelper.getHelper(oList.marker).getNumber()); listInfo.brush = currentBrush; listInfo.font = currentFont; listInfo.format = currentFormat; @@ -219,8 +216,7 @@ class PdfListLayouter extends ElementLayouter { } curList = item.subList; if (curList is PdfOrderedList) { - markerMaxWidth = - _getMarkerMaxWidth(curList! as PdfOrderedList, info); + markerMaxWidth = _getMarkerMaxWidth(curList! as PdfOrderedList, info); } index = -1; indent = indent! + curList!.indent; @@ -250,16 +246,8 @@ class PdfListLayouter extends ElementLayouter { } /// Draws the item. - Map _drawItem( - _PageLayoutResult pageResult, - double x, - PdfList curList, - int index, - double indent, - List listInfo, - PdfListItem item, - double height, - double y) { + Map _drawItem(_PageLayoutResult pageResult, double x, PdfList curList, int index, + double indent, List listInfo, PdfListItem item, double height, double y) { final PdfStringLayouter layouter = PdfStringLayouter(); PdfStringLayoutResult? markerResult; PdfStringLayoutResult? result; @@ -301,8 +289,7 @@ class PdfListLayouter extends ElementLayouter { itemFormat = item.stringFormat; } - if (((size.width <= 0) || (size.width < itemFont!.size)) && - currentPage != null) { + if (((size.width <= 0) || (size.width < itemFont!.size)) && currentPage != null) { throw Exception('There is not enough space to layout list.'); } size.height = size.height - height; @@ -325,8 +312,8 @@ class PdfListLayouter extends ElementLayouter { if (markerText != null && ((marker is PdfUnorderedMarker) && (marker.style == PdfUnorderedMarkerStyle.customString))) { - markerResult = layouter.layout(markerText, _getMarkerFont(marker, item)!, - _getMarkerFormat(marker, item), + markerResult = layouter.layout( + markerText, _getMarkerFont(marker, item)!, _getMarkerFormat(marker, item), width: size.width, height: size.height); posX += markerResult.size.width; pageResult.markerWidth = markerResult.size.width; @@ -353,11 +340,8 @@ class PdfListLayouter extends ElementLayouter { canDrawMarker = false; } } else { - posX += PdfUnorderedMarkerHelper.getHelper(marker as PdfUnorderedMarker) - .size! - .width; - pageResult.markerWidth = - PdfUnorderedMarkerHelper.getHelper(marker).size!.width; + posX += PdfUnorderedMarkerHelper.getHelper(marker as PdfUnorderedMarker).size!.width; + pageResult.markerWidth = PdfUnorderedMarkerHelper.getHelper(marker).size!.width; markerHeight = PdfUnorderedMarkerHelper.getHelper(marker).size!.height; if (currentPage != null) { @@ -380,8 +364,7 @@ class PdfListLayouter extends ElementLayouter { itemSize.width = itemSize.width - item.textIndent; } - if (((itemSize.width <= 0) || (itemSize.width < itemFont!.size)) && - currentPage != null) { + if (((itemSize.width <= 0) || (itemSize.width < itemFont!.size)) && currentPage != null) { throw Exception( 'There is not enough space to layout the item text. Marker is too long or there is no enough space to draw it.'); } @@ -412,19 +395,15 @@ class PdfListLayouter extends ElementLayouter { result = layouter.layout(text, itemFont!, itemFormat, width: itemSize.width, height: itemSize.height); - final PdfRectangle rect = - PdfRectangle(itemX, posY, itemSize.width, itemSize.height); - PdfGraphicsHelper.getHelper(graphics!).drawStringLayoutResult( - result, itemFont, itemPen, itemBrush, rect, itemFormat); + final PdfRectangle rect = PdfRectangle(itemX, posY, itemSize.width, itemSize.height); + PdfGraphicsHelper.getHelper(graphics!) + .drawStringLayoutResult(result, itemFont, itemPen, itemBrush, rect, itemFormat); y = posY; itemHeight = result.size.height; } height = (itemHeight < markerHeight) ? markerHeight : itemHeight; - final bool isRemainder = - (result!.remainder == null) || (result.remainder == ''); - if (!isRemainder || - (markerResult != null) && !isRemainder || - !canDrawMarker) { + final bool isRemainder = (result!.remainder == null) || (result.remainder == ''); + if (!isRemainder || (markerResult != null) && !isRemainder || !canDrawMarker) { y = 0; height = 0; pageResult.itemText = result.remainder; @@ -450,8 +429,7 @@ class PdfListLayouter extends ElementLayouter { pageResult.markerX = posX + itemSize.width - result.size.width; break; case PdfTextAlignment.center: - pageResult.markerX = - posX + (itemSize.width / 2) - (result.size.width / 2); + pageResult.markerX = posX + (itemSize.width / 2) - (result.size.width / 2); break; case PdfTextAlignment.left: case PdfTextAlignment.justify: @@ -475,35 +453,26 @@ class PdfListLayouter extends ElementLayouter { } } - if ((marker is PdfUnorderedMarker) && - marker.style == PdfUnorderedMarkerStyle.customString) { + if ((marker is PdfUnorderedMarker) && marker.style == PdfUnorderedMarkerStyle.customString) { if (markerResult != null) { - wroteMaker = - _drawMarker(curList, item, markerResult, posY, pageResult.markerX); + wroteMaker = _drawMarker(curList, item, markerResult, posY, pageResult.markerX); pageResult.markerWrote = true; pageResult.markerWidth = markerResult.size.width; } } else { if (canDrawMarker && !pageResult.markerWrote) { - wroteMaker = - _drawMarker(curList, item, markerResult, posY, pageResult.markerX); + wroteMaker = _drawMarker(curList, item, markerResult, posY, pageResult.markerX); pageResult.markerWrote = wroteMaker; if (curList is PdfOrderedList) { pageResult.markerWidth = markerResult!.size.width; } else { pageResult.markerWidth = - PdfUnorderedMarkerHelper.getHelper(marker as PdfUnorderedMarker) - .size! - .width; + PdfUnorderedMarkerHelper.getHelper(marker as PdfUnorderedMarker).size!.width; } } } - return { - 'pageResult': pageResult, - 'height': height, - 'y': y - }; + return {'pageResult': pageResult, 'height': height, 'y': y}; } /// Sets the current parameters. @@ -527,8 +496,8 @@ class PdfListLayouter extends ElementLayouter { double? width = -1; for (int i = 0; i < list.items.count; i++) { - final PdfStringLayoutResult result = _createOrderedMarkerResult( - list, list.items[i], i + list.marker.startNumber, info, true); + final PdfStringLayoutResult result = + _createOrderedMarkerResult(list, list.items[i], i + list.marker.startNumber, info, true); if (width! < result.size.width) { width = result.size.width; @@ -538,8 +507,8 @@ class PdfListLayouter extends ElementLayouter { } /// Creates the ordered marker result. - PdfStringLayoutResult _createOrderedMarkerResult(PdfList list, - PdfListItem? item, int index, List info, bool findMaxWidth) { + PdfStringLayoutResult _createOrderedMarkerResult( + PdfList list, PdfListItem? item, int index, List info, bool findMaxWidth) { PdfOrderedList orderedList = list as PdfOrderedList; PdfOrderedMarker marker = orderedList.marker; PdfOrderedMarkerHelper.getHelper(marker).currentIndex = index; @@ -578,8 +547,7 @@ class PdfListLayouter extends ElementLayouter { markerSize.width = markerMaxWidth! as double; markerFormat = _setMarkerStringFormat(marker, markerFormat); } - final PdfStringLayoutResult result = layouter.layout( - text, markerFont, markerFormat, + final PdfStringLayoutResult result = layouter.layout(text, markerFont, markerFormat, width: markerSize.width, height: markerSize.height); return result; } @@ -610,11 +578,8 @@ class PdfListLayouter extends ElementLayouter { } /// Sets the marker alingment. - PdfStringFormat _setMarkerStringFormat( - PdfOrderedMarker marker, PdfStringFormat? markerFormat) { - markerFormat = markerFormat == null - ? PdfStringFormat() - : _markerFormatClone(markerFormat); + PdfStringFormat _setMarkerStringFormat(PdfOrderedMarker marker, PdfStringFormat? markerFormat) { + markerFormat = markerFormat == null ? PdfStringFormat() : _markerFormatClone(markerFormat); if (marker.stringFormat == null) { markerFormat.alignment = PdfTextAlignment.right; if (PdfMarkerHelper.getHelper(marker).rightToLeft) { @@ -628,8 +593,8 @@ class PdfListLayouter extends ElementLayouter { } PdfStringFormat _markerFormatClone(PdfStringFormat format) { - final PdfStringFormat markerFormat = PdfStringFormat( - alignment: format.alignment, lineAlignment: format.lineAlignment); + final PdfStringFormat markerFormat = + PdfStringFormat(alignment: format.alignment, lineAlignment: format.lineAlignment); markerFormat.lineSpacing = format.lineSpacing; markerFormat.characterSpacing = format.characterSpacing; markerFormat.clipPath = format.clipPath; @@ -647,11 +612,9 @@ class PdfListLayouter extends ElementLayouter { } /// Before the page layout. - bool _beforePageLayout( - Rect currentBounds, PdfPage? currentPage, PdfList list) { + bool _beforePageLayout(Rect currentBounds, PdfPage? currentPage, PdfList list) { bool cancel = false; - if (PdfLayoutElementHelper.getHelper(element!).raiseBeginPageLayout && - currentPage != null) { + if (PdfLayoutElementHelper.getHelper(element!).raiseBeginPageLayout && currentPage != null) { final ListBeginPageLayoutArgs args = ListBeginPageLayoutArgs._(currentBounds, currentPage, list); @@ -664,13 +627,10 @@ class PdfListLayouter extends ElementLayouter { } /// After the page layouted. - ListEndPageLayoutArgs? _afterPageLayouted( - Rect bounds, PdfPage? currentPage, PdfList list) { + ListEndPageLayoutArgs? _afterPageLayouted(Rect bounds, PdfPage? currentPage, PdfList list) { ListEndPageLayoutArgs? args; - if (PdfLayoutElementHelper.getHelper(element!).raisePageLayouted && - currentPage != null) { - final PdfLayoutResult result = - PdfLayoutResultHelper.load(currentPage, bounds); + if (PdfLayoutElementHelper.getHelper(element!).raisePageLayouted && currentPage != null) { + final PdfLayoutResult result = PdfLayoutResultHelper.load(currentPage, bounds); args = ListEndPageLayoutArgs._internal(result, list); PdfLayoutElementHelper.getHelper(element!).onEndPageLayout(args); } @@ -679,8 +639,7 @@ class PdfListLayouter extends ElementLayouter { /// Before the item layout. void _beforeItemLayout(PdfListItem item, PdfPage page) { - final BeginItemLayoutArgs args = - BeginItemLayoutArgsHelper.internal(item, page); + final BeginItemLayoutArgs args = BeginItemLayoutArgsHelper.internal(item, page); PdfListHelper.getHelper(element!).onBeginItemLayout(args); } @@ -691,12 +650,11 @@ class PdfListLayouter extends ElementLayouter { } /// Draws the marker. - bool _drawMarker(PdfList curList, PdfListItem item, - PdfStringLayoutResult? markerResult, double posY, double posX) { + bool _drawMarker(PdfList curList, PdfListItem item, PdfStringLayoutResult? markerResult, + double posY, double posX) { if (curList is PdfOrderedList) { if (markerResult != null) { - if (curList.font != null && - curList.font!.size > markerResult.size.height) { + if (curList.font != null && curList.font!.size > markerResult.size.height) { posY += (curList.font!.size / 2) - (markerResult.size.height / 2); markerResult.size.height = markerResult.size.height + posY; } @@ -704,8 +662,7 @@ class PdfListLayouter extends ElementLayouter { _drawOrderedMarker(curList, markerResult!, item, posX, posY); } else if (curList is PdfUnorderedList) { if (curList.marker.font != null && markerResult != null) { - final PdfFont font = curList.font != null && - curList.font!.size > curList.marker.font!.size + final PdfFont font = curList.font != null && curList.font!.size > curList.marker.font!.size ? curList.font! : curList.marker.font!; if (font.size > markerResult.size.height) { @@ -719,20 +676,16 @@ class PdfListLayouter extends ElementLayouter { } /// Draws the ordered marker. - PdfStringLayoutResult _drawOrderedMarker( - PdfList curList, - PdfStringLayoutResult markerResult, - PdfListItem item, - double posX, - double posY) { + PdfStringLayoutResult _drawOrderedMarker(PdfList curList, PdfStringLayoutResult markerResult, + PdfListItem item, double posX, double posY) { final PdfOrderedList oList = curList as PdfOrderedList; final PdfOrderedMarker marker = oList.marker; final PdfFont markerFont = _getMarkerFont(marker, item)!; PdfStringFormat? markerFormat = _getMarkerFormat(marker, item); final PdfPen? markerPen = _getMarkerPen(marker, item); final PdfBrush? markerBrush = _getMarkerBrush(marker, item); - final PdfRectangle rect = PdfRectangle(posX - markerMaxWidth!, posY, - markerResult.size.width, markerResult.size.height); + final PdfRectangle rect = PdfRectangle( + posX - markerMaxWidth!, posY, markerResult.size.width, markerResult.size.height); rect.width = markerMaxWidth! as double; markerFormat = _setMarkerStringFormat(marker, markerFormat); PdfGraphicsHelper.getHelper(graphics!).drawStringLayoutResult( @@ -741,12 +694,8 @@ class PdfListLayouter extends ElementLayouter { } /// Draws the unordered marker. - PdfStringLayoutResult? _drawUnorderedMarker( - PdfList curList, - PdfStringLayoutResult? markerResult, - PdfListItem item, - double posX, - double posY) { + PdfStringLayoutResult? _drawUnorderedMarker(PdfList curList, PdfStringLayoutResult? markerResult, + PdfListItem item, double posX, double posY) { final PdfUnorderedList uList = curList as PdfUnorderedList; final PdfUnorderedMarker marker = uList.marker; final PdfFont? markerFont = _getMarkerFont(marker, item); @@ -757,15 +706,10 @@ class PdfListLayouter extends ElementLayouter { final PdfPoint location = PdfPoint(posX - markerResult.size.width, posY); PdfUnorderedMarkerHelper.getHelper(marker).size = markerResult.size; if (marker.style == PdfUnorderedMarkerStyle.customString) { - final PdfRectangle rect = PdfRectangle(location.x, location.y, - markerResult.size.width, markerResult.size.height); + final PdfRectangle rect = + PdfRectangle(location.x, location.y, markerResult.size.width, markerResult.size.height); PdfGraphicsHelper.getHelper(graphics!).drawStringLayoutResult( - markerResult, - markerFont!, - markerPen, - markerBrush, - rect, - markerFormat); + markerResult, markerFont!, markerPen, markerBrush, rect, markerFormat); } else { PdfUnorderedMarkerHelper.getHelper(marker).unicodeFont = PdfStandardFont(PdfFontFamily.zapfDingbats, markerFont!.size); @@ -773,8 +717,7 @@ class PdfListLayouter extends ElementLayouter { .draw(graphics, location.offset, markerBrush, markerPen); } } else { - PdfUnorderedMarkerHelper.getHelper(marker).size = - PdfSize(markerFont!.size, markerFont.size); + PdfUnorderedMarkerHelper.getHelper(marker).size = PdfSize(markerFont!.size, markerFont.size); final PdfPoint location = PdfPoint(posX - markerFont.size, posY); PdfUnorderedMarkerHelper.getHelper(marker) .draw(graphics, location.offset, markerBrush, markerPen, curList); @@ -811,8 +754,7 @@ class PdfListLayouter extends ElementLayouter { int index, PdfList curList, List listInfo, PdfListItem item) { PdfStringLayoutResult? markerResult; if (curList is PdfOrderedList) { - markerResult = - _createOrderedMarkerResult(curList, item, index, info, false); + markerResult = _createOrderedMarkerResult(curList, item, index, info, false); } else { final PdfSize markerSize = PdfSize.empty; markerResult = _createUnorderedMarkerResult(curList, item, markerSize); @@ -843,14 +785,10 @@ class PdfListLayouter extends ElementLayouter { break; // ignore: no_default_cases default: - final PdfStandardFont uFont = - PdfStandardFont(PdfFontFamily.zapfDingbats, markerFont!.size); + final PdfStandardFont uFont = PdfStandardFont(PdfFontFamily.zapfDingbats, markerFont!.size); result = layouter.layout( - PdfUnorderedMarkerHelper.getHelper(marker).getStyledText(), - uFont, - null, - width: size.width, - height: size.height); + PdfUnorderedMarkerHelper.getHelper(marker).getStyledText(), uFont, null, + width: size.width, height: size.height); PdfUnorderedMarkerHelper.getHelper(marker).size = result.size; if (marker.pen != null) { result.size = PdfSize(result.size.width + 2 * marker.pen!.width, @@ -929,8 +867,7 @@ class ListBeginPageLayoutArgs extends BeginPageLayoutArgs { /// [ListBeginPageLayoutArgs] helper class ListBeginPageLayoutArgsHelper { /// internal method - static ListBeginPageLayoutArgs internal( - Rect bounds, PdfPage page, PdfList list) { + static ListBeginPageLayoutArgs internal(Rect bounds, PdfPage page, PdfList list) { return ListBeginPageLayoutArgs._(bounds, page, list); } } diff --git a/packages/syncfusion_flutter_pdf/pubspec.lock b/packages/syncfusion_flutter_pdf/pubspec.lock new file mode 100644 index 000000000..4492710c7 --- /dev/null +++ b/packages/syncfusion_flutter_pdf/pubspec.lock @@ -0,0 +1,149 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: "direct main" + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: "direct main" + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + http: + dependency: "direct main" + description: + name: http + sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f + url: "https://pub.dev" + source: hosted + version: "1.3.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + meta: + dependency: transitive + description: + name: meta + sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + url: "https://pub.dev" + source: hosted + version: "1.16.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646" + url: "https://pub.dev" + source: hosted + version: "6.1.0" + pure_dart_ui: + dependency: "direct main" + description: + name: pure_dart_ui + sha256: "0591dc1774a3f9e1d1ea2685a527d027707877717b47639127dd95b253594771" + url: "https://pub.dev" + source: hosted + version: "0.1.10" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + xml: + dependency: "direct main" + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" +sdks: + dart: ">=3.5.0 <4.0.0" diff --git a/packages/syncfusion_flutter_pdf/pubspec.yaml b/packages/syncfusion_flutter_pdf/pubspec.yaml index 12ff09f7c..3fc82bf91 100644 --- a/packages/syncfusion_flutter_pdf/pubspec.yaml +++ b/packages/syncfusion_flutter_pdf/pubspec.yaml @@ -7,16 +7,11 @@ environment: sdk: '>=3.4.0 <4.0.0' dependencies: - flutter: - sdk: flutter intl: '>=0.18.0 <0.21.0' xml: ">=6.5.0 <7.0.0" - syncfusion_flutter_core: - path: ../syncfusion_flutter_core - - crypto: ">=3.0.0 <4.0.0" convert: ">=3.0.0 <4.0.0" - http: ^1.2.1 + pure_dart_ui: ">=0.1.0 <0.2.0" + http: ">=1.2.1 <2.0.0" From 127789e1c2e4974668fea9c3d1b6a0c121ae384c Mon Sep 17 00:00:00 2001 From: LucazzP Date: Mon, 7 Apr 2025 13:17:04 -0300 Subject: [PATCH 13/13] Fixed last file pdf --- .../pdf/implementation/annotations/pdf_action_annotation.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_action_annotation.dart b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_action_annotation.dart index d1e2ee659..21e7ee4cc 100644 --- a/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_action_annotation.dart +++ b/packages/syncfusion_flutter_pdf/lib/src/pdf/implementation/annotations/pdf_action_annotation.dart @@ -1,4 +1,4 @@ -import 'dart:ui'; +import 'package:pure_dart_ui/pure_dart_ui.dart'; import '../../interfaces/pdf_interface.dart'; import '../actions/pdf_action.dart';