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;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Prologue\Alerts\Facades\Alert;
+use Fluidbook\Tools\FluidbookFontToWoff;
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)
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)) {
return false;
}
});
- this.key('ctrl+y', function () {
- $this.preview();
- return false;
- });
var commonDragAndDropEvent = function (e) {
e.originalEvent.dataTransfer.dropEffect = "copy";
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),
'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])
+ }
}
}
},
<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>