summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2013-04-21 14:02:49 +0200
committerTomaž Vajngerl <quikee@gmail.com>2013-04-21 21:55:46 +0200
commit75f60bff0811b521b39c3d5cddc35e06556ab25e (patch)
tree9c285b1bc0fed875f7bfcdcd9c68be1e86533219
parent6c7e476ae6b6ff56b81ff19ef7dd0e8a9083a257 (diff)
Add rotation for PNG and GIF to GraphicNativeRotation.
Rotation for PNG and GIF format perform by exporting and importing of the Graphic. This is a "fallback" way to perform graphic rotation and the easiest to do for lossless raster formats. Change-Id: I31efad9106b5cfbd1d7c6c5063726c455d05f934
-rw-r--r--sw/source/ui/uiview/view2.cxx11
-rw-r--r--vcl/inc/vcl/GraphicNativeMetadata.hxx4
-rw-r--r--vcl/inc/vcl/GraphicNativeTransform.hxx7
-rw-r--r--vcl/source/filter/GraphicNativeMetadata.cxx4
-rw-r--r--vcl/source/filter/GraphicNativeTransform.cxx60
5 files changed, 72 insertions, 14 deletions
diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx
index 3cf7c4acb953..b48e4033f4a4 100644
--- a/sw/source/ui/uiview/view2.cxx
+++ b/sw/source/ui/uiview/view2.cxx
@@ -177,9 +177,7 @@ static void lcl_SetAllTextToDefaultLanguage( SwWrtShell &rWrtSh, sal_uInt16 nWhi
}
}
-/*---------------------------------------------------------------------------
- Beschreibung: String fuer die Seitenanzeige in der Statusbar basteln.
- ----------------------------------------------------------------------------*/
+/* Create string for showing of page in statusbar */
String SwView::GetPageStr( sal_uInt16 nPg, sal_uInt16 nLogPg,
const String& rDisplay )
{
@@ -220,16 +218,17 @@ int SwView::InsertGraphic( const String &rPath, const String &rFilter,
if( GRFILTER_OK == nRes )
{
GraphicNativeMetadata aMetadata;
- if (aMetadata.Read(aGrf))
+ if (aMetadata.read(aGrf))
{
- if (aMetadata.GetRotation() != 0)
+ sal_uInt16 aRotation = aMetadata.getRotation();
+ if (aRotation != 0)
{
OUString aMessage("This image is rotated. Would you like LibreOffice to rotate it into standard orientation?");
QueryBox aQueryBox(GetWindow(), WB_YES_NO | WB_DEF_YES, aMessage);
if (aQueryBox.Execute() == RET_YES)
{
GraphicNativeTransform aTransform(aGrf);
- aTransform.Rotate(aMetadata.GetRotation());
+ aTransform.rotate( aRotation );
}
}
}
diff --git a/vcl/inc/vcl/GraphicNativeMetadata.hxx b/vcl/inc/vcl/GraphicNativeMetadata.hxx
index 711f81a290b1..ab5b767ceb15 100644
--- a/vcl/inc/vcl/GraphicNativeMetadata.hxx
+++ b/vcl/inc/vcl/GraphicNativeMetadata.hxx
@@ -30,8 +30,8 @@ public:
GraphicNativeMetadata();
virtual ~GraphicNativeMetadata();
- bool Read(Graphic& rGraphic);
- sal_uInt16 GetRotation();
+ bool read(Graphic& rGraphic);
+ sal_uInt16 getRotation();
};
#endif //_GRAPHICNATIVEMETADATA_HXX
diff --git a/vcl/inc/vcl/GraphicNativeTransform.hxx b/vcl/inc/vcl/GraphicNativeTransform.hxx
index ed6b70296e75..40b661ba58a0 100644
--- a/vcl/inc/vcl/GraphicNativeTransform.hxx
+++ b/vcl/inc/vcl/GraphicNativeTransform.hxx
@@ -25,11 +25,16 @@
class VCL_DLLPUBLIC GraphicNativeTransform
{
Graphic& mrGraphic;
+
+ bool rotateJPEG (sal_uInt16 aRotation);
+ bool rotateSVG (sal_uInt16 aRotation);
+ bool rotateGeneric (sal_uInt16 aRotation, sal_uInt32 aType);
+
public:
GraphicNativeTransform(Graphic& rGraphic);
virtual ~GraphicNativeTransform();
- bool Rotate(sal_uInt16 aRotation);
+ bool rotate(sal_uInt16 aRotation);
};
#endif //_GRAPHICNATIVETRANSFORM_HXX
diff --git a/vcl/source/filter/GraphicNativeMetadata.cxx b/vcl/source/filter/GraphicNativeMetadata.cxx
index c147f5461423..1339ec81c854 100644
--- a/vcl/source/filter/GraphicNativeMetadata.cxx
+++ b/vcl/source/filter/GraphicNativeMetadata.cxx
@@ -30,12 +30,12 @@ GraphicNativeMetadata::GraphicNativeMetadata() :
GraphicNativeMetadata::~GraphicNativeMetadata()
{}
-sal_uInt16 GraphicNativeMetadata::GetRotation()
+sal_uInt16 GraphicNativeMetadata::getRotation()
{
return mRotation;
}
-bool GraphicNativeMetadata::Read(Graphic& rGraphic)
+bool GraphicNativeMetadata::read(Graphic& rGraphic)
{
GfxLink aLink = rGraphic.GetLink();
if ( aLink.GetType() != GFX_LINK_TYPE_NATIVE_JPG )
diff --git a/vcl/source/filter/GraphicNativeTransform.cxx b/vcl/source/filter/GraphicNativeTransform.cxx
index 6115e9353947..9759592b8c96 100644
--- a/vcl/source/filter/GraphicNativeTransform.cxx
+++ b/vcl/source/filter/GraphicNativeTransform.cxx
@@ -20,6 +20,8 @@
#include <vcl/GraphicNativeTransform.hxx>
#include <vcl/gfxlink.hxx>
+#include <vcl/cvtgrf.hxx>
+
#include "jpeg/Exif.hxx"
#include "jpeg/JpegTransform.hxx"
@@ -31,7 +33,7 @@ GraphicNativeTransform::GraphicNativeTransform(Graphic& rGraphic) :
GraphicNativeTransform::~GraphicNativeTransform()
{}
-bool GraphicNativeTransform::Rotate(sal_uInt16 aRotation)
+bool GraphicNativeTransform::rotate(sal_uInt16 aRotation)
{
if (aRotation == 0)
return true;
@@ -40,8 +42,60 @@ bool GraphicNativeTransform::Rotate(sal_uInt16 aRotation)
return false;
GfxLink aLink = mrGraphic.GetLink();
- if ( aLink.GetType() != GFX_LINK_TYPE_NATIVE_JPG )
- return false;
+ if ( aLink.GetType() == GFX_LINK_TYPE_NATIVE_JPG )
+ {
+ return rotateJPEG(aRotation);
+ }
+ else if ( aLink.GetType() == GFX_LINK_TYPE_NATIVE_SVG )
+ {
+ return rotateSVG(aRotation);
+ }
+ else if ( aLink.GetType() == GFX_LINK_TYPE_NATIVE_PNG )
+ {
+ return rotateGeneric(aRotation, CVT_PNG);
+ }
+ else if ( aLink.GetType() == GFX_LINK_TYPE_NATIVE_GIF )
+ {
+ return rotateGeneric(aRotation, CVT_PNG);
+ }
+ return false;
+}
+
+bool GraphicNativeTransform::rotateGeneric(sal_uInt16 aRotation, sal_uInt32 aType)
+{
+ BitmapEx aBitmap = mrGraphic.GetBitmapEx();
+ aBitmap.Rotate(aRotation, COL_BLACK);
+
+ SvMemoryStream aStream;
+ GraphicConverter::Export(aStream, aBitmap, aType);
+ aStream.Seek( STREAM_SEEK_TO_BEGIN );
+
+ Graphic aNewGraphic;
+ GraphicConverter::Import(aStream, aNewGraphic, aType);
+
+ mrGraphic = aNewGraphic;
+ return true;
+}
+
+bool GraphicNativeTransform::rotateSVG(sal_uInt16 aRotation)
+{
+ GDIMetaFile aGDIMetafile = mrGraphic.GetGDIMetaFile();
+ //aGDIMetafile.Rotate(aRotation);
+
+ SvMemoryStream aStream;
+ GraphicConverter::Export(aStream, aGDIMetafile, CVT_SVG);
+ aStream.Seek( STREAM_SEEK_TO_BEGIN );
+
+ Graphic aNewGraphic;
+ GraphicConverter::Import(aStream, aNewGraphic, CVT_SVG);
+
+ mrGraphic = aNewGraphic;
+ return true;
+}
+
+bool GraphicNativeTransform::rotateJPEG(sal_uInt16 aRotation)
+{
+ GfxLink aLink = mrGraphic.GetLink();
sal_uInt32 aDataSize = aLink.GetDataSize();
sal_uInt8* aInputBuffer = new sal_uInt8[aDataSize];