File Coverage

third_party/modest/source/myfont/hmtx.c
Criterion Covered Total %
statement 0 21 0.0
branch 0 10 0.0
condition n/a
subroutine n/a
pod n/a
total 0 31 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/hmtx.h"
22              
23 0           mystatus_t myfont_load_table_hmtx(myfont_font_t* mf, uint8_t* font_data, size_t data_size)
24             {
25 0           memset(&mf->table_hmtx, 0, sizeof(myfont_table_hmtx_t));
26            
27 0 0         if(mf->cache.tables_offset[MyFONT_TKEY_hmtx] == 0)
28 0           return MyFONT_STATUS_OK;
29            
30 0           myfont_table_hmtx_t *thmtx = &mf->table_hmtx;
31 0           const uint32_t table_offset = mf->cache.tables_offset[MyFONT_TKEY_hmtx];
32            
33             /* get current data */
34 0           uint8_t *data = &font_data[table_offset];
35 0           uint16_t num_metrics = mf->table_hhea.numberOfHMetrics;
36            
37 0 0         if(num_metrics == 0)
38 0           return MyFONT_STATUS_OK;
39            
40 0 0         if(data_size < (table_offset + (num_metrics * 2)))
41 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
42            
43 0           myfont_long_hor_metric_t *lhor_metric = (myfont_long_hor_metric_t *)myfont_calloc(mf, num_metrics, sizeof(myfont_long_hor_metric_t));
44            
45 0 0         if(lhor_metric == NULL)
46 0           return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
47            
48 0 0         for(uint16_t i = 0; i < num_metrics; i++) {
49 0           lhor_metric[i].advanceWidth = myfont_read_u16(&data);
50 0           lhor_metric[i].lsb = myfont_read_16(&data);
51             }
52            
53 0           thmtx->hMetrics = lhor_metric;
54 0           thmtx->leftSideBearing = NULL;
55            
56 0           return MyFONT_STATUS_OK;
57             }
58