Skip to content

Commit

Permalink
Add default paper orientation to Options class
Browse files Browse the repository at this point in the history
  • Loading branch information
bsweeney committed Nov 25, 2016
1 parent 0df18ff commit d3769f4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public function __construct($options = null)
$this->localeStandard = sprintf('%.1f', 1.0) == '1.0';
$this->saveLocale();
$this->paperSize = $this->options->getDefaultPaperSize();
$this->paperOrientation = $this->options->getDefaultPaperOrientation();

$this->setCanvas(CanvasFactory::get_instance($this, $this->paperSize, $this->paperOrientation));
$this->setFontMetrics(new FontMetrics($this->getCanvas(), $this->getOptions()));
Expand Down Expand Up @@ -1036,6 +1037,33 @@ public function setPaper($size, $orientation = "portrait")
return $this;
}

/**
* Gets the paper size
*
* @return int[] A four-element integer array
*/
public function getPaperSize()
{
$size = $this->_paperSize;
if (is_array($size)) {
return $size;
} else if (isset(Adapter\CPDF::$PAPER_SIZES[mb_strtolower($size)])) {
return Adapter\CPDF::$PAPER_SIZES[mb_strtolower($size)];
} else {
return Adapter\CPDF::$PAPER_SIZES["letter"];
}
}

/**
* Gets the paper orientation
*
* @return string Either
*/
public function getPaperOrientation()
{
return $this->_paperOrientation;
}

/**
* @param FrameTree $tree
* @return $this
Expand Down
31 changes: 31 additions & 0 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ class Options
*/
private $defaultPaperSize = "letter";

/**
* The default paper orientation.
*
* The orientation of the page (portrait or landscape).
*
* @var string
*/
private $defaultPaperOrientation = "portrait";

/**
* The default font family
*
Expand Down Expand Up @@ -319,6 +328,8 @@ public function set($attributes, $value = null)
$this->setDefaultMediaType($value);
} elseif ($key === 'defaultPaperSize' || $key === 'default_paper_size') {
$this->setDefaultPaperSize($value);
} elseif ($key === 'defaultPaperOrientation' || $key === 'default_paper_orientation') {
$this->setDefaultPaperOrientation($value);
} elseif ($key === 'defaultFont' || $key === 'default_font') {
$this->setDefaultFont($value);
} elseif ($key === 'dpi') {
Expand Down Expand Up @@ -384,6 +395,8 @@ public function get($key)
return $this->getDefaultMediaType();
} elseif ($key === 'defaultPaperSize' || $key === 'default_paper_size') {
return $this->getDefaultPaperSize();
} elseif ($key === 'defaultPaperOrientation' || $key === 'default_paper_orientation') {
return $this->getDefaultPaperOrientation();
} elseif ($key === 'defaultFont' || $key === 'default_font') {
return $this->getDefaultFont();
} elseif ($key === 'dpi') {
Expand Down Expand Up @@ -708,6 +721,16 @@ public function setDefaultPaperSize($defaultPaperSize)
return $this;
}

/**
* @param string $defaultPaperOrientation
* @return $this
*/
public function setDefaultPaperOrientation($defaultPaperOrientation)
{
$this->defaultPaperOrientation = $defaultPaperOrientation;
return $this;
}

/**
* @return string
*/
Expand All @@ -716,6 +739,14 @@ public function getDefaultPaperSize()
return $this->defaultPaperSize;
}

/**
* @return string
*/
public function getDefaultPaperOrientation()
{
return $this->defaultPaperOrientation;
}

/**
* @param int $dpi
* @return $this
Expand Down

0 comments on commit d3769f4

Please sign in to comment.