From e5d6a3149de5ef4931d347f21c19ab8588c5dddc Mon Sep 17 00:00:00 2001 From: konn Date: Tue, 15 Jul 2008 07:43:58 +0000 Subject: [PATCH] * Added body tag with CSS for CHTML2.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2934 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml20.c | 88 ++++++++++++++++++++++++++++------- test/chxj_chtml20/test_chxj_chtml20.c | 50 ++++++++++++++++++++ 2 files changed, 121 insertions(+), 17 deletions(-) diff --git a/src/chxj_chtml20.c b/src/chxj_chtml20.c index 16253e24..88c56ea3 100644 --- a/src/chxj_chtml20.c +++ b/src/chxj_chtml20.c @@ -929,12 +929,15 @@ s_chtml20_start_body_tag(void *pdoc, Node *node) Doc *doc; request_rec *r; Attr *attr; + char *attr_bgcolor = NULL; + char *attr_text = NULL; + char *attr_link = NULL; + char *attr_style = NULL; chtml20 = GET_CHTML20(pdoc); doc = chtml20->doc; r = doc->r; - W_L("entryp)) { + css_prop_list_t *style = s_chtml20_push_and_get_now_style(pdoc, node, attr_style); + if (style) { + css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color"); + css_property_t *bgcolor_prop = chxj_css_get_property_value(doc, style, "background-color"); + css_property_t *cur; + for (cur = color_prop->next; cur != color_prop; cur = cur->next) { + if (cur->value && *cur->value) { + attr_text = apr_pstrdup(doc->pool, cur->value); + } + } + for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) { + if (cur->value && *cur->value) { + attr_bgcolor = apr_pstrdup(doc->pool, cur->value); + } + } + } + if (chtml20->style) { + css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, chtml20->style); + css_selector_t *cur_sel; + for (cur_sel = pseudos->selector_head.next; cur_sel != &pseudos->selector_head; cur_sel = cur_sel->next) { + if (cur_sel->name && strcasecmp(cur_sel->name, "a:link") == 0) { + css_property_t *cur; + for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) { + if (cur->name && strcasecmp(cur->name, "color") == 0) { + attr_link = apr_pstrdup(doc->pool, cur->value); + break; + } + } + break; + } + } + } + } + W_L(""); return chtml20->out; @@ -3614,7 +3668,7 @@ s_chtml20_end_dl_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a handter who processes the DT tag. + * It is a handler who processes the DT tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3632,7 +3686,7 @@ s_chtml20_start_dt_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a handter who processes the DT tag. + * It is a handler who processes the DT tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3649,7 +3703,7 @@ s_chtml20_end_dt_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a handder who processes the DD tag. + * It is a handler who processes the DD tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3667,7 +3721,7 @@ s_chtml20_start_dd_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a handder who processes the DD tag. + * It is a handler who processes the DD tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3684,7 +3738,7 @@ s_chtml20_end_dd_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a hanmenuer who processes the MENU tag. + * It is a handler who processes the MENU tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3703,7 +3757,7 @@ s_chtml20_start_menu_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a hanmenuer who processes the MENU tag. + * It is a handler who processes the MENU tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. @@ -3722,7 +3776,7 @@ s_chtml20_end_menu_tag(void *pdoc, Node *UNUSED(child)) /** - * It is a hanplaintexter who processes the PLAINTEXT tag. + * It is a handler who processes the PLAINTEXT tag. * * @param pdoc [i/o] The pointer to the CHTML structure at the output * destination is specified. diff --git a/test/chxj_chtml20/test_chxj_chtml20.c b/test/chxj_chtml20/test_chxj_chtml20.c index c6f5346c..405b1f94 100644 --- a/test/chxj_chtml20/test_chxj_chtml20.c +++ b/test/chxj_chtml20/test_chxj_chtml20.c @@ -577,6 +577,7 @@ void test_chtml20_body_tag_with_css_001(); void test_chtml20_body_tag_with_css_002(); void test_chtml20_body_tag_with_css_003(); void test_chtml20_body_tag_with_css_004(); +void test_chtml20_body_tag_with_css_005(); /* pend */ int @@ -1115,6 +1116,7 @@ main() CU_add_test(chtml20_suite, "test body with css 002", test_chtml20_body_tag_with_css_002); CU_add_test(chtml20_suite, "test body with css 003", test_chtml20_body_tag_with_css_003); CU_add_test(chtml20_suite, "test body with css 004", test_chtml20_body_tag_with_css_004); + CU_add_test(chtml20_suite, "test body with css 005", test_chtml20_body_tag_with_css_005); /* aend */ CU_basic_run_tests(); @@ -15672,6 +15674,8 @@ void test_chtml20_body_tag_with_css_004() tmp = chxj_encoding(&r, TEST_STRING, &destlen); ret = chxj_convert_chtml20(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); CU_ASSERT(ret != NULL); CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); @@ -15681,6 +15685,52 @@ void test_chtml20_body_tag_with_css_004() #undef TEST_STRING #undef RESULT_STRING } +char *test_chxj_serf_get060(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:link { color:#ff0000 }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml20_body_tag_with_css_005() +{ +#define TEST_STRING "" \ + "あいう" +#define RESULT_STRING "あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get060; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_chtml20(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */ -- 2.11.0