Skip to content

Commit 058524e

Browse files
committed
Update Cpdf Surface font selection logic
- handles genrics better - passes the specified font through to Cpdf when a core PDF font match is not made fixes #18
1 parent 7926073 commit 058524e

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

src/Svg/Surface/SurfaceCpdf.php

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -435,51 +435,52 @@ public function setStyle(Style $style)
435435

436436
public function setFont($family, $style, $weight)
437437
{
438-
$map = array(
439-
"serif" => "Times",
440-
"sans-serif" => "Helvetica",
441-
"fantasy" => "Symbol",
442-
"cursive" => "Times",
443-
"monospace" => "Courier",
444-
445-
"arial" => "Helvetica",
446-
"verdana" => "Helvetica",
447-
);
448-
449-
$styleMap = array(
450-
'Helvetica' => array(
451-
'b' => 'Helvetica-Bold',
452-
'i' => 'Helvetica-Oblique',
453-
'bi' => 'Helvetica-BoldOblique',
454-
),
455-
'Courier' => array(
456-
'b' => 'Courier-Bold',
457-
'i' => 'Courier-Oblique',
458-
'bi' => 'Courier-BoldOblique',
459-
),
460-
'Times' => array(
461-
'' => 'Times-Roman',
462-
'b' => 'Times-Bold',
463-
'i' => 'Times-Italic',
464-
'bi' => 'Times-BoldItalic',
465-
),
466-
);
467-
468-
$family = strtolower($family);
469-
$style = strtolower($style);
470-
$weight = strtolower($weight);
471-
472-
if (isset($map[$family])) {
473-
$family = $map[$family];
438+
$map = [
439+
"serif" => "times",
440+
"sans-serif" => "helvetica",
441+
"fantasy" => "symbol",
442+
"cursive" => "times",
443+
"monospace" => "courier"
444+
];
445+
446+
$styleMap = [
447+
"courier" => [
448+
"" => "Courier",
449+
"b" => "Courier-Bold",
450+
"i" => "Courier-Oblique",
451+
"bi" => "Courier-BoldOblique",
452+
],
453+
"helvetica" => [
454+
"" => "Helvetica",
455+
"b" => "Helvetica-Bold",
456+
"i" => "Helvetica-Oblique",
457+
"bi" => "Helvetica-BoldOblique",
458+
],
459+
"symbol" => [
460+
"" => "Symbol"
461+
],
462+
"times" => [
463+
"" => "Times-Roman",
464+
"b" => "Times-Bold",
465+
"i" => "Times-Italic",
466+
"bi" => "Times-BoldItalic",
467+
],
468+
];
469+
470+
$family_lc = strtolower($family);
471+
if (isset($map[$family_lc])) {
472+
$family = $map[$family_lc];
474473
}
475474

476475
if (isset($styleMap[$family])) {
477476
$key = "";
478477

478+
$weight = strtolower($weight);
479479
if ($weight === "bold" || $weight === "bolder" || (is_numeric($weight) && $weight >= 600)) {
480480
$key .= "b";
481481
}
482482

483+
$style = strtolower($style);
483484
if ($style === "italic" || $style === "oblique") {
484485
$key .= "i";
485486
}

0 commit comments

Comments
 (0)