summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2010-07-08 14:45:29 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2010-07-08 14:45:29 +0200
commitb257428150e2c13dcc24fd8f75e4ee2c679ab414 (patch)
tree89c8dddc9e9ad373d0de9588fd71f63c779838fc
parentbedc88225c948ad1288b69c6c106adce36233442 (diff)
[glib] Add poppler_page_get_selected_text()
And change poppler_page_get_text() to return the text of the whole page. For consistency with poppler_page_get_selection_region() get_seletect_text() doesn't invert the y coords as get_text() did. This change breaks the API. Users of poppler_page_get_text should: - Use the new poppler_page_get_text() if they want the text of the whole page - Use poppler_page_get_selected_text() if they want the text of the selected area. In this case they shouldn't invert the y coords anymore before calling the method.
-rw-r--r--glib/demo/text.c9
-rw-r--r--glib/poppler-page.cc43
-rw-r--r--glib/poppler-page.h3
-rw-r--r--glib/reference/poppler-sections.txt1
4 files changed, 36 insertions, 20 deletions
diff --git a/glib/demo/text.c b/glib/demo/text.c
index b7a5c91b..28e90ae9 100644
--- a/glib/demo/text.c
+++ b/glib/demo/text.c
@@ -69,10 +69,8 @@ pgd_text_get_text (GtkWidget *button,
PgdTextDemo *demo)
{
PopplerPage *page;
- PopplerRectangle rect;
PopplerRectangle *recs = NULL;
guint n_recs;
- gdouble width, height;
gchar *text;
GTimer *timer;
gint i;
@@ -83,13 +81,8 @@ pgd_text_get_text (GtkWidget *button,
gtk_list_store_clear (demo->model);
- poppler_page_get_size (page, &width, &height);
- rect.x1 = rect.y1 = 0;
- rect.x2 = width;
- rect.y2 = height;
-
timer = g_timer_new ();
- text = poppler_page_get_text (page, POPPLER_SELECTION_GLYPH, &rect);
+ text = poppler_page_get_text (page);
g_timer_stop (timer);
if (text) {
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 031edc74..5b35d8c6 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -912,23 +912,23 @@ poppler_page_selection_region_free (GList *region)
}
/**
- * poppler_page_get_text:
+ * poppler_page_get_selected_text:
* @page: a #PopplerPage
* @style: a #PopplerSelectionStyle
* @selection: the #PopplerRectangle including the text
- *
+ *
* Retrieves the contents of the specified @selection as text.
- *
+ *
* Return value: a pointer to the contents of the @selection
* as a string
+ * Since: 0.16
**/
char *
-poppler_page_get_text (PopplerPage *page,
- PopplerSelectionStyle style,
- PopplerRectangle *selection)
+poppler_page_get_selected_text (PopplerPage *page,
+ PopplerSelectionStyle style,
+ PopplerRectangle *selection)
{
GooString *sel_text;
- double height;
char *result;
TextPage *text;
SelectionStyle selection_style = selectionStyleGlyph;
@@ -937,11 +937,10 @@ poppler_page_get_text (PopplerPage *page,
g_return_val_if_fail (POPPLER_IS_PAGE (page), FALSE);
g_return_val_if_fail (selection != NULL, NULL);
- poppler_page_get_size (page, NULL, &height);
pdf_selection.x1 = selection->x1;
- pdf_selection.y1 = height - selection->y2;
+ pdf_selection.y1 = selection->y1;
pdf_selection.x2 = selection->x2;
- pdf_selection.y2 = height - selection->y1;
+ pdf_selection.y2 = selection->y2;
switch (style)
{
@@ -965,6 +964,28 @@ poppler_page_get_text (PopplerPage *page,
}
/**
+ * poppler_page_get_text:
+ * @page: a #PopplerPage
+ *
+ * Retrieves the text of @page.
+ *
+ * Return value: a pointer to the text of the @page
+ * as a string
+ * Since: 0.16
+ **/
+char *
+poppler_page_get_text (PopplerPage *page)
+{
+ PopplerRectangle rectangle = {0, 0, 0, 0};
+
+ g_return_val_if_fail (POPPLER_IS_PAGE (page), FALSE);
+
+ poppler_page_get_size (page, &rectangle.x2, &rectangle.y2);
+
+ return poppler_page_get_selected_text (page, POPPLER_SELECTION_GLYPH, &rectangle);
+}
+
+/**
* poppler_page_find_text:
* @page: a #PopplerPage
* @text: the text to search for (UTF-8 encoded)
@@ -1908,7 +1929,7 @@ poppler_page_get_crop_box (PopplerPage *page, PopplerRectangle *rect)
* This array must be freed with g_free () when done.
*
* The position in the array represents an offset in the text returned by
- * poppler_page_get_text
+ * poppler_page_get_text()
*
* Return value: %TRUE if the page contains text, %FALSE otherwise
*
diff --git a/glib/poppler-page.h b/glib/poppler-page.h
index 785c48ff..6af7d89b 100644
--- a/glib/poppler-page.h
+++ b/glib/poppler-page.h
@@ -94,7 +94,8 @@ GList *poppler_page_find_text (PopplerPage *page,
const char *text);
void poppler_page_render_to_ps (PopplerPage *page,
PopplerPSFile *ps_file);
-char *poppler_page_get_text (PopplerPage *page,
+char *poppler_page_get_text (PopplerPage *page);
+char *poppler_page_get_selected_text (PopplerPage *page,
PopplerSelectionStyle style,
PopplerRectangle *selection);
GList *poppler_page_get_selection_region (PopplerPage *page,
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 012eb281..ab91b9a3 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -31,6 +31,7 @@ poppler_page_render_selection
poppler_page_render_selection_to_pixbuf
poppler_page_get_selection_region
poppler_page_selection_region_free
+poppler_page_get_selected_text
poppler_page_find_text
poppler_page_get_text
poppler_page_get_text_layout