@import "variables";

$font-types: (
  "eot":   "embedded-opentype",
  "woff2": "woff2",
  "woff":  "woff",
  "ttf":   "truetype",
  "otf":   "opentype"
);

@mixin font-face($font-family, $postfix, $types) {
  $font-name: 'material-icons';
  $base-name: $md-prefix;

  @if $postfix != null {
    $font-name: $font-name + '-' + $postfix;
    $base-name: $base-name + '-' + $postfix;
  }

  $url: '#{$md-font-path}/#{$font-name}';
  $src: ();

  @each $type in $types {
    $fix: '';
    @if $type == 'eot' {
      $fix: '#iefix';
    }
    $format: map_get($font-types, $type);
    $font: url('#{$url}.#{$type}#{$fix}') format($format);
    $src: append($src, $font, comma);
  }

  @font-face {
    font-family: $font-family;
    font-style: normal;
    font-weight: 400;
    @if null != index($types, eot) {
      src: url('#{$url}.eot');
    }
    src: $src;
  }
}


@mixin font-classes($font-families) {
  $all-classes: ();
  $ligatures: ();

  @each $font-family in map_keys($font-families) {
    $postfix: map_get($font-families, $font-family);
    $font-name: 'material-icons';
    $base-name: $md-prefix;

    @if $postfix != null {
      $font-name: $font-name + '-' + $postfix;
      $base-name: $base-name + '-' + $postfix;
    }

    .#{$base-name}, .#{$font-name} {
      font: normal normal normal #{$md-font-size}/1 $font-family;
    }

    $all-classes: append($all-classes, (".#{$base-name}", ".#{$font-name}"), comma);
    $ligatures: append($ligatures, ".#{$font-name}", comma);
  }

  #{$all-classes} {
    font-size: inherit;
    display: inline-block;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1;
    position: relative;
    white-space: nowrap;
    word-wrap: normal;
    top: 1px;
    /* Support for all WebKit browsers. */
    -webkit-font-smoothing: antialiased;
    /* Support for Firefox. */
    -moz-osx-font-smoothing: grayscale;
    transform: translate(0, 0); // ensures no half-pixel rendering in firefox
  }

  #{$ligatures} {
    width: 1em;
    height: 1em;
    font-feature-settings: 'liga';
  }
}
