Exemplo n.º 1
0
bool DecodeHexBlk(CBlock& block, const std::string& strHexBlk)
{
    if (!IsHex(strHexBlk))
        return false;

    std::vector<unsigned char> blockData(ParseHex(strHexBlk));
    CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
    try {
        ssBlock >> block;
    }
    catch (const std::exception&) {
        return false;
    }

    return true;
}
Exemplo n.º 2
0
  void PreprocessPBF::ProcessBlock(const TypeConfigRef& typeConfig,
                                   std::unique_ptr<PBF::PrimitiveBlock>&& block)
  {
    PreprocessorCallback::RawBlockDataRef blockData(new PreprocessorCallback::RawBlockData());

    for (int currentGroup=0;
         currentGroup<block->primitivegroup_size();
         currentGroup++) {
      const PBF::PrimitiveGroup &group=block->primitivegroup(currentGroup);

      if (group.nodes_size()>0) {
        ReadNodes(*typeConfig,
                  *block,
                  group,
                  *blockData);
      }
      else if (group.has_dense()) {
        ReadDenseNodes(*typeConfig,
                       *block,
                       group,
                       *blockData);
      }
      else if (group.ways_size()>0) {
        ReadWays(*typeConfig,
                 *block,
                 group,
                 *blockData);
      }
      else if (group.relations_size()>0) {
        ReadRelations(*typeConfig,
                      *block,
                      group,
                      *blockData);
      }
    }

    callback.ProcessBlock(std::move(blockData));
  }
Exemplo n.º 3
0
void ae3d::Font::LoadBMFontMetaBinary(const FileSystem::FileContentsData& metaData)
{
    std::stringstream ifs( std::string( metaData.data.begin(), metaData.data.end() ) );
    unsigned char header[ 4 ];
    ifs.read( (char*)&header, 4 );
    const bool validHeaderHead = header[ 0 ] == 66 && header[ 1 ] == 77 && header[ 2 ] == 70;
    
    if (!validHeaderHead)
    {
        System::Print( "%s does not contain a valid BMFont header!\n", metaData.path.c_str() );
        return;
    }
    
    const bool validHeaderTail = header[ 3 ] == 3;
    
    if (!validHeaderTail)
    {
        System::Print( "%s contains a BMFont header but the version is invalid! Valid is version 3.\n", metaData.path.c_str() );
        return;
    }
    
    while (!ifs.eof())
    {
        unsigned char blockId;
        ifs.read( (char*)&blockId, 1 );
        int blockType = (BlockType::Enum)blockId;
        
        int blockSize;
        ifs.read( (char*)&blockSize, 4 );
        
        std::vector< unsigned char > blockData( blockSize );
        
        if (blockType == BlockType::Info)
        {
            ifs.read( (char*)&blockData[ 0 ], blockSize );
            
            padding[ 0 ] = blockData[  7 ];
            padding[ 1 ] = blockData[  8 ];
            padding[ 2 ] = blockData[  9 ];
            padding[ 3 ] = blockData[ 10 ];
            
            spacing[ 0 ] = blockData[ 11 ];
            spacing[ 1 ] = blockData[ 12 ];
        }
        else if (blockType == BlockType::Common)
        {
            CommonBlock block;
            ifs.read( (char*)&block, blockSize );
            
            lineHeight = block.lineHeight;
            base = block.base;
        }
        else if (blockType == BlockType::Pages)
        {
            ifs.read( (char*)&blockData[ 0 ], blockSize );
        }
        else if (blockType == BlockType::Chars)
        {
            std::vector< CharacterBlock > blocks( blockSize / sizeof( CharacterBlock ) );
            ifs.read( (char*)&blocks[ 0 ].id, blockSize );
            System::Assert( blocks.size() <= 256, "Too many glyphs." );
            
            for (std::size_t c = 0; c < blocks.size(); ++c)
            {
                chars[ blocks[ c ].id ].x = blocks[ c ].x;
                chars[ blocks[ c ].id ].y = blocks[ c ].y;
                chars[ blocks[ c ].id ].width = blocks[ c ].width;
                chars[ blocks[ c ].id ].height = blocks[ c ].height;
                chars[ blocks[ c ].id ].xOffset = blocks[ c ].xOffset;
                chars[ blocks[ c ].id ].yOffset = blocks[ c ].yOffset;
                chars[ blocks[ c ].id ].xAdvance = blocks[ c ].xAdvance;
            }
            
            return;
        }
        else if (blockType == BlockType::Kerning)
        {
            ifs.read( (char*)&blockData[ 0 ], blockSize );
        }
        else
        {
            System::Assert( false, "Fonter: Corrupted binary meta data file or a bug in reader!" );
        }
    }
}