コード例 #1
0
        public PDFJS_PromiseCoroutine(MonoBehaviour monoBehaviour, IPDFJS_Promise promise, Func <PDFJS_PromiseCoroutine, IPDFJS_Promise, object, IEnumerator> coroutine, object parameters)
        {
            m_MonoBehaviour = monoBehaviour;
            m_Coroutine     = coroutine;
            m_Parameters    = parameters;

            m_Promise = promise;
        }
コード例 #2
0
 public PDFJS_PromiseCoroutine PreparePromiseCoroutine(
     Func <PDFJS_PromiseCoroutine, IPDFJS_Promise, object, IEnumerator> coroutine, IPDFJS_Promise promise, object parameters)
 {
     m_PromiseCoroutineMap[promise.PromiseHandle] = new PDFJS_PromiseCoroutine(this, promise, coroutine, parameters);
     return((PDFJS_PromiseCoroutine)m_PromiseCoroutineMap[promise.PromiseHandle]);
 }
コード例 #3
0
ファイル: PDFRenderer.cs プロジェクト: kimch2/Unity-1
        private static IEnumerator RenderPageCoroutine(PDFJS_PromiseCoroutine promiseCoroutine, IPDFJS_Promise promise, object parameters)
        {
            PDFJS_Promise <PDFJS_WebGLCanvas> renderToCanvasPromise = new PDFJS_Promise <PDFJS_WebGLCanvas>();

            PDFJS_Library.Instance.PreparePromiseCoroutine(null, renderToCanvasPromise, null);

            IntPtr    pageHandle     = ((RenderPageParameters)parameters).pageHandle;
            Texture2D texture        = ((RenderPageParameters)parameters).existingTexture;
            Vector2   newtextureSize = ((RenderPageParameters)parameters).newTextureSize;

            Vector2 pageSize = PDFPage.GetPageSize(pageHandle, 1.0f);

            float scale = 1.0f;

            if (texture != null)
            {
                float wf = pageSize.x / texture.width;
                float hf = pageSize.y / texture.height;

                scale = 1.0f / Mathf.Max(wf, hf);
            }
            else
            {
                float wf = pageSize.x / ((int)newtextureSize.x);
                float hf = pageSize.y / ((int)newtextureSize.y);

                scale = 1.0f / Mathf.Max(wf, hf);
            }

            PDFJS_RenderPageIntoCanvas(renderToCanvasPromise.PromiseHandle, pageHandle.ToInt32(), scale);

            while (!renderToCanvasPromise.HasReceivedJSResponse)
            {
                yield return(null);
            }

            if (renderToCanvasPromise.HasSucceeded)
            {
                int canvasHandle = int.Parse(renderToCanvasPromise.JSObjectHandle);

                using (PDFJS_WebGLCanvas canvas = new PDFJS_WebGLCanvas(new IntPtr(canvasHandle)))
                {
                    PDFJS_Promise <Texture2D> renderToTexturePromise = promise as PDFJS_Promise <Texture2D>;

                    if (texture == null)
                    {
                        texture            = new Texture2D((int)newtextureSize.x, (int)newtextureSize.y, TextureFormat.ARGB32, false);
                        texture.filterMode = FilterMode.Bilinear;
                        texture.Apply();
                    }


                    PDFJS_RenderCanvasIntoTexture(canvasHandle, texture.GetNativeTexturePtr().ToInt32());

                    renderToTexturePromise.Result       = texture;
                    renderToTexturePromise.HasSucceeded = true;
                    renderToTexturePromise.HasFinished  = true;

                    promiseCoroutine.ExecuteThenAction(true, texture);
                }
            }
            else
            {
                PDFJS_Promise <Texture2D> renderToTexturePromise = promise as PDFJS_Promise <Texture2D>;

                renderToTexturePromise.Result       = null;
                renderToTexturePromise.HasSucceeded = false;
                renderToTexturePromise.HasFinished  = true;

                promiseCoroutine.ExecuteThenAction(false, null);
            }
        }
コード例 #4
0
        private static IEnumerator LoadPageCoroutine(PDFJS_PromiseCoroutine promiseCoroutine, IPDFJS_Promise promise, object par)
        {
            PDFLibrary.Instance.EnsureInitialized();
            while (!PDFLibrary.Instance.IsInitialized)
            {
                yield return(null);
            }

            PDFJS_Promise <PDFPage> pagePromise = promise as PDFJS_Promise <PDFPage>;

            LoadPageParameters parameters = par as LoadPageParameters;

            PDFJS_LoadPage(promise.PromiseHandle, parameters.document.NativePointer.ToInt32(), parameters.pageIndex + 1);

            while (!pagePromise.HasReceivedJSResponse)
            {
                yield return(null);
            }

            if (pagePromise.HasSucceeded)
            {
                int     pageHandle = int.Parse(pagePromise.JSObjectHandle);
                PDFPage page       = new PDFPage(parameters.document, new IntPtr(pageHandle), parameters.pageIndex);

                pagePromise.Result      = page;
                pagePromise.HasFinished = true;

                promiseCoroutine.ExecuteThenAction(true, page);
            }
            else
            {
                pagePromise.Result      = null;
                pagePromise.HasFinished = true;

                promiseCoroutine.ExecuteThenAction(false, null);
            }
        }
コード例 #5
0
        private static IEnumerator LoadDocumentFromWWWCoroutine(PDFJS_PromiseCoroutine promiseCoroutine, IPDFJS_Promise promise, object urlString)
        {
            PDFJS_Promise <PDFDocument> documentPromise = promise as PDFJS_Promise <PDFDocument>;

            PDFLibrary.Instance.EnsureInitialized();
            while (!PDFLibrary.Instance.IsInitialized)
            {
                yield return(null);
            }

            string url = urlString as string;

            WWW www = new WWW(url);

            yield return(www);

            if (string.IsNullOrEmpty(www.error))
            {
                documentPromise.HasFinished           = true;
                documentPromise.HasSucceeded          = true;
                documentPromise.HasReceivedJSResponse = true;
                documentPromise.Result = new PDFDocument(www.bytes);

                promiseCoroutine.ExecuteThenAction(true, documentPromise.Result);
            }
            else
            {
                documentPromise.HasFinished  = true;
                documentPromise.HasSucceeded = false;

                promiseCoroutine.ExecuteThenAction(false, null);
            }
        }
コード例 #6
0
        private static IEnumerator LoadDocumentCoroutine(PDFJS_PromiseCoroutine promiseCoroutine, IPDFJS_Promise promise, object pars)
        {
            PDFJS_Promise <PDFDocument> documentPromise = promise as PDFJS_Promise <PDFDocument>;

            PDFLibrary.Instance.EnsureInitialized();
            while (!PDFLibrary.Instance.IsInitialized)
            {
                yield return(null);
            }

            LoadDocumentParameters parameters = pars as LoadDocumentParameters;

            if (!string.IsNullOrEmpty(parameters.url))
            {
                PDFJS_LoadDocumentFromURL(promise.PromiseHandle, parameters.url);
            }
            else
            {
                PDFJS_LoadDocumentFromBytes(promise.PromiseHandle, Convert.ToBase64String(parameters.bytes));
            }

            while (!promiseCoroutine.Promise.HasReceivedJSResponse)
            {
                yield return(null);
            }

            if (documentPromise.HasSucceeded)
            {
                int         documentHandle = int.Parse(promiseCoroutine.Promise.JSObjectHandle);
                PDFDocument document       = new PDFDocument(new IntPtr(documentHandle));

                documentPromise.Result      = document;
                documentPromise.HasFinished = true;

                promiseCoroutine.ExecuteThenAction(true, documentHandle);
            }
            else
            {
                documentPromise.Result      = null;
                documentPromise.HasFinished = true;

                promiseCoroutine.ExecuteThenAction(false, null);
            }
        }