Welcome to mirror list, hosted at ThFree Co, Russian Federation.

os_2.c « myfont « source - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b5e0773e035090f8d71450a5cc31f336ce61c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 Copyright (C) 2016-2017 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"

mystatus_t myfont_load_table_os_2(myfont_font_t* mf, uint8_t* font_data, size_t data_size)
{
    memset(&mf->table_os_2, 0, sizeof(myfont_table_os_2_t));
    
    if(mf->cache.tables_offset[MyFONT_TKEY_OS_2] == 0)
        return MyFONT_STATUS_OK;
    
    myfont_table_os_2_t *tos_2 = &mf->table_os_2;
    const uint32_t table_offset = mf->cache.tables_offset[MyFONT_TKEY_OS_2];
    
    /* get current data */
    uint8_t *data = &font_data[table_offset];
    uint32_t pos = table_offset + 32 + 10 + 16 + 4 + 16;
    
    if(pos > data_size)
        return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
    
    tos_2->version = myfont_read_u16(&data);
    tos_2->xAvgCharWidth = myfont_read_16(&data);
    tos_2->usWeightClass = myfont_read_u16(&data);
    tos_2->usWidthClass = myfont_read_u16(&data);
    tos_2->fsType = myfont_read_16(&data);
    tos_2->ySubscriptXSize = myfont_read_16(&data);
    tos_2->ySubscriptYSize = myfont_read_16(&data);
    tos_2->ySubscriptXOffset = myfont_read_16(&data);
    tos_2->ySubscriptYOffset = myfont_read_16(&data);
    tos_2->ySuperscriptXSize = myfont_read_16(&data);
    tos_2->ySuperscriptYSize = myfont_read_16(&data);
    tos_2->ySuperscriptXOffset = myfont_read_16(&data);
    tos_2->ySuperscriptYOffset = myfont_read_16(&data);
    tos_2->yStrikeoutSize = myfont_read_16(&data);
    tos_2->yStrikeoutPosition = myfont_read_16(&data);
    tos_2->sFamilyClass = myfont_read_16(&data);
    
    memcpy(tos_2->panose, data, 10);
    data += 10;
    
    tos_2->ulUnicodeRange1 = myfont_read_u32(&data);
    tos_2->ulUnicodeRange2 = myfont_read_u32(&data);
    tos_2->ulUnicodeRange3 = myfont_read_u32(&data);
    tos_2->ulUnicodeRange4 = myfont_read_u32(&data);
    
    memcpy(tos_2->achVendID, data, 4);
    data += 4;
    
    tos_2->fsSelection = myfont_read_u16(&data);
    tos_2->usFirstCharIndex = myfont_read_u16(&data);
    tos_2->usLastCharIndex = myfont_read_u16(&data);
    tos_2->sTypoAscender = myfont_read_16(&data);
    tos_2->sTypoDescender = myfont_read_16(&data);
    tos_2->sTypoLineGap = myfont_read_16(&data);
    tos_2->usWinAscent = myfont_read_u16(&data);
    tos_2->usWinDescent = myfont_read_u16(&data);
    
    switch (tos_2->version) {
        case 1:
            pos += 8;
            if(pos > data_size)
                return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
            
            tos_2->ulCodePageRange1 = myfont_read_u32(&data);
            tos_2->ulCodePageRange2 = myfont_read_u32(&data);
            
            break;
        case 2:
        case 3:
        case 4:
            pos += 18;
            if(pos > data_size)
                return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
            
            tos_2->ulCodePageRange1 = myfont_read_u32(&data);
            tos_2->ulCodePageRange2 = myfont_read_u32(&data);
            tos_2->sxHeight = myfont_read_16(&data);
            tos_2->sCapHeight = myfont_read_16(&data);
            tos_2->usDefaultChar = myfont_read_u16(&data);
            tos_2->usBreakChar = myfont_read_u16(&data);
            tos_2->usMaxContext = myfont_read_u16(&data);
            
            break;
        case 5:
            pos += 22;
            if(pos > data_size)
                return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
            
            tos_2->ulCodePageRange1 = myfont_read_u32(&data);
            tos_2->ulCodePageRange2 = myfont_read_u32(&data);
            tos_2->sxHeight = myfont_read_16(&data);
            tos_2->sCapHeight = myfont_read_16(&data);
            tos_2->usDefaultChar = myfont_read_u16(&data);
            tos_2->usBreakChar = myfont_read_u16(&data);
            tos_2->usMaxContext = myfont_read_u16(&data);
            tos_2->usLowerOpticalPointSize = myfont_read_u16(&data);
            tos_2->usUpperOpticalPointSize = myfont_read_u16(&data);
            
            break;
        default:
            break;
    }
    
    return MyFONT_STATUS_OK;
}

int8_t myfont_os_2_panose(myfont_font_t *mf, myfont_table_os_2_panose_t id)
{
    return mf->table_os_2.panose[id];
}