mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-20 17:52:46 +00:00
Whitespace support on text field, Fixes: #138
This commit is contained in:
parent
6cdca71a45
commit
2a0a1d7e9f
@ -9,7 +9,7 @@ export class FontFixer {
|
||||
static DEFAULT_FONT = "TypeWriter";
|
||||
static DEFAULT_SIZE = 10;
|
||||
static REPLACE_BY_FONT = "Noto Sans";
|
||||
static REPLACE_BY_SIZE = 10;
|
||||
static REPLACE_BY_SIZE = 11;
|
||||
|
||||
public fix(font: Font): Font {
|
||||
if (font.font_family === FontFixer.DEFAULT_FONT && font.font_size === FontFixer.DEFAULT_SIZE) {
|
||||
|
@ -39,9 +39,9 @@ describe('TextDrawingWidget', () => {
|
||||
const drew = drawings_merge.selectAll<SVGTextElement, TextElement>('text.text_element');
|
||||
expect(drew.size()).toEqual(1);
|
||||
const text_element = drew.nodes()[0];
|
||||
expect(text_element.innerHTML).toEqual('<tspan x="0" dy="0em">THIS IS TEXT</tspan>');
|
||||
expect(text_element.innerHTML).toEqual('<tspan xml:space="preserve" x="0" dy="0em">THIS IS TEXT</tspan>');
|
||||
expect(text_element.getAttribute('fill')).toEqual("#000000");
|
||||
expect(text_element.getAttribute('style')).toEqual('font-family: "TypeWriter"; font-size: 10pt; font-weight: bold');
|
||||
expect(text_element.getAttribute('style')).toEqual('font-family: "Noto Sans"; font-size: 11pt; font-weight: bold');
|
||||
});
|
||||
|
||||
it('should draw multiline text', () => {
|
||||
@ -67,4 +67,24 @@ describe('TextDrawingWidget', () => {
|
||||
expect(drew.nodes()[1].getAttribute('dy')).toEqual('1.2em');
|
||||
});
|
||||
|
||||
it('should draw whitespaces', () => {
|
||||
const text = new TextElement();
|
||||
text.text = ' Text with whitespaces';
|
||||
drawing.element = text;
|
||||
|
||||
const drawings = svg.canvas.selectAll<SVGGElement, Drawing>('g.drawing').data([drawing]);
|
||||
const drawings_enter = drawings.enter().append<SVGGElement>('g').classed('drawing', true);
|
||||
const drawings_merge = drawings.merge(drawings_enter);
|
||||
|
||||
widget.draw(drawings_merge);
|
||||
|
||||
const drew = drawings_merge.selectAll<SVGTSpanElement, string>('tspan');
|
||||
expect(drew.nodes().length).toEqual(1);
|
||||
|
||||
expect(drew.nodes()[0].innerHTML).toEqual(' Text with whitespaces');
|
||||
expect(drew.nodes()[0].getAttribute('space')).toEqual('preserve');
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
@ -57,6 +57,7 @@ export class TextDrawingWidget implements DrawingWidget {
|
||||
|
||||
lines_merge
|
||||
.text((line) => line)
|
||||
.attr('xml:space', 'preserve')
|
||||
.attr('x', 0)
|
||||
.attr("dy", (line, i) => i === 0 ? '0em' : '1.2em');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user