You are here

protected function Font::doGetMetadataFromFile in File metadata manager 8

Same name and namespace in other branches
  1. 8.2 file_mdm_font/src/Plugin/FileMetadata/Font.php \Drupal\file_mdm_font\Plugin\FileMetadata\Font::doGetMetadataFromFile()

Gets file metadata from the file at URI/local path.

Return value

mixed The metadata retrieved from the file.

Throws

\Drupal\file_mdm\FileMetadataException In case there were significant errors reading from file.

Overrides FileMetadataPluginBase::doGetMetadataFromFile

File

file_mdm_font/src/Plugin/FileMetadata/Font.php, line 33

Class

Font
FileMetadata plugin for TTF/OTF/WOFF font information.

Namespace

Drupal\file_mdm_font\Plugin\FileMetadata

Code

protected function doGetMetadataFromFile() {
  $font = LibFont::load($this
    ->getLocalTempPath());

  // @todo ::parse raises 'Undefined offset' notices in phenx/php-font-lib
  // 0.5, suppress errors while upstream is fixed.
  @$font
    ->parse();
  $keys = $this
    ->getSupportedKeys();
  $metadata = [];
  foreach ($keys as $key) {
    $l_key = strtolower($key);
    switch ($l_key) {
      case 'fonttype':
        $metadata[$l_key] = $font
          ->getFontType();
        break;
      case 'fontweight':
        $metadata[$l_key] = $font
          ->getFontWeight();
        break;
      default:
        $code = array_search($l_key, array_map('strtolower', name::$nameIdCodes), TRUE);
        if ($value = $font
          ->getNameTableString($code)) {
          $metadata[$l_key] = $value;
        }
        break;
    }
  }
  return $metadata;
}