File indexing completed on 2025-01-05 04:01:17
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "rive_html_format.hpp" 0008 #include "rive_exporter.hpp" 0009 #include "io/lottie/lottie_html_format.hpp" 0010 0011 0012 bool glaxnimate::io::rive::RiveHtmlFormat::on_save( 0013 QIODevice& file, const QString&, model::Composition* comp, const QVariantMap& 0014 ) 0015 { 0016 file.write(lottie::LottieHtmlFormat::html_head(this, comp, 0017 "<script src='https://unpkg.com/@rive-app/canvas@1.0.79'></script>" 0018 )); 0019 QBuffer buffer; 0020 buffer.open(QIODevice::WriteOnly); 0021 RiveExporter exp(&buffer, this); 0022 exp.write_document(comp->document()); 0023 file.write(QString(R"( 0024 <body> 0025 <canvas id="animation" width="%1" height="%2"></canvas> 0026 0027 <script> 0028 var rive_data = new Uint8Array([)") 0029 .arg(comp->width.get()) 0030 .arg(comp->height.get()) 0031 .toUtf8() 0032 ); 0033 0034 for ( auto c : buffer.buffer() ) 0035 { 0036 file.write(QString::number(c).toUtf8()); 0037 file.write(","); 0038 } 0039 0040 file.write(R"(]); 0041 0042 var anim = new rive.Rive({ 0043 buffer: rive_data, 0044 canvas: document.getElementById("animation"), 0045 autoplay: true 0046 }); 0047 </script> 0048 </body></html> 0049 )"); 0050 0051 return true; 0052 }