/******************************************************************************************** > BOOL TipsDlg::DrawBitmap(ResourceID BitmapID, DocRect& RedrawRect) Author: Colin_Barfoot (Xara Group Ltd) <*****@*****.**> Created: 08/08/96 Inputs: BitmapID : the resource id of the bitmap to draw RedrawRect : the rectangle in which to draw it Returns: TRUE if drawn OK FALSE otherwise Purpose: Renders the given bitmap in the given rectangle ********************************************************************************************/ BOOL TipsDlg::DrawBitmap(ResourceID BitmapID, DocRect& RedrawRect) { OILBitmap *pOILBitmap = OILBitmap::Create(); if (pOILBitmap == NULL) { return FALSE; } if (!pOILBitmap->LoadBitmap(BitmapID)) { return FALSE; } // Centre the bitmap within the RedrawRect UINT32 bitmapWidth = pOILBitmap->GetRecommendedWidth(); UINT32 bitmapHeight = pOILBitmap->GetRecommendedHeight(); UINT32 xOffset = RedrawRect.lo.x + (RedrawRect.Width() - bitmapWidth) / 2; UINT32 yOffset = RedrawRect.lo.y + (RedrawRect.Height() - bitmapHeight) / 2; DocCoord lowCorner(xOffset, yOffset); DocRect bitmapRect(lowCorner, bitmapWidth, bitmapHeight); KernelBitmap bitmap(pOILBitmap, TRUE); // Now we need to create a temporary NodeBitmap, which we will // use to render the bitmap preview. NodeBitmap* dummyNode = new NodeBitmap(); if (dummyNode == NULL) { return FALSE; } // Set the NodeBitmap path to be our RedrawRect and attach the Bitmap to it. dummyNode->SetUpPath(); dummyNode->CreateShape(bitmapRect); dummyNode->GetBitmapRef()->SetBitmap(&bitmap); // Now render the bitmap preview dummyNode->Render(m_pRenderer); delete dummyNode; // All OK return TRUE; }
/******************************************************************************************** > BOOL MakeBitmapFilter::InsertBitmapIntoDocument(UndoableOperation *pOp, KernelBitmap* KernelBmp, Document* DestDoc) Author: Will_Cowling (Xara Group Ltd) <*****@*****.**> Created: 11/6/96 Purpose: Exports the current selection as a bitmap, via the virtual fns of the inherited class. Returns: TRUE if worked, FALSE if failed. SeeAlso: GetExportOptions; PrepareToExport; ExportRenderNodes; CleanUpAfterExport; ********************************************************************************************/ BOOL MakeBitmapFilter::InsertBitmapIntoDocument(UndoableOperation *pOp, KernelBitmap* KernelBmp, Document* DestDoc) { Spread *pSpread; DocCoord Origin; // Remember the selection rect, before we change it DocRect SelRect = GetApplication()->FindSelection()->GetBoundingRect(); // For now, position Draw objects on 1st page of spread 1 PORTNOTE("spread", "Multi-spread warning!") pSpread = GetFirstSpread(DestDoc); Page *pPage = (Page *) pSpread->FindFirstPageInSpread(); ERROR3IF(!pPage->IsKindOf(CC_RUNTIME_CLASS(Page)), "MakeBitmapFilter::InsertBitmapIntoDocument: Could not find first Page"); // Use bottom left of page as origin DocRect PageRect = pPage->GetPageRect(); Origin.x = PageRect.lo.x; Origin.y = PageRect.hi.y; // Get a new NodeBitmap object to import into. NodeBitmap *pNodeBitmap = new NodeBitmap; if ((pNodeBitmap == NULL) || (!pNodeBitmap->SetUpPath(12,12))) return FALSE; // Attach the Imported Bitmap to our Node pNodeBitmap->GetBitmapRef()->Attach(KernelBmp, DestDoc); //GetDocument()); if (pNodeBitmap->GetBitmap() != KernelBmp) delete KernelBmp; // It didn't use the bitmap we gave it, so we can delete it // Import worked - try to add the bitmap object into the tree. // First, set the rectangle to the right size for the bitmap... BitmapInfo Info; pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info); DocRect BoundsRect; BoundsRect.lo = Origin; BoundsRect.hi.x = BoundsRect.lo.x + Info.RecommendedWidth; BoundsRect.hi.y = BoundsRect.lo.y + Info.RecommendedHeight; // And set this in our bitmap node pNodeBitmap->CreateShape(BoundsRect); // Make sure that there is a layer to put the bitmap onto if (!MakeSureLayerExists(DestDoc)) { // There is no layer and one could not be made, so we will have to fail delete pNodeBitmap; return FALSE; } // Set the default attrs // This MUST be done before the NodeBitmap is Inserted into the tree if (!pNodeBitmap->ApplyDefaultBitmapAttrs(pOp)) return FALSE; // Insert the node, but don't invalidate its region if (!pOp->DoInsertNewNode(pNodeBitmap, pSpread, FALSE)) { // It didn't work - delete the sub-tree we just created, and report error. delete pNodeBitmap; return FALSE; } // bitmap is currently positioned so its bottom left hand // corner is at the top left of the page // By default we'll move it down so the top-left of the bitmap is on the top-left of the page INT32 XTranslate = 0; INT32 YTranslate = -Info.RecommendedHeight; ClickModifiers ClickMods = ClickModifiers::GetClickModifiers(); if (ClickMods.Adjust && !SelRect.IsEmpty()) { // If shift is down, then we'll try and place the bitmap exactly on top of the selection DocCoord SelectionCentre(SelRect.lo.x + (SelRect.Width()/2), SelRect.lo.y + (SelRect.Height()/2)); XTranslate = SelectionCentre.x - Origin.x - (Info.RecommendedWidth/2); YTranslate = SelectionCentre.y - Origin.y - (Info.RecommendedHeight/2); } else { // Otherwise we'll try and centre it within the current view Spread* pCurrentSpread; DocCoord ViewCentre; if (FindCentreInsertionPosition(&pCurrentSpread, &ViewCentre)) { /* Karim 19/01/2000 * Ensure that the bmp is pixel-aligned as close to the centre as possible. * XTranslate = ViewCentre.x - Origin.x - (Info.RecommendedWidth/2); YTranslate = ViewCentre.y - Origin.y - (Info.RecommendedHeight/2); /**/ DocCoord PixAlignBmpOrigin( ViewCentre.x - Info.RecommendedWidth/2, ViewCentre.y - Info.RecommendedHeight/2 ); INT32 FullDPI = GRenderRegion::GetDefaultDPI(); MILLIPOINT PixWidth = (INT32)((IN_MP_VAL / (double)FullDPI) + 0.5); PixAlignBmpOrigin.x -= PixAlignBmpOrigin.x % PixWidth; PixAlignBmpOrigin.y -= PixAlignBmpOrigin.y % PixWidth; XTranslate = PixAlignBmpOrigin.x - Origin.x; YTranslate = PixAlignBmpOrigin.y - Origin.y; } } Trans2DMatrix Xlate(XTranslate, YTranslate); pNodeBitmap->Transform(Xlate); // Ensure Sel Bounds are correct after translation GetApplication()->UpdateSelection(); return TRUE; }
void BitmapEffectAtom::Test2(UndoableOperation * Op) { BOOL CarryOn=TRUE; Range Sel(*(GetApplication()->FindSelection())); Node* FirstSelectedNode = Sel.FindFirst(); if (FirstSelectedNode != NULL) // No nodes selected so End { Node* CurrentNode = FirstSelectedNode; Node* NextCurrent; // Do all bitmaps while ((CurrentNode != NULL) && CarryOn) { NextCurrent = Sel.FindNext(CurrentNode); if ( (CurrentNode->IsSelected()) && (CurrentNode->GetRuntimeClass() == CC_RUNTIME_CLASS(NodeBitmap)) ) { KernelBitmap * pBitmap = ((NodeBitmap *)(CurrentNode))->GetBitmap(); BitmapInfo BMInfo; UINT32 bpp; pBitmap->ActualBitmap->GetInfo(&BMInfo); bpp=BMInfo.PixelDepth; TRACEUSER( "Alex", _T("Bitmap found %d bpp\n"),bpp); if ((bpp==32) || TRUE) { CarryOn = FALSE; NodeBitmap *pNodeBitmap = new NodeBitmap; if ((pNodeBitmap == NULL) || (!pNodeBitmap->SetUpPath(12,12))) return; Spread *pSpread; DocCoord Origin; // For now, position Draw objects on 1st page of spread 1 Node *pNode = (Document::GetSelected())->GetFirstNode()->FindNext()->FindFirstChild(); while ((pNode != NULL) && (!pNode->IsKindOf(CC_RUNTIME_CLASS(Chapter)))) pNode = pNode->FindNext(); ENSURE(pNode->IsKindOf(CC_RUNTIME_CLASS(Chapter)), "Filter::GetFirstSpread(): Could not find Chapter"); Chapter *pChapter = (Chapter *) pNode; // pSpread is a child of pChapter pSpread = (Spread *) pChapter->FindFirstChild(); ENSURE(pSpread->IsKindOf(CC_RUNTIME_CLASS(Spread)), "Filter::GetFirstSpread(): Could not find Spread"); Page *pPage = (Page *) pSpread->FindFirstPageInSpread(); ENSURE(pPage->IsKindOf(CC_RUNTIME_CLASS(Page)), "BaseBitmapFilter::DoImport(): Could not find first Page"); // Use bottom left of page as origin DocRect PageRect = pPage->GetPageRect(); Origin = PageRect.lo; KernelBitmap* kb = new KernelBitmap(BMInfo.PixelWidth,BMInfo.PixelHeight,32,100); // Get a new bitmap object for this node. pNodeBitmap->GetBitmapRef()->Attach(kb); if (pNodeBitmap->GetBitmap() != kb) { // It didn't use the bitmap we gave it, so we can delete it delete kb; } ENSURE(pNodeBitmap->GetBitmap()->ActualBitmap != NULL, "No bitmap object found!"); // Import worked - try to add the bitmap object into the tree. // First, set the rectangle to the right size for the bitmap... BitmapInfo Info; pNodeBitmap->GetBitmap()->ActualBitmap->GetInfo(&Info); DocRect BoundsRect; BoundsRect.lo = Origin; BoundsRect.hi.x = BoundsRect.lo.x + Info.RecommendedWidth; BoundsRect.hi.y = BoundsRect.lo.y + Info.RecommendedHeight; // And set this in our bitmap node pNodeBitmap->CreateShape(BoundsRect); // Apply some default attrs for the bitmap // This Must be done before the NodeBitmap is inserted into the tree if (!pNodeBitmap->ApplyDefaultBitmapAttrs(Op)) { return; } // Insert the node, but don't invalidate its region if (!Op->DoInsertNewNode(pNodeBitmap, pSpread, FALSE)) { // It didn't work - delete the sub-tree we just created, and report error. delete pNodeBitmap; return; } // Invalidate the region Op->DoInvalidateNodeRegion(pNodeBitmap, TRUE, FALSE); // Right, now we're going to do some processing... BitmapEffectBase * pEffect; pEffect=new /*TestBitmapEffect*/ BitmapEffectSILT; pEffect->SetParameters(); pEffect->SetSourceImage(pBitmap); pEffect->UseDestinationBitmap(pNodeBitmap->GetBitmap()); pEffect->Run(); pEffect->UseDestinationBitmap(NULL); delete(pEffect); } } CurrentNode = NextCurrent; } } // if (CarryOn) BitmapEffectSILT::RunA(); return; }