diff --git a/packages/pdfx/ohos/src/main/ets/dev/flutter/pigeon/Pigeon.ets b/packages/pdfx/ohos/src/main/ets/dev/flutter/pigeon/Pigeon.ets deleted file mode 100644 index 6bfbe6746124e40475d227b873c81729d8fd8734..0000000000000000000000000000000000000000 --- a/packages/pdfx/ohos/src/main/ets/dev/flutter/pigeon/Pigeon.ets +++ /dev/null @@ -1,1007 +0,0 @@ -/** - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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 AbilityAware from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityAware'; -import { AbilityPluginBinding } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/ability/AbilityPluginBinding'; -import { FlutterPlugin, FlutterPluginBinding } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; -import { MethodCallHandler, MethodResult } from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; -import MethodChannel from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodChannel'; -import MethodCall from '@ohos/flutter_ohos/src/main/ets/plugin/common/MethodCall'; -import Log from '@ohos/flutter_ohos/src/main/ets/util/Log'; -import HashMap from '@ohos.util.HashMap'; -import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec'; -import { ByteBuffer } from '@ohos/flutter_ohos/src/main/ets/util/ByteBuffer'; -import MessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/MessageCodec'; -import { BinaryMessenger } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BinaryMessenger'; -import BasicMessageChannel, { Reply } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel'; - - - -export class OpenDataMessage{ - - private data: Uint8Array; - - constructor(data: Uint8Array) { - this.data = data; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("data", this.data); - return toMapResult; - } - - static fromMap(map: Map): OpenDataMessage{ - const data = map.get("data") as Uint8Array; - return new OpenDataMessage(data); - } - -} - -class OpenPathMessage { - - private path : string; - -/* setPath(path : string){ - this.path = path; - } - - getPath(): string { - return this.path; - }*/ - - private password : string; - -/* setPassword(password : string){ - this.password = password; - } - - getPassword(): string { - return this.password; - }*/ - - constructor(path : string, password : string) { - this.path = path; - this.password = password; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("path", this.path); - toMapResult.set("password", this.password); - return toMapResult; - } - - static fromMap(map: Map): OpenPathMessage{ - const path = map.get("path") as string; - const password = map.get("password") as string; - return new OpenPathMessage(path,password); - } - -} - -class OpenReply { - - private id : string; - - private pagesCount : number; - - constructor(id : string, pagesCount : number) { - this.id = id; - this.pagesCount = pagesCount; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("id", this.id); - toMapResult.set("pagesCount", this.pagesCount); - return toMapResult; - } - - static fromMap(map: Map): OpenReply{ - const path = map.get("id") as string; - const pagesCount = map.get("pagesCount") as number; - return new OpenReply(path,pagesCount); - } -} - -class IdMessage { - - private id : string; - - - constructor(id : string) { - this.id = id; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("id", this.id); - return toMapResult; - } - - static fromMap(map: Map): IdMessage{ - const path = map.get("id") as string; - return new IdMessage(path); - } -} - - -class GetPageMessage { - - private documentId : string; - - private pageNumber : number; - - private autoCloseOhOs : boolean; - - constructor(documentId : string, pageNumber : number, autoCloseOhOs : boolean) { - this.documentId = documentId; - this.pageNumber = pageNumber; - this.autoCloseOhOs = autoCloseOhOs; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("documentId", this.documentId); - toMapResult.set("pageNumber", this.pageNumber); - toMapResult.set("autoCloseOhOs", this.autoCloseOhOs); - return toMapResult; - } - - static fromMap(map: Map): GetPageMessage{ - const documentId = map.get("documentId") as string; - const pageNumber = map.get("pageNumber") as number; - const autoCloseOhOs = map.get("autoCloseOhOs") as boolean; - return new GetPageMessage(documentId,pageNumber,autoCloseOhOs); - } -} - -class GetPageReply { - - private id : string; - - private width : number; - - private height : number; - - constructor(id : string, width : number, height : number) { - this.id = id; - this.width = width; - this.height = height; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("id", this.id); - toMapResult.set("width", this.width); - toMapResult.set("height", this.height); - return toMapResult; - } - - static fromMap(map: Map): GetPageReply{ - const id = map.get("id") as string; - const width = map.get("width") as number; - const height = map.get("height") as number; - return new GetPageReply(id,width,height); - } -} - -class RenderPageMessage { - - private pageId : string; - - private width : number; - - private height : number; - - private format : number; - - private backgroundColor : string; - - private crop : boolean; - - private cropX : number; - - private cropY : number; - - private cropHeight : number; - - private cropWidth : number; - - private quality : number; - - private forPrint : boolean; - - - constructor(pageId : string, width : number, height : number, format : number, backgroundColor : string, crop : boolean, - cropX : number, cropY : number, cropHeight : number, cropWidth : number, quality : number,forPrint : boolean ) { - this.pageId = pageId; - this.width = width; - this.height = height; - this.format = format; - this.backgroundColor = backgroundColor; - this.crop = crop; - this.cropX = cropX; - this.cropY = cropY; - this.cropHeight = cropHeight; - this.cropWidth = cropWidth; - this.quality = quality; - this.forPrint = forPrint; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("pageId", this.pageId); - toMapResult.set("width", this.width); - toMapResult.set("height", this.height); - toMapResult.set("format", this.format); - toMapResult.set("backgroundColor", this.backgroundColor); - toMapResult.set("crop", this.crop); - toMapResult.set("cropX", this.cropX); - toMapResult.set("cropY", this.cropY); - toMapResult.set("cropHeight", this.cropHeight); - toMapResult.set("cropWidth", this.cropWidth); - toMapResult.set("quality", this.quality); - toMapResult.set("forPrint", this.forPrint); - - return toMapResult; - } - - static fromMap(map: Map): RenderPageMessage{ - const pageId = map.get("pageId") as string; - const width = map.get("width") as number; - const height = map.get("height") as number; - const format = map.get("format") as number; - const backgroundColor = map.get("backgroundColor") as string; - const crop = map.get("crop") as boolean; - const cropX = map.get("cropX") as number; - const cropY = map.get("cropY") as number; - const cropHeight = map.get("cropHeight") as number; - const cropWidth = map.get("cropWidth") as number; - const quality = map.get("quality") as number; - const forPrint = map.get("forPrint") as boolean; - return new RenderPageMessage(pageId,width,height,format,backgroundColor,crop,cropX,cropY,cropHeight,cropWidth,quality,forPrint); - } - -} - -class RenderPageReply { - - private width : number; - - private height : number; - - private path : string; - - private data : Uint8Array; - - - constructor(width : number, height : number, path : string, data : Uint8Array) { - this.width = width; - this.height = height; - this.path = path; - this.data = data; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("width", this.width); - toMapResult.set("height", this.height); - toMapResult.set("path", this.path); - toMapResult.set("data", this.data); - return toMapResult; - } - - static fromMap(map: Map): RenderPageReply{ - const width = map.get("width") as number; - const height = map.get("height") as number; - const path = map.get("path") as string; - const data = map.get("data") as Uint8Array; - return new RenderPageReply(width,height,path,data); - } - -} - -class RegisterTextureReply { - - private id : number; - - constructor(id : number) { - this.id = id; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("id", this.id); - return toMapResult; - } - - static fromMap(map: Map): RegisterTextureReply{ - const id = map.get("id") as number; - return new RegisterTextureReply(id); - } -} - -class UpdateTextureMessage { - - private documentId : string; - - private pageNumber : number; - - private pageId : string; - - private textureId : number; - - private width : number; - - private height : number; - - private backgroundColor : string; - - private sourceX : number; - - private sourceY : number; - - private destinationX : number; - - private destinationY : number; - - private fullWidth : number; - - private fullHeight : number; - - private textureWidth : number; - - private textureHeight : number; - - private allowAntiAliasing : boolean; - - constructor(documentId : string, pageNumber : number, pageId : string, textureId : number, width : number, height : number, - backgroundColor : string, sourceX : number, sourceY : number, destinationX : number, destinationY : number, - fullWidth : number, fullHeight : number, textureWidth : number, textureHeight : number, allowAntiAliasing : boolean) { - this.documentId = documentId; - this.pageNumber = pageNumber; - this.pageId = pageId; - this.textureId = textureId; - this.width = width; - this.height = height; - this.backgroundColor = backgroundColor; - this.sourceX = sourceX; - this.sourceY = sourceY; - this.destinationX = destinationX; - this.destinationY = destinationY; - this.fullWidth = fullWidth; - this.fullHeight = fullHeight; - this.textureWidth = textureWidth; - this.textureHeight = textureHeight; - this.allowAntiAliasing = allowAntiAliasing; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("documentId", this.documentId); - toMapResult.set("pageNumber", this.pageNumber); - toMapResult.set("pageId", this.pageId); - toMapResult.set("textureId", this.textureId); - toMapResult.set("width", this.width); - toMapResult.set("height", this.height); - toMapResult.set("backgroundColor", this.backgroundColor); - toMapResult.set("sourceX", this.sourceX); - toMapResult.set("sourceY", this.sourceY); - toMapResult.set("destinationX", this.destinationX); - toMapResult.set("destinationY", this.destinationY); - toMapResult.set("fullWidth", this.fullWidth); - toMapResult.set("fullHeight", this.fullHeight); - toMapResult.set("textureWidth", this.textureWidth); - toMapResult.set("textureHeight", this.textureHeight); - toMapResult.set("allowAntiAliasing", this.allowAntiAliasing); - return toMapResult; - } - - static fromMap(map: Map): UpdateTextureMessage{ - const documentId = map.get("documentId") as string; - const pageNumber = map.get("pageNumber") as number; - const pageId = map.get("pageId") as string; - const textureId = map.get("textureId") as number; - const width = map.get("width") as number; - const height = map.get("height") as number; - const backgroundColor = map.get("backgroundColor") as string; - const sourceX = map.get("sourceX") as number; - const sourceY = map.get("sourceY") as number; - const destinationX = map.get("destinationX") as number; - const destinationY = map.get("destinationY") as number; - const fullWidth = map.get("fullWidth") as number; - const fullHeight = map.get("fullHeight") as number; - const textureWidth = map.get("textureWidth") as number; - const textureHeight = map.get("textureHeight") as number; - const allowAntiAliasing = map.get("allowAntiAliasing") as boolean; - return new UpdateTextureMessage(documentId,pageNumber,pageId,textureId,width,height,backgroundColor,sourceX,sourceY, - destinationX,destinationY,fullWidth,fullHeight,textureWidth,textureHeight,allowAntiAliasing); - } -} - -class ResizeTextureMessage { - - private textureId : number; - - private width : number; - - private height : number; - - constructor(textureId : number, width : number, height : number) { - this.textureId = textureId; - this.width = width; - this.height = height; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("textureId", this.textureId); - toMapResult.set("width", this.width); - toMapResult.set("height", this.height); - return toMapResult; - } - - static fromMap(map: Map): ResizeTextureMessage{ - const textureId = map.get("textureId") as number; - const width = map.get("width") as number; - const height = map.get("height") as number; - return new ResizeTextureMessage(textureId,width,height); - } -} - -class UnregisterTextureMessage { - - private id : number; - - constructor(id : number) { - this.id = id; - } - - toMap(): Map{ - const toMapResult = new Map(); - toMapResult.set("id", this.id); - return toMapResult; - } - - static fromMap(map: Map): UnregisterTextureMessage{ - const id = map.get("id") as number; - return new UnregisterTextureMessage(id); - } -} - -export interface Result { - success: (result: T) => void; - - error: (error: Error) => void; -} - - class PdfxApiCodec extends StandardMessageCodec { - - public static INSTANCE :PdfxApiCodec = new PdfxApiCodec(); - - readValueOfType(type: number, buffer: ByteBuffer): ESObject { - switch (type) { - case 128: - return GetPageMessage.fromMap(super.readValue(buffer)); - - case 129: - return GetPageReply.fromMap(super.readValue(buffer)); - - case 130: - return IdMessage.fromMap(super.readValue(buffer)); - - case 131: - return OpenDataMessage.fromMap(super. readValue(buffer)); - - case 132: - return OpenPathMessage.fromMap(super.readValue(buffer)); - - case 133: - return OpenReply.fromMap(super.readValue(buffer)); - - case 134: - return RegisterTextureReply.fromMap(super.readValue(buffer)); - - case 135: - return RenderPageMessage.fromMap(super.readValue(buffer)); - - case 136: - return RenderPageReply.fromMap(super.readValue(buffer)); - - case 137: - return ResizeTextureMessage.fromMap(super.readValue(buffer)); - - case 138: - return UnregisterTextureMessage.fromMap(super.readValue(buffer)); - - case 139: - return UpdateTextureMessage.fromMap(super.readValue(buffer)); - - default: - return super.readValueOfType(type, buffer); - - } - - } - - writeValue(stream: ByteBuffer, value: ESObject): ESObject { - - if (value instanceof GetPageMessage) { - stream.writeInt8(128); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof GetPageReply) { - stream.writeInt8(129); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof IdMessage) { - stream.writeInt8(130); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof OpenDataMessage) { - stream.writeInt8(131); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof OpenPathMessage) { - stream.writeInt8(132); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof OpenReply) { - stream.writeInt8(133); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof RegisterTextureReply) { - stream.writeInt8(134); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof RenderPageMessage) { - stream.writeInt8(135); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof RenderPageReply) { - stream.writeInt8(136); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof ResizeTextureMessage) { - stream.writeInt8(137); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof UnregisterTextureMessage) { - stream.writeInt8(138); - super.writeValue(stream, value.toMap()); - } else - if (value instanceof UpdateTextureMessage) { - stream.writeInt8(139); - super.writeValue(stream, value.toMap()); - } else - { - super.writeValue(stream, value); - } - - } -} - -export abstract class PdfxApi { - - abstract openDocumentData(message :OpenDataMessage , result:Result) : void; - - abstract openDocumentFile(message: OpenPathMessage, result: Result) : void; - - abstract openDocumentAsset(message: OpenPathMessage, result: Result) : void; - - abstract closeDocument(message: IdMessage) : void; - - abstract getPage(message: GetPageMessage, result: Result) : void; - - abstract renderPage(message: RenderPageMessage, result: Result ) : void; - - abstract closePage(message: IdMessage) : void; - - abstract registerTexture(): RegisterTextureReply; - - abstract updateTexture(message: UpdateTextureMessage, result: Result ) : void; - - abstract resizeTexture(message: ResizeTextureMessage, result: Result) : void; - - abstract unregisterTexture(message: UnregisterTextureMessage ) : void; - - static getCodec() : MessageCodec{ - return PdfxApiCodec.INSTANCE; - } - - setup(binaryMessenger: BinaryMessenger,api: PdfxApi):void{ - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.openDocumentData",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { - onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: OpenDataMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: OpenReply): void => { - wrapped.set("result", result); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.openDocumentData(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.openDocumentFile",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: OpenPathMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: OpenReply): void => { - wrapped.set("result", result); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.openDocumentFile(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.openDocumentAsset",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: OpenPathMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: OpenReply): void => { - wrapped.set("result", result); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.openDocumentAsset(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.closeDocument",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: IdMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - api.closeDocument(messageArg); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - } - reply.reply(wrapped); - } - }); - } else { - channel.setMessageHandler(null); - } - } - - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.getPage",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: GetPageMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: GetPageReply): void => { - wrapped.set("result", result); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.getPage(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.renderPage",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: RenderPageMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: RenderPageReply): void => { - wrapped.set("result", result); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.renderPage(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.closePage",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: IdMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - api.closePage(messageArg); - wrapped.set("result", null); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - } - reply.reply(wrapped); - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.registerTexture",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const output = api.registerTexture(); - wrapped.set("result", output); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - } - reply.reply(wrapped); - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.updateTexture",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: UpdateTextureMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: void): void => { - wrapped.set("result", null); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.updateTexture(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.resizeTexture",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: ResizeTextureMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - const resultCallback: Result = - { - success: (result: void): void => { - wrapped.set("result", null); - reply.reply(wrapped); - }, - - error: (error: Error): void => { - wrapped.set("error", PdfxApi.wrapError(error)); - reply.reply(wrapped); - } - }; - api.resizeTexture(messageArg,resultCallback); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - { - const channel: BasicMessageChannel = - new BasicMessageChannel(binaryMessenger,"dev.flutter.pigeon.PdfxApi.unregisterTexture",PdfxApi.getCodec()); - if (api != null) { - channel.setMessageHandler( - { onMessage: (message: ESObject, reply: Reply) => { - let wrapped: Map = new Map(); - try { - const args: Array = message; - const messageArg: UnregisterTextureMessage = args[0]; - if (messageArg == null) { - throw new Error("messageArg unexpectedly null.") - } - - api.unregisterTexture(messageArg); - wrapped.set("result", null); - } catch (err) { - wrapped.set("error", PdfxApi.wrapError(err)); - reply.reply(wrapped); - } - } - }); - } else { - channel.setMessageHandler(null); - } - } - - } - - - static wrapError(exception: Error): Map { - const errorMap: Map = new Map(); - errorMap.set("message",exception.message); - errorMap.set("code", exception.name); - errorMap.set("details", exception.stack); - return errorMap; - } - -} - diff --git a/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Messages.ets b/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Messages.ets index 74e51762b9052472aeedddfa5aef5ed9a69585ff..01b698c646a690d6ad474931449d2251ee23ddd9 100644 --- a/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Messages.ets +++ b/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Messages.ets @@ -142,20 +142,28 @@ export class Messages extends PdfxApi { } } - getPage(message: GetPageMessage): GetPageReply { + getPage(message: GetPageMessage, result: Result): void { const resultResponse = new GetPageReply() - const documentId = message.documentId!!; - const pageNumber = message.pageNumber!!; - - const pageRenderer = this.documents.get(documentId).openPage(pageNumber); - const page = this.pages.register(documentId, pageRenderer); // 打开了page,绑定了一个pageId, page 未关闭 - - resultResponse.id = page.id; - resultResponse.width = page.getWidth() + 0.1; - resultResponse.height = page.getHeight() + 0.1; - - return resultResponse; - + try { + const documentId = message.documentId!!; + const pageNumber = message.pageNumber!!; + + if (message.autoCloseOhos!!) { + const page = this.documents.get(documentId).openPage(pageNumber); + resultResponse.width = page.getWidth(); + resultResponse.height = page.getHeight(); + + } else { + const pageRenderer = this.documents.get(documentId).openPage(pageNumber); + const page = this.pages.register(documentId, pageRenderer); + resultResponse.id = page.id; + resultResponse.width = page.getWidth() + 0.1; + resultResponse.height = page.getHeight() + 0.1; + } + result.success(resultResponse) + } catch (e) { + result.error(e) + } } registerTexture(): RegisterTextureReply { diff --git a/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Pigeon.ets b/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Pigeon.ets index 6c65e51cbbccd33b60f4bb35b04eecd4e59c47f8..5ca1af897d68608c42d3aad851e5cbda55fb6cd7 100644 --- a/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Pigeon.ets +++ b/packages/pdfx/ohos/src/main/ets/io/scer/pdfx/Pigeon.ets @@ -579,6 +579,15 @@ export class UpdateTextureMessage { } private pageId: string; + + public getPageId() { + return this.pageId; + } + + public setPageId(setterArg: string) { + this.pageId = setterArg; + } + private textureId: number; public getTextureId(): number {