// **************************************************************************** // // Function Name: REditImageInterfaceImp::GetClippingPath( ) // // Description: Returns the component image's clipping path // (if any). // // Returns: // // Exceptions: // // **************************************************************************** // BOOLEAN REditImageInterfaceImp::GetClippingPath( RClippingPath& rPath ) { // Get a pointer to the image document's image. Note, // normally we can assume that it is a RBitmapImage // as this interface is only provided by image components, // but if this is a placeholder from a layout there is no // RBitmapImage so just return FALSE in that case. RBitmapImage* pImage = dynamic_cast<RBitmapImage*>( m_pImageDocument->GetImage() ); if (!pImage) return FALSE; rPath.Undefine(); RClippingPath* pPath = pImage->GetClippingRPath(); if (pPath) { const RImageEffects& rEffects = GetImageEffects(); RRealSize rSize = RImageLibrary().GetImageDimensions( m_pImageDocument->m_rInternalDataBuffer ); R2dTransform xform; xform.PostScale( rSize.m_dx, rSize.m_dy ); RRealRect rRect( rEffects.m_rCropArea * xform ); xform.MakeIdentity(); xform.PostTranslate( rRect.m_Left, rSize.m_dy - rRect.m_Bottom - rRect.m_Top ); rPath = RClippingPath( *pPath, xform ); return TRUE; } return FALSE; }
//***************************************************************************** // // Function Name: CHeadlineSheet::OnPaint // // Description: WM_PAINT handler // // Returns: VOID // // Exceptions: None // //***************************************************************************** // void CHeadlineSheet::OnPaint( ) { PAINTSTRUCT ps; HDC hdc = ::BeginPaint( GetSafeHwnd( ), &ps ); // Put it in a DcDrawingSurface RDcDrawingSurface drawingSurface; drawingSurface.Initialize( hdc ); // Create a transform R2dTransform transform; // Scale to the device DPI RRealSize deviceDPI = drawingSurface.GetDPI( ); transform.PreScale( (YFloatType)deviceDPI.m_dx / kSystemDPI, (YFloatType)deviceDPI.m_dy / kSystemDPI ); // Get the preview rectangle RRealRect previewRect; GetPreviewRect( &previewRect ); // Offset the transform by the top left corner of the preview rect transform.PreTranslate( previewRect.m_Left, previewRect.m_Top ); // Render the preview headline m_pPreviewHeadline->Render( drawingSurface, transform, RRealRect( previewRect.WidthHeight( ) ), previewRect.WidthHeight( ) ); drawingSurface.DetachDCs( ); ::EndPaint( GetSafeHwnd( ), &ps ); }
// **************************************************************************** // // Function Name: RGraphicInterfaceImp::Render( ) // // Description: Render the data in the view. // // Returns: Nothing // // Exceptions: kMemory // // **************************************************************************** // void RGraphicInterfaceImp::Render( RDrawingSurface& drawingSurface, const R2dTransform& transform, const RIntRect& rcRender, const RIntRect& rcLocation ) { R2dTransform graphicTransform = transform; graphicTransform.PreTranslate( rcLocation.m_Left, rcLocation.m_Top ); TpsAssert( m_pGraphic != NULL, "Render called with NULL graphic" ); m_pGraphic->Render( drawingSurface, rcLocation.WidthHeight(), graphicTransform, rcRender, m_pGraphic->GetMonochromeColor(), FALSE ); }
// **************************************************************************** // // Function Name: RDragSelectionTracker::GetFeedbackBoundingRect( ) // // Description: Returns the feedback bounding rect // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealRect RDragSelectionTracker::GetFeedbackBoundingRect( const RRealPoint& point ) const { // Get the view transform R2dTransform transform; m_pView->GetViewTransform( transform, TRUE ); // Get the bounding rect, in device units RRealRect boundingRect = m_pSelection->GetDragTrackingFeedbackBoundingRect( transform, point - m_TrackingMouseDownPoint ); // Convert back to logical units transform.Invert( ); return boundingRect * transform; }
void RWinColorPaletteWell::OnPaint( ) { CPaintDC dc( this ); CRect rect; GetClientRect( rect ); if (m_crColor.GetFillMethod() != RColor::kTransparent) { // The bounding rect is in logical units, so we // need to create a transform to scale from logical // units to device units. We also divide by 2 to // account for the scaling in the bounding rect to // make the texture more visible in such a small area. RRealSize dpi( ::GetScreenDPI() ); R2dTransform transform; transform.PostScale( dpi.m_dx / kSystemDPI * 0.5, dpi.m_dy / kSystemDPI * 0.5 ); RColor crFillColor = m_crColor; crFillColor *= transform; RIntRect rRect( rect ); RDcDrawingSurface ds; ds.Initialize( (HDC) dc ); RColor oldColor = ds.GetFillColor(); ds.SetFillColor( crFillColor ); ds.FillRectangle( rRect ); ds.SetFillColor( oldColor ); ds.DetachDCs(); } else { dc.FillSolidRect( rect, RGB( 255, 255, 255 ) ); CString strText ; GetWindowText( strText ); CRect rcTextRect( rect ); rcTextRect.DeflateRect( 1, 1 ); CFont* pFont = dc.SelectObject( GetParent()->GetFont() ); dc.DrawText( strText, rcTextRect, DT_CENTER | DT_VCENTER ); dc.SelectObject( pFont ); } dc.MoveTo( rect.left, rect.bottom - 1 ); dc.LineTo( rect.left, rect.top ); dc.LineTo( rect.right, rect.top ); }
// **************************************************************************** // // Function Name: RPsd3RuledLineGraphic::Render() // // Description: Draws the RuledLine // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RPsd3RuledLineGraphic::Render(RDrawingSurface& rDrawingSurface, const RRealSize& rSize, const R2dTransform& rTransform, const RIntRect& rRender, const RColor& rMonoColor, BOOLEAN) { R2dTransform rLineTransform = rTransform; RRealSize rLineSize = rSize; if (!m_fHorizontal) { rLineSize.m_dx = rSize.m_dy; rLineSize.m_dy = rSize.m_dx; rLineTransform.PreRotateAboutOrigin(::DegreesToRadians(-90.0)); rLineTransform.PreTranslate(0.0, -rLineSize.m_dy); } Render(&rDrawingSurface, NULL, rLineSize, rLineTransform, rRender, rMonoColor); }
// **************************************************************************** // // Function Name: RResizeSelectionTracker::GetFeedbackBoundingRect( ) // // Description: Returns the feedback bounding rect // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealRect RResizeSelectionTracker::GetFeedbackBoundingRect( const RRealPoint& point ) const { // Get the view transform R2dTransform transform; m_pView->GetViewTransform( transform, TRUE ); RRealSize scaleFactor = CalcScaleFactor( point ); RRealRect boundingRect = m_pSelection->GetResizeTrackingFeedbackBoundingRect( transform, m_ScalingCenter, scaleFactor, m_fMaintainAspectRatio ); // Convert back to logical units transform.Invert( ); return boundingRect * transform; }
// **************************************************************************** // // Function Name: RPsd3RuledLineGraphic::GetOutlinePath( ) // // Description: Compute and return the path the encompases the path of this graphic // // Returns: nothing // // Exceptions: None // // **************************************************************************** // BOOLEAN RPsd3RuledLineGraphic::GetOutlinePath( RPath& path, const RRealSize& size, const R2dTransform& transform ) { R2dTransform rLineTransform = transform; RRealSize rLineSize = size; if (!m_fHorizontal) { rLineSize.m_dx = size.m_dy; rLineSize.m_dy = size.m_dx; rLineTransform.PreRotateAboutOrigin(::DegreesToRadians(-90.0)); rLineTransform.PreTranslate(0.0, -rLineSize.m_dy); } Render( NULL, &path, rLineSize, rLineTransform, RIntRect(0,0,0,0), RColor(kBlack) ); return TRUE; }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::CalcAngle( ) // // Description: Calculates the current angle for this rotation tracker // // Returns: The angle // // Exceptions: None // // **************************************************************************** // YAngle RRotateSelectionTracker::CalcAngle( const RRealPoint& mousePoint ) const { // Calculate the new rotation angle. Use the law of cosines: // c^2 = a^2 + b^2 - 2abcosC // where: // A = The original handle position // B = The current mouse position // C = The center of rotation YRealDimension a = m_TrackingRotationCenter.Distance( m_TrackingOriginalHandlePoint ); YRealDimension b = m_TrackingRotationCenter.Distance( mousePoint ); YRealDimension c = mousePoint.Distance( m_TrackingOriginalHandlePoint ); // The distance from the center point to the original handle point should be positive TpsAssert( ::AreFloatsGT( a, 0.0 ), "Distance from rotation center to handle must be positive." ); YAngle angle = 0.0; // Check for the mouse point over the rotation center if( !::AreFloatsEqual( b, 0.0 ) ) { YFloatType cosAngle = ( ( a * a ) + ( b * b ) - ( c * c ) ) / ( 2 * a * b ); // Constrain the cos to legal values. I have seen cases where it was very slightly outside, // when b is close to 0 cosAngle = ::Min( cosAngle, 1.0F ); cosAngle = ::Max( cosAngle, -1.0F ); angle = ::acos( cosAngle ); } // Rotate the frame of reference parallel to the x-axis R2dTransform rotationTransform; rotationTransform.PreRotateAboutPoint( m_TrackingRotationCenter.m_x, m_TrackingRotationCenter.m_y, m_TrackingInitialRotationAngle ); RRealPoint temp = mousePoint * rotationTransform; // If the mouse is below the line through the center of rotation and parallel to the x-axis, we are rotating clockwise if( ::AreFloatsGT( temp.m_y, m_TrackingRotationCenter.m_y ) ) angle *= -1; // If necessary, contrain the angle angle = ConstrainAngle( angle ); return angle; }
// **************************************************************************** // // Function Name: RPsd3RuledLineGraphic::RenderRightCap() // // Description: Draws the right cap of the Ruled Line // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RPsd3RuledLineGraphic::RenderRightCap(RDrawingSurface* pDS, RPath* pPath, const RRealSize& rLineSize, const R2dTransform& rTransform, const RIntRect& rRender, const RColor& rMonoColor) const { if (m_pRightCap) { // The right cap exists, so render it RRealSize rRightCapSize; rRightCapSize.m_dy = rLineSize.m_dy; rRightCapSize.m_dx = rLineSize.m_dy * m_pRightCap->GetAspectRatio(); // If the line is real small AND the line is not that large, make sure we don't overwrite ourselves if ( rRightCapSize.m_dx > (rLineSize.m_dx / 2.0)) rRightCapSize.m_dx = rLineSize.m_dx / 2.0; R2dTransform rRightCapTransform = rTransform; rRightCapTransform.PreTranslate((YRealDimension)(rLineSize.m_dx - rRightCapSize.m_dx), 0.0); if (pDS) m_pRightCap->Render(*pDS, rRightCapSize, rRightCapTransform, rRender, rMonoColor); if (pPath) m_pRightCap->GetOutlinePath(*pPath, rRightCapSize, rRightCapTransform); } else if (m_fMirrorCaps) { // The right cap does not exist, so render a mirror image of m_pLeftCap RRealSize rLeftCapSize; rLeftCapSize.m_dy = rLineSize.m_dy; rLeftCapSize.m_dx = rLineSize.m_dy * m_pLeftCap->GetAspectRatio(); // If the line is real small AND the line is not that large, make sure we don't overwrite ourselves if ( rLeftCapSize.m_dx > (rLineSize.m_dx / 2.0)) rLeftCapSize.m_dx = rLineSize.m_dx / 2.0; R2dTransform rLeftCapTransform = rTransform; rLeftCapTransform.PreTranslate((YRealDimension)rLineSize.m_dx, 0.0); rLeftCapTransform.PreScale(-1.0, 1.0); if (pDS) m_pLeftCap->Render(*pDS, rLeftCapSize, rLeftCapTransform, rRender, rMonoColor); if (pPath) m_pLeftCap->GetOutlinePath(*pPath, rLeftCapSize, rLeftCapTransform); } else { // Do not render either the right cap or a mirror image of m_pLeftCap return; } }
// **************************************************************************** // // Function Name: RBreakGroupAction::Undo( ) // // Description: Undoes the action // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RBreakGroupAction::Undo( ) { // Call the base method to setup the state properly RUndoableAction::Undo( ); // Add the group component m_pParentDocument->AddComponent( m_pGroupDocument ); // Unselect the current selection m_pCurrentSelection->UnselectAll( ); // Go through all components in the selection RCompositeSelection::YIterator iterator = m_OldSelection.Start( ); for( ; iterator != m_OldSelection.End( ); ++iterator ) { // Get the component document RComponentDocument* pComponentDocument = dynamic_cast<RComponentDocument*>( ( *iterator )->GetRDocument( ) ); TpsAssert( pComponentDocument, "Invalid document." ); // Remove the component from its current document m_pParentDocument->RemoveComponent( pComponentDocument ); // NULL out the views parent ( *iterator )->SetParentView( NULL ); // Add it to the group component m_pGroupDocument->AddComponent( pComponentDocument ); // Move the component back to the groups coordinate space R2dTransform transform = m_pGroupView->GetBoundingRect( ).GetTransform( ); transform.Invert( ); YComponentBoundingRect temp = ( *iterator )->GetBoundingRect( ); temp *= transform; ( *iterator )->SetBoundingRect( temp ); } // Update the view that its layout has changed m_pCurrentSelection->GetView()->XUpdateAllViews( kLayoutChanged, 0 ); // Select the group component m_pCurrentSelection->Select( m_pGroupDocument, TRUE ); }
// **************************************************************************** // // Function Name: RRotateSelectionTracker::GetFeedbackBoundingRect( ) // // Description: Returns the feedback bounding rect // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealRect RRotateSelectionTracker::GetFeedbackBoundingRect( const RRealPoint& point ) const { // Get the view transform R2dTransform transform; m_pView->GetViewTransform( transform, TRUE ); // Calculate the angle YAngle angle = CalcAngle( point ); // Get the bounding rect, in device units RRealRect boundingRect = m_pSelection->GetRotateTrackingFeedbackBoundingRect( transform, m_TrackingRotationCenter, angle ); // Convert back to logical units transform.Invert( ); boundingRect *= transform; // Add the feedback line boundingRect.AddPointToRect( point ); return boundingRect; }
// **************************************************************************** // // Function Name: RWindowView::GetCursorPosition( ) // // Description: Gets the current cursor position within this view // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // RRealPoint RWindowView::GetCursorPosition( ) const { // Get the absolute cursor position POINT pt; ::GetCursorPos( &pt ); // Convert to client coordinates GetCWnd( ).ScreenToClient( &pt ); RRealPoint cursorPosition( pt.x, pt.y ); // Convert to logical units ::DeviceUnitsToLogicalUnits( cursorPosition, *this ); // Get our transform R2dTransform transform; ApplyTransform( transform, FALSE, FALSE ); // Invert the transform and convert the point to our coordinate system transform.Invert( ); return cursorPosition * transform; }
// **************************************************************************** // // Function Name: RComponentView::ApplyTransform( ) // // Description: Adds this views transform operations to the given // transform. // // Returns: Nothing // // Exceptions: None // // **************************************************************************** // void RWindowView::ApplyTransform( R2dTransform& transform, BOOLEAN, BOOLEAN fIsPrinting ) const { // If we are not printing, apply a translation to account for scrolling if( !fIsPrinting && m_pHorizontalScrollBar ) { // Get the amount we are scrolled in device units RRealSize scrollAmount( -m_pHorizontalScrollBar->GetPosition( ), -m_pVerticalScrollBar->GetPosition( ) ); // Convert it to logical units ::DeviceUnitsToLogicalUnits( scrollAmount, *this ); // Apply the translate transform.PreTranslate( scrollAmount.m_dx, scrollAmount.m_dy ); } }
void RWinColorPaletteWell::SetColor( RColor& crColor ) { if (crColor != m_crColor) { m_crColor = crColor; CRect rect; GetClientRect( rect ); RIntRect rRect( rect ); // By making the bounding rect // twice as large, we will make // textures more visible. R2dTransform transform; transform.PostScale( 2, 2 ); rRect *= transform; ::ScreenUnitsToLogicalUnits( rRect ); m_crColor.SetBoundingRect( rRect ); if (m_hWnd) Invalidate( FALSE ); } }
// **************************************************************************** // // Function Name: YFontInfo::operator*( ) // // Description: Apply the transform to alter the FontInfo // This involves scaling the height by the transform.XScale // and changing the rotation by the transform XRotation // // Returns: Nothing // // Exceptions: Nothing // // **************************************************************************** // YFontInfo YFontInfo::operator*( const R2dTransform& transform ) const { YFontInfo newFont = *this; YAngle rotation; YRealDimension xScale; YRealDimension yScale; transform.Decompose( rotation, xScale, yScale ); if ( xScale < yScale ) yScale = xScale; else xScale = yScale; newFont.height = ::Abs( ::Round( (YRealDimension)height * yScale ) ); newFont.width = ::Abs( ::Round( (YRealDimension)width * xScale ) ); newFont.angle += (YIntDegrees)Round( RadiansToDegrees( rotation ) ); return newFont; }
// **************************************************************************** // // Function Name: RPsd3RuledLineGraphic::RenderRails() // // Description: Draws the rails of the Ruled Line // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RPsd3RuledLineGraphic::RenderRails(RDrawingSurface* pDS, RPath* pPath, const RRealSize& rLineSize, const R2dTransform& rTransform, const RIntRect& rRender, const RColor& rMonoColor) const { // Make sure we have a rail (is this necessary?) if ( !m_pRail ) return; // Compute the inverse of the transform R2dTransform invTransform( rTransform ); invTransform.Invert( ); YRealDimension xScale; YRealDimension yScale; YAngle rotation; rTransform.Decompose( rotation, xScale, yScale ); // Compute the size of the right and left caps respectively (if they exist) YRealDimension leftCapSize = (m_pLeftCap!=NULL)? rLineSize.m_dy * m_pLeftCap->GetAspectRatio( ) : 0.0; YRealDimension rightCapSize = (m_pRightCap!=NULL)? rLineSize.m_dy * m_pRightCap->GetAspectRatio( ) : ((m_fMirrorCaps)? leftCapSize : 0.0 ); YRealDimension halfLine = rLineSize.m_dx / 2.0; if ( leftCapSize > halfLine ) leftCapSize = halfLine; if ( rightCapSize > halfLine) rightCapSize = halfLine; // Count the number of rails needed YRealDimension yVariableLength( rLineSize.m_dx - leftCapSize - rightCapSize ); YRealDimension yNominalXDimension( rLineSize.m_dy * m_pRail->GetAspectRatio() ); sLONG sRailCount = ::GetRailCount(yVariableLength, yNominalXDimension ); // // If no rails are needed, we are done if (sRailCount == 0) return; // Compute the new rail sizes (the small and large ones) RRealSize smallRailSize( yVariableLength / (YFloatType)sRailCount, rLineSize.m_dy ); smallRailSize *= rTransform; smallRailSize = RRealSize( floor( smallRailSize.m_dx ), floor( smallRailSize.m_dy ) ); RRealSize largeRailSize( smallRailSize.m_dx+1.0, smallRailSize.m_dy+1.0 ); // // Re-expand to logical units smallRailSize *= invTransform; largeRailSize *= invTransform; // // Reset the y dimension smallRailSize.m_dy = largeRailSize.m_dy = rLineSize.m_dy; // What is the excess YIntDimension smallSize = sRailCount; YIntDimension increment = static_cast<YIntDimension>( (yVariableLength - (smallRailSize.m_dx * sRailCount)) * xScale) + 1; YRealDimension xStartOffset = 0.0; YIntDimension excessCounter = 0; TpsAssert( smallSize>=0, "Extra space is negative" ); if (m_pLeftCap) xStartOffset += leftCapSize; RRealSize rRailSize( rLineSize ); for (int nRail = 0; nRail < sRailCount-1; ++nRail) { // Create a transform and offset it to the proper location R2dTransform renderTransform( rTransform ); renderTransform.PreTranslate( xStartOffset, 0 ); // Add the extra to the excessCounter excessCounter += increment; if ( excessCounter >= smallSize ) { rRailSize = largeRailSize;//smallRailSize; excessCounter -= smallSize; } else rRailSize = smallRailSize;//largeRailSize; if (pDS) m_pRail->Render(*pDS, rRailSize, renderTransform, rRender, rMonoColor); if (pPath) m_pRail->GetOutlinePath(*pPath, rRailSize, renderTransform); xStartOffset += rRailSize.m_dx; } // Render the last rail, but make sure it is large enough R2dTransform tmpTransform( rTransform ); tmpTransform.PreTranslate( xStartOffset, 0 ); rRailSize.m_dx = yVariableLength + leftCapSize - xStartOffset; if (pDS) m_pRail->Render(*pDS, rRailSize, tmpTransform, rRender, rMonoColor); if (pPath) m_pRail->GetOutlinePath(*pPath, rRailSize, tmpTransform); }
// **************************************************************************** // // Function Name: RPsd3VerticalBannerGraphic::Render() // // Description: Draws the Backdrop // // Returns: Nothing // // Exceptions: None // // **************************************************************************** void RPsd3VerticalBannerGraphic::Render(RDrawingSurface& rDrawingSurface, const RRealSize& rSize, const R2dTransform& rTransform, const RIntRect& rRender, const RColor& rMonoColor, BOOLEAN) { // Compute the sizes of the elements RRealSize rTopCapSize = ::GetYSize(m_pTopCap, rSize.m_dx); RRealSize rBottomCapSize = (m_fMirrorCaps) ? ::GetYSize(m_pTopCap, rSize.m_dx) : ::GetXSize(m_pBottomCap, rSize.m_dx); RRealSize rLeftRailSize = ::GetYSize(m_pLeftRail, rSize.m_dx / 2.0); RRealSize rRightRailSize = ::GetYSize(m_pRightRail, rSize.m_dx / 2.0); R2dTransform rGraphicTransform; // Left cap rGraphicTransform = rTransform; if (m_pTopCap) m_pTopCap->Render(rDrawingSurface, rTopCapSize, rGraphicTransform, rRender, rMonoColor); // Right cap rGraphicTransform = rTransform; ::FlipY(rSize, rGraphicTransform); if (m_fMirrorCaps) { // Render the mirrored left cap as the right cap if (m_pTopCap) m_pTopCap->Render(rDrawingSurface, rTopCapSize, rGraphicTransform, rRender, rMonoColor); } else { // Render the right cap ::FlipY(rBottomCapSize, rGraphicTransform); if (m_pBottomCap) m_pBottomCap->Render(rDrawingSurface, rBottomCapSize, rGraphicTransform, rRender, rMonoColor); } // Rails YRealDimension yVariableLength = rSize.m_dy - rTopCapSize.m_dy - rBottomCapSize.m_dy; uLONG uRailCount = 0; uLONG uRail = 0; // Top rails uRailCount = ::GetRailCount(yVariableLength, rLeftRailSize.m_dy); if (uRailCount > 0) { // Adjust the top rail size rLeftRailSize.m_dy = yVariableLength / (YFloatType)uRailCount; rGraphicTransform = rTransform; rGraphicTransform.PreTranslate(0.0, rTopCapSize.m_dy); for (uRail = 0; uRail < uRailCount; uRail++) { if (m_pLeftRail) m_pLeftRail->Render(rDrawingSurface, rLeftRailSize, rGraphicTransform, rRender, rMonoColor); rGraphicTransform.PreTranslate(0.0, rLeftRailSize.m_dy); } } // Bottom rails uRailCount = ::GetRailCount(yVariableLength, rRightRailSize.m_dy); if (uRailCount > 0) { // Adjust the bottom rail size rRightRailSize.m_dy = yVariableLength / (YFloatType)uRailCount; rGraphicTransform = rTransform; rGraphicTransform.PreTranslate(rSize.m_dx / 2.0, rTopCapSize.m_dy); for (uRail = 0; uRail < uRailCount; uRail++) { if (m_pRightRail) m_pRightRail->Render(rDrawingSurface, rRightRailSize, rGraphicTransform, rRender, rMonoColor); rGraphicTransform.PreTranslate(0.0, rRightRailSize.m_dy); } } }
////////////////////////////////////////////////////////////////////////////// // // void ExportGraphicImage( RBitmapImage* pImage, RMBCString *pInitialDir ) // // export a graphic to file from a bitmap image // ////////////////////////////////////////////////////////////////////////////// void ExportGraphicImage( RBitmapImage* pImage, RMBCString *pInitialDir /*=NULL*/) { RImageLibrary rLibrary ; CArray<int, int> arrFileFormats ; // // Build the export file filter list... // CString strFilter, str ; for (int i = 0; i < kNumFormats - 1; i++) { if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] )) { str.LoadString( kImageExportFilters[i][1] ) ; strFilter += str ; arrFileFormats.Add( kImageExportFilters[i][0] ) ; } } TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ; str.LoadString( kImageExportFilters[i][1] ) ; strFilter += str ; strFilter += "|" ; arrFileFormats.Add( kImageExportFilters[i][0] ) ; // // Create and execute the dialog... // RExportGraphicDlg dlg( pImage, strFilter ) ; // Load in the dialog title string CString strTitle ; strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ; dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ; if( pInitialDir ) { dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir; } if (IDOK == dlg.DoModal()) { RMBCString strPathName = dlg.GetPathName() ; EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ; try { if (kImageFormatXRX == eFormat) // exporting as WMF { // get our output image size RRealSize rRealOutputSize( dlg.GetSize() ); RRealSize screenDPI = ::GetScreenDPI(); // create a vector image RVectorImage vectorImage; vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( rRealOutputSize.m_dx, (uLONG) screenDPI.m_dx ) ); vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( rRealOutputSize.m_dy, (uLONG) screenDPI.m_dy ) ); // Create an offscreen drawing surface and set the picture ROffscreenDrawingSurface rODS; rODS.SetImage( &vectorImage ); // Scale to the device DPI RRealSize rRealImageSize = pImage->GetSizeInLogicalUnits(); R2dTransform transform ; RRealSize deviceDPI = rODS.GetDPI(); transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, (YFloatType) deviceDPI.m_dy / screenDPI.m_dy ); transform.PreScale( rRealOutputSize.m_dx / rRealImageSize.m_dx, rRealOutputSize.m_dy / rRealImageSize.m_dy ) ; // calculate the output rect RRealRect outputRect( rRealOutputSize ) ; ::ScreenUnitsToLogicalUnits( outputRect ); outputRect *= transform; // render to the offscreen pImage->Render( rODS, outputRect ) ; // clean up rODS.ReleaseImage(); // export rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ; if (rLibrary.GetLastException() != kNoError) { throw rLibrary.GetLastException() ; } } else // all other formats { _nFilterIndex = dlg.m_ofn.nFilterIndex ; EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ; rLibrary.ExportImage( *pImage, strPathName, eFormat ); if (rLibrary.GetLastException() != kNoError) { throw rLibrary.GetLastException() ; } } } catch( YException e) { ReportException( e ) ; } } }
////////////////////////////////////////////////////////////////////////////// // // void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir ) // // export a graphic to file from a component view // ////////////////////////////////////////////////////////////////////////////// void ExportGraphicComponent( RComponentView* pComponentView, RMBCString *pInitialDir /*=NULL*/) { RImageLibrary rLibrary ; CArray<int, int> arrFileFormats ; // // Build the export file filter list... // CString strFilter, str ; for (int i = 0; i < kNumFormats - 1; i++) { if (rLibrary.IsFormatSupported( (EImageFormat) kImageExportFilters[i][0] )) { str.LoadString( kImageExportFilters[i][1] ) ; strFilter += str ; arrFileFormats.Add( kImageExportFilters[i][0] ) ; } } TpsAssert( kImageExportFilters[i][0] == kImageFormatXRX, "Invalid export format!" ) ; str.LoadString( kImageExportFilters[i][1] ) ; strFilter += str ; strFilter += "|" ; arrFileFormats.Add( kImageExportFilters[i][0] ) ; // // Create and execute the dialog... // RExportGraphicDlg dlg( pComponentView, strFilter ) ; // Load in the dialog title string CString strTitle ; strTitle.LoadString( STRING_EXPORT_IMAGE_DIALOG_TITLE ) ; dlg.m_ofn.lpstrTitle = (LPCTSTR) strTitle ; if( pInitialDir ) { dlg.m_ofn.lpstrInitialDir = (LPCTSTR)*pInitialDir; } if (IDOK == dlg.DoModal()) { RMBCString strPathName = dlg.GetPathName() ; RIntSize szImageSize = dlg.GetSize() ; _nFilterIndex = dlg.m_ofn.nFilterIndex ; EImageFormat eFormat = (EImageFormat) arrFileFormats[dlg.m_ofn.nFilterIndex - 1] ; RRealSize pictureSize = pComponentView->GetReferenceSize() ; try { if (kImageFormatXRX == eFormat) { RRealSize outputSize( szImageSize.m_dx, szImageSize.m_dy ) ; // = pictureSize ; RRealSize screenDPI = ::GetScreenDPI() ; RVectorImage vectorImage ; vectorImage.SetSuggestedWidthInInches( ::PixelsToInches( outputSize.m_dx, (uLONG) screenDPI.m_dx ) ) ; vectorImage.SetSuggestedHeightInInches( ::PixelsToInches( outputSize.m_dy, (uLONG) screenDPI.m_dy ) ) ; // Create an offscreen drawing surface and set the picture ROffscreenDrawingSurface drawingSurface; drawingSurface.SetImage( &vectorImage ); R2dTransform transform ; // Scale to the device DPI RRealSize deviceDPI = drawingSurface.GetDPI( ); transform.PreScale( (YFloatType) deviceDPI.m_dx / screenDPI.m_dy, (YFloatType) deviceDPI.m_dy / screenDPI.m_dy ); transform.PreScale( outputSize.m_dx / pictureSize.m_dx, outputSize.m_dy / pictureSize.m_dy ) ; // Render the component RRealRect outputRect( pictureSize ) ; pComponentView->Render( drawingSurface, transform, outputRect ) ; drawingSurface.ReleaseImage( ); rLibrary.ExportImage( vectorImage, strPathName, kImageFormatXRX ) ; if (rLibrary.GetLastException() != kNoError) { throw rLibrary.GetLastException() ; } } // if (XRX) else { // Check for a image interface RImageInterface* pInterface = (RImageInterface *) pComponentView->GetInterface( kImageInterfaceId ) ; if (pInterface) { pInterface->Export( strPathName, eFormat ) ; delete pInterface ; } else { // Initialize the new bitmap at a bit depth of 24 RBitmapImage image ; image.Initialize( szImageSize.m_dx, szImageSize.m_dy, 24 ) ; ROffscreenDrawingSurface dsMem ; dsMem.SetImage( &image ) ; R2dTransform transform ; transform.PreScale( szImageSize.m_dx / pictureSize.m_dx, szImageSize.m_dy / pictureSize.m_dy ) ; // Render the component dsMem.SetFillColor( RSolidColor( kWhite ) ) ; dsMem.FillRectangle( RRealRect( pictureSize ), transform ) ; pComponentView->Render( dsMem, transform, RIntRect( RIntSize( pictureSize.m_dx, pictureSize.m_dy ) ) ) ; dsMem.ReleaseImage() ; rLibrary.ExportImage( image, strPathName, eFormat ) ; } if (rLibrary.GetLastException() != kNoError) { throw rLibrary.GetLastException() ; } } // else } // try catch( YException e) { ReportException( e ) ; } } // if (IDOK) }