From b0430b3d96f7929053e56865f2b0995e7667bc02 Mon Sep 17 00:00:00 2001 From: konn Date: Fri, 18 Jul 2008 06:33:44 +0000 Subject: [PATCH] * Added img tag with CSS for CHTML2.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2992 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml20.c | 199 ++++++++++++++++ test/chxj_chtml20/test_chxj_chtml20.c | 417 ++++++++++++++++++++++++++++++++++ 2 files changed, 616 insertions(+) diff --git a/src/chxj_chtml20.c b/src/chxj_chtml20.c index ef49208b..c344cc66 100644 --- a/src/chxj_chtml20.c +++ b/src/chxj_chtml20.c @@ -2420,6 +2420,7 @@ s_chtml20_end_hr_tag(void *pdoc, Node *UNUSED(child)) static char * s_chtml20_start_img_tag(void *pdoc, Node *node) { +#if 0 chtml20_t *chtml20; Doc *doc; request_rec *r; @@ -2566,6 +2567,204 @@ s_chtml20_start_img_tag(void *pdoc, Node *node) } W_L(">"); return chtml20->out; +#endif + chtml20_t *chtml20; + 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 + + chtml20 = GET_CHTML20(pdoc); +#ifndef IMG_NOT_CONVERT_FILENAME + spec = chtml20->spec; +#endif + doc = chtml20->doc; + r = doc->r; + + /*--------------------------------------------------------------------------*/ + /* Get Attributes */ + /*--------------------------------------------------------------------------*/ + for (attr = qs_get_attr(doc,node); + attr; + attr = qs_get_next_attr(doc,attr)) { + char *name = qs_get_attr_name (doc,attr); + char *value = qs_get_attr_value(doc,attr); + switch(*name) { + case 's': + case 'S': + if (strcasecmp(name, "src") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ +#ifdef IMG_NOT_CONVERT_FILENAME + value = chxj_encoding_parameter(r, value); + value = chxj_add_cookie_parameter(r, value, chtml20->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, chtml20->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; + + 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; + } + } + + 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 *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 chtml20->out; } diff --git a/test/chxj_chtml20/test_chxj_chtml20.c b/test/chxj_chtml20/test_chxj_chtml20.c index e54e10ff..b2d26b5c 100644 --- a/test/chxj_chtml20/test_chxj_chtml20.c +++ b/test/chxj_chtml20/test_chxj_chtml20.c @@ -613,6 +613,17 @@ void test_chtml20_hr_tag_with_css_005(); void test_chtml20_hr_tag_with_css_006(); void test_chtml20_hr_tag_with_css_007(); void test_chtml20_hr_tag_with_css_008(); + +void test_chtml20_img_tag_with_css_001(); +void test_chtml20_img_tag_with_css_002(); +void test_chtml20_img_tag_with_css_003(); +void test_chtml20_img_tag_with_css_004(); +void test_chtml20_img_tag_with_css_005(); +void test_chtml20_img_tag_with_css_006(); +void test_chtml20_img_tag_with_css_007(); +void test_chtml20_img_tag_with_css_008(); +void test_chtml20_img_tag_with_css_009(); +void test_chtml20_img_tag_with_css_010(); /* pend */ int @@ -1187,6 +1198,17 @@ main() CU_add_test(chtml20_suite, "test hr with css 006", test_chtml20_hr_tag_with_css_006); CU_add_test(chtml20_suite, "test hr with css 007", test_chtml20_hr_tag_with_css_007); CU_add_test(chtml20_suite, "test hr with css 008", test_chtml20_hr_tag_with_css_008); + + CU_add_test(chtml20_suite, "test img with css 001", test_chtml20_img_tag_with_css_001); + CU_add_test(chtml20_suite, "test img with css 002", test_chtml20_img_tag_with_css_002); + CU_add_test(chtml20_suite, "test img with css 003", test_chtml20_img_tag_with_css_003); + CU_add_test(chtml20_suite, "test img with css 004", test_chtml20_img_tag_with_css_004); + CU_add_test(chtml20_suite, "test img with css 005", test_chtml20_img_tag_with_css_005); + CU_add_test(chtml20_suite, "test img with css 006", test_chtml20_img_tag_with_css_006); + CU_add_test(chtml20_suite, "test img with css 007", test_chtml20_img_tag_with_css_007); + CU_add_test(chtml20_suite, "test img with css 008", test_chtml20_img_tag_with_css_008); + CU_add_test(chtml20_suite, "test img with css 009", test_chtml20_img_tag_with_css_009); + CU_add_test(chtml20_suite, "test img with css 010", test_chtml20_img_tag_with_css_010); /* aend */ CU_basic_run_tests(); @@ -17036,6 +17058,401 @@ void test_chtml20_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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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_chtml20_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_chtml20(&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