Commit d61b9487 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1843202: Allow theme fonts to be included in skin_fonts table



So that they can be
- used in skins
- viewed on the Admin -> Config -> Fonts page

behatnotneeded

Change-Id: I49aff91a7f56a003adbc9f3513aa9a094a3069e4
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 6f955958
......@@ -32,7 +32,12 @@ if (!empty($font)) {
$fontdata = get_record('skin_fonts', 'name', $font);
$fonttitle = $fontdata->title;
if (!empty($fontdata->licence) && !is_null($fontdata->licence)) {
if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
$fontpath = get_config('wwwroot') . 'theme/' . $matches[1] . '/fonts/' . strtolower($fontdata->name) . '/';
}
else {
$fontpath = get_config('wwwroot') . 'skins/fonts/' . $fontdata->name . '/';
}
$fontlicence = '<a href="' . $fontpath . $fontdata->licence . '">' . get_string('fontlicence', 'skin') . '</a>';
}
else {
......
......@@ -83,6 +83,7 @@ $previewform = pieform(array(
'all' => get_string('fonttypes.all', 'skin'),
'site' => get_string('fonttypes.site', 'skin'),
'google' => get_string('fonttypes.google', 'skin'),
'theme' => get_string('fonttypes.theme', 'skin'),
),
'defaultvalue' => $fonttype,
),
......@@ -105,7 +106,7 @@ $data = Skin::get_sitefonts_data($limit, $offset, $fonttype);
$sitefonts = '';
$googlefonts = '';
foreach ($data->data as $font) {
if ($font['fonttype'] == 'site') {
if ($font['fonttype'] == 'site' || preg_match('/^t_/', $font['fonttype'])) {
$sitefonts .= $font['title'] . '|';
}
if ($font['fonttype'] == 'google') {
......
......@@ -243,6 +243,11 @@ $string['fonttype.site'] = 'Local font';
$string['fonttypes.site'] = 'Local fonts';
$string['fonttype.google'] = 'Google web font';
$string['fonttypes.google'] = 'Google web fonts';
$string['fonttypes.theme'] = 'Theme fonts';
$string['fonttype.t_raw'] = 'Theme font: Raw';
$string['fonttype.t_ocean'] = 'Theme font: Ocean';
$string['fonttype.t_modern'] = 'Theme font: Modern';
$string['fonttype.t_primaryschool'] = 'Theme font: Primary school';
// For examples of pangrams, see: http://en.wikipedia.org/wiki/List_of_pangrams
$string['preview'] = 'Preview';
......
......@@ -1169,7 +1169,7 @@
<FIELD NAME="notice" TYPE="text" NOTNULL="false" />
<FIELD NAME="previewfont" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="variants" TYPE="text" LENGTH="big" NOTNULL="true" />
<FIELD NAME="fonttype" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="site" />
<FIELD NAME="fonttype" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="site" />
<FIELD NAME="onlyheading" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="fontstack" TYPE="text" NOTNULL="true" />
<FIELD NAME="genericfont" TYPE="char" LENGTH="10" NOTNULL="true" ENUM="true" ENUMVALUES="'cursive', 'fantasy', 'monospace', 'sans-serif', 'serif'" />
......
......@@ -1447,5 +1447,17 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2019090900) {
log_debug('Update the skin_fonts to know about the theme fonts also');
require_once(get_config('libroot') . 'skin.php');
$table = new XMLDBTable('skin_fonts');
if (table_exists($table)) {
$field = new XMLDBField('fonttype');
$field->setAttributes(XMLDB_TYPE_CHAR, 30, null, XMLDB_NOTNULL, null, null, null, 'site');
change_field_precision($table, $field);
install_skins_default();
}
}
return $status;
}
......@@ -615,8 +615,22 @@ class Skin {
return '';
}
$fontface = '';
if ($fontdata->fonttype == 'site') {
if (preg_match('/^t_(.*)/', $fontdata->fonttype, $matches)) {
$theme = $matches[1];
$fontfamily = urlencode($fontdata->title);
// We need to create @font-face css rule for each variant of the font
$variants = unserialize($fontdata->variants);
foreach ($variants as $variant) {
$baseurl = get_config('wwwroot') . 'theme/' . $theme . '/fonts/' . strtolower($fontdata->name) . '/';
$fontface .= '@font-face {';
$fontface .= 'font-family: \'' . escape_css_string($fontdata->title) . '\'; ';
$fontface .= 'src: url(\'' . $baseurl . $variant['WOFF'] . '\') format(\'woff\'); '; // The only type that is crossbrowser compatible
$fontface .= 'font-weight: ' . $variant['font-weight'] . '; ';
$fontface .= 'font-style: ' . $variant['font-style'] . '; ';
$fontface .= '}';
}
}
else if ($fontdata->fonttype == 'site') {
$fontfamily = urlencode($fontdata->title);
// We need to create @font-face css rule for each variant of the font
$variants = unserialize($fontdata->variants);
......@@ -1091,7 +1105,14 @@ class Skin {
*/
public static function get_sitefonts_data($limit=9, $offset=0, $fonttype='site') {
if ($fonttype != 'all') {
if ($fonttype == 'theme') {
$count = count_records_sql('
SELECT COUNT(f.name) FROM {skin_fonts} f
WHERE f.fonttype LIKE ?', array('t_%'));
$fontdata = get_records_sql_array('
SELECT * FROM {skin_fonts} WHERE fonttype LIKE ? ORDER BY fonttype', array('t_%'), $offset, $limit);
}
else if ($fonttype != 'all') {
$count = count_records_sql('
SELECT COUNT(f.name) FROM {skin_fonts} f
WHERE f.fonttype = ?', array($fonttype));
......@@ -1261,159 +1282,378 @@ class Skin {
/**
* Installs default skin data, called during Mahara installation
* Installs default skin data.
* This function is now designed so that it can be run more than once.
* To add more fonts set up the "ensure_record_exists( ... )" blocks for them
* To remove a font set up a "delete_record( ... )" for it
*/
function install_skins_default() {
// Add data for 'common' fonts...
$variants = serialize(array(
array('variant' => 'regular', 'font-weight' => 'normal', 'font-style' => 'normal'),
array('variant' => 'bold', 'font-weight' => 'bold', 'font-style' => 'normal'),
array('variant' => 'italic', 'font-weight' => 'normal', 'font-style' => 'italic'),
array('variant' => 'bolditalic', 'font-weight' => 'bold', 'font-style' => 'italic'),
));
$italiconly = serialize(array(
array('variant' => 'italic', 'font-weight' => 'normal', 'font-style' => 'italic'),
));
insert_record('skin_fonts', (object) array(
// Add data for the 'common' and theme fonts.
// Set up the possible variations
// - add in new ones if needed
$fv = array(
'regular' => array('variant' => 'regular', 'font-weight' => 'normal', 'font-style' => 'normal'),
'bold' => array('variant' => 'bold', 'font-weight' => 'bold', 'font-style' => 'normal'),
'italic' => array('variant' => 'italic', 'font-weight' => 'normal', 'font-style' => 'italic'),
'bolditalic' => array('variant' => 'bolditalic', 'font-weight' => 'bold', 'font-style' => 'italic'),
'thin' => array('variant' => 'thin', 'font-weight' => 'normal', 'font-style' => 'normal'),
'light' => array('variant' => 'light', 'font-weight' => 'lighter', 'font-style' => 'normal'),
'lightitalic' => array('variant' => 'light', 'font-weight' => 'lighter', 'font-style' => 'italic'),
);
// The basic regular/bold/italic/bolditalic combo
$basicvariants = serialize(array($fv['regular'], $fv['bold'], $fv['italic'], $fv['bolditalic']));
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Arial',
'title' => 'Arial'
),
(object) array(
'name' => 'Arial',
'title' => 'Arial',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'NimbusSansL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Arial\', \'Helvetica\', \'Nimbus Sans L\', \'FreeSans\'',
'genericfont' => 'sans-serif'
));
insert_record('skin_fonts', (object) array(
'name' => 'Book_Antiqua',
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'BookAntiqua',
'title' => 'Book Antiqua'
),
(object) array(
'name' => 'BookAntiqua',
'title' => 'Book Antiqua',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'URWPalladioL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Book Antiqua\', \'Palatino Linotype\', \'Palatino\', \'URW Palladio L\'',
'genericfont' => 'serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Bookman',
'title' => 'Bookman'
),
(object) array(
'name' => 'Bookman',
'title' => 'Bookman',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'URWBookmanL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Bookman Old Style\', \'Bookman\', \'URW Bookman L\'',
'genericfont' => 'serif'));
insert_record('skin_fonts', (object) array(
'genericfont' => 'serif'
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Chancery',
'title' => 'Chancery'
),
(object) array(
'name' => 'Chancery',
'title' => 'Chancery',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'URWChanceryL.ttf',
'variants' => $italiconly,
'variants' => serialize(array($fv['italic'])),
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Monotype Corsiva\', \'Apple Chancery\', \'Zapf Chancery\', \'URW Chancery L\'',
'genericfont' => 'cursive'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Courier',
'title' => 'Courier New'
),
(object) array(
'name' => 'Courier',
'title' => 'Courier New',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'NimbusMonoL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Courier New\', \'Courier\', \'Nimbus Mono L\', \'FreeMono\'',
'genericfont' => 'monospace'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Georgia',
'title' => 'Georgia'
),
(object) array(
'name' => 'Georgia',
'title' => 'Georgia',
'licence' => 'Charis SIL Open Font Licence.txt',
'previewfont' => 'CharisSILR.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Georgia\', \'Charis SIL\'',
'genericfont' => 'serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Gothic',
'title' => 'Century Gothic'
),
(object) array(
'name' => 'Gothic',
'title' => 'Century Gothic',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'URWGothicL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Century Gothic\', \'Avant Garde\', \'URW Gothic L\'',
'genericfont' => 'sans-serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Helvetica',
'title' => 'Helvetica'
),
(object) array(
'name' => 'Helvetica',
'title' => 'Helvetica',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'NimbusSansL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Helvetica\', \'Arial\', \'Nimbus Sans L\', \'FreeSans\'',
'genericfont' => 'sans-serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Palatino',
'title' => 'Palatino'
),
(object) array(
'name' => 'Palatino',
'title' => 'Palatino',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'URWPalladioL.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Palatino Linotype\', \'Palatino\', \'URW Palladio L\', \'Book Antiqua\'',
'genericfont' => 'serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Tahoma',
'title' => 'Tahoma'
),
(object) array(
'name' => 'Tahoma',
'title' => 'Tahoma',
'licence' => 'DejaVu Font Licence.txt',
'previewfont' => 'DejaVuSans.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Tahoma\', \'DejaVu Sans\'',
'genericfont' => 'sans-serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Times',
'title' => 'Times New Roman'
),
(object) array(
'name' => 'Times',
'title' => 'Times New Roman',
'licence' => 'GPL-2.0.txt',
'previewfont' => 'NimbusRomanNo9L.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Times New Roman\', \'Times\', \'Nimbus Roman No9\', \'FreeSerif\'',
'genericfont' => 'serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Trebuchet',
'title' => 'Trebuchet'
),
(object) array(
'name' => 'Trebuchet',
'title' => 'Trebuchet',
'licence' => 'Aurulent Open Font Licence.txt',
'previewfont' => 'AurulentSans.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Trebuchet MS\', \'Aurulent Sans\'',
'genericfont' => 'sans-serif'
));
insert_record('skin_fonts', (object) array(
)
);
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Verdana',
'title' => 'Verdana'
),
(object) array(
'name' => 'Verdana',
'title' => 'Verdana',
'licence' => 'DejaVu Font Licence.txt',
'previewfont' => 'DejaVuSans.ttf',
'variants' => $variants,
'variants' => $basicvariants,
'fonttype' => 'common',
'onlyheading' => 0,
'fontstack' => '\'Verdana\', \'DejaVu Sans\'',
'genericfont' => 'sans-serif'
));
)
);
// Theme fonts
$filetypes = array('EOT', 'SVG', 'TTF', 'WOFF', 'WOFF2', 'OTF');
$robotoslabvariants = array();
foreach (array('bold', 'regular', 'light', 'thin') as $option) {
$robotoslabvariants[$option] = $fv[$option];
foreach ($filetypes as $type) {
$robotoslabvariants[$option][$type] = 'robotoslab-' . $option . '.' . strtolower($type);
}
}
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'RobotoSlab',
'title' => 'Roboto Slab'
),
(object) array(
'name' => 'RobotoSlab',
'title' => 'Roboto Slab',
'licence' => '',
'previewfont' => 'robotoslab-regular.ttf',
'variants' => serialize($robotoslabvariants),
'fonttype' => 't_raw',
'onlyheading' => 0,
'fontstack' => '\'Roboto Slab\', \'Roboto\'',
'genericfont' => 'serif'
)
);
$opensansvariants = array();
foreach (array('bold', 'regular', 'light', 'lightitalic') as $option) {
$opensansvariants[$option] = $fv[$option];
foreach ($filetypes as $type) {
if ($option == 'lightitalic') {
$opensansvariants[$option][$type] = 'OpenSansLightItalic.' . strtolower($type);
}
else {
$opensansvariants[$option][$type] = 'OpenSans' . ucfirst($option) . '.' . strtolower($type);
}
}
}
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'OpenSans',
'title' => 'Open Sans'
),
(object) array(
'name' => 'OpenSans',
'title' => 'Open Sans',
'licence' => '',
'previewfont' => 'OpenSansRegular.ttf',
'variants' => serialize($opensansvariants),
'fonttype' => 't_raw',
'onlyheading' => 0,
'fontstack' => '\'Open Sans\', \'Verdana\'',
'genericfont' => 'sans-serif'
)
);
$osvaldovariants = array();
foreach (array('regular') as $option) {
$osvaldovariants[$option] = $fv[$option];
foreach ($filetypes as $type) {
$osvaldovariants[$option][$type] = 'osvaldo-' . $option . '.' . strtolower($type);
}
}
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Osvaldo',
'title' => 'Osvaldo'
),
(object) array(
'name' => 'Osvaldo',
'title' => 'Osvaldo',
'licence' => 'SIL Open Font License.txt',
'previewfont' => 'osvaldo-regular.ttf',
'variants' => serialize($osvaldovariants),
'fonttype' => 't_ocean',
'onlyheading' => 0,
'fontstack' => '\'Osvaldo\', \'Verdana\'',
'genericfont' => 'sans-serif'
)
);
$ralewayvariants = array();
foreach (array('bold', 'regular', 'italic', 'light', 'lightitalic', 'thin') as $option) {
$ralewayvariants[$option] = $fv[$option];
foreach ($filetypes as $type) {
$ralewayvariants[$option][$type] = 'raleway-' . $option . '.' . strtolower($type);
}
}
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'Raleway',
'title' => 'Raleway'
),
(object) array(
'name' => 'Raleway',
'title' => 'Raleway',
'licence' => '',
'previewfont' => 'raleway-regular.ttf',
'variants' => serialize($ralewayvariants),
'fonttype' => 't_modern',
'onlyheading' => 0,
'fontstack' => '\'Raleway\'',
'genericfont' => 'sans-serif'
)
);
$shadowsintolight2variants = array();
foreach (array('regular') as $option) {
$shadowsintolight2variants[$option] = $fv[$option];
foreach ($filetypes as $type) {
$shadowsintolight2variants[$option][$type] = 'shadows-into-light-two-v6-latin-ext_latin-' . $option . '.' . strtolower($type);
}
}
ensure_record_exists('skin_fonts',
(object) array(
'name' => 'ShadowsIntoLightTwo',
'title' => 'Shadows Into Light Two'
),
(object) array(
'name' => 'ShadowsIntoLightTwo',
'title' => 'Shadows Into Light Two',
'licence' => 'OFL.txt',
'previewfont' => 'shadowsintolight2-regular.ttf',
'variants' => serialize($shadowsintolight2variants),
'fonttype' => 't_primaryschool',
'onlyheading' => 0,
'fontstack' => '\'Shadows Into Light Two\'',
'genericfont' => 'sans-serif'
)
);
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019080802;
$config->version = 2019090900;
$config->series = '19.10';
$config->release = '19.10dev';
$config->minupgradefrom = 2017031605;
......
......@@ -3,11 +3,11 @@
font-family: 'Shadows Into Light Two';
font-style: normal;
font-weight: 400;
src: url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.eot'); /* IE9 Compat Modes */
src: url('../fonts/ShadowsIntoLighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.eot'); /* IE9 Compat Modes */
src: local('Shadows Into Light Two'), local('ShadowsIntoLightTwo-Regular'),
url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.woff') format('woff'), /* Modern Browsers */
url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('../fonts/ShadowsIntoLightTwo/shadows-into-light-two-v6-latin-ext_latin-regular.svg#ShadowsIntoLightTwo') format('svg'); /* Legacy iOS */
url('../fonts/shadowsintolighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../fonts/shadowsintolighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('../fonts/shadowsintolighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.woff') format('woff'), /* Modern Browsers */
url('../fonts/shadowsintolighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('../fonts/shadowsintolighttwo/shadows-into-light-two-v6-latin-ext_latin-regular.svg#ShadowsIntoLightTwo') format('svg'); /* Legacy iOS */
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment