Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1426099
generate-font-test-page.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
generate-font-test-page.php
View Options
<?php
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @file
*/
namespace
UniversalLanguageSelector
;
use
FormatJson
;
use
Maintenance
;
use
MediaWiki\Html\Html
;
// Standard boilerplate to define $IP
if
(
getenv
(
'MW_INSTALL_PATH'
)
!==
false
)
{
$IP
=
getenv
(
'MW_INSTALL_PATH'
);
}
else
{
$dir
=
__DIR__
;
$IP
=
"$dir/../../.."
;
}
require_once
"$IP/maintenance/Maintenance.php"
;
class
GenerateFontTestPage
extends
Maintenance
{
public
function
__construct
()
{
parent
::
__construct
();
$this
->
addDescription
(
'Creates a HTML page with text for all fonts.'
);
}
public
function
execute
()
{
$base
=
dirname
(
__DIR__
);
$relpath
=
'../data/fontrepo/fonts'
;
$compiler
=
new
FontRepoCompiler
(
"$base/data/fontrepo/fonts"
,
$relpath
);
$list
=
$compiler
->
getRepository
();
$corpus
=
file_get_contents
(
__DIR__
.
'/../data/langsamples.json'
);
$corpus
=
FormatJson
::
decode
(
$corpus
,
true
);
$body
=
''
;
foreach
(
$list
[
'languages'
]
as
$code
=>
$fonts
)
{
if
(
!
isset
(
$corpus
[
$code
]
)
)
{
continue
;
}
foreach
(
$fonts
as
$fontname
)
{
if
(
$fontname
===
'system'
)
{
continue
;
}
$class
=
'font-'
.
substr
(
md5
(
$fontname
),
0
,
6
);
$body
.=
Html
::
element
(
'div'
,
[
'class'
=>
"$class sax"
],
"[$code/$fontname] {$corpus[$code]}"
);
}
}
$css
=
".sax { white-space: nowrap; overflow: hidden; }
\n\n
"
;
$formats
=
[
'woff2'
,
'woff'
,
'ttf'
];
foreach
(
$list
[
'fonts'
]
as
$fontname
=>
$font
)
{
$class
=
'font-'
.
substr
(
md5
(
$fontname
),
0
,
6
);
$css
.=
"@font-face {
\n\t
font-family: '$fontname';
\n\t
src:
\n
"
;
$xus
=
[];
foreach
(
$formats
as
$format
)
{
if
(
!
isset
(
$font
[
$format
]
)
)
{
continue
;
}
$xus
[]
=
"
\t
url('$relpath/{$font[$format]}') format('$format')"
;
}
$css
.=
implode
(
",
\n
"
,
$xus
);
$css
.=
";
\n
}
\n\n
"
;
$css
.=
".$class {
\n\t
font-family: '$fontname';
\n
}
\n\n
"
;
}
// Charset is needed, because Edge is so brilliant that it thinks this page full of UTF-8
// is actually in some legacy encoding and does not provide way to change it ;)
$html
=
<<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
$css
</style>
</head>
<body>
$body
</body>
HTML;
file_put_contents
(
"$base/tests/all-fonts.html"
,
$html
);
$this
->
output
(
"Done.
\n
"
);
}
}
$maintClass
=
GenerateFontTestPage
::
class
;
require_once
RUN_MAINTENANCE_IF_MAIN
;
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 12:35 (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
82/e7/98761aa2d1c45f731dbadd781b73
Default Alt Text
generate-font-test-page.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment