def get_font_features(font_kerning='normal', font_variant_ligatures=
    'normal', font_variant_position='normal', font_variant_caps='normal',
    font_variant_numeric='normal', font_variant_alternates='normal',
    font_variant_east_asian='normal', font_feature_settings='normal'):
    """Get the font features from the different properties in style.

    See https://www.w3.org/TR/css-fonts-3/#feature-precedence

    """
    features = {}
    ligature_keys = {'common-ligatures': ['liga', 'clig'],
        'historical-ligatures': ['hlig'], 'discretionary-ligatures': [
        'dlig'], 'contextual': ['calt']}
    caps_keys = {'small-caps': ['smcp'], 'all-small-caps': ['c2sc', 'smcp'],
        'petite-caps': ['pcap'], 'all-petite-caps': ['c2pc', 'pcap'],
        'unicase': ['unic'], 'titling-caps': ['titl']}
    numeric_keys = {'lining-nums': 'lnum', 'oldstyle-nums': 'onum',
        'proportional-nums': 'pnum', 'tabular-nums': 'tnum',
        'diagonal-fractions': 'frac', 'stacked-fractions': 'afrc',
        'ordinal': 'ordn', 'slashed-zero': 'zero'}
    east_asian_keys = {'jis78': 'jp78', 'jis83': 'jp83', 'jis90': 'jp90',
        'jis04': 'jp04', 'simplified': 'smpl', 'traditional': 'trad',
        'full-width': 'fwid', 'proportional-width': 'pwid', 'ruby': 'ruby'}
    if font_kerning != 'auto':
        features['kern'] = int(font_kerning == 'normal')
    if font_variant_ligatures == 'none':
        for keys in ligature_keys.values():
            for key in keys:
                features[key] = 0
    elif font_variant_ligatures != 'normal':
        for ligature_type in font_variant_ligatures:
            value = 1
            if ligature_type.startswith('no-'):
                value = 0
                ligature_type = ligature_type[3:]
            for key in ligature_keys[ligature_type]:
                features[key] = value
    if font_variant_position == 'sub':
        features['subs'] = 1
    elif font_variant_position == 'super':
        features['sups'] = 1
    if font_variant_caps != 'normal':
        for key in caps_keys[font_variant_caps]:
            features[key] = 1
    if font_variant_numeric != 'normal':
        for key in font_variant_numeric:
            features[numeric_keys[key]] = 1
    if font_variant_alternates != 'normal':
        if font_variant_alternates == 'historical-forms':
            features['hist'] = 1
    if font_variant_east_asian != 'normal':
        for key in font_variant_east_asian:
            features[east_asian_keys[key]] = 1
    if font_feature_settings != 'normal':
        features.update(dict(font_feature_settings))
    return features
