From b2386cbc635ac04a0c1d816414dfedb8137d9145 Mon Sep 17 00:00:00 2001 From: konn Date: Tue, 15 Jul 2008 07:44:39 +0000 Subject: [PATCH] * Added font tag with CSS for CHTML2.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2948 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml20.c | 47 +++++++++++++----- test/chxj_chtml20/test_chxj_chtml20.c | 91 +++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 11 deletions(-) diff --git a/src/chxj_chtml20.c b/src/chxj_chtml20.c index 9bfffb5f..ebcc6a17 100644 --- a/src/chxj_chtml20.c +++ b/src/chxj_chtml20.c @@ -1430,7 +1430,8 @@ s_chtml20_start_font_tag(void *pdoc, Node *node) Doc *doc; request_rec *r; Attr *attr; - char *color = NULL; + char *attr_color = NULL; + char *attr_style = NULL; chtml20 = GET_CHTML20(pdoc); doc = chtml20->doc; @@ -1441,7 +1442,7 @@ s_chtml20_start_font_tag(void *pdoc, Node *node) /* Get Attributes */ /*--------------------------------------------------------------------------*/ for (attr = qs_get_attr(doc,node); - attr && color == NULL; + attr && attr_color == NULL; attr = qs_get_next_attr(doc,attr)) { char *name = qs_get_attr_name(doc,attr); char *value = qs_get_attr_value(doc,attr); @@ -1449,7 +1450,7 @@ s_chtml20_start_font_tag(void *pdoc, Node *node) case 'c': case 'C': if (strcasecmp(name, "color") == 0 && value && *value) { - color = apr_pstrdup(doc->buf.pool, value); + attr_color = apr_pstrdup(doc->buf.pool, value); } break; @@ -1461,17 +1462,38 @@ s_chtml20_start_font_tag(void *pdoc, Node *node) /*--------------------------------------------------------------------*/ /* ignore */ } + else if (strcasecmp(name, "style") == 0 && value && *value) { + attr_style = value; + } break; default: break; } } - if (color) { + if (IS_CSS_ON(chtml20->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 *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); + } + } + } + } + if (attr_color) { W_L(""); - chtml20->font_flag++; + chtml20_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg)); + memset(flg, 0, sizeof(*flg)); + flg->with_font_flag = 1; + node->userData = flg; + } + else { + node->userData = NULL; } return chtml20->out; } @@ -1486,7 +1508,7 @@ s_chtml20_start_font_tag(void *pdoc, Node *node) * @return The conversion result is returned. */ static char * -s_chtml20_end_font_tag(void *pdoc, Node *UNUSED(child)) +s_chtml20_end_font_tag(void *pdoc, Node *node) { chtml20_t *chtml20; Doc *doc; @@ -1496,9 +1518,12 @@ s_chtml20_end_font_tag(void *pdoc, Node *UNUSED(child)) doc = chtml20->doc; r = doc->r; - if (chtml20->font_flag) { + chtml20_flags_t *flg = (chtml20_flags_t *)node->userData; + if (flg && flg->with_font_flag) { W_L(""); - chtml20->font_flag--; + } + if (IS_CSS_ON(chtml20->entryp)) { + chxj_css_pop_prop_list(chtml20->css_prop_stack); } return chtml20->out; } @@ -3322,10 +3347,10 @@ s_chtml20_end_p_tag(void *pdoc, Node *node) r = doc->r; chtml20_flags_t *flg = (chtml20_flags_t *)node->userData; - if (flg->with_font_flag) { + if (flg && flg->with_font_flag) { W_L(""); } - if (flg->with_blink_flag) { + if (flg && flg->with_blink_flag) { W_L(""); } W_L("

"); diff --git a/test/chxj_chtml20/test_chxj_chtml20.c b/test/chxj_chtml20/test_chxj_chtml20.c index 405b1f94..45c7a898 100644 --- a/test/chxj_chtml20/test_chxj_chtml20.c +++ b/test/chxj_chtml20/test_chxj_chtml20.c @@ -578,6 +578,9 @@ 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(); + +void test_chtml20_font_tag_with_css_001(); +void test_chtml20_font_tag_with_css_002(); /* pend */ int @@ -1117,6 +1120,9 @@ main() 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); + + CU_add_test(chtml20_suite, "test font with css 001", test_chtml20_font_tag_with_css_001); + CU_add_test(chtml20_suite, "test font with css 002", test_chtml20_font_tag_with_css_002); /* aend */ CU_basic_run_tests(); @@ -15731,6 +15737,91 @@ void test_chtml20_body_tag_with_css_005() #undef TEST_STRING #undef RESULT_STRING } + +/*===========================================================================*/ +/* font tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get065(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" + "font { color:#ff0000 }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml20_font_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_get065; + 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_font_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_get065; + 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 +} /* * vim:ts=2 et */ -- 2.11.0