2 Port from c++ is protected by a GNU Lesser GPLv3
3 Copyright © 2013 Sylvain BERTRAND <sylvain.bertrand@gmail.com>
13 #include "hb-private.h"
14 #include "hb-open-file-private.h"
16 static struct ot_fnt_face
*ttc_hdr_ver1_get_face(struct ttc_hdr_ver1
17 *ttc_hdr_ver1
, unsigned i
)
20 uint8_t *base
; /*the beginning of the file */
25 of
= be32toh(ttc_hdr_ver1
->of_tbls_ofs
[i
]);
26 base
= (uint8_t *) ttc_hdr_ver1
;
27 return (struct ot_fnt_face
*)(base
+ of
);
30 static struct ot_fnt_face
*ttc_hdr_get_face(struct ttc_hdr
*ttc_hdr
, unsigned i
)
35 switch (ttc_hdr
->u
.hdr
.ver
.major
) {
36 case 2: /*version 2 is compatible with version 1 */
38 return ttc_hdr_ver1_get_face(&ttc_hdr
->u
.ver1
, i
);
44 struct ot_fnt_face
*ot_fnt_file_get_face(struct ot_fnt_file
*ot_fnt_file
,
52 tag
= be32toh(ot_fnt_file
->u
.tag
);
55 /*Note: for non-collection SFNT data we ignore index. This is because
56 Apple dfont container is a container of SFNT's. So each SFNT is a
57 non-TTC, but the index is more than zero. */
58 case CFF_TAG
: /*All the non-collection tags */
62 return &ot_fnt_file
->u
.fnt_face
;
64 return ttc_hdr_get_face(&ot_fnt_file
->u
.ttc_hdr
, i
);
70 static struct tbl_rec
*ot_fnt_face_get_tbl(struct ot_fnt_face
*ot_fnt_face
,
73 /*XXX:check is useless in known code paths */
77 if (i
>= ot_fnt_face
->tbls_n
)
78 return NULL
; /*XXX:original code use a "null" object */
79 return &ot_fnt_face
->tbls
[i
];
82 static hb_bool_t
ot_fnt_face_find_tbl_idx(struct ot_fnt_face
*ot_fnt_face
,
83 hb_tag_t tag
, unsigned *tbl_idx
)
88 /*XXX:check is useless in known code paths */
92 cnt
= ot_fnt_face
->tbls_n
;
93 for (i
= 0; i
< cnt
; ++i
) {
96 tbl_tag
= be32toh(ot_fnt_face
->tbls
[i
].tag
);
104 *tbl_idx
= IDX_NOT_FOUND
;
108 struct tbl_rec
*ot_fnt_face_get_tbl_by_tag(struct ot_fnt_face
*ot_fnt_face
,
116 ot_fnt_face_find_tbl_idx(ot_fnt_face
, tag
, &tbl_idx
);
117 return ot_fnt_face_get_tbl(ot_fnt_face
, tbl_idx
);