[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - 2 commits - sw/source writerfilter/source

Luboš Luňák l.lunak at suse.cz
Thu May 23 08:04:10 PDT 2013


 sw/source/filter/ww8/docxattributeoutput.cxx   |  116 ++++++++++++++++++++-----
 writerfilter/source/dmapper/GraphicHelpers.cxx |   23 ++++
 writerfilter/source/dmapper/GraphicHelpers.hxx |   11 +-
 writerfilter/source/dmapper/GraphicImport.cxx  |   12 +-
 4 files changed, 132 insertions(+), 30 deletions(-)

New commits:
commit 4f7c23741e18a88c2da0c615558e2a1d406fed31
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu May 23 16:32:44 2013 +0200

    improve exporting of picture alignment to docx
    
    Basing this on anchoring is wrong, as SwFmt{Hori/Vert}Orient seems to provide
    everything. Also try avoid hardcoding position if possible.
    
    Change-Id: I880bc5c3eeabdde9e52c0c16d1033e44e203a8a3

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index a233f12..27bd60f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2057,35 +2057,113 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
         m_pSerializer->singleElementNS( XML_wp, XML_simplePos, XML_x, "0", XML_y, "0", FSEND ); // required, unused
         const char* relativeFromH;
         const char* relativeFromV;
-        switch( pFrmFmt->GetAnchor().GetAnchorId())
+        const char* alignH = NULL;
+        const char* alignV = NULL;
+        switch (pFrmFmt->GetVertOrient().GetRelationOrient() )
         {
-            case FLY_AT_PAGE:
-                relativeFromV = relativeFromH = "page";
+            case text::RelOrientation::PAGE_PRINT_AREA:
+                relativeFromV = "margin";
                 break;
-            case FLY_AT_PARA:
-                relativeFromH = "column";
+            case text::RelOrientation::PAGE_FRAME:
+                relativeFromV = "page";
+                break;
+            case text::RelOrientation::FRAME:
                 relativeFromV = "paragraph";
                 break;
-            case FLY_AT_CHAR:
+            case text::RelOrientation::TEXT_LINE:
             default:
-                relativeFromH = "character";
                 relativeFromV = "line";
                 break;
-        };
-        Point pos( 0, 0 );
-        if( const SwFlyFrmFmt* flyfmt = dynamic_cast<const SwFlyFrmFmt*>(pFrmFmt)) // TODO is always true?
-            pos = flyfmt->GetAnchoredObj()->GetCurrRelPos();
-        OString x( OString::valueOf( TwipsToEMU( pos.X())));
-        OString y( OString::valueOf( TwipsToEMU( pos.Y())));
+        }
+        switch (pFrmFmt->GetVertOrient().GetVertOrient() )
+        {
+            case text::VertOrientation::TOP:
+            case text::VertOrientation::CHAR_TOP:
+            case text::VertOrientation::LINE_TOP:
+                if( pFrmFmt->GetVertOrient().GetRelationOrient() == text::RelOrientation::TEXT_LINE)
+                    alignV = "bottom";
+                else
+                    alignV = "top";
+                break;
+            case text::VertOrientation::BOTTOM:
+            case text::VertOrientation::CHAR_BOTTOM:
+            case text::VertOrientation::LINE_BOTTOM:
+                if( pFrmFmt->GetVertOrient().GetRelationOrient() == text::RelOrientation::TEXT_LINE)
+                    alignV = "top";
+                else
+                    alignV = "bottom";
+                break;
+            case text::VertOrientation::CENTER:
+            case text::VertOrientation::CHAR_CENTER:
+            case text::VertOrientation::LINE_CENTER:
+                alignV = "center";
+                break;
+            default:
+                break;
+        }
+        switch (pFrmFmt->GetHoriOrient().GetRelationOrient() )
+        {
+            case text::RelOrientation::PAGE_PRINT_AREA:
+                relativeFromH = "margin";
+                break;
+            case text::RelOrientation::PAGE_FRAME:
+                relativeFromH = "page";
+                break;
+            case text::RelOrientation::CHAR:
+                relativeFromH = "character";
+                break;
+            case text::RelOrientation::FRAME:
+            default:
+                relativeFromH = "column";
+                break;
+        }
+        switch (pFrmFmt->GetHoriOrient().GetHoriOrient() )
+        {
+            case text::HoriOrientation::LEFT:
+                alignH = "left";
+                break;
+            case text::HoriOrientation::RIGHT:
+                alignH = "right";
+                break;
+            case text::HoriOrientation::CENTER:
+                alignH = "center";
+                break;
+            case text::HoriOrientation::INSIDE:
+                alignH = "inside";
+                break;
+            case text::HoriOrientation::OUTSIDE:
+                alignH = "outside";
+                break;
+            default:
+                break;
+        }
         m_pSerializer->startElementNS( XML_wp, XML_positionH, XML_relativeFrom, relativeFromH, FSEND );
-        m_pSerializer->startElementNS( XML_wp, XML_posOffset, FSEND );
-        m_pSerializer->write( x.getStr() );
-        m_pSerializer->endElementNS( XML_wp, XML_posOffset );
+        if( alignH != NULL )
+        {
+            m_pSerializer->startElementNS( XML_wp, XML_align, FSEND );
+            m_pSerializer->write( alignH );
+            m_pSerializer->endElementNS( XML_wp, XML_align );
+        }
+        else
+        {
+            m_pSerializer->startElementNS( XML_wp, XML_posOffset, FSEND );
+            m_pSerializer->write( TwipsToEMU( pFrmFmt->GetHoriOrient().GetPos()));
+            m_pSerializer->endElementNS( XML_wp, XML_posOffset );
+        }
         m_pSerializer->endElementNS( XML_wp, XML_positionH );
         m_pSerializer->startElementNS( XML_wp, XML_positionV, XML_relativeFrom, relativeFromV, FSEND );
-        m_pSerializer->startElementNS( XML_wp, XML_posOffset, FSEND );
-        m_pSerializer->write( y.getStr() );
-        m_pSerializer->endElementNS( XML_wp, XML_posOffset );
+        if( alignV != NULL )
+        {
+            m_pSerializer->startElementNS( XML_wp, XML_align, FSEND );
+            m_pSerializer->write( alignV );
+            m_pSerializer->endElementNS( XML_wp, XML_align );
+        }
+        else
+        {
+            m_pSerializer->startElementNS( XML_wp, XML_posOffset, FSEND );
+            m_pSerializer->write( TwipsToEMU( pFrmFmt->GetVertOrient().GetPos()));
+            m_pSerializer->endElementNS( XML_wp, XML_posOffset );
+        }
         m_pSerializer->endElementNS( XML_wp, XML_positionV );
     }
     else
commit 6ef6cf6584f01adf58ee69f3f7c77fa828712964
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue May 21 15:56:12 2013 +0200

    map docx line alignment properly to writer's line-of-text align (bnc#820792)
    
    Apparently the top/bottom line of text alignment in writer is backwards
    compared to all others, while alignment to the top of a page puts
    an object's top edge at the top of the page, top of line of text
    puts the object on top of the line (i.e. bottom edge of the object
    at the line). The handling of NS_rtf::LN_YAlign suggests that swapping
    bottom and top in the input filter is the right way of handling this.
    
    Change-Id: I916c8ea0f2fd00de3e17b16b31433c9b6ba92e64

diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx
index 4564f3a..9a259b9 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.cxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.cxx
@@ -134,6 +134,29 @@ void PositionHandler::lcl_sprm( Sprm& )
 {
 }
 
+sal_Int16 PositionHandler::orientation() const
+{
+    if( m_nRelation == text::RelOrientation::TEXT_LINE )
+    { // It appears that to 'line of text' alignment is backwards to other alignments,
+      // 'top' meaning putting on top of the line instead of having top at the line.
+        if( m_nOrient == text::VertOrientation::TOP )
+            return text::VertOrientation::BOTTOM;
+        else if( m_nOrient == text::VertOrientation::BOTTOM )
+            return text::VertOrientation::TOP;
+    }
+    return m_nOrient;
+}
+
+sal_Int16 PositionHandler::relation() const
+{
+    return m_nRelation;
+}
+
+sal_Int32 PositionHandler::position() const
+{
+    return m_nPosition;
+}
+
 void PositionHandler::setPositionOffset(const OUString & sText, bool vertical)
 {
     if( vertical )
diff --git a/writerfilter/source/dmapper/GraphicHelpers.hxx b/writerfilter/source/dmapper/GraphicHelpers.hxx
index f60da10..e3e4be6 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.hxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.hxx
@@ -39,14 +39,15 @@ public:
     static void setPositionOffset(const OUString & sText, bool vertical);
     static void setAlignH(const OUString & sText);
     static void setAlignV(const OUString & sText);
-
-    sal_Int16 m_nOrient;
-    sal_Int16 m_nRelation;
-    sal_Int32 m_nPosition;
-
+    sal_Int16 orientation() const;
+    sal_Int16 relation() const;
+    sal_Int32 position() const;
  private:
     virtual void lcl_attribute( Id aName, Value& rVal );
     virtual void lcl_sprm( Sprm& rSprm );
+    sal_Int16 m_nOrient;
+    sal_Int16 m_nRelation;
+    sal_Int32 m_nPosition;
     static int savedPositionOffsetV, savedPositionOffsetH;
     static int savedAlignV, savedAlignH;
 };
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 1dd4f14..0f7865c 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1221,9 +1221,9 @@ void GraphicImport::lcl_sprm(Sprm & rSprm)
                 pProperties->resolve( *pHandler );
                 if( !m_pImpl->bUseSimplePos )
                 {
-                    m_pImpl->nHoriRelation = pHandler->m_nRelation;
-                    m_pImpl->nHoriOrient = pHandler->m_nOrient;
-                    m_pImpl->nLeftPosition = pHandler->m_nPosition;
+                    m_pImpl->nHoriRelation = pHandler->relation();
+                    m_pImpl->nHoriOrient = pHandler->orientation();
+                    m_pImpl->nLeftPosition = pHandler->position();
                 }
             }
         }
@@ -1238,9 +1238,9 @@ void GraphicImport::lcl_sprm(Sprm & rSprm)
                 pProperties->resolve( *pHandler );
                 if( !m_pImpl->bUseSimplePos )
                 {
-                    m_pImpl->nVertRelation = pHandler->m_nRelation;
-                    m_pImpl->nVertOrient = pHandler->m_nOrient;
-                    m_pImpl->nTopPosition = pHandler->m_nPosition;
+                    m_pImpl->nVertRelation = pHandler->relation();
+                    m_pImpl->nVertOrient = pHandler->orientation();
+                    m_pImpl->nTopPosition = pHandler->position();
                 }
             }
         }


More information about the Libreoffice-commits mailing list