[Date Prev][Date Next][Thread Prev][Thread Next][Thread Index]

[XaraXtreme-commits] Commit Complete



Commit by  : luke
Repository : xara
Revision   : 1760
Date       : Fri Sep 22 11:13:34 BST 2006

Changed paths:
   M /Trunk/XaraLX/Kernel/bitfilt.cpp
   M /Trunk/XaraLX/Kernel/bitfilt.h
   M /Trunk/XaraLX/Kernel/filters.cpp
   M /Trunk/XaraLX/wxOil/xrc/EN/bmpres-strings.xrc

Some fixes for bitmap import, including zoom to large bitmaps (with warning) and fix alignment to pixel grid


Diff:
Index: Trunk/XaraLX/Kernel/filters.cpp
===================================================================
--- Trunk/XaraLX/Kernel/filters.cpp	(revision 1759)
+++ Trunk/XaraLX/Kernel/filters.cpp	(revision 1760)
@@ -4418,6 +4418,7 @@
 	DocRect SpreadRect = pPos->pSpread->GetPasteboardRect();
 	pPos->pSpread->DocCoordToSpreadCoord(&SpreadRect);
 
+#if defined( DODGY_BITMAP_POS_CODE )
 	// Now check that the bounding rectangle is small enough to fit on the spread...
 	if ((BoundsRect.Width() > SpreadRect.Width()) ||
 		(BoundsRect.Height() > SpreadRect.Height()))
@@ -4427,6 +4428,7 @@
 		Offset->y = 0;
 		return FALSE;
 	}
+#endif
 
 	// Bounding box should be centred on drop point
 	DocCoord Centre;
@@ -4447,11 +4449,11 @@
 	else if (BoundsRect.hi.x > SpreadRect.hi.x)
 		Offset->x -= (BoundsRect.hi.x - SpreadRect.hi.x);
 
-	// (b) Vertical adjustment
-	if (BoundsRect.lo.y < SpreadRect.lo.y)
+	// (b) Vertical adjustment (most useful to clip hi co-ords)
+	if (BoundsRect.hi.y > SpreadRect.hi.y)
+		Offset->y -= (BoundsRect.hi.y - SpreadRect.hi.y);
+	else if (BoundsRect.lo.y < SpreadRect.lo.y)
 		Offset->y += (SpreadRect.lo.y - BoundsRect.lo.y);
-	else if (BoundsRect.hi.y > SpreadRect.hi.y)
-		Offset->y -= (BoundsRect.hi.y - SpreadRect.hi.y);
 
 	// Whatever happened, we can fit it on the spread.
 	return TRUE;
Index: Trunk/XaraLX/Kernel/bitfilt.h
===================================================================
--- Trunk/XaraLX/Kernel/bitfilt.h	(revision 1759)
+++ Trunk/XaraLX/Kernel/bitfilt.h	(revision 1760)
@@ -308,6 +308,9 @@
 	virtual BOOL CanDoImportDPI()				{ return FALSE; }
 	virtual void SetImportDPI(DPI ImportDPI)	{}
 
+	static BOOL GetZoomOnImport()				{ return s_fZoomOnImport; }
+	static void SetZoomOnImport( BOOL fFlag )	{ s_fZoomOnImport = fFlag; }
+
 protected:
 	// Something to mark if this is a meant as a Preview Bitmap or not
 	BOOL IsPreviewBitmap;
@@ -487,7 +490,12 @@
 	void		SetDepthToRender(const BMP_DEPTH& Depth)	{	m_RenderDepth = Depth;	}
 	BMP_DEPTH	GetRenderDepth() const						{	return m_RenderDepth;	}
 	BOOL		WarnIfIncompatible();
-	
+
+	// Flag to indicate whether an imported bitmap should be zoom'ed to fit, if
+	// it goes outside view.
+	static BOOL		s_fZoomOnImport;
+	static BOOL		s_fWarnedZoomOnImport;	
+
 private:
 	// Progress bar variables...should be in Filter class really
 	UINT32		m_ProgressBarCount;			// Current progress bar count
Index: Trunk/XaraLX/Kernel/bitfilt.cpp
===================================================================
--- Trunk/XaraLX/Kernel/bitfilt.cpp	(revision 1759)
+++ Trunk/XaraLX/Kernel/bitfilt.cpp	(revision 1760)
@@ -124,6 +124,7 @@
 //#include "fillattr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
 #include "bmpexdoc.h"
 #include "impexpop.h"
+#include "zoomops.h"
 //#include "will3.h"		// for _R(IDS_GENOPTPALMSGID)
 #include "nodetxtl.h"
 #include "qualattr.h"
@@ -190,6 +191,9 @@
 
 LPLOGPALETTE 	BaseBitmapFilter::m_pBrowserPalette 		= NULL;
 
+BOOL			BaseBitmapFilter::s_fZoomOnImport		= 9999;
+BOOL			BaseBitmapFilter::s_fWarnedZoomOnImport	= 9999;
+
 //  This constant gives you the ( square of the ) maximum distance that a colour has to be from a browser colour
 //  to be snapped to that colour.
 const INT32 WEB_SNAP_OPTIMISED_DISTANCE_SQUARED = 25;
@@ -299,6 +303,16 @@
 ********************************************************************************************/
 BOOL BaseBitmapFilter::InitBaseClass()
 {
+	if( 9999 == s_fZoomOnImport &&
+		Camelot.DeclareSection( _T("Filters"), 10 ) )
+	{
+		s_fZoomOnImport = TRUE;
+		s_fWarnedZoomOnImport = FALSE;
+
+		Camelot.DeclarePref( NULL, _T("ZoomToFitOnImport"), &s_fZoomOnImport, FALSE, TRUE );
+		Camelot.DeclarePref( NULL, _T("WarnedZoomToFitOnImport"), &s_fWarnedZoomOnImport, FALSE, TRUE );
+	}
+	
 	return BitmapExportOptions::Declare();
 }
 
@@ -749,15 +763,15 @@
 	Spread *pSpread = NULL;
 	DocCoord Origin;
 
+	//So first find the current view
+	DocView* pDocView=DocView::GetCurrent();
+		
 	if (Pos == NULL)
 	{
 		// For now, position Draw objects on 1st page of spread 1
 
 		//Graham 30/6/97: We now position imported bitmaps in the top left of the view
 
-		//So first find the current view
-		DocView* pDocView=DocView::GetCurrent();
-		
 		ERROR2IF(pDocView==NULL, FALSE, "BaseBitmapFilter::DoImport - no current view");
 
 		//And get the centre coordinate
@@ -843,14 +857,8 @@
 			BitmapInfo Info;
 			pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info);
 
-			INT32 hdpi = pNodeBitmap->GetBitmap()->GetHorizontalDPI();
-			if (hdpi == 0)
-				hdpi = 96;
-			INT32 vdpi = pNodeBitmap->GetBitmap()->GetVerticalDPI();
-			if (vdpi == 0)
-				vdpi = 96;
-			const INT32 HPixelSize = (INT32) ((72000.0 / hdpi) + 0.5);	// Size of output pixel in millipoints
-			const INT32 VPixelSize = (INT32) ((72000.0 / vdpi) + 0.5);	// Size of output pixel in millipoints
+			const INT32 HPixelSize = ( pDocView->GetPixelWidth() + 0.5 ).MakeLong();	// Size of output pixel in millipoints
+			const INT32 VPixelSize = ( pDocView->GetPixelHeight() + 0.5 ).MakeLong();// Size of output pixel in millipoints
 
 			DocRect BoundsRect;
 			BoundsRect.lo = Origin;
@@ -1013,6 +1021,35 @@
 				}
 				return FALSE;	// hmmm....
 			}
+	
+			DocRect		docrectBounds = pNodeBitmap->GetBoundingRect();
+			DocRect		docrectView = pDocView->GetDocViewRect( pSpread );
+            pSpread->DocCoordToSpreadCoord( &docrectView );
+			if( ( docrectBounds.lo.x < docrectView.lo.x ||
+				  docrectBounds.lo.y < docrectView.lo.y ||
+				  docrectBounds.hi.x > docrectView.hi.x ||
+				  docrectBounds.hi.y > docrectView.hi.y ) &&
+				s_fZoomOnImport )
+			{
+				OpZoomFitRectDescriptor* pOpDesc = (OpZoomFitRectDescriptor*)OpDescriptor::FindOpDescriptor( OPTOKEN_ZOOMRECT );
+				if( NULL != pOpDesc )
+				{
+					pOpDesc->SetZoomRect( docrectBounds );
+					pOpDesc->Invoke();
+				}
+
+				if( !s_fWarnedZoomOnImport )
+				{
+					ErrorInfo	Info;
+					memset( &Info, 0, sizeof(Info) );
+					Info.ErrorMsg	= _R(IDS_ZOOM_ON_IMAGE_IMPORT);
+					Info.Button[0]  = _R(IDS_OK);
+					Info.Button[1]  = _R(IDS_DONT_SHOW_AGAIN);
+					Info.OK			= 1;
+					if( _R(IDS_DONT_SHOW_AGAIN) == UINT32(InformMessage( &Info )) )
+						s_fWarnedZoomOnImport = TRUE;
+				}
+			}
 		}
 	}
 	while (AreBitmapsToRead());
Index: Trunk/XaraLX/wxOil/xrc/EN/bmpres-strings.xrc
===================================================================
--- Trunk/XaraLX/wxOil/xrc/EN/bmpres-strings.xrc	(revision 1759)
+++ Trunk/XaraLX/wxOil/xrc/EN/bmpres-strings.xrc	(revision 1760)
@@ -316,6 +316,18 @@
 					<label> - mask</label>
 				</object>
 			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_ZOOM_ON_IMAGE_IMPORT">
+					<label>This picture is very large, so the zoom has been altered to show it all. Resize the image as required. You can click the previous Zoom Button (next to the zoom value on the top button bar) to restore your previous settings.</label>
+				</object>
+			</object>
+			<object class="sizeritem">
+				<flag>wxALIGN_LEFT|wxALL|wxADJUST_MINSIZE</flag>
+				<object class="wxStaticText" name="IDS_DONT_SHOW_AGAIN">
+					<label>&amp;Don't show again</label>
+				</object>
+			</object>
 		</object>
 	</object>
 </resource>


Xara