From 228b19363ac5dcd2b812a997e44cdbe66bdc5d67 Mon Sep 17 00:00:00 2001 From: konn Date: Fri, 18 Jul 2008 06:34:02 +0000 Subject: [PATCH] * Added img tag with CSS for SoftBank XHTML converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2997 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_jxhtml.c | 99 +++++--- test/chxj_jxhtml/test_chxj_jxhtml.c | 438 ++++++++++++++++++++++++++++++++++++ 2 files changed, 508 insertions(+), 29 deletions(-) diff --git a/src/chxj_jxhtml.c b/src/chxj_jxhtml.c index 032c3340..388d6629 100644 --- a/src/chxj_jxhtml.c +++ b/src/chxj_jxhtml.c @@ -2778,16 +2778,20 @@ s_jxhtml_end_hr_tag(void *pdoc, Node *UNUSED(child)) static char * s_jxhtml_start_img_tag(void *pdoc, Node *node) { - jxhtml_t *jxhtml = GET_JXHTML(pdoc); - Doc *doc = jxhtml->doc; - request_rec *r = doc->r; - Attr *attr; + jxhtml_t *jxhtml = GET_JXHTML(pdoc); + Doc *doc = jxhtml->doc; + request_rec *r = doc->r; + Attr *attr; + char *attr_src = NULL; + char *attr_height = NULL; + char *attr_width = NULL; + char *attr_align = NULL; + char *attr_alt = NULL; + char *attr_style = NULL; #ifndef IMG_NOT_CONVERT_FILENAME device_table *spec = jxhtml->spec; #endif - int has_alt = 0; - W_L("pool, "middle"); } } } @@ -2848,17 +2844,13 @@ s_jxhtml_start_img_tag(void *pdoc, Node *node) /*----------------------------------------------------------------------*/ /* CHTML 1.0 */ /*----------------------------------------------------------------------*/ - W_L(" width=\""); - W_V(value); - W_L("\""); + attr_width = value; } else if (STRCASEEQ('h','H',"height",name) && value && *value) { /*----------------------------------------------------------------------*/ /* CHTML 1.0 */ /*----------------------------------------------------------------------*/ - W_L(" height=\""); - W_V(value); - W_L("\""); + attr_height = value; } else if (STRCASEEQ('h','H',"hspace",name)) { /*----------------------------------------------------------------------*/ @@ -2876,13 +2868,62 @@ s_jxhtml_start_img_tag(void *pdoc, Node *node) /*----------------------------------------------------------------------*/ /* CHTML 1.0 */ /*----------------------------------------------------------------------*/ - W_L(" alt=\""); - W_V(value); - W_L("\""); - has_alt = 1; + attr_alt = value; + } + else if (STRCASEEQ('s','S',"style",name) && value && *value) { + /*----------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*----------------------------------------------------------------------*/ + attr_style = value; } } - if (! has_alt) { + + if (IS_CSS_ON(jxhtml->entryp)) { + css_prop_list_t *style = s_jxhtml_nopush_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(""); diff --git a/test/chxj_jxhtml/test_chxj_jxhtml.c b/test/chxj_jxhtml/test_chxj_jxhtml.c index ea33c220..cfd71f99 100644 --- a/test/chxj_jxhtml/test_chxj_jxhtml.c +++ b/test/chxj_jxhtml/test_chxj_jxhtml.c @@ -680,6 +680,17 @@ void test_jxhtml_hr_tag_with_css_005(); void test_jxhtml_hr_tag_with_css_006(); void test_jxhtml_hr_tag_with_css_007(); void test_jxhtml_hr_tag_with_css_008(); + +void test_jxhtml_img_tag_with_css_001(); +void test_jxhtml_img_tag_with_css_002(); +void test_jxhtml_img_tag_with_css_003(); +void test_jxhtml_img_tag_with_css_004(); +void test_jxhtml_img_tag_with_css_005(); +void test_jxhtml_img_tag_with_css_006(); +void test_jxhtml_img_tag_with_css_007(); +void test_jxhtml_img_tag_with_css_008(); +void test_jxhtml_img_tag_with_css_009(); +void test_jxhtml_img_tag_with_css_010(); /* pend */ int @@ -1407,6 +1418,17 @@ main() CU_add_test(jxhtml_suite, "test hr with css 006", test_jxhtml_hr_tag_with_css_006); CU_add_test(jxhtml_suite, "test hr with css 007", test_jxhtml_hr_tag_with_css_007); CU_add_test(jxhtml_suite, "test hr with css 008", test_jxhtml_hr_tag_with_css_008); + + CU_add_test(jxhtml_suite, "test img with css 001", test_jxhtml_img_tag_with_css_001); + CU_add_test(jxhtml_suite, "test img with css 002", test_jxhtml_img_tag_with_css_002); + CU_add_test(jxhtml_suite, "test img with css 003", test_jxhtml_img_tag_with_css_003); + CU_add_test(jxhtml_suite, "test img with css 004", test_jxhtml_img_tag_with_css_004); + CU_add_test(jxhtml_suite, "test img with css 005", test_jxhtml_img_tag_with_css_005); + CU_add_test(jxhtml_suite, "test img with css 006", test_jxhtml_img_tag_with_css_006); + CU_add_test(jxhtml_suite, "test img with css 007", test_jxhtml_img_tag_with_css_007); + CU_add_test(jxhtml_suite, "test img with css 008", test_jxhtml_img_tag_with_css_008); + CU_add_test(jxhtml_suite, "test img with css 009", test_jxhtml_img_tag_with_css_009); + CU_add_test(jxhtml_suite, "test img with css 010", test_jxhtml_img_tag_with_css_010); /* aend */ CU_basic_run_tests(); @@ -20721,6 +20743,422 @@ void test_jxhtml_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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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_jxhtml_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_jxhtml(&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