@@ -156,6 +156,7 @@ public function createShorthands()
156
156
/**
157
157
* Split shorthand border declarations (e.g. <tt>border: 1px red;</tt>)
158
158
* Additional splitting happens in expandDimensionsShorthand
159
+ * Multiple borders are not yet supported as of CSS3
159
160
**/
160
161
public function expandBorderShorthand ()
161
162
{
@@ -170,10 +171,16 @@ public function expandBorderShorthand()
170
171
{
171
172
if (!isset ($ aRules [$ sBorderRule ])) continue ;
172
173
$ oRule = $ aRules [$ sBorderRule ];
173
- foreach ($ oRule ->getValues () as $ aValues )
174
+ $ mRuleValue = $ oRule ->getValue ();
175
+ $ aValues = array ();
176
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
177
+ $ aValues [] = $ mRuleValue ;
178
+ }
179
+ else {
180
+ $ aValues = $ mRuleValue ->getListComponents ();
181
+ }
182
+ foreach ($ aValues as $ mValue )
174
183
{
175
- // multiple borders are not yet supported as of CSS3
176
- $ mValue = $ aValues [0 ];
177
184
if ($ mValue instanceof CSSValue)
178
185
{
179
186
$ mNewValue = clone $ mValue ;
@@ -229,7 +236,14 @@ public function expandDimensionsShorthand()
229
236
{
230
237
if (!isset ($ aRules [$ sProperty ])) continue ;
231
238
$ oRule = $ aRules [$ sProperty ];
232
- $ aValues = $ oRule ->getValues ();
239
+ $ mRuleValue = $ oRule ->getValue ();
240
+ $ aValues = array ();
241
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
242
+ $ aValues [] = $ mRuleValue ;
243
+ }
244
+ else {
245
+ $ aValues = $ mRuleValue ->getListComponents ();
246
+ }
233
247
$ top = $ right = $ bottom = $ left = null ;
234
248
switch (count ($ aValues ))
235
249
{
@@ -278,37 +292,44 @@ public function expandFontShorthand()
278
292
'font-style ' => 'normal ' , 'font-variant ' => 'normal ' , 'font-weight ' => 'normal ' ,
279
293
'font-size ' => 'normal ' , 'line-height ' => 'normal '
280
294
);
281
- foreach ($ oRule ->getValues () as $ aValues )
295
+ $ mRuleValue = $ oRule ->getValue ();
296
+ $ aValues = array ();
297
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
298
+ $ aValues [] = $ mRuleValue ;
299
+ }
300
+ else {
301
+ $ aValues = $ mRuleValue ->getListComponents ();
302
+ }
303
+ foreach ($ aValues as $ mValue )
282
304
{
283
- $ mValue = $ aValues [0 ];
284
305
if (!$ mValue instanceof CSSValue)
285
306
{
286
- $ mValue = strtolower ($ mValue );
307
+ $ mValue = mb_strtolower ($ mValue );
287
308
}
288
309
if (in_array ($ mValue , array ('normal ' , 'inherit ' )))
289
310
{
290
311
foreach (array ('font-style ' , 'font-weight ' , 'font-variant ' ) as $ sProperty )
291
312
{
292
313
if (!isset ($ aFontProperties [$ sProperty ]))
293
314
{
294
- $ aFontProperties [$ sProperty ] = $ aValues ;
315
+ $ aFontProperties [$ sProperty ] = $ mValue ;
295
316
}
296
317
}
297
318
}
298
319
else if (in_array ($ mValue , array ('italic ' , 'oblique ' )))
299
320
{
300
- $ aFontProperties ['font-style ' ] = $ aValues ;
321
+ $ aFontProperties ['font-style ' ] = $ mValue ;
301
322
}
302
323
else if ($ mValue == 'small-caps ' )
303
324
{
304
- $ aFontProperties ['font-variant ' ] = $ aValues ;
325
+ $ aFontProperties ['font-variant ' ] = $ mValue ;
305
326
}
306
327
else if (in_array ($ mValue , array ('bold ' , 'bolder ' , 'lighter ' ))
307
328
|| ($ mValue instanceof CSSSize
308
329
&& in_array ($ mValue ->getSize (), range (100 , 900 , 100 ))
309
330
)
310
331
){
311
- $ aFontProperties ['font-weight ' ] = $ aValues ;
332
+ $ aFontProperties ['font-weight ' ] = $ mValue ;
312
333
}
313
334
else if ($ mValue instanceof CSSRuleValueList && $ mValue ->getListSeparator () === '/ ' )
314
335
{
@@ -318,18 +339,17 @@ public function expandFontShorthand()
318
339
}
319
340
else if ($ mValue instanceof CSSSize && $ mValue ->getUnit () !== null )
320
341
{
321
- $ aFontProperties ['font-size ' ] = $ aValues ;
342
+ $ aFontProperties ['font-size ' ] = $ mValue ;
322
343
}
323
344
else
324
345
{
325
- $ aFontProperties ['font-family ' ] = $ aValues ;
346
+ $ aFontProperties ['font-family ' ] = $ mValue ;
326
347
}
327
348
}
328
- foreach ($ aFontProperties as $ sProperty => $ aValues )
349
+ foreach ($ aFontProperties as $ sProperty => $ mValue )
329
350
{
330
- if (!is_array ($ aValues )) $ aValues = array ($ aValues );
331
351
$ oNewRule = new CSSRule ($ sProperty );
332
- $ oNewRule ->setValues ( array ( $ aValues ) );
352
+ $ oNewRule ->addValue ( $ mValue );
333
353
$ oNewRule ->setIsImportant ($ oRule ->getIsImportant ());
334
354
$ this ->addRule ($ oNewRule );
335
355
}
@@ -352,41 +372,47 @@ public function expandBackgroundShorthand()
352
372
'background-repeat ' => array ('repeat ' ), 'background-attachment ' => array ('scroll ' ),
353
373
'background-position ' => array (new CSSSize (0 , '% ' ), new CSSSize (0 , '% ' ))
354
374
);
355
- $ aValuesList = $ oRule ->getValues ();
356
- if (count ($ aValuesList ) == 1 && $ aValuesList [0 ][0 ] == 'inherit ' )
375
+ $ mRuleValue = $ oRule ->getValue ();
376
+ $ aValues = array ();
377
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
378
+ $ aValues [] = $ mRuleValue ;
379
+ }
380
+ else {
381
+ $ aValues = $ mRuleValue ->getListComponents ();
382
+ }
383
+ if (count ($ aValues ) == 1 && $ aValues [0 ] == 'inherit ' )
357
384
{
358
- foreach ($ aBgProperties as $ sProperty => $ aValues ) {
385
+ foreach ($ aBgProperties as $ sProperty => $ mValue ) {
359
386
$ oNewRule = new CSSRule ($ sProperty );
360
- $ oNewRule ->addValue (array ( 'inherit ' ) );
387
+ $ oNewRule ->addValue ('inherit ' );
361
388
$ oNewRule ->setIsImportant ($ oRule ->getIsImportant ());
362
389
$ this ->addRule ($ oNewRule );
363
390
}
364
391
$ this ->removeRule ('background ' );
365
392
return ;
366
393
}
367
394
$ iNumBgPos = 0 ;
368
- foreach ($ aValuesList as $ aValues )
395
+ foreach ($ aValues as $ mValue )
369
396
{
370
- $ mValue = $ aValues [0 ];
371
397
if (!$ mValue instanceof CSSValue)
372
398
{
373
- $ mValue = strtolower ($ mValue );
399
+ $ mValue = mb_strtolower ($ mValue );
374
400
}
375
401
if ($ mValue instanceof CSSURL )
376
402
{
377
- $ aBgProperties ['background-image ' ] = $ aValues ;
403
+ $ aBgProperties ['background-image ' ] = $ mValue ;
378
404
}
379
405
else if ($ mValue instanceof CSSColor)
380
406
{
381
- $ aBgProperties ['background-color ' ] = $ aValues ;
407
+ $ aBgProperties ['background-color ' ] = $ mValue ;
382
408
}
383
409
else if (in_array ($ mValue , array ('scroll ' , 'fixed ' )))
384
410
{
385
- $ aBgProperties ['background-attachment ' ] = $ aValues ;
411
+ $ aBgProperties ['background-attachment ' ] = $ mValue ;
386
412
}
387
413
else if (in_array ($ mValue , array ('repeat ' ,'no-repeat ' , 'repeat-x ' , 'repeat-y ' )))
388
414
{
389
- $ aBgProperties ['background-repeat ' ] = $ aValues ;
415
+ $ aBgProperties ['background-repeat ' ] = $ mValue ;
390
416
}
391
417
else if (in_array ($ mValue , array ('left ' ,'center ' ,'right ' ,'top ' ,'bottom ' ))
392
418
|| $ mValue instanceof CSSSize
@@ -403,10 +429,10 @@ public function expandBackgroundShorthand()
403
429
$ iNumBgPos ++;
404
430
}
405
431
}
406
- foreach ($ aBgProperties as $ sProperty => $ aValues ) {
432
+ foreach ($ aBgProperties as $ sProperty => $ mValue ) {
407
433
$ oNewRule = new CSSRule ($ sProperty );
408
434
$ oNewRule ->setIsImportant ($ oRule ->getIsImportant ());
409
- $ oNewRule ->addValue ($ aValues );
435
+ $ oNewRule ->addValue ($ mValue );
410
436
$ this ->addRule ($ oNewRule );
411
437
}
412
438
$ this ->removeRule ('background ' );
@@ -424,8 +450,16 @@ public function createBackgroundShorthand()
424
450
if (!isset ($ aRules [$ sProperty ])) continue ;
425
451
$ oRule = $ aRules [$ sProperty ];
426
452
if (!$ oRule ->getIsImportant ()) {
427
- foreach ($ aRules [$ sProperty ]->getValues () as $ aValues ) {
428
- $ aNewValues [] = $ aValues ;
453
+ $ mRuleValue = $ oRule ->getValue ();
454
+ $ aValues = array ();
455
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
456
+ $ aValues [] = $ mRuleValue ;
457
+ }
458
+ else {
459
+ $ aValues = $ mRuleValue ->getListComponents ();
460
+ }
461
+ foreach ($ aValues as $ mValue ) {
462
+ $ aNewValues [] = $ mValue ;
429
463
}
430
464
$ this ->removeRule ($ sProperty );
431
465
}
@@ -455,10 +489,17 @@ public function createBorderShorthand() {
455
489
if (!isset ($ aRules [$ sBorderRule ])) continue ;
456
490
$ oRule = $ aRules [$ sBorderRule ];
457
491
if (!$ oRule ->getIsImportant ()) {
492
+ $ mRuleValue = $ oRule ->getValue ();
493
+ $ aValues = array ();
494
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
495
+ $ aValues [] = $ mRuleValue ;
496
+ }
497
+ else {
498
+ $ aValues = $ mRuleValue ->getListComponents ();
499
+ }
458
500
// Can't merge if multiple values !
459
- if (count ($ oRule ->getValues ()) > 1 ) continue ;
460
- foreach ($ oRule ->getValues () as $ aValues ) {
461
- $ mValue = $ aValues [0 ];
501
+ if (count ($ aValues ) > 1 ) continue ;
502
+ foreach ($ aValues as $ mValue ) {
462
503
if ($ mValue instanceof CSSValue) {
463
504
$ mNewValue = clone $ mValue ;
464
505
$ aNewValues [] = $ mNewValue ;
@@ -472,7 +513,7 @@ public function createBorderShorthand() {
472
513
if (count ($ aNewValues )) {
473
514
$ oNewRule = new CSSRule ('border ' );
474
515
foreach ($ aNewValues as $ mNewValue ) {
475
- $ oNewRule ->addValue (array ( $ mNewValue) );
516
+ $ oNewRule ->addValue ($ mNewValue );
476
517
}
477
518
$ this ->addRule ($ oNewRule );
478
519
foreach ($ aBorderRules as $ sRuleName ) {
@@ -516,8 +557,16 @@ public function createDimensionsShorthand()
516
557
$ aValues = array ();
517
558
foreach ($ aPositions as $ sPosition )
518
559
{
519
- $ aValuesList = $ aRules [sprintf ($ sExpanded , $ sPosition )]->getValues ();
520
- $ aValues [$ sPosition ] = $ aValuesList [0 ];
560
+ $ oRule = $ aRules [sprintf ($ sExpanded , $ sPosition )];
561
+ $ mRuleValue = $ oRule ->getValue ();
562
+ $ aRuleValues = array ();
563
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
564
+ $ aRuleValues [] = $ mRuleValue ;
565
+ }
566
+ else {
567
+ $ aRuleValues = $ mRuleValue ->getListComponents ();
568
+ }
569
+ $ aValues [$ sPosition ] = $ aRuleValues ;
521
570
}
522
571
$ oNewRule = new CSSRule ($ sProperty );
523
572
if ((string )$ aValues ['left ' ][0 ] == (string )$ aValues ['right ' ][0 ])
@@ -582,35 +631,65 @@ public function createFontShorthand()
582
631
if (isset ($ aRules [$ sProperty ]))
583
632
{
584
633
$ oRule = $ aRules [$ sProperty ];
585
- $ aValuesList = $ oRule ->getValues ();
586
- if ($ aValuesList [0 ][0 ] !== 'normal ' )
634
+ $ mRuleValue = $ oRule ->getValue ();
635
+ $ aValues = array ();
636
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
637
+ $ aValues [] = $ mRuleValue ;
638
+ }
639
+ else {
640
+ $ aValues = $ mRuleValue ->getListComponents ();
641
+ }
642
+ if ($ aValues [0 ] !== 'normal ' )
587
643
{
588
- $ oNewRule ->addValue ($ aValuesList [0 ]);
644
+ $ oNewRule ->addValue ($ aValues [0 ]);
589
645
}
590
646
}
591
647
}
592
648
// Get the font-size value
593
- $ aFSValues = $ aRules ['font-size ' ]->getValues ();
649
+ $ oRule = $ aRules ['font-size ' ];
650
+ $ mRuleValue = $ oRule ->getValue ();
651
+ $ aFSValues = array ();
652
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
653
+ $ aFSValues [] = $ mRuleValue ;
654
+ }
655
+ else {
656
+ $ aFSValues = $ mRuleValue ->getListComponents ();
657
+ }
594
658
// But wait to know if we have line-height to add it
595
659
if (isset ($ aRules ['line-height ' ]))
596
660
{
597
- $ aLHValues = $ aRules ['line-height ' ]->getValues ();
598
- if ($ aLHValues [0 ][0 ] !== 'normal ' )
661
+ $ oRule = $ aRules ['line-height ' ];
662
+ $ mRuleValue = $ oRule ->getValue ();
663
+ $ aLHValues = array ();
664
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
665
+ $ aLHValues [] = $ mRuleValue ;
666
+ }
667
+ else {
668
+ $ aLHValues = $ mRuleValue ->getListComponents ();
669
+ }
670
+ if ($ aLHValues [0 ] !== 'normal ' )
599
671
{
600
672
$ val = new CSSRuleValueList ('/ ' );
601
- $ val ->addListComponent ($ aFSValues [0 ][ 0 ] );
602
- $ val ->addListComponent ($ aLHValues [0 ][ 0 ] );
603
- $ oNewRule ->addValue (array ( $ val) );
673
+ $ val ->addListComponent ($ aFSValues [0 ]);
674
+ $ val ->addListComponent ($ aLHValues [0 ]);
675
+ $ oNewRule ->addValue ($ val );
604
676
}
605
677
}
606
678
else
607
679
{
608
680
$ oNewRule ->addValue ($ aFSValues [0 ]);
609
681
}
610
-
611
- $ aFFValues = $ aRules ['font-family ' ]->getValues ();
682
+ $ oRule = $ aRules ['font-family ' ];
683
+ $ mRuleValue = $ oRule ->getValue ();
684
+ $ aFFValues = array ();
685
+ if (!$ mRuleValue instanceof CSSRuleValueList) {
686
+ $ aFFValues [] = $ mRuleValue ;
687
+ }
688
+ else {
689
+ $ aFFValues = $ mRuleValue ->getListComponents ();
690
+ }
612
691
$ oFFValue = new CSSRuleValueList (', ' );
613
- $ oFFValue ->setListComponents ($ aFFValues[ 0 ] );
692
+ $ oFFValue ->setListComponents ($ aFFValues );
614
693
$ oNewRule ->addValue ($ oFFValue );
615
694
616
695
$ this ->addRule ($ oNewRule );
0 commit comments