diff options
author | dodji <dodji@seketeli.org> | 2003-06-12 22:07:50 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2003-06-12 22:07:50 +0000 |
commit | b85770d0ee4bdfa59c025216637c9c22773ae314 (patch) | |
tree | ae601ad556fe4dc5f5ccb48590ab92ac46f0deb3 | |
parent | 400f3b108f7e00c1a3189fed728581df8ed8dce7 (diff) | |
download | libcroco-b85770d0ee4bdfa59c025216637c9c22773ae314.tar.gz |
added pango stuffs. added pango detection. a bit more font selection. a
2003-06-12 dodji <dodji@seketeli.org>
* src/seleng/Makefile.am: added pango stuffs.
* configure.in: added pango detection.
* src/seleng/cr-fonts.c: a bit more font selection.
* src/layeng/cr-lay-eng.c: a bit more font selection.
* src/seleng/cr-style.c: font selection code again.
Dodji.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | configure.in | 32 | ||||
-rw-r--r-- | src/layeng/cr-lay-eng.c | 6 | ||||
-rw-r--r-- | src/parser/cr-enc-handler.c | 4 | ||||
-rw-r--r-- | src/parser/cr-utils.h | 2 | ||||
-rw-r--r-- | src/seleng/Makefile.am | 2 | ||||
-rw-r--r-- | src/seleng/cr-fonts.c | 106 | ||||
-rw-r--r-- | src/seleng/cr-fonts.h | 10 | ||||
-rw-r--r-- | src/seleng/cr-style.c | 100 | ||||
-rw-r--r-- | src/seleng/cr-style.h | 4 | ||||
-rw-r--r-- | tests/test7-main.c | 5 |
11 files changed, 261 insertions, 18 deletions
@@ -1,3 +1,11 @@ +2003-06-12 dodji <dodji@seketeli.org> + + * src/seleng/Makefile.am: added pango stuffs. + * configure.in: added pango detection. + * src/seleng/cr-fonts.c: a bit more font selection. + * src/layeng/cr-lay-eng.c: a bit more font selection. + * src/seleng/cr-style.c: font selection code again. + 2003-06-09 Dodji <dodji@seketeli.org> * tests/test4-main.c: updated this test to test the new cr_declaration_to_string () api. diff --git a/configure.in b/configure.in index d8d2a1c..add331d 100644 --- a/configure.in +++ b/configure.in @@ -34,6 +34,7 @@ dnl GLIB2_VERSION=2.0 LIBXML2_VERSION=2.4.23 LIBGNOMEUI_VERSION=2.0.3 +PANGO_VERSION=1.0.4 dnl Checks for programs. AC_PROG_CC @@ -101,6 +102,22 @@ AC_SUBST(CROCO_HAVE_LIBXML2) CROCO_PARSER_LIB=libcroco.la AC_SUBST(CROCO_PARSER_LIB) +dnl +dnl check glib-2.0 version +dnl +have_pango=no +PKG_CHECK_MODULES(PANGO, + [pango >= $PANGO_VERSION], + [have_pango=yes + CROCO_HAVE_PANGO=1], + have_pango=no) +if test "$have_pango" = no ; then + AC_MSG_ERROR([*** pango not found. See http://www.pango.org]) +fi + +AC_SUBST(PANGO_VERSION) +AC_SUBST(CROCO_HAVE_PANGO) + dnl --enable-tests dnl this option enables compilation of the unit tests built in to .c files dnl and also some stuff in the test/ subdir @@ -131,12 +148,23 @@ AC_ARG_ENABLE(seleng, WITH_SELENG="no") if test "$WITH_SELENG" = "auto" ; then - if test "$have_libxml2" != no; then - CROCO_SELENG_ENABLED=1 + if test "x$have_libxml2" != "xno" -a "x$have_pango" != "xno" ; then + CROCO_SELENG_ENABLED=1 WITH_SELENG="yes" else WITH_SELENG="no" fi + + if test "x$WITH_SELENG" = "yes" ; then + if test "x$have_libxml2" != "yes" ; then + AC_MSG_ERROR([*** libxml2 is not present, so you cannot have seleng enabled. Go to http://xmlsoft.org to get libxml2 version $LIBXML2_VERSION ***]) + fi + + if test "x$have_pango" != "yes" ; then + AC_MSG_ERROR([*** pango is not present, so you cannot have seleng enabled. Go to http://www.pango.org to get pango version $PANGO_VERSION ***]) + fi + fi + elif test "$WITH_SELENG" = "yes" ; then CROCO_SELENG_ENABLED=1 else diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c index e6a1bb4..eaeeb6c 100644 --- a/src/layeng/cr-lay-eng.c +++ b/src/layeng/cr-lay-eng.c @@ -818,6 +818,7 @@ compute_text_box_inner_edge_size (CRLayEng *a_this, return status ; } + static enum CRStatus layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) { @@ -886,6 +887,11 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) /* *TODO: set the font description attributes. */ + + pgo_attr_list = + pango_attr_list_new () ; + g_return_val_if_fail (pgo_attr_list, CR_ERROR) ; + return CR_OK ; } diff --git a/src/parser/cr-enc-handler.c b/src/parser/cr-enc-handler.c index 14c8f83..85ad1c5 100644 --- a/src/parser/cr-enc-handler.c +++ b/src/parser/cr-enc-handler.c @@ -168,8 +168,8 @@ cr_enc_handler_convert_input (CREncHandler *a_this, { status = a_this->enc_str_len_as_utf8 (a_in, - &a_in[*a_in_len -1], - a_out_len) ; + &a_in[*a_in_len -1], + a_out_len) ; g_return_val_if_fail (status == CR_OK, status) ; } diff --git a/src/parser/cr-utils.h b/src/parser/cr-utils.h index 4627a31..d43dffc 100644 --- a/src/parser/cr-utils.h +++ b/src/parser/cr-utils.h @@ -43,7 +43,7 @@ G_BEGIN_DECLS enum CRStatus { CR_OK, CR_BAD_PARAM_ERROR, - CR_INSTANCIATION_FAILED, + CR_INSTANCIATION_FAILED_ERROR, CR_UNKNOWN_TYPE_ERROR, CR_UNKNOWN_PROP_ERROR, CR_UNKNOWN_PROP_VAL_ERROR, diff --git a/src/seleng/Makefile.am b/src/seleng/Makefile.am index a122c07..f7908fb 100644 --- a/src/seleng/Makefile.am +++ b/src/seleng/Makefile.am @@ -10,7 +10,7 @@ endif libcrseleng_la_SOURCES=$(SELENG_SRCS) INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/src/parser -I$(top_srcdir)/intl \ -@GLIB2_CFLAGS@ @LIBXML2_CFLAGS@ +@GLIB2_CFLAGS@ @LIBXML2_CFLAGS@ @PANGO_CFLAGS@ LDADD=$(top_srcdir)/src/parser/libcroco.la diff --git a/src/seleng/cr-fonts.c b/src/seleng/cr-fonts.c index 810f120..2a5f908 100644 --- a/src/seleng/cr-fonts.c +++ b/src/seleng/cr-fonts.c @@ -25,6 +25,78 @@ #include "cr-fonts.h" #include <string.h> + +static enum CRStatus +cr_font_family_to_string_real (CRFontFamily *a_this, + gboolean a_walk_list, + GString **a_string) +{ + guchar * name = NULL ; + enum CRStatus result = CR_OK ; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + + if (!*a_string) + { + *a_string = g_string_new (NULL) ; + g_return_val_if_fail (*a_string, + CR_INSTANCIATION_FAILED_ERROR) ; + } + + switch (a_this->type) + { + case FONT_FAMILY_SANS_SERIF: + name = (guchar*) "sans-serif" ; + break ; + + case FONT_FAMILY_SERIF: + name = (guchar*) "sans-serif" ; + break ; + + case FONT_FAMILY_CURSIVE: + name = (guchar*) "cursive" ; + break ; + + case FONT_FAMILY_FANTASY: + name = (guchar*) "fantasy" ; + break ; + + case FONT_FAMILY_MONOSPACE: + name = (guchar*) "monospace" ; + break ; + + case FONT_FAMILY_NON_GENERIC: + name = (guchar*) a_this->name; + break ; + + default: + name = (guchar*) NULL ; + break ; + } + + if (name) + { + if (a_this->prev) + { + g_string_append_printf (*a_string, + ", %s", name) ; + } + else + { + g_string_append (*a_string, + name) ; + } + } + + if (a_walk_list == TRUE && a_this->next) + { + result = cr_font_family_to_string_real (a_this->next, + TRUE, a_string) ; + } + + return result ; +} + CRFontFamily * cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) { @@ -46,6 +118,40 @@ cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) return result ; } + +guchar * +cr_font_family_to_string (CRFontFamily *a_this, + gboolean a_walk_font_family_list) +{ + enum CRStatus status = CR_OK ; + guchar *result = NULL ; + GString *stringue = NULL ; + + g_return_val_if_fail (a_this, + NULL) ; + + status = cr_font_family_to_string_real (a_this, + a_walk_font_family_list, + &stringue) ; + + if (status == CR_OK && stringue) + { + result = stringue->str ; + g_string_free (stringue, FALSE) ; + stringue = NULL ; + + } + else + { + if (stringue) + { + g_string_free (stringue, TRUE) ; + stringue = NULL ; + } + } + + return result ; +} enum CRStatus cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name) { diff --git a/src/seleng/cr-fonts.h b/src/seleng/cr-fonts.h index ad804c9..758778f 100644 --- a/src/seleng/cr-fonts.h +++ b/src/seleng/cr-fonts.h @@ -85,7 +85,9 @@ enum CRPredefinedAbsoluteFontSize FONT_SIZE_MEDIUM, FONT_SIZE_LARGE, FONT_SIZE_X_LARGE, - FONT_SIZE_XX_LARGE + FONT_SIZE_XX_LARGE, + + NB_PREDEFINED_ABSOLUTE_FONT_SIZES } ; /** @@ -151,7 +153,7 @@ struct _CRFontSize enum CRFontSizeType type ; union { - enum CRPredefinedAbsoluteFontSize predef_abs ; + enum CRPredefinedAbsoluteFontSize predefined ; enum CRRelativeFontSize relative ; CRNum * absolute ; } value; @@ -229,6 +231,10 @@ CRFontFamily * cr_font_family_append (CRFontFamily *a_this, CRFontFamily *a_family_to_append) ; +guchar * +cr_font_family_to_string (CRFontFamily *a_this, + gboolean a_walk_font_family_list) ; + CRFontFamily * cr_font_family_prepend (CRFontFamily *a_this, CRFontFamily *a_family_to_prepend); diff --git a/src/seleng/cr-style.c b/src/seleng/cr-style.c index b021b51..1f4d54e 100644 --- a/src/seleng/cr-style.c +++ b/src/seleng/cr-style.c @@ -143,6 +143,18 @@ static CRPropertyDesc gv_prop_table [] = {NULL, 0} } ; +const gulong gv_predefined_abs_font_size_tab [NB_PREDEFINED_ABSOLUTE_FONT_SIZES] += +{ + 7, /*FONT_SIZE_XX_SMALL*/ + 9,/*FONT_SIZE_X_SMALL*/ + 11, /*FONT_SIZE_SMALL*/ + 14, /*FONT_MEDIUM*/ + 17, /*FONT_LARGE*/ + 20, /*FONT_X_LARGE*/ + 24 /*FONT_XX_LARGE*/ +} ; + /** *A the key/value pair of this hash table *are: @@ -1495,7 +1507,7 @@ init_style_font_size_field (CRStyle *a_style) a_style->font_size = cr_font_size_new () ; if (!a_style->font_size) { - return CR_INSTANCIATION_FAILED ; + return CR_INSTANCIATION_FAILED_ERROR ; } } else @@ -1526,7 +1538,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_XX_SMALL ; } @@ -1540,7 +1552,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_X_SMALL ; } else if (a_value->content.str @@ -1553,7 +1565,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_SMALL ; } else if (a_value->content.str @@ -1566,7 +1578,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_MEDIUM ; } else if (a_value->content.str @@ -1579,7 +1591,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_LARGE ; } else if (a_value->content.str @@ -1592,7 +1604,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_X_LARGE ; } else if (a_value->content.str @@ -1605,7 +1617,7 @@ set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) a_style->font_size->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predef_abs = + a_style->font_size->value.predefined = FONT_SIZE_XX_LARGE ; } else if (a_value->content.str @@ -1737,7 +1749,7 @@ set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) if (!strcmp (a_value->content.str->str, "normal")) { - a_style->font_weight = FONT_WEIGHT_BOLD ; + a_style->font_weight = FONT_WEIGHT_NORMAL ; } else if (!strcmp (a_value->content.str->str, "bold")) @@ -2166,6 +2178,76 @@ cr_style_dup (CRStyle *a_this) return result ; } + +enum CRStatus +cr_style_to_pango_font_attributes (CRStyle *a_style, + PangoAttrList *a_pgo_attrs) +{ + PangoFontDescription *pgo_font_desc = NULL ; + guchar *font_family = NULL ; + + g_return_val_if_fail (a_pgo_attrs + && a_style + && a_style->font_size, + CR_BAD_PARAM_ERROR) ; + + pgo_font_desc = pango_font_description_new () ; + if (!pgo_font_desc) + { + cr_utils_trace_info ("Could not instanciate " + "pango font description") ; + return CR_ERROR ; + } + + + /*set font size*/ + switch (a_style->font_size->type) + { + 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]) ; + 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) ; + 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*/ + font_family = cr_font_family_to_string (a_style->font_family, + TRUE) ; + if (font_family) + { + pango_font_description_set_family (pgo_font_desc, + font_family) ; + } + + return CR_OK ; +} + /** *Destructor of the #CRStyle class. *@param a_this the instance to destroy. diff --git a/src/seleng/cr-style.h b/src/seleng/cr-style.h index 9265300..322bf15 100644 --- a/src/seleng/cr-style.h +++ b/src/seleng/cr-style.h @@ -23,6 +23,7 @@ #ifndef __CR_STYLE_H__ #define __CR_STYLE_H__ +#include <pango/pango.h> #include "cr-utils.h" #include "cr-statement.h" #include "cr-fonts.h" @@ -267,6 +268,9 @@ enum CRStatus 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) ; +enum CRStatus cr_style_ref (CRStyle *a_this) ; gboolean diff --git a/tests/test7-main.c b/tests/test7-main.c index ab94ab6..ddc26a2 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -78,7 +78,10 @@ const char * gv_cssbuf= " border:1px solid #000; " " overflow:auto; " " background-color:#eee; " -" font: 12px verdana; " +" /*font: 12px verdana;*/ " +" font-zise: 12px; " +" font-style: font-family ; " +" font-style: normal; " "} " " " "item " |