fix: update font size options

修复字体大小错误
This commit is contained in:
yanglbme 2020-01-06 15:40:30 +08:00
parent f79b8711c3
commit 64c06a8a5d
2 changed files with 20 additions and 5 deletions

View File

@ -136,6 +136,7 @@ let app = new Vue({
this.wxRenderer.setOptions({
fonts: fonts
});
this.currentFont = fonts;
this.refresh();
},
sizeChanged(size) {
@ -146,18 +147,22 @@ let app = new Vue({
this.wxRenderer.setOptions({
theme: theme
});
this.currentSize = size;
this.refresh();
},
colorChanged(color) {
let theme = setColor(color);
let theme = setFontSize(this.currentSize.replace('px', ''));
theme = setColorWithCustomTemplate(theme, color);
this.wxRenderer.setOptions({
theme: theme
});
this.currentColor = color;
this.refresh();
},
cssChanged() {
let json = css2json(this.cssEditor.getValue(0));
let theme = customCssWithTemplate(json, this.currentColor);
let theme = setFontSize(this.currentSize.replace('px', ''));
theme = customCssWithTemplate(json, this.currentColor, theme);
this.wxRenderer.setOptions({
theme: theme
});

View File

@ -11,6 +11,17 @@ function setColorWithTemplate(template) {
};
}
let setColorWithCustomTemplate = function setColorWithCustomTemplate(template, color) {
let custom_theme = JSON.parse(JSON.stringify(template));
custom_theme.block.h1['border-bottom'] = `2px solid ${color}`;
custom_theme.block.h2['background'] = color;
custom_theme.block.h3['border-left'] = `3px solid ${color}`;
custom_theme.block.h4['color'] = color;
custom_theme.inline.strong['color'] = color;
return custom_theme;
}
// 设置自定义字体大小
function setFontSizeWithTemplate(template) {
return function (fontSize) {
@ -21,14 +32,13 @@ function setFontSizeWithTemplate(template) {
custom_theme.block.h4['font-size'] = `${fontSize}px`;
return custom_theme;
}
}
let setColor = setColorWithTemplate(default_theme);
let setFontSize = setFontSizeWithTemplate(default_theme);
function customCssWithTemplate(jsonString, color) {
let custom_theme = JSON.parse(JSON.stringify(default_theme));
function customCssWithTemplate(jsonString, color, theme) {
let custom_theme = JSON.parse(JSON.stringify(theme));
// block
custom_theme.block.h1['border-bottom'] = `2px solid ${color}`;
custom_theme.block.h2['background'] = color;