]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6788 @14:00
authorsoufiane <soufiane@cubedesigners.com>
Fri, 22 Mar 2024 17:36:59 +0000 (18:36 +0100)
committersoufiane <soufiane@cubedesigners.com>
Fri, 22 Mar 2024 17:36:59 +0000 (18:36 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
resources/linkeditor/js/linkeditor.accessControl.js
resources/linkeditor/js/linkeditor.links.js
resources/views/fluidbook_publication/link_editor.blade.php

index 169af7ade3148588630275e444f5712683ab9746..b2229f9d68dad43c7db57bf9f94e01f7a4d71d59 100644 (file)
@@ -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)) {
index 10b15c6ab7b2cb18d723439ad0af494a543f0a8b..2a7dd3e82efc0abe0426eed4f02f9f6da0e7e8b4 100644 (file)
@@ -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)
-        });
+        });*/
     },
 }
 
index 0bbb9519350a8cebf5da8215688419948cbd10ff..505ef5fb74c14d14c00d8ac4e8de97408e7be1e5 100644 (file)
@@ -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("<style id='extra-font-face'></style>")
+                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])
+                }
             }
         }
     },
index d2ae2f988e83f9256a566be29b106c2dda7092bf..ca26ab7cfdb8f5ff04e29f770b75a57ed273fe61 100644 (file)
                     <a href="#" data-action="toggleWhiteOverlay" data-icon="white-overlay"
                        data-tooltip="{{__('Afficher un overlay blanc semi-opaque au dessus des pages')}}"></a>
                     <a href="#" data-action="links.preview" data-icon="preview-links"
-                       data-tooltip="{{__('Voir un aperçu des liens (ctrl+y)')}}"></a>
+                       data-tooltip="{{__('Voir un aperçu des liens (Ctrl+Y)')}}" data-key="ctrl+y"></a>
                     <a href="#" data-action="openFluidbook" data-icon="open-fluidbook"
                        data-tooltip="{{__('Ouvrir le fluidbook à la page courante')}}"></a>
                 </nav>
         var ASSETS = @json($assets);
         var CAN_CONTAIN_LINKS = @json($canContainLinks);
         var DEPTH = @json($depths);
+        var FONT_SIZE = @json([]);
     </script>
     <script
             src="/packages/linkeditor/js/linkeditor.js?v={{filemtime(public_path('packages/linkeditor/js/linkeditor.js'))}}"></script>