@@ -269,7 +269,7 @@ protected function loadStyle(DOMElement $nodeStyle)
269
269
$ distance = ($ offsetY < 0 ? $ offsetY * -1 : $ offsetY );
270
270
}
271
271
$ oShadow ->setDirection ((int ) rad2deg (atan2 ($ offsetY , $ offsetX )));
272
- $ oShadow ->setDistance (( int ) round ( CommonDrawing::centimetersToPixels ($ distance) ));
272
+ $ oShadow ->setDistance (CommonDrawing::centimetersToPixels ($ distance ));
273
273
}
274
274
}
275
275
// Read Fill
@@ -365,6 +365,19 @@ protected function loadStyle(DOMElement $nodeStyle)
365
365
366
366
$ nodeParagraphProps = $ this ->oXMLReader ->getElement ('style:paragraph-properties ' , $ nodeStyle );
367
367
if ($ nodeParagraphProps instanceof DOMElement) {
368
+ if ($ nodeParagraphProps ->hasAttribute ('fo:line-height ' )) {
369
+ $ lineHeightUnit = $ this ->getExpressionUnit ($ nodeParagraphProps ->getAttribute ('fo:margin-bottom ' ));
370
+ $ lineSpacingMode = $ lineHeightUnit == '% ' ? Paragraph::LINE_SPACING_MODE_PERCENT : Paragraph::LINE_SPACING_MODE_POINT ;
371
+ $ lineSpacing = $ this ->getExpressionValue ($ nodeParagraphProps ->getAttribute ('fo:margin-bottom ' ));
372
+ }
373
+ if ($ nodeParagraphProps ->hasAttribute ('fo:margin-bottom ' )) {
374
+ $ spacingAfter = (float ) substr ($ nodeParagraphProps ->getAttribute ('fo:margin-bottom ' ), 0 , -2 );
375
+ $ spacingAfter = CommonDrawing::centimetersToPoints ($ spacingAfter );
376
+ }
377
+ if ($ nodeParagraphProps ->hasAttribute ('fo:margin-top ' )) {
378
+ $ spacingBefore = (float ) substr ($ nodeParagraphProps ->getAttribute ('fo:margin-top ' ), 0 , -2 );
379
+ $ spacingBefore = CommonDrawing::centimetersToPoints ($ spacingBefore );
380
+ }
368
381
$ oAlignment = new Alignment ();
369
382
if ($ nodeParagraphProps ->hasAttribute ('fo:text-align ' )) {
370
383
$ oAlignment ->setHorizontal ($ nodeParagraphProps ->getAttribute ('fo:text-align ' ));
@@ -407,10 +420,10 @@ protected function loadStyle(DOMElement $nodeStyle)
407
420
$ oNodeListProperties = $ this ->oXMLReader ->getElement ('style:list-level-properties ' , $ oNodeListLevel );
408
421
if ($ oNodeListProperties instanceof DOMElement) {
409
422
if ($ oNodeListProperties ->hasAttribute ('text:min-label-width ' )) {
410
- $ oAlignment ->setIndent (( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeListProperties ->getAttribute ('text:min-label-width ' ), 0 , -2 ) )));
423
+ $ oAlignment ->setIndent (CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeListProperties ->getAttribute ('text:min-label-width ' ), 0 , -2 )));
411
424
}
412
425
if ($ oNodeListProperties ->hasAttribute ('text:space-before ' )) {
413
- $ iSpaceBefore = ( int ) CommonDrawing::centimetersToPixels (substr ($ oNodeListProperties ->getAttribute ('text:space-before ' ), 0 , -2 ));
426
+ $ iSpaceBefore = CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeListProperties ->getAttribute ('text:space-before ' ), 0 , -2 ));
414
427
$ iMarginLeft = $ iSpaceBefore + $ oAlignment ->getIndent ();
415
428
$ oAlignment ->setMarginLeft ($ iMarginLeft );
416
429
}
@@ -432,12 +445,16 @@ protected function loadStyle(DOMElement $nodeStyle)
432
445
}
433
446
434
447
$ this ->arrayStyles [$ keyStyle ] = [
435
- 'alignment ' => isset ($ oAlignment ) ? $ oAlignment : null ,
436
- 'background ' => isset ($ oBackground ) ? $ oBackground : null ,
437
- 'fill ' => isset ($ oFill ) ? $ oFill : null ,
438
- 'font ' => isset ($ oFont ) ? $ oFont : null ,
439
- 'shadow ' => isset ($ oShadow ) ? $ oShadow : null ,
440
- 'listStyle ' => isset ($ arrayListStyle ) ? $ arrayListStyle : null ,
448
+ 'alignment ' => $ oAlignment ?? null ,
449
+ 'background ' => $ oBackground ?? null ,
450
+ 'fill ' => $ oFill ?? null ,
451
+ 'font ' => $ oFont ?? null ,
452
+ 'shadow ' => $ oShadow ?? null ,
453
+ 'listStyle ' => $ arrayListStyle ?? null ,
454
+ 'spacingAfter ' => $ spacingAfter ?? null ,
455
+ 'spacingBefore ' => $ spacingBefore ?? null ,
456
+ 'lineSpacingMode ' => $ lineSpacingMode ?? null ,
457
+ 'lineSpacing ' => $ lineSpacing ?? null ,
441
458
];
442
459
443
460
return true ;
@@ -507,11 +524,11 @@ protected function loadShapeDrawing(DOMElement $oNodeFrame): void
507
524
$ oShape ->setName ($ oNodeFrame ->hasAttribute ('draw:name ' ) ? $ oNodeFrame ->getAttribute ('draw:name ' ) : '' );
508
525
$ oShape ->setDescription ($ oNodeFrame ->hasAttribute ('draw:name ' ) ? $ oNodeFrame ->getAttribute ('draw:name ' ) : '' );
509
526
$ oShape ->setResizeProportional (false );
510
- $ oShape ->setWidth ($ oNodeFrame ->hasAttribute ('svg:width ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:width ' ), 0 , -2 ))) : '' );
511
- $ oShape ->setHeight ($ oNodeFrame ->hasAttribute ('svg:height ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:height ' ), 0 , -2 ))) : '' );
527
+ $ oShape ->setWidth ($ oNodeFrame ->hasAttribute ('svg:width ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:width ' ), 0 , -2 )) : 0 );
528
+ $ oShape ->setHeight ($ oNodeFrame ->hasAttribute ('svg:height ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:height ' ), 0 , -2 )) : 0 );
512
529
$ oShape ->setResizeProportional (true );
513
- $ oShape ->setOffsetX ($ oNodeFrame ->hasAttribute ('svg:x ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:x ' ), 0 , -2 ))) : '' );
514
- $ oShape ->setOffsetY ($ oNodeFrame ->hasAttribute ('svg:y ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:y ' ), 0 , -2 ))) : '' );
530
+ $ oShape ->setOffsetX ($ oNodeFrame ->hasAttribute ('svg:x ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:x ' ), 0 , -2 )) : 0 );
531
+ $ oShape ->setOffsetY ($ oNodeFrame ->hasAttribute ('svg:y ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:y ' ), 0 , -2 )) : 0 );
515
532
516
533
if ($ oNodeFrame ->hasAttribute ('draw:style-name ' )) {
517
534
$ keyStyle = $ oNodeFrame ->getAttribute ('draw:style-name ' );
@@ -535,10 +552,10 @@ protected function loadShapeRichText(DOMElement $oNodeFrame): void
535
552
$ oShape = $ this ->oPhpPresentation ->getActiveSlide ()->createRichTextShape ();
536
553
$ oShape ->setParagraphs ([]);
537
554
538
- $ oShape ->setWidth ($ oNodeFrame ->hasAttribute ('svg:width ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:width ' ), 0 , -2 ))) : '' );
539
- $ oShape ->setHeight ($ oNodeFrame ->hasAttribute ('svg:height ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:height ' ), 0 , -2 ))) : '' );
540
- $ oShape ->setOffsetX ($ oNodeFrame ->hasAttribute ('svg:x ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:x ' ), 0 , -2 ))) : '' );
541
- $ oShape ->setOffsetY ($ oNodeFrame ->hasAttribute ('svg:y ' ) ? ( int ) round ( CommonDrawing::centimetersToPixels (substr ($ oNodeFrame ->getAttribute ('svg:y ' ), 0 , -2 ))) : '' );
555
+ $ oShape ->setWidth ($ oNodeFrame ->hasAttribute ('svg:width ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:width ' ), 0 , -2 )) : 0 );
556
+ $ oShape ->setHeight ($ oNodeFrame ->hasAttribute ('svg:height ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:height ' ), 0 , -2 )) : 0 );
557
+ $ oShape ->setOffsetX ($ oNodeFrame ->hasAttribute ('svg:x ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:x ' ), 0 , -2 )) : 0 );
558
+ $ oShape ->setOffsetY ($ oNodeFrame ->hasAttribute ('svg:y ' ) ? CommonDrawing::centimetersToPixels (( float ) substr ($ oNodeFrame ->getAttribute ('svg:y ' ), 0 , -2 )) : 0 );
542
559
543
560
foreach ($ this ->oXMLReader ->getElements ('draw:text-box/* ' , $ oNodeFrame ) as $ oNodeParagraph ) {
544
561
$ this ->levelParagraph = 0 ;
@@ -565,6 +582,23 @@ protected function loadShapeRichText(DOMElement $oNodeFrame): void
565
582
protected function readParagraph (RichText $ oShape , DOMElement $ oNodeParent ): void
566
583
{
567
584
$ oParagraph = $ oShape ->createParagraph ();
585
+ if ($ oNodeParent ->hasAttribute ('text:style-name ' )) {
586
+ $ keyStyle = $ oNodeParent ->getAttribute ('text:style-name ' );
587
+ if (isset ($ this ->arrayStyles [$ keyStyle ])) {
588
+ if (!empty ($ this ->arrayStyles [$ keyStyle ]['spacingAfter ' ])) {
589
+ $ oParagraph ->setSpacingAfter ($ this ->arrayStyles [$ keyStyle ]['spacingAfter ' ]);
590
+ }
591
+ if (!empty ($ this ->arrayStyles [$ keyStyle ]['spacingBefore ' ])) {
592
+ $ oParagraph ->setSpacingBefore ($ this ->arrayStyles [$ keyStyle ]['spacingBefore ' ]);
593
+ }
594
+ if (!empty ($ this ->arrayStyles [$ keyStyle ]['lineSpacingMode ' ])) {
595
+ $ oParagraph ->setLineSpacingMode ($ this ->arrayStyles [$ keyStyle ]['lineSpacingMode ' ]);
596
+ }
597
+ if (!empty ($ this ->arrayStyles [$ keyStyle ]['lineSpacing ' ])) {
598
+ $ oParagraph ->setLineSpacing ($ this ->arrayStyles [$ keyStyle ]['lineSpacing ' ]);
599
+ }
600
+ }
601
+ }
568
602
$ oDomList = $ this ->oXMLReader ->getElements ('text:span ' , $ oNodeParent );
569
603
$ oDomTextNodes = $ this ->oXMLReader ->getElements ('text() ' , $ oNodeParent );
570
604
foreach ($ oDomTextNodes as $ oDomTextNode ) {
@@ -666,4 +700,32 @@ protected function loadStylesFile(): void
666
700
}
667
701
}
668
702
}
703
+
704
+ /**
705
+ * @param string $expr
706
+ *
707
+ * @return string
708
+ */
709
+ private function getExpressionUnit (string $ expr ): string
710
+ {
711
+ if (substr ($ expr , -1 ) == '% ' ) {
712
+ return '% ' ;
713
+ }
714
+
715
+ return substr ($ expr , -2 );
716
+ }
717
+
718
+ /**
719
+ * @param string $expr
720
+ *
721
+ * @return string
722
+ */
723
+ private function getExpressionValue (string $ expr ): string
724
+ {
725
+ if (substr ($ expr , -1 ) == '% ' ) {
726
+ return substr ($ expr , 0 , -1 );
727
+ }
728
+
729
+ return substr ($ expr , 0 , -2 );
730
+ }
669
731
}
0 commit comments