|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Page thumbnail generator class definition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ThumbnailGenerator.h" |
|
21 |
|
22 #include <fbs.h> |
|
23 #include <bitstd.h> |
|
24 #include <w32std.h> |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // ============================= LOCAL FUNCTIONS =============================== |
|
43 |
|
44 // ============================= CLASSES METHODS=============================== |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 |
|
49 CThumbnailGenerator* CThumbnailGenerator::NewL(MPageScalerCallback& aCallback) |
|
50 { |
|
51 CThumbnailGenerator* self = new( ELeave ) CThumbnailGenerator(aCallback); |
|
52 |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(); |
|
56 |
|
57 return self; |
|
58 |
|
59 } |
|
60 |
|
61 CThumbnailGenerator::CThumbnailGenerator(MPageScalerCallback& aCallback) |
|
62 : iCallback(&aCallback), |
|
63 iThumbnailBitmap(NULL), |
|
64 iThumbnailBitmapDevice(NULL), |
|
65 iThumbnailBitmapGc(NULL) |
|
66 { |
|
67 } |
|
68 |
|
69 void CThumbnailGenerator::ConstructL() |
|
70 { |
|
71 } |
|
72 |
|
73 CThumbnailGenerator::~CThumbnailGenerator() |
|
74 { |
|
75 delete iThumbnailBitmap; |
|
76 delete iThumbnailBitmapDevice; |
|
77 delete iThumbnailBitmapGc; |
|
78 } |
|
79 |
|
80 TBool CThumbnailGenerator::CreateBitMapL(TSize aSize, CFbsBitmap*& aBm, CFbsBitmapDevice*& aDev, CFbsBitGc*& aGc) |
|
81 { |
|
82 if ( aSize.iWidth==0 || aSize.iHeight==0 ) |
|
83 { |
|
84 // delete bitmap if there was one |
|
85 delete aGc; |
|
86 delete aDev; |
|
87 delete aBm; |
|
88 aGc = 0; |
|
89 aDev = 0; |
|
90 aBm = 0; |
|
91 return EFalse; |
|
92 } |
|
93 else |
|
94 { |
|
95 if ( aBm && aSize != aBm->SizeInPixels() ) |
|
96 { |
|
97 // resize if different size |
|
98 User::LeaveIfError(aDev->Resize(aSize)); |
|
99 aGc->Resized(); |
|
100 } |
|
101 else if ( !aBm ) |
|
102 { |
|
103 // create new |
|
104 CFbsBitmap* bm = new (ELeave) CFbsBitmap; |
|
105 CleanupStack::PushL(bm); |
|
106 User::LeaveIfError(bm->Create(aSize,EColor64K)); |
|
107 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bm); |
|
108 CleanupStack::PushL(dev); |
|
109 User::LeaveIfError(dev->CreateContext(aGc)); |
|
110 aDev = dev; |
|
111 aBm = bm; |
|
112 CleanupStack::Pop(2); |
|
113 } |
|
114 } |
|
115 return ETrue; |
|
116 } |
|
117 |
|
118 void CThumbnailGenerator::CreatePageThumbnailL() |
|
119 { |
|
120 //Get the thumnail size |
|
121 //if in portrait mode, take Thumbnail(60*height, height) |
|
122 //In lanadscape mode, take Thumbnail(60*width,width) |
|
123 |
|
124 TInt thumbnailWidth; |
|
125 TInt thumbnailHeight; |
|
126 TRect clientRect = iCallback->DocumentViewport(); |
|
127 if (clientRect.Width() > clientRect.Height()) |
|
128 { |
|
129 thumbnailWidth = clientRect.Width() * 60 / 100; |
|
130 thumbnailHeight = clientRect.Width(); |
|
131 } |
|
132 else |
|
133 { |
|
134 thumbnailWidth = clientRect.Height() * 60 / 100; |
|
135 thumbnailHeight = clientRect.Height(); |
|
136 } |
|
137 |
|
138 TRect viewRect = TRect(0, 0, thumbnailWidth, thumbnailHeight); |
|
139 if (!CreateBitMapL(viewRect.Size(), iThumbnailBitmap, iThumbnailBitmapDevice, iThumbnailBitmapGc)) |
|
140 { |
|
141 return; |
|
142 } |
|
143 |
|
144 iCallback->DrawDocumentPart(*iThumbnailBitmapGc,iThumbnailBitmap,viewRect); |
|
145 TSize bitmapSize = iThumbnailBitmap->SizeInPixels(); |
|
146 iCallback->ScaledPageChanged(viewRect, true, false); |
|
147 } |
|
148 |
|
149 |