From 6c9882818e4afc1502c6200f082794811d394b1c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 24 Apr 2010 18:59:04 +0200 Subject: Fix pdfapp_oncopy logic for inserting newlines. --- apps/pdfapp.c | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 2eb3e395..414d44e7 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -620,10 +620,10 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen) { - ucsbuf[0] = 0; - fz_textspan *ln; - int y, c; - int i, p; + int bx0, bx1, by0, by1; + fz_textspan *span; + int c, i, p; + int seen; int x0 = app->image->x + app->selr.x0 - app->panx; int x1 = app->image->x + app->selr.x1 - app->panx; @@ -631,37 +631,36 @@ void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen) int y1 = app->image->y + app->selr.y1 - app->pany; p = 0; - for (ln = app->text; ln; ln = ln->next) + for (span = app->text; span; span = span->next) { - if (ln->len > 0) + seen = 0; + + for (i = 0; i < span->len; i++) { - y = y0 - 1; - for (i = 0; i < ln->len; i++) + bx0 = span->text[i].bbox.x0; + bx1 = span->text[i].bbox.x1; + by0 = span->text[i].bbox.y0; + by1 = span->text[i].bbox.y1; + + c = span->text[i].c; + if (c < 32) + c = '?'; + if (bx1 >= x0 && bx0 <= x1 && by1 >= y0 && by0 <= y1) { - int bx0, bx1, by0, by1; - - bx0 = ln->text[i].bbox.x0; - bx1 = ln->text[i].bbox.x1; - by0 = ln->text[i].bbox.y0; - by1 = ln->text[i].bbox.y1; - - c = ln->text[i].c; - if (c < 32) - c = '?'; - if (bx1 >= x0 && bx0 <= x1 && by1 >= y0 && by0 <= y1) - if (p < ucslen - 1) - ucsbuf[p++] = c; + if (p < ucslen - 1) + ucsbuf[p++] = c; + seen = 1; } + } - if (y >= y0 && y <= y1) - { + if (seen) + { #ifdef _WIN32 - if (p < ucslen - 1) - ucsbuf[p++] = '\r'; + if (p < ucslen - 1) + ucsbuf[p++] = '\r'; #endif - if (p < ucslen - 1) - ucsbuf[p++] = '\n'; - } + if (p < ucslen - 1) + ucsbuf[p++] = '\n'; } } -- cgit v1.2.3