From 52875e5c3140f5159cccddfc486b478f7868d575 Mon Sep 17 00:00:00 2001 From: konn Date: Fri, 18 Jul 2008 06:33:51 +0000 Subject: [PATCH] * Added img tag with CSS for CHTML4.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2994 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml40.c | 261 +++++++++++++-------- test/chxj_chtml40/test_chxj_chtml40.c | 420 +++++++++++++++++++++++++++++++++- 2 files changed, 590 insertions(+), 91 deletions(-) diff --git a/src/chxj_chtml40.c b/src/chxj_chtml40.c index 932b47aa..b4bab56c 100644 --- a/src/chxj_chtml40.c +++ b/src/chxj_chtml40.c @@ -2046,120 +2046,201 @@ s_chtml40_end_hr_tag(void *pdoc, Node *UNUSED(child)) static char * s_chtml40_start_img_tag(void *pdoc, Node *node) { + chtml40_t *chtml40; + 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 - chtml40_t *chtml40; - Doc *doc; - request_rec *r; - Attr *attr; chtml40 = GET_CHTML40(pdoc); - doc = chtml40->doc; - r = doc->r; #ifndef IMG_NOT_CONVERT_FILENAME spec = chtml40->spec; #endif + doc = chtml40->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, chtml40->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, chtml40->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 (strcasecmp(name,"style") == 0 && value && *value) { + attr_style = value; } + break; -#else - value = chxj_img_conv(r,spec,value); - value = chxj_encoding_parameter(r, value); - value = chxj_add_cookie_parameter(r, value, chtml40->cookie); - if (value) { - value = apr_psprintf(r->pool, - "%s%c%s=true", - value, - (strchr(value, '?')) ? '&' : '?', - CHXJ_COOKIE_NOUPDATE_PARAM); + 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"); + } + } } - W_L(" src=\""); - W_V(value); - W_L("\""); -#endif - } - else if (STRCASEEQ('a','A',"align", name)) { - /*----------------------------------------------------------------------*/ - /* CHTML 1.0 */ - /*----------------------------------------------------------------------*/ - if (value && (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, "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(chtml40->entryp)) { + css_prop_list_t *style = s_chtml40_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(""); return chtml40->out; } diff --git a/test/chxj_chtml40/test_chxj_chtml40.c b/test/chxj_chtml40/test_chxj_chtml40.c index ecfe817f..022de3d3 100644 --- a/test/chxj_chtml40/test_chxj_chtml40.c +++ b/test/chxj_chtml40/test_chxj_chtml40.c @@ -638,6 +638,17 @@ void test_chtml40_hr_tag_with_css_005(); void test_chtml40_hr_tag_with_css_006(); void test_chtml40_hr_tag_with_css_007(); void test_chtml40_hr_tag_with_css_008(); + +void test_chtml40_img_tag_with_css_001(); +void test_chtml40_img_tag_with_css_002(); +void test_chtml40_img_tag_with_css_003(); +void test_chtml40_img_tag_with_css_004(); +void test_chtml40_img_tag_with_css_005(); +void test_chtml40_img_tag_with_css_006(); +void test_chtml40_img_tag_with_css_007(); +void test_chtml40_img_tag_with_css_008(); +void test_chtml40_img_tag_with_css_009(); +void test_chtml40_img_tag_with_css_010(); /* pend */ int @@ -1238,6 +1249,17 @@ main() CU_add_test(chtml40_suite, "test hr with css 006", test_chtml40_hr_tag_with_css_006); CU_add_test(chtml40_suite, "test hr with css 007", test_chtml40_hr_tag_with_css_007); CU_add_test(chtml40_suite, "test hr with css 008", test_chtml40_hr_tag_with_css_008); + + CU_add_test(chtml40_suite, "test img with css 001", test_chtml40_img_tag_with_css_001); + CU_add_test(chtml40_suite, "test img with css 002", test_chtml40_img_tag_with_css_002); + CU_add_test(chtml40_suite, "test img with css 003", test_chtml40_img_tag_with_css_003); + CU_add_test(chtml40_suite, "test img with css 004", test_chtml40_img_tag_with_css_004); + CU_add_test(chtml40_suite, "test img with css 005", test_chtml40_img_tag_with_css_005); + CU_add_test(chtml40_suite, "test img with css 006", test_chtml40_img_tag_with_css_006); + CU_add_test(chtml40_suite, "test img with css 007", test_chtml40_img_tag_with_css_007); + CU_add_test(chtml40_suite, "test img with css 008", test_chtml40_img_tag_with_css_008); + CU_add_test(chtml40_suite, "test img with css 009", test_chtml40_img_tag_with_css_009); + CU_add_test(chtml40_suite, "test img with css 010", test_chtml40_img_tag_with_css_010); /* aend */ CU_basic_run_tests(); @@ -6252,7 +6274,7 @@ void test_chtml40_img_tag_013() void test_chtml40_img_tag_013_1() { #define TEST_STRING "" -#define RESULT_STRING "" +#define RESULT_STRING "" char *ret; char *tmp; device_table spec; @@ -18190,6 +18212,402 @@ void test_chtml40_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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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_chtml40_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_chtml40(&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