Skip to content

Commit

Permalink
append strikewidth
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Sep 6, 2023
1 parent d7f2340 commit 73ae753
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def generate_handwriting():
strikethrough_length_sigma=float(data["strikethrough_length_sigma"]), # 删除线长度随机扰动
strikethrough_width_sigma=float(data["strikethrough_width_sigma"]), # 删除线宽度随机扰动
strikethrough_angle_sigma=float(data["strikethrough_angle_sigma"]), # 删除线角度随机扰动

strikethrough_width=float(data["strikethrough_width"]), # 删除线宽度
)
images = handwrite(text_to_generate, template)
logger.info("images generated successfully")
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const messages = {
"Standard deviation of the strikethrough width",
strikethrough_angle_sigma:
"Standard deviation of the strikethrough angle",
strikethrough_width: "Width of strikethrough",
},
},
cn: {
Expand Down Expand Up @@ -103,6 +104,7 @@ const messages = {
strikethrough_length_sigma: "涂改线长度的标准差",
strikethrough_width_sigma: "涂改线宽度的标准差",
strikethrough_angle_sigma: "涂改线角度的标准差",
strikethrough_width: "涂改线宽度",
},
},
};
Expand Down
33 changes: 24 additions & 9 deletions frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<div class="label-container">

<label>{{ $t('message.fontSize') }}:
<input type="number" v-model="fontSize" placeholder="recommend > 100"/>
<input type="number" v-model="fontSize" placeholder="recommend > 100" />
</label>
</div>

Expand Down Expand Up @@ -118,7 +118,7 @@
</button>

<!-- 这是一个内容区域,它的 id 与上面的按钮的 data-target 相对应 -->
<div v-if="isExpanded" id="collapseContent">
<div v-if="isExpanded" id="collapseContent">
<div class="card card-body">
<div class="label-container">
<label>{{ $t('message.lineSpacingSigma') }}:
Expand Down Expand Up @@ -186,6 +186,12 @@
</label>
</div>

<div class='label-container'>
<label>{{ $t('message.strikethrough_width') }}:
<input type="number" v-model="strikethrough_width" />
</label>
</div>

</div>
</div>
</div>
Expand Down Expand Up @@ -274,8 +280,9 @@ export default {
strikethrough_angle_sigma: 2,
strikethrough_width_sigma: 2,
strikethrough_probability: 0.08,
isExpanded: false,
localStorageItems: ['text', 'fontFile', 'fontSize', 'lineSpacing', 'fill', 'width', 'height', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'selectedFontFileName', 'selectedOption', 'lineSpacingSigma', 'fontSizeSigma', 'wordSpacingSigma', 'perturbXSigma', 'perturbYSigma', 'perturbThetaSigma', 'wordSpacing', 'strikethrough_length_sigma', 'strikethrough_angle_sigma', 'strikethrough_width_sigma', 'strikethrough_probability'],
strikethrough_width: 8,
isExpanded: false,
localStorageItems: ['text', 'fontFile', 'fontSize', 'lineSpacing', 'fill', 'width', 'height', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'selectedFontFileName', 'selectedOption', 'lineSpacingSigma', 'fontSizeSigma', 'wordSpacingSigma', 'perturbXSigma', 'perturbYSigma', 'perturbThetaSigma', 'wordSpacing', 'strikethrough_length_sigma', 'strikethrough_angle_sigma', 'strikethrough_width_sigma', 'strikethrough_probability', 'strikethrough_width'],
};
},
created() {
Expand Down Expand Up @@ -485,6 +492,12 @@ export default {
},
deep: true
},
strikethrough_width: {
handler(newVal) {
localStorage.setItem('strikethrough_width', JSON.stringify(newVal));
},
deep: true
},
},
methods: {
Expand All @@ -493,7 +506,7 @@ export default {
},
async generateHandwriting(preview = false) {
// 验证输入
const Items = ['text', 'backgroundImage', 'fontSize', 'lineSpacing', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'lineSpacingSigma', 'fontSizeSigma', 'wordSpacingSigma', 'perturbXSigma', 'perturbYSigma', 'perturbThetaSigma', 'wordSpacing', 'strikethrough_length_sigma', 'strikethrough_angle_sigma', 'strikethrough_width_sigma', 'strikethrough_probability'];
const Items = ['text', 'backgroundImage', 'fontSize', 'lineSpacing', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'lineSpacingSigma', 'fontSizeSigma', 'wordSpacingSigma', 'perturbXSigma', 'perturbYSigma', 'perturbThetaSigma', 'wordSpacing', 'strikethrough_length_sigma', 'strikethrough_angle_sigma', 'strikethrough_width_sigma', 'strikethrough_probability', 'strikethrough_width'];
Items.forEach(item => {
let value = this[item];
// if (!value) {
Expand All @@ -508,8 +521,8 @@ export default {
console.error(`Invalid value for ${item}`);
this.errorMessage = '请输入字符串';
}
return;
// break;
// return;
break;
case 'fontSize':
case 'lineSpacing':
case 'marginTop':
Expand All @@ -527,13 +540,14 @@ export default {
case 'strikethrough_angle_sigma':
case 'strikethrough_width_sigma':
case 'strikethrough_probability':
case 'strikethrough_width':
// 验证这些值是否是数字
if (isNaN(Number(value))) {
console.error(`Invalid value for ${item}`);
this.errorMessage = '请输入数字';
}
return
// break;
// return
break;
case 'backgroundImage':
// 验证 backgroundImage 是否是有效的 URL 或者文件路径
// 这可能需要更复杂的验证
Expand Down Expand Up @@ -590,6 +604,7 @@ export default {
formData.append("strikethrough_angle_sigma", this.strikethrough_angle_sigma);
formData.append("strikethrough_width_sigma", this.strikethrough_width_sigma);
formData.append("strikethrough_probability", this.strikethrough_probability);
formData.append("strikethrough_width", this.strikethrough_width);
for (let pair of formData.entries()) {
console.log(pair[0] + ', ' + pair[1]);
Expand Down

0 comments on commit 73ae753

Please sign in to comment.