src/hbcore/svgext/hbnvgdecoder/hbnvgcsicon.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    34 #include <QScopedArrayPointer>
    34 #include <QScopedArrayPointer>
    35 
    35 
    36 /*!
    36 /*!
    37   NVG-CS version
    37   NVG-CS version
    38  */
    38  */
    39 const int Version2   = 2;
    39 const qint32 Version2   = 2;
    40 
    40 
    41 /*!
    41 /*!
    42   File offsets
    42   File offsets
    43  */
    43  */
    44 const int NVG_VIEWBOX_WIDTH_OFS = 44;
    44 const qint32 NVG_VIEWBOX_WIDTH_OFS = 44;
    45 const int NVG_VIEWBOX_HEIGHT_OFS = 48;
    45 const qint32 NVG_VIEWBOX_HEIGHT_OFS = 48;
    46 const int NVG_VIEWBOX_X_OFS = 36;
    46 const qint32 NVG_VIEWBOX_X_OFS = 36;
    47 const int NVG_VIEWBOX_Y_OFS = 40;
    47 const qint32 NVG_VIEWBOX_Y_OFS = 40;
    48 const int NVG_PATHDATATYPE_OFS = 26;
    48 const qint32 NVG_PATHDATATYPE_OFS = 26;
    49 const int NVG_SCALE_OFS = 28;
    49 const qint32 NVG_SCALE_OFS = 28;
    50 const int NVG_BIAS_OFS = 32;
    50 const qint32 NVG_BIAS_OFS = 32;
    51 const int NVG_COMMANDSECTION_OFS = 2;
    51 const qint32 NVG_COMMANDSECTION_OFS = 2;
    52 const int NVG_RGBA_OFS = 4;
    52 const qint32 NVG_RGBA_OFS = 4;
    53 const int NVG_HEADERSIZE_OFS = 4;
    53 const qint32 NVG_HEADERSIZE_OFS = 4;
    54 const int NVG_PAINTSECTION_LINEARGRAD_TRANSFORM_OFFSET = 20;
    54 const qint32 NVG_PAINTSECTION_LINEARGRAD_TRANSFORM_OFFSET = 20;
    55 const int NVG_PAINTSECTION_RADIALGRAD_TRANSFORM_OFFSET = 24;
    55 const qint32 NVG_PAINTSECTION_RADIALGRAD_TRANSFORM_OFFSET = 24;
    56 const int NVG_VERSION_OFS         = 3;
    56 const qint32 NVG_VERSION_OFS         = 3;
    57 
    57 
    58 /*!
    58 /*!
    59   NVG-CS commands
    59   NVG-CS commands
    60  */ 
    60  */
    61 const int CMD_SET_FILL_PAINT           = 4  << 24;
    61 const qint32 CMD_SET_FILL_PAINT           = 4  << 24;
    62 const int CMD_SET_COLOR_RAMP           = 6  << 24;
    62 const qint32 CMD_SET_COLOR_RAMP           = 6  << 24;
    63 const int CMD_DRAW_PATH                = 7  << 24;
    63 const qint32 CMD_DRAW_PATH                = 7  << 24;
    64 const int CMD_SET_TRANSFORMATION       = 8  << 24;
    64 const qint32 CMD_SET_TRANSFORMATION       = 8  << 24;
    65 const int CMD_SET_STROKE_PAINT         = 5  << 24;
    65 const qint32 CMD_SET_STROKE_PAINT         = 5  << 24;
    66 const int CMD_SET_STROKE_WIDTH         = 9  << 24;
    66 const qint32 CMD_SET_STROKE_WIDTH         = 9  << 24;
    67 const int CMD_SET_STROKE_LINE_JOIN_CAP = 10 << 24;
    67 const qint32 CMD_SET_STROKE_LINE_JOIN_CAP = 10 << 24;
    68 const int CMD_SET_STROKE_MITER_LIMIT   = 11 << 24;
    68 const qint32 CMD_SET_STROKE_MITER_LIMIT   = 11 << 24;
    69 
    69 
    70 /*!
    70 /*!
    71  Stroke cap style
    71  Stroke cap style
    72  */
    72  */
    73 const int CAP_BUTT        = 1;
    73 const qint32 CAP_BUTT        = 1;
    74 const int CAP_SQUARE      = 2;
    74 const qint32 CAP_SQUARE      = 2;
    75 const int CAP_ROUND       = 3;
    75 const qint32 CAP_ROUND       = 3;
    76 
    76 
    77 /*!
    77 /*!
    78  Stroke join style
    78  Stroke join style
    79  */
    79  */
    80 const int LINE_JOIN_BEVEL = 1;
    80 const qint32 LINE_JOIN_BEVEL = 1;
    81 const int LINE_JOIN_MITER = 2;
    81 const qint32 LINE_JOIN_MITER = 2;
    82 const int LINE_JOIN_ROUND = 3;
    82 const qint32 LINE_JOIN_ROUND = 3;
    83 
    83 
    84 /*!
    84 /*!
    85  Fill paint type
    85  Fill paint type
    86  */
    86  */
    87 const int PAINT_FLAT      = 1;
    87 const qint32 PAINT_FLAT      = 1;
    88 const int PAINT_LGRAD     = 2;
    88 const qint32 PAINT_LGRAD     = 2;
    89 const int PAINT_RGRAD     = 3;
    89 const qint32 PAINT_RGRAD     = 3;
    90 
    90 
    91 /*!
    91 /*!
    92  Stroke paint type
    92  Stroke paint type
    93  */
    93  */
    94 const int STROKE_LGRAD        = 2;
    94 const qint32 STROKE_LGRAD        = 2;
    95 const int STROKE_RGRAD        = 3;
    95 const qint32 STROKE_RGRAD        = 3;
    96 const int STROKE_COLOR_RAMP   = 4;
    96 const qint32 STROKE_COLOR_RAMP   = 4;
    97 
    97 
    98 /*!
    98 /*!
    99  Transform encoding values
    99  Transform encoding values
   100  */
   100  */
   101 const int TRANSFORM_COMPLETE    = 0;
   101 const qint32 TRANSFORM_COMPLETE    = 0;
   102 const int TRANSFORM_SCALING     = 2;
   102 const qint32 TRANSFORM_SCALING     = 2;
   103 const int TRANSFORM_SHEARING    = 4;
   103 const qint32 TRANSFORM_SHEARING    = 4;
   104 const int TRANSFORM_ROTATION    = 8;
   104 const qint32 TRANSFORM_ROTATION    = 8;
   105 const int TRANSFORM_TRANSLATION = 16;
   105 const qint32 TRANSFORM_TRANSLATION = 16;
   106 
   106 
   107 const VGfloat IdentityMatrix[] = {
   107 const VGfloat identityMatrix[] = {
   108     1.0f, 0.0f, 0.0f,
   108     1.0f, 0.0f, 0.0f,
   109     0.0f, 1.0f, 0.0f,
   109     0.0f, 1.0f, 0.0f,
   110     0.0f, 0.0f , 1.0f
   110     0.0f, 0.0f , 1.0f
   111 };
   111 };
   112 
   112 
   113     /**
   113 /**
   114      * @fn      Constructor
   114  * @fn      Constructor
   115      * @Version
   115  * @Version
   116      * @parameter: buffer - None
   116  * @parameter: buffer - None
   117      *
   117  *
   118      * @return: None
   118  * @return: None
   119      */
   119  */
   120 
   120 
   121 HbNvgCsIcon::HbNvgCsIcon()
   121 HbNvgCsIcon::HbNvgCsIcon()
   122         :   mPaintFill(VG_INVALID_HANDLE),
   122         :   mPaintFill(VG_INVALID_HANDLE),
   123         mPaintStroke(VG_INVALID_HANDLE),
   123         mPaintStroke(VG_INVALID_HANDLE),
   124         mVgPath(VG_INVALID_HANDLE),
   124         mVgPath(VG_INVALID_HANDLE),
   125         mLastPathDataType(0),
   125         mLastPathDataType(0),
   126         mDoFill (VG_FALSE),
   126         mDoFill(VG_FALSE),
   127         mDoStroke(VG_FALSE),
   127         mDoStroke(VG_FALSE),
   128         mCreatingNvgIcon(0),
   128         mCreatingNvgIcon(0),
   129         mPreserveAspectSetting(HbNvgEngine::NvgPreserveAspectRatioXmidYmid),
   129         mPreserveAspectSetting(HbNvgEngine::NvgPreserveAspectRatioXmidYmid),
   130         mSmilFitSetting(HbNvgEngine::NvgMeet),
   130         mSmilFitSetting(HbNvgEngine::NvgMeet),
   131         mNvgIconData(0),
   131         mNvgIconData(0),
   134         mLastStrokePaintType(0),
   134         mLastStrokePaintType(0),
   135         mLastFillPaintColor(0),
   135         mLastFillPaintColor(0),
   136         mLastStrkePaintColor(0),
   136         mLastStrkePaintColor(0),
   137         mResetFillPaint(0),
   137         mResetFillPaint(0),
   138         mResetStrokePaint(0),
   138         mResetStrokePaint(0),
   139         mMirroringMode(false)
   139         mMirrored(false)
   140 {
   140 {
   141 }
   141 }
   142 
   142 
   143 void HbNvgCsIcon::setIconData(const QByteArray &buffer)
   143 void HbNvgCsIcon::setIconData(const QByteArray &buffer)
   144 {
   144 {
   157         vgDestroyPaint(mPaintStroke);
   157         vgDestroyPaint(mPaintStroke);
   158     }
   158     }
   159     if (mVgPath) {
   159     if (mVgPath) {
   160         vgDestroyPath(mVgPath);
   160         vgDestroyPath(mVgPath);
   161     }
   161     }
   162     
   162 
   163     vgSetPaint(VG_INVALID_HANDLE, VG_FILL_PATH);
   163     vgSetPaint(VG_INVALID_HANDLE, VG_FILL_PATH);
   164     vgSetPaint(VG_INVALID_HANDLE, VG_STROKE_PATH);
   164     vgSetPaint(VG_INVALID_HANDLE, VG_STROKE_PATH);
   165     
   165 
   166     delete mNvgIconData;
   166     delete mNvgIconData;
   167     delete mOpenVgHandles;
   167     delete mOpenVgHandles;
   168 }
   168 }
   169 
   169 
   170 
   170 
   174     mViewBoxY = y;
   174     mViewBoxY = y;
   175     mViewBoxW = w;
   175     mViewBoxW = w;
   176     mViewBoxH = h;
   176     mViewBoxH = h;
   177 }
   177 }
   178 
   178 
   179 void  HbNvgCsIcon::setPreserveAspectRatio(HbNvgEngine::NvgAlignStatusType preserveAspectSetting,
   179 /*!
   180         HbNvgEngine::NvgMeetOrSliceType smilFitSetting)
   180     set the aspectRatio \a preserveAspectSetting and \a smilFitSetting
       
   181     to be applied on the nvgicon.
       
   182 */
       
   183 void  HbNvgCsIcon::setPreserveAspectRatio(HbNvgEngine::HbNvgAlignType preserveAspectSetting,
       
   184         HbNvgEngine::HbNvgMeetType smilFitSetting)
   181 {
   185 {
   182     mPreserveAspectSetting = preserveAspectSetting;
   186     mPreserveAspectSetting = preserveAspectSetting;
   183     mSmilFitSetting = smilFitSetting;
   187     mSmilFitSetting = smilFitSetting;
   184 }
   188 }
   185 
   189 
   186 void HbNvgCsIcon::setMirroringMode(bool mirroringMode)
   190 void HbNvgCsIcon::enableMirroring(bool mirroringMode)
   187 {
   191 {
   188     mMirroringMode = mirroringMode;
   192     mMirrored = mirroringMode;
   189 }
   193 }
   190 
   194 
       
   195 /*!
       
   196     Set the \a angle for rotation of the nvgicon at the
       
   197     coordiantes  \a x and \a y.
       
   198 */
   191 void HbNvgCsIcon::rotate(float angle, float xValue, float yValue)
   199 void HbNvgCsIcon::rotate(float angle, float xValue, float yValue)
   192 {
   200 {
   193      mRotationAngle  = angle;
   201     mRotationAngle  = angle;
   194      mRotationX      = xValue;
   202     mRotationX      = xValue;
   195      mRotationY      = yValue;
   203     mRotationY      = yValue;
   196 }
   204 }
   197 
   205 
       
   206 /*!
       
   207     Do the direct draw of the nvg graphic data \a buffer of size \a targetSize
       
   208     and return the status of the draw.
       
   209 */
   198 void HbNvgCsIcon ::directDraw(const QByteArray &buffer, const QSize &targetSize)
   210 void HbNvgCsIcon ::directDraw(const QByteArray &buffer, const QSize &targetSize)
   199 {
   211 {
   200     drawCommandSection(buffer, targetSize, 0);
   212     drawCommandSection(buffer, targetSize, 0);
   201 }
   213 }
   202 
   214 
       
   215 /*!
       
   216     Create the nvg graphic data \a buffer of size \a targetSize
       
   217     and return the status of the draw.
       
   218 */
   203 void HbNvgCsIcon::create(const QByteArray &buffer, const QSize& targetSize)
   219 void HbNvgCsIcon::create(const QByteArray &buffer, const QSize& targetSize)
   204 {
   220 {
   205     drawCommandSection(buffer, targetSize, 1);
   221     drawCommandSection(buffer, targetSize, 1);
   206 }
   222 }
   207 
   223 
   208 void HbNvgCsIcon::drawCommandSection(const QByteArray &buffer, const QSize & targetSize,
   224 void HbNvgCsIcon::drawCommandSection(const QByteArray &buffer, const QSize & targetSize,
   209         int objectCaching)
   225                                      qint32 objectCaching)
   210 {       
   226 {
   211     mCreatingNvgIcon = objectCaching;
   227     mCreatingNvgIcon = objectCaching;
   212  
   228 
   213     HbDereferencer iconData(buffer);
   229     HbDereferencer iconData(buffer);
   214     qint16 lHeaderSize  = iconData.derefInt16(NVG_HEADERSIZE_OFS);
   230     qint16 headerSize  = iconData.derefInt16(NVG_HEADERSIZE_OFS);
   215     quint8 nvgVersion   = iconData.derefInt8(NVG_VERSION_OFS);
   231     quint8 nvgVersion   = iconData.derefInt8(NVG_VERSION_OFS);
   216  
   232 
   217     HbNvgEngine::NvgErrorType errInit = HbNvgEngine::NvgErrNone;
   233     HbNvgEngine::HbNvgErrorType errInit = HbNvgEngine::NvgErrNone;
   218         
   234 
   219     errInit = initializeGc();
   235     errInit = initializeGc();
   220     if (HbNvgEngine::NvgErrNone != errInit){
   236     if (HbNvgEngine::NvgErrNone != errInit) {
   221        throw HbNvgException(errInit);
       
   222     }
       
   223         
       
   224     qint16 lPathDataType = iconData.derefInt16(NVG_PATHDATATYPE_OFS);
       
   225     float lScale         = iconData.derefReal32(NVG_SCALE_OFS);
       
   226     float lBias          = iconData.derefReal32(NVG_BIAS_OFS);
       
   227 
       
   228     errInit = createPathHandle(lPathDataType, lScale, lBias);
       
   229     if (HbNvgEngine::NvgErrNone != errInit){
       
   230         throw HbNvgException(errInit);
   237         throw HbNvgException(errInit);
   231     }
   238     }
   232 
   239 
   233     VGfloat lCurrentPathMatrix[9];
   240     qint16 pathDataType = iconData.derefInt16(NVG_PATHDATATYPE_OFS);
   234     vgGetMatrix(lCurrentPathMatrix);
   241     float scale         = iconData.derefReal32(NVG_SCALE_OFS);
       
   242     float bias          = iconData.derefReal32(NVG_BIAS_OFS);
       
   243 
       
   244     errInit = createPathHandle(pathDataType, scale, bias);
       
   245     if (HbNvgEngine::NvgErrNone != errInit) {
       
   246         throw HbNvgException(errInit);
       
   247     }
       
   248 
       
   249     VGfloat currentPathMatrix[9];
       
   250     vgGetMatrix(currentPathMatrix);
   235     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
   251     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
   236 
   252 
   237     // We use the caller's base batrix regardless of which mode the caller was.
   253     // We use the caller's base batrix regardless of which mode the caller was.
   238     // The caller may have set the matrix in VG_MATRIX_IMAGE_USER_TO_SURFACE mode
   254     // The caller may have set the matrix in VG_MATRIX_IMAGE_USER_TO_SURFACE mode
   239     // as it thinks it is drawing images (textures).
   255     // as it thinks it is drawing images (textures).
   240     // But even though the texture gets stroked instead, we must use the caller's
   256     // But even though the texture gets stroked instead, we must use the caller's
   241     // transformation matrix.
   257     // transformation matrix.
   242     // Everything gets restored to the original values before we return.
   258     // Everything gets restored to the original values before we return.
   243     vgLoadMatrix(lCurrentPathMatrix);
   259     vgLoadMatrix(currentPathMatrix);
   244 
   260 
   245 //    applyScissoring(lCurrentPathMatrix, targetSize);
   261 //    applyScissoring(currentPathMatrix, targetSize);
   246 
   262 
   247     /*
   263     /*
   248      * set the rotation angle if available
   264      * set the rotation angle if available
   249      */
   265      */
   250            
   266 
   251     setRotation();
   267     setRotation();
   252     
   268 
   253     if (mMirroringMode) {
   269     if (mMirrored) {
   254 	    vgTranslate((VGfloat)(targetSize.width()), 0); 
   270         vgTranslate((VGfloat)(targetSize.width()), 0);
   255 	    vgScale(-1.0f, 1.0f);
   271         vgScale(-1.0f, 1.0f);
   256 	    }
   272     }
   257     
   273 
   258 
   274 
   259 #ifdef __MIRROR_
   275 #ifdef __MIRROR_
   260      vgScale(1.0f, -1.0f);
   276     vgScale(1.0f, -1.0f);
   261      vgTranslate(0, (VGfloat)(-targetSize.height()));
   277     vgTranslate(0, (VGfloat)(-targetSize.height()));
   262 #endif
   278 #endif
   263 
   279 
   264     //viewbox parameters
   280     //viewbox parameters
   265     float lViewboxX   = iconData.derefReal32(NVG_VIEWBOX_X_OFS);
   281     float viewboxX   = iconData.derefReal32(NVG_VIEWBOX_X_OFS);
   266     float lViewboxY   = iconData.derefReal32(NVG_VIEWBOX_Y_OFS);
   282     float viewboxY   = iconData.derefReal32(NVG_VIEWBOX_Y_OFS);
   267     float lViewboxW   = iconData.derefReal32(NVG_VIEWBOX_WIDTH_OFS);
   283     float viewboxW   = iconData.derefReal32(NVG_VIEWBOX_WIDTH_OFS);
   268     float lViewboxH   = iconData.derefReal32(NVG_VIEWBOX_HEIGHT_OFS);
   284     float viewboxH   = iconData.derefReal32(NVG_VIEWBOX_HEIGHT_OFS);
   269 
   285 
   270     applyViewboxToViewPortTransformation(targetSize, lViewboxX, lViewboxY, lViewboxW, lViewboxH);
   286     applyViewboxToViewPortTransformation(targetSize, viewboxX, viewboxY, viewboxW, viewboxH);
   271 
   287 
   272     quint32 offsetSectionLength = iconData.getLength() - lHeaderSize;
   288     quint32 offsetSectionLength = iconData.getLength() - headerSize;
   273     quint8 * offsetPtr = iconData.derefInt8Array(offsetSectionLength, lHeaderSize);
   289     quint8 * offsetPtr = iconData.derefInt8Array(offsetSectionLength, headerSize);
   274     
   290 
   275     HbDereferencer offsetSection(offsetPtr, offsetSectionLength);
   291     HbDereferencer offsetSection(offsetPtr, offsetSectionLength);
   276     quint16 lOffsetVectorCount = offsetSection.derefInt16();
   292     quint16 offsetVectorCount = offsetSection.derefInt16();
   277 
   293 
   278     offsetPtr = iconData.derefInt8Array(offsetSectionLength - sizeof(quint16), lHeaderSize + sizeof(quint16));
   294     offsetPtr = iconData.derefInt8Array(offsetSectionLength - sizeof(quint16), headerSize + sizeof(quint16));
   279     HbDereferencer offsetVector(offsetPtr, offsetSectionLength - sizeof(quint16));
   295     HbDereferencer offsetVector(offsetPtr, offsetSectionLength - sizeof(quint16));
   280 
   296 
   281     qint32 commandSectionOffset = lOffsetVectorCount * sizeof(quint16);
   297     qint32 commandSectionOffset = offsetVectorCount * sizeof(quint16);
   282     HbDereferencer commandSection((offsetVector.getPtr() + commandSectionOffset), 
   298     HbDereferencer commandSection((offsetVector.getPtr() + commandSectionOffset),
   283             iconData.getLength() - commandSectionOffset - lHeaderSize - sizeof(quint16));
   299                                   iconData.getLength() - commandSectionOffset - headerSize - sizeof(quint16));
   284             
   300 
   285     // from version 2 onwards command section will start on word boundary
   301     // from version 2 onwards command section will start on word boundary
   286     if (nvgVersion >= Version2 && ((lOffsetVectorCount  & 0x01) == 0))
   302     if (nvgVersion >= Version2 && ((offsetVectorCount  & 0x01) == 0)) {
   287         {
       
   288         commandSection.skip(2);
   303         commandSection.skip(2);
   289         }
   304     }
   290          
   305 
   291     quint16 lCmdCount = commandSection.derefInt16();
   306     quint16 cmdCount = commandSection.derefInt16();
   292     commandSection.skip(NVG_COMMANDSECTION_OFS);   
   307     commandSection.skip(NVG_COMMANDSECTION_OFS);
   293     
   308 
   294     /*
   309     /*
   295      * from version 2 onwards there will be a padding added
   310      * from version 2 onwards there will be a padding added
   296      * after the command count to make it word aligned
   311      * after the command count to make it word aligned
   297      */
   312      */
   298     if (nvgVersion >= Version2)
   313     if (nvgVersion >= Version2) {
   299         {
       
   300         commandSection.skip(2);
   314         commandSection.skip(2);
   301         }
   315     }
   302         
   316 
   303     executeNVGCSCommandLoop(lCmdCount, &iconData, &offsetVector, &commandSection, nvgVersion);
   317     executeNvgCsCommandLoop(cmdCount, &iconData, &offsetVector, &commandSection, nvgVersion);
   304 }
   318 }
   305 
   319 
   306 void HbNvgCsIcon::executeNVGCSCommandLoop(quint16 commandCount, HbDereferencer *iconData, 
   320 void HbNvgCsIcon::executeNvgCsCommandLoop(quint16 commandCount, HbDereferencer *iconData,
   307         HbDereferencer * offsetVector,HbDereferencer * commandSection, quint8 nvgVersion)
   321         HbDereferencer * offsetVector, HbDereferencer * commandSection, quint8 nvgVersion)
   308     {
   322 {
   309     quint32 transVal;
   323     quint32 transVal;
   310 
   324 
   311     VGfloat lCurrentPathMatrix[9];
   325     VGfloat currentPathMatrix[9];
   312     
   326 
   313     vgGetMatrix(lCurrentPathMatrix);
   327     vgGetMatrix(currentPathMatrix);
   314         
   328 
   315     qint32 lOffsetIx = 0;
   329     qint32 offsetIx = 0;
   316     for (int i=0; i < commandCount; i++)
   330     for (qint32 i = 0; i < commandCount; i++) {
   317         {
       
   318         quint32 currentCommand = commandSection->derefInt32();
   331         quint32 currentCommand = commandSection->derefInt32();
   319         lOffsetIx = currentCommand & 0x0000ffff;
   332         offsetIx = currentCommand & 0x0000ffff;
   320                 
   333 
   321         switch (currentCommand & 0xff000000)
   334         switch (currentCommand & 0xff000000) {
   322             {
   335         case CMD_SET_FILL_PAINT: {
   323             case CMD_SET_FILL_PAINT:
   336             mFillAlpha        = (currentCommand & 0x00ff0000) >> 16;
   324                 {
   337             quint16 offset    = offsetVector->derefInt16(offsetIx * sizeof(quint16));
   325                 mFillAlpha        = (currentCommand & 0x00ff0000) >> 16;
   338 
   326                 quint16 offset    = offsetVector->derefInt16(lOffsetIx * sizeof(quint16));
   339             HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
   327                 
   340 
   328                 HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
   341             setFillPaint(&section);
   329                                 
   342         }
   330                 setFillPaint(&section); 
   343         break;
   331                 }
   344         case CMD_SET_COLOR_RAMP: {
   332                 break;    
   345             quint16 offset = offsetVector->derefInt16(offsetIx * sizeof(quint16));
   333             case CMD_SET_COLOR_RAMP:
   346 
   334                 {
   347             HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
   335                 quint16 offset = offsetVector->derefInt16(lOffsetIx * sizeof(quint16));
   348 
   336 
   349             setColorRamp(&section);
   337                 HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
   350         }
   338 
   351         break;
   339                 setColorRamp(&section);
   352         case CMD_DRAW_PATH: {
   340                 }
   353             if ((currentCommand & 0x00010000)) {
       
   354                 mDoStroke = VG_TRUE;
       
   355             }
       
   356 
       
   357             if ((currentCommand & 0x00020000)) {
       
   358                 mDoFill = VG_TRUE;
       
   359             }
       
   360             quint16 offset = offsetVector->derefInt16(offsetIx * sizeof(quint16));
       
   361 
       
   362             HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
       
   363 
       
   364             drawPath(&section);
       
   365         }
       
   366         break;
       
   367         case CMD_SET_TRANSFORMATION: {
       
   368             setTransform(commandSection, transVal, currentPathMatrix);
       
   369             commandSection->skip(transVal * sizeof(quint32));
       
   370         }
       
   371         break;
       
   372         case CMD_SET_STROKE_PAINT: {
       
   373             mStrokeAlpha = (currentCommand & 0x00ff0000) >> 16;
       
   374             quint16 offset = offsetVector->derefInt16(offsetIx * sizeof(quint16));
       
   375 
       
   376             HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
       
   377 
       
   378             setStrokePaint(&section);
       
   379         }
       
   380         break;
       
   381         case CMD_SET_STROKE_WIDTH: {
       
   382             float strokeWidth;
       
   383             commandSection->skip(sizeof(quint32));
       
   384 
       
   385             /*
       
   386              * check for alignment and copy data if not aligned, else directly convert
       
   387              * version 2 or above guarantees that is always word aligned
       
   388              */
       
   389             quint8 * cptr = commandSection->derefInt8Array(sizeof(float), 0);
       
   390             if (nvgVersion < Version2 && !isAligned4(cptr)) {
       
   391 
       
   392                 memcpy(reinterpret_cast<void *>(&strokeWidth),
       
   393                        reinterpret_cast<void *>(cptr), sizeof(strokeWidth));
       
   394             } else {
       
   395                 strokeWidth = commandSection->derefReal32();
       
   396             }
       
   397 
       
   398             COND_COM_OC(mCreatingNvgIcon,
       
   399                         addSetStrokeWidthCommand(strokeWidth),
       
   400                         vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth));
       
   401         }
       
   402         break;
       
   403         case CMD_SET_STROKE_MITER_LIMIT: {
       
   404             float miterLimit;
       
   405             commandSection->skip(sizeof(float));
       
   406 
       
   407             /*
       
   408              * check for alignment and copy data if not aligned, else directly convert
       
   409              * version 2 or above guarantees that is always word aligned
       
   410              */
       
   411             quint8 * cptr = commandSection->derefInt8Array(sizeof(float), 0);
       
   412 
       
   413             if (nvgVersion < Version2 && !isAligned4(cptr)) {
       
   414                 memcpy(reinterpret_cast<void *>(&miterLimit),
       
   415                        reinterpret_cast<void *>(cptr), sizeof(miterLimit));
       
   416             } else {
       
   417                 miterLimit = commandSection->derefReal32();
       
   418             }
       
   419 
       
   420             COND_COM_OC(mCreatingNvgIcon,
       
   421                         addSetStrokeMiterLimitCommand(miterLimit),
       
   422                         vgSetf(VG_STROKE_MITER_LIMIT, miterLimit));
       
   423         }
       
   424         break;
       
   425         case CMD_SET_STROKE_LINE_JOIN_CAP: {
       
   426             quint8 joinType = (currentCommand & 0x0000ff00) >> 8;
       
   427             quint8 capType = (currentCommand & 0x000000ff);
       
   428 
       
   429             VGCapStyle capStyle;
       
   430             switch (capType) {
       
   431             case CAP_SQUARE:
       
   432                 capStyle = VG_CAP_SQUARE;
   341                 break;
   433                 break;
   342             case CMD_DRAW_PATH:
   434             case CAP_ROUND:
   343                 {
   435                 capStyle = VG_CAP_ROUND;
   344                 if ((currentCommand & 0x00010000)) 
       
   345                     {
       
   346                     mDoStroke = VG_TRUE;
       
   347                     }
       
   348                 
       
   349                 if ((currentCommand & 0x00020000))
       
   350                     {
       
   351                     mDoFill = VG_TRUE;
       
   352                     }
       
   353                 quint16 offset = offsetVector->derefInt16(lOffsetIx * sizeof(quint16));
       
   354 
       
   355                 HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
       
   356 
       
   357                 drawPath(&section);
       
   358                 }
       
   359                 break;
   436                 break;
   360             case CMD_SET_TRANSFORMATION:
   437             case CAP_BUTT:
   361                 {
   438             default:
   362                 setTransform(commandSection, transVal, lCurrentPathMatrix);
   439                 capStyle = VG_CAP_BUTT;
   363                 commandSection->skip(transVal * sizeof(quint32));
       
   364                 }
       
   365                 break;
   440                 break;
   366             case CMD_SET_STROKE_PAINT:
   441             }
   367                 {
   442 
   368                 mStrokeAlpha = (currentCommand & 0x00ff0000) >> 16;
   443             VGJoinStyle lineJoinStyle;
   369                 quint16 offset = offsetVector->derefInt16(lOffsetIx * sizeof(quint16));
   444             switch (joinType) {
   370 
   445             case LINE_JOIN_BEVEL:
   371                 HbDereferencer section = getCommandSection(offset, iconData, nvgVersion);
   446                 lineJoinStyle = VG_JOIN_BEVEL;
   372 
       
   373                 setStrokePaint(&section); 
       
   374                 }
       
   375                 break;
   447                 break;
   376             case CMD_SET_STROKE_WIDTH:
   448             case LINE_JOIN_ROUND:
   377                 {
   449                 lineJoinStyle = VG_JOIN_ROUND;
   378                 float lStrokeWidth;
       
   379                 commandSection->skip(sizeof(quint32));
       
   380                 
       
   381                 /*
       
   382                  * check for alignment and copy data if not aligned, else directly convert
       
   383                  * version 2 or above guarantees that is always word aligned
       
   384                  */
       
   385                 quint8 * cptr = commandSection->derefInt8Array(sizeof(float), 0); 
       
   386                 if (nvgVersion < Version2 && !isAligned4(cptr))
       
   387                     {
       
   388                     
       
   389                     memcpy(reinterpret_cast<void *>(&lStrokeWidth),
       
   390                               reinterpret_cast<void *>(cptr), sizeof(lStrokeWidth));
       
   391                     }
       
   392                 else
       
   393                     {
       
   394                     lStrokeWidth = commandSection->derefReal32();
       
   395                     }
       
   396                 
       
   397                 COND_COM_OC(mCreatingNvgIcon,
       
   398                         addSetStrokeWidthCommand(lStrokeWidth),
       
   399                         vgSetf(VG_STROKE_LINE_WIDTH, lStrokeWidth));
       
   400                 }
       
   401                 break;
   450                 break;
   402             case CMD_SET_STROKE_MITER_LIMIT:
   451             case LINE_JOIN_MITER:
   403                 {
   452             default:
   404                 float lMiterLimit;
   453                 lineJoinStyle = VG_JOIN_MITER;
   405                 commandSection->skip(sizeof(float));
       
   406 
       
   407                 /*
       
   408                  * check for alignment and copy data if not aligned, else directly convert
       
   409                  * version 2 or above guarantees that is always word aligned
       
   410                  */
       
   411                 quint8 * cptr = commandSection->derefInt8Array(sizeof(float), 0); 
       
   412 
       
   413                 if (nvgVersion < Version2 && !isAligned4(cptr))
       
   414                     {
       
   415                     memcpy(reinterpret_cast<void *>(&lMiterLimit),
       
   416                               reinterpret_cast<void *>(cptr), sizeof(lMiterLimit));
       
   417                     }
       
   418                 else
       
   419                     {
       
   420                     lMiterLimit = commandSection->derefReal32();
       
   421                     }
       
   422                 
       
   423                 COND_COM_OC(mCreatingNvgIcon,
       
   424                         addSetStrokeMiterLimitCommand(lMiterLimit),
       
   425                         vgSetf(VG_STROKE_MITER_LIMIT, lMiterLimit));
       
   426                 }
       
   427                 break;
   454                 break;
   428             case CMD_SET_STROKE_LINE_JOIN_CAP:
   455             }
   429                 {
   456 
   430                 quint8 lJoinType =(currentCommand & 0x0000ff00)>>8;
   457             COND_COM_OC(mCreatingNvgIcon,
   431                 quint8 lCapType = (currentCommand & 0x000000ff);
       
   432                 
       
   433                 VGCapStyle capStyle;
       
   434                 switch(lCapType)
       
   435                     {
       
   436                     case CAP_SQUARE:
       
   437                         capStyle = VG_CAP_SQUARE;
       
   438                         break;
       
   439                     case CAP_ROUND:
       
   440                         capStyle = VG_CAP_ROUND;
       
   441                         break;
       
   442                     case CAP_BUTT:
       
   443                     default:
       
   444                         capStyle = VG_CAP_BUTT;
       
   445                         break;
       
   446                     }
       
   447    
       
   448                 VGJoinStyle lineJoinStyle;
       
   449                 switch(lJoinType)
       
   450                     {
       
   451                     case LINE_JOIN_BEVEL:
       
   452                         lineJoinStyle = VG_JOIN_BEVEL;
       
   453                         break;
       
   454                     case LINE_JOIN_ROUND:
       
   455                         lineJoinStyle = VG_JOIN_ROUND;
       
   456                         break;
       
   457                     case LINE_JOIN_MITER:
       
   458                     default:
       
   459                         lineJoinStyle = VG_JOIN_MITER;
       
   460                         break;
       
   461                     }
       
   462                 
       
   463                 COND_COM_OC(mCreatingNvgIcon,
       
   464                         addStrokeLineJoinCapCommand(capStyle, lineJoinStyle),
   458                         addStrokeLineJoinCapCommand(capStyle, lineJoinStyle),
   465                         vgSeti(VG_STROKE_CAP_STYLE, capStyle);
   459                         vgSeti(VG_STROKE_CAP_STYLE, capStyle);
   466                         vgSeti(VG_STROKE_JOIN_STYLE, lineJoinStyle););
   460                         vgSeti(VG_STROKE_JOIN_STYLE, lineJoinStyle););
   467                 }
   461         }
   468                 break;
   462         break;
   469             default:
   463         default: {
   470                 {
   464             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   471                 throw HbNvgException(HbNvgEngine::NvgErrCorrupt);			
   465         }
   472                 }
   466         }
   473             }
   467 
   474         
       
   475         // go to the next command
   468         // go to the next command
   476         commandSection->skip(sizeof(quint32));
   469         commandSection->skip(sizeof(quint32));
   477         }
   470     }
   478     
   471 
   479     }
   472 }
   480 
   473 
   481 HbDereferencer HbNvgCsIcon::getCommandSection(quint16 offset, HbDereferencer * iconData, int nvgVersion)
   474 HbDereferencer HbNvgCsIcon::getCommandSection(quint16 offset, HbDereferencer * iconData, qint32 nvgVersion)
   482     {
   475 {
   483     // the max length that the command section can have
   476     // the max length that the command section can have
   484     int commandSectionLength = iconData->getLength() - offset;
   477     qint32 commandSectionLength = iconData->getLength() - offset;
   485 
   478 
   486     if (commandSectionLength <= 0){
   479     if (commandSectionLength <= 0) {
   487         throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   480         throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   488     }
   481     }
   489 
   482 
   490     HbDereferencer section(iconData->derefInt8Array(commandSectionLength, offset), commandSectionLength);
   483     HbDereferencer section(iconData->derefInt8Array(commandSectionLength, offset), commandSectionLength);
   491 
   484 
   496      */
   489      */
   497     if (nvgVersion >= Version2) {
   490     if (nvgVersion >= Version2) {
   498         if (!isAligned4(offset)) {
   491         if (!isAligned4(offset)) {
   499             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   492             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   500         }
   493         }
   501     }else{
   494     } else {
   502         /*
   495         /*
   503          * no need to do anything here as once the nvgdecoder release
   496          * no need to do anything here as once the nvgdecoder release
   504          * its version will be always greater than 2
   497          * its version will be always greater than 2
   505          * infact the check for version will be removed
   498          * infact the check for version will be removed
   506          */ 
   499          */
   507     }
   500     }
   508     
   501 
   509     return section;
   502     return section;
   510     }
   503 }
   511 
   504 
   512 void HbNvgCsIcon::applyViewboxToViewPortTransformation(const QSize& targetSize, 
   505 void HbNvgCsIcon::applyViewboxToViewPortTransformation(const QSize& targetSize,
   513         float viewboxX, float viewboxY, float viewboxW, float viewboxH)
   506         float viewboxX, float viewboxY, float viewboxW, float viewboxH)
   514     {
   507 {
   515     HbNvgFitToViewBoxImpl *viewBoxTx = new HbNvgFitToViewBoxImpl();
   508     HbNvgFitToViewBoxImpl *viewBoxTx = new HbNvgFitToViewBoxImpl();
   516     Q_CHECK_PTR(viewBoxTx);
   509     Q_CHECK_PTR(viewBoxTx);
   517     QScopedPointer<HbNvgFitToViewBoxImpl> viewboxTrnsfr(viewBoxTx);
   510     QScopedPointer<HbNvgFitToViewBoxImpl> viewboxTrnsfr(viewBoxTx);
   518 
   511 
   519     /*
   512     /*
   520      * this is bit unreadable,
   513      * this is bit unreadable,
   521      * need to find a better design to separate the object caching solution from normal rendering,
   514      * need to find a better design to separate the object caching solution from normal rendering,
   522      */
   515      */
   523     
   516 
   524     COND_COM_OC_NOC(
   517     COND_COM_OC_NOC( {
   525             {
   518         if (mCreatingNvgIcon) {
   526             if (mCreatingNvgIcon) {
   519             setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
   527                 setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
   520         } else {
   528                 }
   521             viewboxTrnsfr->setAllignment(mPreserveAspectSetting);
   529             else{
       
   530                 viewboxTrnsfr->setAlign(mPreserveAspectSetting);
       
   531                 viewboxTrnsfr->setScaling(mSmilFitSetting);
       
   532                 
       
   533                 if (viewboxW > 0 && viewboxH > 0){
       
   534                     viewboxTrnsfr->setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
       
   535                 }
       
   536                 
       
   537                 int lWidth = aTargetSize.width();
       
   538                 int lHeight = aTargetSize.height();
       
   539                 
       
   540                 viewboxTrnsfr->setWindowViewportTrans(QRect(0, 0, lWidth, lHeight), QSize(0, 0));
       
   541             }
       
   542            },
       
   543             {
       
   544             viewboxTrnsfr->setAlign(mPreserveAspectSetting);
       
   545             viewboxTrnsfr->setScaling(mSmilFitSetting);
   522             viewboxTrnsfr->setScaling(mSmilFitSetting);
   546             
   523 
   547             if (viewboxW > 0 && viewboxH > 0){
   524             if (viewboxW > 0 && viewboxH > 0) {
   548                 viewboxTrnsfr->setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
   525                 viewboxTrnsfr->setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
   549                 }
   526             }
   550             
   527 
   551             int lWidth = targetSize.width();
   528             qint32 width = aTargetSize.width();
   552             int lHeight = targetSize.height();
   529             qint32 height = aTargetSize.height();
   553             
   530 
   554             viewboxTrnsfr->setWindowViewportTrans(QRect(0, 0, lWidth, lHeight), QSize(0, 0));
   531             viewboxTrnsfr->setWindowViewportTrans(QRect(0, 0, width, height), QSize(0, 0));
   555             });
   532         }
   556     }
   533     }, {
       
   534         viewboxTrnsfr->setAllignment(mPreserveAspectSetting);
       
   535         viewboxTrnsfr->setScaling(mSmilFitSetting);
       
   536 
       
   537         if (viewboxW > 0 && viewboxH > 0) {
       
   538             viewboxTrnsfr->setViewBox(viewboxX, viewboxY, viewboxW, viewboxH);
       
   539         }
       
   540 
       
   541         qint32 width = targetSize.width();
       
   542         qint32 height = targetSize.height();
       
   543 
       
   544         viewboxTrnsfr->setWindowViewportTrans(QRect(0, 0, width, height), QSize(0, 0));
       
   545     });
       
   546 }
   557 
   547 
   558 void HbNvgCsIcon::applyScissoring(VGfloat *aMatrix, const QSize& targetSize)
   548 void HbNvgCsIcon::applyScissoring(VGfloat *aMatrix, const QSize& targetSize)
   559     {
   549 {
   560     /*
   550     /*
   561      * calculate the rectangle with respect to the transformation applied
   551      * calculate the rectangle with respect to the transformation applied
   562      * and set the scissoring rect
   552      * and set the scissoring rect
   563      */ 
   553      */
   564     QPoint leftBottom  = getTranslatedPoint(aMatrix, QPoint(0, 0));
   554     QPoint leftBottom  = getTranslatedPoint(aMatrix, QPoint(0, 0));
   565     QPoint leftTop     = getTranslatedPoint(aMatrix, QPoint(0, targetSize.height()));
   555     QPoint leftTop     = getTranslatedPoint(aMatrix, QPoint(0, targetSize.height()));
   566     QPoint rightBottom = getTranslatedPoint(aMatrix, QPoint(targetSize.width(), 0));
   556     QPoint rightBottom = getTranslatedPoint(aMatrix, QPoint(targetSize.width(), 0));
   567     QPoint rightTop    = getTranslatedPoint(aMatrix, QPoint(targetSize.width(),targetSize.height()));
   557     QPoint rightTop    = getTranslatedPoint(aMatrix, QPoint(targetSize.width(), targetSize.height()));
   568 
   558 
   569     VGfloat minX = leftBottom.x();
   559     VGfloat minX = leftBottom.x();
   570     VGfloat minY = leftBottom.y();
   560     VGfloat minY = leftBottom.y();
   571     VGfloat maxX = leftBottom.x();
   561     VGfloat maxX = leftBottom.x();
   572     VGfloat maxY = leftBottom.y();
   562     VGfloat maxY = leftBottom.y();
   582 
   572 
   583     VGint clipRect[] = {minX, minY, newW, newH};
   573     VGint clipRect[] = {minX, minY, newW, newH};
   584 
   574 
   585     vgSeti(VG_SCISSORING, VG_TRUE);
   575     vgSeti(VG_SCISSORING, VG_TRUE);
   586     vgSetiv(VG_SCISSOR_RECTS, 4, clipRect);
   576     vgSetiv(VG_SCISSOR_RECTS, 4, clipRect);
   587     }
   577 }
   588 
   578 
   589 
   579 
   590 HbNvgEngine::NvgErrorType HbNvgCsIcon::initializeGc()
   580 HbNvgEngine::HbNvgErrorType HbNvgCsIcon::initializeGc()
   591 {
   581 {
   592     if (mPaintFill == VG_INVALID_HANDLE) {
   582     if (mPaintFill == VG_INVALID_HANDLE) {
   593         mPaintFill = vgCreatePaint();
   583         mPaintFill = vgCreatePaint();
   594         if (mPaintFill == VG_INVALID_HANDLE) {
   584         if (mPaintFill == VG_INVALID_HANDLE) {
   595             return openVgErrorToHbNvgError(vgGetError());
   585             return openVgErrorToHbNvgError(vgGetError());
   596         }
   586         }
   597     }
   587     }
   598     
   588 
   599     vgSetPaint(mPaintFill, VG_FILL_PATH);
   589     vgSetPaint(mPaintFill, VG_FILL_PATH);
   600     
   590 
   601     if (mPaintStroke == VG_INVALID_HANDLE) {
   591     if (mPaintStroke == VG_INVALID_HANDLE) {
   602         mPaintStroke = vgCreatePaint();
   592         mPaintStroke = vgCreatePaint();
   603         if (mPaintStroke == VG_INVALID_HANDLE) {
   593         if (mPaintStroke == VG_INVALID_HANDLE) {
   604             return openVgErrorToHbNvgError(vgGetError());
   594             return openVgErrorToHbNvgError(vgGetError());
   605         }
   595         }
   608     vgSetPaint(mPaintStroke, VG_STROKE_PATH);
   598     vgSetPaint(mPaintStroke, VG_STROKE_PATH);
   609 
   599 
   610     return HbNvgEngine::NvgErrNone;
   600     return HbNvgEngine::NvgErrNone;
   611 }
   601 }
   612 
   602 
   613 HbNvgEngine::NvgErrorType HbNvgCsIcon::createPathHandle(qint16 pathDataType, float scale, float bias)
   603 HbNvgEngine::HbNvgErrorType HbNvgCsIcon::createPathHandle(qint16 pathDataType, float scale, float bias)
   614 {
   604 {
   615     (void) scale;
   605     Q_UNUSED(scale);
   616     (void) bias;
   606     Q_UNUSED(bias);
   617 
   607 
   618     HbNvgEngine::NvgErrorType error = HbNvgEngine::NvgErrNone;
   608     HbNvgEngine::HbNvgErrorType error = HbNvgEngine::NvgErrNone;
   619 
   609 
   620     if (mLastPathDataType != pathDataType) {
   610     if (mLastPathDataType != pathDataType) {
   621         if (mVgPath != VG_INVALID_HANDLE) {
   611         if (mVgPath != VG_INVALID_HANDLE) {
   622             vgDestroyPath(mVgPath);
   612             vgDestroyPath(mVgPath);
   623             mVgPath = VG_INVALID_HANDLE;
   613             mVgPath = VG_INVALID_HANDLE;
   629         case NvgEightBitEncoding: {
   619         case NvgEightBitEncoding: {
   630             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   620             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   631                                    VG_PATH_DATATYPE_S_16, 1.0f / 2.0f, 0.0f, 0, 0,
   621                                    VG_PATH_DATATYPE_S_16, 1.0f / 2.0f, 0.0f, 0, 0,
   632                                    VG_PATH_CAPABILITY_APPEND_TO);
   622                                    VG_PATH_CAPABILITY_APPEND_TO);
   633             break;
   623             break;
   634             }
   624         }
   635             
   625 
   636         case NvgSixteenBitEncoding: {
   626         case NvgSixteenBitEncoding: {
   637             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   627             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   638                                    VG_PATH_DATATYPE_S_16, 1.0f / 16.0f, 0.0f, 0, 0,
   628                                    VG_PATH_DATATYPE_S_16, 1.0f / 16.0f, 0.0f, 0, 0,
   639                                    VG_PATH_CAPABILITY_APPEND_TO);
   629                                    VG_PATH_CAPABILITY_APPEND_TO);
   640             break;
   630             break;
   641             }
   631         }
   642             
   632 
   643         case NvgThirtyTwoBitEncoding: {
   633         case NvgThirtyTwoBitEncoding: {
   644             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   634             mVgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD,
   645                                    VG_PATH_DATATYPE_S_32, 1.0f / 65536.0f, 0.0f, 0, 0,
   635                                    VG_PATH_DATATYPE_S_32, 1.0f / 65536.0f, 0.0f, 0, 0,
   646                                    VG_PATH_CAPABILITY_APPEND_TO);
   636                                    VG_PATH_CAPABILITY_APPEND_TO);
   647             break;
   637             break;
   648             }
   638         }
   649 
   639 
   650         default: {
   640         default: {
   651             return HbNvgEngine::NvgErrCorrupt;
   641             return HbNvgEngine::NvgErrCorrupt;
   652             }
   642         }
   653         }
   643         }
   654     }
   644     }
   655 
   645 
   656     if (mVgPath == VG_INVALID_HANDLE) {
   646     if (mVgPath == VG_INVALID_HANDLE) {
   657         // Get the Symbian error code
   647         // Get the Symbian error code
   689         vgDestroyPaint(mPaintStroke);
   679         vgDestroyPaint(mPaintStroke);
   690         mPaintStroke = VG_INVALID_HANDLE;
   680         mPaintStroke = VG_INVALID_HANDLE;
   691     }
   681     }
   692 }
   682 }
   693 
   683 
   694     /**
   684 /**
   695      * @fn setFillPaint
   685  * @fn setFillPaint
   696      * @brief  SetPaint gradient or solid in OpenVG
   686  * @brief  SetPaint gradient or solid in OpenVG
   697      * @version
   687  * @version
   698      * @param   buffer - buffer containing OpenVG data
   688  * @param   buffer - buffer containing OpenVG data
   699      * @return  None
   689  * @return  None
   700      */
   690  */
   701 
   691 
   702 void HbNvgCsIcon::setFillPaint(HbDereferencer *iconData)
   692 void HbNvgCsIcon::setFillPaint(HbDereferencer *iconData)
   703 {
   693 {
   704     COND_COM_OC_OOC(register int drawingMode = mCreatingNvgIcon);
   694     COND_COM_OC_OOC(register qint32 drawingMode = mCreatingNvgIcon);
   705     
   695 
   706     quint32 lCommonData  = iconData->derefInt32();
   696     quint32 commonData  = iconData->derefInt32();
   707     quint32 lPaintType   = lCommonData & 0x07;
   697     quint32 paintType   = commonData & 0x07;
   708     quint16 lSpecifcData = (lCommonData >> 16) & 0xff;
   698     quint16 specifcData = (commonData >> 16) & 0xff;
   709 
   699 
   710     switch (lPaintType) {
   700     switch (paintType) {
   711         case PAINT_LGRAD: {
   701     case PAINT_LGRAD: {
   712             mGradPaintFill = mPaintFill;
   702         mGradPaintFill = mPaintFill;
   713             COND_COM_OC_OOC(
   703         COND_COM_OC_OOC(
   714                 if (mCreatingNvgIcon) {
   704         if (mCreatingNvgIcon) {
   715                 // CNVGCSIcon will destroy the paint handle
   705         // CNVGCSIcon will destroy the paint handle
   716                 mGradPaintFill = vgCreatePaint();
   706         mGradPaintFill = vgCreatePaint();
   717                 if (mGradPaintFill == VG_INVALID_HANDLE){
   707             if (mGradPaintFill == VG_INVALID_HANDLE) {
   718                     throw HbNvgException(openVgErrorToHbNvgError(vgGetError()));
   708                 throw HbNvgException(openVgErrorToHbNvgError(vgGetError()));
   719                 }
   709             }
   720             });
   710         });
   721 
   711 
   722             // gradient data, the data will be word aligned
   712         // gradient data, the data will be word aligned
   723             float* lGradData =  (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(float));
   713         float* gradData = (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(float));
   724             
   714 
   725             vgSetParameteri(mGradPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
   715         vgSetParameteri(mGradPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
   726             vgSetParameterfv(mGradPaintFill, VG_PAINT_LINEAR_GRADIENT, 4, lGradData);
   716         vgSetParameterfv(mGradPaintFill, VG_PAINT_LINEAR_GRADIENT, 4, gradData);
   727             vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
   717         vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
   728 
   718 
   729             if (lSpecifcData & 0x1) {
   719         if (specifcData & 0x1) {
   730                 float* lGradMatrix1 = (float*) iconData->derefInt8Array(6 * sizeof (VGfloat),
   720             float* gradMatrix1 = (float*) iconData->derefInt8Array(6 * sizeof(VGfloat),
   731                                                                    NVG_PAINTSECTION_LINEARGRAD_TRANSFORM_OFFSET);
   721                                   NVG_PAINTSECTION_LINEARGRAD_TRANSFORM_OFFSET);
   732                                
   722 
   733                 float lGradMatrix[9] = {lGradMatrix1[0], lGradMatrix1[3], 0.0f,
   723             float gradMatrix[9] = {gradMatrix1[0], gradMatrix1[3], 0.0f,
   734                                         lGradMatrix1[1], lGradMatrix1[4], 0.0f,
   724                                     gradMatrix1[1], gradMatrix1[4], 0.0f,
   735                                         lGradMatrix1[2], lGradMatrix1[5], 1.0f
   725                                     gradMatrix1[2], gradMatrix1[5], 1.0f
   736                                        };
   726                                    };
   737     
   727 
   738                 COND_COM_OC(drawingMode,
       
   739                             addLinearGradientCommand(4, lGradData, lGradMatrix, mGradPaintFill),
       
   740                             vgLoadMatrix(lGradMatrix););
       
   741                 Q_UNUSED(IdentityMatrix);
       
   742             } else {
       
   743                 COND_COM_OC(drawingMode,
       
   744                             addLinearGradientCommand(4, lGradData, (VGfloat*)IdentityMatrix, mGradPaintFill),
       
   745                             vgLoadIdentity());
       
   746             }
       
   747 
       
   748             COND_COM_OC(drawingMode, ; ,
       
   749                         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE));
       
   750         }
       
   751         break;
       
   752         case PAINT_RGRAD: {
       
   753             mGradPaintFill = mPaintFill;
       
   754     
       
   755             COND_COM_OC_OOC(
       
   756             if (mCreatingNvgIcon) {
       
   757                 mGradPaintFill = vgCreatePaint();
       
   758                 if (mGradPaintFill == VG_INVALID_HANDLE){
       
   759                     throw HbNvgException(openVgErrorToHbNvgError(vgGetError()));
       
   760                 }                
       
   761             });
       
   762     
       
   763             // gradient data, the data will be word aligned
       
   764             float* lGradData = (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(quint32));
       
   765                        
       
   766             vgSetParameteri(mGradPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
       
   767             vgSetParameterfv(mGradPaintFill, VG_PAINT_RADIAL_GRADIENT, 5, lGradData);
       
   768             vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
       
   769     
       
   770     
       
   771             if (lSpecifcData & 0x1) {
       
   772                 float* lGradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof (VGfloat),
       
   773                                         NVG_PAINTSECTION_RADIALGRAD_TRANSFORM_OFFSET);
       
   774                 float lGradMatrix[9] = {lGradMatrix1[0], lGradMatrix1[3], 0.0f,
       
   775                                         lGradMatrix1[1], lGradMatrix1[4], 0.0f,
       
   776                                         lGradMatrix1[2], lGradMatrix1[5], 1.0f
       
   777                                        };
       
   778     
       
   779                 COND_COM_OC(drawingMode,
       
   780                             addRadialGradientCommand(5, lGradData, lGradMatrix, mGradPaintFill),
       
   781                             vgLoadMatrix(lGradMatrix));
       
   782                 Q_UNUSED(IdentityMatrix);
       
   783             } else {
       
   784                 COND_COM_OC(drawingMode,
       
   785                             addRadialGradientCommand(5, lGradData, (VGfloat*)IdentityMatrix, mGradPaintFill),
       
   786                             vgLoadIdentity());
       
   787             }
       
   788     
       
   789             COND_COM_OC(drawingMode, ; ,
       
   790                         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE));
       
   791         }
       
   792         break;
       
   793         case PAINT_FLAT:
       
   794             {
       
   795             quint32 lRgba = iconData->derefInt32(NVG_RGBA_OFS);
       
   796     
       
   797             lRgba = (lRgba & 0xffffff00) | mFillAlpha;
       
   798             
       
   799             COND_COM_OC(drawingMode,
   728             COND_COM_OC(drawingMode,
   800                     addSetColorCommand(lRgba),
   729                         addLinearGradientCommand(4, gradData, gradMatrix, mGradPaintFill),
       
   730                         vgLoadMatrix(gradMatrix););
       
   731             Q_UNUSED(identityMatrix);
       
   732         } else {
       
   733             COND_COM_OC(drawingMode,
       
   734                         addLinearGradientCommand(4, gradData, (VGfloat*)identityMatrix, mGradPaintFill),
       
   735                         vgLoadIdentity());
       
   736         }
       
   737 
       
   738         COND_COM_OC(drawingMode, ; ,
       
   739                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE));
       
   740     }
       
   741     break;
       
   742     case PAINT_RGRAD: {
       
   743         mGradPaintFill = mPaintFill;
       
   744 
       
   745         COND_COM_OC_OOC(
       
   746         if (mCreatingNvgIcon) {
       
   747         mGradPaintFill = vgCreatePaint();
       
   748             if (mGradPaintFill == VG_INVALID_HANDLE) {
       
   749                 throw HbNvgException(openVgErrorToHbNvgError(vgGetError()));
       
   750             }
       
   751         });
       
   752 
       
   753         // gradient data, the data will be word aligned
       
   754         float* gradData = (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(quint32));
       
   755 
       
   756         vgSetParameteri(mGradPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
       
   757         vgSetParameterfv(mGradPaintFill, VG_PAINT_RADIAL_GRADIENT, 5, gradData);
       
   758         vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
       
   759 
       
   760 
       
   761         if (specifcData & 0x1) {
       
   762             float* gradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof(VGfloat),
       
   763                                   NVG_PAINTSECTION_RADIALGRAD_TRANSFORM_OFFSET);
       
   764             float gradMatrix[9] = {gradMatrix1[0], gradMatrix1[3], 0.0f,
       
   765                                     gradMatrix1[1], gradMatrix1[4], 0.0f,
       
   766                                     gradMatrix1[2], gradMatrix1[5], 1.0f
       
   767                                    };
       
   768 
       
   769             COND_COM_OC(drawingMode,
       
   770                         addRadialGradientCommand(5, gradData, gradMatrix, mGradPaintFill),
       
   771                         vgLoadMatrix(gradMatrix));
       
   772             Q_UNUSED(identityMatrix);
       
   773         } else {
       
   774             COND_COM_OC(drawingMode,
       
   775                         addRadialGradientCommand(5, gradData, (VGfloat*)identityMatrix, mGradPaintFill),
       
   776                         vgLoadIdentity());
       
   777         }
       
   778 
       
   779         COND_COM_OC(drawingMode, ; ,
       
   780                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE));
       
   781     }
       
   782     break;
       
   783     case PAINT_FLAT: {
       
   784         quint32 rgba = iconData->derefInt32(NVG_RGBA_OFS);
       
   785 
       
   786         rgba = (rgba & 0xffffff00) | mFillAlpha;
       
   787 
       
   788         COND_COM_OC(drawingMode,
       
   789                     addSetColorCommand(rgba),
   801                     vgSetParameteri(mPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   790                     vgSetParameteri(mPaintFill, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
   802                     vgSetColor(mPaintFill, lRgba));            
   791                     vgSetColor(mPaintFill, rgba));
   803             }
   792     }
   804             break;
   793     break;
   805         default: {
   794     default: {
   806             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   795         throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   807         }
   796     }
   808     }
   797     }
   809 }
   798 }
   810 
   799 
   811 void HbNvgCsIcon::setColorRamp(HbDereferencer *iconData)
   800 void HbNvgCsIcon::setColorRamp(HbDereferencer *iconData)
   812 {
   801 {
   813     quint32 lCommonData = iconData->derefInt32();
   802     quint32 commonData = iconData->derefInt32();
   814 
   803 
   815     int lStopCount = (lCommonData >> 16) & 0x00ff;
   804     int stopCount = (commonData >> 16) & 0x00ff;
   816     float* lStopData = (float*) iconData->derefInt8Array(lStopCount * 5 * sizeof(float), sizeof(quint32));
   805     float* stopData = (float*) iconData->derefInt8Array(stopCount * 5 * sizeof(float), sizeof(quint32));
   817     
   806 
   818     VGfloat *crs = new VGfloat[lStopCount * 5];
   807     VGfloat *crs = new VGfloat[stopCount * 5];
   819     Q_CHECK_PTR(crs);
   808     Q_CHECK_PTR(crs);
   820     QScopedArrayPointer<VGfloat> colorRamps(crs); 
   809     QScopedArrayPointer<VGfloat> colorRamps(crs);
   821     
   810 
   822     if (mFillAlpha == 0xff) {
   811     if (mFillAlpha == 0xff) {
   823         vgSetParameteri(mGradPaintFill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
   812         vgSetParameteri(mGradPaintFill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
   824         vgSetParameterfv(mGradPaintFill, VG_PAINT_COLOR_RAMP_STOPS, lStopCount*5, lStopData);
   813         vgSetParameterfv(mGradPaintFill, VG_PAINT_COLOR_RAMP_STOPS, stopCount*5, stopData);
   825     } else {
   814     } else {
   826         // Copy color ramps and modify alpha
   815         // Copy color ramps and modify alpha
   827         memcpy(colorRamps.data(), lStopData, lStopCount*5*sizeof(VGfloat));
   816         memcpy(colorRamps.data(), stopData, stopCount*5*sizeof(VGfloat));
   828         VGfloat lAlphaInFloat = mFillAlpha * 0.003921568627450f; //(1.0f/255.0f);
   817         VGfloat alphaInFloat = mFillAlpha * 0.003921568627450f; //(1.0f/255.0f);
   829         VGfloat* lAlphaValue = &(colorRamps[4]);
   818         VGfloat* alphaValue = &(colorRamps[4]);
   830         for (int i = 0; i < lStopCount; i++) {
   819         for (int i = 0; i < stopCount; i++) {
   831             *lAlphaValue *= lAlphaInFloat;
   820             *alphaValue *= alphaInFloat;
   832             lAlphaValue += 5;
   821             alphaValue += 5;
   833         }
   822         }
   834 
   823 
   835         vgSetParameteri(mGradPaintFill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
   824         vgSetParameteri(mGradPaintFill, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
   836         vgSetParameterfv(mGradPaintFill, VG_PAINT_COLOR_RAMP_STOPS, lStopCount * 5, colorRamps.data());
   825         vgSetParameterfv(mGradPaintFill, VG_PAINT_COLOR_RAMP_STOPS, stopCount * 5, colorRamps.data());
   837     }
   826     }
   838 }
   827 }
   839 
   828 
   840 void HbNvgCsIcon::drawPath(HbDereferencer * iconData)
   829 void HbNvgCsIcon::drawPath(HbDereferencer * iconData)
   841 {
   830 {
   842     int numSegments = iconData->derefInt16();
   831     qint32 numSegments = iconData->derefInt16();
   843     const VGubyte * pathSegments  = iconData->derefInt8Array(numSegments, sizeof(quint16));
   832     const VGubyte * pathSegments  = iconData->derefInt8Array(numSegments, sizeof(quint16));
   844     /*
   833     /*
   845     * verify that what we got is proper data
   834     * verify that what we got is proper data
   846     * for that calculate the path co-ordinate length
   835     * for that calculate the path co-ordinate length
   847     * and check that the path data does not overflow
   836     * and check that the path data does not overflow
   848     */    
       
   849    int coordinateCount = 0;
       
   850    for (int i = 0; i < numSegments; ++i)
       
   851        {
       
   852        switch (pathSegments[i])
       
   853            {
       
   854            case VG_HLINE_TO:
       
   855            case VG_VLINE_TO:
       
   856                coordinateCount += 1;
       
   857                break;
       
   858            case VG_MOVE_TO:
       
   859            case VG_LINE_TO:
       
   860            case VG_SQUAD_TO:
       
   861                coordinateCount += 2;
       
   862                break;                
       
   863            case VG_QUAD_TO:
       
   864            case VG_SCUBIC_TO:
       
   865                coordinateCount += 4;
       
   866                break;
       
   867            case VG_SCCWARC_TO:
       
   868            case VG_SCWARC_TO:
       
   869            case VG_LCCWARC_TO:
       
   870            case VG_LCWARC_TO:
       
   871                coordinateCount += 5;
       
   872                break;
       
   873            case VG_CUBIC_TO:
       
   874                coordinateCount += 6;
       
   875                break;
       
   876            default:
       
   877                break;
       
   878            }
       
   879        }
       
   880 
       
   881    // this one is just to check the alignment
       
   882    quint8* pathData = iconData->derefInt8Array(sizeof(float), sizeof(quint16) + numSegments);
       
   883    
       
   884    /*
       
   885     * path data need to be word aligned
       
   886     * alignment are done according to the path format
       
   887     */
   837     */
   888    quint32 sizeofpathdata = sizeof(float);
   838     qint32 coordinateCount = 0;
   889    quint32 alignSkip = 0;
   839     for (qint32 i = 0; i < numSegments; ++i) {
   890    quint8 * alignedPtr = 0;
   840         switch (pathSegments[i]) {
   891    if (mLastPathDataType == NvgSixteenBitEncoding)
   841         case VG_HLINE_TO:
   892        {
   842         case VG_VLINE_TO:
   893        alignedPtr = Align2(pathData);
   843             coordinateCount += 1;
   894        sizeofpathdata = sizeof( quint16);
   844             break;
   895        }
   845         case VG_MOVE_TO:
   896    else if (mLastPathDataType == NvgThirtyTwoBitEncoding)
   846         case VG_LINE_TO:
   897        {        
   847         case VG_SQUAD_TO:
   898        alignedPtr = Align4(pathData);
   848             coordinateCount += 2;
   899        }
   849             break;
   900    else
   850         case VG_QUAD_TO:
   901        {
   851         case VG_SCUBIC_TO:
   902        throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   852             coordinateCount += 4;
   903        }
   853             break;
   904    
   854         case VG_SCCWARC_TO:
   905    alignSkip = alignedPtr - pathData; 
   855         case VG_SCWARC_TO:
   906    
   856         case VG_LCCWARC_TO:
   907    /*
   857         case VG_LCWARC_TO:
   908     * check to see whether we have enough path data
   858             coordinateCount += 5;
   909     */
   859             break;
   910    iconData->isSafe(coordinateCount * sizeofpathdata + alignSkip, sizeof(quint16) + numSegments);
   860         case VG_CUBIC_TO:
   911    
   861             coordinateCount += 6;
   912    pathData = alignedPtr;
   862             break;
   913    
   863         default:
   914    VGint paintMode = (mDoFill ? VG_FILL_PATH : 0)|(mDoStroke ? VG_STROKE_PATH : 0);
   864             break;
   915    if (paintMode == 0)
   865         }
   916        {
   866     }
   917        paintMode = VG_FILL_PATH;
   867 
   918        }
   868     // this one is just to check the alignment
   919    
   869     quint8* pathData = iconData->derefInt8Array(sizeof(float), sizeof(quint16) + numSegments);
   920    COND_COM_OC(mCreatingNvgIcon,
   870 
   921            {
   871     /*
   922                VGPath path = createPath();
   872      * path data need to be word aligned
   923                
   873      * alignment are done according to the path format
   924                if (path != VG_INVALID_HANDLE)
   874      */
   925                    {
   875     quint32 sizeofpathdata = sizeof(float);
   926                    vgAppendPathData(path, numSegments, pathSegments, pathData);
   876     quint32 alignSkip = 0;
   927                    }
   877     quint8 * alignedPtr = 0;
   928                else
   878     if (mLastPathDataType == NvgSixteenBitEncoding) {
   929                    {
   879         alignedPtr = Align2(pathData);
   930                    addPathData(numSegments, pathSegments, pathData);
   880         sizeofpathdata = sizeof(quint16);
   931                    }        
   881     } else if (mLastPathDataType == NvgThirtyTwoBitEncoding) {
   932                    addDrawPathCommand(path, paintMode);
   882         alignedPtr = Align4(pathData);
   933            }, 
   883     } else {
   934            {
   884         throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
   935                vgClearPath(mVgPath, VG_PATH_CAPABILITY_APPEND_TO);
   885     }
   936                
   886 
   937                vgAppendPathData(mVgPath, numSegments, pathSegments, pathData);
   887     alignSkip = alignedPtr - pathData;
   938                vgDrawPath(mVgPath, paintMode);
   888 
   939            });
   889     /*
       
   890      * check to see whether we have enough path data
       
   891      */
       
   892     iconData->assertBound(coordinateCount * sizeofpathdata + alignSkip, sizeof(quint16) + numSegments);
       
   893 
       
   894     pathData = alignedPtr;
       
   895 
       
   896     VGint paintMode = (mDoFill ? VG_FILL_PATH : 0) | (mDoStroke ? VG_STROKE_PATH : 0);
       
   897     if (paintMode == 0) {
       
   898         paintMode = VG_FILL_PATH;
       
   899     }
       
   900 
       
   901     COND_COM_OC(mCreatingNvgIcon, {
       
   902         VGPath path = createPath();
       
   903 
       
   904         if (path != VG_INVALID_HANDLE) {
       
   905             vgAppendPathData(path, numSegments, pathSegments, pathData);
       
   906         } else {
       
   907             addPathData(numSegments, pathSegments, pathData);
       
   908         }
       
   909         addDrawPathCommand(path, paintMode);
       
   910     }, {
       
   911         vgClearPath(mVgPath, VG_PATH_CAPABILITY_APPEND_TO);
       
   912 
       
   913         vgAppendPathData(mVgPath, numSegments, pathSegments, pathData);
       
   914         vgDrawPath(mVgPath, paintMode);
       
   915     });
   940     mDoStroke   = VG_FALSE;
   916     mDoStroke   = VG_FALSE;
   941     mDoFill     = VG_FALSE;
   917     mDoFill     = VG_FALSE;
   942 }
   918 }
   943 
   919 
   944 void HbNvgCsIcon::setTransform(HbDereferencer * iconData, quint32 & counter, const VGfloat* currentMatrix)
   920 void HbNvgCsIcon::setTransform(HbDereferencer * iconData, quint32 & counter, const VGfloat* currentMatrix)
   945 {
   921 {
   946     COND_COM_OC(mCreatingNvgIcon, ;, vgLoadMatrix(currentMatrix));
   922     COND_COM_OC(mCreatingNvgIcon, ; , vgLoadMatrix(currentMatrix));
   947 
   923 
   948     quint32 lCommonData =  iconData->derefInt32();
   924     quint32 commonData =  iconData->derefInt32();
   949     quint32 lTransformType = (lCommonData & 0x00ff0000) >> 16 ;
   925     quint32 transformType = (commonData & 0x00ff0000) >> 16 ;
   950 
   926 
   951     VGfloat matrixTemp[9] = {
   927     VGfloat matrixTemp[9] = {
   952         1.0f, 0.0f, 0.0f,
   928         1.0f, 0.0f, 0.0f,
   953         0.0f, 1.0f, 0.0f,
   929         0.0f, 1.0f, 0.0f,
   954         0.0f, 0.0f, 1.0f
   930         0.0f, 0.0f, 1.0f
   955     };
   931     };
   956 
   932 
   957     counter = 0;
   933     counter = 0;
   958 
   934 
   959     if (lTransformType != 1) {
   935     if (transformType != 1) {
   960         if (lTransformType == TRANSFORM_COMPLETE) {
   936         if (transformType == TRANSFORM_COMPLETE) {
   961             matrixTemp[0] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   937             matrixTemp[0] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   962             matrixTemp[4] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   938             matrixTemp[4] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   963             matrixTemp[3] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   939             matrixTemp[3] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   964             matrixTemp[1] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   940             matrixTemp[1] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   965             matrixTemp[6] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   941             matrixTemp[6] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   966             matrixTemp[7] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   942             matrixTemp[7] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   967         } else {
   943         } else {
   968             if (lTransformType & TRANSFORM_ROTATION) {
   944             if (transformType & TRANSFORM_ROTATION) {
   969                 //vgScale
   945                 //vgScale
   970                 matrixTemp[0] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   946                 matrixTemp[0] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   971                 matrixTemp[4] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   947                 matrixTemp[4] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   972                 
   948 
   973                 //vgShear
   949                 //vgShear
   974                 matrixTemp[3] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   950                 matrixTemp[3] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   975                 matrixTemp[1] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   951                 matrixTemp[1] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   976             } else {
   952             } else {
   977                 if (lTransformType & TRANSFORM_SCALING) {
   953                 if (transformType & TRANSFORM_SCALING) {
   978                     //vgScale
   954                     //vgScale
   979                     matrixTemp[0] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   955                     matrixTemp[0] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   980                     matrixTemp[4] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   956                     matrixTemp[4] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   981                 }
   957                 }
   982 
   958 
   983                 if (lTransformType & TRANSFORM_SHEARING) {
   959                 if (transformType & TRANSFORM_SHEARING) {
   984                     //vgShear
   960                     //vgShear
   985                     matrixTemp[3] = iconData->derefReal32((++counter) * sizeof (VGfloat));
   961                     matrixTemp[3] = iconData->derefReal32((++counter) * sizeof(VGfloat));
   986                     matrixTemp[1] = iconData->derefReal32((++counter) * sizeof (VGfloat));;
   962                     matrixTemp[1] = iconData->derefReal32((++counter) * sizeof(VGfloat));;
   987                 }
   963                 }
   988             }
   964             }
   989 
   965 
   990             if (lTransformType & TRANSFORM_TRANSLATION) {
   966             if (transformType & TRANSFORM_TRANSLATION) {
   991                 //vgTranslate
   967                 //vgTranslate
   992                 matrixTemp[6] = iconData->derefReal32((++counter) * sizeof (VGfloat));;
   968                 matrixTemp[6] = iconData->derefReal32((++counter) * sizeof(VGfloat));;
   993                 matrixTemp[7] = iconData->derefReal32((++counter) * sizeof (VGfloat));;
   969                 matrixTemp[7] = iconData->derefReal32((++counter) * sizeof(VGfloat));;
   994             }
   970             }
   995         }
   971         }
   996 
   972 
   997         COND_COM_OC(mCreatingNvgIcon,
   973         COND_COM_OC(mCreatingNvgIcon,
   998                     addSetTransformCommand(matrixTemp, 1),
   974                     addSetTransformCommand(matrixTemp, 1),
  1003     }
   979     }
  1004 }
   980 }
  1005 
   981 
  1006 void HbNvgCsIcon::setStrokePaint(HbDereferencer * iconData)
   982 void HbNvgCsIcon::setStrokePaint(HbDereferencer * iconData)
  1007 {
   983 {
  1008     COND_COM_OC_OOC(register int drawingMode = mCreatingNvgIcon;);
   984     COND_COM_OC_OOC(register qint32 drawingMode = mCreatingNvgIcon;);
  1009     
   985 
  1010     quint32 lCommonData = iconData->derefInt32();
   986     quint32 commonData = iconData->derefInt32();
  1011     quint32 lStrokeType = lCommonData & 0x07;
   987     quint32 strokeType = commonData & 0x07;
  1012     quint16 lSpecifcData = (lCommonData >> 16) & 0xff;
   988     quint16 specifcData = (commonData >> 16) & 0xff;
  1013 
   989 
  1014     switch (lStrokeType) {
   990     switch (strokeType) {
  1015     case STROKE_LGRAD: {
   991     case STROKE_LGRAD: {
  1016         mGradPaintStroke = mPaintStroke;
   992         mGradPaintStroke = mPaintStroke;
  1017         
   993 
  1018         COND_COM_OC_OOC(
   994         COND_COM_OC_OOC(
  1019                    if (mCreatingNvgIcon)
   995         if (mCreatingNvgIcon) {
  1020                        {
   996         mGradPaintStroke = vgCreatePaint();
  1021                        mGradPaintStroke = vgCreatePaint();
   997             if (mGradPaintStroke == VG_INVALID_HANDLE) {
  1022                        if (mGradPaintStroke == VG_INVALID_HANDLE) {
   998                 throw HbNvgException(HbNvgEngine::NvgErrBadHandle);
  1023                            throw HbNvgException(HbNvgEngine::NvgErrBadHandle);
   999             }
  1024                        }
  1000         });
  1025                        });
  1001 
  1026               
       
  1027         // gradient data, the data will be word aligned
  1002         // gradient data, the data will be word aligned
  1028         float* lGradData = (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(float));
  1003         float* gradData = (float*)iconData->derefInt8Array(4 * sizeof(VGfloat), sizeof(float));
  1029                    
  1004 
  1030         COND_COM_OC(drawingMode, ; ,
  1005         COND_COM_OC(drawingMode, ; ,
  1031                     vgSetParameteri(mGradPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
  1006                     vgSetParameteri(mGradPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT);
  1032                     vgSetParameterfv(mGradPaintStroke, VG_PAINT_LINEAR_GRADIENT, 4, lGradData);
  1007                     vgSetParameterfv(mGradPaintStroke, VG_PAINT_LINEAR_GRADIENT, 4, gradData);
  1033                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER));
  1008                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER));
  1034 
  1009 
  1035         if (lSpecifcData & 0x1) {
  1010         if (specifcData & 0x1) {
  1036             float* lGradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof(VGfloat),
  1011             float* gradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof(VGfloat),
  1037                     4 + 4 * sizeof(VGfloat));
  1012                                   4 + 4 * sizeof(VGfloat));
  1038                             
  1013 
  1039             float lGradMatrix[9] = {lGradMatrix1[0], lGradMatrix1[3], 0.0f,
  1014             float gradMatrix[9] = {gradMatrix1[0], gradMatrix1[3], 0.0f,
  1040                                     lGradMatrix1[1], lGradMatrix1[4], 0.0f,
  1015                                     gradMatrix1[1], gradMatrix1[4], 0.0f,
  1041                                     lGradMatrix1[2], lGradMatrix1[5], 1.0f
  1016                                     gradMatrix1[2], gradMatrix1[5], 1.0f
  1042                                    };
  1017                                    };
  1043 
  1018 
  1044             COND_COM_OC(drawingMode,
  1019             COND_COM_OC(drawingMode,
  1045                         addStrokeLinearGradientCommand(4, lGradData, lGradMatrix, mGradPaintStroke),
  1020                         addStrokeLinearGradientCommand(4, gradData, gradMatrix, mGradPaintStroke),
  1046                         vgLoadMatrix(lGradMatrix));
  1021                         vgLoadMatrix(gradMatrix));
  1047             Q_UNUSED(IdentityMatrix);
  1022             Q_UNUSED(identityMatrix);
  1048         } else {
  1023         } else {
  1049             COND_COM_OC(drawingMode,
  1024             COND_COM_OC(drawingMode,
  1050                         addStrokeLinearGradientCommand(4, lGradData, (VGfloat*)IdentityMatrix, mGradPaintStroke),
  1025                         addStrokeLinearGradientCommand(4, gradData, (VGfloat*)identityMatrix, mGradPaintStroke),
  1051                         vgLoadIdentity());
  1026                         vgLoadIdentity());
  1052         }
  1027         }
  1053         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1028         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1054     } 
  1029     }
  1055     break;
  1030     break;
  1056     case STROKE_RGRAD: {
  1031     case STROKE_RGRAD: {
  1057         mGradPaintStroke = mPaintStroke;
  1032         mGradPaintStroke = mPaintStroke;
  1058         
  1033 
  1059         COND_COM_OC_OOC(
  1034         COND_COM_OC_OOC(
  1060                     if (mCreatingNvgIcon)
  1035         if (mCreatingNvgIcon) {
  1061                         {
  1036         mGradPaintStroke = vgCreatePaint();
  1062                         mGradPaintStroke = vgCreatePaint();
  1037             if (mGradPaintStroke == VG_INVALID_HANDLE) {
  1063                         if (mGradPaintStroke == VG_INVALID_HANDLE) {
  1038                 throw HbNvgException(HbNvgEngine::NvgErrBadHandle);
  1064                             throw HbNvgException(HbNvgEngine::NvgErrBadHandle);
  1039             }
  1065                         }
  1040         });
  1066                         });
       
  1067         // gradient data, the data will be word aligned
  1041         // gradient data, the data will be word aligned
  1068         float* lGradData = (float*)iconData->derefInt8Array(5 * sizeof(VGfloat), sizeof(quint32));
  1042         float* gradData = (float*)iconData->derefInt8Array(5 * sizeof(VGfloat), sizeof(quint32));
  1069 
  1043 
  1070         COND_COM_OC(drawingMode, ; ,
  1044         COND_COM_OC(drawingMode, ; ,
  1071                     vgSetParameteri(mGradPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
  1045                     vgSetParameteri(mGradPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
  1072                     vgSetParameterfv(mGradPaintStroke, VG_PAINT_RADIAL_GRADIENT, 5, lGradData);
  1046                     vgSetParameterfv(mGradPaintStroke, VG_PAINT_RADIAL_GRADIENT, 5, gradData);
  1073                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER));
  1047                     vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER));
  1074 
  1048 
  1075         if (lSpecifcData & 0x1) {
  1049         if (specifcData & 0x1) {
  1076             float* lGradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof(VGfloat),
  1050             float* gradMatrix1 = (float*)iconData->derefInt8Array(6 * sizeof(VGfloat),
  1077                 4 + 5 * sizeof(VGfloat));
  1051                                   4 + 5 * sizeof(VGfloat));
  1078             float lGradMatrix[9] = {lGradMatrix1[0], lGradMatrix1[3], 0.0f,
  1052             float gradMatrix[9] = {gradMatrix1[0], gradMatrix1[3], 0.0f,
  1079                                     lGradMatrix1[1], lGradMatrix1[4], 0.0f,
  1053                                     gradMatrix1[1], gradMatrix1[4], 0.0f,
  1080                                     lGradMatrix1[2], lGradMatrix1[5], 1.0f
  1054                                     gradMatrix1[2], gradMatrix1[5], 1.0f
  1081                                    };
  1055                                    };
  1082 
  1056 
  1083             COND_COM_OC(drawingMode,
  1057             COND_COM_OC(drawingMode,
  1084                         addStrokeRadialGradientCommand(4, lGradData, lGradMatrix, mGradPaintStroke),
  1058                         addStrokeRadialGradientCommand(4, gradData, gradMatrix, mGradPaintStroke),
  1085                         vgLoadMatrix(lGradMatrix));
  1059                         vgLoadMatrix(gradMatrix));
  1086             Q_UNUSED(IdentityMatrix);
  1060             Q_UNUSED(identityMatrix);
  1087         } else {
  1061         } else {
  1088             COND_COM_OC(drawingMode,
  1062             COND_COM_OC(drawingMode,
  1089                         addStrokeRadialGradientCommand(4, lGradData, (VGfloat*)IdentityMatrix, mGradPaintStroke),
  1063                         addStrokeRadialGradientCommand(4, gradData, (VGfloat*)identityMatrix, mGradPaintStroke),
  1090                         vgLoadIdentity());
  1064                         vgLoadIdentity());
  1091         }
  1065         }
  1092         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1066         vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1093         }
  1067     }
  1094         break;
  1068     break;
  1095 
  1069 
  1096     case STROKE_COLOR_RAMP: {
  1070     case STROKE_COLOR_RAMP: {
  1097         int lStopCount = lSpecifcData;
  1071         qint32 stopCount = specifcData;
  1098         float* lStopData = (float*) iconData->derefInt8Array(lStopCount * 5 * sizeof(VGfloat), 4);
  1072         float* stopData = (float*) iconData->derefInt8Array(stopCount * 5 * sizeof(VGfloat), 4);
  1099 
  1073 
  1100         if (mStrokeAlpha == 0xff) {
  1074         if (mStrokeAlpha == 0xff) {
  1101             vgSetParameteri(mGradPaintStroke, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
  1075             vgSetParameteri(mGradPaintStroke, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
  1102             vgSetParameterfv(mGradPaintStroke, VG_PAINT_COLOR_RAMP_STOPS, lStopCount*5, lStopData);
  1076             vgSetParameterfv(mGradPaintStroke, VG_PAINT_COLOR_RAMP_STOPS, stopCount*5, stopData);
  1103         } else {
  1077         } else {
  1104             VGfloat *crs = new VGfloat[lStopCount * 5];
  1078             VGfloat *crs = new VGfloat[stopCount * 5];
  1105             Q_CHECK_PTR(crs);
  1079             Q_CHECK_PTR(crs);
  1106             QScopedArrayPointer<VGfloat> colorRamps(crs);
  1080             QScopedArrayPointer<VGfloat> colorRamps(crs);
  1107             // Copy color ramps and modify alpha
  1081             // Copy color ramps and modify alpha
  1108             memcpy(colorRamps.data(), lStopData, lStopCount*5*sizeof(VGfloat));
  1082             memcpy(colorRamps.data(), stopData, stopCount*5*sizeof(VGfloat));
  1109             VGfloat lAlphaInFloat = mStrokeAlpha * 0.003921568627450f; //(1.0f/255.0f);
  1083             VGfloat alphaInFloat = mStrokeAlpha * (1.0f/255.0f);
  1110             VGfloat* lAlphaValue = &colorRamps[4];
  1084             VGfloat* alphaValue = &colorRamps[4];
  1111             for (int i = 0; i < lStopCount; i++) {
  1085             for (qint32 i = 0; i < stopCount; i++) {
  1112                 *lAlphaValue *= lAlphaInFloat;
  1086                 *alphaValue *= alphaInFloat;
  1113                 lAlphaValue += 5;
  1087                 alphaValue += 5;
  1114             }
  1088             }
  1115 
  1089 
  1116             vgSetParameteri(mGradPaintStroke, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
  1090             vgSetParameteri(mGradPaintStroke, VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
  1117             vgSetParameterfv(mGradPaintStroke, VG_PAINT_COLOR_RAMP_STOPS, lStopCount*5, colorRamps.data());
  1091             vgSetParameterfv(mGradPaintStroke, VG_PAINT_COLOR_RAMP_STOPS, stopCount*5, colorRamps.data());
  1118             }
  1092         }
  1119         }
  1093     }
  1120         break;
  1094     break;
  1121 
  1095 
  1122     default: {
  1096     default: {
  1123         quint32 lRgba = iconData->derefInt32(NVG_RGBA_OFS);
  1097         quint32 rgba = iconData->derefInt32(NVG_RGBA_OFS);
  1124         lRgba = (lRgba & 0xffffff00) | mStrokeAlpha; // replace alpha
  1098         rgba = (rgba & 0xffffff00) | mStrokeAlpha; // replace alpha
  1125 
  1099 
  1126         COND_COM_OC(drawingMode,
  1100         COND_COM_OC(drawingMode,
  1127                     addStrokeSetColorCommand(lRgba),
  1101                     addStrokeSetColorCommand(rgba),
  1128                     vgSetParameteri(mPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
  1102                     vgSetParameteri(mPaintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
  1129                     vgSetColor(mPaintStroke, lRgba));
  1103                     vgSetColor(mPaintStroke, rgba));
  1130         }
  1104     }
  1131         break;
  1105     break;
  1132     }
  1106     }
  1133 }
  1107 }
  1134 
  1108 
  1135 #ifdef    OPENVG_OBJECT_CACHING
  1109 #ifdef    OPENVG_OBJECT_CACHING
  1136 VGPath HbNvgCsIcon::createPath()
  1110 VGPath HbNvgCsIcon::createPath()
  1155         path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
  1129         path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
  1156                             VG_PATH_DATATYPE_S_32, 1.0f / 65536.0f, 0.0f, 0, 0,
  1130                             VG_PATH_DATATYPE_S_32, 1.0f / 65536.0f, 0.0f, 0, 0,
  1157                             VG_PATH_CAPABILITY_APPEND_TO);
  1131                             VG_PATH_CAPABILITY_APPEND_TO);
  1158     }
  1132     }
  1159     break;
  1133     break;
  1160     default: {
  1134     default: 
  1161 
       
  1162     }
       
  1163     break;
  1135     break;
  1164     }
  1136     }
  1165     return path;
  1137     return path;
  1166 }
  1138 }
  1167 #endif
  1139 #endif
  1168 
  1140 
  1169 void HbNvgCsIcon::addPathData(VGint numSegments, const VGubyte * pathSegments, const void * pathData)
  1141 void HbNvgCsIcon::addPathData(VGint numSegments, const VGubyte * pathSegments, const void * pathData)
  1170 {
  1142 {
  1171     mNvgIconData->encodeInt32(NvgPathData);
  1143     mNvgIconData->encodeUint32(NvgPathData);
  1172     mNvgIconData->encodeInt32(numSegments);
  1144     mNvgIconData->encodeUint32(numSegments);
  1173     mNvgIconData->encodeData(pathSegments, numSegments);
  1145     mNvgIconData->encodeData(pathSegments, numSegments);
  1174 
  1146 
  1175     int coordinateCount = 0;
  1147     qint32 coordinateCount = 0;
  1176     for (int i = 0; i < numSegments; ++i) {
  1148     for (qint32 i = 0; i < numSegments; ++i) {
  1177         switch (pathSegments[i]) {
  1149         switch (pathSegments[i]) {
  1178         case VG_HLINE_TO:
  1150         case VG_HLINE_TO:
  1179         case VG_VLINE_TO:
  1151         case VG_VLINE_TO:
  1180             coordinateCount += 1;
  1152             coordinateCount += 1;
  1181             break;
  1153             break;
  1199             break;
  1171             break;
  1200         default:
  1172         default:
  1201             break;
  1173             break;
  1202         }
  1174         }
  1203     }
  1175     }
  1204     mNvgIconData->encodeInt16(coordinateCount);
  1176     mNvgIconData->encodeUint16(coordinateCount);
  1205     mNvgIconData->encodeData(pathData, coordinateCount * 4);
  1177     mNvgIconData->encodeData(pathData, coordinateCount * 4);
  1206 }
  1178 }
  1207 
  1179 
  1208 void HbNvgCsIcon::addDrawPathCommand(VGPath path, VGbitfield paintMode)
  1180 void HbNvgCsIcon::addDrawPathCommand(VGPath path, VGbitfield paintMode)
  1209 {
  1181 {
  1210     mOpenVgHandles->addPath(path);
  1182     mOpenVgHandles->addPath(path);
  1211     mNvgIconData->encodeInt32(NvgPath);
  1183     mNvgIconData->encodeUint32(NvgPath);
  1212     mNvgIconData->encodeInt32(path);
  1184     mNvgIconData->encodeUint32(path);
  1213     mNvgIconData->encodeInt32(paintMode);
  1185     mNvgIconData->encodeUint32(paintMode);
  1214 }
  1186 }
  1215 
  1187 
  1216 void HbNvgCsIcon::addLinearGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1188 void HbNvgCsIcon::addLinearGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1217 {
  1189 {
  1218     mOpenVgHandles->addPaint(paint);
  1190     mOpenVgHandles->addPaint(paint);
  1219     mNvgIconData->encodeInt32(NvgPaint);
  1191     mNvgIconData->encodeUint32(NvgPaint);
  1220     addLinearGradientCommandData(paint, count, gradientData, gradientMatrix);
  1192     addLinearGradientCommandData(paint, count, gradientData, gradientMatrix);
  1221 }
  1193 }
  1222 
  1194 
  1223 void HbNvgCsIcon::addRadialGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1195 void HbNvgCsIcon::addRadialGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1224 {
  1196 {
  1225     mOpenVgHandles->addPaint(paint);
  1197     mOpenVgHandles->addPaint(paint);
  1226     mNvgIconData->encodeInt32(NvgPaint);
  1198     mNvgIconData->encodeUint32(NvgPaint);
  1227     addRadialGradientCommandData(paint, count, gradientData, gradientMatrix);
  1199     addRadialGradientCommandData(paint, count, gradientData, gradientMatrix);
  1228 }
  1200 }
  1229 
  1201 
  1230 void HbNvgCsIcon::addSetColorCommand(VGuint rgba)
  1202 void HbNvgCsIcon::addSetColorCommand(VGuint rgba)
  1231 {
  1203 {
  1232     mNvgIconData->encodeInt32(NvgPaint);
  1204     mNvgIconData->encodeUint32(NvgPaint);
  1233     mNvgIconData->encodeInt32(VG_PAINT_TYPE_COLOR);
  1205     mNvgIconData->encodeUint32(VG_PAINT_TYPE_COLOR);
  1234     mNvgIconData->encodeInt32(rgba);
  1206     mNvgIconData->encodeUint32(rgba);
  1235 }
  1207 }
  1236 
  1208 
  1237 void HbNvgCsIcon::addColorRampCommand(VGPaint paint)
  1209 void HbNvgCsIcon::addColorRampCommand(VGPaint paint)
  1238 {
  1210 {
  1239     mNvgIconData->encodeInt32(NvgColorRamp);
  1211     mNvgIconData->encodeUint32(NvgColorRamp);
  1240     mNvgIconData->encodeInt32(paint);
  1212     mNvgIconData->encodeUint32(paint);
  1241 }
  1213 }
  1242 
  1214 
  1243 void HbNvgCsIcon::addSetTransformCommand(const VGfloat* transformMatrix, int aFlag)
  1215 void HbNvgCsIcon::addSetTransformCommand(const VGfloat* transformMatrix, int aFlag)
  1244 {
  1216 {
  1245     mNvgIconData->encodeInt32(NvgTransform);
  1217     mNvgIconData->encodeUint32(NvgTransform);
  1246     mNvgIconData->encodeData(transformMatrix, 9 * sizeof(VGfloat));
  1218     mNvgIconData->encodeData(transformMatrix, 9 * sizeof(VGfloat));
  1247     mNvgIconData->encodeInt32(aFlag);
  1219     mNvgIconData->encodeUint32(aFlag);
  1248 }
  1220 }
  1249 
  1221 
  1250 void HbNvgCsIcon::addSetStrokeWidthCommand(VGfloat strokeWidth)
  1222 void HbNvgCsIcon::addSetStrokeWidthCommand(VGfloat strokeWidth)
  1251 {
  1223 {
  1252     mNvgIconData->encodeInt32(NvgStrokeWidth);
  1224     mNvgIconData->encodeUint32(NvgStrokeWidth);
  1253     mNvgIconData->encodeReal32(strokeWidth);
  1225     mNvgIconData->encodeReal32(strokeWidth);
  1254 }
  1226 }
  1255 
  1227 
  1256 void HbNvgCsIcon::addSetStrokeMiterLimitCommand(VGfloat miterLimit)
  1228 void HbNvgCsIcon::addSetStrokeMiterLimitCommand(VGfloat miterLimit)
  1257 {
  1229 {
  1258     mNvgIconData->encodeInt32(NvgStrokeMiterLimit);
  1230     mNvgIconData->encodeUint32(NvgStrokeMiterLimit);
  1259     mNvgIconData->encodeReal32(miterLimit);
  1231     mNvgIconData->encodeReal32(miterLimit);
  1260 }
  1232 }
  1261 
  1233 
  1262 void HbNvgCsIcon::addStrokeLineJoinCapCommand(VGint capStyle, VGint joinStyle)
  1234 void HbNvgCsIcon::addStrokeLineJoinCapCommand(VGint capStyle, VGint joinStyle)
  1263 {
  1235 {
  1264     mNvgIconData->encodeInt32(NvgStrokeLineJoinCap);
  1236     mNvgIconData->encodeUint32(NvgStrokeLineJoinCap);
  1265     mNvgIconData->encodeInt32(capStyle);
  1237     mNvgIconData->encodeUint32(capStyle);
  1266     mNvgIconData->encodeInt32(joinStyle);
  1238     mNvgIconData->encodeUint32(joinStyle);
  1267 }
  1239 }
  1268 
  1240 
  1269 void HbNvgCsIcon::addStrokeLinearGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1241 void HbNvgCsIcon::addStrokeLinearGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1270 {
  1242 {
  1271     mOpenVgHandles->addPaint(paint);
  1243     mOpenVgHandles->addPaint(paint);
  1272     mNvgIconData->encodeInt32(NvgStrokePaint);
  1244     mNvgIconData->encodeUint32(NvgStrokePaint);
  1273     addLinearGradientCommandData(paint, count, gradientData, gradientMatrix);
  1245     addLinearGradientCommandData(paint, count, gradientData, gradientMatrix);
  1274 }
  1246 }
  1275 
  1247 
  1276 void HbNvgCsIcon::addStrokeRadialGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1248 void HbNvgCsIcon::addStrokeRadialGradientCommand(VGint count, VGfloat* gradientData, VGfloat* gradientMatrix, VGPaint paint)
  1277 {
  1249 {
  1278     mOpenVgHandles->addPaint(paint);
  1250     mOpenVgHandles->addPaint(paint);
  1279     mNvgIconData->encodeInt32(NvgStrokePaint);
  1251     mNvgIconData->encodeUint32(NvgStrokePaint);
  1280     addRadialGradientCommandData(paint, count, gradientData, gradientMatrix);
  1252     addRadialGradientCommandData(paint, count, gradientData, gradientMatrix);
  1281 }
  1253 }
  1282 
  1254 
  1283 void HbNvgCsIcon::addStrokeSetColorCommand(VGuint rgba)
  1255 void HbNvgCsIcon::addStrokeSetColorCommand(VGuint rgba)
  1284 {
  1256 {
  1285     mNvgIconData->encodeInt32(NvgStrokePaint);
  1257     mNvgIconData->encodeUint32(NvgStrokePaint);
  1286     addSetColorCommandData(rgba);
  1258     addSetColorCommandData(rgba);
  1287 }
  1259 }
  1288 
  1260 
  1289 void HbNvgCsIcon::addStrokeColorRampCommand(VGPaint paint)
  1261 void HbNvgCsIcon::addStrokeColorRampCommand(VGPaint paint)
  1290 {
  1262 {
  1291     mNvgIconData->encodeInt32(NvgStrokeColorRamp);
  1263     mNvgIconData->encodeUint32(NvgStrokeColorRamp);
  1292     mNvgIconData->encodeInt32(paint);
  1264     mNvgIconData->encodeUint32(paint);
  1293 }
  1265 }
  1294 
  1266 
  1295 void HbNvgCsIcon::addLinearGradientCommandData(VGPaint paint, VGint count, VGfloat* gradientData, VGfloat* gradientMatrix)
  1267 void HbNvgCsIcon::addLinearGradientCommandData(VGPaint paint, VGint count, VGfloat* gradientData, VGfloat* gradientMatrix)
  1296 {
  1268 {
  1297     mNvgIconData->encodeInt32(VG_PAINT_TYPE_LINEAR_GRADIENT);
  1269     mNvgIconData->encodeUint32(VG_PAINT_TYPE_LINEAR_GRADIENT);
  1298     mNvgIconData->encodeInt32(paint);
  1270     mNvgIconData->encodeUint32(paint);
  1299     mNvgIconData->encodeInt32(count);
  1271     mNvgIconData->encodeUint32(count);
  1300     mNvgIconData->encodeData(gradientData, count * sizeof(VGfloat));
  1272     mNvgIconData->encodeData(gradientData, count * sizeof(VGfloat));
  1301     mNvgIconData->encodeData(gradientMatrix, 9 * sizeof(VGfloat));
  1273     mNvgIconData->encodeData(gradientMatrix, 9 * sizeof(VGfloat));
  1302 }
  1274 }
  1303 
  1275 
  1304 void HbNvgCsIcon::addRadialGradientCommandData(VGPaint paint, VGint count, VGfloat* gradientData, VGfloat* gradientMatrix)
  1276 void HbNvgCsIcon::addRadialGradientCommandData(VGPaint paint, VGint count, VGfloat* gradientData, VGfloat* gradientMatrix)
  1305 {
  1277 {
  1306     mNvgIconData->encodeInt32(VG_PAINT_TYPE_RADIAL_GRADIENT);
  1278     mNvgIconData->encodeUint32(VG_PAINT_TYPE_RADIAL_GRADIENT);
  1307     mNvgIconData->encodeInt32(paint);
  1279     mNvgIconData->encodeUint32(paint);
  1308     mNvgIconData->encodeInt32(count);
  1280     mNvgIconData->encodeUint32(count);
  1309     mNvgIconData->encodeData(gradientData, count * sizeof(VGfloat));
  1281     mNvgIconData->encodeData(gradientData, count * sizeof(VGfloat));
  1310     mNvgIconData->encodeData(gradientMatrix, 9 * sizeof(VGfloat));
  1282     mNvgIconData->encodeData(gradientMatrix, 9 * sizeof(VGfloat));
  1311 }
  1283 }
  1312 
  1284 
  1313 void HbNvgCsIcon::addSetColorCommandData(VGuint rgba)
  1285 void HbNvgCsIcon::addSetColorCommandData(VGuint rgba)
  1314 {
  1286 {
  1315     mNvgIconData->encodeInt32(VG_PAINT_TYPE_COLOR);
  1287     mNvgIconData->encodeUint32(VG_PAINT_TYPE_COLOR);
  1316     mNvgIconData->encodeInt32(rgba);
  1288     mNvgIconData->encodeUint32(rgba);
  1317 }
  1289 }
  1318 
  1290 
  1319 HbNvgEngine::NvgErrorType HbNvgCsIcon::draw(const QSize &size)
  1291 HbNvgEngine::HbNvgErrorType HbNvgCsIcon::draw(const QSize &size)
  1320 {
  1292 {
  1321     NVG_DEBUGP2("DRAWING NVGCSIcon %s, ", __FUNCTION__);
  1293     NVG_DEBUGP2("DRAWING NvgCsIcon %s, ", __FUNCTION__);
  1322 
  1294 
  1323     HbNvgEngine::NvgErrorType error = HbNvgEngine::NvgErrNone;
  1295     HbNvgEngine::HbNvgErrorType error = HbNvgEngine::NvgErrNone;
  1324 
  1296 
  1325     // Get Matrix modes and all caller matrices (must be restored afterwards)
  1297     // Get Matrix modes and all caller matrices (must be restored afterwards)
  1326     updateClientMatrices();
  1298     updateClientMatrices();
  1327 
  1299 
  1328     //Exception handling has to happen
  1300     //Exception handling has to happen
  1332     restoreClientMatrices();
  1304     restoreClientMatrices();
  1333 
  1305 
  1334     return error;
  1306     return error;
  1335 }
  1307 }
  1336 
  1308 
  1337 HbNvgEngine::NvgErrorType HbNvgCsIcon::doDraw(const QSize &size)
  1309 HbNvgEngine::HbNvgErrorType HbNvgCsIcon::doDraw(const QSize &size)
  1338 {
  1310 {
  1339     HbNvgEngine::NvgErrorType ret = HbNvgEngine::NvgErrNone;
  1311     HbNvgEngine::HbNvgErrorType ret = HbNvgEngine::NvgErrNone;
  1340 
  1312 
  1341     vgSetPaint(mPaintFill,   VG_FILL_PATH);
  1313     vgSetPaint(mPaintFill,   VG_FILL_PATH);
  1342     vgSetPaint(mPaintStroke, VG_STROKE_PATH);
  1314     vgSetPaint(mPaintStroke, VG_STROKE_PATH);
  1343     mLastFillPaintColor     = 0;
  1315     mLastFillPaintColor     = 0;
  1344     mLastStrkePaintColor    = 0;
  1316     mLastStrkePaintColor    = 0;
  1345     mLastFillPaintType      = 0;
  1317     mLastFillPaintType      = 0;
  1346     mLastStrokePaintType    = 0;
  1318     mLastStrokePaintType    = 0;
  1347 
  1319 
  1348     VGfloat lCurrentPathMatrix[9];
  1320     VGfloat currentPathMatrix[9];
  1349     vgGetMatrix(lCurrentPathMatrix);
  1321     vgGetMatrix(currentPathMatrix);
  1350 
  1322 
  1351     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1323     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1352     vgLoadMatrix(lCurrentPathMatrix);
  1324     vgLoadMatrix(currentPathMatrix);
  1353     setRotation();
  1325     setRotation();
  1354 #ifdef __MIRROR_  
  1326 #ifdef __MIRROR_
  1355     vgScale(1.0f, -1.0f);
  1327     vgScale(1.0f, -1.0f);
  1356     vgTranslate(0, (VGfloat)(-size.height()));
  1328     vgTranslate(0, (VGfloat)(-size.height()));
  1357 #endif
  1329 #endif
  1358 
  1330 
  1359     setViewBoxToViewTransformation(size);
  1331     setViewBoxToViewTransformation(size);
  1361     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1333     vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  1362 
  1334 
  1363     VGfloat currentMatrix[9];
  1335     VGfloat currentMatrix[9];
  1364 
  1336 
  1365     vgGetMatrix(currentMatrix);
  1337     vgGetMatrix(currentMatrix);
  1366     
  1338 
  1367     mNvgIconData->beginRead();
  1339     mNvgIconData->beginRead();
  1368 
  1340 
  1369     while (!mNvgIconData->eof()) {
  1341     while (!mNvgIconData->eof()) {
  1370         switch (mNvgIconData->readInt32()) {
  1342         switch (mNvgIconData->readInt32()) {
  1371         case NvgPath: {
  1343         case NvgPath: {
  1379             }
  1351             }
  1380             break;
  1352             break;
  1381         }
  1353         }
  1382         case NvgPathData: {
  1354         case NvgPathData: {
  1383             if (mVgPath != VG_INVALID_HANDLE) {
  1355             if (mVgPath != VG_INVALID_HANDLE) {
  1384             
  1356 
  1385                 VGint numSegments = mNvgIconData->readInt32();
  1357                 VGint numSegments = mNvgIconData->readInt32();
  1386                 
  1358 
  1387                 VGubyte *pSegArry = new VGubyte[numSegments];
  1359                 VGubyte *pSegArry = new VGubyte[numSegments];
  1388                 Q_CHECK_PTR(pSegArry);
  1360                 Q_CHECK_PTR(pSegArry);
  1389                 QScopedArrayPointer<VGubyte> pathSegments(pSegArry);
  1361                 QScopedArrayPointer<VGubyte> pathSegments(pSegArry);
  1390                 mNvgIconData->read(pathSegments.data(), numSegments);
  1362                 mNvgIconData->read(pathSegments.data(), numSegments);
  1391                 
  1363 
  1392                 VGint coordinateCount = mNvgIconData->readInt32();
  1364                 VGint coordinateCount = mNvgIconData->readInt32();
  1393                 
  1365 
  1394                 VGubyte *pDataArry = new VGubyte[coordinateCount * 4];
  1366                 VGubyte *pDataArry = new VGubyte[coordinateCount * 4];
  1395                 Q_CHECK_PTR(pDataArry);
  1367                 Q_CHECK_PTR(pDataArry);
  1396                 QScopedArrayPointer<VGubyte> pathData(pDataArry);
  1368                 QScopedArrayPointer<VGubyte> pathData(pDataArry);
  1397                 mNvgIconData->read(pathData.data(), coordinateCount * 4);
  1369                 mNvgIconData->read(pathData.data(), coordinateCount * 4);
  1398                 
  1370 
  1399                 vgClearPath(mVgPath, VG_PATH_CAPABILITY_APPEND_TO);
  1371                 vgClearPath(mVgPath, VG_PATH_CAPABILITY_APPEND_TO);
  1400                 vgAppendPathData(mVgPath, numSegments, pathSegments.data(), pathData.data());
  1372                 vgAppendPathData(mVgPath, numSegments, pathSegments.data(), pathData.data());
  1401             }
  1373             }
  1402             break;
  1374             break;
  1403             }
  1375         }
  1404         case NvgPaint: {
  1376         case NvgPaint: {
  1405             drawPaint(mPaintFill, VG_MATRIX_FILL_PAINT_TO_USER, mLastFillPaintType, mLastFillPaintColor, VG_FILL_PATH);
  1377             drawPaint(mPaintFill, VG_MATRIX_FILL_PAINT_TO_USER, mLastFillPaintType, mLastFillPaintColor, VG_FILL_PATH);
  1406             break;
  1378             break;
  1407             }
  1379         }
  1408         case NvgColorRamp: {
  1380         case NvgColorRamp: {
  1409             mNvgIconData->readInt32();
  1381             mNvgIconData->readInt32();
  1410             break;
  1382             break;
  1411             }
  1383         }
  1412         case NvgTransform: {
  1384         case NvgTransform: {
  1413             int flag;
  1385             qint32 flag;
  1414             VGfloat transformMatrix[9];
  1386             VGfloat transformMatrix[9];
  1415 
  1387 
  1416             mNvgIconData->read((quint8 *)transformMatrix, 9 * sizeof(VGfloat));
  1388             mNvgIconData->read((quint8 *)transformMatrix, 9 * sizeof(VGfloat));
  1417             flag = mNvgIconData->readInt32();
  1389             flag = mNvgIconData->readInt32();
  1418 
  1390 
  1419             vgLoadMatrix(currentMatrix);
  1391             vgLoadMatrix(currentMatrix);
  1420             if (flag) {
  1392             if (flag) {
  1421                 vgMultMatrix(transformMatrix);
  1393                 vgMultMatrix(transformMatrix);
  1422             }
  1394             }
  1423             
  1395 
  1424             break;
  1396             break;
  1425             }
  1397         }
  1426         case NvgStrokeWidth: {
  1398         case NvgStrokeWidth: {
  1427             VGfloat strokeWidth = mNvgIconData->readReal32();
  1399             VGfloat strokeWidth = mNvgIconData->readReal32();
  1428             vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth);
  1400             vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth);
  1429             break;
  1401             break;
  1430             }
  1402         }
  1431         
  1403 
  1432         case NvgStrokeMiterLimit: {
  1404         case NvgStrokeMiterLimit: {
  1433             VGfloat miterLimit = mNvgIconData->readReal32();
  1405             VGfloat miterLimit = mNvgIconData->readReal32();
  1434             vgSetf(VG_STROKE_MITER_LIMIT, miterLimit);
  1406             vgSetf(VG_STROKE_MITER_LIMIT, miterLimit);
  1435             break;
  1407             break;
  1436             }
  1408         }
  1437         
  1409 
  1438         case NvgStrokeLineJoinCap: {
  1410         case NvgStrokeLineJoinCap: {
  1439             VGint lineJoin = mNvgIconData->readInt32();
  1411             VGint lineJoin = mNvgIconData->readInt32();
  1440             VGint cap = mNvgIconData->readInt32();
  1412             VGint cap = mNvgIconData->readInt32();
  1441 
  1413 
  1442             vgSeti(VG_STROKE_JOIN_STYLE, (VGJoinStyle)lineJoin);
  1414             vgSeti(VG_STROKE_JOIN_STYLE, (VGJoinStyle)lineJoin);
  1443             vgSeti(VG_STROKE_CAP_STYLE, (VGCapStyle)cap);
  1415             vgSeti(VG_STROKE_CAP_STYLE, (VGCapStyle)cap);
  1444             break;
  1416             break;
  1445             }
  1417         }
  1446         case NvgStrokePaint: {
  1418         case NvgStrokePaint: {
  1447             drawPaint(mPaintStroke, VG_MATRIX_STROKE_PAINT_TO_USER, mLastStrokePaintType, mLastStrkePaintColor, VG_STROKE_PATH);
  1419             drawPaint(mPaintStroke, VG_MATRIX_STROKE_PAINT_TO_USER, mLastStrokePaintType, mLastStrkePaintColor, VG_STROKE_PATH);
  1448             break;
  1420             break;
  1449             }
  1421         }
  1450         case NvgStrokeColorRamp: {
  1422         case NvgStrokeColorRamp: {
  1451             mNvgIconData->readInt32();
  1423             mNvgIconData->readInt32();
  1452             break;
  1424             break;
  1453             }
  1425         }
  1454         default: {  
  1426         default: {
  1455             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
  1427             throw HbNvgException(HbNvgEngine::NvgErrCorrupt);
  1456             }
  1428         }
  1457         }
  1429         }
  1458     }
  1430     }
  1459 
  1431 
  1460     mNvgIconData->endRead();
  1432     mNvgIconData->endRead();
  1461 
  1433 
  1462     return ret;
  1434     return ret;
  1463 }
  1435 }
  1464 
  1436 
  1465 void HbNvgCsIcon::drawColorRamp(VGPaint paint)
  1437 void HbNvgCsIcon::drawColorRamp(VGPaint paint)
  1466 {
  1438 {
  1467     int stopCount = mNvgIconData->readInt32();
  1439     qint32 stopCount = mNvgIconData->readInt32();
  1468     
  1440 
  1469     VGfloat *crs = new VGfloat[stopCount];
  1441     VGfloat *crs = new VGfloat[stopCount];
  1470     Q_CHECK_PTR(crs);
  1442     Q_CHECK_PTR(crs);
  1471     QScopedArrayPointer<VGfloat> colorRamps(crs);
  1443     QScopedArrayPointer<VGfloat> colorRamps(crs);
  1472 
  1444 
  1473     mNvgIconData->read((quint8 *)colorRamps.data(), stopCount * sizeof(VGfloat));
  1445     mNvgIconData->read((quint8 *)colorRamps.data(), stopCount * sizeof(VGfloat));
  1485         if (paintType == VG_PAINT_TYPE_RADIAL_GRADIENT) {
  1457         if (paintType == VG_PAINT_TYPE_RADIAL_GRADIENT) {
  1486             paintPType = VG_PAINT_RADIAL_GRADIENT;
  1458             paintPType = VG_PAINT_RADIAL_GRADIENT;
  1487         }
  1459         }
  1488 
  1460 
  1489         VGPaint paintHandle = mNvgIconData->readInt32();
  1461         VGPaint paintHandle = mNvgIconData->readInt32();
  1490         int count = mNvgIconData->readInt32();
  1462         qint32 count = mNvgIconData->readInt32();
  1491         VGfloat gradientData[5];
  1463         VGfloat gradientData[5];
  1492         VGfloat gradientMatrix[9];
  1464         VGfloat gradientMatrix[9];
  1493 
  1465 
  1494         mNvgIconData->read((quint8 *)gradientData, count * sizeof(VGfloat));
  1466         mNvgIconData->read((quint8 *)gradientData, count * sizeof(VGfloat));
  1495         mNvgIconData->read((quint8 *)gradientMatrix, 9 * sizeof(VGfloat));
  1467         mNvgIconData->read((quint8 *)gradientMatrix, 9 * sizeof(VGfloat));
  1541 {
  1513 {
  1542     HbNvgFitToViewBoxImpl *viewBoxTx = new HbNvgFitToViewBoxImpl();
  1514     HbNvgFitToViewBoxImpl *viewBoxTx = new HbNvgFitToViewBoxImpl();
  1543     Q_CHECK_PTR(viewBoxTx);
  1515     Q_CHECK_PTR(viewBoxTx);
  1544     QScopedPointer<HbNvgFitToViewBoxImpl> fitToViewBoxImpl(viewBoxTx);
  1516     QScopedPointer<HbNvgFitToViewBoxImpl> fitToViewBoxImpl(viewBoxTx);
  1545 
  1517 
  1546     fitToViewBoxImpl->setAlign(mPreserveAspectSetting);
  1518     fitToViewBoxImpl->setAllignment(mPreserveAspectSetting);
  1547     fitToViewBoxImpl->setScaling(mSmilFitSetting);
  1519     fitToViewBoxImpl->setScaling(mSmilFitSetting);
  1548     fitToViewBoxImpl->setViewBox(mViewBoxX, mViewBoxY, mViewBoxW, mViewBoxH);
  1520     fitToViewBoxImpl->setViewBox(mViewBoxX, mViewBoxY, mViewBoxW, mViewBoxH);
  1549     fitToViewBoxImpl->setWindowViewportTrans(QRect(0, 0, size.width(), size.height()), QSize(0, 0));
  1521     fitToViewBoxImpl->setWindowViewportTrans(QRect(0, 0, size.width(), size.height()), QSize(0, 0));
  1550 }
  1522 }
  1551 
  1523 
  1552 void HbNvgCsIcon::setRotation()
  1524 void HbNvgCsIcon::setRotation()
  1553 {
  1525 {
  1554     if (mRotationAngle) {    
  1526     if (mRotationAngle) {
  1555         vgTranslate(mRotationX, mRotationY);             
  1527         vgTranslate(mRotationX, mRotationY);
  1556         vgRotate(mRotationAngle);
  1528         vgRotate(mRotationAngle);
  1557         vgTranslate(-mRotationX, -mRotationY);
  1529         vgTranslate(-mRotationX, -mRotationY);
  1558     }
  1530     }
  1559 }
  1531 }
  1560 
  1532