sw/qa/extras/ww8export/data/tdf120412_proportionalEscapement.odt |binary
 sw/qa/extras/ww8export/ww8export3.cxx                            |   13 +++++-
 sw/source/filter/ww8/ww8par6.cxx                                 |   20 
++++++++--
 3 files changed, 27 insertions(+), 6 deletions(-)

New commits:
commit 227100ff4e5560c09c5a822052fc5ada541b8cc5
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Nov 7 15:22:08 2019 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Nov 18 09:25:35 2019 +0100

    related tdf#120412 ww8import: allow > 100% escapement, fix calculation
    
    On import, it was calculating the escapement before reading
    the character size. If there is a fontsize SPRM in the
    character run, make sure that is processed first.
    
    Also, use the new MAX_*_ESC values since 100% is not nearly
    enough as a maximum.
    
    I looked for a mechanism that could delay processing, but
    found nothing. I thought about creating such a mechanism,
    but that could get extremely complicated, as loops would
    need to be detected (co-dependencies, etc). In the
    end, it seems likely that SOME function would need to be
    re-run (for example make Read_SubSuperProp runAgain at
    the end of the character properties) since there
    (likely) is no guarantee of the order of SPRMs.
    From my code-reading, it looks like Read_Fontsize is
    re-entrant-able, so that seems like the simplest
    solution in this case. This is mature code, so
    no real call for creating new mechanisms...
    
    Change-Id: I1269989c74cf34e38f8db77bd6fc510e395ee864
    Reviewed-on: https://gerrit.libreoffice.org/82248
    Reviewed-by: Justin Luth <justin_l...@sil.org>
    Tested-by: Justin Luth <justin_l...@sil.org>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ww8export/data/tdf120412_proportionalEscapement.odt 
b/sw/qa/extras/ww8export/data/tdf120412_proportionalEscapement.odt
new file mode 100644
index 000000000000..ecd5841a8e66
Binary files /dev/null and 
b/sw/qa/extras/ww8export/data/tdf120412_proportionalEscapement.odt differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 95520e563155..96940648ad2b 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -180,8 +180,17 @@ DECLARE_WW8EXPORT_TEST(testTdf127316_autoEscapement, 
"tdf127316_autoEscapement.o
     // Automatic escapement SHOULD BE limited by the font bottom line(?)
     // and so the calculations ought to be different. There is room for a lot 
of export improvement here.
     // Negative escapements (subscripts) were decreasing by 1% every 
round-trip due to bad manual rounding.
-    // The actual number of 33% isn't so important here, but test that it is 
stable across multiple round-trips.
-    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Did you fix or break me?", -33.f, 
getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
+    // The actual number of 50% isn't so important here, but test that it is 
stable across multiple round-trips.
+    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Did you fix or break me?", -50.f, 
getProperty<float>(getRun(xPara, 2), "CharEscapement"), 1);
+}
+
+DECLARE_WW8EXPORT_TEST(testTdf120412_proportionalEscapement, 
"tdf120412_proportionalEscapement.odt")
+{
+    uno::Reference<text::XTextRange> xPara = getParagraph(2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.f, getProperty<float>(getRun(xPara, 2, 
"Base"), "CharEscapement"), 0);
+    // Import was limiting to 100%. And export based the position on the 
original height, not the proportional height.
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( 150.f, getProperty<float>(getRun(xPara, 
3,"Super"), "CharEscapement"), 2);
+    CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
 DECLARE_WW8EXPORT_TEST(testTdf121111_fillStyleNone, 
"tdf121111_fillStyleNone.docx")
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 72e5f77db274..f0d93a16044f 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3448,6 +3448,15 @@ void SwWW8ImplReader::Read_SubSuperProp( sal_uInt16, 
const sal_uInt8* pData, sho
         return;
     }
 
+    // if the fontsize for these characters is specified, make sure it is 
updated first
+    if ( m_xPlcxMan )
+    {
+        const sal_uInt16 nFontsizeID = m_bVer67 ? NS_sprm::v6::sprmCHps : 
NS_sprm::sprmCHps;
+        const SprmResult aFontsize = m_xPlcxMan->GetChpPLCF()->HasSprm( 
nFontsizeID );
+        if ( aFontsize.pSprm && aFontsize.nRemainingData )
+            Read_FontSize(nFontsizeID, aFontsize.pSprm, 
aFontsize.nRemainingData);
+    }
+
     // font position in HalfPoints
     short nPos = eVersion <= ww::eWW2 ? static_cast< sal_Int8 >( *pData ) : 
SVBT16ToInt16( pData );
     sal_Int32 nPos2 = nPos * ( 10 * 100 );      // HalfPoints in 100 * tw
@@ -3460,10 +3469,10 @@ void SwWW8ImplReader::Read_SubSuperProp( sal_uInt16, 
const sal_uInt8* pData, sho
     if (pF != nullptr && pF->GetHeight() != 0)
         nHeight = pF->GetHeight();
     nPos2 /= nHeight;                       // ... now in % (rounded)
-    if( nPos2 > 100 )                       // for safety
-        nPos2 = 100;
-    if( nPos2 < -100 )
-        nPos2 = -100;
+    if( nPos2 > MAX_ESC_POS )
+        nPos2 = MAX_ESC_POS;
+    if( nPos2 < -MAX_ESC_POS )
+        nPos2 = -MAX_ESC_POS;
     SvxEscapementItem aEs( static_cast<short>(nPos2), 100, 
RES_CHRATR_ESCAPEMENT );
     NewAttr( aEs );
 }
@@ -3833,6 +3842,9 @@ void SwWW8ImplReader::closeFont(sal_uInt16 nId)
 */
 void SwWW8ImplReader::Read_FontCode( sal_uInt16 nId, const sal_uInt8* pData, 
short nLen )
 {
+    //Note: this function needs to be able to run multiple times on the same 
data.
+    //It is called by Read_SubSuperProp to ensure that the current fontsize is 
known.
+
     if (!m_bSymbol)           // if bSymbol, the symbol's font
     {                       // (see sprmCSymbol) is valid!
         switch( nId )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to