namespace Fluidbook\Tools\Compiler;
use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
use Cubist\Util\Graphics\Color;
+use Cubist\Util\Graphics\Image;
trait Styles
{
protected $lessVariables = [];
+ protected $stylesheets = [];
+ protected $lessSource;
+ protected $cssfont = [];
+ public $lessFiles = ['fluidbook'];
- protected function writeCSS($links)
+ public function isMobileFirst()
+ {
+ return $this->config->mobileNavigationType === 'mobilefirst';
+ }
+
+ public function addFontKit($font)
+ {
+ if ($font === 'sans-serif') {
+ return;
+ }
+ if ($font === 'Open Sans') {
+ $font = 'OpenSans';
+ }
+
+ $path = 'fonts/' . $font;
+ $css = $path . '/font.css';
+ if (in_array($css, $this->stylesheets)) {
+ return;
+ }
+ $this->stylesheets[] = $css;
+ $this->vdir->copyDirectory($this->lessSource . $path, $path);
+ return $path . '/font.css';
+ }
+
+ protected function _font($f)
+ {
+ $default = 'Arial, Helvetica, sans-serif';
+ if ($f === 'OpenSans') {
+ $f = 'Open Sans';
+ }
+ switch ($f) {
+ case 'Montserrat':
+ case 'Open Sans':
+ $this->addFontKit($f);
+ return "'" . $f . "', " . $default;
+ case 'sans-serif':
+ return $f;
+ case 'Arial':
+ return $default;
+ default:
+ return "'Open Sans', Arial, Helverica, sans-serif";
+ }
+ }
+
+ protected function compileStyles($links)
{
$res = array();
- $this->addFontKit('OpenSans');
+ $this->lessSource = $this->stub . '/_less/';
$lessContents = '';
+ $this->lessVariables['import-cart-styles']='none';
+ $this->lessVariables['articles-title-color']='#000000';
+
$this->lessVariables['font'] = $this->_font($this->config->interfaceFont);
$this->lessVariables['text-transform'] = $this->_themeBoolean($this->config->interfaceFontUppercase) ? 'uppercase' : 'inherit';
- $this->lessVariables['css-scale'] = $this->cssScale;
+ $this->lessVariables['css-scale'] = $this->config->cssScale;
$this->lessVariables['slider-background'] = Color::colorToCSS(!$this->config->sliderBackground ? 'rgba(0,0,0,0.1)' : $this->config->sliderBackground);
$this->lessVariables['slider-handle'] = Color::colorToCSS(!$this->config->sliderHandle ? '#ffffff' : $this->config->sliderHandle);
// General theme
- $cssWidth = $this->cssWidth;
- $cssHeight = $this->cssHeight;
- $cssScale = $this->cssScale;
+ $cssWidth = $this->config->width;
+ $cssHeight = $this->config->height;
+ $cssScale = $this->config->cssScale;
$w2 = ($cssWidth * 2) . 'px';
$h = $cssHeight . 'px';
- $wm = ($this->getWidth() * $this->multiply) . 'px';
- $hm = ($this->getHeight() * $this->multiply) . 'px';
+ $wm = ($this->getWidth() * $this->config->multiply) . 'px';
+ $hm = ($this->getHeight() * $this->config->multiply) . 'px';
$w = $cssWidth . 'px';
- $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 3);
+ $offsetLeft = round(($this->config->optimalWidth - $cssWidth) / 2, 3);
$offsetLeft2 = $offsetLeft * 2;
- $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 3);
+ $offsetTop = round(($this->config->optimalHeight - $cssHeight) / 2, 3);
$navTop = ($cssHeight - 40 - 100) / 2;
$leftOfRightPage = (floor($cssWidth) - 1) . 'px';
- $this->lessVariables['z'] = $this->z;
+ $this->lessVariables['z'] = $this->config->pageZoomFactor;
$this->lessVariables['book-page-width'] = $w;
if ($this->config->correctCenter && !$this->isMobileFirst()) {
- $this->lessVariables['book-page-correct-width'] = ceil($w) + 1;
- $this->lessVariables['book-page-correct-height'] = ceil($h) + 1;
+ $this->lessVariables['book-page-correct-width'] = ceil($cssWidth) + 1;
+ $this->lessVariables['book-page-correct-height'] = ceil($cssHeight) + 1;
} else {
$this->lessVariables['book-page-correct-width'] = $w;
$this->lessVariables['book-page-correct-height'] = $h;
$corrText = $this->isMobileFirst() ? 0 : 4;
- if ($this->cssSVGScale != 1) {
- $texts = '.texts{' . wsHTML5::writeCSSUA('transform-origin', 'top left') . ';';
- $texts .= wsHTML5::writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';';
- $texts .= 'width:' . ($wm / $this->cssSVGScale) . 'px; max-width:' . ($wm / $this->cssSVGScale) . 'px;';
- $texts .= 'height:' . ($hm / $this->cssSVGScale) . 'px; max-height:' . ($hm / $this->cssSVGScale) . 'px;';
- $texts .= '}';
- } else {
- $texts = '.texts{width:' . floor(floatval($w) + $corrText) . 'px;height:' . floor(floatval($h) + $corrText) . 'px;}';
- }
-
- $res[] = $texts;
-
// Theme
$shade = '.page .shade{';
$shade .= 'opacity:' . min(($this->config->shadeAlpha * 2) / 100, 1) . ';';
$logo = '#logo{';
if ($l = $this->checkThemeImage($this->config->logo)) {
$this->vdir->copy($l, 'data/images/' . $this->config->logo);
- $dim = CubeIT_Image::getimagesize($l);
+ $dim = Image::getimagesize($l);
$logo .= 'background-image:url(../images/' . $this->config->logo . ');width:' . $dim[0] . 'px;height:' . $dim[1] . 'px;';
}
$logo .= '}';
$this->lessVariables['bookmark-star-disabled-color'] = Color::colorToCSS($this->config->bookmarkStarDisabledColor);
$this->lessVariables['bookmark-star-enabled-color'] = Color::colorToCSS($this->config->bookmarkStarEnabledColor);
$this->lessVariables['bookmark-color'] = Color::colorToCSS($this->config->bookmarkBackgroundColor);
- $this->lessVariables['bookmark-corner-size'] = round($this->getWidth() * $this->config->bookmarkCornerSize * 0.0075 * $this->z) . 'px';
+ $this->lessVariables['bookmark-corner-size'] = round($this->getWidth() * $this->config->bookmarkCornerSize * 0.0075 * $this->config->pageZoomFactor) . 'px';
$this->lessVariables['bookmark-corner-offset'] = $this->config->bookmarkOffset . 'px';
// Menus
$this->lessVariables['menu-chapters-columns-width'] = $this->config->chaptersColMaxWidth;
$this->lessVariables['menu-chapters-font-size'] = $this->config->chaptersFontSize;
- foreach ($this->book->chapters as $chapter) {
+ foreach ($this->config->chapters as $chapter) {
if (substr($chapter->page, 0, 1) != '#') {
continue;
}
$lessContents .= '.mview.c_' . $color . '{.menu-color(' . Color::colorToCSS($color) . ');}';
}
- // Archives
- if ($this->config->externalArchivesBack) {
- $this->vdir->copy($this->wdir . '/' . $this->config->externalArchivesBack, 'data/images/' . $this->config->externalArchivesBack);
- $res[] = '.mview.archives{background-image:url("../images/' . $this->config->externalArchivesBack . '");}';
- }
+// // Archives
+// if ($this->config->externalArchivesBack) {
+// $this->vdir->copy($this->wdir . '/' . $this->config->externalArchivesBack, 'data/images/' . $this->config->externalArchivesBack);
+// $res[] = '.mview.archives{background-image:url("../images/' . $this->config->externalArchivesBack . '");}';
+// }
# Index
$thumbw = $this->config->mobileNavigationType === 'portrait' ? 200 : 100;
protected function compileLess($variables, $lessContents = '')
{
- if ($this->widget) {
- $this->lessFiles[] = 'widget';
- }
- foreach ($this->specialCSS as $s) {
- $this->lessFiles[] = 'special/' . $s;
- }
+// if ($this->widget) {
+// $this->lessFiles[] = 'widget';
+// }
+// foreach ($this->specialCSS as $s) {
+// $this->lessFiles[] = 'special/' . $s;
+// }
- $tmp = CubeIT_Files::tmpdir();
+ $tmp = Files::tmpdir();
- $from = $this->assets . '/style/*';
+ $from = $this->lessSource . '/*';
`cp -r $from $tmp`;
$bookVariables = array();
file_put_contents($tmp . '/additional.less', $lessContents);
foreach ($this->lessFiles as $f) {
- $source_less = $this->assets . '/style/' . $f . '.less';
+ $source_less = $this->lessSource . '/' . $f . '.less';
$destination_less = $tmp . '/' . $f . '.less';
$destination_css = $tmp . '/' . $f . '.css';
return false;
}
+ protected function _lessBoolean($val)
+ {
+ return $this->_themeBoolean($val) ? 'true' : 'false';
+ }
+
protected function _themeBoolean($v): bool
{
return !(null === $v || $v === '0' || $v === 0 || $v === false || !$v);
}
+
+
+ protected function _cssBackground()
+ {
+ $body = '#background, #splash {';
+
+ switch ($this->config->repeat) {
+ case 1:
+ $body .= 'background-repeat:repeat;';
+ break;
+ case 3:
+ $body .= 'background-repeat:no-repeat;';
+ break;
+ case 2:
+ $body .= 'background-repeat:no-repeat;';
+ $body .= 'background-size:cover;';
+ break;
+ case 0:
+ $body .= 'background-repeat:no-repeat;';
+ $body .= 'background-size:100% 100%;';
+ break;
+ }
+
+ if ($bi = $this->checkThemeImage($this->config->backgroundImage)) {
+
+ $dbi = Image::getimagesize($bi);
+ $this->config->backgroundImageDimensions = array('width' => $dbi[0], 'height' => $dbi[1]);
+
+
+ $this->vdir->copy($bi, 'data/images/' . $this->config->backgroundImage);
+ $body .= 'background-image:url(../images/' . $this->config->backgroundImage . ');';
+ $body .= 'background-position:';
+
+ switch ($this->config->backgroundVAlign) {
+ case 8:
+ $body .= 'top';
+ break;
+ case 7:
+ $body .= 'center';
+ break;
+ case 9:
+ $body .= 'bottom';
+ break;
+ }
+
+ $body .= ' ';
+
+ switch ($this->config->backgroundHAlign) {
+ case 5:
+ $body .= 'left';
+ break;
+ case 4:
+ $body .= 'center';
+ break;
+ case 6:
+ $body .= 'right';
+ break;
+ }
+ $body .= ';';
+ }
+
+ $body .= '}';
+
+
+ if ($this->_themeBoolean($this->config->displayBackgroundDuringLoading)) {
+ $body .= '#background, #splash {
+ background-color:' . Color::colorToCSS($this->config->backgroundColor) . ' !important;
+ }';
+ } else {
+ $body .= '#background {
+ transition: 500ms opacity;
+ visibility: hidden;
+ opacity: 0;
+ background-color:' . Color::colorToCSS($this->config->backgroundColor) . ' !important;
+ }';
+
+ $body .= '#splash {
+ background-color:' . Color::colorToCSS($this->config->loadingBackColor) . ' !important;
+ background-image: none;
+ }';
+ }
+
+ return $body;
+ }
}