33 #include <QFile> |
33 #include <QFile> |
34 #include "hbpixmapiconimpl_p.h" |
34 #include "hbpixmapiconimpl_p.h" |
35 #include "hbmemoryutils_p.h" |
35 #include "hbmemoryutils_p.h" |
36 #include "hbiconsource_p.h" |
36 #include "hbiconsource_p.h" |
37 #include "hbthemeserverutils_p.h" |
37 #include "hbthemeserverutils_p.h" |
|
38 |
|
39 #if defined (Q_OS_SYMBIAN) |
|
40 #include <VG/openvg.h> |
|
41 #include <VG/vgcontext_symbian.h> |
|
42 #endif //Q_OS_SYMBIAN |
38 |
43 |
39 /*! |
44 /*! |
40 @hbserver |
45 @hbserver |
41 \class HbPixmapIconProcessor |
46 \class HbPixmapIconProcessor |
42 \brief HbPixmapIconProcessor is responsible for retrieving the pixmap raster data from the icon file, |
47 \brief HbPixmapIconProcessor is responsible for retrieving the pixmap raster data from the icon file, |
124 if (iconType == "SVG") { |
129 if (iconType == "SVG") { |
125 isIconCreated = renderSvgToPixmap(iconPath); |
130 isIconCreated = renderSvgToPixmap(iconPath); |
126 } else if (iconType == "PIC") { |
131 } else if (iconType == "PIC") { |
127 isIconCreated = renderPicToPixmap(iconPath); |
132 isIconCreated = renderPicToPixmap(iconPath); |
128 } else if (iconType == "NVG") { |
133 } else if (iconType == "NVG") { |
129 isIconCreated = storeNvgData(iconPath); |
134 #if defined (Q_OS_SYMBIAN) |
|
135 isIconCreated = renderNvgToPixmap(iconPath); |
|
136 #endif //Q_OS_SYMBIAN |
130 } else { |
137 } else { |
131 isIconCreated = renderOtherFormatsToPixmap(iconPath); |
138 isIconCreated = renderOtherFormatsToPixmap(iconPath); |
132 } |
139 } |
133 if (isIconCreated) { |
140 if (isIconCreated) { |
134 // Apply mirroring if required |
141 // Apply mirroring if required |
249 } |
256 } |
250 painter.drawPicture(QPointF(0.0, 0.0), *picture); |
257 painter.drawPicture(QPointF(0.0, 0.0), *picture); |
251 painter.end(); |
258 painter.end(); |
252 isIconCreated = true; |
259 isIconCreated = true; |
253 return isIconCreated; |
260 return isIconCreated; |
254 } |
|
255 |
|
256 /*! |
|
257 \fn HbPixmapIconProcessor::storeNvgData() |
|
258 \a iconpath |
|
259 */ |
|
260 bool HbPixmapIconProcessor::storeNvgData(const QString& iconPath) |
|
261 { |
|
262 bool isIconCreated = false; |
|
263 if (iconKey.size.isNull()) { |
|
264 QSize dummySize(50, 50); |
|
265 pixmap = QPixmap(dummySize); |
|
266 pixmap.fill(Qt::transparent); |
|
267 isIconCreated = true; |
|
268 return isIconCreated; |
|
269 } |
|
270 |
|
271 QFile file(iconPath); |
|
272 if (!file.open(QIODevice::NotOpen | QIODevice::ReadOnly)) |
|
273 return isIconCreated; |
|
274 else { |
|
275 // @ToDo |
|
276 // QByteArray byteArray = file.readAll() ; |
|
277 |
|
278 // Draw the nvg file on the offscreen eglsurface |
|
279 // copy content from surface to pixmap |
|
280 // createPixmapFromEglSurface(byteArray); |
|
281 return isIconCreated; |
|
282 } |
|
283 |
|
284 |
|
285 } |
261 } |
286 |
262 |
287 /*! |
263 /*! |
288 \fn HbPixmapIconProcessor::renderOtherFormatsToPixmap() |
264 \fn HbPixmapIconProcessor::renderOtherFormatsToPixmap() |
289 \a iconpath |
265 \a iconpath |
389 } |
365 } |
390 setPixmap(finalPixmap); |
366 setPixmap(finalPixmap); |
391 return true; |
367 return true; |
392 } |
368 } |
393 |
369 |
|
370 #if defined (Q_OS_SYMBIAN) |
|
371 /** |
|
372 * HbNvgIconProcessor::renderNvgToPixmap() |
|
373 * This is used to render NVG data to a pixmap using the Software OpenVG |
|
374 * \a iconPath |
|
375 */ |
|
376 bool HbPixmapIconProcessor::renderNvgToPixmap(const QString& iconPath) |
|
377 { |
|
378 bool isIconCreated = false; |
|
379 bool isDefaultSize = iconKey.size.isNull(); |
|
380 HbIconSource *source = HbThemeServerUtils::getIconSource(iconPath); |
|
381 QByteArray *sourceByteArray = source->byteArray(); |
|
382 if( !sourceByteArray ) { |
|
383 return false; |
|
384 } |
|
385 QByteArray byteArray = *sourceByteArray; |
|
386 QSizeF renderSize = source->defaultSize(); |
|
387 defaultSize = renderSize.toSize(); |
|
388 if (!isDefaultSize) { |
|
389 renderSize.scale(iconKey.size,iconKey.aspectRatioMode); |
|
390 } |
|
391 size = renderSize.toSize(); |
|
392 TSize surfaceSize(TSize(size.width(), size.height())); |
|
393 |
|
394 QScopedPointer<CFbsBitmap> bitmapData(new CFbsBitmap()); |
|
395 |
|
396 TInt err = bitmapData.data()->Create(surfaceSize, EColor16MA); |
|
397 if(err != KErrNone) { |
|
398 return isIconCreated; |
|
399 } |
|
400 |
|
401 //Reset the surface incase already present |
|
402 VGISymbianTerminate(); |
|
403 |
|
404 // Surface creation |
|
405 err = VGISymbianInitialize( surfaceSize, VGI_COLORSPACE_SRGB ); |
|
406 if( err != KErrNone) { |
|
407 return isIconCreated; |
|
408 } |
|
409 |
|
410 QScopedPointer<CNvgEngine> nvgEngine(CNvgEngine::NewL()); |
|
411 //CNvgEngine* nvgEngine = CNvgEngine::NewL(); |
|
412 HbNvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(iconKey.aspectRatioMode); |
|
413 nvgEngine.data()->SetPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, settings.type); |
|
414 // Rendering onto active surface |
|
415 TPtr8 data ((unsigned char*)byteArray.data(), byteArray.length(), byteArray.length()); |
|
416 err = nvgEngine.data()->DrawNvg(data, surfaceSize, bitmapData.data(), 0); |
|
417 if(err !=KErrNone) { |
|
418 return isIconCreated; |
|
419 } |
|
420 |
|
421 //Copy the data from the surface |
|
422 err = VGISymbianCopyToBitmap(bitmapData.data(), 0, VGI_COPY_TRANSPARENT_PIXELS); |
|
423 if(err !=KErrNone) { |
|
424 return isIconCreated; |
|
425 } |
|
426 //Get Pixmap from the Symbian Native format. |
|
427 pixmap = QPixmap::fromSymbianCFbsBitmap(bitmapData.data()); |
|
428 isIconCreated = true; |
|
429 |
|
430 //Clean Up |
|
431 VGISymbianTerminate(); |
|
432 return isIconCreated; |
|
433 } |
|
434 |
|
435 /*! |
|
436 \fn HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio() |
|
437 \a aspectRatio |
|
438 */ |
|
439 HbNvgAspectRatioSettings HbPixmapIconProcessor::mapKeyAspectRatioToNvgAspectRatio( |
|
440 Qt::AspectRatioMode aspectRatio) const |
|
441 { |
|
442 HbNvgAspectRatioSettings settings; |
|
443 switch(aspectRatio) { |
|
444 |
|
445 case Qt::IgnoreAspectRatio: { |
|
446 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_None; |
|
447 settings.type = ENvgMeet; |
|
448 break; |
|
449 } |
|
450 case Qt::KeepAspectRatio: { |
|
451 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
452 settings.type = ENvgMeet; |
|
453 break; |
|
454 } |
|
455 case Qt::KeepAspectRatioByExpanding: { |
|
456 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
457 settings.type = ENvgSlice; |
|
458 break; |
|
459 } |
|
460 default: { |
|
461 settings.nvgAlignStatusAndAspectRatio = ENvgPreserveAspectRatio_XmidYmid; |
|
462 settings.type = ENvgMeet; |
|
463 break; |
|
464 } |
|
465 } |
|
466 return settings; |
|
467 } |
|
468 #endif //Q_OS_SYMBIAN |
|
469 |