create svg text multi-line with one of them is empty line - text

I am creating the SVG text by using the <text> with <tspan> for each line.
The text has many lines and one of them is empty line, some thing like this:
this is text line 1
this is text line 3
the example above is a text with three lines, one of them is empty.
the problem is the SVG text only displays two lines instead of three lines (the first and the end line, without the middle line).
See here: http://jsfiddle.net/svincoll4/DX4Cn/
Anyone have solution about this to make it display three lines?
Note: I am using the Raphael JS to create these text.

By default whitespace is compressed in html and svg so \n\n\n becomes \n. Also if there's no text at all then the middle line is ignored. xml:space="preserve" stops whitespace compression in SVG and and extra space makes the middle line exist.
var $svg = Raphael('container', 400, 400);
var $text = "this is line 1\n \nthis is line 3";
$svg.canvas.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space","preserve");
$svg.text(50, 100, $text);

Related

JTextPane, second word must not go to new line when typing and exceeding width

I'm using JTextPane because I need to markup text.
When typing into the JtextPane the second word always goes to new line. Then also when making the second word longer (after it went to a new line) the scroll bar appears and the JTextPane resizes. If I start typing in a new row then second word in that line does not go to a new line (as long the second word does not exceed width)
I tried adding a blank string that is very long in the first line and seems to do the trick, but this blank line is not really what I want to have.
Also tried adding it to after the text but it gives more problems
Is there something else that I can do to make the text only go to new line when I press enter? I can do it without a blank string using jtextarea, but then I can't markup text as I type.
I found the answer:
JTextPane textPane = new JTextPane()
{
public boolean getScrollableTracksViewportWidth()
{
return getUI().getPreferredSize(this).width
<= getParent().getSize().width;
}
};
We can overite the getScrollableTracksViewportWidth method to have a no wrapping text pane.
Website for more info: Here

How to indent a line starting from the position of the cursor in vim?

I want to indent a line partially in vim, starting from the cursor. For example: I have the line
var array = []
with cursor positioned on =.
And I want to get something like this as a result
var array = []
My AlignFromCursor plugin does that.
In your example, to align the = and following to column 20, use 20<Leader>le.
For aligning multiple instances, also look into Align - Help folks to align text, eqns, declarations, tables, etc or the alternative Tabular - Vim script for text filtering and alignment.

How to conditionally move lines up?

I have a text file with many lines.
test =
more text more text more text more text
more text more text more text more text
... etc....
more text more text more text more text
more text more text more text more text
1 text
test2 =
more text more text more text more text
more text more text more text more text
3 more text
etc
What I want to do is to move lines up starting with a number
and attach them after the first line found (going backwards) ending with '=\s'
expected output:
test = 1 text
more text more text more text more text
more text more text more text more text
... etc....
more text more text more text more text
more text more text more text more text
test2 = 3 more text
more text more text more text more text
more text more text more text more text
I have no idea how to do this.
Can someone help me?
Using :global, :norm, :move and the possibility to use a search as target for Ex commands:
:g/^\d/m?.*=$|norm kJ
Breakdown:
:g/pattern/command " executes command for every line matching pattern
^\d " pattern for "lines that start with a number"
m?.*=$ " move matched line to right below the first
" line ending with = upward
| " separator between Ex commands
norm " execute normal mode command
kJ " go to line above and join
A macro may help...
/^\d<cr>:.m?=<cr>kJ
short explanation:
/^\d " find line beginning with number
:.m?= " move current line under the previous line with (=)
kJ "move cursor back to the line with (=), and join the next
it is working like:
(it seems that I typed one more ? and the last n in screenshot, but I won't record it again.)

Whenever I type colon in insert mode it moves my text to the very beginning of line

Whenever I type a : (colon) it moves all the text on the current line to the beginning of the line, ignoring spaces and tabs.
So if I type
var combo = new Ext.form.ComboBox({
typeAhead //I'm about to type a colon, but right now it looks fine
})
Then I type the colon it moves the text and it now looks like
var combo = new Ext.form.ComboBox({
typeAhead: //text is no longer indented
})
This is a javascript file, so that might be causing the problem?
How can I stop my text from being moved to the beginning of the line when I type a colon?
Adding a colon to the end of a token is causing vim to interpret it as a jump label for C-indenting purposes. :set cino+=L0 should cause it to stay in the current column.
Also, doesn't the JSON syntax allow you to quote the thing that precedes the colon? That should prevent vim from thinking it's a label too.
var combo = new Ext.form.ComboBox({
"typeAhead": "foo" // this isn't a jump label
});

setting line height for text element in raphael

I'd like to increase the line height for a multiline text element generated with raphael. This does not appear to work:
text_element.attr({"line-height": "16" });
How can this be done? Thanks
You can do the following, but it's not pretty and breaks the encapsulation provided by Raphael. Consider the following:
text_element = r.text(10, 10, "Text in\nRaphael\nis a pain");
text_element.node.childNodes[0].setAttribute('dy', 0);
text_element.node.childNodes[1].setAttribute('dy', 5);
text_element.node.childNodes[2].setAttribute('dy', 5);
This will yield overlapping lines of text with the default font settings.
If I discover a better way, I'll update my answer.

Resources