//***************************************************************************** // // 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: 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; } }
////////////////////////////////////////////////////////////////////////////// // // 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) }