third_party/modest/source/myfont/vmtx.c

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 54 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« third_party/modest/source/myfont/vhea.c ↑ Summary third_party/modest/source/myhtml/callback.c »
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 ▶ if(mf->cache.tables_offset[MyFONT_TKEY_vmtx] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(mf->cache.tables_offset[MyFONT_TKEY_vmtx] == 0) 0 0 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 ▶ if(num_metrics == 0)
Branch: 1 branch
BranchTrueFalseTotal
if(num_metrics == 0) 0 0 0
38 0 return MyFONT_STATUS_OK;
39
40 0 uint32_t pos = table_offset + (num_metrics * 4);
41 0 ▶ if(pos > data_size)
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) 0 0 0
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 ▶ if(lver_metric == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(lver_metric == NULL) 0 0 0
47 0 return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
48
49 0 ▶ for(uint16_t i = 0; i < num_metrics; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(uint16_t i = 0; i < num_metrics; i++) { 0 0 0
50 0 lver_metric[i].advanceHeight = myfont_read_u16(&data);
51 0 lver_metric[i].topSideBearing = myfont_read_16(&data);
52 }
53
54 0 ▶ if(mf->table_maxp.numGlyphs <= mf->table_vhea.numOfLongVerMetrics) {
Branch: 1 branch
BranchTrueFalseTotal
if(mf->table_maxp.numGlyphs <= mf->table_vhea.numOfLongVerMetrics) { 0 0 0
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 ▶ if(pos > data_size) {
Branch: 1 branch
BranchTrueFalseTotal
if(pos > data_size) { 0 0 0
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 ▶ if(topSideBearing == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(topSideBearing == NULL) { 0 0 0
71 0 myfont_free(mf, lver_metric);
72 0 return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION;
73 }
74
75 0 ▶ for(uint16_t i = 0; i < num_metrics; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(uint16_t i = 0; i < num_metrics; i++) { 0 0 0
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  
« third_party/modest/source/myfont/vhea.c ↑ Summary third_party/modest/source/myhtml/callback.c »