/******************************************************************************************** > BOOL MakeBitmapFilter::FindCentreInsertionPosition(Spread** Spread, DocCoord* Position) Author: Will_Cowling (Xara Group Ltd) <*****@*****.**> (from Simon) Created: 12/6/96 Inputs: - Outputs: Spread: The spread to place the clipboard objects on Position:The centre of the view (Spread coords) Purpose: Finds the centre insertion position for clipboard objects ********************************************************************************************/ BOOL MakeBitmapFilter::FindCentreInsertionPosition(Spread** Spread, DocCoord* Position) { // --------------------------------------------------------------------------------- // Find out which spread is in the centre of the view // this is the spread that the pasted objects will be placed on // Obtain the current DocView DocView* CurDocView = DocView::GetCurrent(); ENSURE(CurDocView != NULL, "The current DocView is NULL"); if (CurDocView == NULL) return FALSE; // No DocView // Get the view rect WorkRect WrkViewRect = CurDocView->GetViewRect(); if (WrkViewRect.IsEmpty() || (!WrkViewRect.IsValid()) ) return FALSE; // Defensive // Determine the centre of the view WorkCoord WrkCentreOfView; WrkCentreOfView.x = WrkViewRect.lox + (WrkViewRect.Width()/2); WrkCentreOfView.y = WrkViewRect.loy + (WrkViewRect.Height()/2); // FindEnclosing spread requires an OilCoord OilCoord OilCentreOfView = WrkCentreOfView.ToOil(CurDocView->GetScrollOffsets()); // Find out which spread to insert the pasteboard objects onto (*Spread) = CurDocView->FindEnclosingSpread(OilCentreOfView); if ((*Spread) == NULL) return FALSE; // There is no spread // Phew // --------------------------------------------------------------------------------- // Now lets find the spread coordinate of the centre of the view DocRect DocViewRect = CurDocView->GetDocViewRect(*Spread); if ( DocViewRect.IsEmpty() || (!DocViewRect.IsValid()) ) { ERROR3("DocViewRect is invalid"); return FALSE; // Defensive } // Find the centre of the DocViewRect DocCoord DocCentreOfView; DocCentreOfView.x = DocViewRect.lox + (DocViewRect.Width()/2); DocCentreOfView.y = DocViewRect.loy + (DocViewRect.Height()/2); // -------------------------------------------------------------------------------- // Now convert from DocCoords to spread coords DocRect PhysSpreadRect = (*Spread)->GetPasteboardRect(); (*Position).x = DocCentreOfView.x - PhysSpreadRect.lo.x; (*Position).y = DocCentreOfView.y - PhysSpreadRect.lo.y; return TRUE; }
BOOL NativePrefsDlg::InitDialog () { ERROR2IF ( mpParams == NULL, FALSE, "NativePrefsDlg::InitDialog called after duff initialisation?!" ); //First, do we have a selection? Application *pApp = GetApplication(); ERROR2IF(pApp == NULL, FALSE,"NativePrefsDlg::InitDialog - no application!"); SelRange *pRange = pApp->FindSelection(); ERROR2IF(pRange == NULL, FALSE,"NativePrefsDlg::InitDialog - no selection range!"); DocRect ClipRect = pRange->GetBoundingRect(); BOOL fThereIsASelection=!ClipRect.IsEmpty(); //Now, is there a selection? if (fThereIsASelection) { // Yes. So ungrey both the buttons for selecting the nodes to export. EnableGadget(_R(IDC_NATIVEOPTS_SELECT), TRUE); EnableGadget(_R(IDC_NATIVEOPTS_DRAWING), TRUE); //Now, which of those buttons should be selected? switch ( mpParams->GetExportSel () ) { case SELECTION: // Choose the export pair of buttons. SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), FALSE); SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), TRUE); break; default: case DRAWING: // Choose the export pair of buttons. SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), TRUE); SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), FALSE); break; } } else { //No. So grey the SELECTION button and ungrey //the DRAWING button EnableGadget(_R(IDC_NATIVEOPTS_SELECT), FALSE); EnableGadget(_R(IDC_NATIVEOPTS_DRAWING), TRUE); // And we must select the DRAWING button for the export area controls. SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), TRUE); SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), FALSE); } return TRUE; }
void OpDragBox::UpdateSolidDragBox(const DocRect& drNewDragBox) { // Set up four update rectangles. We will xor none, some, or all of these rectangles to // produce the new drag box. DocRect drUpdate[4]; INT32 nHowMany; // Find the intersection of the last and new rectangles. We will exclude this from // any xoring as it is already xored. DocRect drCommonDragBox = drNewDragBox.Intersection(m_drLastDragBox); // Calculate the rectangles that need to be xored to change the last into the new // drag box. This depends on how they overlap. if (drCommonDragBox.IsEmpty()) { // There's no intersection between the last drag box and the new drag box, even // though they share a common corner. So xor the full extent of both drag rects. drUpdate[0] = m_drLastDragBox; drUpdate[1] = drNewDragBox; nHowMany = 2; } else if (drNewDragBox.ContainsRect(m_drLastDragBox)) { // The new drag rect completely contains the last one, so clip out the last. nHowMany = ((DocRect&) drNewDragBox).SplitRect(m_drLastDragBox, drUpdate); } else if (m_drLastDragBox.ContainsRect(drNewDragBox)) { // The last drag rect completely contains the new one, so clip out the new. nHowMany = m_drLastDragBox.SplitRect(drNewDragBox, drUpdate); } else { // The drag rectangles overlap but neither completely contains the other, so set // the xor rectangles to be each drag rectangle less the common drag rectangle. nHowMany = m_drLastDragBox.SplitRect(drCommonDragBox, &drUpdate[0]); nHowMany += ((DocRect&) drNewDragBox).SplitRect(drCommonDragBox, &drUpdate[nHowMany]); } // Sanity check. ERROR3IF(nHowMany < 0 || nHowMany > 4, "Wrong number of split rects in OpDragBox::UpdateSolidDragBox\n"); // Draw the xor rects. for (INT32 i = 0; i < nHowMany; i++) { DrawXorRect(drUpdate[i], m_pStartSpread, drUpdate[i]); } }
BOOL PrintPSRenderRegion::WriteClipRegion(KernelDC *pDC, const DocRect& Rect) { if (!Rect.IsValid() || Rect.IsEmpty()) return TRUE; DocCoord c0,c1; c0=Rect.lo; c1=Rect.hi; BOOL ok = pDC->OutputCoord(c0); ok = ok && pDC->OutputCoord(c1); ok = ok && pDC->OutputToken(TEXT("Cp")); ok = ok && pDC->OutputNewLine(); return ok; }
void OpDragBox::DrawXorRect(const DocRect& drClip, Spread* pspdXor, const DocRect& drXor) const { // Check if we have nothing to do. if (drXor.IsEmpty()) return; // Ask the derived class what colour its drag box is. If we are doing solid drags we // want to use the same colour to fill the box as well, otherwise we fill with no colour. StockColour scLineColour = GetBoxColour(); StockColour scFillColour = (m_fDoSolidDragBoxes) ? scLineColour : COLOUR_NONE; // Xor the rect on all supplied render-regions. RenderRegion* pRegion = DocView::RenderOnTop(&((DocRect&) drClip), pspdXor, ClippedEOR); while (pRegion != NULL) { // Set the line and fill colours. pRegion->SetLineColour(scLineColour); pRegion->SetFillColour(scFillColour); // Draw the xored drag box and go on to the next render-region. pRegion->DrawDragRect(&((DocRect&) drXor)); pRegion = DocView::GetNextOnTop(&((DocRect&) drClip)); } }
/******************************************************************************************** > 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; }
/******************************************************************************************** > BOOL MakeBitmapFilter::DoCreateBitmap(Operation *pOp, Document *pDoc, KernelBitmap** ppBitmap) 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::DoCreateBitmap(Operation *pOp, Document *pDoc, KernelBitmap** ppBitmap) { ERROR3IF(ppBitmap == NULL, "NULL bitmap pointer passed to MakeBitmapFilter::DoCreateBitmap"); if (ppBitmap == NULL) return FALSE; pTheBitmap = NULL; *ppBitmap = NULL; // Set the bitmap pointer to null just in case, usually only used by DoExportBitmap pExportBitmap = NULL; // Get pointer to the spread to export. PORTNOTE("spread", "Multi-spread warning!") pSpread = GetFirstSpread(pDoc); // remember the document in the class variable TheDocument = pDoc; // We must now check if there is a selection present so that we can set up whether the // user gets the choice of exporting the selection, drawing or spread if there is a // selection present OR just a choice between the spread or drawing if no selection is // present. // If have a caret selected in a text story then the selection will be almost zero so trap // this case as well. RangeControl rg = GetApplication()->FindSelection()->GetRangeControlFlags(); rg.PromoteToParent = TRUE; GetApplication()->FindSelection()->Range::SetRangeControl(rg); SelRange Rng(*(GetApplication()->FindSelection())); // now, run through the selection selecting all nodes under all compound nodes // if we don't do this then all compound nodes aren't rendered correctly with transparent // bitmaps Node * pNode = Rng.FindFirst(FALSE); while (pNode) { pNode->SetSelected(FALSE); pNode->SetSelected(TRUE); pNode = Rng.FindNext(pNode, FALSE); } rg.PromoteToParent = FALSE; GetApplication()->FindSelection()->Range::SetRangeControl(rg); GetApplication()->UpdateSelection(); DocRect ClipRect = GetApplication()->FindSelection()->GetBoundingRect(); SelectionType Selection = DRAWING; if ( ClipRect.IsEmpty() || ClipRect.Width() < MinExportSize || ClipRect.Height() < MinExportSize) Selection = DRAWING; // no selection present, so choose drawing by default else Selection = SELECTION; // selection present, so choose this by default if (Selection != SELECTION) { BOOL UseDrawingBounds = TRUE; SelRange* pSel = GetApplication()->FindSelection(); if (pSel && pSel->Count()==1) { // Only one thing selected ... Is it the Text Caret per chance ? Node* pSelNode = pSel->FindFirst(); if (pSelNode && pSelNode->IsAVisibleTextNode()) { VisibleTextNode* pTextNode = (VisibleTextNode*)pSelNode; if (pTextNode->IsACaret()) { // Aha! It's the Caret that's selected. // We'll use the bounds of the parent text line instead then ... Node* pTextLine = pTextNode->FindParent(); ERROR3IF(!IS_A(pTextLine, TextLine), "Caret doesn't have a parent text line in DoCreateBitmap"); // Get the bounds of the text line ClipRect = ((TextLine*)pTextLine)->GetBoundingRect(); Selection = SELECTION; UseDrawingBounds = FALSE; } } } if (UseDrawingBounds) { // Work out the size of the rectangle encompassing the drawing (visible layers only) ClipRect = GetSizeOfDrawing(pSpread); } } // Create somewhere to put the user options and fill them up MakeBitmapExportOptions* pMakeBmpExportOptions = (MakeBitmapExportOptions*)CreateExportOptions(); if (pMakeBmpExportOptions == NULL) { Error::SetError(_R(IDS_OUT_OF_MEMORY)); return FALSE; } pMakeBmpExportOptions->RetrieveDefaults(); pMakeBmpExportOptions->SetDepth(32); // create bmp copies shoulda always default to being 32 bit pMakeBmpExportOptions->SetSelectionType(Selection); // Set the BaseBitmapFilter member so we can use base class functionality - blurghh SetExportOptions(pMakeBmpExportOptions); BOOL ok = GetExportOptions( (BitmapExportOptions*)pMakeBmpExportOptions ); BOOL IsAnimation = BmapPrevDlg::m_pExportOptions == NULL; BaseBitmapFilter * pNewFilter = this; BitmapExportOptions * pExportOptions = BmapPrevDlg::m_pExportOptions; if (!IsAnimation) { pNewFilter = pExportOptions->FindBitmapFilterForTheseExportOptions(); // from the exporting point of view we should always have been using png options // set them to the png options for the export part if (pNewFilter) pNewFilter->SetExportOptions(pExportOptions); // gets the real export options that the prevdlg has set up for us BmapPrevDlg::m_pExportOptions = NULL; // take responsibility for this data } else { // the animation export didn't bring up the dlg so never set BmapPrevDlg::m_pExportOptions // so continue with these options pExportOptions = (BitmapExportOptions*)pMakeBmpExportOptions; } SetExportOptions(pExportOptions); if (!ok) { SetExportOptions(NULL); // deletes the filter ptr and nulls it delete pExportOptions; return FALSE; // if cancelled } //////////////// SMFIX pExportOptions->MarkValid(); SetDepthToRender(pExportOptions->GetDepth()); // Set up device context and render region for this export. // This will show a progress hourglass for the objects being rendered // THis will now also write the data out to file via our ExportRenderNodes function if (!PrepareToExport(pSpread, pExportOptions->GetDepth(), pExportOptions->GetDPI(), pExportOptions->GetSelectionType(), pExportOptions->GetDither())) { pNewFilter->SetExportOptions(NULL); SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return FALSE; } RenderInStrips = FALSE; if (!ExportRender(ExportRegion)) { pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return FALSE; } // Now get the converted 32Bit BMP pTheBitmap = GetTheBitmap(pExportOptions); // if we`ve got a transparency index AND we`ve got a 32 Bit Render region with alpha channel info // then we can quickly do if(pExportOptions->GetDepth() <= 8 && pExportOptions->GetTransparencyIndex() != -1 && pTheBitmap) { // What we do now is to go throught the bitmap setting the relavent pixels to transparent // depending on the alpha channel info held in the 32 bit version. if(!ApplyTransparentColoursToBitmap(pTheBitmap,pExportOptions)) { pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it return FALSE; } // Now make sure the bitmap knows that it has a transparent colour! pTheBitmap->SetTransparencyIndex(pExportOptions->GetTransparencyIndex()); } // Set pointer to the bitmap we have created *ppBitmap = pTheBitmap; pNewFilter->SetExportOptions(NULL); // deletes the filter ptr and nulls it SetExportOptions(NULL); delete pExportOptions; CleanUpAfterExport(); return *ppBitmap != NULL; //////////////// SMFIX }