File Coverage

third_party/modest/source/myfont/vmtx.c
Criterion Covered Total %
statement 0 36 0.0
branch 0 18 0.0
condition n/a
subroutine n/a
pod n/a
total 0 54 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/vmtx.h"
22              
23 0           mystatus_t myfont_load_table_vmtx(myfont_font_t* mf, uint8_t* font_data, size_t data_size)
24             {
25 0           memset(&mf->table_vmtx, 0, sizeof(myfont_table_vmtx_t));
26            
27 0 0         if(mf->cache.tables_offset[MyFONT_TKEY_vmtx] == 0)
28 0           return MyFONT_STATUS_OK;
29            
30 0           myfont_table_vmtx_t *tvmtx = &mf->table_vmtx;
31 0           const uint32_t table_offset = mf->cache.tables_offset[MyFONT_TKEY_vmtx];
32            
33             /* get current data */
34 0           uint8_t *data = &font_data[table_offset];
35 0           uint16_t num_metrics = mf->table_vhea.numOfLongVerMetrics;
36            
37 0 0         if(num_metrics == 0)
38 0           return MyFONT_STATUS_OK;
39            
40 0           uint32_t pos = table_offset + (num_metrics * 4);
41 0 0         if(pos > data_size)
42 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
43            
44 0           myfont_long_ver_metric_t *lver_metric = (myfont_long_ver_metric_t *)myfont_calloc(mf, num_metrics, sizeof(myfont_long_ver_metric_t));
45            
46 0 0         if(lver_metric == NULL)
47 0           return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
48            
49 0 0         for(uint16_t i = 0; i < num_metrics; i++) {
50 0           lver_metric[i].advanceHeight = myfont_read_u16(&data);
51 0           lver_metric[i].topSideBearing = myfont_read_16(&data);
52             }
53            
54 0 0         if(mf->table_maxp.numGlyphs <= mf->table_vhea.numOfLongVerMetrics) {
55 0           myfont_free(mf, lver_metric);
56 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
57             }
58            
59 0           uint16_t numOfTSB = mf->table_maxp.numGlyphs - mf->table_vhea.numOfLongVerMetrics;
60            
61 0           pos = pos + (numOfTSB * 2);
62            
63 0 0         if(pos > data_size) {
64 0           myfont_free(mf, lver_metric);
65 0           return MyFONT_STATUS_ERROR_TABLE_UNEXPECTED_ENDING;
66             }
67            
68 0           int16_t *topSideBearing = (int16_t *)myfont_calloc(mf, numOfTSB, sizeof(int16_t));
69            
70 0 0         if(topSideBearing == NULL) {
71 0           myfont_free(mf, lver_metric);
72 0           return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
73             }
74            
75 0 0         for(uint16_t i = 0; i < num_metrics; i++) {
76 0           topSideBearing[i] = myfont_read_16(&data);
77             }
78            
79 0           tvmtx->vMetrics = lver_metric;
80 0           tvmtx->topSideBearing = topSideBearing;
81            
82 0           return MyFONT_STATUS_OK;
83             }
84              
85