From 3e6f3f15dd288be573b86d9013ba9f49e3bd7fdf Mon Sep 17 00:00:00 2001 From: Michael Vrhel Date: Thu, 20 Mar 2014 16:50:13 -0700 Subject: Update the winrt solution with the changes made in the win32 solution. Also update the code for the changes made in the stream API --- platform/winrt/libmupdf_winRT.vcxproj | 9 +++++++ platform/winrt/libmupdf_winRT.vcxproj.filters | 30 +++++++++++++++++++++ platform/winrt/mupdfwinrt/muctx.cpp | 38 +++++++++++++++++++-------- platform/winrt/mupdfwinrt/muctx.h | 1 + 4 files changed, 67 insertions(+), 11 deletions(-) (limited to 'platform/winrt') diff --git a/platform/winrt/libmupdf_winRT.vcxproj b/platform/winrt/libmupdf_winRT.vcxproj index 756a2b5a..9b12992b 100644 --- a/platform/winrt/libmupdf_winRT.vcxproj +++ b/platform/winrt/libmupdf_winRT.vcxproj @@ -70,6 +70,7 @@ + @@ -95,6 +96,7 @@ + @@ -114,6 +116,7 @@ + @@ -134,12 +137,16 @@ + + + + @@ -149,6 +156,7 @@ + @@ -228,6 +236,7 @@ + {0715f3cf-5d1b-4617-a331-6527371365b7} diff --git a/platform/winrt/libmupdf_winRT.vcxproj.filters b/platform/winrt/libmupdf_winRT.vcxproj.filters index be80fd15..841edf9d 100644 --- a/platform/winrt/libmupdf_winRT.vcxproj.filters +++ b/platform/winrt/libmupdf_winRT.vcxproj.filters @@ -25,6 +25,9 @@ {7b0f7938-a977-4cd9-a8bc-aeef816ae84c} + + {90cc5056-84ea-40ea-9d8a-66a753c2e637} + @@ -390,6 +393,30 @@ fitz + + fitz + + + fitz + + + pdf + + + pdf + + + pdf + + + pdf + + + tiff + + + pdf + @@ -590,5 +617,8 @@ !include\pdf + + pdf + \ No newline at end of file diff --git a/platform/winrt/mupdfwinrt/muctx.cpp b/platform/winrt/mupdfwinrt/muctx.cpp index cc3feff3..59f41204 100644 --- a/platform/winrt/mupdfwinrt/muctx.cpp +++ b/platform/winrt/mupdfwinrt/muctx.cpp @@ -7,28 +7,40 @@ * (other than the file streaming stuff) */ #ifdef _WINRT_DLL +// Attempt to use t.wait() +//#include +//using namespace concurrency; /* File streaming set up for WinRT */ -static int win_read_file(fz_stream *stm, unsigned char *buf, int len) +static int win_next_file(fz_stream *stm, int len) { void *temp = stm->state; - win_stream_struct *stream = reinterpret_cast (temp); - IRandomAccessStream^ Stream = stream->stream; + win_stream_struct *state = reinterpret_cast (temp); + IRandomAccessStream^ Stream = state->stream; + unsigned char *buf = state->public_buffer; unsigned long long curr_pos = Stream->Position; unsigned long long length = Stream->Size; DataReader^ local_reader = ref new DataReader(Stream); if (local_reader == nullptr) return 0; - DataReaderLoadOperation^ result = local_reader->LoadAsync(len); - - /* Block on the Async call. This is not on the UI thread. */ - while(result->Status != AsyncStatus::Completed) { + // This does not work here. mupdf is not set up to wait for win_next_file + // to complete in an ansyn manner + //auto t = create_task(local_reader->LoadAsync(len)); + //t.wait(); + DataReaderLoadOperation^ result = local_reader->LoadAsync(len); + while (result->Status != AsyncStatus::Completed) { } result->GetResults(); + + /* First see what is available */ int curr_len2 = local_reader->UnconsumedBufferLength; if (curr_len2 < len) len = curr_len2; + /* And make sure that we have enough room */ + if (len > sizeof(state->public_buffer)) + len = sizeof(state->public_buffer); + Platform::Array^ arrByte = ref new Platform::Array(len); if (arrByte == nullptr) return 0; @@ -37,7 +49,12 @@ static int win_read_file(fz_stream *stm, unsigned char *buf, int len) memcpy(buf, arrByte->Data, len); local_reader->DetachStream(); - return len; + stm->rp = buf; + stm->wp = buf + len; + stm->pos += len; + if (len == 0) + return EOF; + return *stm->rp++; } static void win_seek_file(fz_stream *stm, int offset, int whence) @@ -64,8 +81,7 @@ static void win_seek_file(fz_stream *stm, int offset, int whence) Stream->Seek(n); curr_pos = Stream->Position; stm->pos = n; - stm->rp = stm->bp; - stm->wp = stm->bp; + stm->wp = stm->rp; } static void win_close_file(fz_context *ctx, void *state) @@ -78,7 +94,7 @@ static void win_close_file(fz_context *ctx, void *state) status_t muctx::InitializeStream(IRandomAccessStream^ readStream, char *ext) { win_stream.stream = readStream; - fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_read_file, win_close_file, NULL); + fz_stream *mu_stream = fz_new_stream(mu_ctx, 0, win_next_file, win_close_file, NULL); mu_stream->seek = win_seek_file; mu_stream->state = reinterpret_cast (&win_stream); diff --git a/platform/winrt/mupdfwinrt/muctx.h b/platform/winrt/mupdfwinrt/muctx.h index 0a27af52..90ef90e2 100644 --- a/platform/winrt/mupdfwinrt/muctx.h +++ b/platform/winrt/mupdfwinrt/muctx.h @@ -58,6 +58,7 @@ using namespace Windows::Foundation; typedef struct win_stream_struct_s { IRandomAccessStream^ stream; + unsigned char public_buffer[4096]; } win_stream_struct; #endif -- cgit v1.2.3