Skip to content

Commit

Permalink
fix: update font size options
Browse files Browse the repository at this point in the history
修复字体大小错误
  • Loading branch information
yanglbme committed Jan 6, 2020
1 parent f79b871 commit 64c06a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions assets/scripts/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ let app = new Vue({
this.wxRenderer.setOptions({
fonts: fonts
});
this.currentFont = fonts;
this.refresh();
},
sizeChanged(size) {
Expand All @@ -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
});
Expand Down
16 changes: 13 additions & 3 deletions assets/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 64c06a8

Please sign in to comment.