#include <bmpexdoc.h>
Inheritance diagram for BitmapExportDocument:
Public Member Functions | |
BitmapExportDocument (BOOL fHide=TRUE) | |
BitmapExportDocument constructor. | |
BOOL | Init (KernelBitmap *pBitmap, const DocRect &RectToExport) |
This method initialises the document It calls down to Document::Init, then adds an insertion Layer node to the bottom of the basic doc tree. It then adds a totally transparent NodeRectangle and a NodeBitmap with the default NodeBitmap attributes referencing the specified KernelBitmap. | |
BOOL | SetBitmap (KernelBitmap *pBitmap) |
This function sets the bitmap method initialises the document It is an internal method, called by Initialise() It calls down to Document::Init, then adds an insertion Layer node to the bottom of the basic doc tree. It then adds a NodeBitmap referencing the specified KernelBitmap. | |
Protected Member Functions | |
BOOL | InitFailed (void) |
This function deletes the NodeBitmap and then calls Document::InitFailed(). | |
CC_DECLARE_DYNAMIC (BitmapExportDocument) | |
Protected Attributes | |
NodeBitmap * | pBitmapNode |
DocRect | ExportRect |
> class BitmapExportDocument : public Document
Definition at line 119 of file bmpexdoc.h.
|
BitmapExportDocument constructor.
Definition at line 130 of file bmpexdoc.cpp. 00131 : Document(fHide), 00132 pBitmapNode(0) 00133 { 00134 // Empty. 00135 }
|
|
|
|
This method initialises the document It calls down to Document::Init, then adds an insertion Layer node to the bottom of the basic doc tree. It then adds a totally transparent NodeRectangle and a NodeBitmap with the default NodeBitmap attributes referencing the specified KernelBitmap.
Definition at line 158 of file bmpexdoc.cpp. 00159 { 00160 // Don't attach any CCamDoc. 00161 if (!Document::Init(0)) return(FALSE); 00162 00163 Node *pSpread = FindFirstSpread(); 00164 ERROR3IF(pSpread == NULL, "No Spread in document!"); 00165 00166 Node *pLayer = pSpread->FindFirstChild(); 00167 ERROR3IF(pLayer == NULL, "No Spread-child in document!"); 00168 00169 // Store away the rectangle 00170 ExportRect = RectToExport; 00171 00172 // Now scan the children of the first spread until we find a layer, or run out of nodes 00173 while (pLayer != NULL && !pLayer->IsLayer()) 00174 pLayer = pLayer->FindNext(); 00175 00176 if (pLayer == NULL) // No Layer, so we'd better add one for ourselves 00177 { 00178 String_256 LayerID = String_256(_R(IDS_K_CLIPINT_LAYERNAME)); 00179 pLayer = new Layer(pSpread, LASTCHILD, LayerID); 00180 if (pLayer == NULL) 00181 return(InitFailed()); 00182 } 00183 00184 // Create a new NodeRect 00185 NodeRect* pRectNode = new NodeRect(pLayer, FIRSTCHILD); 00186 00187 // Failed so cleanup and exit 00188 if (pRectNode == NULL) 00189 return(InitFailed()); 00190 00191 // Initilaise the node 00192 if (!pRectNode->SetUpPath(6,6)) 00193 return(InitFailed()); 00194 00195 // Create the rectangle 00196 pRectNode->CreateShape(ExportRect); 00197 00198 // Give the rectangle a line colour 00199 #if 0 00200 // This memory leaks a StrokeColourAttribute 00201 StrokeColourAttribute* pAttrValue = new StrokeColourAttribute(DocColour(COLOUR_TRANS)); 00202 if (pAttrValue == NULL) 00203 return(InitFailed()); 00204 00205 NodeAttribute* pAttr = pAttrValue->MakeNode(); 00206 if (pAttr == NULL) 00207 return(InitFailed()); 00208 00209 // Attach the attribute to the rectangle 00210 pAttr->AttachNode(pRectNode, FIRSTCHILD); 00211 #else 00212 // Do what ApplyDefaultBitmapAttrs does 00213 Node* pLineColAttr = new AttrStrokeColour(); 00214 if (pLineColAttr == NULL) 00215 return(InitFailed()); 00216 00217 DocColour none(COLOUR_NONE); 00218 ((AttrFillGeometry*)pLineColAttr)->SetStartColour(&none); 00219 pLineColAttr->AttachNode(pRectNode, FIRSTCHILD); 00220 #endif 00221 00222 // Create a NodeBitmap (don't attach it to the tree straight away 'cos we 00223 // have to put the attributes on it first) 00224 00225 pBitmapNode = new NodeBitmap(); 00226 if (pBitmapNode == NULL) 00227 return(InitFailed()); 00228 00229 if (!pBitmapNode->SetUpPath(6,6)) 00230 return(InitFailed()); 00231 00232 pBitmapNode->CreateShape(ExportRect); 00233 00234 if (!SetBitmap(pBitmap)) 00235 return(InitFailed()); 00236 00237 // Set the bitmap's attributes 00238 // This must be done before the NodeBitmap is inserted into the tree 00239 if (!pBitmapNode->ApplyDefaultBitmapAttrs(NULL)) 00240 return(InitFailed()); 00241 00242 // Attach it to the tree as the next sibling of the rectangle 00243 pBitmapNode->AttachNode(pRectNode, NEXT); 00244 00245 // Success... 00246 return(TRUE); 00247 }
|
|
This function deletes the NodeBitmap and then calls Document::InitFailed().
Reimplemented from Document. Definition at line 369 of file bmpexdoc.cpp. 00370 { 00371 if (pBitmapNode) 00372 { 00373 delete pBitmapNode; 00374 pBitmapNode = NULL; 00375 } 00376 00377 return(Document::InitFailed()); 00378 }
|
|
This function sets the bitmap method initialises the document It is an internal method, called by Initialise() It calls down to Document::Init, then adds an insertion Layer node to the bottom of the basic doc tree. It then adds a NodeBitmap referencing the specified KernelBitmap.
Definition at line 268 of file bmpexdoc.cpp. 00269 { 00270 TRACEUSER( "Gerry", _T("BitmapExportDocument::SetBitmap()\n")); 00271 00272 ERROR2IF(pBitmap == NULL, FALSE, "NULL bitmap passed to SetBitmap()\n"); 00273 ERROR2IF(pBitmapNode == NULL, FALSE, "pBitmapNode is NULL in SetBitmap()\n"); 00274 00275 // Attach the bitmap to our node 00276 // 00277 // Note: Neville 18/9/97 00278 // If the bitmap is a lone bitmap i.e. not attached to any document, then we 00279 // must attach it properly to this document so that it gets cleaned out 00280 // rather than memory leaking. If not, then we are just temporarily using 00281 // the bitmap and so everything should be ok. We need to work in the following 00282 // situations:- 00283 // - Selecting multiple bitmaps in the bitmap gallery and saving as animated GIF. 00284 // Here we are passed a list of bitmaps which are already in use in the source 00285 // document. 00286 // - Making a new clipart index for bitmaps. Here we are passed a brand spanking 00287 // new bitmap which is not on any lists. This used to memory leak. 00288 BitmapList* pBmpList = pBitmap->GetParentBitmapList(); 00289 if (pBmpList != NULL) 00290 { 00291 // This will memory leak a kernel bitmap each time if it is not on a parent 00292 // document list. You will also end up with a KernelBitmap which contains 00293 // a deleted ActualBitmap pointer, which is very bad! 00294 pBitmapNode->GetBitmapRef()->SetBitmap(pBitmap); 00295 } 00296 else 00297 { 00298 // This is the same technique that the BaseBitmapFilter uses and so must be correct! 00299 pBitmapNode->GetBitmapRef()->Attach(pBitmap, this); 00300 if (pBitmapNode->GetBitmap() != pBitmap) 00301 { 00302 // It didn't use the bitmap we gave it, so we can delete it 00303 delete pBitmap; 00304 } 00305 } 00306 00307 BitmapInfo Info; 00308 pBitmapNode->GetBitmap()->ActualBitmap->GetInfo(&Info); 00309 00310 // Calculate the rectangle for this bitmap 00311 // We make it as large as possible (within the ExportRect) 00312 // without changing the aspect ration 00313 00314 INT32 RectWidth = ExportRect.Width(); 00315 INT32 RectHeight = ExportRect.Height(); 00316 00317 double xScale = (double) RectWidth / (double) Info.RecommendedWidth; 00318 double yScale = (double) RectHeight / (double) Info.RecommendedHeight; 00319 00320 DocRect BitmapRect; 00321 00322 BitmapRect.lo.x = 0; 00323 BitmapRect.lo.y = 0; 00324 00325 if (xScale < yScale) 00326 { 00327 // Bitmap will be full width 00328 BitmapRect.hi.x = RectWidth; 00329 BitmapRect.hi.y = (INT32) ((double) Info.RecommendedHeight * xScale); 00330 00331 // Center the bitmap vertically in the rectangle 00332 BitmapRect.Translate(0, (RectHeight - BitmapRect.Height()) / 2); 00333 } 00334 else 00335 { 00336 // Bitmap will be full height 00337 BitmapRect.hi.x = (INT32) ((double) Info.RecommendedWidth * yScale); 00338 BitmapRect.hi.y = RectHeight; 00339 00340 // Center the bitmap horizontally in the rectangle 00341 BitmapRect.Translate((RectWidth - BitmapRect.Width()) / 2, 0); 00342 } 00343 00344 // Delete the node's path 00345 // Because CreateShape inserts a rectangle at the beginning of the path 00346 pBitmapNode->InkPath.DeleteFromElement(0); 00347 00348 // And create the shape 00349 pBitmapNode->CreateShape(BitmapRect); 00350 00351 return(TRUE); 00352 }
|
|
Definition at line 133 of file bmpexdoc.h. |
|
Definition at line 132 of file bmpexdoc.h. |