Gitlab CSE Unil
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
M. Chardon
moodle-assignfeedback_editpdfplus
Commits
303964cb
Commit
303964cb
authored
May 31, 2019
by
M. Chardon
Browse files
- maj fpdi et indépendance editpdf
- corrections caractères unicode dans les stamps
parent
84642d6f
Changes
55
Hide whitespace changes
Inline
Side-by-side
classes/document_services.php
View file @
303964cb
...
...
@@ -646,7 +646,7 @@ EOD;
$combined
=
$tmpdir
.
'/'
.
self
::
COMBINED_PDF_FILENAME
;
$file
->
copy_content_to
(
$combined
);
// Copy the file.
$pdf
=
new
dom
pdf
();
$pdf
=
new
pdf
();
$pagecount
=
$pdf
->
set_pdf
(
$combined
);
$grade
=
$assignment
->
get_user_grade
(
$userid
,
true
,
$attemptnumber
);
...
...
classes/pdf.php
View file @
303964cb
...
...
@@ -33,9 +33,11 @@ defined('MOODLE_INTERNAL') || die();
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/editpdf
plus
/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
;
...
...
@@ -254,6 +256,12 @@ class pdf extends \FPDI {
if
(
!
$this
->
filename
)
{
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);
...
...
@@ -456,9 +464,11 @@ class pdf extends \FPDI {
$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.
...
...
@@ -469,6 +479,7 @@ class pdf extends \FPDI {
$cartouche
=
$toolObject
->
cartridge
;
if
(
$annotation
->
textannot
)
{
$cartouche
.
=
' ['
.
$annotation_index
.
']'
;
//$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
);
}
...
...
dompdf/lib/php-css-parser/lib/Sabberworm/CSS/Value/Size.php
deleted
100644 → 0
View file @
84642d6f
<?php
namespace
Sabberworm\CSS\Value
;
class
Size
extends
PrimitiveValue
{
const
ABSOLUTE_SIZE_UNITS
=
'px/cm/mm/mozmm/in/pt/pc/vh/vw/vm/vmin/vmax/rem'
;
//vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport)
const
RELATIVE_SIZE_UNITS
=
'%/em/ex/ch/fr'
;
const
NON_SIZE_UNITS
=
'deg/grad/rad/s/ms/turns/Hz/kHz'
;
private
$fSize
;
private
$sUnit
;
private
$bIsColorComponent
;
public
function
__construct
(
$fSize
,
$sUnit
=
null
,
$bIsColorComponent
=
false
,
$iLineNo
=
0
)
{
parent
::
__construct
(
$iLineNo
);
$this
->
fSize
=
floatval
(
$fSize
);
$this
->
sUnit
=
$sUnit
;
$this
->
bIsColorComponent
=
$bIsColorComponent
;
}
public
function
setUnit
(
$sUnit
)
{
$this
->
sUnit
=
$sUnit
;
}
public
function
getUnit
()
{
return
$this
->
sUnit
;
}
public
function
setSize
(
$fSize
)
{
$this
->
fSize
=
floatval
(
$fSize
);
}
public
function
getSize
()
{
return
$this
->
fSize
;
}
public
function
isColorComponent
()
{
return
$this
->
bIsColorComponent
;
}
/**
* Returns whether the number stored in this Size really represents a size (as in a length of something on screen).
* @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object.
*/
public
function
isSize
()
{
if
(
in_array
(
$this
->
sUnit
,
explode
(
'/'
,
self
::
NON_SIZE_UNITS
)))
{
return
false
;
}
return
!
$this
->
isColorComponent
();
}
public
function
isRelative
()
{
if
(
in_array
(
$this
->
sUnit
,
explode
(
'/'
,
self
::
RELATIVE_SIZE_UNITS
)))
{
return
true
;
}
if
(
$this
->
sUnit
===
null
&&
$this
->
fSize
!=
0
)
{
return
true
;
}
return
false
;
}
public
function
__toString
()
{
return
$this
->
render
(
new
\
Sabberworm\CSS\OutputFormat
());
}
public
function
render
(
\
Sabberworm\CSS\OutputFormat
$oOutputFormat
)
{
$l
=
localeconv
();
$sPoint
=
preg_quote
(
$l
[
'decimal_point'
],
'/'
);
return
preg_replace
(
array
(
"/
$sPoint
/"
,
"/^(-?)0\./"
),
array
(
'.'
,
'$1.'
),
$this
->
fSize
)
.
(
$this
->
sUnit
===
null
?
''
:
$this
->
sUnit
);
}
}
fpdi/FpdfTpl.php
0 → 100755
View file @
303964cb
<?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
;
}
fpdi/FpdfTplTrait.php
0 → 100755
View file @
303964cb
<?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
;
/**
* Trait FpdfTplTrait
*
* This class adds a templating feature to tFPDF.
*
* @package setasign\Fpdi
*/
trait
FpdfTplTrait
{
/**
* Data of all created templates.
*
* @var array
*/
protected
$templates
=
[];
/**
* The template id for the currently created template.
*
* @var null|int
*/
protected
$currentTemplateId
;
/**
* A counter for template ids.
*
* @var int
*/
protected
$templateId
=
0
;
/**
* Set the page format of the current page.
*
* @param array $size An array with two values defining the size.
* @param string $orientation "L" for landscape, "P" for portrait.
* @throws \BadMethodCallException
*/
public
function
setPageFormat
(
$size
,
$orientation
)
{
if
(
$this
->
currentTemplateId
!==
null
)
{
throw
new
\
BadMethodCallException
(
'The page format cannot be changed when writing to a template.'
);
}
if
(
!
\
in_array
(
$orientation
,
[
'P'
,
'L'
],
true
))
{
throw
new
\
InvalidArgumentException
(
\
sprintf
(
'Invalid page orientation "%s"! Only "P" and "L" are allowed!'
,
$orientation
));
}
$size
=
$this
->
_getpagesize
(
$size
);
if
(
$orientation
!=
$this
->
CurOrientation
||
$size
[
0
]
!=
$this
->
CurPageSize
[
0
]
||
$size
[
1
]
!=
$this
->
CurPageSize
[
1
]
)
{
// New size or orientation
if
(
$orientation
===
'P'
)
{
$this
->
w
=
$size
[
0
];
$this
->
h
=
$size
[
1
];
}
else
{
$this
->
w
=
$size
[
1
];
$this
->
h
=
$size
[
0
];
}
$this
->
wPt
=
$this
->
w
*
$this
->
k
;
$this
->
hPt
=
$this
->
h
*
$this
->
k
;
$this
->
PageBreakTrigger
=
$this
->
h
-
$this
->
bMargin
;
$this
->
CurOrientation
=
$orientation
;
$this
->
CurPageSize
=
$size
;
$this
->
PageInfo
[
$this
->
page
][
'size'
]
=
array
(
$this
->
wPt
,
$this
->
hPt
);
}
}
/**
* Draws a template onto the page or another template.
*
* Give only one of the size parameters (width, height) to calculate the other one automatically in view to the
* aspect ratio.
*
* @param mixed $tpl The template id
* @param array|float|int $x The abscissa of upper-left corner. Alternatively you could use an assoc array
* with the keys "x", "y", "width", "height", "adjustPageSize".
* @param float|int $y The ordinate of upper-left corner.
* @param float|int|null $width The width.
* @param float|int|null $height The height.
* @param bool $adjustPageSize
* @return array The size
* @see FpdfTplTrait::getTemplateSize()
*/
public
function
useTemplate
(
$tpl
,
$x
=
0
,
$y
=
0
,
$width
=
null
,
$height
=
null
,
$adjustPageSize
=
false
)
{
if
(
!
isset
(
$this
->
templates
[
$tpl
]))
{
throw
new
\
InvalidArgumentException
(
'Template does not exist!'
);
}
if
(
\
is_array
(
$x
))
{
unset
(
$x
[
'tpl'
]);
\
extract
(
$x
,
EXTR_IF_EXISTS
);
/** @noinspection NotOptimalIfConditionsInspection */
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
if
(
\
is_array
(
$x
))
{
$x
=
0
;
}
}
$template
=
$this
->
templates
[
$tpl
];
$originalSize
=
$this
->
getTemplateSize
(
$tpl
);
$newSize
=
$this
->
getTemplateSize
(
$tpl
,
$width
,
$height
);
if
(
$adjustPageSize
)
{
$this
->
setPageFormat
(
$newSize
,
$newSize
[
'orientation'
]);
}
$this
->
_out
(
// reset standard values, translate and scale
\
sprintf
(
'q 0 J 1 w 0 j 0 G 0 g %.4F 0 0 %.4F %.4F %.4F cm /%s Do Q'
,
(
$newSize
[
'width'
]
/
$originalSize
[
'width'
]),
(
$newSize
[
'height'
]
/
$originalSize
[
'height'
]),
$x
*
$this
->
k
,
(
$this
->
h
-
$y
-
$newSize
[
'height'
])
*
$this
->
k
,
$template
[
'id'
]
)
);
return
$newSize
;
}
/**
* Get the size of a template.
*
* Give only one of the size parameters (width, height) to calculate the other one automatically in view to the
* aspect ratio.
*
* @param mixed $tpl The template id
* @param float|int|null $width The width.
* @param float|int|null $height The height.
* @return array|bool An array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P)
*/
public
function
getTemplateSize
(
$tpl
,
$width
=
null
,
$height
=
null
)
{
if
(
!
isset
(
$this
->
templates
[
$tpl
]))
{
return
false
;
}
if
(
$width
===
null
&&
$height
===
null
)
{
$width
=
$this
->
templates
[
$tpl
][
'width'
];
$height
=
$this
->
templates
[
$tpl
][
'height'
];
}
elseif
(
$width
===
null
)
{
$width
=
$height
*
$this
->
templates
[
$tpl
][
'width'
]
/
$this
->
templates
[
$tpl
][
'height'
];
}
if
(
$height
===
null
)
{
$height
=
$width
*
$this
->
templates
[
$tpl
][
'height'
]
/
$this
->
templates
[
$tpl
][
'width'
];
}
if
(
$height
<=
0.
||
$width
<=
0.
)
{
throw
new
\
InvalidArgumentException
(
'Width or height parameter needs to be larger than zero.'
);
}
return
[
'width'
=>
$width
,
'height'
=>
$height
,
0
=>
$width
,
1
=>
$height
,
'orientation'
=>
$width
>
$height
?
'L'
:
'P'
];
}
/**
* Begins a new template.
*
* @param float|int|null $width The width of the template. If null, the current page width is used.
* @param float|int|null $height The height of the template. If null, the current page height is used.
* @param bool $groupXObject Define the form XObject as a group XObject to support transparency (if used).
* @return int A template identifier.
*/
public
function
beginTemplate
(
$width
=
null
,
$height
=
null
,
$groupXObject
=
false
)
{
if
(
$width
===
null
)
{
$width
=
$this
->
w
;
}
if
(
$height
===
null
)
{
$height
=
$this
->
h
;
}
$templateId
=
$this
->
getNextTemplateId
();
// initiate buffer with current state of FPDF
$buffer
=
"2 J
\n
"
.
\
sprintf
(
'%.2F w'
,
$this
->
LineWidth
*
$this
->
k
)
.
"
\n
"
;
if
(
$this
->
FontFamily
)
{
$buffer
.
=
\
sprintf
(
"BT /F%d %.2F Tf ET
\n
"
,
$this
->
CurrentFont
[
'i'
],
$this
->
FontSizePt
);
}
if
(
$this
->
DrawColor
!==
'0 G'
)
{
$buffer
.
=
$this
->
DrawColor
.
"
\n
"
;
}
if
(
$this
->
FillColor
!==
'0 g'
)
{
$buffer
.
=
$this
->
FillColor
.
"
\n
"
;
}
if
(
$groupXObject
&&
\
version_compare
(
'1.4'
,
$this
->
PDFVersion
,
'>'
))
{
$this
->
PDFVersion
=
'1.4'
;
}
$this
->
templates
[
$templateId
]
=
[
'objectNumber'
=>
null
,
'id'
=>
'TPL'
.
$templateId
,
'buffer'
=>
$buffer
,
'width'
=>
$width
,
'height'
=>
$height
,
'groupXObject'
=>
$groupXObject
,
'state'
=>
[
'x'
=>
$this
->
x
,
'y'
=>
$this
->
y
,
'AutoPageBreak'
=>
$this
->
AutoPageBreak
,
'bMargin'
=>
$this
->
bMargin
,
'tMargin'
=>
$this
->
tMargin
,
'lMargin'
=>
$this
->
lMargin
,
'rMargin'
=>
$this
->
rMargin
,
'h'
=>
$this
->
h
,
'w'
=>
$this
->
w
,
'FontFamily'
=>
$this
->
FontFamily
,
'FontStyle'
=>
$this
->
FontStyle
,
'FontSizePt'
=>
$this
->
FontSizePt
,
'FontSize'
=>
$this
->
FontSize
,
'underline'
=>
$this
->
underline
,
'TextColor'
=>
$this
->
TextColor
,
'DrawColor'
=>
$this
->
DrawColor
,
'FillColor'
=>
$this
->
FillColor
,
'ColorFlag'
=>
$this
->
ColorFlag
]
];
$this
->
SetAutoPageBreak
(
false
);
$this
->
currentTemplateId
=
$templateId
;
$this
->
h
=
$height
;
$this
->
w
=
$width
;
$this
->
SetXY
(
$this
->
lMargin
,
$this
->
tMargin
);
$this
->
SetRightMargin
(
$this
->
w
-
$width
+
$this
->
rMargin
);
return
$templateId
;
}
/**
* Ends a template.
*
* @return bool|int|null A template identifier.
*/
public
function
endTemplate
()
{
if
(
null
===
$this
->
currentTemplateId
)
{
return
false
;
}
$templateId
=
$this
->
currentTemplateId
;
$template
=
$this
->
templates
[
$templateId
];
$state
=
$template
[
'state'
];
$this
->
SetXY
(
$state
[
'x'
],
$state
[
'y'
]);
$this
->
tMargin
=
$state
[
'tMargin'
];
$this
->
lMargin
=
$state
[
'lMargin'
];
$this
->
rMargin
=
$state
[
'rMargin'
];
$this
->
h
=
$state
[
'h'
];
$this
->
w
=
$state
[
'w'
];
$this
->
SetAutoPageBreak
(
$state
[
'AutoPageBreak'
],
$state
[
'bMargin'
]);
$this
->
FontFamily
=
$state
[
'FontFamily'
];
$this
->
FontStyle
=
$state
[
'FontStyle'
];
$this
->
FontSizePt
=
$state
[
'FontSizePt'
];
$this
->
FontSize
=
$state
[
'FontSize'
];
$this
->
TextColor
=
$state
[
'TextColor'
];
$this
->
DrawColor
=
$state
[
'DrawColor'
];
$this
->
FillColor
=
$state
[
'FillColor'
];
$this
->
ColorFlag
=
$state
[
'ColorFlag'
];
$this
->
underline
=
$state
[
'underline'
];
$fontKey
=
$this
->
FontFamily
.
$this
->
FontStyle
;
if
(
$fontKey
)
{
$this
->
CurrentFont
=&
$this
->
fonts
[
$fontKey
];
}
else
{
unset
(
$this
->
CurrentFont
);
}
$this
->
currentTemplateId
=
null
;
return
$templateId
;
}
/**
* Get the next template id.
*
* @return int
*/
protected
function
getNextTemplateId
()
{
return
$this
->
templateId
++
;
}
/* overwritten FPDF methods: */
/**
* @inheritdoc
*/
public
function
AddPage
(
$orientation
=
''
,
$size
=
''
,
$rotation
=
0
)
{
if
(
$this
->
currentTemplateId
!==
null
)
{
throw
new
\
BadMethodCallException
(
'Pages cannot be added when writing to a template.'
);
}
parent
::
AddPage
(
$orientation
,
$size
,
$rotation
);
}
/**
* @inheritdoc
*/
public
function
Link
(
$x
,
$y
,
$w
,
$h
,
$link
)
{
if
(
$this
->
currentTemplateId
!==
null
)
{
throw
new
\
BadMethodCallException
(
'Links cannot be set when writing to a template.'
);
}
parent
::
Link
(
$x
,
$y
,
$w
,
$h
,
$link
);
}
/**
* @inheritdoc
*/
public
function
SetLink
(
$link
,
$y
=
0
,
$page
=
-
1
)
{
if
(
$this
->
currentTemplateId
!==
null
)
{
throw
new
\
BadMethodCallException
(
'Links cannot be set when writing to a template.'
);
}
return
parent
::
SetLink
(
$link
,
$y
,
$page
);
}
/**
* @inheritdoc
*/
public
function
SetDrawColor
(
$r
,
$g
=
null
,
$b
=
null
)
{
parent
::
SetDrawColor
(
$r
,
$g
,
$b
);
if
(
$this
->
page
===
0
&&
$this
->
currentTemplateId
!==
null
)
{
$this
->
_out
(
$this
->
DrawColor
);
}
}
/**
* @inheritdoc
*/
public
function
SetFillColor
(
$r
,
$g
=
null
,
$b
=
null
)
{
parent
::
SetFillColor
(
$r
,
$g
,
$b
);
if
(
$this
->
page
===
0
&&
$this
->
currentTemplateId
!==
null
)
{
$this
->
_out
(
$this
->
FillColor
);
}
}
/**
* @inheritdoc
*/
public
function
SetLineWidth
(
$width
)
{
parent
::
SetLineWidth
(
$width
);
if
(
$this
->
page
===
0
&&
$this
->
currentTemplateId
!==
null
)
{
$this
->
_out
(
\
sprintf
(
'%.2F w'
,
$width
*
$this
->
k
));
}
}
/**
* @inheritdoc
*/
public
function
SetFont
(
$family
,
$style
=
''
,
$size
=
0
)
{
parent
::
SetFont
(
$family
,
$style
,
$size
);
if
(
$this
->
page
===
0
&&
$this
->
currentTemplateId
!==
null
)
{
$this
->
_out
(
\
sprintf
(
'BT /F%d %.2F Tf ET'
,
$this
->
CurrentFont
[
'i'
],
$this
->
FontSizePt
));
}
}
/**
* @inheritdoc
*/
public
function
SetFontSize
(
$size
)
{
parent
::
SetFontSize
(
$size
);
if
(
$this
->
page
===
0
&&
$this
->
currentTemplateId
!==
null
)
{
$this
->
_out
(
sprintf
(
'BT /F%d %.2F Tf ET'
,
$this
->
CurrentFont
[
'i'
],
$this
->
FontSizePt
));
}
}
/**
* @inheritdoc
*/
protected
function
_putimages
()
{
parent
::
_putimages
();
foreach
(
$this
->
templates
as
$key
=>
$template
)
{
$this
->
_newobj
();
$this
->
templates
[
$key
][
'objectNumber'
]
=
$this
->
n
;
$this
->
_put
(
'<</Type /XObject /Subtype /Form /FormType 1'
);
$this
->
_put
(
\
sprintf
(
'/BBox[0 0 %.2F %.2F]'
,
$template
[
'width'
]
*
$this
->
k
,
$template
[
'height'
]
*
$this
->
k
));
$this
->
_put
(
'/Resources 2 0 R'
);
// default resources dictionary of FPDF
if
(
$this
->
compress
)
{
$buffer
=
\
gzcompress
(
$template
[
'buffer'
]);
$this
->
_put
(
'/Filter/FlateDecode'
);
}
else
{
$buffer
=
$template
[
'buffer'
];
}
$this
->
_put
(
'/Length '
.
\
strlen
(
$buffer
));
if
(
$template
[
'groupXObject'
])
{
$this
->
_put
(
'/Group <</Type/Group/S/Transparency>>'
);
}
$this
->
_put
(
'>>'
);
$this
->
_putstream
(
$buffer
);
$this
->
_put
(
'endobj'
);
}
}
/**
* @inheritdoc
*/
protected
function
_putxobjectdict
()
{
foreach
(
$this
->
templates
as
$key
=>
$template
)
{
$this
->
_put
(
'/'
.
$template
[
'id'
]
.
' '
.
$template
[
'objectNumber'
]
.
' 0 R'
);
}
parent
::
_putxobjectdict
();
}
/**
* @inheritdoc
*/
public
function
_out
(
$s
)