Added textLength and lengthAdjust to text formatting tools

This commit is contained in:
Timo Dittmann
2021-01-26 11:06:13 +01:00
committed by JFH
parent 69bf3d9d81
commit 41fc05672d
70 changed files with 553 additions and 60 deletions

View File

@@ -495,6 +495,8 @@ exports[`use various parts of svg-edit > check tool_star #0`] = `
text-decoration=" underline overline line-through"
letter-spacing="150"
word-spacing="10"
textLength="600"
lengthAdjust="spacingAndGlyphs"
>
B
</text>
@@ -589,6 +591,8 @@ exports[`use various parts of svg-edit > check tool_polygon #0`] = `
text-decoration=" underline overline line-through"
letter-spacing="150"
word-spacing="10"
textLength="600"
lengthAdjust="spacingAndGlyphs"
>
B
</text>
@@ -1183,3 +1187,212 @@ exports[`use various parts of svg-edit > check tool_word_spacing #0`] = `
</g>
</svg>
`;
exports[`use various parts of svg-edit > check tool_text_length #0`] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
width="640"
height="480"
id="svgcontent"
overflow="visible"
x="640"
y="480"
viewBox="0 0 640 480"
>
<g class="layer">
<title>Layer 1</title>
<rect
id="rect"
fill="#FF0000"
height="70"
stroke="#000000"
stroke-width="5"
width="94"
x="69.5"
y="51.5"
fill-opacity="1"
stroke-opacity="1"
></rect>
<text
fill="#ffff00"
stroke="#000000"
stroke-width="0"
x="116"
y="87"
id="svg_1"
font-size="24"
font-family="serif"
text-anchor="end"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
font-=""
font-weight="bold"
text-decoration=" underline overline line-through"
letter-spacing="150"
word-spacing="10"
textLength="600"
>
B
</text>
<text
fill="#000000"
stroke="#000000"
stroke-width="0"
x="136"
y="107"
font-size="24"
font-family="serif"
text-anchor="middle"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
id="svg_2"
transform="matrix(1 0 0 1 0 0)"
>
B
</text>
</g>
</svg>
`;
exports[`use various parts of svg-edit > check tool_length_adjust_spacing #0`] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
width="640"
height="480"
id="svgcontent"
overflow="visible"
x="640"
y="480"
viewBox="0 0 640 480"
>
<g class="layer">
<title>Layer 1</title>
<rect
id="rect"
fill="#FF0000"
height="70"
stroke="#000000"
stroke-width="5"
width="94"
x="69.5"
y="51.5"
fill-opacity="1"
stroke-opacity="1"
></rect>
<text
fill="#ffff00"
stroke="#000000"
stroke-width="0"
x="116"
y="87"
id="svg_1"
font-size="24"
font-family="serif"
text-anchor="end"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
font-=""
font-weight="bold"
text-decoration=" underline overline line-through"
letter-spacing="150"
word-spacing="10"
textLength="600"
lengthAdjust="spacing"
>
B
</text>
<text
fill="#000000"
stroke="#000000"
stroke-width="0"
x="136"
y="107"
font-size="24"
font-family="serif"
text-anchor="middle"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
id="svg_2"
transform="matrix(1 0 0 1 0 0)"
>
B
</text>
</g>
</svg>
`;
exports[`use various parts of svg-edit > check tool_length_adjust_spacingAndGlyphs #0`] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
width="640"
height="480"
id="svgcontent"
overflow="visible"
x="640"
y="480"
viewBox="0 0 640 480"
>
<g class="layer">
<title>Layer 1</title>
<rect
id="rect"
fill="#FF0000"
height="70"
stroke="#000000"
stroke-width="5"
width="94"
x="69.5"
y="51.5"
fill-opacity="1"
stroke-opacity="1"
></rect>
<text
fill="#ffff00"
stroke="#000000"
stroke-width="0"
x="116"
y="87"
id="svg_1"
font-size="24"
font-family="serif"
text-anchor="end"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
font-=""
font-weight="bold"
text-decoration=" underline overline line-through"
letter-spacing="150"
word-spacing="10"
textLength="600"
lengthAdjust="spacingAndGlyphs"
>
B
</text>
<text
fill="#000000"
stroke="#000000"
stroke-width="0"
x="136"
y="107"
font-size="24"
font-family="serif"
text-anchor="middle"
xml:space="preserve"
fill-opacity="1"
stroke-opacity="1"
id="svg_2"
transform="matrix(1 0 0 1 0 0)"
>
B
</text>
</g>
</svg>
`;

View File

@@ -122,6 +122,26 @@ describe('use various parts of svg-edit', function () {
.type('{enter}', {force: true});
testSnapshot();
});
it('check tool_text_length', function () {
cy.get('#svg_1').click({force: true});
cy.get('#text_length')
.type('{selectall}', {force: true})
.type('600', {force: true})
.type('{enter}', {force: true});
testSnapshot();
});
it('check tool_length_adjust_spacing', function () {
cy.get('#svg_1').click({force: true});
cy.get('#tool_length_adjust_spacing')
.click({force: true});
testSnapshot();
});
it('check tool_length_adjust_spacingAndGlyphs', function () {
cy.get('#svg_1').click({force: true});
cy.get('#tool_length_adjust_spacingAndGlyphs')
.click({force: true});
testSnapshot();
});
it('check tool_star', function () {
cy.get('#tool_star')
.click({force: true});

View File

@@ -56,4 +56,24 @@ describe('sanitize', function () {
assert.equal(text.getAttribute('word-spacing'), '10');
});
it('Test sanitizeSvg() does not strip textLength attribute from text', function () {
const text = document.createElementNS(NS.SVG, 'text');
text.setAttribute('textLength', '200');
svg.append(text);
sanitize.sanitizeSvg(text);
assert.equal(text.getAttribute('textLength'), '200');
});
it('Test sanitizeSvg() does not strip lengthAdjust attribute from text', function () {
const text = document.createElementNS(NS.SVG, 'text');
text.setAttribute('lengthAdjust', 'spacingAndGlyphs');
svg.append(text);
sanitize.sanitizeSvg(text);
assert.equal(text.getAttribute('lengthAdjust'), 'spacingAndGlyphs');
});
});