OSDN Git Service

* Added center tag with CSS for CHTML4.0 converter.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Thu, 17 Jul 2008 12:45:12 +0000 (12:45 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Thu, 17 Jul 2008 12:45:12 +0000 (12:45 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2985 1a406e8e-add9-4483-a2c8-d8cac5b7c224

src/chxj_chtml10.c
src/chxj_chtml20.c
src/chxj_chtml30.c
src/chxj_chtml40.c
test/chxj_chtml40/test_chxj_chtml40.c

index 5efe791..3cbca72 100644 (file)
@@ -2436,7 +2436,7 @@ s_chtml10_start_hr_tag(void *pdoc, Node *node)
     }
   }
   if (IS_CSS_ON(chtml10->entryp)) {
-    css_prop_list_t *style = s_chtml10_push_and_get_now_style(pdoc, node, attr_style);
+    css_prop_list_t *style = s_chtml10_nopush_and_get_now_style(pdoc, node, attr_style);
     if (style) {
       css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style");
       css_property_t *height_prop       = chxj_css_get_property_value(doc, style, "height");
@@ -2508,10 +2508,6 @@ s_chtml10_end_hr_tag(void *pdoc, Node *UNUSED(child))
 {
   chtml10_t *chtml10 = GET_CHTML10(pdoc);
 
-  if (IS_CSS_ON(chtml10->entryp)) {
-    chxj_css_pop_prop_list(chtml10->css_prop_stack);
-  }
-
   return chtml10->out;
 }
 
index 8e08446..ef49208 100644 (file)
@@ -2334,7 +2334,7 @@ s_chtml20_start_hr_tag(void *pdoc, Node *node)
     }
   }
   if (IS_CSS_ON(chtml20->entryp)) {
-    css_prop_list_t *style = s_chtml20_push_and_get_now_style(pdoc, node, attr_style);
+    css_prop_list_t *style = s_chtml20_nopush_and_get_now_style(pdoc, node, attr_style);
     if (style) {
       css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style");
       css_property_t *height_prop       = chxj_css_get_property_value(doc, style, "height");
@@ -2405,9 +2405,6 @@ static char *
 s_chtml20_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
 {
   chtml20_t *chtml20 = GET_CHTML20(pdoc);
-  if (IS_CSS_ON(chtml20->entryp)) {
-    chxj_css_pop_prop_list(chtml20->css_prop_stack);
-  }
   return chtml20->out;
 }
 
index 0da8d2d..396c7f3 100644 (file)
@@ -1949,7 +1949,7 @@ s_chtml30_start_hr_tag(void *pdoc, Node *node)
     }
   }
   if (IS_CSS_ON(chtml30->entryp)) {
-    css_prop_list_t *style = s_chtml30_push_and_get_now_style(pdoc, node, attr_style);
+    css_prop_list_t *style = s_chtml30_nopush_and_get_now_style(pdoc, node, attr_style);
     if (style) {
       css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style");
       css_property_t *height_prop       = chxj_css_get_property_value(doc, style, "height");
@@ -2020,9 +2020,6 @@ static char *
 s_chtml30_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
 {
   chtml30_t *chtml30 = GET_CHTML30(pdoc);
-  if (IS_CSS_ON(chtml30->entryp)) {
-    chxj_css_pop_prop_list(chtml30->css_prop_stack);
-  }
   return chtml30->out;
 }
 
index b23f2c6..086773a 100644 (file)
@@ -1871,13 +1871,150 @@ s_chtml40_start_hr_tag(void *pdoc, Node *node)
   chtml40_t   *chtml40;
   Doc         *doc;
   request_rec *r;
+  char        *attr_align   = NULL;
+  char        *attr_size    = NULL;
+  char        *attr_width   = NULL;
+  char        *attr_noshade = NULL;
+  char        *attr_style   = NULL;
+  char        *attr_color   = NULL;
 
   chtml40 = GET_CHTML40(pdoc);
   doc     = chtml40->doc;
   r       = doc->r;
 
+  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 'a':
+    case 'A':
+      if (strcasecmp(name, "align") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
+          attr_align = value;
+        }
+      }
+      break;
+
+    case 's':
+    case 'S':
+      if (strcasecmp(name, "size") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value && *value) {
+          attr_size = value;
+        }
+      }
+      else if (strcasecmp(name, "style") == 0) {
+        if (value && *value) {
+          attr_style = value;
+        }
+      }
+      break;
+
+    case 'w':
+    case 'W':
+      if (strcasecmp(name, "width") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        if (value && *value) {
+          attr_width = value;
+        }
+      }
+      break;
+
+    case 'n':
+    case 'N':
+      if (strcasecmp(name, "noshade") == 0) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 1.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_noshade = apr_pstrdup(doc->pool, "noshade");
+      }
+      break;
+
+    case 'c':
+    case 'C':
+      if (strcasecmp(name, "color") == 0 && value && *value) {
+        /*--------------------------------------------------------------------*/
+        /* CHTML 4.0                                                          */
+        /*--------------------------------------------------------------------*/
+        attr_color = value;
+      }
+      break;
+
+    default:
+      break;
+    }
+  }
+  if (IS_CSS_ON(chtml40->entryp)) {
+    css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-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 *cur;
+      for (cur = border_style_prop->next; cur != border_style_prop; cur = cur->next) {
+        if (STRCASEEQ('s','S',"solid",cur->value)) {
+          attr_noshade = "noshade";
+        }
+      }
+      for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
+        char *tmp = apr_pstrdup(doc->pool, cur->value);
+        char *tmpp = strstr(tmp, "px");
+        if (tmpp) { 
+          *tmpp = 0;
+          attr_size = apr_pstrdup(doc->pool, tmp);
+        }
+      }
+      for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
+        char *tmp = apr_pstrdup(doc->pool, cur->value);
+        char *tmpp = strstr(tmp, "px");
+        if (tmpp) {
+          *tmpp = 0;
+          attr_width = apr_pstrdup(doc->pool, tmp);
+        }
+        else {
+          tmpp = strstr(tmp, "%");
+          if (tmpp) {
+            attr_width = apr_pstrdup(doc->pool, tmp);
+          }
+        }
+      }
+    }
+  }
   W_L("<hr");
+  if (attr_align) {
+    W_L(" align=\"");
+    W_V(attr_align);
+    W_L("\"");
+  }
+  if (attr_size) {
+    W_L(" size=\"");
+    W_V(attr_size);
+    W_L("\"");
+  }
+  if (attr_width) {
+    W_L(" width=\"");
+    W_V(attr_width);
+    W_L("\"");
+  }
+  if (attr_color) {
+    W_L(" color=\"");
+    W_V(attr_color);
+    W_L("\"");
+  }
+  if (attr_noshade) {
+    W_L(" noshade");
+  }
+  W_L(">");
+#if 0
   for (attr = qs_get_attr(doc,node);
        attr; 
        attr = qs_get_next_attr(doc,attr)) {
@@ -1928,7 +2065,9 @@ s_chtml40_start_hr_tag(void *pdoc, Node *node)
       W_L("\"");
     }
   }
+  W_L("<hr");
   W_L(">");
+#endif
   return chtml40->out;
 }
 
index 11ac110..ecfe817 100644 (file)
@@ -629,6 +629,15 @@ void test_chtml40_center_tag_with_css_001();
 void test_chtml40_center_tag_with_css_002();
 void test_chtml40_center_tag_with_css_003();
 void test_chtml40_center_tag_with_css_004();
+
+void test_chtml40_hr_tag_with_css_001();
+void test_chtml40_hr_tag_with_css_002();
+void test_chtml40_hr_tag_with_css_003();
+void test_chtml40_hr_tag_with_css_004();
+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();
 /* pend */
 
 int
@@ -1220,6 +1229,15 @@ main()
   CU_add_test(chtml40_suite, "test center with css 002",                           test_chtml40_center_tag_with_css_002);
   CU_add_test(chtml40_suite, "test center with css 003",                           test_chtml40_center_tag_with_css_003);
   CU_add_test(chtml40_suite, "test center with css 004",                           test_chtml40_center_tag_with_css_004);
+
+  CU_add_test(chtml40_suite, "test hr with css 001",                               test_chtml40_hr_tag_with_css_001);
+  CU_add_test(chtml40_suite, "test hr with css 002",                               test_chtml40_hr_tag_with_css_002);
+  CU_add_test(chtml40_suite, "test hr with css 003",                               test_chtml40_hr_tag_with_css_003);
+  CU_add_test(chtml40_suite, "test hr with css 004",                               test_chtml40_hr_tag_with_css_004);
+  CU_add_test(chtml40_suite, "test hr with css 005",                               test_chtml40_hr_tag_with_css_005);
+  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);
   /* aend */
 
   CU_basic_run_tests();
@@ -17850,6 +17868,328 @@ void test_chtml40_center_tag_with_css_004()
 #undef TEST_STRING
 #undef RESULT_STRING
 }
+
+
+
+/*===========================================================================*/
+/* hr tag with CSS                                                           */
+/*===========================================================================*/
+char *test_chxj_serf_get100(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"
+                     "hr      { border-style:solid }\n";
+  *len = strlen(css);
+  call_check = 1;
+  return css;
+}
+void test_chtml40_hr_tag_with_css_001()
+{
+#define  TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\"  type=\"text/css\" />" \
+                     "</head><body><hr>あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr noshade>あいう</body></html>"
+  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_get100;
+  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_hr_tag_with_css_002()
+{
+#define  TEST_STRING "<html><head>" \
+                     "</head><body><hr style=\"border-style:solid\">あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr noshade>あいう</body></html>"
+  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_get100;
+  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_get101(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"
+                     "hr      { height:10px }\n";
+  *len = strlen(css);
+  call_check = 1;
+  return css;
+}
+void test_chtml40_hr_tag_with_css_003()
+{
+#define  TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\"  type=\"text/css\" />" \
+                     "</head><body><hr>あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr size=\"10\">あいう</body></html>"
+  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_get101;
+  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_hr_tag_with_css_004()
+{
+#define  TEST_STRING "<html><head>" \
+                     "</head><body><hr style=\"height:10px\">あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr size=\"10\">あいう</body></html>"
+  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_get101;
+  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_get102(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"
+                     "hr      { width:10px }\n";
+  *len = strlen(css);
+  call_check = 1;
+  return css;
+}
+void test_chtml40_hr_tag_with_css_005()
+{
+#define  TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\"  type=\"text/css\" />" \
+                     "</head><body><hr>あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr width=\"10\">あいう</body></html>"
+  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_get102;
+  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_hr_tag_with_css_006()
+{
+#define  TEST_STRING "<html><head>" \
+                     "</head><body><hr style=\"width:10px\">あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr width=\"10\">あいう</body></html>"
+  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_get102;
+  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_get103(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"
+                     "hr      { width:80% }\n";
+  *len = strlen(css);
+  call_check = 1;
+  return css;
+}
+void test_chtml40_hr_tag_with_css_007()
+{
+#define  TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\"  type=\"text/css\" />" \
+                     "</head><body><hr>あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr width=\"80%\">あいう</body></html>"
+  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_get103;
+  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_hr_tag_with_css_008()
+{
+#define  TEST_STRING "<html><head>" \
+                     "</head><body><hr style=\"width:10%\">あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body><hr width=\"10%\">あいう</body></html>"
+  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_get103;
+  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
  */