From d5c9438f7229b82f25e0c6e319379fda735fa256 Mon Sep 17 00:00:00 2001 From: soufiane Date: Fri, 22 Mar 2024 18:36:59 +0100 Subject: [PATCH] wip #6788 @14:00 --- .../FluidbookPublication/LinksOperation.php | 38 +++++++++++++++++++ .../linkeditor/js/linkeditor.accessControl.js | 4 +- resources/linkeditor/js/linkeditor.links.js | 25 ++++++++++-- .../link_editor.blade.php | 3 +- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php index 169af7ade..b2229f9d6 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php @@ -10,6 +10,8 @@ use App\Models\FluidbookPublication; use App\Models\User; use Cubist\Backpack\Http\Controllers\Base\XSendFileController; use Cubist\Util\Files\Files; +use Fluidbook\Tools\Links\Link; +use Fluidbook\Tools\Links\TextLink; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Route; @@ -18,6 +20,7 @@ use Illuminate\Support\Facades\Broadcast; use Illuminate\Support\Str; use Illuminate\Http\Request; use Prologue\Alerts\Facades\Alert; +use Fluidbook\Tools\FluidbookFontToWoff; trait LinksOperation @@ -45,6 +48,8 @@ trait LinksOperation // ->whereIn('type', ['raster', 'images', 'texts', 'vector']) ->whereNumber('page'); //->whereIn('format', ['jpg', 'png', 'avif', 'webp', 'svg']); + + Route::post($segment . '/{id}/generatefont', $controller . '@generateFont'); } protected function getLinkAsset($fluidbook_id, $file) @@ -80,6 +85,39 @@ trait LinksOperation return response()->json(['assets' => $fb->getLinksAssetsDimensions(), 'versions' => LinksData::getLinksVersions($fluidbook_id)]); } + protected function generateFont(Request $request, $id) { + $l = $request->links; + $textLinks = array_filter($l, function($n) { + return $n['type'] === '35'; + }); + $rulers = $request->rulers; + $fb = FluidbookPublication::find($id); + $wdir = $fb->protected_path('fluidbookpublication/working/'.$id).'/'; + $css = []; + $w = round($fb->getPageWidth(), 8); + $h = round($fb->getPageHeight(), 8); + + foreach ($textLinks as $link) { + if(array_key_exists('image', $link)) { + $fontFile = $link['image']; + $hash = 'fb_' . substr(md5($fontFile), 0, 10); + $final = $hash . '.woff'; + $filepath = $wdir . '/' . $link['image']; + $dest = $wdir . '/' . $final; + if(!file_exists($dest)) { + FluidbookFontToWoff::fontforge($dest, $filepath); + FluidbookFontToWoff::fontline($filepath); + } + $i = \App\Fluidbook\Link\Link::getInstance($link['id'],$link,$compiler); + $css[$link['uid']]['inline'] = FluidbookFontToWoff::getCSS($i, $fontFile, $hash, $filepath, $w, $h); + $css[$link['uid']]['font'] = $hash; + $css[$link['uid']]['hash'] = $final; + } + } + + return json_encode($css); + } + protected function moveLinks($fluidbook_id) { if (!FluidbookPublication::hasPermission($fluidbook_id)) { diff --git a/resources/linkeditor/js/linkeditor.accessControl.js b/resources/linkeditor/js/linkeditor.accessControl.js index 10b15c6ab..2a7dd3e82 100644 --- a/resources/linkeditor/js/linkeditor.accessControl.js +++ b/resources/linkeditor/js/linkeditor.accessControl.js @@ -30,7 +30,7 @@ LinkeditorAccessControl.prototype = { let currentToken = sessionStorage.getItem('token') const $this = this - $.ajax({ + /*$.ajax({ method: "POST", url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/edit/links', data: {id: FLUIDBOOK_DATA.id, token: currentToken ? currentToken : $this.token, unload: unload, clear: clear} @@ -75,7 +75,7 @@ LinkeditorAccessControl.prototype = { $this.interval = setTimeout(() => { $this.intervalConnection() }, 2000) - }); + });*/ }, } diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index 0bbb95193..505ef5fb7 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -147,10 +147,6 @@ LinkeditorLinks.prototype = { return false; } }); - this.key('ctrl+y', function () { - $this.preview(); - return false; - }); var commonDragAndDropEvent = function (e) { e.originalEvent.dataTransfer.dropEffect = "copy"; @@ -1561,6 +1557,23 @@ LinkeditorLinks.prototype = { setPreview: function(p) { const links = this.getLinksOfPage(1) + $.ajax({ + url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id + '/generatefont', + type: 'post', + data: { links: window.LINKS, rulers: window.RULERS }, + success: function (response) { + FONT_SIZE = JSON.parse(response); + }, + complete: function() { + $("#extra-font-face").remove() + $("head").append("") + for(let k in FONT_SIZE) { + $("#extra-font-face").append("@font-face{font-family:"+FONT_SIZE[k]['font']+";src:url('/fluidbook-publication/"+ FLUIDBOOK_DATA.id +"/edit/links/assets/"+FONT_SIZE[k]['hash']+"' ) format('woff');}") + $("[data-id-preview=" + k + "]").text(links[k].to).attr('style', FONT_SIZE[k]['inline']) + } + } + }); + for(let link in links) { let linkData = links[link], l = this.getLinkById(linkData.uid), @@ -1594,6 +1607,10 @@ LinkeditorLinks.prototype = { 'background-size': '100% 100%', 'background-position': '0 0', }) + } else if(linkData.type === '35') { + if(FONT_SIZE[linkData.uid] !== undefined) { + $("[data-id-preview=" + linkData.uid + "]").text(linkData.to).attr('style', FONT_SIZE[linkData.uid]) + } } } }, diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index d2ae2f988..ca26ab7cf 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -309,7 +309,7 @@ + data-tooltip="{{__('Voir un aperçu des liens (Ctrl+Y)')}}" data-key="ctrl+y"> @@ -402,6 +402,7 @@ var ASSETS = @json($assets); var CAN_CONTAIN_LINKS = @json($canContainLinks); var DEPTH = @json($depths); + var FONT_SIZE = @json([]); -- 2.39.5