From 9b77f4a1419f99eb33329369886ea9e139ae5ada Mon Sep 17 00:00:00 2001 From: konn Date: Tue, 15 Jul 2008 07:44:19 +0000 Subject: [PATCH] * Added body tag with CSS for au XHTML converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2940 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_xhtml_mobile_1_0.c | 88 ++++++++-- .../test_chxj_xhtml_mobile_1_0.c | 194 ++++++++++++++++++++- 2 files changed, 267 insertions(+), 15 deletions(-) diff --git a/src/chxj_xhtml_mobile_1_0.c b/src/chxj_xhtml_mobile_1_0.c index d1a4d3ab..1d38f491 100644 --- a/src/chxj_xhtml_mobile_1_0.c +++ b/src/chxj_xhtml_mobile_1_0.c @@ -952,11 +952,14 @@ s_xhtml_1_0_end_base_tag(void *pdoc, Node *UNUSED(child)) static char * s_xhtml_1_0_start_body_tag(void *pdoc, Node *node) { - xhtml_t *xhtml = GET_XHTML(pdoc); - Doc *doc = xhtml->doc; - Attr *attr; + xhtml_t *xhtml = GET_XHTML(pdoc); + Doc *doc = xhtml->doc; + Attr *attr; + char *attr_bgcolor = NULL; + char *attr_text = NULL; + char *attr_link = NULL; + char *attr_style = NULL; - W_L("entryp)) { + css_prop_list_t *style = s_xhtml_1_0_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 (xhtml->style) { + css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, xhtml->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); + } + } + } + } + } + } + + W_L("pool, attr_bgcolor); + W_L("background-color:"); + W_V(attr_bgcolor); + W_L(";"); + } + if (attr_text) { + attr_text = chxj_css_rgb_func_to_value(doc->pool, attr_text); + W_L("color:"); + W_V(attr_text); + W_L(";"); + } + W_L("\""); + } + if (attr_link) { + attr_link = chxj_css_rgb_func_to_value(doc->pool, attr_link); + W_L(" link=\""); + W_V(attr_link); + W_L("\""); } W_L(">"); + return xhtml->out; } @@ -1007,6 +1065,10 @@ s_xhtml_1_0_end_body_tag(void *pdoc, Node *UNUSED(child)) Doc *doc = xhtml->doc; W_L(""); + if (IS_CSS_ON(xhtml->entryp)) { + chxj_css_pop_prop_list(xhtml->css_prop_stack); + } + return xhtml->out; } diff --git a/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c b/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c index 2a4c46e1..0908f68e 100644 --- a/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c +++ b/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c @@ -623,6 +623,11 @@ void test_xhtml_h6_tag_with_css_003(); void test_xhtml_h6_tag_with_css_004(); void test_xhtml_h6_tag_with_css_005(); void test_xhtml_h6_tag_with_css_006(); + +void test_xhtml_body_tag_with_css_001(); +void test_xhtml_body_tag_with_css_002(); +void test_xhtml_body_tag_with_css_003(); +void test_xhtml_body_tag_with_css_004(); /* pend */ int @@ -1282,6 +1287,11 @@ main() CU_add_test(xhtml_suite, "test h6 with css 004", test_xhtml_h6_tag_with_css_004); CU_add_test(xhtml_suite, "test h6 with css 005", test_xhtml_h6_tag_with_css_005); CU_add_test(xhtml_suite, "test h6 with css 006", test_xhtml_h6_tag_with_css_006); + + CU_add_test(xhtml_suite, "test body with css 001", test_xhtml_body_tag_with_css_001); + CU_add_test(xhtml_suite, "test body with css 002", test_xhtml_body_tag_with_css_002); + CU_add_test(xhtml_suite, "test body with css 003", test_xhtml_body_tag_with_css_003); + CU_add_test(xhtml_suite, "test body with css 004", test_xhtml_body_tag_with_css_004); /* aend */ CU_basic_run_tests(); @@ -2192,7 +2202,7 @@ void test_xhtml_body_tag_003() void test_xhtml_body_tag_004() { #define TEST_STRING "" -#define RESULT_STRING "" +#define RESULT_STRING "" char *ret; char *tmp; device_table spec; @@ -2279,7 +2289,7 @@ void test_xhtml_body_tag_006() void test_xhtml_body_tag_007() { #define TEST_STRING "" -#define RESULT_STRING "" +#define RESULT_STRING "" char *ret; char *tmp; device_table spec; @@ -17913,6 +17923,186 @@ void test_xhtml_h6_tag_with_css_006() #undef TEST_STRING #undef RESULT_STRING } + + +/*===========================================================================*/ +/* body tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get058(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:visited { display:none }\n" + "body { color:#ff0000 }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_body_tag_with_css_001() +{ +#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_get058; + 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_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + 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 +} + + +char *test_chxj_serf_get059(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:visited { display:none }\n" + "body { background-color:#ff0000 }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_body_tag_with_css_002() +{ +#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_get059; + 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_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + 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 +} + +void test_xhtml_body_tag_with_css_003() +{ +#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_get059; + 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_xhtml_mobile_1_0(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_xhtml_body_tag_with_css_004() +{ +#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_get059; + 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_xhtml_mobile_1_0(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */ -- 2.11.0