이 번들은 Symfony 프로젝트에서 DOMPDF 라이브러리를 위해 선택한 글꼴을로드/설치하는 간단한 방법을 제공합니다. 이 번들은 캐시 워밍업에서 글꼴 패밀리를 프로그래밍 방식으로 또는 자동으로로드하는 기능을 제공합니다. 이름과 글꼴 파일의 경로로 각 글꼴 패밀리를 지정하거나 번들이 디렉토리의 모든 글꼴을 자동으로 향상시킬 수 있습니다.
composer require jbtronics/dompdf-font-loader-bundleconfig/bundles.php 에서 번들을 활성화하십시오 (일반적으로 Symfony Flex에서 자동으로 수행)config/packages/jbtronics_dompdf_font_loader.yaml 아래에 설명 된 콘텐츠와 함께 (필요에 따라 변경). dompdf_font_loader :
# Set this to true to enable the automatic font loading on cache warmup, without it you have to load the fonts
# manually via the ConfiguredFontsInstaller service
auto_install : true
# You can specify font families here manually
fonts :
my_font : # The name of the font family (used to access it in dompdf later)
# A font family consists of up to four font files (normal, bold, italic, bold_italic)
normal : " %kernel.project_dir%/assets/fonts/my_font.ttf "
bold : " %kernel.project_dir%/assets/fonts/my_font_bold.ttf "
italic : " %kernel.project_dir%/assets/fonts/my_font_italic.ttf "
bold_italic : " %kernel.project_dir%/assets/fonts/my_font_bold_italic.ttf "
# But only the normal font file is required, the others can be omitted
unifont :
normal : " %kernel.project_dir%/assets/fonts/unifont.ttf "
# Autodiscover allows you to specify directories, where all fonts will be loaded automatically
autodiscovery :
# Each of this directory will be scanned for font files
paths :
- " %kernel.project_dir%/assets/fonts "
- " %kernel.project_dir%/vendor/fonts/package/ttfs "
exclude_patterns :
# You can exclude certain patterns from the autodiscovery if you want
- " exclude_this_font.ttf "글꼴과 자동 검색 키는 모두 선택 사항이지만 글꼴을로드하려면 적어도 하나 이상이 필요합니다.
auto_install 옵션을 활성화하면 다른 작업을 수행 할 필요가 없으면 캐시 워밍업에서 글꼴이 자동으로로드됩니다 ( php bin/console cache:clear 가 실행될 때). 번들은 글꼴 파일을 DOMPDF 글꼴 디렉토리에 복사하고 글꼴 메트릭을 만들고 DOMPDF 라이브러리에 등록합니다.
자동 검색 메커니즘은 TTF 파일의 구성 디렉토리를 스캔하여 글꼴 파일 이름을 가진 글꼴 패밀리로 등록합니다. _bold_italic 접미사를 기반 _i 글꼴 _bold 유형을 _bi _italic _b . 따라서 my_font_bold.ttf my_font 제품군의 대담한 글꼴로 등록되며 my_font.ttf my_font 제품군의 정상적인 글꼴로 등록됩니다.
원칙적으로 DOMPDF는 OTF 파일도 사용할 수 있어야하지만 테스트에서는 작동하지 않았으므로 자동 조정은 기본적으로 TTF 파일 만 감지합니다. autodiscovery.file_pattern 옵션을 통해 감지 된 파일 유형을 변경할 수 있습니다.
DOMPDF에는 글꼴 파일과 메트릭을 저장하는 자체 글꼴 디렉토리가 있습니다. 이것은 set_option('fontDir', $path) 메소드를 사용하여 dompdf 객체에서 인스턴스 기준으로 구성됩니다. 이 번들에서 사용하는 dompdf 인스턴스의 글꼴 디렉토리를 지정하려면 DompdfFactoryInterface 장식하고 create() 메소드에서 객체를 구성해야합니다.
#[AsDecorator(decorates: DompdfFactoryInterface::class)]
class MyDompdfFactory implements DompdfFactoryInterface
{
public function create (): Dompdf
{
return new Dompdf ([ ' fontDir ' => ' %kernel.project_dir%/var/dompdf/fonts ' ]);
}
} 이 번들은 FONT 패밀리를 수동으로 설치하는 데 사용할 수있는 DompdfFontLoader 서비스를 제공합니다. installFontFamily() 메소드로 단일 글꼴 패밀리를 설치하거나 autodiscoverAndInstallFonts() 메소드가있는 폴더에 발견 된 모든 글꼴을 설치할 수 있습니다.
이 번들은 MIT 라이센스에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스를 참조하십시오.