diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-02-10 09:49:16 +0000 |
---|---|---|
committer | Adolfo Jayme Barrientos <fitojb@ubuntu.com> | 2015-02-20 13:02:36 +0000 |
commit | f2c562a64da925d96260939181574770224dadad (patch) | |
tree | b30dd1ba92a266a95d61774d34f82a60091acb12 | |
parent | dd925ae885eea0fa84730196d4df64ca9b9584d1 (diff) |
Resolves: tdf#83073 use loaded graphic's width/height as defaults
(cherry picked from commit 4327ee505f8507f653c8f4db9ac7503db2e15c3a)
Conflicts:
sw/source/filter/html/htmlgrin.cxx
Change-Id: Idad25f82d884c40c55b886fd7634a6c6e51693c4
Reviewed-on: https://gerrit.libreoffice.org/14394
Tested-by: Michael Stahl <mstahl@redhat.com>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
(cherry picked from commit dd53735c5fe98fa4f8da4bf214a04b7883bf73c8)
Reviewed-on: https://gerrit.libreoffice.org/14426
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
-rw-r--r-- | sw/source/filter/html/htmlgrin.cxx | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 69862008cbfb..bf2e17a5d797 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -312,6 +312,7 @@ void SwHTMLParser::InsertImage() OUString sGrfNm; sal_Int16 eVertOri = text::VertOrientation::TOP; sal_Int16 eHoriOri = text::HoriOrientation::NONE; + bool bWidthProvided=false, bHeightProvided=false; long nWidth=0, nHeight=0; long nVSpace=0, nHSpace=0; @@ -361,6 +362,7 @@ void SwHTMLParser::InsertImage() bPrcWidth = (rOption.GetString().indexOf('%') != -1); if( bPrcWidth && nWidth>100 ) nWidth = 100; + bWidthProvided = true; break; case HTML_O_HEIGHT: // erstmal nur als Pixelwerte merken! @@ -368,6 +370,7 @@ void SwHTMLParser::InsertImage() bPrcHeight = (rOption.GetString().indexOf('%') != -1); if( bPrcHeight && nHeight>100 ) nHeight = 100; + bHeightProvided = true; break; case HTML_O_VSPACE: nVSpace = rOption.GetNumber(); @@ -461,6 +464,38 @@ IMAGE_SETEVENT: } } + Graphic aGraphic; + INetURLObject aGraphicURL( sGrfNm ); + if( aGraphicURL.GetProtocol() == INET_PROT_DATA ) + { + std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData()); + if (pStream) + { + if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream)) + sGrfNm = ""; + } + } + // sBaseURL is empty if the source is clipboard + else if (sBaseURL.isEmpty()) + { + if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL)) + sGrfNm = ""; + } + + if (!sGrfNm.isEmpty()) + { + aGraphic.SetDefaultType(); + } + + if (!bHeightProvided || !bWidthProvided) + { + Size aPixelSize = aGraphic.GetSizePixel(Application::GetDefaultDevice()); + if (!bWidthProvided) + nWidth = aPixelSize.Width(); + if (!bHeightProvided) + nHeight = aPixelSize.Height(); + } + SfxItemSet aItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() ); SvxCSS1PropertyInfo aPropInfo; if( HasStyleOptions( aStyle, aId, aClass ) ) @@ -694,28 +729,6 @@ IMAGE_SETEVENT: aFrmSize.SetHeightPercent( nPrcHeight ); aFrmSet.Put( aFrmSize ); - Graphic aGraphic; - INetURLObject aGraphicURL( sGrfNm ); - if( aGraphicURL.GetProtocol() == INET_PROT_DATA ) - { - std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData()); - if (pStream) - { - if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream)) - sGrfNm = ""; - } - } - // sBaseURL is empty if the source is clipboard - else if (sBaseURL.isEmpty()) - { - if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aGraphicURL)) - sGrfNm = ""; - } - if (!sGrfNm.isEmpty()) - { - aGraphic.SetDefaultType(); - } - // passing empty sGrfNm here, means we don't want the graphic to be linked SwFrmFmt *pFlyFmt = pDoc->getIDocumentContentOperations().Insert( *pPam, sGrfNm, aEmptyOUStr, &aGraphic, &aFrmSet, NULL, NULL ); @@ -739,10 +752,10 @@ IMAGE_SETEVENT: if( !sAltNm.isEmpty() ) pGrfNd->SetTitle( sAltNm ); - if( bSetTwipSize ) - pGrfNd->SetTwipSize( aGrfSz ); + if( bSetTwipSize ) + pGrfNd->SetTwipSize( aGrfSz ); - pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize ); + pGrfNd->SetChgTwipSize( bChangeFrmSize, bChangeFrmSize ); if( bSetScaleImageMap ) pGrfNd->SetScaleImageMap( true ); |