writerfilter/Library_rtftok.mk | 1 + writerfilter/source/rtftok/rtfdocumentimpl.cxx | 25 ++++++++++++++++++++++++- writerfilter/source/rtftok/rtfdocumentimpl.hxx | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-)
New commits: commit 68e458cef973fcf568b8efa5614ee978e8ea9d55 Author: Miklos Vajna <vmik...@frugalware.org> Date: Tue Feb 7 16:56:27 2012 +0100 n#192129 fix RTF import of PNG images with bogus width/height For example Apache FOP generates RTF output where the \picw and \pich values are even negative, SvxRTFParser::ReadBmpData() used the same trick to solve the issue. Signed-off-by: Cédric Bosdonnat <cedric.bosdon...@free.fr> diff --git a/writerfilter/Library_rtftok.mk b/writerfilter/Library_rtftok.mk index 3835a5d..1afdd27 100644 --- a/writerfilter/Library_rtftok.mk +++ b/writerfilter/Library_rtftok.mk @@ -52,6 +52,7 @@ $(eval $(call gb_Library_add_linked_libs,rtftok,\ cppuhelper \ oox \ sal \ + svt \ ucbhelper \ utl \ tl \ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index a96d821..e87e880 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -41,6 +41,10 @@ #include <unotools/ucbstreamhelper.hxx> #include <unotools/streamwrap.hxx> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <rtl/oustringostreaminserter.hxx> +#include <vcl/graph.hxx> +#include <svtools/grfmgr.hxx> +#include <vcl/svapp.hxx> #include <doctok/sprmids.hxx> // NS_sprm namespace #include <doctok/resourceids.hxx> // NS_rtf namespace @@ -584,6 +588,20 @@ int RTFDocumentImpl::resolvePict(bool bInline) aExtHeader.yExt = m_aStates.top().aPicture.nHeight; OUString aGraphicUrl = m_pGraphicHelper->importGraphicObject(xInputStream, &aExtHeader); + if (m_aStates.top().aPicture.nStyle == BMPSTYLE_PNG) + { + // In case of PNG, the real size is known, don't use the values + // provided by picw and pich. + OString aURLBS(OUStringToOString(aGraphicUrl, RTL_TEXTENCODING_UTF8)); + const char aURLBegin[] = "vnd.sun.star.GraphicObject:"; + Graphic aGraphic = GraphicObject(aURLBS.copy(RTL_CONSTASCII_LENGTH(aURLBegin))).GetTransformedGraphic(); + Size aSize(aGraphic.GetPrefSize()); + MapMode aMap(MAP_100TH_MM); + aSize = Application::GetDefaultDevice()->PixelToLogic( aSize, aMap ); + m_aStates.top().aPicture.nWidth = aSize.Width(); + m_aStates.top().aPicture.nHeight = aSize.Height(); + } + // Wrap it in an XShape. uno::Reference<drawing::XShape> xShape; OUString aService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicObjectShape")); @@ -1910,6 +1928,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_FORMSHADE: // Noop, this is the default in Writer. break; + case RTF_PNGBLIP: + m_aStates.top().aPicture.nStyle = BMPSTYLE_PNG; + break; case RTF_POSYT: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_top; break; case RTF_POSYB: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_bottom; break; case RTF_POSYC: m_aStates.top().aFrame.nVertAlign = NS_ooxml::LN_Value_wordprocessingml_ST_YAlign_center; break; @@ -1929,6 +1950,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) case RTF_POSXO: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_outside; break; case RTF_POSXL: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_left; break; case RTF_POSXR: m_aStates.top().aFrame.nHoriAlign = NS_ooxml::LN_Value_wordprocessingml_ST_XAlign_right; break; + default: #if OSL_DEBUG_LEVEL > 1 OSL_TRACE("%s: TODO handle flag '%s'", OSL_THIS_FUNC, lcl_RtfToString(nKeyword)); @@ -3313,7 +3335,8 @@ RTFPicture::RTFPicture() nCropB(0), nCropL(0), nCropR(0), - eWMetafile(0) + eWMetafile(0), + nStyle(BMPSTYLE_NONE) { } diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 12d414c..90ecc98 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -150,6 +150,12 @@ namespace writerfilter { FORMFIELD_LIST }; + enum RTFBmpStyles + { + BMPSTYLE_NONE, + BMPSTYLE_PNG + }; + /// A buffer storing dmapper calls. typedef std::deque< std::pair<RTFBufferTypes, RTFValue::Pointer_t> > RTFBuffer_t; @@ -184,6 +190,7 @@ namespace writerfilter { sal_uInt16 nScaleX, nScaleY; short nCropT, nCropB, nCropL, nCropR; sal_uInt16 eWMetafile; + RTFBmpStyles nStyle; }; /// Stores the properties of a frame
_______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits