FontOperationTrait.php in Image Effects 8        
                          
                  
                        
  
  
  
  
File
  src/Plugin/ImageToolkit/Operation/FontOperationTrait.php
  
    View source  
  <?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation;
use Drupal\Core\StreamWrapper\LocalStream;
trait FontOperationTrait {
  
  protected $streamWrapperManagerForFontHandling;
  
  protected static $fontPaths = [];
  
  protected function getRealFontPath($uri) {
    $uri_wrapper = $this
      ->getStreamWrapperManagerForFontHandling()
      ->getViaUri($uri);
    if ($uri_wrapper instanceof LocalStream) {
      return $uri_wrapper
        ->realpath();
    }
    else {
      return is_file($uri) ? $uri : NULL;
    }
  }
  
  protected function getFontPath($font_uri) {
    if (!$font_uri) {
      throw new \InvalidArgumentException('Font file not specified');
    }
    if (!isset(static::$fontPaths[$font_uri])) {
      if (!($ret = $this
        ->getRealFontPath($font_uri))) {
        throw new \InvalidArgumentException("Could not find the font file {$font_uri}");
      }
      static::$fontPaths[$font_uri] = $ret;
    }
    return static::$fontPaths[$font_uri];
  }
  
  protected function getStreamWrapperManagerForFontHandling() {
    if (!$this->streamWrapperManagerForFontHandling) {
      $this->streamWrapperManagerForFontHandling = \Drupal::service('stream_wrapper_manager');
    }
    return $this->streamWrapperManagerForFontHandling;
  }
}