summaryrefslogtreecommitdiff
path: root/winrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2013-05-10 15:20:08 -0700
committerRobin Watts <robin.watts@artifex.com>2013-05-16 19:25:57 +0100
commit7afefc8342853df50dc1e1a192415cd1164a7382 (patch)
treedd7924dc87f6ba2f5168ddab92755a604a5f2570 /winrt
parent33280868285321bfa3e7e8cad7b77dbfa5ca26f6 (diff)
downloadmupdf-7afefc8342853df50dc1e1a192415cd1164a7382.tar.xz
Implemented zooming and fixed and simplified the binding of several objects to the UI XAML
Diffstat (limited to 'winrt')
-rw-r--r--winrt/mupdf_cpp/DocumentPage.cpp3
-rw-r--r--winrt/mupdf_cpp/DocumentPage.h57
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml4
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.cpp75
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.h2
5 files changed, 93 insertions, 48 deletions
diff --git a/winrt/mupdf_cpp/DocumentPage.cpp b/winrt/mupdf_cpp/DocumentPage.cpp
index c705c237..637a19a4 100644
--- a/winrt/mupdf_cpp/DocumentPage.cpp
+++ b/winrt/mupdf_cpp/DocumentPage.cpp
@@ -10,5 +10,8 @@ namespace mupdf_cpp
this->Width = 0;
this->Zoom = 1.0;
this->Content = NOTSET;
+ _isPropertyChangedObserved = false;
}
}
+
+
diff --git a/winrt/mupdf_cpp/DocumentPage.h b/winrt/mupdf_cpp/DocumentPage.h
index dc006e65..a7585410 100644
--- a/winrt/mupdf_cpp/DocumentPage.h
+++ b/winrt/mupdf_cpp/DocumentPage.h
@@ -8,6 +8,7 @@
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Foundation::Collections;
+using namespace Windows::UI::Xaml::Data;
typedef enum {
FULL_RESOLUTION = 0,
@@ -21,8 +22,7 @@ namespace mupdf_cpp
{
// enables data binding with this class
[Windows::UI::Xaml::Data::Bindable]
-
- public ref class DocumentPage sealed
+ public ref class DocumentPage sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
{
private:
int height;
@@ -42,6 +42,7 @@ namespace mupdf_cpp
void set(IVector<RectList^>^ value)
{
textbox = value;
+ DocumentPage::OnPropertyChanged("TextBox");
}
}
@@ -51,6 +52,7 @@ namespace mupdf_cpp
void set(IVector<RectList^>^ value)
{
linkbox = value;
+ DocumentPage::OnPropertyChanged("LinkBox");
}
}
@@ -112,7 +114,58 @@ namespace mupdf_cpp
void set(WriteableBitmap^ value)
{
image = value;
+ DocumentPage::OnPropertyChanged("Image");
}
}
+
+ private:
+ bool _isPropertyChangedObserved;
+ event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ _privatePropertyChanged;
+
+
+ protected:
+ /// <summary>
+ /// Notifies listeners that a property value has changed.
+ /// </summary>
+ /// <param name="propertyName">Name of the property used to notify listeners.</param>
+ void OnPropertyChanged(String^ propertyName)
+ {
+ if (_isPropertyChangedObserved)
+ {
+ PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ public:
+
+ // in c++, it is not neccessary to include definitions of add, remove, and raise.
+ // these definitions have been made explicitly here so that we can check if the
+ // event has listeners before firing the event
+ virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged
+ {
+ virtual Windows::Foundation::EventRegistrationToken add(Windows::UI::Xaml::Data::PropertyChangedEventHandler^ e)
+ {
+ _isPropertyChangedObserved = true;
+ return _privatePropertyChanged += e;
+ }
+ virtual void remove(Windows::Foundation::EventRegistrationToken t)
+ {
+ _privatePropertyChanged -= t;
+ }
+
+ protected:
+ virtual void raise(Object^ sender, Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e)
+ {
+ if (_isPropertyChangedObserved)
+ {
+ _privatePropertyChanged(sender, e);
+ }
+ }
+ }
+#pragma endregion
+
+
+
+
};
}
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml
index deb262cc..54226eac 100644
--- a/winrt/mupdf_cpp/MainPage.xaml
+++ b/winrt/mupdf_cpp/MainPage.xaml
@@ -82,7 +82,7 @@
HorizontalSnapPointsType="None"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
- MinZoomFactor="1"
+ MinZoomFactor="0.25"
MaxZoomFactor="4">
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="{Binding Height}" Width="{Binding Width}">
<Image Source="{Binding Image}" Width="{Binding Width}" Height="{Binding Height}"
@@ -160,7 +160,7 @@
HorizontalSnapPointsType="None"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
- MinZoomFactor="1"
+ MinZoomFactor="0.25"
MaxZoomFactor="4">
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="{Binding Height}" Width="{Binding Width}">
<Image Source="{Binding Image}" Width="{Binding Width}" Height="{Binding Height}"
diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp
index 61079103..685024e6 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.cpp
+++ b/winrt/mupdf_cpp/MainPage.xaml.cpp
@@ -208,6 +208,22 @@ void MainPage::UpdatePage(int page_num, InMemoryRandomAccessStream^ ras,
m_page_update = false;
}
+/* Set the page with the new raster information but only the image data */
+void MainPage::ReplaceImage(int page_num, InMemoryRandomAccessStream^ ras,
+ Point ras_size)
+{
+ assert(IsMainThread());
+
+ WriteableBitmap ^bmp = ref new WriteableBitmap(ras_size.X, ras_size.Y);
+ bmp->SetSource(ras);
+
+ DocumentPage^ doc_page = this->m_docPages->GetAt(page_num);
+ doc_page->Image = bmp;
+
+ doc_page->Height = ras_size.Y;
+ doc_page->Width = ras_size.X;
+}
+
Point MainPage::ComputePageSize(spatial_info_t spatial_info, int page_num)
{
Point screenSize;
@@ -395,7 +411,6 @@ void mupdf_cpp::MainPage::CleanUp()
m_flip_from_searchlink = false;
m_num_pages = -1;
m_search_rect_count = 0;
- ResetSearch();
m_ren_status = REN_AVAILABLE;
m_links_on = false;
m_rectlist_page = -1;
@@ -590,8 +605,6 @@ void mupdf_cpp::MainPage::OpenDocument(StorageFile^ file)
render_task.then([this, k, ras_size] (InMemoryRandomAccessStream^ ras)
{
- /* Set up the image brush when rendering is completed, must be on
- UI thread */
UpdatePage(k, ras, ras_size, FULL_RESOLUTION);
}, task_continuation_context::use_current());
}
@@ -704,7 +717,6 @@ void mupdf_cpp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows:
this->m_currpage = newValue;
m_sliderchange = true;
this->m_curr_flipView->SelectedIndex = newValue;
- ResetSearch();
}, task_continuation_context::use_current());
}
}
@@ -810,6 +822,7 @@ void mupdf_cpp::MainPage::ShowSearchResults(SearchResult_t result)
screenSize.Y *= screenScale;
pageSize = mu_doc->GetPageSize(m_currpage);
scale = fitPageToScreen(pageSize, screenSize);
+ auto doc_page = this->m_docPages->GetAt(old_page);
/* Construct our list of rectangles */
for (int k = 0; k < result.box_count; k++)
@@ -822,17 +835,13 @@ void mupdf_cpp::MainPage::ShowSearchResults(SearchResult_t result)
rect_item->Width = curr_box->LowerRight.X - curr_box->UpperLeft.X;
rect_item->X = curr_box->UpperLeft.X * scale.X;
rect_item->Y = curr_box->UpperLeft.Y * scale.Y;
- rect_item->Width *= scale.X;
- rect_item->Height *= scale.Y;
+ rect_item->Width *= (scale.X * doc_page->Zoom);
+ rect_item->Height *= (scale.Y * doc_page->Zoom);
rect_item->Index = k.ToString();
m_text_list->Append(rect_item);
}
/* Make sure the current page has its text results cleared */
- auto doc_page = this->m_docPages->GetAt(old_page);
doc_page->TextBox = nullptr;
- m_page_update = true;
- this->m_docPages->SetAt(old_page, doc_page);
- m_page_update = false;
/* Go ahead and set our doc item to this in the vertical and horizontal view */
m_searchpage = new_page;
@@ -874,29 +883,6 @@ void mupdf_cpp::MainPage::CancelSearch(Platform::Object^ sender, Windows::UI::Xa
m_searchcts.cancel();
}
-void mupdf_cpp::MainPage::ResetSearch(void)
-{
- m_searchpage = -1;
-#if 0
- wchar_t buf[20];
- String^ TempString = ref new String(buf);
-
- /* Remove all the rects */
- for (int k = 0; k < this->m_search_rect_count; k++)
- {
- unsigned int index;
- int len = swprintf_s(buf, 20, L"%s_%d", L"Rect",k);
- Rectangle^ curr_rect = (Rectangle^) (m_curr_flipView->FindName(TempString));
- if (curr_rect != nullptr)
- {
- Canvas^ results_Canvas = (Canvas^) curr_rect->Parent;
- results_Canvas->Children->IndexOf(curr_rect, &index);
- results_Canvas->Children->RemoveAt(index);
- }
- }
-#endif
-}
-
void mupdf_cpp::MainPage::AddTextCanvas()
{
/* Go ahead and set our doc item to this in the vertical and horizontal view */
@@ -905,9 +891,6 @@ void mupdf_cpp::MainPage::AddTextCanvas()
if (doc_page->Content == FULL_RESOLUTION) // We should not be doing links for thumbnails
{
doc_page->TextBox = m_text_list;
- m_page_update = true;
- this->m_docPages->SetAt(m_currpage, doc_page);
- m_page_update = false;
}
this->m_search_active = false;
}
@@ -1095,9 +1078,6 @@ void mupdf_cpp::MainPage::Linker(Platform::Object^ sender, Windows::UI::Xaml::Ro
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;
}
}
}
@@ -1109,6 +1089,8 @@ void mupdf_cpp::MainPage::AddLinkCanvas()
{
/* See if the link object for this page has already been computed */
int link_page = m_linkset->GetAt(m_currpage);
+ auto doc_page = this->m_docPages->GetAt(m_currpage);
+
if (!link_page)
{
m_linkset->SetAt(m_currpage, true);
@@ -1141,8 +1123,8 @@ void mupdf_cpp::MainPage::AddLinkCanvas()
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->Width *= (scale.X * doc_page->Zoom);
+ rect_item->Height *= (scale.Y * doc_page->Zoom);
rect_item->Type = curr_link->Type;
rect_item->Urilink = curr_link->Uri;
rect_item->PageNum = curr_link->PageNum;
@@ -1154,13 +1136,11 @@ void mupdf_cpp::MainPage::AddLinkCanvas()
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);
if (doc_page->LinkBox == nullptr)
{
if (doc_page->Content == FULL_RESOLUTION) // We should not be doing links for thumbnails
{
doc_page->LinkBox = m_page_link_list->GetAt(m_currpage);
- this->m_docPages->SetAt(m_currpage, doc_page);
}
}
}
@@ -1319,8 +1299,17 @@ void mupdf_cpp::MainPage::ScrollChanged(Platform::Object^ sender,
if (!e->IsIntermediate)
{
doc_page->Zoom = scrollviewer->ZoomFactor;
+ int page = m_currpage;
/* Render at new resolution */
+ spatial_info_t spatial_info = InitSpatial(doc_page->Zoom);
+ Point ras_size = ComputePageSize(spatial_info, page);
+ auto render_task =
+ create_task(mu_doc->RenderPage(page, ras_size.X, ras_size.Y));
+ render_task.then([this, page, ras_size] (InMemoryRandomAccessStream^ ras)
+ {
+ ReplaceImage(page, ras, ras_size);
+ }, task_continuation_context::use_current());
}
}
diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h
index 562ef704..ad66787f 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.h
+++ b/winrt/mupdf_cpp/MainPage.xaml.h
@@ -103,6 +103,7 @@ namespace mupdf_cpp
bool m_sliderchange;
bool m_update_flip;
+ void ReplaceImage(int page_num, InMemoryRandomAccessStream^ ras, Point ras_size);
void Picker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void Searcher(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OpenDocumentPrep(StorageFile^ file);
@@ -120,7 +121,6 @@ namespace mupdf_cpp
void FlipView_SelectionChanged(Object^ sender, SelectionChangedEventArgs^ e);
void SearchNext(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void SearchPrev(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
- void ResetSearch(void);
void CancelSearch(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void SearchInDirection(int dir, String^ textToFind);
void ShowSearchResults(SearchResult_t result);