[REVIEW] Adam Blokus' changes so far
by John-Mark Bell
Hi all,
I've finally gone through the core changes Adam has made. I've not looked
in detail at the printing and pdf generation stuff itself -- I'll assume
that John T has done/will do that :)
Overall, the quality of this code is pretty good. Most of my comments
address stylistic issues. My comments are prefixed *jmb* for ease of
searching.
I've no real bright ideas about the font function issue. What's currently
there is ok for the timebeing, however.
J.
Index: render/loosen.c
===================================================================
--- render/loosen.c (.../trunk/netsurf) (revision 0)
+++ render/loosen.c (.../branches/adamblokus/netsurf) (revision 4686)
@@ -0,0 +1,399 @@
+/*
+ * Copyright 2008 Adam Blokus <adamblokus(a)gmail.com>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdbool.h>
+#include <assert.h>
+
+#include "render/box.h"
+#include "render/font.h"
+
+#include "content/content.h"
+
*jmb* This should probably be above box.h.
+#include "utils/log.h"
+#include "utils/talloc.h"
+
+#define AUTO INT_MIN
+
+bool loosen_document_layout(struct content *content, struct box *layout,
+ int width, int height);
*jmb* Is this meant to be static? If not, it should be defined in a header
+static bool loosen_text(struct box *text, int width, struct content* content);
+
+static bool loosen_table(struct box *box, int available_width,
+ struct content *content);
+
+static bool loosen_make_block_element(struct box *box, int width, int cx,
+ struct content *content);
+
+static bool loosen_shrink_object(struct box* box, int width);
+
+static bool loosen_all_first_pass(struct box* box, int width, int cx,
+ struct content* content);
+static bool loosen_all_second_pass(struct box* box, int width, int cx,
+ struct content* content);
+static bool loosen_all_third_pass(struct box* box, int width, int cx,
+ struct content* content);
+
*jmb* struct box *box here, please.
+/**
+ * Main loosing procedure
+ * \param content Reformated content - talloc memory pool for new boxes
+ * \param layout Root of the loosened box tree
+ * \param width Width the content is intended to fit
+ * \param height Height of a single page - to be taken into consideration for \
+ * preventing elements for being cropped at top/bottom edges of pages.
+ * \return true if successful, false otherwise (lack of memory)
+*/
+bool loosen_document_layout(struct content *content, struct box *layout,
+ int width, int height)
*jmb* Style: two-tab indent
+{
+ /* Optional try - if the current layout is not more than xx% too wide,
+ * maybe we scale the content to preserve the original layout?
+ */
+
+ if (!loosen_all_first_pass(layout, width, 0, content))
+ return false;
+ layout->min_width = 0;
+ layout->max_width = UNKNOWN_MAX_WIDTH;
+ content_reformat(content, width, 0);
+
+ /*Check if pass 1 was enough - if re-layouting doesn't give
+ *us the right width, go on to pass 2. And again - if pass 2 was not
+ *enough - go on to pass 3
+ */
+
+ if (content->width > width) {
+ if( !loosen_all_second_pass(layout, width, 0, content))
+ return false;
*jmb* Style: space before the bracket, not after it
+ layout->min_width = 0;
+ layout->max_width = UNKNOWN_MAX_WIDTH;
+ content_reformat(content, width, 0);
+ }
+
+ if (content->width > width) {
+ if( !loosen_all_third_pass(layout, width, 0, content))
+ return false;
*jmb* as above
+ layout->min_width = 0;
+ layout->max_width = UNKNOWN_MAX_WIDTH;
+ content_reformat(content, width, 0);
+ }
+
+ return true;
+}
+
+/** Primarily - break too wide words into pieces.
+ * \param text - the box that contains text to be broken
+ * \param width Width the content is intended to fit
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+*/
+bool loosen_text(struct box *text, int width, struct content *content)
+{
+ unsigned int offset;
+ int actual_x;
+
+ int *breaks;
+ int break_count;
+
+ int position, i;
+ struct font_functions * font_func;
+
*jmb* Style: lose the space after *
+ if (content->type == CONTENT_HTML)
+ font_func = content->data.html.font_func;
+ else
+ return false;
+
+ if (text->width <= width) {
+ LOG(("loosen_text called unnecessary?"));
+ /*Still - not an error for this function*/
+ return true;
+ }
+
+ breaks = (int*)malloc( sizeof(int) * text->length);
*jmb* The cast to int* is unnecessary -- it's implicit.
+ if (breaks == NULL)
+ return false;
+
+ break_count = 0;
+ position = 0;
+
+ while (position < text->length) {
+ font_func->font_position_in_string(text->style,
+ text->text + position,
+ text->length - position,
+ width, &offset, &actual_x);
*jmb* Style: Use 2 tabs for indent here.
+
+ if (offset < text->length - position) {
+ /*Another break*/
+ LOG(("Current text broken at offset %d", position + offset));
*jmb* Style: wrap this
+ breaks[break_count++] = position + offset-1;
+ }
+
+ position+=offset;
*jmb* Style: spaces either side of +=
+ }
+
+ text->text = talloc_realloc(content, text->text, char, text->length + break_count);
+
*jmb* Style: wrap this
+ i=text->length-1;
*jmb* Style: spaces either side of =
+ text->length = text->length + break_count;
+
+ for (; i>=0; i--) {
+ text->text[i + break_count] = text->text[i];
+ if (i == breaks[break_count - 1]){
*jmb* Style: space before brace
+ break_count--;
+ text->text[i + break_count] = ' ';
+ }
+ }
+
+ free(breaks);
+
+ return true;
+}
+
+/**
+ * Changing table layout and structure to fit the contents width.
+ * In the most extreme case - the table has no influence on the width
+ * (each row is broken into one-cell rows).
+ * \param table - the box that contains table to be broken
+ * \param width Width the content is intended to fit
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+ */
+bool loosen_table(struct box *table, int width,
+ struct content *content)
*jmb* Style: this can all be one line
+{
+
+ struct box *row_group, *row, *cell, *br, *prev, *inline_container;
+ unsigned int row_sum;
+ bool first_cell_in_row;
+
+ if (table->min_width <= width)
+ return true;
+
+ inline_container = box_create(0, 0, 0, 0, 0, content);
+ inline_container->type = BOX_INLINE_CONTAINER;
+ inline_container->parent = table;
+ inline_container->style = talloc_memdup(content, table->style, sizeof *table->style);
+
*jmb* Style: wrap this
+ prev = NULL;
+
+ for (row_group = table->children; row_group; row_group =row_group->next)
*jmb* Style: space after =.
This loop's body should probably be inside braces
The entire loop below should be indented one tab.
+ for (row = row_group->children; row; row = row->next) {
+
+ for (cell = row->children; cell; cell = cell->next) {
+ cell->type = BOX_INLINE_BLOCK;
+ cell->prev = prev;
+ cell->parent = inline_container;
+ cell->max_width = width;
+ cell->min_width = 0;
+
+ if (prev!=NULL)
*jmb* Style: spaces around !=
+ prev->next = cell;
+ else
+ inline_container->children = cell;
+
+ prev = cell;
+ }
+
+ br = box_create(0, 0, 0, 0, 0, content);
+ br->type = BOX_BR;
+ br->parent = inline_container;
+ br->prev = prev;
+ br->style = talloc_memdup(content, table->style, sizeof *table->style);
*jmb* Style: wrap this
+ br->style->clear = CSS_CLEAR_BOTH;
+
+ if (prev!=NULL)
*jmb* Style: spaces around !=
+ prev->next = br;
+ else
+ inline_container->children = br;
+
+ prev = br;
+ }
+
+ inline_container->last = prev;
+
+ table->type = BOX_BLOCK;
+ table->children = table->last = inline_container;
+ table->col = NULL; //we can 'forget' this pointer thanks to talloc, right?
*jmb* This should be safe, yes.
+ return true;
+}
+
+
+/**
+ * Change absolute and relative positioned elements into block elements
+ * in case they are positioned to far to the rigth
+ * \param box - the box that should be changed
+ * \param width Width the content is intended to fit
+ * \param cx current x - not yet in use
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+ */
+bool loosen_make_block_element(struct box *box, int width, int cx,
+ struct content *content)
*jmb* This probably wants to be called something like layout_position_static
Style: 2 tab indent
+{
+ assert(box->style);
+
+ if(box->style->position == CSS_POSITION_ABSOLUTE /*&&
*jmb* Style: space after if
+ box->x + box->width > width*/){
*jmb* Space before brace
+ box->style->position = CSS_POSITION_NOT_SET;
+ }
+
+ return true;
+}
+
+/**
+ * Shrink an object (esp. an image) to fit the page-width
+ * \note Not sure wheter it won't be better for images to be cropped
+ * \param box - the box that should be changed
+ * \param width Width the content is intended to fit
+ * \return true if successful, false otherwise
+*/
+bool loosen_shrink_object(struct box* box, int width)
+{
+ assert(box->object != NULL);
+
+ box->height = AUTO;
+ box->width = width;
+
+ if (box->style) {
+ box->style->width.width = CSS_WIDTH_PERCENT;
+ box->style->width.value.percent = 100;
+ box->style->height.height= CSS_HEIGHT_AUTO;
+ }
+
+ return true;
+}
+/*pass 1 -
+ */
+/**
+ * Pass 1 of loosening - do such obvious changes as: breaking too long words,
+ * moving absolute positioned objects into the visibile scope of width.
+ * \param box - the box that should be changed
+ * \param width Width the content is intended to fit
+ * \param cx current x - not yet in use
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+*/
+bool loosen_all_first_pass(struct box* box, int width, int cx, struct content* content)
*jmb* Style: wrap this
+{
+ struct box* c;
+ int got_width;
+ int x;
+
+ for (c = box->children; c ; c = c->next) {
+ x = cx + c->x;
+ if (c->children != NULL)
+ loosen_all_first_pass(c, width, x, content);
+
+ if (c->style) {
+ if (c->style->position == CSS_POSITION_RELATIVE ||
+ c->style->position == CSS_POSITION_ABSOLUTE )
+ loosen_make_block_element(c, width, cx, content);
+ if ( c->style->width.width == CSS_WIDTH_LENGTH &&
+ css_len2px(&c->style->width.value.length, c->style) > width)
+ c->style->width.width = CSS_WIDTH_NOT_SET;
+ }
+
+ if (c->object && c->width > width)
+ loosen_shrink_object(c, width);
+
+ switch (c->type) {
+ case BOX_TEXT:
+ loosen_text(c, width, content);
+ break;
+ }
+
+ c->min_width = 0;
+ c->max_width = UNKNOWN_MAX_WIDTH;
+
+ }
*jmb* Where's the return statement? Also, you need to check for any of
the functions you're calling returning failure, then act
appropriately.
+}
+
+/**
+ * Pass 2 of loosening - break tables
+ * \param box - the box that should be changed
+ * \param width Width the content is intended to fit
+ * \param cx current x - not yet in use
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+ */
+bool loosen_all_second_pass(struct box* box, int width, int cx, struct content* content)
*jmb* Style: wrap this
+{
+ struct box* c;
*jmb* struct box *c, please
+ int got_width;
+ int x;
+
+ for (c = box->children; c ; c = c->next) {
*jmb* Style: no space before semicolon
+ x = cx + c->x;
+ if (c->children != NULL)
+ loosen_all_second_pass(c, width, x, content);
+
+ switch (c->type) {
+ case BOX_TABLE:
+ loosen_table(c, width, content);
+ break;
+ }
+
+ c->min_width = 0;
+ c->max_width = UNKNOWN_MAX_WIDTH;
+ }
*jmb* Where's the return statement? Again, error checking.
+}
+
+
+/**
+ * Pass 3 of loosening -zero all margins and paddings
+ * \param box - the box that should be changed
+ * \param width Width the content is intended to fit
+ * \param cx current x - not yet in use
+ * \param content talloc memory pool for new boxes
+ * \return true if successful, false otherwise
+ */
+bool loosen_all_third_pass(struct box* box, int width, int cx, struct content* content)
*jmb* Style: wrap this.
+{
+ struct box* c;
*jmb* See above
+ int got_width;
+ int x;
+
+ for (c = box->children; c ; c = c->next) {
+ x = cx + c->x;
+ if (c->children != NULL)
+ loosen_all_third_pass(c, width, x, content);
+
+ c->padding[LEFT] = c->padding[RIGHT] = 0;
+ c->margin[LEFT] = c->margin[RIGHT] = 0;
+
+ if (c->style) {
+ c->style->margin[LEFT].margin = CSS_MARGIN_PERCENT;
+ c->style->margin[LEFT].value.percent = 0;
+
+ c->style->margin[RIGHT].margin = CSS_MARGIN_PERCENT;
+ c->style->margin[RIGHT].value.percent = 0;
+
+ c->style->padding[LEFT].padding = CSS_PADDING_PERCENT;
+ c->style->padding[LEFT].value.percent = 0;
+
+ c->style->padding[RIGHT].padding = CSS_PADDING_PERCENT;
+ c->style->padding[RIGHT].value.percent = 0;
+
+ }
+
+ c->min_width = 0;
+ c->max_width = UNKNOWN_MAX_WIDTH;
+
+ }
*jmb* Missing return. Error checking.
+}
+
Index: render/html.c
===================================================================
--- render/html.c (.../trunk/netsurf) (revision 4686)
+++ render/html.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine.
Index: render/loosen.h
===================================================================
--- render/loosen.h (.../trunk/netsurf) (revision 0)
+++ render/loosen.h (.../branches/adamblokus/netsurf) (revision 4686)
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2008 Adam Blokus <adamblokus(a)gmail.com>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+\file
+General idea - a set of routines working themselves recursively through
+the box tree and trying to change the layout of the document as little
+as possible to acquire the desired width ( - to make it fit in a printed
+page ), where possible - also taking the dividing height into consideration,
+to prevent objects being cut by ends of pages.
+*/
+
+#ifndef NETSURF_RENDER_LOOSEN_H
+#define NETSURF_RENDER_LOOSEN_H
+#include <stdbool.h>
+
+bool loosen_document_layout(struct content *content, struct box *layout,
+ int width, int height);
*jmb* Style: 2 tab indent
+
+#endif
Index: render/html_redraw.c
===================================================================
--- render/html_redraw.c (.../trunk/netsurf) (revision 4686)
+++ render/html_redraw.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Style: wrap to 80 columns. Otherwise fine.
Index: render/textplain.c
===================================================================
--- render/textplain.c (.../trunk/netsurf) (revision 4686)
+++ render/textplain.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Style: wrapping. Otherwise fine
Index: render/html.h
===================================================================
--- render/html.h (.../trunk/netsurf) (revision 4686)
+++ render/html.h (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine.
Index: render/font.h
===================================================================
--- render/font.h (.../trunk/netsurf) (revision 4686)
+++ render/font.h (.../branches/adamblokus/netsurf) (revision 4686)
@@ -39,14 +39,19 @@
struct css_style;
-bool nsfont_width(const struct css_style *style,
+struct font_functions
+{
+bool (*font_width)(const struct css_style *style,
const char *string, size_t length,
int *width);
-bool nsfont_position_in_string(const struct css_style *style,
+bool (*font_position_in_string)(const struct css_style *style,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x);
-bool nsfont_split(const struct css_style *style,
+bool (*font_split)(const struct css_style *style,
const char *string, size_t length,
int x, size_t *char_offset, int *actual_x);
+};
*jmb* Style: indent struct members 1 tab.
+extern const struct font_functions nsfont;
+
#endif
Index: render/layout.c
===================================================================
--- render/layout.c (.../trunk/netsurf) (revision 4686)
+++ render/layout.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Style: wrapping, and 2 tab indents. Otherwise fine
Index: render/box.c
===================================================================
--- render/box.c (.../trunk/netsurf) (revision 4686)
+++ render/box.c (.../branches/adamblokus/netsurf) (revision 4686)
@@ -33,7 +33,6 @@
#include "utils/log.h"
#include "utils/talloc.h"
-
static bool box_contains_point(struct box *box, int x, int y);
#define box_is_float(box) (box->type == BOX_FLOAT_LEFT || \
@@ -545,6 +544,10 @@
fprintf(stream, "(%i %i %i %i) ",
box->descendant_x0, box->descendant_y0,
box->descendant_x1, box->descendant_y1);
+
+ fprintf(stream, "m(%i %i %i %i) ",
+ box->margin[TOP], box->margin[LEFT],
+ box->margin[BOTTOM], box->margin[RIGHT]);
switch (box->type) {
case BOX_BLOCK: fprintf(stream, "BLOCK "); break;
@@ -638,3 +641,196 @@
box_dump(stream, c, depth + 1);
}
}
+
+/* Box tree duplication below
+*/
+
+/** structure for translating addresses in the box tree */
+struct box_dict_element{
+ struct box *old, *new;
+};
+
+static bool box_duplicate_main_tree(struct box* box, struct content* c, int *count);
+static void box_duplicate_create_dict(struct box* old_box, struct box* new_box,
+ struct box_dict_element **dict);
+static void box_duplicate_update( struct box* box, struct box_dict_element* dict, int n);
+
+static int box_compare_dict_elements(struct box_dict_element* a,
+ struct box_dict_element* b);
+
+int box_compare_dict_elements(struct box_dict_element* a,
+ struct box_dict_element* b){
+ return (int)((*a).old) - (int)((*b).old);
+}
+
*jmb* Style: 2 tab indent & wrapping
+/** Duplication of a box tree. We assume that all the content is fetched,
+fallbacks have been applied where necessary and we reuse a lot of content
+like strings, fetched objects etc - just replicating all we need to create
+two different layouts.
+\return true on success, false on lack of memory
+*/
+struct box* box_duplicate_tree(struct box* root, struct content* c)
+{
+ struct box *new_root;/**< Root of the new box tree*/
+ int box_number = 0;
+ struct box *old_addr, *new_addr;
+ struct box_dict_element *box_dict, *box_dict_end;
+
+ /* 1. Duplicate parent - children structure, list_markers*/
+ new_root = talloc_memdup(c, root, sizeof (struct box));
+ if( !box_duplicate_main_tree(new_root, c, &box_number))
+ return NULL;
+
*jmb* Style: space after if, not bracket
+ /* 2. Create address translation dictionary*/
+ /*TODO: dont save unnecessary addresses*/
+
+ box_dict_end = box_dict =
+ (struct box_dict_element*)malloc(box_number *
+ sizeof(struct box_dict_element));
+
*jmb* This case is unnecessary
+ if (box_dict == NULL)
+ return NULL;
*jmb* Should the duplicate tree get cleaned up here?
+ box_duplicate_create_dict(root, new_root, &box_dict_end);
+
+ assert((box_dict_end - box_dict) == box_number);
+
+ /*3. Sort it*/
+
+ qsort(box_dict, (box_dict_end - box_dict), sizeof(struct box_dict_element),
+ (int (*)(const void *, const void *))box_compare_dict_elements);
+
+ /* 4. Update inline_end and float_children pointers */
+
+ box_duplicate_update(new_root, box_dict, (box_dict_end - box_dict));
+
+ free(box_dict);
+
+ return new_root;
+}
+
+/**
+ * Recursively duplicates children of an element, and also if present - its
+ * list_marker, style and text.
+ * \param box Current box to duplicate its children
+ * \param c talloc memory pool
+ * \param count number of boxes seen so far
+ * \return true if successful, false otherwise (lack of memory)
+*/
+bool box_duplicate_main_tree(struct box* box, struct content* c, int *count)
*jmb* Style: struct box *box, etc.
+{
+
+ struct box *b, *prev, *copy;
+
+ prev = NULL;
+
+ for (b = box->children; b; b = b->next){
+ /*Copy child*/
+ copy = talloc_memdup(c, b, sizeof (struct box));
+ if (copy == NULL)
+ return false;
+
+ copy->parent = box;
+
+ if (prev != NULL)
+ prev->next = copy;
+ else
+ box->children = copy;
+
+ /* Recursively visit child */
+ box_duplicate_main_tree(copy, c, count);
+
+ prev = copy;
+ }
+
+ box->last = prev;
+
+ if (box->list_marker){
*jmb* Style: space before brace
+ box->list_marker = talloc_memdup(c, box->list_marker,
+ sizeof *box->list_marker);
+ if (box->list_marker == NULL)
+ return false;
+ box->list_marker->parent = box;
+ }
+
+ if (box->text){
*jmb* as above
+ box->text = talloc_memdup(c, box->text, box->length);
+ if (box->text == NULL)
+ return false;
+ }
+
+ if (box->style){
*jmb* as above
+ box->style = talloc_memdup(c, box->style, sizeof *box->style);
+ if (box->style == NULL)
+ return false;
+ }
+
+ /*Make layout calculate the size of this element later
+ (might change because of font change etc.) */
+ box->width = UNKNOWN_WIDTH;
+ box->min_width = 0;
+ box->max_width = UNKNOWN_MAX_WIDTH;
+
+ (*count)++;
+
+ return true;
+}
+
+/**
+ * Recursively creates a dictionary of addresses - binding the address of a box
+ * with its copy.
+ * \param old_box original box
+ * \param new_box copy of the original box
+ * \param dict pointer to a pointer to the current position in the dictionary
+ */
+void box_duplicate_create_dict(struct box* old_box, struct box* new_box,
+ struct box_dict_element **dict)
+{
+ /**Children of the old and new boxes*/
+ struct box *b_old, *b_new;
+
+ for (b_old = old_box->children, b_new = new_box->children;
+ b_old != NULL && b_new != NULL;
+ b_old = b_old->next, b_new = b_new->next)
+ box_duplicate_create_dict(b_old, b_new, dict);
*jmb* Style: 2 tab indent
+
+ /*The new tree should be a exact copy*/
+ assert(b_old == NULL && b_new == NULL);
+
+ (**dict).old = old_box;
+ (**dict).new = new_box;
+ (*dict)++;
+}
+
+/**
+ * Recursively updates pointers in box tree.
+ * \param box current box in the new box tree
+ * \param box_dict box pointers dictionary
+ * \param n number of memory addresses in the dictionary
+ */
+void box_duplicate_update(struct box* box, struct box_dict_element* box_dict, int n)
*jmb* Style: wrapping
+{
+ struct box_dict_element* box_dict_element;
+ struct box* b;
+ struct box_dict_element element;
+
+ for (b = box->children; b; b = b->next)
+ box_duplicate_update(b, box_dict, n);
+
+ if (box->float_children){
+ element.old = box->float_children;
+ box_dict_element = bsearch(&element,
+ box_dict, n,
+ sizeof(struct box_dict_element),
+ (int (*)(const void *, const void *))box_compare_dict_elements);
+ box->float_children = box_dict_element->new;
+ }
+
+ if (box->next_float){
+ element.old = box->next_float;
+ box_dict_element = bsearch(&element,
+ box_dict, n,
+ sizeof(struct box_dict_element),
+ (int (*)(const void *, const void *))box_compare_dict_elements);
+ box->next_float = box_dict_element->new;
+ }
+}
*jmb* Style: spaces before brace, etc.
Index: render/box.h
===================================================================
--- render/box.h (.../trunk/netsurf) (revision 4686)
+++ render/box.h (.../branches/adamblokus/netsurf) (revision 4686)
@@ -311,4 +311,6 @@
bool box_normalise_block(struct box *block, struct content *c);
+struct box* box_duplicate_tree(struct box* root, struct content* c);
+
*jmb* Style: struct box *box, etc.
#endif
Index: image/gif.c
Index: image/nssprite.c
Index: image/ico.c
Index: image/bmp.c
Index: image/mng.c
Index: image/rsvg.c
Index: image/jpeg.c
*jmb* fine
Index: Docs/Doxyfile
===================================================================
--- Docs/Doxyfile (.../trunk/netsurf) (revision 4686)
+++ Docs/Doxyfile (.../branches/adamblokus/netsurf) (revision 4686)
@@ -97,7 +97,7 @@
# (but less readable) file names. This can be useful is your file systems
# doesn't support long names like on DOS, Mac, or CD-ROM.
-SHORT_NAMES = NO
+SHORT_NAMES = YES
*jmb* Is this change needed?
Index: riscos/save_draw.c
===================================================================
--- riscos/save_draw.c (.../trunk/netsurf) (revision 4686)
+++ riscos/save_draw.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine.
Index: riscos/save.c
===================================================================
--- riscos/save.c (.../trunk/netsurf) (revision 4686)
+++ riscos/save.c (.../branches/adamblokus/netsurf) (revision 4686)
@@ -28,13 +28,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "oslib/dragasprite.h"
-#include "oslib/osbyte.h"
-#include "oslib/osfile.h"
-#include "oslib/osmodule.h"
+#include <oslib/dragasprite.h>
+#include <oslib/osbyte.h>
+#include <oslib/osfile.h>
+#include <oslib/osmodule.h>
#include <oslib/osspriteop.h>
-#include "oslib/wimp.h"
-#include "oslib/wimpspriteop.h"
+#include <oslib/wimp.h>
+#include <oslib/wimpspriteop.h>
#include "desktop/netsurf.h"
#include "desktop/save_text.h"
#include "desktop/selection.h"
@@ -47,6 +47,7 @@
#include "riscos/save.h"
#include "riscos/save_complete.h"
#include "riscos/save_draw.h"
+#include "riscos/save_pdf.h"
#include "riscos/textselection.h"
#include "riscos/thumbnail.h"
#include "riscos/wimp.h"
@@ -92,10 +93,12 @@
/** Table of filetypes and default filenames. Must be in sync with
* gui_save_type (riscos/gui.h). A filetype of 0 indicates the content should
- * be used. */
-struct gui_save_table_entry gui_save_table[] = {
+ * be used.
+ */
+static const struct gui_save_table_entry gui_save_table[] = {
/* GUI_SAVE_SOURCE, */ { 0, "SaveSource" },
/* GUI_SAVE_DRAW, */ { 0xaff, "SaveDraw" },
+ /* GUI_SAVE_PDF, */ { 0xadf, "SavePDF" },
/* GUI_SAVE_TEXT, */ { 0xfff, "SaveText" },
/* GUI_SAVE_COMPLETE, */ { 0xfaf, "SaveComplete" },
/* GUI_SAVE_OBJECT_ORIG, */ { 0, "SaveObject" },
@@ -633,7 +636,7 @@
/**
* Does the actual saving
*
- * \param c content to save (or 0 for other)
+ * \param c content to save (or NULL for other)
* \param path path to save as
* \return true on success, false on error and error reported
*/
@@ -647,6 +650,10 @@
case GUI_SAVE_DRAW:
return save_as_draw(c, path);
#endif
+#ifdef WITH_DRAW_EXPORT
*jmb* WITH_PDF_EXPORT?
+ case GUI_SAVE_PDF:
+ return save_as_pdf(c, path);
+#endif
case GUI_SAVE_TEXT:
save_as_text(c, path);
xosfile_set_type(path, 0xfff);
Index: riscos/plotters.c
===================================================================
--- riscos/plotters.c (.../trunk/netsurf) (revision 4686)
+++ riscos/plotters.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine
Index: desktop/history_core.c
===================================================================
--- desktop/history_core.c (.../trunk/netsurf) (revision 4686)
+++ desktop/history_core.c (.../branches/adamblokus/netsurf) (revision 4686)
@@ -597,13 +597,13 @@
int tailsize = 5;
if (!plot.bitmap(entry->x, entry->y, WIDTH, HEIGHT,
- entry->bitmap, 0xffffff))
+ entry->bitmap, 0xffffff,NULL))
*jmb* Style: space before NULL
return false;
if (!plot.rectangle(entry->x - 1, entry->y - 1, WIDTH + 1, HEIGHT + 1,
entry == history->current ? 2 : 1, c, false, false))
return false;
- if (!nsfont_position_in_string(&css_base_style, entry->page.title,
+ if (!nsfont.font_position_in_string(&css_base_style, entry->page.title,
strlen(entry->page.title), WIDTH,
&char_offset, &actual_x))
return false;
Index: desktop/plotters.h
===================================================================
--- desktop/plotters.h (.../trunk/netsurf) (revision 4686)
+++ desktop/plotters.h (.../branches/adamblokus/netsurf) (revision 4686)
@@ -25,6 +25,7 @@
#include <stdbool.h>
#include "css/css.h"
+#include "content/content.h"
struct bitmap;
@@ -46,10 +47,10 @@
bool (*arc)(int x, int y, int radius, int angle1, int angle2,
colour c);
bool (*bitmap)(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg);
+ struct bitmap *bitmap, colour bg, struct content *content);
*jmb* Style: wrapping
bool (*bitmap_tile)(int x, int y, int width, int height,
struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y);
+ bool repeat_x, bool repeat_y, struct content *content);
bool (*group_start)(const char *name); /** optional */
bool (*group_end)(void); /** optional */
bool (*flush)(void);
Index: desktop/browser.c
===================================================================
--- desktop/browser.c (.../trunk/netsurf) (revision 4686)
+++ desktop/browser.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine.
Index: desktop/knockout.c
===================================================================
--- desktop/knockout.c (.../trunk/netsurf) (revision 4686)
+++ desktop/knockout.c (.../branches/adamblokus/netsurf) (revision 4686)
*jmb* Fine.
14 years, 6 months
Re: r4737 adamblokus - in /branches/adamblokus/netsurf: desktop/ gtk/ gtk/dialogs/ gtk/res/ pdf/
by John Tytgat
In message <courier.488B107D.00001AC1(a)atlanta.semichrome.net> you wrote:
> Author: adamblokus
> Date: Sat Jul 26 06:54:36 2008
> New Revision: 4737
>
> [...]
> --- branches/adamblokus/netsurf/desktop/options.c (original)
> +++ branches/adamblokus/netsurf/desktop/options.c Sat Jul 26 06:54:36 2008
> @@ -136,6 +136,18 @@
> #else
> unsigned int option_min_reflow_period = 25; /* time in cs */
> #endif
> +/** top margin of exported page*/
> +int option_margin_top = DEFAULT_MARGIN_TOP;
> +/** bottom margin of exported page*/
> +int option_margin_bottom = DEFAULT_MARGIN_BOTTOM;
> +/** left margin of exported page*/
> +int option_margin_left = DEFAULT_MARGIN_LEFT;
> +/** right margin of exported page*/
> +int option_margin_right = DEFAULT_MARGIN_RIGHT;
> +/** scale of exported content*/
> +int option_export_scale = DEFAULT_EXPORT_SCALE;
> +/** directory where the exported file will be saved*/
> +char *option_export_directory = 0;
I think this can become "const char *" as you don't want other code
changing the string via this pointer (assuming this won't result in having
to cast the const away in other code, if it does feel free to leave this
as is).
Also I slightly prefer using NULL i.s.o. 0 for pointers. C standard wise it
boils down to the same but it is slightly more clear what this is all about.
> ==============================================================================
> --- branches/adamblokus/netsurf/desktop/print.c (original)
> +++ branches/adamblokus/netsurf/desktop/print.c Sat Jul 26 06:54:36 2008
> [...]
> + settings->scale = option_export_scale;
> + settings->scale /= 100;
I would turn this into one line.
> +
> + settings->margins[MARGINLEFT] = option_margin_left;
> + settings->margins[MARGINRIGHT] = option_margin_right;
> + settings->margins[MARGINTOP] = option_margin_top;
> + settings->margins[MARGINBOTTOM] = option_margin_bottom;
> +
> + settings->margins[MARGINTEXT] = DEFAULT_MARGIN_TEXT;
> +
> + strcpy(path, option_export_directory);
> + strcat(path, "/out.pdf");
This is potentionally not platform independent as not all platforms use
the '/' character as directory separator. I don't think it is a real
issue for platforms we're supporting right now (including RISC OS) so you
can leave it as is but adding a FIXME or Doxygen todo comment could avoid
grumble in the future.
> [...]
> ==============================================================================
> --- branches/adamblokus/netsurf/gtk/gtk_gui.c (original)
> +++ branches/adamblokus/netsurf/gtk/gtk_gui.c Sat Jul 26 06:54:36 2008
> @@ -273,7 +273,13 @@
> LOG(("Using '%s' as download directory", home));
> option_downloads_directory = home;
> }
> -
> +
> + if (!option_export_directory) {
> + char *home = getenv("HOME");
> + LOG(("Using '%s' as export directory", home));
When HOME is not defined, you're using NULL to print. With some C runtime
libraries you get away with this but don't count on it. Avoid this with
something like: home ? home : "<NULL>".
> [...]
> ==============================================================================
> --- branches/adamblokus/netsurf/pdf/font_haru.c (original)
> +++ branches/adamblokus/netsurf/pdf/font_haru.c Sat Jul 26 06:54:36 2008
> @@ -60,6 +60,8 @@
> };
>
>
> +extern float pdf_scale;
> +
'extern' in a C file rings my alarm bells...
> [...]
> ==============================================================================
> --- branches/adamblokus/netsurf/pdf/pdf_plotters.c (original)
> +++ branches/adamblokus/netsurf/pdf/pdf_plotters.c Sat Jul 26 06:54:36 2008
> +bool pdf_set_scale(float s)
> +{
> + pdf_scale = s;
> +}
Ahem, no 'return' ? Didn't the compiler warn you about this ?
I don't see a good reason to have a return value here. If you do, please
add some Doxygen comments explaining how to interpret that value (and make
sure you use that return value yourself in the code calling pdf_set_scale()).
>
> Modified: branches/adamblokus/netsurf/pdf/pdf_plotters.h
> URL: http://source.netsurf-browser.org/branches/adamblokus/netsurf/pdf/pdf_plo...
> ==============================================================================
> --- branches/adamblokus/netsurf/pdf/pdf_plotters.h (original)
> +++ branches/adamblokus/netsurf/pdf/pdf_plotters.h Sat Jul 26 06:54:36 2008
> @@ -37,4 +37,7 @@
> /**Close pdf document and save changes to file*/
> void pdf_end(void);
>
> +float pdf_scale;
Tss, no 'extern' for variables in header ?!
Thanks,
John.
--
John Tytgat
joty(a)netsurf-browser.org
14 years, 6 months
RFC: gcc2 fixes needed for BeOS
by François Revol
Here is my current diff.
It's mostly moving back variable decl before statements as gcc2 wasn't
c99, and BeOS can't use gcc4 without great hackery, and g++ crashes
miserably on the C code.
The css font size is due to g++ not liking it inlined in the union.
Still needs cleanup though, like strtod stuff.
Haiku should soon be usable so we can move to it, and it can use gcc4,
but I'd like to at least have some revisions that build under BeOS
without patch before moving along.
François.
Index: render/form.c
===================================================================
--- render/form.c (révision 4724)
+++ render/form.c (copie de travail)
@@ -343,12 +343,13 @@
case GADGET_IMAGE: {
/* image */
+ const size_t len;
if (control != submit_button)
/* only the activated submit button
* is successful */
continue;
- const size_t len = strlen(control->name) + 3;
+ len = strlen(control->name) + 3;
/* x */
success_new = malloc(sizeof(*success_new));
Index: render/html.c
===================================================================
--- render/html.c (révision 4724)
+++ render/html.c (copie de travail)
@@ -534,10 +534,11 @@
LOG(("Node: %s", node->name));
if (!c->title && strcmp((const char *) node->name,
"title") == 0) {
+ char *title2;
xmlChar *title = xmlNodeGetContent(node);
if (!title)
return false;
- char *title2 = squash_whitespace((const char *) title);
+ title2 = squash_whitespace((const char *) title);
xmlFree(title);
if (!title2)
return false;
Index: render/textplain.c
===================================================================
--- render/textplain.c (révision 4724)
+++ render/textplain.c (copie de travail)
@@ -24,7 +24,9 @@
#include <assert.h>
#include <errno.h>
#include <stddef.h>
+#ifndef __BEOS__
#define LIBICONV_PLUG
+#endif
#include <iconv.h>
#include "content/content.h"
#include "css/css.h"
Index: render/html_redraw.c
===================================================================
--- render/html_redraw.c (révision 4724)
+++ render/html_redraw.c (copie de travail)
@@ -778,7 +778,8 @@
!box->text) {
int padding_height = (box->padding[TOP] + box->height +
box->padding[BOTTOM]) * scale;
- for (struct box *c = box; c; c = c->next) {
+ struct box *c;
+ for (c = box; c; c = c->next) {
int x = (x_parent + c->x) * scale;
int y = y_parent + c->y;
int padding_width = c->width;
@@ -792,6 +793,7 @@
y *= scale;
padding_width *= scale;
}
+{//XXX
int p[20] = {
x, y,
x - left, y - top,
@@ -830,6 +832,7 @@
box->border[RIGHT] * scale);
if (!box->inline_end || c == box->inline_end)
break;
+}//XXX
}
} else {
int x = (x_parent + box->x) * scale;
@@ -846,7 +849,8 @@
x, y,
x - left, y - top
};
- for (unsigned int i = 0; i != 4; i++) {
+ unsigned int i;
+ for (i = 0; i != 4; i++) {
if (box->border[i] == 0)
continue;
if (!html_redraw_border_plot(i, p,
@@ -1446,7 +1450,8 @@
bool html_redraw_text_decoration_inline(struct box *box, int x, int y,
float scale, colour colour, float ratio)
{
- for (struct box *c = box->next;
+ struct box *c;
+ for (c = box->next;
c && c != box->inline_end;
c = c->next) {
if (!plot.line((x + c->x) * scale,
@@ -1475,8 +1480,9 @@
bool html_redraw_text_decoration_block(struct box *box, int x, int y,
float scale, colour colour, float ratio)
{
+ struct box *c;
/* draw through text descendants */
- for (struct box *c = box->children; c; c = c->next) {
+ for (c = box->children; c; c = c->next) {
if (c->type == BOX_TEXT) {
if (!plot.line((x + c->x) * scale,
(y + c->y + c->height * ratio) * scale,
Index: render/layout.c
===================================================================
--- render/layout.c (révision 4724)
+++ render/layout.c (copie de travail)
@@ -848,11 +848,11 @@
box->gadget->type == GADGET_PASSWORD ||
box->gadget->type == GADGET_FILE ||
box->gadget->type == GADGET_TEXTAREA)) {
+ struct css_length size;
/* Give sensible dimensions to gadgets, with auto width/height,
* that don't shrink to fit contained text. */
assert(box->style);
- struct css_length size;
size.unit = CSS_UNIT_EM;
if (box->gadget->type == GADGET_TEXTBOX ||
box->gadget->type == GADGET_PASSWORD ||
Index: render/imagemap.c
===================================================================
--- render/imagemap.c (révision 4724)
+++ render/imagemap.c (copie de travail)
@@ -449,6 +449,8 @@
}
if (new_map->type != IMAGEMAP_DEFAULT) {
+ int x, y;
+ float *xcoords, *ycoords;
/* coordinates are a comma-separated list of values */
val = strtok(coords, ",");
num = 1;
@@ -518,8 +520,6 @@
xmlFree(coords);
return false;
}
- int x, y;
- float *xcoords, *ycoords;
while (val) {
x = atoi(val);
val = strtok('\0', ",");
Index: render/box_construct.c
===================================================================
--- render/box_construct.c (révision 4724)
+++ render/box_construct.c (copie de travail)
@@ -957,10 +957,11 @@
"maxlength"))) {
int maxlength = isdigit(s[0]) ? atoi(s): -1;
if (0 < maxlength && size == -1 && maxlength < 10) {
+ char *type;
/* Bump up really small widths */
maxlength = maxlength < 5 ? maxlength + 1 :
maxlength;
- char *type = (char *) xmlGetProp(n,
+ type = (char *) xmlGetProp(n,
(const xmlChar *) "type");
style->width.width = CSS_WIDTH_LENGTH;
if (!type || strcasecmp(type, "text") == 0 ||
@@ -1052,7 +1053,8 @@
int border_width = atoi(s);
/* precentage border width not implemented */
if (!strrchr(s, '%') && 0 < border_width) {
- for (unsigned int i = 0; i != 4; i++) {
+ unsigned int i;
+ for (i = 0; i != 4; i++) {
if (!author->border_color[i])
style->border[i].color =
border_color;
@@ -1077,7 +1079,8 @@
strcmp((const char *) n->name, "th") == 0) {
/* set any cellborders stipulated by associated table */
if (markup_track->cell_border) {
- for (unsigned int i = 0; i != 4; i++) {
+ unsigned int i;
+ for (i = 0; i != 4; i++) {
if (!author->border_color[i])
style->border[i].color = markup_track->
border_color;
@@ -1095,7 +1098,8 @@
}
/* set any cellpadding stipulated by associated table */
if (markup_track->cell_padding) {
- for (unsigned int i = 0; i != 4; i++) {
+ unsigned int i;
+ for (i = 0; i != 4; i++) {
if (!author->padding[i]) {
style->padding[i].padding =
CSS_PADDING_LENGTH;
@@ -1285,8 +1289,8 @@
}
if ((s = (char *) xmlGetProp(n,
(const xmlChar *) "border"))) {
+ int border_width = atoi(s);
markup_track->border_color = border_color;
- int border_width = atoi(s);
/* percentage border width not implemented */
if (!strrchr(s, '%') && 0 < border_width) {
markup_track->cell_border = true;
@@ -2977,7 +2981,12 @@
for (i = 0; i != n; i++) {
while (isspace(*s))
s++;
+#if defined(__HAIKU__) || defined(__BEOS__)
+#warning FIXME
+ length[i].value = (float)strtod(s, &end);
+#else
length[i].value = strtof(s, &end);
+#endif
if (length[i].value <= 0)
length[i].value = 1;
s = end;
Index: image/jpeg.c
===================================================================
--- image/jpeg.c (révision 4724)
+++ image/jpeg.c (copie de travail)
@@ -122,6 +122,7 @@
rowstride = bitmap_get_rowstride(bitmap);
do {
+ int i;
JSAMPROW scanlines[1];
scanlines[0] = (JSAMPROW) (pixels +
rowstride * cinfo.output_scanline);
@@ -129,7 +130,7 @@
#if RGB_RED != 0 || RGB_GREEN != 1 || RGB_BLUE != 2 || RGB_PIXELSIZE != 4
/* expand to RGBA */
- for (int i = width - 1; 0 <= i; i--) {
+ for (i = width - 1; 0 <= i; i--) {
int r = scanlines[0][i * RGB_PIXELSIZE + RGB_RED];
int g = scanlines[0][i * RGB_PIXELSIZE + RGB_GREEN];
int b = scanlines[0][i * RGB_PIXELSIZE + RGB_BLUE];
Index: css/ruleset.c
===================================================================
--- css/ruleset.c (révision 4724)
+++ css/ruleset.c (copie de travail)
@@ -681,6 +681,7 @@
colour named_colour(const char *name)
{
struct css_colour_entry *col;
+ int length;
col = bsearch(name, css_colour_table,
sizeof css_colour_table / sizeof css_colour_table[0],
@@ -693,7 +694,7 @@
* start of a colour specified in #rrggbb or #rgb format.
* This attempts to detect and recover from this.
*/
- int length = strlen(name);
+ length = strlen(name);
if ((length == 3) || (length == 6))
return hex_colour(name, length);
return CSS_COLOR_NONE;
Index: css/css.c
===================================================================
--- css/css.c (révision 4724)
+++ css/css.c (copie de travail)
@@ -2461,6 +2461,7 @@
* Set all members to false
*/
void css_importance_reset(struct css_importance *i) {
+ int j;
i->background_color = false;
i->background_image = false;
i->border_spacing = false;
@@ -2469,7 +2470,7 @@
i->width = false;
/**< top, right, bottom, left */
- for (int j = 0; j < 4; j++) {
+ for (j = 0; j < 4; j++) {
i->border_color[j] = false;
i->border_style[j] = false;
i->border_width[j] = false;
Index: css/css.h
===================================================================
--- css/css.h (révision 4724)
+++ css/css.h (copie de travail)
@@ -152,6 +152,15 @@
CSS_VERTICAL_ALIGN_NOT_SET
} css_vertical_align_type;
+typedef enum {
+ CSS_FONT_SIZE_INHERIT,
+ CSS_FONT_SIZE_ABSOLUTE,
+ CSS_FONT_SIZE_LENGTH,
+ CSS_FONT_SIZE_PERCENT,
+ CSS_FONT_SIZE_NOT_SET
+} css_font_size_type;
+
+
struct css_counter_control {
char *name;
int value;
@@ -255,11 +264,7 @@
/* font properties */
css_font_family font_family;
struct {
- enum { CSS_FONT_SIZE_INHERIT,
- CSS_FONT_SIZE_ABSOLUTE,
- CSS_FONT_SIZE_LENGTH,
- CSS_FONT_SIZE_PERCENT,
- CSS_FONT_SIZE_NOT_SET } size;
+ css_font_size_type size;
union {
struct css_length length;
float absolute;
Index: utils/utils.c
===================================================================
--- utils/utils.c (révision 4724)
+++ utils/utils.c (copie de travail)
@@ -172,8 +172,10 @@
static char buffer2[BYTESIZE_BUFFER_SIZE];
static char buffer3[BYTESIZE_BUFFER_SIZE];
static char *curbuffer = buffer3;
+ enum {bytes, kilobytes, megabytes, gigabytes} unit = bytes;
+ static char units[][7] = {"Bytes", "kBytes", "MBytes", "GBytes"};
- float bytesize = (float)bsize;
+ float bytesize = (float)bsize;
if (curbuffer == buffer1)
curbuffer = buffer2;
@@ -182,9 +184,6 @@
else
curbuffer = buffer1;
- enum {bytes, kilobytes, megabytes, gigabytes} unit = bytes;
- static char units[][7] = {"Bytes", "kBytes", "MBytes", "GBytes"};
-
if (bytesize > 1024) {
bytesize /= 1024;
unit = kilobytes;
Index: utils/utils.h
===================================================================
--- utils/utils.h (révision 4724)
+++ utils/utils.h (copie de travail)
@@ -39,6 +39,14 @@
#ifndef max
#define max(x,y) (((x)>(y))?(x):(y))
#endif
+#ifndef PRIxPTR
+#define PRIxPTR "x"
+#endif
+/*
+#if defined(__HAIKU__) || defined(__BEOS__)
+#define strtof(s,p) ((float)(strtod((s),(p)))
+#endif
+*/
/**
* Calculate length of constant C string.
Index: utils/config.h
===================================================================
--- utils/config.h (révision 4724)
+++ utils/config.h (copie de travail)
@@ -24,11 +24,12 @@
/* Try to detect which features the target OS supports */
#define HAVE_STRNDUP
-#if defined(__FreeBSD__) || (defined(__SRV4) && defined(__sun))
+#if defined(__FreeBSD__) || (defined(__SRV4) && defined(__sun)) || defined(__HAIKU__) || defined(__BEOS__)
/* FreeBSD and Solaris do not have this function, so
* we implement it ourselves in util.c
*/
#undef HAVE_STRNDUP
+#include <size_t.h>
char *strndup(const char *s, size_t n);
#endif
@@ -72,6 +73,17 @@
#define WITH_PRINT
/* Theme auto-install */
#define WITH_THEME_INSTALL
+#elif defined(__HAIKU__) || defined(__BEOS__)
+ /* for intptr_t */
+ #include <inttypes.h>
+ #if defined(__HAIKU__)
+ /*not yet: #define WITH_MMAP*/
+ #endif
+ //#define WITH_NS_SVG /* internal SVG renderer */
+ // XXX: temp
+ //#undef WITH_JPEG
+ //#undef WITH_MNG
+ //#define WITH_RSVG
#else
/* We're likely to have a working mmap() */
#define WITH_MMAP
Index: utils/talloc.c
===================================================================
--- utils/talloc.c (révision 4724)
+++ utils/talloc.c (copie de travail)
@@ -55,10 +55,12 @@
#include "replace.h"
#else
#include <stdarg.h>
+#ifndef __BEOS__
/* Assume we've got va_copy */
#define HAVE_VA_COPY
#include <string.h>
#endif
+#endif
#include "talloc.h"
#endif /* not _TALLOC_SAMBA3 */
Index: utils/filename.c
===================================================================
--- utils/filename.c (révision 4724)
+++ utils/filename.c (copie de travail)
@@ -433,7 +433,7 @@
TEMP_FILENAME_PREFIX);
last_1 = filename_directory + strlen(TEMP_FILENAME_PREFIX) + 1;
last_2 = new_dir->prefix;
- for (int i = 0; i < 3 && *last_2; i++) {
+ for (index = 0; index < 3 && *last_2; index++) {
*last_1++ = *last_2++;
while (*last_2 && *last_2 != '/')
*last_1++ = *last_2++;
Index: utils/utf8.c
===================================================================
--- utils/utf8.c (révision 4724)
+++ utils/utf8.c (copie de travail)
@@ -25,7 +25,9 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#ifndef __BEOS__
#define LIBICONV_PLUG
+#endif
#include <iconv.h>
#include "utils/log.h"
Index: desktop/textinput.c
===================================================================
--- desktop/textinput.c (révision 4724)
+++ desktop/textinput.c (copie de travail)
@@ -618,11 +618,12 @@
case KEY_WORD_LEFT:
{
+ bool start_of_word;
/* if there is a selection, caret should stay at beginning */
if (selection_exists)
break;
- bool start_of_word = (char_offset <= 0 ||
+ start_of_word = (char_offset <= 0 ||
isspace(text_box->text[char_offset - 1]));
while (!word_left(text_box->text, &char_offset, NULL)) {
@@ -652,13 +653,14 @@
case KEY_WORD_RIGHT:
{
+ bool in_word;
/* if there is a selection, caret should move to the end */
if (selection_exists) {
text_box = selection_get_end(bw->sel, &char_offset);
break;
}
- bool in_word = (char_offset < text_box->length &&
+ in_word = (char_offset < text_box->length &&
!isspace(text_box->text[char_offset]));
while (!word_right(text_box->text, text_box->length,
@@ -1818,13 +1820,13 @@
void delete_selection(struct selection *s)
{
- assert(s->defined);
size_t start_offset, end_offset;
struct box *text_box = selection_get_start(s, &start_offset);
struct box *end_box = selection_get_end(s, &end_offset);
struct box *next;
size_t sel_len = s->end_idx - s->start_idx;
int beginning = 0;
+ assert(s->defined);
/* Clear selection so that deletion from textboxes proceeds */
selection_clear(s, true);
Index: desktop/browser.c
===================================================================
--- desktop/browser.c (révision 4724)
+++ desktop/browser.c (copie de travail)
@@ -2248,13 +2248,14 @@
void browser_window_form_select(struct browser_window *bw,
struct form_control *control, int item)
{
+ struct box *inline_box;
struct form_option *o;
int count;
assert(bw);
assert(control);
- struct box *inline_box = control->box->children->children;
+ inline_box = control->box->children->children;
for (count = 0, o = control->data.select.items;
o != NULL;
Index: desktop/selection.c
===================================================================
--- desktop/selection.c (révision 4724)
+++ desktop/selection.c (copie de travail)
@@ -547,6 +547,8 @@
struct content *c;
save_text_whitespace before = WHITESPACE_NONE;
bool first = true;
+ const char *text;
+ size_t length;
if (!selection_defined(s))
return true; /* easy case, nothing to do */
@@ -559,8 +561,7 @@
c = s->bw->current_content;
if (!c) return true;
- size_t length;
- const char *text = textplain_get_raw_data(c, s->start_idx,
+ text = textplain_get_raw_data(c, s->start_idx,
s->end_idx, &length);
if (text && !handler(text, length, NULL, handle, NULL, 0))
Index: desktop/options.c
===================================================================
--- desktop/options.c (révision 4724)
+++ desktop/options.c (copie de travail)
@@ -44,6 +44,8 @@
#include "riscos/options.h"
#elif defined(nsgtk)
#include "gtk/options.h"
+#elif defined(nsbeos)
+#include "beos/options.h"
#else
#define EXTRA_OPTION_DEFINE
#define EXTRA_OPTION_TABLE
Index: content/fetchers/fetch_curl.c
===================================================================
--- content/fetchers/fetch_curl.c (révision 4724)
+++ content/fetchers/fetch_curl.c (copie de travail)
@@ -252,9 +252,9 @@
curl_fetchers_registered--;
LOG(("Finalise cURL fetcher %s", scheme));
if (curl_fetchers_registered == 0) {
+ CURLMcode codem;
/* All the fetchers have been finalised. */
LOG(("All cURL fetchers finalised, closing down cURL"));
- CURLMcode codem;
curl_easy_cleanup(fetch_blank_curl);
Index: content/urldb.c
===================================================================
--- content/urldb.c (révision 4724)
+++ content/urldb.c (copie de travail)
@@ -2340,6 +2340,7 @@
char *scheme;
time_t now;
url_func_result res;
+ int i;
assert(url);
@@ -2552,7 +2553,7 @@
ret_used = strlen(ret) + 1;
}
- for (int i = 0; i < count; i++) {
+ for (i = 0; i < count; i++) {
if (!urldb_concat_cookie(matched_cookies[i], version,
&ret_used, &ret_alloc, &ret)) {
free(path);
@@ -3490,6 +3491,7 @@
int version, domain_specified, path_specified,
secure, no_destroy, value_quoted;
time_t expires, last_used;
+ struct cookie_internal_data *c;
if(s[0] == 0 || s[0] == '#')
/* Skip blank lines or comments */
@@ -3548,8 +3550,7 @@
assert(p <= end);
/* Now create cookie */
- struct cookie_internal_data *c =
- malloc(sizeof(struct cookie_internal_data));
+ c = malloc(sizeof(struct cookie_internal_data));
if (!c)
break;
@@ -3602,11 +3603,12 @@
void urldb_delete_cookie_hosts(const char *domain, const char *path,
const char *name, struct host_part *parent)
{
+ struct host_part *h;
assert(parent);
urldb_delete_cookie_paths(domain, path, name, &parent->paths);
- for (struct host_part *h = parent->children; h; h = h->next)
+ for (h = parent->children; h; h = h->next)
urldb_delete_cookie_hosts(domain, path, name, h);
}
@@ -3614,6 +3616,7 @@
const char *name, struct path_data *parent)
{
struct cookie_internal_data *c;
+ struct path_data *p;
assert(parent);
@@ -3635,7 +3638,7 @@
}
}
- for (struct path_data *p = parent->children; p; p = p->next)
+ for (p = parent->children; p; p = p->next)
urldb_delete_cookie_paths(domain, path, name, p);
}
@@ -3684,11 +3687,12 @@
*/
void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent)
{
+ struct host_part *h;
assert(fp && parent);
urldb_save_cookie_paths(fp, &parent->paths);
- for (struct host_part *h = parent->children; h; h = h->next)
+ for (h = parent->children; h; h = h->next)
urldb_save_cookie_hosts(fp, h);
}
@@ -3700,12 +3704,14 @@
*/
void urldb_save_cookie_paths(FILE *fp, struct path_data *parent)
{
+ struct path_data *p;
time_t now = time(NULL);
assert(fp && parent);
if (parent->cookies) {
- for (struct cookie_internal_data *c = parent->cookies; c;
+ struct cookie_internal_data *c;
+ for (c = parent->cookies; c;
c = c->next) {
if (c->expires < now)
/* Skip expired cookies */
@@ -3726,7 +3732,7 @@
}
}
- for (struct path_data *p = parent->children; p; p = p->next)
+ for (p = parent->children; p; p = p->next)
urldb_save_cookie_paths(fp, p);
}
@@ -3737,9 +3743,10 @@
void urldb_destroy(void)
{
struct host_part *a, *b;
+ int i;
/* Clean up search trees */
- for (int i = 0; i < NUM_SEARCH_TREES; i++) {
+ for (i = 0; i < NUM_SEARCH_TREES; i++) {
if (search_trees[i] != &empty)
urldb_destroy_search_tree(search_trees[i]);
}
@@ -3809,11 +3816,12 @@
void urldb_destroy_path_node_content(struct path_data *node)
{
struct cookie_internal_data *a, *b;
+ unsigned int i;
free(node->url);
free(node->scheme);
free(node->segment);
- for (unsigned int i = 0; i < node->frag_cnt; i++)
+ for (i = 0; i < node->frag_cnt; i++)
free(node->fragment[i]);
free(node->fragment);
Index: content/fetch.c
===================================================================
--- content/fetch.c (révision 4724)
+++ content/fetch.c (copie de travail)
@@ -352,6 +352,8 @@
void fetch_dispatch_jobs(void)
{
int all_active, all_queued;
+ struct fetch *q;
+ struct fetch *f;
if (!queue_ring)
return; /* Nothing to do, the queue is empty */
@@ -362,7 +364,7 @@
LOG(("queue_ring %i, fetch_ring %i", all_queued, all_active));
#endif
- struct fetch *q = queue_ring;
+ q = queue_ring;
if (q) {
do {
#ifdef DEBUG_FETCH_VERBOSE
@@ -371,7 +373,7 @@
q = q->r_next;
} while (q != queue_ring);
}
- struct fetch *f = fetch_ring;
+ f = fetch_ring;
if (f) {
do {
#ifdef DEBUG_FETCH_VERBOSE
Index: content/fetchcache.c
===================================================================
--- content/fetchcache.c (révision 4724)
+++ content/fetchcache.c (copie de travail)
@@ -574,6 +574,7 @@
r = regexec(&re_content_type, s, 2 + MAX_ATTRS * 3, pmatch, 0);
if (r) {
+ char *semi;
LOG(("failed to parse content-type '%s'", s));
/* The mime type must be first, so only copy up to the
* first semicolon in the string. This allows us to have
@@ -581,7 +582,7 @@
* Content-Type headers. Obviously, any truly broken
* Content-Type headers will be unaffected by this heuristic
*/
- char *semi = strchr(s, ';');
+ semi = strchr(s, ';');
if (semi)
type = strndup(s, semi - s);
else
14 years, 6 months
Re: Roll-over in CSS
by John-Mark Bell
On Thu, 24 Jul 2008, Richard Ashbery wrote:
> I've been having a look at CSS - I am in the learning curve mode. I've
> tried a piece of test code that enables a user to "hover" over a link
> which forces a colour change and the text to grow larger. I can't see
> anything in the Help file...... CSS properties about the id selector
> declaration #menu li a:hover. I hope this is the correct terminology.
> Are your team intending to implement this useful Javascript "lookalike"
> facility?
Pseudo selectors are on the todo list, yes.
John.
14 years, 6 months
Re: regexec
by John-Mark Bell
On Mon, 21 Jul 2008, Chris Young wrote:
> On Mon, 21 Jul 2008 14:36:03 +0100, Michael Drake wrote:
>
>> There was some NetSurf/regexec() issue before:
>>
> http://vlists.pepperfish.net/pipermail/netsurf-dev-netsurf-browser.org/20...
>>
>> Not sure how that got fixed, but he did get it working, iirc.
>
> That does at least appear to be exactly the same crash, so I'd be very
> interested to find out how it was resolved.
I'm not sure I have any recollection of it being solved, tbh. None of us
have been able to reproduce it, so it's somewhat difficult to work out
what's happening. My best guess is that the regex implementation you're
using objects to the input we're giving it, which is odd, as the input is
perfectly valid extended POSIX regex. You may like to experiment to
discover if the regex implementation you're using actually supports
REG_EXTENDED properly, or if it's limited to basic POSIX regex.
[stack trace]
There's not much to go on there, I'm afraid.
J.
14 years, 6 months
What would you like to see done to NSGTK?
by Mike Lester
After I finish touching up the downloads dialog, I am unsure of what I
should spend the remaining GSoC time on. Which features or bugs are you most
interested in seeing implemented/fixed? Here are some of my own ideas:
- Text searching and a Find toolbar (my personal choice)
- Bookmarks (probably the most essential feature)
- Bookmarks toolbar
- Tabs
- Save/Export
- URL entry bar works as a search bar / bookmark lookup (you can read
more about this in my project
proposal<http://article.gmane.org/gmane.comp.web.netsurf.user/761/match=>
)
Would it be a good idea to send this to the users' list as well?
14 years, 6 months
GSoC Progress Report (July 23)
by Mike Lester
This past week and a half was spent finishing and polishing the downloads
dialog. It is very nearly done, just a bugs and features left (file
overwrite confirmation for the "Save" button, "save link/image as"
contextual right click button, downloads without a total size to not pulse
correctly if they are not the only active download). Some of this weeks
hurdles were implementing the total progress bar, which meant that I had to
rethink the way the downloads were updated and kept track of, and
implementing pulsing (where a progress block bounces back and forth in a
progress bar) for both the individual downloads and the total progress bar.
Overall I think downloads are in quite good condition, everything works
well, and there are no show stopping bugs and I've tried hard to keep the
code clean and understandable. One thing I am concerned about though is
performance, I'm not sure how nsgtk_download_update will hold up with many
downloads. If someone with a low-end machine could test the dialog with lots
of downloads updating at the same time and get back to me with some comments
it would be greatly appreciated.
~ Mike :D
14 years, 6 months
Re: regexec
by John-Mark Bell
On Sun, 20 Jul 2008, Rob Kendrick wrote:
[regex implementations]
> Under RISC OS, UnixLib uses Henry Spencer's implementation. It strikes
> me as unlikely that there's a bug in it after all these years and ports
> to fruity platforms via NetBSD, so I'd check your compiler and other
> environmental factors first.
Last I looked, UnixLib was using the regex implementation from PostgreSQL.
That's probably a heavily modified version of the original Henry Spencer
code. Either way, as Rob said, it's far more likely to be something other
than the regex library causing issues.
J.
14 years, 6 months
GSoC Report
by Adam Blokus
Hi,
This weeks goal was to finish gtk printing.
The first thing I have done was handling the 'Page Setup' dialog.
Now it is possible to choose the required rotation as well as different paper
sizes. It allows also managing custom sizes and margins.
I have fixed (almost) all bugs found in gtk printing during the last two weeks.
The background color was overflowing on the right side on some pages, this
was handled by normalization of the clipping and fill bounds. A wrong number
of pages was printed, it was necessary to pass the height of the content
as a parameter in the print functions. I am not sure about this, it
was the simplest
way to do that but it needed a change in the print interface so it's
not perfect.
After scaling over 1.0 the content on the page was clipped to a
smaller rectangle,
it turned out to be a bug in the print function affecting PDF printing, too.
The last bug was too high positioned text, which caused clipping the
words on the top.
This one was most difficult to find and unluckily wasted a lot of my
time. It turned out
to be a problem with the nsfont_paint function, which I have copied
from font_pango.c.
This version used pango/gdk as default (with not defined CAIRO_VERSION)
to render the text but for my needs I left only the Cairo part what
caused the bug to show
up (what didn't happen in the browser window for the mentioned
reason). The good side
is that I found a bug in the window plotting code this way.
I made the changes in both versions of the function.
The bug I didn't manage to fix is one I thought was connected with the
previous one.
After choosing the 'Landscape' rotation some/all? first letters in
each line disappear.
I will try to manage this one at the end of this week if I have some
time left or during the 4 week.
Despite the gtk stuff I have also done some code maintaince work. I
changed the code
according to jmb's review, solved the netsurf.glade clash and what is
most important
I merged from trunk to my branch.
During the next week I will stick to my timeline: adding UTF-8 support
to Haru and
the posibilty of changing print settings. Before I start with that I
will apply the changes
suggested by joty's review.
Let me know if you have any comments :)
14 years, 6 months
regexec
by Chris Young
Hi
Can I quickly ask which regex library is being used for NetSurf. I'm
compiling against a version of Henry Spencer's code but regexec() is
just crashing here. I'm having trouble finding any other free regexp
implementations I can replace it with. Any suggestions?
Thanks
Chris
14 years, 6 months