daily: 2021-09-29 Night

This commit is contained in:
2021-09-29 22:32:20 +08:00
parent 488a2532b2
commit 615ba6ffba
21 changed files with 709 additions and 168 deletions
+45
View File
@@ -0,0 +1,45 @@
import store from "../store/global";
import { VERSION } from "./version";
const initialData = {
version: VERSION,
canvasWidth: 1024,
canvasHeight: 1448,
defaultFontSize: 16,
defaultSubFontSize: 12,
title: "无标题",
tone: "C",
marginHorizontal: 64,
marginTop: 32,
gapAfterTitle: 16,
gapAfterHeader: 32,
gapBetweenParagraph: 32,
gapBetweenNotation: 8,
beat: [4, 4],
speed: 75,
authors: ["佚名 作词", "简谱编辑器 制谱"],
notations: [],
};
function getInitialGlobalData() {
return JSON.parse(JSON.stringify(initialData));
}
// 根据key查找符号在全局记录中的位置
function findParagraphAndNotation(key) {
let res = {};
const paras = store.paragraphs || [];
paras.some((p, i) => {
const notationIndex = (p.notations || []).findIndex((n) => n.key === key);
if (notationIndex !== -1) {
res.notation = p.notations[notationIndex];
res.notationIndex = notationIndex;
res.paragraph = p;
res.paragraphIndex = i;
return true;
}
});
return res;
}
export { getInitialGlobalData, findParagraphAndNotation };
+50
View File
@@ -0,0 +1,50 @@
const notations = {
zero: "0",
do: "1",
re: "2",
mi: "3",
fa: "4",
sol: "5",
la: "6",
si: "7",
extend: "─",
separator: "│",
};
const notes = [
notations.zero,
notations.do,
notations.re,
notations.mi,
notations.fa,
notations.sol,
notations.la,
notations.si,
];
const separators = ["│", "‖"];
function isNote(notationOrNote) {
return notes.includes(notationOrNote?.note || notationOrNote);
}
function isSeparator(notationOrNote) {
return separators.includes(notationOrNote?.note || notationOrNote);
}
// 创建符号
function createNotation(initial) {
const n = {
key: `n_${String(Math.random())}`,
note: "0",
octave: 0,
dotted: false,
underline: 0,
breakUnderline: false,
prefixSups: [],
topDecorators: [],
tieTo: null,
};
if (initial) {
Object.assign(n, initial);
}
return n;
}
export { notations, isNote, isSeparator, createNotation };
-12
View File
@@ -1,12 +0,0 @@
const Notes = {
do: "1",
re: "2",
mi: "3",
fa: "4",
sol: "5",
la: "6",
si: "7",
extend: "─",
};
export { Notes };
+16
View File
@@ -0,0 +1,16 @@
// 新建段落
function createParagraph(initial) {
const p = {
key: `p_${String(Math.random())}`,
// 符号列表
notations: [],
// 是否两端对齐
alignJustify: null,
};
if (initial) {
Object.assign(p, initial);
}
return p;
}
export { createParagraph };
+16 -2
View File
@@ -73,6 +73,9 @@ const placement = observable({
return 8;
},
get maxTieHeight() {
return 20;
},
get maxTieBezierOffset() {
return 25;
},
get underlineStepOffsetY() {
@@ -136,9 +139,16 @@ const placement = observable({
const calcTextWidth = _calcTextWidth.bind(null, store.defaultFontSize);
const calcSubTextWidth = _calcTextWidth.bind(null, store.defaultSubFontSize);
// 计算段落
// 计算段落占的空间
function calcParagraphHeight(paragraph) {
return calcParagraphContentHeight(paragraph) + store.gapBetweenParagraph;
}
// 计算段落内容的高度
function calcParagraphContentHeight(paragraph) {
const notations = paragraph.notations || [];
if (notations.length === 0) {
return placement.xHeight;
}
let tieHeight = 0;
if (_hasTie(paragraph)) {
tieHeight = placement.maxTieHeight;
@@ -150,7 +160,7 @@ function calcParagraphHeight(paragraph) {
const belowOffsetMap = noteHeightMap.map((v, i) => v - aboveOffsetMap[i]);
const maxNoteOffset =
Math.max(...belowOffsetMap) + Math.max(...aboveOffsetMap);
return tieHeight + maxNoteOffset + store.gapBetweenParagraph;
return tieHeight + maxNoteOffset;
}
// 计算一行中所有音符的宽度和
@@ -169,6 +179,9 @@ function calcParagraphWidth(paragraph) {
// 计算段落中的音符中心以上偏移量的最大值
function calcParagraphAboveOffset(paragraph) {
const notations = paragraph.notations || [];
if (notations.length === 0) {
return placement.xHeight / 2;
}
let tieHeight = 0;
if (_hasTie(paragraph)) {
tieHeight = placement.maxTieHeight;
@@ -270,6 +283,7 @@ export {
calcNotationAboveOffset,
calcParagraphWidth,
calcParagraphHeight,
calcParagraphContentHeight,
calcParagraphAboveOffset,
calcTextWidth,
calcSubTextWidth,
+3
View File
@@ -0,0 +1,3 @@
const VERSION = 1;
export { VERSION };