diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-11-04 11:36:05 -0800 |
---|---|---|
committer | Michael Vrhel <michael.vrhel@artifex.com> | 2013-11-04 11:36:05 -0800 |
commit | d6b312aa86bb78faeb0bf430464a494d1113a62c (patch) | |
tree | 674ad1d874b4ab8aa86379656fabe5b53c45fec2 /platform/winrt/mupdf_cpp/MainPage.xaml.cpp | |
parent | 7867807a8471af734820fbbaf6d3dbeee4add9eb (diff) | |
download | mupdf-d6b312aa86bb78faeb0bf430464a494d1113a62c.tar.xz |
Fix of tab/space issues as well as changing thumbnail scale look ahead to +/- 2. Thanks to Robin for catching this.
Diffstat (limited to 'platform/winrt/mupdf_cpp/MainPage.xaml.cpp')
-rw-r--r-- | platform/winrt/mupdf_cpp/MainPage.xaml.cpp | 369 |
1 files changed, 183 insertions, 186 deletions
diff --git a/platform/winrt/mupdf_cpp/MainPage.xaml.cpp b/platform/winrt/mupdf_cpp/MainPage.xaml.cpp index 767cba97..36becdaa 100644 --- a/platform/winrt/mupdf_cpp/MainPage.xaml.cpp +++ b/platform/winrt/mupdf_cpp/MainPage.xaml.cpp @@ -9,7 +9,7 @@ #include <sstream> #define LOOK_AHEAD 1 /* A +/- count on the pages to pre-render */ -#define LOOK_AHEAD_SCALE 10 /* A +/- count on the pages to adjust for scale change */ +#define LOOK_AHEAD_SCALE 2 /* A +/- count on the pages to adjust for scale change */ #define THUMB_PREADD 10 #define MIN_SCALE 0.5 @@ -445,7 +445,7 @@ void MainPage::CleanUp() m_page_link_list->Clear(); if (m_text_list->Size > 0) m_text_list->Clear(); - m_ppage_num_list.clear(); + m_ppage_num_list.clear(); if (m_linkset != nullptr && m_linkset->Size > 0) m_linkset->Clear(); @@ -661,8 +661,6 @@ void MainPage::InitialRender() m_currpage = 0; } - //m_print.RegisterForPrinting(); - /* Initialize all the flipvew items with blanks and the thumbnails. */ for (int k = 0; k < m_num_pages; k++) { @@ -729,7 +727,6 @@ void MainPage::InitialRender() void MainPage::RenderRange(int curr_page) { /* Render +/- the look ahead from where we are if blank page is present */ - //spatial_info_t spatial_info = InitSpatial(1); spatial_info_t spatial_info = InitSpatial(m_doczoom); bool curr_page_rendered = true; int range = LOOK_AHEAD; @@ -1600,16 +1597,16 @@ void MainPage::PrintTaskRequested(PrintManager^ sender, PrintTaskRequestedEventA printDetailedOptions->DisplayedOptions->Append(Windows::Graphics::Printing::StandardPrintTaskOptions::MediaSize); printDetailedOptions->DisplayedOptions->Append(Windows::Graphics::Printing::StandardPrintTaskOptions::Copies); - // Our custom options - PrintCustomItemListOptionDetails^ resolution = - printDetailedOptions->CreateItemListOption("resolution", "Render Resolution"); - resolution->AddItem("sres72", "72 dpi"); - resolution->AddItem("sres150", "150 dpi"); - resolution->AddItem("sres300", "300 dpi"); - resolution->AddItem("sres600", "600 dpi"); + // Our custom options + PrintCustomItemListOptionDetails^ resolution = + printDetailedOptions->CreateItemListOption("resolution", "Render Resolution"); + resolution->AddItem("sres72", "72 dpi"); + resolution->AddItem("sres150", "150 dpi"); + resolution->AddItem("sres300", "300 dpi"); + resolution->AddItem("sres600", "600 dpi"); resolution->TrySetValue("sres600"); m_printresolution = 600; - printDetailedOptions->DisplayedOptions->Append("resolution"); + printDetailedOptions->DisplayedOptions->Append("resolution"); PrintCustomItemListOptionDetails^ scaling = printDetailedOptions->CreateItemListOption("scaling", "Scaling"); scaling->AddItem("sScaleToFit", "Scale To Fit"); @@ -1647,101 +1644,101 @@ void MainPage::PrintTaskRequested(PrintManager^ sender, PrintTaskRequestedEventA }); // Set the document source. args->SetSource(PrintDocumentSource); - })); + })); } void MainPage::PrintOptionsChanged(PrintTaskOptionDetails^ sender, PrintTaskOptionChangedEventArgs^ args) { bool force_reset = false; - if (args->OptionId == nullptr) - return; - - String^ optionId = safe_cast<String^>(args->OptionId); - - if (optionId == "resolution") - { - IPrintOptionDetails^ resolution = sender->Options->Lookup(optionId); - String^ resolutionValue = safe_cast<String^>(resolution->Value); - - if (resolutionValue == "sres72") - { - m_printresolution = 72; - } - else if (resolutionValue == "sres150") - { - m_printresolution = 150; - } - else if (resolutionValue == "sres300") - { - m_printresolution = 300; - } - else if(resolutionValue == "sres600") - { - m_printresolution = 600; - } - } + if (args->OptionId == nullptr) + return; + + String^ optionId = safe_cast<String^>(args->OptionId); + + if (optionId == "resolution") + { + IPrintOptionDetails^ resolution = sender->Options->Lookup(optionId); + String^ resolutionValue = safe_cast<String^>(resolution->Value); + + if (resolutionValue == "sres72") + { + m_printresolution = 72; + } + else if (resolutionValue == "sres150") + { + m_printresolution = 150; + } + else if (resolutionValue == "sres300") + { + m_printresolution = 300; + } + else if(resolutionValue == "sres600") + { + m_printresolution = 600; + } + } /* Need to update preview with a change of this one */ - if (optionId == "scaling") - { - IPrintOptionDetails^ scaling = sender->Options->Lookup(optionId); - String^ scaleValue = safe_cast<String^>(scaling->Value); - - if (scaleValue == "sScaleToFit") - { - m_printcrop = false; - } - if (scaleValue == "sCrop") - { - m_printcrop = true; - } + if (optionId == "scaling") + { + IPrintOptionDetails^ scaling = sender->Options->Lookup(optionId); + String^ scaleValue = safe_cast<String^>(scaling->Value); + + if (scaleValue == "sScaleToFit") + { + m_printcrop = false; + } + if (scaleValue == "sCrop") + { + m_printcrop = true; + } force_reset = true; - } + } if (optionId == L"PageRange") - { - IPrintOptionDetails^ pagerange = sender->Options->Lookup(optionId); - String^ pageRangeValue = pagerange->Value->ToString(); - - if(pageRangeValue == L"PrintRange") - { - sender->DisplayedOptions->Append(L"PageRangeEdit"); - m_pageRangeEditVisible = true; - } - else - { - RemovePageRangeEdit(sender); - } - RefreshPreview(); - } + { + IPrintOptionDetails^ pagerange = sender->Options->Lookup(optionId); + String^ pageRangeValue = pagerange->Value->ToString(); + + if(pageRangeValue == L"PrintRange") + { + sender->DisplayedOptions->Append(L"PageRangeEdit"); + m_pageRangeEditVisible = true; + } + else + { + RemovePageRangeEdit(sender); + } + RefreshPreview(); + } if (optionId == L"PageRangeEdit") - { - IPrintOptionDetails^ pagerange = sender->Options->Lookup(optionId); - - std::wregex rangePattern(L"^\\s*\\d+\\s*(\\-\\s*\\d+\\s*)?(\\,\\s*\\d+\\s*(\\-\\s*\\d+\\s*)?)*$"); - std::wstring pageRangeValue(pagerange->Value->ToString()->Data()); - - if(!std::regex_match(pageRangeValue.begin(), pageRangeValue.end(), rangePattern)) - { - pagerange->ErrorText = L"Invalid Page Range (eg: 1-3, 5)"; - } - else - { - pagerange->ErrorText = L""; - try - { - GetPagesInRange(pagerange->Value->ToString()); - } - catch(PageRangeException* rangeException) - { - pagerange->ErrorText = ref new String(rangeException->get_DisplayMessage().data()); - delete rangeException; - } - force_reset = true; - } - } + { + IPrintOptionDetails^ pagerange = sender->Options->Lookup(optionId); + + std::wregex rangePattern(L"^\\s*\\d+\\s*(\\-\\s*\\d+\\s*)?(\\,\\s*\\d+\\s*(\\-\\s*\\d+\\s*)?)*$"); + std::wstring pageRangeValue(pagerange->Value->ToString()->Data()); + + if(!std::regex_match(pageRangeValue.begin(), pageRangeValue.end(), rangePattern)) + { + pagerange->ErrorText = L"Invalid Page Range (eg: 1-3, 5)"; + } + else + { + pagerange->ErrorText = L""; + try + { + GetPagesInRange(pagerange->Value->ToString()); + } + catch(PageRangeException* rangeException) + { + pagerange->ErrorText = ref new String(rangeException->get_DisplayMessage().data()); + delete rangeException; + } + force_reset = true; + } + } if (force_reset) { RefreshPreview(); @@ -1749,84 +1746,84 @@ void MainPage::PrintOptionsChanged(PrintTaskOptionDetails^ sender, PrintTaskOpti } void MainPage::SplitString(String^ string, wchar_t delimiter, std::vector<std::wstring>& words) -{ - std::wistringstream iss(string->Data()); + { + std::wistringstream iss(string->Data()); - std::wstring part; - while(std::getline(iss, part, delimiter)) - { - words.push_back(part); - }; + std::wstring part; + while(std::getline(iss, part, delimiter)) + { + words.push_back(part); + }; } void MainPage::GetPagesInRange(String^ pagerange) { - std::vector<std::wstring> vector_range; - SplitString(pagerange, ',', vector_range); + std::vector<std::wstring> vector_range; + SplitString(pagerange, ',', vector_range); - m_ppage_num_list.clear(); - for(std::vector<std::wstring>::iterator it = vector_range.begin(); it != vector_range.end(); ++ it) - { - int intervalPos = static_cast<int>((*it).find('-')); - if( intervalPos != -1) - { - int start = _wtoi((*it).substr(0, intervalPos).data()); - int end = _wtoi((*it).substr(intervalPos + 1, (*it).length() - intervalPos - 1).data()); + m_ppage_num_list.clear(); + for(std::vector<std::wstring>::iterator it = vector_range.begin(); it != vector_range.end(); ++ it) + { + int intervalPos = static_cast<int>((*it).find('-')); + if( intervalPos != -1) + { + int start = _wtoi((*it).substr(0, intervalPos).data()); + int end = _wtoi((*it).substr(intervalPos + 1, (*it).length() - intervalPos - 1).data()); - if ((start < 1) || (end > static_cast<int>(m_num_pages)) || (start >= end)) - { - std::wstring message(L"Invalid page(s) in range "); + if ((start < 1) || (end > static_cast<int>(m_num_pages)) || (start >= end)) + { + std::wstring message(L"Invalid page(s) in range "); - message.append(std::to_wstring(start)); - message.append(L" - "); - message.append(std::to_wstring(end)); + message.append(std::to_wstring(start)); + message.append(L" - "); + message.append(std::to_wstring(end)); throw new PageRangeException(message); - } - - for(int intervalPage=start; intervalPage <= end; ++intervalPage) - { - m_ppage_num_list.push_back(intervalPage); - } - } - else - { - int pageNr = _wtoi((*it).data()); - std::wstring message(L"Invalid page "); - - if (pageNr < 1) - { - message.append(std::to_wstring(pageNr)); + } + + for(int intervalPage=start; intervalPage <= end; ++intervalPage) + { + m_ppage_num_list.push_back(intervalPage); + } + } + else + { + int pageNr = _wtoi((*it).data()); + std::wstring message(L"Invalid page "); + + if (pageNr < 1) + { + message.append(std::to_wstring(pageNr)); throw new PageRangeException(message); - } - if (pageNr > static_cast<int>(m_num_pages)) - { - message.append(std::to_wstring(pageNr)); + } + if (pageNr > static_cast<int>(m_num_pages)) + { + message.append(std::to_wstring(pageNr)); throw new PageRangeException(message); - } - m_ppage_num_list.push_back(pageNr); - } - } - std::sort(m_ppage_num_list.begin(), m_ppage_num_list.end(), std::less<int>()); - std::unique(m_ppage_num_list.begin(), m_ppage_num_list.end()); + } + m_ppage_num_list.push_back(pageNr); + } + } + std::sort(m_ppage_num_list.begin(), m_ppage_num_list.end(), std::less<int>()); + std::unique(m_ppage_num_list.begin(), m_ppage_num_list.end()); } void MainPage::RemovePageRangeEdit(PrintTaskOptionDetails^ printTaskOptionDetails) { - if (m_pageRangeEditVisible) - { - unsigned int index; - if(printTaskOptionDetails->DisplayedOptions->IndexOf(ref new String(L"PageRangeEdit"), &index)) - { - printTaskOptionDetails->DisplayedOptions->RemoveAt(index); - } - m_pageRangeEditVisible = false; - } + if (m_pageRangeEditVisible) + { + unsigned int index; + if(printTaskOptionDetails->DisplayedOptions->IndexOf(ref new String(L"PageRangeEdit"), &index)) + { + printTaskOptionDetails->DisplayedOptions->RemoveAt(index); + } + m_pageRangeEditVisible = false; + } } void MainPage::ClearPrintCollection() { - m_printlock.lock(); + m_printlock.lock(); for (int k = 0; k < m_num_pages; k++) { auto thumb_page = this->m_thumbnails->GetAt(k); @@ -1838,34 +1835,34 @@ void MainPage::ClearPrintCollection() /* Just use the thumbnail images for now */ void MainPage::CreatePrintPreviewPages(Object^ sender, PaginateEventArgs^ e) { - InterlockedIncrement64(&m_requestCount); - PrintPageDesc ppageDescription; - PrintTaskOptionDetails^ printDetailedOptions = + InterlockedIncrement64(&m_requestCount); + PrintPageDesc ppageDescription; + PrintTaskOptionDetails^ printDetailedOptions = PrintTaskOptionDetails::GetFromPrintTaskOptions(e->PrintTaskOptions); - PrintPageDescription DeviceDescription = + PrintPageDescription DeviceDescription = e->PrintTaskOptions->GetPageDescription(0); /* This has the media dimension */ - ppageDescription.pagesize = DeviceDescription.PageSize; + ppageDescription.pagesize = DeviceDescription.PageSize; ppageDescription.resolution.Width = DeviceDescription.DpiX; ppageDescription.resolution.Height = DeviceDescription.DpiY; - ppageDescription.margin.Width = (std::max)(DeviceDescription.ImageableRect.Left, - DeviceDescription.ImageableRect.Right - - DeviceDescription.PageSize.Width); + ppageDescription.margin.Width = (std::max)(DeviceDescription.ImageableRect.Left, + DeviceDescription.ImageableRect.Right - + DeviceDescription.PageSize.Width); - ppageDescription.margin.Height = (std::max)(DeviceDescription.ImageableRect.Top, - DeviceDescription.ImageableRect.Bottom - - DeviceDescription.PageSize.Height); + ppageDescription.margin.Height = (std::max)(DeviceDescription.ImageableRect.Top, + DeviceDescription.ImageableRect.Bottom - + DeviceDescription.PageSize.Height); - ppageDescription.printpagesize.Width = DeviceDescription.PageSize.Width - + ppageDescription.printpagesize.Width = DeviceDescription.PageSize.Width - ppageDescription.margin.Width * 2; - ppageDescription.printpagesize.Height = DeviceDescription.PageSize.Height - + ppageDescription.printpagesize.Height = DeviceDescription.PageSize.Height - ppageDescription.margin.Height * 2; - ClearPrintCollection(); - PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); + ClearPrintCollection(); + PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); m_printpagedesc = ppageDescription; if (m_ppage_num_list.size() > 0) @@ -1919,21 +1916,21 @@ void MainPage::CleanUpPreview(int page_num) void MainPage::RefreshPreview() { - auto callback = + auto callback = ref new Windows::UI::Core::DispatchedHandler([this]() { m_printdoc->InvalidatePreview(); }); - Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback); + Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, callback); } void MainPage::GetPrintPreviewPages(Object^ sender, GetPreviewPageEventArgs^ e) { - PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); + PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); - LONGLONG requestNumber = 0; - InterlockedExchange64(&requestNumber, m_requestCount); - int index_page_num = e->PageNumber; + LONGLONG requestNumber = 0; + InterlockedExchange64(&requestNumber, m_requestCount); + int index_page_num = e->PageNumber; int ren_page_num = index_page_num; if (m_ppage_num_list.size() > 0) @@ -1989,20 +1986,20 @@ void MainPage::GetPrintPreviewPages(Object^ sender, GetPreviewPageEventArgs^ e) void MainPage::AddPrintPages(Object^ sender, AddPagesEventArgs^ e) { - PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); + PrintDocument^ printDocument = safe_cast<PrintDocument^>(sender); - /* We create a list of tasks to create the pages for printing. Once all the - pages are created then we can go ahead and start adding them for printing */ - std::vector<concurrency::task<void>> createPageTasks; + /* We create a list of tasks to create the pages for printing. Once all the + pages are created then we can go ahead and start adding them for printing */ + std::vector<concurrency::task<void>> createPageTasks; double res_scale = ((double) m_printresolution / 72.0); int page_count = m_num_pages; if (m_ppage_num_list.size() > 0) page_count = m_ppage_num_list.size(); - for(int i = 0; i < page_count; ++i) - { - m_printlock.lock(); + for(int i = 0; i < page_count; ++i) + { + m_printlock.lock(); int page_num = i; if (m_ppage_num_list.size() > 0) @@ -2033,11 +2030,11 @@ void MainPage::AddPrintPages(Object^ sender, AddPagesEventArgs^ e) }, task_continuation_context::use_current())); } m_printlock.unlock(); - } + } - /* When all the tasks have finished then go ahead and add them to the print - document */ - concurrency::when_all(createPageTasks.begin(), createPageTasks.end()). then([=] + /* When all the tasks have finished then go ahead and add them to the print + document */ + concurrency::when_all(createPageTasks.begin(), createPageTasks.end()). then([=] { for (int i = 0; i < page_count; i++) { @@ -2058,7 +2055,7 @@ void MainPage::AddPrintPages(Object^ sender, AddPagesEventArgs^ e) /* All pages provided. */ printDocument->AddPagesComplete(); /* Reset the current page description as soon as possible since the - PrintTask.Completed event might fire later */ + PrintTask.Completed event might fire later */ m_printpagedesc = PrintPageDesc(); }); } |