Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBernskiold committed Feb 17, 2024
1 parent be81e22 commit ffbbd03
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
20 changes: 16 additions & 4 deletions src/Branding/Branding.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use function array_merge;
use function collect;
use function config;

class Branding
{
Expand Down Expand Up @@ -44,10 +45,21 @@ class Branding

public function __construct()
{
$this->baseFont = config('powerpoint.baseBranding.font', 'Calibri');
$this->creatorCompanyName = config('powerpoint.baseBranding.creatorCompanyName', '');
$this->websiteUrl = config('powerpoint.baseBranding.websiteUrl', '#');
$this->defaultChartColors = config('powerpoint.baseBranding.chartColors', 'ff000000');
if (empty($this->baseFont)) {
$this->baseFont = config('powerpoint.baseBranding.font', 'Calibri');
}

if (empty($this->creatorCompanyName)) {
$this->creatorCompanyName = config('powerpoint.baseBranding.creatorCompanyName', '');
}

if (empty($this->websiteUrl)) {
$this->websiteUrl = config('powerpoint.baseBranding.websiteUrl', '#');
}

if (empty($this->chartColors)) {
$this->defaultChartColors = config('powerpoint.baseBranding.chartColors', 'ff000000');
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Branding/SlideTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public function customMasterSlide(string $className): self
*/
public function applyToSlide(BaseSlide $slide): void
{
if ($this->backgroundColor && ! $slide->backgroundColor) {
if ($this->backgroundColor && $slide->backgroundColor === null) {
$slide->backgroundColor($this->backgroundColor);
}

if ($this->backgroundImage && ! $slide->backgroundImage) {
if ($this->backgroundImage && $slide->backgroundImage === null) {
$slide->backgroundImage($this->backgroundImage, true);
}

if ($this->chartBackgroundColor && ! $slide->chartBackgroundColor) {
if ($this->chartBackgroundColor && $slide->chartBackgroundColor === null) {
$slide->chartBackgroundColor($this->chartBackgroundColor);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/ChartShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function render(): static
$this->backgroundColor = $this->slide->chartBackgroundColor;
}

if ($this->backgroundColor) {
if (!empty($this->backgroundColor)) {
$this->shape->getFill()
->setFillType(Fill::FILL_SOLID)
->setStartColor(new Color($this->backgroundColor));
Expand Down
4 changes: 3 additions & 1 deletion src/Components/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Image extends Component
public function __construct(
protected string $path
) {
$this->shape = (new File())->setPath($path);
$this->shape = (new File())
->setPath($path)
->setName(str()->random());
}

public function render(): static
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use BernskioldMedia\LaravelPpt\Components\Component;
use BernskioldMedia\LaravelPpt\Concerns\Slides\WithFontSettings;
use BernskioldMedia\LaravelPpt\Concerns\Slides\WithShape;
use BernskioldMedia\LaravelPpt\Presentation\BaseSlide;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Font;

/**
* @method static static make(int $columns = 1, array $rows = [])
* @method static static make(BaseSlide $slide, int $columns = 1, array $rows = [])
*/
class Table extends Component
{
Expand Down
16 changes: 16 additions & 0 deletions src/Concerns/Slides/WithEdgeImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ trait WithEdgeImages

public function bottomLeftImage(string $path, int $width, int $height, ?int $x = null, ?int $y = null, ?string $url = null): self
{
if($this->bottomLeftImagePath) {
return $this;
}

$this->bottomLeftImagePath = $path;
$this->bottomLeftImageDimensions = ['width' => $width, 'height' => $height];

Expand All @@ -58,6 +62,10 @@ public function bottomLeftImage(string $path, int $width, int $height, ?int $x =

public function bottomRightImage(string $path, int $width, int $height, ?int $x = null, ?int $y = null, ?string $url = null): self
{
if($this->bottomRightImagePath) {
return $this;
}

$this->bottomRightImagePath = $path;
$this->bottomRightImageDimensions = ['width' => $width, 'height' => $height];

Expand All @@ -78,6 +86,10 @@ public function bottomRightImage(string $path, int $width, int $height, ?int $x

public function topLeftImage(string $path, int $width, int $height, ?int $x = null, ?int $y = null, ?string $url = null): self
{
if($this->topLeftImagePath) {
return $this;
}

$this->topLeftImagePath = $path;
$this->topLeftImageDimensions = ['width' => $width, 'height' => $height];

Expand All @@ -98,6 +110,10 @@ public function topLeftImage(string $path, int $width, int $height, ?int $x = nu

public function topRightImage(string $path, int $width, int $height, ?int $x = null, ?int $y = null, ?string $url = null): self
{
if($this->topRightImagePath) {
return $this;
}

$this->topRightImagePath = $path;
$this->topRightImageDimensions = ['width' => $width, 'height' => $height];

Expand Down
3 changes: 2 additions & 1 deletion src/Presentation/BaseSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ protected function applyEdgeImage(string $key): void
$shape->setPath($imagePath)
->setWidthAndHeight($imageDimensions['width'], $imageDimensions['height'])
->setOffsetX($x)
->setOffsetY($y);
->setOffsetY($y)
->setName(str()->random());

if ($url) {
$shape->getHyperlink()->setUrl($url);
Expand Down
7 changes: 5 additions & 2 deletions src/SlideMasters/ChartTitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ protected function render(): void
{
$title = $this->renderTitle();

$width = $this->chart->width ?? $this->presentation->width;
$height = $this->chart->height ?? $this->presentation->height;

ChartShape::make($this, $this->chart->slide($this)->get())
->height($this->presentation->height - $title->height - $this->verticalPadding * 2 - 20)
->width($this->presentation->width - $this->horizontalPadding * 2)
->height($height - $title->height - $this->verticalPadding * 2 - 20)
->width($width - $this->horizontalPadding * 2)
->centerHorizontally()
->y($title->height + $this->verticalPadding + 20)
->backgroundColor($this->chartBackgroundColor)
Expand Down

0 comments on commit ffbbd03

Please sign in to comment.