I use cocos2d:::Label and I need to control the spacing of adjustment characters in the text. I use cocos2d-x 3.0 and the font of the label is TTF. Is it possible to achieve, or I should use another thing instead of cocos2d:::Label?
I figured out that bitmap fonts can be created with appropriate inter-character spacing. There is a good online tool for that. And it can customize even more settings, and it is very handy.
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 working on an embedded platform (STM32F407) with a TFT LCD as a display (480x800px) and would like to make my user interface somewhat customizable to the end user. I figured the best source of fonts would be windows compatible as their the most common.
My current implementation uses my own custom drawn font in a binary format and a descriptor table giving the character width and ascii value but having to draw my own font bit by bit is tedious.
I would like to read in a True Type Font file from an SD card and be able to use the different sized glyphs inside it but I have not seen a strait forward implementation on how to actually achieve this magic. Can somebody point me to a good c/c++ example of what I am looking for?
Even better as a way to iron out the kinks I would like to make a simple gcc command line program that will print out my input with a selected font using '#' as pixels. That way I can just worry about implementation and not any other random bugs that might pop up.
Can anybody help me out?
Perhaps you can use the Freetype library.
As duskwuff says: TTF is primarily a vector format, would need to write a renderer. Better off using an image file to define the font, or using a bitmap font format like FNT (Windows) or BDF (UNIX).
Here is my answer to my own question: AngelCode's BMFont & Useage. This makes choosing selective characters from the installed char set, mix in a font and exports an image with a map file to each character. Simple to use.
I'm drawing some graphics and text with GDI in my CScrollView. I need to implement the zooming functionality. I only need the zoom out functionality, no need to zoom in more than what is normally rendered.
Here are my best ideas:
Use MM_ANISOTROPIC mapping mode with SetWindowExt/SetViewportExt... The problem with this approach is that it does not scale text. Is there any way to force MFC to scale the text as well? Only thing I can think of is to set text font size according to the selected zoom value, but I'm not sure whether this will look well after all...
Draw to memory DC, and use StretchBlt to blit to the client area of appropriate size (set with SetScrollSizes...). This will solve the text scaling issue.
Also it is desirable to have antialiasing effect in the process. I think both methods above should accomplish this per se, but I don't know which will look better. Also I will have to implement printing/print-preview functionality later (using MFC's standard implementation from doc/view architecture), so I need the method to be compatible with that.
Need your advice please. Which way to go and why. Maybe other options exist too?..
You really don't want to mess with the mapping mode when you use MFC -- MFC itself already uses it for (at least) the print preview functionality.
I'd see if SetWorldTransform will work for you. At least with vector/TrueType fonts, it will scale the text along with everything else. Note that before SetWorldTransform will work, you need to call SetGraphicsMode with GM_ADVANCED.
I ended up using the second method I proposed in the question, but used DIBs instead of DDBs (and StretchDIBits() instead of StretchBlt()) because it proved to cause less problems, especially when using big bitmaps, and when printing.
I'm rendering some text using pangomm, but the font that I am using doesn't have glyphs for parts of the text (in this case, there is some Japanese mixed in with English). Pango seems to render the text correctly using a fallback font.
How can I determine which font is being used as the fallback?
Actually the font selection is based on the selected Pango font backend. Mostly used (I think) is Fontconfig.
You fonts are basically always chosen by looking at the fonts Unicode coverage, meaning that Fontconfig tries to choose the font that covers the letters in the text you want to render best.
Not knowing if your problem applies to Fontconfig, I won't go into to much detail. But if so, have a look at http://www.freedesktop.org/software/fontconfig/fontconfig-user.html, especially the section on 'font matching'.
Feel free to ask again.
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.