mirror of
https://github.com/Xevion/calligraphy.git
synced 2025-12-08 12:06:41 -06:00
fix font variant selection from fromEach callback being ignored, using for-of instead. begin adding font selection list expansion, fix font API sorting not refreshing fonts shown
This commit is contained in:
10
src/App.vue
10
src/App.vue
@@ -99,27 +99,27 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleMenu() {
|
|
||||||
this.menuVisible = !this.menuVisible
|
|
||||||
},
|
|
||||||
showSettings() {},
|
showSettings() {},
|
||||||
showStylizer() {},
|
showStylizer() {},
|
||||||
showAbout() {},
|
showAbout() {},
|
||||||
createPDF() {
|
createPDF() {
|
||||||
var doc = new jsPDF();
|
var doc = new jsPDF();
|
||||||
|
|
||||||
|
// Load font if not already
|
||||||
if (!this.fontData)
|
if (!this.fontData)
|
||||||
this.loadFile(this.fontURL)
|
this.loadFile(this.fontURL)
|
||||||
|
|
||||||
console.log(this.fontData)
|
// Adding font
|
||||||
|
|
||||||
doc.addFileToVFS('antic.ttf', this.fontData);
|
doc.addFileToVFS('antic.ttf', this.fontData);
|
||||||
doc.addFont('antic.ttf', 'Antic', 'regular')
|
doc.addFont('antic.ttf', 'Antic', 'regular')
|
||||||
doc.setFont('Antic', 'regular');
|
doc.setFont('Antic', 'regular');
|
||||||
doc.setFontSize(15);
|
doc.setFontSize(15);
|
||||||
|
|
||||||
|
// Add text
|
||||||
doc.text("Some Text with Google Fonts", 5, 10);
|
doc.text("Some Text with Google Fonts", 5, 10);
|
||||||
doc.save('test.pdf');
|
doc.save('test.pdf');
|
||||||
},
|
},
|
||||||
|
|
||||||
loadFile(fontURL) {
|
loadFile(fontURL) {
|
||||||
this.directAxios.get(fontURL, {
|
this.directAxios.get(fontURL, {
|
||||||
responseType: "blob"
|
responseType: "blob"
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<md-list-item @click="selectFont(font.index)" :style="fontStyle">
|
<md-list-item @click="selectFont" :style="fontStyle">
|
||||||
<template v-if="fontReady">{{ font.family }}</template>
|
<span v-if="fontReady" class="md-list-item-text">{{ font.family }}</span>
|
||||||
<Skeleton v-else></Skeleton>
|
<Skeleton v-else></Skeleton>
|
||||||
|
<md-list v-if="selected" slot="md-expand">
|
||||||
|
<md-list-item class="md-inset" v-for="(variant, index) in font.variants" :key="index">{{ variant }}</md-list-item>
|
||||||
|
</md-list>
|
||||||
</md-list-item>
|
</md-list-item>
|
||||||
</template>
|
</template>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@@ -15,12 +18,12 @@
|
|||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import WebFontLoader from 'webfontloader';
|
import WebFontLoader from 'webfontloader';
|
||||||
import {Skeleton} from 'vue-loading-skeleton';
|
// import {Skeleton} from 'vue-loading-skeleton';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'FontItem',
|
name: 'FontItem',
|
||||||
components: {
|
components: {
|
||||||
Skeleton
|
// Skeleton
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -30,7 +33,17 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
font: {
|
font: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true,
|
||||||
|
},
|
||||||
|
selected: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
selectFont() {
|
||||||
|
this.$emit('select-font', this.font.index)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -41,14 +54,13 @@ export default {
|
|||||||
},
|
},
|
||||||
fontSelection() {
|
fontSelection() {
|
||||||
// Preferred font variants (in order0
|
// Preferred font variants (in order0
|
||||||
let order = ['regular', '500', '600', '700', '300', 'italic', '500italic', '600italic', '700italic', '800',
|
let order = ["regular", "500", "300", "600", "700", "italic", "500italic", "600italic", "700italic", "800",
|
||||||
'800italic', '200', '200italic', '100', '100italic', '300italic', '900', '900italic']
|
"800italic", "200", "200italic", "100", "100italic", "300italic", "900", "900italic"]
|
||||||
|
|
||||||
// Iterate over all weights possible, return first available
|
// Iterate over all weights possible, return first available
|
||||||
order.forEach((variant) => {
|
for (let variant of order)
|
||||||
if (this.font.variants.includes(variant))
|
if (this.font.variants.includes(variant))
|
||||||
return variant;
|
return variant;
|
||||||
})
|
|
||||||
|
|
||||||
// Otherwise return first variant (? should not occur naturally)
|
// Otherwise return first variant (? should not occur naturally)
|
||||||
return this.font.variants[0];
|
return this.font.variants[0];
|
||||||
|
|||||||
@@ -21,10 +21,10 @@
|
|||||||
</md-field>
|
</md-field>
|
||||||
</div>
|
</div>
|
||||||
<md-list>
|
<md-list>
|
||||||
<vue-custom-scrollbar :distance="20"
|
<vue-custom-scrollbar :distance="10"
|
||||||
:settings="{suppressScrollX: true, suppressScrollY: false}"
|
:settings="{suppressScrollX: true, suppressScrollY: false}"
|
||||||
class="scroll-area">
|
class="scroll-area">
|
||||||
<FontItem v-for="font in shown" :key="font.index" :font="font"></FontItem>
|
<FontItem v-for="font in shown" :key="font.index" @select-font="selectFont" :selected="selectedFont !== null && selectedFont.index === font.index" :font="font"></FontItem>
|
||||||
<infinite-loading :identifier="search + sort" force-use-infinite-wrapper=".scroll-area"
|
<infinite-loading :identifier="search + sort" force-use-infinite-wrapper=".scroll-area"
|
||||||
@infinite="infiniteHandler">
|
@infinite="infiniteHandler">
|
||||||
<div slot="spinner"></div>
|
<div slot="spinner"></div>
|
||||||
@@ -139,6 +139,7 @@ export default {
|
|||||||
).then((res) => {
|
).then((res) => {
|
||||||
this.fonts = res.data;
|
this.fonts = res.data;
|
||||||
this.fonts.items.forEach((font, index) => font.index = index)
|
this.fonts.items.forEach((font, index) => font.index = index)
|
||||||
|
this.shown = this.results.slice(0, 5);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
selectFont(fontIndex) {
|
selectFont(fontIndex) {
|
||||||
@@ -161,7 +162,6 @@ export default {
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
sort: function() {
|
sort: function() {
|
||||||
this.shown = [];
|
|
||||||
this.getFonts();
|
this.getFonts();
|
||||||
},
|
},
|
||||||
search: function (newSearch, oldSearch) {
|
search: function (newSearch, oldSearch) {
|
||||||
|
|||||||
Reference in New Issue
Block a user