From 9aa7184b790200df2da11b2188e1a6485cb69971 Mon Sep 17 00:00:00 2001 From: konn Date: Wed, 16 Jul 2008 18:58:59 +0000 Subject: [PATCH] * Added center tag with CSS for CHTML4.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2977 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml40.c | 32 +++++- test/chxj_chtml40/test_chxj_chtml40.c | 182 ++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 4 deletions(-) diff --git a/src/chxj_chtml40.c b/src/chxj_chtml40.c index 7a78373d..b23f2c69 100644 --- a/src/chxj_chtml40.c +++ b/src/chxj_chtml40.c @@ -1783,6 +1783,7 @@ s_chtml40_start_center_tag(void *pdoc, Node *node) Doc *doc; Attr *attr; char *attr_style = NULL; + char *attr_color = NULL; chtml40 = GET_CHTML40(pdoc); doc = chtml40->doc; @@ -1796,11 +1797,30 @@ s_chtml40_start_center_tag(void *pdoc, Node *node) attr_style = value; } } + if (IS_CSS_ON(chtml40->entryp)) { + css_prop_list_t *style = s_chtml40_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("
"); - if (IS_CSS_ON(chtml40->entryp)) { - s_chtml40_push_and_get_now_style(pdoc, node, attr_style); + chtml40_flags_t *flg = (chtml40_flags_t *)apr_palloc(doc->pool, sizeof(chtml40_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 chtml40->out; } @@ -1815,7 +1835,7 @@ s_chtml40_start_center_tag(void *pdoc, Node *node) * @return The conversion result is returned. */ static char * -s_chtml40_end_center_tag(void *pdoc, Node *UNUSED(child)) +s_chtml40_end_center_tag(void *pdoc, Node *node) { chtml40_t *chtml40; Doc *doc; @@ -1823,10 +1843,14 @@ s_chtml40_end_center_tag(void *pdoc, Node *UNUSED(child)) chtml40 = GET_CHTML40(pdoc); doc = chtml40->doc; - W_L("
"); if (IS_CSS_ON(chtml40->entryp)) { chxj_css_pop_prop_list(chtml40->css_prop_stack); } + chtml40_flags_t *flg = (chtml40_flags_t *)node->userData; + if (flg && flg->with_font_flag) { + W_L(""); + } + W_L(""); return chtml40->out; } diff --git a/test/chxj_chtml40/test_chxj_chtml40.c b/test/chxj_chtml40/test_chxj_chtml40.c index 409a039c..11ac1109 100644 --- a/test/chxj_chtml40/test_chxj_chtml40.c +++ b/test/chxj_chtml40/test_chxj_chtml40.c @@ -624,6 +624,11 @@ void test_chtml40_input_tag_with_css_005(); void test_chtml40_input_tag_with_css_006(); void test_chtml40_input_tag_with_css_007(); void test_chtml40_input_tag_with_css_008(); + +void test_chtml40_center_tag_with_css_001(); +void test_chtml40_center_tag_with_css_002(); +void test_chtml40_center_tag_with_css_003(); +void test_chtml40_center_tag_with_css_004(); /* pend */ int @@ -1210,6 +1215,11 @@ main() CU_add_test(chtml40_suite, "test input with css 006", test_chtml40_input_tag_with_css_006); CU_add_test(chtml40_suite, "test input with css 007", test_chtml40_input_tag_with_css_007); CU_add_test(chtml40_suite, "test input with css 008", test_chtml40_input_tag_with_css_008); + + CU_add_test(chtml40_suite, "test center with css 001", test_chtml40_center_tag_with_css_001); + CU_add_test(chtml40_suite, "test center with css 002", test_chtml40_center_tag_with_css_002); + CU_add_test(chtml40_suite, "test center with css 003", test_chtml40_center_tag_with_css_003); + CU_add_test(chtml40_suite, "test center with css 004", test_chtml40_center_tag_with_css_004); /* aend */ CU_basic_run_tests(); @@ -17668,6 +17678,178 @@ void test_chtml40_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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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