From b21142fecf54a992e9e783cb5964992b0005c781 Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Fri, 19 Oct 2018 14:46:23 +0200 Subject: [PATCH 1/4] Certificate Order --- resources/latex/template.tex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/latex/template.tex b/resources/latex/template.tex index 0e3faf7dd..396f3d082 100644 --- a/resources/latex/template.tex +++ b/resources/latex/template.tex @@ -1,6 +1,7 @@ \documentclass[12pt]{article} +\usepackage[T2A,T1]{fontenc} \usepackage[utf8]{inputenc} -\usepackage[russian,english]{babel} +\usepackage[english, russian]{babel} \usepackage{mathpazo} \renewcommand{\familydefault}{\rmdefault} \usepackage[landscape,a4paper]{geometry} @@ -11,7 +12,6 @@ \usepackage{graphicx} \usepackage{url} \usepackage{eso-pic} -\usepackage[T2A,T1]{fontenc} \usepackage{textcomp} \newcommand\BackgroundPic{% @@ -49,9 +49,9 @@ } \vspace{0.4cm} - -\Huge{that \textbf{ -}} +\begin{otherlanguage*}{russian} +\Huge{that \textbf{}} +\end{otherlanguage*} \vspace{0.4cm} From 8eede150eb6220643e4a01c952c13dcbb45899bc Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Fri, 19 Oct 2018 15:00:09 +0200 Subject: [PATCH 2/4] cyrillic --- resources/latex/template.tex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/latex/template.tex b/resources/latex/template.tex index 396f3d082..b52b453f9 100644 --- a/resources/latex/template.tex +++ b/resources/latex/template.tex @@ -1,7 +1,7 @@ \documentclass[12pt]{article} \usepackage[T2A,T1]{fontenc} \usepackage[utf8]{inputenc} -\usepackage[english, russian]{babel} +\usepackage[greek,russian,english]{babel} \usepackage{mathpazo} \renewcommand{\familydefault}{\rmdefault} \usepackage[landscape,a4paper]{geometry} @@ -13,6 +13,11 @@ \usepackage{url} \usepackage{eso-pic} \usepackage{textcomp} +\usepackage{paratype} % tlmgr install paratype +\usepackage{tgpagella} + +\usepackage{substitutefont} +\substitutefont{T2A}{\rmdefault}{PTSerif-TLF} \newcommand\BackgroundPic{% \put(0,0){% From 94e9f078b530c653b224233f5dbc6b1761a5c6e9 Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Fri, 19 Oct 2018 16:58:31 +0200 Subject: [PATCH 3/4] Greek template --- app/Certificate.php | 39 ++++++++--- resources/latex/template.tex | 2 +- resources/latex/template_greek.tex | 106 +++++++++++++++++++++++++++++ tests/Feature/ReportEventTest.php | 58 ++++++++++++++++ 4 files changed, 193 insertions(+), 12 deletions(-) create mode 100644 resources/latex/template_greek.tex diff --git a/app/Certificate.php b/app/Certificate.php index db7399c44..ab66ff06e 100644 --- a/app/Certificate.php +++ b/app/Certificate.php @@ -4,6 +4,7 @@ use Carbon\Carbon; +use Log; use Illuminate\Support\Facades\Storage; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; @@ -35,7 +36,7 @@ public function generate() $this->customize_and_save_latex(); $this->run_pdf_creation(); - $s3path = $this->copy_to_s3(); + $s3path = $this->copy_to_s3(); $this->update_event($s3path); $this->clean_temp_files(); @@ -44,11 +45,26 @@ public function generate() } - private function clean_temp_files(){ - Storage::disk('latex')->delete($this->event->id.".aux"); - Storage::disk('latex')->delete($this->event->id.".tex"); - Storage::disk('latex')->delete($this->event->id.".pdf"); - Storage::disk('latex')->delete($this->event->id.".log"); + private function clean_temp_files() + { + Storage::disk('latex')->delete($this->event->id . ".aux"); + Storage::disk('latex')->delete($this->event->id . ".tex"); + Storage::disk('latex')->delete($this->event->id . ".pdf"); + Storage::disk('latex')->delete($this->event->id . ".log"); + } + + public function is_greek() + { + + $split = preg_split('/[\p{Greek}]/u', $this->name_of_certificate_holder); + if (count($split) > 1) { + Log::info("Detected as Greek: " . $this->name_of_certificate_holder); + return true; + } + + return false; + + } private function tex_escape($string) @@ -74,9 +90,10 @@ function ($matches) use ($map) { , $string); } - protected function update_event($s3path){ + protected function update_event($s3path) + { $this->event->update([ - "certificate_url"=>$s3path, + "certificate_url" => $s3path, "certificate_generated_at" => Carbon::now() ]); } @@ -87,7 +104,7 @@ protected function update_event($s3path){ */ protected function copy_to_s3(): string { - $inputStream = Storage::disk('latex')->getDriver()->readStream( $this->event->id . '.pdf'); + $inputStream = Storage::disk('latex')->getDriver()->readStream($this->event->id . '.pdf'); $destination = Storage::disk('s3')->getDriver()->getAdapter()->getPathPrefix() . '/certificates/' . $this->id . '.pdf'; Storage::disk('s3')->getDriver()->putStream($destination, $inputStream); @@ -100,6 +117,8 @@ protected function copy_to_s3(): string */ protected function customize_and_save_latex() { + if ($this->is_greek()) $this->templateName = "template_greek.tex"; + Log::info($this->templateName); //open the latex template $base_template = Storage::disk('latex')->get($this->templateName); @@ -130,6 +149,4 @@ protected function run_pdf_creation(): void } - - } \ No newline at end of file diff --git a/resources/latex/template.tex b/resources/latex/template.tex index b52b453f9..72932d3b4 100644 --- a/resources/latex/template.tex +++ b/resources/latex/template.tex @@ -13,7 +13,7 @@ \usepackage{url} \usepackage{eso-pic} \usepackage{textcomp} -\usepackage{paratype} % tlmgr install paratype +\usepackage{paratype} \usepackage{tgpagella} \usepackage{substitutefont} diff --git a/resources/latex/template_greek.tex b/resources/latex/template_greek.tex new file mode 100644 index 000000000..212743ba2 --- /dev/null +++ b/resources/latex/template_greek.tex @@ -0,0 +1,106 @@ +\documentclass[12pt]{article} +\usepackage[T1,LGR,T2A]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage[greek,russian,english]{babel} +\usepackage{mathpazo} +\renewcommand{\familydefault}{\rmdefault} +\usepackage[landscape,a4paper]{geometry} +\geometry{verbose,tmargin=0cm,bmargin=0cm,lmargin=3cm,rmargin=3cm} +\usepackage{fancybox} +\usepackage{calc} +\usepackage{multicol} +\usepackage{graphicx} +\usepackage{url} +\usepackage{eso-pic} +\usepackage{textcomp} +\usepackage{paratype} +\usepackage{tgpagella} + +\usepackage{substitutefont} +\substitutefont{T2A}{\rmdefault}{PTSerif-TLF} +\substitutefont{LGR}{\rmdefault}{udidot} + +\newcommand\BackgroundPic{% +\put(0,0){% +\parbox[b][\paperheight]{\paperwidth}{% +\vfill +\centering +\includegraphics[width=\paperwidth,height=\paperheight,% +keepaspectratio]{images/background.png}% +\vfill +}}} + + +\begin{document} +\AddToShipoutPicture{\BackgroundPic} +~ +\vspace{1.2cm} +~ +\begin{center} + +\begin{table}[h] +\footnotesize +\begin{center} +\begin{tabular}{lr} +%~\hspace{0.7cm} +\includegraphics[height=3.4cm]{images/codeweek_logo.png} +\includegraphics[height=3.4cm]{images/european_commission_logo.png} +\end{tabular} +\end{center} +\end{table} +\vspace{-0.2cm} +\LARGE{CodeWeek EU organisers are honoured\\ +\vspace{1cm} +\fontsize{50}{60}{\textbf{TO CERTIFY}} +} + +\vspace{0.4cm} +\begin{otherlanguage*}{greek} +\Huge{that \textbf{}} +\end{otherlanguage*} + +\vspace{0.4cm} + +\Huge{actively contributed to the success of} + +\vspace{0.3cm} + +\Huge{\textbf{EUROPE CODE WEEK 2018}} + +\vspace{0.3cm} + +\Large{by running a coding event.} + +\vspace{.2cm} + +\vspace{1cm} + +\begin{table}[h] +\footnotesize +\begin{center} + +\end{center} +\end{table} + +\vspace{-3cm} +\end{center} +\begin{table}[h] +\footnotesize +\begin{center} +\begin{tabular}{lr} +%~\hspace{0.7cm} +\includegraphics[height=2.5cm]{images/signature_and_stamp.png} +\end{tabular} +\end{center} +\end{table} +\vspace{-2.2cm} +\begin{center} +\footnotesize{On behalf of Europe Code Week Ambassadors}\\ +%\end{tabular} + +%Diploma elaborado con el software libre \texttt{Pyploma}, (c) +%\url{fjruizruano@gmail.com} bajo licencia +%GPLv3. Visite: \url{http://code.google.com/p/pyploma} + +\end{center} +\end{document} diff --git a/tests/Feature/ReportEventTest.php b/tests/Feature/ReportEventTest.php index a37b7a9df..41e063196 100644 --- a/tests/Feature/ReportEventTest.php +++ b/tests/Feature/ReportEventTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Certificate; use App\Event; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseMigrations; @@ -158,6 +159,63 @@ public function user_should_see_list_of_his_reportable_events(){ ; } + /** @test */ + public function text_should_not_be_detected_as_greek(){ + + $certificate = new Certificate($this->event); + $this->assertFalse($certificate->is_greek()); + + } + + /** @test */ + public function text_should_be_detected_as_greek(){ + + $this->event->name_for_certificate = "Λιανού Κυριακή - Lianou Kiriaki 10ο Δημοτικό Σχολείο Αιγάλεω"; + $certificate = new Certificate($this->event); + $this->asserttrue($certificate->is_greek()); + + + } + + /** @test */ + public function text_should_be_detected_as_greek_with_all_uppercase(){ + + $this->event->name_for_certificate = "ΖΑΧΑΡΩΦ ΣΟΝΙΑ"; + $certificate = new Certificate($this->event); + $this->asserttrue($certificate->is_greek()); + + + } + + /** @test */ + public function text_should_be_detected_as_greek_with_one_greek_char(){ + + $this->event->name_for_certificate = "This is a Σ"; + $certificate = new Certificate($this->event); + $this->asserttrue($certificate->is_greek()); + + + } + + /** @test */ + public function text_should_not_be_detected_as_greek_with_one_special_char(){ + + $this->event->name_for_certificate = "Teacher Di Lella Lucia and the 1D con l’evento “Di Pixel in Pixel.. cosa apparirà?:stuck_out_tongue_winking_eye:"; + $certificate = new Certificate($this->event); + $this->assertfalse($certificate->is_greek()); + + + } + + /** @test */ + public function text_should_not_be_detected_as_greek_with_several_special_chars(){ + + $this->event->name_for_certificate = 'Nemyriv Educational Establishment "Comprehensive Shool of I-III grades №2-lyceum" - of Nemyriv town Concil Vinnytsia Region'; + $certificate = new Certificate($this->event); + $this->assertfalse($certificate->is_greek()); + + } + } From 086712fc6ad6230b92d95e6e3a2a9e3d34815bba Mon Sep 17 00:00:00 2001 From: Alain Van Driessche Date: Fri, 19 Oct 2018 17:07:49 +0200 Subject: [PATCH 4/4] Greek part only --- resources/latex/template.tex | 6 +++++- resources/latex/template_greek.tex | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/resources/latex/template.tex b/resources/latex/template.tex index 72932d3b4..399a553eb 100644 --- a/resources/latex/template.tex +++ b/resources/latex/template.tex @@ -54,9 +54,13 @@ } \vspace{0.4cm} + +\Huge{that \begin{otherlanguage*}{russian} -\Huge{that \textbf{}} +\textbf{} \end{otherlanguage*} +} + \vspace{0.4cm} diff --git a/resources/latex/template_greek.tex b/resources/latex/template_greek.tex index 212743ba2..8e83ea33c 100644 --- a/resources/latex/template_greek.tex +++ b/resources/latex/template_greek.tex @@ -54,10 +54,13 @@ \fontsize{50}{60}{\textbf{TO CERTIFY}} } -\vspace{0.4cm} + +\Huge{that \begin{otherlanguage*}{greek} -\Huge{that \textbf{}} +\textbf{} \end{otherlanguage*} +} + \vspace{0.4cm}