diff options
author | Dodji Seketeli <dodji at seketeli dot org> | 2003-07-05 21:09:27 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-07-05 21:09:27 +0000 |
commit | c7418f6eda2da5515257b8bcebf1b65178be1864 (patch) | |
tree | 8472293e52eb505d9154b436ca8766b132db470e | |
parent | d1846a58bffd77f4f0034d5ab5250b601abb7b0e (diff) | |
download | libcroco-c7418f6eda2da5515257b8bcebf1b65178be1864.tar.gz |
rearranged the enum CRNumProp values.
2003-07-05 Dodji Seketeli <dodji at seketeli dot org>
* src/seleng/cr-style.h: rearranged the enum CRNumProp values.
* src/seleng/cr-style.c: fixed the border-x:<a number> bug.
This now support also number and not only symbolic border width
like thin,thick etc ...
* src/parser/cr-num.c: documented the apis here.
* src/layeng/cr-lay-eng.c: Fixed some subtle bugs and finally implemented
the width:15% (set percentage to width).
Dodji.
-rw-r--r-- | ChangeLog | 22 | ||||
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | configure.in | 4 | ||||
-rw-r--r-- | src/layeng/cr-box-view.c | 6 | ||||
-rw-r--r-- | src/layeng/cr-box.h | 4 | ||||
-rw-r--r-- | src/layeng/cr-lay-eng.c | 196 | ||||
-rw-r--r-- | src/parser/cr-num.c | 32 | ||||
-rw-r--r-- | src/parser/cr-num.h | 10 | ||||
-rw-r--r-- | src/seleng/cr-style.c | 7 | ||||
-rw-r--r-- | src/seleng/cr-style.h | 16 | ||||
-rw-r--r-- | tests/test7-main.c | 6 |
11 files changed, 229 insertions, 82 deletions
@@ -1,3 +1,25 @@ +2003-07-05 Dodji Seketeli <dodji at seketeli dot org> + + * src/seleng/cr-style.h: rearranged the enum CRNumProp values. + + * src/seleng/cr-style.c: fixed the border-x:<a number> bug. + This now support also number and not only symbolic border width + like thin,thick etc ... + + * src/parser/cr-num.c: documented the apis here. + + * src/layeng/cr-lay-eng.c: Fixed some subtle bugs and finally implemented + the width:15% (set percentage to width). + +2003-07-01 Dodji Seketeli <dodji at seketeli dot org> + + * src/layeng/cr-lay-eng.c: put the + call to style_specified_2_computed_values() in the + layout_box() function. It was previously in the create_box_tree_real(). + + * src/layeng/cr-box-view.c: fixed a compiler warning. + * hmmh first commit after 0.2 release. + 2003-06-30 Dodji Seketeli <dodji at seketeli dot org> * tests/test-output-refs/test4.1.css.out: updated this @@ -1,6 +1,8 @@ *coding:) + + Well, in the cr_statement_xxx_parse_functions, memleaks occur (the parsing result set in the sac callback is not freed) when a parsing fails. This is because the unrecoverable error @@ -10,12 +12,14 @@ I have now to support 2 modes of parsing. Normal and standalone. In standalone mode, the standalone parsing functions must call the "unrecoverable_error" sac callback when they fail. -More debug of the test case for cr_statement_parse_from_buf (). +implements the width:20% case. (on going) + implement the size wrapping using the rightmost_x field of CRLayEngPriv. Provide support for font selection. (hard, started, is well underway.) First make sure to be able to gather all the font related property values. - Then, figure out how to implement a font selector that uses pango. + Then, figure out how to implement a font selector that uses + pango. (on going) Go forward in the cascading implementation in cr-sel-eng.c test/debug it. diff --git a/configure.in b/configure.in index 49c4dbe..2e4e585 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ AC_INIT(src/parser/cr-input.c) PACKAGE=libcroco LIBCROCO_MAJOR_VERSION=0 -LIBCROCO_MINOR_VERSION=2 +LIBCROCO_MINOR_VERSION=3 LIBCROCO_MICRO_VERSION=0 LIBCROCO_VERSION=$LIBCROCO_MAJOR_VERSION.$LIBCROCO_MINOR_VERSION.$LIBCROCO_MICRO_VERSION @@ -262,7 +262,7 @@ dnl*Dodji's environment. dnl************************ if test "x$LOGNAME" = "xdodji" -a "x$GCC" = "xyes" ; then - CFLAGS="$CFLAGS -g -Wunused -Wimplicit -Wreturn-type -Wswitch \ + CFLAGS="-g -Wunused -Wimplicit -Wreturn-type -Wswitch \ -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts \ -Wparentheses -Wpointer-arith -Wcast-align \ -Wwrite-strings -Waggregate-return -Wstrict-prototypes \ diff --git a/src/layeng/cr-box-view.c b/src/layeng/cr-box-view.c index 1f48153..2835cd4 100644 --- a/src/layeng/cr-box-view.c +++ b/src/layeng/cr-box-view.c @@ -169,13 +169,15 @@ set_border_line_attrs (CRBoxView *a_this, enum CRBorderStyleProp a_style_prop) { enum CRNumProp border_width_dir ; - GdkGCValues gc_values = {0} ; + GdkGCValues gc_values ; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_box && a_style_prop < NB_BORDER_STYLE_PROPS, CR_BAD_PARAM_ERROR) ; + memset (&gc_values, 0, sizeof (GdkGCValues)) ; + gdk_gc_get_values (PRIVATE (a_this)->gc, &gc_values) ; switch (a_style_prop) @@ -723,6 +725,8 @@ cr_box_view_layout (CRBoxView *a_this) cr_lay_eng_layout_box_tree (PRIVATE (a_this)->layeng, PRIVATE (a_this)->box_model->box.children) ; + cr_box_dump_to_file (PRIVATE (a_this)->box_model->box.children, + 0, stdout) ; return CR_OK ; } diff --git a/src/layeng/cr-box.h b/src/layeng/cr-box.h index 606b18d..d96fe42 100644 --- a/src/layeng/cr-box.h +++ b/src/layeng/cr-box.h @@ -82,7 +82,9 @@ typedef struct _CRBoxEdge CRBoxEdge ; */ struct _CRBoxEdge { - gulong x, y, width, max_width, height, x_offset, y_offset ; + gulong x, y, width, max_width, + height, x_offset, y_offset, + child_rmost_x ; } ; diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c index 5fb005f..ad82aec 100644 --- a/src/layeng/cr-lay-eng.c +++ b/src/layeng/cr-lay-eng.c @@ -49,6 +49,7 @@ struct _CRLayEngPriv GtkLayout *layout ; gulong xdpi ;/*x resolution*/ gulong ydpi ; /*y resolution*/ + gulong rightmost_x ; } ; @@ -81,8 +82,8 @@ static glong get_box_rightmost_x (CRBox *a_this) ; static enum CRStatus -compute_box_size (CRLayEng *a_this, - CRBox *a_cur_box) ; +compute_and_set_box_dimensions (CRLayEng *a_this, + CRBox *a_cur_box) ; static enum CRStatus layout_inline_box (CRLayEng *a_this, @@ -388,10 +389,8 @@ style_specified_2_computed_values (CRLayEng *a_this, &a_style->num_props[i].sv, DIR_VERTICAL) ; } - break ; - - case NUM_PROP_WIDTH: + case NUM_PROP_RIGHT: case NUM_PROP_LEFT: case NUM_PROP_PADDING_LEFT: @@ -416,7 +415,8 @@ style_specified_2_computed_values (CRLayEng *a_this, CR_BAD_PARAM_ERROR) ; a_style->num_props[i].cv.val = - parent_inner_edge->width * + a_style->parent_style-> + num_props[NUM_PROP_WIDTH].cv.val * a_style->num_props[i].sv.val / 100 ; } else @@ -428,6 +428,45 @@ style_specified_2_computed_values (CRLayEng *a_this, } break ; + case NUM_PROP_WIDTH: + if (a_style->num_props[i].sv.type == NUM_PERCENTAGE) + { + /* + *TODO: compute the computed value + *using the parent box size. + */ + if (a_parent_box) + { + parent_inner_edge = + &a_parent_box->inner_edge ; + } + + g_return_val_if_fail (parent_inner_edge, + CR_BAD_PARAM_ERROR) ; + + a_style->num_props[i].cv.val = + a_style->parent_style-> + num_props[NUM_PROP_WIDTH].cv.val * + a_style->num_props[i].sv.val / 100 ; + + a_style->num_props[i].cv.val -= + (a_style->num_props[NUM_PROP_MARGIN_LEFT].cv.val + +a_style->num_props[NUM_PROP_MARGIN_RIGHT].cv.val + +a_style->num_props[NUM_PROP_BORDER_LEFT].cv.val + +a_style->num_props[NUM_PROP_BORDER_RIGHT].cv.val + +a_style->num_props[NUM_PROP_PADDING_LEFT].cv.val + +a_style->num_props[NUM_PROP_PADDING_RIGHT].cv.val); + a_style->num_props[i].cv.type = + NUM_LENGTH_PX ; + } + else + { + normalize_num (a_this, + &a_style->num_props[i].cv, + &a_style->num_props[i].sv, + DIR_HORIZONTAL) ; + } + break ; default: normalize_num (a_this, &a_style->num_props[i].cv, @@ -563,8 +602,8 @@ create_box_tree_real (CRLayEng * a_this, *the positioning. The positioning will *be updated later via the cr_box_layout() method. */ - style_specified_2_computed_values - (a_this, style, a_parent_box) ; + /*style_specified_2_computed_values + (a_this, style, a_parent_box) ;*/ cur_box = cr_box_new (style, TRUE) ; if (!cur_box) @@ -673,8 +712,8 @@ create_box_tree_real (CRLayEng * a_this, */ init_anonymous_text_box (cur_box) ; - style_specified_2_computed_values - (a_this, cur_box->style, a_parent_box) ; + /*style_specified_2_computed_values + (a_this, cur_box->style, a_parent_box) ;*/ cr_box_append_child (a_parent_box, cur_box) ; @@ -811,7 +850,17 @@ compute_text_box_inner_edge_size (CRLayEng *a_this, /*gtk_widget_size_request (label, &requisition) ;*/ - a_box->inner_edge.width = logical_rect.width ; + if (cr_num_is_fixed_length + (&a_box->style->num_props[NUM_PROP_WIDTH].cv)) + { + a_box->inner_edge.width = + a_box->style->num_props[NUM_PROP_WIDTH].cv.val ; + } + else + { + a_box->inner_edge.width = logical_rect.width ; + } + a_box->inner_edge.height = logical_rect.height ; return status ; @@ -860,27 +909,11 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) FALSE) ; pgo_layout = gtk_label_get_layout (GTK_LABEL (label)) ; - /* - *set the wrap width if necessary. - */ - if (cr_num_is_fixed_length - (&a_text_box->style->num_props[NUM_PROP_WIDTH].cv) - == TRUE) - { - wrap_width = - a_text_box->style->num_props[NUM_PROP_WIDTH].cv.val; - } - else - { - wrap_width = a_text_box->parent->inner_edge.max_width - + a_text_box->parent->inner_edge.x - - a_text_box->inner_edge.x ; - } + wrap_width = a_text_box->inner_edge.max_width ; gtk_label_set_line_wrap (GTK_LABEL (label), TRUE) ; gtk_widget_set_size_request (label, wrap_width, -1) ; - /* *TODO: set the font description attributes. */ @@ -890,8 +923,7 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) g_return_val_if_fail (pgo_attr_list, CR_ERROR) ; status = cr_style_to_pango_font_attributes - (a_text_box->style, - pgo_attr_list, + (a_text_box->style, pgo_attr_list, strlen (a_text_box->content->u.text)) ; gtk_label_set_attributes (GTK_LABEL (label), pgo_attr_list) ; @@ -912,8 +944,8 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -compute_box_size (CRLayEng *a_this, - CRBox *a_cur_box) +compute_and_set_box_dimensions (CRLayEng *a_this, + CRBox *a_cur_box) { enum CRStatus status = CR_OK ; @@ -925,7 +957,9 @@ compute_box_size (CRLayEng *a_this, *left padding edges. *2/compute the left most x and topmost y of *the inner box. - *3/Compute the outer edge of the contained + *3/compute the max_width of the inner edge. + * + *4/Compute the outer edge of the contained *box; this is recursive. *******************************************/ @@ -968,21 +1002,33 @@ compute_box_size (CRLayEng *a_this, + a_cur_box->style->num_props[NUM_PROP_PADDING_LEFT].cv.val ; + /* + *Step 3/ + */ a_cur_box->inner_edge.max_width = - a_cur_box->outer_edge.max_width + - a_cur_box->outer_edge.x - - a_cur_box->inner_edge.x ; + (a_cur_box->parent->inner_edge.x + + a_cur_box->parent->inner_edge.max_width) - + a_cur_box->inner_edge.x - + (a_cur_box->style->num_props[NUM_PROP_MARGIN_RIGHT].cv.val + + a_cur_box->style->num_props[NUM_PROP_BORDER_RIGHT].cv.val + + a_cur_box->style->num_props[NUM_PROP_PADDING_RIGHT].cv.val) ; /* - *Step 3. + *Step 4. */ if (cr_num_is_fixed_length - (&a_cur_box->style->num_props[NUM_PROP_WIDTH].cv) - == TRUE) + (&a_cur_box->style->num_props[NUM_PROP_WIDTH].cv) == TRUE) { a_cur_box->inner_edge.width = a_cur_box->style->num_props[NUM_PROP_WIDTH].cv.val ; - a_cur_box->inner_edge.max_width = a_cur_box->inner_edge.width ; + + if (a_cur_box->inner_edge.max_width > + a_cur_box->style->num_props[NUM_PROP_WIDTH].cv.val) + { + a_cur_box->inner_edge.max_width = + a_cur_box->style-> + num_props[NUM_PROP_WIDTH].cv.val ; + } } if (a_cur_box->children) @@ -993,7 +1039,6 @@ compute_box_size (CRLayEng *a_this, */ status = layout_box (a_this, a_cur_box->children) ; g_return_val_if_fail (status == CR_OK, status) ; - } else { @@ -1008,6 +1053,17 @@ compute_box_size (CRLayEng *a_this, switch (a_cur_box->content->type) { case TEXT_CONTENT_TYPE: + if (a_cur_box->parent + && cr_num_is_fixed_length + (&a_cur_box->parent->style-> + num_props[NUM_PROP_WIDTH].cv)) + { + cr_num_copy + (&a_cur_box->style-> + num_props[NUM_PROP_WIDTH].cv, + &a_cur_box->parent->style-> + num_props[NUM_PROP_WIDTH].cv) ; + } layout_text_in_box (a_this, a_cur_box) ; compute_text_box_inner_edge_size (a_this, a_cur_box) ; @@ -1032,9 +1088,8 @@ compute_box_size (CRLayEng *a_this, break ; } } - } - - + } + /******************************************* *Inner edge position (x,y) and size computing is *finished. @@ -1063,6 +1118,14 @@ compute_box_size (CRLayEng *a_this, a_cur_box->style->num_props[NUM_PROP_MARGIN_TOP].cv.val + a_cur_box->style->num_props[NUM_PROP_MARGIN_BOTTOM].cv.val ; + if (a_cur_box->parent->inner_edge.child_rmost_x + < a_cur_box->outer_edge.x + a_cur_box->outer_edge.width) + { + a_cur_box->parent->inner_edge.child_rmost_x = + a_cur_box->outer_edge.x + + a_cur_box->outer_edge.width ; + } + return CR_OK ; } @@ -1070,16 +1133,25 @@ compute_box_size (CRLayEng *a_this, *Adjusts the size of the inner edge of this box's parent. *That is, increases (if needed) the parent inner edge's width/height. *@param a_this the current instance of #CRBox. + *@param a_cur_box the box to consider. */ static enum CRStatus adjust_parent_inner_edge_size (CRLayEng *a_this, CRBox *a_cur_box) -{ +{ g_return_val_if_fail (a_cur_box && a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR) ; - +/* + if (a_cur_box->parent + && a_cur_box->parent->style + && (cr_num_is_fixed_length + (&a_cur_box->parent->style->num_props[NUM_PROP_WIDTH].cv) == TRUE)) + { + return CR_OK ; + } +*/ if (PRIVATE (a_this)->update_parent_box_size == TRUE && a_cur_box->parent) { @@ -1165,7 +1237,7 @@ layout_block_box (CRLayEng *a_this, { a_cur_box->outer_edge.x = 0 ; a_cur_box->outer_edge.y = 0 ; - a_cur_box->inner_edge.width = 800 ; + a_cur_box->inner_edge.width = 800 ; a_cur_box->inner_edge.height = 600 ; a_cur_box->inner_edge.max_width = 800 ; } @@ -1180,7 +1252,7 @@ layout_block_box (CRLayEng *a_this, } else { - a_cur_box->outer_edge.y = + a_cur_box->outer_edge.y = cont_box->inner_edge.y ; } } @@ -1188,15 +1260,10 @@ layout_block_box (CRLayEng *a_this, g_return_val_if_fail (a_cur_box->parent->inner_edge.max_width + a_cur_box->parent->inner_edge.x > a_cur_box->outer_edge.x, - CR_ERROR) ; - - a_cur_box->outer_edge.max_width = - a_cur_box->parent->inner_edge.max_width - + a_cur_box->parent->inner_edge.x - - a_cur_box->outer_edge.x ; - - status = compute_box_size (a_this, - a_cur_box) ; + CR_ERROR) ; + + status = compute_and_set_box_dimensions (a_this, + a_cur_box) ; return status ; } @@ -1270,13 +1337,8 @@ layout_inline_box (CRLayEng *a_this, *box; this is recursive. *******************************************/ - a_cur_box->outer_edge.max_width = - a_cur_box->parent->inner_edge.max_width - + a_cur_box->parent->inner_edge.x - - a_cur_box->outer_edge.x ; - - status = compute_box_size (a_this, - a_cur_box) ; + status = compute_and_set_box_dimensions (a_this, + a_cur_box) ; return status ; } @@ -1363,9 +1425,12 @@ layout_box (CRLayEng *a_this, PRIVATE (a_this)->update_parent_box_size = TRUE ; - for (cur_box = a_cur_box ; cur_box ; + for (cur_box = a_cur_box ; cur_box ; cur_box = cur_box->next) { + style_specified_2_computed_values (a_this, cur_box->style, + cur_box->parent) ; + switch (cur_box->style->position) { case POSITION_STATIC: @@ -1382,6 +1447,7 @@ layout_box (CRLayEng *a_this, case POSITION_INHERIT: break ; } + /* *make sure the parent inner_edge is big enough to contain *the current box. diff --git a/src/parser/cr-num.c b/src/parser/cr-num.c index e982629..36c29b7 100644 --- a/src/parser/cr-num.c +++ b/src/parser/cr-num.c @@ -201,7 +201,15 @@ cr_num_to_string (CRNum *a_this) return result ; } - +/** + *Copies an instance of #CRNum. + *@param a_src the instance of #CRNum to copy. + *Must be non NULL. + *@param a_dst the destination of the copy. + *Must be non NULL + *@return CR_OK upon sucessfull completion, an + *error code otherwise. + */ enum CRStatus cr_num_copy (CRNum *a_dest, CRNum *a_src) { @@ -213,6 +221,13 @@ cr_num_copy (CRNum *a_dest, CRNum *a_src) return CR_OK ; } + +/** + *Duplicates an instance of #CRNum + *@param a_this the instance of #CRNum to duplicate. + *@return the newly created (duplicated) instance of #CRNum. + *Must be freed by cr_num_destroy(). + */ CRNum * cr_num_dup (CRNum *a_this) { @@ -230,6 +245,13 @@ cr_num_dup (CRNum *a_this) return result ; } +/** + *Sets an instance of #CRNum. + *@param a_this the current instance of #CRNum to be set. + *@param a_val the new numerical value to be hold by the current + *instance of #CRNum + *@param a_type the new type of #CRNum. + */ enum CRStatus cr_num_set (CRNum *a_this, gdouble a_val, enum CRNumType a_type) { @@ -241,6 +263,14 @@ cr_num_set (CRNum *a_this, gdouble a_val, enum CRNumType a_type) return CR_OK ; } +/** + *Tests if the current instance of #CRNum is a fixed + *length value or not. Typically a fixed length value + *is anything from NUM_LENTGTH_EM to NUM_LENGTH_PC. + *See the definition of #CRNumType to see what we mean. + *@return TRUE if the instance of #CRNum is a fixed length number, + *FALSE otherwise. + */ gboolean cr_num_is_fixed_length (CRNum *a_this) { diff --git a/src/parser/cr-num.h b/src/parser/cr-num.h index a84cd30..f50cfb2 100644 --- a/src/parser/cr-num.h +++ b/src/parser/cr-num.h @@ -40,6 +40,12 @@ G_BEGIN_DECLS /** + *@file + *The declaration of the #CRNum class. + * + */ + +/** *The different types *of numbers. *Please, do not modify @@ -71,6 +77,10 @@ enum CRNumType } ; +/** + *An abstraction of a number (num) + *as defined in the css2 spec. + */ typedef struct _CRNum CRNum ; /** diff --git a/src/seleng/cr-style.c b/src/seleng/cr-style.c index 5936c78..f47db8d 100644 --- a/src/seleng/cr-style.c +++ b/src/seleng/cr-style.c @@ -562,6 +562,13 @@ set_prop_border_x_width_from_value (CRStyle *a_style, } } } + else if (a_value->type == TERM_NUMBER) + { + if (a_value->content.num) + { + cr_num_copy (num_val, a_value->content.num) ; + } + } else if (a_value->type != TERM_NUMBER || a_value->content.num == NULL) { diff --git a/src/seleng/cr-style.h b/src/seleng/cr-style.h index 8070531..20c7d28 100644 --- a/src/seleng/cr-style.h +++ b/src/seleng/cr-style.h @@ -137,28 +137,28 @@ struct _CRRgbPropVal enum CRNumProp -{ - NUM_PROP_WIDTH = 0, - - NUM_PROP_TOP, +{ + NUM_PROP_TOP=0, NUM_PROP_RIGHT, NUM_PROP_BOTTOM, - NUM_PROP_LEFT, + NUM_PROP_LEFT,/*3*/ NUM_PROP_PADDING_TOP, NUM_PROP_PADDING_RIGHT, NUM_PROP_PADDING_BOTTOM, - NUM_PROP_PADDING_LEFT, + NUM_PROP_PADDING_LEFT,/*7*/ NUM_PROP_BORDER_TOP, NUM_PROP_BORDER_RIGHT, NUM_PROP_BORDER_BOTTOM, - NUM_PROP_BORDER_LEFT, + NUM_PROP_BORDER_LEFT,/*11*/ NUM_PROP_MARGIN_TOP, NUM_PROP_MARGIN_RIGHT, NUM_PROP_MARGIN_BOTTOM, - NUM_PROP_MARGIN_LEFT, + NUM_PROP_MARGIN_LEFT,/*15*/ + + NUM_PROP_WIDTH, /*must be last*/ NB_NUM_PROPS diff --git a/tests/test7-main.c b/tests/test7-main.c index 56dfc15..4ed3393 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -85,6 +85,7 @@ const char * gv_cssbuf= " " "item " "{ " +" width: 100%; " " display: block; " " padding:10px; " " margin-bottom:10px; " @@ -101,8 +102,9 @@ const char * gv_cssbuf= "channel>title, channel>description " "{ " " display: block; " -" margin-left:10px; " -" margin-top:10px; " +" width: 100%; " +" /*margin-left:10px;*/ " +" /*margin-top:10px;*/ " " background-color:#eee; " " font-weight:bold; " " font-size: 12px; " |