mirror of
https://github.com/Xevion/calligraphy.git
synced 2025-12-14 22:11:17 -06:00
basic app material design, font ttf to base64, jsPDF saving
This commit is contained in:
109
src/App.vue
109
src/App.vue
@@ -1,28 +1,93 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<img alt="Vue logo" src="./assets/logo.png">
|
||||
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
||||
</div>
|
||||
<div id="app">
|
||||
<div class="md-layout md-center md-alignment-center-center">
|
||||
<div class="md-layout-item md-size-50">
|
||||
<md-field>
|
||||
<label for="fonturl">Font URL</label>
|
||||
<md-input id="fonturl" v-model="fontURL"></md-input>
|
||||
</md-field>
|
||||
</div>
|
||||
<div class="md-layout-item md-size-20">
|
||||
<md-button class="md-raised md-primary" v-on:click="loadFile(fontURL)">Load Font</md-button>
|
||||
</div>
|
||||
<div class="md-layout-item md-size-20">
|
||||
<md-button class="md-raised md-primary" v-on:click="createPDF">Save PDF</md-button>
|
||||
</div>
|
||||
<div class="md-layout-item md-size-100">
|
||||
<md-card style="padding: 0.10em 0.3em;">
|
||||
<pre v-highlightjs="JSON.stringify({'data': fontData})"><code class="json"></code></pre>
|
||||
</md-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HelloWorld from './components/HelloWorld.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
HelloWorld
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
<style lang="css">
|
||||
#app {
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-align: center;
|
||||
color: #2c3e50;
|
||||
margin-top: 60px;
|
||||
width: 50%;
|
||||
margin: 60px auto;
|
||||
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
text-align: center;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.hljs {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: pre-wrap; /* css-3 */
|
||||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||
white-space: -pre-wrap; /* Opera 4-6 */
|
||||
white-space: -o-pre-wrap; /* Opera 7 */
|
||||
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import jsPDF from 'jspdf'
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
fontURL: "https://themes.googleusercontent.com/static/fonts/anonymouspro/v3/WDf5lZYgdmmKhO8E1AQud--Cz_5MeePnXDAcLNWyBME.ttf",
|
||||
fontData: null,
|
||||
directAxios: axios.create({baseURL: ''}),
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
createPDF() {
|
||||
var doc = new jsPDF();
|
||||
|
||||
if(!this.fontData)
|
||||
this.loadFile(this.fontURL)
|
||||
|
||||
doc.addFileToVFS('antic.ttf', this.fontURL);
|
||||
doc.addFont('antic.ttf', 'Antic', 'regular')
|
||||
doc.setFont('Antic', 'regular');
|
||||
// doc.setFontType("regular");
|
||||
doc.setFontSize(15);
|
||||
doc.text("Some Text with Google Fonts", 0, 10);
|
||||
doc.save('test.pdf');
|
||||
},
|
||||
loadFile(fontURL) {
|
||||
this.directAxios.get(fontURL, {
|
||||
responseType: "blob"
|
||||
})
|
||||
.then((res) => {
|
||||
var reader = new FileReader();
|
||||
reader.readAsDataURL(res.data);
|
||||
reader.onload = e => {
|
||||
console.log(this);
|
||||
this.fontData = e.target.result.substring(21);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>{{ msg }}</h1>
|
||||
<p>
|
||||
For a guide and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
14
src/main.js
14
src/main.js
@@ -1,8 +1,20 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import axios from 'axios'
|
||||
import VueAxios from 'vue-axios'
|
||||
import VueHighlightJS from 'vue-highlightjs'
|
||||
import VueMaterial from 'vue-material'
|
||||
import json from 'highlight.js/lib/languages/css';
|
||||
import 'vue-material/dist/vue-material.min.css'
|
||||
import 'vue-material/dist/theme/default.css'
|
||||
import 'highlight.js/styles/default.css';
|
||||
|
||||
Vue.use(VueHighlightJS, {languages: {json}})
|
||||
Vue.use(VueMaterial)
|
||||
Vue.use(VueAxios, axios)
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
render: h => h(App),
|
||||
}).$mount('#app')
|
||||
|
||||
Reference in New Issue
Block a user