bmf-parser 0.0.2

read BMFont binary files
Documentation
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Peter Bjorklund. All rights reserved.
 *  Licensed under the MIT License. See LICENSE in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

use binary::from_octets;
use std::io;
pub mod binary;
pub mod text;

use std::collections::HashMap;

#[derive(Debug)]
pub struct BMFont {
    pub info: Option<InfoBlock>,
    pub common: Option<CommonBlock>,
    pub pages: Vec<String>,
    pub chars: HashMap<u32, Char>,
    pub kernings: Vec<KerningPair>,
}

#[derive(Debug)]
pub struct InfoBlock {
    pub font_size: i16,
    pub bit_field: u8,
    pub char_set: u8,
    pub stretch_h: u16,
    pub aa: u8,
    pub padding: [u8; 4],
    pub spacing: [u8; 2],
    pub outline: u8,
    pub font_name: String,
}

#[derive(Debug)]
pub struct CommonBlock {
    pub line_height: u16,
    pub base: u16,
    pub scale_w: u16,
    pub scale_h: u16,
    pub pages: u16,
    pub bit_field: u8,
    pub alpha_chnl: u8,
    pub red_chnl: u8,
    pub green_chnl: u8,
    pub blue_chnl: u8,
}

#[derive(Debug)]
pub struct Char {
    pub id: u32,
    pub x: u16,
    pub y: u16,
    pub width: u16,
    pub height: u16,
    pub x_offset: i16,
    pub y_offset: i16,
    pub x_advance: i16,
    pub page: u8,
    pub chnl: u8,
}

#[derive(Debug)]
pub struct KerningPair {
    pub first: u32,
    pub second: u32,
    pub amount: i16,
}

impl BMFont {
    pub fn from_octets(data: &[u8]) -> io::Result<Self> {
        from_octets(data)
    }
}