summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2018-02-04 23:45:09 +0800
committerMark Hung <marklh9@gmail.com>2018-02-13 13:26:14 +0100
commit3c1bfd952b7cf6b07b4d862e048146a9d245ec26 (patch)
tree43f3bfa67ea90ee46be9eeb759e9b8531bb4c9fb
parenta4e0d20c7eff8b053ec754b0a4b89dcb26636bf5 (diff)
docx: output ruby attributes properly.
Enclose ruby with run, output hps, hpsBaseText, hpsRaise, etc, ,make the size and script correct as much as possible. The ruby format in docx can be round-tripped now, so it is moved to ooxmlexport. Change-Id: I03797be54aeffeff016011ad8ec536cecf40064f Reviewed-on: https://gerrit.libreoffice.org/49509 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mark Hung <marklh9@gmail.com>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf49073.docx (renamed from sw/qa/extras/ooxmlimport/data/tdf49073.docx)bin17584 -> 17584 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport11.cxx19
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx19
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx80
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx10
5 files changed, 73 insertions, 55 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/tdf49073.docx b/sw/qa/extras/ooxmlexport/data/tdf49073.docx
index ddcbb62fbb36..ddcbb62fbb36 100644
--- a/sw/qa/extras/ooxmlimport/data/tdf49073.docx
+++ b/sw/qa/extras/ooxmlexport/data/tdf49073.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index d3cc7275a92e..134576b6275c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -20,6 +20,8 @@
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
+#include <com/sun/star/text/RubyAdjust.hpp>
+#include <com/sun/star/text/RubyPosition.hpp>
#include <sfx2/docfile.hxx>
@@ -208,6 +210,23 @@ DECLARE_OOXMLEXPORT_TEST(testTdf114882, "tdf114882.docx")
// fastserializer must not fail assertion because of mismatching elements
}
+DECLARE_OOXMLEXPORT_TEST(testTdf49073, "tdf49073.docx")
+{
+ // test case for Asisan phontic guide ( ruby text.)
+ sal_Unicode aRuby[3] = {0x304D,0x3082,0x3093};
+ OUString sRuby = OUString(aRuby, SAL_N_ELEMENTS(aRuby));
+ CPPUNIT_ASSERT_EQUAL(sRuby,getProperty<OUString>(getParagraph(1)->getStart(), "RubyText"));
+ OUString sStyle = getProperty<OUString>( getParagraph(1)->getStart(), "RubyCharStyleName");
+ uno::Reference<beans::XPropertySet> xPropertySet(getStyles("CharacterStyles")->getByName(sStyle), uno::UNO_QUERY );
+ CPPUNIT_ASSERT_EQUAL(5.f, getProperty<float>(xPropertySet, "CharHeight"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_CENTER) ,getProperty<sal_Int16>(getParagraph(2)->getStart(),"RubyAdjust"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_BLOCK) ,getProperty<sal_Int16>(getParagraph(3)->getStart(),"RubyAdjust"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_INDENT_BLOCK),getProperty<sal_Int16>(getParagraph(4)->getStart(),"RubyAdjust"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_LEFT) ,getProperty<sal_Int16>(getParagraph(5)->getStart(),"RubyAdjust"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_RIGHT) ,getProperty<sal_Int16>(getParagraph(6)->getStart(),"RubyAdjust"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyPosition::INTER_CHARACTER) ,getProperty<sal_Int16>(getParagraph(7)->getStart(),"RubyPosition"));
+}
+
DECLARE_OOXMLEXPORT_TEST(testTdf114703, "tdf114703.docx")
{
uno::Reference<container::XIndexAccess> xRules
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index a47803d60869..fc5a4034fc6c 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -46,8 +46,6 @@
#include <com/sun/star/text/XTextFrame.hpp>
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
-#include <com/sun/star/text/RubyAdjust.hpp>
-#include <com/sun/star/text/RubyPosition.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <com/sun/star/text/SizeType.hpp>
#include <com/sun/star/util/DateTime.hpp>
@@ -1045,23 +1043,6 @@ DECLARE_OOXMLIMPORT_TEST(testFdo87488, "fdo87488.docx")
}
}
-DECLARE_OOXMLIMPORT_TEST(testTdf49073, "tdf49073.docx")
-{
- // test case for Asisan phontic guide ( ruby text.)
- sal_Unicode aRuby[3] = {0x304D,0x3082,0x3093};
- OUString sRuby = OUString(aRuby, SAL_N_ELEMENTS(aRuby));
- CPPUNIT_ASSERT_EQUAL(sRuby,getProperty<OUString>(getParagraph(1)->getStart(), "RubyText"));
- OUString sStyle = getProperty<OUString>( getParagraph(1)->getStart(), "RubyCharStyleName");
- uno::Reference<beans::XPropertySet> xPropertySet(getStyles("CharacterStyles")->getByName(sStyle), uno::UNO_QUERY );
- CPPUNIT_ASSERT_EQUAL(5.f, getProperty<float>(xPropertySet, "CharHeight"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_CENTER) ,getProperty<sal_Int16>(getParagraph(2)->getStart(),"RubyAdjust"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_BLOCK) ,getProperty<sal_Int16>(getParagraph(3)->getStart(),"RubyAdjust"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_INDENT_BLOCK),getProperty<sal_Int16>(getParagraph(4)->getStart(),"RubyAdjust"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_LEFT) ,getProperty<sal_Int16>(getParagraph(5)->getStart(),"RubyAdjust"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyAdjust_RIGHT) ,getProperty<sal_Int16>(getParagraph(6)->getStart(),"RubyAdjust"));
- CPPUNIT_ASSERT_EQUAL(sal_Int16(text::RubyPosition::INTER_CHARACTER) ,getProperty<sal_Int16>(getParagraph(7)->getStart(),"RubyPosition"));
-}
-
DECLARE_OOXMLIMPORT_TEST(testTdf85232, "tdf85232.docx")
{
uno::Reference<drawing::XShapes> xShapes(getShapeByName("Group 219"), uno::UNO_QUERY);
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c4143c91a8c1..df6d32fa6253 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -952,6 +952,25 @@ void lcl_writeParagraphMarkerProperties(DocxAttributeOutput& rAttributeOutput, c
}
}
+const char *RubyAlignValues[] =
+{
+ "center",
+ "distributeLetter",
+ "distributeSpace",
+ "left",
+ "right",
+ "rightVertical"
+};
+
+
+const char *lclConvertWW8JCToOOXMLRubyAlign(sal_Int32 nJC)
+{
+ const sal_Int32 nElements = SAL_N_ELEMENTS(RubyAlignValues);
+ if ( nJC >=0 && nJC < nElements )
+ return RubyAlignValues[nJC];
+ return RubyAlignValues[0];
+}
+
}
void DocxAttributeOutput::EndParagraphProperties(const SfxItemSet& rParagraphMarkerProperties, const SwRedlineData* pRedlineData, const SwRedlineData* pRedlineParagraphMarkerDeleted, const SwRedlineData* pRedlineParagraphMarkerInserted)
@@ -2499,16 +2518,28 @@ void DocxAttributeOutput::RawText(const OUString& rText, rtl_TextEncoding /*eCha
void DocxAttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 nPos, const SwFormatRuby& rRuby )
{
+ WW8Ruby aWW8Ruby( rNode, rRuby, GetExport() );
SAL_INFO("sw.ww8", "TODO DocxAttributeOutput::StartRuby( const SwTextNode& rNode, const SwFormatRuby& rRuby )" );
EndRun( &rNode, nPos ); // end run before starting ruby to avoid nested runs, and overlap
assert(!m_closeHyperlinkInThisRun); // check that no hyperlink overlaps ruby
assert(!m_closeHyperlinkInPreviousRun);
+ m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->startElementNS( XML_w, XML_ruby, FSEND );
m_pSerializer->startElementNS( XML_w, XML_rubyPr, FSEND );
- // hps
- // hpsBaseText
- // hpsRaise
- // lid
+
+ m_pSerializer->singleElementNS( XML_w, XML_rubyAlign,
+ FSNS( XML_w, XML_val ), lclConvertWW8JCToOOXMLRubyAlign(aWW8Ruby.GetJC()), FSEND );
+ sal_uInt32 nHps = (aWW8Ruby.GetRubyHeight() + 5) / 10;
+ sal_uInt32 nHpsBaseText = (aWW8Ruby.GetBaseHeight() + 5) / 10;
+ m_pSerializer->singleElementNS( XML_w, XML_hps,
+ FSNS( XML_w, XML_val ), OString::number(nHps).getStr(), FSEND );
+
+ m_pSerializer->singleElementNS( XML_w, XML_hpsRaise,
+ FSNS( XML_w, XML_val ), OString::number(nHpsBaseText).getStr(), FSEND );
+
+ m_pSerializer->singleElementNS( XML_w, XML_hpsBaseText,
+ FSNS( XML_w, XML_val ), OString::number(nHpsBaseText).getStr(), FSEND );
+
lang::Locale aLocale( SwBreakIt::Get()->GetLocale(
rNode.GetLang( nPos ) ) );
OUString sLang( LanguageTag::convertToBcp47( aLocale) );
@@ -2516,41 +2547,23 @@ void DocxAttributeOutput::StartRuby( const SwTextNode& rNode, sal_Int32 nPos, co
FSNS( XML_w, XML_val ),
OUStringToOString( sLang, RTL_TEXTENCODING_UTF8 ).getStr( ), FSEND );
- OString sAlign ( "center" );
- switch ( rRuby.GetAdjustment( ) )
- {
- case css::text::RubyAdjust_LEFT:
- sAlign = OString( "left" );
- break;
- case css::text::RubyAdjust_CENTER:
- // Defaults to center
- break;
- case css::text::RubyAdjust_RIGHT:
- sAlign = OString( "right" );
- break;
- case css::text::RubyAdjust_BLOCK:
- sAlign = OString( "distributeLetter" );
- break;
- case css::text::RubyAdjust_INDENT_BLOCK:
- sAlign = OString( "distributeSpace" );
- break;
- default:
- break;
- }
- m_pSerializer->singleElementNS( XML_w, XML_rubyAlign,
- FSNS( XML_w, XML_val ), sAlign.getStr(), FSEND );
m_pSerializer->endElementNS( XML_w, XML_rubyPr );
m_pSerializer->startElementNS( XML_w, XML_rt, FSEND );
StartRun( nullptr, nPos );
StartRunProperties( );
- SwWW8AttrIter aAttrIt( m_rExport, rNode );
- aAttrIt.OutAttr( nPos, true );
- sal_uInt16 nStyle = m_rExport.GetId( rRuby.GetTextRuby()->GetCharFormat() );
- OString aStyleId(m_rExport.m_pStyles->GetStyleId(nStyle));
- m_pSerializer->singleElementNS( XML_w, XML_rStyle,
- FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND );
+ if (rRuby.GetTextRuby() && rRuby.GetTextRuby()->GetCharFormat())
+ {
+ const SwCharFormat* pFormat = rRuby.GetTextRuby()->GetCharFormat();
+ sal_uInt16 nScript = g_pBreakIt->GetBreakIter()->getScriptType(rRuby.GetText(), 0);
+ sal_uInt16 nWhichFont = (nScript == i18n::ScriptType::LATIN) ? RES_CHRATR_FONT : RES_CHRATR_CJK_FONT;
+ sal_uInt16 nWhichFontSize = (nScript == i18n::ScriptType::LATIN) ? RES_CHRATR_FONTSIZE : RES_CHRATR_CJK_FONTSIZE;
+
+ CharFont(ItemGet<SvxFontItem>(*pFormat, nWhichFont));
+ CharFontSize(ItemGet<SvxFontHeightItem>(*pFormat, nWhichFontSize));
+ CharFontSize(ItemGet<SvxFontHeightItem>(*pFormat, RES_CHRATR_CTL_FONTSIZE));
+ }
EndRunProperties( nullptr );
RunText( rRuby.GetText( ) );
@@ -2567,6 +2580,7 @@ void DocxAttributeOutput::EndRuby(const SwTextNode& rNode, sal_Int32 nPos)
EndRun( &rNode, nPos );
m_pSerializer->endElementNS( XML_w, XML_rubyBase );
m_pSerializer->endElementNS( XML_w, XML_ruby );
+ m_pSerializer->endElementNS( XML_w, XML_r );
StartRun(nullptr, nPos); // open Run again so OutputTextNode loop can close it
}
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 7a698f18907e..0a2d6128ce07 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3348,10 +3348,14 @@ WW8Ruby::WW8Ruby(const SwTextNode& rNode, const SwFormatRuby& rRuby, const MSWor
else
nRubyScript = i18n::ScriptType::ASIAN;
- const SwAttrSet& rSet = rNode.GetSwAttrSet();
- auto& rHeightItem = static_cast<const SvxFontHeightItem&>(
- rSet.Get(GetWhichOfScript(RES_CHRATR_FONTSIZE, nRubyScript)));
+ const OUString &rText = rNode.GetText();
+ sal_uInt16 nScript = i18n::ScriptType::LATIN;
+ if (!rText.isEmpty())
+ nScript = g_pBreakIt->GetBreakIter()->getScriptType(rText, 0);
+
+ sal_uInt16 nWhich = GetWhichOfScript(RES_CHRATR_FONTSIZE, nScript);
+ auto& rHeightItem = static_cast<const SvxFontHeightItem&>(rExport.GetItem(nWhich));
m_nBaseHeight = rHeightItem.GetHeight();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */