File Coverage

third_party/modest/source/myfont/name.c
Criterion Covered Total %
statement 0 45 0.0
branch 0 20 0.0
condition n/a
subroutine n/a
pod n/a
total 0 65 0.0


line stmt bran cond sub pod time code
1             /*
2             Copyright (C) 2016-2017 Alexander Borisov
3            
4             This library is free software; you can redistribute it and/or
5             modify it under the terms of the GNU Lesser General Public
6             License as published by the Free Software Foundation; either
7             version 2.1 of the License, or (at your option) any later version.
8            
9             This library is distributed in the hope that it will be useful,
10             but WITHOUT ANY WARRANTY; without even the implied warranty of
11             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12             Lesser General Public License for more details.
13            
14             You should have received a copy of the GNU Lesser General Public
15             License along with this library; if not, write to the Free Software
16             Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17            
18             Author: lex.borisov@gmail.com (Alexander Borisov)
19             */
20              
21             #include "myfont/name.h"
22              
23 0           mystatus_t myfont_load_table_name(myfont_font_t *mf, uint8_t* font_data, size_t data_size)
24             {
25 0           memset(&mf->table_name, 0, sizeof(myfont_table_name_t));
26            
27 0 0         if(mf->cache.tables_offset[MyFONT_TKEY_name] == 0)
28 0           return MyFONT_STATUS_OK;
29            
30 0           myfont_table_name_t *tname = &mf->table_name;
31 0           const uint32_t table_offset = mf->cache.tables_offset[MyFONT_TKEY_name];
32 0           uint32_t pos = table_offset + 6;
33            
34 0 0         if(pos > data_size)
35 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
36            
37             /* get current data */
38 0           uint8_t *data = &font_data[table_offset];
39            
40 0           tname->format = myfont_read_u16(&data);
41 0           tname->count = myfont_read_u16(&data);
42 0           tname->stringOffset = myfont_read_u16(&data);
43            
44 0           pos = pos + (tname->count * 12);
45 0 0         if(pos > data_size) {
46 0           tname->count = 0;
47 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
48             }
49            
50 0           myfont_record_t *record = (myfont_record_t *)myfont_calloc(mf, tname->count, sizeof(myfont_record_t));
51            
52 0 0         if(record == NULL)
53 0           return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
54            
55 0 0         for(uint16_t i = 0; i < tname->count; i++) {
56 0           record[i].platformID = myfont_read_u16(&data);
57 0           record[i].encodingID = myfont_read_u16(&data);
58 0           record[i].languageID =myfont_read_u16(&data);
59 0           record[i].nameID = myfont_read_u16(&data);
60 0           record[i].length = myfont_read_u16(&data);
61 0           record[i].offset = myfont_read_u16(&data);
62             }
63            
64 0           tname->nameRecord = record;
65            
66 0 0         if(tname->format == 1)
67             {
68 0           pos += 2;
69 0 0         if(pos > data_size)
70 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
71            
72 0           tname->langTagCount = myfont_read_u16(&data);
73            
74 0           pos = pos + (tname->langTagCount * 4);
75 0 0         if(pos > data_size) {
76 0           tname->langTagCount = 0;
77 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
78             }
79            
80 0           myfont_ltag_record_t *lang_record = (myfont_ltag_record_t *)myfont_calloc(mf, tname->langTagCount, sizeof(myfont_ltag_record_t));
81            
82 0 0         if(lang_record == NULL)
83 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
84            
85 0 0         for(uint16_t i = 0; i < tname->count; i++) {
86 0           lang_record[i].length = myfont_read_u16(&data);
87 0           lang_record[i].offset = myfont_read_u16(&data);
88             }
89            
90 0           tname->langTagRecord = lang_record;
91             }
92            
93 0           return MyFONT_STATUS_OK;
94             }
95