dompdf / php-svg-lib

SVG file parsing / rendering library
GNU Lesser General Public License v3.0
1.4k stars 77 forks source link

Using custom fonts #42

Closed javfres closed 2 years ago

javfres commented 6 years ago

I am trying to generate a pdf with dompdf that contains a svg with custom fonts and I was unable to do it. I had to do a fork of the repository with a hack. I suppose this is related with #18.

I think that the SurfaceCpdf@setFont method is calling $this->canvas->selectFont without the full path of the font directory. I end up replacing that method with something similar as:

public function setFont($family, $style, $weight){
    $family = strtolower($family);
    // Am I allowed to access canvas fonts this way????
    foreach($this->canvas->fonts as $font => $data){
        $font_family = strtolower($data['FontName']);
        if($font_family === $family) $this->canvas->selectFont($font);
    }
}

This sets the actual font but things like font subsetting doesn't work.

bsweeney commented 2 years ago

I think this probably is related to 18 so we'll address related to that ticket.

FYI, the version of the Cpdf library in use right now doesn't support font subsetting. I'm thinking we'll unify the Cpdf library (also used by Dompdf) into it's own project and add as a dependency. Supporting font subsetting will require a further dependency on php-font-lib. Until font subsetting support is available you can create your own subsets using php-font-lib (if it's important to your project).