From d6856ab35832b62d696d396bb275b91b92f89e67 Mon Sep 17 00:00:00 2001 From: konn Date: Wed, 16 Jul 2008 18:58:53 +0000 Subject: [PATCH] * Added center tag with CSS for CHTML2.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2975 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml20.c | 33 ++++++- test/chxj_chtml20/test_chxj_chtml20.c | 177 ++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 4 deletions(-) diff --git a/src/chxj_chtml20.c b/src/chxj_chtml20.c index a1678d4f..7f33dd77 100644 --- a/src/chxj_chtml20.c +++ b/src/chxj_chtml20.c @@ -1892,6 +1892,7 @@ s_chtml20_start_center_tag(void *pdoc, Node *node) request_rec *r; Attr *attr; char *attr_style = NULL; + char *attr_color = NULL; chtml20 = GET_CHTML20(pdoc); doc = chtml20->doc; @@ -1907,11 +1908,31 @@ s_chtml20_start_center_tag(void *pdoc, Node *node) } } - W_L("
"); if (IS_CSS_ON(chtml20->entryp)) { - s_chtml20_push_and_get_now_style(pdoc, node, attr_style); + 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 *cur; + for (cur = color_prop->next; cur != color_prop; cur = cur->next) { + if (cur->value && *cur->value) { + attr_color = apr_pstrdup(doc->pool, cur->value); + } + } + } } + W_L("
"); + chtml20_flags_t *flg = (chtml20_flags_t *)apr_palloc(doc->pool, sizeof(chtml20_flags_t)); + memset(flg, 0, sizeof(*flg)); + if (attr_color) { + attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color); + W_L(""); + flg->with_font_flag = 1; + } + node->userData = flg; + return chtml20->out; } @@ -1925,7 +1946,7 @@ s_chtml20_start_center_tag(void *pdoc, Node *node) * @return The conversion result is returned. */ static char * -s_chtml20_end_center_tag(void *pdoc, Node *UNUSED(child)) +s_chtml20_end_center_tag(void *pdoc, Node *node) { chtml20_t *chtml20; Doc *doc; @@ -1935,10 +1956,14 @@ s_chtml20_end_center_tag(void *pdoc, Node *UNUSED(child)) doc = chtml20->doc; r = doc->r; - W_L("
"); if (IS_CSS_ON(chtml20->entryp)) { chxj_css_pop_prop_list(chtml20->css_prop_stack); } + chtml20_flags_t *flg = (chtml20_flags_t *)node->userData; + if (flg && flg->with_font_flag) { + W_L(""); + } + W_L("
"); return chtml20->out; } diff --git a/test/chxj_chtml20/test_chxj_chtml20.c b/test/chxj_chtml20/test_chxj_chtml20.c index 62553094..8039b32c 100644 --- a/test/chxj_chtml20/test_chxj_chtml20.c +++ b/test/chxj_chtml20/test_chxj_chtml20.c @@ -599,6 +599,11 @@ void test_chtml20_input_tag_with_css_005(); void test_chtml20_input_tag_with_css_006(); void test_chtml20_input_tag_with_css_007(); void test_chtml20_input_tag_with_css_008(); + +void test_chtml20_center_tag_with_css_001(); +void test_chtml20_center_tag_with_css_002(); +void test_chtml20_center_tag_with_css_003(); +void test_chtml20_center_tag_with_css_004(); /* pend */ int @@ -1159,6 +1164,11 @@ main() CU_add_test(chtml20_suite, "test input with css 006", test_chtml20_input_tag_with_css_006); CU_add_test(chtml20_suite, "test input with css 007", test_chtml20_input_tag_with_css_007); CU_add_test(chtml20_suite, "test input with css 008", test_chtml20_input_tag_with_css_008); + + CU_add_test(chtml20_suite, "test center with css 001", test_chtml20_center_tag_with_css_001); + CU_add_test(chtml20_suite, "test center with css 002", test_chtml20_center_tag_with_css_002); + CU_add_test(chtml20_suite, "test center with css 003", test_chtml20_center_tag_with_css_003); + CU_add_test(chtml20_suite, "test center with css 004", test_chtml20_center_tag_with_css_004); /* aend */ CU_basic_run_tests(); @@ -16520,6 +16530,173 @@ void test_chtml20_input_tag_with_css_008() #undef TEST_STRING #undef RESULT_STRING } + +/*===========================================================================*/ +/* center tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get084(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" + "center { color:rgb(100%,0%,0%);}\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml20_center_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_get084; + 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 +} +void test_chtml20_center_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_get084; + 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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + +char *test_chxj_serf_get085(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" + "center { font-size:xx-small;}\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml20_center_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_get085; + 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 +} +void test_chtml20_center_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_get085; + 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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* -wap-input-format: "*<ja:n>"; */ -- 2.11.0