IText Paragraph preposition line breaks - itext

When creating long Paragraph with ALIGN_JUSTIFIED mine text has some "language grammar volations" which are very annoying for mine customer. Such volations occurs when line ends on single character like: 'o', 'i', etc. They are called preposition I guess. Those characters should be moved to next line and next line should start from them. The problem is I do not know if they occurs on the end or in the middle. Maybe someone will give me hint how to solve this ?
Please imagine that those two below examples are justified but they have line breaks in different place.
NOT OK:
Demonstracja problemu z
bekartami
OK (desired):
Demonstracja problemu
z bekartami

This should be solved by using a non-breaking space.
Instead of using a String "z bekartami", you should use a String "z/u00a0bekartami".
This will solve your problem.

Related

Save UITextView String With \n Instead of Line Breaks (Swift)

I have a UITextView in my Swift app in which users can input text. They can input text with as many line breaks as they like but I need to save the string with the newline command (\n). How would I do this?
For example, my user inputs
Line 1
Line 2
Line 3
in the UITextView. If I was to retrieve the string...
let string = textview.text!
this would return
"Line 1
Line 2
Line 3"
when I would like for it to return
"Line1\nLine2\nLine3"
How would I go about doing this? Can I use a form of replacingOccurrences(of:with:)? I feel like I'm missing a fairly obvious solution...
Eureka! After WAY too much research and learning all about String escapes, I found a very simple solution. I'm quite surprised that this isn't an answer out there already (as far as I can tell haha) so hopefully, this helps someone!
It's actually quite simple and this will work of any String you could be using.
textView.text!.replacingOccurrences(of: "\n", with: "\\n")
Explanation:
Ok so as you can tell, it's quite simple. We want to replace the newline command \n with the string "\n". The problem is that if we replace \n with \n, it's just going to transfer over to a newline, not a string. This is why escapes are so important. As you can see, I am replacing \n with \\n. By adding an extra \ we escape the command \n entirely which turns it into a string.
I hope this helps someone! Have a great day!
Have you tried replacing \r with \n? or even \r\n with \n?
I hope I am not making an obvious assumption you considered, but maybe this may come in handy:
Is a new line = \n OR \r\n?

iText Chinese punctuation at the beginning of line

Do you know how to resolve the problem when one line is full, then the Chinese punctuations will be placed at the beginning of next line as shown in (1)? In fact we hope the punctuations to be placed at the end of each line as shown in (2).
(1)
你好你好
,你好你好
(2)
你好你好,
你好你好
Thank you very much for your help in advance!
You are placing a space between the last char and the punctuation and that is a split point. The simplest way is to remove the space before the puntuation and add it after. Other option is to replace the space with a non breaking space \u00a0 to avoid the split at that point.

Line 1, Column 1: character "‍" not allowed in prolog

When I am going to validate my page using w3c validator, I am getting : Line 1, Column 1: character "‍" not allowed in prolog error.
There is a character, or data interpreted as a character, in the document before the doctype declaration. In the error message quoted, there is the character U+200D ZERO WIDTH JOINER (ZWJ) between the quotation marks, so this seems to be the culprit. ZWJ is an invisible control character. There is no point in having it at the start of a file, as it is supposed to cause ligature or joining behavior for the characters (usually letters) around it. ZWJ is invalid at the start of a document by HTML rules.
You may need a good editor, like BabelPad, to detect and remove the ZWJ.
I copied all my code into a new fresh file and used that file instead. It worked for me

Why does Github Flavored Markup only add newlines for lines that start with [\w\<]?

In our site (which is aimed at highly non-technical people), we let them use Markdown when sending emails. That way, they get nice things like bold, italic, etc. Being non-technical, however, they would never get past the “add two lines to make newlines actually work” quirk.
For that reason mainly, we are using a variant of Github Flavored Markdown.
We mainly borrowed this part:
# in very clear cases, let newlines become <br /> tags
text.gsub!(/^[\w\<][^\n]*\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end
This works well, but in some cases it doesn’t add the new-lines, and I guess the key to that is the “in very clear cases” part of that comment.
If I interpret it correctly, this is only adding newlines for lines that start with either a word character or a ‘<’.
Does anyone know why that is? Particularly, why ‘<’?
What would be the harm in just adding the two spaces to essentially anything (lines starting with spaces, hyphens, anything)?
'<' character is used at the beginning of a line to quote messages. I guess that is the reason.
The other answer to this question is quite wrong. This has nothing to do with quoting, and the character for markdown quoting is >.
^[\w\<][^\n]*\n+
Let's break the above regex into parts:
^ = anchor start of string.
[\w\<] matches a word character or the start of word boundary. \< is not a literal, but rather a GNU word boundary. See here (do a ctrl+f for \<).
[^\n]* matches any length of non-newline characters
\n matches a new line.
+ is, I believe, a possessive quantifier.
I believe, but am not 100% sure, that this simply is used to set x to a line of text. Then, the heavy work is done with the next line:
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
This says "if x satisfies the regex \n{2} (that is, has two line breaks), leave x as is. Otherwise, strip x and append a newline character.

Using Eclipse with Arabic and English on the same line

I just noticed as I was doing a string compare in Eclipse that when I place an Arabic character in a line it completely throws off Eclipse. How can I interchange English and Arabic on a single line of code?
** EDIT **
Ok now that my question has been migrated here, I supposed some code is in order. I was trying to do the following in Java:
Character c1 = 'ة';
Map<Character, Double> arabicRootMap = new HashMap<Character, Double>();
arabicRootMap.put(c1, 5.0);
The exact same thing happens here on SO as in Eclipse where instead of putting c1 into my map, I would like to put my Arabic character into the map directly, but my left to right is order is partly broken and the new mixed cursor navigation on the line is crazy. As you see, I have an indirect solution to the problem by defining a character beforehand.
So that is my answer, substitution whenever you have a character or string which needs to be in the middle of a statement. This gets to be rather labor intesive as you build up strings of various lengths and can not pre-define every Arabic word ever written. If there is a better answer, I would like to hear it.