]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6788 @5:00
authorsoufiane <soufiane@cubedesigners.com>
Tue, 26 Mar 2024 16:14:32 +0000 (17:14 +0100)
committersoufiane <soufiane@cubedesigners.com>
Tue, 26 Mar 2024 16:14:32 +0000 (17:14 +0100)
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/js/linkeditor.save.js
resources/linkeditor/js/linkeditor.zoom.js

index ac0302d9a0c1676df803213607f6a91ad1436769..1518c2ed6653d5078c159e14d85bfab084763d08 100644 (file)
@@ -90,7 +90,6 @@ trait LinksOperation
         $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 = [];
@@ -106,12 +105,12 @@ trait LinksOperation
                 $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']]['capHeight'] = FluidbookFontToWoff::getCSS($i, $fontFile, $hash, $filepath, $w, $h);
-                $css[$link['uid']]['font'] = $hash;
-                $css[$link['uid']]['hash'] = $final;
+
+                $config = FluidbookFontToWoff::configFont($fontFile,$hash,$filepath);
+                $css[$hash]['capHeight'] = $config['capHeight'];
+                $css[$hash]['font'] = $hash;
+                $css[$hash]['hash'] = $final;
             }
         }
 
index 630d753edb39f3919310b19fea0a0e1c7243020c..9d0b8bc819d8390d49410ab61158b0aa66da9893 100644 (file)
@@ -64,6 +64,8 @@ import LinkeditorPreviewLinks from "./linkeditor.previewLinks";
 
 window.MD5 = require("crypto-js/md5");
 
+console.log(window.MD5("MaisonNeue-Medium.otf").toString().substring(0,10))
+
 $.ajaxSetup({
     headers: {
         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
index c0ca90a7261b388fac62cc98803ac1fb11fc9ca1..3652b0396c9ed52148f49b95d6d719b5f350f96d 100644 (file)
@@ -423,6 +423,7 @@ LinkeditorLinks.prototype = {
         this.linkeditor.hasChanged();
         this.updatePolygonLinks();
         this.updateLayers();
+        this.updatePreview(this.lastSelectedLinkData);
     },
 
     hasUIDLink: function (uid) {
@@ -573,7 +574,6 @@ LinkeditorLinks.prototype = {
         this.linkeditor.form.updateLinkForm();
         this.resizeLinkPos = null;
         this.linkeditor.hasChanged();
-        this.setFontSize(this.lastSelectedLinkData)
     },
 
     moveResizeLink: function () {
@@ -903,6 +903,7 @@ LinkeditorLinks.prototype = {
 
 
     addLink: function (link, triggerChange) {
+        console.log('new')
         if (triggerChange === undefined) {
             triggerChange = true;
         }
@@ -1163,6 +1164,9 @@ LinkeditorLinks.prototype = {
         this.linkeditor.rulers.updateMagnetValues();
         this.updateLayers();
         this.updatePolygonLinks(false);
+        if($(['data-action=links.preview']).hasClass("active")) {
+            this.updatePreview(LINKS[id]);
+        }
     },
 
     updateSelectionData: function (props) {
@@ -1575,77 +1579,79 @@ LinkeditorLinks.prototype = {
         });
     },
 
-    setPreview: function(p) {
-        const links = this.getLinksOfPage(this.linkeditor.currentPage)
+    updatePreview: function(link) {
+        let linkData = link,
+            gsapConfig = this.convertAnimationStringToObject(linkData.image_rollover)
 
-        const imageFormat = FLUIDBOOK_DATA.settings.imageFormat
+        $("[data-id-preview="+linkData.uid+"]").css({
+            height: '100%',
+            width: '100%'
+        })
 
-        for(let link in links) {
-            let linkData = links[link],
-                l = this.getLinkById(linkData.uid),
-                gsapConfig = this.convertAnimationStringToObject(linkData.image_rollover)
+        if(linkData.type === '14') {
+            $("[data-id-preview="+linkData.uid+"]").css({
+                backgroundColor: linkData.to,
+                'z-index': 99
+            })
 
-            l.html("<div data-id-preview='"+linkData.uid+"'></div>")
+            /*gsapConfig.forEach(function(conf) {
+                gsap.to($("[data-id-preview="+linkData.uid+"]"),conf)
+            })*/
+        } else if(linkData.type === '15' || /\.(jpg|png|svg|webp|avif)$/.exec(linkData.image)) {
+            let imgUrl = linkData.type === '15' ? ASSETS['uid_'+linkData.uid]['url'] : "/fluidbook-publication/"+FLUIDBOOK_DATA.id +"/edit/links/assets/"+linkData.image
+            let img = "<img src='"+imgUrl+"' />"
+            $("[data-id-preview="+linkData.uid+"]").html(img)
 
-            $("[data-id-preview="+linkData.uid+"]").css({
+            $("[data-id-preview="+linkData.uid+"] img").css({
                 height: '100%',
-                width: '100%'
+                width: '100%',
+                display: 'block',
+                'background-size': '100% 100%',
+                'background-position': '0 0',
             })
+        } else if(linkData.type === '35') {
+            var hash = 'fb_'+window.MD5(link.image).toString().substring(0,10)
+            this.setFontSize(linkData, hash)
+            $("[data-id-preview=" + linkData.uid + "]").text(linkData.to).css({
+                'font-family': hash,
+                'color': linkData.extra,
+            })
+        }
+    },
 
-            if(linkData.type === '14') {
-                $("[data-id-preview="+linkData.uid+"]").css({
-                    backgroundColor: linkData.to,
-                    'z-index': 99
-                })
+    setPreview: function() {
+        const links = this.getLinksOfPage(this.linkeditor.currentPage)
 
-                /*gsapConfig.forEach(function(conf) {
-                    gsap.to($("[data-id-preview="+linkData.uid+"]"),conf)
-                })*/
-            } else if(linkData.type === '15' || /\.(jpg|png|svg|webp|avif)$/.exec(linkData.image)) {
-                let imgUrl = linkData.type === '15' ? ASSETS['uid_'+linkData.uid]['url'] : "/fluidbook-publication/"+FLUIDBOOK_DATA.id +"/edit/links/assets/"+linkData.image
-                let img = "<img src='"+imgUrl+"' />"
-                $("[data-id-preview="+linkData.uid+"]").append(img)
-
-                $("[data-id-preview="+linkData.uid+"] img").css({
-                    height: '100%',
-                    width: '100%',
-                    display: 'block',
-                    'background-size': '100% 100%',
-                    'background-position': '0 0',
-                })
-            } else if(linkData.type === '35') {
-                this.setFontSize(linkData)
-                $("[data-id-preview=" + linkData.uid + "]").text(linkData.to).css({
-                    'font-family': FONT_SIZE[linkData.uid]['font'],
-                    'color': linkData.extra,
-                })
-            }
+        for(let link in links) {
+            let l = this.getLinkById(links[link].uid)
+            l.html("<div data-id-preview='"+links[link].uid+"'></div>")
+            this.updatePreview(links[link])
         }
     },
 
-    setFontSize: function(link) {
+    setFontSize: function(link, hash) {
         var pw = FLUIDBOOK_DATA.settings.width;
         var ph = FLUIDBOOK_DATA.settings.height;
 
         var fs = link.height * (1 * Math.min((567 / pw), (709 / ph) ));
 
-        $("[data-id-preview=" + link.uid + "]").text(link.to).css({
-            'font-size': Math.round((fs / FONT_SIZE[link.uid].capHeight))+'px',
-            'line-height': FONT_SIZE[link.uid]['capHeight']
-        })
-    },
+        try {
+            $("[data-id-preview=" + link.uid + "]").text(link.to).css({
+                'font-size': Math.round((fs / FONT_SIZE[hash]['capHeight'])) + 'px',
+                'line-height': FONT_SIZE[hash]['capHeight']
+            })
+        } catch (e) {
 
-    updateFontSize: function(zoom) {
-        for(let k in LINKS) {
-            if(LINKS[k].type === '35') {
-                $("[data-id-preview="+LINKS[k].uid+"]").css({
-                    transform: "scale("+zoom+")",
-                    'transform-origin': 'left top'
-                })
-            }
         }
     },
 
+    updateFontSize: function(zoom, link) {
+        $("[data-id-preview="+link.uid+"]").css({
+            transform: "scale("+zoom+")",
+            'transform-origin': 'left top'
+        })
+    },
+
     clearPreview: function() {
       $("[data-id-preview]").remove()
     },
index 6f9dbc96e89a2c262c54c0145a829b96b2dfc46a..f65222f25b7a6c664d55b4771cb13f56b5d0900f 100644 (file)
@@ -80,6 +80,8 @@ LinkeditorSave.prototype = {
                 $this.linkeditor.notification(TRANSLATIONS.error_save + ' : ' + error, 'error');
             },
         });
+
+        $this.linkeditor.links.loadFontSize();
     },
 
     automaticSave: function () {
index a0a450a8a408c45a5c926539c08eb431b598476d..8dd75017febb2d24159ccae34b335c9e9b070087 100644 (file)
@@ -128,7 +128,7 @@ LinkeditorZoom.prototype = {
             if (this.zoom === 1) {
                 $this.resetZoomDrag();
             }
-            $this.linkeditor.links.updateFontSize($this.zoom)
+            //$this.linkeditor.links.updateFontSize($this.zoom)
             $this.linkeditor.rulers.updateRulers();
         }, 10);
         return true;