Merge pull request #1577 from mailpoet/fonts
adding custom fonts [MAILPOET-1493]
This commit is contained in:
@@ -50,10 +50,12 @@ class Renderer {
|
||||
$content = $this->preProcessALC($content);
|
||||
$rendered_body = $this->renderBody($content);
|
||||
$rendered_styles = $this->renderStyles($styles);
|
||||
$custom_fonts_links = StylesHelper::getCustomFontsLinks($styles);
|
||||
|
||||
$template = $this->injectContentIntoTemplate($this->template, array(
|
||||
htmlspecialchars($newsletter['subject']),
|
||||
$rendered_styles,
|
||||
$custom_fonts_links,
|
||||
$newsletter['preheader'],
|
||||
$rendered_body
|
||||
));
|
||||
|
@@ -2,7 +2,7 @@
|
||||
namespace MailPoet\Newsletter\Renderer;
|
||||
|
||||
class StylesHelper {
|
||||
static $css_attributes = array(
|
||||
static $css_attributes = [
|
||||
'backgroundColor' => 'background-color',
|
||||
'fontColor' => 'color',
|
||||
'fontFamily' => 'font-family',
|
||||
@@ -14,9 +14,9 @@ class StylesHelper {
|
||||
'borderStyle' => 'border-style',
|
||||
'borderColor' => 'border-color',
|
||||
'borderRadius' => 'border-radius',
|
||||
'lineHeight' => 'line-height'
|
||||
);
|
||||
static $font = array(
|
||||
'lineHeight' => 'line-height',
|
||||
];
|
||||
static $font = [
|
||||
'Arial' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
||||
'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif",
|
||||
'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace",
|
||||
@@ -25,8 +25,30 @@ class StylesHelper {
|
||||
'Tahoma' => 'Tahoma, Verdana, Segoe, sans-serif',
|
||||
'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif",
|
||||
'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
|
||||
'Verdana' => 'Verdana, Geneva, sans-serif'
|
||||
);
|
||||
'Verdana' => 'Verdana, Geneva, sans-serif',
|
||||
'Arvo' => 'arvo, courier, georgia, serif',
|
||||
'Lato' => "lato, 'helvetica neue', helvetica, arial, sans-serif",
|
||||
'Lora' => "lora, georgia, 'times new roman', serif",
|
||||
'Merriweather' => "merriweather, georgia, 'times new roman', serif",
|
||||
'Merriweather Sans' => "'merriweather sans', 'helvetica neue', helvetica, arial, sans-serif",
|
||||
'Noticia Text' => "'noticia text', georgia, 'times new roman', serif",
|
||||
'Open Sans' => "'open sans', 'helvetica neue', helvetica, arial, sans-serif",
|
||||
'Playfair Display' => "'playfair display', georgia, 'times new roman', serif",
|
||||
'Roboto' => "roboto, 'helvetica neue', helvetica, arial, sans-serif",
|
||||
'Source Sans Pro' => "'source sans pro', 'helvetica neue', helvetica, arial, sans-serif",
|
||||
];
|
||||
static $custom_fonts = [
|
||||
'Arvo',
|
||||
'Lato',
|
||||
'Lora',
|
||||
'Merriweather',
|
||||
'Merriweather Sans',
|
||||
'Noticia Text',
|
||||
'Open Sans',
|
||||
'Playfair Display',
|
||||
'Roboto',
|
||||
'Source Sans Pro',
|
||||
];
|
||||
static $line_height_multiplier = 1.6;
|
||||
static $heading_margin_multiplier = 0.3;
|
||||
static $padding_width = 20;
|
||||
@@ -102,4 +124,27 @@ class StylesHelper {
|
||||
$style['lineHeight'] = sprintf('%spx', self::$line_height_multiplier * $font_size);
|
||||
return $style;
|
||||
}
|
||||
|
||||
private static function getCustomFontsNames($styles) {
|
||||
$font_names = [];
|
||||
foreach($styles as $style) {
|
||||
if(isset($style['fontFamily']) && in_array($style['fontFamily'], self::$custom_fonts)) {
|
||||
$font_names[$style['fontFamily']] = true;
|
||||
}
|
||||
}
|
||||
return array_keys($font_names);
|
||||
}
|
||||
|
||||
static function getCustomFontsLinks($styles) {
|
||||
$links = [];
|
||||
foreach(self::getCustomFontsNames($styles) as $name) {
|
||||
$links[] = urlencode($name) . ':400,400i,700,700i';
|
||||
}
|
||||
if(!count($links)) {
|
||||
return '';
|
||||
}
|
||||
return '<!--[if !mso]><link href="https://fonts.googleapis.com/css?family='
|
||||
. implode("|", $links)
|
||||
. '" rel="stylesheet"><![endif]-->';
|
||||
}
|
||||
}
|
@@ -78,6 +78,7 @@
|
||||
}
|
||||
{{newsletter_styles}}
|
||||
</style>
|
||||
{{newsletter_custom_fonts}}
|
||||
</head>
|
||||
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
|
||||
<table class="mailpoet_template" border="0" width="100%" cellpadding="0" cellspacing="0"
|
||||
|
Reference in New Issue
Block a user