I wonder if there is any possibility to render special characters (0-31 ASCII, for example) my own way in Qt/QPlainTextEdit? I want to render them as small rectangles as seen in this screenshot: ...or as Notepad++ is doing it. My goal is to be able see all characters. So if a character fails to render with current font (there is no such char for example), a small square should be rendered instead.
Qt does have ways to represent non-characters in QTextDocument which is used in QTextEdit and QPlainTextEditor. There's a sample on inserting an SVG object into a text edit:
http://doc.qt.io/archives/qt-4.7/richtext-textobject.html
Or you can use your own QAbstractTextDocumentLayout to handle the drawing of various text objects in the QTextDocument.
Related
I've been trying to find a way to change a font file's line spacing default value, using QFont, QFontMetrics or something like that. I'm using QPainter::drawText to draw some text in a bounding rectangle.
It's strange that QFont allows for font kerning to be changed and even has some stretch operation and letter spacing but nothing to change the default space between lines. I've searched and found some partial solutions using QTextLayout but none seemed to work properly.
I need to use QPainter because I generate a texture with the text to be rendered with OpenGL.
Looking for more ideas for me to try out!
UPDATE
I've found that I can use QPainter to draw a QStaticText which allows for HTML text formatting, similar to QTextDocument. However, CSS styling doesn't work like in QTextDocument (there's a bug report)... Therefore still no leading but I hope this puts me on the right track.
SOLVED
I got what I wanted using QTextDocument, like Mykhaylo suggested. Link to solution
QFontMetrics was not designed particularly for multi-line text.
Use QTextDocument. You can print multi-line and rich text with it, even using QPainter. See the solution how to use QPainter with QTextDocument
It seems there is not much that can be done here.
QFontMetrics::lineSpacing returns what you need but it is read-only.
It's the sum of font height and leading. You can adjust height - set it in QFont constructor. But you can't set leading.
Some people add \n to the end of string to increase space between lines but of course this is not always a good solution.
I am using SDL and libfreetype and constructing a very basic GUI, I'm implementing a textBox, but I haven't been able to figure out how I'm supposed to generate the standard blinking cursor part. It doesn't seem to be exactly the same as a | character. And moreover if I draw it as a | character that changes the text width.
What's the canonically correct way to render text in a textbox with a cursor?
The easiest way is to just draw a line primitive, this gives you a lot more control over the spacing, length and width of the caret.
And if you want to keep it as a text character in your font system, you can do a render-to-texture and copy it out, or do a simple memory blit onto your font atlas (so you can can keep pipe character separate, an use a control char like 0x01 for the caret).
I'm having trouble displaying Unicode font on opengl. I need to show like 20 lines of Unicode font text on my game and it has to be dynamically loaded(since the text is Japanese). The only unicode font library I could found was slick but rendering is so slow...
Is there any way to display many lines of unicode font text on the fly without sacrificing FPS? No JOGL, I'm using slick and LWJGL right now
Just for clarity, can you define "so slow" so we have an idea of what your rendering constraints are?
As a possible solution you could render the text to off screen textures with alpha, and then draw the textures on screen. If the text is going to be exactly the same every time you could also just use static images with the pre-rendered text (e.g. .PNG files).
I want to show an unicode text in my sdl program , but it doesnt render on screen correctly.
It renders from end to begining and the characters render seperatly (They should connect to each other)
You can see a screen shot here http://up.vatandownload.com/images/ea8d1c2kxpk5ehbjv2.png
SDL does not implement full Unicode text layout. It works for many languages, but Arabic (which has incredibly complex layout and glyph-selection rules) is not one of them. You will need to use either Pango or ICU's layout class to do your text layout if you need Arabic support.
Then I use wxDC::DrawLabel for drawing multiline text I want to control font leading (linespacing). Is it possible?
There is no existing function to do that.
You can create your own. Use DrawText() to draw the individual lines with the spacing you want, but you draw each line individually. Use GetTextExtent() to find the height of the lines, and hence how much linespacing you'll need.