Skip to content

Commit

Permalink
pdf display improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Marion Chardon committed May 31, 2019
1 parent 08aeb05 commit d84bac8
Show file tree
Hide file tree
Showing 62 changed files with 6,898 additions and 59 deletions.
3 changes: 3 additions & 0 deletions classes/bdd/annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class annotation {
/** @var string studentanswer */
public $studentanswer = "";

/** @var string pdfdisplay */
public $pdfdisplay = "footnote";

/**
* Convert a compatible stdClass into an instance of this class.
* @param stdClass $record
Expand Down
13 changes: 11 additions & 2 deletions classes/document_services.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ protected static function addAnnotationstoPDF($pdf, $pagecount, $gradeid) {

//add feedback by annotation
$pdf->SetAutoPageBreak(true);
$pdf->AddPage();
$pdf->AddPage('P', 'A4');
$pdf->SetTextColor(0, 0, 0);
$pdf->Write(10, "", '', false, 'L', true);
$pdf->SetFontSize(14);
Expand All @@ -750,7 +750,16 @@ protected static function addAnnotationstoPDF($pdf, $pagecount, $gradeid) {
if (!$annot->hasReadableComment()) {
continue;
}
$pdf->Write(5, $index, '', false, 'L', false);

//set link target to annotation's text
$pdf->SetLink($pdf->arrayLinks[$index], -1);
//create link source for annotation's display
$pdf->SetTextColor(0, 0, 255);
$pdf->SetFont('', 'U');
$pdf->Write(5, $index, $pdf->arrayLinksOrigi[$index], false, 'L', false);
$pdf->SetFont('', '');
$pdf->SetTextColor(0, 0, 0);

if ($annot->studentstatus === "2") {
$pdf->SetTextColor(255, 0, 0);
$pdf->Write(5, '*', '', false, 'L', false);
Expand Down
45 changes: 40 additions & 5 deletions classes/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

global $CFG;
require_once($CFG->libdir . '/pdflib.php');
require_once($CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/fpdi.php');
require_once($CFG->dirroot . '/mod/assign/feedback/editpdfplus/fpdi/autoload.php');

class pdf extends \FPDI {
use \setasign\Fpdi\Tcpdf\Fpdi;

class pdf extends Fpdi {

/** @var int the number of the current page in the PDF being processed */
protected $currentpage = 0;
Expand All @@ -48,6 +50,8 @@ class pdf extends \FPDI {

/** @var string the path to the PDF currently being processed */
protected $filename = null;
public $arrayLinks = array();
public $arrayLinksOrigi = array();

/** No errors */
const GSPATH_OK = 'ok';
Expand Down Expand Up @@ -255,6 +259,12 @@ public function add_annotation(bdd\annotation $annotation, $path, $annotation_in
return false;
}

//check tcpdf cache directory, needed for image transformation
if (!file_exists(K_PATH_CACHE)) {
//try to create the directory
mkdir(K_PATH_CACHE, 0777, true);
}

$colour = $annotation->colour;
$colourarray = utils_color::getColorRGB($colour); //$this->get_colour_for_pdf($colour);
$this->SetDrawColorArray($colourarray);
Expand Down Expand Up @@ -456,9 +466,11 @@ public function add_annotation(bdd\annotation $annotation, $path, $annotation_in
$this->SetTextColorArray($colourcartridgearray);

$cartouche = $toolObject->label;
//$this->Cell($w);

//Texte centré dans une cellule 20*10 mm encadrée et retour à la ligne
$this->SetFont('freeserif', '', 10);
$this->Cell(strlen($cartouche) * 6 + 4, 10, $cartouche, 1, 1, 'C');
$this->SetFont($this->get_export_font_name());

break;
default: // Line.
Expand All @@ -468,9 +480,32 @@ public function add_annotation(bdd\annotation $annotation, $path, $annotation_in
if ($type == 'commentplus' || $type == 'stampcomment' || ($type == 'frame' && !$annotation->parent_annot) || $type == 'verticalline' || $type == 'highlightplus') {
$cartouche = $toolObject->cartridge;
if ($annotation->textannot) {
$cartouche .= ' [' . $annotation_index . ']';
if ($annotation->pdfdisplay === "inline") {
$cartouche .= ' | ' . $annotation->textannot;
}
$this->Write(5, $cartouche . ' [');

//create link source for annotation's text
$link = $this->addLink();
$this->SetTextColor(0, 0, 255);
$this->SetFont('', 'U');
$this->Write(5, $annotation_index, $link);
$this->SetTextColorArray($colourcartridgearray);
$this->SetFont('', '');
$this->arrayLinks[$annotation_index] = $link;

$this->Write(5, ']');

//create link target to go back to the annotation display
$linkorigi = $this->addLink();
$this->setLink($linkorigi, -1);
$this->arrayLinksOrigi[$annotation_index] = $linkorigi;

//$this->Annotation($sx + 50, $sy, 30, 30, $annotation->textannot, array('Subtype' => 'Text', 'Name' => 'Comment', 'T' => $toolObject->label, 'Subj' => 'example', 'C' => $colourarray));
}
$this->Write(5, $cartouche);

//$html = '&nbsp;<a href="#annot' . $annotation_index . '" style="color:red;">' . '[#annot' . $annotation_index . ']' . '</a>';
//$this->writeHTML($html);
}

$this->SetDrawColor(0, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<FIELD NAME="displayrotation" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="borderstyle" TYPE="char" LENGTH="20" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="parent_annot" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="pdfdisplay" TYPE="char" LENGTH="20" NOTNULL="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
13 changes: 13 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,18 @@ function xmldb_assignfeedback_editpdfplus_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019052400, 'assignfeedback', 'editpdfplus');
}

if ($oldversion < 2019053100) {
/* annotation table */
$table = new xmldb_table('assignfeedback_editpp_annot');
$field = new xmldb_field('pdfdisplay', XMLDB_TYPE_CHAR, '20', null,
XMLDB_NOTNULL, null, 'footnote', 'parent_annot');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Editpdfplus savepoint reached.
upgrade_plugin_savepoint(true, 2019053100, 'assignfeedback', 'editpdfplus');
}

return true;
}
20 changes: 0 additions & 20 deletions editpdfplus.patch

This file was deleted.

22 changes: 22 additions & 0 deletions fpdi/FpdfTpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* This file is part of FPDI
*
* @package setasign\Fpdi
* @copyright Copyright (c) 2019 Setasign - Jan Slabon (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/

namespace setasign\Fpdi;

/**
* Class FpdfTpl
*
* This class adds a templating feature to FPDF.
*
* @package setasign\Fpdi
*/
class FpdfTpl extends \FPDF
{
use FpdfTplTrait;
}
Loading

0 comments on commit d84bac8

Please sign in to comment.