Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as fs from 'fs'
- import {Buf} from './buf'
- class Font {
- header: UcsFontHeader
- // blocks:
- }
- class UcsFontHeader {
- magic: string // char[16]
- size: number // uint Total font size
- blocks: number // uint
- constructor() {
- this.magic = ''
- this.size = 0
- this.blocks = 0
- }
- read_from(buf: Buf) {
- this.magic = buf.read_counted_str(16)
- this.size = buf.read_u32_le()
- this.blocks = buf.read_u32_le()
- }
- }
- class UcsFontBlock {
- start: number // ushort Code start value
- end: number // ushort End code value
- width: number // ushort Lattice (grid) width
- height: number // ushort Lattice (grid) height
- roffs: number // uint Font dot matrix data offset
- xoffs: number // uint Font extension data offset
- constructor() {
- this.start = 0
- this.end = 0
- this.width = 0
- this.height = 0
- this.roffs = 0
- this.xoffs = 0
- }
- read_from(buf: Buf) {
- this.start = buf.read_u16_le()
- this.end = buf.read_u16_le()
- this.width = buf.read_u16_le()
- this.height = buf.read_u16_le()
- this.roffs = buf.read_u32_le()
- this.xoffs = buf.read_u32_le()
- }
- }
- function read_font(path: string) {
- let buf = new Buf()
- buf.data = fs.readFileSync(path)
- console.log('file: ', path)
- console.log('file size: ', buf.data.length)
- let header = new UcsFontHeader()
- header.read_from(buf)
- console.log('header: ', header)
- let blocks = []
- for(let block_index = 0; block_index < header.blocks; block_index++) {
- let block = new UcsFontBlock()
- block.read_from(buf)
- console.log('block: ', block)
- blocks.push(block)
- const bytes_per_symbol = block.width*block.height
- console.log('bytes_per_symbol: ', bytes_per_symbol)
- const symbols_per_block = (block.xoffs - block.roffs) / bytes_per_symbol
- console.log('symbols_per_block: ', symbols_per_block)
- let pos = block.roffs;
- for(let symbol_index = 0; symbol_index < symbols_per_block; symbol_index++) {
- let symbol_data = buf.read_from_offset(pos, bytes_per_symbol)
- let start_pos = pos;
- pos += bytes_per_symbol
- console.log('symbol ', symbol_index, ' start_pos: ', start_pos, ' end_pos: ', pos)
- for(let h = 0; h < block.height; h++) {
- let str = ''
- for(let w = 0; w < block.width; w++) {
- str += symbol_data[h*block.width + w] + ' '
- }
- // console.log(str);
- }
- }
- }
- // console.log('buf.offset: ', buf.offset)
- // console.log('buf len - offset: ', buf.data.length - buf.offset);
- // let font_bytes = (block.width + 7) / 8 * block.height;
- // console.log('font_bytes: ', font_bytes);
- // console.log('bytes_per_symbol: ', block.width*block.height);
- // console.log('bytes_128_symbol: ', 128*block.width*block.height);
- // let m_pASCIIFont = new Uint8Array(font_bytes * 128 + 128);
- for(let block_index = 0; block_index < header.blocks; block_index++) {
- }
- }
- read_font('./Font.bin')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement