diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/layeng/cr-lay-eng.c | 15 | ||||
-rw-r--r-- | src/seleng/cr-style.c | 201 | ||||
-rw-r--r-- | src/seleng/cr-style.h | 3 | ||||
-rw-r--r-- | tests/test7-main.c | 2 |
5 files changed, 186 insertions, 42 deletions
@@ -1,3 +1,10 @@ +2003-06-14 dodji <dodji@seketeli.org> + + * src/layeng/cr-lay-eng.c, src/seleng/cr-style.[hc]: + more fonts selection implementation. + + * tests/test7-main.c: updated this to test the font selection implem. + 2003-06-12 dodji <dodji@seketeli.org> * src/seleng/Makefile.am: added pango stuffs. diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c index eaeeb6c..2338806 100644 --- a/src/layeng/cr-lay-eng.c +++ b/src/layeng/cr-lay-eng.c @@ -771,7 +771,6 @@ compute_text_box_inner_edge_size (CRLayEng *a_this, GtkWidget *label = NULL ; PangoLayout *pgo_layout = NULL ; PangoRectangle ink_rect = {0}, logical_rect = {0} ; - GtkRequisition requisition ; g_return_val_if_fail (a_this && a_box @@ -822,12 +821,10 @@ compute_text_box_inner_edge_size (CRLayEng *a_this, static enum CRStatus layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) { + enum CRStatus status = CR_OK ; GtkWidget *label = NULL ; PangoLayout * pgo_layout = NULL ; PangoAttrList *pgo_attr_list = NULL ; - PangoAttribute *pgo_attr = NULL ; - PangoFontDescription *pgo_font_desc = NULL ; - PangoRectangle ink_rect, logical_rect ; glong wrap_width = 0 ; g_return_val_if_fail (a_this && a_text_box @@ -854,7 +851,7 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) g_return_val_if_fail (GTK_IS_LABEL (label), CR_ERROR) ; gtk_label_set_text (GTK_LABEL (label), - a_text_box->content->u.text) ; + a_text_box->content->u.text) ; gtk_misc_set_alignment (GTK_MISC (label),0, 0) ; gtk_misc_set_padding (GTK_MISC (label), 0, 0) ; gtk_label_set_use_markup (GTK_LABEL (label), @@ -892,8 +889,14 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) pango_attr_list_new () ; g_return_val_if_fail (pgo_attr_list, CR_ERROR) ; + status = cr_style_to_pango_font_attributes + (a_text_box->style, + pgo_attr_list, + strlen (a_text_box->content->u.text)) ; - return CR_OK ; + gtk_label_set_attributes (label, pgo_attr_list) ; + + return status ; } /** diff --git a/src/seleng/cr-style.c b/src/seleng/cr-style.c index 1f4d54e..5936c78 100644 --- a/src/seleng/cr-style.c +++ b/src/seleng/cr-style.c @@ -2181,14 +2181,18 @@ cr_style_dup (CRStyle *a_this) enum CRStatus cr_style_to_pango_font_attributes (CRStyle *a_style, - PangoAttrList *a_pgo_attrs) + PangoAttrList *a_pgo_attrs, + gulong a_text_len) { + enum CRStatus status = CR_OK ; + PangoAttribute * pgo_attr = NULL ; PangoFontDescription *pgo_font_desc = NULL ; + PangoStyle pgo_style = PANGO_STYLE_NORMAL ; guchar *font_family = NULL ; + PangoWeight pgo_weight = PANGO_WEIGHT_NORMAL ; g_return_val_if_fail (a_pgo_attrs - && a_style - && a_style->font_size, + && a_style, CR_BAD_PARAM_ERROR) ; pgo_font_desc = pango_font_description_new () ; @@ -2199,53 +2203,182 @@ cr_style_to_pango_font_attributes (CRStyle *a_style, return CR_ERROR ; } - + if (a_style->font_size) /*set font size*/ - switch (a_style->font_size->type) + switch (a_style->font_size->type) + { + case PREDEFINED_ABSOLUTE_FONT_SIZE: + if ( !(a_style->font_size->value.predefined + < NB_PREDEFINED_ABSOLUTE_FONT_SIZES)) + { + status = CR_OUT_OF_BOUNDS_ERROR ; + goto cleanup ; + } + pango_font_description_set_size + (pgo_font_desc, + gv_predefined_abs_font_size_tab + [a_style->font_size->value.predefined] + * PANGO_SCALE) ; + break ; + + case ABSOLUTE_FONT_SIZE: + if (!a_style->font_size->value.absolute) + { + status = CR_BAD_PARAM_ERROR ; + goto cleanup ; + } + pango_font_description_set_size + (pgo_font_desc, + a_style->font_size->value.absolute->val + * PANGO_SCALE) ; + break ; + + case RELATIVE_FONT_SIZE: + cr_utils_trace_info ("relative font size are not supported " + "yes") ; + + break ; + + case INHERITED_FONT_SIZE: + cr_utils_trace_info ("inherited font size are not supported " + "yes") ; + break ; + } + + + /*set font family*/ + if (a_style->font_family) + font_family = cr_font_family_to_string (a_style->font_family, + TRUE) ; + if (font_family) { - case PREDEFINED_ABSOLUTE_FONT_SIZE: - g_return_val_if_fail (a_style->font_size->value.predefined - < NB_PREDEFINED_ABSOLUTE_FONT_SIZES, - CR_OUT_OF_BOUNDS_ERROR) ; - - pango_font_description_set_size - (pgo_font_desc, - gv_predefined_abs_font_size_tab - [a_style->font_size->value.predefined]) ; + pango_font_description_set_family (pgo_font_desc, + font_family) ; + } + + /*set style*/ + switch (a_style->font_style) + { + case FONT_STYLE_NORMAL: + pgo_style = PANGO_STYLE_NORMAL ; break ; - case ABSOLUTE_FONT_SIZE: - g_return_val_if_fail (a_style->font_size->value.absolute, - CR_BAD_PARAM_ERROR) ; - - pango_font_description_set_size - (pgo_font_desc, - a_style->font_size->value.absolute->val) ; + case FONT_STYLE_ITALIC: + pgo_style = PANGO_STYLE_ITALIC ; break ; - case RELATIVE_FONT_SIZE: - cr_utils_trace_info ("relative font size are not supported " - "yes") ; + case FONT_STYLE_OBLIQUE: + pgo_style = PANGO_STYLE_OBLIQUE ; + break ; + case FONT_STYLE_INHERIT: + cr_utils_trace_info ("font-style: inherit not supported yet") ; break ; - case INHERITED_FONT_SIZE: - cr_utils_trace_info ("inherited font size are not supported " - "yes") ; + default: + cr_utils_trace_info ("unknown font-sytle property value") ; break ; } + pango_font_description_set_style (pgo_font_desc, + pgo_style) ; - /*set font family*/ - font_family = cr_font_family_to_string (a_style->font_family, - TRUE) ; - if (font_family) + /*set font weight*/ + switch (a_style->font_weight) { - pango_font_description_set_family (pgo_font_desc, - font_family) ; + case FONT_WEIGHT_NORMAL: + pgo_weight = PANGO_WEIGHT_NORMAL ; + break ; + + case FONT_WEIGHT_BOLD: + pgo_weight = PANGO_WEIGHT_BOLD; + break ; + + case FONT_WEIGHT_BOLDER: + cr_utils_trace_info + ("font-weight: bolder is not supported yet"); + break ; + + case FONT_WEIGHT_LIGHTER: + cr_utils_trace_info + ("font-weight: lighter is not supported yet"); + break ; + + case FONT_WEIGHT_100: + pgo_weight = 100 ; + break ; + + case FONT_WEIGHT_200: + pgo_weight = 200; + break ; + + case FONT_WEIGHT_300: + pgo_weight = 300 ; + break ; + + case FONT_WEIGHT_400: + pgo_weight = 400 ; + break ; + + case FONT_WEIGHT_500: + pgo_weight = 500 ; + break ; + + case FONT_WEIGHT_600: + pgo_weight = 600 ; + break ; + + case FONT_WEIGHT_700: + pgo_weight = 700 ; + break ; + + case FONT_WEIGHT_800: + pgo_weight = 800 ; + break ; + + case FONT_WEIGHT_900: + pgo_weight = 900 ; + break ; + + case FONT_WEIGHT_INHERIT: + cr_utils_trace_info + ("font-weight: inherit is not supported yet.") ; + break ; + + default: + cr_utils_trace_info ("unknown property value") ; + break ; + } + + pango_font_description_set_weight (pgo_font_desc, + pgo_weight) ; + + pgo_attr = pango_attr_font_desc_new (pgo_font_desc) ; + if (!pgo_attr) + { + status = CR_INSTANCIATION_FAILED_ERROR ; + goto cleanup ; } + pgo_attr->start_index = 0 ; + pgo_attr->end_index = a_text_len ; + pango_attr_list_change (a_pgo_attrs, pgo_attr) ; + pgo_attr = NULL ; - return CR_OK ; + + cleanup: + + if (pgo_attr) + { + pango_attribute_destroy (pgo_attr) ; + pgo_attr = NULL ; + } + if (pgo_font_desc) + { + pango_font_description_free (pgo_font_desc) ; + pgo_font_desc = NULL ; + } + + return status ; } /** diff --git a/src/seleng/cr-style.h b/src/seleng/cr-style.h index 322bf15..8070531 100644 --- a/src/seleng/cr-style.h +++ b/src/seleng/cr-style.h @@ -269,7 +269,8 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) ; enum CRStatus cr_style_to_pango_font_attributes (CRStyle *a_style, - PangoAttrList *a_pgo_attrs) ; + PangoAttrList *a_pgo_attrs, + gulong text_len) ; enum CRStatus cr_style_ref (CRStyle *a_this) ; diff --git a/tests/test7-main.c b/tests/test7-main.c index ddc26a2..56dfc15 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -79,7 +79,6 @@ const char * gv_cssbuf= " overflow:auto; " " background-color:#eee; " " /*font: 12px verdana;*/ " -" font-zise: 12px; " " font-style: font-family ; " " font-style: normal; " "} " @@ -106,6 +105,7 @@ const char * gv_cssbuf= " margin-top:10px; " " background-color:#eee; " " font-weight:bold; " +" font-size: 12px; " "} " " " "channel>title " |