Added MyFONT

This commit is contained in:
lexborisov 2016-08-30 13:07:41 +04:00
parent 31b946e057
commit f6faf9ad64
40 changed files with 2375 additions and 76 deletions

View File

@ -37,7 +37,8 @@ extern "C" {
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
for myfont 070000..07ffff; MyFONT_STATUS_OK == 0x000000
not occupied 080000..
*/
enum modest_status {
MODEST_STATUS_OK = 0x000000,

View File

@ -52,15 +52,7 @@ extern "C" {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_tv
*/
enum mycss_status {
MyCSS_STATUS_OK = 0x000000,

View File

@ -28,19 +28,10 @@ extern "C" {
#include <myhtml/myosi.h>
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum mycss_status {
MyCSS_STATUS_OK = 0x000000,

View File

@ -370,15 +370,7 @@ enum myhtml_tags {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum myhtml_status {
MyHTML_STATUS_OK = 0x0000,

View File

@ -375,15 +375,7 @@ enum myhtml_insertion_mode {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum myhtml_status {
MyHTML_STATUS_OK = 0x0000,

View File

@ -37,7 +37,8 @@ extern "C" {
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
for myfont 070000..07ffff; MyFONT_STATUS_OK == 0x000000
not occupied 080000..
*/
enum modest_status {
MODEST_STATUS_OK = 0x000000,

View File

@ -52,15 +52,7 @@ extern "C" {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_tv
*/
enum mycss_status {
MyCSS_STATUS_OK = 0x000000,

View File

@ -28,19 +28,10 @@ extern "C" {
#include "myhtml/myosi.h"
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum mycss_status {
MyCSS_STATUS_OK = 0x000000,

184
source/myfont/cmap.c Normal file
View File

@ -0,0 +1,184 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/cmap.h"
void myfont_table_cmap_format_0(myfont_font_t *mf, myfont_tcmap_entry_t *entry)
{
myfont_tcmap_format_0_t *f0 = (myfont_tcmap_format_0_t *)malloc(sizeof(myfont_tcmap_format_0_t));
uint16_t glyphCount = 256;
fread(f0, (sizeof(uint16_t) * 2), 1, mf->file_h);
fread(f0->glyphIdArray, sizeof(uint8_t), glyphCount, mf->file_h);
entry->header = (void *)f0;
}
void myfont_table_cmap_format_4(myfont_font_t *mf, myfont_tcmap_entry_t *entry)
{
myfont_tcmap_format_4_t *f4 = (myfont_tcmap_format_4_t *)malloc(sizeof(myfont_tcmap_format_4_t));
fread(f4, MyFONT_TCMAP_FORMAT_4_FIRST_LENGTH, 1, mf->file_h);
uint16_t segCount = ntohs(f4->segCountX2) / 2;
uint16_t glyphCount = ((ntohs(f4->length) - (16L + 8L * segCount )) & 0xffff) / 2;
f4->numGlyphId = glyphCount;
f4->endCount = (uint16_t *)malloc(sizeof(uint16_t) * segCount);
f4->startCount = (uint16_t *)malloc(sizeof(uint16_t) * segCount);
f4->idDelta = (int16_t *)malloc(sizeof(int16_t) * segCount);
f4->idRangeOffset = (uint16_t *)malloc(sizeof(uint16_t) * segCount);
f4->glyphIdArray = (uint16_t *)malloc(sizeof(uint16_t) * glyphCount);
fread(f4->endCount , sizeof(uint16_t) , segCount, mf->file_h);
fread(&f4->reservedPad , sizeof(uint16_t) , 1, mf->file_h);
fread(f4->startCount , sizeof(uint16_t) , segCount, mf->file_h);
fread(f4->idDelta , sizeof(int16_t) , segCount, mf->file_h);
fread(f4->idRangeOffset, sizeof(int16_t) , segCount, mf->file_h);
fread(f4->glyphIdArray , sizeof(uint16_t) , glyphCount, mf->file_h);
entry->header = (void *)f4;
}
uint16_t myfont_glyph_index_by_code_format_0(myfont_tcmap_format_0_t *f0, unsigned long char_code)
{
if(char_code < 256)
return (uint16_t)f0->glyphIdArray[char_code];
return 0;
}
uint16_t myfont_glyph_index_by_code_format_4(myfont_tcmap_format_4_t *f4, unsigned long char_code)
{
uint16_t segCount = ntohs(f4->segCountX2) / 2;
uint16_t i;
for(i = 0; i < segCount; i++)
if(char_code <= ntohs(f4->endCount[i]))
break;
if(i >= segCount || char_code < ntohs(f4->startCount[i]))
return 0;
if(f4->idRangeOffset[i] == 0)
{
return (char_code + ntohs((uint16_t)f4->idDelta[i])) & 0xFFFF;
}
else
{
uint16_t index = ntohs(f4->idRangeOffset[i]) / 2 + (char_code - ntohs(f4->startCount[i])) - (segCount - i);
if(index < f4->numGlyphId)
{
if(f4->glyphIdArray[index] != 0)
return (ntohs(f4->glyphIdArray[index]) + ntohs((uint16_t)f4->idDelta[i])) & 0xFFFF;
}
}
return 0;
}
uint16_t myfont_glyph_index_by_code(myfont_font_t *mf, unsigned long char_code)
{
uint16_t i, index = 0, tcout = ntohs(mf->table_cmap.header.numTables);
for(i = 0; i < tcout; i++)
{
myfont_tcmap_entry_t *entry = &mf->table_cmap.entries[i];
switch (ntohs(entry->format)) {
case 0:
index = myfont_glyph_index_by_code_format_0((myfont_tcmap_format_0_t *)(entry->header), char_code);
break;
case 4:
index = myfont_glyph_index_by_code_format_4((myfont_tcmap_format_4_t *)(entry->header), char_code);
break;
default:
break;
};
if(index)
break;
}
return index;
}
uint16_t myfont_glyph_index_by_code_on_entry(myfont_tcmap_entry_t *entry, unsigned long char_code)
{
switch (ntohs(entry->format)) {
case 0:
return myfont_glyph_index_by_code_format_0((myfont_tcmap_format_0_t *)(entry->header), char_code);
case 4:
return myfont_glyph_index_by_code_format_4((myfont_tcmap_format_4_t *)(entry->header), char_code);
default:
break;
};
return 0;
}
void myfont_load_table_cmap(myfont_font_t *mf)
{
myfont_table_cmap_t *tcmap = &mf->table_cmap;
myfont_load_table(mf, &tcmap->header, sizeof(myfont_tcmap_header_t), MyFONT_TKEY_cmap);
uint16_t tcout = ntohs(tcmap->header.numTables);
if(tcout == 0)
return;
tcmap->records = (myfont_tcmap_record_t *)malloc(sizeof(myfont_tcmap_record_t) * tcout);
tcmap->entries = (myfont_tcmap_entry_t *)malloc(sizeof(myfont_tcmap_entry_t) * tcout);
fread(tcmap->records, sizeof(myfont_tcmap_record_t), tcout, mf->file_h);
uint16_t i;
for(i = 0; i < tcout; i++)
{
uint32_t offset = ntohl(tcmap->records[i].offset) + mf->cache.tables_offset[MyFONT_TKEY_cmap];
fseek(mf->file_h, offset, SEEK_SET);
fread(&tcmap->entries[i].format, sizeof(uint16_t), 1, mf->file_h);
uint16_t hformat = ntohs(tcmap->entries[i].format);
switch (hformat) {
case 0:
myfont_table_cmap_format_0(mf, &tcmap->entries[i]);
break;
case 4:
myfont_table_cmap_format_4(mf, &tcmap->entries[i]);
break;
default:
break;
}
}
}

209
source/myfont/cmap.h Normal file
View File

@ -0,0 +1,209 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_CMAP_H
#define MyFONT_CMAP_H
#pragma once
#include "myfont/myosi.h"
// table cmap
// + formats
// for Format 8 and 12
struct myfont_tcmap_group {
uint32_t startCharCode;
uint32_t endCharCode;
uint32_t startGlyphID;
}
typedef myfont_tcmap_group_t;
// ++ Format 0: Byte encoding table
struct myfont_tcmap_format_0 {
uint16_t length;
uint16_t language;
uint8_t glyphIdArray[256];
}
typedef myfont_tcmap_format_0_t;
// ++ Format 2: High-byte mapping through table
struct myfont_tcmap_format_2_subHeader {
uint16_t firstCode;
uint16_t entryCount;
int16_t idDelta;
uint16_t idRangeOffset;
}
typedef myfont_tcmap_f2_sub_header_t;
struct myfont_tcmap_format_2 {
uint16_t length;
uint16_t language;
uint16_t subHeaderKeys[256];
myfont_tcmap_f2_sub_header_t *subHeaders;
uint16_t *glyphIndexArray;
}
typedef myfont_tcmap_format_2_t;
// ++ Format 4: Segment mapping to delta values
// from length to rangeShift
#define MyFONT_TCMAP_FORMAT_4_FIRST_LENGTH sizeof(uint16_t) * 6
struct myfont_tcmap_format_4 {
uint16_t length;
uint16_t language;
uint16_t segCountX2;
uint16_t searchRange;
uint16_t entrySelector;
uint16_t rangeShift;
uint16_t *endCount; // [segCountX2 / 2]
uint16_t reservedPad;
uint16_t *startCount; // [segCountX2 / 2]
int16_t *idDelta; // [segCountX2 / 2]
uint16_t *idRangeOffset; // [segCountX2 / 2]
uint16_t numGlyphId;
uint16_t *glyphIdArray;
}
typedef myfont_tcmap_format_4_t;
// ++ Format 6: Trimmed table mapping
struct myfont_tcmap_format_6 {
uint16_t length;
uint16_t language;
uint16_t firstCode;
uint16_t entryCount;
uint16_t *glyphIdArray; // [entryCount]
}
typedef myfont_tcmap_format_6_t;
// +++ Format 8: mixed 16-bit and 32-bit coverage
struct myfont_tcmap_format_8 {
uint16_t reserved;
uint32_t length;
uint32_t language;
uint8_t is32[8192];
uint32_t nGroups; // follow myfont_tcmap_group_t
}
typedef myfont_tcmap_format_8_t;
// +++ Format 10: Trimmed array
struct myfont_tcmap_format_10 {
uint16_t reserved;
uint32_t length;
uint32_t language;
uint32_t startCharCode;
uint32_t numChars;
uint16_t *glyphs;
}
typedef myfont_tcmap_format_10_t;
// +++ Format 12: Segmented coverage
struct myfont_tcmap_format_12 {
uint16_t reserved;
uint32_t length;
uint32_t language;
uint32_t nGroups; // follow myfont_tcmap_group_t
}
typedef myfont_tcmap_format_12_t;
// +++ Format 13: Many-to-one range mappings.
struct myfont_tcmap_format_13 {
uint16_t reserved;
uint32_t length;
uint32_t language;
// Glyph index to be used for all the characters in the group's range.
uint32_t nGroups; // follow myfont_tcmap_group_t
}
typedef myfont_tcmap_format_13_t;
// +++ Format 14: Unicode Variation Sequences
struct myfont_tcmap_format_14 {
uint8_t varSelector[3]; // uint24_t
uint32_t length;
uint32_t numVarSelectorRecords;
}
typedef myfont_tcmap_format_14_t;
struct myfont_tcmap_f14_records {
uint32_t defaultUVSOffset;
uint32_t nonDefaultUVSOffset;
}
typedef myfont_tcmap_f14_records_t;
// Default UVS Table
struct myfont_tcmap_f14_val_range {
uint8_t startUnicodeValue[3]; // uint24_t
uint8_t additionalCount;
}
typedef myfont_tcmap_f14_val_range_t;
struct myfont_tcmap_f14_def_uvs {
uint32_t numUnicodeValueRanges;
myfont_tcmap_f14_val_range_t *value_ranges;
}
typedef myfont_tcmap_f14_def_uvs_t;
// Non-Default UVS Table
struct myfont_tcmap_f14_mapp {
uint8_t startUnicodeValue[3]; // uint24_t
uint8_t additionalCount;
}
typedef myfont_tcmap_f14_mapp_t;
struct myfont_tcmap_f14_non_def_uvs {
uint32_t numUVSMappings;
myfont_tcmap_f14_mapp_t *mappings;
}
typedef myfont_tcmap_f14_non_def_uvs_t;
// cmap headers
struct myfont_tcmap_header {
uint16_t version;
uint16_t numTables;
}
typedef myfont_tcmap_header_t;
struct myfont_tcmap_record {
uint16_t platformID;
uint16_t encodingID;
uint32_t offset;
}
typedef myfont_tcmap_record_t;
struct myfont_tcmap_entry {
uint16_t format;
void *header;
}
typedef myfont_tcmap_entry_t;
struct myfont_table_cmap {
myfont_tcmap_header_t header;
myfont_tcmap_record_t *records;
myfont_tcmap_entry_t *entries;
}
typedef myfont_table_cmap_t;
#include "myfont/myfont.h"
void myfont_load_table_cmap(myfont_font_t *mf);
uint16_t myfont_glyph_index_by_code(myfont_font_t *mf, unsigned long char_code);
uint16_t myfont_glyph_index_by_code_on_entry(myfont_tcmap_entry_t *entry, unsigned long char_code);
#endif /* MyFONT_CMAP_H */

154
source/myfont/glyf.c Normal file
View File

@ -0,0 +1,154 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/glyf.h"
void myfont_load_table_glyf(struct myfont_font *mf)
{
}
void myfont_glyf_load(myfont_font_t *mf, myfont_table_glyph_t *glyph, uint16_t glyph_index)
{
uint16_t offset = myfont_loca_get_offset(mf, glyph_index);
offset += mf->cache.tables_offset[MyFONT_TKEY_glyf];
myfont_glyf_load_data(mf, glyph, offset);
}
void myfont_glyf_load_data(myfont_font_t *mf, myfont_table_glyph_t *glyph, uint16_t offset)
{
if(offset > 0)
{
// load head
fseek(mf->file_h, offset, SEEK_SET);
fread(&glyph->head, sizeof(myfont_table_glyf_head_t), 1, mf->file_h);
uint16_t instructionLength;
uint16_t numberOfContours = ntohs(glyph->head.numberOfContours);
uint16_t *endPtsOfContours = (uint16_t *)malloc(sizeof(uint16_t) * numberOfContours);
fread(endPtsOfContours, sizeof(uint16_t), numberOfContours, mf->file_h);
fread(&instructionLength, sizeof(uint16_t), 1, mf->file_h);
uint16_t pointCount = ntohs(endPtsOfContours[numberOfContours - 1]) + 1;
uint8_t *instructions = (uint8_t *)malloc(sizeof(uint8_t) * instructionLength);
fread(instructions, sizeof(uint8_t), instructionLength, mf->file_h);
glyph->simple.endPtsOfContours = endPtsOfContours;
glyph->simple.instructionLength = instructionLength;
glyph->simple.instructions = instructions;
glyph->pointCount = pointCount;
myfont_glyf_load_flags(mf, glyph);
myfont_glyf_load_coordinates(mf, glyph);
}
}
void myfont_glyf_load_flags(myfont_font_t *mf, myfont_table_glyph_t *glyph)
{
uint8_t *flags = (uint8_t *)malloc(sizeof(uint8_t) * myfont_glyf_pointCount(glyph));
uint16_t i, j; uint8_t repeat;
for(i = 0; i < myfont_glyf_pointCount(glyph); i++)
{
flags[i] = fread(flags, sizeof(uint8_t), 1, mf->file_h);
if(flags[i] & MyFONT_GLYF_SML_FLAGS_repeat)
{
repeat = fread(flags, sizeof(uint8_t), 1, mf->file_h);
for(j = 0; j < repeat; j++, i++)
flags[i+1] = flags[i];
}
}
glyph->simple.flags = flags;
}
void myfont_glyf_load_coordinates(myfont_font_t *mf, myfont_table_glyph_t *glyph)
{
int16_t *xCoordinates = (int16_t *)malloc(sizeof(int16_t) * myfont_glyf_pointCount(glyph));
int16_t *yCoordinates = (int16_t *)malloc(sizeof(int16_t) * myfont_glyf_pointCount(glyph));
uint16_t i;
int16_t in_before = 0, in_now;
for(i = 0; i < myfont_glyf_pointCount(glyph); i++)
{
in_now = 0;
if( myfont_glyf_flags(glyph, i) & 0x02 && myfont_glyf_flags(glyph, i) & 0x10 )
{
fread(&in_now, sizeof(uint8_t), 1, mf->file_h);
xCoordinates[i] = in_before + in_now;
}
else if (myfont_glyf_flags(glyph, i) & 0x02 && !(myfont_glyf_flags(glyph, i) & 0x10) )
{
fread(&in_now, sizeof(uint8_t), 1, mf->file_h);
xCoordinates[i] = in_before - in_now;
}
else if (!(myfont_glyf_flags(glyph, i) & 0x02) && myfont_glyf_flags(glyph, i) & 0x10 )
{
xCoordinates[i] = in_before;
}
else
{
fread(&in_now, sizeof(int16_t), 1, mf->file_h);
xCoordinates[i] = in_before + in_now;
}
in_before = xCoordinates[i];
}
in_before = 0;
for(i = 0; i < myfont_glyf_pointCount(glyph); i++)
{
in_now = 0;
if(myfont_glyf_flags(glyph, i) & 0x04 && myfont_glyf_flags(glyph, i) & 0x20)
{
fread(&in_now, sizeof(uint8_t), 1, mf->file_h);
yCoordinates[i] = in_before+in_now;
}
else if (myfont_glyf_flags(glyph, i) & 0x04 && !(myfont_glyf_flags(glyph, i) & 0x20))
{
fread(&in_now, sizeof(uint8_t), 1, mf->file_h);
yCoordinates[i] = in_before-in_now;
}
else if (!(myfont_glyf_flags(glyph, i) & 0x04) && myfont_glyf_flags(glyph, i) & 0x20)
{
yCoordinates[i] = in_before;
}
else
{
fread(&in_now, sizeof(int16_t), 1, mf->file_h);
yCoordinates[i] = in_before+in_now;
}
in_before = yCoordinates[i];
}
glyph->simple.xCoordinates = xCoordinates;
glyph->simple.yCoordinates = yCoordinates;
}

108
source/myfont/glyf.h Normal file
View File

@ -0,0 +1,108 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_GLYF_H
#define MyFONT_GLYF_H
#pragma once
#include "myfont/myosi.h"
enum myfont_table_glyf_composite_flags {
MyFONT_GLYF_ARG_1_AND_2_ARE_WORDS = 0x0001,
MyFONT_GLYF_ARGS_ARE_XY_VALUES = 0x0002,
MyFONT_GLYF_ROUND_XY_TO_GRID = 0x0004,
MyFONT_GLYF_WE_HAVE_A_SCALE = 0x0008,
MyFONT_GLYF_RESERVED = 0x0010,
MyFONT_GLYF_MORE_COMPONENTS = 0x0020,
MyFONT_GLYF_WE_HAVE_AN_X_AND_Y_SCALE = 0x0040,
MyFONT_GLYF_WE_HAVE_A_TWO_BY_TWO = 0x0080,
MyFONT_GLYF_WE_HAVE_INSTRUCTIONS = 0x0100,
MyFONT_GLYF_USE_MY_METRICS = 0x0200,
MyFONT_GLYF_OVERLAP_COMPOUND = 0x0400,
MyFONT_GLYF_SCALED_COMPONENT_OFFSET = 0x0800,
MyFONT_GLYF_UNSCALED_COMPONENT_OFFSET = 0x1000
};
struct myfont_table_composite_glyph {
uint16_t flags;
uint16_t glyphIndex;
int16_t argument1;
int16_t argument2;
}
typedef myfont_table_composite_glyph_t;
enum myfont_table_glyf_simple_flags {
MyFONT_GLYF_SML_FLAGS_onCurve = 0x001,
MyFONT_GLYF_SML_FLAGS_x_ShortVector = 0x002,
MyFONT_GLYF_SML_FLAGS_y_ShortVector = 0x004,
MyFONT_GLYF_SML_FLAGS_repeat = 0x008,
MyFONT_GLYF_SML_FLAGS_p_x_ShortVector = 0x010,
MyFONT_GLYF_SML_FLAGS_p_y_ShortVector = 0x020,
MyFONT_GLYF_SML_FLAGS_reserved_1 = 0x040,
MyFONT_GLYF_SML_FLAGS_reserved_2 = 0x080,
MyFONT_GLYF_SML_FLAGS_last = 0x100
};
struct myfont_table_simple_glyph {
uint16_t *endPtsOfContours;
uint16_t instructionLength;
uint8_t *instructions;
uint8_t *flags;
int16_t *xCoordinates;
int16_t *yCoordinates;
}
typedef myfont_table_simple_glyph_t;
struct myfont_table_glyf_head {
int16_t numberOfContours;
int16_t xMin;
int16_t yMin;
int16_t xMax;
int16_t yMax;
}
typedef myfont_table_glyf_head_t;
struct myfont_table_glyph {
myfont_table_glyf_head_t head;
myfont_table_simple_glyph_t simple;
uint16_t pointCount;
}
typedef myfont_table_glyph_t;
struct myfont_table_glyf {
myfont_table_glyph_t *cache;
}
typedef myfont_table_glyf_t;
#include "myfont/myfont.h"
#define myfont_glyf_pointCount(__glyph__) __glyph__->pointCount
#define myfont_glyf_flags(__glyph__, __i__) __glyph__->simple.flags[__i__]
struct myfont_font;
void myfont_load_table_glyf(struct myfont_font *mf);
void myfont_glyf_load(struct myfont_font *mf, myfont_table_glyph_t *glyph, uint16_t glyph_index);
void myfont_glyf_load_data(struct myfont_font *mf, myfont_table_glyph_t *glyph, uint16_t offset);
void myfont_glyf_load_flags(struct myfont_font *mf, myfont_table_glyph_t *glyph);
void myfont_glyf_load_coordinates(struct myfont_font *mf, myfont_table_glyph_t *glyph);
#endif /* MyFONT_GLYF_H */

42
source/myfont/head.c Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/head.h"
void myfont_load_table_head(struct myfont_font *mf)
{
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_head], SEEK_SET);
fread(&mf->table_head , sizeof(uint32_t), 4, mf->file_h);
fread(&mf->table_head.flags , sizeof(uint16_t), 2, mf->file_h);
fread(mf->table_head.created , sizeof(uint32_t), 2, mf->file_h);
fread(mf->table_head.modified, sizeof(uint32_t), 2, mf->file_h);
fread(&mf->table_head.xMin , sizeof(int16_t) , 9, mf->file_h);
}
float myfont_head_yMax_pixel(struct myfont_font *mf, float font_size)
{
int16_t yMax = ntohs(mf->table_head.yMax);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)yMax * font_size / ((float)reso);
return fsize;
}

56
source/myfont/head.h Normal file
View File

@ -0,0 +1,56 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_HEAD_H
#define MyFONT_HEAD_H
#pragma once
#include "myfont/myosi.h"
struct myfont_table_head {
uint32_t version;
uint32_t fontRevision;
uint32_t checkSumAdjustment;
uint32_t magicNumber;
uint16_t flags;
uint16_t unitsPerEm;
uint32_t created[2]; // 64bit
uint32_t modified[2]; // 64bit
int16_t xMin;
int16_t yMin;
int16_t xMax;
int16_t yMax;
uint16_t macStyle;
uint16_t lowestRecPPEM;
int16_t fontDirectionHint;
int16_t indexToLocFormat;
int16_t glyphDataFormat;
}
typedef myfont_table_head_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_head(struct myfont_font *mf);
float myfont_head_yMax_pixel(struct myfont_font *mf, float font_size);
#endif /* MyFONT_HEAD_H */

26
source/myfont/hhea.c Normal file
View File

@ -0,0 +1,26 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/hhea.h"
void myfont_load_table_hhea(myfont_font_t *mf)
{
myfont_load_table(mf, &mf->table_hhea, sizeof(myfont_table_hhea_t), MyFONT_TKEY_hhea);
}

55
source/myfont/hhea.h Normal file
View File

@ -0,0 +1,55 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_HHEA_H
#define MyFONT_HHEA_H
#pragma once
#include "myfont/myosi.h"
// table hhea
struct myfont_table_hhea {
int32_t version;
int16_t Ascender;
int16_t Descender;
int16_t LineGap;
uint16_t advanceWidthMax;
int16_t minLeftSideBearing;
int16_t minRightSideBearing;
int16_t xMaxExtent;
int16_t caretSlopeRise;
int16_t caretSlopeRun;
int16_t caretOffset;
int16_t reserved1;
int16_t reserved2;
int16_t reserved3;
int16_t reserved4;
int16_t metricDataFormat;
uint16_t numberOfHMetrics;
}
typedef myfont_table_hhea_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_hhea(struct myfont_font *mf);
#endif /* MyFONT_HHEA_H */

35
source/myfont/hmtx.c Normal file
View File

@ -0,0 +1,35 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/hmtx.h"
void myfont_load_table_hmtx(struct myfont_font *mf)
{
uint16_t num_metrics = htons(mf->table_hhea.numberOfHMetrics);
myfont_long_hor_metric_t *lhor_metric = (myfont_long_hor_metric_t *)malloc(sizeof(myfont_long_hor_metric_t) * num_metrics);
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_hmtx], SEEK_SET);
fread(lhor_metric, sizeof(myfont_long_hor_metric_t), num_metrics, mf->file_h);
mf->table_hmtx.hMetrics = lhor_metric;
mf->table_hmtx.leftSideBearing = NULL;
}

46
source/myfont/hmtx.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_HMTX_H
#define MyFONT_HMTX_H
#pragma once
#include "myfont/myosi.h"
struct myfont_long_hor_metric {
uint16_t advanceWidth;
int16_t lsb;
}
typedef myfont_long_hor_metric_t;
// table hhea
struct myfont_table_hmtx {
myfont_long_hor_metric_t *hMetrics;
int16_t *leftSideBearing;
}
typedef myfont_table_hmtx_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_hmtx(struct myfont_font *mf);
#endif /* MyFONT_HMTX_H */

77
source/myfont/loca.c Normal file
View File

@ -0,0 +1,77 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/loca.h"
void myfont_load_table_loca(struct myfont_font *mf)
{
if(mf->cache.tables_offset[MyFONT_TKEY_loca])
{
uint16_t numGlyph = ntohs(mf->table_maxp.numGlyphs);
if(numGlyph)
{
numGlyph++;
if(mf->table_head.indexToLocFormat)
{
mf->table_loca.long_offsets = (uint32_t *)malloc(sizeof(uint32_t) * numGlyph);
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_loca], SEEK_SET);
fread(mf->table_loca.long_offsets, sizeof(uint32_t), numGlyph, mf->file_h);
mf->table_loca.short_offsets = NULL;
}
else
{
mf->table_loca.short_offsets = (uint16_t *)malloc(sizeof(uint16_t) * numGlyph);
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_loca], SEEK_SET);
fread(mf->table_loca.short_offsets, sizeof(uint16_t) , numGlyph, mf->file_h);
mf->table_loca.long_offsets = NULL;
}
}
else
{
mf->table_loca.short_offsets = NULL;
mf->table_loca.long_offsets = NULL;
}
}
}
uint32_t myfont_loca_get_offset(struct myfont_font *mf, uint16_t glyph_index)
{
//uint16_t numGlyph = ntohs(mf->table_maxp.numGlyphs);
if(mf->table_head.indexToLocFormat)
{
return ntohl(mf->table_loca.long_offsets[glyph_index]);
}
else
{
return ntohs(mf->table_loca.short_offsets[glyph_index]);
}
return 0;
}

42
source/myfont/loca.h Normal file
View File

@ -0,0 +1,42 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_LOCA_H
#define MyFONT_LOCA_H
#pragma once
#include "myfont/myosi.h"
// table pclt
struct myfont_table_loca {
uint16_t *short_offsets;
uint32_t *long_offsets;
}
typedef myfont_table_loca_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_loca(struct myfont_font *mf);
uint32_t myfont_loca_get_offset(struct myfont_font *mf, uint16_t glyph_index);
#endif /* MyFONT_LOCA_H */

54
source/myfont/maxp.c Normal file
View File

@ -0,0 +1,54 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/maxp.h"
void myfont_load_table_maxp(myfont_font_t *mf)
{
uint32_t version;
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_maxp], SEEK_SET);
fread(&version, sizeof(uint32_t), 1, mf->file_h);
if(myfont_table_version_major(version) == 1)
{
myfont_load_table(mf, &mf->table_maxp, sizeof(myfont_table_maxp_t), MyFONT_TKEY_maxp);
}
else
{
fread(&(mf->table_maxp.numGlyphs), sizeof(uint16_t), 1, mf->file_h);
mf->table_maxp.version = version;
mf->table_maxp.maxPoints = 0;
mf->table_maxp.maxContours = 0;
mf->table_maxp.maxCompositePoints = 0;
mf->table_maxp.maxCompositeContours = 0;
mf->table_maxp.maxZones = 0;
mf->table_maxp.maxTwilightPoints = 0;
mf->table_maxp.maxStorage = 0;
mf->table_maxp.maxFunctionDefs = 0;
mf->table_maxp.maxInstructionDefs = 0;
mf->table_maxp.maxStackElements = 0;
mf->table_maxp.maxSizeOfInstructions = 0;
mf->table_maxp.maxComponentElements = 0;
mf->table_maxp.maxComponentDepth = 0;
}
}

52
source/myfont/maxp.h Normal file
View File

@ -0,0 +1,52 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_MAXP_H
#define MyFONT_MAXP_H
#pragma once
#include "myfont/myosi.h"
struct myfont_table_maxp {
uint32_t version;
uint16_t numGlyphs;
uint16_t maxPoints;
uint16_t maxContours;
uint16_t maxCompositePoints;
uint16_t maxCompositeContours;
uint16_t maxZones;
uint16_t maxTwilightPoints;
uint16_t maxStorage;
uint16_t maxFunctionDefs;
uint16_t maxInstructionDefs;
uint16_t maxStackElements;
uint16_t maxSizeOfInstructions;
uint16_t maxComponentElements;
uint16_t maxComponentDepth;
}
typedef myfont_table_maxp_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_maxp(struct myfont_font *mf);
#endif /* MyFONT_MAXP_H */

377
source/myfont/myfont.c Normal file
View File

@ -0,0 +1,377 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/myfont.h"
const char myfont_table_name[][5] = {
"cmap", "head", "hhea", "hmtx", "maxp", "name",
"OS/2", "post", "cvt ", "fpgm", "glyf", "loca",
"prep", "CFF ", "VORG", "EBDT", "EBLC", "EBSC",
"BASE", "GDEF", "GPOS", "GSUB", "JSTF", "DSIG",
"gasp", "hdmx", "kern", "LTSH", "PCLT", "VDMX",
"vhea", "vmtx"
};
myfont_font_t * myfont_create(void)
{
myfont_font_t *mf = (myfont_font_t *)malloc(sizeof(myfont_font_t));
memset(mf->cache.tables_offset, 0, sizeof(uint32_t) * MyFONT_TKEY_LAST_KEY);
memset(&mf->header, 0, sizeof(myfont_header_t));
mf->file_path = NULL;
mf->file_h = NULL;
return mf;
}
void myfont_clean(myfont_font_t *mf)
{
memset(mf->cache.tables_offset, 0, sizeof(uint32_t) * MyFONT_TKEY_LAST_KEY);
memset(&mf->header, 0, sizeof(myfont_header_t));
if(mf->file_h)
fclose(mf->file_h);
mf->file_path = NULL;
mf->file_h = NULL;
}
myfont_font_t * myfont_destroy(myfont_font_t *mf)
{
if(mf->file_h)
fclose(mf->file_h);
if(mf)
free(mf);
return NULL;
}
void myfont_load(myfont_font_t *mf, const char *filepath)
{
FILE *fh = fopen(filepath, "rb");
fseek(fh, 0L, SEEK_END);
long file_size = ftell(fh);
fseek(fh, 0L, SEEK_SET);
if(file_size > 0)
mf->file_size = (size_t)file_size;
fread(&mf->header, sizeof(myfont_header_t), 1, fh);
myfont_table_t table = {0};
uint16_t i;
for(i = 0; i < htons(mf->header.numTables); i++)
{
fread(&table, sizeof(myfont_table_t), 1, fh);
switch(table.tag) {
case MyFONT_TABLE_TYPE_cmap: mf->cache.tables_offset[ MyFONT_TKEY_cmap ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_head: mf->cache.tables_offset[ MyFONT_TKEY_head ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_hhea: mf->cache.tables_offset[ MyFONT_TKEY_hhea ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_hmtx: mf->cache.tables_offset[ MyFONT_TKEY_hmtx ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_maxp: mf->cache.tables_offset[ MyFONT_TKEY_maxp ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_name: mf->cache.tables_offset[ MyFONT_TKEY_name ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_OS_2: mf->cache.tables_offset[ MyFONT_TKEY_OS_2 ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_post: mf->cache.tables_offset[ MyFONT_TKEY_post ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_cvt: mf->cache.tables_offset[ MyFONT_TKEY_cvt ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_fpgm: mf->cache.tables_offset[ MyFONT_TKEY_fpgm ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_glyf: mf->cache.tables_offset[ MyFONT_TKEY_glyf ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_loca: mf->cache.tables_offset[ MyFONT_TKEY_loca ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_prep: mf->cache.tables_offset[ MyFONT_TKEY_prep ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_gasp: mf->cache.tables_offset[ MyFONT_TKEY_gasp ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_CFF: mf->cache.tables_offset[ MyFONT_TKEY_CFF ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_VORG: mf->cache.tables_offset[ MyFONT_TKEY_VORG ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_SVG: mf->cache.tables_offset[ MyFONT_TKEY_SVG ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_EBDT: mf->cache.tables_offset[ MyFONT_TKEY_EBDT ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_EBLC: mf->cache.tables_offset[ MyFONT_TKEY_EBLC ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_EBSC: mf->cache.tables_offset[ MyFONT_TKEY_EBSC ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_CBDT: mf->cache.tables_offset[ MyFONT_TKEY_CBDT ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_CBLC: mf->cache.tables_offset[ MyFONT_TKEY_CBLC ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_BASE: mf->cache.tables_offset[ MyFONT_TKEY_BASE ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_GDEF: mf->cache.tables_offset[ MyFONT_TKEY_GDEF ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_GPOS: mf->cache.tables_offset[ MyFONT_TKEY_GPOS ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_GSUB: mf->cache.tables_offset[ MyFONT_TKEY_GSUB ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_JSTF: mf->cache.tables_offset[ MyFONT_TKEY_JSTF ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_MATH: mf->cache.tables_offset[ MyFONT_TKEY_MATH ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_DSIG: mf->cache.tables_offset[ MyFONT_TKEY_DSIG ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_hdmx: mf->cache.tables_offset[ MyFONT_TKEY_hdmx ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_kern: mf->cache.tables_offset[ MyFONT_TKEY_kern ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_LTSH: mf->cache.tables_offset[ MyFONT_TKEY_LTSH ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_PCLT: mf->cache.tables_offset[ MyFONT_TKEY_PCLT ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_VDMX: mf->cache.tables_offset[ MyFONT_TKEY_VDMX ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_vhea: mf->cache.tables_offset[ MyFONT_TKEY_vhea ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_vmtx: mf->cache.tables_offset[ MyFONT_TKEY_vmtx ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_COLR: mf->cache.tables_offset[ MyFONT_TKEY_COLR ] = ntohl(table.offset); break;
case MyFONT_TABLE_TYPE_CPAL: mf->cache.tables_offset[ MyFONT_TKEY_CPAL ] = ntohl(table.offset); break;
default:
break;
};
}
mf->file_h = fh;
mf->file_path = filepath;
myfont_load_table_cmap(mf);
myfont_load_table_head(mf);
myfont_load_table_name(mf);
myfont_load_table_os_2(mf);
myfont_load_table_maxp(mf);
myfont_load_table_hhea(mf);
myfont_load_table_hmtx(mf);
myfont_load_table_glyf(mf);
myfont_load_table_vhea(mf);
myfont_load_table_vmtx(mf);
myfont_load_table_pclt(mf);
myfont_load_table_loca(mf);
}
myfont_status_t myfont_load_table(myfont_font_t *mf, void *table, size_t size, enum myfont_table_key tkey)
{
if(mf->cache.tables_offset[tkey] == 0)
return MyFONT_STATUS_NOT_FOUND;
fseek(mf->file_h, mf->cache.tables_offset[tkey], SEEK_SET);
fread(table, size, 1, mf->file_h);
return MyFONT_STATUS_OK;
}
void myfont_font_print_exists_table(myfont_font_t *mf, FILE *file)
{
size_t i;
for(i = 0; i < MyFONT_TKEY_LAST_KEY; i++)
{
if(!mf->cache.tables_offset[i])
continue;
fprintf(file, "%s = %u\n", myfont_table_name[i], mf->cache.tables_offset[i]);
}
}
// metrics
float myfont_metrics_baseline(myfont_font_t *mf, float font_size)
{
uint16_t baseline = ntohs(mf->table_os_2.usWinAscent);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)baseline * font_size / ((float)reso);
return fsize;
}
float myfont_metrics_ascent(myfont_font_t *mf, float font_size)
{
return 0.0f;
}
float myfont_metrics_descent(myfont_font_t *mf, float font_size)
{
float baseline = myfont_metrics_baseline(mf, font_size);
uint16_t descent = ntohs(mf->table_os_2.usWinDescent);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)descent * font_size / ((float)reso);
return (baseline + fsize);
}
float myfont_metrics_ascender(myfont_font_t *mf, float font_size)
{
float baseline = myfont_metrics_baseline(mf, font_size);
int16_t ascender = ntohs(mf->table_os_2.sTypoAscender);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)ascender * font_size / ((float)reso);
return (baseline - fsize);
}
float myfont_metrics_descender(myfont_font_t *mf, float font_size)
{
float baseline = myfont_metrics_baseline(mf, font_size);
int16_t descender = ntohs(mf->table_os_2.sTypoDescender);
if(descender < 0.0f)
descender = -descender;
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)descender * font_size / ((float)reso);
return (baseline + fsize);
}
float myfont_metrics_x_height(myfont_font_t *mf, float font_size)
{
float baseline = myfont_metrics_baseline(mf, font_size);
int16_t xheight = 0;
if(myfont_table_version_major(mf->table_os_2.version) > 1)
{
if(mf->table_os_2.sxHeight)
xheight = mf->table_os_2.sxHeight;
}
if(xheight == 0 && mf->table_pclt.xHeight)
xheight = (int16_t)mf->table_pclt.xHeight;
if(xheight == 0)
{
uint16_t glyph_index = myfont_glyph_index_by_code(mf, (unsigned long)('x'));
if(glyph_index)
{
myfont_table_glyph_t glyph;
myfont_glyf_load(mf, &glyph, glyph_index);
xheight = glyph.head.yMax;
}
}
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)(ntohs(xheight)) * font_size / (float)(reso);
return (baseline - fsize);
}
float myfont_metrics_cap_height(myfont_font_t *mf, float font_size)
{
float baseline = myfont_metrics_baseline(mf, font_size);
int16_t cap_height = 0;
if(myfont_table_version_major(mf->table_os_2.version) > 1)
{
if(mf->table_os_2.sCapHeight)
cap_height = mf->table_os_2.sCapHeight;
}
if(cap_height == 0 && mf->table_pclt.capHeight)
cap_height = (int16_t)mf->table_pclt.capHeight;
if(cap_height == 0)
{
uint16_t glyph_index = myfont_glyph_index_by_code(mf, (unsigned long)('H'));
if(glyph_index)
{
myfont_table_glyph_t glyph;
myfont_glyf_load(mf, &glyph, glyph_index);
cap_height = glyph.head.yMax;
}
}
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)(ntohs(cap_height)) * font_size / (float)(reso);
return (baseline - fsize);
}
// width, height and ...
float myfont_char_width(myfont_font_t *mf, unsigned long char_code, float font_size)
{
uint16_t glyph_index = myfont_glyph_index_by_code(mf, char_code);
uint16_t num_metrics = ntohs(mf->table_hhea.numberOfHMetrics);
if(num_metrics == 0)
return 0.0f;
if(glyph_index > num_metrics)
glyph_index = num_metrics - 1;
uint16_t width = ntohs(mf->table_hmtx.hMetrics[glyph_index].advanceWidth);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)width * font_size / ((float)reso);
return fsize;
}
float myfont_char_height(myfont_font_t *mf, unsigned long char_code, float font_size)
{
uint16_t glyph_index = myfont_glyph_index_by_code(mf, char_code);
uint16_t num_metrics = ntohs(mf->table_vhea.numOfLongVerMetrics);
if(num_metrics == 0)
{
return myfont_font_height(mf, font_size);
}
if(glyph_index > num_metrics)
glyph_index = num_metrics - 1;
uint16_t height = ntohs(mf->table_vmtx.vMetrics[glyph_index].advanceHeight);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)height * font_size / ((float)reso);
return fsize;
}
float myfont_font_height(myfont_font_t *mf, float font_size)
{
int16_t height = ntohs(mf->table_os_2.usWinAscent) + ntohs(mf->table_os_2.usWinDescent);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)height * font_size / ((float)reso);
return fsize;
}
float myfont_font_ascent(myfont_font_t *mf, float font_size)
{
int16_t ascent = ntohs(mf->table_os_2.usWinAscent);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)ascent * font_size / ((float)reso);
return fsize;
}
float myfont_font_descent(myfont_font_t *mf, float font_size)
{
int16_t descent = ntohs(mf->table_os_2.usWinDescent);
uint16_t reso = ntohs(mf->table_head.unitsPerEm);
float fsize = (float)descent * font_size / ((float)reso);
return fsize;
}
int16_t myfont_table_version_major(uint32_t version)
{
version = htonl(version);
version >>= 16;
return (int16_t)version;
}
int16_t myfont_table_version_minor(uint32_t version)
{
version = htonl(version);
version <<= 16;
version >>= 16;
return (int16_t)version;
}

113
source/myfont/myfont.h Normal file
View File

@ -0,0 +1,113 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_MyFONT_H
#define MyFONT_MyFONT_H
#pragma once
#include "myfont/myosi.h"
#include "myfont/cmap.h"
#include "myfont/head.h"
#include "myfont/name.h"
#include "myfont/os_2.h"
#include "myfont/maxp.h"
#include "myfont/hhea.h"
#include "myfont/hmtx.h"
#include "myfont/glyf.h"
#include "myfont/vhea.h"
#include "myfont/vmtx.h"
#include "myfont/pclt.h"
#include "myfont/loca.h"
// base
#pragma pack(push, 1)
struct myfont_header {
int32_t version;
uint16_t numTables;
uint16_t searchRange;
uint16_t entrySelector;
uint16_t rangeShift;
}
typedef myfont_header_t;
struct myfont_table {
uint32_t tag;
uint32_t checkSum;
uint32_t offset;
uint32_t length;
}
typedef myfont_table_t;
#pragma pack(pop)
struct myfont_cache {
uint32_t tables_offset[MyFONT_TKEY_LAST_KEY];
}
typedef myfont_cache_t;
struct myfont_font {
myfont_header_t header;
myfont_cache_t cache;
myfont_table_cmap_t table_cmap;
myfont_table_head_t table_head;
myfont_table_name_t table_name;
myfont_table_os_2_t table_os_2;
myfont_table_maxp_t table_maxp;
myfont_table_hhea_t table_hhea;
myfont_table_hmtx_t table_hmtx;
myfont_table_glyf_t table_glyf;
myfont_table_vmtx_t table_vmtx;
myfont_table_vhea_t table_vhea;
myfont_table_pclt_t table_pclt;
myfont_table_loca_t table_loca;
const char *file_path;
FILE *file_h;
size_t file_size;
};
myfont_font_t * myfont_create(void);
void myfont_clean(myfont_font_t *mf);
myfont_font_t * myfont_destroy(myfont_font_t *mf);
void myfont_load(myfont_font_t *mf, const char *filepath);
void myfont_font_print_exists_table(myfont_font_t *mf, FILE *file);
float myfont_metrics_baseline(myfont_font_t *mf, float font_size);
float myfont_metrics_ascent(myfont_font_t *mf, float font_size);
float myfont_metrics_descent(myfont_font_t *mf, float font_size);
float myfont_metrics_ascender(myfont_font_t *mf, float font_size);
float myfont_metrics_descender(myfont_font_t *mf, float font_size);
float myfont_metrics_x_height(myfont_font_t *mf, float font_size);
float myfont_metrics_cap_height(myfont_font_t *mf, float font_size);
float myfont_char_width(myfont_font_t *mf, unsigned long char_code, float font_size);
float myfont_char_height(myfont_font_t *mf, unsigned long char_code, float font_size);
float myfont_font_height(myfont_font_t *mf, float font_size);
float myfont_font_ascent(myfont_font_t *mf, float font_size);
float myfont_font_descent(myfont_font_t *mf, float font_size);
myfont_status_t myfont_load_table(myfont_font_t *mf, void *table, size_t size, enum myfont_table_key tkey);
int16_t myfont_table_version_major(uint32_t version);
int16_t myfont_table_version_minor(uint32_t version);
#endif /* MyFONT_MyFONT_H */

140
source/myfont/myosi.h Normal file
View File

@ -0,0 +1,140 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
By specification https://www.microsoft.com/typography/otspec/otff.htm
*/
#ifndef MyFONT_BASE_H
#define MyFONT_BASE_H
#pragma once
#include "myhtml/myosi.h"
// Required Tables
#define MyFONT_TABLE_TYPE_cmap 1885433187
#define MyFONT_TABLE_TYPE_head 1684104552
#define MyFONT_TABLE_TYPE_hhea 1634035816
#define MyFONT_TABLE_TYPE_hmtx 2020896104
#define MyFONT_TABLE_TYPE_maxp 1886937453
#define MyFONT_TABLE_TYPE_name 1701667182
#define MyFONT_TABLE_TYPE_OS_2 841962319 // OS/2
#define MyFONT_TABLE_TYPE_post 1953722224
// Tables Related to TrueType Outlines
#define MyFONT_TABLE_TYPE_cvt 1953915648
#define MyFONT_TABLE_TYPE_fpgm 1835495526
#define MyFONT_TABLE_TYPE_glyf 1719233639
#define MyFONT_TABLE_TYPE_loca 1633906540
#define MyFONT_TABLE_TYPE_prep 1885696624
#define MyFONT_TABLE_TYPE_gasp 1886609767
// Tables Related to PostScript Outlines
#define MyFONT_TABLE_TYPE_CFF 1179009792
#define MyFONT_TABLE_TYPE_VORG 1196576598
// Tables Related to SVG
#define MyFONT_TABLE_TYPE_SVG 1196839680
// Tables Related to Bitmap Glyphs
#define MyFONT_TABLE_TYPE_EBDT 1413759557
#define MyFONT_TABLE_TYPE_EBLC 1129071173
#define MyFONT_TABLE_TYPE_EBSC 1129529925
#define MyFONT_TABLE_TYPE_CBDT 1413759555
#define MyFONT_TABLE_TYPE_CBLC 1129071171
// Advanced Typographic Tables
#define MyFONT_TABLE_TYPE_BASE 1163084098
#define MyFONT_TABLE_TYPE_GDEF 1178944583
#define MyFONT_TABLE_TYPE_GPOS 1397706823
#define MyFONT_TABLE_TYPE_GSUB 1112888135
#define MyFONT_TABLE_TYPE_JSTF 1179931466
#define MyFONT_TABLE_TYPE_MATH 1213481293
// Other OpenType Tables
#define MyFONT_TABLE_TYPE_DSIG 1195987780
#define MyFONT_TABLE_TYPE_hdmx 2020435048
#define MyFONT_TABLE_TYPE_kern 1852990827
#define MyFONT_TABLE_TYPE_LTSH 1213420620
#define MyFONT_TABLE_TYPE_PCLT 1414284112
#define MyFONT_TABLE_TYPE_VDMX 1481458774
#define MyFONT_TABLE_TYPE_vhea 1634035830
#define MyFONT_TABLE_TYPE_vmtx 2020896118
#define MyFONT_TABLE_TYPE_COLR 1380732739
#define MyFONT_TABLE_TYPE_CPAL 1279348803
// base
/*
Very important!!!
see modest/myosi.h:modest_status_t
*/
enum myfont_status {
MyFONT_STATUS_OK = 0x000000,
MyFONT_STATUS_ERROR_MEMORY_ALLOCATION = 0x070000,
MyFONT_STATUS_NOT_FOUND = 0x070001,
}
typedef myfont_status_t;
enum myfont_table_key {
MyFONT_TKEY_cmap = 0x00,
MyFONT_TKEY_head = 0x01,
MyFONT_TKEY_hhea = 0x02,
MyFONT_TKEY_hmtx = 0x03,
MyFONT_TKEY_maxp = 0x04,
MyFONT_TKEY_name = 0x05,
MyFONT_TKEY_OS_2 = 0x06,
MyFONT_TKEY_post = 0x07,
MyFONT_TKEY_cvt = 0x08,
MyFONT_TKEY_fpgm = 0x09,
MyFONT_TKEY_glyf = 0x0A,
MyFONT_TKEY_loca = 0x0B,
MyFONT_TKEY_prep = 0x0C,
MyFONT_TKEY_gasp = 0x0D,
MyFONT_TKEY_CFF = 0x0E,
MyFONT_TKEY_VORG = 0x0F,
MyFONT_TKEY_SVG = 0x10,
MyFONT_TKEY_EBDT = 0x11,
MyFONT_TKEY_EBLC = 0x12,
MyFONT_TKEY_EBSC = 0x13,
MyFONT_TKEY_CBDT = 0x14,
MyFONT_TKEY_CBLC = 0x15,
MyFONT_TKEY_BASE = 0x16,
MyFONT_TKEY_GDEF = 0x17,
MyFONT_TKEY_GPOS = 0x18,
MyFONT_TKEY_GSUB = 0x19,
MyFONT_TKEY_JSTF = 0x1A,
MyFONT_TKEY_MATH = 0x1B,
MyFONT_TKEY_DSIG = 0x1C,
MyFONT_TKEY_hdmx = 0x1D,
MyFONT_TKEY_kern = 0x1E,
MyFONT_TKEY_LTSH = 0x1F,
MyFONT_TKEY_PCLT = 0x20,
MyFONT_TKEY_VDMX = 0x21,
MyFONT_TKEY_vhea = 0x22,
MyFONT_TKEY_vmtx = 0x23,
MyFONT_TKEY_COLR = 0x24,
MyFONT_TKEY_CPAL = 0x25,
MyFONT_TKEY_LAST_KEY = 0x26
}
typedef myfont_table_key_t;
/* base struct typedef */
typedef struct myfont_font myfont_font_t;
#endif /* MyFONT_BASE_H */

51
source/myfont/name.c Normal file
View File

@ -0,0 +1,51 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/name.h"
void myfont_load_table_name(myfont_font_t *mf)
{
myfont_table_name_t *table_name = &mf->table_name;
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_name], SEEK_SET);
fread(table_name, sizeof(uint16_t) * 3, 1, mf->file_h);
size_t record_size = sizeof(myfont_record_t) * ntohs(table_name->count);
myfont_record_t *record = (myfont_record_t *)malloc(record_size);
fread(record, record_size, 1, mf->file_h);
table_name->nameRecord = record;
if(ntohs(table_name->format) == 1)
{
fread(&table_name->langTagCount, sizeof(uint16_t), 1, mf->file_h);
size_t lang_record_size = sizeof(myfont_ltag_record_t) * ntohs(table_name->langTagCount);
myfont_ltag_record_t *lang_record = (myfont_ltag_record_t *)malloc(lang_record_size);
fread(lang_record, lang_record_size, 1, mf->file_h);
table_name->langTagRecord = lang_record;
}
myfont_load_table(mf, table_name, sizeof(myfont_table_hhea_t), MyFONT_TKEY_hhea);
}

61
source/myfont/name.h Normal file
View File

@ -0,0 +1,61 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_NAME_H
#define MyFONT_NAME_H
#pragma once
#include "myfont/myosi.h"
// table name
struct myfont_table_name_record {
uint16_t platformID;
uint16_t encodingID;
uint16_t languageID;
uint16_t nameID;
uint16_t length;
uint16_t offset;
}
typedef myfont_record_t;
struct myfont_lang_tag_record {
uint16_t length;
uint16_t offset;
}
typedef myfont_ltag_record_t;
struct myfont_table_name {
uint16_t format;
uint16_t count;
uint16_t stringOffset;
myfont_record_t *nameRecord;
uint16_t langTagCount;
myfont_ltag_record_t *langTagRecord;
char *str_data;
}
typedef myfont_table_name_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_name(struct myfont_font *mf);
#endif /* MyFONT_NAME_H */

81
source/myfont/os_2.c Normal file
View File

@ -0,0 +1,81 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/os_2.h"
void myfont_load_table_os_2(myfont_font_t *mf)
{
if(mf->cache.tables_offset[MyFONT_TKEY_OS_2])
{
myfont_load_table(mf, &mf->table_os_2, sizeof(int16_t) * 16, MyFONT_TKEY_OS_2);
fread(mf->table_os_2.panose , sizeof(uint8_t) , 10, mf->file_h);
fread(&mf->table_os_2.ulUnicodeRange1 , sizeof(uint32_t), 4, mf->file_h);
fread(mf->table_os_2.achVendID , sizeof(int8_t) , 4, mf->file_h);
fread(&mf->table_os_2.fsSelection , sizeof(int16_t) , 8, mf->file_h);
uint16_t version = myfont_table_version_major(mf->table_os_2.version);
memset(&mf->table_os_2.ulCodePageRange1, 0, sizeof(uint32_t) * 2);
memset(&mf->table_os_2.sxHeight, 0, sizeof(int16_t) * 7);
switch (version)
{
case 1:
fread(&mf->table_os_2.ulCodePageRange1, sizeof(uint32_t), 2, mf->file_h);
break;
case 2:
fread(&mf->table_os_2.ulCodePageRange1, sizeof(uint32_t), 2, mf->file_h);
fread(&mf->table_os_2.sxHeight, sizeof(int16_t), 5, mf->file_h);
break;
case 3:
fread(&mf->table_os_2.ulCodePageRange1, sizeof(uint32_t), 2, mf->file_h);
fread(&mf->table_os_2.sxHeight, sizeof(int16_t), 5, mf->file_h);
break;
case 4:
fread(&mf->table_os_2.ulCodePageRange1, sizeof(uint32_t), 2, mf->file_h);
fread(&mf->table_os_2.sxHeight, sizeof(int16_t), 5, mf->file_h);
break;
case 5:
fread(&mf->table_os_2.ulCodePageRange1, sizeof(uint32_t), 2, mf->file_h);
fread(&mf->table_os_2.sxHeight, sizeof(int16_t), 7, mf->file_h);
break;
default:
break;
}
}
else
{
memset(&mf->table_os_2.version , 0, sizeof(int16_t) * 16);
memset(&mf->table_os_2.panose , 0, sizeof(int8_t) * 10);
memset(&mf->table_os_2.ulUnicodeRange1 , 0, sizeof(uint32_t) * 4);
memset(&mf->table_os_2.achVendID , 0, sizeof(int8_t) * 4);
memset(&mf->table_os_2.achVendID , 0, sizeof(int16_t) * 8);
memset(&mf->table_os_2.ulCodePageRange1, 0, sizeof(uint32_t) * 2);
memset(&mf->table_os_2.sxHeight , 0, sizeof(int16_t) * 7);
}
}
int8_t myfont_os_2_panose(myfont_font_t *mf, enum myfont_table_os_2_panose id)
{
return mf->table_os_2.panose[id];
}

92
source/myfont/os_2.h Normal file
View File

@ -0,0 +1,92 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_OS_2_H
#define MyFONT_OS_2_H
#pragma once
#include "myfont/myosi.h"
enum myfont_table_os_2_panose {
MyFONT_PANOSE_panose_bFamilyType = 0,
MyFONT_PANOSE_bSerifStyle = 1,
MyFONT_PANOSE_bWeight = 2,
MyFONT_PANOSE_bProportion = 3,
MyFONT_PANOSE_bContrast = 4,
MyFONT_PANOSE_bStrokeVariation = 5,
MyFONT_PANOSE_bArmStyle = 6,
MyFONT_PANOSE_bLetterform = 7,
MyFONT_PANOSE_bMidline = 8,
MyFONT_PANOSE_bXHeight = 9,
MyFONT_PANOSE_last = 10
};
struct myfont_table_os_2 {
uint16_t version;
int16_t xAvgCharWidth;
uint16_t usWeightClass;
uint16_t usWidthClass;
int16_t fsType;
int16_t ySubscriptXSize;
int16_t ySubscriptYSize;
int16_t ySubscriptXOffset;
int16_t ySubscriptYOffset;
int16_t ySuperscriptXSize;
int16_t ySuperscriptYSize;
int16_t ySuperscriptXOffset;
int16_t ySuperscriptYOffset;
int16_t yStrikeoutSize;
int16_t yStrikeoutPosition;
int16_t sFamilyClass;
uint8_t panose[10];
uint32_t ulUnicodeRange1;
uint32_t ulUnicodeRange2;
uint32_t ulUnicodeRange3;
uint32_t ulUnicodeRange4;
int8_t achVendID[4];
uint16_t fsSelection;
uint16_t usFirstCharIndex;
uint16_t usLastCharIndex;
int16_t sTypoAscender;
int16_t sTypoDescender;
int16_t sTypoLineGap;
uint16_t usWinAscent;
uint16_t usWinDescent;
uint32_t ulCodePageRange1;
uint32_t ulCodePageRange2;
int16_t sxHeight;
int16_t sCapHeight;
uint16_t usDefaultChar;
uint16_t usBreakChar;
uint16_t usMaxContext;
uint16_t usLowerOpticalPointSize;
uint16_t usUpperOpticalPointSize;
}
typedef myfont_table_os_2_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_os_2(struct myfont_font *mf);
int8_t myfont_os_2_panose(struct myfont_font *mf, enum myfont_table_os_2_panose id);
#endif /* MyFONT_OS_2_H */

46
source/myfont/pclt.c Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/pclt.h"
void myfont_load_table_pclt(struct myfont_font *mf)
{
if(mf->cache.tables_offset[MyFONT_TKEY_PCLT])
{
myfont_load_table(mf, &mf->table_pclt, sizeof(int32_t) * 2, MyFONT_TKEY_PCLT);
fread(&mf->table_pclt.pitch , sizeof(uint32_t) , 6, mf->file_h);
fread(&mf->table_pclt.typeface , sizeof(char) , 16, mf->file_h);
fread(mf->table_pclt.characterComplement , sizeof(char) , 8, mf->file_h);
fread(&mf->table_pclt.fileName , sizeof(char) , 6, mf->file_h);
fread(&mf->table_pclt.strokeWeight , sizeof(char) , 2, mf->file_h);
fread(&mf->table_pclt.serifStyle , sizeof(uint8_t) , 2, mf->file_h);
}
else
{
memset(&mf->table_pclt.pitch , 0, sizeof(uint32_t) * 6);
memset(&mf->table_pclt.typeface , 0, sizeof(char) * 16);
memset(&mf->table_pclt.characterComplement , 0, sizeof(char) * 8);
memset(&mf->table_pclt.fileName , 0, sizeof(char) * 6);
memset(&mf->table_pclt.strokeWeight , 0, sizeof(char) * 2);
memset(&mf->table_pclt.serifStyle , 0, sizeof(uint32_t) * 2);
}
}

53
source/myfont/pclt.h Normal file
View File

@ -0,0 +1,53 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_PCLT_H
#define MyFONT_PCLT_H
#pragma once
#include "myfont/myosi.h"
// table pclt
struct myfont_table_pclt {
int32_t version;
uint32_t fontNumber;
uint16_t pitch;
uint16_t xHeight;
uint16_t style;
uint16_t typeFamily;
uint16_t capHeight;
uint16_t symbolSet;
char typeface[16];
char characterComplement[8];
char fileName[6];
char strokeWeight;
char widthType;
uint8_t serifStyle;
uint8_t reserved;
}
typedef myfont_table_pclt_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_pclt(struct myfont_font *mf);
#endif /* MyFONT_PCLT_H */

50
source/myfont/vhea.c Normal file
View File

@ -0,0 +1,50 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/vhea.h"
void myfont_load_table_vhea(myfont_font_t *mf)
{
if(mf->cache.tables_offset[MyFONT_TKEY_vhea])
{
myfont_load_table(mf, &mf->table_vhea, sizeof(myfont_table_vhea_t), MyFONT_TKEY_vhea);
}
else
{
mf->table_vhea.version = 0;
mf->table_vhea.Ascender = 0;
mf->table_vhea.Descender = 0;
mf->table_vhea.LineGap = 0;
mf->table_vhea.advanceHeightMax = 0;
mf->table_vhea.minTopSideBearing = 0;
mf->table_vhea.minBottomSideBearing = 0;
mf->table_vhea.yMaxExtent = 0;
mf->table_vhea.caretSlopeRise = 0;
mf->table_vhea.caretSlopeRun = 0;
mf->table_vhea.caretOffset = 0;
mf->table_vhea.reserved1 = 0;
mf->table_vhea.reserved2 = 0;
mf->table_vhea.reserved3 = 0;
mf->table_vhea.reserved4 = 0;
mf->table_vhea.metricDataFormat = 0;
mf->table_vhea.numOfLongVerMetrics = 0;
}
}

55
source/myfont/vhea.h Normal file
View File

@ -0,0 +1,55 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_VHEA_H
#define MyFONT_VHEA_H
#pragma once
#include "myfont/myosi.h"
// table vhea
struct myfont_table_vhea {
uint32_t version;
int16_t Ascender;
int16_t Descender;
int16_t LineGap;
int16_t advanceHeightMax;
int16_t minTopSideBearing;
int16_t minBottomSideBearing;
int16_t yMaxExtent;
int16_t caretSlopeRise;
int16_t caretSlopeRun;
int16_t caretOffset;
int16_t reserved1;
int16_t reserved2;
int16_t reserved3;
int16_t reserved4;
int16_t metricDataFormat;
uint16_t numOfLongVerMetrics;
}
typedef myfont_table_vhea_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_vhea(struct myfont_font *mf);
#endif /* MyFONT_VHEA_H */

56
source/myfont/vmtx.c Normal file
View File

@ -0,0 +1,56 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#include "myfont/vmtx.h"
void myfont_load_table_vmtx(myfont_font_t *mf)
{
uint16_t num_metrics = htons(mf->table_vhea.numOfLongVerMetrics);
if(num_metrics)
{
myfont_long_ver_metric_t *lver_metric = (myfont_long_ver_metric_t *)malloc(sizeof(myfont_long_ver_metric_t) * num_metrics);
fseek(mf->file_h, mf->cache.tables_offset[MyFONT_TKEY_vmtx], SEEK_SET);
fread(lver_metric, sizeof(myfont_long_ver_metric_t), num_metrics, mf->file_h);
mf->table_vmtx.vMetrics = lver_metric;
uint16_t numOfTSB = htons(mf->table_maxp.numGlyphs - mf->table_vhea.numOfLongVerMetrics);
if(numOfTSB)
{
int16_t *topSideBearing = (int16_t *)malloc(sizeof(int16_t) * numOfTSB);
fread(topSideBearing, sizeof(int16_t), numOfTSB, mf->file_h);
mf->table_vmtx.topSideBearing = topSideBearing;
}
else {
mf->table_vmtx.topSideBearing = NULL;
}
}
else
{
mf->table_vmtx.vMetrics = NULL;
mf->table_vmtx.topSideBearing = NULL;
}
}

46
source/myfont/vmtx.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2016 Alexander Borisov
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: lex.borisov@gmail.com (Alexander Borisov)
*/
#ifndef MyFONT_VMTX_H
#define MyFONT_VMTX_H
#pragma once
#include "myfont/myosi.h"
struct myfont_long_ver_metric {
uint16_t advanceHeight;
int16_t topSideBearing;
}
typedef myfont_long_ver_metric_t;
// table vmtx
struct myfont_table_vmtx {
myfont_long_ver_metric_t *vMetrics;
int16_t *topSideBearing;
}
typedef myfont_table_vmtx_t;
#include "myfont/myfont.h"
struct myfont_font;
void myfont_load_table_vmtx(struct myfont_font *mf);
#endif /* MyFONT_VMTX_H */

View File

@ -370,15 +370,7 @@ enum myhtml_tags {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum myhtml_status {
MyHTML_STATUS_OK = 0x0000,

View File

@ -375,15 +375,7 @@ enum myhtml_insertion_mode {
// base
/*
Very important!!!
for myhtml 0..00ffff; MyHTML_STATUS_OK == 0x000000
for mycss and modules 010000..01ffff; MyCSS_STATUS_OK == 0x000000
for modest 020000..02ffff; MODEST_STATUS_OK == 0x000000
for myrender 030000..03ffff; MyRENDER_STATUS_OK == 0x000000
for mydom 040000..04ffff; MyDOM_STATUS_OK == 0x000000
for mynetwork 050000..05ffff; MyNETWORK_STATUS_OK == 0x000000
for myecma 060000..06ffff; MyECMA_STATUS_OK == 0x000000
not occupied 070000..
see modest/myosi.h:modest_status_t
*/
enum myhtml_status {
MyHTML_STATUS_OK = 0x0000,

BIN
third_party/font/Arkhip.otf vendored Executable file

Binary file not shown.

BIN
third_party/font/Arkhip.ttf vendored Executable file

Binary file not shown.

2
third_party/font/readme.txt vendored Normal file
View File

@ -0,0 +1,2 @@
Free Font
From: http://arkhipfont.ru/