From fe58bbb01eafa6cd52bb79b0b5986ecad347ecf0 Mon Sep 17 00:00:00 2001 From: konn Date: Fri, 18 Jul 2008 06:33:54 +0000 Subject: [PATCH] * Added img tag with CSS for CHTML5.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2995 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml50.c | 264 +++++++++++++-------- test/chxj_chtml50/test_chxj_chtml50.c | 421 +++++++++++++++++++++++++++++++++- 2 files changed, 591 insertions(+), 94 deletions(-) diff --git a/src/chxj_chtml50.c b/src/chxj_chtml50.c index 8460f057..f30906b4 100644 --- a/src/chxj_chtml50.c +++ b/src/chxj_chtml50.c @@ -2150,124 +2150,202 @@ s_chtml50_end_hr_tag(void *pdoc, Node *UNUSED(child)) static char * s_chtml50_start_img_tag(void *pdoc, Node *node) { + chtml50_t *chtml50; + Doc *doc; + request_rec *r; + Attr *attr; + char *attr_src = NULL; + char *attr_align = NULL; + char *attr_style = NULL; + char *attr_alt = NULL; + char *attr_width = NULL; + char *attr_height = NULL; + char *attr_hspace = NULL; + char *attr_vspace = NULL; #ifndef IMG_NOT_CONVERT_FILENAME device_table *spec; #endif - chtml50_t *chtml50; - Doc *doc; - request_rec *r; - Attr *attr; chtml50 = GET_CHTML50(pdoc); - doc = chtml50->doc; - r = doc->r; #ifndef IMG_NOT_CONVERT_FILENAME spec = chtml50->spec; #endif + doc = chtml50->doc; + r = doc->r; - W_L("cookie); - if (value) { - value = apr_psprintf(r->pool, - "%s%c%s=true", - value, - (strchr(value, '?')) ? '&' : '?', - CHXJ_COOKIE_NOUPDATE_PARAM); - W_L(" src=\""); - W_V(value); - W_L("\""); - } - + value = chxj_encoding_parameter(r, value); + value = chxj_add_cookie_parameter(r, value, chtml50->cookie); + if (value) { + value = apr_psprintf(doc->buf.pool, + "%s%c%s=true", + value, + (strchr(value, '?')) ? '&' : '?', + CHXJ_COOKIE_NOUPDATE_PARAM); + } + attr_src = value; #else - value = chxj_img_conv(r,spec,value); - value = chxj_encoding_parameter(r, value); - value = chxj_add_cookie_parameter(r, value, chtml50->cookie); - if (value) { - value = apr_psprintf(r->pool, - "%s%c%s=true", - value, - (strchr(value, '?')) ? '&' : '?', - CHXJ_COOKIE_NOUPDATE_PARAM); - } - W_L(" src=\""); - W_V(value); - W_L("\""); + value = chxj_img_conv(r, spec, value); + value = chxj_encoding_parameter(r, value); + value = chxj_add_cookie_parameter(r, value, chtml50->cookie); + if (value) { + value = apr_psprintf(doc->buf.pool, + "%s%c%s=true", + value, + (strchr(value, '?')) ? '&' : '?', + CHXJ_COOKIE_NOUPDATE_PARAM); + } + attr_src = value; #endif - } - else if (STRCASEEQ('a','A',"align", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - if (value) { - if (STRCASEEQ('t','T',"top", value) || - STRCASEEQ('m','M',"middle",value) || - STRCASEEQ('b','B',"bottom",value) || - STRCASEEQ('l','L',"left", value) || - STRCASEEQ('c','C',"center", value) || - STRCASEEQ('r','R',"right", value)) { - W_L(" align=\""); - W_V(value); - W_L("\""); + } + else if (strcasecmp(name,"style") == 0 && value && *value) { + attr_style = value; + } + break; + + case 'a': + case 'A': + if (strcasecmp(name, "align" ) == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + /*--------------------------------------------------------------------*/ + /* CHTML 4.0 */ + /*--------------------------------------------------------------------*/ + if (value) { + if (STRCASEEQ('t','T',"top", value) || + STRCASEEQ('m','M',"middle",value) || + STRCASEEQ('b','B',"bottom",value) || + STRCASEEQ('l','L',"left", value) || + STRCASEEQ('r','R',"right", value)) { + attr_align = value; + } + else if (STRCASEEQ('c','C',"center", value)) { + attr_align = apr_pstrdup(doc->pool, "middle"); + } } } + else if (strcasecmp(name, "alt" ) == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_alt = value; + } + break; + + case 'w': + case 'W': + if (strcasecmp(name, "width" ) == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_width = value; + } + break; + + case 'h': + case 'H': + if (strcasecmp(name, "height") == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_height = value; + } + else + if (strcasecmp(name, "hspace") == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_hspace = value; + } + break; + + case 'v': + case 'V': + if (strcasecmp(name, "vspace") == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_vspace = value; + } + break; + + default: + break; } - else if (STRCASEEQ('w','W',"width", name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" width=\""); - W_V(value); - W_L("\""); - } - else if (STRCASEEQ('h','H', "height", name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" height=\""); - W_V(value); - W_L("\""); - } - else if (STRCASEEQ('h','H',"hspace", name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" hspace=\""); - W_V(value); - W_L("\""); - } - else if (STRCASEEQ('v','V',"vspace", name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" vspace=\""); - W_V(value); - W_L("\""); - } - else if (STRCASEEQ('a','A',"alt",name) && value && *value) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - W_L(" alt=\""); - W_V(value); - W_L("\""); + } + + if (IS_CSS_ON(chtml50->entryp)) { + css_prop_list_t *style = s_chtml50_push_and_get_now_style(pdoc, node, attr_style); + if (style) { + css_property_t *height_prop = chxj_css_get_property_value(doc, style, "height"); + css_property_t *width_prop = chxj_css_get_property_value(doc, style, "width"); + css_property_t *valign_prop = chxj_css_get_property_value(doc, style, "vertical-align"); + css_property_t *cur; + for (cur = height_prop->next; cur != height_prop; cur = cur->next) { + attr_height = apr_pstrdup(doc->pool, cur->value); + } + for (cur = width_prop->next; cur != width_prop; cur = cur->next) { + attr_width = apr_pstrdup(doc->pool, cur->value); + } + for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) { + attr_align = apr_pstrdup(doc->pool, cur->value); + } } } - W_L(">"); + W_L(""); return chtml50->out; } diff --git a/test/chxj_chtml50/test_chxj_chtml50.c b/test/chxj_chtml50/test_chxj_chtml50.c index 496b08e4..a5da1e96 100644 --- a/test/chxj_chtml50/test_chxj_chtml50.c +++ b/test/chxj_chtml50/test_chxj_chtml50.c @@ -677,6 +677,17 @@ void test_chtml50_hr_tag_with_css_005(); void test_chtml50_hr_tag_with_css_006(); void test_chtml50_hr_tag_with_css_007(); void test_chtml50_hr_tag_with_css_008(); + +void test_chtml50_img_tag_with_css_001(); +void test_chtml50_img_tag_with_css_002(); +void test_chtml50_img_tag_with_css_003(); +void test_chtml50_img_tag_with_css_004(); +void test_chtml50_img_tag_with_css_005(); +void test_chtml50_img_tag_with_css_006(); +void test_chtml50_img_tag_with_css_007(); +void test_chtml50_img_tag_with_css_008(); +void test_chtml50_img_tag_with_css_009(); +void test_chtml50_img_tag_with_css_010(); /* pend */ int @@ -1315,6 +1326,17 @@ main() CU_add_test(chtml50_suite, "test hr with css 006", test_chtml50_hr_tag_with_css_006); CU_add_test(chtml50_suite, "test hr with css 007", test_chtml50_hr_tag_with_css_007); CU_add_test(chtml50_suite, "test hr with css 008", test_chtml50_hr_tag_with_css_008); + + CU_add_test(chtml50_suite, "test img with css 001", test_chtml50_img_tag_with_css_001); + CU_add_test(chtml50_suite, "test img with css 002", test_chtml50_img_tag_with_css_002); + CU_add_test(chtml50_suite, "test img with css 003", test_chtml50_img_tag_with_css_003); + CU_add_test(chtml50_suite, "test img with css 004", test_chtml50_img_tag_with_css_004); + CU_add_test(chtml50_suite, "test img with css 005", test_chtml50_img_tag_with_css_005); + CU_add_test(chtml50_suite, "test img with css 006", test_chtml50_img_tag_with_css_006); + CU_add_test(chtml50_suite, "test img with css 007", test_chtml50_img_tag_with_css_007); + CU_add_test(chtml50_suite, "test img with css 008", test_chtml50_img_tag_with_css_008); + CU_add_test(chtml50_suite, "test img with css 009", test_chtml50_img_tag_with_css_009); + CU_add_test(chtml50_suite, "test img with css 010", test_chtml50_img_tag_with_css_010); /* aend */ CU_basic_run_tests(); @@ -6328,7 +6350,7 @@ void test_chtml50_img_tag_013() void test_chtml50_img_tag_013_1() { #define TEST_STRING "" -#define RESULT_STRING "" +#define RESULT_STRING "" char *ret; char *tmp; device_table spec; @@ -19719,6 +19741,403 @@ void test_chtml50_hr_tag_with_css_008() #undef TEST_STRING #undef RESULT_STRING } + + + + +/*---------------------------------------------------------------------------*/ +/* img tag with CSS */ +/*---------------------------------------------------------------------------*/ +char *test_chxj_serf_get110(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" + "img { height:80% }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_img_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_get110; + 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_chtml50(&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_chtml50_img_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_get110; + 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_chtml50(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +char *test_chxj_serf_get111(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" + "img { width:80% }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_img_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_get111; + 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_chtml50(&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_chtml50_img_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_get111; + 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_chtml50(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +char *test_chxj_serf_get112(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" + "img { vertical-align:top }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_img_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_get112; + 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_chtml50(&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_chtml50_img_tag_with_css_006() +{ +#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_get112; + 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_chtml50(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +char *test_chxj_serf_get113(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" + "img { vertical-align:middle }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_img_tag_with_css_007() +{ +#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_get113; + 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_chtml50(&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_chtml50_img_tag_with_css_008() +{ +#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_get113; + 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_chtml50(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +char *test_chxj_serf_get114(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" + "img { vertical-align:bottom }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml50_img_tag_with_css_009() +{ +#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_get114; + 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_chtml50(&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_chtml50_img_tag_with_css_010() +{ +#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_get114; + 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_chtml50(&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 == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */ -- 2.11.0