GDI+: Draw underlined space with DrawString - gdi+

Hallo,
i want to draw a justified text in GDI+.
When this text is underlined I have a problem, with the DrawString method:
- If you give to this method a string with a whitespace and the format underlined, it draws nothing, because the space has no width.
- If you have a justified text the maybe spaces are wider than normal.
I found no solution to draw a underlined space with a special width.
Thanks for your help.

GDI+ will draw the underline up to the trailing whitespace, and this is normally a desirable thing compared to GDI TextOut's behavior; but if you append any invisible non-whitespace character to the string you pass to DrawString (like U+200B zero width space or even a control character like U+007F), then the last character will no longer be the space, and all spaces are underlined. This is less brittle than trying to calculate the line length yourself.

This doesn't particularly surprise me. That's the behavior I would expect. GDI+ will draw the underline as expected for spaces that appear in-line with a string of text. The problem is, a string that contains only whitespace has no length, and thus doesn't get underlined.
So, the question is, why do you need to draw underlined white space? What's wrong with DrawLine?

Related

Tooltip overlay over container component

I have a component with tooltip icon when there is an error.
The problem starts when the text for the tooltip includes a one large word (without spaces).
In such case the text inside the tooltip box exceed the borders.
Please see this sandbox:
https://codesandbox.io/s/fragrant-morning-267l5
By default, word breaks on a new line if it is long enough that there is no space left for it to be on the same line. Since you are typing one long word it can't find a new word to break on so it goes over the box.
What you can do is instead breaking on a word you can break on a letter
word-wrap: break-word;
Add that CSS to text. When it runs out of space for new letter it will go to next line.
Read more about it here
Hope this helps :)

Respect space in code but ignore with CSS?

With CSS can I make a browser ignore the character but respect normal white space?
So this:
Some text More text
Is displayed like this:
Some text More text
Not:
Some text More text
UPDATE There is actually more white space in my code. I need the default behavior where extra white space doesn't get rendered on the page so I dont think I can use white-space: pre or pre-wrap
So this shouldn't be excessively indent before the initial word.
Some text More text
I don't think there's a pure CSS way of doing that, since is an actual character that is different from the whitespace created by the spacebar in a text editor (what gets ignored by HTML renderers). However, depending on how those are appearing, you may be able to use a script that searches for and removes that character wherever it sees it.

White space handling in XHTML

Is there any information on how to correctly handle white spaces in XHTML (1.0 Transitional)? It seems as if XHTML does not use standard XML white space handling.
Edit: Mayby I was a bit unprecise about what I was exactly looking for. I'm more interested in how an element gets rendered than how it would be processed by an XML processor.
For example the following will render with 1 white space inbetween:
<em> em content </em> following text
The situation gets more complicated if the space actually has its own formatting, for example content of the hyperlink content after the hyperlink will have an underlined space at the end of the hyperlink, while content of the hyperlink content after the hyperlink<br /> will not underline the the space.
It seems as if the space is always appended to the previous formatting scope and white spaces are handled over (inline) element begin and end tags. But this is based solely on testing and I was wondering if there is some kind of specification on how excatly this behaves.
From the W3C Recommendation:
4.7. White Space handling in attribute values
When user agents process attributes,
they do so according to Section 3.3.3
of [XML]:
Strip leading and trailing white
space.
Map sequences of one or more
white space characters (including line
breaks) to a single inter-word space.
For whitespace in between tags, see the section 3.2 criteria 9:
3.2. User Agent Conformance
[1-8 snipped]
9. White space is handled according to the following rules. The following characters are defined in [XML] white space characters:
SPACE ( )
HORIZONTAL TABULATION ( )
CARRIAGE RETURN (
)
LINE FEED (
)
The XML processor normalizes different systems' line end codes into one single LINE FEED character, that is passed up to the application.
The user agent must use the definition from CSS for processing whitespace characters [CSS2]. Note that the CSS2 recommendation does not explicitly address the issue of whitespace handling in non-Latin character sets. This will be addressed in a future version of CSS, at which time this reference will be updated.
Also see section C.15:
C.15. White Space Characters in HTML vs. XML
Some characters that are legal in HTML documents, are illegal in XML document. For example, in HTML, the Formfeed character (U+000C) is treated as white space, in XHTML, due to XML's definition of characters, it is illegal.
It seems that there is no real documentation on how white spaces are rendered in XHTML. Here is what I found out by experiment:
White spaces are reduced into a single space even over begin and end tags within the same block
The space will be put into the formatting scope of the containing tag. If it spans two tags it will be added to the first tag.
Spaces at the begin and end of block elements or span elements which are the first child element/ the last child element in their block are ignored.
White spaces outside of block elements are ignored.
This is all I could figure out. It is kind of sad that the XHTML specifiaction does not contain information about rendering of white spaces.

XHTML - How can I make a piece of text drop on to a new line or wrap without putting a space in it?

I have a small space in which I would like to put writing. Problem is, if a long word is inputted, it flows off the side because there is no space.
I could do overflow:hidden, but this isn't what I am looking for. Ideally I would like the word to drop to a new line with a - before it.
The word is on a line of its own to begin with so a <br/> will not fix the problem.
word-wrap:break-word in CSS does this (ok, without the - in the newline), but it had some browser issues back when I tried it, so be careful ;).
Second solution is wrapping letters in text (or packets of 3 or 5 letters etc.)in <span></span> so that they'll wrap but have no spaces when fitting the line.
to add the hyphen You could then use jquery and search for elements having certain left offset to prepend hyphens.

asp.net continuous string wrap

Okay, so it seems, for some reason (I might be doing it wrong, obviously), that I have some problem wrapping continuous lines, using Asp.net.
Let's say I have 800 pixels worth of the "m" character, well, my table cell gets extended to that length. I don't want that, I want the cell to automatically break the continuous line after 300px.
To do that, I tried to apply the word-wrap:break-word css style. Didn't work. Now what?
Do I parse the line, to insert explicit linebreaks after a certain number of characters? That doesn't seem very clean to me. Any ideas?
You can insert a <wbr> (little known html element) every few m's. It's not 100% compatible with everything, but it works in most browsers:
<wbr> (word break) means: "The browser may insert a line break here, if it wishes." It the browser does not think a line break necessary nothing happens.
So you would do something like this:
mmmmmmmmm<wbr>mmmmmmmmmm<wbr>mmmmmmmmmmm<wbr> (etc.)
Here's some more info: http://www.quirksmode.org/oddsandends/wbr.html
Do you really have 800px of "m" or is that just test data? If that is real data then yes you will have to create some whitespace in there somewhere. HTML parsers don't wrap text that overflows an element unless that text has spaces in it that allow the text to be wrapped.
If the m's are a test string and do not reflect real data I would suggest you use some dummy text (like Lorem Ipsum) to test with as it has spacing more akin to regular text.

Resources