/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS LINESTRING object * @param string $label Label for the GIS LINESTRING object * @param string $line_color Color for the GIS LINESTRING object * @param array $scale_data Array containing data related to scaling * @param object $pdf TCPDF instance * * @return object the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { // allocate colors $red = hexdec(substr($line_color, 1, 2)); $green = hexdec(substr($line_color, 3, 2)); $blue = hexdec(substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'LINESTRING(' and trailing ')' $linesrting = substr($spatial, 11, strlen($spatial) - 12); $points_arr = $this->extractPoints($linesrting, $scale_data); foreach ($points_arr as $point) { if (!isset($temp_point)) { $temp_point = $point; } else { // draw line section $pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line); $temp_point = $point; } } // print label if (isset($label) && trim($label) != '') { $pdf->SetXY($points_arr[1][0], $points_arr[1][1]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } return $pdf; }
/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS POLYGON object * @param string $label Label for the GIS POLYGON object * @param string $fill_color Color for the GIS POLYGON object * @param array $scale_data Array containing data related to scaling * @param object $pdf TCPDF instance * * @return object the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf) { // allocate colors $red = hexdec(substr($fill_color, 1, 2)); $green = hexdec(substr($fill_color, 3, 2)); $blue = hexdec(substr($fill_color, 4, 2)); $color = array($red, $green, $blue); // Trim to remove leading 'POLYGON((' and trailing '))' $polygon = substr($spatial, 9, strlen($spatial) - 11); // If the polygon doesnt have an inner polygon if (strpos($polygon, "),(") === false) { $points_arr = $this->extractPoints($polygon, $scale_data, true); } else { // Seperate outer and inner polygons $parts = explode("),(", $polygon); $outer = $parts[0]; $inner = array_slice($parts, 1); $points_arr = $this->extractPoints($outer, $scale_data, true); foreach ($inner as $inner_poly) { $points_arr = array_merge($points_arr, $this->extractPoints($inner_poly, $scale_data, true)); } } // draw polygon $pdf->Polygon($points_arr, 'F*', array(), $color, true); // print label if applicable if (isset($label) && trim($label) != '') { $pdf->SetXY($points_arr[2], $points_arr[3]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } return $pdf; }
/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS MULTIPOINT object * @param string $label Label for the GIS MULTIPOINT object * @param string $point_color Color for the GIS MULTIPOINT object * @param array $scale_data Array containing data related to scaling * @param object $pdf TCPDF instance * * @return object the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf) { // allocate colors $red = hexdec(substr($point_color, 1, 2)); $green = hexdec(substr($point_color, 3, 2)); $blue = hexdec(substr($point_color, 4, 2)); $line = array('width' => 1.25, 'color' => array($red, $green, $blue)); // Trim to remove leading 'MULTIPOINT(' and trailing ')' $multipoint = substr($spatial, 11, strlen($spatial) - 12); $points_arr = $this->extractPoints($multipoint, $scale_data); foreach ($points_arr as $point) { // draw a small circle to mark the point if ($point[0] != '' && $point[1] != '') { $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line); } } // print label for each point if (isset($label) && trim($label) != '' && ($points_arr[0][0] != '' && $points_arr[0][1] != '')) { $pdf->SetXY($points_arr[0][0], $points_arr[0][1]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } return $pdf; }
/** * Adds to the TCPDF instance, the data related to a row in the GIS dataset. * * @param string $spatial GIS MULTILINESTRING object * @param string $label Label for the GIS MULTILINESTRING object * @param string $line_color Color for the GIS MULTILINESTRING object * @param array $scale_data Array containing data related to scaling * @param object $pdf TCPDF instance * * @return object the modified TCPDF instance * @access public */ public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf) { // allocate colors $red = hexdec(substr($line_color, 1, 2)); $green = hexdec(substr($line_color, 3, 2)); $blue = hexdec(substr($line_color, 4, 2)); $line = array('width' => 1.5, 'color' => array($red, $green, $blue)); // Trim to remove leading 'MULTILINESTRING((' and trailing '))' $multilinestirng = substr($spatial, 17, strlen($spatial) - 19); // Seperate each linestring $linestirngs = explode("),(", $multilinestirng); $first_line = true; foreach ($linestirngs as $linestring) { $points_arr = $this->extractPoints($linestring, $scale_data); foreach ($points_arr as $point) { if (!isset($temp_point)) { $temp_point = $point; } else { // draw line section $pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line); $temp_point = $point; } } unset($temp_point); // print label if (isset($label) && trim($label) != '' && $first_line) { $pdf->SetXY($points_arr[1][0], $points_arr[1][1]); $pdf->SetFontSize(5); $pdf->Cell(0, 0, trim($label)); } $first_line = false; } return $pdf; }
/** * Add relevant header info to the pdf output * * @param object $newpdf The report pdf we are creating */ public function print_pdf_header($newpdf) { global $CFG; //obtain margins $margins = $newpdf->getMargins(); //initial y position $initial_y = $newpdf->getY() + 0.08; // ELIS-3167: + 0.08 bottom-of-line //determine page with, not including margins $effective_page_width = $newpdf->getPageWidth() - $margins['left'] - $margins['right']; //store the original font size $old_font_size = $newpdf->getFontSizePt(); //use a large font size for the header info $newpdf->setFontSize(12); //used to track vertical positioning $i = 0; //render any appropriate text for each header if ($header_info = $this->get_gas_gauge_header_info()) { foreach ($header_info as $header_entry) { //render across $newpdf->Cell($effective_page_width, 0, $header_entry, 0, 0, 'C'); //draw a line below the text $line_top = $initial_y + 0.2 * $i + 0.1; $newpdf->Line($margins['left'], $line_top, $margins['left'] + $effective_page_width, $line_top); //add necessary spacing $newpdf->Ln(0.2); $i++; } } //if the max value is not zero, render the gas gauge if ($this->gas_gauge_max_value != 0) { //retrieve the color palette as defined by the report $palette = $this->get_gas_gauge_color_palette(); //approximate pixels using points $actual_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH / 2 / 72; //set up the variables needed by the gas-gauge-generating script //current value on the gas gauge $passthru_value = $this->gas_gauge_value; //maximum value on the gauge $passthru_total = $this->gas_gauge_max_value; //radius of the gas gauge $passthru_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH; //colour palette to use (also specifies number of sections) $passthru_palette = $palette; //indicate that we are persisting the image $passthru_persist = 1; //filename to save the image to $passthru_filename = tempnam($CFG->dataroot . '/temp', 'gas_gauge_'); //generate the necessary image file $gas_gauge_url = $CFG->dirroot . '/local/elisreports/gas_gauge_output.php'; require_once($gas_gauge_url); //leftmost position of the gas gauge $left_position = $newpdf->getPageWidth() / 2 - $actual_radius; //vertical offset, based on number of headers $top_position = $initial_y + 0.2 * count($header_info) + 0.1; //draw the gas gauge and add appropriate vertical space $newpdf->Image($passthru_filename, $left_position, $top_position, 2 * $actual_radius, $actual_radius, 'png'); $newpdf->Ln($actual_radius + 0.2); //delete the temporary image file unlink($passthru_filename); } //revert the font size to its initial value $newpdf->setFontSize($old_font_size); }
/** * Displays the items in the $items array as a bulleted or ordered list * * @param array $items * @param array $options * @param bool $ordered */ public static function alist(array $items, $options = array(), $ordered = false) { //Save x $bak_x = $pdf->x; if ($ordered) { $bullet = '•'; } else { $bullet = 1; } for ($i = 0; $i < count($items); $i++) { //Get bullet width including margin $blt_width = self::$pdf->GetStringWidth($bullet . $options['margin']) + self::$pdf->cMargin * 2; // SetX self::$pdf->SetX($bak_x); //Output indent if ($options['indent'] > 0) { self::$pdf->Cell($options['indent']); } //Output bullet self::$pdf->Cell($blt_width, $h, $bullet . $options['margin'], 0, '', $fill); $items[$i] = self::decode_utf8($items[$i]); //Output text self::$pdf->MultiCell($w - $blt_width, $h, $items[$i], $border, $align, $fill); //Insert a spacer between items if not the last item if ($i != count($items) - 1) { self::$pdf->Ln($options['spacer']); } //Increment bullet if it's a number if (is_numeric($bullet)) { $bullet++; } } //Restore x self::$pdf->x = $bak_x; return $pdf; }