TextureData *DataReaderHelper::decodeTexture(TiXmlElement *_textureXML)
{
    TextureData *_textureData = TextureData::create();
    
    if( _textureXML->Attribute(A_NAME) != NULL)
    {
        _textureData->m_strName = _textureXML->Attribute(A_NAME);
    }
    
    _textureXML->QueryFloatAttribute(A_PIVOT_X, &_textureData->m_fPivotX);
    _textureXML->QueryFloatAttribute(A_PIVOT_Y, &_textureData->m_fPivotY);
    _textureXML->QueryFloatAttribute(A_WIDTH, &_textureData->m_fWidth);
    _textureXML->QueryFloatAttribute(A_HEIGHT, &_textureData->m_fHeight);
    
    
    
    TiXmlElement *_contourXML = _textureXML->FirstChildElement(CONTOUR);
    
    while (_contourXML) {
        
        ContourData *_contourData = decodeContour(_contourXML);
        _textureData->addContourData(_contourData);
        
        _contourXML = _contourXML->NextSiblingElement(CONTOUR);
    }
    
    
    return _textureData;
}
CCTextureData *CCDataReaderHelper::decodeTexture(cs::CSJsonDictionary &json)
{
    CCTextureData *textureData = CCTextureData::create();

    const char *name = json.getItemStringValue(A_NAME);
    if(name != NULL)
    {
        textureData->name = name;
    }

    textureData->width = json.getItemFloatValue(A_WIDTH, 0);
    textureData->height = json.getItemFloatValue(A_HEIGHT, 0);
    textureData->pivotX = json.getItemFloatValue(A_PIVOT_X, 0);
    textureData->pivotY = json.getItemFloatValue(A_PIVOT_Y, 0);

    int length = json.getArrayItemCount(CONTOUR_DATA);
    for (int i = 0; i < length; i++)
    {
        cs::CSJsonDictionary *dic = json.getSubItemFromArray(CONTOUR_DATA, i);
        textureData->contourDataList.addObject(decodeContour(*dic));

        delete dic;
    }

    return textureData;
}
CCTextureData *CCDataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML)
{
    CCTextureData *textureData = CCTextureData::create();

    if( textureXML->Attribute(A_NAME) != NULL)
    {
        textureData->name = textureXML->Attribute(A_NAME);
    }

    float px, py, width, height = 0;

    if(s_FlashToolVersion >= VERSION_2_0)
    {
        textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_X, &px);
        textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_Y, &py);
    }
    else
    {
        textureXML->QueryFloatAttribute(A_PIVOT_X, &px);
        textureXML->QueryFloatAttribute(A_PIVOT_Y, &py);
    }

    textureXML->QueryFloatAttribute(A_WIDTH, &width);
    textureXML->QueryFloatAttribute(A_HEIGHT, &height);

    float anchorPointX = px / width;
    float anchorPointY = (height - py) / height;

    textureData->pivotX = anchorPointX;
    textureData->pivotY = anchorPointY;

    tinyxml2::XMLElement *contourXML = textureXML->FirstChildElement(CONTOUR);

    while (contourXML)
    {
        CCContourData *contourData = decodeContour(contourXML);
        textureData->addContourData(contourData);

        contourXML = contourXML->NextSiblingElement(CONTOUR);
    }

    return textureData;
}