summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@src.gnome.org>2003-04-07 20:36:38 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-04-07 20:36:38 +0000
commitdca3db5e31dec3000f198514a596ce0fd13e48ed (patch)
tree8a5ed36e1e227b5dd1e47fdb4c5a6996c93251f5 /src
parent78e9ee7b8999c8e7472781be38cd8f364c3a6eaa (diff)
downloadlibcroco-dca3db5e31dec3000f198514a596ce0fd13e48ed.tar.gz
started to write a box model debuging code.
Dodji.
Diffstat (limited to 'src')
-rw-r--r--src/cr-box.c137
-rw-r--r--src/cr-box.h9
-rw-r--r--src/cr-lay-eng.c92
-rw-r--r--src/cr-style.c42
-rw-r--r--src/cr-style.h5
-rw-r--r--src/cr-utils.c13
-rw-r--r--src/cr-utils.h8
7 files changed, 292 insertions, 14 deletions
diff --git a/src/cr-box.c b/src/cr-box.c
index b057661..5ed3d3d 100644
--- a/src/cr-box.c
+++ b/src/cr-box.c
@@ -32,6 +32,10 @@
*The definition file of the #CRBox class.
*/
+static enum CRStatus
+cr_box_edge_to_string (CRBoxEdge *a_this,
+ gulong a_nb_indent,
+ GString **a_string) ;
static enum CRBoxType
cr_box_guess_type (CRStyle *a_style) ;
@@ -335,6 +339,53 @@ cr_box_layout (CRBox *a_this)
return CR_OK ;
}
+
+static enum CRStatus
+cr_box_edge_to_string (CRBoxEdge *a_this,
+ gulong a_nb_indent,
+ GString **a_string)
+{
+ GString *result = NULL ;
+
+ if (*a_string)
+ {
+ result = *a_string ;
+ }
+ else
+ {
+ result = g_string_new (NULL) ;
+ if (!result)
+ {
+ cr_utils_trace_info ("Out of memory") ;
+ return CR_ERROR ;
+ }
+ }
+
+ cr_utils_dump_n_chars2 (' ', result,
+ a_nb_indent) ;
+ g_string_append_printf (result, "(%ld, %ld)\n",
+ (long int)a_this->x,
+ (long int) a_this->y) ;
+ cr_utils_dump_n_chars2 (' ', result,
+ a_nb_indent) ;
+ g_string_append_printf (result, "width: %ld\n",
+ (long int)a_this->width) ;
+ cr_utils_dump_n_chars2 (' ',
+ result, a_nb_indent) ;
+ g_string_append_printf (result, "height: %ld\n",
+ (long int)a_this->height) ;
+ cr_utils_dump_n_chars2 (' ',
+ result, a_nb_indent) ;
+ g_string_printf (result, "x_offset: %ld\n",
+ (long int)a_this->x_offset) ;
+ cr_utils_dump_n_chars2 (' ', result,
+ a_nb_indent) ;
+ g_string_append_printf (result, "y_offset: %ld\n",
+ (long int)a_this->y_offset) ;
+
+ return CR_OK ;
+}
+
/*******************************
*Public methods
*******************************/
@@ -457,6 +508,7 @@ cr_box_new (CRStyle *a_style)
}
}
result->style = style ;
+ cr_style_ref (result->style) ;
result->type = cr_box_guess_type (result->style) ;
return result ;
@@ -530,12 +582,77 @@ cr_box_insert_sibling (CRBox *a_prev,
*Gives a string representation of the box tree.
*@return the build string of NULL in case of an error.
*/
-GString *
-cr_box_to_string (CRBox *a_this, gulong a_nb_indent)
+enum CRStatus
+cr_box_to_string (CRBox *a_this,
+ gulong a_nb_indent,
+ GString **a_string)
{
- g_return_val_if_fail (a_this, NULL) ;
+ GString *result = NULL ;
+
+ g_return_val_if_fail (a_this && a_string,
+ CR_BAD_PARAM_ERROR) ;
+
+ if (*a_string)
+ {
+ result = *a_string ;
+ }
+ else
+ {
+ result = g_string_new (NULL) ;
+ if (!result)
+ {
+ cr_utils_trace_info ("Out of memory") ;
+ return CR_ERROR ;
+ }
+ }
+
+ cr_utils_dump_n_chars2 (' ', result, a_nb_indent) ;
+
+ switch (a_this->type)
+ {
+ case BOX_TYPE_BLOCK:
+ g_string_printf (result, "BLOCK") ;
+ break ;
+
+ case BOX_TYPE_ANONYMOUS_BLOCK:
+ g_string_printf (result, "ANONYMOUS BLOCK") ;
+ break ;
+
+ case BOX_TYPE_INLINE:
+ g_string_printf (result, "INLINE") ;
+ break ;
+
+ case BOX_TYPE_ANONYMOUS_INLINE:
+ g_string_printf (result, "ANONYMOUS INLINE") ;
+ break ;
+
+ case BOX_TYPE_COMPACT:
+ g_string_printf (result, "COMPACT") ;
+ break ;
+
+ case BOX_TYPE_RUN_IN:
+ g_string_printf (result, "RUN IN") ;
+ break ;
+
+ default:
+ g_string_printf (result, "UNKNOWN") ;
+ break ;
+ }
+ g_string_printf (result, " box\n") ;
+ cr_utils_dump_n_chars2 (' ', result, a_nb_indent) ;
+ g_string_printf (result, "{") ;
- return NULL ;
+ cr_utils_dump_n_chars2 (' ', result, a_nb_indent) ;
+ g_string_printf (result, "*****%s*****\n", "outer_edge") ;
+ cr_box_edge_to_string (&a_this->outer_edge,
+ a_nb_indent, &result) ;
+
+
+ g_string_printf (result, "\n") ;
+ cr_utils_dump_n_chars2 (' ', result, a_nb_indent) ;
+ g_string_printf (result, "}") ;
+
+ return CR_OK ;
}
/**
@@ -550,6 +667,18 @@ cr_box_destroy (CRBox *a_this)
{
g_return_if_fail (a_this) ;
+ if (a_this->content)
+ {
+ cr_box_content_destroy (a_this->content) ;
+ a_this->content = NULL ;
+ }
+
+ if (a_this->style)
+ {
+ cr_style_unref (a_this->style) ;
+ a_this->style = NULL ;
+ }
+
if (a_this->children)
{
CRBox *cur = NULL;
diff --git a/src/cr-box.h b/src/cr-box.h
index 96ddd35..0d5ca0f 100644
--- a/src/cr-box.h
+++ b/src/cr-box.h
@@ -149,7 +149,6 @@ struct _CRBox
*a surrounding area called "border".
*If the border is inexistant, the
*border edge equals the padding edge.
- *
*/
CRBoxEdge border_edge ;
@@ -172,7 +171,7 @@ struct _CRBox
*The content (text or image) of this
*box
*/
- CRBoxContent content ;
+ CRBoxContent *content ;
/**
*if TRUE, it means that this box has
@@ -225,8 +224,10 @@ cr_box_insert_sibling (CRBox *a_prev,
CRBox *a_next,
CRBox *a_to_insert) ;
-GString *
-cr_box_to_string (CRBox *a_this, gulong a_nb_indent) ;
+enum CRStatus
+cr_box_to_string (CRBox *a_this,
+ gulong a_nb_indent,
+ GString **a_string) ;
enum CRStatus
cr_box_append_child (CRBox *a_this, CRBox *a_to_append) ;
diff --git a/src/cr-lay-eng.c b/src/cr-lay-eng.c
index 88a629f..aa4b1dc 100644
--- a/src/cr-lay-eng.c
+++ b/src/cr-lay-eng.c
@@ -54,6 +54,58 @@ cr_lay_eng_create_box_tree_real (CRLayEng * a_this,
*Private methods.
**********************/
+/**
+ *Sets the box style values so that
+ *it has no padding, no border, no margin.
+ *The other style values are left as is cause
+ *they must have been set prior to calling this
+ *function.
+ */
+static void
+init_anonymous_text_box (CRBox *a_box)
+{
+ g_return_if_fail (a_box && a_box->style) ;
+
+ cr_num_set (&a_box->style->padding_top, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->padding_right, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->padding_bottom, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->padding_left, 0, NUM_LENGTH_PX) ;
+
+ cr_num_set (&a_box->style->border_top_width, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->border_right_width, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->border_bottom_width, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->border_left_width, 0, NUM_LENGTH_PX) ;
+
+ cr_num_set (&a_box->style->margin_top, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->margin_right, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->margin_bottom, 0, NUM_LENGTH_PX) ;
+ cr_num_set (&a_box->style->margin_left, 0, NUM_LENGTH_PX) ;
+
+ a_box->style->border_top_style = BORDER_STYLE_NONE ;
+ a_box->style->border_right_style = BORDER_STYLE_NONE ;
+ a_box->style->border_bottom_style = BORDER_STYLE_NONE ;
+ a_box->style->border_left_style = BORDER_STYLE_NONE ;
+
+ cr_num_set (&a_box->style->top.num, 0, NUM_LENGTH_PX) ;
+ a_box->style->top.type = OFFSET_DEFINED ;
+ cr_num_set (&a_box->style->right.num, 0, NUM_LENGTH_PX) ;
+ a_box->style->right.type = OFFSET_DEFINED ;
+ cr_num_set (&a_box->style->bottom.num, 0, NUM_LENGTH_PX) ;
+ a_box->style->bottom.type = OFFSET_DEFINED ;
+ cr_num_set (&a_box->style->left.num, 0, NUM_LENGTH_PX) ;
+ a_box->style->left.type = OFFSET_DEFINED ;
+
+ a_box->style->float_type = FLOAT_NONE ;
+}
+
+/**
+ *Creates a box sub tree from an xml node tree.
+ *@param a_this the current instance of #CRLayEng.
+ *@param a_root_node the root node of the xml tree.
+ *@param a_parent_box the root of the box tree to build.
+ *@return the newly built box tree, or NULL if an error
+ *happens.
+ */
static CRBox *
cr_lay_eng_create_box_tree_real (CRLayEng * a_this,
xmlNode *a_root_node,
@@ -167,7 +219,31 @@ cr_lay_eng_create_box_tree_real (CRLayEng * a_this,
}
if (box_content)
{
- /*create here an anonymous box*/
+ /*
+ *create here an anonymous box
+ *which style inherits the style
+ *of the parent box.
+ */
+ cur_box = cr_box_new (parent_style) ;
+ if (!cur_box)
+ {
+ cr_utils_trace_info
+ ("could not create "
+ "anonymous box") ;
+ goto error ;
+ }
+ cur_box->content = box_content ;
+ box_content = NULL ;
+ /*
+ *the anonymous box
+ *must have no margin,
+ *no padding, no border,
+ *no border style, no offset
+ */
+ init_anonymous_text_box (cur_box) ;
+ cr_box_append_child (a_parent_box,
+ cur_box) ;
+ cur_box = NULL ;
}
}
else
@@ -234,7 +310,15 @@ cr_lay_eng_new (void)
return result ;
}
-
+/**
+ *Creates the box model from an xml document.
+ *@param a_this the current instance of #CRLayEng.
+ *@param a_doc the current xml document.
+ *@param a_cascade the css2 stylesheet cascade.
+ *@param a_box_model out parameter. The returned
+ *@return CR_OK upon successfull completion, an error code
+ *otherwise.
+ */
enum CRStatus
cr_lay_eng_build_box_tree (CRLayEng *a_this,
xmlDoc *a_doc,
@@ -260,6 +344,10 @@ cr_lay_eng_build_box_tree (CRLayEng *a_this,
}
+/**
+ *Destuctor of #CRLayEng.
+ *@param a_this the current instance of #CRLayEng.
+ */
void
cr_lay_eng_destroy (CRLayEng *a_this)
{
diff --git a/src/cr-style.c b/src/cr-style.c
index ae21976..a9404ba 100644
--- a/src/cr-style.c
+++ b/src/cr-style.c
@@ -1265,9 +1265,15 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl,
}
return status ;
-
}
+/**
+ *Increases the reference count
+ *of the current instance of #CRStyle.
+ *@param a_this the current instance of #CRStyle.
+ *@return CR_OK upon successfull completion, an error code
+ *otherwise.
+ */
enum CRStatus
cr_style_ref (CRStyle *a_this)
{
@@ -1277,6 +1283,16 @@ cr_style_ref (CRStyle *a_this)
return CR_OK ;
}
+
+/**
+ *Decreases the reference count of
+ *the current instance of #CRStyle.
+ *If the reference count reaches 0, the
+ *instance of #CRStyle is destoyed.
+ *@param a_this the current instance of #CRStyle.
+ *@return TRUE if the instance has been destroyed, FALSE
+ *otherwise.
+ */
gboolean
cr_style_unref (CRStyle *a_this)
{
@@ -1295,6 +1311,30 @@ cr_style_unref (CRStyle *a_this)
return FALSE ;
}
+/**
+ *Duplicates the current instance of #CRStyle .
+ *The newly created instance of #CRStyle must be
+ *freed using cr_style_destroy ().
+ *@param a_this the current instance of #CRStyle.
+ *@return the newly duplicated instance of #CRStyle.
+ */
+CRStyle *
+cr_style_dup (CRStyle *a_this)
+{
+ CRStyle *result = NULL ;
+
+ g_return_val_if_fail (a_this, NULL) ;
+
+ result = cr_style_new () ;
+ if (!result)
+ {
+ cr_utils_trace_info ("Out of memory") ;
+ return NULL ;
+ }
+ memcpy (result, a_this, sizeof (CRStyle)) ;
+
+ return result ;
+}
/**
*Destructor of the #CRStyle class.
diff --git a/src/cr-style.h b/src/cr-style.h
index 8459e3c..004a232 100644
--- a/src/cr-style.h
+++ b/src/cr-style.h
@@ -130,14 +130,12 @@ struct _CRStyle
{
/**padding properties, in pixel*/
-
CRNum padding_top ;
CRNum padding_right ;
CRNum padding_bottom ;
CRNum padding_left ;
/**border properties*/
-
CRNum border_top_width ;
CRNum border_right_width ;
CRNum border_bottom_width ;
@@ -206,6 +204,9 @@ cr_style_unref (CRStyle *a_this) ;
void
cr_style_destroy (CRStyle *a_this) ;
+CRStyle *
+cr_style_dup (CRStyle *a_this) ;
+
G_END_DECLS
#endif /*__CR_STYLE_H__*/
diff --git a/src/cr-utils.c b/src/cr-utils.c
index c3d5504..f7c2aef 100644
--- a/src/cr-utils.c
+++ b/src/cr-utils.c
@@ -1420,6 +1420,19 @@ cr_utils_dump_n_chars (guchar a_char, FILE *a_fp, glong a_nb)
}
}
+void
+cr_utils_dump_n_chars2 (guchar a_char,
+ GString *a_string,
+ glong a_nb)
+{
+ glong i = 0 ;
+
+ for (i = 0 ; i < a_nb ; i++)
+ {
+ g_string_printf (a_string, "%c", a_char) ;
+ }
+}
+
gdouble
cr_utils_n_to_0_dot_n (glong a_n)
{
diff --git a/src/cr-utils.h b/src/cr-utils.h
index bf22a73..275678e 100644
--- a/src/cr-utils.h
+++ b/src/cr-utils.h
@@ -206,8 +206,14 @@ gboolean
cr_utils_is_hexa_char (guint32 a_char) ;
void
-cr_utils_dump_n_chars (guchar a_char, FILE *a_fp, glong a_nb) ;
+cr_utils_dump_n_chars (guchar a_char,
+ FILE *a_fp,
+ glong a_nb) ;
+void
+cr_utils_dump_n_chars2 (guchar a_char,
+ GString *a_string,
+ glong a_nb) ;
gdouble
cr_utils_n_to_0_dot_n (glong a_n) ;