mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-15 01:55:59 +01:00
Select right text in rectangle
With this commit zathura selects the text in the selected rectangle and copies it to the clipboard.
This commit is contained in:
parent
e17a8b433a
commit
ee182e035a
1 changed files with 81 additions and 38 deletions
79
zathura.c
79
zathura.c
|
@ -3122,7 +3122,7 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||||
if(!Zathura.PDF.document)
|
if(!Zathura.PDF.document)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
double scale, offset_x, offset_y;
|
double scale, offset_x, offset_y, page_width, page_height;
|
||||||
PopplerRectangle rectangle;
|
PopplerRectangle rectangle;
|
||||||
cairo_t* cairo;
|
cairo_t* cairo;
|
||||||
|
|
||||||
|
@ -3147,36 +3147,79 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||||
cairo_fill(cairo);
|
cairo_fill(cairo);
|
||||||
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
gtk_widget_queue_draw(Zathura.UI.drawing_area);
|
||||||
|
|
||||||
/* reset points of the rectangle so that p1 is in the top-left corner
|
|
||||||
* and p2 is in the bottom right corner */
|
|
||||||
if(rectangle.x1 > rectangle.x2)
|
|
||||||
{
|
|
||||||
double d = rectangle.x1 - rectangle.x2;
|
|
||||||
rectangle.x1 = rectangle.x1 - d;
|
|
||||||
rectangle.x2 = rectangle.x2 - d;
|
|
||||||
}
|
|
||||||
if(rectangle.y2 > rectangle.y1)
|
|
||||||
{
|
|
||||||
double d = rectangle.y2 - rectangle.y1;
|
|
||||||
rectangle.y1 = rectangle.y1 + d;
|
|
||||||
rectangle.y2 = rectangle.y2 - d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* resize selection rectangle to document page */
|
/* resize selection rectangle to document page */
|
||||||
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
||||||
|
poppler_page_get_size(Zathura.PDF.pages[Zathura.PDF.page_number]->page, &page_width, &page_height);
|
||||||
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
||||||
|
|
||||||
scale = ((double) Zathura.PDF.scale / 100.0);
|
scale = ((double) Zathura.PDF.scale / 100.0);
|
||||||
rectangle.x1 = (rectangle.x1 - offset_x) / scale;
|
rectangle.x1 = (rectangle.x1 - offset_x) / scale;
|
||||||
rectangle.y1 = (rectangle.y1 - offset_y) / scale;
|
rectangle.y1 = (rectangle.y1 - offset_y) / scale;
|
||||||
rectangle.x2 = (rectangle.x2 - offset_x) / scale;
|
rectangle.x2 = (rectangle.x2 - offset_x) / scale;
|
||||||
rectangle.y2 = (rectangle.y2 - offset_y) / scale;
|
rectangle.y2 = (rectangle.y2 - offset_y) / scale;
|
||||||
|
|
||||||
|
/* rotation */
|
||||||
|
int rotate = Zathura.PDF.rotate;
|
||||||
|
double x1 = rectangle.x1;
|
||||||
|
double x2 = rectangle.x2;
|
||||||
|
double y1 = rectangle.y1;
|
||||||
|
double y2 = rectangle.y2;
|
||||||
|
|
||||||
|
switch(rotate)
|
||||||
|
{
|
||||||
|
case 90:
|
||||||
|
rectangle.x1 = y1;
|
||||||
|
rectangle.y1 = page_height - x2;
|
||||||
|
rectangle.x2 = y2;
|
||||||
|
rectangle.y2 = page_height - x1;
|
||||||
|
break;
|
||||||
|
case 180:
|
||||||
|
rectangle.x1 = (page_height - y1);
|
||||||
|
rectangle.y1 = (page_width - x2);
|
||||||
|
rectangle.x2 = (page_height - y2);
|
||||||
|
rectangle.y2 = (page_width - x1);
|
||||||
|
break;
|
||||||
|
case 270:
|
||||||
|
rectangle.x1 = page_width - y2;
|
||||||
|
rectangle.y1 = x1;
|
||||||
|
rectangle.x2 = page_width - y1;
|
||||||
|
rectangle.y2 = x2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reset points of the rectangle so that p1 is in the top-left corner
|
||||||
|
* and p2 is in the bottom right corner */
|
||||||
|
if(rectangle.x1 > rectangle.x2)
|
||||||
|
{
|
||||||
|
double d = rectangle.x1;
|
||||||
|
rectangle.x1 = rectangle.x2;
|
||||||
|
rectangle.x2 = d;
|
||||||
|
}
|
||||||
|
if(rectangle.y2 > rectangle.y1)
|
||||||
|
{
|
||||||
|
double d = rectangle.y1;
|
||||||
|
rectangle.y1 = rectangle.y2;
|
||||||
|
rectangle.y2 = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* adapt y coordinates */
|
||||||
|
rectangle.y1 = page_height - rectangle.y1;
|
||||||
|
rectangle.y2 = page_height - rectangle.y2;
|
||||||
|
|
||||||
|
/* get selected text */
|
||||||
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_lock(&(Zathura.Lock.pdflib_lock));
|
||||||
char* selected_text = poppler_page_get_text(Zathura.PDF.pages[Zathura.PDF.page_number]->page,
|
char* selected_text = poppler_page_get_text(
|
||||||
POPPLER_SELECTION_GLYPH, &rectangle);
|
Zathura.PDF.pages[Zathura.PDF.page_number]->page,POPPLER_SELECTION_GLYPH,
|
||||||
|
&rectangle);
|
||||||
|
|
||||||
if(selected_text)
|
if(selected_text)
|
||||||
|
{
|
||||||
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), selected_text, -1);
|
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), selected_text, -1);
|
||||||
|
g_free(selected_text);
|
||||||
|
}
|
||||||
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
g_static_mutex_unlock(&(Zathura.Lock.pdflib_lock));
|
||||||
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue