PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Models / Common / Styles / Typography.php

Typography.php in Depicter — Popup & Slider Builder 1.3.3, at app/src/Document/Models/Common/Styles/Typography.php

104 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Models\Common\Styles;
3
4
5 use Depicter\Document\CSS\Breakpoints;
6
7 class Typography extends States
8 {
9 /**
10 * style name
11 */
12 const NAME = 'typography';
13
14
15 public function set( $css ) {
16 $devices = Breakpoints::names();
17
18 foreach ( $devices as $device ) {
19 if ( !empty( $this->{$device} ) ) {
20
21 $fontProperties = [
22 'fontSize' => 'font-size',
23 'align' => 'text-align',
24 'color' => 'color',
25 'font' => 'font-family',
26 'fontVariant' => 'font-weight',
27 'lineHeight' => 'line-height',
28 'transform' => 'text-transform',
29 'letterSpacing' => 'letter-spacing',
30 'wordwrap' => 'word-wrap',
31 'direction' => 'direction',
32 'decoration' => 'text-decoration'
33 ];
34
35 foreach ( $fontProperties as $key => $cssProperty ) {
36
37 if ( isset( $this->{$device}->{$key} ) ) {
38 $cssValue = $this->{$device}->{$key};
39
40 if ( $key == 'fontSize' ) {
41 $css[ $device ][ $cssProperty ] = $cssValue . 'px';
42 } elseif ( $key == 'lineHeight') {
43 $css[ $device ][ $cssProperty ] = $cssValue . '%';
44 } elseif ( $key == 'font') {
45 $css[ $device ][ $cssProperty ] = $cssValue == 'inherit' ? $cssValue : '"' . $cssValue . '"';
46 } elseif ( $key == 'fontVariant') {
47 $fontWeight = $cssValue;
48 // extract font style and weight
49 if( false !== strpos( $fontWeight, 'italic') ){
50 $css[ $device ][ 'font-style' ] = 'italic';
51 $fontWeight = trim( $fontWeight, 'italic');
52
53 // reset font-style if desktop font style was italic
54 } elseif( isset( $this->default->{$key} ) && false !== strpos( $this->default->{$key}, 'italic') ){
55 $css[ $device ][ 'font-style' ] = 'normal';
56 }
57
58 // convert "regular" to 400
59 if( 'regular' == strtolower( $fontWeight ) ){
60 $fontWeight = 400;
61 }
62
63 $css[ $device ][ $cssProperty ] = $fontWeight;
64
65 } elseif ( $key == 'wordwrap') {
66 if( $cssValue == 'break' ){
67 $css[ $device ][ 'overflow-wrap' ] = 'break-word';
68 } else {
69 $css[ $device ][ 'white-space' ] = 'nowrap';
70 }
71 } elseif ( $key == 'letterSpacing' ) {
72 $css[ $device ][ $cssProperty ] = $cssValue . 'px';
73 } else {
74 $css[ $device ][ $cssProperty ] = $cssValue;
75 }
76 }
77 }
78 }
79 }
80
81 return $css;
82 }
83
84 public function getFontsList() {
85 $devices = Breakpoints::names();
86 $fontList = [];
87
88 foreach ( $devices as $device ) {
89 if ( !empty( $this->{$device}->font ) ) {
90 $fontWeight = ! empty( $this->{$device}->fontVariant ) ? $this->{$device}->fontVariant : 400;
91 if( ! empty( $fontList[ $this->{$device}->font ] ) ){
92 if( is_array( $fontList[ $this->{$device}->font ] ) && ! in_array( $fontWeight, $fontList[ $this->{$device}->font ] ) ){
93 $fontList[ $this->{$device}->font ][] = $fontWeight;
94 }
95 } else {
96 $fontList[ $this->{$device}->font ] = [ $fontWeight ];
97 }
98 }
99 }
100
101 return $fontList;
102 }
103 }
104