summaryrefslogtreecommitdiff
path: root/winrt
diff options
context:
space:
mode:
authorMichael Vrhel <michael.vrhel@artifex.com>2013-05-08 22:04:34 -0700
committerRobin Watts <robin.watts@artifex.com>2013-05-16 19:25:54 +0100
commit8c3eb4b417ebb3e9bdd0c0ce12ffa4b22fd05621 (patch)
tree22b0d8ff21c2bd67df5899da78845fe0105319a1 /winrt
parent165a3528f5a48ba9c4f30d18330875b6070ddf96 (diff)
downloadmupdf-8c3eb4b417ebb3e9bdd0c0ce12ffa4b22fd05621.tar.xz
Text search working now. This is done in a similar fashion the the links
Still need a to fix a few minor issues including a progress bar
Diffstat (limited to 'winrt')
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml4
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.cpp128
-rw-r--r--winrt/mupdf_cpp/MainPage.xaml.h1
-rw-r--r--winrt/mupdfwinrt/muctx.cpp2
-rw-r--r--winrt/mupdfwinrt/mudocument.cpp1
5 files changed, 58 insertions, 78 deletions
diff --git a/winrt/mupdf_cpp/MainPage.xaml b/winrt/mupdf_cpp/MainPage.xaml
index 23413db9..deb262cc 100644
--- a/winrt/mupdf_cpp/MainPage.xaml
+++ b/winrt/mupdf_cpp/MainPage.xaml
@@ -90,7 +90,7 @@
<!-- After much work, figured out how to have a binding for the rectangles. TextBox and LinkBox are
a collection that is in the other main collection used for the scroll viewer. It works
nicely and cleanly once you figure out how to set up all the templates and the bindings -->
- <ItemsControl ItemsSource="{Binding Path=TextBox}">
+ <ItemsControl ItemsSource="{Binding Path=TextBox}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
@@ -104,7 +104,7 @@
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
- <Rectangle Name="{Binding Index}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}">
+ <Rectangle Tag="{Binding Path=Index}" Width="{Binding Path=Width}" Height="{Binding Path=Height}" Fill="{Binding Path=Color}">
<Rectangle.RenderTransform>
<TranslateTransform X="{Binding Path=X}" Y="{Binding Path=Y}"/>
</Rectangle.RenderTransform>
diff --git a/winrt/mupdf_cpp/MainPage.xaml.cpp b/winrt/mupdf_cpp/MainPage.xaml.cpp
index 60350170..1f786e55 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.cpp
+++ b/winrt/mupdf_cpp/MainPage.xaml.cpp
@@ -74,8 +74,8 @@ extern "C" {
MainPage::MainPage()
{
InitializeComponent();
- m_textcolor="#2572AC40";
- m_linkcolor="#AC722540";
+ m_textcolor="#402572AC";
+ m_linkcolor="#40AC7225";
mu_doc = nullptr;
m_docPages = ref new Platform::Collections::Vector<DocumentPage^>();
m_thumbnails = ref new Platform::Collections::Vector<DocumentPage^>();
@@ -670,6 +670,10 @@ void mupdf_cpp::MainPage::Slider_ValueChanged(Platform::Object^ sender, Windows:
}
if (m_init_done && this->xaml_PageSlider->IsEnabled)
{
+ /* Make sure to clear any text search */
+ auto doc_old = this->m_docPages->GetAt(m_currpage);
+ doc_old->TextBox = nullptr;
+
auto doc = this->m_docPages->GetAt(newValue);
if (doc->Content != FULL_RESOLUTION)
{
@@ -716,7 +720,9 @@ void mupdf_cpp::MainPage::FlipView_SelectionChanged(Object^ sender, SelectionCha
}
else
{
- ResetSearch();
+ /* Make sure to clear any text search */
+ auto doc_old = this->m_docPages->GetAt(m_currpage);
+ doc_old->TextBox = nullptr;
}
/* Get the current page */
int curr_page = this->m_currpage;
@@ -773,83 +779,57 @@ void mupdf_cpp::MainPage::ShowSearchResults(SearchResult_t result)
int height, width;
int old_page = this->m_currpage;
int new_page = result.page_num;
- spatial_info_t spatial_info = InitSpatial(1);
- return;
- /* This will be fixed and turned on when I determine how best to show the
- canvas and bind to the xmal content */
-#if 0
- this->m_ren_status = REN_PAGE;
- task<Canvas^> the_task = RenderPage_Task(m_doc, new_page, &width, &height,
- spatial_info, &m_renderedImage);
- the_task.then([this, old_page, new_page](task<Canvas^> the_task)
- {
- assert(IsMainThread());
-
- try
- {
- this->m_renderedCanvas = the_task.get();
- }
- catch (const task_canceled& e)
- {
- this->m_renderedCanvas = nullptr;
- }
- ReplacePage(new_page);
- this->m_ren_status = REN_AVAILABLE;
- this->ReleasePages(old_page, new_page);
- }, task_continuation_context::use_current()).then([this, result]()
-
- {
- /* Once the rendering is done launch this task to show the result */
- Point screenSize;
- Point pageSize;
- Point scale;
+ /* Clear out any old search result */
+ if (m_text_list != nullptr && m_text_list->Size > 0)
+ m_text_list->Clear();
- if (this->m_links_on)
- {
- fz_drop_link(ctx, this->m_links);
- AddLinkCanvas();
- }
- fz_page *page = fz_load_page(m_doc, result.page_num);
- FlipViewItem ^flipview_temp = (FlipViewItem^) m_curr_flipView->Items->GetAt(result.page_num);
- Canvas^ results_Canvas = (Canvas^) (flipview_temp->Content);
+ /* Compute any scalings */
+ Point screenSize;
+ Point pageSize;
+ Point scale;
- m_searchpage = result.page_num;
+ screenSize.Y = this->ActualHeight;
+ screenSize.X = this->ActualWidth;
+ screenSize.X *= screenScale;
+ screenSize.Y *= screenScale;
+ pageSize = mu_doc->GetPageSize(m_currpage);
+ scale = fitPageToScreen(pageSize, screenSize);
- screenSize.Y = this->ActualHeight;
- screenSize.X = this->ActualWidth;
+ /* Construct our list of rectangles */
+ for (int k = 0; k < result.box_count; k++)
+ {
+ RectList^ rect_item = ref new RectList();
+ auto curr_box = mu_doc->GetTextSearch(k);
+
+ rect_item->Color = m_textcolor;
+ rect_item->Height = curr_box->LowerRight.Y - curr_box->UpperLeft.Y;
+ 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->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;
- screenSize.X *= screenScale;
- screenSize.Y *= screenScale;
-
- pageSize = measurePage(m_doc, page);
- scale = fitPageToScreen(pageSize, screenSize);
+ /* Now get the upcoming page */
+ auto doc_page_new = this->m_docPages->GetAt(new_page);
+ doc_page_new->TextBox = m_text_list;
+ m_page_update = true;
+ this->m_docPages->SetAt(new_page, doc_page_new);
+ m_page_update = false;
- /* Now add the rects */
- for (int k = 0; k < result.box_count && k < MAX_SEARCH; k++)
- {
- /* Create a new ref counted Rectangle */
- Rectangle^ a_rectangle = ref new Rectangle();
- TranslateTransform ^trans_transform = ref new TranslateTransform();
- a_rectangle->Width = hit_bbox[k].x1 - hit_bbox[k].x0;
- a_rectangle->Height = hit_bbox[k].y1 - hit_bbox[k].y0;
- trans_transform->X = hit_bbox[k].x0 * scale.X;
- trans_transform->Y = hit_bbox[k].y0 * scale.Y;
- a_rectangle->Width *= scale.X;
- a_rectangle->Height *= scale.Y;
- a_rectangle->RenderTransform = trans_transform;
- a_rectangle->Fill = m_textcolor_brush;
- results_Canvas->Children->Append(a_rectangle);
- m_search_rect_count += 1;
- }
- if (result.box_count > 0)
- {
- m_flip_from_searchlink = true;
- this->m_curr_flipView->SelectedIndex = result.page_num;
- m_currpage = result.page_num;
- }
- }, task_continuation_context::use_current());
-#endif
+ /* Go ahead and set our doc item to this in the vertical and horizontal view */
+ m_searchpage = new_page;
+ this->m_curr_flipView->SelectedIndex = new_page;
+ return;
}
void mupdf_cpp::MainPage::SearchNext(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
diff --git a/winrt/mupdf_cpp/MainPage.xaml.h b/winrt/mupdf_cpp/MainPage.xaml.h
index 2c73b67d..257d9d4d 100644
--- a/winrt/mupdf_cpp/MainPage.xaml.h
+++ b/winrt/mupdf_cpp/MainPage.xaml.h
@@ -135,7 +135,6 @@ namespace mupdf_cpp
void ReleasePages(int old_page, int new_page);
void Linker(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void AddLinkCanvas();
- int JumpToLink(int index);
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/mupdfwinrt/muctx.cpp b/winrt/mupdfwinrt/muctx.cpp
index ec10b493..e3d56a0f 100644
--- a/winrt/mupdfwinrt/muctx.cpp
+++ b/winrt/mupdfwinrt/muctx.cpp
@@ -320,7 +320,7 @@ int muctx::GetTextSearch(int page_num, char* needle, sh_vector_text texts_vec)
text_search->upper_left.X = mu_hit_bbox[k].x0;
text_search->upper_left.Y = mu_hit_bbox[k].y0;
text_search->lower_right.X = mu_hit_bbox[k].x1;
- text_search->lower_right.Y = mu_hit_bbox[k].x1;
+ text_search->lower_right.Y = mu_hit_bbox[k].y1;
texts_vec->push_back(text_search);
}
}
diff --git a/winrt/mupdfwinrt/mudocument.cpp b/winrt/mupdfwinrt/mudocument.cpp
index fef09612..c38c2096 100644
--- a/winrt/mupdfwinrt/mudocument.cpp
+++ b/winrt/mupdfwinrt/mudocument.cpp
@@ -194,6 +194,7 @@ int mudocument::ComputeTextSearch(String^ text, int page_num)
return num_items;
}
+/* Returns the kth item for a page after a text search query */
Links^ mudocument::GetTextSearch(int k)
{
if (k >= this->textsearch->Size)