Using SVG in Symbian C++
Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition, MR
Platform Security
Capabilities: )
Article
Keywords: AknIconUtils, SVG
Created: tepaa
(01 Jul 2008)
Last edited: hamishwillee
(15 Jun 2012)
Overview
The following example shows how to add an SVG image into an application and draw it.
You can use, for example, Inkscape which is a free SVG editor.
MMP file
The following capabilities and libraries are required:
CAPABILITY NONE
LIBRARY aknicon.lib
icons_aif_scalable.mk Icon make file
This is the icons makefile that generates the icons.mif file from your icon.svg SVG image.
ifeq (WINS,$(findstring WINS, $(PLATFORM)))
ZDIR=$(EPOCROOT)epoc32\release\$(PLATFORM)\$(CFG)\Z
else
ZDIR=$(EPOCROOT)epoc32\data\z
endif
TARGETDIR=$(ZDIR)\resource\apps
MY_ICONS=$(TARGETDIR)\icons.mif
HEADERDIR=$(EPOCROOT)epoc32\include
MY_ICONS_HEADER=$(HEADERDIR)\icons.mbg
ICONDIR=..\gfx
do_nothing :
@rem do_nothing
MAKMAKE : do_nothing
BLD : do_nothing
CLEAN : do_nothing
LIB : do_nothing
CLEANLIB : do_nothing
RESOURCE :
mifconv $(MY_ICONS) /h$(MY_ICONS_HEADER) \
/c32 $(ICONDIR)\icon.svg
FREEZE : do_nothing
SAVESPACE : do_nothing
RELEASABLES :
@echo $(MY_ICONS)
@echo $(MY_ICONS_HEADER)
FINAL : do_nothing
bld.inf file
Add the gnumakefile into your applicatin bld.inf:
PRJ_MMPFILES
gnumakefile icons_aif_scalable.mk
Header file
public:
void LoadIconL(TInt aIndex, CFbsBitmap*& aBitmap,
CFbsBitmap*& aMask, TSize& aSize);
void Draw( const TRect& aRect ) const;
private:
CFbsBitmap* iBitmap;
CFbsBitmap* iMask;
TSize iBitmapSize;
Source file
void CYourControl::ConstructL()
{
iBitmapSize = TSize(50,50);
LoadIconL(EMbmIconsIcon, iBitmap, iMask, iBitmapSize);
}
void CYourControl::LoadIconL(TInt aIndex, CFbsBitmap*& aBitmap,
CFbsBitmap*& aMask, TSize& aSize)
{
_LIT(KIconsFile, "\\resource\\apps\\icons.mif");
// Create icon from SVG
AknIconUtils::CreateIconL(aBitmap, aMask, KIconsFile, aIndex, aIndex + 1);
// Give size
AknIconUtils::SetSize(aBitmap, aSize);
}
void CMultiViewsContainer1::Draw( const TRect& aRect ) const
{
CWindowGc& gc = SystemGc();
// Draws icon bitmap from SVG into screen
if (iBitmap)
{
TPoint pos(0,0);
TRect rect(TPoint(0,0), iBitmapSize);
gc.BitBltMasked(pos, iBitmap, rect, iMask, EFalse);
}
}
pkg file
Add the following line into your .pkg file. It will install the .mif file (SVG icons).
;Files to install
"epoc32\data\Z\RESOURCE\apps\icons.mif" -"!:\resource\apps\icons.mif"
Postconditions
The SVG file has been created as an icon and drawn on the screen.
See also
KIS000398_-_SVG_rendering_problems_caused_by_missing_viewBox_attribute
KIS000531_-_Compatibility_problem_with_binary-encoded_SVG_images


Creating SVG with Inkscape is not enough or it would not be usable with Symbian. Symbian is using SVGT profile. You can convert SVG to SVGT with SVGTBINENCODE.EXE from tools.