static gint luaH_page_search(lua_State *L) { page_info_t *p = lua_touserdata(L, lua_upvalueindex(1)); const gchar *text = luaL_checkstring(L, 2); p->search_matches = poppler_page_find_text(p->page, text); return 0; }
static find_result_t find_next( find_context_t* fc ) { switch ( fc->state ) { case FIND_STATE_INIT : fc->page = document_get_page( fc->doc, fc->page_index ); { int size = strlen( fc->text ) + 32; char* key = ( char* )malloc( size ); gpointer match; if ( key == NULL ) { return FIND_NONE; } snprintf( key, size, "%p%s", fc->page->page, fc->text ); if ( ( match = g_hash_table_lookup( fc->doc->match_table, key ) ) == fc->doc->match_table ) { fc->match_list = NULL; free( key ); } else if ( match == NULL ) { poppler_lock(); fc->match_list = poppler_page_find_text( fc->page->page, fc->text ); poppler_unlock(); if ( fc->match_list != NULL ) { g_hash_table_insert( fc->doc->match_table, key, fc->match_list ); } else { g_hash_table_insert( fc->doc->match_table, key, fc->doc->match_table ); } } else { fc->match_list = ( GList* )match; free( key ); } } if ( fc->match_list != NULL ) { if ( fc->direction == FIND_FORWARD ) { fc->match = fc->match_list; } else { fc->match = g_list_last( fc->match_list ); } fc->state = FIND_STATE_MATCH; if ( fc->wrapped ) { fc->wrapped = FALSE; return FIND_OK_WRAPPED; } return FIND_OK; } if ( ++fc->no_match_since == document_get_page_count( fc->doc ) ) { fc->state = FIND_STATE_NONE; return FIND_NONE; } fc->match = NULL; fc->state = FIND_STATE_SEARCH; return find_next( fc ); case FIND_STATE_MATCH : fc->no_match_since = 0; fc->state = FIND_STATE_SEARCH; return find_next( fc ); case FIND_STATE_SEARCH : if ( fc->match != NULL ) { if ( fc->direction == FIND_FORWARD ) { fc->match = fc->match->next; } else { fc->match = fc->match->prev; } if ( fc->match != NULL) { fc->wrapped = FALSE; fc->state = FIND_STATE_MATCH; return FIND_OK; } } if ( fc->direction == FIND_FORWARD ) { if ( ++fc->page_index == document_get_page_count( fc->doc ) ) { fc->page_index = 0; fc->wrapped = TRUE; } } else { if ( --fc->page_index == -1 ) { fc->page_index = document_get_page_count( fc->doc ) - 1; fc->wrapped = TRUE; } } fc->state = FIND_STATE_INIT; return find_next( fc ); case FIND_STATE_NONE : return FIND_NONE; } /* for compiler satisfaction */ return FIND_NONE; }
static VALUE rg_find_text(VALUE self, VALUE text) { return GLIST2ARY2F(poppler_page_find_text(SELF(self), RVAL2CSTR(text)), POPPLER_TYPE_RECTANGLE); }