Skip to content

Commit

Permalink
Merge branch 'master' into pdfa_3b_ilja
Browse files Browse the repository at this point in the history
# Conflicts:
#	pdf/lib/src/pdf/obj/catalog.dart
  • Loading branch information
ilaurillard committed Sep 27, 2024
2 parents 8e1b106 + 2ea8ef6 commit bfa75ba
Show file tree
Hide file tree
Showing 23 changed files with 19,980 additions and 8,356 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: stable
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
- name: Enable Linux for flutter
run: flutter config --enable-linux-desktop
- name: Update repo
Expand All @@ -28,7 +33,7 @@ jobs:
- name: Run readme tests
run: make test-readme
- name: Verify that nothing changed
run: test -z "$(git status --porcelain)"
run: test -z "$(git status --porcelain | tee /dev/stderr)"
- name: Push to codecov
run: bash <(curl -s https://codecov.io/bash)
- name: Prepare build
Expand Down Expand Up @@ -81,6 +86,11 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: master
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17
- name: Enable Linux for flutter
run: flutter config --enable-linux-desktop
- name: Update repo
Expand All @@ -94,7 +104,7 @@ jobs:
- name: Run readme tests
run: make test-readme
- name: Verify that nothing changed
run: test -z "$(git status --porcelain)"
run: test -z "$(git status --porcelain | tee /dev/stderr)"
- name: Push to codecov
run: bash <(curl -s https://codecov.io/bash)
- name: Prepare build
Expand Down
4 changes: 4 additions & 0 deletions demo/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include "generated_plugin_registrant.h"

#include <open_file_linux/open_file_linux_plugin.h>
#include <printing/printing_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) open_file_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "OpenFileLinuxPlugin");
open_file_linux_plugin_register_with_registrar(open_file_linux_registrar);
g_autoptr(FlPluginRegistrar) printing_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PrintingPlugin");
printing_plugin_register_with_registrar(printing_registrar);
Expand Down
1 change: 1 addition & 0 deletions demo/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
open_file_linux
printing
url_launcher_linux
)
Expand Down
2 changes: 1 addition & 1 deletion demo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:

dev_dependencies:
# flutter_launcher_icons: ^0.10.0
flutter_lints: ^4.0.0
flutter_lints: ^5.0.0
flutter_test:
sdk: flutter
test:
Expand Down
5 changes: 5 additions & 0 deletions pdf/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.11.1

- Fixed display problems with textfields [ilaurillard]
- Tighten dependencies

## 3.11.0

- Save in an isolate when available
Expand Down
4 changes: 3 additions & 1 deletion pdf/lib/src/pdf/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import 'format/stream.dart';
import 'format/string.dart';
import 'format/xref.dart';
import 'graphic_state.dart';
import 'io/vm.dart' if (dart.library.js) 'io/js.dart';
import 'io/na.dart'
if (dart.library.io) 'io/vm.dart'
if (dart.library.js_interop) 'io/js.dart';
import 'obj/catalog.dart';
import 'obj/encryption.dart';
import 'obj/font.dart';
Expand Down
26 changes: 26 additions & 0 deletions pdf/lib/src/pdf/io/na.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2017, David PHAM-VAN <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import '../format/object_base.dart';

/// Zip compression function
DeflateCallback defaultDeflate = (List<int> a) => a;

/// Computation function
Future<R> pdfCompute<R>(Future<R> Function() computation) async {
await null;
return computation();
}
11 changes: 4 additions & 7 deletions pdf/lib/src/pdf/obj/catalog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,17 @@ class PdfCatalog extends PdfObject<PdfDict> {
for (final w in widgets) {
if (w.annot is PdfTextField) {
// collect textfield font references
PdfTextField tf = w.annot as PdfTextField;
fontRefs.addAll(PdfDict.values(
{tf.font.name: tf.font.ref()}
));
final tf = w.annot as PdfTextField;
fontRefs.addAll(PdfDict.values({tf.font.name: tf.font.ref()}));
}
final ref = w.ref();
if (!fields.values.contains(ref)) {
fields.add(ref);
}
}
if (fontRefs.isNotEmpty) {
acroForm['/DR'] = PdfDict.values( // "Document Resources"
{'/Font': fontRefs}
);
acroForm['/DR'] = PdfDict.values(// "Document Resources"
{'/Font': fontRefs});
}
}

Expand Down
4 changes: 2 additions & 2 deletions pdf/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ topics:
- print
- printing
- report
version: 3.11.0
version: 3.11.1

environment:
sdk: ">=2.19.0 <4.0.0"

dependencies:
archive: ^3.1.0
archive: ^3.4.0
barcode: ">=2.2.3 <3.0.0"
bidi: ^2.0.10
crypto: ^3.0.0
Expand Down
10 changes: 10 additions & 0 deletions printing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Changelog

## 5.13.3

- Update gfonts [Minh-Danh]
- Add compatibility with web 1.1.0

## 5.13.2

- Added new printing output type value on iOS [Matteo Ricupero]
- Workaround for iOS bug and force paper size [Matteo Ricupero]
- Update package:web [Sabin Neupane]
- Force the latest version of pdf_widget_wrapper
- Tighten dependencies
- Update Android build settings

## 5.13.1

Expand Down
23 changes: 12 additions & 11 deletions printing/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'net.nfet.flutter.printing'
version '1.0'
group "net.nfet.flutter.printing"
version "1.0"

buildscript {
repositories {
Expand All @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "com.android.tools.build:gradle:7.3.0"
}
}

Expand All @@ -19,24 +19,25 @@ rootProject.allprojects {
}
}

apply plugin: 'com.android.library'
apply plugin: "com.android.library"

android {
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'net.nfet.flutter.printing'
namespace = "net.nfet.flutter.printing"
}
compileSdkVersion 30

compileSdk = 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
minSdk = 21
}

lintOptions {
disable 'InvalidPackage'
disable "InvalidPackage"
}
}
10 changes: 10 additions & 0 deletions printing/ios/Classes/CustomPrintPaper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class CustomPrintPaper: UIPrintPaper {
private let size: CGSize

override public var paperSize: CGSize { return size }
override public var printableRect: CGRect { return CGRect(origin: CGPoint.zero, size: size) }

init(size: CGSize) {
self.size = size
}
}
23 changes: 22 additions & 1 deletion printing/ios/Classes/PrintJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func dataProviderReleaseDataCallback(info _: UnsafeMutableRawPointer?, data: Uns
// Each printer will be identified by its URL string
var selectedPrinters = [String: UIPrinter]()

// Holds the printer after it was picked
var pickedPrinter: UIPrinter?

public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate {
private var printing: PrintingPlugin
public var index: Int
Expand All @@ -36,6 +39,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
private let semaphore = DispatchSemaphore(value: 0)
private var dynamic = false
private var currentSize: CGSize?
private var forceCustomPrintPaper = false

public init(printing: PrintingPlugin, index: Int) {
self.printing = printing
Expand Down Expand Up @@ -149,6 +153,10 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
return paperList[0]
}

if forceCustomPrintPaper {
return CustomPrintPaper(size: currentSize!)
}

for paper in paperList {
if (paper.paperSize.width == currentSize!.width && paper.paperSize.height == currentSize!.height) ||
(paper.paperSize.width == currentSize!.height && paper.paperSize.height == currentSize!.width)
Expand All @@ -162,9 +170,11 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
return bestPaper
}

func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool, outputType type: UIPrintInfo.OutputType) {
func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool, outputType type: UIPrintInfo.OutputType, forceCustomPrintPaper: Bool = false) {
currentSize = size
dynamic = dyn
self.forceCustomPrintPaper = forceCustomPrintPaper

let printing = UIPrintInteractionController.isPrintingAvailable
if !printing {
self.printing.onCompleted(printJob: self, completed: false, error: "Printing not available")
Expand Down Expand Up @@ -207,6 +217,14 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
selectedPrinters[printerURLString] = UIPrinter(url: printerURL!)
}

// Sometimes using UIPrinter(url:) gives a non-contactable printer.
// https://stackoverflow.com/questions/34602302/creating-a-working-uiprinter-object-from-url-for-dialogue-free-printing
// This lets use a printer saved during picking and fall back using a printer created with UIPrinter(url:)
if pickedPrinter != nil && selectedPrinters[printerURLString]!.url == pickedPrinter?.url {
controller.print(to: pickedPrinter!, completionHandler: completionHandler)
return
}

selectedPrinters[printerURLString]!.contactPrinter { available in
if !available {
self.printing.onCompleted(printJob: self, completed: false, error: "Printer not available")
Expand Down Expand Up @@ -328,6 +346,9 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
"model": printer.makeAndModel as Any,
"location": printer.displayLocation as Any,
]

pickedPrinter = printer

result(data)
}

Expand Down
4 changes: 3 additions & 1 deletion printing/ios/Classes/PrintingPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
let marginBottom = CGFloat((args["marginBottom"] as! NSNumber).floatValue)
let printJob = PrintJob(printing: self, index: args["job"] as! Int)
let dynamic = args["dynamic"] as! Bool
let forceCustomPrintPaper = args["forceCustomPrintPaper"] as! Bool

let outputType: UIPrintInfo.OutputType
switch args["outputType"] as! Int {
Expand Down Expand Up @@ -89,7 +90,8 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
),
withPrinter: printer,
dynamically: dynamic,
outputType: outputType)
outputType: outputType,
forceCustomPrintPaper: forceCustomPrintPaper)
result(NSNumber(value: 1))
} else if call.method == "sharePdf" {
let object = args["doc"] as! FlutterStandardTypedData
Expand Down
17 changes: 12 additions & 5 deletions printing/lib/printing_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ class PrintingPlugin extends PrintingPlatform {

// Restore module and exports
if (module != null) {
web.window['module'] = module;
web.window.module = module;
}
if (exports != null) {
web.window['exports'] = exports;
web.window.exports = exports;
}
}

Expand All @@ -158,6 +158,7 @@ class PrintingPlugin extends PrintingPlatform {
bool dynamicLayout,
bool usePrinterSettings,
OutputType outputType,
bool forceCustomPrintPaper,
) async {
late Uint8List result;
try {
Expand Down Expand Up @@ -191,8 +192,8 @@ class PrintingPlugin extends PrintingPlatform {
}

final userAgent = web.window.navigator.userAgent;
final isChrome = web.window['chrome'] != null;
final isSafari = web.window['safari'] != null &&
final isChrome = web.window['chrome'].isUndefinedOrNull;
final isSafari = web.window['safari'].isUndefinedOrNull &&
!userAgent.contains(RegExp(r'Version/14\.1\.'));
final isMobile = userAgent.contains('Mobile');
final isFirefox = userAgent.contains('Firefox');
Expand All @@ -212,7 +213,8 @@ class PrintingPlugin extends PrintingPlatform {
script.setAttribute('id', _scriptId);
script.setAttribute('type', 'text/javascript');
script.innerHTML =
'''function ${_frameId}_print(){var f=document.getElementById('$_frameId');f.focus();f.contentWindow.print();}''';
'''function ${_frameId}_print(){var f=document.getElementById('$_frameId');f.focus();f.contentWindow.print();}'''
.toJS;
doc.body!.append(script);

final frame = doc.getElementById(_frameId) ?? doc.createElement('iframe');
Expand Down Expand Up @@ -437,3 +439,8 @@ class _WebPdfRaster extends PdfRaster {
return png;
}
}

extension _WindowModule on web.Window {
external set module(js.JSObject? value);
external set exports(js.JSObject? value);
}
Loading

0 comments on commit bfa75ba

Please sign in to comment.