예제 #1
0
파일: head.py 프로젝트: tangjie1992/calibre
    def read_data(self, vmtx):
        if hasattr(self, 'ascender'):
            return
        field_types = (
            '_version_number',
            'l',
            'ascender',
            'h',
            'descender',
            'h',
            'line_gap',
            'h',
            'advance_height_max',
            'H',
            'min_top_side_bearing',
            'h',
            'min_bottom_side_bearing',
            'h',
            'y_max_extent',
            'h',
            'caret_slope_rise',
            'h',
            'caret_slop_run',
            'h',
            'caret_offset',
            'h',
            'r1',
            'h',
            'r2',
            'h',
            'r3',
            'h',
            'r4',
            'h',
            'metric_data_format',
            'h',
            'number_of_v_metrics',
            'H',
        )

        self._fmt = ('>%s' % (''.join(field_types[1::2]))).encode('ascii')
        self._fields = field_types[0::2]

        for f, val in zip(self._fields, unpack_from(self._fmt, self.raw)):
            setattr(self, f, val)

        raw = vmtx.raw
        num = self.number_of_h_metrics
        if len(raw) < 4 * num:
            raise UnsupportedFont('The vmtx table has insufficient data')
        long_hor_metric = raw[:4 * num]
        long_hor_metric = raw[:4 * num]
        a = read_array(long_hor_metric)
        self.advance_heights = a[0::2]
        a = read_array(long_hor_metric, 'h')
        self.top_side_bearings = a[1::2]
예제 #2
0
def read_metrics(raw, num_of_metrics, num_of_glyphs, table_name):
    rawsz = 4 * num_of_metrics
    if len(raw) < rawsz:
        raise UnsupportedFont(f'The {table_name} table has insufficient data')
    long_hor_metric = raw[:rawsz]
    a = read_array(long_hor_metric)
    advances = a[0::2]
    a = read_array(long_hor_metric, 'h')
    bearings = a[1::2]
    if num_of_glyphs > num_of_metrics:
        extra = num_of_glyphs - num_of_metrics
        raw = raw[rawsz:]
        rawsz = 2 * extra
        if len(raw) < rawsz:
            raise UnsupportedFont(f'The {table_name} table has insufficient data for trailing bearings')
        bearings += read_array(raw, 'h')
    return advances, bearings