dymokomi/luce-browser-render
Source of release 0.6.2
0.6.2 / src / web_fonts / font_data.lucb
#==============================================================================================
#
# font_data - FontData: the bytes of a font file, owned as a ByteBuffer or a Core::Resource
#
# DESCRIPTION:
# Port of Libraries/LibGfx/Font/FontData.cpp (lines 1-40). The C++ Variant is two fields
# (types_font_data.lucb). LibCore is not ported (DESIGN.md ยง1.1): a Core::Resource is
# opaque in ak, so a FontData made from one cannot answer its bytes; the port's
# PathFontProvider holds the Core::MappedFile of a file resource instead
# (font_data_create_from_mapped_file, mapped_file.lucb).
#
#==============================================================================================
## Ported from Libraries/LibGfx/Font/FontData.cpp:11 Gfx::FontData::create_from_byte_buffer.
pub func font_data_create_from_byte_buffer(byte_buffer: ak.ByteBuffer) -> FontData*:
let font_data = new FontData else trap("out of memory")
font_data_construct_byte_buffer(font_data, byte_buffer)
return font_data
## Ported from Libraries/LibGfx/Font/FontData.cpp:16 Gfx::FontData::create_from_resource.
pub func font_data_create_from_resource(resource: const ak.CoreResource*) -> FontData*:
let font_data = new FontData else trap("out of memory")
font_data_construct_core_resource(font_data, resource)
return font_data
## FontData::create_from_resource of a file resource, whose data() is its MappedFile's bytes:
## the FontData keeps `mapped_file`. (Port addition, see the header.)
pub func font_data_create_from_mapped_file(mapped_file: CoreMappedFile*) -> FontData*:
let font_data = new FontData else trap("out of memory")
font_data.m_mapped_file = mapped_file
return font_data
## Ported from Libraries/LibGfx/Font/FontData.cpp:21 Gfx::FontData::bytes.
pub func font_data_bytes(this: const FontData*) -> const u8[]:
if let mapped_file = this.m_mapped_file:
return core_mapped_file_bytes(mapped_file)
if this.m_resource != none:
trap("unported: Core::Resource::data (LibCore is not ported)")
return ak.byte_buffer_bytes_const(&this.m_byte_buffer)
## Ported from Libraries/LibGfx/Font/FontData.cpp:30 Gfx::FontData::FontData.
pub func font_data_construct_byte_buffer(this: FontData*, byte_buffer: ak.ByteBuffer):
# move(byte_buffer): the storage is shared, as a move leaves nothing behind.
this.m_byte_buffer = byte_buffer
## Ported from Libraries/LibGfx/Font/FontData.cpp:35 Gfx::FontData::FontData.
pub func font_data_construct_core_resource(this: FontData*, resource: const ak.CoreResource*):
this.m_resource = resource