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 08986a606977764acc85d4ad61fcbefc0d4978a2
Author: Luboš Luňák <l.lu...@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 071900c..36956ce 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2135,35 +2135,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 d129dd2a863906ed05b34b01dd9ca23d5c1c6a22
Author: Luboš Luňák <l.lu...@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 7b3ae3f..e21eaef 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.cxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.cxx
@@ -117,6 +117,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 ::rtl::OUString & sText, bool 
vertical)
 {
     if( vertical )
diff --git a/writerfilter/source/dmapper/GraphicHelpers.hxx 
b/writerfilter/source/dmapper/GraphicHelpers.hxx
index f87b6f9..39f471b 100644
--- a/writerfilter/source/dmapper/GraphicHelpers.hxx
+++ b/writerfilter/source/dmapper/GraphicHelpers.hxx
@@ -21,14 +21,15 @@ public:
     static void setPositionOffset(const ::rtl::OUString & sText, bool 
vertical);
     static void setAlignH(const ::rtl::OUString & sText);
     static void setAlignV(const ::rtl::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 925aaa6..efcfa7e 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1216,9 +1216,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();
                 }
             }
         }
@@ -1233,9 +1233,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();
                 }
             }
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to