Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
djvu-text-page.c File Reference
#include <config.h>
#include <string.h>
#include <glib.h>
#include <libdjvu/miniexp.h>
#include "djvu-text-page.h"
+ Include dependency graph for djvu-text-page.c:

Go to the source code of this file.

Functions

static void djvu_text_page_union (EvRectangle *target, EvRectangle *source)
 
static gboolean djvu_text_page_selection_process_box (DjvuTextPage *page, miniexp_t p, int delimit)
 
static gboolean djvu_text_page_selection_process_text (DjvuTextPage *page, miniexp_t p, int delimit)
 
static gboolean djvu_text_page_selection (DjvuSelectionType type, DjvuTextPage *page, miniexp_t p, int delimit)
 
static void djvu_text_page_limits_process (DjvuTextPage *page, miniexp_t p, EvRectangle *rect)
 
static void djvu_text_page_limits (DjvuTextPage *page, miniexp_t p, EvRectangle *rect)
 
GList * djvu_text_page_get_selection_region (DjvuTextPage *page, EvRectangle *rectangle)
 
char * djvu_text_page_copy (DjvuTextPage *page, EvRectangle *rectangle)
 
static miniexp_t djvu_text_page_position (DjvuTextPage *page, int position)
 
static gboolean djvu_text_page_sexpr_process (DjvuTextPage *page, miniexp_t p, miniexp_t start, miniexp_t end)
 
static gboolean djvu_text_page_sexpr (DjvuTextPage *page, miniexp_t p, miniexp_t start, miniexp_t end)
 
static EvRectangledjvu_text_page_box (DjvuTextPage *page, miniexp_t start, miniexp_t end)
 
static void djvu_text_page_append_text (DjvuTextPage *page, miniexp_t p, gboolean case_sensitive, gboolean delimit)
 
void djvu_text_page_search (DjvuTextPage *page, const char *text)
 
void djvu_text_page_index_text (DjvuTextPage *page, gboolean case_sensitive)
 
DjvuTextPagedjvu_text_page_new (miniexp_t text)
 
void djvu_text_page_free (DjvuTextPage *page)
 

Function Documentation

static void djvu_text_page_append_text ( DjvuTextPage page,
miniexp_t  p,
gboolean  case_sensitive,
gboolean  delimit 
)
static

Definition at line 393 of file djvu-text-page.c.

397 {
398  char *token_text;
399  miniexp_t deeper;
400 
401  g_return_if_fail (miniexp_consp (p) &&
402  miniexp_symbolp (miniexp_car (p)));
403 
404  delimit |= page->char_symbol != miniexp_car (p);
405 
406  deeper = miniexp_cddr (miniexp_cdddr (p));
407  while (deeper != miniexp_nil) {
408  miniexp_t data = miniexp_car (deeper);
409  if (miniexp_stringp (data)) {
410  DjvuTextLink link;
411  link.position = page->text == NULL ? 0 :
412  strlen (page->text);
413  link.pair = p;
414  g_array_append_val (page->links, link);
415 
416  token_text = (char *) miniexp_to_str (data);
417  if (!case_sensitive)
418  token_text = g_utf8_casefold (token_text, -1);
419  if (page->text == NULL)
420  page->text = g_strdup (token_text);
421  else {
422  char *new_text =
423  g_strjoin (delimit ? " " : NULL,
424  page->text, token_text,
425  NULL);
426  g_free (page->text);
427  page->text = new_text;
428  }
429  if (!case_sensitive)
430  g_free (token_text);
431  } else
432  djvu_text_page_append_text (page, data,
433  case_sensitive, delimit);
434  delimit = FALSE;
435  deeper = miniexp_cdr (deeper);
436  }
437 }

+ Here is the caller graph for this function:

static EvRectangle* djvu_text_page_box ( DjvuTextPage page,
miniexp_t  start,
miniexp_t  end 
)
static

Definition at line 374 of file djvu-text-page.c.

377 {
378  page->bounding_box = NULL;
379  djvu_text_page_sexpr (page, page->text_structure, start, end);
380  return page->bounding_box;
381 }

+ Here is the caller graph for this function:

char* djvu_text_page_copy ( DjvuTextPage page,
EvRectangle rectangle 
)

Definition at line 234 of file djvu-text-page.c.

236 {
237  char* text;
238 
239  page->start = miniexp_nil;
240  page->end = miniexp_nil;
241  djvu_text_page_limits (page, page->text_structure, rectangle);
243  page->text_structure, 0);
244 
245  /* Do not free the string */
246  text = page->text;
247  page->text = NULL;
248 
249  return text;
250 }

+ Here is the caller graph for this function:

void djvu_text_page_free ( DjvuTextPage page)

Definition at line 515 of file djvu-text-page.c.

516 {
517  g_free (page->text);
518  g_array_free (page->links, TRUE);
519  g_free (page);
520 }

+ Here is the caller graph for this function:

GList* djvu_text_page_get_selection_region ( DjvuTextPage page,
EvRectangle rectangle 
)

Definition at line 218 of file djvu-text-page.c.

220 {
221  page->start = miniexp_nil;
222  page->end = miniexp_nil;
223 
224  /* Get page->start and page->end filled from selection rectangle */
225  djvu_text_page_limits (page, page->text_structure, rectangle);
226  /* Fills page->results with the bouding boxes */
228  page, page->text_structure, 0);
229 
230  return g_list_reverse (page->results);
231 }

+ Here is the caller graph for this function:

void djvu_text_page_index_text ( DjvuTextPage page,
gboolean  case_sensitive 
)

Definition at line 480 of file djvu-text-page.c.

482 {
484  case_sensitive, FALSE);
485 }

+ Here is the caller graph for this function:

static void djvu_text_page_limits ( DjvuTextPage page,
miniexp_t  p,
EvRectangle rect 
)
static

Definition at line 189 of file djvu-text-page.c.

192 {
193  miniexp_t deeper;
194 
195  g_return_if_fail (miniexp_consp (p) &&
196  miniexp_symbolp (miniexp_car (p)));
197 
198  deeper = miniexp_cddr (miniexp_cdddr (p));
199  while (deeper != miniexp_nil) {
200  miniexp_t str = miniexp_car (deeper);
201  if (miniexp_stringp (str))
202  djvu_text_page_limits_process (page, p, rect);
203  else
204  djvu_text_page_limits (page, str, rect);
205 
206  deeper = miniexp_cdr (deeper);
207  }
208 }

+ Here is the caller graph for this function:

static void djvu_text_page_limits_process ( DjvuTextPage page,
miniexp_t  p,
EvRectangle rect 
)
static

Definition at line 169 of file djvu-text-page.c.

172 {
173  EvRectangle current;
174 
175  current.x1 = miniexp_to_int (miniexp_nth (1, p));
176  current.y1 = miniexp_to_int (miniexp_nth (2, p));
177  current.x2 = miniexp_to_int (miniexp_nth (3, p));
178  current.y2 = miniexp_to_int (miniexp_nth (4, p));
179  if (current.x2 >= rect->x1 && current.y1 <= rect->y2 &&
180  current.x1 <= rect->x2 && current.y2 >= rect->y1) {
181  if (page->start == miniexp_nil)
182  page->start = p;
183  page->end = p;
184  }
185 }

+ Here is the caller graph for this function:

DjvuTextPage* djvu_text_page_new ( miniexp_t  text)

djvu_text_page_new: : S-expression of the page text

Creates a new page to search.

Returns: new DjvuTextPage instance

Definition at line 496 of file djvu-text-page.c.

497 {
498  DjvuTextPage *page;
499 
500  page = g_new0 (DjvuTextPage, 1);
501  page->links = g_array_new (FALSE, FALSE, sizeof (DjvuTextLink));
502  page->char_symbol = miniexp_symbol ("char");
503  page->word_symbol = miniexp_symbol ("word");
504  page->text_structure = text;
505  return page;
506 }

+ Here is the caller graph for this function:

static miniexp_t djvu_text_page_position ( DjvuTextPage page,
int  position 
)
static

Definition at line 263 of file djvu-text-page.c.

265 {
266  GArray *links = page->links;
267  int low = 0;
268  int hi = links->len - 1;
269  int mid = 0;
270 
271  g_return_val_if_fail (hi >= 0, miniexp_nil);
272 
273  /* Shamelessly copied from GNU classpath */
274  while (low <= hi) {
275  DjvuTextLink *link;
276 
277  mid = (low + hi) >> 1;
278  link = &g_array_index (links, DjvuTextLink, mid);
279  if (link->position == position)
280  break;
281  else if (link->position > position)
282  hi = --mid;
283  else
284  low = mid + 1;
285  }
286 
287  return g_array_index (page->links, DjvuTextLink, mid).pair;
288 }

+ Here is the caller graph for this function:

void djvu_text_page_search ( DjvuTextPage page,
const char *  text 
)

Definition at line 448 of file djvu-text-page.c.

450 {
451  char *haystack = page->text;
452  int search_len;
453  EvRectangle *result;
454  if (page->links->len == 0)
455  return;
456 
457  search_len = strlen (text);
458  while ((haystack = strstr (haystack, text)) != NULL) {
459  int start_p = haystack - page->text;
460  miniexp_t start = djvu_text_page_position (page, start_p);
461  int end_p = start_p + search_len - 1;
462  miniexp_t end = djvu_text_page_position (page, end_p);
463  result = djvu_text_page_box (page, start, end);
464  g_assert (result);
465  page->results = g_list_prepend (page->results, result);
466  haystack = haystack + search_len;
467  }
468  page->results = g_list_reverse (page->results);
469 }

+ Here is the caller graph for this function:

static gboolean djvu_text_page_selection ( DjvuSelectionType  type,
DjvuTextPage page,
miniexp_t  p,
int  delimit 
)
static

Definition at line 134 of file djvu-text-page.c.

138 {
139  miniexp_t deeper;
140 
141  g_return_val_if_fail (miniexp_consp (p) && miniexp_symbolp
142  (miniexp_car (p)), FALSE);
143 
144  if (miniexp_car (p) != page->char_symbol)
145  delimit |= miniexp_car (p) == page->word_symbol ? 1 : 2;
146 
147  deeper = miniexp_cddr (miniexp_cdddr (p));
148  while (deeper != miniexp_nil) {
149  miniexp_t str = miniexp_car (deeper);
150  if (miniexp_stringp (str)) {
151  if (type == DJVU_SELECTION_TEXT) {
152  if (!djvu_text_page_selection_process_text (page, p, delimit))
153  return FALSE;
154  } else {
155  if (!djvu_text_page_selection_process_box (page, p, delimit))
156  return FALSE;
157  }
158  } else {
159  if (!djvu_text_page_selection (type, page, str, delimit))
160  return FALSE;
161  }
162  delimit = 0;
163  deeper = miniexp_cdr (deeper);
164  }
165  return TRUE;
166 }

+ Here is the caller graph for this function:

static gboolean djvu_text_page_selection_process_box ( DjvuTextPage page,
miniexp_t  p,
int  delimit 
)
static

Definition at line 60 of file djvu-text-page.c.

63 {
64  if (page->results || p == page->start) {
65  EvRectangle box;
66 
67  box.x1 = miniexp_to_int (miniexp_nth (1, p));
68  box.y1 = miniexp_to_int (miniexp_nth (2, p));
69  box.x2 = miniexp_to_int (miniexp_nth (3, p));
70  box.y2 = miniexp_to_int (miniexp_nth (4, p));
71 
72  if (!(delimit & 2) && page->results != NULL) {
73  EvRectangle *union_box = (EvRectangle *)page->results->data;
74 
75  /* If still on the same line, add box to union */
76  djvu_text_page_union (union_box, &box);
77  } else {
78  /* A new line, a new box */
79  page->results = g_list_prepend (page->results, ev_rectangle_copy (&box));
80  }
81 
82  if (p == page->end)
83  return FALSE;
84  }
85  return TRUE;
86 }

+ Here is the caller graph for this function:

static gboolean djvu_text_page_selection_process_text ( DjvuTextPage page,
miniexp_t  p,
int  delimit 
)
static

Definition at line 99 of file djvu-text-page.c.

102 {
103  if (page->text || p == page->start) {
104  char *token_text = (char *) miniexp_to_str (miniexp_nth (5, p));
105  if (page->text) {
106  char *new_text =
107  g_strjoin (delimit & 2 ? "\n" :
108  delimit & 1 ? " " : NULL,
109  page->text, token_text,
110  NULL);
111  g_free (page->text);
112  page->text = new_text;
113  } else
114  page->text = g_strdup (token_text);
115  if (p == page->end)
116  return FALSE;
117  }
118  return TRUE;
119 }

+ Here is the caller graph for this function:

static gboolean djvu_text_page_sexpr ( DjvuTextPage page,
miniexp_t  p,
miniexp_t  start,
miniexp_t  end 
)
static

Definition at line 338 of file djvu-text-page.c.

342 {
343  miniexp_t deeper;
344 
345  g_return_val_if_fail (miniexp_consp (p) && miniexp_symbolp
346  (miniexp_car (p)), FALSE);
347 
348  deeper = miniexp_cddr (miniexp_cdddr (p));
349  while (deeper != miniexp_nil) {
350  miniexp_t str = miniexp_car (deeper);
351  if (miniexp_stringp (str)) {
353  (page, p, start, end))
354  return FALSE;
355  } else {
357  (page, str, start, end))
358  return FALSE;
359  }
360  deeper = miniexp_cdr (deeper);
361  }
362  return TRUE;
363 }

+ Here is the caller graph for this function:

static gboolean djvu_text_page_sexpr_process ( DjvuTextPage page,
miniexp_t  p,
miniexp_t  start,
miniexp_t  end 
)
static

Definition at line 302 of file djvu-text-page.c.

306 {
307  if (page->bounding_box || p == start) {
308  EvRectangle *new_rectangle = ev_rectangle_new ();
309  new_rectangle->x1 = miniexp_to_int (miniexp_nth (1, p));
310  new_rectangle->y1 = miniexp_to_int (miniexp_nth (2, p));
311  new_rectangle->x2 = miniexp_to_int (miniexp_nth (3, p));
312  new_rectangle->y2 = miniexp_to_int (miniexp_nth (4, p));
313  if (page->bounding_box) {
315  new_rectangle);
316  g_free (new_rectangle);
317  } else
318  page->bounding_box = new_rectangle;
319  if (p == end)
320  return FALSE;
321  }
322  return TRUE;
323 }

+ Here is the caller graph for this function:

static void djvu_text_page_union ( EvRectangle target,
EvRectangle source 
)
static

djvu_text_page_union: : first rectangle and result : second rectangle

Calculates the bounding box of two rectangles and stores the result in the first.

Definition at line 36 of file djvu-text-page.c.

38 {
39  if (source->x1 < target->x1)
40  target->x1 = source->x1;
41  if (source->x2 > target->x2)
42  target->x2 = source->x2;
43  if (source->y1 < target->y1)
44  target->y1 = source->y1;
45  if (source->y2 > target->y2)
46  target->y2 = source->y2;
47 }

+ Here is the caller graph for this function: