r4226 bursa - in /trunk/netsurf/content: fetch.h fetchcache.c fetchers/fetch_curl.c
by netsurf@semichrome.net
Author: bursa
Date: Thu May 29 23:11:16 2008
New Revision: 4226
URL: http://source.netsurf-browser.org?rev=4226&view=rev
Log:
Add new fetch callback FETCH_HEADER for headers and move as much header parsing as possible from fetch_curl.c to fetchcache.c. This simplifies fetch_curl.c and will make it possible to store response headers in future.
Modified:
trunk/netsurf/content/fetch.h
trunk/netsurf/content/fetchcache.c
trunk/netsurf/content/fetchers/fetch_curl.c
Modified: trunk/netsurf/content/fetch.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/fetch.h?rev=4226&...
==============================================================================
--- trunk/netsurf/content/fetch.h (original)
+++ trunk/netsurf/content/fetch.h Thu May 29 23:11:16 2008
@@ -30,6 +30,7 @@
typedef enum {
FETCH_TYPE,
FETCH_PROGRESS,
+ FETCH_HEADER,
FETCH_DATA,
FETCH_FINISHED,
FETCH_ERROR,
Modified: trunk/netsurf/content/fetchcache.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/fetchcache.c?rev=...
==============================================================================
--- trunk/netsurf/content/fetchcache.c (original)
+++ trunk/netsurf/content/fetchcache.c Thu May 29 23:11:16 2008
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <regex.h>
#include <time.h>
+#include <curl/curl.h> /* for curl_getdate() */
#include "utils/config.h"
#include "content/content.h"
#include "content/fetchcache.h"
@@ -47,6 +48,8 @@
static void fetchcache_callback(fetch_msg msg, void *p, const void *data,
unsigned long size);
static char *fetchcache_parse_type(const char *s, char **params[]);
+static void fetchcache_parse_header(struct content *c, const char *data,
+ size_t size);
static void fetchcache_error_page(struct content *c, const char *error);
static void fetchcache_cache_update(struct content *c,
const struct cache_data *data);
@@ -445,6 +448,12 @@
content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
break;
+ case FETCH_HEADER:
+ LOG(("FETCH_HEADER \"%.*s\"",
+ (int) size, (char *) data));
+ fetchcache_parse_header(c, data, size);
+ break;
+
case FETCH_DATA:
if (!content_process_data(c, data, size)) {
fetch_abort(c->fetch);
@@ -453,8 +462,6 @@
break;
case FETCH_FINISHED:
- fetchcache_cache_update(c,
- (const struct cache_data *)data);
c->fetch = 0;
content_set_status(c, messages_get("Converting"),
c->source_size);
@@ -605,6 +612,96 @@
/**
+ * Parse an HTTP response header.
+ *
+ * See RFC 2616 4.2.
+ */
+
+void fetchcache_parse_header(struct content *c, const char *data,
+ size_t size)
+{
+ size_t i;
+
+#define SKIP_ST(o) for (i = (o); i < size && (data[i] == ' ' || data[i] == '\t'); i++)
+
+ /* Set fetch response time if not already set */
+ if (c->cache_data->res_time == 0)
+ c->cache_data->res_time = time(0);
+
+ if (5 < size && strncasecmp(data, "Date:", 5) == 0) {
+ /* extract Date header */
+ SKIP_ST(5);
+ if (i < size)
+ c->cache_data->date = curl_getdate(&data[i], NULL);
+ } else if (4 < size && strncasecmp(data, "Age:", 4) == 0) {
+ /* extract Age header */
+ SKIP_ST(4);
+ if (i < size && '0' <= data[i] && data[i] <= '9')
+ c->cache_data->age = atoi(data + i);
+ } else if (8 < size && strncasecmp(data, "Expires:", 8) == 0) {
+ /* extract Expires header */
+ SKIP_ST(8);
+ if (i < size)
+ c->cache_data->expires = curl_getdate(&data[i], NULL);
+ } else if (14 < size && strncasecmp(data, "Cache-Control:", 14) == 0) {
+ /* extract and parse Cache-Control header */
+ size_t comma;
+ SKIP_ST(14);
+
+ while (i < size) {
+ for (comma = i; comma < size; comma++)
+ if (data[comma] == ',')
+ break;
+
+ SKIP_ST(i);
+
+ if (8 < comma - i && (strncasecmp(data + i, "no-cache", 8) == 0 || strncasecmp(data + i, "no-store", 8) == 0))
+ /* When we get a disk cache we should
+ * distinguish between these two */
+ c->cache_data->no_cache = true;
+ else if (7 < comma - i && strncasecmp(data + i, "max-age", 7) == 0) {
+ for (; i < comma; i++)
+ if (data[i] == '=')
+ break;
+ SKIP_ST(i+1);
+ if (i < comma)
+ c->cache_data->max_age =
+ atoi(data + i);
+ }
+
+ i = comma + 1;
+ }
+ } else if (5 < size && strncasecmp(data, "ETag:", 5) == 0) {
+ /* extract ETag header */
+ free(c->cache_data->etag);
+ c->cache_data->etag = talloc_array(c, char, size);
+ if (!c->cache_data->etag) {
+ LOG(("malloc failed"));
+ return;
+ }
+ SKIP_ST(5);
+ strncpy(c->cache_data->etag, data + i, size - i);
+ c->cache_data->etag[size - i] = '\0';
+ for (i = size - i - 1; i >= 0 &&
+ (c->cache_data->etag[i] == ' ' ||
+ c->cache_data->etag[i] == '\t' ||
+ c->cache_data->etag[i] == '\r' ||
+ c->cache_data->etag[i] == '\n'); --i)
+ c->cache_data->etag[i] = '\0';
+ } else if (14 < size && strncasecmp(data, "Last-Modified:", 14) == 0) {
+ /* extract Last-Modified header */
+ SKIP_ST(14);
+ if (i < size) {
+ c->cache_data->last_modified =
+ curl_getdate(&data[i], NULL);
+ }
+ }
+
+ return;
+}
+
+
+/**
* Generate an error page.
*
* \param c empty content to generate the page in
@@ -682,7 +779,7 @@
struct content *fb;
union content_msg_data msg_data;
- assert(c && data);
+ assert(c);
assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
/* Look for cached content */
@@ -748,8 +845,7 @@
c->status = CONTENT_STATUS_ERROR;
/* and update fallback's cache control data */
- fetchcache_cache_update(fb,
- (const struct cache_data *)data);
+ fetchcache_cache_update(fb, c->cache_data);
}
else {
/* No cached content, so unconditionally refetch */
Modified: trunk/netsurf/content/fetchers/fetch_curl.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/fetchers/fetch_cu...
==============================================================================
--- trunk/netsurf/content/fetchers/fetch_curl.c (original)
+++ trunk/netsurf/content/fetchers/fetch_curl.c Thu May 29 23:11:16 2008
@@ -24,7 +24,7 @@
* This implementation uses libcurl's 'multi' interface.
*
*
- * The CURL handles are cached in the cache_ring. There are at most
+ * The CURL handles are cached in the curl_handle_ring. There are at most
* ::option_max_cached_fetch_handles in this ring.
*/
@@ -81,7 +81,6 @@
char *post_urlenc; /**< Url encoded POST string, or 0. */
unsigned long http_code; /**< HTTP result code from cURL. */
struct curl_httppost *post_multipart; /**< Multipart post data, or 0. */
- struct cache_data cachedata; /**< Cache control data */
time_t last_modified; /**< If-Modified-Since time */
time_t file_etag; /**< ETag for local objects */
#ifdef WITH_SSL
@@ -340,15 +339,6 @@
fetch->post_urlenc = strdup(post_urlenc);
else if (post_multipart)
fetch->post_multipart = fetch_curl_post_convert(post_multipart);
- fetch->cachedata.req_time = time(0);
- fetch->cachedata.res_time = 0;
- fetch->cachedata.date = 0;
- fetch->cachedata.expires = 0;
- fetch->cachedata.age = INVALID_AGE;
- fetch->cachedata.max_age = INVALID_AGE;
- fetch->cachedata.no_cache = false;
- fetch->cachedata.etag = 0;
- fetch->cachedata.last_modified = 0;
fetch->last_modified = 0;
fetch->file_etag = 0;
fetch->http_code = 0;
@@ -700,7 +690,6 @@
free(f->post_urlenc);
if (f->post_multipart)
curl_formfree(f->post_multipart);
- free(f->cachedata.etag);
#ifdef WITH_SSL
for (i = 0; i < MAX_CERTS && f->cert_data[i].cert; i++) {
@@ -764,7 +753,6 @@
bool abort;
struct curl_fetch_info *f;
CURLcode code;
- struct cache_data cachedata;
#ifdef WITH_SSL
struct cert_info certs[MAX_CERTS];
memset(certs, 0, sizeof(certs));
@@ -810,19 +798,10 @@
fetch_curl_stop(f);
- /* If finished, acquire cache info to pass to callback */
- if (finished) {
- memcpy(&cachedata, &f->cachedata, sizeof(struct cache_data));
- f->cachedata.etag = 0;
- }
-
if (abort)
; /* fetch was aborted: no callback */
- else if (finished) {
- fetch_send_callback(FETCH_FINISHED, f->fetch_handle,
- &cachedata, 0);
- free(cachedata.etag);
- }
+ else if (finished)
+ fetch_send_callback(FETCH_FINISHED, f->fetch_handle, 0, 0);
#ifdef WITH_SSL
else if (cert) {
int i;
@@ -1009,6 +988,8 @@
/**
* Callback function for headers.
+ *
+ * See RFC 2616 4.2.
*/
size_t fetch_curl_header(char *data, size_t size, size_t nmemb,
@@ -1017,11 +998,9 @@
int i;
size *= nmemb;
+ fetch_send_callback(FETCH_HEADER, f->fetch_handle, data, size);
+
#define SKIP_ST(o) for (i = (o); i < (int) size && (data[i] == ' ' || data[i] == '\t'); i++)
-
- /* Set fetch response time if not already set */
- if (f->cachedata.res_time == 0)
- f->cachedata.res_time = time(0);
if (12 < size && strncasecmp(data, "Location:", 9) == 0) {
/* extract Location header */
@@ -1075,73 +1054,6 @@
f->realm[i] = '\0';
}
#endif
- } else if (5 < size && strncasecmp(data, "Date:", 5) == 0) {
- /* extract Date header */
- SKIP_ST(5);
- if (i < (int) size)
- f->cachedata.date = curl_getdate(&data[i], NULL);
- } else if (4 < size && strncasecmp(data, "Age:", 4) == 0) {
- /* extract Age header */
- SKIP_ST(4);
- if (i < (int) size && '0' <= data[i] && data[i] <= '9')
- f->cachedata.age = atoi(data + i);
- } else if (8 < size && strncasecmp(data, "Expires:", 8) == 0) {
- /* extract Expires header */
- SKIP_ST(8);
- if (i < (int) size)
- f->cachedata.expires = curl_getdate(&data[i], NULL);
- } else if (14 < size && strncasecmp(data, "Cache-Control:", 14) == 0) {
- /* extract and parse Cache-Control header */
- int comma;
- SKIP_ST(14);
-
- while (i < (int) size) {
- for (comma = i; comma < (int) size; comma++)
- if (data[comma] == ',')
- break;
-
- SKIP_ST(i);
-
- if (8 < comma - i && (strncasecmp(data + i, "no-cache", 8) == 0 || strncasecmp(data + i, "no-store", 8) == 0))
- /* When we get a disk cache we should
- * distinguish between these two */
- f->cachedata.no_cache = true;
- else if (7 < comma - i && strncasecmp(data + i, "max-age", 7) == 0) {
- for (; i < comma; i++)
- if (data[i] == '=')
- break;
- SKIP_ST(i+1);
- if (i < comma)
- f->cachedata.max_age =
- atoi(data + i);
- }
-
- i = comma + 1;
- }
- } else if (5 < size && strncasecmp(data, "ETag:", 5) == 0) {
- /* extract ETag header */
- free(f->cachedata.etag);
- f->cachedata.etag = malloc(size);
- if (!f->cachedata.etag) {
- LOG(("malloc failed"));
- return size;
- }
- SKIP_ST(5);
- strncpy(f->cachedata.etag, data + i, size - i);
- f->cachedata.etag[size - i] = '\0';
- for (i = size - i - 1; i >= 0 &&
- (f->cachedata.etag[i] == ' ' ||
- f->cachedata.etag[i] == '\t' ||
- f->cachedata.etag[i] == '\r' ||
- f->cachedata.etag[i] == '\n'); --i)
- f->cachedata.etag[i] = '\0';
- } else if (14 < size && strncasecmp(data, "Last-Modified:", 14) == 0) {
- /* extract Last-Modified header */
- SKIP_ST(14);
- if (i < (int) size) {
- f->cachedata.last_modified =
- curl_getdate(&data[i], NULL);
- }
} else if (11 < size && strncasecmp(data, "Set-Cookie:", 11) == 0) {
/* extract Set-Cookie header */
SKIP_ST(11);
@@ -1169,10 +1081,6 @@
char *url_path = 0;
f->had_headers = true;
-
- /* Set fetch response time if not already set */
- if (f->cachedata.res_time == 0)
- f->cachedata.res_time = time(0);
if (!f->http_code)
{
@@ -1186,8 +1094,7 @@
if (http_code == 304 && !f->post_urlenc && !f->post_multipart) {
/* Not Modified && GET request */
- fetch_send_callback(FETCH_NOTMODIFIED, f->fetch_handle,
- (const char *)&f->cachedata, 0);
+ fetch_send_callback(FETCH_NOTMODIFIED, f->fetch_handle, 0, 0);
return true;
}
@@ -1225,11 +1132,11 @@
if (url_path && stat(url_path, &s) == 0) {
/* file: URL and file exists */
/* create etag */
- free(f->cachedata.etag);
+ /*free(f->cachedata.etag);
f->cachedata.etag = malloc(13);
if (f->cachedata.etag)
sprintf(f->cachedata.etag,
- "\"%10d\"", (int)s.st_mtime);
+ "\"%10d\"", (int)s.st_mtime);*/
/* don't set last modified time so as to ensure that local
* files are revalidated at all times. */
@@ -1239,7 +1146,7 @@
f->last_modified > s.st_mtime &&
f->file_etag == s.st_mtime) {
fetch_send_callback(FETCH_NOTMODIFIED, f->fetch_handle,
- (const char *)&f->cachedata, 0);
+ 0, 0);
curl_free(url_path);
return true;
}
14 years, 8 months
r4225 jmb - /trunk/netsurf/content/fetch.c
by netsurf@semichrome.net
Author: jmb
Date: Thu May 29 14:32:31 2008
New Revision: 4225
URL: http://source.netsurf-browser.org?rev=4225&view=rev
Log:
Wrap very verbose logging with #ifdef, so as to silence it.
Modified:
trunk/netsurf/content/fetch.c
Modified: trunk/netsurf/content/fetch.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/fetch.c?rev=4225&...
==============================================================================
--- trunk/netsurf/content/fetch.c (original)
+++ trunk/netsurf/content/fetch.c Thu May 29 14:32:31 2008
@@ -52,6 +52,9 @@
#include "utils/url.h"
#include "utils/utils.h"
#include "utils/ring.h"
+
+/* Define this to turn on verbose fetch logging */
+#undef DEBUG_FETCH_VERBOSE
bool fetch_active; /**< Fetches in progress, please call fetch_poll(). */
@@ -260,7 +263,9 @@
}
}
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("fetch %p, url '%s'", fetch, url));
+#endif
/* construct a new fetch structure */
fetch->callback = callback;
@@ -357,19 +362,25 @@
RING_GETSIZE(struct fetch, queue_ring, all_queued);
RING_GETSIZE(struct fetch, fetch_ring, all_active);
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("queue_ring %i, fetch_ring %i", all_queued, all_active));
+#endif
struct fetch *q = queue_ring;
if (q) {
do {
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("queue_ring: %s", q->url));
+#endif
q = q->r_next;
} while (q != queue_ring);
}
struct fetch *f = fetch_ring;
if (f) {
do {
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("fetch_ring: %s", f->url));
+#endif
f = f->r_next;
} while (f != fetch_ring);
}
@@ -385,8 +396,10 @@
}
}
fetch_active = (all_active > 0);
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Fetch ring is now %d elements.", all_active));
LOG(("Queue ring is now %d elements.", all_queued));
+#endif
}
@@ -424,8 +437,10 @@
bool fetch_dispatch_job(struct fetch *fetch)
{
RING_REMOVE(queue_ring, fetch);
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Attempting to start fetch %p, fetcher %p, url %s", fetch,
fetch->fetcher_handle, fetch->url));
+#endif
if (!fetch->ops->start_fetch(fetch->fetcher_handle)) {
RING_INSERT(queue_ring, fetch); /* Put it back on the end of the queue */
return false;
@@ -444,7 +459,9 @@
void fetch_abort(struct fetch *f)
{
assert(f);
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("fetch %p, fetcher %p, url '%s'", f, f->fetcher_handle, f->url));
+#endif
f->ops->abort_fetch(f->fetcher_handle);
}
@@ -455,7 +472,9 @@
void fetch_free(struct fetch *f)
{
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Freeing fetch %p, fetcher %p", f, f->fetcher_handle));
+#endif
f->ops->free_fetch(f->fetcher_handle);
fetch_unref_fetcher(f->ops);
free(f->parent_fetch_url);
@@ -583,7 +602,9 @@
int all_active, all_queued;
/* Go ahead and free the fetch properly now */
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Fetch %p, fetcher %p can be freed", fetch, fetch->fetcher_handle));
+#endif
if (fetch->fetch_is_active) {
RING_REMOVE(fetch_ring, fetch);
@@ -596,15 +617,19 @@
fetch_active = (all_active > 0);
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Fetch ring is now %d elements.", all_active));
LOG(("Queue ring is now %d elements.", all_queued));
+#endif
}
void
fetch_set_http_code(struct fetch *fetch, long http_code)
{
+#ifdef DEBUG_FETCH_VERBOSE
LOG(("Setting HTTP code to %ld", http_code));
+#endif
fetch->http_code = http_code;
}
14 years, 8 months
r4224 jmb - /trunk/netsurf/gtk/gtk_scaffolding.c
by netsurf@semichrome.net
Author: jmb
Date: Thu May 29 07:31:07 2008
New Revision: 4224
URL: http://source.netsurf-browser.org?rev=4224&view=rev
Log:
Fix desensitisation of reload menu entry
Modified:
trunk/netsurf/gtk/gtk_scaffolding.c
Modified: trunk/netsurf/gtk/gtk_scaffolding.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_scaffolding.c?rev...
==============================================================================
--- trunk/netsurf/gtk/gtk_scaffolding.c (original)
+++ trunk/netsurf/gtk/gtk_scaffolding.c Thu May 29 07:31:07 2008
@@ -943,7 +943,7 @@
gtk_widget_set_sensitive(GTK_WIDGET(g->stop_button), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(g->reload_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(g->stop_menu), TRUE);
- gtk_widget_set_sensitive(GTK_WIDGET(g->reload_button), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(g->reload_menu), FALSE);
nsgtk_window_update_back_forward(g);
14 years, 8 months
r4222 jmb - in /trunk/netsurf/gtk: gtk_options.c gtk_plotters.c options.h
by netsurf@semichrome.net
Author: jmb
Date: Thu May 29 06:03:13 2008
New Revision: 4222
URL: http://source.netsurf-browser.org?rev=4222&view=rev
Log:
Drop support for non-cairo plotting.
Implement path plotter.
Modified:
trunk/netsurf/gtk/gtk_options.c
trunk/netsurf/gtk/gtk_plotters.c
trunk/netsurf/gtk/options.h
Modified: trunk/netsurf/gtk/gtk_options.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_options.c?rev=422...
==============================================================================
--- trunk/netsurf/gtk/gtk_options.c (original)
+++ trunk/netsurf/gtk/gtk_options.c Thu May 29 06:03:13 2008
@@ -159,7 +159,6 @@
SET_SPIN(spinFetchesPerHost, option_max_fetchers_per_host);
SET_SPIN(spinCachedConnections, option_max_cached_fetch_handles);
- SET_CHECK(checkUseCairo, option_render_cairo);
SET_CHECK(checkResampleImages, option_render_resample);
SET_SPIN(spinAnimationSpeed, option_minimum_gif_delay / 100);
SET_CHECK(checkDisableAnimations, !option_animate_images);
@@ -229,7 +228,6 @@
GET_SPIN(spinFetchesPerHost, option_max_fetchers_per_host);
GET_SPIN(spinCachedConnections, option_max_cached_fetch_handles);
- GET_CHECK(checkUseCairo, option_render_cairo);
GET_CHECK(checkResampleImages, option_render_resample);
GET_SPIN(spinAnimationSpeed, option_minimum_gif_delay);
option_minimum_gif_delay *= 100;
Modified: trunk/netsurf/gtk/gtk_plotters.c
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_plotters.c?rev=42...
==============================================================================
--- trunk/netsurf/gtk/gtk_plotters.c (original)
+++ trunk/netsurf/gtk/gtk_plotters.c Thu May 29 06:03:13 2008
@@ -39,12 +39,14 @@
#include "gtk/options.h"
#include "gtk/gtk_bitmap.h"
+#ifndef CAIRO_VERSION
+#error "nsgtk requires cairo"
+#endif
+
GtkWidget *current_widget;
GdkDrawable *current_drawable;
GdkGC *current_gc;
-#ifdef CAIRO_VERSION
cairo_t *current_cr;
-#endif
static bool nsgtk_plot_clg(colour c);
static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
@@ -111,18 +113,13 @@
else
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- if (line_width == 0)
- line_width = 1;
-
- cairo_set_line_width(current_cr, line_width);
- cairo_rectangle(current_cr, x0, y0, width, height);
- cairo_stroke(current_cr);
- } else
-#endif
- gdk_draw_rectangle(current_drawable, current_gc,
- FALSE, x0, y0, width, height);
+ if (line_width == 0)
+ line_width = 1;
+
+ cairo_set_line_width(current_cr, line_width);
+ cairo_rectangle(current_cr, x0, y0, width, height);
+ cairo_stroke(current_cr);
+
return true;
}
@@ -138,19 +135,14 @@
else
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- if (width == 0)
- width = 1;
-
- cairo_set_line_width(current_cr, width);
- cairo_move_to(current_cr, x0, y0 - 0.5);
- cairo_line_to(current_cr, x1, y1 - 0.5);
- cairo_stroke(current_cr);
- } else
-#endif
- gdk_draw_line(current_drawable, current_gc,
- x0, y0, x1, y1);
+ if (width == 0)
+ width = 1;
+
+ cairo_set_line_width(current_cr, width);
+ cairo_move_to(current_cr, x0, y0 - 0.5);
+ cairo_line_to(current_cr, x1, y1 - 0.5);
+ cairo_stroke(current_cr);
+
return true;
}
@@ -161,26 +153,15 @@
nsgtk_set_colour(fill);
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- cairo_set_line_width(current_cr, 0);
- cairo_move_to(current_cr, p[0], p[1]);
- for (i = 1; i != n; i++) {
- cairo_line_to(current_cr, p[i * 2], p[i * 2 + 1]);
- }
- cairo_fill(current_cr);
- cairo_stroke(current_cr);
- } else
-#endif
- {
- GdkPoint q[n];
- for (i = 0; i != n; i++) {
- q[i].x = p[i * 2];
- q[i].y = p[i * 2 + 1];
- }
- gdk_draw_polygon(current_drawable, current_gc,
- TRUE, q, n);
- }
+
+ cairo_set_line_width(current_cr, 0);
+ cairo_move_to(current_cr, p[0], p[1]);
+ for (i = 1; i != n; i++) {
+ cairo_line_to(current_cr, p[i * 2], p[i * 2 + 1]);
+ }
+ cairo_fill(current_cr);
+ cairo_stroke(current_cr);
+
return true;
}
@@ -189,16 +170,12 @@
{
nsgtk_set_colour(c);
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- cairo_set_line_width(current_cr, 0);
- cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0);
- cairo_fill(current_cr);
- cairo_stroke(current_cr);
- } else
-#endif
- gdk_draw_rectangle(current_drawable, current_gc,
- TRUE, x0, y0, x1 - x0, y1 - y0);
+
+ cairo_set_line_width(current_cr, 0);
+ cairo_rectangle(current_cr, x0, y0, x1 - x0, y1 - y0);
+ cairo_fill(current_cr);
+ cairo_stroke(current_cr);
+
return true;
}
@@ -206,19 +183,11 @@
bool nsgtk_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1)
{
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- cairo_reset_clip(current_cr);
- cairo_rectangle(current_cr, clip_x0, clip_y0,
+ cairo_reset_clip(current_cr);
+ cairo_rectangle(current_cr, clip_x0, clip_y0,
clip_x1 - clip_x0, clip_y1 - clip_y0);
- cairo_clip(current_cr);
- }
-#endif
- cliprect.x = clip_x0;
- cliprect.y = clip_y0;
- cliprect.width = clip_x1 - clip_x0;
- cliprect.height = clip_y1 - clip_y0;
- gdk_gc_set_clip_rectangle(current_gc, &cliprect);
+ cairo_clip(current_cr);
+
return true;
}
@@ -234,26 +203,18 @@
{
nsgtk_set_colour(c);
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- if (filled)
- cairo_set_line_width(current_cr, 0);
- else
- cairo_set_line_width(current_cr, 1);
-
- cairo_arc(current_cr, x, y, radius, 0, M_PI * 2);
-
- if (filled)
- cairo_fill(current_cr);
-
- cairo_stroke(current_cr);
- } else
-#endif
- gdk_draw_arc(current_drawable, current_gc,
- filled ? TRUE : FALSE, x - (radius), y - radius,
- radius * 2, radius * 2,
- 0,
- 360 * 64);
+
+ if (filled)
+ cairo_set_line_width(current_cr, 0);
+ else
+ cairo_set_line_width(current_cr, 1);
+
+ cairo_arc(current_cr, x, y, radius, 0, M_PI * 2);
+
+ if (filled)
+ cairo_fill(current_cr);
+
+ cairo_stroke(current_cr);
return true;
}
@@ -262,19 +223,12 @@
{
nsgtk_set_colour(c);
nsgtk_set_solid();
-#ifdef CAIRO_VERSION
- if (option_render_cairo) {
- cairo_set_line_width(current_cr, 1);
- cairo_arc(current_cr, x, y, radius,
- (angle1 + 90) * (M_PI / 180),
- (angle2 + 90) * (M_PI / 180));
- cairo_stroke(current_cr);
- } else
-#endif
- gdk_draw_arc(current_drawable, current_gc,
- FALSE, x - (radius), y - radius,
- radius * 2, radius * 2,
- angle1 * 64, angle2 * 64);
+
+ cairo_set_line_width(current_cr, 1);
+ cairo_arc(current_cr, x, y, radius,
+ (angle1 + 90) * (M_PI / 180),
+ (angle2 + 90) * (M_PI / 180));
+ cairo_stroke(current_cr);
return true;
}
@@ -380,10 +334,80 @@
bool nsgtk_plot_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform)
{
- /* Only the internal SVG renderer uses this plot call currently,
- * and the GTK version uses librsvg. Thus, we ignore this complexity,
- * and just return true obliviously.
- */
+ unsigned int i;
+ cairo_matrix_t old_ctm, n_ctm;
+
+ if (n == 0)
+ return true;
+
+ if (p[0] != PLOTTER_PATH_MOVE) {
+ LOG(("Path does not start with move"));
+ return false;
+ }
+
+
+ /* Save CTM */
+ cairo_get_matrix(current_cr, &old_ctm);
+
+ /* Set up line style and width */
+ cairo_set_line_width(current_cr, 1);
+ nsgtk_set_solid();
+
+ /* Load new CTM */
+ n_ctm.xx = transform[0];
+ n_ctm.yx = transform[1];
+ n_ctm.xy = transform[2];
+ n_ctm.yy = transform[3];
+ n_ctm.x0 = transform[4];
+ n_ctm.y0 = transform[5];
+
+ cairo_set_matrix(current_cr, &n_ctm);
+
+ /* Construct path */
+ for (i = 0; i < n; ) {
+ if (p[i] == PLOTTER_PATH_MOVE) {
+ cairo_move_to(current_cr, p[i+1], p[i+2]);
+ i += 3;
+ } else if (p[i] == PLOTTER_PATH_CLOSE) {
+ cairo_close_path(current_cr);
+ i++;
+ } else if (p[i] == PLOTTER_PATH_LINE) {
+ cairo_line_to(current_cr, p[i+1], p[i+2]);
+ i += 3;
+ } else if (p[i] == PLOTTER_PATH_BEZIER) {
+ cairo_curve_to(current_cr, p[i+1], p[i+2],
+ p[i+3], p[i+4],
+ p[i+5], p[i+6]);
+ i += 7;
+ } else {
+ LOG(("bad path command %f", p[i]));
+ /* Reset matrix for safety */
+ cairo_set_matrix(current_cr, &old_ctm);
+ return false;
+ }
+ }
+
+ /* Restore original CTM */
+ cairo_set_matrix(current_cr, &old_ctm);
+
+ /* Now draw path */
+ if (fill != TRANSPARENT) {
+ nsgtk_set_colour(fill);
+
+ if (c != TRANSPARENT) {
+ /* Fill & Stroke */
+ cairo_fill_preserve(current_cr);
+ nsgtk_set_colour(c);
+ cairo_stroke(current_cr);
+ } else {
+ /* Fill only */
+ cairo_fill(current_cr);
+ }
+ } else if (c != TRANSPARENT) {
+ /* Stroke only */
+ nsgtk_set_colour(c);
+ cairo_stroke(current_cr);
+ }
return true;
}
@@ -405,55 +429,32 @@
gdk_color_alloc(gdk_colormap_get_system(),
&colour);
gdk_gc_set_foreground(current_gc, &colour);
-#ifdef CAIRO_VERSION
- if (option_render_cairo)
- cairo_set_source_rgba(current_cr, r / 255.0,
+
+ cairo_set_source_rgba(current_cr, r / 255.0,
g / 255.0, b / 255.0, 1.0);
-#endif
}
void nsgtk_set_solid()
{
-#ifdef CAIRO_VERSION
double dashes = 0;
- if (option_render_cairo)
- cairo_set_dash(current_cr, &dashes, 0, 0);
- else
-#endif
- gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_SOLID, GDK_CAP_BUTT,
- GDK_JOIN_MITER);
+
+ cairo_set_dash(current_cr, &dashes, 0, 0);
}
void nsgtk_set_dotted()
{
double cdashes = 1;
gint8 dashes[] = { 1, 1 };
-#ifdef CAIRO_VERSION
- if (option_render_cairo)
- cairo_set_dash(current_cr, &cdashes, 1, 0);
- else
-#endif
- {
- gdk_gc_set_dashes(current_gc, 0, dashes, 2);
- gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH,
- GDK_CAP_BUTT, GDK_JOIN_MITER);
- }
+
+ cairo_set_dash(current_cr, &cdashes, 1, 0);
}
void nsgtk_set_dashed()
{
double cdashes = 3;
gint8 dashes[] = { 3, 3 };
-#ifdef CAIRO_VERSION
- if (option_render_cairo)
- cairo_set_dash(current_cr, &cdashes, 1, 0);
- else
-#endif
- {
- gdk_gc_set_dashes(current_gc, 0, dashes, 2);
- gdk_gc_set_line_attributes(current_gc, 1, GDK_LINE_ON_OFF_DASH,
- GDK_CAP_BUTT, GDK_JOIN_MITER);
- }
+
+ cairo_set_dash(current_cr, &cdashes, 1, 0);
}
void nsgtk_plot_set_scale(float s)
@@ -483,3 +484,4 @@
x, y,
x, y + h - 1);
}
+
Modified: trunk/netsurf/gtk/options.h
URL: http://source.netsurf-browser.org/trunk/netsurf/gtk/options.h?rev=4222&r1...
==============================================================================
--- trunk/netsurf/gtk/options.h (original)
+++ trunk/netsurf/gtk/options.h Thu May 29 06:03:13 2008
@@ -21,17 +21,14 @@
#include "desktop/options.h"
-extern bool option_render_cairo;
extern bool option_render_resample;
extern char *option_url_file;
#define EXTRA_OPTION_DEFINE \
-bool option_render_cairo = true; \
bool option_render_resample = false; \
char *option_url_file = 0;
#define EXTRA_OPTION_TABLE \
-{ "render_cairo", OPTION_BOOL, &option_render_cairo }, \
{ "render_resample", OPTION_BOOL, &option_render_resample }, \
{ "url_file", OPTION_STRING, &option_url_file },
#endif
14 years, 8 months
r4221 adamblokus - in /branches/adamblokus/netsurf: Makefile pdf/TODO pdf/pdf_plotters.c
by netsurf@semichrome.net
Author: adamblokus
Date: Wed May 28 15:11:05 2008
New Revision: 4221
URL: http://source.netsurf-browser.org?rev=4221&view=rev
Log:
Some more options in graphic primitives and normalizing some parameters.
Modified:
branches/adamblokus/netsurf/Makefile
branches/adamblokus/netsurf/pdf/TODO
branches/adamblokus/netsurf/pdf/pdf_plotters.c
Modified: branches/adamblokus/netsurf/Makefile
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/Makefile?re...
==============================================================================
--- branches/adamblokus/netsurf/Makefile (original)
+++ branches/adamblokus/netsurf/Makefile Wed May 28 15:11:05 2008
@@ -105,7 +105,7 @@
LDFLAGS := -Xlinker -symbols=$(OBJROOT)/sym -lxml2 -lz -lm -lcurl -lssl -lcrypto -lmng -ljpeg
else
LDFLAGS := $(shell $(PKG_CONFIG) --libs libxml-2.0 libcurl openssl)
-LDFLAGS += -lz -lm -lmng -ljpeg
+LDFLAGS += -lz -lm -lmng -ljpeg
CCACHE := $(shell which ccache)
@@ -129,8 +129,10 @@
$(shell $(PKG_CONFIG) --cflags librosprite) \
$(shell xml2-config --cflags)
+#GTKLDFLAGS := $(shell $(PKG_CONFIG) --cflags --libs libglade-2.0 gtk+-2.0 gthread-2.0 gmodule-2.0 librosprite)
GTKLDFLAGS := $(shell $(PKG_CONFIG) --cflags --libs libglade-2.0 gtk+-2.0 gthread-2.0 gmodule-2.0 librsvg-2.0 librosprite)
CFLAGS += $(GTKCFLAGS)
+#LDFLAGS += $(GTKLDFLAGS) $(shell $(PKG_CONFIG) --libs lcms) -lhpdf -lsvgtiny
LDFLAGS += $(GTKLDFLAGS) $(shell $(PKG_CONFIG) --libs lcms) -lhpdf
ifeq ($(HOST),Windows_NT)
Modified: branches/adamblokus/netsurf/pdf/TODO
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/TODO?re...
==============================================================================
--- branches/adamblokus/netsurf/pdf/TODO (original)
+++ branches/adamblokus/netsurf/pdf/TODO Wed May 28 15:11:05 2008
@@ -1,6 +1,10 @@
- finish all graphic primitives
+- allow adding raw bitmaps
- adjust content width to page width
+- add text-scaling (if not yet using the original font - make the default one
+ have the same width)
+- make image-aware (embed the image in its native/original type if possible)
+- add a save file.. dialogue
- divide output into multiple pages (not just the first one)
-- add a save file.. dialogue
- rearrange file structure
- add utf support to Haru ( doable? )
Modified: branches/adamblokus/netsurf/pdf/pdf_plotters.c
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/pdf_plo...
==============================================================================
--- branches/adamblokus/netsurf/pdf/pdf_plotters.c (original)
+++ branches/adamblokus/netsurf/pdf/pdf_plotters.c Wed May 28 15:11:05 2008
@@ -101,6 +101,10 @@
bool pdf_plot_rectangle(int x0, int y0, int width, int height,
int line_width, colour c, bool dotted, bool dashed){
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
+ HPDF_Page_SetLineWidth(pdf_page,line_width);
if(dotted)
pdf_set_dotted();
@@ -119,6 +123,10 @@
bool pdf_plot_line(int x0, int y0, int x1, int y1, int width,
colour c, bool dotted, bool dashed){
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
+ HPDF_Page_SetLineWidth(pdf_page,width);
if(dotted)
pdf_set_dotted();
@@ -141,7 +149,9 @@
int i;
int pmaxx=p[0],pmaxy=p[1];
int pminx=p[0],pminy=p[1];
-
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
if(n==0)
return true;
@@ -216,7 +226,9 @@
bool pdf_plot_text(int x, int y, const struct css_style *style,
const char *text, size_t length, colour bg, colour c){
-
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
char *word;
HPDF_REAL size;
@@ -243,13 +255,15 @@
}
bool pdf_plot_disc(int x, int y, int radius, colour c, bool filled){
-
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
if(filled)
HPDF_Page_SetRGBFill(pdf_page,R(c),G(c),B(c));
else
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
- HPDF_Page_Circle(pdf_page,x,y,radius);
+ HPDF_Page_Circle(pdf_page,x,page_height-y,radius);
if(filled)
HPDF_Page_Fill(pdf_page);
@@ -261,9 +275,20 @@
bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2,
colour c){
+#ifdef PDF_DEBUG
+ LOG(("%d %d %d %d %d %X",x,y,radius,angle1,angle2,c));
+#endif
+
+ /*Normalize angles*/
+ angle1%=360;
+ angle2%=360;
+ if(angle1>angle2)
+ angle1-=360;
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
- HPDF_Page_Arc(pdf_page,x,y,radius,angle1,angle2);
+
+ HPDF_Page_Arc(pdf_page,x,page_height-y,radius,angle1,angle2);
+
HPDF_Page_Stroke(pdf_page);
return true;
}
@@ -283,9 +308,20 @@
return true;
}
+
+static inline float transform_x(float *transform,float x,float y){
+ return (transform[0] * (x) + transform[2] * -(y) + transform[4]) * 2;
+}
+
+static inline float transform_y(float *transform,float x,float y){
+ return (transform[1] * (x) + transform[3] * -(y) - transform[5]) * 2;
+}
+
bool pdf_plot_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform){
-
+#ifdef PDF_DEBUG
+ LOG(("."));
+#endif
unsigned int i;
bool empty_path=true;
@@ -296,40 +332,43 @@
return true;
if (p[0] != PLOTTER_PATH_MOVE) {
- LOG(("path doesn't start with a move"));
return false;
}
HPDF_Page_SetRGBFill(pdf_page,R(fill),G(fill),B(fill));
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
-#define transform_x(x,y) ((transform[0] * (x) + transform[2] * -(y) + transform[4]) * 2)
-#define transform_y(x,y) ((transform[1] * (x) + transform[3] * -(y) - transform[5]) * 2)
+ transform[0]=0.1;
+ transform[1]=0;
+ transform[2]=0;
+ transform[3]=-0.1;
+ transform[4]=0;
+ transform[5]=0;
for(i=0;i<n;){
if(p[i]==PLOTTER_PATH_MOVE){
HPDF_Page_MoveTo(pdf_page,
- transform_x(p[i+1],p[i+2]),
- transform_y(p[i+1],p[i+2]));
+ transform_x(transform,p[i+1],p[i+2]),
+ transform_y(transform,p[i+1],p[i+2]));
i+=3;
}else if (p[i] == PLOTTER_PATH_CLOSE) {
- HPDF_Page_ClosePath(pdf_page);
+ if(!empty_path)
+ HPDF_Page_ClosePath(pdf_page);
i++;
} else if (p[i] == PLOTTER_PATH_LINE) {
HPDF_Page_LineTo(pdf_page,
- transform_x(p[i+1],p[i+2]),
- transform_y(p[i+1],p[i+2]));
+ transform_x(transform,p[i+1],p[i+2]),
+ transform_y(transform,p[i+1],p[i+2]));
i+=3;
empty_path = false;
} else if (p[i] == PLOTTER_PATH_BEZIER) {
-
HPDF_Page_CurveTo(pdf_page,
- transform_x(p[i+1],p[i+2]),
- transform_y(p[i+1],p[i+2]),
- transform_x(p[i+3],p[i+4]),
- transform_y(p[i+3],p[i+4]),
- transform_x(p[i+5],p[i+6]),
- transform_y(p[i+5],p[i+6]));
+ transform_x(transform,p[i+1],p[i+2]),
+ transform_y(transform,p[i+1],p[i+2]),
+ transform_x(transform,p[i+3],p[i+4]),
+ transform_y(transform,p[i+3],p[i+4]),
+ transform_x(transform,p[i+5],p[i+6]),
+ transform_y(transform,p[i+5],p[i+6]));
i += 7;
empty_path = false;
} else {
@@ -337,12 +376,11 @@
return false;
}
}
-
-#undef transform_x
-#undef transform_y
-
- if(empty_path)
- return true;
+
+ if(empty_path){
+ HPDF_Page_EndPath(pdf_page);
+ return true;
+ }
if(fill!=TRANSPARENT){
if(c!=TRANSPARENT)
@@ -424,6 +462,8 @@
printf ("ERROR:\n\terror_no=%x\n\tdetail_no=%d\n",
(HPDF_UINT)error_no,
(HPDF_UINT)detail_no);
+
+ exit(1);
}
void pdf_plot_grid(int x_dist,int y_dist,unsigned int colour){
@@ -436,3 +476,5 @@
pdf_plot_line(0,i,page_width,i,1,colour,false,false);
}
+
+
14 years, 8 months
r4220 jmb - /trunk/netsurf/render/imagemap.c
by netsurf@semichrome.net
Author: jmb
Date: Wed May 28 15:05:30 2008
New Revision: 4220
URL: http://source.netsurf-browser.org?rev=4220&view=rev
Log:
Recurse into <area> and <a>, too.
Modified:
trunk/netsurf/render/imagemap.c
Modified: trunk/netsurf/render/imagemap.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/imagemap.c?rev=422...
==============================================================================
--- trunk/netsurf/render/imagemap.c (original)
+++ trunk/netsurf/render/imagemap.c Wed May 28 15:05:30 2008
@@ -308,11 +308,13 @@
*/
if (strcmp((const char *) node->name, "area") == 0 ||
strcmp((const char *) node->name, "a") == 0) {
- return imagemap_addtolist(node,
- c->data.html.base_url, entry);
- }
- }
- else return true;
+ if (!imagemap_addtolist(node,
+ c->data.html.base_url, entry))
+ return false;
+ }
+ } else {
+ return true;
+ }
for (this_node = node->children; this_node != 0;
this_node = this_node->next) {
14 years, 8 months
r4219 mikeL - in /branches/mikeL/netsurf/gtk: gtk_gui.c gtk_scaffolding.c res/netsurf.glade
by netsurf@semichrome.net
Author: mikeL
Date: Wed May 28 12:17:12 2008
New Revision: 4219
URL: http://source.netsurf-browser.org?rev=4219&view=rev
Log:
Removed wndOpenFile from glade file.
Modified:
branches/mikeL/netsurf/gtk/gtk_gui.c
branches/mikeL/netsurf/gtk/gtk_scaffolding.c
branches/mikeL/netsurf/gtk/res/netsurf.glade
Modified: branches/mikeL/netsurf/gtk/gtk_gui.c
URL: http://source.netsurf-browser.org/branches/mikeL/netsurf/gtk/gtk_gui.c?re...
==============================================================================
--- branches/mikeL/netsurf/gtk/gtk_gui.c (original)
+++ branches/mikeL/netsurf/gtk/gtk_gui.c Wed May 28 12:17:12 2008
@@ -77,7 +77,6 @@
GladeXML *gladeWindows;
GtkWindow *wndTooltip;
GtkLabel *labelTooltip;
-GtkDialog *wndOpenFile;
static GtkWidget *select_menu;
static struct browser_window *select_menu_bw;
@@ -276,7 +275,6 @@
glade_xml_get_widget(gladeWindows, "textviewGPL")), fontdesc);
wndWarning = GTK_WINDOW(glade_xml_get_widget(gladeWindows, "wndWarning"));
- wndOpenFile = GTK_DIALOG(glade_xml_get_widget(gladeWindows, "wndOpenFile"));
nsgtk_history_init();
nsgtk_download_initialise();
Modified: branches/mikeL/netsurf/gtk/gtk_scaffolding.c
URL: http://source.netsurf-browser.org/branches/mikeL/netsurf/gtk/gtk_scaffold...
==============================================================================
--- branches/mikeL/netsurf/gtk/gtk_scaffolding.c (original)
+++ branches/mikeL/netsurf/gtk/gtk_scaffolding.c Wed May 28 12:17:12 2008
@@ -119,7 +119,7 @@
static void nsgtk_attach_menu_handlers(GladeXML *, gpointer);
-gboolean nsgtk_openfile_open(GtkWidget *widget, gpointer data);
+void nsgtk_openfile_open(char *filename);
#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
@@ -373,12 +373,10 @@
}
-gboolean nsgtk_openfile_open(GtkWidget *widget, gpointer data)
-{
- struct browser_window *bw = nsgtk_get_browser_for_gui(
- current_model->top_level);
- char *filename = gtk_file_chooser_get_filename(
- GTK_FILE_CHOOSER(wndOpenFile));
+void nsgtk_openfile_open(char *filename)
+{
+ struct browser_window *bw = nsgtk_get_browser_for_gui(
+ current_model->top_level);
char *url = malloc(strlen(filename) + strlen("file://") + 1);
sprintf(url, "file://%s", filename);
@@ -387,8 +385,6 @@
g_free(filename);
free(url);
-
- return TRUE;
}
/* signal handlers for menu entries */
@@ -418,8 +414,16 @@
MENUHANDLER(open_file)
{
current_model = (struct gtk_scaffolding *)g;
- gtk_dialog_run(wndOpenFile);
-
+ GtkWidget *dlgOpen = gtk_file_chooser_dialog_new("Open File",
+ current_model->window, GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, -6, GTK_STOCK_OPEN, -5, NULL);
+
+ gint response = gtk_dialog_run(GTK_DIALOG(dlgOpen));
+ if (response == GTK_RESPONSE_OK){
+ char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlgOpen));
+ nsgtk_openfile_open(filename);
+ }
+ gtk_widget_destroy(dlgOpen);
return TRUE;
}
Modified: branches/mikeL/netsurf/gtk/res/netsurf.glade
URL: http://source.netsurf-browser.org/branches/mikeL/netsurf/gtk/res/netsurf....
==============================================================================
--- branches/mikeL/netsurf/gtk/res/netsurf.glade (original)
+++ branches/mikeL/netsurf/gtk/res/netsurf.glade Wed May 28 12:17:12 2008
@@ -333,9 +333,9 @@
<property name="visible">True</property>
<property name="label" translatable="yes">Zoom _in</property>
<property name="use_underline">True</property>
+ <accelerator key="plus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ <accelerator key="KP_Add" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<accelerator key="equal" modifiers="GDK_CONTROL_MASK" signal="activate"/>
- <accelerator key="KP_Add" modifiers="GDK_CONTROL_MASK" signal="activate"/>
- <accelerator key="plus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image564">
<property name="visible">True</property>
@@ -350,8 +350,8 @@
<property name="visible">True</property>
<property name="label" translatable="yes">_Normal size</property>
<property name="use_underline">True</property>
+ <accelerator key="0" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<accelerator key="KP_0" modifiers="GDK_CONTROL_MASK" signal="activate"/>
- <accelerator key="0" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image565">
<property name="visible">True</property>
@@ -366,8 +366,8 @@
<property name="visible">True</property>
<property name="label" translatable="yes">Zoom _out</property>
<property name="use_underline">True</property>
+ <accelerator key="minus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<accelerator key="KP_Subtract" modifiers="GDK_CONTROL_MASK" signal="activate"/>
- <accelerator key="minus" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image566">
<property name="visible">True</property>
@@ -805,17 +805,25 @@
<placeholder/>
</child>
<child>
- <widget class="GtkStatusbar" id="statusbar1">
- <property name="height_request">1</property>
- <property name="visible">True</property>
+ <widget class="GtkHSeparator" id="hseparator3">
+ <property name="visible">True</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkVScrollbar" id="coreScrollVertical">
+ <property name="visible">True</property>
+ <property name="adjustment">0 0 100 1 10 0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
+ <property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_SHRINK | GTK_FILL</property>
</packing>
</child>
<child>
@@ -856,25 +864,17 @@
</packing>
</child>
<child>
- <widget class="GtkVScrollbar" id="coreScrollVertical">
- <property name="visible">True</property>
- <property name="adjustment">0 0 100 1 10 0</property>
+ <widget class="GtkStatusbar" id="statusbar1">
+ <property name="height_request">1</property>
+ <property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="bottom_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHSeparator" id="hseparator3">
- <property name="visible">True</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="y_options">GTK_FILL</property>
+ <property name="y_options">GTK_SHRINK | GTK_FILL</property>
</packing>
</child>
</widget>
@@ -918,61 +918,34 @@
<property name="column_spacing">11</property>
<property name="row_spacing">10</property>
<child>
- <widget class="GtkLabel" id="labelLoginHost">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">moo.yoo.com</property>
+ <widget class="GtkEntry" id="entryLoginUser">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="has_focus">True</property>
+ <property name="text" translatable="yes">sesame</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options"></property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label57">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Password</property>
+ <widget class="GtkEntry" id="entryLoginPass">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="visibility">False</property>
+ <property name="activates_default">True</property>
+ <property name="text" translatable="yes">opensesame</property>
</widget>
<packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label56">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Username</property>
- </widget>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label54">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Host</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label55">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Realm</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
</packing>
</child>
<child>
@@ -990,34 +963,61 @@
</packing>
</child>
<child>
- <widget class="GtkEntry" id="entryLoginPass">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="visibility">False</property>
- <property name="activates_default">True</property>
- <property name="text" translatable="yes">opensesame</property>
+ <widget class="GtkLabel" id="label55">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Realm</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label54">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Host</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label56">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Username</property>
+ </widget>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label57">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Password</property>
+ </widget>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="labelLoginHost">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">moo.yoo.com</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkEntry" id="entryLoginUser">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="has_focus">True</property>
- <property name="text" translatable="yes">sesame</property>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options"></property>
+ <property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>
@@ -1350,15 +1350,54 @@
<property name="n_columns">2</property>
<property name="column_spacing">4</property>
<child>
- <widget class="GtkLabel" id="labelHistoryAddress">
+ <widget class="GtkLabel" id="label117">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Address</property>
+ </widget>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label118">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Last visited</property>
+ </widget>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label119">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Number of visits</property>
+ </widget>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="labelHistoryVisits">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">http://netsurf.sf.net/</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
+ <property name="label" translatable="yes">2</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
@@ -1378,54 +1417,15 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="labelHistoryVisits">
+ <widget class="GtkLabel" id="labelHistoryAddress">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">2</property>
- <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+ <property name="label" translatable="yes">http://netsurf.sf.net/</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label119">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Number of visits</property>
- </widget>
- <packing>
- <property name="top_attach">2</property>
- <property name="bottom_attach">3</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label118">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Last visited</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label117">
- <property name="visible">True</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Address</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
@@ -1523,54 +1523,6 @@
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- <widget class="GtkFileChooserDialog" id="wndOpenFile">
- <property name="title" translatable="yes">Open file</property>
- <property name="modal">True</property>
- <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
- <child internal-child="vbox">
- <widget class="GtkVBox" id="dialog-vbox4">
- <property name="visible">True</property>
- <property name="spacing">24</property>
- <child internal-child="action_area">
- <widget class="GtkHButtonBox" id="dialog-action_area4">
- <property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
- <child>
- <widget class="GtkButton" id="button15">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="label">gtk-cancel</property>
- <property name="use_stock">True</property>
- <property name="response_id">-6</property>
- <signal name="clicked" handler="gtk_widget_hide" object="wndOpenFile"/>
- </widget>
- </child>
- <child>
- <widget class="GtkButton" id="button16">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="has_default">True</property>
- <property name="label">gtk-open</property>
- <property name="use_stock">True</property>
- <property name="response_id">-5</property>
- <signal name="clicked" handler="nsgtk_openfile_open"/>
- <signal name="clicked" handler="gtk_widget_hide" object="wndOpenFile"/>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
14 years, 8 months
r4218 adamblokus - /branches/adamblokus/netsurf/pdf/pdf_plotters.c
by netsurf@semichrome.net
Author: adamblokus
Date: Wed May 28 05:37:30 2008
New Revision: 4218
URL: http://source.netsurf-browser.org?rev=4218&view=rev
Log:
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
Modified:
branches/adamblokus/netsurf/pdf/pdf_plotters.c
Modified: branches/adamblokus/netsurf/pdf/pdf_plotters.c
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/pdf_plo...
==============================================================================
--- branches/adamblokus/netsurf/pdf/pdf_plotters.c (original)
+++ branches/adamblokus/netsurf/pdf/pdf_plotters.c Wed May 28 05:37:30 2008
@@ -54,6 +54,9 @@
static bool pdf_plot_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform);
+static void pdf_set_solid();
+static void pdf_set_dashed();
+static void pdf_set_dotted();
bool pdf_begin(const char *);
void pdf_next_page();
@@ -98,22 +101,38 @@
bool pdf_plot_rectangle(int x0, int y0, int width, int height,
int line_width, colour c, bool dotted, bool dashed){
-
+
+ if(dotted)
+ pdf_set_dotted();
+ else if(dashed)
+ pdf_set_dashed();
+
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
HPDF_Page_Rectangle(pdf_page, x0, page_height - y0 + height, width, height);
HPDF_Page_Stroke(pdf_page);
+
+ if(dotted||dashed)
+ pdf_set_solid();
return true;
}
bool pdf_plot_line(int x0, int y0, int x1, int y1, int width,
colour c, bool dotted, bool dashed){
+
+ if(dotted)
+ pdf_set_dotted();
+ else if(dashed)
+ pdf_set_dashed();
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
HPDF_Page_SetLineWidth(pdf_page,width);
HPDF_Page_MoveTo(pdf_page, x0, page_height - y0);
HPDF_Page_LineTo(pdf_page, x1, page_height - y1);
HPDF_Page_Stroke(pdf_page);
+
+ if(dotted||dashed)
+ pdf_set_solid();
return true;
}
@@ -126,7 +145,6 @@
if(n==0)
return true;
- HPDF_Page_SetRGBStroke(pdf_page,R(fill),G(fill),B(fill));
HPDF_Page_SetRGBFill(pdf_page,R(fill),G(fill),B(fill));
HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]);
@@ -156,8 +174,11 @@
LOG(("%d %d %d %d %f %X",x0,y0,x1,y1,page_height-y0,c));
#endif
- if(x0<0 || y0<0 || x1>page_width || y1>page_height)
- return true;
+ /*Normalize boundaries of the area - to prevent overflows*/
+ x0=min(max(x0,0),page_width);
+ y0=min(max(y0,0),page_height);
+ x1=min(max(x1,0),page_width);
+ y1=min(max(y1,0),page_height);
HPDF_Page_SetRGBFill(pdf_page,R(c),G(c),B(c));
HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1-x0, y1-y0);
@@ -264,9 +285,90 @@
bool pdf_plot_path(float *p, unsigned int n, colour fill, float width,
colour c, float *transform){
- return true;
-}
-
+
+ unsigned int i;
+ bool empty_path=true;
+
+ if(n==0)
+ return true;
+
+ if(c==TRANSPARENT && fill==TRANSPARENT)
+ return true;
+
+ if (p[0] != PLOTTER_PATH_MOVE) {
+ LOG(("path doesn't start with a move"));
+ return false;
+ }
+
+ HPDF_Page_SetRGBFill(pdf_page,R(fill),G(fill),B(fill));
+ HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
+
+#define transform_x(x,y) ((transform[0] * (x) + transform[2] * -(y) + transform[4]) * 2)
+#define transform_y(x,y) ((transform[1] * (x) + transform[3] * -(y) - transform[5]) * 2)
+
+ for(i=0;i<n;){
+ if(p[i]==PLOTTER_PATH_MOVE){
+ HPDF_Page_MoveTo(pdf_page,
+ transform_x(p[i+1],p[i+2]),
+ transform_y(p[i+1],p[i+2]));
+ i+=3;
+ }else if (p[i] == PLOTTER_PATH_CLOSE) {
+ HPDF_Page_ClosePath(pdf_page);
+ i++;
+ } else if (p[i] == PLOTTER_PATH_LINE) {
+ HPDF_Page_LineTo(pdf_page,
+ transform_x(p[i+1],p[i+2]),
+ transform_y(p[i+1],p[i+2]));
+ i+=3;
+ empty_path = false;
+ } else if (p[i] == PLOTTER_PATH_BEZIER) {
+
+ HPDF_Page_CurveTo(pdf_page,
+ transform_x(p[i+1],p[i+2]),
+ transform_y(p[i+1],p[i+2]),
+ transform_x(p[i+3],p[i+4]),
+ transform_y(p[i+3],p[i+4]),
+ transform_x(p[i+5],p[i+6]),
+ transform_y(p[i+5],p[i+6]));
+ i += 7;
+ empty_path = false;
+ } else {
+ LOG(("bad path command %f", p[i]));
+ return false;
+ }
+ }
+
+#undef transform_x
+#undef transform_y
+
+ if(empty_path)
+ return true;
+
+ if(fill!=TRANSPARENT){
+ if(c!=TRANSPARENT)
+ HPDF_Page_FillStroke(pdf_page);
+ else
+ HPDF_Page_Fill(pdf_page);
+ }
+ else
+ HPDF_Page_Stroke(pdf_page);
+
+ return true;
+}
+
+void pdf_set_solid(){
+ HPDF_Page_SetDash(pdf_page,NULL,0,0);
+}
+
+void pdf_set_dashed(){
+ HPDF_UINT16 dash_ptn[]={3};
+ HPDF_Page_SetDash(pdf_page,dash_ptn,1,1);
+}
+
+void pdf_set_dotted(){
+ HPDF_UINT16 dash_ptn[]={1};
+ HPDF_Page_SetDash(pdf_page,dash_ptn,1,1);
+}
bool pdf_begin(const char *path){
14 years, 8 months
r4217 adamblokus - in /branches/adamblokus/netsurf/pdf: TODO pdf_plotters.c
by netsurf@semichrome.net
Author: adamblokus
Date: Tue May 27 14:39:35 2008
New Revision: 4217
URL: http://source.netsurf-browser.org?rev=4217&view=rev
Log:
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
Added:
branches/adamblokus/netsurf/pdf/TODO
Modified:
branches/adamblokus/netsurf/pdf/pdf_plotters.c
Added: branches/adamblokus/netsurf/pdf/TODO
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/TODO?re...
==============================================================================
--- branches/adamblokus/netsurf/pdf/TODO (added)
+++ branches/adamblokus/netsurf/pdf/TODO Tue May 27 14:39:35 2008
@@ -1,0 +1,6 @@
+- finish all graphic primitives
+- adjust content width to page width
+- divide output into multiple pages (not just the first one)
+- add a save file.. dialogue
+- rearrange file structure
+- add utf support to Haru ( doable? )
Modified: branches/adamblokus/netsurf/pdf/pdf_plotters.c
URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/pdf_plo...
==============================================================================
--- branches/adamblokus/netsurf/pdf/pdf_plotters.c (original)
+++ branches/adamblokus/netsurf/pdf/pdf_plotters.c Tue May 27 14:39:35 2008
@@ -21,12 +21,15 @@
#include "desktop/plotters.h"
#include "utils/log.h"
+#include "utils/utils.h"
#include "hpdf.h"
-#define R(x) (( x & 0xff)/256.0)
-#define G(x) ((( x & 0xff00)>>8)/256.0)
-#define B(x) ((( x & 0xff0000)>>16)/256.0)
+#define R(x) (( (x) & 0x0000ff )/256.0)
+#define G(x) ((( (x) & 0x00ff00)>>8 )/256.0)
+#define B(x) ((( (x) & 0xff0000)>>16)/256.0)
+
+//#define PDF_DEBUG
static bool pdf_plot_clg(colour c);
static bool pdf_plot_rectangle(int x0, int y0, int width, int height,
@@ -56,9 +59,10 @@
void pdf_next_page();
void pdf_end(const char *);
-void error_handler (HPDF_STATUS error_no,
- HPDF_STATUS detail_no,
- void *user_data);
+void error_handler (HPDF_STATUS error_no, HPDF_STATUS detail_no,
+ void *user_data);
+
+static void pdf_plot_grid(int x_dist,int y_dist,unsigned int colour);
/*PDF Plotter - current doc,page and font*/
static HPDF_Doc pdf_doc;
@@ -66,6 +70,7 @@
static HPDF_Font pdf_font;
/*PDF Page size*/
static HPDF_REAL page_height, page_width;
+static bool page_clipped;
extern struct plotter_table plot;
@@ -95,7 +100,7 @@
int line_width, colour c, bool dotted, bool dashed){
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
- HPDF_Page_Rectangle(pdf_page, x0, page_height - y0, width, height);
+ HPDF_Page_Rectangle(pdf_page, x0, page_height - y0 + height, width, height);
HPDF_Page_Stroke(pdf_page);
return true;
@@ -105,6 +110,7 @@
colour c, bool dotted, bool dashed){
HPDF_Page_SetRGBStroke(pdf_page,R(c),G(c),B(c));
+ HPDF_Page_SetLineWidth(pdf_page,width);
HPDF_Page_MoveTo(pdf_page, x0, page_height - y0);
HPDF_Page_LineTo(pdf_page, x1, page_height - y1);
HPDF_Page_Stroke(pdf_page);
@@ -114,30 +120,76 @@
bool pdf_plot_polygon(int *p, unsigned int n, colour fill){
int i;
+ int pmaxx=p[0],pmaxy=p[1];
+ int pminx=p[0],pminy=p[1];
if(n==0)
return true;
- HPDF_Page_SetRGBFill(pdf_page,R(fill),G(fill),B(fill));
-
- HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]);
-
- for(i=1;i<n;i++)
+ HPDF_Page_SetRGBStroke(pdf_page,R(fill),G(fill),B(fill));
+ HPDF_Page_SetRGBFill(pdf_page,R(fill),G(fill),B(fill));
+ HPDF_Page_MoveTo(pdf_page, p[0], page_height - p[1]);
+
+ for(i=1;i<n;i++){
HPDF_Page_LineTo(pdf_page, p[i*2], page_height - p[i*2+1]);
-
- HPDF_Page_LineTo(pdf_page, p[0], page_height - p[1]);
-
+#ifdef PDF_DEBUG
+ pmaxx=max(pmaxx,p[i*2]);
+ pmaxy=max(pmaxy,p[i*2+1]);
+ pminx=min(pminx,p[i*2]);
+ pminy=min(pminy,p[i*2+1]);
+#endif
+ }
+
+#ifdef PDF_DEBUG
+ LOG(("%d %d %d %d %f",pminx,pminy, pmaxx, pmaxy, page_height-pminy));
+#endif
+
+ HPDF_Page_LineTo(pdf_page, p[0], page_height - p[1]);
HPDF_Page_Fill(pdf_page);
return true;
}
bool pdf_plot_fill(int x0, int y0, int x1, int y1, colour c){
+
+#ifdef PDF_DEBUG
+ LOG(("%d %d %d %d %f %X",x0,y0,x1,y1,page_height-y0,c));
+#endif
+
+ if(x0<0 || y0<0 || x1>page_width || y1>page_height)
+ return true;
+
+ HPDF_Page_SetRGBFill(pdf_page,R(c),G(c),B(c));
+ HPDF_Page_Rectangle(pdf_page, x0, page_height - y1, x1-x0, y1-y0);
+ HPDF_Page_Fill(pdf_page);
+
return true;
}
bool pdf_plot_clip(int clip_x0, int clip_y0,
int clip_x1, int clip_y1){
+
+
+#ifdef PDF_DEBUG
+ LOG(("%d %d %d %d",clip_x0, clip_y0, clip_x1, clip_y1));
+#endif
+ if(page_clipped)
+ HPDF_Page_GRestore(pdf_page);
+
+ /*Normalize cllipping area - to prevent overflows*/
+ clip_x0=min(max(clip_x0,0),page_width);
+ clip_y0=min(max(clip_y0,0),page_height);
+ clip_x1=min(max(clip_x1,0),page_width);
+ clip_y1=min(max(clip_y1,0),page_height);
+
+ HPDF_Page_GSave(pdf_page);
+ HPDF_Page_Rectangle(pdf_page, clip_x0, page_height-clip_y1,
+ clip_x1-clip_x0, clip_y1-clip_y0);
+ HPDF_Page_Clip(pdf_page);
+ HPDF_Page_EndPath(pdf_page);
+
+ page_clipped=true;
+
return true;
}
@@ -151,9 +203,7 @@
strncpy(word,text,length);
word[length]='\0';
-
- //LOG(("%d %d %X %s %X %X %f %f %f", x,y,style->color,word,bg,c,R(c),G(c),B(c)));
-
+
if (style->font_size.value.length.unit == CSS_UNIT_PX)
size = style->font_size.value.length.value;
else
@@ -162,9 +212,11 @@
HPDF_Page_SetRGBFill(pdf_page,R(c),G(c),B(c));
HPDF_Page_BeginText(pdf_page);
- HPDF_Page_SetFontAndSize (pdf_page, pdf_font, size);
+ HPDF_Page_SetFontAndSize (pdf_page, pdf_font, size*1.5);
HPDF_Page_TextOut (pdf_page, x, page_height - y, word);
HPDF_Page_EndText(pdf_page);
+
+ free(word);
return true;
}
@@ -218,9 +270,11 @@
bool pdf_begin(const char *path){
-
+#ifdef PDF_DEBUG
+ pdf_doc = HPDF_New(error_handler,NULL);
+#else
pdf_doc = HPDF_New(NULL,NULL);
-
+#endif
if(!pdf_doc){
LOG(("Error creating pdf_doc"));
return false;
@@ -228,7 +282,9 @@
HPDF_SetCompressionMode(pdf_doc,HPDF_COMP_ALL); /*Compression on*/
pdf_font = HPDF_GetFont (pdf_doc, "Times-Roman", "StandardEncoding");
-
+#ifdef PDF_DEBUG
+ LOG(("pdf_begin finishes"));
+#endif
return true;
}
@@ -237,11 +293,26 @@
HPDF_Page_SetSize (pdf_page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
page_height = HPDF_Page_GetHeight(pdf_page);
page_width = HPDF_Page_GetWidth(pdf_page);
+ page_clipped = false;
+#ifdef PDF_DEBUG
+ LOG(("%f %f",page_width,page_height));
+#endif
}
void pdf_end(const char *path){
+
+#ifdef PDF_DEBUG
+ LOG(("pdf_end begins"));
+ pdf_plot_grid(10,10,0xCCCCCC);
+ pdf_plot_grid(100,100,0xCCCCFF);
+#endif
+
HPDF_SaveToFile(pdf_doc, path);
HPDF_Free(pdf_doc);
+
+#ifdef PDF_DEBUG
+ LOG(("pdf_end finishes"));
+#endif
}
void error_handler (HPDF_STATUS error_no,
@@ -252,3 +323,14 @@
(HPDF_UINT)error_no,
(HPDF_UINT)detail_no);
}
+
+void pdf_plot_grid(int x_dist,int y_dist,unsigned int colour){
+ int i;
+
+ for(int i=x_dist;i<page_width;i+=x_dist)
+ pdf_plot_line(i,0,i,page_height,1,colour,false,false);
+
+ for(int i=y_dist;i<page_height;i+=x_dist)
+ pdf_plot_line(0,i,page_width,i,1,colour,false,false);
+
+}
14 years, 8 months