1<?php 2 3namespace ComboStrap; 4 5/** 6 * Utility font class 7 * 8 * 9 * Font Library to get info on font 10 * https://github.com/dompdf/php-font-lib 11 * 12 * Linux: 13 * * Conf file: `/etc/fonts/fonts.conf` 14 * * Command: `fc-list` command 15 * * font for a language: `fc-list :lang=fr` 16 * * font family name: `fc-list : family | sort | uniq` 17 * 18 * Windows: 19 * * Location: 'c:\windows\fonts' 20 * 21 */ 22class Font 23{ 24 25 26 /** 27 * There is no default system font 28 * This function will return a sort of default font 29 * for the operating system 30 * @return LocalPath 31 */ 32 static public function getSystemFont(): LocalPath 33 { 34 if (Os::isWindows()) { 35 return self::getWindowsFontDirectory()->resolve('Arial.ttf'); 36 } else { 37 return LocalPath::createFromPathString('/usr/share/fonts/liberation/LiberationSans-Regular.ttf'); 38 } 39 } 40 41 /** 42 * @return LocalPath - the font locale path 43 * https://github.com/liberationfonts/liberation-fonts/releases 44 */ 45 static public function getLiberationSansFontRegularPath(): LocalPath 46 { 47 return WikiPath::createComboResource(":fonts:LiberationSans-Regular.ttf")->toLocalPath(); 48 } 49 50 static public function getLiberationSansFontBoldPath(): LocalPath 51 { 52 return WikiPath::createComboResource(":fonts:LiberationSans-Bold.ttf")->toLocalPath(); 53 } 54 55 static public function printWindowsTrueTypeFont() 56 { 57 $path = self::getWindowsFontDirectory(); 58 foreach (FileSystems::getChildrenLeaf($path) as $path) { 59 $extension = strtolower($path->getExtension()); 60 if ($extension === "ttf") { 61 echo $path->toAbsoluteId() . "\n"; 62 } 63 } 64 } 65 66 public static function getWindowsFontDirectory(): LocalPath 67 { 68 return LocalPath::createFromPathString('c:\windows\fonts'); 69 } 70} 71