Closed Cruglk closed 3 years ago
Can you please specify the context? did you test in a web browser? if yes, which one?
Thanks
@tbela99, Example. Full HTML-code. The font is displayed:
<style>@font-face{font-family:'CenturyGothic';src:url('https://static.tildacdn.com/tild3266-3633-4465-b435-326361353130/CenturyGothic.woff') format('woff');font-weight:400;}.text{font-family:'CenturyGothic';}
</style><div class="text">Test</div>
And test. The font is not displayed.
<?php require 'vendor/autoload.php';
use \TBela\CSS\Parser;
use \TBela\CSS\Renderer;
$test = "@font-face{font-family:'CenturyGothic';src:url('https://static.tildacdn.com/tild3266-3633-4465-b435-326361353130/CenturyGothic.woff') format('woff');font-weight:400;}*{font-family:'CenturyGothic';}";
$parser = new Parser($test);
$element = $parser->parse();
$css = (string)$element;
$renderer = new Renderer([
'compress' => false,
'css_level' => 4,
'allow_duplicate_declarations' => false
]);
$css = $renderer->render($element);
echo '<style>'.$css.'</style>';`
https://jigsaw.w3.org/css-validator/validator.html.en#validate_by_input
@font-face {
font-family: CenturyGothic;
src: url(/fonts/CenturyGothic.woff) format('woff');
font-weight: 400;
}
And:
@font-face {
font-family: CenturyGothic;
src: url(/fonts/CenturyGothic.woff) format(woff);
font-weight: 400;
}
Ungly fix. CssString.php:
if(preg_match('#woff#', $data->value)){
$data->q = '';
}else{
$data->value = substr($data->value, 1, -1);
}
if (preg_match('#^[\w_-]+$#', $data->value)) {
$data->q = '';
}
all issues are now fixed and will be merged soon into the master branch.
Thanks for your reports!
$test = "@font-face{font-family:'CenturyGothic';src:url('/CenturyGothic.woff') format('woff');font-weight:400;}";
Result:
@font-face { font-family: CenturyGothic; font-weight: 400; src: url(/CenturyGothic.woff) format(woff) }
Correctly:
@font-face { font-family: CenturyGothic; font-weight: 400; src: url(/CenturyGothic.woff) format('woff') }