From 3824bf32f8595c2f037db14e133b798bfae65027 Mon Sep 17 00:00:00 2001 From: Michael Vrhel Date: Wed, 8 May 2013 15:23:37 -0700 Subject: Display of link in document reworked. They are now bound to the UI xaml as a collection of rectangle coordinate and color. --- winrt/mupdf_cpp/DocumentPage.h | 22 +++++- winrt/mupdf_cpp/MainPage.xaml | 113 ++++++++++++++++++++++++++-- winrt/mupdf_cpp/MainPage.xaml.cpp | 152 +++++++++++++++++--------------------- winrt/mupdf_cpp/MainPage.xaml.h | 9 ++- winrt/mupdf_cpp/RectList.h | 63 +++++++++++++--- winrt/mupdfwinrt/muctx.cpp | 2 +- 6 files changed, 251 insertions(+), 110 deletions(-) (limited to 'winrt') diff --git a/winrt/mupdf_cpp/DocumentPage.h b/winrt/mupdf_cpp/DocumentPage.h index 737a7f73..dc006e65 100644 --- a/winrt/mupdf_cpp/DocumentPage.h +++ b/winrt/mupdf_cpp/DocumentPage.h @@ -30,10 +30,30 @@ namespace mupdf_cpp double zoom; WriteableBitmap^ image; Page_Content_t content; - + IVector^ textbox; + IVector^ linkbox; public: DocumentPage(void); + /* Note IVector needed for WinRT interface */ + property IVector^ TextBox + { + IVector^ get() { return (textbox); } + void set(IVector^ value) + { + textbox = value; + } + } + + property IVector^ LinkBox + { + IVector^ get() { return (linkbox); } + void set(IVector^ value) + { + linkbox = value; + } + } + property int Content { int get() { return ((int) content); } diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml index e5083d63..770d8bd3 100644 --- a/winrt/mupdf_cpp/MainPage.xaml +++ b/winrt/mupdf_cpp/MainPage.xaml @@ -63,6 +63,7 @@ + @@ -70,7 +71,6 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -111,13 +162,59 @@ VerticalScrollBarVisibility="Auto" MinZoomFactor="1" MaxZoomFactor="4"> - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - (); m_thumbnails = ref new Platform::Collections::Vector(); + m_page_link_list = ref new Platform::Collections::Vector^>(); + m_text_list = ref new Platform::Collections::Vector(); + m_linkset = ref new Platform::Collections::Vector(); CleanUp(); RecordMainThread(); } @@ -214,10 +204,8 @@ void MainPage::UpdatePage(int page_num, InMemoryRandomAccessStream^ ras, /* We do not want flipview change notification to occur for ourselves */ m_page_update = true; - //this->m_docPages->BindableSetAt(page_num, doc_page); this->m_docPages->SetAt(page_num, doc_page); m_page_update = false; - } Point MainPage::ComputePageSize(spatial_info_t spatial_info, int page_num) @@ -379,6 +367,13 @@ void mupdf_cpp::MainPage::CleanUp() m_docPages->Clear(); if (m_thumbnails != nullptr && m_thumbnails->Size > 0) m_thumbnails->Clear(); + /* With the ref counting this should not leak */ + if (m_page_link_list != nullptr && m_page_link_list->Size > 0) + m_page_link_list->Clear(); + if (m_text_list != nullptr && m_text_list->Size > 0) + m_text_list->Clear(); + if (m_linkset != nullptr && m_linkset->Size > 0) + m_linkset->Clear(); if (this->mu_doc != nullptr) mu_doc->CleanUp(); @@ -403,6 +398,7 @@ void mupdf_cpp::MainPage::CleanUp() ResetSearch(); m_ren_status = REN_AVAILABLE; m_links_on = false; + m_rectlist_page = -1; this->xaml_PageSlider->Minimum = m_slider_min; this->xaml_PageSlider->Maximum = m_slider_max; @@ -443,6 +439,8 @@ void mupdf_cpp::MainPage::RenderThumbs() doc_page->Height = ras_size.Y / SCALE_THUMB; doc_page->Width = ras_size.X / SCALE_THUMB; doc_page->Content = THUMBNAIL; + doc_page->TextBox = nullptr; + doc_page->LinkBox = nullptr; if (this->m_ren_status == REN_THUMBS) { m_thumbnails->Append(doc_page); /* Flipview object get overwhelmed unless I do this */ @@ -559,12 +557,20 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file) /* Initialize all the flipvew items with blanks */ for (int k = 0; k < m_num_pages; k++) { + /* Blank pages */ DocumentPage^ doc_page = ref new DocumentPage(); doc_page->Image = this->m_BlankBmp; doc_page->Height = BLANK_HEIGHT; doc_page->Width = BLANK_WIDTH; doc_page->Content = DUMMY; + doc_page->TextBox = nullptr; + doc_page->LinkBox = nullptr; this->m_docPages->Append(doc_page); + /* Create empty lists for our links and specify that they have not + been computed for these pages */ + Vector^ temp_link = ref new Vector(); + m_page_link_list->Append(temp_link); + m_linkset->Append(false); } this->xaml_horiz_flipView->ItemsSource = m_docPages; @@ -1059,20 +1065,6 @@ void mupdf_cpp::MainPage::UpDatePageSizes() } }; -void mupdf_cpp::MainPage::ClearLinksCanvas() -{ - Canvas^ link_canvas = (Canvas^) (this->FindName("linkCanvas")); - if (link_canvas != nullptr) - { - Canvas^ Parent_Canvas = (Canvas^) link_canvas->Parent; - if (Parent_Canvas != nullptr) - { - Parent_Canvas->Children->RemoveAtEnd(); - delete link_canvas; - } - } -} - /* Link related code */ void mupdf_cpp::MainPage::Linker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { @@ -1081,18 +1073,33 @@ void mupdf_cpp::MainPage::Linker(Platform::Object^ sender, Windows::UI::Xaml::Ro if (m_links_on) AddLinkCanvas(); else - ClearLinksCanvas(); + { + /* Make sure surrounding render pages lose their links */ + for (int k = m_currpage - LOOK_AHEAD; k <= m_currpage + LOOK_AHEAD; k++) + { + if (k >= 0 && k < m_num_pages) + { + auto doc_page = this->m_docPages->GetAt(k); + if (doc_page->Content == FULL_RESOLUTION) + { + doc_page->LinkBox = nullptr; + m_page_update = true; + this->m_docPages->SetAt(m_currpage, doc_page); + m_page_update = false; + } + } + } + } } +/* Add in the link rects. If we have not already computed them then do that now */ void mupdf_cpp::MainPage::AddLinkCanvas() { - return; - /* This is disabled for now until I figure out how to add the canvas - with rects into the data template for the scroll view object */ - if (m_links_on) + /* See if the link object for this page has already been computed */ + int link_page = m_linkset->GetAt(m_currpage); + if (!link_page) { - ClearLinksCanvas(); - + m_linkset->SetAt(m_currpage, true); int num_links = mu_doc->ComputeLinks(m_currpage); if (num_links == 0) return; @@ -1107,23 +1114,8 @@ void mupdf_cpp::MainPage::AddLinkCanvas() pageSize = mu_doc->GetPageSize(m_currpage); scale = fitPageToScreen(pageSize, screenSize); - /* A new canvas */ - Canvas^ link_canvas = ref new Canvas(); - link_canvas->Name = "linkCanvas"; - - /* Get current scrollview item */ - auto currItem = m_curr_flipView->ItemContainerGenerator->ContainerFromItem(m_curr_flipView->SelectedItem); - if (currItem == nullptr) - { - return; - } - - FlipViewItem ^flipview_temp = (FlipViewItem^) m_curr_flipView->Items->GetAt(m_currpage); - Canvas^ curr_canvas = (Canvas^) flipview_temp->Content; - - link_canvas->Height = curr_canvas->Height; - link_canvas->Width = curr_canvas->Width; - curr_canvas->Children->Append(link_canvas); + /* Create a new RectList collection */ + auto link_list = ref new Platform::Collections::Vector(); /* Now add the rects */ for (int k = 0; k < num_links; k++) @@ -1131,22 +1123,29 @@ void mupdf_cpp::MainPage::AddLinkCanvas() auto curr_link = mu_doc->GetLink(k); if (curr_link->Type != NOT_SET) { - Rectangle^ a_rectangle = ref new Rectangle(); - TranslateTransform ^trans_transform = ref new TranslateTransform(); - - a_rectangle->IsTapEnabled = true; - a_rectangle->Width = curr_link->LowerRight.X - curr_link->UpperLeft.X; - a_rectangle->Height = curr_link->UpperLeft.Y - curr_link->LowerRight.Y; - trans_transform->X = curr_link->UpperLeft.X * scale.X; - trans_transform->Y = curr_link->UpperLeft.Y * scale.Y; - a_rectangle->Width *= scale.X; - a_rectangle->Height *= scale.Y; - a_rectangle->RenderTransform = trans_transform; - a_rectangle->Fill = m_linkcolor_brush; - link_canvas->Children->Append(a_rectangle); + RectList^ rect_item = ref new RectList(); + rect_item->Color = m_linkcolor; + rect_item->Height = curr_link->LowerRight.Y - curr_link->UpperLeft.Y; + rect_item->Width = curr_link->LowerRight.X - curr_link->UpperLeft.X; + rect_item->X = curr_link->UpperLeft.X * scale.X; + rect_item->Y = curr_link->UpperLeft.Y * scale.Y; + rect_item->Width *= scale.X; + rect_item->Height *= scale.Y; + rect_item->Type = curr_link->Type; + rect_item->Urilink = curr_link->Uri; + rect_item->PageNum = curr_link->PageNum; + link_list->Append(rect_item); } } + /* Now set it in our list of links */ + m_page_link_list->SetAt(m_currpage, link_list); } + /* Go ahead and set our doc item to this in the vertical and horizontal view */ + auto doc_page = this->m_docPages->GetAt(m_currpage); + doc_page->LinkBox = m_page_link_list->GetAt(m_currpage); + m_page_update = true; + this->m_docPages->SetAt(m_currpage, doc_page); + m_page_update = false; } bool mupdf_cpp::MainPage::CheckRect(Rectangle^ curr_rect, Point pt) @@ -1193,23 +1192,6 @@ void mupdf_cpp::MainPage::Canvas_Single_Tap(Platform::Object^ sender, Windows::U } } -/* Window string hurdles.... */ -static String^ char_to_String(char *char_in) -{ - size_t size = MultiByteToWideChar(CP_UTF8, 0, char_in, -1, NULL, 0); - wchar_t *pw; - pw = new wchar_t[size]; - if (!pw) - { - delete []pw; - return nullptr; - } - MultiByteToWideChar (CP_UTF8, 0, char_in, -1, pw, size ); - String^ str_out = ref new String(pw); - delete []pw; - return str_out; -} - int mupdf_cpp::MainPage::JumpToLink(int index) { auto link = mu_doc->GetLink(index); diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h index 0b8f48fe..9c39534e 100644 --- a/winrt/mupdf_cpp/MainPage.xaml.h +++ b/winrt/mupdf_cpp/MainPage.xaml.h @@ -73,6 +73,10 @@ namespace mupdf_cpp private: Vector^ m_docPages; Vector^ m_thumbnails; + Vector^>^ m_page_link_list; + Vector^ m_linkset; + Vector^ m_text_list; + int m_rectlist_page; mudocument^ mu_doc; bool m_file_open; int m_currpage; @@ -88,8 +92,8 @@ namespace mupdf_cpp bool m_page_update; long long m_memory_use; WriteableBitmap ^m_BlankBmp; - SolidColorBrush^ m_textcolor_brush; - SolidColorBrush^ m_linkcolor_brush; + String^ m_textcolor; + String^ m_linkcolor; FlipView^ m_curr_flipView; RenderingStatus_t m_ren_status; cancellation_token_source m_ThumbCancel; @@ -134,7 +138,6 @@ namespace mupdf_cpp void Canvas_Single_Tap(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e); bool CheckRect(Rectangle^ curr_rect, Point pt); int JumpToLink(int index); - void ClearLinksCanvas(); void ContentDisplay(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void FlattenOutline(fz_outline *outline, int level); void ListView_Single_Tap(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e); diff --git a/winrt/mupdf_cpp/RectList.h b/winrt/mupdf_cpp/RectList.h index eb4532aa..d138397a 100644 --- a/winrt/mupdf_cpp/RectList.h +++ b/winrt/mupdf_cpp/RectList.h @@ -1,12 +1,10 @@ #pragma once - -/* Used for binding to the xaml in the scroll view. */ +/* WinRT RectList class for binding a collection of rects to the xaml ui */ using namespace Windows::UI::Xaml::Media::Imaging; using namespace Windows::UI::Xaml::Controls; +using namespace Platform; /* For String */ - - namespace mupdf_cpp { [Windows::UI::Xaml::Data::Bindable] // in c++, adding this attribute to ref classes enables data binding for more info search for 'Bindable' on the page http://go.microsoft.com/fwlink/?LinkId=254639 @@ -14,36 +12,50 @@ namespace mupdf_cpp public ref class RectList sealed { private: - int heightr; - int widthr; + int height; + int width; int x; int y; + String^ color; + /* These are used to store the link infomation */ + int type; + int pagenum; + Windows::Foundation::Uri ^uri; public: RectList(void); - property int HeightR + property int Height { - int get() { return ((int) heightr); } + int get() { return ((int) height); } void set(int value) { if (value < 0) { throw ref new Platform::InvalidArgumentException(); } - heightr = value; + height = value; + } + } + + property String^ Color + { + String^ get() { return (color); } + void set(String^ value) + { + color = value; } } - property int WidthR + property int Width { - int get() { return widthr; } + int get() { return width; } void set(int value) { if (value < 0) { throw ref new Platform::InvalidArgumentException(); } - widthr = value; + width = value; } } @@ -64,5 +76,32 @@ namespace mupdf_cpp y = value; } } + + property int Type + { + int get() { return type; } + void set(int value) + { + type = value; + } + } + + property int PageNum + { + int get() { return pagenum; } + void set(int value) + { + pagenum = value; + } + } + + property Windows::Foundation::Uri^ Urilink + { + Windows::Foundation::Uri^ get() { return uri; } + void set(Windows::Foundation::Uri^ value) + { + uri = value; + } + } }; } diff --git a/winrt/mupdfwinrt/muctx.cpp b/winrt/mupdfwinrt/muctx.cpp index 128b35e0..ec10b493 100644 --- a/winrt/mupdfwinrt/muctx.cpp +++ b/winrt/mupdfwinrt/muctx.cpp @@ -380,7 +380,7 @@ int muctx::GetLinks(int page_num, sh_vector_link links_vec) link->upper_left.X = curr_rect.x0; link->upper_left.Y = curr_rect.y0; link->lower_right.X = curr_rect.x1; - link->lower_right.Y = curr_rect.x1; + link->lower_right.Y = curr_rect.y1; switch (curr_link->dest.kind) { -- cgit v1.2.3