sw/qa/extras/htmlimport/data/list-style.html | 58 +++++++++++++++++++++++++++ sw/qa/extras/htmlimport/htmlimport.cxx | 48 ++++++++++++++++++++++ sw/source/filter/html/css1kywd.cxx | 1 sw/source/filter/html/css1kywd.hxx | 2 sw/source/filter/html/htmlnumreader.cxx | 10 ++++ sw/source/filter/html/svxcss1.cxx | 52 ++++++++++++++++++++++++ sw/source/filter/html/svxcss1.hxx | 5 ++ 7 files changed, 176 insertions(+)
New commits: commit 0755b26191782b17e307832452af4a66d8fdfac7 Author: Thorsten Behrens <thorsten.behr...@cib.de> Date: Mon Feb 20 04:20:51 2017 +0100 Add list-style-type support to html parser Change-Id: Ibd7978b12a3c5024c55571b165b82c6abe7a8925 Reviewed-on: https://gerrit.libreoffice.org/34461 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/sw/qa/extras/htmlimport/data/list-style.html b/sw/qa/extras/htmlimport/data/list-style.html new file mode 100644 index 0000000..8c5468a --- /dev/null +++ b/sw/qa/extras/htmlimport/data/list-style.html @@ -0,0 +1,58 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> + <body> + <div> + <p> + This document contains a number of lists... + <ul> + <li>list-style-type</li> + <li>default</li> + </ul> + <ul style="list-style-type: circle;"> + <li>list-style-type</li> + <li>circle</li> + </ul> + <ul style="list-style-type: square;"> + <li>list-style-type</li> + <li>square</li> + </ul> + <ul style="list-style-type: disc;"> + <li>list-style-type</li> + <li>disc</li> + </ul> + <ol> + <li>list-style-type</li> + <li>default</li> + </ol> + <ol style="list-style-type: decimal;"> + <li>list-style-type</li> + <li>decimal</li> + </ol> + <ol style="list-style-type: lower-alpha;"> + <li>list-style-type</li> + <li>lower-alpha</li> + </ol> + <ol style="list-style-type: lower-latin;"> + <li>list-style-type</li> + <li>lower-latin</li> + </ol> + <ol style="list-style-type: lower-roman;"> + <li>list-style-type</li> + <li>lower-roman</li> + </ol> + <ol style="list-style-type: upper-alpha;"> + <li>list-style-type</li> + <li>upper-alpha</li> + </ol> + <ol style="list-style-type: upper-latin;"> + <li>list-style-type</li> + <li>upper-latin</li> + </ol> + <ol style="list-style-type: upper-roman;"> + <li>list-style-type</li> + <li>upper-roman</li> + </ol> + </p> + </div> + </body> +</html> diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 66d070d..b04f7c9 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -126,6 +126,54 @@ DECLARE_HTMLIMPORT_TEST(testInlinedImagesPageAndParagraph, "PageAndParagraphFill } } +DECLARE_HTMLIMPORT_TEST(testListStyleType, "list-style.html") +{ + // check unnumbered list style - should be type circle here + uno::Reference< beans::XPropertySet > xParagraphProperties(getParagraph(4), + uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xLevels( + xParagraphProperties->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aProps; + xLevels->getByIndex(0) >>= aProps; // 1st level + + bool bBulletFound=false; + for (int i = 0; i < aProps.getLength(); ++i) + { + const beans::PropertyValue& rProp = aProps[i]; + + if (rProp.Name == "BulletChar") + { + // should be 'o'. + CPPUNIT_ASSERT_EQUAL(OUString("\xEE\x80\x89", 3, RTL_TEXTENCODING_UTF8), rProp.Value.get<OUString>()); + bBulletFound = true; + break; + } + } + CPPUNIT_ASSERT_MESSAGE("no BulletChar property found for para 4", bBulletFound); + + // check numbered list style - should be type lower-alpha here + xParagraphProperties.set(getParagraph(14), + uno::UNO_QUERY); + xLevels.set(xParagraphProperties->getPropertyValue("NumberingRules"), + uno::UNO_QUERY); + xLevels->getByIndex(0) >>= aProps; // 1st level + + for (int i = 0; i < aProps.getLength(); ++i) + { + const beans::PropertyValue& rProp = aProps[i]; + + if (rProp.Name == "NumberingType") + { + printf("style is %d\n", rProp.Value.get<sal_Int16>()); + // is lower-alpha in input, translates into chars_lower_letter here + CPPUNIT_ASSERT_EQUAL(style::NumberingType::CHARS_LOWER_LETTER, + rProp.Value.get<sal_Int16>()); + return; + } + } + CPPUNIT_FAIL("no NumberingType property found for para 14"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/css1kywd.cxx b/sw/source/filter/html/css1kywd.cxx index 6088d42..7f8cc83 100644 --- a/sw/source/filter/html/css1kywd.cxx +++ b/sw/source/filter/html/css1kywd.cxx @@ -144,6 +144,7 @@ const sal_Char* sCSS1_PV_justify = "justify"; const sal_Char* sCSS1_P_text_indent = "text-indent"; const sal_Char* sCSS1_P_line_height = "line-height"; +const sal_Char* sCSS1_P_list_style_type = "list-style-type"; // Strings for box properties diff --git a/sw/source/filter/html/css1kywd.hxx b/sw/source/filter/html/css1kywd.hxx index 9522cd7..49e41a2 100644 --- a/sw/source/filter/html/css1kywd.hxx +++ b/sw/source/filter/html/css1kywd.hxx @@ -147,6 +147,8 @@ extern const sal_Char* sCSS1_P_text_indent; extern const sal_Char* sCSS1_P_line_height; +extern const sal_Char* sCSS1_P_list_style_type; + // Strings for box properties extern const sal_Char* sCSS1_P_margin_left; diff --git a/sw/source/filter/html/htmlnumreader.cxx b/sw/source/filter/html/htmlnumreader.cxx index cc7a608..0626634 100644 --- a/sw/source/filter/html/htmlnumreader.cxx +++ b/sw/source/filter/html/htmlnumreader.cxx @@ -288,6 +288,16 @@ void SwHTMLParser::NewNumBulList( int nToken ) aNumFormat.SetFirstLineOffset( nTextIndent ); bChangeNumFormat = true; } + if( aPropInfo.m_bNumbering ) + { + aNumFormat.SetNumberingType(aPropInfo.m_nNumberingType); + bChangeNumFormat = true; + } + if( aPropInfo.m_bBullet ) + { + aNumFormat.SetBulletChar( (sal_Unicode)aPropInfo.m_cBulletChar ); + bChangeNumFormat = true; + } } aPropInfo.m_bLeftMargin = aPropInfo.m_bTextIndent = false; if( !aPropInfo.m_bRightMargin ) diff --git a/sw/source/filter/html/svxcss1.cxx b/sw/source/filter/html/svxcss1.cxx index 5373a5f..9841091 100644 --- a/sw/source/filter/html/svxcss1.cxx +++ b/sw/source/filter/html/svxcss1.cxx @@ -53,6 +53,7 @@ #include "css1kywd.hxx" #include "svxcss1.hxx" +#include "htmlnum.hxx" #include <utility> @@ -215,6 +216,26 @@ static CSS1PropertyEnum const aPageBreakTable[] = { nullptr, 0 } }; +static CSS1PropertyEnum const aNumberStyleTable[] = +{ + { "decimal", SVX_NUM_ARABIC }, + { "lower-alpha", SVX_NUM_CHARS_LOWER_LETTER }, + { "lower-latin", SVX_NUM_CHARS_LOWER_LETTER }, + { "lower-roman", SVX_NUM_ROMAN_LOWER }, + { "upper-alpha", SVX_NUM_CHARS_UPPER_LETTER }, + { "upper-latin", SVX_NUM_CHARS_UPPER_LETTER }, + { "upper-roman", SVX_NUM_ROMAN_UPPER }, + { nullptr, 0 } +}; + +static CSS1PropertyEnum const aBulletStyleTable[] = +{ + { "circle", HTML_BULLETCHAR_CIRCLE }, + { "disc", HTML_BULLETCHAR_DISC }, + { "square", HTML_BULLETCHAR_SQUARE }, + { nullptr, 0 } +}; + static sal_uInt16 const aBorderWidths[] = { @@ -400,6 +421,7 @@ void SvxCSS1PropertyInfo::Clear() m_aId.clear(); m_bTopMargin = m_bBottomMargin = false; m_bLeftMargin = m_bRightMargin = m_bTextIndent = false; + m_bNumbering = m_bBullet = false; m_nLeftMargin = m_nRightMargin = 0; m_eFloat = SVX_ADJUST_END; @@ -407,6 +429,9 @@ void SvxCSS1PropertyInfo::Clear() m_nTopBorderDistance = m_nBottomBorderDistance = m_nLeftBorderDistance = m_nRightBorderDistance = USHRT_MAX; + m_nNumberingType = 0; + m_cBulletChar = ' '; + m_nColumnCount = 0; m_nLeft = m_nTop = m_nWidth = m_nHeight = 0; @@ -1673,6 +1698,32 @@ static void ParseCSS1_line_height( const CSS1Expression *pExpr, } +static void ParseCSS1_list_style_type( const CSS1Expression *pExpr, + SfxItemSet & /*rItemSet*/, + SvxCSS1PropertyInfo& rPropInfo, + const SvxCSS1Parser& /*rParser*/ ) +{ + OSL_ENSURE( pExpr, "no expression" ); + + if( pExpr->GetType() == CSS1_IDENT ) + { + const OUString& rValue = pExpr->GetString(); + + // values are context-dependent, so fill both + sal_uInt16 nEnum; + if( SvxCSS1Parser::GetEnum( aNumberStyleTable, rValue, nEnum ) ) + { + rPropInfo.m_bNumbering = true; + rPropInfo.m_nNumberingType = nEnum; + } + if( SvxCSS1Parser::GetEnum( aBulletStyleTable, rValue, nEnum ) ) + { + rPropInfo.m_bBullet = true; + rPropInfo.m_cBulletChar = nEnum; + } + } +} + static void ParseCSS1_font( const CSS1Expression *pExpr, SfxItemSet &rItemSet, SvxCSS1PropertyInfo& rPropInfo, @@ -3080,6 +3131,7 @@ static CSS1PropEntry aCSS1PropFnTab[] = CSS1_PROP_ENTRY(font_weight), CSS1_PROP_ENTRY(letter_spacing), CSS1_PROP_ENTRY(line_height), + CSS1_PROP_ENTRY(list_style_type), CSS1_PROP_ENTRY(font), CSS1_PROP_ENTRY(text_align), CSS1_PROP_ENTRY(text_decoration), diff --git a/sw/source/filter/html/svxcss1.hxx b/sw/source/filter/html/svxcss1.hxx index ae149a1..e91c643 100644 --- a/sw/source/filter/html/svxcss1.hxx +++ b/sw/source/filter/html/svxcss1.hxx @@ -109,6 +109,8 @@ public: bool m_bLeftMargin : 1; bool m_bRightMargin : 1; bool m_bTextIndent : 1; + bool m_bNumbering : 1; + bool m_bBullet : 1; SvxAdjust m_eFloat; @@ -119,6 +121,9 @@ public: sal_uInt16 m_nLeftBorderDistance; sal_uInt16 m_nRightBorderDistance; + sal_uInt16 m_nNumberingType; + sal_Unicode m_cBulletChar; + sal_uInt16 m_nColumnCount; long m_nLeft, m_nTop; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits