Debian Codegraph @

podofo/3rdparty/adobe/afdko/source/cffwrite/cffwrite_varstore.c

raw
1 /* Copyright 2017 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved.
2 This software is licensed as OpenSource, under the Apache License, Version 2.0.
3 This license is available at: http://opensource.org/licenses/Apache-2.0. */
4
5 /*
6 * Dictionary support.
7 */
8
9 #include "ctutil.h"
10 #include "cffwrite_varstore.h"
11 #include "cffwrite_dict.h"
12 #include <stdio.h>
13
14 /* Save byte int in DICT. */
15 void cfwDictSaveByteInt(DICT *dict, long i) {
16 char *arg = dnaEXTEND(*dict, 1);
17 arg[1] = (unsigned char)(i);
18 }
19
20 /* Save short int in DICT. */
21 void cfwDictSaveShortInt(DICT *dict, long i) {
22 char *arg = dnaEXTEND(*dict, 2);
23 arg[0] = (unsigned char)(i >> 8);
24 arg[1] = (unsigned char)i;
25 }
26
27 /* Save long int in DICT. */
28 void cfwDictSaveLongInt(DICT *dict, long i) {
29 char *arg = dnaEXTEND(*dict, 4);
30 arg[0] = (unsigned char)(i >> 24);
31 arg[1] = (unsigned char)(i >> 16);
32 arg[2] = (unsigned char)(i >> 8);
33 arg[3] = (unsigned char)i;
34 }
35
36 unsigned long getRegionListSize(variationRegionList *regionList) {
37 unsigned int size = 4 + regionList->regionCount * regionList->axisCount * 6;
38
39 return size;
40 }
41
42 unsigned long getDataItemSize(itemVariationDataSubtable *ds) {
43 unsigned int size = 6 + ds->regionCount * 2 + ds->itemCount * 2;
44 return size;
45 }
46
47 void writeRegionList(DICT *dst, variationRegionList *regionList) {
48 unsigned short i, j;
49 variationRegion *vr = &(regionList->regions.array[0]);
50 cfwDictSaveShortInt(dst, regionList->axisCount);
51 cfwDictSaveShortInt(dst, regionList->regionCount);
52
53 for (i = 0; i < regionList->regionCount; i++) {
54 for (j = 0; j < regionList->axisCount; j++) {
55 cfwDictSaveShortInt(dst, FIXED_TO_F2DOT14(vr->startCoord));
56 cfwDictSaveShortInt(dst, FIXED_TO_F2DOT14(vr->peakCoord));
57 cfwDictSaveShortInt(dst, FIXED_TO_F2DOT14(vr->endCoord));
58 vr++;
59 }
60 }
61 }
62
63 void writeDataItemList(DICT *dst, itemVariationDataSubtable *ivd) {
64 unsigned short i, cnt;
65 cfwDictSaveShortInt(dst, ivd->itemCount);
66 cfwDictSaveShortInt(dst, 0);
67 cfwDictSaveShortInt(dst, ivd->regionCount);
68
69 cnt = ivd->regionCount;
70 for (i = 0; i < cnt; i++) {
71 cfwDictSaveShortInt(dst, ivd->regionIndices.array[i]);
72 }
73 }
74
75 void cfwDictFillVarStore(cfwCtx g, DICT *dst, abfTopDict *top) {
76 int i;
77 var_itemVariationStore ivs = top->varStore;
78 unsigned long offset;
79
80 // Write place holder for length.
81 cfwDictSaveShortInt(dst, 0);
82
83 // write format
84 cfwDictSaveShortInt(dst, 1);
85
86 // write offset to RegionList.
87 // The Region list immediately follows the IVS header and offset to the dataItems.
88 offset = 8 + ivs->dataList.ivdSubtables.cnt * 4;
89 cfwDictSaveLongInt(dst, offset);
90
91 // write ItemVariationData count
92 cfwDictSaveShortInt(dst, ivs->dataList.ivdSubtables.cnt);
93
94 // write the offsets to the ItemVariationData items.
95 offset += getRegionListSize(&(ivs->regionList));
96 for (i = 0; i < ivs->dataList.ivdSubtables.cnt; i++) {
97 cfwDictSaveLongInt(dst, offset);
98 offset += getDataItemSize(&(ivs->dataList.ivdSubtables.array[i]));
99 }
100
101 writeRegionList(dst, &(ivs->regionList));
102
103 // write the ItemVariationData subtables
104 for (i = 0; i < ivs->dataList.ivdSubtables.cnt; i++) {
105 writeDataItemList(dst, &(ivs->dataList.ivdSubtables.array[i]));
106 }
107
108 // Write length
109 {
110 char *arg = &(dst->array[0]);
111 arg[0] = (unsigned char)(offset >> 8);
112 arg[1] = (unsigned char)offset;
113 }
114 }