mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 23:13:48 +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
ca9a381bb0
commit
c38d89bb15
79
zathura.c
79
zathura.c
@ -3399,7 +3399,7 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||
if(!Zathura.PDF.document)
|
||||
return FALSE;
|
||||
|
||||
double scale, offset_x, offset_y;
|
||||
double scale, offset_x, offset_y, page_width, page_height;
|
||||
PopplerRectangle rectangle;
|
||||
cairo_t* cairo;
|
||||
|
||||
@ -3424,36 +3424,79 @@ cb_view_button_release(GtkWidget* widget, GdkEventButton* event, gpointer data)
|
||||
cairo_fill(cairo);
|
||||
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 */
|
||||
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);
|
||||
rectangle.x1 = (rectangle.x1 - offset_x) / scale;
|
||||
rectangle.y1 = (rectangle.y1 - offset_y) / scale;
|
||||
rectangle.x2 = (rectangle.x2 - offset_x) / 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));
|
||||
char* selected_text = poppler_page_get_text(Zathura.PDF.pages[Zathura.PDF.page_number]->page,
|
||||
POPPLER_SELECTION_GLYPH, &rectangle);
|
||||
char* selected_text = poppler_page_get_text(
|
||||
Zathura.PDF.pages[Zathura.PDF.page_number]->page,POPPLER_SELECTION_GLYPH,
|
||||
&rectangle);
|
||||
|
||||
if(selected_text)
|
||||
{
|
||||
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));
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user