Created
February 23, 2018 22:48
-
-
Save alphp/b9fd0a7487c1377562a6fe54de47b4f6 to your computer and use it in GitHub Desktop.
New implementation of SetDrawColor, SetFillColor and SetTextColor for FPDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function SetDrawColor() { | |
$args = func_get_args(); | |
if (count($args) and is_array($args[0])) { | |
$args = $args[0]; | |
} | |
switch (count($args)) { | |
case 1: | |
$this->DrawColor = sprintf('%.3f G', $args[0] / 100); | |
break; | |
case 3: | |
$this->DrawColor = sprintf('%.3f %.3f %.3f RG', $args[0] / 255, $args[1] / 255, $args[2] / 255); | |
break; | |
case 4: | |
$this->DrawColor = sprintf('%.3f %.3f %.3f %.3f K', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); | |
break; | |
default: | |
$this->DrawColor = '0 G'; | |
} | |
if ($this->page > 0) { | |
$this->_out($this->DrawColor); | |
} | |
} | |
public function SetFillColor () { | |
$args = func_get_args(); | |
if (count($args) and is_array($args[0])) { | |
$args = $args[0]; | |
} | |
switch (count($args)) { | |
case 1: | |
$this->FillColor = sprintf('%.3f g', $args[0] / 100); | |
break; | |
case 3: | |
$this->FillColor = sprintf('%.3f %.3f %.3f rg', $args[0] / 255, $args[1] / 255, $args[2] / 255); | |
break; | |
case 4: | |
$this->FillColor = sprintf('%.3f %.3f %.3f %.3f k', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); | |
break; | |
default: | |
$this->FillColor = '0 g'; | |
} | |
$this->ColorFlag = ($this->FillColor != $this->TextColor); | |
if ($this->page > 0) { | |
$this->_out($this->FillColor); | |
} | |
} | |
public function SetTextColor () { | |
//Set color for text | |
$args = func_get_args(); | |
if (count($args) and is_array($args[0])) { | |
$args = $args[0]; | |
} | |
switch (count($args)) { | |
case 1: | |
$this->TextColor = sprintf('%.3f g', $args[0] / 100); | |
break; | |
case 3: | |
$this->TextColor = sprintf('%.3f %.3f %.3f rg', $args[0] / 255, $args[1] / 255, $args[2] / 255); | |
break; | |
case 4: | |
$this->TextColor = sprintf('%.3f %.3f %.3f %.3f k', $args[0] / 100, $args[1] / 100, $args[2] / 100, $args[3] / 100); | |
break; | |
default: | |
$this->TextColor = '0 g'; | |
} | |
$this->ColorFlag = ($this->FillColor != $this->TextColor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment