sw/source/filter/ww8/attributeoutputbase.hxx |   16 ++
 sw/source/filter/ww8/rtfattributeoutput.cxx  |   91 +-------------
 sw/source/filter/ww8/wrtw8nds.cxx            |  174 ++++++++++++++-------------
 3 files changed, 115 insertions(+), 166 deletions(-)

New commits:
commit 21a53c857830414968a7acea4dc1f9b95676a6b1
Author: Mark Hung <mark...@gmail.com>
Date:   Sat Jan 27 19:27:30 2018 +0800

    sw: refactor StartRuby in ww8 filter.
    
    Refactor the copy-pasted code in StartRuby of WW8AttributeOutput,
    RtfAttributeOutput, so that it can be used it in DocxAttributeOutput
    later.
    
    Change-Id: I63631be7604a62899c5630f3e57985993f128728
    Reviewed-on: https://gerrit.libreoffice.org/48764
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Mark Hung <mark...@gmail.com>

diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index 028961cd1d8b..fc1648e77031 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -668,6 +668,22 @@ public:
     const SwRedlineData* GetParagraphMarkerRedline( const SwTextNode& rNode, 
RedlineType_t aRedlineType );
 };
 
+class WW8Ruby
+{
+    sal_Int32 m_nJC;
+    sal_Char m_cDirective;
+    sal_uInt32 m_nRubyHeight;
+    sal_uInt32 m_nBaseHeight;
+    OUString m_sFontFamily;
+
+public:
+    WW8Ruby(const SwTextNode& rNode, const SwFormatRuby& rRuby, const 
MSWordExportBase& rExport );
+    sal_Int32   GetJC() { return m_nJC; }
+    sal_Char    GetDirective() { return m_cDirective; }
+    sal_uInt32   GetRubyHeight() { return m_nRubyHeight; }
+    sal_uInt32   GetBaseHeight() { return m_nBaseHeight; }
+    OUString    GetFontFamily() { return m_sFontFamily; }
+};
 #endif // INCLUDED_SW_SOURCE_FILTER_WW8_ATTRIBUTEOUTPUTBASE_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 8e15fe6c9aed..959881aed103 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -450,100 +450,23 @@ void RtfAttributeOutput::RawText(const OUString& rText, 
rtl_TextEncoding eCharSe
 void RtfAttributeOutput::StartRuby(const SwTextNode& rNode, sal_Int32 nPos,
                                    const SwFormatRuby& rRuby)
 {
+    WW8Ruby aWW8Ruby(rNode, rRuby, GetExport());
     OUString aStr(FieldString(ww::eEQ));
     aStr += "\\* jc";
-    sal_Int32 nJC = 0;
-    sal_Char cDirective = 0;
-    switch (rRuby.GetAdjustment())
-    {
-        case css::text::RubyAdjust_LEFT:
-            nJC = 3;
-            cDirective = 'l';
-            break;
-        case css::text::RubyAdjust_CENTER:
-            //defaults to 0
-            break;
-        case css::text::RubyAdjust_RIGHT:
-            nJC = 4;
-            cDirective = 'r';
-            break;
-        case css::text::RubyAdjust_BLOCK:
-            nJC = 1;
-            cDirective = 'd';
-            break;
-        case css::text::RubyAdjust_INDENT_BLOCK:
-            nJC = 2;
-            cDirective = 'd';
-            break;
-        default:
-            OSL_ENSURE(false, "Unhandled Ruby justication code");
-            break;
-    }
-    aStr += OUString::number(nJC);
-
-    /*
-     MS needs to know the name and size of the font used in the ruby item,
-     but we could have written it in a mixture of asian and western
-     scripts, and each of these can be a different font and size than the
-     other, so we make a guess based upon the first character of the text,
-     defaulting to asian.
-     */
-    assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
-    sal_uInt16 nRubyScript = 
g_pBreakIt->GetBreakIter()->getScriptType(rRuby.GetText(), 0);
-
-    const SwTextRuby* pRubyText = rRuby.GetTextRuby();
-    const SwCharFormat* pFormat = pRubyText ? pRubyText->GetCharFormat() : 
nullptr;
-    OUString sFamilyName;
-    long nHeight;
-    if (pFormat)
-    {
-        const auto& rFont
-            = ItemGet<SvxFontItem>(*pFormat, GetWhichOfScript(RES_CHRATR_FONT, 
nRubyScript));
-        sFamilyName = rFont.GetFamilyName();
-
-        const auto& rHeight = ItemGet<SvxFontHeightItem>(
-            *pFormat, GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript));
-        nHeight = rHeight.GetHeight();
-    }
-    else
-    {
-        /*Get defaults if no formatting on ruby text*/
-
-        const SfxItemPool* pPool = rNode.GetSwAttrSet().GetPool();
-        pPool = pPool ? pPool : &m_rExport.m_pDoc->GetAttrPool();
-
-        const auto& rFont
-            = DefaultItemGet<SvxFontItem>(*pPool, 
GetWhichOfScript(RES_CHRATR_FONT, nRubyScript));
-        sFamilyName = rFont.GetFamilyName();
-
-        const auto& rHeight = DefaultItemGet<SvxFontHeightItem>(
-            *pPool, GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript));
-        nHeight = rHeight.GetHeight();
-    }
-    nHeight = (nHeight + 5) / 10;
+    aStr += OUString::number(aWW8Ruby.GetJC());
 
     aStr += " \\* \"Font:";
-    aStr += sFamilyName;
+    aStr += aWW8Ruby.GetFontFamily();
     aStr += "\" \\* hps";
-    aStr += OUString::number(nHeight);
+    aStr += OUString::number((aWW8Ruby.GetRubyHeight() + 5) / 10);
     aStr += " \\o";
-    if (cDirective)
+    if (aWW8Ruby.GetDirective())
     {
-        aStr += "\\a" + OUString(cDirective);
+        aStr += "\\a" + OUString(aWW8Ruby.GetDirective());
     }
     aStr += "(\\s\\up ";
 
-    if (pRubyText)
-        nRubyScript
-            = g_pBreakIt->GetBreakIter()->getScriptType(rNode.GetText(), 
pRubyText->GetStart());
-    else
-        nRubyScript = i18n::ScriptType::ASIAN;
-
-    const SwAttrSet& rSet = rNode.GetSwAttrSet();
-    auto& rHeightItem = static_cast<const SvxFontHeightItem&>(
-        rSet.Get(GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript)));
-    nHeight = (rHeightItem.GetHeight() + 10) / 20 - 1;
-    aStr += OUString::number(nHeight);
+    aStr += OUString::number((aWW8Ruby.GetBaseHeight() + 10) / 20 - 1);
     aStr += "(";
     EndRun(&rNode, nPos);
     m_rExport.OutputField(nullptr, ww::eEQ, aStr, FieldFlags::Start | 
FieldFlags::CmdStart);
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 0fd463a0cd93..358ef108c711 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -822,99 +822,24 @@ const SfxPoolItem& SwWW8AttrIter::GetItem(sal_uInt16 
nWhich) const
 
 void WW8AttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 
/*nPos*/, const SwFormatRuby& rRuby )
 {
+    WW8Ruby aWW8Ruby(rNode, rRuby, GetExport());
     OUString aStr( FieldString( ww::eEQ ) );
     aStr += "\\* jc";
-    sal_Int32 nJC = 0;
-    sal_Char cDirective = 0;
-    switch ( rRuby.GetAdjustment() )
-    {
-        case css::text::RubyAdjust_LEFT:
-            nJC = 3;
-            cDirective = 'l';
-            break;
-        case css::text::RubyAdjust_CENTER:
-            //defaults to 0
-            break;
-        case css::text::RubyAdjust_RIGHT:
-            nJC = 4;
-            cDirective = 'r';
-            break;
-        case css::text::RubyAdjust_BLOCK:
-            nJC = 1;
-            cDirective = 'd';
-            break;
-        case css::text::RubyAdjust_INDENT_BLOCK:
-            nJC = 2;
-            cDirective = 'd';
-            break;
-        default:
-            OSL_ENSURE( false,"Unhandled Ruby justication code" );
-            break;
-    }
-    aStr += OUString::number( nJC );
+    aStr += OUString::number(aWW8Ruby.GetJC());
 
-    /*
-     MS needs to know the name and size of the font used in the ruby item,
-     but we could have written it in a mixture of asian and western
-     scripts, and each of these can be a different font and size than the
-     other, so we make a guess based upon the first character of the text,
-     defaulting to asian.
-     */
-    assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
-    sal_uInt16 nRubyScript = g_pBreakIt->GetBreakIter()->getScriptType( 
rRuby.GetText(), 0);
-
-    const SwTextRuby* pRubyText = rRuby.GetTextRuby();
-    const SwCharFormat* pFormat = pRubyText ? pRubyText->GetCharFormat() : 
nullptr;
-    OUString sFamilyName;
-    long nHeight;
-    if ( pFormat )
-    {
-        const SvxFontItem &rFont = ItemGet< SvxFontItem >( *pFormat,
-                GetWhichOfScript(RES_CHRATR_FONT,nRubyScript) );
-        sFamilyName = rFont.GetFamilyName();
-
-        const SvxFontHeightItem &rHeight = ItemGet< SvxFontHeightItem >( 
*pFormat,
-                GetWhichOfScript( RES_CHRATR_FONTSIZE, nRubyScript ) );
-        nHeight = rHeight.GetHeight();
-    }
-    else
-    {
-        /*Get defaults if no formatting on ruby text*/
-
-        const SfxItemPool *pPool = rNode.GetSwAttrSet().GetPool();
-        pPool = pPool ? pPool : &m_rWW8Export.m_pDoc->GetAttrPool();
-
-        const SvxFontItem &rFont  = DefaultItemGet< SvxFontItem >( *pPool,
-                GetWhichOfScript( RES_CHRATR_FONT,nRubyScript ) );
-        sFamilyName = rFont.GetFamilyName();
-
-        const SvxFontHeightItem &rHeight = DefaultItemGet< SvxFontHeightItem >
-            ( *pPool, GetWhichOfScript( RES_CHRATR_FONTSIZE, nRubyScript ) );
-        nHeight = rHeight.GetHeight();
-    }
-    nHeight = (nHeight + 5)/10;
 
     aStr += " \\* \"Font:";
-    aStr += sFamilyName;
+    aStr += aWW8Ruby.GetFontFamily();
     aStr += "\" \\* hps";
-    aStr += OUString::number( nHeight );
+    aStr += OUString::number((aWW8Ruby.GetRubyHeight() + 5) / 10);
     aStr += " \\o";
-    if ( cDirective )
+    if (aWW8Ruby.GetDirective())
     {
-        aStr += "\\a" + OUString(cDirective);
+        aStr += "\\a" + OUString(aWW8Ruby.GetDirective());
     }
     aStr += "(\\s\\up ";
 
-    assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
-    nRubyScript = g_pBreakIt->GetBreakIter()->getScriptType( rNode.GetText(),
-            pRubyText->GetStart() );
-
-    const SwAttrSet& rSet = rNode.GetSwAttrSet();
-    const SvxFontHeightItem &rHeightItem  =
-        static_cast< const SvxFontHeightItem& >(rSet.Get(
-                                             GetWhichOfScript( 
RES_CHRATR_FONTSIZE, nRubyScript ) ));
-    nHeight = (rHeightItem.GetHeight() + 10)/20-1;
-    aStr += OUString::number(nHeight);
+    aStr += OUString::number((aWW8Ruby.GetBaseHeight() + 10) / 20 - 1);
     aStr += "(";
     aStr += rRuby.GetText();
     aStr += ")";
@@ -3337,4 +3262,89 @@ void MSWordExportBase::OutputContentNode( SwContentNode& 
rNode )
     }
 }
 
+
+WW8Ruby::WW8Ruby(const SwTextNode& rNode, const SwFormatRuby& rRuby, const 
MSWordExportBase& rExport ):
+    m_nJC(0),
+    m_cDirective(0),
+    m_nRubyHeight(0),
+    m_nBaseHeight(0)
+{
+    switch ( rRuby.GetAdjustment() )
+    {
+        case css::text::RubyAdjust_LEFT:
+            m_nJC = 3;
+            m_cDirective = 'l';
+            break;
+        case css::text::RubyAdjust_CENTER:
+            //defaults to 0
+            break;
+        case css::text::RubyAdjust_RIGHT:
+            m_nJC = 4;
+            m_cDirective = 'r';
+            break;
+        case css::text::RubyAdjust_BLOCK:
+            m_nJC = 1;
+            m_cDirective = 'd';
+            break;
+        case css::text::RubyAdjust_INDENT_BLOCK:
+            m_nJC = 2;
+            m_cDirective = 'd';
+            break;
+        default:
+            OSL_ENSURE( false,"Unhandled Ruby justication code" );
+            break;
+    }
+
+    /*
+     MS needs to know the name and size of the font used in the ruby item,
+     but we could have written it in a mixture of asian and western
+     scripts, and each of these can be a different font and size than the
+     other, so we make a guess based upon the first character of the text,
+     defaulting to asian.
+     */
+    assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
+    sal_uInt16 nRubyScript = 
g_pBreakIt->GetBreakIter()->getScriptType(rRuby.GetText(), 0);
+
+    const SwTextRuby* pRubyText = rRuby.GetTextRuby();
+    const SwCharFormat* pFormat = pRubyText ? pRubyText->GetCharFormat() : 
nullptr;
+
+    if (pFormat)
+    {
+        const auto& rFont
+            = ItemGet<SvxFontItem>(*pFormat, GetWhichOfScript(RES_CHRATR_FONT, 
nRubyScript));
+        m_sFontFamily = rFont.GetFamilyName();
+
+        const auto& rHeight = ItemGet<SvxFontHeightItem>(
+            *pFormat, GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript));
+        m_nRubyHeight = rHeight.GetHeight();
+    }
+    else
+    {
+        /*Get defaults if no formatting on ruby text*/
+
+        const SfxItemPool* pPool = rNode.GetSwAttrSet().GetPool();
+        pPool = pPool ? pPool : &rExport.m_pDoc->GetAttrPool();
+
+
+        const auto& rFont
+            = DefaultItemGet<SvxFontItem>(*pPool, 
GetWhichOfScript(RES_CHRATR_FONT, nRubyScript));
+        m_sFontFamily = rFont.GetFamilyName();
+
+        const auto& rHeight = DefaultItemGet<SvxFontHeightItem>(
+            *pPool, GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript));
+        m_nRubyHeight = rHeight.GetHeight();
+    }
+
+    if (pRubyText)
+        nRubyScript
+            = g_pBreakIt->GetBreakIter()->getScriptType(rNode.GetText(), 
pRubyText->GetStart());
+    else
+        nRubyScript = i18n::ScriptType::ASIAN;
+
+    const SwAttrSet& rSet = rNode.GetSwAttrSet();
+    auto& rHeightItem = static_cast<const SvxFontHeightItem&>(
+        rSet.Get(GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript)));
+
+    m_nBaseHeight = rHeightItem.GetHeight();
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to