/** * Compute the styles that should be applied for the * current element. * We start with the default style, and successively override * this with the current style, style set for the tag, classes * and inline styles. * */ function _htmltodocx_get_style($element, $state) { $style_sheet = $state['style_sheet']; // Get the default styles $phpword_style = $style_sheet['default']; // Update with the current style $current_style = $state['current_style']; // Remove uninheritable items: $inheritable_props = htmltodocx_inheritable_props(); foreach ($current_style as $property => $value) { if (!in_array($property, $inheritable_props)) { unset($current_style[$property]); } } $phpword_style = array_merge($phpword_style, $current_style); // Update with any styles defined by the element tag $tag_style = isset($style_sheet['elements'][$element->tag]) ? $style_sheet['elements'][$element->tag] : array(); $phpword_style = array_merge($phpword_style, $tag_style); // Find any classes defined for this element: $class_list = array(); if (!empty($element->class)) { $classes = explode(' ', $element->class); foreach ($classes as $class) { $class_list[] = trim($class); } } // Look for any style definitions for these classes: $classes_style = array(); if (!empty($class_list) && !empty($style_sheet['classes'])) { foreach ($style_sheet['classes'] as $class => $attributes) { if (in_array($class, $class_list)) { $classes_style = array_merge($classes_style, $attributes); } } } $phpword_style = array_merge($phpword_style, $classes_style); // Find any inline styles: $inline_style_list = array(); if (!empty($element->attr['style'])) { $inline_styles = explode(';', rtrim(rtrim($element->attr['style']), ';')); foreach ($inline_styles as $inline_style) { $style_pair = explode(':', $inline_style); $inline_style_list[] = trim($style_pair[0]) . ': ' . trim($style_pair[1]); } } // Look for style definitions of these inline styles: $inline_styles = array(); if (!empty($inline_style_list) && !empty($style_sheet['inline'])) { foreach ($style_sheet['inline'] as $inline_style => $attributes) { if (in_array($inline_style, $inline_style_list)) { $inline_styles = array_merge($inline_styles, $attributes); } } } $phpword_style = array_merge($phpword_style, $inline_styles); return $phpword_style; }
/** * Compute the styles that should be applied for the * current element. * We start with the default style, and successively override * this with the current style, style set for the tag, classes * and inline styles. * */ function _htmltodocx_get_style($element, $state) { $style_sheet = $state['style_sheet']; // Get the default styles $phpword_style = $style_sheet['default']; // Update with the current style $current_style = $state['current_style']; // Remove uninheritable items: $inheritable_props = htmltodocx_inheritable_props(); foreach ($current_style as $property => $value) { if (!in_array($property, $inheritable_props)) { unset($current_style[$property]); } } $phpword_style = array_merge($phpword_style, $current_style); // Update with any styles defined by the element tag $tag_style = isset($style_sheet['elements'][$element->tag]) ? $style_sheet['elements'][$element->tag] : array(); $phpword_style = array_merge($phpword_style, $tag_style); // Find any classes defined for this element: $class_list = array(); if (!empty($element->class)) { $classes = explode(' ', $element->class); foreach ($classes as $class) { $class_list[] = trim($class); } } // Look for any style definitions for these classes: $classes_style = array(); if (!empty($class_list) && !empty($style_sheet['classes'])) { foreach ($style_sheet['classes'] as $class => $attributes) { if (in_array($class, $class_list)) { $classes_style = array_merge($classes_style, $attributes); } } } $phpword_style = array_merge($phpword_style, $classes_style); // Find any inline styles: $inline_style_list = array(); if (!empty($element->attr['style'])) { $inline_styles = explode(';', rtrim(rtrim($element->attr['style']), ';')); foreach ($inline_styles as $inline_style) { $style_pair = explode(':', $inline_style); $inline_style_list[] = trim($style_pair[0]) . ': ' . trim($style_pair[1]); } } // Look for style definitions of these inline styles: $inline_styles = array(); if (!empty($inline_style_list) && !empty($style_sheet['inline'])) { foreach ($style_sheet['inline'] as $inline_style => $attributes) { if (in_array($inline_style, $inline_style_list)) { $inline_styles = array_merge($inline_styles, $attributes); } } } $phpword_style = array_merge($phpword_style, $inline_styles); $new_style = array(); if ($element->attr && !empty($element->attr["style"])) { //解决文本颜色 $attr = $element->attr; $style = explode(";", $attr["style"]); foreach ($style as $k => $v) { $colorStyle = str_replace(" ", "", $v); if (mb_strpos($colorStyle, "color:") === 0) { $colorStr = str_replace("color:", "", $colorStyle); if (mb_strpos($colorStr, "rgb") !== false) { $new_style['color'] = RGBToHex($colorStr); } elseif (mb_strpos($colorStr, "#") !== false) { $new_style['color'] = str_replace("#", "", $colorStr); } } if (mb_strpos($colorStyle, "font-family:") === 0) { //解决文本字体 $colorStr = str_replace("font-family:", "", $colorStyle); $new_style['name'] = $colorStr; } if (mb_strpos($colorStyle, "font-size:") === 0) { //解决文本字体大小 $colorStr = str_replace("font-size:", "", $colorStyle); $new_style['size'] = str_replace("px", "", $colorStr); } if (mb_strpos($colorStyle, "line-through") !== false) { //解决文本加删除线 $new_style['strikethrough'] = true; } } } if (find_parent_strikethrough($element)) { //解决文本加删除线 $new_style['strikethrough'] = true; } $phpword_style = array_merge($phpword_style, $new_style); return $phpword_style; }
<?php $allowed_children = htmltodocx_html_allowed_children($tag = NULL); $html = '<table><tbody><tr><th width="80">Element</th><th width="560">Allowed child elements</th></tr>'; foreach ($allowed_children as $element => $child_elements) { $html .= '<tr><td class="heading"><code>' . $element . '</code></td><td><code>' . implode(', ', $child_elements) . '</code></td></tr>'; } $html .= '</tbody></table>'; print $html; ?> <h3>Inheritance</h3> <p>Attributes which can be inherited follow <a href="http://www.w3.org/TR/CSS21/propidx.html">standard CSS recommendations for inheritance</a>. See the function <code>htmltodocx_inheritable_props()</code>. The following attributes can be inherited:</p> <?php $inheritable_props = htmltodocx_inheritable_props(); $html = ''; foreach ($inheritable_props as $property) { $html .= '<code>' . $property . '</code><br>'; } $html .= ''; print $html; ?> <h2>Special characters</h2> <p>All HTML entities <a href="http://www.w3schools.com/tags/ref_entities.asp">listed here</a> are supported. For example: © (&copy;), £ (&pound;), ® (&reg;).</p> <h2>Language support</h2> <p>Note PHPWord does not support utf8 character encoding. The version of PHPWord shipped with the docxtohtml converter is patched to deal with this: all instances of utf8_encode() have been replaced with a new function - utf8encode_dummy() - which simply returns its string argument. <a href="http://phpword.codeplex.com/discussions/261365">Discussion</a>.</p>